How to Convert Sign Fields to Alpha Numeric in COBOL


COBOL is still one of the richest and most elegant computer languages on the market. Aside from the computing power and massive file handling capabilities, you have the flexibility of number conversions and reporting. Many times you may need to display specific numerical values on output reports, files or screen display fields like CICS. Undoubtedly, you will encounter numeric formats that will not display properly as stored and will need to be further converted to a more readable format. One of the most common is the packed decimal or COMP-3 numeric field.

  • Identify the field(s) you wish to convert in the COBOL code. For example, you may have a field that reads similar to: "05 pkd-field-01 pic s9(5v99) comp-3." This is a signed, packed decimal field used efficiently for computations but cannot be easily read in a display.

  • Go to the "Working-Storage Section of the program and set up the intermediate fields you will need to make the desired numeric transition as follows: create two numeric fields "05 ws-numeric pic s9(5v99) value zero," and "05 ws-display-numeric pix x(8)."

  • Insert code in the program to move the input field directly into the first intermediary field "ws-numeric." This will unpack the comp-3 number into a zoned numeric field. In turn, have the code now move the first intermediary field into the second one, ws-display-numeric. This last field can be used to display the number either on a printed form or on a computer screen.

  • Compile the program with the saved changes and make sure there are no errors in the compile by checking the condition code.

  • Run the compiled version and verify the results.

Related Searches


  • Photo Credit F64/Digital Vision/Getty Images
Promoted By Zergnet



You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!