HiHui
HiHui

Reputation: 55

COBOL ACCEPT FROM ENVIRONMENT return "Invalid parameter error"

I am trying to use "ACCEPT FROM ENVIRONMENT" statement to retrieve a value from environment variable, but it does not work. (I am using Micro Focus COBOL on Linux)

My COBOL program is very simple:

   IDENTIFICATION DIVISION.
   PROGRAM-ID.     HELLO.

   ENVIRONMENT DIVISION.
   CONFIGURATION SECTION.
   SOURCE-COMPUTER. RM-COBOL.
   OBJECT-COMPUTER. RM-COBOL.

   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01  ENV-VALUE    PIC X(1024).

   PROCEDURE DIVISION.

   ACCEPT ENV-VALUE FROM ENVIRONMENT "ENVVAR".

   DISPLAY ENV-VALUE.

To execute the program:

]$ export ENVVAR="test value"
]$ cobrun HELLO

Execution error :

file '/path_to_here/HELLO.gnt'
error code: 181, pc=0, call=1, seg=0
181     Invalid parameter error 

And if i replace the "ACCEPT FROM ENVIRONMENT" with following format:

   IDENTIFICATION DIVISION.
   PROGRAM-ID.     HELLO.

   ENVIRONMENT DIVISION.
   CONFIGURATION SECTION.
   SOURCE-COMPUTER. RM-COBOL.
   OBJECT-COMPUTER. RM-COBOL.

   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01  ENV-NAME    PIC X(1024).
   01  ENV-VALUE   PIC X(1024).

   PROCEDURE DIVISION.

   DISPLAY "ENVVAR" UPON ENVIRONMENT-NAME.
   ACCEPT ENV-VALUE FROM ENVIRONMENT-VALUE.

   DISPLAY ENV-VALUE.

It works fine, i can get the environment variable value in ENV-VALUE.

Upvotes: 4

Views: 2318

Answers (1)

Bill Woodger
Bill Woodger

Reputation: 13076

Shot-in-the-dark time.

Micro Focus have more than one COBOL product. A couple of them in particular are from companies that they took over, RM-COBOL and AcuCOBOL.

On your SOURCE-COMPUTER paragraph you are specifying RM-COBOL. The format of the ACCEPT statement that you are attempting to use is documented as Format 5 of ACCEPT for AcuCOBOL.

The error message you are getting is for a "file". I think you have RM-COBOL and in attempting to use AcuCOBOL syntax the word ENVIRONMENT is being treated as a file and hence the message and failure.

You need to use the Manual for RM-COBOL, an up-to-date one. If you don't have it already, a copy can be obtained from Micro Focus (they will want to know your license number).

ACCEPT and DISPLAY are the COBOL verbs which are the most likely to have differences from one compiler implementer to another, as they were "bent" from the language Standard to provide screen-based user interaction. You must use the syntax for your compiler, the many variants of ACCEPT and DISPLAY are not necessarily portable from one compiler to another.

For confirmation of the exact problem, you can contact Micro Focus support through their website. You can also do that if this answer is of no use :-)

Upvotes: 3

Related Questions