COBOL COMMITTED BY ENVIRONMENT return "Invalid parameter error"

I am trying to use the "RECEIVE FROM ENVIRONMENT" statement to retrieve a value from an environment variable, but it doesn't 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 run the program:

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

      

Runtime error:

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

      

And if I replace "ACCEPT FROM THE ENVIRONMENT" with the 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 great, I can get the value of the environment variable in ENV-VALUE.

+3


source to share


1 answer


Time for a shot in the dark.

Micro Focus has more than one COBOL product. Some of them, in particular, are owned by the companies they took over, RM-COBOL and AcuCOBOL.

In the section, SOURCE-COMPUTER

you specify RM-COBOL. The ACCEPT statement format you are trying to use is documented as ACCEPT format 5 for AcuCOBOL.

The error message you receive is for "file". I think you have RM-COBOL and when trying to use the AcuCOBOL syntax the word is ENVIRONMENT

treated as a file and hence the message and crash.



You need to use the RM-COBOL Guide, which is current. If you don't already have one, a copy can be obtained from Micro Focus (they will want to know your license number).

ACCEPT

and DISPLAY

are COBOL verbs that are likely to differ from one compiler executor to another because they have been "bent" from the Standard language to provide on-screen user interaction. You must use the syntax for your compiler, many of the ACCEPT and DISPLAY options are not necessarily portable from one compiler to another.

To confirm the exact issue, you can contact Micro Focus support through their website. You can also do this if this answer is not helpful :-)

+2


source







All Articles