# Fetch vs Run in Natural

**URL:** <https://techcommunity.softwareag.com/t/fetch-vs-run-in-natural/102090>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-Code-Samples, Inside-Natural-and-Performance-Hints\
**Created:** [January 11, 2013, 6:45pm UTC](https://techcommunity.softwareag.com/t/fetch-vs-run-in-natural/102090 "2013-01-11T18:45:16Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naomi22](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/naomi22/32/7056_2.png) [@Naomi22](https://techcommunity.softwareag.com/u/Naomi22)\
**Post date:** [January 11, 2013, 6:45pm UTC](https://techcommunity.softwareag.com/t/fetch-vs-run-in-natural/102090/1 "2013-01-11T18:45:16Z")

</div>

Hi,

I’ve been investigating several programs and saw that a few of them are executing RUN commands. This was the first time I saw a code with a Run command in Natural. From what I’ve seen, run seems similar to Fetch except it compiles the code first before executing the object.

I was just wondering when do people use run over fetch and which one is more efficient.

Thanks in advance for any response.

---

<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 11, 2013, 10:52pm UTC](https://techcommunity.softwareag.com/t/fetch-vs-run-in-natural/102090/2 "2013-01-11T22:52:43Z")

</div>

Efficiency first. FETCH is more efficient than RUN. As you correctly stated, RUN requires a compilation, then an execution of the resultant object code. Since FETCH starts with the object code, no compilation is required.

So, why RUN? Simple. There is a facility in Natural I call “ampersand variables”, although technically, they are not variables at all.

Consider the following program (called report1)

FIND &FILE WITH &WITH  
DISPLAY &DISPLAY  
LOOP  
END

Note the three “ampersand variables”.

The above program cannnot be STOW’ed.

Suppose I now have a “driver program” as shown below:

INPUT 'enter file name==\> ’ +FILE (a32) // ‘enter serach criteria==\>’ +WITH (a50) // ‘enter display fields’  
+display (a50)  
RUN ‘REPORT1’

I enter in EMPLOYEES for +FILE NAME = ‘SMITH’ for +WITH and CITY COUNTRY for +DISPLAY

Now we RUN report1. At compile time, when Natural sees an ampersand variable, it looks for a global variable with the same name. It then does a text replacement.

Hence, the program to be compiled is

FIND EMPLOYEES WITH NAME = ‘SMITH’  
DISPLAY CITY COUNTRY  
LOOP  
END

At the end of the program report1 I could FETCH the driver program, enter in new report info, then RUN report1 again, generating a different report, etc.

steve

---

<div class="post-metadata">

**Author:** ![Naomi22](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/naomi22/32/7056_2.png) [@Naomi22](https://techcommunity.softwareag.com/u/Naomi22)\
**Post date:** [January 23, 2013, 4:10pm UTC](https://techcommunity.softwareag.com/t/fetch-vs-run-in-natural/102090/3 "2013-01-23T16:10:10Z")

</div>

Thanks so much for this Steve. This helped a lot! 😃

---

<div class="post-metadata">

**Author:** ![Vasanth\_Murali](https://avatars.discourse-cdn.com/v4/letter/v/ce73a5/32.png) [@Vasanth\_Murali](https://techcommunity.softwareag.com/u/Vasanth_Murali)\
**Post date:** [March 13, 2015, 3:36pm UTC](https://techcommunity.softwareag.com/t/fetch-vs-run-in-natural/102090/4 "2015-03-13T15:36:40Z")

</div>

Hey Steve,

I know this is a old post, but thought of asking a follow up question.

I am using a program to call another sub program ( passing data using ambersant variables)

After the called program completes, I now want to run it from the next step of main program ( Like the fetch back).

So is it possible with RUN? I checked the documentation and didn’t find anything.

Regards,  
Vasanth

---

<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:** [March 13, 2015, 4:16pm UTC](https://techcommunity.softwareag.com/t/fetch-vs-run-in-natural/102090/5 "2015-03-13T16:16:10Z")

</div>

First things first.

You are correct, there is no RUN RETURN statement as a counterpart to FETCH RETURN (or CALLNAT).

You can, however, write your own navigation logic using the Stack. Coding can get a little tricky, but usually not too terrible. Usually requires a “driver” program with a “dummy” REPEAT loop.

---

<div class="post-metadata">

**Author:** ![Vasanth\_Murali](https://avatars.discourse-cdn.com/v4/letter/v/ce73a5/32.png) [@Vasanth\_Murali](https://techcommunity.softwareag.com/u/Vasanth_Murali)\
**Post date:** [March 14, 2015, 6:52am UTC](https://techcommunity.softwareag.com/t/fetch-vs-run-in-natural/102090/6 "2015-03-14T06:52:27Z")

</div>

Thanks Steve,

I never used a STACK ☹

So I will need to read the basics first.

Meanwhile I am trying to find alternatives. Below is the reason why I had to use the & variables.

1. I am using Define work file 1 ‘pathname’  
pathname will be - /home/MYID/MEMBER…kind of

2. I want to assign the Member dynamically. I mean, the member will be decided based on the User input.

3. I tried giving it as DEFINE WORK FILE 3 ‘/opt/sop/inputlib/’ #INPUT-MEM , which doesn’t seem to working.

So do you think there is a way out, so that I need not do the Stack stuff?

Regards,  
Vasanth

---

<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:** [March 14, 2015, 11:24am UTC](https://techcommunity.softwareag.com/t/fetch-vs-run-in-natural/102090/7 "2015-03-14T11:24:04Z")

</div>

DEFINE DATA LOCAL  
1 #WORK (A35)  
1 #INPUT-MEM (A10) INIT \<‘USER-NAME’\>  
END-DEFINE  
COMPRESS ‘/opt/sop/inputlib/’ #INPUT-MEM INTO #WORK LEAVING NO SPACE  
\*\*DEFINE WORK FILE 3 ‘/opt/sop/inputlib/’ #INPUT-MEM  
DEFINE WORK FILE 3 #WORK  
END

The work file must either be an all explicit designation, OR, an all implicit designation (as in #WORK). You cannot “mix and match” (as you tried to do).

---

<div class="post-metadata">

**Author:** ![Vasanth\_Murali](https://avatars.discourse-cdn.com/v4/letter/v/ce73a5/32.png) [@Vasanth\_Murali](https://techcommunity.softwareag.com/u/Vasanth_Murali)\
**Post date:** [March 14, 2015, 11:56am UTC](https://techcommunity.softwareag.com/t/fetch-vs-run-in-natural/102090/8 "2015-03-14T11:56:22Z")

</div>

Thanks Steve,

You truly are The Rockstar of Natural 🙂

This reduces a lot of my effort. I need not use & variables and the Stack now… :lol:

So Thanks a lot Steve Ji.

Regards,  
Vasanth

---

<div class="post-metadata">

**Author:** ![luiz\_hopf](https://avatars.discourse-cdn.com/v4/letter/l/3e96dc/32.png) [@luiz\_hopf](https://techcommunity.softwareag.com/u/luiz_hopf)\
**Post date:** [July 6, 2015, 10:21pm UTC](https://techcommunity.softwareag.com/t/fetch-vs-run-in-natural/102090/9 "2015-07-06T22:21:05Z")

</div>

Hi everybody,

After exaustively look for at internet, i tought i had found a solution to my problem using Run to pass parameters to my program. But not. I loose context using run with my original program.

What i’m trying to do is:  
Execute diferent “Read” comands to read an adabas file but i would like to use several different descritor/super-descritor and diffenrent values to read this descritor. Than i tried use the Include command with parameter to change the descritor to solve my problem but the include incorporate the hole command at stow.

In the code below i use +campo and +valor global variables the change the fields to use as descritor and

Program copycode ‘test1’:  
0080 FIND F168-VIEW WITH &CAMPO = &VALOR  
0090 WRITE NOTITLE ‘=’ &CAMPO  
0100 END-FIND

Program ‘test2’:

0730 MOVE ‘CO-UNIDADE-08’ TO +CAMPO  
0740 MOVE ‘’‘1010500’‘’ TO +VALOR  
0750  
0800 INCLUDE TEST1

But it doesn’t work because Test2 includes fixed values for &campo and &valor

Are there any way to change at execution time values for &campo and &valor so at execution of Test2 performs different selections ???

It is easy on others languages called as “Indirection” but i couldn’t find similar command at Natural help.  
The version of my Natural is 8.2.5.1

Thanks for any help

---

<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:** [July 7, 2015, 1:47pm UTC](https://techcommunity.softwareag.com/t/fetch-vs-run-in-natural/102090/10 "2015-07-07T13:47:53Z")

</div>

It is difficult to know where to start. So, lets start with something simple.

As you noted, you wanted to:

> [@](#):
>
> Are there any way to change at execution time values for &campo and &valor so at execution of Test2 performs different selections ???

This is quite impossible using your code layout. As you yourself noted, there is no way to change &CAMPO and &VALOR except by changing the underlying global variables and recompiling (or re-Running, see below).

Depending on how many descriptor fields you might be using, one way to do what you want would be to have something like:

DECIDE various conditions or values  
WHEN condition 1  
PERFORM first combination of descriptor and value  
WHEN condition 2  
PERFORM second combination of descriptor and value

where each combination is a local (or stand alone) subroutine.

Actually, for the values (assuming all are alpha) you could use a local variable such as #VALOR. Then all the FINDs would be something like FIND … WITH CO-UNIDADE-08 = #VALUE.

The above is probably the easiest way to go and maintain.

If you want to use ampersand variables, you could “combine” test1 and test2 into a single source program called, just test.

Then you could have something like:

0080 FIND F168-VIEW WITH &CAMPO = &VALOR  
0090 WRITE NOTITLE ‘=’ &CAMPO  
0100 END-FIND

IF something true

MOVE ‘CO-UNIDADE-08’ TO +CAMPO  
MOVE ‘’‘1010500’‘’ TO +VALOR  
RUN ‘test’  
else STOP

This is typically rather silly code, but it does work. NOT recommended.

The reason it is NOT recommended is that you would lose values of all the other local variables, since the program test would be recompiled. Yes, you could pass values between different executions of test, but this could be VERY messy depending on how may such variables there are.

---

<div class="post-metadata">

**Author:** ![luiz\_hopf](https://avatars.discourse-cdn.com/v4/letter/l/3e96dc/32.png) [@luiz\_hopf](https://techcommunity.softwareag.com/u/luiz_hopf)\
**Post date:** [July 7, 2015, 7:33pm UTC](https://techcommunity.softwareag.com/t/fetch-vs-run-in-natural/102090/11 "2015-07-07T19:33:35Z")

</div>

Steve,

Thanks for your reply.  
I could learn something i havent never used. Call the same program.  
This is a good idea. I tested it and i could control the execution fluxo by a variable in a global area. Consecutive RUN calls to the same program using a global never lose the values. Thanks for this solution. 🙂

But the problem now is that this program will be called by a micro procedure running in a low end asp server.  
This low end asp calls the natural program and stay waiting for a response.

My solutions till today works fine because sequencial fetch return or callnat ou perform comands always go back to original first natural called program and the micro procedure always receive an answer from Natural High end computer.

If i use a run call passing parameters in this first called Natural program, it will run fine but my original called Natural program will never ends correctly.

I read something about the use of an stack to control the sequence of an Natural routines.

Do you think i could use stack solution to control this sequence on Natural environment and go back to my first called Natural program ?

If yes, how use stack ? I never used it before.

Thanks again.

---

<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, 3:02pm UTC](https://techcommunity.softwareag.com/t/fetch-vs-run-in-natural/102090/12 "2021-04-02T15:02:45Z")

</div>


