FLOD exits: Difference between revisions
Line 28: | Line 28: | ||
<p>This method is shown in [[#Inserting records read from alternate data sets|Inserting records read from alternate data sets]].</p> | <p>This method is shown in [[#Inserting records read from alternate data sets|Inserting records read from alternate data sets]].</p> | ||
<b>FLOD Exit Inserting Records Read From Alternate Data Sets</b> | <b>FLOD Exit Inserting Records Read From Alternate Data Sets</b> | ||
[[File: | |||
[[File:FLOD exit inserting records read from alt data sets.gif]] | |||
==Storage requirements== | ==Storage requirements== | ||
<p>To ensure that FLOD Exit has enough working storage space, SPCORE requires:</p> | <p>To ensure that FLOD Exit has enough working storage space, SPCORE requires:</p> |
Revision as of 21:43, 1 July 2013
Overview
The Model 204 File Load utility enables you to load raw data from a sequential data set into Model 204. The heart of the File Load utility, the FLOD program, allows you to manipulate the data as it is being loaded. FLOD (or FILELOAD) Exits allow for much more sophisticated data manipulation including performing edit checks, creating derived fields, and merging data from multiple data sets.
FLOD Exits are programs much like E15 Sort Exits. They add the capability to exit the FLOD program, passing control to a "FLOD Exit" COBOL or Assembler program.
FLOD Exit allows the FLOD or FILELOAD command to read from another source besides the TAPEI file normally required for FLOD and FILELOAD. This allows you to use more than one input file for FLOD or FILELOAD processing.
FLOD Exits are normally run as batch applications.
File Load XG statement
The FLOD or FILELOAD command uses the XG statement to pass control to the FLOD Exit. The XG statement is discussed in detail on XG statement.
FLOD Exits and Sort Exits
FLOD Exits are modeled on Sort Exits similar to the IBM DFSORT. FLOD Exit programs are similar to E15 Sort Exit programs. For more information about E15 Sort Exits, see the documentation for your sort package.
E32 and E35 types of Sort Exits (which allow you to modify records already modified by an E15 Exit) are not supported.
Data sources for FLOD Exits
FLOD Exits are capable of using data from two sources:
- TAPEI data passed to the Exit
- Data accessed by the FLOD Exit
The data source you select depends on the purpose of the FLOD Exit program. The data source argument specified on the XG statement determines whether or not TAPEI records are to be passed to the FLOD Exit. Other data accessed by the FLOD Exit can always be used to generate records for insertion.
The return codes within FLOD Exits vary both according to the source of the data and to the language in which the Exit is written. FLOD Exits involving each data source are discussed separately in the following sections.
Passing records from TAPEI
Pass records to a FLOD Exit from TAPEI when you do not want to code I/O logic into the FLOD Exit or when you want general purpose FLOD Exits. For example, if your site has a number of input files, all of which have the same record format, one FLOD Exit can manipulate the data in any of the files.
The path taken by the data using this method is shown in Passing records from TAPEI.
Passing TAPEI Records To FLOD Exit
Inserting records read from alternate data sets
Use this FLOD Exit feature when you want to read records from multiple data sets. The FLOD Exit is responsible for defining and accessing all alternate data sets.
This method is shown in Inserting records read from alternate data sets.
FLOD Exit Inserting Records Read From Alternate Data Sets
Storage requirements
To ensure that FLOD Exit has enough working storage space, SPCORE requires:
80 bytes + the size of the modified record buffer + any storage acquired by the Exit
For information about the modified record buffer, see XG statement.
If the FLOD Exit program does not have enough space, it might terminate the Model 204 run.
Using FLOD Exits in z/OS environment
In the z/OS environment, control is transferred to a FLOD Exit in 24-bit addressing mode through a BALR 14,15 instruction. All addresses, including the parameter list address passed in Register 1, are 24-bit addresses (bits 25-31 are 0).
When a FLOD Exit passes a new record to FLOD (using an INSERT or ALTER/REPLACE return code), the address of the new record is treated as a valid 31-bit address and might, therefore, reside above the 16M line.
Because a BALR 14,15 instruction stores link information in the high-order byte of Register 14 when executed in 24-bit mode, a FLOD Exit using 31-bit processing mode must clear the high-order byte of the address in Register 14 before issuing a BR 14 instruction.
XG statement
Within a FLOD program, the XG statement is an enhanced G statement. It returns a new input record for processing. If no more input records remain, the file load program terminates and Model 204 goes on to the command that follows the END statement.
The order and content of input records returned to FLOD is determined by the FLOD Exit. The XG statement allows you to call a specific FLOD Exit program and process records in the format of your choice.
The XG statement can be specified as often as needed in a FLOD program. However, Model 204 only processes the syntax of the first XG statement that it compiles, and that syntax is used for any further calls to a FLOD Exit within that FLOD program.
The syntax for the XG statement is:
Syntax
XG [n] [,[c] [,[r] [,[s]]]]
where:
n is the number of a FLOD Exit program that has been linked into Model 204. FLOD Exit programs must be named FLODXTn, where n is a number from 0 to 19. Up to 20 FLOD Exit programs can exist (FLODXT0 to FLODXT19) at any time.
If you try to call a nonexistent FLOD Exit program, Model 204 detects it before executing the first FLOD statement, and issues an appropriate error message.
The default FLOD Exit program is 0 (FLOD Exit program FLODXT0).
c specifies the language of the calling convention such as COBOL or Assembler, that modifies the record image FLOD or FILELOAD operates on.
The valid settings for the calling conventions are:
- 1, the default, for COBOL. You cannot use the DYNAM option in COBOL.
- 2 for Assembler
The default is COBOL.
Any language that uses the same calling conventions as COBOL or Assembler can be used to call the FLOD Exit. Specify the calling convention that is similar to the language of the FLODXTn program.
r specifies the length of the modified record buffer to be allocated by Model 204. The possible settings for this argument are:
- Negative number indicates that a modified record buffer is not allocated.
- Zero, the default, indicates that the number of bytes to allocate is TAPEI's lrecl.
- Positive number specifies the length in bytes of the modified record buffer. The author of the FLOD Exit is responsible for including 4 bytes of variable record overhead and 4 bytes of block overhead (totaling 8 bytes) in the space requirements.
For Assembler-style Exits, this parameter is ignored. These Exits must provide their own modified record buffer if modified records are to be returned or additional records inserted.
For COBOL-style Exits, a modified record buffer is required for INSERT and ALTER/REPLACE operations. You must specify a positive value if you are not passing TAPEI records to the Exit.
s specifies the source of the data.
0, the default, indicates that FLOD supplies the data from TAPEI to the FLOD Exit. The FLOD Exit receives and returns fixed- or variable-length records depending on the record format of TAPEI.
1 indicates that FLOD does not pass records to the Exit and that the Exit returns (INSERT) fixed-length records to FLOD.
2 indicates that FLOD does not pass records to the Exit and that the Exit returns (INSERT) variable-length records to FLOD.
If TAPEI records are not passed, the initial condition is reflected as an EOF condition on TAPEI.
XG statement logic flow
The following example shows the flow of the XG statement logic.
XG statement logic flow
If Passing TAPEI Data If Previous Return Code Not INSERT Read Next TAPEI Data If EOF Set EOF State in Parmlist If Previous Return Code Is DONE Return EOF Condition To FLOD Program End If Clear TAPEI Information In Parmlist Else If Previous Return Code Is DONE Return Unmodified TAPEI Record To FLOD Program End If Store New TAPEI Information In Parmlist End If End If End If Call FLOD Exit Program If Not EOF State In Parmlist Set MIDDLE-REC State In Parmlist End If Select On Return Code: When ACCEPT Error If EOF State In Parmlist Return (Un)Modified TAPEI Record To FLOD Program* When DELETE Error If EOF State In Parmlist When DONE If EOF State In Parmlist Return EOF Condition To FLOD Program Else Return (Un)Modified TAPEI Record To FLOD Program* End If When INSERT Error If Modified Record Length > Buffer Size (COBOL Only) Return Insert Record To FLOD Program When TERMINATE Error When ALTER/REPLACE Error If EOF State In Parmlist Error If Assembler Error If Modified Record Length > Buffer Size (COBOL Only) Return Modified TAPEI Record To FLOD Program Select End Repeat Logic (Entered Only For DELETE)
Note
Modified TAPEI records can be returned to FLOD through ACCEPT and DONE return codes only through Assembler Style Exits.
Writing Assembler-style FLOD Exits
With Assembler-style FLOD Exits, the address of a parameter list, one word long and aligned on the fullword boundary, is placed in Register 1. The first byte of the parameter list is X'00' and the last three bytes contain the address of the record.
A zero address in Register 1 indicates an EOF condition. This means either that all TAPEI records have been passed, or that there were no records to pass. A zero address is the initial condition when TAPEI records are not passed.
When the FLOD Exit has finished processing the record, store the appropriate return code (seeAssembler return codes) in Register 15. Depending on the return code you specify, Register 1 might point to a record, either modified or unmodified.
When variable-length records are returned to FLOD with Assembler-style FLOD Exits, the first four bytes of the record must contain a Record Descriptor Word that gives the length of the record.
Note
Do not modify either input parameters or the parameter list itself. Instead, copy the TAPEI record to a work area before modifying it.
Assembler register conventions
Assembler-Style FLOD Exits must follow these register conventions:
Register | Address of... |
---|---|
1 | FLOD Exit parameter list upon entrance. This register might point to a record upon return. |
13 | 18- word area in which registers can be saved. This register is used for linkage. |
14 | FLOD's return. |
15 | Exit program's entry point. This register must contain the return code upon return. |
Registers 2-12 must be preserved by the FLOD Exit upon return.
Assembler return codes
The return codes within the FLOD Exit program give FLOD explicit instructions about how to handle each record. Return codes are defined in Assembler return codes.
Return code | Meaning |
---|---|
0 |
ACCEPT record from TAPEI. Return code 0 is invalid for an EOF condition (where either EOF is reached or no records are passed from TAPEI). Send the record to FLOD. Load record address into Register 1. |
4 |
DELETE record from TAPEI. Return code 4 is invalid for an EOF condition. Read the next record from TAPEI, then call FLOD Exit. Do not exit the XG statement. A record with the 4 return code is not sent to FLOD. You do not need to load the address into Register 1. |
8 |
DONE - do not return to this Exit. This return code is always valid. The 8 return code returns control to FLOD for the remainder of the FLOD program. You must pass the 8 return code at EOF unless you are inserting records after the original data. If the FLOD Exit passes an 8 return code to FLOD before EOF, ACCEPT processing is performed for the current record to which Register 1 points. Subsequent executions of the XG statement perform like a G statement. Thus, the remaining TAPEI records are accepted on behalf of the Exit. |
12 |
INSERT record in FLOD. This return code is always valid. The 12 return code sends the record to FLOD, but does not advance TAPEI. Load the address into Register 1. This return code does not move the TAPEI record pointer to the next record. If FLOD is not an EOF, the FLOD Exit must ACCEPT or DELETE the current TAPEI record before another TAPEI record is passed. In Assembler FLOD Exits, the 12 return code does not perform a check for modified record buffer overflow. |
16 |
TERMINATE abnormally. This return code is always valid. The FLOD program is abnormally terminated. Use this return code to abort the FLOD program when the Exit determines a fatal error has occurred. You do not need to load the address into Register 1. |
Assembler/TAPEI example
In the following sample Assembler program, variable-length records are passed from FLOD to the FLOD Exit. The FLOD Exit checks each record for a minimum length. Any record that is at least the expected length can be accepted, modified, or deleted. Any record that is to be modified cannot exceed the modified record buffer length that is allocated in the Assembler Exit. If a length error is detected, the FLOD program is terminated.
All records, including the first record passed, are altered, deleted, or accepted. If the DEPT-ID field is 11111, it is altered to 33333. If the DEPT-ID field is 22222, the record is deleted (that is, are not passed to FLOD). All other records are accepted (that is, are passed to FLOD unmodified).
Note
This FLOD Exit must be modified to handle fixed-length records passed from FLOD. Assume that TAPEI has a variable-length record format. The syntax to invoke this FLOD Exit is:
XG 2,2,-1,0
FLOD Exit using Assembler and TAPEI
FLODXT2 CSECT R1 EQU 1 R2 EQU 2 R12 EQU 12 R13 EQU 13 R14 EQU 14 R15 EQU 15 STM R14,R12,12(R13) STANDARD SAVE CONVENTION LR R12,R15 SET UP BASE REGISTER USING FLODXT2,R12 PROVIDE ADDRESSABILITY SPACE SLR R15,R15 DEFAULT RC=0 L R1,0(,R1) R1 := PTR TO RECORD LTR R1,R1 CHECK TAPEI RECORD PTR BZ DONE IF EOF, THEN DONE LH R2,0(,R1) R2 := LENGTH FROM RDW C R2,MINLEN CHECK LENGTH BL ERROR ERROR IF BELOW MINIMUM CLC DELDEPT,DEPTID-RDW(R1) CHECK IF DEPT TO DELETE BE DELETE IF EQUAL, THEN DELETE CLC CHGDEPT,DEPTID-RDW(R1) CHECK IF DEPT TO CHANGE BNE RETURN IF NOT EQUAL, THEN ACCEPT C R2,MAXLEN CHECK LENGTH BH ERROR ERROR IF ABOVE BUFFER MAXIMUM BCTR R2,0 DECREMENT FOR EX MVC EX R2,MOVEREC MVC RDW(0),0(R1) LA R1,RDW R1 := PTR TO MODIFIED RECORD MVC DEPTID,NEWDEPT SAVE NEW DEPT ID SPACE RETURN LM R2,R12,4*4+12(R13) RESTORE ONLY REGISTERS 2-12 BR R14 RETURN TO FLOD SPACE MOVEREC MVC RDW(*-*),0(R1) MOVE RECORD INTO BUFFER SPACE ERROR LA R15,8(,R15) RESULTANT RC=16 DONE LA R15,4(,R15) RESULTANT RC=8 DELETE LA R15,4(,R15) RESULTANT RC=4 B RETURN COMMON EXIT SPACE DC 0D'0' ALIGN STORAGE ON DOUBLEWORD MINLEN DC A(DEPTNAME-RDW+1) NAME MUST BE AT LEAST 1 BYTE MAXLEN DC A(BUFFEND-RDW) VARIABLE LENGTH RECORD MAX DC CL8'FLXTMRBF' EYE-CATCHER FOR DEBUGGING RDW DC Y(0,0) RECORD DESCRIPTOR WORD DEPTID DC CL5' ' DEPT ID ALWAYS PRESENT DEPTNAME DC CL75' ' DEPT NAME IS 1 TO 75 BYTES BUFFEND DS 0C END OF MODIFIED RECORD BUFFER SPACE CHGDEPT DC CL5'11111' DEPT ID TO CHANGE TO NEW DEPT DELDEPT DC CL5'22222' DEPT ID TO DELETE NEWDEPT DC CL5'33333' NEW DEPT ID FOR CHGDEPT DROP R12 DROP ADDRESSABILITY TO EXIT END
Writing COBOL-style FLOD Exits
Parameters for COBOL-style FLOD Exits
Each time a COBOL-Style FLOD Exit is called, FLOD supplies the following parameter list:
- RECORD-FLAGS
- TAPEI-RECORD
- MODIFIED-RECORD
- TAPEI-RECORD-LEN
- MODIFIED-RECORD-LEN
These parameters are discussed in detail in the following sections.
RECORD-FLAGS
A pointer to a fullword specifying the TAPEI record being passed. This input parameter contains a X'00000000' when the first TAPEI record is passed and a X'00000004' when any other TAPEI record is passed.
The value X'00000008' reflects an EOF condition and indicates that FLOD is not passing a TAPEI record. Either all TAPEI records have already been passed and accepted or deleted, or there were no records to pass. This is the initial condition when FLOD is not passing TAPEI records.
TAPEI-RECORD
A pointer to the current TAPEI record being passed. This pointer is zero when an EOF condition is found. This pointer is for system use only. This input parameter contains the record returned to FLOD when the RETURN-CODE is set to ACCEPT or the record to be ignored when the RETURN-CODE is set to DELETE.
This input parameter also contains the record returned to FLOD when the RETURN-CODE is set to DONE and an EOF condition is not found.
MODIFIED-RECORD
A pointer to the modified record buffer allocated by FLOD on behalf of the FLOD Exit. For variable-length records, this pointer is 4 bytes into the buffer to allow a record descriptor word to be built. If the XG statement did not request that a modified record buffer be allocated, this pointer is zero and is invalid to use. This parameter contains the record returned to FLOD when the RETURN-CODE is set to INSERT or ALTER/REPLACE.
TAPEI-RECORD-LEN
A pointer to a fullword specifying the length of the current TAPEI record being passed. If an EOF condition is reflected, the length is zero. This input parameter contains the length of the record returned to FLOD when the RETURN-CODE is set to ACCEPT, or DONE when an EOF condition is not reflected.
MODIFIED-RECORD-LEN
A pointer to a fullword specifying the length of the modified record. This parameter is set initially to the usable length of the modified record buffer or 0 if none was allocated. For variable-length records, this length must not exceed the size of the modified record buffer minus the 4 bytes required to build the record descriptor word (that is, usable length for variable-length records). This parameter is used to build the record descriptor word and contains the length of the variable-length record returned to FLOD when the RETURN-CODE is set to INSERT or ALTER/REPLACE. Modifying this parameter has no effect when fixed-length records are being processed.
Using COBOL-style FLOD Exit parameters
When processing variable-length records with COBOL-style Exits, all length and record parameters do not include the 4-byte record descriptor. This is managed by FLOD for the Exit.
Do not modify either input parameters or the parameter list itself. Copy the TAPEI record to a work area before modifying it.
Output parameters are given initial values but are not modified by FLOD. The Exit can depend on output parameters being preserved.
The parameter list is static except for the TAPEI-RECORD pointer. All input parameters are static for an EOF condition.
Note
You can choose to have an Assembler program be called with the COBOL-style convention to take advantage of the extended parameter list. However, this program must not modify input parameters nor the parameter list itself.
COBOL return codes
The return codes within the FLOD Exit program give FLOD explicit instructions about how to handle each record. The return code is moved to the RETURN-CODE special register. Return codes are described in Table 12-2.
Return code | Meaning |
---|---|
0 |
ACCEPT record from TAPEI. This return code is invalid for an EOF condition (where either EOF is reached or no records are passed from TAPEI). Send the unmodified record (TAPEI-RECORD) to FLOD. |
4 |
DELETE record from TAPEI. This return code is invalid for an EOF condition. Read next record from TAPEI, then call FLOD Exit. Do not exit the XG statement. The 4 return code does not send a record to FLOD. |
8 |
DONE-do not return to this Exit. This return code is always valid. The 8 return code returns control to FLOD for the remainder of the FLOD program. You must pass the 8 return code at EOF unless you are inserting records after the original data. If the FLOD Exit passes an 8 return code to FLOD before EOF is reached, ACCEPT processing is performed for the current TAPEI record. Subsequent executions of the XG statement perform like a G statement. Thus, the remaining TAPEI records are accepted on behalf of the Exit. |
12 |
INSERT record in FLOD. This return code is always valid. This return code sends the record to FLOD, but does not advance TAPEI. Move the record to the MODIFIED-RECORD parameter and move the length of this record to the MODIFIED-RECORD-LEN parameter. The 12 return code keeps the TAPEI-RECORD pointer at the same location. If there is no EOF condition, the FLOD Exit must ACCEPT, DELETE, or ALTER/REPLACE the current TAPEI record before the next TAPEI record is passed. The 12 return code performs a check (for COBOL-style Exits) for modified record buffer overflow with variable-length records by comparing the MODIFIED-RECORD-LEN parameter against its maximum value. |
16 |
TERMINATE Abnormally. This return code is always valid. The FLOD program is abnormally terminated. Use this return code to alert the FLOD program when the Exit determines a fatal error has occurred. |
20 |
ALTER/REPLACE record. This return code is invalid for an EOF condition. Move the record to the MODIFIED-RECORD parameter and move the length of this record to the MODIFIED-RECORD-LEN parameter. The 20 return code (only valid from COBOL-style Exits) causes a check for modified record buffer overflow for variable-length records by comparing the MODIFIED-RECORD-LEN parameter against its maximum value. |
Diagram of COBOL-style FLOD Exits
Structure of COBOL-style FLOD Exits shows the structure of the COBOL interface to FLOD Exit functions.
Structure of COBOL-style FLOD Exits
LINKAGE SECTION and PROCEDURE DIVISION issues
The LINKAGE SECTION and PROCEDURE DIVISION are required in COBOL FLOD Exit programs. The LINKAGE SECTION identifies what gets passed to the FLOD Exit; the parameters are repeated in the USING option of the PROCEDURE DIVISION.
In the USING option, specify each 01-level name in the LINKAGE SECTION. Specify each name in order up to the last one you plan to use, even if you do not use all the names.
You must use the GOBACK statement to return control to FLOD.
COBOL/TAPEI example
In the following sample COBOL program, variable-length records are passed from FLOD to the FLOD Exit.
When the first record is passed, the usable size of the modified record buffer is checked against the maximum allowed for in the COBOL Exit. The FLOD program is terminated if the modified record buffer cannot hold the largest record that the COBOL Exit can handle. In addition, all TAPEI record lengths are verified against the maximum allowed length. Any length violations detected cause the FLOD program to terminate. No check is provided to verify the minimum length of a record. (This can easily be added.)
All records, including the first record passed, are either altered, deleted, or accepted. If the DEPT-ID field is 11111, it is altered to 33333. If the DEPT-ID field is 22222, the record is deleted (that is, not passed to FLOD). All other records are accepted that is, passed to FLOD unmodified).
Note
This FLOD Exit need not be modified to handle fixed-length records passed from FLOD. In either case, this COBOL Exit can be invoked with:
XG 3,1,84,0
Sample COBOL/TAPEI FLOD Exit
IDENTIFICATION DIVISION. PROGRAM-ID. FLODXT3. COMMENTS. VARIABLE OR FIXED LENGTH RECORDS ARE PASSED. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 DEPT-RECORD. 05 DEPT-ID PIC 9(5). 88 CHG-DEPT VALUE 11111. 88 DEL-DEPT VALUE 22222. 05 DEPT-NAME OCCURS 1 TO 75 TIMES DEPENDING ON DEPT-NAME-LEN PIC X. 01 DEPT-NAME-LEN PIC 9(4) COMP. 01 RETCODES. 05 ACCEPT-TAPEI PIC 9(4) COMP VALUE 00. 05 DELETE-TAPEI PIC 9(4) COMP VALUE 04. 05 DO-NOT-RETURN PIC 9(4) COMP VALUE 08. 05 INSERT-RECORD PIC 9(4) COMP VALUE 12. 05 TERMINATE-FLOD PIC 9(4) COMP VALUE 16. 05 ALTER-REPLACE PIC 9(4) COMP VALUE 20. 01 CONSTANTS. 05 MAXLEN PIC 9(4) COMP VALUE 80. 05 NEW-DEPT PIC 9(5) VALUE 33333. LINKAGE SECTION. 01 RECORD-FLAGS PIC 9(8) COMP. 88 FIRST-TAPEI VALUE 00. 88 OTHER-TAPEI VALUE 04. 88 EOF VALUE 08. 01 TAPEI-RECORD. 05 TRB OCCURS 1 TO 80 TIMES DEPENDING ON TAPEI-RECORD-LEN PIC X. 01 MODIFIED-RECORD. 05 MRB OCCURS 1 TO 80 TIMES DEPENDING ON MODIFIED-RECORD-LEN PIC X. 01 TAPEI-RECORD-LEN PIC 9(8) COMP. 01 MODIFIED-RECORD-LEN PIC 9(8) COMP. PROCEDURE DIVISION USING RECORD-FLAGS, TAPEI-RECORD, MODIFIED-RECORD, TAPEI-RECORD-LEN, MODIFIED-RECORD-LEN. *********************************************************** MAIN-LOGIC. IF FIRST-TAPEI IF MODIFIED-RECORD-LEN IS LESS THAN MAXLEN PERFORM TERMINATE-LOGIC. IF NOT EOF IF TAPEI-RECORD-LEN IS GREATER THAN MAXLEN PERFORM TERMINATE-LOGIC ELSE SUBTRACT 5 FROM TAPEI-RECORD-LEN GIVING DEPT-NAME-LEN MOVE TAPEI-RECORD TO DEPT-RECORD IF CHG-DEPT PERFORM ALTER-LOGIC ELSE IF DEL-DEPT PERFORM DELETE-LOGIC ELSE PERFORM ACCEPT-LOGIC ELSE PERFORM EOJ-LOGIC. TERMINATE-LOGIC. MOVE TERMINATE-FLOD TO RETURN-CODE. GOBACK. ALTER-LOGIC. MOVE NEW-DEPT TO DEPT-ID. MOVE TAPEI-RECORD-LEN TO MODIFIED-RECORD-LEN. MOVE DEPT-RECORD TO MODIFIED-RECORD. MOVE ALTER-REPLACE TO RETURN-CODE. GOBACK. ACCEPT-LOGIC. MOVE ACCEPT-TAPEI TO RETURN-CODE. GOBACK. DELETE-LOGIC. MOVE DELETE-TAPEI TO RETURN-CODE. GOBACK. EOJ-LOGIC. MOVE DO-NOT-RETURN TO RETURN-CODE. GOBACK.
COBOL/TAPEI/alternate data set example
In the following sample COBOL program, variable-length TAPEI records can be passed from FLOD to the FLOD Exit. The FLOD Exit also processes records from another data set. Variable-length records are returned to FLOD. An output file is produced for debugging purposes. Rocket Software suggests that you use debugging statements when testing FLOD Exits, which you can later comment out, after the Exit is performing as expected.
Sample COBOL/TAPEI FLOD Exit with alternate data sets
IDENTIFICATION DIVISION. PROGRAM-ID. FLODXT1. COMMENTS. FIXED LENGTH RECORDS ARE READ BY EXIT AND PASSED TO FLOD AS VARIABLE LENGTH RECORDS. THIS EXIT CAN BE INVOKED WITH: XG 1,1,84,2 VARIABLE LENGTH RECORDS MAY ALSO BE PASSED BY FLOD. IF THIS EXIT IS INVOKED WITH THE FOLLOWING STATEMENT, THE RECFM OF TAPEI MUST BE VARIABLE LENGTH. XG 1,1,84,0 BECAUSE ALL RECORDS ARE MOVED INTO WORKING STORAGE, THE MAXIMUM DATA LENGTH THAT CAN BE PROCESSED IS 80 BYTES (SEE WORK-RECORD). THE DATA PORTIONS OF THE VARIABLE LENGTH RECORDS READ BY THE EXIT AND PASSED BY FLOD ARE ASSUMED TO BE 3 TO 80 BYTES LONG WHERE THE FIRST 2 BYTES IS A ZONED DECIMAL LENGTH FOLLOWED BY A 1 TO 78 BYTE STRING THAT IS TO BE TRUNCATED OR PADDED WITH ZEROES TO THE LENGTH SPECIFIED IN THE FIRST 2 BYTES. A TRUNCATED OR PADDED STRING OF 0 TO 80 BYTES IS RETURNED TO FLOD. THE FOLLOWING EXAMPLE SHOWS THE HEXADECIMAL REPRESENTATION OF DATA: INPUT OUTPUT OUTPUT FLOD DATA DATA LEN RECORD F0F2C140 C140 00000002 00020000C140 F0F2C140C2 C140 00000002 00020000C140 F0F2C1 C140 00000002 00020000C140 NOTE: FLOD WILL BUILD A 4 BYTE R DW PRECEDING THE MODIFIED RECORD. THUS THE FOLLOWING FLOD PROGRAM WILL PRINT THE PROCESSED RECORDS: FILELOAD -1,-1,0 XG 1,1,84,0 * INVOKE FLOD EXIT I 1,1,2,-4 * CALCULATE DATA LENGTH P 5,0|1 * PRINT DATA PORTION END IF THE EXAMPLE DATA WERE USED, THE LETTER 'A' FOLLOWED BY A SPACE WOULD BE PRINTED FOR ALL 3 RECORDS. ENVIRONMENT DIVISION. CONFIGURATION SECTION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT IN-FILE ASSIGN TO UT-S-FLODXIN STATUS IN-STATUS. SELECT OUT-FILE ASSIGN TO UT-S-FLODXOUT STATUS OUT-STATUS. DATA DIVISION. FILE SECTION. FD IN-FILE LABEL RECORD OMITTED BLOCK CONTAINS 0 RECORDS RECORD CONTAINS 80 CHARACTERS. 01 IN-RECORD PIC X(80). FD OUT-FILE LABEL RECORD OMITTED BLOCK CONTAINS 0 RECORDS RECORD CONTAINS 28 TO 105 CHARACTERS. 01 OUT-RECORD. 05 OUT-COMMENT PIC X(25). 05 OREC. 10 OCHAR OCCURS 3 TO 80 TIMES DEPENDING ON OREC-LEN PIC X. WORKING-STORAGE SECTION. 01 IN-STATUS PIC 9(2). 01 OUT-STATUS PIC 9(2). 01 OREC-LEN PIC 9(8) COMP. 01 WREC-LEN PIC 9(8) COMP. 01 WMAX-LEN PIC 9(8) COMP VALUE 80. 01 FLAGS. 05 INIT-FLAG PIC X VALUE "1". 88 FIRST-TIME-THROUGH VALUE "1". 88 EOF-ON-INPUT VALUE "2". 01 WORK-RECORD. 05 WLEN PIC 9(2). 05 WREC. 10 WCHAR OCCURS 1 TO 78 TIMES DEPENDING ON WREC-LEN PIC X. 01 RETCODES. 05 ACCEPT-REC PIC 9(8) COMP VALUE 00. 05 DELETE-REC PIC 9(8) COMP VALUE 04. 05 DO-NOT-RETURN PIC 9(8) COMP VALUE 08. 05 INSERT-REC PIC 9(8) COMP VALUE 12. 05 TERMINATE-FLOD PIC 9(8) COMP VALUE 16. 05 ALTER-REPLACE-REC PIC 9(8) COMP VALUE 20. LINKAGE SECTION. 01 RECORD-FLAGS PIC 9(8) COMP. 88 FIRST-TAPEI-REC VALUE 00. 88 OTHER-TAPEI-REC VALUE 04. 88 EOF-ON-TAPEI VALUE 08. 01 TAPEI-RECORD. 05 TREC OCCURS 1 TO 80 TIMES DEPENDING ON TAPEI-RECORD-LEN PIC X. 01 MODIFIED-RECORD. 05 MREC OCCURS 1 TO 80 TIMES DEPENDING ON MODIFIED-RECORD-LEN PIC X. 01 TAPEI-RECORD-LEN PIC 9(8) COMP. 01 MODIFIED-RECORD-LEN PIC 9(8) COMP. PROCEDURE DIVISION USING RECORD-FLAGS, TAPEI-RECORD, MODIFIED-RECORD, TAPEI-RECORD-LEN, MODIFIED-RECORD-LEN. *************************************************************** MAIN-LOGIC. IF FIRST-TIME-THROUGH PERFORM OPEN-FILE. IF NOT EOF-ON-INPUT PERFORM READ-FILE. IF NOT EOF-ON-TAPEI PERFORM READ-TAPEI. PERFORM EOJ-RTN. *************************************************************** OPEN-FILE. MOVE "0" TO INIT-FLAG. OPEN INPUT IN-FILE. OPEN OUTPUT OUT-FILE. MOVE "OPEN-FILE: RECORD-FLAGS " TO OUT-COMMENT. MOVE 25 TO OREC-LEN. IF FIRST-TAPEI-REC MOVE "FIRST-TAPEI-REC " TO OREC ELSE IF EOF-ON-TAPEI MOVE "EOF-ON-TAPEI " TO OREC ELSE IF OTHER-TAPEI-REC MOVE "*** OTHER-TAPEI-REC *** " TO OREC PERFORM TERMINATE-RTN ELSE MOVE "*** UNDEFINED VALUE *** " TO OREC PERFORM TERMINATE-RTN. WRITE OUT-RECORD. MOVE "INPUT FILE STATUS: " TO OUT-COMMENT. MOVE 2 TO OREC-LEN. MOVE IN-STATUS TO OREC. WRITE OUT-RECORD. MOVE "OUTPUT FILE STATUS: " TO OUT-COMMENT. MOVE OUT-STATUS TO OREC. WRITE OUT-RECORD. IF MODIFIED-RECORD-LEN IS LESS THAN WMAX-LEN MOVE "MODIFIED-RECORD BUFFER: " TO OUT-COMMENT MOVE 25 TO OREC-LEN MOVE "*** TOO SMALL *** " TO OREC PERFORM TERMINATE-RTN. ************************************************************** CLOSE-FILE. MOVE "CLOSE-FILE: RECORD-FLAGS " TO OUT-COMMENT. MOVE 25 TO OREC-LEN. IF EOF-ON-TAPEI MOVE "EOF-ON-TAPEI " TO OREC ELSE MOVE "*** NOT EOF-ON-TAPEI *** " TO OREC. WRITE OUT-RECORD. CLOSE IN-FILE. CLOSE OUT-FILE. ************************************************************** More READ-FILE. MOVE 78 TO WREC-LEN. READ IN-FILE RECORD INTO WORK-RECORD AT END MOVE 2 TO INIT-FLAG. MOVE "READ-FILE: WORK-RECORD " TO OUT-COMMENT. IF EOF-ON-INPUT MOVE 25 TO OREC-LEN MOVE "EOF-ON-INPUT " TO OREC WRITE OUT-RECORD ELSE MOVE WREC-LEN TO OREC-LEN MOVE WORK-RECORD TO OREC WRITE OUT-RECORD MOVE INSERT-REC TO RETURN-CODE PERFORM WORK-SEND. ************************************************************** WORK-SEND. MOVE WLEN TO WREC-LEN. IF WREC-LEN IS GREATER THAN WMAX-LEN MOVE "WORK-SEND: WREC-LEN " TO OUT-COMMENT MOVE 25 TO OREC-LEN MOVE "*** TOO LARGE *** " TO OREC PERFORM TERMINATE-RTN. MOVE WREC-LEN TO OREC-LEN. MOVE "WORK-SEND: WREC " TO OUT-COMMENT. MOVE WREC TO OREC. WRITE OUT-RECORD. MOVE WREC-LEN TO MODIFIED-RECORD-LEN. MOVE WREC TO MODIFIED-RECORD. PERFORM RETURN-TO-FLOD. ************************************************************** READ-TAPEI. IF TAPEI-RECORD-LEN IS GREATER THAN WMAX-LEN MOVE "READ-TAPEI: TAPEI-RECORD " TO OUT-COMMENT MOVE 25 TO OREC-LEN MOVE "*** TOO LARGE *** " TO OREC PERFORM TERMINATE-RTN. MOVE "READ-TAPEI: TAPEI-RECORD " TO OUT-COMMENT. MOVE TAPEI-RECORD-LEN TO OREC-LEN. MOVE TAPEI-RECORD TO OREC. WRITE OUT-RECORD. MOVE 78 TO WREC-LEN. MOVE TAPEI-RECORD TO WORK-RECORD. MOVE ALTER-REPLACE-REC TO RETURN-CODE. PERFORM WORK-SEND. ************************************************************** RETURN-TO-FLOD. GOBACK. ************************************************************** EOJ-RTN. PERFORM CLOSE-FILE. MOVE DO-NOT-RETURN TO RETURN-CODE. PERFORM RETURN-TO-FLOD. ************************************************************** TERMINATE-RTN. WRITE OUT-RECORD. PERFORM CLOSE-FILE. MOVE TERMINATE-FLOD TO RETURN-CODE. PERFORM RETURN-TO-FLOD. **************************************************************