EGL Development User Group

EGL Development User Group

EGL Development User Group

The EGL Development User Group is dedicated to sharing news, knowledge, and insights regarding the EGL language and Business Developer product. Consisting of IBMers, HCL, and users, this community collaborates to advance the EGL ecosystem.

 View Only
Expand all | Collapse all

Sorting Array of Data in EGL Service

  • 1.  Sorting Array of Data in EGL Service

    Posted Fri January 06, 2012 06:24 AM
    Hi,
    I am using RBD version 8.

    I had a couple of questions with arrays in EGL.

    1. Can I declare a 2 dimensional array with one dimension of type int and other of type string in my egl service.
    2. If I have created a two dimensional array then is there any way I can sort the array.

    Actually my scenario is that I need to get the sequece of operation from database file in one dimenstion of array and then put my egl step name against it in my second dimenstion.

    Thanks,
    Vivek Sharma
    VivekSharma57


  • 2.  Re: Sorting Array of Data in EGL Service

    Posted Sat January 07, 2012 11:37 AM
    Hi Vivek,

    I am making an assumption here, your sequence numbers are unique. If that's the case then you can use a Dictionary to sort your data. Example:

    myDictionary dictionary{Ordering = byKey};         // Put some data, the 'byKey' above will take of the sort        // Note that the key value has to be a string...        for (i int from 1 to 5)            myDictionary[i as string] = "My string data " :: i;        end                // Get the values from the dictionary and display them        stringArray string[] = myDictionary.getValues() as string[];                for (i int from 1 to stringArray.getSize())            SysLib.writeStdout(stringArray[i]);        end


    Of course, the example above is very simple.
    Actually, what you put as value into your dictionary can be any object. We quite often use a dictionary so sort data for display.

    Hope this helps.
    Willem.
    clogs


  • 3.  Re: Sorting Array of Data in EGL Service

    Posted Fri January 27, 2017 11:20 AM

    Hello Willem.

     


    I saw your post in the forum .. but I could not get the result of the classified data ..

    What have I done wrong? can you see ?



     

    The display shows the declassified data

    See my example ..

    Thank you for your attention ..

     

    Osvaldo Menezes

     

    ===========================================

        myDictionary dictionary{Ordering = byKey};
         w int = 0;
        dictionaryKey string = "";         

        for (i int from 1 to 5)
            if (i<3)
                w = i * 10;
            else
                   w = i;
            end
            
              dictionaryKey = "My string data " :: w;         
              
            myDictionary[dictionaryKey] = dictionaryKey :: " " :: i;
            
        end
        stringArray string[] = myDictionary.getValues() as string[];  
        for (i int from 1 to stringArray.getSize())
            SysLib.writeStdout(stringArray[i]);
        end

    ===========================================

     

     

    ojomenezes


  • 4.  Re: Sorting Array of Data in EGL Service

    Posted Mon January 30, 2017 02:11 AM

    Hi,

    do you want to sort a string array or a record?

     

    here is an example to sort a record:

     

            sortDictionary Dictionary{Ordering = byKey};        for(idx int from 1 to rec.getSize() by 1)            SORTKEY string = rec[idx].SORTKEY;            dictionaryKey string = SORTKEY;            sortDictionary[dictionaryKey] = rec[idx];        end        rec = sortDictionary.getValues() as YOUR_REC[];

     

     

    Kind Regards!

    Marcel-D


  • 5.  Re: Sorting Array of Data in EGL Service

    Posted Mon January 30, 2017 07:44 AM

    Hello Marcel ,,

    Congratulations, it worked.

    At first I was trying to sort an array ..

    With your hint, I've turned the data into a record and this into a record array, I've done the sorting and it worked.

    Thank you so much

     

    Osvaldo Menezes

    ==================================================================================================================================================================

    function TestOrder()
            C093WT222Array C093WT222[] = [];
            C093WT222 C093WT222;
            C093WT222.WT02-CHAVE = "6";
            C093WT222.WT02-DESCRICAO = "letter 6F";
            C093WT222Array.appendElement(C093WT222);
            C093WT222.WT02-CHAVE = "5";
            C093WT222.WT02-DESCRICAO = "letter 5E";
            C093WT222Array.appendElement(C093WT222);
            C093WT222.WT02-CHAVE = "4";
            C093WT222.WT02-DESCRICAO = "letter 4D";
            C093WT222Array.appendElement(C093WT222);
            C093WT222.WT02-CHAVE = "3";
            C093WT222.WT02-DESCRICAO = "letter 3C";
            C093WT222Array.appendElement(C093WT222);
            C093WT222.WT02-CHAVE = "2";
            C093WT222.WT02-DESCRICAO = "letter 2B";
            C093WT222Array.appendElement(C093WT222);
            C093WT222.WT02-CHAVE = "1";
            C093WT222.WT02-DESCRICAO = "letter 1A";
            C093WT222Array.appendElement(C093WT222);

            SysLib.writeStdout(" Applying the function - Ordering of dictionary for RECORD ");

            sortDictionary Dictionary{Ordering = byKey};
            for(idx int from 1 to C093WT222Array.getSize() by 1)
                SORTKEY string = C093WT222Array[idx].WT02-CHAVE;
                dictionaryKey string = SORTKEY;
                sortDictionary[dictionaryKey] = C093WT222Array[idx];
            end

            C093WT222Array = sortDictionary.getValues() as C093WT222[];

            for (i int from 1 to C093WT222Array.getSize())
                SysLib.writeStdout(C093WT222Array[i].WT02-CHAVE + " " + C093WT222Array[i].WT02-DESCRICAO);
            end

    end

    record C093WT222 type basicRecord
           WT02-CHAVE string;
           WT02-DESCRICAO string;
    end

     

     

     

    Log - Console

     

    ==================================================================================================================================================================

     Applying the function - Ordering of dictionary for RECORD
    1 letter 1A
    2 letter 2B
    3 letter 3C
    4 letter 4D
    5 letter 5E
    6 letter 6F
    A sessão de depuração foi finalizada.

     

    ==================================================================================================================================================================

     

    ojomenezes