Use a Variable for a File-Name

Is it possible Visual COBOL Personal to use a variable for the 'assign to' name.

I am working on a project that I need to split a file in about 100 different files for delivery. And DO NOT want to create 100 Selects and FD's.

 

Is this possible?

  • Yes, you can do this. It's enough to specify a data-name in the ASSIGN phrase, e.g.:
    SELECT my-file ASSIGN file-name...
    file-name can be declared explicitly in working-storage, but will otherwise be generated implicitly by the compiler (I think as PIC X(260)).
  • Off course, you can assign to ws-variable where ws-variable has the file-name.

    ex.

    SELECT FINV-ACLIN    ASSIGN TO WS-NAME-FISIC

    ...

    ...

    move "MY-FILE-NAME.DAT" TO WS-NAME-FISIC

     

    the other thing that could be useful is to use (prefix) on FD to maximize re-usability through several programs.

    Look the micro Focus Book demo or AirPortDemo for examples in your instalation.

    regards, 

  • Verified Answer

    Thanks, I thought it was easy but could not find a reference and when I tried this method before I received a file not found. So I gave up and asked the question. I did figure out that I could use an environment variable to do the job. But this answer is much easier and a little more portable. Thanks again.
  • *******************I want to give you 3 different COBOL programs that accept File name
    *******************from the User at Run Time. Here is The First File.



    IDENTIFICATION DIVISION.
    PROGRAM-ID. LINE-NUMBER.
    AUTHOR. TIM R P BROWN.
    ********************************************************
    * THIS PROGRAM NUMBERS SOURCE CODE LINE WHEN USER
    * ENTERS COBOL SOURCE CODE FILE NAME TO BE NUMBERED.
    * THE OUTPUT FILE NAME WILL BE 'COBOLOUT.CBL.
    * SO USER SHOULD RENAME NUMBERED FILE NAME TO
    * WHATEVER ELSE.
    ********************************************************

    ENVIRONMENT DIVISION.
    INPUT-OUTPUT SECTION.
    FILE-CONTROL.
    SELECT IN-FILE ASSIGN TO COBOL-INPUT-FILE
    ORGANIZATION IS LINE SEQUENTIAL.
    SELECT OUT-FILE ASSIGN TO 'COBOLOUT.CBL'
    ORGANIZATION IS LINE SEQUENTIAL.


    *********************************************************

    DATA DIVISION.
    FILE SECTION.
    FD IN-FILE.
    01 LINE-CODE-IN.
    03 CHAR-1 PIC X.
    03 CODE-LINE PIC X(131).

    FD OUT-FILE.
    01 LINE-CODE-OUT PIC X(132).


    WORKING-STORAGE SECTION.

    01 COBOL-INPUT-FILE PIC X(50).
    01 USER-COBOL-INPUT-FILE PIC X(50).
    01 COBOL-OUTPUT-FILE PIC X(50).

    01 EOF-FLAG PIC X VALUE 'N'.
    88 END-OF-FILE VALUE 'Y'.

    01 NUMBER-CODE.
    03 L-NUM-CODE PIC 9(6) VALUE ZEROS.
    03 B-SPACE PIC X VALUE SPACE.
    03 L-CODE PIC X(125) VALUE SPACES.

    01 NUMBER-COMMENT.
    03 L-NUM-COM PIC 9(6) VALUE ZEROS.
    03 L-COMMENT PIC X(126) VALUE SPACE.

    01 LINE-NUMBER PIC 9(6) VALUE ZERO.

    ******************************************************

    PROCEDURE DIVISION.

    MAIN-PARA.
    DISPLAY 'PLEASE TYPE COBOL SOURCE CODE FILE TO BE'
    - ' NUMBERED : '
    ACCEPT USER-COBOL-INPUT-FILE
    MOVE USER-COBOL-INPUT-FILE TO COBOL-INPUT-FILE
    OPEN INPUT IN-FILE
    OUTPUT OUT-FILE

    PERFORM UNTIL END-OF-FILE
    ADD 10 TO LINE-NUMBER
    READ IN-FILE RECORD
    AT END MOVE 'Y' TO EOF-FLAG
    NOT AT END IF (CHAR-1 = '*')
    OR (CHAR-1 = '/')
    OR (CHAR-1 = '-') THEN

    MOVE LINE-CODE-IN TO L-COMMENT
    MOVE LINE-NUMBER TO L-NUM-COM
    WRITE LINE-CODE-OUT FROM NUMBER-COMMENT
    ELSE
    MOVE LINE-CODE-IN TO L-CODE
    MOVE LINE-NUMBER TO L-NUM-CODE
    WRITE LINE-CODE-OUT FROM NUMBER-CODE
    END-IF
    END-READ
    INITIALIZE NUMBER-CODE, NUMBER-COMMENT
    END-PERFORM

    CLOSE IN-FILE, OUT-FILE
    EXIT PROGRAM
    STOP RUN.



    *********************Above File numbers COBOL program source code, the time will come
    *********************when our Visual COBOL trial version will soon expire, then we should
    *********************use Notepad as our COBOL Editor which has no Source Code Numbering
    *********************Function. But we find Source Code Numbering is very Useful, So above
    *********************Program generate new COBOL Source Code File with Line Numbering
    *********************Based upon User Provided COBOL Source Code File Name using ACCEPT.








    ********************Below is Another COBOL Program to Number COBOL Source Code File
    ********************which doesn't has Numbering in it.






    IDENTIFICATION DIVISION.
    PROGRAM-ID. LINE-NUMBER2.
    AUTHOR. TIM R P BROWN.
    **************************************************************
    * THIS PROGRAM RE-NUMBERS ALREADY NUMBERED COBOL SOURCE CODE *
    * FILE WHOSE SOURCE CODE LINE NUMBERING INTERRUPTED BY BEING *
    * EDITED. USER IS REQUIRED TO ENTER COBOL SOURCE CODE FILE *
    * NAME AND OUTPUT FILE NAME WILL BE COBOLOUT.CBL. *
    * SO USER SHOULD RENAME THE OUTPUT FILE NAME WHATEVER ELSE *
    * *
    *************************************************************

    ENVIRONMENT DIVISION.
    INPUT-OUTPUT SECTION.
    FILE-CONTROL.
    SELECT IN-FILE ASSIGN TO COBOL-INPUT-FILE-NAME
    ORGANIZATION IS LINE SEQUENTIAL.
    SELECT OUT-FILE ASSIGN TO 'COBOLOUT.CBL'
    ORGANIZATION IS LINE SEQUENTIAL.


    *********************************************************

    DATA DIVISION.
    FILE SECTION.

    FD IN-FILE.
    01 CODE-IN.
    03 OLD-NUM PIC 9(6).
    03 IN-CODE PIC X(122).

    FD OUT-FILE.
    01 CODE-OUT PIC X(132).

    WORKING-STORAGE SECTION.

    01 COBOL-INPUT-FILE-NAME PIC X(50).

    01 USER-INPUT-FILE-NAME PIC X(50).

    01 EOF-FLAG PIC X VALUE 'N'.
    88 END-OF-FILE VALUE 'Y'.

    01 W-NUMBER-CODE.
    03 W-NUM PIC 9(6) VALUE ZEROS.
    03 W-CODE PIC X(122) VALUE SPACES.

    01 LINE-NUMBER PIC 9(6) VALUE ZERO.

    ******************************************************

    PROCEDURE DIVISION.

    MAIN-PARA.
    DISPLAY 'PLEASE TYPE IN COBOL SOURCE CODE FILE NAME
    - 'TO BE RE-NUMBERED : '
    ACCEPT USER-INPUT-FILE-NAME
    MOVE USER-INPUT-FILE-NAME TO COBOL-INPUT-FILE-NAME
    OPEN INPUT IN-FILE
    OUTPUT OUT-FILE

    PERFORM UNTIL END-OF-FILE
    ADD 10 TO LINE-NUMBER
    READ IN-FILE RECORD
    AT END MOVE 'Y' TO EOF-FLAG
    NOT AT END
    MOVE IN-CODE TO W-CODE
    MOVE LINE-NUMBER TO W-NUM
    WRITE CODE-OUT FROM W-NUMBER-CODE
    END-READ
    END-PERFORM

    CLOSE IN-FILE, OUT-FILE

    EXIT PROGRAM

    STOP RUN.







    ****************After we number our COBOL Source Code using first COBOL Program,
    ****************There is no guarantee that we can pass Compiler at one pass, we should
    ***************Debug it. When we use Notepad to debug our COBOL Source Code File,
    **************Line Numbers which were previously generated by first COBOL Program will
    **************be destroyed and interrupted. So After Debugging, We need to Re-Number
    *************our COBOL Source Code File. Above Program also Re-Generate Line Number
    *************for Damaged COBOL Source Code Line Numbering based upon User Provided
    *************COBOL Source Code File Name using 'ACCEPT' clause.
    ************But we can accept 'Output COBOL Source Code File Name' from User. Here
    ************in this case, these above two Programs will generate COBOL Source Code
    ************File Name as 'COBOLOUT.CBL'. So User should change this 'COBOLOUT.CBL'
    ************to whatever he or she wants. But I can't implement that User can Provide
    ************his or her desired 'Output COBOL Source Code Program File Name', becuase
    ********** when User has 'REPORT.CBL' Source Code File Name, he or she wants use
    **********that Same File Name for his or her new Numbered (or Re-Numbered) COBOL
    ***********Source Code File. But I could use Same 'REPORT.CBL' for both Input COBOL
    *********Source Code File Name and , at the same time, for Output COBOL Source Code
    **********File Name.



    SELECT IN-FILE ASSIGN TO COBOL-INPUT-FILE-NAME(===>REPORT.CBL)
    ORGANIZATION IS LINE SEQUENTIAL.
    SELECT OUT-FILE ASSIGN TO COBOL-OUTPUT-FILE-NAME(===>REPORT.CBL)
    ORGANIZATION IS LINE SEQUENTIAL.


    ************Maybe Above Source Code will cause Run Time Error. I didn't try above
    *************Source Code. Or I can just create 'Temporary File' Named Temp.CBL
    ************and then Read the TEMP.CBL into original REPORT.CBL effectively deleting
    ************original Un-Numbered 'REPORT.CBL' and replacing it as New Numbered
    **********or Re-Numbered) version of 'REPORT.CBL' like below.









    SELECT IN-FILE ASSIGN TO COBOL-INPUT-FILE-NAME
    ORGANIZATION IS LINE SEQUENTIAL.

    SELECT WORKFILE ASSIGN TO 'TEMP.CBL'.




    PROCEDURE DIVISION.

    PROGRAM-BEGIN.


    ......

    OPEN INPUT IN-FILE
    OUTPUT WORKFILE




    * Procedures for Generating Line Number or for Re-Generating Line Number

    LINE-NUMBERING
    ....





    * Procedures for Writing New Numbered(Or Re-Numbered) COBOL Source Code File to WORKFILE

    Write.....









    * We have created WORKFILE, Now We prepare to read from WORKFILE, So we Close it and
    * Re-Open it as INPUT Mode. And we Close IN-FILE and Re-Open it as OUTPUT Mode.

    CLOSE IN-FILE, WORKFILE
    OPEN INPUT WORKFILE
    OUTPUT IN-FILE









    * Procedures for Writing Records From WORKFILE To IN-FILE


    WRITE.........





    CLOSE IN-FILE, WORKFILE






    STOP RUN.








    ************That's why Numbered(Or Re-Numbered) Output COBOL Source
    **********Code File Name is different than Original Un-Numbered (Numbered) COBOL
    ***********Source Code File. But If We need to handle Thousands and Millions Files
    **********We should use This 'WORKFILE' Method.







    ****************About Below COBOL Program, I don't know why there is third COBOL
    **************Program for Numbering(Or Re-Numbering) Line Number. Below COBOL
    *************Program may be intermediate COBOL File during my Debugging Process
    ************or I just saved it By Mistake. But I also upload This COBOL File also
    ************Just In Case.





    IDENTIFICATION DIVISION.
    PROGRAM-ID. LINE-NUMBER2.
    AUTHOR. TIM R P BROWN.
    **************************************************************
    * THIS PROGRAM RE-NUMBERS ALREADY NUMBERED COBOL SOURCE CODE *
    * FILE WHOSE SOURCE CODE LINE NUMBERING INTERRUPTED BY BEING *
    * EDITED. USER IS REQUIRED TO ENTER COBOL SOURCE CODE FILE *
    * NAME AND OUTPUT FILE NAME WILL BE COBOLOUT.CBL. *
    * SO USER SHOULD RENAME THE OUTPUT FILE NAME WHATEVER ELSE *
    * *
    *************************************************************

    ENVIRONMENT DIVISION.
    INPUT-OUTPUT SECTION.
    FILE-CONTROL.
    SELECT IN-FILE ASSIGN TO COBOL-INPUT-FILE-NAME
    ORGANIZATION IS LINE SEQUENTIAL.
    SELECT OUT-FILE ASSIGN TO 'COBOLOUT.CBL'
    ORGANIZATION IS LINE SEQUENTIAL.


    *********************************************************

    DATA DIVISION.
    FILE SECTION.

    FD IN-FILE.
    01 CODE-IN.
    03 OLD-NUM PIC 9(6).
    03 IN-CODE PIC X(122).

    FD OUT-FILE.
    01 CODE-OUT PIC X(132).

    WORKING-STORAGE SECTION.

    01 COBOL-INPUT-FILE-NAME PIC X(50).

    01 USER-INPUT-FILE-NAME PIC X(50).

    01 EOF-FLAG PIC X VALUE 'N'.
    88 END-OF-FILE VALUE 'Y'.

    01 W-NUMBER-CODE.
    03 W-NUM PIC 9(6) VALUE ZEROS.
    03 W-CODE PIC X(122) VALUE SPACES.

    01 LINE-NUMBER PIC 9(6) VALUE ZERO.

    ******************************************************

    PROCEDURE DIVISION.

    MAIN-PARA.
    DISPLAY 'PLEASE TYPE IN COBOL SOURCE CODE FILE NAME'
    - 'TO BE RE-NUMBERED : '
    ACCEPT USER-INPUT-FILE-NAME
    MOVE USER-INPUT-FILE-NAME TO COBOL-INPUT-FILE-NAME
    OPEN INPUT IN-FILE
    OUTPUT OUT-FILE

    PERFORM UNTIL END-OF-FILE
    ADD 10 TO LINE-NUMBER
    READ IN-FILE RECORD
    AT END MOVE 'Y' TO EOF-FLAG
    NOT AT END
    MOVE IN-CODE TO W-CODE
    MOVE LINE-NUMBER TO W-NUM
    WRITE CODE-OUT FROM W-NUMBER-CODE
    END-READ
    END-PERFORM

    CLOSE IN-FILE, OUT-FILE

    EXIT PROGRAM

    STOP RUN.
  • *******************I want to give you 3 different COBOL programs that accept File name
    *******************from the User at Run Time. Here is The First File.



    IDENTIFICATION DIVISION.
    PROGRAM-ID. LINE-NUMBER.
    AUTHOR. TIM R P BROWN.
    ********************************************************
    * THIS PROGRAM NUMBERS SOURCE CODE LINE WHEN USER
    * ENTERS COBOL SOURCE CODE FILE NAME TO BE NUMBERED.
    * THE OUTPUT FILE NAME WILL BE 'COBOLOUT.CBL.
    * SO USER SHOULD RENAME NUMBERED FILE NAME TO
    * WHATEVER ELSE.
    ********************************************************

    ENVIRONMENT DIVISION.
    INPUT-OUTPUT SECTION.
    FILE-CONTROL.
    SELECT IN-FILE ASSIGN TO COBOL-INPUT-FILE
    ORGANIZATION IS LINE SEQUENTIAL.
    SELECT OUT-FILE ASSIGN TO 'COBOLOUT.CBL'
    ORGANIZATION IS LINE SEQUENTIAL.


    *********************************************************

    DATA DIVISION.
    FILE SECTION.
    FD IN-FILE.
    01 LINE-CODE-IN.
    03 CHAR-1 PIC X.
    03 CODE-LINE PIC X(131).

    FD OUT-FILE.
    01 LINE-CODE-OUT PIC X(132).


    WORKING-STORAGE SECTION.

    01 COBOL-INPUT-FILE PIC X(50).
    01 USER-COBOL-INPUT-FILE PIC X(50).
    01 COBOL-OUTPUT-FILE PIC X(50).

    01 EOF-FLAG PIC X VALUE 'N'.
    88 END-OF-FILE VALUE 'Y'.

    01 NUMBER-CODE.
    03 L-NUM-CODE PIC 9(6) VALUE ZEROS.
    03 B-SPACE PIC X VALUE SPACE.
    03 L-CODE PIC X(125) VALUE SPACES.

    01 NUMBER-COMMENT.
    03 L-NUM-COM PIC 9(6) VALUE ZEROS.
    03 L-COMMENT PIC X(126) VALUE SPACE.

    01 LINE-NUMBER PIC 9(6) VALUE ZERO.

    ******************************************************

    PROCEDURE DIVISION.

    MAIN-PARA.
    DISPLAY 'PLEASE TYPE COBOL SOURCE CODE FILE TO BE'
    - ' NUMBERED : '
    ACCEPT USER-COBOL-INPUT-FILE
    MOVE USER-COBOL-INPUT-FILE TO COBOL-INPUT-FILE
    OPEN INPUT IN-FILE
    OUTPUT OUT-FILE

    PERFORM UNTIL END-OF-FILE
    ADD 10 TO LINE-NUMBER
    READ IN-FILE RECORD
    AT END MOVE 'Y' TO EOF-FLAG
    NOT AT END IF (CHAR-1 = '*')
    OR (CHAR-1 = '/')
    OR (CHAR-1 = '-') THEN

    MOVE LINE-CODE-IN TO L-COMMENT
    MOVE LINE-NUMBER TO L-NUM-COM
    WRITE LINE-CODE-OUT FROM NUMBER-COMMENT
    ELSE
    MOVE LINE-CODE-IN TO L-CODE
    MOVE LINE-NUMBER TO L-NUM-CODE
    WRITE LINE-CODE-OUT FROM NUMBER-CODE
    END-IF
    END-READ
    INITIALIZE NUMBER-CODE, NUMBER-COMMENT
    END-PERFORM

    CLOSE IN-FILE, OUT-FILE
    EXIT PROGRAM
    STOP RUN.



    *********************Above File numbers COBOL program source code, the time will come
    *********************when our Visual COBOL trial version will soon expire, then we should
    *********************use Notepad as our COBOL Editor which has no Source Code Numbering
    *********************Function. But we find Source Code Numbering is very Useful, So above
    *********************Program generate new COBOL Source Code File with Line Numbering
    *********************Based upon User Provided COBOL Source Code File Name using ACCEPT.








    ********************Below is Another COBOL Program to Number COBOL Source Code File
    ********************which doesn't has Numbering in it.






    IDENTIFICATION DIVISION.
    PROGRAM-ID. LINE-NUMBER2.
    AUTHOR. TIM R P BROWN.
    **************************************************************
    * THIS PROGRAM RE-NUMBERS ALREADY NUMBERED COBOL SOURCE CODE *
    * FILE WHOSE SOURCE CODE LINE NUMBERING INTERRUPTED BY BEING *
    * EDITED. USER IS REQUIRED TO ENTER COBOL SOURCE CODE FILE *
    * NAME AND OUTPUT FILE NAME WILL BE COBOLOUT.CBL. *
    * SO USER SHOULD RENAME THE OUTPUT FILE NAME WHATEVER ELSE *
    * *
    *************************************************************

    ENVIRONMENT DIVISION.
    INPUT-OUTPUT SECTION.
    FILE-CONTROL.
    SELECT IN-FILE ASSIGN TO COBOL-INPUT-FILE-NAME
    ORGANIZATION IS LINE SEQUENTIAL.
    SELECT OUT-FILE ASSIGN TO 'COBOLOUT.CBL'
    ORGANIZATION IS LINE SEQUENTIAL.


    *********************************************************

    DATA DIVISION.
    FILE SECTION.

    FD IN-FILE.
    01 CODE-IN.
    03 OLD-NUM PIC 9(6).
    03 IN-CODE PIC X(122).

    FD OUT-FILE.
    01 CODE-OUT PIC X(132).

    WORKING-STORAGE SECTION.

    01 COBOL-INPUT-FILE-NAME PIC X(50).

    01 USER-INPUT-FILE-NAME PIC X(50).

    01 EOF-FLAG PIC X VALUE 'N'.
    88 END-OF-FILE VALUE 'Y'.

    01 W-NUMBER-CODE.
    03 W-NUM PIC 9(6) VALUE ZEROS.
    03 W-CODE PIC X(122) VALUE SPACES.

    01 LINE-NUMBER PIC 9(6) VALUE ZERO.

    ******************************************************

    PROCEDURE DIVISION.

    MAIN-PARA.
    DISPLAY 'PLEASE TYPE IN COBOL SOURCE CODE FILE NAME
    - 'TO BE RE-NUMBERED : '
    ACCEPT USER-INPUT-FILE-NAME
    MOVE USER-INPUT-FILE-NAME TO COBOL-INPUT-FILE-NAME
    OPEN INPUT IN-FILE
    OUTPUT OUT-FILE

    PERFORM UNTIL END-OF-FILE
    ADD 10 TO LINE-NUMBER
    READ IN-FILE RECORD
    AT END MOVE 'Y' TO EOF-FLAG
    NOT AT END
    MOVE IN-CODE TO W-CODE
    MOVE LINE-NUMBER TO W-NUM
    WRITE CODE-OUT FROM W-NUMBER-CODE
    END-READ
    END-PERFORM

    CLOSE IN-FILE, OUT-FILE

    EXIT PROGRAM

    STOP RUN.







    ****************After we number our COBOL Source Code using first COBOL Program,
    ****************There is no guarantee that we can pass Compiler at one pass, we should
    ***************Debug it. When we use Notepad to debug our COBOL Source Code File,
    **************Line Numbers which were previously generated by first COBOL Program will
    **************be destroyed and interrupted. So After Debugging, We need to Re-Number
    *************our COBOL Source Code File. Above Program also Re-Generate Line Number
    *************for Damaged COBOL Source Code Line Numbering based upon User Provided
    *************COBOL Source Code File Name using 'ACCEPT' clause.
    ************But we can accept 'Output COBOL Source Code File Name' from User. Here
    ************in this case, these above two Programs will generate COBOL Source Code
    ************File Name as 'COBOLOUT.CBL'. So User should change this 'COBOLOUT.CBL'
    ************to whatever he or she wants. But I can't implement that User can Provide
    ************his or her desired 'Output COBOL Source Code Program File Name', becuase
    ********** when User has 'REPORT.CBL' Source Code File Name, he or she wants use
    **********that Same File Name for his or her new Numbered (or Re-Numbered) COBOL
    ***********Source Code File. But I could use Same 'REPORT.CBL' for both Input COBOL
    *********Source Code File Name and , at the same time, for Output COBOL Source Code
    **********File Name.



    SELECT IN-FILE ASSIGN TO COBOL-INPUT-FILE-NAME(===>REPORT.CBL)
    ORGANIZATION IS LINE SEQUENTIAL.
    SELECT OUT-FILE ASSIGN TO COBOL-OUTPUT-FILE-NAME(===>REPORT.CBL)
    ORGANIZATION IS LINE SEQUENTIAL.


    ************Maybe Above Source Code will cause Run Time Error. I didn't try above
    *************Source Code. Or I can just create 'Temporary File' Named Temp.CBL
    ************and then Read the TEMP.CBL into original REPORT.CBL effectively deleting
    ************original Un-Numbered 'REPORT.CBL' and replacing it as New Numbered
    **********or Re-Numbered) version of 'REPORT.CBL' like below.









    SELECT IN-FILE ASSIGN TO COBOL-INPUT-FILE-NAME
    ORGANIZATION IS LINE SEQUENTIAL.

    SELECT WORKFILE ASSIGN TO 'TEMP.CBL'.




    PROCEDURE DIVISION.

    PROGRAM-BEGIN.


    ......

    OPEN INPUT IN-FILE
    OUTPUT WORKFILE




    * Procedures for Generating Line Number or for Re-Generating Line Number

    LINE-NUMBERING
    ....





    * Procedures for Writing New Numbered(Or Re-Numbered) COBOL Source Code File to WORKFILE

    Write.....









    * We have created WORKFILE, Now We prepare to read from WORKFILE, So we Close it and
    * Re-Open it as INPUT Mode. And we Close IN-FILE and Re-Open it as OUTPUT Mode.

    CLOSE IN-FILE, WORKFILE
    OPEN INPUT WORKFILE
    OUTPUT IN-FILE









    * Procedures for Writing Records From WORKFILE To IN-FILE


    WRITE.........





    CLOSE IN-FILE, WORKFILE






    STOP RUN.








    ************That's why Numbered(Or Re-Numbered) Output COBOL Source
    **********Code File Name is different than Original Un-Numbered (Numbered) COBOL
    ***********Source Code File. But If We need to handle Thousands and Millions Files
    **********We should use This 'WORKFILE' Method.







    ****************About Below COBOL Program, I don't know why there is third COBOL
    **************Program for Numbering(Or Re-Numbering) Line Number. Below COBOL
    *************Program may be intermediate COBOL File during my Debugging Process
    ************or I just saved it By Mistake. But I also upload This COBOL File also
    ************Just In Case.





    IDENTIFICATION DIVISION.
    PROGRAM-ID. LINE-NUMBER2.
    AUTHOR. TIM R P BROWN.
    **************************************************************
    * THIS PROGRAM RE-NUMBERS ALREADY NUMBERED COBOL SOURCE CODE *
    * FILE WHOSE SOURCE CODE LINE NUMBERING INTERRUPTED BY BEING *
    * EDITED. USER IS REQUIRED TO ENTER COBOL SOURCE CODE FILE *
    * NAME AND OUTPUT FILE NAME WILL BE COBOLOUT.CBL. *
    * SO USER SHOULD RENAME THE OUTPUT FILE NAME WHATEVER ELSE *
    * *
    *************************************************************

    ENVIRONMENT DIVISION.
    INPUT-OUTPUT SECTION.
    FILE-CONTROL.
    SELECT IN-FILE ASSIGN TO COBOL-INPUT-FILE-NAME
    ORGANIZATION IS LINE SEQUENTIAL.
    SELECT OUT-FILE ASSIGN TO 'COBOLOUT.CBL'
    ORGANIZATION IS LINE SEQUENTIAL.


    *********************************************************

    DATA DIVISION.
    FILE SECTION.

    FD IN-FILE.
    01 CODE-IN.
    03 OLD-NUM PIC 9(6).
    03 IN-CODE PIC X(122).

    FD OUT-FILE.
    01 CODE-OUT PIC X(132).

    WORKING-STORAGE SECTION.

    01 COBOL-INPUT-FILE-NAME PIC X(50).

    01 USER-INPUT-FILE-NAME PIC X(50).

    01 EOF-FLAG PIC X VALUE 'N'.
    88 END-OF-FILE VALUE 'Y'.

    01 W-NUMBER-CODE.
    03 W-NUM PIC 9(6) VALUE ZEROS.
    03 W-CODE PIC X(122) VALUE SPACES.

    01 LINE-NUMBER PIC 9(6) VALUE ZERO.

    ******************************************************

    PROCEDURE DIVISION.

    MAIN-PARA.
    DISPLAY 'PLEASE TYPE IN COBOL SOURCE CODE FILE NAME'
    - 'TO BE RE-NUMBERED : '
    ACCEPT USER-INPUT-FILE-NAME
    MOVE USER-INPUT-FILE-NAME TO COBOL-INPUT-FILE-NAME
    OPEN INPUT IN-FILE
    OUTPUT OUT-FILE

    PERFORM UNTIL END-OF-FILE
    ADD 10 TO LINE-NUMBER
    READ IN-FILE RECORD
    AT END MOVE 'Y' TO EOF-FLAG
    NOT AT END
    MOVE IN-CODE TO W-CODE
    MOVE LINE-NUMBER TO W-NUM
    WRITE CODE-OUT FROM W-NUMBER-CODE
    END-READ
    END-PERFORM

    CLOSE IN-FILE, OUT-FILE

    EXIT PROGRAM

    STOP RUN.
  • ***************Input Sample COBOL File for Above Program is below. It has File Name as 'READ.CBL'
    ***************And User provided That COBOL Source Code File Name(READ.CBL) using Keyboard
    **************Input and the Program accepted that File Name from User during Run Time using
    *************'ACCEPT' clause and MOVEed its Value into COBOL-INPUT-FILE-NAME using 'MOVE' clause.
    ************But here we still should indent Source Code into Area B using 'Tab' Key on keyboard as
    ************shown below.





    PROGRAM-ID. READ.
    ENVIRONMENT DIVISION.
    configuration section.
    INPUT-OUTPUT SECTION.
    FILE-CONTROL.
    SELECT IN-FILE ASSIGN TO 'INPUT.DAT'
    ORGANIZATION IS LINE SEQUENTIAL.


    data division.
    FILE SECTION.
    FD IN-FILE.
    01 IN-RECORD PIC X.
    working-storage section.
    01 READ-RECORD PIC X.

    procedure division.
    OPEN OUTPUT IN-FILE.
    MOVE '*' TO IN-RECORD.
    DISPLAY IN-RECORD.
    WRITE IN-RECORD.
    CLOSE IN-FILE.

    end program READ.




    *****************Numbered Output COBOL Source Code File is below. It has File Name as 'COBOLOUT.CBL'.




    000010
    000020 PROGRAM-ID. READ.
    000030 ENVIRONMENT DIVISION.
    000040 configuration section.
    000050 INPUT-OUTPUT SECTION.
    000060 FILE-CONTROL.
    000070 SELECT IN-FILE ASSIGN TO 'INPUT.DAT'
    000080 ORGANIZATION IS LINE SEQUENTIAL.
    000090
    000100
    000110 data division.
    000120 FILE SECTION.
    000130 FD IN-FILE.
    000140 01 IN-RECORD PIC X.
    000150 working-storage section.
    000160 01 READ-RECORD PIC X.
    000170
    000180 procedure division.
    000190 OPEN OUTPUT IN-FILE.
    000200 MOVE '*' TO IN-RECORD.
    000210 DISPLAY IN-RECORD.
    000220 WRITE IN-RECORD.
    000230 CLOSE IN-FILE.
    000240
    000250 end program READ.








    ********************And Below is Sample Input COBOL Source Code File which should be
    ******************Re-Numbered after Debugging, Editing and Commenting. As we can see,
    ****************Line Number was disrupted.







    000010
    000020 PROGRAM-ID. READ.
    000030 ENVIRONMENT DIVISION.
    000040 configuration section.
    000050 INPUT-OUTPUT SECTION.
    000060 FILE-CONTROL.
    000070 SELECT IN-FILE ASSIGN TO 'INPUT.DAT'
    000080 ORGANIZATION IS LINE SEQUENTIAL.
    000090
    000100
    000110 data division.
    000120 FILE SECTION.
    *******************************
    ********************
    ******************
    *****************
    ******************
    **********************
    000130 FD IN-FILE.
    000140 01 IN-RECORD PIC X.
    000150 working-storage section.
    000160 01 READ-RECORD PIC X.
    000170
    000180 procedure division.
    000190 OPEN OUTPUT IN-FILE.
    000200 MOVE '*' TO IN-RECORD.
    000210 DISPLAY IN-RECORD.
    000220 WRITE IN-RECORD.
    000230 CLOSE IN-FILE.
    000240
    000250 end program READ.








    ***********And Below is Output COBOL Source Code File which was Re-Numbered.






    000010
    000020 PROGRAM-ID. READ.
    000030 ENVIRONMENT DIVISION.
    000040 configuration section.
    000050 INPUT-OUTPUT SECTION.
    000060 FILE-CONTROL.
    000070 SELECT IN-FILE ASSIGN TO 'INPUT.DAT'
    000080 ORGANIZATION IS LINE SEQUENTIAL.
    000090
    000100
    000110 data division.
    000120 FILE SECTION.
    000130*******************************
    000140********************
    000150******************
    000160*****************
    000170******************
    000180**********************
    000190 FD IN-FILE.
    000200 01 IN-RECORD PIC X.
    000210 working-storage section.
    000220 01 READ-RECORD PIC X.
    000230
    000240 procedure division.
    000250 OPEN OUTPUT IN-FILE.
    000260 MOVE '*' TO IN-RECORD.
    000270 DISPLAY IN-RECORD.
    000280 WRITE IN-RECORD.
    000290 CLOSE IN-FILE.
    000300
    000310 end program READ.
  • ***********Sorry above Reply Needs some Editing, So I upload it again.






    *********Input Sample COBOL File for Above Program is below. It has File Name as 'READ.CBL'
    ********And User provided That COBOL Source Code File Name(READ.CBL) using Keyboard
    ********Input and the Program accepted that File Name from User during Run Time using
    *******'ACCEPT' clause and MOVEed its Value into COBOL-INPUT-FILE-NAME using 'MOVE' clause.
    *******But here we still should indent Source Code into Area B using 'Tab' Key on keyboard as
    *******shown below.




    123456789===>Column Number
    PROGRAM-ID. READ.
    ENVIRONMENT DIVISION.
    configuration section.
    INPUT-OUTPUT SECTION.
    FILE-CONTROL.
    1234567890
    SELECT IN-FILE ASSIGN TO 'INPUT.DAT'===> This statement starts at 5 column in Notepad as it should be Area B
    ORGANIZATION IS LINE SEQUENTIAL.


    data division.
    FILE SECTION.
    FD IN-FILE.
    01 IN-RECORD PIC X.
    working-storage section.
    01 READ-RECORD PIC X.

    procedure division.
    OPEN OUTPUT IN-FILE.
    MOVE '*' TO IN-RECORD.
    DISPLAY IN-RECORD.
    WRITE IN-RECORD.
    CLOSE IN-FILE.

    end program READ.




    *****************Numbered Output COBOL Source Code File is below. It has File Name as 'COBOLOUT.CBL'.




    000010
    000020 PROGRAM-ID. READ.
    000030 ENVIRONMENT DIVISION.
    000040 configuration section.
    000050 INPUT-OUTPUT SECTION.
    000060 FILE-CONTROL.
    000070 SELECT IN-FILE ASSIGN TO 'INPUT.DAT'
    000080 ORGANIZATION IS LINE SEQUENTIAL.
    000090
    000100
    000110 data division.
    000120 FILE SECTION.
    000130 FD IN-FILE.
    000140 01 IN-RECORD PIC X.
    000150 working-storage section.
    000160 01 READ-RECORD PIC X.
    000170
    000180 procedure division.
    000190 OPEN OUTPUT IN-FILE.
    000200 MOVE '*' TO IN-RECORD.
    000210 DISPLAY IN-RECORD.
    000220 WRITE IN-RECORD.
    000230 CLOSE IN-FILE.
    000240
    000250 end program READ.








    ********************And Below is Sample Input COBOL Source Code File which should be
    ******************Re-Numbered after Debugging, Editing and Commenting. As we can see,
    ****************Line Number was disrupted.







    000010
    000020 PROGRAM-ID. READ.
    000030 ENVIRONMENT DIVISION.
    000040 configuration section.
    000050 INPUT-OUTPUT SECTION.
    000060 FILE-CONTROL.
    000070 SELECT IN-FILE ASSIGN TO 'INPUT.DAT'
    000080 ORGANIZATION IS LINE SEQUENTIAL.
    000090
    000100
    000110 data division.
    000120 FILE SECTION.
    *******************************(=====> These comments are added at Column position 6 in Source Code)
    ********************
    ******************
    *****************
    ******************
    **********************
    000130 FD IN-FILE.
    000140 01 IN-RECORD PIC X.
    000150 working-storage section.
    000160 01 READ-RECORD PIC X.
    000170
    000180 procedure division.
    000190 OPEN OUTPUT IN-FILE.
    000200 MOVE '*' TO IN-RECORD.
    000210 DISPLAY IN-RECORD.
    000220 WRITE IN-RECORD.
    000230 CLOSE IN-FILE.
    000240
    000250 end program READ.








    ***********And Below is Output COBOL Source Code File which was Re-Numbered.






    000010
    000020 PROGRAM-ID. READ.
    000030 ENVIRONMENT DIVISION.
    000040 configuration section.
    000050 INPUT-OUTPUT SECTION.
    000060 FILE-CONTROL.
    000070 SELECT IN-FILE ASSIGN TO 'INPUT.DAT'
    000080 ORGANIZATION IS LINE SEQUENTIAL.
    000090
    000100
    000110 data division.
    000120 FILE SECTION.
    000130*******************************
    000140********************
    000150******************
    000160*****************
    000170******************
    000180**********************
    000190 FD IN-FILE.
    000200 01 IN-RECORD PIC X.
    000210 working-storage section.
    000220 01 READ-RECORD PIC X.
    000230
    000240 procedure division.
    000250 OPEN OUTPUT IN-FILE.
    000260 MOVE '*' TO IN-RECORD.
    000270 DISPLAY IN-RECORD.
    000280 WRITE IN-RECORD.
    000290 CLOSE IN-FILE.
    000300
    000310 end program READ.