Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's the result? 6

Status
Not open for further replies.

fabiousa

MIS
Aug 13, 2001
45
BR

If I have the following code and the WS-WORK-1-ND is pic 9(2) and contains 1 what is the value of WS-WORK3-ND?

DIVIDE WS-WORK-1-ND BY 2 GIVING WS-WORK-2-ND
REMAINDER WS-WORK-3-ND

I what I am assuming is that everytime I have an odd value, WS-WORK-3-ND will be 1 and when I have a even value, the result will be zero. Is that correct?

Thanks a lot!

Fabio
 
hello,
It seems to me that is not the way it is going to work
1 / 2 = 0.5
in this case, WS-WORK-3-ND = 0 , even if WS-WORK-1-ND is an odd number. It would work with any number that is greater than 1.
I may be wrong.
I see that i am not helping. Sorry
 

No problem...the thing is that I can test the code now.
What I had in my mind is that if I divide 1 by 2, result would be 0 and reminder 1.
 
Your code should be OK... depending on how you define all the fields involved. Make sure all of them are integers - no V's in your picture clause (example: PIC 99V99).

You have absolutely the right idea... define different receving fields for the quotient and the remainder - so just make sure your quotient will hold only whole numbers (integers) so that you don't get a quotient = 0.5! And that will happen if you define it as PIC 99V99

 
If you have a field for the result then you may want to initialize it to Zero.

Better watch out for the "ON SIZE ERROR". If the "ON SIZE ERROR" occurs the result of the remainder will be unchanged. If you do not like my post feel free to point out your opinion or my errors.
 
You wrote:
------------------
If I have the following code and the WS-WORK-1-ND is pic 9(2) and contains 1 what is the value of WS-WORK3-ND?

DIVIDE WS-WORK-1-ND BY 2 GIVING WS-WORK-2-ND
REMAINDER WS-WORK-3-ND

I what I am assuming is that everytime I have an odd value, WS-WORK-3-ND will be 1 and when I have a even value, the result will be zero. Is that correct?
------------------
If you divide a positive integer (whole number) by +2, if the number is even, then you will have a remainder (modulus) of zero. If you divide a positive integer by +2 and the number is odd, then your remainder (modulus) is +1.

I've done some coding where I wanted to see if one entry is divisible by the other. To do this, then I check to see if the remainder (modulus) = 0. This means that there is no remainder. This might be useful if WS-WORK-3-ND is not necessarily a positive integer.

Hope this helps, Nina Too

 
You could always subtract any number by 2 until it is <=2. If the result is 2 it is even. If you do not like my post feel free to point out your opinion or my errors.
 
Hi,

it would be nice if these kinds of questions are asked to the compiler, which will give you all the answers on your platform.

Example:
Code:
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. TEST.
000300 AUTHOR.
000400 DATA DIVISION.
000500 WORKING-STORAGE SECTION.
000600 01 CNT1   PIC 9999.
000700 01 CNT2   PIC 9999.
000800 01 REST   PIC 9999.
000900 PROCEDURE DIVISION.
001000 01. PERFORM VARYING CNT1 FROM 1 BY 1 UNTIL CNT1 > 3
001100        DIVIDE CNT1 BY 2 GIVING CNT2 REMAINDER REST
001200        EXHIBIT NAMED CNT1 CNT2 REST
001300     END-PERFORM.
001400     GOBACK.

Output:
Code:
CNT1 = 0001 CNT2 = 0000 REST = 0001
CNT1 = 0002 CNT2 = 0001 REST = 0000
CNT1 = 0003 CNT2 = 0001 REST = 0001


Regards,

Crox
 
So the answer on your original question is: yes you are correct.
 
Crox,

I just thought that if I had only one code, it wouldn't be any difference of which compiler I am using.
Anyway, thanks to all of you who to helped me out.
I feel sorry I can't give a star to myself hahaha just kidding!!

Fabio
 
Fabio,

You would be surprised if you knew all the differences between compilers, bugs, etc.

Some possibilities in COBOL are even difficult for the ANS COBOL committee.

I asked them once about a combination of the REPLACE statement which works on a COPY ... REPLACING statement which contains a REPLACE statement.... Not easy stuff.

I was working on an automatic maintenance tool. I needed to know exactly what COBOL does and what the differences are between COBOL '74 and COBOL '85.

So don't expect source to work the same way on all the platforms. Test it. That is your proof!

I have a personal proverb: THE COMPILER (on this current platform) IS ALWAYS RIGHT.

The case is, if the compiler reacts differently from what you expect, it doesn't help you that you are right by some book or so. The compiler is always right.

:)

Regards,

Crox

 
Ummm, actually, the compiler CAN be wrong, and if you tell the vendor about it, they will fix it. It happens occasionally, particularly when first released.

I once found a bug in CICS 1.7 (a LONG time ago). IBM told us it was a &quot;known bug&quot;, but the fix was typed into their reply letter! Funny thing, another programmer in my shop ran into the same bug a couple of weeks later. (This was a new feature, and fairly obscure.)

Stephen J Spiro
 
Speaking of the vendor being happy to fix things, I used to be on the COBOL compiler team at NCR. At the request of a customer, we fixed LINAGE, which wasn't working according to the ANS specification. This annoyed everyone whohad previously figured out what it was actually doing and used it to do that in their programs, since once it was fixed, all of their programs stopped working. We wound up implementing a switch, so they could optionally have it work correctly or the way it used to work.

The thing caused me such headaches that I had a T-shirt printed with the phrase &quot;LINAGE IS RECURSIVE&quot;. When people said I must be joking, and that the LINAGE algorithm couldn't be recursive, I replied, &quot;Sure it is, I've cursed it over and over again!&quot; LOL Betty Scherber
Brainbench MVP for COBOL II
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top