Type Conversion: Code := Text

user323user323 Member Posts: 3
The following code is giving me an odd error -- I thought it was always possible to convert CODE to TEXT:
Report - OnPostReport()
AddDimVal('SEGMENT', '2300', 'QSR', 3);
AddDimVal('SEGMENT','2399','QSR Total',4);
AddDimVal('END-USER-SEGMENT','2300','QSR',3);
AddDimVal('END-USER-SEGMENT','2399','QSR Total',4);

AddDimVal(VAR DimCode : Code[20];VAR ValCode : Code[20];VAR Name : Text[50];VAR Type : Option)
DimVal.INIT;
DimVal."Dimension Code" := DimCode;
DimVal.Code := ValCode;
DimVal.Name := Name;
DimVal."Dimension Value Type" := Type;
IF NOT DimVal.INSERT(TRUE) THEN
  MESSAGE('Dimension Value with\Dimension Code=%1\Code=%2\aready exists', DimVal."Dimension Code", DimVal.Code);
CLEAR(DimVal);


Type conversion is not possible because 1 of the operators contains an invalid type.

Code := Text


Any ideas?????

Answers

  • matttraxmatttrax Member Posts: 2,309
    I believe it's because you're passing the parameters by reference instead of value.

    Since it is reference, it is expecting an actual CODE variable, and 'Text' always defaults to text. Since those values don't change inside the function, they should be passed by value instead.
  • user323user323 Member Posts: 3
    Ah, of course!

    Thanks for the quick and correct help!
  • aquawateraquawater Member Posts: 71
    matttrax wrote:
    I believe it's because you're passing the parameters by reference instead of value.

    Since it is reference, it is expecting an actual CODE variable, and 'Text' always defaults to text. Since those values don't change inside the function, they should be passed by value instead.

    Sorry could you mind to tell me how to pass by parameters and by values in C/AL.
    I am reading the documentation, but there is no sample.
    How am I supposed to know just from the following guide. It only explains the meaning of pass by value and reference in general programming language. I know that !! But what is the syntax in CAL.
    Pass By Value

    Sometimes a parameter is passed to a function strictly to give the function
    information. In that case, the parameter is said to be passed, or called, by value.
    In this case, the parameter knows just the value of the variable or expression used
    for the parameter. Since it is just a value, any change that the function does to
    this parameter does not affect any variables in the calling trigger.

    Pass By Reference
    Other times, a parameter is passed to the function and the function modifies that
    parameter. In this case, the parameter is said to be passed, or called, by reference
    or by name. The parameter actually knows the variable's location in the computer
    memory that it represents. The parameter passes the computer memory location
    to the new function. Any changes that the function makes to this type of
    parameter are permanent and affect variables in the calling trigger.

    These concepts are covered more thoroughly in the next section. However, there
    is one important thing to note at this point. If a parameter is passed by value, then
    you can use any expression for that parameter. However, if a parameter is passed
    by reference, you must use a variable for that parameter so that its value can be
    changed. A variable has a location in memory, whereas an expression or a
    constant does not.
  • aquawateraquawater Member Posts: 71
    Answering to my own question:

    VAR indicates passed by reference
    (without VAR) indicates passed by VALUE..

    #-o
Sign In or Register to comment.