Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Problem while dividing comp-3 variables

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
bg_anudeep

New User


Joined: 17 Aug 2006
Posts: 4

PostPosted: Fri Jan 06, 2012 4:13 pm    Post subject: Problem while dividing comp-3 variables
Reply with quote

Hi,
I am facing a problem while dividing comp-3 variables.
Below is the description:

variable A PIC S9(12)V9(05)
variable B PIC S9(13)V9(02)
variable C PIC S9(13)V9(05)

now when i am dividing these variables as below

compute C = (B*100)/A
if C > 99
then
...
...
end-if

the value in C is never having a decimal. Should i move the result in C to a numeric-edited variable ?

variable D 9(13).9(05)
MOVE C to D
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7230

PostPosted: Fri Jan 06, 2012 4:21 pm    Post subject: Reply to: COMP-3 VARIABLE DIVISION
Reply with quote

With V the decimal place is always implied. If you need to see a decimal point, yes, you have to use numeric-edited.

If you only think you need to see a decimal point, then leave it as a V. The definition takes care of understanding where the decimal place is With your example, C is calculated to five decimal places. Doesn't matter that you can't "see" a decimal point.
Back to top
View user's profile Send private message
bg_anudeep

New User


Joined: 17 Aug 2006
Posts: 4

PostPosted: Fri Jan 06, 2012 4:35 pm    Post subject:
Reply with quote

Hi Bill,

The problem that i am facing is that once i have a value in C , then the further processing is done on the fact if C > 99 %.
now if i put a display on C i always get to see a value without any decimal.

in other words , what i want to achieve is

divide PIC S9(13)V9(02) by PIC S9(12)V9(05)
find out the percentage
and then proceed with the logic if % > 99

so should C be S9(13)V9(05) or some other PIC clause

Thanks
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7230

PostPosted: Fri Jan 06, 2012 4:42 pm    Post subject: Reply to: COMP-3 VARIABLE DIVISION
Reply with quote

Yes, if you do want to be able to see the decimal-point for a value you display, rather than just "know" it is there from the PICture, then MOVE it to a new numeric-edited field which is defined with an explicit decimal-point.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Fri Jan 06, 2012 5:17 pm    Post subject:
Reply with quote

bg_anudeep, it sounds like you are mixed up about several things:

1. C has an implied decimal point (that's what the V in the PIC means). You will not, under any circumstances, ever see a decimal point if you DISPLAY the value of C. If you want to DISPLAY the value and see a decimal point, you will need to move C to a numeric edited variable.

2. COBOL understands the decimal point, and the IF statement will process the THEN part any time the value of B is at least as large as the value of A. This processing does NOT depend upon any actual decimal point -- COBOL can keep track of implied decimal points quite well.

3. I suspect you're going to have issues with intermediate results since the number of digits after the decimal point varies so much, and especially if the number of digits before the decimal point for the value of B approaches 12.

4. If B and A are close in value (why else use that particular IF statement?), then C does not need 13 digits in front of the decimal place -- 3 or 4 would probably be enough. If B and A can be very different values, then you need to do some numerical analysis and verify that your PIC clauses are big enough to handle all potential problems.
Back to top
View user's profile Send private message
bg_anudeep

New User


Joined: 17 Aug 2006
Posts: 4

PostPosted: Fri Jan 06, 2012 6:41 pm    Post subject: Reply to: COMP-3 VARIABLE DIVISION
Reply with quote

Hi Robert,

Thanks for the repy.
the problem that i am having is inaccordance with
<3. I suspect you're going to have issues with intermediate results since the number of digits after the decimal point varies so much, and especially if the number of digits before the decimal point for the value of B approaches 12. >

how do you suggest i find out the percentage ?
i had put displays on A B & C got the below result :

B =000000000600360
A =00000002120233333
C =(B*100)/A
C =000000000002831575

Now ideally if i move C to a variable with PIC 9(13).9(05)

what i get is 28.31575 which is incorrect
How should i get the correct percentage
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Fri Jan 06, 2012 6:59 pm    Post subject:
Reply with quote

When I take 6003.60 and multiply by 100 and then divide by 21202.33333, I get 28.315751415459894573782743184521, which is the same number you get to 5 decimal digits.

Since COBOL is getting the correct result, as verified independently, just what do you think the "correct percentage" should be?
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Fri Jan 06, 2012 7:21 pm    Post subject: Reply to: COMP-3 VARIABLE DIVISION
Reply with quote

the same with 998 decimal digits

value calculated for A = 21202.33333
Code:

28.31575141545989457378274318452100290605137844986422539183804068606254668292209
13866275868043812138293554504739031003622090493754160783208477177544684889641813
77672926152416074669834463922183794853111103314589762654203116426525872376707889
44246826441153776540499280981731457383893511309115900971452183088567639267465473
81066006474297798430093825904396344098038949187674147371778915429399109442262504
03921934756225247968969649247562320066590519921799569217507439309746952270936681
85434569809208824470452752758415387104943699137664675136017211177388842608107416
26049136357012457175627282716623529283981877668178325918244584073803918448253166
86029103193992658542926511003965996038795414976149702859142814919606775185059313
46943879030129369256548708358600265435974069746407481841056406030948858778271080
03494443693853576445022336605251361737741343207153511910191254407563830145670103
94228152623803693402267626739551877425370144390612691117426178112067253307350960
31998851703743118163683732633779887847844


value calculated for A = 21202.3(3) <== 3 periodical aka 62607 /3
Code:

28.31575141100822236546292074771644630307984970207681544484097662206989796720486
73888094077695851085572342666687628720109421918971182417029572216894366972188595
59482446900498372820601506123539861964878079456663574763783860266951750593488138
09800808087160218214976339082176490008961277846777870360180483280142122722341880
61062461678746049963054380807143867813290989985378967723678211517600264121873378
71617903689845457260993286902384957630449478830946279497539578977156602260757463
80115396104202367663936359205747795054003490181898218749508701872435423774112912
10086940116653827408932979074630150769569387017152200229534485198170012734447466
47381577499331834546512176332793560457182385586492052761488515414970050466143663
43326992312166899869511217318848554404389453990912949832565598125992422217680443
97629191755624380964359268633955382269247095445469838225352555536340339899696574
27641611772289213451349694216045403807757007876491581115286053421793198861760498
05838979986479475529422862263587341015926

Back to top
View user's profile Send private message
bg_anudeep

New User


Joined: 17 Aug 2006
Posts: 4

PostPosted: Fri Jan 06, 2012 7:25 pm    Post subject:
Reply with quote

Hi Robert,

Apologies for the mistake i made.
While calculating the percentage i didnt take the decimal into consideration.

Thanks for all your help.

Cheers!!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm
No new posts Problem in Running Query via JCL vickey_dw DB2 3 Tue Oct 18, 2016 11:11 pm
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts DB2 Streaming Batch Processing Problem Manshadi DB2 4 Sat Sep 24, 2016 12:14 pm
No new posts How can we create a flat file in JAVA... rakesh.v18 Java & MQSeries 7 Fri Sep 23, 2016 10:46 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us