Initially we coded with bleow syntax where divide statement used to return the remainder in #WS-TEMP-REM. However we got always 0 in Remainder field and it looks like #WS-TEMP-INT defined as N4.2 causing problem.
DIVIDE 4 INTO #WS-TEMP-CCYY GIVING #WS-TEMP-INT REMAINDER #WS-TEMP-REM
When we corrected Local variable definition as shown below then it worked as expected.
1 #WS-TEMP-CCYY (N4)
1 #WS-TEMP-INT (N4)
1 #WS-TEMP-REM (N4)
DIVIDE 4 INTO #WS-TEMP-CCYY GIVING #WS-TEMP-INT REMAINDER #WS-TEMP-REM
Clarification:
As such Natural does not give any error on both the syntax but it behaved differently when job run .Does this mean that giving statement operand must be Numeric field with out decimal ?
What remainder do you expect if you divide 4 into a number when the result contains 2 decimals? All results will have a precision of 2 decimals in this case. So the remainder is always 0. That’s not a problem with Natural but a problem of mathematics.
If you divide 3 into 1 you will always have a remainder (with any number of possible decimals). That’s also not a speciality of Natural but mathematics.
Btw, if possible (and there probably aren’t many reasons why it shouldn’t be) avoid using N-fields in computations, NATURAL will have to convert it back and forth as it isn’t possible to do any arithmetic operations on N (display format) fields.
I guess it’s not that easy. Please see Remainder - Wikipedia
Maybe Venkatesan has to define his own definition of a remainder. May that way is suitable:
Now I know: The result depends on the format of #operand3. Try this:
define data local
1 #operand3 (N1.0) /* and try (N1.1) and (N1.2) here
1 #operand4 (N1.1)
end-define
divide 1.2 into 4.3 giving #operand3 remainder #operand4
display #operand3 #operand4
end
Thanks for your reply. As you said the format of #Operand3 decideds the results of #operand4. It worked for N1.0 format alone.
Anyway we have used another syntax ‘DIVIDE 4 INTO #WS-TEMP-CCYY REMAINDER #WS-TEMP-REM-N’ and we got expected result here.
In this case we don’t need to worry about format of #operand3 as we are not using.
Exactly, but the more comlex rules you mentioned were only introduced with the Gregorian Calendar ( i.e. years >= 1582 or so). The above program classifies 600, 700, 1300, 1500 etc. as “no leap years”, when in fact they were: In Julian Calendar every year divisible by four without remainder is a leap year. So if one wants to be exact, one would have to check first if #ws-temp-ccyy is smaller than 1582, in which case the divisibility by four must be checked, or greater, in which case a test for 29 February can apply.