COBOL User Groups COBOL COBOL Programming
Home | Search | Join COBUG | Call for User Group Leaders | Contact | About
COBOL Jobs | Submit Resumes | Post Jobs | COBOL Forums | Advertise with us

COBOL Resources

 >  Blogs
 >  Books
 >  Code Samples
 >  Courses
 >  Forums
 >  Knowledge Bases
 >  Magazines
 >  Manuals
 >  Portals
 >  Support
 >  Tutorials
 >  User Groups
 >  White Papers

COBOL Software

 >  Change Management
 >  Code Conversion
 >  Compilers
 >  Data Access
 >  Database
 >  Documentation
 >  Editors
 >  File Conversion
 >  GUI
 >  Modernization
 >  Report Generators
 >  Sort
 >  Terminal Emulators
 >  Test
 >  Tools
 >  Trans. Processing

COBOL Information

 >  Events
 >  Job Resources
 >  News Articles
 >  Newsletters
 >  Product News
 >  Standards

Support COBUG

COBOL Donation
 

COBOL Forums

 
COBOL Language [ return ]
From Message
rampras

 Email

4/05/2006
07:31:40
Subject: Tracking invalid chars in COBOL.


Message:
Hello,

I wanna track the invalid characters in a given string and replace them with spaces.
These invalid chars are non-displayable (displayed as a dot (.) in browse mode) chars. It can be a char other than valid chars on the keyboard.

I could think of two approaches...but there are issues with both and do not meet my requirement.

Approach 1:

1. Create CLASS A in SPECIAL-NAMES in configuration section and code all valid characters (Alphabets, numerics and special characters).
2. Extract the input string, character by character and iterate step-3 for each character.
3. Check if current character is equal to class A. If yes, continue with the next character. If no, replace the character in the input string with space.

Issues with Approach 1:

We'll have to identify all valid characters the string can have including the displayable characters that gets printed when combination of keys are pressed (Eg: Alt + 4, 5 and 6 = ╚ which is NOT an undisplayable invalid character and hence have to be included in the speaial names clause...its tedious...).

Approach 2:

Code an SQL to retreive and store the COBOL HEX value of each character in the column in a host variable. Check if the host variable is equal to '0D' (x'0D'). If yes, move spaces to the position in the string. Please refer the SQL below:

1. READ would retreive the so-comments and store it in host variable.
2. For counter <= length of the column
3. SELECT HEX(SUBSTR(column,COUNTER))
INTO :WS-HEX-VALUE
FROM table
4. Increment the counter.
5. Check if WS-HEX-VALUE = '0D'. If true, move spaces to the host variable WS-column(counter,1).

Issues with Approach 2:

x'0D' is not the only invalid character, though commonly occuring. Hence, invalid characters other than x'0D' would not be scanned by the above approach. Please note that it is not possible to list out possible hex values of invalid characters.

Experts, please help !!


rpquin

4/05/2006
08:10:30
Registration in COBOL.


Message:
Dear Sirs;
I am very interested in participating in your forums; please activate my account.
Thanks
Ricardo Palomino


JWL

4/06/2006
01:45:59
RE: Tracking invalid chars in COBOL.


Message:
Hi,

The easiest way to handle this, would be to have a table with 256 entries containing the character for each value in the Ascii character set. Unprintable characters would contain a space.

Using the binary value of each character in the string, get the printable character from the table.

01 HEX-TABLE
03 ASCII-CHAR PIC X(01) OCCURS 256.

Binary 00 thru 1F, 7F and FF would would each contain space. All other characters are printable, depending on the font being used. If you do not require any of these characters, use a space for the printable character.

Define something similar to

77 DEC-CHR-VAL PIC 9(05) COMP-0

01 CONVERT-X.
03 BIN-CHR PIC 9(02) COMP-X.
03 ASCII-CHR REDEFINES BIN-CHR PIC X(01).

Perform a procedure to replace the characters.

I will use SUB as the position of the character in the string and use CHARACTER to represent the character being checked. VARY SUB FROM 1 TO length of STRING OR use until SUB > length.

Procedure would be something like this

* character currently being checked

MOVE CHARACTER(SUB) TO ASCII-CHR

* convert from binary to decimal

MOVE BIN-CHR TO DEC-CHR-VAL

* as first value is zero add 1 to decimal value to get the correct location in the table

ADD 1 TO DEC-CHR-VAL

* move printable character to string

MOVE ASCII-CHAR(DEC-CHR-VAL) TO CHARACTER(SUB)

* increment subscript

ADD 1 T0 SUB

Hope this helps.

Regards
jwl



rampras

4/11/2006
05:02:17
RE: Tracking invalid chars in COBOL.


Message:
JWL,

Thanks for your prompt response.

As per my understanding of your logic, I changed the "COMP-X" you had mentioned to "COMP" (Bin) and "COMP-0" to COMP-3 (packed dec).

1. I have the ASCII table declared like below:

01 TABLE-OF-DATA.
05 HEX-00 PIC X(4) VALUE '00.0'.
05 HEX-01 PIC X(4) VALUE '01.0'.
05 HEX-02 PIC X(4) VALUE '02.0'.
05 HEX-03 PIC X(4) VALUE '03.0'.
05 HEX-04 PIC X(4) VALUE '04.0'.
05 HEX-05 PIC X(4) VALUE '05.0'.
05 HEX-06 PIC X(4) VALUE '06.0'.
05 HEX-07 PIC X(4) VALUE '07.0'.
05 HEX-08 PIC X(4) VALUE '08.0'.
05 HEX-09 PIC X(4) VALUE '09.0'.
05 HEX-0A PIC X(4) VALUE '0A.0'.
05 HEX-0B PIC X(4) VALUE '0B.0'.
05 HEX-0C PIC X(4) VALUE '0C.0'.
05 HEX-0D PIC X(4) VALUE '0D.0'.
..
..
05 HEX-66 PIC X(4) VALUE '66f1'.
05 HEX-67 PIC X(4) VALUE '67g1'.
05 HEX-68 PIC X(4) VALUE '68h1'.
05 HEX-69 PIC X(4) VALUE '69i1'.
05 HEX-6A PIC X(4) VALUE '6Aj1'.
05 HEX-6B PIC X(4) VALUE '6Bk1'.
05 HEX-6C PIC X(4) VALUE '6Cl1'.
05 HEX-6D PIC X(4) VALUE '6Dm1'.
..
..
till FF.


The last char (0 or 1) would mean Invalid (0) or Valid (1).

2. I have the following piece (your MASTER logic, really).

01 WS-DEC-CHR-VAL PIC 9(05) COMP-3.
01 WS-CONVERT-X.
03 BIN-CHR PIC 9(02) COMP.
03 EBCDIC-CHR REDEFINES BIN-CHR
PIC X(01).


3. I have this in procedure div:

PERFORM 014-PROCESS-PARA THRU
014-PROCESS-PARA-EXIT
VARYING WS-COUNT FROM 1 BY 1
UNTIL WS-COUNT > 64. ==> Becos my string is of length 64, as of now.

MOVE WS-DESCRIPTION(WS-COUNT:1) TO EBCDIC-CHR.
MOVE BIN-CHR TO WS-DEC-CHR-VAL.

ADD 1 TO WS-DEC-CHR-VAL.

DISPLAY 'LAST VAL ' TAB-X1(WS-DEC-CHR-VAL)(4:1).

IF (TAB-X1(WS-DEC-CHR-VAL)(4:1)) = 0
DISPLAY ' INVALID CHAR FOUND '
DISPLAY WS-DESCRIPTION(WS-COUNT:1)
MOVE SPACES TO WS-DESCRIPTION(WS-COUNT:1)

Now, even for Invalid input chars, the IF statement is not getting satisfied. I beleive, the problem would be: The cardinality of TAB-X1 is 256 and that the length of DEC-CHR-VAL is 9(5) COMP-3. I am not sure if we can use 9(5) comp-3 as the index value of TAB-X1. I guess, thats causing the problem. Please advice !!

Thanks once again for the wonderful thought. I was thinking it would be complex to acheive and now that I am realising it would be simpler.

Regards,
Ram.



P 1 Next Page >>


 
[ Go to Top of Page ]
COBOL NuTrak Ad



Local COBOL User Groups
COBOL User Group Check out the list of local COBOL user groups from around the world and join a user group near you.


Call for User Group Leaders!
COBOL User Groups Get Involved! We are looking for user group leaders to help organize and coordinate a local COBOL user group.

Join COBUG!
COBOL User Groups Become a part of the COBUG community today. Join Now ...


COBOL Forums
COBOL Forum Try our forums for help!
Let the COBUG members help you. Post your issues!



COBOL Job Resources
COBOL Jobs Here are references to a wealth of job resources, including job listing sites, resume preparation, and interview questions.


Job and Resume Matchmaker!
COBOL Jobs Employers submit your COBOL job openings. Job seekers submit your resumes.

COBOL (c) Information Computing Services. All Rights Reserved. COBOL