Search code examples
cobol

COBOL: Can a GDG file descriptor (FD) reference multiple generations?


I have a program which reads a GDG file and moves data to working storage. I am interested to know if it can be made to repeat this process for multiple generations of the GDG using a reference to the file definition. Perhaps there is a way to use subscripts on the file definition? My thought is there must be a method to move different file definitions into a reference variable from which to access the files.


Solution

  • Code Sample based on suggested, setenv solution

    FILE-CONTROL.
    SELECT DATAIN        ASSIGN TO UT-S-DATAIN.
    
    DATA DIVISION.
    FILE-SECTION.
    FD  DATAIN                         
    BLOCK CONTAINS 0 RECORDS       
    RECORD CONTAINS 133 CHARACTERS 
    LABEL RECORDS ARE STANDARD     
    DATA RECORD IS DATA-REC.       
    01  DATA-REC   PIC X(133).         
    
    WORKING-STORAGE SECTION.   
    01  ENV-VARS.                                             
    02  ENV-NAME        PIC  X(9).                        
    02  ENV-VALUE       PIC  X(100).                      
    02  ENV-OVERWRITE   PIC  S9(8) COMPUTATIONAL VALUE 1.
    
    PROCEDURE DIVISION.
    MOVE Z"DATAIN" TO ENV-NAME                                   
    MOVE Z"DSN(PROGRAMMER.TEST.GDGFILE(-1)),SHR" TO ENV-VALUE 
    MOVE 1 TO ENV-OVERWRITE                                      
    CALL "setenv" USING ENV-NAME ENV-VALUE ENV-OVERWRITE.
    

    Notes

    1. Pay special attention when moving DSN value to ENV-VALUE. On my first swing I left out the closing parentheses, most likely because of JCL muscle memory.
    2. Be sure to empty out your DD statement in JCL/Step.