Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
malathy_tv

New User

Joined: 29 May 2007
Posts: 34
Location: chennai

 Posted: Sat Oct 11, 2008 6:16 pm    Post subject: using overlay option in COBOL hi, i need to do an computaion, adding two decimal values and storing it in a variable ex: declaration are like A PIC +99999999999.99. B PIC S9(11)V9(2). C PIC S9(11)V9(2). COMPUTE A = B + C B = 1000.5 and C= 2000.2 the value for A comes as A= 1000.5+2000.2 = +00000003000.70 but i need the vale of A to be A = +00000003000.07 instead of '70' in the decimal part how can this be done.

enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

Posted: Sat Oct 11, 2008 6:37 pm    Post subject: Reply to: using overlay option in COBOL

 Quote: B = 1000.5 and C= 2000.2 the value for A comes as A= 1000.5+2000.2 = +00000003000.70 but i need the vale of A to be A = +00000003000.07 instead of '70' in the decimal part how can this be done.

invent a new math theory/architecture
expat

Global Moderator

Joined: 14 Mar 2007
Posts: 8657
Location: Back in jolly old England

 Posted: Sat Oct 11, 2008 6:43 pm    Post subject: Why would you want to change the actual result to some ficticious one ?
dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

Posted: Sat Oct 11, 2008 7:38 pm    Post subject:

Hello,

On you indows pc, there is a calculator.

Please add your numbers with the decimals as you've shown and notice the calculator arrives at the same answer (the one you want to change).

 Quote: but i need the vale of A to be A = +00000003000.07
Why do you need this value?
bala_velan27

New User

Joined: 09 Oct 2007
Posts: 1
Location: chennai

Posted: Mon Oct 13, 2008 2:10 pm    Post subject:

Hi Malathy,

Here is the solution for your question.

Declare the following codes in working storage section

 Code: WORKING-STORAGE SECTION.   77 A       PIC S9(11)V9(2).                          77 B       PIC S9(11)V9(2) VALUE 1000.5.            77 C       PIC S9(11)V9(2) VALUE 2000.2.            77 D       PIC +9(11).9(2).                                                                              01 REC1.                                                                                                  02 REC2  PIC 9(12).                                  02 REC3  PIC 9(01).                                  02 REC4  PIC 9(01).                                  02 REC5  PIC 9(01).                                                                                    01 REC6.                                                                                                  02 REC7  PIC 9(12).                                  02 REC8  PIC X(01) VALUE '.'.                        02 REC9  PIC 9(01).                                  02 REC10 PIC 9(01).

In procedure code the following codes:

 Code: PROCEDURE DIVISION.                                                              COMPUTE A = B + C                                                                                       MOVE A     TO D.                                                                                       MOVE D     TO REC1.                                 MOVE REC2  TO REC7.                                 MOVE REC4  TO REC10.                               MOVE REC5  TO REC9.                                                                                     MOVE REC6  TO E.                                   DISPLAY 'A: ' A.                                   DISPLAY 'D: ' D.                                   DISPLAY 'REC1: ' REC1.                             DISPLAY 'REC6: ' REC6.                *  DISPLAY 'E: ' E.

Output :

You will get your desired output

 Code: A: 000000030007{      D: +00000003000.70    REC1: +00000003000.70 REC6:+00000003000.07
dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

 Posted: Mon Oct 13, 2008 2:30 pm    Post subject: Hello, There must be something i am missing Why all the effort to create an incorrect result? It is easy to force the answer, but why is an invalid result wanted? In what situation does this become a valid result?
enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

 Posted: Mon Oct 13, 2008 3:13 pm    Post subject: Reply to: using overlay option in COBOL One thing I have noticed in many ( too many ) posts is that people just fall in love with the technical, or better.... bit mangling side losing the proper perspective as far as organizational, business requirement and ... basic arithmetics issues
mshemanthkumar

New User

Joined: 01 Oct 2008
Posts: 2
Location: Melbourne,Australia

 Posted: Mon Oct 13, 2008 3:18 pm    Post subject: hello, The given Question is wrong with the arithmetic operation using standard COBOL format. But,she might need for some other purpose to need the result.The above code works fine for the question. with regards, Hemanth
dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

Posted: Mon Oct 13, 2008 11:41 pm    Post subject:

Hello Hemanth,

Keep in mind that just because somthing can be done does not mean that it should be done. When requirements posted differ from standard business practice it is best to understand the requirement before throwing code at it.

Nearly anything can be made to happen with code.

 Quote: she might need for some other purpose
We understand this is possible as well, but so far have had no explanation what that purpose might be.

If there is a business reason to do this, having it posted here may help someone with a similar requirement at some later time. If there is no business reason, it probably should not be implemented as discussed.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics How to display offset thru cobol prog... tvinodkumar7 CICS 2 Sun Apr 22, 2018 8:42 pm Linkage editor is part of COBOL, z/OS... ankit.jain COBOL Programming 4 Fri Apr 20, 2018 4:17 pm Difference between EQUAL and EQUAL TO... jithinraghavan COBOL Programming 3 Thu Apr 19, 2018 2:22 am Call COBOL or PLI with a click from w... vaibhav gs All Other Mainframe Topics 1 Mon Apr 16, 2018 7:29 pm COBOL MVS options BiswajitDG COBOL Programming 8 Fri Apr 06, 2018 12:35 am

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us