Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

how to find an invalid hex character from a given string

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: how to find an invalid hex character from a given string
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: 7913
Location: Bellevue, IA

PostPosted: Wed Mar 19, 2014 2:52 pm    Post subject:
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Mar 19, 2014 4:38 pm    Post subject: Reply to: how to find an invalid hex character from a given
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    Post subject:
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: 1715
Location: UK

PostPosted: Wed Mar 19, 2014 5:57 pm    Post subject: Reply to: how to find an invalid hex character from a given
Reply with quote

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

Site Director


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

PostPosted: Wed Mar 19, 2014 6:50 pm    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Mar 19, 2014 7:21 pm    Post subject: Reply to: how to find an invalid hex character from a given
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: 1219
Location: Israel

PostPosted: Wed Mar 19, 2014 8:20 pm    Post subject: Reply to: how to find an invalid hex character from a given
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: 641
Location: Whitby, ON, Canada

PostPosted: Wed Mar 19, 2014 10:49 pm    Post subject: Re: Reply to: how to find an invalid hex character from a gi
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

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Thu Mar 20, 2014 1:12 am    Post subject:
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    Post subject:
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: 1219
Location: Israel

PostPosted: Thu Mar 20, 2014 6:11 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to find the first monday of the w... abdulrafi COBOL Programming 10 Fri Nov 25, 2016 3:24 pm
No new posts Find out a active PGM jpsager JCL & VSAM 10 Fri Oct 07, 2016 4:32 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
This topic is locked: you cannot edit posts or make replies. DSList (3.4) cannot display Chinese c... jacobdng TSO/ISPF 4 Wed Oct 05, 2016 2:51 pm
No new posts How to find a CICS resource used in C... Arunkumar Chandrasekaran CICS 8 Thu Sep 29, 2016 1:45 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us