I wish i could do some reflection using RPGLe. By reflection, I mean : 'The process or mechanism of determining the capabilities of an object at run-time.'
Imagine you have this datastructure :
D DS_Format DS Qualified Based(pDS_Format)
D Type 20I 0 Inz(1)
D Label 50A Inz('myLabel')
D Description 5000A Inz('myDescription')
With a reflection api, I could do this :
Reflection_ListSubfields(DS_Format);
=> return this array : { 'Type', 'Label', 'Description' }
And then, I could do :
Reflection_GetSubfield(DS_Format : 'Label'); => return 'myLabel'
I wish i could do this too :
Reflection_GetSubfieldType(DS_Format : 'Label'); => return 'A'
Reflection_GetSubfieldLength(DS_Format : 'Label'); => return 50
Reflection_GetSubfieldPrecision(DS_Format : 'Type'); => return 0
With this, I expect I could do something like this (with some little work) :
SerializeXml(DS_Format); //I build xml with one line of code !
And get :
<DS_Format>
<Type>1</Type>
<Label>myLabel</Label>
<Description>myDescription</Description>
</DS_Format>
And conversely with DeserializeXml(myXml);
Reflection would help me to build really cool apis. Is there any way ?
I have been contemplating some of these concepts, and may have a work around. (I don't have time at the moment to write a full answer & flesh out the details yet, but waited you to see there is some hope ;-) although some may consider it a cheat.)
The basic concept is this: IF you define a table with the desired format if your days structure, enabling the DS to be externally defined, then with embedded SQL you could DESCRIBE the table or query SYSCOLUMNS to get your field definitions, preferably in procedures.
Granted, this is not the same thing as refection, but could accomplish much the same. And one would probably only do this in limited circumstances. I'm sure others will point out a variety of issues, but the point here is that it is possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With