Search code examples
ibm-midrangerpglerpg

Retrieving names of data structure fields


i want to retrieve the field names of a data structure. Is that possible? My plan is to write a toString() procedure to dump a given data structure. For example i could print all field names and values of the ds as JSON.


Solution

  • While RPG doesn't truly support "reflection" like C# for instance does, in the last few years IBM has added "open access" functionality.

    Originally, open access worked with file I/O op-codes. Then IBM for v7.2+ added the DATA-INTO op-code for parsing into a data structure. In the fall of 2019 for v7.3+ IBM added the DATA-GEN op-code for generating from a data structure.

    You're free to code your own parser or generator.

    However, Scott Klement has kindly provided a parser (YAJLINTO) and generator (YAJLDTAGEN) into his and David Russo's original open source IBM i port of "Yet Another JSON Library (YAJL)".