How to make values into variables?

rocopsarocopsa Member Posts: 38
Hi experts,

I have a table (TableA) storing the desired variable names (Var1, Var2) by cases.

TableA:
(Fieldname: Case - Var)
Case1 - Var1
Case2 - Var2
Case3 - Var1
...etc.

Then, in report, Var1 and Var2 are registered in G/AL Globals as variables and the values are defined as VarValue1 and VarValue2.

My desired result in report is:
Case1 - VarValue1
Case2 - VarValue2
Case3 - VarValue1

By the following function, I can have the above result. Yet, it will be very clumsy as there are plenty of Var1, Var2,....
CASE TableA.Var OF
'Var1': EXIT(Var1);
'Var2': EXIT(Var2);
END;

How can I code it smartly without the need to do the above declaration? (as TableA.Var already telling what variable to return).

I've tried the following but it just give me texts of 'Var1' and 'Var2' but not VarValue1 and VarValue2.
EXIT(TableA.Var);

Please help! #-o

Thanks in advance!!!

Comments

  • mabl4367mabl4367 Member Posts: 143
    I'm not sure I have understood you completly.

    Why not add a field "Value" to to the variable table. then the function could look like this:

    recVarTable.GET(VarName);
    EXIT(recVarTable.Value);
  • BeliasBelias Member Posts: 2,998
    no...you can't do such a thing...a variable name can't be retrieved from a value...
    'Var1' is a text value and if you "exit" it, you're exiting the text 'Var1' not the variable named Var1
    BUT
    You can use an array, for example, if you insert in your table (mytable) integer values (field varindex)
    you can then do
    EXIT(myvariable[mytable.varindex]);
    
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • rocopsarocopsa Member Posts: 38
    Thanks, Belias,

    It works fine if I turned all the variables in the table as integers.

    Thanks a bunch! :D
  • BeliasBelias Member Posts: 2,998
    I hope you really understood what i told...your last message was not really clear...did you use arrays?
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • rocopsarocopsa Member Posts: 38
    Dear Belias,

    Yes, I added a variant (varResult) with Array in the Report and changed all the Var1, Var2 in TableA into integers 1, 2.

    Then, replace the variable name Var1, Var2 in Report as varResult[1], varResult[2], etc.

    It then works fine with:
    EXIT(varResult[TableA.Var]);

    Just one line then I can save all the clumsy declarations in Report!

    Thanks again for such a great idea!
  • BeliasBelias Member Posts: 2,998
    rocopsa wrote:
    Dear Belias,

    Yes, I added a variant (varResult) with Array in the Report and changed all the Var1, Var2 in TableA into integers 1, 2.

    Then, replace the variable name Var1, Var2 in Report as varResult[1], varResult[2], etc.

    It then works fine with:
    EXIT(varResult[TableA.Var]);

    Just one line then I can save all the clumsy declarations in Report!

    Thanks again for such a great idea!
    Ok, you got it! :thumbsup: You're welcome
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.