For Programmers: Free Programming Magazines  


Home > Archive > Cobol > April 2005 > REPLACING Algorythm









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author REPLACING Algorythm
Keith Paterson

2005-04-19, 8:55 am

I'm trying to code the REPLACING algorythm. I've played with the Fujitsu
NetCobol compiler and am trying to get some insight. All the examples
and descriptions I found don't have a word and a pseudo word. Somehow I
can't get it together.

COPY BLA REPLACING 10 BY 20, ==(20)== BY ==(20)==

What happens is clear, but I could code it. Can anybody point me in the
right direction or give me a code snippet in more or less anything other
than assembler ;-).

Keith
William M. Klein

2005-04-20, 3:55 am

OK, I have been waiting and hoping someone else would answer this question. I
am not totally clear what you are actually asking for/about - but the following
MAY help. (This applies to the '85 Standard and compilers conforming to that
with NO extensions to COPY REPLACING support. Those with extensions may allow
"other stuff". The '02 Standard also introduces some new functionality - such as
the "common extension" of allowing copy "member" names in quotes.)

Rule 1
any text NOT in pseudo-text delimiters is treated "as if it were" in such.
(such text is SUPPOSED TO BE COBOL words and identifiers)

Rule 2
REPLACING rules apply to TEXT WORDS - these include (but are not limited to)
"COBOL words".

Rule 3
The special characters ":" "(" and ")" can be used to "make" text words
without space (or other) separators, e.g.
A(B)
is made up of 2 text words "A" and "B" and the two separators "(" and ")"

Therefore, if you have a COPY statement (named CPY) of:

05 A(B)C PIX X(10).

and a COPY/REPLACING statement of

Copy CPY
Replacing ==(B)== by ==-insert-here-==
PIX by Pic
LX-i

2005-04-20, 8:55 am

Keith Paterson wrote:
> I'm trying to code the REPLACING algorythm. I've played with the Fujitsu
> NetCobol compiler and am trying to get some insight. All the examples
> and descriptions I found don't have a word and a pseudo word. Somehow I
> can't get it together.
>
> COPY BLA REPLACING 10 BY 20, ==(20)== BY ==(20)==
>
> What happens is clear, but I could code it. Can anybody point me in the
> right direction or give me a code snippet in more or less anything other
> than assembler ;-).


I've never been able to get a word *and* pseudo-text on the same replace
(or replacing) statement. My compiler is the Unisys 2200 UCS COBOL
compiler, so I can't guarantee it won't work on yours. Is there any way
you can uniquely identify the words you're wanting to replace? i.e., do
they all start with "Pic" or something?

What I've had to do in certain situations is use pseudo-text to avoid
replacing a paragraph in a proc I wanted to intercept. Say I have a
paragraph called 900-SQL-ERROR, and I wanted to code my own, if I say

copy my-proc
replacing 900-SQL-ERROR by MY-SQL-ERROR.

I would also replace 900-SQL-ERROR (which is contained in the proc).
However, if I use the pseudo-text option, I can say

copy my-proc
replacing == GO TO 900-SQL-ERROR==
by == GO TO MY-SQL-ERROR==.

and intercept all the performs, without changing the unwanted paragraph
to the same name that I have in my program.

Hope that helps a bit...


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~ / \ / ~ Live from Montgomery, AL! ~
~ / \/ o ~ ~
~ / /\ - | ~ daniel@thebelowdomain ~
~ _____ / \ | ~ http://www.djs-consulting.com ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ GEEKCODE 3.12 GCS/IT d s-:+ a C++ L++ E--- W++ N++ o? K- w$ ~
~ !O M-- V PS+ PE++ Y? !PGP t+ 5? X+ R* tv b+ DI++ D+ G- e ~
~ h---- r+++ z++++ ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
Fiona McBride

2005-04-20, 8:55 am

Keith Paterson wrote:
> I'm trying to code the REPLACING algorythm. I've played with the Fujitsu
> NetCobol compiler and am trying to get some insight. All the examples
> and descriptions I found don't have a word and a pseudo word. Somehow I
> can't get it together.
>
> COPY BLA REPLACING 10 BY 20, ==(20)== BY ==(20)==
>
> What happens is clear, but I could code it. Can anybody point me in the
> right direction or give me a code snippet in more or less anything other
> than assembler ;-).
>
> Keith


Thanks for the answers. I am actually trying to implement the REPLACING
algorythm for am IDE to show a Copy in it's modified form and to be able
to show the complete "data tree". I just want to make sure my view shows
something that is near to the real thing. This means I have to think of
more or less all possibilities and not just Pattern A leads to Result A.

THX

Keith
William M. Klein

2005-04-20, 8:55 am

In that case (shudder, shudder), the "hardest" things to understand are

A) when REPLACING introduces "new" lines of text, e.g.

COPY Bla
Replacing ==abc== by
==this line
that line
another line==.

This gets "tricky" when you are using a compiler that still pays attention to
A-/B-margin stuff because the rules are a little tricky (please don't ask me to
explain them <G> )

B) when there are debugging lines "in play". Even the J4 COBOL committee has
admitted this isn't clear in the '85 (or '02) Standards. You need to play with
YOUR compiler to figure out what it does with:

D Copy Bla
replacing ==ABC== by ==xyz==.

versus

D Copy Bla
D replacing ==ABC== by ==xyz==.

versus

Copy Bla
replacing
D ==ABC== by xyz
==123== by 456.

versus

Copy Bla
Replacing ==ABC
D XYZ
123==
by ==other==.

***

Although I am NOT a compiler writer, I have worked with enough of them to know
that they HATE when they have to "touch" the COPY/REPLACING code - as even those
who wrote it tend not to remember/understand all variations.

--
Bill Klein
wmklein <at> ix.netcom.com
"Fiona McBride" <Fiona.McBride@gmx.de> wrote in message
news:1in44d.qls.ln@uter.bbv-l.de...
> Keith Paterson wrote:
>
> Thanks for the answers. I am actually trying to implement the REPLACING
> algorythm for am IDE to show a Copy in it's modified form and to be able to
> show the complete "data tree". I just want to make sure my view shows
> something that is near to the real thing. This means I have to think of more
> or less all possibilities and not just Pattern A leads to Result A.
>
> THX
>
> Keith



William M. Klein

2005-04-20, 8:55 am

I should have also asked about which compiler and operating system.

IBM (for example) used to have a compiler option (in their OS/VS COBOL and
earlier products) called LANGLVL(1) or (2). This impacted (ignorantly) how COPY
statements on an 01-level item worked. (They claimed - but I won't swear to
this - that this was due to a change between the '68 and '74 ANSI Standards).

--
Bill Klein
wmklein <at> ix.netcom.com
"William M. Klein" <wmklein@nospam.netcom.com> wrote in message
news:36n9e.452307$za2.71316@news.easynews.com...
> In that case (shudder, shudder), the "hardest" things to understand are
>
> A) when REPLACING introduces "new" lines of text, e.g.
>
> COPY Bla
> Replacing ==abc== by
> ==this line
> that line
> another line==.
>
> This gets "tricky" when you are using a compiler that still pays attention to
> A-/B-margin stuff because the rules are a little tricky (please don't ask me
> to explain them <G> )
>
> B) when there are debugging lines "in play". Even the J4 COBOL committee has
> admitted this isn't clear in the '85 (or '02) Standards. You need to play
> with YOUR compiler to figure out what it does with:
>
> D Copy Bla
> replacing ==ABC== by ==xyz==.
>
> versus
>
> D Copy Bla
> D replacing ==ABC== by ==xyz==.
>
> versus
>
> Copy Bla
> replacing
> D ==ABC== by xyz
> ==123== by 456.
>
> versus
>
> Copy Bla
> Replacing ==ABC
> D XYZ
> 123==
> by ==other==.
>
> ***
>
> Although I am NOT a compiler writer, I have worked with enough of them to know
> that they HATE when they have to "touch" the COPY/REPLACING code - as even
> those who wrote it tend not to remember/understand all variations.
>
> --
> Bill Klein
> wmklein <at> ix.netcom.com
> "Fiona McBride" <Fiona.McBride@gmx.de> wrote in message
> news:1in44d.qls.ln@uter.bbv-l.de...
>
>



Richard

2005-04-20, 8:55 am

> trying to implement the REPLACING
> algorythm for am IDE to show a Copy in it's modified form


Starting with a template file of a simple Cobol source, process this to
add the COPY statement and replacing clauses. Execute compiler, or at
least the preprocessor part, with COPYLIST output. Scrape out the
results of the COPY for display.

Keith Paterson

2005-04-21, 3:55 am

Keith Paterson wrote:
> I'm trying to code the REPLACING algorythm. I've played with the Fujitsu
> NetCobol compiler and am trying to get some insight. All the examples
> and descriptions I found don't have a word and a pseudo word. Somehow I
> can't get it together.
>
> COPY BLA REPLACING 10 BY 20, ==(20)== BY ==(20)==
>
> What happens is clear, but I could code it. Can anybody point me in the
> right direction or give me a code snippet in more or less anything other
> than assembler ;-).
>
> Keith


This gets evenmore mindboggling.

I have

000030 20 BLA PIC X(020).
000040 20 BLA2 PIC X(20).

and

000023 COPY IMPORT2 REPLACING 20 BY 01,
000024 ==(20)== BY ==(20)==.

works. Huh? I thought pseudo text was like quoted text.
Does this apply to all/most compilers.

Sorry for the sobbing.

Keith
LX-i

2005-04-21, 3:55 pm

Keith Paterson wrote:
> Keith Paterson wrote:
>
>
>
> This gets evenmore mindboggling.
>
> I have
>
> 000030 20 BLA PIC X(020).
> 000040 20 BLA2 PIC X(20).
>
> and
>
> 000023 COPY IMPORT2 REPLACING 20 BY 01,
> 000024 ==(20)== BY ==(20)==.
>
> works. Huh? I thought pseudo text was like quoted text.
> Does this apply to all/most compilers.


What do you mean by "works"? (Can you post the compiler-translated code
for the above?) Also, I'm not sure what swapping (20) for (20) does for
you - did you mean for those to be different?


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~ / \ / ~ Live from Montgomery, AL! ~
~ / \/ o ~ ~
~ / /\ - | ~ daniel@thebelowdomain ~
~ _____ / \ | ~ http://www.djs-consulting.com ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ GEEKCODE 3.12 GCS/IT d s-:+ a C++ L++ E--- W++ N++ o? K- w$ ~
~ !O M-- V PS+ PE++ Y? !PGP t+ 5? X+ R* tv b+ DI++ D+ G- e ~
~ h---- r+++ z++++ ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
James J. Gavan

2005-04-21, 3:55 pm

Keith Paterson wrote:[color=darkred]
> Keith Paterson wrote:
>

Always hesitant when it's F/J - it may just not be the same as M/F, but
does this help ?

1 - This is the bare bones copy :-

OBJECT-STORAGE SECTION.
copy "\copylib\sqlResult.cpy"
replacing ==(tag)== by ==01 ws==.

01 Continent-Info.
copy "\copylib\sqlResult.cpy"
replacing ==(tag)== by ==05 Continent==.
copy "Continent2.cpy" replacing ==(tag1)== by ==05 Continent==
==(tag)== by ==Continent==.

2 - the Copyfiles before compilation :

*>----------sqlresult.cpy-------------------------------------

(tag)-SqlResult pic 9(03).

88 ResultOK value 0.
88 FileResultOK value 0.

88 RecNotFound value 1.

88 NoMoreRows value 2.
88 FileFinis value 2.

88 DuplicateKey value 3.

88 DataError value 97.
88 CursorError value 98.

88 FileError value 99.
88 TableError value 97 thru 99.

*>----------------------------------------------------------------

*>----------------contint2.cpy ------------------------------
(tag1)-Record.
10 (tag)-PrimeKey.
15 (tag)-Code pic x(02).
15 pic x(18).
10 (tag)-Name pic x(14).
10 (tag)-Flag pic 9.
88 (tag)-Actioned value 1.
88 (tag)-NotActioned value 2.

*>--------------------------------------------------------------

3. Now the entries in # 1 above after compilation :-

OBJECT-STORAGE SECTION.

*>----------sqlresult.cpy-------------------------------------

01 ws-SqlResult pic 9(03).

88 ResultOK value 0.
88 FileResultOK value 0.

88 RecNotFound value 1.

88 NoMoreRows value 2.
88 FileFinis value 2.

88 DuplicateKey value 3.

88 DataError value 97.
88 CursorError value 98.

88 FileError value 99.
88 TableError value 97 thru 99.

*>----------------------------------------------------------------

01 Continent-Info.
*>----------sqlresult.cpy-------------------------------------

05 Continent-SqlResult pic 9(03).

88 ResultOK value 0.
88 FileResultOK value 0.

88 RecNotFound value 1.

88 NoMoreRows value 2.
88 FileFinis value 2.

88 DuplicateKey value 3.

88 DataError value 97.
88 CursorError value 98.

88 FileError value 99.
88 TableError value 97 thru 99.

*>----------------------------------------------------------------
*>----------------contint2.cpy ------------------------------
05 Continent-Record.
10 Continent-PrimeKey.
15 Continent-Code pic x(02).
15 pic x(18).
10 Continent-Name pic x(14).
10 Continent-Flag pic 9.
88 Continent-Actioned value 1.
88 Continent-NotActioned value 2.

*>--------------------------------------------------------------
William M. Klein

2005-04-21, 3:55 pm

See separate (previous) note.

"(" ")" and ":"

ALWAYS ('85 Standard and above) create TEXT WORDS.

REPLACING (like the REPLACE statement) works on text words *NOT* quoted text.

X (20) is composed of
two text words - "X" and "20"
and
two separators "(" and ")"

On the other hand
X-20
is a single text word

--
Bill Klein
wmklein <at> ix.netcom.com
"Keith Paterson" <keith.paterson@gmx.de> wrote in message
news:09e74d.qls.ln@uter.bbv-l.de...
> Keith Paterson wrote:
>
> This gets evenmore mindboggling.
>
> I have
>
> 000030 20 BLA PIC X(020).
> 000040 20 BLA2 PIC X(20).
>
> and
>
> 000023 COPY IMPORT2 REPLACING 20 BY 01,
> 000024 ==(20)== BY ==(20)==.
>
> works. Huh? I thought pseudo text was like quoted text.
> Does this apply to all/most compilers.
>
> Sorry for the sobbing.
>
> Keith



Keith Paterson

2005-04-27, 3:55 pm

Keith Paterson wrote:
> I'm trying to code the REPLACING algorythm. I've played with the Fujitsu
> NetCobol compiler and am trying to get some insight. All the examples
> and descriptions I found don't have a word and a pseudo word. Somehow I
> can't get it together.
>
> COPY BLA REPLACING 10 BY 20, ==(20)== BY ==(20)==
>
> What happens is clear, but I could code it. Can anybody point me in the
> right direction or give me a code snippet in more or less anything other
> than assembler ;-).
>
> Keith


This gets evenmore mindboggling.

I have

000030 20 BLA PIC X(020).
000040 20 BLA2 PIC X(20).

and

000023 COPY IMPORT2 REPLACING 20 BY 01,
000024 ==(20)== BY ==(20)==.

works. Huh? I thought pseudo text was like quoted text.
Does this apply to all/most compilers.

Sorry for the sobbing.

Keith
LX-i

2005-04-27, 8:55 pm

Keith Paterson wrote:
> Keith Paterson wrote:
>
>
>
> This gets evenmore mindboggling.
>
> I have
>
> 000030 20 BLA PIC X(020).
> 000040 20 BLA2 PIC X(20).
>
> and
>
> 000023 COPY IMPORT2 REPLACING 20 BY 01,
> 000024 ==(20)== BY ==(20)==.
>
> works. Huh? I thought pseudo text was like quoted text.
> Does this apply to all/most compilers.


What do you mean by "works"? (Can you post the compiler-translated code
for the above?) Also, I'm not sure what swapping (20) for (20) does for
you - did you mean for those to be different?


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~ / \ / ~ Live from Montgomery, AL! ~
~ / \/ o ~ ~
~ / /\ - | ~ daniel@thebelowdomain ~
~ _____ / \ | ~ http://www.djs-consulting.com ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ GEEKCODE 3.12 GCS/IT d s-:+ a C++ L++ E--- W++ N++ o? K- w$ ~
~ !O M-- V PS+ PE++ Y? !PGP t+ 5? X+ R* tv b+ DI++ D+ G- e ~
~ h---- r+++ z++++ ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
James J. Gavan

2005-04-27, 8:55 pm

Keith Paterson wrote:[color=darkred]
> Keith Paterson wrote:
>

Always hesitant when it's F/J - it may just not be the same as M/F, but
does this help ?

1 - This is the bare bones copy :-

OBJECT-STORAGE SECTION.
copy "\copylib\sqlResult.cpy"
replacing ==(tag)== by ==01 ws==.

01 Continent-Info.
copy "\copylib\sqlResult.cpy"
replacing ==(tag)== by ==05 Continent==.
copy "Continent2.cpy" replacing ==(tag1)== by ==05 Continent==
==(tag)== by ==Continent==.

2 - the Copyfiles before compilation :

*>----------sqlresult.cpy-------------------------------------

(tag)-SqlResult pic 9(03).

88 ResultOK value 0.
88 FileResultOK value 0.

88 RecNotFound value 1.

88 NoMoreRows value 2.
88 FileFinis value 2.

88 DuplicateKey value 3.

88 DataError value 97.
88 CursorError value 98.

88 FileError value 99.
88 TableError value 97 thru 99.

*>----------------------------------------------------------------

*>----------------contint2.cpy ------------------------------
(tag1)-Record.
10 (tag)-PrimeKey.
15 (tag)-Code pic x(02).
15 pic x(18).
10 (tag)-Name pic x(14).
10 (tag)-Flag pic 9.
88 (tag)-Actioned value 1.
88 (tag)-NotActioned value 2.

*>--------------------------------------------------------------

3. Now the entries in # 1 above after compilation :-

OBJECT-STORAGE SECTION.

*>----------sqlresult.cpy-------------------------------------

01 ws-SqlResult pic 9(03).

88 ResultOK value 0.
88 FileResultOK value 0.

88 RecNotFound value 1.

88 NoMoreRows value 2.
88 FileFinis value 2.

88 DuplicateKey value 3.

88 DataError value 97.
88 CursorError value 98.

88 FileError value 99.
88 TableError value 97 thru 99.

*>----------------------------------------------------------------

01 Continent-Info.
*>----------sqlresult.cpy-------------------------------------

05 Continent-SqlResult pic 9(03).

88 ResultOK value 0.
88 FileResultOK value 0.

88 RecNotFound value 1.

88 NoMoreRows value 2.
88 FileFinis value 2.

88 DuplicateKey value 3.

88 DataError value 97.
88 CursorError value 98.

88 FileError value 99.
88 TableError value 97 thru 99.

*>----------------------------------------------------------------
*>----------------contint2.cpy ------------------------------
05 Continent-Record.
10 Continent-PrimeKey.
15 Continent-Code pic x(02).
15 pic x(18).
10 Continent-Name pic x(14).
10 Continent-Flag pic 9.
88 Continent-Actioned value 1.
88 Continent-NotActioned value 2.

*>--------------------------------------------------------------
William M. Klein

2005-04-27, 8:55 pm

See separate (previous) note.

"(" ")" and ":"

ALWAYS ('85 Standard and above) create TEXT WORDS.

REPLACING (like the REPLACE statement) works on text words *NOT* quoted text.

X (20) is composed of
two text words - "X" and "20"
and
two separators "(" and ")"

On the other hand
X-20
is a single text word

--
Bill Klein
wmklein <at> ix.netcom.com
"Keith Paterson" <keith.paterson@gmx.de> wrote in message
news:09e74d.qls.ln@uter.bbv-l.de...
> Keith Paterson wrote:
>
> This gets evenmore mindboggling.
>
> I have
>
> 000030 20 BLA PIC X(020).
> 000040 20 BLA2 PIC X(20).
>
> and
>
> 000023 COPY IMPORT2 REPLACING 20 BY 01,
> 000024 ==(20)== BY ==(20)==.
>
> works. Huh? I thought pseudo text was like quoted text.
> Does this apply to all/most compilers.
>
> Sorry for the sobbing.
>
> Keith



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com