Pages

Wednesday, November 28, 2012

Declare numeric field with More than 18 Digits in Cobol

Have you ever wondered about the 18digits maximum limit of Numerical variable declaration (PIC 9(18) ) in Cobol?

Well you can override it in Enterprise Cool, or in other words if Language environment (a.k.a LE) is available at your shop. The Language environment is introduced back in 2000 by IBM, which is a common application layer for many Programming languages. The LE has a lot of cool features which I’ll be covering future posts. So keep coming back.

Here is a sample program for Numeric field declaration with more than 18 digits. The Compiler directive (CBL) is that really turning the ship around.
This compiler-directing statement selectively suppresses output or causes output to be produced. The keywords *CONTROL and *CBL are synonymous.

The Program logic is simple its just move a 31 digit number to the number 1 variable, then add it with itself and display it.
If you Don’t have mainframe access to try it out, visit my post on getting a free mainframe id, it really helps.  http://mainframegeek.me/2012/11/23/free-mainframe-id-to-practice/ . It’s a raw mainframe so you won’t be getting handy compile JCL on this mainframe, let me know if you need one, I can help you.







 CBL ARITH(EXTEND)
IDENTIFICATION DIVISION.
PROGRAM-ID. COB18DIG.
AUTHOR.     SHIBU.T.
*
DATA DIVISION.
WORKING-STORAGE SECTION.
77  WS-NUM1                      PIC 9(31).
*
PROCEDURE DIVISION.
A0000100-MAIN-PARA.
MOVE 1234567890123456789012345678901
TO WS-NUM1.
DISPLAY 'WS-NUM1 BEFORE ADDITION: ' WS-NUM1.
ADD WS-NUM1                 TO WS-NUM1.
DISPLAY 'WS-NUM1 AFTER ADDITION: ' WS-NUM1.
STOP RUN.

 

The compile and run JCL will complete with return-code 000, here is the output I got in my machine.

image

Does my Program, post helped you? Comment, rate or like my facebook page (top right corner of this page) and click on the adds listed below. It really help me to make this website alive.

-Cheers, Shibu

No comments:

Post a Comment