shashanktg1 Beginner
Joined: 30 Dec 2014 Posts: 1 Topics: 1
|
Posted: Wed Dec 31, 2014 11:40 am Post subject: Fixedoverflow vs Size |
|
|
As per IBM manual, the FIXEDOVERFLOW condition differs from the SIZE
condition in that SIZE is raised when a result exceeds the declared size of a variable, while FIXEDOVERFLOW is raised when a result exceeds the maximum allowed by the computer. But below code:
Code: | ON SIZE
PUT SKIP LIST ('ONSIZE');
DCL A FIXED DEC (01);
DCL B FIXED DEC (01);
DCL C FIXED DEC (01);
A = 8;
B = 3;
C = A * B; |
fails with FIXEDOVERFLOW instead of SIZE which is opposite to what is
written in IBM manuals. Can anyone please tell me waht exactly is the
difference in FIXEDOVERLOW and SIZE with example?
Thanks! |
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Wed Dec 31, 2014 4:42 pm Post subject: |
|
|
shashanktg1,
Isn't fixed DEC defined as FIXED DEC(total-digits, decimal-digits) ?? Either way here is an example showcasing both size and fixedoverflow errors.
Code: |
MYPGM: PROC OPTIONS(MAIN);
DCL SYSPRINT FILE STREAM OUTPUT;
DCL(BOOL,ONCODE,ONLOC) BUILTIN; /*BONUS - USING BOOL FUNCTION FOR */
DCL A BIT(8) INIT('11110000'B); /*EXCLUSIVE OR COULD USE ON CHAR OR */
DCL B BIT(8) INIT('10101010'B); /* NUMERIC DATA */
DCL C BIT(8) INIT('00000000'B); /* BOOL BUILTIN does heavy lifting */
DCL Z BIT(4) INIT('0110'B); /* THIS IS AN EXCLUSIVE OR */
DCL (I,J,K) FIXED BIN(15);
DCL VALUE PIC'99999999';
ON ERROR BEGIN; ON ERROR SYSTEM; VALUE = ONCODE;
PUT SKIP EDIT('@'||ONLOC||' OF '||VALUE)(A); END;
PUT SKIP DATA(A,B);
C = A&B; PUT SKIP DATA(C); /* AND */
C = A|B; PUT SKIP DATA(C); /* OR */
C = BOOL(A,B,Z); PUT SKIP DATA(C); /* EXCLUSIVE OR */
K=9000;
CALL SIZE_ERROR;
CALL FIXED_OVER_ERROR;
SIZE_ERROR: PROC;
Size is a logical error. Target is too small for result.
ON SIZE BEGIN; PUT SKIP LIST('SIZE ERROR'); END;
I = 32000+32000; /* SIZE ERROR CAUGHT AT COMPLILE TIME */
(SIZE): I = 32000+K; /* FORCE CATCHING SIZE ERROR IN EXECUTION */
PUT DATA(I);
END SIZE_ERROR;
FIXED_OVER_ERROR: PROC;
Overflow is a machine error. The operation cannot be performed.
I = 32000; J = 1000;
K = I**J; /* THIS WILL NOT FIT IN 16 BITS */
PUT DATA(K);
END FIXED_OVER_ERROR;
END MYPGM;
|
|
|