× 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 Eduard,

>>Or better said, the procedures just returns 19 positions overwritting 7
positions in other variables.
>>I can understand what is happening (although I do not want to understand
it).
>>Is this intended to happen?

Yes.

I'll try to explain clearly what happens.
The default for parameter passing is by reference. That means only a pointer
to the original field is passed to the called procedure. If you specify
OPTIONS(*NOPASS) for an input/output parameter (keywords CONST or VALUE are
not specified), the compiler accepts any length smaller than the maximum
length defined in the prototype.

Because the called procedure only receives a pointer, it's up to you to
check and handle the length of the incomming parameter. To achieve this, you
have to add the Keyword OPDESC in the prototype in the PR-Row. OPDESC (=
Operational Descriptor) allows you to determine the length of the incomming
parameter by using the API CEEDOD.
If you don't check the incomming length, and change the complete parameter
field (i.e. CLEAR), you'll override global storage. (That's what happened in
your case!)
To work correctly, you are only allowed to change the incomming number of
bytes.

In my opinion OPTIONS(*VARSIZE) in an input/output parameter should only be
used, if there is no other solution.
In most cases a varying text field will do the job.
If an parameter is input only, either the keyword VALUE or CONST should be
added to the parameter definition in the prototype. With specifying one of
these keywords different field length are handled correctly.

Birgitta



-----Ursprüngliche Nachricht-----
Von: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]Im Auftrag von Eduard Sluis
Gesendet: Freitag, 16. Dezember 2005 15:00
An: RPG400-L Midrange
Betreff: *VARSIZE parameter overwrites other variables.


Dear all,

  I have a procedure accepting an *VARSIZE parameter.
  On return other variables ar overwritten and as result, crashing the
program.
  The Procedure is defined as follow:
  D P_AMTCHR        PR             1a
D   AMTNUM                      14  0
D   AMTCHR                      19A   OPTIONS(*VARSIZE)
D   AMTLNG                      10i 0 VALUE
D   AMTSGN                       1A   CONST
D   AMTCCY                       3A   OPTIONS(*NOPASS)

  The execution is as follow:
  C                   EVAL      P_OK=P_AMTCHR(BITCHRSTP:
C                             SFLD6:%LEN(SFLD6):'-')
C                   EVAL      P_OK=P_AMTCHR(BITCHRIBN:
C                             SFLD7:%LEN(SFLD7):'-')

  Variable SFLD7 is in this example 12 positions (but could be any).
  The value in SFLD7 on return is correct.
  Variables defined after SFLD7 are altered.

  Here the specific part of the dump:
  SFLD7                 CHAR(12)             '       4.00-'
                      VALUE IN HEX         '40404040404040F44BF0F060'X
SFLMAX                PACKED(2,0)          04.              '4040'X
SSTAT                 CHAR(11)             '   ered    '

  Or better said, the procedures just returns 19 positions overwritting 7
positions in other variables.
  I can understand what is happening (although I do not want to understand
it).
  Is this intended to happen?

  Regards,
  Eduard Sluis.
--
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.

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.