Skip to content

Access to an Adabas Database from Node.js using the Adabas TCP connection

License

Notifications You must be signed in to change notification settings

mgerth/adabas-lnk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Adabas LNK

Access to an Adabas Database from Node.js using the Adabas ADALNK connection

It offers the classical CRUD access methods for Adabas

  • C reate - inserts an new Adabas record
  • R ead - read Adabas records
  • U pdate - update an Adabas record
  • D elete - delete an Adabas record

Installation

npm install adabas-lnk

Introduction

This simple example shows how to read all records of file 11 of database 12 and writes the result to the console:

const Adabas = require('adabas-lnk').Adabas;

const adabas = new Adabas(12);
adabas.read({ fnr: 11 }).then( result => {
    console.log(result);
    adabas.close();
});

What it does is to read the File Description Table of the file and adds all available fields to the format buffer. The result is an array of Javascript objects:

[
  { ISN: 1,
    AA: '50005800',
    AB: { AC: 'SIMONE', AE: 'ADAM', AD: '' },
    AF: 'M',
    AG: 'F',
    AH: 712981,
    A1: { AI: [ '26 AVENUE RHIN ET DA' ], AJ: 'JOIGNY', AK: '89300', AL: 'F' },
    A2: { AN: '1033', AM: '44864858' },
    AO: 'VENT59',
    AP: 'CHEF DE SERVICE',
    AQ: [ { AR: 'EUR', AS: 963, AT: [ 138] } ],
    A3: { AU: 19, AV: 5 },
    AW: [ { AX: 19990801, AY: 19990831 } ],
    AZ: [ 'FRE', 'ENG' ]
  },
  { ISN: 2,
...

General

To hide the complexity of an Adabas call with all the buffers, short names and options from the user this implementation offers a high level API, which generates all buffers from the provided metadata.

Data Representation

The Adabas data is represented as an Javascript object. This means the read method returns Javascript object and the insert and update methods access a Javascript object as input. Here is an example for the Javascript object for an Employees record:

const record = {
    'Personnel Id': '50001234',
    'First Name'  : 'John',
    'Name'        : 'Doe',
    'Middle Name' : 'M.',
    'City'        : 'Seattle',
    'Country'     : 'USA'
};

The type of object attributes must fit to the Adabas types. This means a numeric type in Adabas must be a Javascript type of number. These types are validated during the processing and an error is thrown if there are incompatibilites.

Multiple Fields

Multiple fields are represented as arrays.

Groups

A group is a Javascript object.

Periodic Groups

A periodic group is an array of Javascript objects.

Data Representation Example

Below is an example of an object

{
    ISN: 207,
    'Personnel Id': '11100107',
    'Full Name': { 'First Name': 'HELGA', Name: 'SCHMIDT' },
    Name: 'SCHMIDT',
    Language: [ 'GER', 'FRE' ],
    Income:
        [
            { 'Currency Code': 'EUR', Salary: 18461, Bonus: [ 1025, 75] },
            { 'Currency Code': 'EUR', Salary: 16410, Bonus: [] }
        ]
}

Classes

AdabasMap

The AdabasMap class contains the metadata for the Adabas call.

AdabasMap Constructor

The constructor has the file number as parameter.

Fields

For each field that is access the following information must be provided:

  • type (regular field, multiple field, periodic group)
  • format
  • length
  • short name
  • options

With the options long name, precision, max occurrence, etc. can be provided.

Each Adabas field is defined like this

alpha(8, 'AA', { name: 'Personnel Id' })

Meaning that the Adabas field is of type 'alpha', has a length of 8 and the short name is 'AA'. In the returned object the attribute is named 'Personnel Id'.

To add the fields to the map a function must be used. The following function are implemented:

  • alpha (A)
  • binary (B)
  • fixed (F)
  • float (G)
  • packed (P)
  • unpacked (U)
  • wide (W)

Multiple fields must set the 'occ' attribute in the options:

alpha(3, 'AZ', { name: 'Language', occ: 5 }) // multiple field

For groups another function must be used where instead of the length a map for the group is provided:

group(FullName, 'AB', { name: 'FullName' }) // group

Periodic groups are very simular to groups. The difference is that occ attribute is set in the options:

group(Income, 'AQ', { name: 'Income', occ: 6 }) // periodic group

Import

Typescript
import { Adabas, AdabasMap } from 'adabas-lnk';
Javascript
const Adabas = require('adabas-lnk').Adabas;
const AdabasMap = require('adabas-lnk').AdabasMap;

Fields Example

Here is an example for an Employees file (file number 11):

// define elements of the periodic group
const Income = new AdabasMap()
    .alpha(3, 'AR', { name: 'Currency Code' })
    .packed(5, 'AS', { name: 'Salary' })
    .packed(5, 'AT', { name: 'Bonus', occ: 5 }) // multiple field within periodic group
    ;

// define a group
const FullName = new AdabasMap()
    .alpha(20, 'AC', { name: 'First Name' })
    .alpha(20, 'AE', { name: 'Name' })
    ;

// define the adabas record
const Map = new AdabasMap(11)
    .alpha(8, 'AA', { name: 'Personnel Id' })
    .group(FullName, 'AB', { name: 'FullName' }) // group
    .alpha(20, 'AE', { name: 'Name' })
    .alpha(3, 'AZ', { name: 'Language', occ: 5 }) // multiple field
    .group(Income, 'AQ', { name: 'Income', occ: 6 }) // periodic group
    ;

Adabas

The Adabas class does the Adabas calls.

Adabas Constructor

The Adabas class has the database number as required parameter. Options for multifetch or logging can be added:

const adabas = new Adabas('localhost', 49152, { multifetch: 20 } );

Methods

The create, read, update and delete methods need the map or a file number as parameter. If the file number is provided the File Description Table of the file is read and a map containing all fields is created from these definitions.

Each command has some parameter provided as an object to control the command. At minimum a map or file number must be provided. See examples below.

The following parameters are supported:

export interface CallData {
    map?: AdabasMap,
    fnr?: number,
    isn?: number,
    object?: any,
    criteria?: string,
    fields?: string[]
}

Here are examples for these methods.

create(CallData)

Parameter:

  • map/fnr: map or file number
  • object: that is stored

Store object 'create' using the map 'empl':

adabas.create( { map: empl, object: create } );
read(CallData)

Parameter:

  • map/fnr: map or file number
  • criteria: return only objects that meet the criteria
  • isn: read a single ISN
  • fields[]: limit the returned fields

Read all data from file 11:

adabas.read( { fnr: 11 } );

Read ISN 207 using the map 'empl':

adabas.read( { map: empl, isn: 207 } );
update(CallData)

Parameter:

  • map/fnr: map or file number
  • criteria: return only objects that meet the criteria
  • object: that is stored

Update the corresponding record where 'Personnel Id' equals to 'Test1234' with object 'update':

adabas.update( { map: empl, criteria: 'Personnel Id=Test1234', object: update } );
delete(CallData)

Parameter:

  • map/fnr: map or file number
  • criteria: return only objects that meet the criteria

Delete record where 'Personnel Id' equals to 'Test1234':

adabas.delete( {map: empl, criteria: 'Personnel Id=Test1234' } );
endTransaction()

Performs an end of transaction. The data is committed to the database.

backoutTransaction()

Performs a backout of this transaction.

close()

Performs a close of the database.

Know Problems

  • Alpha fields with length 0 and LOB fields are currently not supported

Dislaimer

Utilities and samples shown here are not official parts of the Software AG products. These utilities and samples are not eligible for technical assistance through Software AG Global Support. Software AG makes no guarantees pertaining to the functionality, scalability , robustness, or degree of testing of these utilities and samples. Customers are strongly advised to consider these utilities and samples as "working examples" from which they should build and test their own solutions.

About

Access to an Adabas Database from Node.js using the Adabas TCP connection

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.9%
  • JavaScript 0.1%