blank in a numeric field



Software AG's platform-independent programming language with full support for open-source and Internet applications

blank in a numeric field

Postby alex65 » Mon Jun 19, 2017 1:20 pm

Hello
Why Natural treets a blank in a numeric field like a zero value?!

DEFINE DATA          
LOCAL                    
1 #F          (N3)        
1 REDEFINE #F            
  2 #N1        (N1)      
  2 #A2        (A1)      
  2 #N3        (N1)      
END-DEFINE                
#N1:= 1                  
RESET #A2                
DISPLAY #F                
IF #F = 100              
  WRITE '!!!' '=' #F      
END-IF                    
#F :=   #F * 2            
DISPLAY #F                
END                      

  #F                
 ----              
                   
  1 0              
 !!! #F:  1 0      
  200              


Thanks
alex65
 
Posts: 1
Joined: Mon Jun 19, 2017 1:02 pm
Has thanked: 0 time
Been thanked: 0 time

Re: blank in a numeric field

Postby Robert Sample » Mon Jun 19, 2017 7:17 pm

It depends upon what Natural does internally. If numeric values are converted from zoned decimal to packed decimal for operations, then blanks are X'40' and the first 4 bits (the zone) will be ignored and only the second 4 bits will be treated as the value -- and since a zero is X'F0' you cannot tell the difference between a blank and a zero once the value is packed.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: blank in a numeric field

Postby Angeltor » Fri Jan 19, 2018 1:22 am

You are redefining a numeric field. The alphabetic fields are allowed to help the development. the null value on the alphabetic field is transformed on the null value fot the numeric field. If you tried to put any letter it will fail in the moment you use the numeric field. Also you are not using the concept correctly.

This would be the normal use of it:

DEFINE DATA
*
LOCAL
*
1 #DATE (N8)
1 REDEFINE #DATE
2 #DATE-Y (N4)
2 #DATE-M (A2)
2 #DATE-D  (N2)
*
END-DEFINE
*
#DATE := 20170501
*
WRITE '=' DATE-M
WRITE '=' DATE-D
WRITE '=' DATE-Y
*
END

Output:
DATE-M 05
DATE-D  1
DATE-Y  2017
 

So, you can use it to present dates with leading zeros or other numeric/alphabetic manipulations where you need not lose the leading zeros.
Angeltor
 
Posts: 1
Joined: Thu Jan 18, 2018 10:18 pm
Has thanked: 0 time
Been thanked: 0 time


Return to Natural

 


  • Related topics
    Replies
    Views
    Last post