|
Scott,
Thanks for the help. I removed the OPTIONS(*varsize) keyword and the
procedure worked like a charm.
Thanks again,
Mark
----- Original Message -----
From: Scott Klement <infosys@klements.com>
To: <RPG400-L@midrange.com>
Sent: Monday, December 20, 1999 6:39 PM
Subject: Re: Procedure Problem
> Hi Mark,
>
> I'm really glad you included the source code... it made it easy for
> me to understand what you needed help with!
>
> First of all, lets take a look at your prototype... Note that you
> are passing your parameters by REFERENCE as opposed to passing it
> by VALUE. Passing by reference is the default method, and its
> certainly the one that I prefer for passing strings, since its
> faster, and you can return changes to the string and have it be
> changed in the calling routine. However, please understand that
> this means that the compiler is actually passing the ADDRESS
> in main storage to your procedure, *NOT* the values of the bytes
> that are stored there!
>
> So, when you pass "dsshpnm" to the Center sub-proc, what its
> actually receiving is a pointer to the start of the area of memory
> where dsshpnm is stored.
>
> Next, you're using the MOVEA op-code to move instring to work_arr.
> Since instring is defined as 256 bytes long, you're actually
> telling the computer to move "256 bytes, starting at the
> address of the dsshpnm variable"
>
> Do you see why this results in you passing the remainder of the
> data structure? If you look more closely, you'll probably see
> that its also passing additional data after your data structure,
> since the DS is only 155 bytes long, but instring is 256!
>
> A few things pop into my mind. First, its important that when
> you use OPTIONS(*VARSIZE) that you find out the length of the
> original variable thats being passed, and make sure you ONLY use
> THAT MUCH of the variable. (Imagine if you were changing the
> data that was passed! If you're not careful, you could end up
> accidentally changing the values of other variables in memory!!!)
> Presumably, this is why you're passing the Len parameter to begin
> with!
>
> Second, you could simply remove the options(*varsize) from your
> prototype/interface. What good is it really doing you? This way,
> you could use "instring" as a 256 byte string without any problems.
>
> Third, if you do want to use options(*varsize) you could use an
> operational descriptor to get the string length, and then make
> sure that you only reference that length of data...
>
> Here's an example of this:
>
> D* Note the OPDESC keyword, this tells the calling routine to
> D* pass an operational descriptor for each parameter...
> D Center PR 256A OPDESC
> D instring 256A Const Options(*varsize)
>
> D* I'm at V3R2, and so I can't directly reference "shiptods"
> D* in the overlay statements. However, the way you were
> D* doing it should work fine...
> D shiptods ds
> D dswhole 155
> D dsshpnm 35 overlay(dswhole:1)
> D dsship1 35 overlay(dswhole:36)
> D dsship2 35 overlay(dswhole:71)
> D dsship3 35 overlay(dswhole:106)
> D dsshpst 2 overlay(dswhole:141)
> D dsshpzp 10 overlay(dswhole:143)
> D dsshpco 3 overlay(dswhole:153)
>
> C* test the center sub-proc
> c eval dsshpnm = 'CENTER ME'
> c eval output = Center(dsshpnm)
> c dsply output 35
>
> c eval *inlr = *on
>
>
> P*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> P* routine to center text within its own field...
> P*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> P Center B
> D Center PI 256A OPDESC
> D instring 256A Const Options(*varsize)
>
> D* This API is documented in the Integrated Language Enviornment (ILE)
> D* CEE API's manual.
> D GetStrInf PR ExtProc('CEEGSI')
> D ParmNum 10I 0 const
> D DataType 10I 0
> D CurrLen 10I 0
> D MaxLen 10I 0
>
> D dataType S 10I 0
> D currLen S 10I 0
> D maxLen S 10I 0
> D work_str S 256A
> D work_rtn S 256A
> D work_pad S 10I 0
>
> C* Find out how long instring is...
> c callp GetStrInf(1: dataType: currLen: maxLen)
>
> C* Only use the amount that was passed...
> c eval work_str = %subst(instring: 1: currLen)
>
> C* how many spaces do we need to pad the string to make it centered?
> C ' ' checkr work_str work_pad
> c eval(h) work_pad = (currLen - work_pad) / 2
>
> C* pad the string
> c eval work_rtn = *blanks
> c eval %subst(work_rtn:work_pad+1) = work_str
>
> C* return the result
> c return work_rtn
> P E
>
>
> Hope that helps!
>
>
>
> "Mark Walter" <mwalter@netrax.net> wrote:
> > All,
> >
> > I have a service program of string handling routines I am trying to
> > develop. I have a procedure called "Center" that receives a string
> > and an output len then centers the text into a field. I defined the
> > parameters as 256 with the CONST and OPTIONS(*varsize) keywords. The
> > problem is when i try to pass a sub-element of a data structure to
> > the procedure, the entire data structure is passed, not just the
> > sub-element. I have included code snippets below.
> >
> > TIA
> >
> > Mark Walter
> >
> > Test program module source
> >
> > Dshiptods ds 155
> > D dsshpnm 35 OVERLAY(shiptods:1)
> > D dsship1 35 OVERLAY(shiptods:36)
> > D dsship2 35 OVERLAY(shiptods:71)
> > D dsship3 35 OVERLAY(shiptods:106)
> > D dsshpst 2 OVERLAY(shiptods:141)
> > D dsshpzp 10 OVERLAY(shiptods:143)
> > D dsshpco 3 OVERLAY(shiptods:153)
> > *
> > Dlen s 3p 0 INZ(35)
> > Doutput s 35
> > Dcusno s 8 0 inz(206800)
> > Dstore s 8 inz('A1889')
> > *
> > C EVAL shiptods = GetShipto(cusno:store)
> >
> > C EVAL output = Center(dsshpnm:len)
> > C output DSPLY
> > C CLEAR output
> >
> > String handling service program
> >
> > HNOMAIN
> >
> > * module prototypes
> >
> > DCenter PR 256
> >
> > D instring 256 OPTIONS(*varsize) CONST
> >
> > D strlen 3p 0 CONST
> >
> > * Procedure Interface
> >
> > PCenter B EXPORT
> >
> > DCenter PI 256
> >
> > D instring 256 OPTIONS(*varsize) CONST
> >
> > D strlen 3p 0 CONST
> >
> > * work fields
> >
> > D outstring S 256
> >
> > Dwork_arr S 1 DIM(256)
> >
> > Dx S 3 0
> >
> > Dstrt S 3 0
> >
> > C MOVEA instring work_arr
> >
> >
> > Instring contains the entire data structure
>
> +---
> | This is the RPG/400 Mailing List!
> | To submit a new message, send your mail to RPG400-L@midrange.com.
> | To subscribe to this list send email to RPG400-L-SUB@midrange.com.
> | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
> | Questions should be directed to the list owner/operator:
david@midrange.com
> +---
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---
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.