-

- -

Thursday, November 3, 2022

Getting Started With ADABAS and NATURAL Programming using Natural ONE IDE

.

This part describes the steps to access Adabas database using Natural language that is coded using Natural ONE IDE.

Continue with the project created in the previous part i.e. PRJ1. Create a new program, PRG2.

A Natural program requires a Data Definition Module in order to access Adabas database.

For Natural to be able to access a database file, a logical definition of the physical database file is required. Such a logical file definition is called a data definition module (DDM). (https://documentation.softwareag.com/natural/nat838unx/pg/pg_dbms_ada.htm)

To prepare DDM, some information regarding database and file name reference is needed. From Part 1, it is learned that the database no. is 12 and related file no. is 9.

Right-click SRC, select New/DDM.

Type the DDM/File name DDM1. Click “Next”.

Type 12 for “DBID” and 9 for “FNR”. Click “Finish”.

The result is a DDM file containing the short field names.

Alternatively, DDM files can be imported. For example, a DDM file Employees.NSD in the Natural ONE IDE sample can be used for this project. Download Employees.NSD into the local host machine.

Right-click SRC, select Import…

In the Import dialog window, select “File System”. Click Next.

Select the source folder and file. Click “Finish”.

The result is a DDM file containing a more friendlier field names.

Begin coding the PRG2 with the following codes.

/** New Program PRG2.
/**
DEFINE DATA
LOCAL
END-DEFINE
*
END

Put the cursor in the line below the word “LOCAL”, right-click and select “Advanced Edit Features/Import Data Fields…”.

In the “Import Data Fields” window, select “Data Definition Module” for the “Object Type”, and then click “Browse” to select “EMPLOYEES.NSD” file.

Select the following items and then click “OK”.
EMPLOYEES
.. FULL-NAME
.. .. NAME
.. DEPT
.. LEAVE-DATA
.. .. LEAVE-DUE
.. .. LEAVE-TAKEN

The items are now inserted into PRG2. To avoid confusion, add a text “-view” to the EMPLOYEES view as shown below.

Add codes to read and display the data after the “END-DEFINE” line.

READ EMPLOYEES-VIEW BY NAME
*
DISPLAY NAME 3X DEPT 3X LEAVE-DUE
*
END-READ

The READ statement is used to read records from a database. The records can be retrieved in physical sequence, in Adabas ISN sequence, or in the value sequence of a descriptor (key) field. The READ statement causes a processing loop to be initiated. (https://documentation.softwareag.com/natural/nat914win/sm/read.htm)
The DISPLAY statement is used to specify the fields to be output on a report in column format. A column is created for each field and a field header is placed over the column.
(https://documentation.softwareag.com/natural/nat914win/sm/display.htm)

The full codes is as follows.

/** New Program PRG2.
/**
DEFINE DATA
LOCAL
/*( imported data fields from Data Definition Module EMPLOYEES
1 EMPLOYEES-VIEW VIEW OF EMPLOYEES
2 FULL-NAME
3 NAME (A20)
2 DEPT (A6)
2 LEAVE-DATA
3 LEAVE-DUE (N2.0)
3 LEAVE-TAKEN (N2.0)
/*) imported data fields from Data Definition Module EMPLOYEES
END-DEFINE
*
READ EMPLOYEES-VIEW BY NAME
*
DISPLAY NAME 3X DEPT 3X LEAVE-DUE
*
END-READ
*
END

Press [ALT+SHIFT+X][N] to run PRG2.

To make PRG2 interactive, add below codes to get the employee names from the computer user.

/** New Program PRG2.
/**
DEFINE DATA
LOCAL
1 #NAME-START (A20) INIT <"ADKINSON">
1 #NAME-END (A20) INIT <"BENNETT">

1 EMPLOYEES-VIEW VIEW OF EMPLOYEES
2 FULL-NAME
3 NAME (A20)
2 DEPT (A6)
2 LEAVE-DATA
3 LEAVE-DUE (N2)
END-DEFINE
*
INPUT (AD=MT)
"Start:" #NAME-START /
"End: " #NAME-END

*
READ EMPLOYEES-VIEW BY NAME
STARTING FROM #NAME-START
ENDING AT #NAME-END
*
DISPLAY NAME 3X DEPT 3X LEAVE-DUE
*
END-READ
*
END

Press [ALT+T] to update the PRG2 to the Natural server.

Press [SHIFT+ALT+X][N] to run PRG2.

Suppose the computer user enters “ADKINSON” for “Start:” and “AHL” for “End:”, PRG2 will display the following.

For an enhanced input layout, a map can be used.

To be continued in the next part.

— — — — —

This post is a part of the series “Getting Started With Adabas & Natural”:
Part 1: Setting up Adabas & Natural Community Edition Docker Version.
Part 2: Accessing Adabas Database via Adabas REST Web app.
Part 3: Adabas “Periodic Groups” and “Multiple Values” representation in JSON data format.
Part 4: Accessing Adabas Database using Adabas TCP-IP Node Package.
Part 5: Creating Natural Project using Natural ONE IDE.
Part 6: Accessing Adabas Database using Natural Programming and Natural ONE IDE.

— — — — —

.

No comments:

Post a Comment