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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COPY.. REPLACING 1

Status
Not open for further replies.

staceybauer

Instructor
Aug 19, 2003
9
US
I am trying to use the COPY REPLACING option in an Enterprise COBOL program and can't seem to get it to work. It compiles cleanly, but seems to ignore the statement. No data is replaced. Here is the code.

COPY TR319XXX REPLACING ==DL== BY ==XL==.

I have tried literals, fields etc. and no luck.

Does anyone know if the ADATA compile option needs to be turned on to make this work?
 
COPY REPLACING does not do a text-search based replace like a word processor but does it based on blocks or tokens. Try doing this with a complete variable name (which is delineated by spaces) and you will see it will work.

The solution is to add tokens to your copybook definitions that you are wanting to REPLACE.

See for a more detailed explanation.
 
Did the trick.

Unfortunately it opens up another set of issues for us.

Thank you!
 
Depending upon "how big" your Enterprise COBOL shop is, you might want to contact your "IBM marketing rep" and ask them to create a "REQUEST" for IBM to implement the

LEADING / TRAILING
"partial word replacing" feature from the ISO 2002 COBOL Standard.

Refer the IBM rep to the existing SHARE requirement,

" SSLNGC0313590 2002 ISO COBOL - COPY & REPLACE Partial Word Replacement"

Bill Klein
 
at many sites people create copymembers containing prefixes looking like:

01 (PREFIX)-DEMORECORD.
03 (PREFIX)-DEMO-ELEMENT PIC X(100).

etcetera. Those can be replaced by

COPY DEMOREC REPLACING ==(PREFIX)== BY ==MY-PREFIX==.

It is also possible to replace complete parts of source, using several lines.

Regards,

Crox
 
I already knew about the "tokens" option, but we actually import the copybooks into a client side product (Ivory) that is used for developing webservices. Anyway the Ivory data definitions then contain datanames that include the tokens. It works, but gets a little confusing and ugly. I was hoping to find a nice option to simply replace a specific string in our COBOL programs, so we could use the copybook several times in the same program.

Thanks anyway Crox
 
An other option is to implement al your wishes by making your own precompiler. That can have many advantages. For example typical user situations can be fixed by the precompiler. Things like "!GET CUSTOMER" can be a complete and for some programmers complex dbms access, handled in one company precompiler statement using company defaults. A precompiler can know many company things and can be very smart. Also you can isolate platform or dbms dependent things into your own precompiler. To make such a precompiler can be very easy. I made several of them.
 
For how to use (and create) "preprocessors" in an IBM mainframe environment (VS COBOL II and later), see:


and following.

A "LIBEXIT" is where you would want to put "customized" COPY processing.

P.S. I do NOT personally recommend this solution - but it is documented as "possible".

Bill Klein
 
I prefer a precompiler that runs before any other precompiler/compiler, not integrated with any other product. Also many companies have their own policy about what is and is not allowed. I would put the checks in the same preprocessor-run.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top