passing parameters via a datastructure to and from a procedure

15 pts.
iSeries RPG programming
Can anyone provide a simple example of passing data via a data structure from one procedure to another? I would like to call a procedure to post data to a transaction file using a data structure to pass the data.

Answer Wiki

Thanks. We'll let you know when a new response is added.

Basically the method is pretty similar to passing a “regular” parameter, only you define as a data structure and refer to that data structure on the prototype and procedure interface. Are you wanting pass by reference or by value? Passing by reference is implicit, but if you want to pass by value, just add the VALUE keyword to your parameter definitions.

Do you have an external definition for the data structure? I would recommend that, so that you won’t have to define it twice (once from the calling procedure and once to the receiving procedure or program). Also, you would be able to use in other programs or modules as well.

Below is a quick example. Note that the parameter names don’t have to match between the calling code and the receiving procedure; just as long as the signatures match. Ideally, you’ll want to define your data structure elsewhere in the Definition specifications, whether internal or external, so that you can just refer to it in your prototope. Use the EXTPGM keyword (on the PR line) if you were prototyping a call to another program and wanting to pass that same data structure.

D Procedure1 PR
D ParmDS LIKEDS(SomeDataStruct)

Here is that data structure internally defined (however, the column positions aren’t necessarily lined up correctly).
D SomeDataStruct DS
D Field1 10A
D Field2 2S 0

If you have an external definition, such as based on an externally described file, you could use the EXTNAME keyword to refer to that file, and then you wouldn’t need the individual field definitions because they’d be brought in from your external file.

In your incoming procedure, it would look similar.

P Procedure1 B
D ParmDS LIKE(SomeDataStruct)

//To call procedure (or if using fixed format, you’ll need the CALLP operation code).
Procedure1 ( SomeDataStructure) ;


Discuss This Question: 5  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • TomLiotta
    Note that DSes don't have "signatures" and they don't have to match between caller and callee. The normal rule for matching size for the entire length of the DS in the called procedure applies, and decimal data exceptions can be a problem if care isn't taken. Tom
    125,585 pointsBadges:
  • KimDinh
    I got it working.  Thank you for your instructions. 
    65 pointsBadges:
  • Mwasim400256
    its not working getting a decimal data  error

    10 pointsBadges:
  • JohnD2
    Where is it getting the error?
    15 pointsBadges:
  • Splat
    If you've defined one or more subfields as packed decimal data you'd be advised to initialise either the subfield(s) or the data structure.  The INZ keyword can be quite useful.
    12,915 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: