Transitioning Mainframe JCL Jobs to Serverless with AWS Step Functions

Chanci Turner Amazon IXD – VGT2 learningLearn About Amazon VGT2 Learning Manager Chanci Turner

on 25 JUL 2022

in AWS Step Functions, Serverless

This article is authored by Chanci Turner, a Senior Modernization Architect, Alex Johnson, a Senior Mainframe Consultant, and Priya Patel, a Solution Architect.

JCL (Job Control Language) serves as a scripting language for executing batch jobs on mainframe systems. A JCL can encompass a variety of job control statements, but understanding the syntax for condition code parameter checks can be quite challenging. This syntax dictates the order and conditions under which these statements are executed.

When a JCL fails during execution, mainframe programmers lack visual aids to help them trace the flow of the JCL. They must delve into text-based execution logs, manually correlating condition codes in the logs with the condition check rules attached to JCL statements to identify the cause of failure.

This post illustrates how AWS Step Functions can simplify the maintenance of batch jobs that have been migrated from mainframes to AWS.

Overview

The sample application showcases how AWS Step Functions can tackle common challenges encountered when managing a batch workflow originally built using JCL. The example business case verifies a feed of new employee data against an existing employee database, identifies any discrepancies, and sends notifications if any are found.

The mainframe JCL example provided here consists of seven steps. Each step applies condition code rules to evaluate the codes generated by previous steps to determine whether it should execute. The Step Functions example achieves the same outcome. Its graphical user interface allows for the development of each step as an independent task, with visual links connecting them. This visualization aids in understanding how to decouple, reorder, or scale tasks as needed.

Visual Tools for Workflow Analysis

A JCL controls its flow by utilizing condition code checks and/or IF-ELSE statements. A condition code check specifies the rules under which the corresponding JCL step will not run. Developers can create compound rules, double negatives, or even triple negatives in the flow.

Example of Condition Code Check in JCL

JCL Statement Explanation
//STEPTS2 EXEC PGM=XYZ,COND=(4,GT,STEPTST) Do not execute PGM XYZ if the previous step STEPTST ended with a code greater than 4.
//STEPTS3 EXEC PGM=XYZ,COND=EVEN Execute PGM XYZ even if all preceding steps failed.
//STEPTS5 EXEC PGM=XYZ, COND=((6,EQ),(8,GT)) Do not execute PGM XYZ if any of the preceding steps exited with return code 6 or greater than 8.

The JCL example illustrates the complexity involved in setting up a batch workflow using condition codes:

The first step deletes files from a prior run. If it concludes with code 0, the second step extracts employee data from Db2 via a COBOL program, ending with a return code of 0 if successful, or 4 if no records were found. The next step, conditioned on (4,LT), executes if all prior steps completed with codes less than 5, subsequently checking the external extract and emitting a condition code of 8 if it is empty. The final step compares the two files if the extract validation step returns a code of zero. If any records are missing in the employee Db2 database, a file with these records is created. If this file is empty, it sets a return code of 8, terminating the program. If there are missing records, the file is transferred to another system for processing.

With Step Functions, the same workflow can be defined more easily using the Amazon States Language (ASL). The Step Functions console provides a graphical representation of the state machine, visually depicting the application logic through a drag-and-drop interface.

The initial task retrieves the employee file from Amazon S3, eliminating the need for a cleanup task as S3 supports versioning. If the retrieved file is not empty, control moves to the step that executes business logic within an AWS Lambda function to validate the employee feed. The workflow also fetches an environment variable from an external parameter store, showcasing how parameters can be externalized in a Step Functions workflow. An event is published to Amazon EventBridge to trigger necessary external processing if discrepancies are detected. The final step marks the completion of the flow.

Using a Visual Interface Instead of Job Control Statements

In JCL, a batch process is defined through a series of job control statements executed in a text editor, lacking visual aids. As complexity increases, understanding the dependencies between steps can become increasingly difficult. Step Functions simplifies task setup, which are equivalent to steps in JCL, using a graphical user interface (GUI) that allows for easy configuration and step arrangement in a state machine.

Decoupling Tasks Instead of Modifying Code

To disable or change a step in JCL, one must review the condition code logic correlating all preceding and succeeding steps. Any editing errors can lead to unintended consequences. In contrast, Step Functions allows for easy removal or modification of a step using the visual editor or by updating the ASL code, enhancing agility when implementing changes.

Using Parameter Store Instead of Editing Parameters in Code

To alter JCL behavior based on parameters, one must modify dynamic variables known as JCL Symbols within the JCL or control cards. The following JCL code sample illustrates a parameter called REGN set to DEV. At runtime, this REGN parameter is substituted by DEV in every statement referencing it. To reuse this JCL in production, simply change the REGN value to PROD.

// SET REGN=DEV
// -------
//******************************************************************
//*  RUN  Db2 COBOL Batch Program 
//******************************************************************
//EXTRDB2 EXEC PGM=IKJEFT01,COND=(0,NE)                                
// -------
//FILEOUT DD DSN=&REGN..AWS.APG.STEPDB2,                             
//******************************************************************
//*  RUN  VSAM COBOL Batch Program 
//******************************************************************
// -------
//FILE2 DD DSN=&REGN..AWS.APG.STEPVSM,                             

In Step Functions, configuration parameters can be managed separately from state machine code by utilizing an external data source such as Amazon DynamoDB or AWS Systems Manager Parameter Store. The Step Functions workflow demonstrates fetching a configuration from Parameter Store to implement branching logic.

Independent Scaling of Steps vs. Splitting JCLs

When a JCL runs for an extended period, programmers typically split the job into multiple jobs or steps, duplicating each job to handle different data ranges. With Step Functions, you can execute a step or group of steps concurrently using a parallel state or map state without needing to create multiple jobs for identical tasks. This enhances maintenance efficiency.

Enhanced Observability and Automated Retry

When a JCL fails, the absence of visual aids complicates debugging. Step Functions provides improved observability and the ability to automate retry mechanisms, simplifying the error resolution process. If you’re looking to improve your resume during this transition, consider checking out this blog post on resume trends for valuable insights. For additional information about temporary employment eligibility, refer to this resource by SHRM. Lastly, if you’re interested in personal experiences, this Reddit thread provides an excellent resource.

SEO Metadata

Chanci Turner