I have a query regarding a requirement I have received, to convert from Cobol 4 to Cobol 6. Following are the various numeric checks we need to do:-
Data to be converted are:-
1. Numeric Packed signed fields / Numeric Packed unsigned fields
2. Numeric unpacked signed fields / Numeric unpacked unsigned fields
Need to check for spaces / low-values / non-numeric in the field. Also need to check for the signed (last nibble) bit is having valid 'C' or 'D'.
Need to generalize the code for numerous fields (100+) fields are present in the file.
Numerous fields mentioned above can be of S9(03)V99, S9(05)V99, s9(07)v9999, S9(09)V99, S9(11)V9999 and so on... Sample code tried for packed signed conversion, it is working for s9(05)v99, however when data type changes it is not working fine:-
MOVE SOURCE-FIELD TO WS-COMP-HOLD-X
PERFORM CONVERT-PARA.
CONVERT-PARA.
INITIALIZE WS-NUMCHK-LEN.
INSPECT WS-COMP-HOLD-X TALLYING WS-NUMCHK-LEN FOR
CHARACTERS BEFORE INITIAL SPACE.
MOVE FUNCTION HEX-TO-CHAR(WS-COMP-HOLD-X(1:WS-NUMCHK-LEN))
TO WS-COMP-HOLD-9.
MOVE WS-COMP-HOLD-X TO WS-COMP-OLD.
EVALUATE TRUE
WHEN WS-COMP-HOLD-9(1:WS-NUMCHK-LEN) EQUAL SPACES
SET ERROR-DATA TO TRUE
MOVE ZEROES TO WS-COMP-NUM2
MOVE FUNCTION HEX-OF(WS-COMP-NUM2) TO WS-COMP-HOLD-X
WHEN WS-COMP-HOLD-9(1:WS-NUMCHK-LEN) EQUAL LOW-VALUES
SET ERROR-DATA TO TRUE
MOVE ZEROES TO WS-COMP-NUM2
MOVE FUNCTION HEX-OF(WS-COMP-NUM2)
TO WS-COMP-HOLD-X
WHEN WS-COMP-HOLD-X(WS-NUMCHK-LEN:1) NOT = 'F'
SET ERROR-DATA TO TRUE
MOVE 'F' TO WS-COMP-HOLD-X(WS-NUMCHK-LEN:1)
MOVE FUNCTION
HEX-TO-CHAR(WS-COMP-HOLD-X(1:WS-NUMCHK-LEN))
TO WS-COMP-HOLD-9(1:WS-NUMCHK-LEN)
IF WS-COMP-NUM2 NOT NUMERIC
MOVE ZEROES TO WS-COMP-NUM2
MOVE FUNCTION HEX-OF(WS-COMP-NUM2)
TO WS-COMP-HOLD-X
ELSE
COMPUTE WS-COMP-NUM2 = WS-COMP-NUM2 * WS-ONE
MOVE FUNCTION HEX-OF(WS-COMP-NUM2)
TO WS-COMP-HOLD-X
END-IF
WHEN WS-COMP-HOLD-X(WS-NUMCHK-LEN:1) = 'F'
SET ERROR-DATA TO TRUE
IF WS-COMP-NUM2 NUMERIC
COMPUTE WS-COMP-NUM2 = WS-COMP-NUM2 * WS-ONE
MOVE FUNCTION HEX-OF(WS-COMP-NUM2)
TO WS-COMP-HOLD-X
ELSE
MOVE ZEROES TO WS-COMP-NUM2
MOVE FUNCTION HEX-OF(WS-COMP-NUM2)
TO WS-COMP-HOLD-X
END-IF
WHEN OTHER
CONTINUE
END-EVALUATE.
Could some one suggest a general code for numeric check that will work for various picture clauses?
Code'd for you
My suggestion is, to process such data verification, and data fix out of COBOL code; it may require much less efforts, and be much more effective on huge datasets.
Process each input data via DFSORT/SYNCSORT utility, to make them fully matching the required COBOL definition.
SORT can be executed either as separate JCL step, or called from COBOL code itself (with some extra efforts).
I also tried to understand the idea of error check in your example in COBOL code, but finally had to give up; not able to find out, what is your plan: how to deal with various combinations of input characters?
Maybe, you can clarify it first of all without using a program code?
This is an example: how to pre-process the input records by SORT, to make all field formats acceptable. It may be adjusted according to your own acceptance rules, which are not fully clear from the given COBOL example.