× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I will post a separate message with a more complete example using the SQL REPLACE, but using CALLPRC in a CLLE vs the CALL noted in that prior reply. However, I thought I would also provide a reply about the CLP that was offered as the current approach...

Here is a similar approach to the given CLP [in fact, a rewrite of that code] which uses the conspicuous library naming pattern to verify the environment, keeps the SCNVAR, assumes that the replacement value is smaller than the pattern [and that both are fixed], naming the third argument of %sst as a /Length/ vs an /End Position/ , and then uses *cat to reassemble the &text from an updated prefix and the suffix beyond the replaced value. The @?? comments denote the use of, and evaluations for, effecting the replacement for the given sample\example input string [as shown in the first such comment line]:

PGM parm(&text)
/* parameters */
dcl &text *char len(500)
/* constants */
dcl &textLen *dec len( 3) value(500)
dcl &patternLen *dec len( 3) value( 6)
dcl &replaceLen *dec len( 3) value( 4)
/* variables */
dcl &dblib *char len( 10) /* pattern is known and fixed */
dcl &envr1 *char len( 1) stg(*defined) defvar(&dblib 1)
dcl &envr4 *char len( 4) stg(*defined) defvar(&dblib 1)
dcl &envLIB *char len( 3) stg(*defined) defvar(&dblib 5)
dcl &patternPos *dec len( 3)
dcl &headLen *dec len( 3)
dcl &tailPos *dec len( 3)
dcl &tailLen *dec len( 3)

rtvobjd *LIBL/RESTART objtype(*FILE) rtnlib(&DBLIB)
monmsg (cpf9800 cpf2100 cpf3200) exec(goto badthing)
if cond( ( &envr4 *EQ 'PROD' +
*or &envr4 *EQ 'TEST' +
*or &envr4 *EQ 'DEMO' +
) *and &envLIB *EQ 'LIB' ) +
then(do) /* one of the supported library environments */
SCNVAR RESULT(&patternPos) STRING(&TEXT) +
STRINGLEN(&textLen) PATTERN('&ENVR4') +
PATTERNLEN(&patternlen) TRANSLATE(*YES)
if cond(&patternPos > 1) /* pattern was found */
then(do) /* effect replacement with a smaller value */
/* replace pattern "&ENVR4" with value of &envr4 */
/*@?? SET_ENVR ('jde_&ENVR4_report@xxxxxxxxxxxxx') */
/*@?? ....+....1....+....2....+....3. */
/*@?? patternPos = 5 */
chgvar %sst(&text &patternPos &replaceLen) &envr4
/*@?? 'jde_XXXXR4_report@xxxxxxxxxxxxx' */
/*@?? ....+....1....+....2....+....3 */
/*@?? from 11 for 490 is remainder of string */
chgvar &headLen (&patternPos + &replaceLen - 1)
/*@?? headLen=8 */
chgvar &tailPos (&patternPos + &patternLen)
/*@?? tailPos=11 */
chgvar &tailLen (&textLen - &tailPos + 1)
/*@?? tailLen=490 */
/* replace &text with head and tail */
chgvar &text ( %sst(&text 1 &headLen ) +
*cat %sst(&text &tailPos &tailLen ) )
enddo
enddo
else do
badthing:
sndpgmmsg msg('RESTART file unavail in PROD, TEST, or DEMO LIB') +
msgtype(*escape)
enddo
ENDPGM

Regards, Chuck

On 15 Apr 2013 13:07, Stone, Joel wrote:
<<SNIP>>

Here is what I have so far: - any suggestions would be appreciated!

PGM parm(&text)
dcl &text *char len(500)
dcl &textLen *dec len(3) value(500)
dcl &envr1 *char len(1) value('?')
dcl &envr4 *char len(4) value('????')
dcl &patternlen *dec len(3)
dcl &dblib *char len(10)
dcl &start_pos *dec len(3)
dcl &start_pos1 *dec len(3)
dcl &end_pos1 *dec len(3)
dcl &start_pos2 *dec len(3)
dcl &end_pos2 *dec len(3)

rtvobjd RESTART objtype(*FILE) rtnlib(&DBLIB)
select
when (&DBLIB = 'PRODLIB') DO
chgvar &ENVR1 'P'
chgvar &ENVR4 'PROD'
ENDDO
when (&DBLIB = 'TESTLIB') DO
chgvar &ENVR1 'T'
chgvar &ENVR4 'TEST'
ENDDO
when (&DBLIB = 'DEMOLIB') DO
chgvar &ENVR1 'D'
chgvar &ENVR4 'DEMO'
ENDDO
endselect

chgvar &patternlen 6
SCNVAR RESULT(&start_pos) STRING(&TEXT) +
STRINGLEN(&textLen) PATTERN('&ENVR4') +
PATTERNLEN(&patternlen) TRANSLATE(*YES)
IF (&start_pos > 1) do
chgvar &end_pos1 (&start_pos - 1)
chgvar &start_pos2 (&start_pos + &patternlen)
chgvar &end_pos2 (&textLen - &start_pos2)
chgvar &text +
(%sst(&text 1 &end_pos1 ) +
|| &ENVR4 +
|| %sst(&text &start_pos2 &end_pos2))
ENDDO

ENDPGM


Vern Hamberg on Monday, April 15, 2013 2:58 PM wrote:

There is now a %scan builtin function - if you are at v7.1. You
could still use QCLSCAN, too - and write your own. Once you find
the location of&ENVR, you can use %SST to get the part before it
and the part after it and put TEST or PROD in between.

That's the hard way. RPG is much better at this. So is a thing
called REXX - easily called from CL.

I'm hoping IBM comes out with a %replace, too, for CL.

On 15 Apr 2013 12:04, Stone, Joel wrote:

For the purpose of describing the operating environment state
(DEV, TEST, or PROD).

I want to call

SET_ENVR ('text or network path or email address goes here
&ENVR4 and more text')

And have the CL named SET_ENVR change the text "&ENVR4" to TEST
when the environment is a test environment (or PROD for
production environment).

I am using the TAATOOL "SCNVAR" to locate the string of
interest.

Is there a "replace" function in CL or TAATOOL or elsewhere that
would help accomplish this?

End result:

SET_ENVR (jde_&ENVR_report@xxxxxxxxxxxxx)

will result in the following if run from a test LPAR:

jde_TEST_report@xxxxxxxxxxxxx

If run on a production LPAR, the environment would resolve to:

jde_PROD_report@xxxxxxxxxxxxx

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.