15 pts.
 passing parameters via a datastructure to and from a procedure
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.

Software/Hardware used:
ASKED: October 10, 2008  6:40 PM
UPDATED: August 21, 2010  11:13 AM

Answer Wiki:
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 PI D ParmDS LIKE(SomeDataStruct) -------------------- //To call procedure (or if using fixed format, you'll need the CALLP operation code). Procedure1 ( SomeDataStructure) ; CWC
Last Wiki Answer Submitted:  October 13, 2008  6:39 pm  by  Cwc   4,275 pts.
All Answer Wiki Contributors:  Cwc   4,275 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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

 107,695 pts.