View Full Version : Data structure parameter issue
B.Morris
12-12-2005, 03:07 PM
d_meca wrote: > > I am creating a procedure (within a service program) that accepts a data structure as a parameter. > > Since the procedure is generic it will receive different types of data structures. The length and type of the data structure being passed is unknown and will vary. > > Is there a way of finding the lengths/types/names of each field within the data structure being passed? > Can any of this be achieved using pointers? > If the data structure is externally-described from a file, you could also pass the file name to your procedure, and your procedure could use an API (QUSLFLD) to get the layout of the data structure (field names, lengths, types etc). Use google to search for this API - you should be able to find some RPG examples. If you add "extpgm" to your search, it will increase the likelihood of it being an RPG example. http://www.google.com/search?hl=en&q=quslfld+extpgm
Guest.Visitor
12-15-2005, 12:42 PM
Thanks Barbara. I have already implemented what you have described above. Now I'm trying to take the next step and use 'internal user defined data structures'. From what people have been telling me it looks like it can't be done.
Guest.Visitor
12-16-2005, 01:26 AM
I am creating a procedure (within a service program) that accepts a data structure as a parameter. Since the procedure is generic it will receive different types of data structures. The length and type of the data structure being passed is unknown and will vary. Is there a way of finding the lengths/types/names of each field within the data structure being passed? Can any of this be achieved using pointers? <hr width=50 align=left>Code ('http://www.mcpressonline.com/mc/showcode@@.6b324996')
odedf
12-16-2005, 01:26 AM
You can write the metadata in the same DS. for each field writre its attributes befor you send it . The srvpgm will read them and put in tPROGRAM A D abcd_DS DS D A_TYP 1A (= A,T,D...) D A_LNG 2S (= LENGTH) D A_DEC 2S (=LENGTH) D a 1a D b 2a D c 3a D d 4a D END 1A INZ('/') he proper filds. Use varchar will help.
B.Morris
12-16-2005, 01:03 PM
d_meca wrote: > > Thanks Barbara. I have already implemented what you have described above. Now I'm trying to take the next step and use 'internal user defined data structures'. From what people have been telling me it looks like it can't be done. Correct, a called procedure can't detect anything about a data structure parameter that it was passed, by on looking at the parameter's data. You would have to have some way of telling the procedure about the layout of the DS. Rather than have the information directly in the data structure as odedf suggested, I would add a separate parameter that described the data structure, probably as an array of data structures, with each element describing one subfield. But the complexity of defining the describing data structure might be too great compared to whatever your procedure does. Unless the program described data structures would have features that aren't supported by DDS, it would probably be easiest to have the programmers define a file to describe their data structure, and use your existing procedure.
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.