Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RPGle - i wish i could do some 'Reflection' using RPGLe

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 ?

like image 392
Charles Martin Avatar asked Oct 30 '13 14:10

Charles Martin


1 Answers

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.

like image 151
WarrenT Avatar answered Dec 30 '22 06:12

WarrenT