1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Return Default Value When No Match Found

Discussão em 'StackOverflow' iniciado por fdantas, Agosto 22, 2019.

  1. fdantas

    fdantas Administrator Moderador

    I have a function GetQuantity that returns a decimal. In some cases I want to return nothing i.e. and empty string so that ' ' is displayed.

    Actual Behavior:

    1. GetQuantity(1) -> 1.0
    2. GetQuantity(2) -> 2.0
    3. GetQuantity(3) -> 3.3

    Desired Behavior:

    1. GetQuantity(1) -> 1.0
    2. GetQuantity(2) -> 2.0
    3. GetQuantity(3) -> ' '

    In case 3 I can obviously return -1.0 or something but that is not what I need.

    FUNCTION GetQuantity RETURNS DECIMAL(INPUT num AS INTEGER):
    DEFINE VARIABLE quantity AS DECIMAL NO-UNDO FORMAT "->,>>>,>>9.9<<<<<<<<".

    quantity = 3.3. //initialization is neccessary as IRL my value is initialized

    IF num = 1 THEN DO:
    RETURN 1.0.
    END.

    ELSE IF num = 2 THEN DO:
    RETURN 2.0.
    END.

    RETURN quantity. //base case return ' '
    END.

    DISPLAY GetQuantity(3)

    Continue reading...

Compartilhe esta Página