× 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 created a "replace character" module that I have used in a similar
fashion.

Typically, I have a need for dynamic SQL and create a module that has the
body of the SQL
statement in a run-time array that is loaded into a variable at
progam init, complete
with "markers" at each point where character substitution needs to
occur.

Markers would be something like: ?01, ?02, etc

The actual marker value is specified in a parameter.

When the program gets to a point where all replacement values for the next
SQL statement
are known. the program starts with value of the SQL statement that
was set at
program init, and calls the replace module for each marker. It is
ok to replace
a marker with blank, assuming the syntax of the SQL will remain
correct.

Here is a code fragment showing the call to the replacement module:

* Replace ?1 with data lib name for current PO
C Eval myInpStr = SqlStmt1
C Eval myOldStr = '?1'
C Eval myNewStr = 'BASDB' + ph_H1FSET
C CALLB 'RPLCHRM'
C PARM myInpStr
C PARM myOldStr
C PARM myNewStr
C PARM myOutStr
* Replace ?2 with Outlet Number
C Eval myInpStr = myOutStr
C Eval myOldStr = '?2'
C Eval int13 = ph_H1OUTN
C Eval myNewStr = int13x
C CALLB 'RPLCHRM'
C PARM myInpStr
C PARM myOldStr
C PARM myNewStr
C PARM myOutStr
* Replace ?3 with Delivery Date From
C Eval myInpStr = myOutStr
C Eval myOldStr = '?3'
C Eval int07 = DelDatFr
C Eval myNewStr = int07x
C CALLB 'RPLCHRM'
C PARM myInpStr
C PARM myOldStr
C PARM myNewStr
C PARM myOutStr

After all markers are replaced, the next step is the sql prepare, etc.

Not as elegant as HereDoc, but the code is available if it helps; I just
don't know
the best way to make this available.


When the program gets to the point where all of the values



"Mark Murphy/STAR BASE Consulting Inc." <mmurphy@xxxxxxxxxxxxxxx>
Sent by: rpg400-l-bounces@xxxxxxxxxxxx
01/20/2011 07:46 AM
Please respond to
RPG programming on the IBM i / System i <rpg400-l@xxxxxxxxxxxx>


To
RPG programming on the IBM i/System i <rpg400-l@xxxxxxxxxxxx>
cc

Subject
HereDoc






Some time ago I learned PHP, and was introduced to a concept called
HereDoc. Essentially a way to insert a string inline. Didn't really see
the use of it, and never really thought about it much until now. I have a

piece of code where it would be highly useful for improving the
readability of my program. Unfortunately The use is in an RPG program,
and the feature does not exist there.

Anyway here is what I was thinking. I am using dynamic SQL in a
particular program (so that I can use set schema to direct unqualified
references to the environment of my choice). Some of the SQL commands are

quite complex, and I have to double quotes in my string literals. the
whole thing degenerates into a bunch of extra quotes and continuation
marks that would not be necessary with a HereDoc.

Consider the following (very simple, but serves to make the point):

updateStmt =
'Update MCPSRV Set SESCLS=''O'', ' +
' semdat = Date_As_Cymd(Current_Date), ' +
' semtim = time_As_Hms(Current_Time), seuser = user, ' +
' sempgm = ''SQL'' ' +
'Where SEICD9=''V2020Z''';

With a HereDoc I could write something like:

updateStmt = <<<DOC
Update MCPSRV Set SESCLS='O',
semdat = Date_As_Cymd(Current_Date),
semtim = time_As_Hms(Current_Time), seuser = user,
sempgm = 'SQL'
Where SEICD9='V2020Z'
<<<DOC

Even with a simple example the lack of superfluous quotes and continuation

marks makes the second far more readable than the first.

Any thoughts?

Mark Murphy
STAR BASE Consulting, Inc.
mmurphy@xxxxxxxxxxxxxxx

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.