Skip to main content

Generating and Storing Credit Scores (CRDTAGY2)

The CRDTAGY2 program is responsible for generating and storing credit scores in a simulated banking application. The program achieves this by setting up a delay, handling errors, retrieving and storing data in CICS containers, and performing final cleanup operations.

The flow starts with setting up a delay to simulate real-world processing time. If any errors occur during this delay, they are handled appropriately. Next, the program retrieves data from a CICS container, generates a random credit score, and stores this score back in the container. Finally, the program performs cleanup operations to ensure all resources are released and the process is safely terminated.

Here is a high level diagram of the program:

Setup Delay


Setting Container and Channel Names

First, the container name and channel name are set to 'CIPB' and 'CIPCREDCHANN' respectively. This is essential for identifying the data and communication channel used in subsequent operations.

           MOVE 'CIPB            ' TO WS-CONTAINER-NAME.
MOVE 'CIPCREDCHANN ' TO WS-CHANNEL-NAME.


Setting Seed Value

Next, the seed value for the random number generator is set using the task number (EIBTASKN). This ensures that the delay amount is varied for each task.

           MOVE EIBTASKN           TO WS-SEED.


Computing Delay Amount

Then, a random delay amount between 1 and 3 seconds is computed. This simulates a real-world delay in processing.

           COMPUTE WS-DELAY-AMT = ((3 - 1)
* FUNCTION RANDOM(WS-SEED)) + 1.


Executing CICS Delay

The computed delay amount is then used to execute a CICS delay command. This introduces the actual delay in the program's execution.

           EXEC CICS DELAY
FOR SECONDS(WS-DELAY-AMT)
RESP(WS-CICS-RESP)
RESP2(WS-CICS-RESP2)
END-EXEC.


Checking CICS Response

Finally, the response from the CICS delay command is checked. If the response is not normal, error handling procedures are initiated.

           IF WS-CICS-RESP NOT = DFHRESP(NORMAL)

Handle Delay Errors


Checking CICS Response

First, the code checks if the CICS response code (WS-CICS-RESP) is not equal to DFHRESP(NORMAL). This indicates that an error has occurred and further error handling is required.

           IF WS-CICS-RESP NOT = DFHRESP(NORMAL)


Initializing Error Information

Next, the code initializes the ABNDINFO-REC record and moves the response codes (EIBRESP and EIBRESP2) into the ABND-RESPCODE and ABND-RESP2CODE fields respectively. This step is crucial for preserving the error information.

              INITIALIZE ABNDINFO-REC
MOVE EIBRESP TO ABND-RESPCODE
MOVE EIBRESP2 TO ABND-RESP2CODE


Collecting Supplemental Information

Then, the code collects additional information such as the application ID (APPLID), task number (EIBTASKN), and transaction ID (EIBTRNID). This information is essential for diagnosing the error.

              EXEC CICS ASSIGN APPLID(ABND-APPLID)
END-EXEC

MOVE EIBTASKN TO ABND-TASKNO-KEY
MOVE EIBTRNID TO ABND-TRANID


Populating Date and Time

Moving to the next step, the code performs the POPULATE-TIME-DATE routine to gather the current date and time.

              PERFORM POPULATE-TIME-DATE


Collecting Date and Time Information

The POPULATE-TIME-DATE routine uses CICS commands to get the current time (ASKTIME) and format it (FORMATTIME). This information is stored in WS-U-TIME, WS-ORIG-DATE, and WS-TIME-NOW.

       POPULATE-TIME-DATE SECTION.
PTD010.

EXEC CICS ASKTIME
ABSTIME(WS-U-TIME)
END-EXEC.

EXEC CICS FORMATTIME
ABSTIME(WS-U-TIME)
DDMMYYYY(WS-ORIG-DATE)
TIME(WS-TIME-NOW)
DATESEP
END-EXEC.

PTD999.
EXIT.


Formatting Date and Time

Next, the code moves the collected date and time into the ABND-DATE and ABND-TIME fields. This step ensures that the error record includes accurate timestamp information.

              MOVE WS-ORIG-DATE TO ABND-DATE
STRING WS-TIME-NOW-GRP-HH DELIMITED BY SIZE,
':' DELIMITED BY SIZE,
WS-TIME-NOW-GRP-MM DELIMITED BY SIZE,
':' DELIMITED BY SIZE,
WS-TIME-NOW-GRP-MM DELIMITED BY SIZE
INTO ABND-TIME


Assigning Program Information

Then, the code assigns the current program name to ABND-PROGRAM. This helps in identifying which program was executing when the error occurred.

              EXEC CICS ASSIGN PROGRAM(ABND-PROGRAM)
END-EXEC


Creating Freeform Error Message

The code constructs a freeform error message that includes the response codes. This message is stored in ABND-FREEFORM and provides a human-readable description of the error.

              STRING 'A010  - *** The delay messed up! ***'
DELIMITED BY SIZE,
' EIBRESP=' DELIMITED BY SIZE,
ABND-RESPCODE DELIMITED BY SIZE,
' RESP2=' DELIMITED BY SIZE,
ABND-RESP2CODE DELIMITED BY SIZE
INTO ABND-FREEFORM


Linking to Abend Handler

Finally, the code links to the Abend Handler program (WS-ABEND-PGM) and passes the ABNDINFO-REC record. This step initiates the abend processing to handle the error.

              EXEC CICS LINK PROGRAM(WS-ABEND-PGM)
COMMAREA(ABNDINFO-REC)
END-EXEC


Displaying Error Message and Abending

The code displays an error message and then abends the transaction with the code 'PLOP'. This ensures that the error is logged and the transaction is terminated gracefully.

              DISPLAY '*** The delay messed up ! ***'
EXEC CICS ABEND
ABCODE('PLOP')
END-EXEC

Interim Summary

So far, we saw how the program handles setting up the delay, computing the delay amount, executing the CICS delay, and handling any errors that occur during this process. Now, we will focus on retrieving the container from the CICS channel and handling any errors that may arise during this operation.

Retrieve Container


Compute Container Length

First, the length of the container is computed and stored in WS-CONTAINER-LEN. This is necessary to allocate the correct amount of memory for the container data.

           COMPUTE WS-CONTAINER-LEN = LENGTH OF WS-CONT-IN.


Get Container from CICS Channel

Next, the code retrieves the container from the CICS channel using the EXEC CICS GET CONTAINER command. The container name and channel name are specified, and the data is stored in WS-CONT-IN. The response codes are stored in WS-CICS-RESP and WS-CICS-RESP2.

           EXEC CICS GET CONTAINER(WS-CONTAINER-NAME)
CHANNEL(WS-CHANNEL-NAME)
INTO(WS-CONT-IN)
FLENGTH(WS-CONTAINER-LEN)
RESP(WS-CICS-RESP)
RESP2(WS-CICS-RESP2)
END-EXEC.


Check Response and Handle Errors

Then, the response code WS-CICS-RESP is checked to see if it is not equal to DFHRESP(NORMAL). If the response indicates an error, an error message is displayed with details about the container and channel, and the GET-ME-OUT-OF-HERE section is performed to handle the error and exit the process.

           IF WS-CICS-RESP NOT = DFHRESP(NORMAL)
DISPLAY 'CRDTAGY2 - UNABLE TO GET CONTAINER. RESP='
WS-CICS-RESP ', RESP2=' WS-CICS-RESP2
DISPLAY 'CONTAINER=' WS-CONTAINER-NAME ' CHANNEL='
WS-CHANNEL-NAME ' FLENGTH='
WS-CONTAINER-LEN
PERFORM GET-ME-OUT-OF-HERE
END-IF.


GET-ME-OUT-OF-HERE

The GET-ME-OUT-OF-HERE section handles the error by executing the CICS RETURN command, which ends the current task and returns control to CICS.

       GET-ME-OUT-OF-HERE SECTION.
GMOFH010.

EXEC CICS RETURN
END-EXEC.

GMOFH999.
EXIT.

Generate Credit Score

This is the next section of the flow.


Generate Random Credit Score

First, we generate a random credit score between 1 and 999. The use of a SEED in the initial RANDOM function ensures that subsequent calls to RANDOM will produce a different value each time.

      *    Now generate a credit score between 1 and 999. Because we
* used a SEED on the first RANDOM (above) we don't need to
* use a SEED again when using RANDOM for a subsequent time
*


Compute Credit Score

Next, we compute the new credit score using the formula ((999- 1) *FUNCTION RANDOM) + 1. This ensures the credit score falls within the desired range of 1 to 999.

           COMPUTE WS-NEW-CREDSCORE = ((999 - 1)
* FUNCTION RANDOM) + 1.


Store Credit Score

Then, we store the newly computed credit score in WS-CONT-IN-CREDIT-SCORE for further processing or storage.

           MOVE WS-NEW-CREDSCORE TO WS-CONT-IN-CREDIT-SCORE.

Store Credit Score and Handle Errors


Calculate Container Length

First, the length of the container data (WS-CONT-IN) is calculated and stored in WS-CONTAINER-LEN. This length is necessary for the subsequent step where the container data is stored in the CICS channel.

           COMPUTE WS-CONTAINER-LEN = LENGTH OF WS-CONT-IN.


Store Container in CICS Channel

Next, the container data (WS-CONT-IN) is stored in the CICS channel using the PUT CONTAINER command. The container name (WS-CONTAINER-NAME), the length of the data (WS-CONTAINER-LEN), and the channel name (WS-CHANNEL-NAME) are specified. The response codes (WS-CICS-RESP and WS-CICS-RESP2) are also captured to check if the operation was successful.

           EXEC CICS PUT CONTAINER(WS-CONTAINER-NAME)
FROM(WS-CONT-IN)
FLENGTH(WS-CONTAINER-LEN)
CHANNEL(WS-CHANNEL-NAME)
RESP(WS-CICS-RESP)
RESP2(WS-CICS-RESP2)
END-EXEC.


Check Response

Then, the response code (WS-CICS-RESP) is checked to determine if the PUT CONTAINER operation was successful. If the response is not normal (DFHRESP(NORMAL)), an error message is displayed with the response codes and container details. The GET-ME-OUT-OF-HERE routine is performed to handle the error and exit the process.

           IF WS-CICS-RESP NOT = DFHRESP(NORMAL)
DISPLAY 'CRDTAGY2 - UNABLE TO PUT CONTAINER. RESP='
WS-CICS-RESP ', RESP2=' WS-CICS-RESP2
DISPLAY 'CONTAINER=' WS-CONTAINER-NAME
' CHANNEL=' WS-CHANNEL-NAME ' FLENGTH='
WS-CONTAINER-LEN
PERFORM GET-ME-OUT-OF-HERE
END-IF.

Final Cleanup

This is the next section of the flow.


Start Termination Process

First, the termination process is initiated by performing the GET-ME-OUT-OF-HERE routine. This routine is responsible for handling the necessary steps to safely terminate the current process.

           PERFORM GET-ME-OUT-OF-HERE.

A999.
EXIT.


Perform GET-ME-OUT-OF-HERE

Next, the GET-ME-OUT-OF-HERE routine is executed. This routine ensures that all necessary cleanup operations are performed, such as closing files, releasing resources, and updating any relevant status indicators.

           PERFORM GET-ME-OUT-OF-HERE.

A999.
EXIT.


End Process

Finally, the process reaches the A999 label, which signifies the end of the termination process. At this point, the process is considered safely terminated, and control is returned to the calling program or the operating system.

       A999.
EXIT.

 

This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human