Page 1 of 1

Numeric check on PIC 9(04)

PostPosted: Wed Jan 17, 2018 1:40 pm
by Vinnie95
INPUT FROM CARD - FIELD: 0004 ID: 000B

INPUT stored in temp
 03 WS-TERM-FIELD                  PIC 9(4) VALUE ZERO.  
 03 WS-TERM-ID                    PIC 9(4) VALUE ZERO.  


Error check:
                                           
 IF WS-TERM-FIELD NOT NUMERIC                
      DISPLAY 'INVALID FIELD'                
      INITIALIZE MSG-002                    
      MOVE '002'         TO MSG-WORK-NUM    
      SET MSG-WORK-ERR   TO TRUE            
      MOVE CARDI-WORK    TO MSG-002-COMMAND  
      MOVE SPACES        TO MSG-WORK-DTL    
      MOVE MSG-002       TO MSG-WORK-DTL    
      PERFORM DISP-RTN THRU DISP-EXIT        
 END-IF.                                    
                                             
 IF WS-TERM-ID NOT NUMERIC                  
      DISPLAY 'INVALID ID'                  
      INITIALIZE MSG-002                    
      MOVE '002'         TO MSG-WORK-NUM    
      SET MSG-WORK-ERR   TO TRUE            
      MOVE CARDI-WORK    TO MSG-002-COMMAND  
      MOVE SPACES        TO MSG-WORK-DTL    
      MOVE MSG-002       TO MSG-WORK-DTL    
      PERFORM DISP-RTN THRU DISP-EXIT        
 END-IF.                                    


Result:
No error and ID = 0002

Why is B taken to be 2? How to correct this?
If there are two letters it gives an error but if there is one letter, no error.

Re: Numeric check on PIC 9(04)

PostPosted: Wed Jan 17, 2018 4:13 pm
by prino
How about actually reading the manual?

Re: Numeric check on PIC 9(04)

PostPosted: Wed Jan 17, 2018 5:04 pm
by NicC
This sort of question has been asked many times. Yes, reaad the manual. That is what it is there for. Also look through other topics within the forum.

Re: Numeric check on PIC 9(04)

PostPosted: Wed Jan 17, 2018 6:36 pm
by Vinnie95
prino wrote:How about actually reading the manual?


NicC wrote:This sort of question has been asked many times. Yes, reaad the manual. That is what it is there for. Also look through other topics within the forum.


So helpful. Thanks for nothing

Re: Numeric check on PIC 9(04)

PostPosted: Wed Jan 17, 2018 6:41 pm
by NicC
Not for 'nothing'. You should have learned at least 2 things - the answer can be got by reading the manual and that you should search before posting. Actually, 2 more things - this is not a 'read the manual for you' service and that we encourage people to help themselves.

Re: Numeric check on PIC 9(04)

PostPosted: Wed Jan 17, 2018 11:14 pm
by Robert Sample
Why is B taken to be 2? How to correct this?
If there are two letters it gives an error but if there is one letter, no error.
If you had read the manual, you would know the internal representation of zoned decimal values and you would understand why '000B' is treated as '0002' by COBOL. The way to correct this is to use a REDEFINES on WS-TERM-FIELD and WS-TERM-ID to have a PIC X(04) value and then check each byte of the redefined variable to see if the value is between 'A' and 'Z'. Depending upon your release of z/OS Enterprise COBOL, the IF NUMERIC test in COBOL on a zoned decimal value may not be able to distinguish between a letter and a digit.