# Fetch-return Statement

**URL:** <https://techcommunity.softwareag.com/t/fetch-return-statement/75267>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [August 23, 2007, 10:07am UTC](https://techcommunity.softwareag.com/t/fetch-return-statement/75267 "2007-08-23T10:07:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@rishi](https://techcommunity.softwareag.com/u/rishi)\
**Post date:** [August 23, 2007, 10:07am UTC](https://techcommunity.softwareag.com/t/fetch-return-statement/75267/1 "2007-08-23T10:07:42Z")

</div>

I have a program p1 which calls 3 other program p2,p3,p4 using fetch return.  
Program p1 passes some parameters to each of these other programs.  
I want these value of these parameters after execution of fetch return.  
How do i get these values from the other modules.Does fetch reTurn give you the value of the parameters passed after execution?  
I have used the parameters as local in p2,p3 and p4.  
I want this detail because I want to make changes only to p1 such that it applies to all the fecthing modules.  
If I dont get these values passed back from p2,p3 and p4 then i’ll have to repeat the changes for every module (which I dont want to do).  
Can some throw light on this.

Eg:  
DEFINE DATA  
LOCAL  
01 #UPDATE-FLAG (L) INIT  
END-DEFINE  
.  
.  
.

FETCH RETURN P2-MODULE #UPDATE-FLAG #END-TIME

IF #UPDATE-FLAG =TRUE  
PERFORM USAGE  
ELSE  
ESCAPE BOTTOM  
END-IF

FETCH RETURN P3-MODULE #UPDATE-FLAG #END-TIME

(same code here)

IN P2

DEFINE DATA  
LOCAL  
01 #UPDATE-FLAG (L) INIT  
END-DEFINE

---

<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:** [August 23, 2007, 11:57am UTC](https://techcommunity.softwareag.com/t/fetch-return-statement/75267/2 "2007-08-23T11:57:29Z")

</div>

No, there is absolutely NO connection between the calling and the called program’s LOCAL data.

When you pass parameters on a FETCH or FETCH RETURN, these are put on the STACK and can be read by the called program via an INPUT statement.

If you absolutely insist in having the called objects being of type PROGRAM instead of making it SUBROUTINEs and just CALLNAT them, choices are:

- - STACK the modified parameters in the called programs and read them back in with an INPUT in P1 after the FETCH RETURN.  
  
- Put that variables into a GLOBAL data area, which can be shared by caller and callee.

---

<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:** [August 23, 2007, 12:52pm UTC](https://techcommunity.softwareag.com/t/fetch-return-statement/75267/3 "2007-08-23T12:52:36Z")

</div>

> [@Wolfgang Winter](#):
>
> - STACK the modified parameters in the called programs and read them back in with an INPUT in P1 after the FETCH RETURN.

This works as follows:

P1 is:

```auto
define data local
01 p2-module (A8) const <'p2module'>
01 p3-module (A8) const <'p3module'>
01 #UPDATE-FLAG (L) INIT<FALSE>
end-define

FETCH RETURN P2-MODULE #UPDATE-FLAG
input #update-flag /* get data from stack

IF #UPDATE-FLAG =TRUE
write 'p2-true'
ELSE
write 'p2-false'
END-IF

reset #update-flag
FETCH RETURN P3-MODULE #UPDATE-FLAG
input #update-flag

IF #UPDATE-FLAG =TRUE
write 'p3-true'
ELSE
write 'p3-false'
END-IF
end
```

P2MODULE is:

```auto
DEFINE DATA
LOCAL
01 #UPDATE-FLAG (L)
END-DEFINE
input #update-flag
#update-flag := TRUE
stack top data #update-flag
END
```

Third possibility is: Use CALLNAT and write a proper subprogram.

---

<div class="post-metadata">

**Author:** ![rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@rishi](https://techcommunity.softwareag.com/u/rishi)\
**Post date:** [August 23, 2007, 5:32pm UTC](https://techcommunity.softwareag.com/t/fetch-return-statement/75267/4 "2007-08-23T17:32:44Z")

</div>

thanks wolf and matthias  
That helped me a lot

---

<div class="post-metadata">

**Author:** ![James\_Bando](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@James\_Bando](https://techcommunity.softwareag.com/u/James_Bando)\
**Post date:** [August 31, 2007, 5:54pm UTC](https://techcommunity.softwareag.com/t/fetch-return-statement/75267/5 "2007-08-31T17:54:59Z")

</div>

May favorite is to use Application Independent Variables (AIV’s) in cases like this. Just another alternative.

---

<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:48pm UTC](https://techcommunity.softwareag.com/t/fetch-return-statement/75267/6 "2021-04-02T14:48:40Z")

</div>


