Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
using overlay option in COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe COBOL
Author Message
malathy_tv

New User


Joined: 29 May 2007
Posts: 34
Location: chennai

PostPosted: Sat Oct 11, 2008 6:16 pm    Post subject: using overlay option in COBOL
Reply with quote

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.
Back to top
View user's profile Send private message
References
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 3273
Location: italy

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

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 icon_biggrin.gif
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 3731
Location: Brussels once more ...

PostPosted: Sat Oct 11, 2008 6:43 pm    Post subject:
Reply with quote

Why would you want to change the actual result to some ficticious one ?
Back to top
View user's profile Send private message
dick scherrer

Global Moderator


Joined: 23 Nov 2006
Posts: 9200
Location: 221 B Baker St

PostPosted: Sat Oct 11, 2008 7:38 pm    Post subject:
Reply with quote

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?
Back to top
View user's profile Send private message
bala_velan27

New User


Joined: 09 Oct 2007
Posts: 1
Location: chennai

PostPosted: Mon Oct 13, 2008 2:10 pm    Post subject:
Reply with quote

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   
Back to top
View user's profile Send private message
dick scherrer

Global Moderator


Joined: 23 Nov 2006
Posts: 9200
Location: 221 B Baker St

PostPosted: Mon Oct 13, 2008 2:30 pm    Post subject:
Reply with quote

Hello,

There must be something i am missing icon_confused.gif

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?
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 3273
Location: italy

PostPosted: Mon Oct 13, 2008 3:13 pm    Post subject: Reply to: using overlay option in COBOL
Reply with quote

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
Back to top
View user's profile Send private message
mshemanthkumar

New User


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

PostPosted: Mon Oct 13, 2008 3:18 pm    Post subject:
Reply with quote

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
Back to top
View user's profile Send private message
dick scherrer

Global Moderator


Joined: 23 Nov 2006
Posts: 9200
Location: 221 B Baker St

PostPosted: Mon Oct 13, 2008 11:41 pm    Post subject:
Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe COBOL All times are GMT + 6 Hours
Page 1 of 1