IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Numeric check on packed signed and unsigned variables


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
nimisanand

New User


Joined: 22 Nov 2005
Posts: 26

PostPosted: Tue Jun 22, 2021 8:17 pm
Reply with quote

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:-

Code:
05  SOURCE-FIELD      PIC S9(05)V99.
05  WS-COMP-HOLD-X          PIC X(18).
05  WS-COMP-HOLD-9.                                   
    10  WS-COMP-INT-X       PIC X(18).                 
    10  WS-COMP-NUM1        REDEFINES WS-COMP-INT-X.   
        15 WS-COMP-NUM1-9   PIC S9(03)    COMP-3.     
        15 FILLER           PIC X(16).                 
    10  WS-COMP-NUM2        REDEFINES WS-COMP-INT-X   
                            PIC S9(05)V99 COMP-3.     


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
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Tue Jun 22, 2021 8:55 pm
Reply with quote

please use code tags when presenting any code or sample data.
Quote:
Sample code tried for packed signed conversion, it is working for s9(05)v99, however when data type changes it is not working fine:-
Why can't different routines be called based on the data types , pass data type as one of the input and route it?
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2142
Location: USA

PostPosted: Tue Jun 22, 2021 9:58 pm
Reply with quote

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).
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2142
Location: USA

PostPosted: Wed Jun 23, 2021 12:53 am
Reply with quote

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?
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2142
Location: USA

PostPosted: Wed Jun 23, 2021 8:08 pm
Reply with quote

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.
Code:
//SORTNUMS  EXEC PGM=SORT
//SYNOUT    DD SYSOUT=*
//SYMNAMES  DD *
* SAMPLE INPUT RECORD

* COBOL FORMAT
*      01 INPUT-DATA.
*         05 FIELD-S99999V99           PIC S9(5)V99.
*         05 FIELD-S99999V99-COMP-3    PIC S9(5)V99 COMP-3.
*         05 FIELD-S999-COMP-3         PIC S9(3)    COMP-3.

* SYNCSORT FORMAT
INPUT_DATA,1
FIELD_S99999V99,*,7,ZD                 PIC S9(5)V99.
FIELD_S99999V99_COMP_3,*,4,PD          PIC S9(5)V99 COMP-3.
FIELD_S999_COMP_3,*,2,PD               PIC S9(3)    COMP-3.

//SORTIN    DD *
1111111222233
      7   8 9
-444444555-66

//*-+----1----+----2----+----3----+----4----+----5----+----6----+----7-
//*
//SORTOUT   DD SYSOUT=*
//*
//SYSIN     DD *
 INREC IFTHEN=(WHEN=(FIELD_S99999V99,NE,NUM),
               OVERLAY=(FIELD_S99999V99:FIELD_S99999V99,
                        SFF,TO=ZD,LENGTH=07),
               HIT=NEXT),
       IFTHEN=(WHEN=(FIELD_S99999V99_COMP_3,NE,NUM),
               OVERLAY=(FIELD_S99999V99_COMP_3:FIELD_S99999V99_COMP_3,
                        SFF,TO=PD,LENGTH=04),
               HIT=NEXT),
       IFTHEN=(WHEN=(FIELD_S999_COMP_3,NE,NUM),
               OVERLAY=(FIELD_S999_COMP_3:FIELD_S999_COMP_3,
                        SFF,TO=PD,LENGTH=02),
               HIT=NEXT)
 SORT FIELDS=COPY
 END
//*

The test results are as follows
Code:
****** ******************************************************* Top of Data *********
000001 1111111
       FFFFFFF0022034444444444444444444444444444444444444444444444444444444444444444
       1111111022F3F0000000000000000000000000000000000000000000000000000000000000000
------------------------------------------------------------------------------------
000002 0000007   ± €
       FFFFFFF0008094444444444444444444444444444444444444444444444444444444444444444
       0000007000F0F0000000000000000000000000000000000000000000000000000000000000000
------------------------------------------------------------------------------------
000003 044444M  í) ?
       FFFFFFD0055064444444444444444444444444444444444444444444444444444444444444444
       0444444005D6F0000000000000000000000000000000000000000000000000000000000000000
------------------------------------------------------------------------------------
000004 0000000
       FFFFFFF0000004444444444444444444444444444444444444444444444444444444444444444
       0000000000F0F0000000000000000000000000000000000000000000000000000000000000000
------------------------------------------------------------------------------------
****** ****************************************************** Bottom of Data *******
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Repeat n times by substuting SEQNUM i... DFSORT/ICETOOL 2
No new posts Preserve changes to ISPF Panel Variables TSO/ISPF 5
No new posts Using Multiple IFTHEN and WHEN condit... SYNCSORT 12
No new posts Check if CICS is online in JCL CICS 10
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
Search our Forums:

Back to Top