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



Mark:

I was only responding to your provided example "use case" for why you wanted something like "heredoc" for RPG. For that fairly trivial case, it hardly seems worthwhile to implement a whole new mechanism requiring a language pre-processor...

And there are already many other mechanisms on this platform for formatting strings with substitution values embedded in them, such as the QMHRTVM API to retrieve a message, substituting provided data values into the message defined with substitution variables (&1, &2, etc.)

Mark

> On 1/20/2011 2:08 PM, Mark Murphy/STAR BASE Consulting Inc. wrote:
Not in all cases. From your reference, D has it, and I believe that is a
compiled language. And so what? Don't you ever say something like a = 'a
little string'? What if your string is big or formatted? Wouldn't it be
easier to be able to say here is a formatted string for you to use, than
having only a few limited ways to process strings? I have heard, on this
list even, people saying that RPG isn't all that great at processing
strings. I simply present here an idea to improve upon that.

Mark Murphy
STAR BASE Consulting, Inc.
mmurphy@xxxxxxxxxxxxxxx



From: "Mark S. Waterbury"<mark.s.waterbury@xxxxxxxxxxxxx>
To: RPG programming on the IBM i / System i<rpg400-l@xxxxxxxxxxxx>
Date: 01/20/2011 01:01 PM
Subject: Re: HereDoc
Sent by: rpg400-l-bounces@xxxxxxxxxxxx



Hi, Mark:

This "heredoc" stuff seems oriented to scripting languages. (PHP is
interpreted, not compiled, so it is technically a "scripting" language.)

http://en.wikipedia.org/wiki/Here_document

If the trouble is mainly dealing with all the embedded double-quotes
inside string literals, perhaps you could just do something 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";
updateStmt = %xlate('"' : '''' : updateStmt;


This uses the double-quote character where ever a single quote is needed
in the final string, and then replaces the double-quote character with
the single quote character, using the %xlate built-in function.

This seems to me to be the "best simple" solution to this problem.

HTH,
Mark S. Waterbury

> On 1/20/2011 9: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.