Inside cobol libc function such as printf can be called directly
Print an integer
To print an integer in %d, or %x
CALL "printf" USING "CONST INT=[%d, 0x%04x]%c"&x"00" BY VALUE 1234 BY VALUE 1234 BY VALUE 10.
Print a string
To print a string
CALL "printf" USING "CONST STR=[%s]%c"&x"00" BY REFERENCE "ABCD" BY VALUE 10.
Detail Sample
$set sourceformat(free) IDENTIFICATION DIVISION. PROGRAM-ID. SHENHUI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. RM-COBOL. OBJECT-COMPUTER. RM-COBOL. DATA DIVISION. FILE SECTION. WORKING-STORAGE SECTION. 01 VAR-INT PIC S9(4) COMP. 01 VAR-STR PIC X(4). PROCEDURE DIVISION. MAIN-LOGIC SECTION. BEGIN. MOVE 1234 TO VAR-INT. MOVE "ABCD" TO VAR-STR. * * PRINT INT CONST CALL "printf" USING "CONST INT=[%d, 0x%04x]%c"&x"00" BY VALUE 1234 BY VALUE 1234 BY VALUE 10. * * PRINT INT VAR CALL "printf" USING "VAR INT=[%d, 0x%04x]%c"&x"00" BY VALUE VAR-INT BY VALUE VAR-INT BY VALUE 10. * * PRINT STR CONST CALL "printf" USING "CONST STR=[%s]%c"&x"00" BY REFERENCE "ABCD" BY VALUE 10. * * PRINT STR VAR CALL "printf" USING "VAR STR=[%s]%c"&x"00" BY REFERENCE VAR-STR BY VALUE 10. STOP RUN. MAIN-LOGIC-EXIT. EXIT.
Execution Result
CONST INT=[1234, 0x04d2] VAR INT=[1234, 0x04d2] CONST STR=[ABCD] VAR STR=[ABCD]