Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to replace Unprintable Characters in IBM z/os cobol

Status
Not open for further replies.

jdrewf

Programmer
Apr 18, 2008
2
0
0
US
I had this routine to find and replace Unprintable Characters, but it does not compile under IBM z/os Cobol.

Environment Divison.
Configuration Section.
Special-Names.
class unprintable-char is x'00' thru x'49'
x'51' thru x'59'
x'62' thru x'69'
x'70' thru x'79'
x'80'.
.
.
inspect some-filed replacing all unprintable-char by space.

Any have a routine that works with IBM z/os cobol ?

 
What error message are you getting from the compiler?

I believe that you cannot use a class name (i.e. "UNPRINTABLE-CHAR") as you have in the INSPECT statement.

According to my manuals, you can only use the class name you have defined in a class condition test.

In other words, you might try something like the following:
Code:
PERFORM
    VARYING I FROM 1 BY 1
    UNTIL   I > LENGTH OF some-filed
        IF  some-filed (I:1) IS unprintable-char
            MOVE SPACE TO some-filed (I:1)
        END-IF
END-PERFORM

Code what you mean,
and mean what you code!
But by all means post your code!

Razalas
 
Hi JD,

I've used this:
Code:
           INSPECT WS-WORK-UNPACKED CONVERTING
                   X"FAFBFCFDFEFF"  TO  "ABCDEF"
You might want to code your unprintables something like this:
Code:
01  YOUR-FLD   PIC X(??)
01  UNPRTS     PIC X(??) VALUE X'00' THRU X'49' etc.

INSPECT YOUR-FLD CONVERTING
                 UNPRTS  TO  SPACES
You'll notice I used a literal in the 1st example, but used a variable for the 2nd You could use either:

Literals make the pgm more efficient. Only a TR (or is it a TM?) instruction is generated, but it's more coding for you; you can't use THRU when coding an in line literal.

Using a variable generates a CALL to a subpgm.



Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
slade, TR is TRanslate as you suggested, TM is Test under Mask, a completely different function. In older (70s)compilers, the literal did not generate any more efficient code, perhaps it has improved. I'm sure there are even new machine codes.

The INSPECT ... CONVERTING is probably the fastest method and should work with any compiler. One of the last "new" machine codes I discovered in the 70s was MVCR, an implementaion of the REVERSE function in machine code.

With ascii, it's a little easier; just compare less than space, then if you want to get rid of the high characters, compare greater than "~".
 
WR, Yeah, that came to me about 5 mins after I logged out, but thanx for the update, what I was fishing for was translate and test. I don't recall the OP code - TRT?, but you're right, the TR assembler instruction is the one used in INSPECT/CONVERTING.

Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
Jack:
Your 01 level entry "UNPRTS" cannot use the THRU option of the VALUE clause. That's only allowed on an 88 level entry. You need to list all of the values that you want the 01 to contain. Example:

VALUE X'010203040506...'

It could get rather long.
 
You're right, CD; I guess the OP is better off using the in-line literal. At least s/he'll get the preformance payback.

Thanx

Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
Thank you everyone for your input, this has been very helpful.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top