Page 2 of 2

Re: Numeric Edited Picture clause

PostPosted: Sun Jun 05, 2011 9:58 pm
by dick scherrer
Hello,

I guess you have a better idea as to what records i deal with now..
Only slightly better. . . :(

Is there some reason you did not post some of these values using HEX ON as you were requested?

the length of the record is 140+
I cannot extract the whole record..
There is no need to show "whole records" - only a few of the values you need to work with.

If you are certain that all of the fields to be totaled have valid values, use the NUMVAL function as suggested. If this data is the entered by a user, it will need to be edited before using NUMVAL or there will be abends.

Re: Numeric Edited Picture clause

PostPosted: Mon Jun 06, 2011 4:07 am
by BillyBoyo
I'm with Dick on the data.

The type is telling you whether you have a positive/negative value. So check that they are consistent (which will also validate the minus sign).

In front of the decimal point, apart from the minus sign, everything should be numeric. So check.

After the decimal point, everything should be numeric. So check.

The decimal point itself, should be a decimal point. So check.

Then the data is good-to-go. This might seem a lot of work, but it is good programming practice (as in being an element of the way to write good programs). It is also good practice of programming. With modern editors, it isn't even a lot of "work" to do it.

05  INF-NEGATIVE-VALUE.
      10  INF-NEGATIVE-VALUE-SIGN PIC X.
      10  INF-NEGATIVE-VALUE-INTEGER-PART PIC X(7).
      10  INF-NEGATIVE-VALUE-DECIMAL-POINT PIC X.
      10  INF-NEGATIVE-VALUE-DECIMAL-PART PIC XX.


You can still use INF-NEGATIVE-VALUE as input to NUMVAL. It is still effectively PIC X(11), it is just know broken up into four "subordinate" items, it has become a "group" item.

Obviously you can do the same for the positive value on your input.

This data definition leads naturally to an alternative to using NUMVAL. Define the INTEGER-PART and DECIMAL-PART as 9 instead of X. Then also define

01  WS-NUMERIC-FROM-EDITED PIC S9(7)V99.
01  FILLER REDEFINES WS-NUMERIC-FROM-EDITED.
     05  WS-NUMERIC-FROM-EDITED-INTEGER-PART PIC 9(7).
     05  WS-NUMERIC-FROM-EDITED-DECIMAL-PART PIC S99.


Move the appropriate fields from your input to these (negative and positive). Be careful with the definitions. INTEGER-PART must remain unsigned, but DECIMAL-PART and the original 01 should be signed. Then, if you have a negative sign (-) in your input, to get the negative value SUBTRACT WS-NUMERIC-FROM-EDITED FROM ZERO GIVING WS-NUMERIC-FROM-EDITED (or use COMPUTE to do the same thing). For the positive value, nothing else to do. Do your addition. Do the second (with the positive). Do your addition.

Why not try both ways. One way of checking your results (because from both sets of code they should be the same).

For the file, I'd also be interested to know if the "Type" always starts in the same position, otherwise you will have another problem.