# programm

**URL:** <https://techcommunity.softwareag.com/t/programm/95039>\
**Category:** Forum\
**Tags:** Adabas-Natural, Adabas, Adabas-Code-Samples, Adabas-Natural-Cloud\
**Created:** [October 18, 2010, 9:57pm UTC](https://techcommunity.softwareag.com/t/programm/95039 "2010-10-18T21:57:58Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![swan](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/swan/32/296_2.png) [@swan](https://techcommunity.softwareag.com/u/swan)\
**Post date:** [October 18, 2010, 9:57pm UTC](https://techcommunity.softwareag.com/t/programm/95039/1 "2010-10-18T21:57:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Johnson1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/brian_johnson1/32/163_2.png) [@Brian\_Johnson1](https://techcommunity.softwareag.com/u/Brian_Johnson1)\
**Post date:** [October 18, 2010, 11:38pm UTC](https://techcommunity.softwareag.com/t/programm/95039/2 "2010-10-18T23:38:01Z")

</div>

Hi Swan,

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

PROGRAM FACTOR-P

```auto

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 *                                    
0100 CALLNAT 'FACTOR-N' #NUMBER #FACTOR   
0110 *                                    
0120 WRITE #NUMBER 'factorial =' #FACTOR  
0130 *                                    
0140 END                                  
```

SUBPROGRAM FACTOR-N

```auto

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             
0150 CALLNAT 'FACTOR-N' #PASS-NEXT #FACTOR    
0160 END-IF                                     
0170 *                                          
0180 END                                        
```

RESULTS:  
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.

---

<div class="post-metadata">

**Author:** ![swan](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/swan/32/296_2.png) [@swan](https://techcommunity.softwareag.com/u/swan)\
**Post date:** [October 19, 2010, 7:45pm UTC](https://techcommunity.softwareag.com/t/programm/95039/3 "2010-10-19T19:45:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Johnson1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/brian_johnson1/32/163_2.png) [@Brian\_Johnson1](https://techcommunity.softwareag.com/u/Brian_Johnson1)\
**Post date:** [October 19, 2010, 7:55pm UTC](https://techcommunity.softwareag.com/t/programm/95039/4 "2010-10-19T19:55:55Z")

</div>

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

[http://www.whobooks.com/pub.html](http://www.whobooks.com/pub.html)

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.

---

<div class="post-metadata">

**Author:** ![Ats](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@Ats](https://techcommunity.softwareag.com/u/Ats)\
**Post date:** [October 20, 2010, 11:43am UTC](https://techcommunity.softwareag.com/t/programm/95039/5 "2010-10-20T11:43:48Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [October 20, 2010, 11:47am UTC](https://techcommunity.softwareag.com/t/programm/95039/6 "2010-10-20T11:47:06Z")

</div>

> [@swan](#):
>
> 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

Natural’s documentation contains a tutorial:

[http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat639win/firststeps/fs-over.htm](http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat639win/firststeps/fs-over.htm)

plus a programming guide…

[http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat639win/pg/pg-over.htm](http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat639win/pg/pg-over.htm)

---

<div class="post-metadata">

**Author:** ![swan](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/swan/32/296_2.png) [@swan](https://techcommunity.softwareag.com/u/swan)\
**Post date:** [January 11, 2012, 5:39am UTC](https://techcommunity.softwareag.com/t/programm/95039/7 "2012-01-11T05:39:08Z")

</div>

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.

Thanks,  
Swan

---

<div class="post-metadata">

**Author:** ![sajith\_kumar](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@sajith\_kumar](https://techcommunity.softwareag.com/u/sajith_kumar)\
**Post date:** [January 8, 2013, 11:18am UTC](https://techcommunity.softwareag.com/t/programm/95039/8 "2013-01-08T11:18:25Z")

</div>

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,

IF #NUMBER \> 1  
0130 #PASS-NEXT := #NUMBER - 1   
0140 #FACTOR := #FACTOR \* #NUMBER  
0150 CALLNAT ‘FACTOR-N’ #PASS-NEXT #FACTOR  
0160 END-IF

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

regards

---

<div class="post-metadata">

**Author:** ![Brian\_Johnson1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/brian_johnson1/32/163_2.png) [@Brian\_Johnson1](https://techcommunity.softwareag.com/u/Brian_Johnson1)\
**Post date:** [January 9, 2013, 5:00pm UTC](https://techcommunity.softwareag.com/t/programm/95039/9 "2013-01-09T17:00:02Z")

</div>

(edited)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [January 9, 2013, 5:28pm UTC](https://techcommunity.softwareag.com/t/programm/95039/10 "2013-01-09T17:28:02Z")

</div>

The confusion stems from

```auto
0150 CALLNAT 'FACTOR-N' #PASS-NEXT #FACTOR
```

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

```auto
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 😉

---

<div class="post-metadata">

**Author:** ![Brian\_Johnson1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/brian_johnson1/32/163_2.png) [@Brian\_Johnson1](https://techcommunity.softwareag.com/u/Brian_Johnson1)\
**Post date:** [January 9, 2013, 7:53pm UTC](https://techcommunity.softwareag.com/t/programm/95039/11 "2013-01-09T19:53:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [January 9, 2013, 10:45pm UTC](https://techcommunity.softwareag.com/t/programm/95039/12 "2013-01-09T22:45:46Z")

</div>

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.

steve

---

<div class="post-metadata">

**Author:** ![sajith\_kumar](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@sajith\_kumar](https://techcommunity.softwareag.com/u/sajith_kumar)\
**Post date:** [January 10, 2013, 6:44am UTC](https://techcommunity.softwareag.com/t/programm/95039/13 "2013-01-10T06:44:12Z")

</div>

Thanks Wolfgang Winter

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:59pm UTC](https://techcommunity.softwareag.com/t/programm/95039/14 "2021-04-02T14:59:15Z")

</div>


