Returning multiple values from single function

vivek4121vivek4121 Member Posts: 165
Hello,

Can anyone help me in that, how can I return multiple values from one function?

As NAV allowed to select only one return type in function declaration.

Thanks in advance.

Comments

  • SiStSiSt Member Posts: 46
    You can pass parameters by reference (VAR) and change the value of the parameter in the function. But depending on what you want to do it is often times considered as a bad programing style to return more than one value. Have, for example, a look ad the DATE2DMY function from NAV, which you have to call three times to get all three return values.
  • vivek4121vivek4121 Member Posts: 165
    What according to you " and change the value of Parameter in the function"?
  • SiStSiSt Member Posts: 46
    Create a function and define two parameter, for example, Ret1 and Ret2 Check the "Var" mark before the variables.

    At the begin of the function it is a good idea to reset the variables to their default values:
    CLEAR(Ret1);
    CLEAR(Ret2);
    
    // Some code
    Ret1 := 'Return value 1';
    Ret2 := 'Return value 2';
    

    You can now call this function from another place:
    MyFunction(x, y);
    // x is the first return value, y the second one
    MESSAGE('Value of x: %1 Value of y: %2', x, y);
    
  • vivek4121vivek4121 Member Posts: 165
    Thanks.
Sign In or Register to comment.