Someone please explain this COMPUTE statement

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
User avatar
Gurugars
Active Member
Posts: 107
Joined: Sat Oct 23, 2010 2:17 pm
Location: Chennai,India.

Someone please explain this COMPUTE statement

Post by Gurugars » Tue Nov 25, 2014 10:17 pm

Hi

I'm having a compute statement like below

Code: Select all

COMPUTE 2XXM-VARPC = (100 * ((100 + 2XXM-VARPC) / 
                      102,10) - 100)              
When ever the result of this statement is +ve, it is rounded to the small number and when ever the result of the statement is -ve then it is rounded to the next higher number.

Say for an example is I'm passing 13.44 (to 2XXM-VARPC) then the expected result must be 11.11. but I'm getting 11.00.

like wise whenever the result is negative say -9.10 then it is rounded to 10.00.

The field 2XXM-VARPC is declared as below.

Code: Select all

09  2XXM-VARPCX.                                       
    11  2XXM-VARPC                 PIC S9(03)V99 COMP-3
Could someone please explain me why the statement working like this.? Am i missing something here.?


Bunch of Thanks in advance!
Guru:-)

You're never fully dressed without a smile :)

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Tue Nov 25, 2014 11:04 pm

The last thing you are doing is multiplying by 100. Means the content of the V99 will always be zero.

You must do multiply first, divide last. Just rearrange it and you should get what you want.

User avatar
Gurugars
Active Member
Posts: 107
Joined: Sat Oct 23, 2010 2:17 pm
Location: Chennai,India.

Post by Gurugars » Wed Nov 26, 2014 2:12 pm

Thanks much William :) You made my day :)
Guru:-)

You're never fully dressed without a smile :)

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Fri May 01, 2015 2:27 pm

This is plagiarism, just to get that SPAM in at the bottom.

If there are active moderators around, expect to lose your account and get your IP address banned.

It is not a good idea to spam computer programmers. There will of course be no connection to anything unusual which happens to any of your accounts over the coming months, but it is still not a good idea.

Here's the original: http://stackoverflow.com/a/22682497/1927206

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others