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

how to find an invalid hex character from a given string


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

New User


Joined: 25 Jul 2013
Posts: 13
Location: INDIA

PostPosted: Wed Mar 19, 2014 1:46 pm
Reply with quote

Hi,

i have a requirement to inspect a string and if it contains invalid hex characters display error.

i tried using inspect with tallying but its not working.

can anyone tell me how can i acheive this in COBOL-IMS.


Thanks
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Mar 19, 2014 2:52 pm
Reply with quote

I love your title!
THERE IS NO SUCH THING AS "AN INVALID HEX CHARACTER"!
A hex character is one of the 256 EBCDIC characters -- and since that covers every possible character, none of them can be invalid.

So why don't you start over and tell us -- in detail -- what you are wanting to do, the results you are getting, and the results you want.
Back to top
View user's profile Send private message
Susheel singh

New User


Joined: 25 Jul 2013
Posts: 13
Location: INDIA

PostPosted: Wed Mar 19, 2014 3:19 pm
Reply with quote

hehehee.........sorry for the confusion. i just wanted to say that for some hex characters i wanted to throw error.

for example, i want X'40' but i dont want X'41'. So if i have given an input string which contains X'41' then it should throw an error. and if i have given an input string which has X'40' then it should accept it and should not throw an error.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Mar 19, 2014 4:38 pm
Reply with quote

If you were to find a X'41' (or some other hex-byte which you've determined to be invalid), would you be willing to overlay a X'41' with an obscure replacement value? If so, what value would that be?

An INSPECT could be used, but do you need to know the position (and value) of the rogue hex-byte in the INSPECT target-area?

Other than an INSPECT, an in-line PERFORM could also be used.

Please advise....
Back to top
View user's profile Send private message
Susheel singh

New User


Joined: 25 Jul 2013
Posts: 13
Location: INDIA

PostPosted: Wed Mar 19, 2014 5:53 pm
Reply with quote

As per my requirement, valid characters are any character that can be typed from a keyboard and is visible on the screen . Apart from this for any other character it should throw an error.

For example, i want to validate the non-printable values like " âìÎâ " and display error is they occur in input.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Wed Mar 19, 2014 5:57 pm
Reply with quote

Errors are not "thrown". You raise an error.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Mar 19, 2014 6:50 pm
Reply with quote

Hello,

One way to get what you want is to create a table of all of the valid values and it the byte being looked at is not one of these, raise the error.

I suspect there are less valid values than invalid values.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Mar 19, 2014 7:21 pm
Reply with quote

Here's some example code (UNTESTED) -

Code:

           03  WS-SUB              PIC  9(08)      BINARY.             
           03  WS-SUB-X            REDEFINES WS-SUB                     
                                   PIC  X(04).                         
           03  WS-PACKED-X.                                             
               05  WS-PACKED       PIC  9(01)V9    PACKED-DECIMAL.     
           03  WS-DISPLAY-X.                                           
               05  WS-DISPLAY-V9   PIC  9(02)V9.                       
               05  WS-DISPLAY      REDEFINES WS-DISPLAY-V9             
                                   PIC  9(03).                         
           03  WS-DISPLAY-MSG      PIC  X(80).                         
           03  WS-XLATE-FROM-TBL   PIC  X(256).                         
           03  WS-XLATE-TO-TBL     PIC  X(256).                         
           03  WS-STRING           PIC  X(256).                         
      *                                                                 
           MOVE 1                      TO TALLY.                       
           MOVE ZERO                   TO WS-SUB.                       
      *                                                                 
      **** BUILD THE 'FROM-TBL' WITH HEX-ENTRIES (X'00' THRU X'FF')     
      *                                                                 
           PERFORM UNTIL TALLY > LENGTH OF WS-XLATE-FROM-TBL           
               MOVE WS-SUB-X (4:)      TO WS-XLATE-FROM-TBL (TALLY:1)   
               ADD  1                  TO TALLY                         
               ADD  1                  TO WS-SUB                       
           END-PERFORM.                                                 
      *                                                                 
      **** BUILD THE 'TO-TBL', LEGITIMISING LOWER-CASE AND UPPER-CASE   
      **** LETTERS AS WELL AS NUMERICS 0-9.                             
      *                                                                 
           MOVE SPACES                 TO WS-XLATE-TO-TBL.             
           MOVE ZERO                   TO WS-SUB.                       
           MOVE X'81'                  TO WS-SUB-X (4:).               
           MOVE WS-XLATE-FROM-TBL (WS-SUB:9)                           
                                       TO WS-XLATE-TO-TBL (WS-SUB:9).   
           MOVE X'91'                  TO WS-SUB-X (4:).               
           MOVE WS-XLATE-FROM-TBL (WS-SUB:9)                           
                                       TO WS-XLATE-TO-TBL (WS-SUB:9).   
           MOVE X'A2'                  TO WS-SUB-X (4:).               
           MOVE WS-XLATE-FROM-TBL (WS-SUB:8)                           
                                       TO WS-XLATE-TO-TBL (WS-SUB:8).   
           MOVE 'A'                    TO WS-SUB-X (4:).                             
           MOVE WS-XLATE-FROM-TBL (WS-SUB:9)                           
                                       TO WS-XLATE-TO-TBL (WS-SUB:9).   
           MOVE 'J'                    TO WS-SUB-X (4:).               
           MOVE WS-XLATE-FROM-TBL (WS-SUB:9)                           
                                       TO WS-XLATE-TO-TBL (WS-SUB:9).   
           MOVE 'S'                    TO WS-SUB-X (4:).               
           MOVE WS-XLATE-FROM-TBL (WS-SUB:8)                           
                                       TO WS-XLATE-TO-TBL (WS-SUB:8).   
           MOVE ZERO                   TO WS-SUB-X (4:).               
           MOVE WS-XLATE-FROM-TBL (WS-SUB:10)                           
                                       TO WS-XLATE-TO-TBL (WS-SUB:10). 
           MOVE WS-XLATE-FROM-TBL      TO WS-STRING.                   
      *                                                                 
      **** RETAIN ONLY THE LOWER-CASE AND UPPER-CASE LETTERS AS WELL AS
      **** NUMERICS 0-9. ALL OTHER STRING-POSITIONS ARE CONVERTED TO   
      **** SPACE X'40'.                                                 
      *                                                                 
           INSPECT WS-STRING           CONVERTING WS-XLATE-FROM-TBL     
                                       TO WS-XLATE-TO-TBL.             
      *                                                                 
      **** DISPLAY EACH STRING-POSITION WITH ITS INVALID HEX-VALUE     
      **** CONVERTED TO READABLE-HEX.                                   
      *                                                                 
           MOVE 1                      TO WS-SUB.                       
           MOVE ZERO                   TO WS-PACKED.                   
           MOVE 'STRING-POSITION 000 = X''00'''                         
                                       TO WS-DISPLAY-MSG.               
      *                                                                 
           DISPLAY SPACE.                                               
      *                                                                 
           PERFORM UNTIL WS-SUB > LENGTH OF WS-STRING                   
               IF  WS-STRING (WS-SUB:1) = SPACE                         
                   MOVE WS-XLATE-FROM-TBL (WS-SUB:1)                   
                                        TO WS-PACKED-X (1:1)           
                   MOVE WS-PACKED       TO WS-DISPLAY-V9               
                   INSPECT WS-DISPLAY-X CONVERTING X'FAFBFCFDFEFF'     
                                        TO 'ABCDEF'                     
                   MOVE WS-DISPLAY-X    TO WS-DISPLAY-MSG (25:2)       
                   MOVE WS-SUB          TO WS-DISPLAY                   
                   MOVE WS-DISPLAY-X    TO WS-DISPLAY-MSG (17:3)       
                   DISPLAY WS-DISPLAY-MSG                                                                             
               END-IF                                                   
               ADD  1                   TO WS-SUB                       
           END-PERFORM.                                                 
      *                                                                 
           DISPLAY SPACE.                                               

HTH....
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Wed Mar 19, 2014 8:20 pm
Reply with quote

My favorite method is to use:
Code:
       CONFIGURATION SECTION.
       SPECIAL-NAMES.
           CLASS VALID-CHARSET IS 'A' THROUGH 'I' 'J' THROUGH 'R'
                               'S' THROUGH 'Z' '0' THROUGH '9'       
                               ' !@#$%¢&*()_-=¬¦\{}|:"<>?/.,'.

and then
Code:
           IF my-field IS VALID-CHARSET THEN             
               DISPLAY 'my-field is a VALID-CHARSET'     
           ELSE                                                 
               DISPLAY 'my-field is not a VALID-CHARSET'
           END-IF                                               
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Wed Mar 19, 2014 10:49 pm
Reply with quote

Nic Clouston wrote:
Errors are not "thrown". You raise an error.

Agree. Mainframe programs do not "throw" errors. Though if they did they would throw them faster and more reliably than programs running on other platforms. icon_biggrin.gif
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Thu Mar 20, 2014 1:12 am
Reply with quote

I do follow with Marso and instead of checking for invalid Hex character you can also check for all valid characters and do the error handling.
Back to top
View user's profile Send private message
Susheel singh

New User


Joined: 25 Jul 2013
Posts: 13
Location: INDIA

PostPosted: Thu Mar 20, 2014 3:36 pm
Reply with quote

THANKS ALL FOR THE SUGGESSTIONS.

ESPECIALLY marso......... icon_biggrin.gif
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Mar 20, 2014 6:11 pm
Reply with quote

Welcome!
Of course, in the CLASS statement you can add or remove any characters you want
Here is another example:
Code:
           CLASS VALID-CHARSET IS 'A' THROUGH 'I' 'J' THROUGH 'R'
                               'S' THROUGH 'Z' '0' THROUGH '9'       
                               'a' THROUGH 'i' 'j' THROUGH 'r'
                               's' THROUGH 'z' '!():"?.,'
                               SPACE QUOTE LOW-VALUE.
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Find the size of a PS file before rea... COBOL Programming 13
Search our Forums:

Back to Top