IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

using overlay option in COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
malathy_tv

New User


Joined: 29 May 2007
Posts: 34
Location: chennai

PostPosted: Sat Oct 11, 2008 6:16 pm
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
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Oct 11, 2008 6:37 pm
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: 8797
Location: Welsh Wales

PostPosted: Sat Oct 11, 2008 6:43 pm
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

Moderator Emeritus


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

PostPosted: Sat Oct 11, 2008 7:38 pm
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
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

Moderator Emeritus


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

PostPosted: Mon Oct 13, 2008 2:30 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Oct 13, 2008 3:13 pm
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
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

Moderator Emeritus


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

PostPosted: Mon Oct 13, 2008 11:41 pm
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts SCOPE PENDING option -check data DB2 2
Search our Forums:

Back to Top