|
I want to eval rc=deblock(';': 512byteBlock: 50byteWord)
Here's the original prototype (doesn't work):
>>d workBlock s 1024 varying
>>
>>d deblock pr like(SUCCESS_RC)
>>d inpSepChar 10 const varying
>>d inpBlock const like(workBlock)
>>d outSingle like(workBlock)
>code options(*varsize) for outSingle, you can pass whatever
>length of parameter you want. But then you better use
>operational descriptors then, so you can find out the maximum
>size of the passed parameter.
My next attempt:
d workBlock s 1024 varying
d templateBlock s 65535
d separator s 10 varying
d outSingle s 50 varying
d blocked s like(workBlock)
d deblock pr like(SUCCESS_RC) opdesc
d inpSepChar 10 const varying
d inpBlock const like(workBlock)
d outSingle like(templateBlock)
d options(*varsize)
c eval rc = deblock(separator:
c blocked:
c outSingle)
Won't compile because outSingle is defined varying. If I take out the
varying, we're good to go. I wonder if this is a result of the incomplete
OPDESC support from Rochester? Anyway, inside the function, I need to see
how long a string I've passed in:
d getParmInf pr extproc('CEEGSI') opdesc
d parmNum 10i 0 const
d dataType 10i 0
d currLen 10i 0
d maxLen 10i 0
d errorFeedback 12a options(*omit)
d deblock pi like(SUCCESS_RC) opdesc
d inpSepChar 10 const varying
d inpBlock const like(workBlock)
d outSingle like(templateBlock)
d options(*varsize)
d currPos s 10i 0
d delimPos s 10i 0
d rc s like(SUCCESS_RC)
d tokenLength s 10i 0
d currLen s 10i 0
d maxLen s 10i 0
d dataType s 10i 0
c eval rc = UNKNOWN_RC
* determine length of outSingle
c callp getParmInf(3: dataType: currLen: maxLen:
c *omit)
...
* extract the token
c eval outSingle = %subst(workBlock:
c currPos:
c tokenLength)
WHAM! This clobbers storage elsewhere because I am changing the WHOLE
ALLOCATED SIZE of outSingle (64k) instead of the part allocated to me by the
caller (50 bytes.) Moral: Substring is your friend with *varsize! Let's
try this instead:
* extract the token
c eval %subst(outSingle: 1: maxLen) =
c %subst(workBlock:
c currPos:
c tokenLength)
which works as expected.
>But why not have your function just return outSingle
>instead of using a parameter?
Like this:
d templateBlockV s 65535 varying
d outSingleV s 100 varying
d deblock2 pr like(templateBlockV)
d inpSepChar 10 const varying
d inpBlock const like(workBlock)
d outRc like(SUCCESS_RC)
c eval outSingleV = deblock2(separator:
c blocked:
c rc)
This is the clearest and perhaps simplest answer of all, because as Jon
points out, the EVAL will "map" the returned value to whatever size string I
define. There are several issues:
o The procedure can't tell if the returned token is too large for the
assigned variable.
o I can't return multiple values.
In this case, I'd like to return the token and it's size so the caller can
see if "overflow" occurred. Not really a problem; put the size as an output
parameter and I'm good to go. But what if I need to return multiple
strings? Maybe I'm worried about something too theoretical.
If anybody's following this to this point <grin> does this demonstrate a
flaw in my thinking? If I need to return multiple variables, I mean.
Perhaps I should really break this into two functions: return a token and
return the token's size. Each function to return exactly one variable.
I'd like to thank everybody for their patience. I do hope that somebody
else will be able to learn from my stumbling about.
Buck Calabro
Commsoft; Albany, NY
Visit the Midrange archives and FAQ at http://www.midrange.com
"As a rule, men worry more about what they can't see than
about what they can." -- Julius Caesar
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.