Microsoft KB Archive/60855

Cannot Pass PIC 9 Literals to COBOL Programs

PSS ID Number: Q60855 Article last modified on 04-19-1990

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: A COBOL program can pass a nonnumeric literal (string) to another COBOL program. It cannot, however, pass a numeric literal (number). For example, the following statement will execute successfully: CALL COBOL-PROG USING “ABC” The called program would declare a PIC X(3) data-item in its LINKAGE SECTION to receive the data. The following statement, however, will not execute successfully: CALL COBOL-PROG USING 10 The compiler will not flag an error. Even if a PIC 99 data-item is declared in the LINKAGE SECTION of the called program, no data will be passed. This information applies to Microsoft COBOL Compiler Versions 3.00 and 3.00a for MS-DOS and MS OS/2.

More Information: This limitation of not being able to pass numeric literals as parameters in a CALL is stated on Page 10-37 of the “Microsoft COBOL Compiler 3.0: Language Reference Manual”: Literal-2 must be non-numeric and cannot be a figurative constant. To work around this limitation, define a WORKING-STORAGE data-item to hold the numeric value, and then pass the data-item in place of the numeric literal. The following example illustrates how to pass a nonnumeric literal between two COBOL programs. Compile and LINK as follows: COBOL MAIN.CBL ; LINK MAIN.CBL ; COBOL SUB.CBL ; LINK SUB.CBL ; The following, MAIN.CBL, is the calling program: $SET ANS85 IDENTIFICATION DIVISION. PROGRAM-ID. MAIN. PROCEDURE DIVISION. CALL “SUB” USING “ABC”. STOP RUN. The following, SUB.CBL, is the called program: $SET ANS85 IDENTIFICATION DIVISION. PROGRAM-ID. SUB. DATA DIVISION. LINKAGE SECTION. * This parameter will receive the literal. 01 THE-STRING PIC X(3). PROCEDURE DIVISION USING THE-STRING. DISPLAY THE-STRING. EXIT PROGRAM. When MAIN is run, the output of the program is as follows: ABC

Copyright Microsoft Corporation 1990.