BINARY formatted data in an ACCEPT statement
According to Standard COBOL 2002, the ACCEPT
statement causes the transfer of data from the hardware device. This
data replaces the content of the data item referenced by identifier-1
. Any
conversion of data that is required between the hardware device and the data item referenced by
identifier-1
is defined by the implementer. The IBM®
COBOL for Linux® on x86 implementation allows only
displayable data (display, national, numeric, alphanumeric) which precludes binary formatted
data.
When you use IBM
COBOL for Linux on x86 to compile source code that
contains
BINARY
formatted data in an ACCEPT
statement, you will
receive the error message in the following example:$ cat tcAcceptBinary.cbl
000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TEST-CASE.
000030 ENVIRONMENT DIVISION.
000040 DATA DIVISION.
000050
000060 WORKING-STORAGE SECTION.
000070 01 EMPLOYEE-ID PIC S9(4) COMP-5 VALUE ZERO.
000080
000090 PROCEDURE DIVISION.
000100 MY-PROGRAM.
000110 DISPLAY "PLEASE INSERT EMPLOYEE'S ID NUMBER..".
000120 ACCEPT EMPLOYEE-ID.
000130
000140 STOP RUN.
$ cob2 -o tcAcceptBinary tcAcceptBinary.cbl IBM COBOL for Linux 1.2.0 compile started 0LineID Message code Message text 12 IGYLN0642-E Statement accepted, but ACCEPT identifier may not achieve expected conversion. -Messages Total Informational Warning Error Severe Terminating 0Printed: 1 1 End of compilation 1, program TEST-CASE, highest severity: Error. Return code 8
Change the data type from
COMP-5
to DISPLAY
,
and make further changes to the input source as well.$ cat sol-tcAcceptBinary.cbl
000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TEST-CASE.
000030 ENVIRONMENT DIVISION.
000040 DATA DIVISION.
000050
000060 WORKING-STORAGE SECTION.
000070 01 EMP-ID PIC 9(4) VALUE ZEROES.
000080 01 EMPLOYEE-ID PIC S9(4) COMP-5 VALUE ZERO.
000090
000100 PROCEDURE DIVISION.
000110 MY-PROGRAM.
000120 DISPLAY "PLEASE INSERT EMPLOYEE'S ID NUMBER..".
000130 ACCEPT EMP-ID.
000140 MOVE EMP-ID TO EMPLOYEE-ID.
000150 STOP RUN.