Problem:
The example program, "CONVERTING.cbl", illustrates how to use an "inspect ... converting" statement to translate EBCDIC numeric display values to equivalent ASCII numeric display values.
Resolution:
=============
Two Net Express project files, CONVERTING.APP and CONVERTING.OLD, are present in the project directory. The CONVERTING.APP file is a Net Express 4.0 project file. The CONVERTING.OLD file is a Net Express 3.1, SP1 project file. If you are working with Net Express 3.1 rename the 4.0 project file (CONVERTING.V40) and change the file extension of the 3.1 project file from "OLD" to "APP".
INTRODUCTION
==========
The example program, "CONVERTING.cbl", illustrates how to use an "inspect ... converting" statement to translate EBCDIC numeric display values to equivalent ASCII numeric display values. The example program is an ASCII program. A character data item in working-storage has an
EBCDIC value. This field is redefined as a signed, numeric display item. An inspect statement is used to translate the character data item with the EBCDIC value to an ASCII value using two small tables. Before the inspect statement is executed, the signed, numeric display item that redefines the EBCDIC value returns "illegal data in numeric field". After the inspect is executed, a signed, numeric value is returned.
SOURCE FILES:
=========
Program Files Description
-------------------- -----------------------------------------------------------
CONVERTING.cbl Example program that illustrates use of the "inspect ... converting" statement.
REQUIREMENTS:
==========
You must open the project and do a Rebuild All. Then you can animate the example program.
OPERATION:
========
The example program, "CONVERTING.cbl". Illustrates how to use an "inspect ... converting" statement to translate EBCDIC numeric display values to equivalent ASCII numeric display values. The following syntax is used.
INSPECT identifier-1 CONVERTING identifier-6 TO identifier-7
"identifier-1" is a pic x(9) item initialized to a hexadecimal value 'F1F2F3F4F5F6F7F8D9' that is equivalent to "123456789-", a signed, numeric display value on an EBCDIC computer system.
"identifier-6" is a table of the numeric EBCDIC characters that might appear in a signed, numeric display item. There are three groups of possibilities. The first group, (C0C1...), are positive, unsigned digits. The second group, (D0D1...), are negative, signed digits. The third group, (F0F1...) are plain digits. The signed and unsigned possibilities only exist in the units (least significant) position.
'C0C1C2C3C4C5C6C7C8C9D0D1D2D3D4D5D6D7D8D9F0F1F2F3F4F5F6F7F8F9'
"identifier-7" is a second table that defines the ASCII equivalent of the EBCDIC table. Micro Focus COBOL doesn't support a negative zero so you will see a "30" in the position that corresponds to the "D0" in the EBCDIC table. You'll also note that the plain ASCII digits appear twice in the table as unsigned digits are not distinguished from plain digits on ASCII systems.
'303132333435363738393071727374757677787930313233343536373839'
The complete source of the example program follows.
working-storage section.
77 dtItem pic x(9) value x'F1F2F3F4F5F6F7F8D9'.
77 dataItem redefines dtItem pic s9(9).
78 ebcdicDigits value
x'C0C1C2C3C4C5C6C7C8C9D0D1D2D3D4D5D6D7D8D9F0F1F2F3F4F5F6F7F8F9'.
78 asciiDigits value
x'303132333435363738393071727374757677787930313233343536373839'.
procedure division.
display dtItem
inspect dtItem converting ebcdicDigits to asciiDigits
display dtItem
display dataItem
exit program
stop run.
dtItem: a pic x(9) display item initialized to EBCDIC characters that are appropriate for a signed, numeric display item.
dataItem: a pic s9(9) display item that redefines dtItem.
ebcdicDigits: The EBCDIC characters that may exist in an numeric display value.
asciiDigits: The ASCII characters that correspond to the EBCDIC characters. In ASCII there are really only two sets of characters, negative signed and unsigned.
The inspect statement first locates a matching EBCDIC character in the EBCDIC table and then retrieves, from the corresponding location in the ASCII table, the equivalent ASCII character value. It then overlays the EBCDIC value with the ASCII value.
==========================================================
Keywords: demonstration, sample, example, demo, converting.zip
demo.ex
demo.me
demo.ne
demo.se