View previous topic :: View next topic
|
Author |
Message |
Amsar
New User
Joined: 26 Sep 2008 Posts: 84 Location: Chennai
|
|
|
|
Hello All,
I have a program for which the input file has some junk value, i am not getting how to handle it in the code, i have tried below code.
Its not working.
Code: |
IF NOT WS-KO-CODE = LOW-VALUES
CONTINUE
ELSE
MOVE SPACES TO WS-KO-CODE
END-IF. |
Value for WS-KO-CODE in hex format.
|
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
What values do you consider "keepers", such as alphabetic letters (upper/lower case), numerics 0-9, etc?
The following code keeps alphabetic letters (upper/lower) as well as numerics 0-9. All other values are converted to spaces. Note, the code uses COBOL Special-Register TALLY, which is perfectly legitimate -
Code: |
03 WS-XLATE-FROM-TBL PIC X(256).
03 WS-XLATE-TO-TBL PIC X(256).
03 WS-SUB PIC 9(008) COMP.
03 WS-SUB-X REDEFINES WS-SUB
PIC X(004).
03 WS-KEEPER-KTR PIC 9(008) COMP.
03 WS-MIXED-KTR PIC 9(008) COMP.
03 WS-BAD-KTR PIC 9(008) COMP.
*
MOVE ZERO TO WS-SUB.
MOVE 1 TO TALLY.
*
PERFORM UNTIL TALLY > LENGTH OF WS-XLATE-FROM-TBL
MOVE WS-SUB-X (4:1) TO WS-XLATE-FROM-TBL (TALLY:1)
ADD 1 TO TALLY
ADD 1 TO WS-SUB
END—PERFORM.
*
MOVE SPACES TO WS-XLATE-TO-TBL.
MOVE ZERO TO WS-KEEPER-KTR.
MOVE ZERO TO WS-MIXED-KTR.
MOVE ZERO TO WS-BAD-KTR.
MOVE WS-XLATE-FROM-TBL (129:)
TO WS-XLATE-TO-TBL (129:9).
MOVE WS-XLATE-FROM-TBL (145:)
TO WS-XLATE-TO-TBL (145:9).
MOVE WS-XLATE-FROM-TBL (162:)
TO WS-XLATE-TO—TBL (162:8).
MOVE WS-XLATE-FROM-TBL (193:)
TO WS-XLATE-TO-TBL (193:9).
MOVE WS-XLATE-FROM-TBL (209:)
TO WS-XLATE-TO-TBL (209:9).
MOVE WS-XLATE-FROM-TBL (226:)
TO WS-XLATE-TO-TBL (226:8).
MOVE WS-XLATE-FROM-TBL (240:)
TO WS-XLATE-TO-TBL (240:10).
MOVE ZERO TO TALLY.
*
INSPECT WS-KO-CODE CONVERTING WS-XLATE-FROM-TBL
TO WS-XLATE-TO-TBL.
*
INSPECT WS-KO-CODE TALLYING TALLY FOR ALL SPACE.
*
EVALUATE TALLY
WHEN < 1
ADD 1 TO WS-KEEPER-KTR
WHEN < LENGTH OF WS-KO-CODE
ADD 1 TO WS-MIXED-KTR
WHEN OTHER
ADD 1 TO WS-BAD-KTR
END-EVALUATE.
|
After the first INSPECT, WS-KO-CODE will contain all SPACES or a mixture of SPACES and legitimate characters or all legitimate characters.
After the second INSPECT, if TALLY is equal to the LENGTH OF WS-KO-CODE (4) then WS-KO-CODE contains non-keepers and were converted to SPACE. If TALLY is equal to ZERO, then all characters are legitimate. IF TALLY equals 1, 2 or 3, then it contains a mixture of legitimate and non-legitimate (SPACES) characters, either interspersed or sequential.
HTH.... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
There is no such thing as a junk value in COBOL. Every byte has a value from the 256 possible values of the EBCDIC collating sequence. Whether or not that value is one you expected, that is a different question.
The data you posted indicates the variable contained SPACES, not LOW-VALUES. Spaces are X'40' and LOW-VALUES are X'00'. Since you did not indicates what are the good data values for your variable, you might implement Bill's solution. |
|
Back to top |
|
|
Karthikeyan Subbarayan
New User
Joined: 24 Feb 2008 Posts: 62 Location: Boston
|
|
|
|
I am not clear, even Bill is proposing to make spaces which are already having space in the field WS-KO-CODE.
Do having spaces is a junk value? |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
For those values which you consider to be "junk", what value (if at all) would you like them to be converted? An example would be X'00' converts to X'40'.
If WS-KO-CODE contains values which are partial or totally "junk", what do you need to do with the contents?
Do you write these exceptions to a report? (you'll need to convert the contents of WS-KO-CODE to 8-bytes of displayable-hex, which is not too difficult).
Please advise.... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Do having spaces is a junk value? |
No - as has been explained There Are No Junk Values. Suggest you lose the term "junk values". Some around you may believe this sounds "cool" but it surely is not.
You need to establish (or obtain) the data rules - then enforce them. By whatever code is needed. If the processing is to continue when invalid data is encountered, you need to define the replacement/default value that will be substituted for the invalid value. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Are Amsar (OP) and 'Karthikeyan Subbarayan' following-on on the same problem...? |
|
Back to top |
|
|
Karthikeyan Subbarayan
New User
Joined: 24 Feb 2008 Posts: 62 Location: Boston
|
|
|
|
Thanks for correcting me !! |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome
Several of us work hard to improve the terms used.
d |
|
Back to top |
|
|
|