View previous topic :: View next topic
|
Author |
Message |
srinut123
New User
Joined: 11 Oct 2005 Posts: 62 Location: India
|
|
|
|
Hi
Requirement: I've to replace all non printable characters with spaces.
Can any one help?
Thanks
SRK |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Use reference modification to look at each character; if it is a "non printable character" (whatever that means to you), change it. The process will run slow since you're looking at every byte, but it's very standard code. There are examples of very similar code on the forum already. |
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
I have done this on many occasions by coding two 256-byte working storage elements - the first containing All of the 256 possible byte values ( x'00' thru x'FF' ), and the second containing the same, except for replacing each "non-printable" position with x'40' - and then using the INSPECT source-field CONVERTING source-values TO target-values. The execution is very fast if the source-field is less than 257 bytes - slower if greater than 256 since it requires looping under the covers. Here's the code:
Code: |
In Working Storage:
01 SOURCE-VALUES.
05 PIC X(16) VALUE X'000102030405060708090A0B0C0D0E0F'.
05 PIC X(16) VALUE X'101112131415161718191A1B1C1D1E1F'.
05 PIC X(16) VALUE X'202122232425262728292A2B2C2D2E2F'.
05 PIC X(16) VALUE X'303132333435363738393A3B3C3D3E3F'.
05 PIC X(16) VALUE X'404142434445464748494A4B4C4D4E4F'.
05 PIC X(16) VALUE X'505152535455565758595A5B5C5D5E5F'.
05 PIC X(16) VALUE X'606162636465666768696A6B6C6D6E6F'.
05 PIC X(16) VALUE X'707172737475767778797A7B7C7D7E7F'.
05 PIC X(16) VALUE X'808182838485868788898A8B8C8D8E8F'.
05 PIC X(16) VALUE X'909192939495969798999A9B9C9D9E9F'.
05 PIC X(16) VALUE X'A0A1A2A3A4A5A6A7A8A9AAABACADAEAF'.
05 PIC X(16) VALUE X'B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF'.
05 PIC X(16) VALUE X'C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF'.
05 PIC X(16) VALUE X'D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF'.
05 PIC X(16) VALUE X'E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF'.
05 PIC X(16) VALUE X'F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF'.
01 TARGET-VALUES.
05 PIC X(16) VALUE X'40404040404040404040404040404040'.
05 PIC X(16) VALUE X'40404040404040404040404040404040'.
05 PIC X(16) VALUE X'40404040404040404040404040404040'.
05 PIC X(16) VALUE X'40404040404040404040404040404040'.
05 PIC X(16) VALUE X'404040404040404040404A4B4C4D4E4F'.
05 PIC X(16) VALUE X'504040404040404040405A5B5C5D5E5F'.
05 PIC X(16) VALUE X'606140404040404040406A6B6C6D6E6F'.
05 PIC X(16) VALUE X'404040404040404040797A7B7C7D7E7F'.
05 PIC X(16) VALUE X'40818283848586878889404040404040'.
05 PIC X(16) VALUE X'40919293949596979899404040404040'.
05 PIC X(16) VALUE X'40A1A2A3A4A5A6A7A8A9404040404040'.
05 PIC X(16) VALUE X'40404040404040404040404040404040'.
05 PIC X(16) VALUE X'C0C1C2C3C4C5C6C7C8C9404040404040'.
05 PIC X(16) VALUE X'D0D1D2D3D4D5D6D7D8D9404040404040'.
05 PIC X(16) VALUE X'E040E2E3E4E5E6E7E8E9404040404040'.
05 PIC X(16) VALUE X'F0F1F2F3F4F5F6F7F8F9404040404040'.
In Procedure Division
INSPECT source-field CONVERTING SOURCE-VALUES TO TARGET-VALUES
|
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Another way to do this is to use the input value as the displacement into the "target array" and simply "move" the target value to the output byte. It would require a loop to process the input string.
This may (or may not) use less cpu cycles than the inspect. It has been too long since i did any timing testing on something like this for me to say positively. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
A pre-defined translate-table is often defined in a shop, which contains all 256-byte values and can be accessed from both Batch and CICS. This table is Assembled and Linked as if it were a plain-jane Batch Assembler program. It would be incorrect to run this through the CICS translator and then Assembling/Linking it as a CICS/Assembler program -
Code: |
TRANSTBL CSECT
DC 256AL1(*-TRANSTBL) CREATE ALL ENTRIES, X'00' - X'FF'
TRANSTBL AMODE 31
TRANSTBL RMODE ANY
END
|
Assuming this is Batch (don't EVER use the following technique in CICS) you can keep the previously defined TARGET-VALUES group (these are the keepers) and define the SOURCE-VALUES group simply as -
Code: |
01 SOURCE-VALUES PIC X(256).
|
Then define the following -
Code: |
WORKING-STORAGE SECTION.
01 WS-MISCELLANEOUS.
03 WS-PROCEDURE-POINTER PROCEDURE-POINTER.
03 FILLER REDEFINES WS-PROCEDURE-POINTER.
05 WS-LOAD-POINT POINTER.
05 FILLER PIC X(04).
03 WS-TRANSTBL PIC X(08) VALUE 'TRANSTBL'.
LINKAGE SECTION.
01 LS-TRANSTBL-DSECT PIC X(256).
PROCEDURE DIVISION.
*
SET WS-PROCEDURE-POINTER TO ENTRY WS-TRANSTBL.
SET ADDRESS OF LS-TRANSTBL-DSECT TO WS-LOAD-POINT.
MOVE LS-TRANSTBL-DSECT TO SOURCE-VALUES.
|
You've now loaded the pre-defined/static Assembler TRANSTBL into memory, established addressability to the LINKAGE SECTION "DSECT" assigned to TRANSTBL and moved the contents of the "DSECT" (values X'00' through X'FF') to the WS 01-level SOURCE-VALUES. In fact, SOURCE-VALUES can be considered optional as your FROM-TBL data can be found in LS-TRANSTBL-DSECT.
PROCEDURE-POINTER was introduced with COBOL/370, nearly 20 years ago and if you're using COBOL2 (or OS/VS COBOL for that matter), then this technique won't work and you'd need to Call an Assembler sub-program, which issues an MVS LOAD Macro, to mimic a PROCEDURE-POINTER.
Note that the COBOL Batch program must have been compiled with the compiler option DYNAM, which is typically used in Batch.
Having a pre-defined/static TRANSTBL in a shop's utility arsenal removes the redundancy of having to code this table in every program where it's needed.
FWIW, CICS access is performed via a "LOAD PROGRAM" API.
Bill |
|
Back to top |
|
|
srinut123
New User
Joined: 11 Oct 2005 Posts: 62 Location: India
|
|
|
|
Many Thanks for your inputs. |
|
Back to top |
|
|
essence21
New User
Joined: 05 Dec 2008 Posts: 20 Location: mumbai
|
|
|
|
Ronald , i tried ur method but while compilation it gives below error:
Can you please help out?
IGYPA3097-S
IDENTIFIER "WS-SOURCE (GROUP)" WAS NEITHER AN ELEMENTARY ITEM WITH "USAGE DISPLAY", "USAGE DISPLAY-1" OR "USAGE NATIONAL" NOR AN ALPHANUMERIC OR NATIONAL FUNCTION. THE STATEMENT WAS DISCARDED.
IGYPA3097-S
IDENTIFIER "WS-TARGET (GROUP)" WAS NEITHER AN ELEMENTARY ITEM WITH "USAGE DISPLAY", "USAGE DISPLAY-1" OR "USAGE NATIONAL" NOR AN ALPHANUMERIC OR NATIONAL FUNCTION. THE STATEMENT WAS DISCARDED. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10886 Location: italy
|
|
|
|
nobody can help You out because...
You did not use the code posted as is,
You did not post the code used ! |
|
Back to top |
|
|
essence21
New User
Joined: 05 Dec 2008 Posts: 20 Location: mumbai
|
|
|
|
here's the code used
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. SMPLEUC.
AUTHOR. XXXX.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-3390.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-DATA PIC X(50) VALUE
'ABÄÆm|JKLOMM'.
01 WS-SOURCE.
05 PIC X(16) VALUE X'000102030405060708090A0B0C0D0E0F'.
05 PIC X(16) VALUE X'101112131415161718191A1B1C1D1E1F'.
05 PIC X(16) VALUE X'202122232425262728292A2B2C2D2E2F'.
05 PIC X(16) VALUE X'303132333435363738393A3B3C3D3E3F'.
05 PIC X(16) VALUE X'404142434445464748494A4B4C4D4E4F'.
05 PIC X(16) VALUE X'505152535455565758595A5B5C5D5E5F'.
05 PIC X(16) VALUE X'606162636465666768696A6B6C6D6E6F'.
05 PIC X(16) VALUE X'707172737475767778797A7B7C7D7E7F'.
05 PIC X(16) VALUE X'808182838485868788898A8B8C8D8E8F'.
05 PIC X(16) VALUE X'909192939495969798999A9B9C9D9E9F'.
05 PIC X(16) VALUE X'A0A1A2A3A4A5A6A7A8A9AAABACADAEAF'.
05 PIC X(16) VALUE X'B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF'.
05 PIC X(16) VALUE X'C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF'.
05 PIC X(16) VALUE X'D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF'.
05 PIC X(16) VALUE X'E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF'.
05 PIC X(16) VALUE X'F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF'.
01 WS-TARGET
05 PIC X(16) VALUE X'40404040404040404040404040404040'.
05 PIC X(16) VALUE X'40404040404040404040404040404040'.
05 PIC X(16) VALUE X'40404040404040404040404040404040'.
05 PIC X(16) VALUE X'40404040404040404040404040404040'.
05 PIC X(16) VALUE X'404040404040404040404A4B4C4D4E4F'.
05 PIC X(16) VALUE X'504040404040404040405A5B5C5D5E5F'.
05 PIC X(16) VALUE X'606140404040404040406A6B6C6D6E6F'.
05 PIC X(16) VALUE X'404040404040404040797A7B7C7D7E7F'.
05 PIC X(16) VALUE X'40818283848586878889404040404040'.
05 PIC X(16) VALUE X'40919293949596979899404040404040'.
05 PIC X(16) VALUE X'40A1A2A3A4A5A6A7A8A9404040404040'.
05 PIC X(16) VALUE X'40404040404040404040404040404040'.
05 PIC X(16) VALUE X'C0C1C2C3C4C5C6C7C8C9404040404040'.
05 PIC X(16) VALUE X'D0D1D2D3D4D5D6D7D8D9404040404040'.
05 PIC X(16) VALUE X'E040E2E3E4E5E6E7E8E9404040404040'.
05 PIC X(16) VALUE X'F0F1F2F3F4F5F6F7F8F9404040404040'.
PROCEDURE DIVISION.
A000-MAIN-CONTROL SECTION.
DISPLAY 'BEFORE: ' WS-DATA
INSPECT WS-DATA CONVERTING WS-SOURCE TO WS-TARGET
DISPLAY 'AFTER: ' WS-DATA
STOP RUN
.
A000-EXIT.
EXIT.
|
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Which compiler is being used?
This is printed at the top of a compilation. |
|
Back to top |
|
|
essence21
New User
Joined: 05 Dec 2008 Posts: 20 Location: mumbai
|
|
|
|
Not sure if this is it...
1PP 5655-S71 IBM ENTERPRISE COBOL FOR Z/OS 4.1.0 CS12 |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
essence21 wrote: |
Not sure if this is it...
1PP 5655-S71 IBM ENTERPRISE COBOL FOR Z/OS 4.1.0 CS12 |
Then, Ron's code should work as the minimum COBOL version/release is VS/COBOL II, over 20+ years ago.
Bill |
|
Back to top |
|
|
essence21
New User
Joined: 05 Dec 2008 Posts: 20 Location: mumbai
|
|
|
|
Apparently something is going wrong somewhere by me and i am not able to spot it |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Note that (based upon your posted code), the WS-TARGET 01-Level does not have a delineating period, which should raise an "E" level error during compilation.
Otherwise, everything else looks fine....
Bill |
|
Back to top |
|
|
essence21
New User
Joined: 05 Dec 2008 Posts: 20 Location: mumbai
|
|
|
|
Nope .. Just put in a period and tried again.. No luck... |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
from the compiler output,
what does the OPTIONS page look like.
(cut&paste, please). |
|
Back to top |
|
|
essence21
New User
Joined: 05 Dec 2008 Posts: 20 Location: mumbai
|
|
|
|
I hope you mean this:
OPTIONS IN EFFECT:
NOADATA
ADV
APOST
ARITH(COMPAT)
NOAWO
BUFSIZE(16384)
NOCICS
CODEPAGE(1146)
NOCOMPILE(S)
NOCURRENCY
DATA(31)
NODATEPROC
NODBCS
NODECK
NODIAGTRUNC
NODLL
NODUMP
NODYNAM
NOEXIT
NOEXPORTALL
NOFASTSRT
FLAG(I,E)
NOFLAGSTD
INTDATE(ANSI)
LANGUAGE(UE)
LIB
LINECOUNT(60)
LIST
MAP
NOMDECK
NONAME
NSYMBOL(DBCS)
NONUMBER
NUMPROC(NOPFD)
OBJECT
NOOFFSET
NOOPTIMIZE
OUTDD(SYSOUT)
PGMNAME(COMPAT) TEST(NOHOOK,SEPARATE,NOEJPD)
NOTHREAD
TRUNC(OPT)
NOVBREF
WORD(TBL1)
XMLPARSE(XMLSS)
XREF(FULL)
YEARWINDOW(1900)
ZWB
RENT
RMODE(AUTO)
NOSEQUENCE
SIZE(MAX)
SOURCE
SPACE(1)
NOSQL
SQLCCSID
NOSSRANGE
NOTERM
TEST(NOHOOK,SEPARATE,NOEJPD) |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
do the errors reference the INSPECT statement? |
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
Sorry about that. I "wrote" the code by memory rather than by cut/paste.
The SOURCE-VALUES and TARGET-VALUES data items MUST be elementary items - not group items (as was the case in my first code example ). The code should be corrected to mirror this example (note the lines that redefine the source/target values).
Code: |
In Working Storage:
01 CONVERSION-TABLES.
05 SOURCE-BYTES.
03 PIC X(16) VALUE X'000102030405060708090A0B0C0D0E0F'.
03 PIC X(16) VALUE X'101112131415161718191A1B1C1D1E1F'.
03 PIC X(16) VALUE X'202122232425262728292A2B2C2D2E2F'.
03 PIC X(16) VALUE X'303132333435363738393A3B3C3D3E3F'.
03 PIC X(16) VALUE X'404142434445464748494A4B4C4D4E4F'.
03 PIC X(16) VALUE X'505152535455565758595A5B5C5D5E5F'.
03 PIC X(16) VALUE X'606162636465666768696A6B6C6D6E6F'.
03 PIC X(16) VALUE X'707172737475767778797A7B7C7D7E7F'.
03 PIC X(16) VALUE X'808182838485868788898A8B8C8D8E8F'.
03 PIC X(16) VALUE X'909192939495969798999A9B9C9D9E9F'.
03 PIC X(16) VALUE X'A0A1A2A3A4A5A6A7A8A9AAABACADAEAF'.
03 PIC X(16) VALUE X'B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF'.
03 PIC X(16) VALUE X'C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF'.
03 PIC X(16) VALUE X'D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF'.
03 PIC X(16) VALUE X'E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF'.
03 PIC X(16) VALUE X'F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF'.
05 SOURCE-VALUES REDEFINES SOURCE-BYTES PIC X(256).
05 TARGET-BYTES.
03 PIC X(16) VALUE X'40404040404040404040404040404040'.
03 PIC X(16) VALUE X'40404040404040404040404040404040'.
03 PIC X(16) VALUE X'40404040404040404040404040404040'.
03 PIC X(16) VALUE X'40404040404040404040404040404040'.
03 PIC X(16) VALUE X'404040404040404040404A4B4C4D4E4F'.
03 PIC X(16) VALUE X'504040404040404040405A5B5C5D5E5F'.
03 PIC X(16) VALUE X'606140404040404040406A6B6C6D6E6F'.
03 PIC X(16) VALUE X'404040404040404040797A7B7C7D7E7F'.
03 PIC X(16) VALUE X'40818283848586878889404040404040'.
03 PIC X(16) VALUE X'40919293949596979899404040404040'.
03 PIC X(16) VALUE X'40A1A2A3A4A5A6A7A8A9404040404040'.
03 PIC X(16) VALUE X'40404040404040404040404040404040'.
03 PIC X(16) VALUE X'C0C1C2C3C4C5C6C7C8C9404040404040'.
03 PIC X(16) VALUE X'D0D1D2D3D4D5D6D7D8D9404040404040'.
03 PIC X(16) VALUE X'E040E2E3E4E5E6E7E8E9404040404040'.
03 PIC X(16) VALUE X'F0F1F2F3F4F5F6F7F8F9404040404040'.
05 TARGET-VALUES REDEFINES TARGET-BYTES PIC X(256).
In Procedure Division
INSPECT source-field CONVERTING SOURCE-VALUES TO TARGET-VALUES. |
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Ronald Burr,
thanks for the clarification. I spent some time going thru the manual and
missed the part that identifier-6 & 7 had to be elementary items. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
dbzTHEdinosauer wrote: |
Ronald Burr,
thanks for the clarification. I spent some time going thru the manual and
missed the part that identifier-6 & 7 had to be elementary items. |
Dick,
This restriction borders on "nutty". Why would the compiler folks impose this?
Whether it's addressed at a group level or at an elementary level, it's the same address.
I guess they have their reasons.
BTW, I missed this too in the manual.
Bill |
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
Bill O'Boyle wrote: |
This restriction borders on "nutty". Why would the compiler folks impose this?
Whether it's addressed at a group level or at an elementary level, it's the same address.
Bill |
I agree.
The requirement that both of the identifiers be "elementary" items does seem a bit arbitrary, given that each of the group-items and its respective redefined elementary items have the same address, the same length, and the same class (alphanumeric).
I guess that's why I mis-remembered that requirement when I posted the original code. I only remembered the requirements that both identifiers had to have the same length, and that identifier-6 could not contain duplicate character values. Hopefully, I won't mis-remember similarly in the future. |
|
Back to top |
|
|
acevedo
Active User
Joined: 11 May 2005 Posts: 344 Location: Spain
|
|
|
|
ooops... I had posted the same as Ronald Burr about the redefines... I hadn't read the 2 page.
|
|
Back to top |
|
|
essence21
New User
Joined: 05 Dec 2008 Posts: 20 Location: mumbai
|
|
|
|
Thanks All,
Its working perfectly now.
I feel the issue was cropping up due to 03 level defined under 05.. i now modified to 01 --> 03 --> 05.. And its working ok.
Thank you for your help...
Just one more thing i was wondering what be the CPU usage if this is inserted into a scheduler which runs 1 minute frequency and the field is PIC X(967) |
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
An INSPECT...CONVERTING statement in COBOL results in assembler TRANSLATE instructions, which are very, very fast - especially when compared to any other method of performing the same task. The Principles of Operation Manual describes the TRANSLATE instruction thusly:
"The bytes of the first operand are selected one by one for translation, proceeding left to right. Each argument byte is added to the initial second operand address. The addition is performed following the rules for address arithmetic, with the argument byte treated as an eight-bit unsigned binary integer and extended with zeros on the left. The sum is used as the address of the function byte, which then replaces the original argument byte."
Since your source field is more than 256 bytes ( the limit for a single TRANSLATE instruction ), and of a FIXED length, I'm "assuming" that the compiler will simply generate FOUR such TRANSLATE instructions ( three of 256 bytes each, and one for the remainder (199 bytes)) in order to convert the entire field.
If the field were of a VARIABLE length, the underlying code would have to contain a "loop" to perform zero or more 256-byte TRANSLATEs, followed by one for the remainder ( when it becomes less than 256 bytes ). Though somewhat less efficient than when dealing with FIXED length fields, it would still be the fastest method available to accomplish the task. |
|
Back to top |
|
|
|