ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Truncate result of aritm. expression - Free form

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Truncate result of aritm. expression - Free form

    In fixed form RPGIV, the H spec option TruncNbr( *YES ) allow to have a small field as a result of a calculation regardless of loosing data (useful sometimes whe result comes from wrong data input).
    In free form RPGLE expression such rule does not aplly.
    How can I have a result field with length 3,0 when the calculation might have a result bigger than 3 digits?
    Ex:
    DaysToExpire = %diff(FutureExpire: %date: *days) ;
    where DaysToExpire is an output field length 3,0 and FutureExpire might be any formally correct date but with a big difference from today date.

    Thanks for a solution.
    Regards.

  • #2
    Re: Truncate result of aritm. expression - Free form

    One way around this


    If %diff(FutureExpire: %date: *days) > 999;
    DaysToExpire = 999;
    Else;
    DaysToExpire = %diff(FutureExpire: %date: *days);
    EndIf;

    Comment

    Working...
    X