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



Hi again,

On 2/19/2010 2:06 PM, Scott Klement wrote:
I'm going to go over your code and fix it up, and post my results. Give
me a few minutes to do that...

Okay, here's the code posted by John Kelly with only some minor revisions... this should solve the problem, and make it run slightly faster as well:

h noMain bndDir('QC2LE') option(*srcstmt: *noDebugIO)

/include protoUtil

d getToken pr * extProc('strtok')
d pString * value options(*string)
d pDelimiters * value options(*string)

d delimiters s 2a inz('; ')

p get_eMail_Addresses...
p B export
d PI
d forSplit 1000a const
d numEmails 5i 0
d emails 75a dim(13)

d pToken s *
d split s 1000a varying
d emailIs s like(emails)

/free
split = %trim(forSplit);
pToken = getToken(split: delimiters);
numEMails = 0;
doW (pToken <> *null);
emailIs = %str(pToken);
if (emailIs <> *blanks);
numEmails += 1;
if (numEmails <= %elem(emails));
emails(numEmails) = emailIs;
endIf;
endIf;
pToken = getToken(*null: delimiters);
endDo;
return;
/end-Free
p E

p set_eMail_Addresses...
p B export
d PI
d forSplit 1000a
d emails 75a dim(13) const

d i s 5i 0
d split s 1000a varying inz('')

/free
for i = 1 to %elem(emails);
if (emails(i) <> *blanks);
if (%len(split) > 0);
split = split + ';';
endIf;
split = split + %trim(emails(i));
endIf;
endFor;
forSplit = split;
return;
/end-Free
P E

Here are the important points of what I changed:

1) I changed 'split' to a VARYING variable, and trimmed the blanks from
the end. It just seemed pointless to ask strtok() to find all of
those blanks at the end.

2) (the crucial one) I changed getToken(%addr(split): %addr(delimiters))
to be simply getToken(split: delimiters) and also changed
getToken(*null: %addr(delimiters)) to getToken(*null: delimiters)

This is the important change. Passing the strings directly lets RPG
null-terminate the properly, and therefore they don't go off into
random memory locations that follow the string, reading garbage
from memory.

3) I added CONST to the 2nd parameter of set_eMail_Addresses()...
another minor change, but it bugged me, so I changed it. You'll
need to make that change in your protoUtil copy book as well.

#2 was the big one.. that's what was causing the extra array elements with garbage in them.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.