can any one tell me recursion in natural with example of factorial …
please give me sourc code…[/b]

Hi Swan,

Please advise what you wish to do. Here is an example of recursion in Natural:


0010 	DEFINE DATA LOCAL                    
0020 	1 #NUMBER(P10)                       
0030 	1 #FACTOR(P29)                       
0040 	END-DEFINE                           
0050 	*                                    
0060 	#FACTOR := 1                         
0070 	*                                    
0080 	INPUT 'Find factorial:' #NUMBER      
0090 	*                                    
0110 	*                                    
0120 	WRITE #NUMBER 'factorial =' #FACTOR  
0130 	*                                    
0140 	END                                  


0010 	DEFINE DATA PARAMETER                      
0020 	1 #NUMBER(P10)                             
0030 	1 #FACTOR(P29)                             
0040 	LOCAL                                      
0050 	1 #PASS-NEXT(P10)                          
0060 	END-DEFINE                                 
0070 	*                                          
0080 	IF #FACTOR = 0                             
0090 	  #FACTOR := 1                             
0100 	END-IF                                     
0110 	*                                          
0120 	IF #NUMBER > 1                             
0130 	  #PASS-NEXT := #NUMBER - 1                
0140 	  #FACTOR := #FACTOR * #NUMBER             
0160 	END-IF                                     
0170 	*                                          
0180 	END                                        

1 factorial = 1
2 factorial = 2
3 factorial = 6
4 factorial = 24
5 factorial = 120
6 factorial = 720
7 factorial = 5040
8 factorial = 40320
9 factorial = 362880
10 factorial = 3628800
11 factorial = 39916800
12 factorial = 479001600
13 factorial = 6227020800

27 factorial = 10888869450418352160768000000

Be aware that you will likely hit a limit as Natural cannot call itself recursively infinitely deep, but it shows a Natural subprogram calling itself recursively at least 27 levels.

thanks brian…
brian, a am new user of natural ag can you suggest me any book regarding natural ag and adabas… please give me link

The best reference materials for Natural programming and Adabas concepts are from Meristem Systems Corporation’s WH&O books:

However, what you really need is training, which then will provide context to the books and also will be applied in your day to day activities. Please ask your employer about training opportunities they provide. New programmers should never start coding in Natural without at least some foundational level of training, even if the course is an in-house activity. There is no way you can start coding in Natural day one and know what you are doing, even if you know other programming languages.

Hi Swan,

To me, the code you asked (factorial) seems to be (generally) an assignment given at college level or training level. However, you won’t see such a basic code in real Natural world and would be mostly business logics. Hence, I feel you should start looking at Natural from business point of view.

I agree with Brian, look for some training and ask your trainer to give you business related assignments (yes possible with standard SAG files available like EMPLOYEE, VEHICLE etc).

Natural’s documentation contains a tutorial:

plus a programming guide…

Hello All,

I have problem regarding Natural Community Edition i.e. My Community Edition has been expired.
The Expiry Date was 31-12-2011 in license file.
I am unable to use my community edition can any one tell me where i can find the new license file of 2012??
please share me the link.


hi ,
in the factoial example. one doubt i have, iam rookie in adabas, but in the pgm that is mentioned, how doers the variable ‘number’ decrement,

0130 #PASS-NEXT := #NUMBER - 1
0160 END-IF

the page-next will decrement the variabel by 1. but its value remains same. .pls correct me



The confusion stems from


simply because #PASS-NEXT is sent to FACTOR-N where it is picked up as #NUMBER due to

0010    DEFINE DATA PARAMETER                        
0020    1 #NUMBER(P10)                               
0030    1 #FACTOR(P29)

So although it looks like #NUMBER doesn’t change … it does, that’s exactly where the recursion kicks in :wink:

I thought this was a new snippet. I shoulda looked above at the previous posts to see the larger code block. :oops:

One quick note. So that you do not make it too obvious you are a newbie.

There is no such thing as “Natural ag”.

The company that developed Adabas and Natural is Software AG.

AG is an abbreviation for Aktiengesellschaft, which is the German equivalent of Limited or Incorporated.


Thanks Wolfgang Winter