0

I need to write a job where i could fetch the index of an array element of EDT Dimension e.g. In my EDT Dimension i have array elements A B C when i click over them for properties I see the index for A as 1, B as 2 and C as 3. Now with a job ui want to fetch the index value. Kindly Assist.

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
piku
  • 471
  • 4
  • 12
  • 44

3 Answers3

0

I'm not sure if I did understand the real problem. Some code sample could help.
The Dimensions Table has some useful methods like arrayIdx2Code.

Maybe the following code helps:

static void Job1(Args _args)
{
    Counter         idx;
    Dimension       dimension;
    DimensionCode   dimensionCode;
    str             name;
    ;
    for (idx = 1; idx <= dimof(dimension); idx++)
    {
        dimensionCode = Dimensions::arrayIdx2Code(idx);
        name = enum2str(dimensionCode);
        // if (name == 'B') ...
        info(strfmt("%1: %2", idx, name));
    }
}
user85421
  • 28,957
  • 10
  • 64
  • 87
  • Hi Carlos thanks for your response but i want the index of array elements in dimension. And the job you gave returns the elements of Base Enum `SysDimension` – piku May 06 '11 at 12:52
  • should be the same result (for `Dimension`) – user85421 May 09 '11 at 09:51
0

I found a way but still looking if there is any other solution.

static void Job10(Args _args)
{

    Dicttype    dicttype;
    counter     i;
    str         test;
    ;
    test = "Client";
    dicttype = new dicttype(132);//132 here is the id of edt dimension 

    for (i=1;i<=dicttype.arraySize();i++)
    {
        if ( dicttype.label(i) == test)
        {
            break;
        }
    }
    print i;
    pause;

}
piku
  • 471
  • 4
  • 12
  • 44
0

Array elements A B C from your example are nothing else but simple labels - they cannot be used as identifiers. First of all, for user convenience the labels can be modified anytime, then even if they aren't, the labels are different in different languages, and so on and so forth.

Overall your approach (querying DictType) would be correct but I cannot think of any scenario that would actually require such a code.

If you clarified your business requirements someone could come up with a better solution.

10p
  • 5,488
  • 22
  • 30
  • Thanks for notifying :) All I want to do is in the below query `queryRun.query().dataSourceTable(tablenum(LedgerTrans)).addange(fieldId2Ext(fieldNum(LedgerTrans, Dimensions), dimension)).value(dimensionValue);` the `dimension` here is the index value. So i was trying to match the lable through a for loop as you could see in the job(my answer) and get the index value(which i dont think could be a reliable way). – piku May 12 '11 at 10:41
  • I understand your query but so far I don't understand why you need to retrieve the index value - don't you have it already? If you got your "dimensionValue" - how come you need to figure out the "dimension" (the index) that needs to be filtered? – 10p May 12 '11 at 11:55
  • in the query two values needs to be supplied `dimension` e.g. `Branch`(i need its array index) and `dimensionValue` e.g. `B001` thats why i need the index there. – piku May 12 '11 at 12:13
  • My point is that the developer knows where the values are coming from: it's either from a specific field on a form, or some variable, or a value returned by a specific function, etc. You shouldn't guess whether this is a `Branch` or not - your code should take the value from wherever it takes it from and at this point you already know if `fieldId2Ext(fieldNum(LedgerTrans, Dimensions), 0)` should be used or `fieldId2Ext(fieldNum(LedgerTrans, Dimensions), 1)` etc. - depends on where the dimensionValue is taken from. – 10p May 12 '11 at 15:00
  • Thanks for your comment but the value `dimension` here is selected from a combobox and the selection there can change e.g. may be `department` or `Branch` or `Horizontal` etc ... so i thought of the array index :( – piku May 13 '11 at 05:43
  • And the `dimensionValue` field is a stringEdit lookUp and gets populated based on the selection in the dropDown box. – piku May 13 '11 at 06:13
  • Exactly, so all you need to do is get the index from your combobox, it would be `int dimension = ComboBoxName.selection(); ; queryRun.query().dataSourceTable(tablenum(LedgerTrans)).addange(fieldId2Ext(fie­ldNum(LedgerTrans, Dimensions), dimension)).value(dimensionValue);` in your example above. That is if your combobox is of the `Dimension` type as well. – 10p May 13 '11 at 09:51
  • thats true but the thing is the `CB.selection()` returns Enum Value(which is e.g. `111` `231`) I need to pass the value as an array index `dimension` (of LedgerTrans) which are generally `<10` i.e. `1` `2` `3` `4` `5` etc depends on the no. of dimensions. Now if i pass the return value `int dimension` which would be suppose `231` something like `Dimesions[231]` it will trigger an error("out of range"), so i wrote the method in this thread. I hope I am able to explain the scenario. – piku May 13 '11 at 12:28
  • `switch (CB.selection()) { case 111 : dimension = 1; break; case 231 : dimension = 2; break; /* etc. */ }` – 10p May 13 '11 at 13:53
  • in that case there is another problem...when i add a new dimension i have to menually add in the switch statement... – piku May 16 '11 at 12:10