View previous topic :: View next topic
|
Author |
Message |
Susheel singh
New User
Joined: 25 Jul 2013 Posts: 13 Location: INDIA
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Susheel singh
New User
Joined: 25 Jul 2013 Posts: 13 Location: INDIA
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
Susheel singh
New User
Joined: 25 Jul 2013 Posts: 13 Location: INDIA
|
|
|
|
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 |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Errors are not "thrown". You raise an error. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
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. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3049 Location: NYC,USA
|
|
|
|
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 |
|
|
Susheel singh
New User
Joined: 25 Jul 2013 Posts: 13 Location: INDIA
|
|
|
|
THANKS ALL FOR THE SUGGESSTIONS.
ESPECIALLY marso......... |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
|