|
What about MODS? Would all occurrences be available?
IBM hasn't created a prototype keyword to pass a MODS properly. I think this has to do with the bizarre nature of a MODS -- you can't unambiguously reference a particular element when you use the variable name! You have to select the element name with the OCCUR opcode or the %OCCUR BIF, and this makes it very difficult for the compiler to know the difference between the current occurrence and the whole structure.
Data structure arrays are a better choice, and I suggest that you use them instead of a MODS. Always.
But, since I know that not everyone will do that, here's how you pass a MODS:
A MODS is always stored in contiguous memory. The second occurrence is always immediately after the first occurrence, the third is always immediately after the 2nd, etc. Therefore, if you can get a pointer to the first occurrence, and base an identical MODS on that pointer, you'll be good to go.
For example: D TestMods ds occurs(50) D field1 10A D field2 9P 0 D IsModsOk PR 1N D mods like(TestMods) /free %occur(TestMods) = 1; if IsModsOk(TestMods); // there was much rejoicing endif; . . . P IsModsOk B D IsModsOk PI 1N D mods like(TestMods) D MyMods ds occurs(50) D based(p_Mods) D field1 10A D field2 9P 0 /free p_Mods = %addr(mods); // MyMods is now the MODS from the caller, starting // with the occurence that the caller had set when // he called this procedure. /end-free P E This is better than declaring a pointer on the prototype because:a) The caller doesn't have to do any pointer logic to call you. You should always make it as easy for the caller as possible when writing re-usable routines!
b) The use of LIKE on the prototype makes it more self-documenting that this is what you want passed for this parameter.
However, it obviously doesn't work as nicely because: a) You have to set the occurrence before calling. b) You have to do pointer logic in the called procedure c) You have to make a 2nd copy of the DS layout. d) You can't use CONST to improve and clarify the interface.So, again, I recommend using a data structure array instead. They work almost exactly like MODS, so I don't understand why you'd use a MODS.
D TestArray ds dim(50) D qualified D field1 10A D field2 9P 0 D IsArrayOk PR 1N D ary likeds(TestArray) D dim(50) /free if IsArrayOk(TestArray); // there was much rejoicing endif; P IsArrayOk B D IsArrayOk PI 1N D ary likeds(TestArray) D dim(50) /free for x = 1 to %elem(ary); if ( ary(x).field1 = 'foo' ); return *OFF; endif; endif; /end-free P E
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.