Writing a converter in COBOL

In the working storage section of the data division, you should use the COPY statement to copy the copybook DFHRPUCO, and any other copybooks you need. You should also define any other data items you need in working storage.

You use the COPY statement to include the definition of the communication area in the linkage section of the data division.

Figure 1 shows the layout of the data division. Comments, which would be part of a well-documented converter, are omitted.

The following discussion is based on a converter that consists of four main parts:
  • A routing part that consults the function code in the communication area, and then calls the appropriate function
  • A function for Getlengths processing
  • A function for Decode processing
  • A function for Encode processing
Figure 2 shows how you can route control to the appropriate function.
Figure 1. Layout of data division in COBOL
 DATA DIVISION.

WORKING-STORAGE SECTION.

COPY DFHRPUCO.

01 RESP PIC S9(8) COMP.
01 RESP2 PIC S9(8) COMP.
01 REM-PROC-COMMSIZE PIC S9(8) COMP VALUE +12.
01 CLIENT-OUT-SIZE PIC S9(8) COMP VALUE +8.

LINKAGE SECTION.

01 DFHCOMMAREA.
02 COMM-PARMLIST PIC X(1).

01 CONVERTER-PARMS REDEFINES DFHCOMMAREA.
02 CONVERTER-EYECATCHER PIC X(8).
02 CONVERTER-FUNCTION PIC 9(8) COMP.
02 CONVERTER-RESPONSE PIC 9(8) COMP.
02 CONVERTER-REASON PIC 9(8) COMP.
02 CONVERTER-PARMLIST PIC X(1).

01 GLENGTH-PARMS REDEFINES DFHCOMMAREA.
02 GLENGTH-EYECATCHER PIC X(8).
02 GLENGTH-FUNCTION PIC 9(8) COMP.
02 GLENGTH-RESPONSE PIC 9(8) COMP.
02 GLENGTH-REASON PIC 9(8) COMP.
02 GLENGTH-SERVER-INPUT-DATA-LEN PIC S9(8) COMP.
02 …

01 DECODE-PARMS REDEFINES DFHCOMMAREA.
02 …

01 DECODE-RETURNED-DATA.
02 DECODE-PASSWORD PIC X(8).
02 DECODE-SERVER-INPUT-DATA PIC X(1).

01 ENCODE-PARMS REDEFINES DFHCOMMAREA.
02 …
Figure 2. Routing control to the functions in COBOL
 PROCEDURE DIVISION.

A-CONTROL SECTION.

A-0000-MAIN-TASK.

MOVE URP-INVALID TO DECODE-RESPONSE.

IF CONVERTER-FUNCTION = URP-GETLENGTHS
PERFORM B-0000-GETLENGTHS END-IF.

IF CONVERTER-FUNCTION = URP-DECODE THEN
PERFORM C-0000-DECODE END-IF.

IF CONVERTER-FUNCTION = URP-ENCODE THEN
PERFORM D-0000-ENCODE END-IF.

A-9999-EXIT.

EXEC CICS RETURN END-EXEC.
GOBACK.
In this program fragment:
  1. The response URP-INVALID is set.
  2. The IF statements examine the function code in the communication area, and pass control to the appropriate function.
  3. The converter returns to the program that called it. (If the IF statements selected a function, the DECODE-RESPONSE value returned is the response from that function.)
Figure 3 is an example of a Decode function.
Figure 3. Example of a Decode function in COBOL
 C-0000-DECODE.

IF DECODE-EYECATCHER IS NOT = DECODE-EYECATCHER-INIT
MOVE URP-INVALID TO DECODE-RESPONSE
ELSE
SET ADDRESS OF CLIENT-IN-DATA TO DECODE-CLIENT-DATA-PTR
ADD 8 TO REM-PROC-COMMSIZE
EXEC CICS GETMAIN
SET(DECODE-RETURNED-DATA-PTR)
FLENGTH(REM-PROC-COMMSIZE)
SHARED
NOSUSPEND
CICSDATAKEY
RESP(RESP)
RESP2(RESP2)
END-EXEC
SET ADDRESS OF DECODE-RETURNED-DATA
TO DECODE-RETURNED-DATA-PTR
MOVE "PASSWD" TO DECODE-PASSWORD
SET ADDRESS OF REM-PROC-DATA
TO ADDRESS OF DECODE-SERVER-INPUT-DATA
MOVE CLIENT-IN-U-CHAR TO REM-PROC-U-CHAR
MOVE CLIENT-IN-CHAR TO REM-PROC-CHAR
MOVE URP-OK TO DECODE-RESPONSE.
In this program fragment, the names beginning DECODE- (except DECODE-PASSWORD) are fields in the communication area for the Decode function. DECODE-PASSWORD is the field at the beginning of the returned data. The processing is as follows:
  1. The eyecatcher is checked to see if it agrees with the function code. If it does not, the URP-INVALID response is returned.
  2. If it does:
    1. The structure CLIENT-IN-DATA is overlaid on the data coming from the inbound XDR routine addressed by DECODE-CLIENT-DATA-PTR.
    2. The communication area size is increased by 8 to allow for the password field.
    3. EXEC CICS® GETMAIN is used to get storage for the password and for the communication area. REM-PROC-COMMSIZE is the size of the structure REM-PROC-DATA, which defines the format of the communication area. The address of the storage is put directly into DECODE-RETURNED-DATA-PTR.
    4. The structure DECODE-RETURNED-DATA is overlaid on the newly-acquired storage addressed by DECODE-RETURNED-DATA-PTR.
    5. The password is moved into DECODE-PASSWORD.
    6. The data is moved from CLIENT-IN-DATA to REM-PROC-DATA, and the response is set to URP-OK.


dfhtmc00235.html | Timestamp icon Last updated: Monday, 5 June 2017