Many thanks.
I liked your idea of having a quote function so considered writing my
own. However, I thought I would first check first whether you would
share your own code in order to save some time.
Again, thanks for sharing your code, I will make use of this.
Sean
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Joe Pluta
Sent: 03 April 2008 15:04
To: RPG programming on the AS400 / iSeries
Subject: Re: Assistance With Embedded SQL
McGovern, Sean wrote:
Joe,
Could you share your quote function code ?
Thanks.
Sean, a lot depends on the context. In general the hardest part is not
the quote code, but instead the way you make the procedure generic. RPG
requires a little magic to pass fields of differing sizes.
If you're already using varying length fields, it's relatively simple.
IBM's support for *VARSIZE and VARYING makes it very easy. I'll include
a sort of skeleton example here, showing the use of a couple of bit
flags. Things get a little more involved with fixed-length fields;
*VARSIZE requires a little more work.
Joe
h dftactgrp(*no) actgrp(*new)
d Quote pr 128 varying
d input 64 varying options(*varsize)
d flags 5u 0 const options(*Nopass)
d Quote_DoubleQuote...
d C 1
d Quote_Trim...
d C 2
d start s 30 varying
d msg s 50
/free
start = 'My Baby ';
msg = Quote(start);
dsply msg;
start = 'My Baby ';
msg = Quote(start : Quote_Trim);
dsply msg;
start = 'She''s my baby';
msg = Quote(start);
dsply msg;
start = 'She''s my baby';
msg = Quote(start : Quote_Trim + Quote_DoubleQuote);
dsply msg;
*inlr = *on;
/end-free
p Quote b
d pi 128 varying
d input 64 varying options(*varsize)
d flags 5u 0 const options(*Nopass)
d SingleQuote c ''''
d DoubleQuote c ''''''
d Work s 128 varying
d x s 3u 0
d char s 1
d Work2 s 128 varying
/free
Work = input;
if %bitand(flags : Quote_DoubleQuote) = Quote_DoubleQuote;
Work2 = '';
for x = 1 to %len(Work);
char = %subst(Work:x:1);
Work2 += char;
if char = SingleQuote;
Work2 += char;
endif;
endfor;
Work = Work2;
endif;
if %bitand(flags : Quote_Trim) = Quote_Trim;
Work = %trim(Work);
endif;
return SingleQuote + Work + SingleQuote;
/end-free
p e
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing
list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.