|
> From: Fisher, Don > > If so, does this also mean that other procedures that also have this data > structure defined will also know the values? The reason I ask is I have a > file i/o module that handles multiple sort sequences. In this case, there > are four such sequences and a procedure that handles each one. These > procedures each execute a "Next Record", "Previous Record", and "Matching > Record" procedures. I would like the four procedures and their "children" > to manipulate this information independently from each the other three > procedures and their "children". Don, are the procedures in the same or different modules? If they are in the same module, you can specify the data structure once at the beginning of the module outside of any procedures, and it will be "global" to all the procedures in the module. If they are in different modules, you can simply pass the data structure between them, but that involves copying a lot of data. Another way to pass data structures between procedures is to use a pointer: Main procedure: DmyDS E DS EXTNAME(MYFILE) DmyPtr S * inz(%addr(myDS)) DmyKeyValue S like(MYKEY) DReadMYFILE PR * d Key like(MYKEY) value d Buffer * This creates a data structure with all the fields and a pointer to it called myPtr, as well as defining an external procedure that accepts a key and a pointer to a buffer. You pass a key and the address of this buffer to the called procedure: C eval myKeyValue = 'SOMEKEY' C if ReadMYFILE(myKeyValue:pBuffer) C (process record) C endif In your called procedures, you create a "BASED" data structure up at the top of your module. Then, before you do any I/O, you set the pointer of the based DS to the pointer passed in from the calling procedure: Called procedure: FMYFILE UF A E K DISK DmyDS E DS EXTNAME(MYFILE) BASED(pMYFILE) PReadMYFILE B export D PI * d Key like(MYKEY) value d Buffer * C eval pMYFILE = pBuffer C Key chain MYFILE C return %found(MYFILE) P e This procedure will chain to MYFILE using "Key", which is defined to be the same as MYKEY, a field in MYFILE. I use this all the time. Obviously you have to be careful to pass correct pointers, but once you get that done, this becomes really easy, and an excellent way to put all your I/O routines into one module. Joe
As an Amazon Associate we earn from qualifying purchases.
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.