Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

CALL "SYSTEM" passed parameter has extra value

CALL "SYSTEM" passed parameter has extra value

Problem:

When using CALL "SYSTEM" USING command-line to execute a COBOL program and pass parameter to the program, the received parameter in ACCEPT passed-parms FROM COMMAND-LINE in the called program may contain extra values that are appended to the end of the string being passed. In the example below, you may get 'A B C ABC' in PASSED-PARMS, instead of 'A B C'.

Calling program:

       WORKING-STORAGE SECTION.

       01  WS-COMMAND-LINE.

           05  WS-CALLED-PROG                PIC X(08) VALUE 'PROGNAME' .

           05  WS-SPACE-DELIMITER         PIC X(01) VALUE SPACE.

           05  WS-PASSED-PARMS             PIC X(20) VALUE 'A B C'.

       01  WS-JUNK                                    PIC X(5) VALUE 'ABC'.

       PROCEDURE DIVISION.

                 CALL "SYSTEM" USING WS-COMMAND-LINE.

Called program:

       WORKING-STORAGE SECTION.

       01  PASSED-PARMS         PIC X(30).

       PROCEDURE DIVISION.

                 ACCEPT PASSED-PARMS FROM COMMAND-LINE.

Resolution: 

CALL "SYSTEM" isn't the proper way to call a COBOL program. However, if you want to use it, you need to be aware that when passing strings to subroutines written in, or for use with, other languages, e.g. Micro Focus' own functions SYSTEM, etc.,strings are typically passed by reference. The string itself is not copied to the subroutine's equivalent of a COBOL linkage section; only the memory address of the first byte is passed to the equivalent of a COBOL "USAGE POINTER" variable. The number of bytes in the string is unknown. Thus the end of the string needs to be marked by a defined "terminator". For example, the operating system may use a null (X'00' or LOW-VALUES) byte to mark the string end. So one solution to the problem is to define the field WS-PASSED-PARMS as PIC X(20) VALUE z'A B C' to make it a null terminated string. 

SI2818466

   

 

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2015-04-09 15:46
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.