Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JCL on a PC

Status
Not open for further replies.

WelshGasman

Programmer
Oct 18, 2024
5
Hi all, newbie here to the forum.

Retired now and was an old Analyst Programmer on Bull DPS7, using COBOL, JCL etc.

Decided to just play around with COBOL for fun and downloaded the GNU Cobol IDE.

I was wondering however, just a thought, how does PC Cobol handle different files?
In the DPS7 environment, we used JCL, so the external filename could always be different. Internal always the same obviously.

So how would you handle that situation, should you need the same functionality on a PC please?

TIA
 
Hi all, newbie here to the forum.

Retired now and was an old Analyst Programmer on Bull DPS7, using COBOL, JCL etc.

Decided to just play around with COBOL for fun and downloaded the GNU Cobol IDE.

I was wondering however, just a thought, how does PC Cobol handle different files?
In the DPS7 environment, we used JCL, so the external filename could always be different. Internal always the same obviously.

So how would you handle that situation, should you need the same functionality on a PC please?

TIA
Here is an example or the file assignment that I've used for sequential files.
*-----------------------
INPUT-OUTPUT SECTION.
*-----------------------
FILE-CONTROL.
select AAAA-IN ASSIGN TO "C:\CURTIS\AAAA QUERY FILE.csv"
ORGANIZATION IS LINE SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS WS-AAAA-STATUS.
select NCC-IN ASSIGN TO 'C:\CURTIS\NCC QUERY FILE.csv'
ORGANIZATION IS LINE SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS WS-NCC-STATUS.
 
to make it more flexible you can replace
Code:
select AAAA-IN ASSIGN TO "C:\CURTIS\AAAA QUERY FILE.csv"
with a variable (e.g. FILE-NAME)
Code:
select AAAA-IN ASSIGN TO FILE-NAME
and populate that variable from command line argument
then you will call your program as
Code:
your_program "C:\CURTIS\AAAA QUERY FILE.csv"

if you want i can post an example
 
Last edited:
Ok, that would do it. :)
Now in the example above, there were two files, so how does the program know which is which?
How does FILE-NAME and FILE-NAME1 get defined please.

I was thinking of just copying whatever file I needed to process to the hardcoded named file. :)
 
This is a remake of the TXT2CSV example I posted previously on this forum
Unfortunately poorly performed migration broke that example.

The program uses two text files: it reads a *.TXT file and writes *.CSV file.
I modified it so, that it now reads the file names from command line arguments:
Code:
      * Sample COBOL program which reads command line arguments
      * compile:
      *    $ cobc -x txt2csv_linux_cmd_line.cbl
      * run:
      *    $ ./txt2csv_linux_cmd_line file_input.txt file_output.csv

       IDENTIFICATION DIVISION.
       PROGRAM-ID.  TXT2CSV.
         AUTHOR.  MIKROM.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       SELECT MY-INPUT-FILE ASSIGN TO FILE-NAME-INPUT
               ORGANIZATION IS LINE SEQUENTIAL.
       SELECT MY-OUTPUT-FILE ASSIGN TO FILE-NAME-OUTPUT
               ORGANIZATION IS LINE SEQUENTIAL.

       DATA DIVISION.
       FILE SECTION.
       FD MY-INPUT-FILE.
       01 MY-INPUT-LINE    PIC X(256).
       FD MY-OUTPUT-FILE.
       01 MY-OUTPUT-LINE   PIC X(256).
       WORKING-STORAGE SECTION.
       01 FILE-NAME-INPUT  PIC X(100).
       01 FILE-NAME-OUTPUT PIC X(100).
       01 END-OF-FILE-FLAG PIC X VALUE SPACE.
          88 END-OF-INPUT-FILE VALUE 'T'.
          88 NOT-END-OF-INPUT-FILE VALUE 'F'.
       01 WS-FIELDS.
          05 WS-LINE     PIC X(256).
          05 LINE-LENGTH PIC 9(3).
          05 NR-SPACES   PIC 9(3).
          05 I           PIC 9(3).
          05 J           PIC 9(3).
          05 SEPARATOR   PIC X VALUE ";".

       PROCEDURE DIVISION CHAINING FILE-NAME-INPUT FILE-NAME-OUTPUT.
       MAIN-PARA.
         OPEN INPUT MY-INPUT-FILE
         OPEN OUTPUT MY-OUTPUT-FILE

         SET NOT-END-OF-INPUT-FILE TO TRUE

         PERFORM UNTIL END-OF-INPUT-FILE
           READ MY-INPUT-FILE
             NOT AT END
               PERFORM PROCESS-LINE
               WRITE MY-OUTPUT-LINE
             AT END
                SET END-OF-INPUT-FILE TO TRUE
           END-READ
         END-PERFORM
         CLOSE MY-INPUT-FILE
         CLOSE MY-OUTPUT-FILE
         STOP RUN.

       PROCESS-LINE.
         INITIALIZE MY-OUTPUT-LINE
      *  remove leading spaces from INPUT-LINE
         MOVE FUNCTION TRIM(MY-INPUT-LINE) TO WS-LINE
      *  compute length of trimmed line (without trailing spaces)
         COMPUTE LINE-LENGTH = FUNCTION LENGTH(FUNCTION TRIM(WS-LINE))
         MOVE 1 TO J
         MOVE 0 TO NR-SPACES
         PERFORM VARYING I FROM 1 BY 1 UNTIL I > LINE-LENGTH
           IF WS-LINE(I:1) = ' '
             ADD 1 TO NR-SPACES
             IF NR-SPACES = 1
               MOVE SEPARATOR TO MY-OUTPUT-LINE(J:1)
               ADD 1 TO J
             ELSE
               CONTINUE
             END-IF
           ELSE
             MOVE WS-LINE(I:1) TO MY-OUTPUT-LINE(J:1)
             ADD 1 TO J
      *      reset spaces counter
             MOVE 0 TO NR-SPACES
           END-IF
         END-PERFORM.

i compile the program in the OpenCobolIDE
or on command line like this:
Code:
$ cobc -x txt2csv_linux_cmd_line.cbl
Now when I have this text file /home/mikrom/tmp/file_input.txt
i run the program with this command
Code:
$ ./txt2csv_linux_cmd_line /home/mikrom/tmp/file_input.txt /home/mikrom/tmp/file_output.csv
it reads input file
home/mikrom/tmp/file_input.txt
and creates the output file:
/home/mikrom/tmp/file_output.csv

I tried it on Linux but if you are on Windows it should work for you too.

I used as input file
file_input.txt
Code:
foo bar baz
spam eggs foobar
and it created output file
file_output.csv
Code:
foo;bar;baz
spam;eggs;foobar
 
Last edited:
Thank you for that.
So effectively it is the order of the input filenames as defined in File-Control and the order they are passed into the program. Purely positional?
 
The command line arguments are here positional, i.e. if i have defined
Code:
PROCEDURE DIVISION CHAINING FILE-NAME-INPUT FILE-NAME-OUTPUT.
then i need call the program as
Code:
./txt2csv_linux_cmd_line /home/mikrom/tmp/file_input.txt /home/mikrom/tmp/file_output.csv
when i would change
Code:
PROCEDURE DIVISION CHAINING FILE-NAME-OUTPUT FILE-NAME-INPUT.
then i would need to call the program as
Code:
./txt2csv_linux_cmd_line /home/mikrom/tmp/file_output.csv /home/mikrom/tmp/file_input.txt
 
Have you tried the example on windows? Does it work for you?
 
No not yet, but I understand how it works, thanks to you.

Thanks again.
 
Last edited:
If you don't want to have positional parameters, you could use options (short, long or both).
But i don't know, how to do it in GNU COBOL .
So i would wrap my executable in a shell script, which would make easily possible to use options, for example
-i, --input
-o, --output
Then i could be able to call the cobol program via this shell script like this:
./txt2csv.sh -i file_input.txt -o file_output.csv
or
./txt2csv.sh --input file_input.txt --output file_output.csv
or
./txt2csv.sh -o file_output.csv -i file_input.txt
or
./txt2csv.sh --output file_output.csv --input file_input.txt

On Windows similiar would be possible maybe via a PowerShell script.
 
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top