Sometimes it is necessary to dynamically retrieve the value of an environment variable at run time. This topic describes one way to modify the code in one of the COBOL sample projects to enable environment variable access.
This topic involves COBOL Sample 1, which is available through the workbench examples interface. The sample includes two COBOL files, StartApp.cbl and PrintApp.cbl. Complete the following instructions to modify a project containing this sample so that StartApp.cbl reads an environment variable and displays its value.
01 P pointer. 01 ENVVAR pic x(5) value Z"PATH". 01 var-ptr pointer. 01 var-len pic 9(4) binary.
01 var pic x(1000).
Set P to address of ENVVAR. >>CALLINT OPTLINK call "getenv" using by value P returning var-ptr. >>CALLINT if var-ptr = null then Display "PATH is null" else Set address of var to var-ptr Move 0 to var-len Inspect var tallying var-len for characters before initial x"00" Display "PATH = " var (1:var-len) end-if.
,NODYNAM,PGMNAME(LONGMIXED)Ensure that you maintain the leading comma to separate these options from the current set of options.
cpprmi36.dllThis file is located in the bin directory of the Rational® Developer for System z® installation path, for example, c:\Program Files\IBM\SDP\bin.
Error LNK2029: "?GETENV": unresolved externalThis normally occurs when the .dll file specified above cannot be found. The required .dll file cpprmi36.dll is normally found in the bin folder of the Rational Developer for System z installation path. For example, C:\Program Files\IBM\SDP\bin. You may specify the complete path to the file in the Link Options field. In this case, it would be C:\Program Files\IBM\SDP\bin\cpprmi36.dll.
If other errors occur, ensure that the Compile Options property was correctly updated, as described above.