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.,s trings 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 t he 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
↧