Skip to main content

Problem:

Extract of Net Express documentation:

                  search on keyword rargument-number

Accessing Data on the Command Line

There are two main ways in which a program can access data on the command line:

ACCEPT data-name FROM COMMAND-LINE. This causes the complete contents of the command line to be moved to data-name.

Alternately, you can access individual arguments on the command line, using:

DISPLAY ... UPON ARGUMENT-NUMBER

ACCEPT ... FROM ARGUMENT-NUMBER

Resolution:

Code attached to KB:

       working-storage section.

       01 Args-Work-Area.

        03 args-num                pic x(4) comp-x.

        03 args-val                pic x(40).

       procedure division.

      *    Find out how many arguments have been passed to the program

           accept args-num from argument-number

           if args-num = 0

                display "*--> No parameters passed to this program"

                exit program

                stop run

           else display "*--> Number of params received: " args-num

           end-if

      *    Iterate through the arguments

           perform args-num times

               accept args-val from argument-value

               display "*--> Parameter " args-num "  Value: " args-val

           end-perform

           exit program.

           goback.      

           stop run.

Attachments:

comlin3.cbl

Old KB# 3989