× 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.



Yeah, here-docs are kinda nice. I use them from time-to-time in shell scripts... I also used to use them a lot in perl (though, I rarely code in perl anymore.)

In RPG, I tend to solve the same problem by using CTDATA arrays. For example:

D MyData s 80a dim(20) ctdata
/free
... put your code here ...
/end-free
**
Update MCPSRV Set SESCLS='O',
semdat = Date_As_Cymd(Current_Date),
semtim = time_As_Hms(Current_Time), seuser = user,
sempgm = 'SQL'
Where SEICD9='V2020Z'

It's not in-line with the code like it would be with a here-doc, but that's proven to be a minor issue, not a major one.

Another approach is to use CGIDEV2's templating feature... maybe a bit overkill, but it gives you the ability to put your 'here-doc' in a stmf or pf-mbr, and you can have variables that get replaced with data, etc.

Another thing you may not have considered... you don't actually need to close the quotes, and open them again on every line (as you did in your example.) You could've coded it a little simpler, like this:

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''';

Not quite as nice as the CTDATA or here-doc approach, but it's a little nicer than what you had.

Don't get me wrong... I don't think a here-doc is a bad idea... it's a pretty good one (if implemented well), I just wanted to point out that there are other alternatives that might help you in the short term.


On 1/20/2011 8:46 AM, Mark Murphy/STAR BASE Consulting Inc. wrote:
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.