Skip to main content

Generating and Storing Credit Scores (CRDTAGY1)

The CRDTAGY1 program is responsible for generating and storing credit scores in a simulated banking application. It achieves this by setting up a delay, handling potential errors, retrieving data from a CICS container, generating a random credit score, and storing the updated data back into the container.

The CRDTAGY1 program starts by setting up a delay and handling any errors that might occur during this delay. It then retrieves data from a CICS container, generates a random credit score, and stores this new credit score back into the container. Finally, it checks for any errors during the storage process and exits the program gracefully.

Here is a high level diagram of the program:

Setup and Delay


Generating Delay

First, the program sets up the container and channel names, and initializes the seed for the random number generator. It then computes a random delay amount between 1 and 3 seconds and executes a CICS DELAY command to introduce this delay.

       PREMIERE SECTION.
A010.
*
* Generate a random number of seconds between 0 & 3.
* This is the delay amount in seconds.
*

MOVE 'CIPA ' TO WS-CONTAINER-NAME.
MOVE 'CIPCREDCHANN ' TO WS-CHANNEL-NAME.
MOVE EIBTASKN TO WS-SEED.

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

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


Handling Delay Response

Next, the program checks if the delay response is not normal. If the response is not normal, it initializes the ABNDINFO-REC structure, moves the response codes to the appropriate fields, and performs the POPULATE-TIME-DATE paragraph to gather additional information.

           IF WS-CICS-RESP NOT = DFHRESP(NORMAL)
*
* Preserve the RESP and RESP2, then set up the
* standard ABEND info before getting the applid,
* date/time etc. and linking to the Abend Handler
* program.
*
INITIALIZE ABNDINFO-REC
MOVE EIBRESP TO ABND-RESPCODE
MOVE EIBRESP2 TO ABND-RESP2CODE
*
* Get supplemental information
*
EXEC CICS ASSIGN APPLID(ABND-APPLID)
END-EXEC

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

PERFORM POPULATE-TIME-DATE



POPULATE-TIME-DATE

The POPULATE-TIME-DATE paragraph retrieves the current time and formats it into a human-readable date and time. This information is then used to populate the ABNDINFO-REC structure for error handling.

       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.

Error Handling for Delay


Move Original Date to Abend Date

First, the original date is moved to the abend date field to record when the delay occurred.

              MOVE WS-ORIG-DATE TO ABND-DATE


Format Current Time

Next, the current time is formatted into a string with hours, minutes, and seconds, and stored in the abend time field.

              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


Move Current Time to Abend Time

Then, the formatted current time is moved into the abend time field.

                       INTO ABND-TIME


Move User Time to Abend UTime Key

Moving to the next step, the user time is moved to the abend UTime key field.

              MOVE WS-U-TIME   TO ABND-UTIME-KEY


Set Abend Code to PLOP

The abend code is set to 'PLOP' to indicate the type of error.

              MOVE 'PLOP'      TO ABND-CODE


Assign Program to Abend Program

The current program is assigned to the abend program field for tracking purposes.

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


Move Zeros to Abend SQLCode

Zeros are moved to the abend SQL code field to reset any previous SQL error codes.

              MOVE ZEROS      TO ABND-SQLCODE


Format Freeform Abend Message

A freeform abend message is formatted with specific error details including response codes.

              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


The abend program is linked with the abend information record to handle the error.

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


Display Delay Error Message

An error message is displayed to indicate that the delay caused an issue.

              DISPLAY '*** The delay messed up ! ***'


Trigger Abend with Code PLOP

Finally, the abend is triggered with the code 'PLOP' to terminate the process due to the error.

              EXEC CICS ABEND
ABCODE('PLOP')
END-EXEC

Interim Summary

So far, we saw how the program handles the delay response, including setting up the ABNDINFO-REC structure and gathering additional information. We also covered the steps involved in formatting and moving the current time and date to the appropriate fields for error handling. Now, we will focus on retrieving the container from the CICS channel and handling any potential errors during this process.

Retrieve Container


Compute Container Length

First, the length of the container WS-CONT-IN is computed and stored in WS-CONTAINER-LEN. This length is necessary for the subsequent retrieval of the container from the CICS channel.

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


Get Container from CICS Channel

Next, the container is retrieved from the CICS channel using the EXEC CICS GET CONTAINER command. The container name is specified by WS-CONTAINER-NAME, and the channel name is specified by WS-CHANNEL-NAME. The retrieved data is stored in WS-CONT-IN, and the length of the data is specified by WS-CONTAINER-LEN. 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 Code

Then, the response code WS-CICS-RESP is checked to determine if the container retrieval was successful. If the response code is not DFHRESP(NORMAL), an error message is displayed, including the response codes, container name, channel name, and container length.

           IF WS-CICS-RESP NOT = DFHRESP(NORMAL)
DISPLAY 'CRDTAGY1 - 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


Handle Error

If an error occurs during the container retrieval, the GET-ME-OUT-OF-HERE section is called. This section executes the EXEC CICS RETURN command to terminate the current task and exit gracefully.

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

EXEC CICS RETURN
END-EXEC.

GMOFH999.
EXIT.

Generate and Store Credit Score

This is the next section of the flow.


Generate Credit Score

First, we generate a new credit score for the customer. The credit score is computed using the RANDOM function to get a value between 1 and 999. This ensures that each customer gets a unique and random credit score.

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


Move Credit Score to Container

Next, we move the newly generated credit score (WS-NEW-CREDSCORE) to the container variable (WS-CONT-IN-CREDIT-SCORE). This step prepares the credit score data to be stored back into the container.

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


Put Data Back into Container

Then, we compute the length of the container data (WS-CONTAINER-LEN) and use the EXEC CICS PUT CONTAINER command to store the updated data back into the container. This step ensures that the new credit score is saved and can be accessed by other parts of the application.

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

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.

Final Error Handling and Exit


Check CICS Response

First, the code checks if the CICS response (WS-CICS-RESP) is not equal to DFHRESP(NORMAL). This condition determines if there was an error when attempting to put the container.

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


Display Error Message

If the CICS response is not normal, the code displays an error message. This message includes the response codes (WS-CICS-RESP and WS-CICS-RESP2), the container name (WS-CONTAINER-NAME), the channel name (WS-CHANNEL-NAME), and the container length (WS-CONTAINER-LEN). This helps in diagnosing the issue.

              DISPLAY 'CRDTAGY1 - 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 Exit Routine on Error

Next, the code performs the GET-ME-OUT-OF-HERE routine if there was an error. This routine likely handles the cleanup and exit procedures to safely terminate the program.

              PERFORM GET-ME-OUT-OF-HERE
END-IF.


Perform Exit Routine

Finally, the code performs the GET-ME-OUT-OF-HERE routine again to ensure the program exits properly, regardless of whether there was an error or not.

           PERFORM GET-ME-OUT-OF-HERE.

 

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