ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

%Uns - not working with negetive number

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

  • %Uns - not working with negetive number

    hi,

    below code is giving this runtime error "The target for a numeric operation is too small to hold the result"

    Code:
     D UnsVar          S             15P 5                              
     D Var1            S              3P 0                              
                                                                        
     C                                                                  
      /Free                                                             
                                                                        
          Var1 = -99 ;                                                  
          UnsVar = %Uns(Var1) ;                                         
          Dsply %Char(UnsVar) ;                                         
                                                                        
      /End-Free                                                         
     C                   SetOn                                        LR
    with positive number program works fine.

    can anyone please tell why its not accepting negative value

    thanks

  • #2
    Re: %Uns - not working with negetive number

    can anyone please tell why its not accepting negative value
    Because it works as designed and described!

    %UNS() and Unsigned Integer (for example 10U 0) can only work with positive numbers.
    If you also need to convert negative numbers you have to use the built-in-functions %INT or %INTH.

    Birgitta

    Comment


    • #3
      Re: %Uns - not working with negetive number

      In the example given, where your "unsigned" variable can actually hold a sign (ie 15p5), you can use the %abs() bif to get rid of the sign. You ill probably find that you will use %abs far more often than %uns(). I believe with %uns, the result must be an unsigned data type, otherwise you get the error you received.
      Michael Catalani
      IS Director, eCommerce & Web Development
      Acceptance Insurance Corporation
      www.AcceptanceInsurance.com
      www.ProvatoSys.com

      Comment

      Working...
      X