Sunteți pe pagina 1din 44

ADABAS

Objectives

The objective of this presentation is
To get in depth knowledge on ADABAS (Adaptable Data Base System).
Identify advantages and disadvantages of ADABAS.
How to do an efficient programming with ADABAS.
To get knowledge of ADABAS nucleus , ADABAS Calls and Utilities.
Cobol-Adabas programming using ADASQL.
Use of direct calls to access ADABAS.




Learning Outcome

At the end of this course, you are expected to

To use ADABAS database efficiently in your program.
To do programming by using cobol with adabas.
Indepth knowledge of ADASQL.


Adabas (Adaptable Database)
Pseudo-Relational DBMS
4 Components
NUCLEUS
ADABAS ASSOCIATOR
INVERTED LIST
ADABAS CONVERTER
DATA STORAGE
WORK DATASET
Additional datasets can be incorporated into the operating environment to maintain
The images of changes to the database and an audit of all commands processed
during the Session.
PROTECTION LOG
COMMAND LOG








ASSOCIATOR :
The first of the three required data sets is the associator which contains
information about the data base in general and specific information about
individual files.
DATA STORAGE :
The data storage data set,the second component of an ADABAS
session,contains the actual data without chaining or pointers and no fixed or
pre-defined parent-child relationships , just basic data stored for subsequent
access .
WORK DATA SET :
The work dataset is used by the nucleus (and applications in certain
circumstances) as temporary storage for processing large lists of records
sorting,error recovery and working storage.







PROTECTION LOG :
The protection log contains all the before and after images necessary for
ADABASs maintenance of the integrity of the database:back out , recovery and
regeneration of corrupted data.
COMMAND LOG :
The optional command log contains information useful for audit trails as well as
performance monitoring.







Data Storage :

ADABAS Controls and maintains data in physical blocks within data storage.
Each physical block is automatically assign a Relative ADABAS block number (RABN)
ADABAS BLOCK LAYOUT





ADABAS RECORD LAYOUT IN STORAGE




INCLUSIVE BLOCK
LENGTH
REC-1 REC-2 REC-N FREE SPACE PADDING AREA
INCLUSIVE RECORD
LENGTH
ISN FIELD-1 FIELD-2 FIELD-3



DATA COMPRESSION
NORMAL COMPRESSION :
The ADABAS default for compression of data is Normal Compression.
- Trailing blanks are removed from alphanumeric field
- Leading zeros are removed from numeric field values and the data is
being packed before being stored.
- Packed data is stored as it is.
FIXED FORMAT :
This is termed as Negative Compression
- If a field which is always filled with non-zero or non-blank data would require one
extra byte for the length .In such cases a designer may specify that a field is to be
stored in Fixed Format (FI) to have the field always stored as its full length
without the length byte.





NULL SUPRESSION

- A null suppression option (NU) , the designer can achieve even greater space
savings.A null suppressed field which contains blanks or zeros will be stored as
one empty field byte.Contiguous empty fields upto 63 will be compressed into a
one byte empty field count.



MULTIPLE VALUE (MU) FIELDS :
An elementary field that occurs multiple times,is called a Multiple Value Field in
ADABAS.

PERIODIC GROUP (PE) :
When a group of fields that occurs multiple times is called a Periodic Group in
ADABAS

Note :
PE Can have 99 occurrences and MU can have 191 occurrences.
As defined by adabas , a periodic group can not be defined within a periodic group but can
have multiple value fields .



3GL RECORD LAYOUT :
01 CUSTOMER-RECORD.
02 CUSTOMER-NUMBER PIC 9(07).
02 SHIPPING-ADDRESS OCCURS 4 TIMES PIC X(25).
02 ORDER-NUMBER PIC 9(07).
02 LINE-ITEMS OCCURS 99 TIMES.
03 LINE-NUMBER PIC 9(03).
03 PART-ID PIC 9(07).
03 DESCRIPTION OCCURS 10 TIMES PIC X(20).
03 QUANTITY PIC 9(03).
03 UNIT-COST PIC 9(03)V99.
ADABAS RECORD LAYOUT :
TY L DB NAME F LENG S D REMAR
------ ---- ----------------------------------------------------------------------- - --------- - - ------------
1 AA CUSTOMER-NUMBER N 7.0 N D
M 1 AB SHIPPING-ADDRESS A 25 N
1 AC ORDER-NUMBER N 7.0 N D
P 1 AD LINE-ITEM
2 AE LINE-NUMBER N 3
2 AF PART-ID N 7.0 N D
M 2 AG DESCRIPTION A 20 N
2 AH QUANTITY N 3 N
2 AJ UNIT-COST N 3.2 N




Adabas (Adaptable Database)



ADABAS INVERTED LIST :
Normal indexes contain the information necessary for ADABAS to locate all records
Which have a given value in a given field.There is one normal index for each
Descriptor,Superdescriptor and Hyperdescriptor defined for a file.A normal index is
Often referred to as an INVERTED LIST in ADABAS.

Within each normal index , there is a single entry for each value of the descriptor .This
Entry contains the compressed value of the descriptor (field) preceded by a one-byte inclusive
length of this compressed value.



Descriptor value count ISNs
American motor 3 6,13,34
fiat 8 23,27,35,49
ford 29 2,11,54,55
opel 2 22,32



ADABAS ADDRESS CONVERTER :
The address Converter for each ADABAS file is a simple table ,indexed by ISN,It
contains the relative ADABAS block number ,or RABN , of the corresponding
Adabas block where the record having that ISN is stored .

DATA STORAGE :
The data storage data set,the second component of an ADABAS session,contains the
actual data without chaining or pointers and no fixed or pre-defined parent-child
relationships , just basic data stored for subsequent access .









ADABAS DESCRIPTORS :
DESCRIPTORS :
A field can be selected as descriptor for identifying records in adabas files.
UNIQUE DESCRIPTOR :
It is a key that may contain one and only one occurrence of a value.ADABAS provides
this capability with a single field descriptor and will not allow addition of a record with
a value currently maintained in the field .
SUBDESCRIPTOR :
Subdescriptors are descriptors which are defined from a portion of a field.They are
most useful where one wishes to provide a browse capability on long fields.
SUPERDESCRIPTOR :
Superdescriptors are descriptors which are made up from concatenating 2 to 5 fields.
PHONETIC DESCRIPTORS :
Phonetic descriptors are field values passed through an algorithm that establishes a
phonetic equivalent value for ease of search




ADABAS NUCLEUS :
The major facility of a ADABAS NUCLEUS includes
the application interface
multi-threading
request queuing
holding records pending update
buffers
backout and recovery
common ADABAS commands
The important buffers associated with ADABAS are :
Control Block
Search Buffer
Value Buffer
Format Buffer
Record Buffer
ISN Buffer








CONTROL BLOCK
Contains Command ID ,Database and File Ids,
Return-Code.
SEARCH BUFFER
Descriptor Ids for retrieval requests and boolean
relationships needed.
VALUE BUFFER
Value specifications (ranges,lists..) for retrieval
requests.
FORMAT BUFFER
List of Ids and formats of the fields transferred.
RECORD BUFFER
List of values of the fields transferred
ISN Buffer
List of ISNs resulting from a successful FIND
operation.



HOLD QUEUE :

To ensure data integrity it is important that two users are not able to update one record
simultaneously.Therefore.When a record is read with the intention of updating or deleting it,
the ISN is placed in the HOLD QUEUE along with information necessary to identify its
temporary owner .

DATA DEFINATION MODULE (DDM) :

To access a database file by NATURAL, a logical definition of the physical database file is required.
Such a logical file definition is called a DDM (data definition module).

The DDM contains information about the individual fields of the file - information which is relevant
for the use of these fields in a Natural program.








Thus a DDM constitutes a logical view of a physical database file.
For each physical file of a database, one or more DDMs can be defined.
DDMs are defined by the Natural administrator with Predict.





For each database field, a DDM contains :
The database-internal field name.
"External" field name, that is, the name of the field as used in a Natural program.
The formats and lengths of the field
As well as various specifications that are used when the fields are output with a DISPLAY
or WRITE statement (column headings, edit masks, etc.).
The Data Dictionary field definitions should match the FDT field definitions.
If these do not match then there is a danger to data integrity.




ADABAS COMMANDS :
READ COMMANDS :
L1 / L4 READ BY ISN
L2 / L5 READ IN PHYSICAL SEQUENCE
L3 /L6 READ IN LOGICAL SEQUENCE
L9 READ ASSOCIATOR (HISTOGRAM)
FIND COMMANDS :
S1 / S4 FIND ISNs
S2 FIND and SORT ISNs
DATA MODIFICATION COMMANDS :
A1 UPDATE DATABASE FIELDS
N1 / N2 ADD DATABASE RECORD WITH FIELD
E1 DELETE RECORD
LOGICAL TRANSACTION PROCESSING :
ET END OF TRANSACTION
BT BACKOUT TRANSACTION

ADABAS utilities :
Unload (ADAULD)
ADAULD is used to unload a file in compressed format .Various options allow for the
unload to take place based on a specific descriptor field or other sorts on data

Dump and Restore (ADASAV) :
The backup/restore utility , ADASAV,is used to dump the database or selected files
and restore the same.

Reorder Associator & Data Storage (ADAORD) :
ADAORD is the utility used to reorder the Associator .

Regenerate and Backout (ADARES) :
ADARES is the utility for restarting applications,backing out data by application,user and even to
time frames and/or regenerating transactions when added.

INTRODUCTION TO DIRECT CALLS :
Communication with ADABAS from 3GL programs is accomplished through direct
calls.The primary block of code used to effect this interface is the CALL ADABAS USING
Statement coded in each application program.This call will contain all necessary parameters and
options to search,read,modify and write data to and from the data base.Its syntax and component
are :

CALL ADABAS USING CONTROL-BLOCK,
FORMAT-BUFFER,
RECORD-BUFFER,
SEARCH-BUFFER,
VALUE-BUFFER,
ISN-BUFFER.

Declaration should be included for above mentioned buffers in working-storage section.

For ADABAS CONTROL BLOCK :
1 CONTROL-BLOCK.
02 FILLER PIC X(2) VALUE SPACES.
02 COMMAND-CODE PIC X(2) VALUE SPACES.
02 COMMAND-ID PIC X(4) VALUE SPACES.
02 FILE-NUMBER PIC S9(4) COMP VALUE +0.
02 RESPONSE-CODE PIC S9(4) COMP VALUE +0.
02 ISN PIC S9(8) COMP VALUE +0.
02 ISN-LOWER-LIMIT PIC S9(8) COMP VALUE +0.
02 ISN-QUANTITY PIC S9(8) COMP VALUE +0.
02 FORMAT-BUFFER-LENGTH PIC S9(4) COMP VALUE +80.
02 RECORD-BUFFER-LENGTH PIC S9(4) COMP VALUE +80.
02 SEARCH-BUFFER-LENGTH PIC S9(4) COMP VALUE +80.
02 VALUE-BUFFER-LENGTH PIC S9(4) COMP VALUE +80.
02 ISN-BUFFER-LENGTH PIC S9(4) COMP VALUE +80.
02 COMMAND-OPTION-1 PIC X VALUE SPACES.
02 COMMAND-OPTION-2 PIC X VALUE SPACES.
02 ADDITIONS-1 PIC X(8) VALUE SPACES.
02 ADDITIONS-2 PIC X(4) VALUE SPACES.
02 ADDITIONS-3 PIC X(8) VALUE SPACES.
02 ADDITIONS-4 PIC X(8) VALUE SPACES.
02 ADDITIONS-5 PIC X(8) VALUE SPACES.
02 COMMAND-TIME PIC S9(8) COMP VALUE +0.
02 FILLER PIC X(4) VALUE SPACES.

For User Buffers :
01 FORMAT-BUFFER PIC X(80) VALUE SPACES.
01 RECORD-BUFFER PIC X(80) VALUE SPACES.
01 SEARCH-BUFFER PIC X(80) VALUE SPACES.
01 VALUE-BUFFER PIC X(80) VALUE SPACES.
01 ISN-BUFFER PIC X(80) VALUE SPACES.
PROCEDURE DIVISION .
MOVE OP TO COMMAND-CODE.
CALL ADABAS USING CONTROL-BLOCK,FORMAT-BUFFER
IF NOT SUCCESSFUL
THEN PERFORM ERROR-ROUTINE.
MOVE +202 TO FILE-NUMBER.
PERFORM FIND-ROUTINE.
MOVE 0 TO ISN.
FIND ROUTINE.
MOVE S1 TO COMMAND-ID.
MOVE DH01 TO COMMAND-ID.
CALL ADABAS USING CONTROL-BLOCK,SEARCH,BUFFER,VALUE-BUFFER,ISN-BUFFER
CLOSE-ROUTINE
MOVE CL TO COMMAND-CODE .
CALL ADABAS USING CONTROL-BLOCK.
IF NOT SUCCESSFUL
THEN PERFORM ERROR-ROUTINE.


INTRODUCTION TO ADASQL :
ADABAS SQL allows access to adabas by the emerging standard for structured
relational data languages.ADABAS SQL integrated with PREDICT for centralized
control of all corporate data.

The integration with PREDICT provides access to the definition of database files/tables and fields
as well as PREDICTs cross-referencing facility.Cross references are maintained by program-name
files or fields referenced ,copycode members accessed and also by programming language,date
and time compiled.

Programs with ADASQL statements are converted during execution of a preprocessor step prior
to compilation.The resulting source contains the ADASQL statements , the generated code and
the original host language source code.Any changes must be passed the preprocessor before
recompilation.





Topics to be covered :


1. Program Preparation
2. ADABAS Buffer overview
3. ADASQL Statements
4. Single record processing
5. Multiple record processing
6. Online Processing with ADASQL
7. Examples






ADABAS SQL
PREPROCESSOR
Generated Program
Host Compiler
Object Module
LINKAGE EDITOR
Load Module
Source Program with
ADABAS SQL Statements
PREDICT
Data Dictionary
Cross Reference
Facility
ADABAS
PROGRAM PREPARATION
ADABAS BUFFER OVERVIEW :
The record buffer is an area of storage allocated by the program which is used by
ADABAS to transfer information from the database to the program and vice-
versa.
If an ALIAS is specified in the ADABAS SQL Command which creates the record
buffer ,then that name is used as the level 1 qualifier.If an alias is not specified
then the filename or view name is used as the level 1 qualifier.
The attributes for the fields referred in ADASQL are taken from PREDICT, the data
dictionary.
To refer to the data base fields from a COBOL Program, the syntax would be :
<field-name > OF <buffer-name>
ADABAS SQL appends three fields to each record in the Record Buffer.The fields
are defined as follows :

ISN
A four byte binary field containing the Internal Sequence Number of the record found
cobol structure is : PIC 9(9) COMP

QUANTITY
A four byte binary field containing the number of records found for the specific
search criteria.
COBOL Structure is : PIC 9(9) COMP
When used with HISTOGRAM , QUANTITY contains the count field from the Inverted
list,that is the number of records in the database for that specific descriptor value.

RESPONSE-CODE
A two byte binary field containing the response code for the execution of the
ADABAS SQL Command.
COBOL Structure is : PIC 9(4) COMP



ADASQL STATEMENTS :
General Statement Syntax
EXEC ADABAS
ADABAS SQL-Statement
END-EXEC
Retrieval Types
statement -name FIND
READ { PHYSICAL { SEQUENCE}
READ LOGICAL
READ ISN
HISTOGRAM
SORT [ISN {LIST[S]]
General Syntax.
EXEC ADABAS
Statement-name
[ DECLARE cursor-name CURSOR [FOR] ]
[ SELECT { select-list / * } ]
FROM file [ alias] .
[ WHERE search-criteria]
OPTIONS < REFER NEXT SLIDE >
ORDER BY descriptor DESC/ASC
GROUP BY descriptor
END-EXEC



ADASQL STATEMENTS (Continue )

OPTIONS :

INDEXED = { Y / N }
COND-NAME = { Y / N}
HOLD [ RETURN]
PASSWORD = { CONSTANT/VARIABLE/ :VARIABLE}
CIPHER = { CONSTANT/VARIABLE/ :VARIABLE}
ISNSIZE = Length {CONSTANT/VARIABLE}
SAVE
SEQUENCE
ISN = VALUE
PREFIX = Prefix
SUFFIX = Suffix
STATIC = { Y / N }
MAXTIME = ss
AUTODBID
DBID = database-name

FIND
- Produces as ISN list for all the records which satisfy the given search criteria .
- The only OPTIONS available for a FIND are HOLD,
PASSWORD , CIPHER , ISNSIZE and SAVE
- The list may be sorted in ORDER BY a DESCRIPTOR
- The GROUP BY clause is not permitted for a FIND
- The search criteria for the FIND is specified in
WHERE <Search Criteria>
- In search option we can specify following conditions
DESCRIPTOR (EQ,GT,GE,LT,LE ) Expression/values
or DESCRIPTOR (=,>,>=,<,<=) Expression /values

READ PHYSICAL SEQUENCE

- Records are read in the order that they are physically stored
in the database.
- Only one file may be specified in the FROM clause
- The WHERE , ORDER BY , GROUP BY should not be
coded with READ PHYSICAL
- The only options available for a READ PHYSICAL are
HOLD , PASSWORD , CIPHER and ISN



READ LOGICAL
- Records are read in ascending logical order based on a given
descriptor
- Only one file can be specified in FROM clause
- If alias is specified ,it is used as the same name of the record
buffer . If it is not specified , the file name is used.
- The OPTIONS available for READ LOGICAL are
HOLD , PASSWORD , CIPHER and ISN
- The descriptor specified in the ORDER BY clause must be
the same as the descriptor in the WHERE clause
- The WHERE clause specifies the starting point for the read of
a descriptor.

READ ISN
- Reads data from a record based on a given ISN value.
- only one file name can be specified in FROM clause
- If alias is specified that can be used as record buffer.
- The only OPTIONS available for READ ISN is
HOLD,PASSWORD,CIPHER and SEQUENCE
- WHERE ISN = (CONST / VARIABLE)
CURRENT OF cursor-name


HISTOGRAM
- This determines the values which are currently present
for a descriptor. The number of records which contain that
descriptor value is also available.
- only one file can be specified in FROM clause
- if alias is specified that can be used as a record buffer name
- the only options available for a HISTOGRAM is
PASSWORD
- The list can be sorted by a descriptor specified with the
ORDER BY clause.
- WHERE descriptor BETWEEN value AND value
descriptor GT/EQ value


OPTIONS Clause
- INDEXED , is available for Cobol program only.MU / PU
will be generated with the indexed by keywords.
- COND-NAME = Y , Condition name defined to PREDICT
may be generated into record buffers of COBOL programs.
These are defined as level-88 entries if COND-NAME = Y
- HOLD is specified , the retrieved record is placed in hold
status and can't be updated or deleted by another user.
- PASSWORD , Must be specified if the file is secured thru
ADABAS.
- CIPHER , If the file is encrypted.
- ISNSIZE indicates the maximum number of ISNs
which can be stored in the ISN Buffer
- SAVE option is used to retain the ISN list.It will be
deleted when a CLOSE is executed.
- SEQUENCE ,Record with the specified ISN will be
retrieved .
- ISN , record will be retrieved with specified ISN value


MULTIPLE RECORD PROCESSING :



- EXEC ADABAS
OPEN cursor-name
END-EXEC.

- EXEC ADABAS
FETCH cursor-name
END-EXEC.

- EXEC ADABAS
CLOSE cursor-name
END-EXEC



DELETE
EXEC ADABAS
DELETE
[ DECLARE cursor-name CURSOR
FROM file ISN = Value
CURRENT OF cursor-name
OPTIONS (PASSWORD/CIPHER/STATUS)
END-EXEC
INSERT

EXEC ADABAS
INSERT INTO file [alias]
WHERE ISN = Value,
SET field = (constant / value)
OPTIONS =
(PASSWORD/CIPHER/PREFIX/STATUS)
END-EXEC





UPDATE

EXEC ADABAS
UPDATE file [alias]
[ DECLARE cursor-name CURSOR ]
FROM file
WHERE ISN = value
CURRENT OF cursor-name
OPTIONS PASSWORD
PREFIX
CIPHER
STATUS
END-EXEC



OTHER COMMANDS :
EXEC ADABAS
BEGIN DECLARE SECTION
END-EXEC
EXEC ADABAS
CONNECT <user id>
ACC = file
OPTIONS DBID = < database name>
END-EXEC
EXEC ADABAS
DBCLOSE
OPTIONS DBID=database-name
END-EXEC
EXEC ADABAS
COMMIT WORK
END-EXEC

EXEC ADABAS
ROLLBACK WORK
END-EXEC



EXAMPLES :
DATA RETRIEVAL :
EXEC ADABAS
BEGIN DECLARE SECTION
END-EXEC
EXEC ADABAS
DECLARE PERS CURSOR FOR
SELECT LASTNAME,FIRSTNAME,MIDDLE-INIT,SEX,SALARY
FROM PERSONNEL
WHERE LASTNAME = HARRIS
END-EXEC

EXEC ADABAS
OPEN PERS
END-EXEC
.
EXEC ADABAS
FETCH PERS
END-EXEC
PERFORM READ-PERS UNTIL ADACODE = 3.
EXEC ADABAS
CLOSE PERS
END-EXEC
STOP RUN
READ-PERS.
DISPLAY LAST-NAME FIRST-NAME MIDDLE-INIT AGE SEX SALARY.
EXEC ADABAS
FETCH PERS
END-EXEC.



DATA CREATION :
EXEC ADABAS
BEGIN DECLARE SECTION
END-EXEC
..
EXEC ADABAS
INSERT INTO PERSONNEL
SET LAST-NAME = HARRIS
FIRST-NAME = CODY
MIDDLE-INIT = A
SEX = M
SALARY = 146500
END-EXEC

EXEC ADABAS
COMMIT WORK
END-EXEC.


DATA MODIFICATION :
EXEC ADABAS
BEGIN DECLARE SECTION
END-EXEC
..
EXEC ADABAS
DECLARE PERS CURSOR
SELECT LAST-NAME,FIRST-NAME,MIDDLE-INT,SEX,SALARY
FROM PERSONNEL
WHERE LAST-NAME = HARRIS
OPTIONS HOLD
END-EXEC.

EXEC ADABAS
UPDATE PERSONNEL
SET SALARY = 54500
WHERE CURRENT OF PERS
END-EXEC
EXEC ADABAS
COMMIT WORK
END-EXEC
..
EXEC ADABAS
DBCLOSE
END-EXEC


DATA DELETION :
EXEC ADABAS
BEGIN DECLARE SECTION
END-EXEC
..
EXEC ADABAS
DECLARE PERS CURSOR FOR
FROM PERSONNEL
WHERE PERSONNEL-NUMBER=070187
OPTIONS HOLD
END-EXEC.

EXEC ADABAS
FETCH PERS
END-EXEC
EXEC ADABAS
DELETE
WHERE CURRENT OF PERS
END-EXEC
EXEC ADABAS
COMMIT WORK
END-EXEC
..
EXEC ADABAS
DBCLOSE
END-EXEC

S-ar putea să vă placă și