Numeric check on PIC 9(04)



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Numeric check on PIC 9(04)

Postby Vinnie95 » Wed Jan 17, 2018 1:40 pm

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.
Vinnie95
 
Posts: 2
Joined: Wed Jan 17, 2018 1:19 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Numeric check on PIC 9(04)

 

Re: Numeric check on PIC 9(04)

Postby prino » Wed Jan 17, 2018 4:13 pm

How about actually reading the manual?
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 561
Joined: Wed Mar 11, 2009 12:22 am
Location: Oostende, Belgium
Has thanked: 3 times
Been thanked: 24 times

Re: Numeric check on PIC 9(04)

Postby NicC » Wed Jan 17, 2018 5:04 pm

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.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2805
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 115 times

Re: Numeric check on PIC 9(04)

Postby Vinnie95 » Wed Jan 17, 2018 6:36 pm

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
Vinnie95
 
Posts: 2
Joined: Wed Jan 17, 2018 1:19 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Numeric check on PIC 9(04)

Postby NicC » Wed Jan 17, 2018 6:41 pm

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.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2805
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 115 times

Re: Numeric check on PIC 9(04)

Postby Robert Sample » Wed Jan 17, 2018 11:14 pm

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.
Robert Sample
Global moderator
 
Posts: 3519
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 250 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post