For Each... Next equivalent - IBM AS400

This is a discussion on For Each... Next equivalent - IBM AS400 ; Hi, Is there a way to programmatically scan the fields of a data structure in RPG ILE (V5R4), so we can retrieve the sub-field? And for each one, retrieve the subfield definition? VB has such a thing call "For Each... ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: For Each... Next equivalent

  1. For Each... Next equivalent

    Hi,

    Is there a way to programmatically scan the fields of a data structure
    in RPG ILE (V5R4), so we can retrieve the sub-field? And for each one,
    retrieve the subfield definition?

    VB has such a thing call "For Each... Next" that allows to scan a
    structure and to retrieve all the sub-elements contained in it.

    Let's say I have this data structure:

    D myDs Ds
    D myNum1 15S 0
    D myAlpha1 10A
    D myNum2 11P 2

    The "For Each... next" equivalent should then give me:

    Loop 1) Subfield = myNum1, Type = "S", Length = 15, Decimals = 0
    Loop 2) Subfield = MyAlpha1, Type = "A", Length = 10 Decimals = 0
    Loop 3) Subfield myNum2, Type = "P", Length = 11, Decimals = 2

    Thanks


  2. Re: For Each... Next equivalent

    Jack,

    As far as I know there is no such way for RPG. However if you can use an external data structure you
    can use my RTVFLDA (Retrieve Field Attributes) utility to retrieve the field definition one by one.

    The utility uses the QDBRTVFD API and it is quite fast because there is no user space involved.

    The information returned is:

    *================================================= ==============*
    * QDBRTVFD API - FLDA0310 *
    * ================================================== =========== *
    D flda0310_t...
    D DS qualified
    * File name
    D file 10A
    * Library name
    D lib 10A
    * Field name
    D name 10A
    * Data type
    D type 1A
    * Use
    D use 1A
    * Output buffer position
    D outBufPos 10I 0
    * Input buffer position
    D inBufPos 10I 0
    * Field length in bytes
    D length 10I 0
    * Digits
    D digits 10I 0
    * Decimal position
    D decPos 10I 0
    * Field text description
    D text 50A
    * Edit code
    D edtC 2A
    * Edit word length
    D edtWLen 9B 0
    * Edit word
    D edtW 64A
    * Column heading 1
    D colHdg1 20A
    * Column heading 2
    D colHdg2 20A
    * Column heading 3
    D colHdg3 20A
    * Date and time format
    D datTimFmt 4A
    * Date and time separator
    D datTimSep 1A
    *
    * Additional fields of format FLDA0200
    * Reference file name
    D refFile 10A
    * Reference library name
    D refLib 10A
    * Reference record format name
    D refFmt 10A
    * Reference field name
    D refFld 10A
    *
    * Additional fields of format FLDA0300
    D alwNull N
    D ccsid 10U 0
    *
    * Additional fields of format FLDA0310
    D varLength N
    D buffLength 10I 0
    D alcLength 10I 0
    *

    The basic operation sequence is:

    D isFound S N inz
    D handle S like(fldDct_handle_t) inz
    D FLDA0310 DS likeds(FLDA0310_t ) inz

    f_fldDct_new(i_file: i_lib: '*FIRST': handle);

    isFound = f_FldDct_rtvFldAtr(handle: cFLDDCT_FLD_FIRST: FLDA0310: 'FLDA0310');

    dow isFound;
    f_FldDct_rtvFldAtr(handle: cFLDDCT_FLD_NEXT: FLDA0310: 'FLDA0310');
    enddo;

    You can download RTVFLDA from here:

    http://www.tools400.de/English/Freew...list_apis.html


    Thomas Raddatz.


    Jack schrieb:
    > Hi,
    >
    > Is there a way to programmatically scan the fields of a data structure
    > in RPG ILE (V5R4), so we can retrieve the sub-field? And for each one,
    > retrieve the subfield definition?
    >
    > VB has such a thing call "For Each... Next" that allows to scan a
    > structure and to retrieve all the sub-elements contained in it.
    >
    > Let's say I have this data structure:
    >
    > D myDs Ds
    > D myNum1 15S 0
    > D myAlpha1 10A
    > D myNum2 11P 2
    >
    > The "For Each... next" equivalent should then give me:
    >
    > Loop 1) Subfield = myNum1, Type = "S", Length = 15, Decimals = 0
    > Loop 2) Subfield = MyAlpha1, Type = "A", Length = 10 Decimals = 0
    > Loop 3) Subfield myNum2, Type = "P", Length = 11, Decimals = 2
    >
    > Thanks
    >


  3. Re: For Each... Next equivalent

    On 20 Jun., 22:13, Thomas Raddatz wrote:
    > Jack,
    >
    > As far as I know there is no such way for RPG. However if you can use an external data structure ....


    If he already uses an external data structure, it may be easier to
    retrieve the data types by querying the Catalog view SYSCOLUMNS
    (located in the QSYS2-Lib).

    .... and RPG has no equivalent for FOR EACH ... NEXT over a data
    structure.
    The only way would be, if all fields would have the same data type and
    length. In this way the datastructure can be overlayed by an array.
    This array can be read with FOR ... NEXT.

    Birgitta


+ Reply to Thread