READ PARAMETERS from command line

hey,
i have to write a program that gets 1 to 5 parameters.
Is there a possibility to get the count of the parameters before reading they with accept?

I am using gnu-cobol.

thanks
Dirk

Hello

I don’t know “gnu-cobol” so I can’t help you technically, but your solution is not necessarily technical, for example:

  1. you could reserve the first character of the first parameter to contain this number of parameters to apply

  2. if you can, it’s preferable to externalise the parameters (so they could be modified without modifying any code) in a file of a table and the first line could contain the number or parameters to apply

anyway, it’s better to have the number of parameters to apply somewhere to check if the good number of parameters has been provided correctly

Typically, there multiple ways to get this information into your program.

Control Cards are sometimes read into programs for runtime parms.
You can use the “ACCEPT” cobol keyword to take parms in directly from the operator (not best practice anymore).
You use Linkage and use of PARMS on your JCL used to execute the program. This is very standard and I show a piece of code from: Simotime


   LINKAGE SECTION.
   01  PARM-BUFFER.
       05  PARM-LENGTH         pic S9(4)   comp.
       05  PARM-DATA           pic X(256).

  *****************************************************************
   PROCEDURE DIVISION using PARM-BUFFER.
       if  FIRST-TIME not = 'N'
           perform Z-POST-COPYRIGHT
           move 'N' to FIRST-TIME
       end-if

       add PARM-LENGTH to ZERO giving JCL-PARM-LENGTH
       move MESSAGE-TEXT-01 to MESSAGE-TEXT
       perform Z-POST-MESSAGE

       if  PARM-LENGTH > 0
           move PARM-DATA(1:PARM-LENGTH) to MESSAGE-TEXT
           perform Z-POST-MESSAGE
       end-if

       perform Z-THANK-YOU.

       GOBACK.

A few suggestions.

  1. Change the file type from ACCEPT to READ. That way, you can see the AT END of file which will prevent further reading.
  2. Use the first ACCEPT to indicate the number of lines following it.
  3. Use the PARM to indicate the number of lines to be read.
  4. Pass all the parameters using the PARM.
    I see the use of the ACCEPT statement as poor programming. Accepting more statements than in the file can cause an abend. Use the READ instead.