# Accessing ADABAS file using OBTAIN

**URL:** <https://techcommunity.softwareag.com/t/accessing-adabas-file-using-obtain/201645>\
**Category:** Forum\
**Tags:** Adabas-Natural, Adabas, Adabas-Code-Samples\
**Created:** [November 8, 2018, 8:16am UTC](https://techcommunity.softwareag.com/t/accessing-adabas-file-using-obtain/201645 "2018-11-08T08:16:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prakash\_Parandhaman](https://avatars.discourse-cdn.com/v4/letter/p/eb8c5e/32.png) [@Prakash\_Parandhaman](https://techcommunity.softwareag.com/u/Prakash_Parandhaman)\
**Post date:** [November 8, 2018, 8:16am UTC](https://techcommunity.softwareag.com/t/accessing-adabas-file-using-obtain/201645/1 "2018-11-08T08:16:51Z")

</div>

I could see some nat programs using the OBTAIN to access the ADABAS files. Is it good practice to access the ADABAS files using OBTAIN in the Reporting mode ? Please advice

---

<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:** [November 8, 2018, 12:34pm UTC](https://techcommunity.softwareag.com/t/accessing-adabas-file-using-obtain/201645/2 "2018-11-08T12:34:27Z")

</div>

> [@](#):
>
> I could see some nat programs using the OBTAIN to access the ADABAS files

Sorry, but your sentence is false. OBTAIN does not access Adabas files. OBTAIN is a non-executable statement. What it does is generate entries in the Format buffer for Adabas calls.  
Consider the following Report Mode code:  
READ EMPLOYEES  
DISPLAY NAME FIRST-NAME  
LOOP  
END

The Natural compiler looks at the READ loop and creates a call to Adabas with just two fields in the Format Buffer; NAME and FIRST-NAME. No other fields are transferred from Adabas to Natural.

Here is another code snippet

READ EMPLOYEES  
DISPLAY NAME FIRST-NAME LANG (1) LANG(2)  
LOOP  
END

The above is perfectly legal code. The Natural call includes the first two occurrences of the Multiple valued field LANG.

Now for some more valid Natural code:

READ EMPLOYEES  
IF something true  
DISPLAY NAME FIRST-NAME LANG (1)  
ELSE  
DISPLAY NAME FIRST-NAME LANG (2)  
LOOP  
END

Once again this is valid code. The first two occurrences of LANG are in the Format Buffer of the call to Adabas, and the values of the first two occurrences are in the Record buffer which returns the values to Natural.

Basically, the Natural compiler looks for database fields that are used within the READ loop, to create the appropriate Format buffer for the call to Adabas.

Now for something that will not work.

READ EMPLOYEES  
IF something true  
#SUB = 1  
ELSE  
#SUB = 2  
DISPLAY NAME FIRST-NAME LANG (#SUB)  
LOOP  
END

Why does this code NOT work? Simple. Natural does not know how to create the Format buffer for the READ command being sent to Adabas. A simple change to the code will fix the problem:

READ EMPLOYEES  
OBTAIN LANG (1:2)  
IF something true  
#SUB = 1  
ELSE  
#SUB = 2  
DISPLAY NAME FIRST-NAME LANG (#SUB)  
LOOP  
END

As long as #SUB is 1 or 2, this code works. The OBTAIN tells the Natural compiler to ask Adabas for LANG(1:2) even though there is no specific reference to LANG (1) or LANG(2).

A good way to understand this is the OBTAIN helps Natural build the Structured Mode View.

There is a lot more information in the Natural Documentation;

[http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat827mf/sm/obtain.htm#obtain](http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat827mf/sm/obtain.htm#obtain)

---

<div class="post-metadata">

**Author:** ![Prakash\_Parandhaman](https://avatars.discourse-cdn.com/v4/letter/p/eb8c5e/32.png) [@Prakash\_Parandhaman](https://techcommunity.softwareag.com/u/Prakash_Parandhaman)\
**Post date:** [November 8, 2018, 2:20pm UTC](https://techcommunity.softwareag.com/t/accessing-adabas-file-using-obtain/201645/3 "2018-11-08T14:20:48Z")

</div>

Thanks Steve, It makes sense

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [November 8, 2018, 10:03pm UTC](https://techcommunity.softwareag.com/t/accessing-adabas-file-using-obtain/201645/4 "2018-11-08T22:03:14Z")

</div>

Software AG recommends Structured Mode programming, which does not support the OBTAIN statement. I have used Structured Mode exclusively for many years, and I encourage all Natural programmers to do the same.

---

<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:41pm UTC](https://techcommunity.softwareag.com/t/accessing-adabas-file-using-obtain/201645/5 "2021-04-02T15:41:46Z")

</div>


