Accessing ADABAS file using OBTAIN

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

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

Thanks Steve, It makes sense

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.