blank in a numeric field

Software AG's platform-independent programming language with full support for open-source and Internet applications
alex65
Posts: 1
Joined: Mon Jun 19, 2017 1:02 pm
Skillset: adabas/natural
Referer: google

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?!

Code: Select all

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

Robert Sample
Global moderator
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Skillset: Systems programming, SAS, COBOL, CICS, JCL, SMS, VSAM, etc.
Referer: other forum
Location: Dubuque, Iowa, USA

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.

Angeltor
Posts: 1
Joined: Thu Jan 18, 2018 10:18 pm
Skillset: Adabas, DB2, Natural, JCL, TSO, ISPF
Referer: Google

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:

Code: Select all

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.


  • Similar Topics
    Replies
    Views
    Last post