IDMS Training

Embed Size (px)

DESCRIPTION

IDMS basic level batch programming knowledge.

Citation preview

VSIGN INFOTECH

Introduction

TITLEIDMS/R OverviewIDMS is a network database.

A network data model is regarded as an extension of hierarchical model. The principle difference between the two is that in a hierarchic model, a child is associated with only one type of parent record, whereas in a network model it can be associated with many types.

A network database consists of records, which actually hold information as a set of links between records, which form relationships.

OverviewIDMS (Integrated Data Management System) was developed by Cullinet Software Inc. It was enhanced and is currently supported by Computer Associates (CA). Initially IDMS was developed to run on IBM mainframes, however of late, versions for other environments have also been developed.

IDMS centralizes the data used by an organization but does not prevent data from being arranged in different ways to suit different applications. All data records are treated as members of one cohesive storage facility, i.e. the database.

The database contains a single definition for each data record. Records are connected in different logical groups called Sets, expressing various arrangements between records as required by applications

Page

Database is subdivided into number of pages. Smallest unit of data transfer between auxiliary and main memory Page size is typically 2k or 4k bytesRecord occurrences are stored in pagesEach page has a unique page numberEach record within the page has a unique line number AreasPages in the database are grouped into areasPages in an area are sequentially numberedGaps in page numbers can occur between areasA page can belong to one and only one areaAll pages of an area are of the same size. Record typeA Record type is the structural component that conveys the format in which records are stored. Record type is a generic group of similar record occurrences that would exist in the database. Record OccurrenceA Record occurrence is the actual content of data that is stored; it can be thought as the substance of information stored in the database. Record occurrence is the basic addressable unit of data under IDMS database.Record occurrences are always related to a specific Record type, and reside in pages. Each record occurrence can be fixed or variable in length.A record occurrence is further subdivided into fields or data elements based on its structure.Database key or DBKEY is a unique identifier for each record occurrence within the database. DBKEY comprises of two components Page number and Line number within a page.DBKEY of a record occurrence does not change as long as the occurrence exists in the database.Each record occurrence has two components: Prefix and Data:The Prefix consists of pointers such as those pointing to the NEXT, PRIOR and OWNER record. Each pointer is in form of a DBKEY. The pointer refers to physical location of another record occurrence that is related to the one containing the pointer.The Data is the set of bytes that represents the record value; it may have some internal structure that is defined by the application developer DBKEY Location ModeThe assignment of record to a particular page in its area is determined by the location mode.CALCrecord stored on or near a page calculated by IDMSretrieval of record based on symbolic key value IDMS converts symbolic key into record addressCan have duplicates clause as DF/DL/DN

OBTAIN CALC .

Move 0657 to dept-keyObtain CALC dept

. Location ModeVIA cluster member records with their respective ownersminimize disk accesses needed to retrieve membersgroups records that are likely to be retrieved at the same time

DIRECTRecords are retrieved using DB-Key DB-Key Each record occurrence is assigned a unique numeric identifier, called its database key (db-key). Format of db-key is shown below. A record occurrences db-key consists of a 32-bit field that typically contains a 23-bit page number and an 8-bit line number. The page number identifies the page in which the record occurrence is stored and the line number identifies the location of the record occurrence within that page. IDMS/R uses database keys to keep track of where in the database record occurrences are physically stored. Sign Bit (Not used)

0 1 23 24 31 Database Page NumberLine Number SetsA Set expresses relationships or association between two record types, where one is the super ordinate and other is the sub ordinate.The super ordinate record type is called the OWNER record and the subordinate record type is called the MEMBER record.A set associates one owner record occurrence with one or more member record occurrences; it establishes a one-to-many relationship.

A Set Type defines the structural components of a set, or the attributes of a set.A Set Occurrence comprises of an owner record occurrence along with its associated member record occurrences.There exists one set occurrence for each owner record occurrence.In case of a NULL set, an owner record may be the only one in the set occurrence if it does not have any associated member records.

Sets TypeSet Nameunique name of the set Set Linkagetype of pointers used in member recordsNEXT: each member record points to the next in the setPRIOR: each member record points to the previous in the setOWNER: each member record points to its owner

Sets TypeSet Orderspecifies where a new record is to be placed during insertionFIRST: new record placed first in the setLAST: new record placed last in the setNEXT: new record placed next to the current recordPRIOR: new record placed previous to the current recordSORTED: new record placed based sort key value

Sets Membership optionRemoval OptionsThese are also known as Disconnect or Erase optionsRemoval options are MANDATORY or OPTIONALMANDATORY: member is disconnected only when erasedOPTIONAL: member can be disconnected and can remain in the database

Sets Membership option STORAGE OPTION

These are also known as Connect optionsStorage options are MANUAL or AUTOMATICAUTOMATIC: member automatically connected when createdMANUAL: member not connected when created

Sets membership optionMA - Mandatory Automaticthis is defaultmembers automatically connected while insertionmembers disconnected while deletion MM - Mandatory Manualowner not identified at the time of insertion of memberhence member created but left isolatedmember connected when owner is identifiedOA - Optional Automaticmembers automatically connected while creationneed to disconnect and keep isolated from ownerto be possibly connected to some other owner OM - Optional Manualowner not identified at the time of insertionmembers connected when owner is identifiedmembers need to be disconnected and left isolated from ownerto be connected to other owner

Duplicates Option For CALCThe duplicates option is specified only for CALC location mode.

DN (Duplicates Not Allowed). A record occurrence with a duplicate CALC-key value will not be accepted. IDMS/R will signal an error if the program attempts to store a record that has the same CALC-key value as an existing record in the database.

DF (Duplicates First). A record occurrence with a duplicate CALC-key value will be accepted. IDMS/R will store the record before any record in the database that has a matching CALC-key value. When a CALC retrieval is made, the new record will be retrieved first.

DL (Duplicates Last). A record occurrence with a duplicate CALC-key value will be accepted. IDMS/R will store the record after any record in the database that has a matching CALC-key value. When a CALC retrieval is made, the new record will be retrieved last. Duplicates Option DF (Duplicates First) D1JoshiPatil(2)Patil(1)VermaAfter insertion. Patil(2) inserted. With the DF duplicates option, a record with a duplicate sort-key value is stored immediately before the existing duplicate record in the set. The first duplicate record encountered in the next direction is always the most recently stored duplicate record. Duplicates Option DL (Duplicates Last) D1JoshiPatil(1)Patil(2)VermaAfter insertion. Patil(2) inserted. With the DL duplicates option, a record with a duplicate sort-key value is stored immediately after the existing duplicate record in the set. The last duplicate record encountered in the next direction is always the most recently stored duplicate record. Duplicates Option DN (Duplicates Not Allowed) D1JoshiPatil(1)VermaTry to insert Patil(2).

It is rejected. IDMS/R returns an error code. With the DN duplicates option, a record with a duplicate sort-key value cannot be stored in the set. When a program attempts to store a record with a duplicate sort-key value, the DBMS returns an error code. Copyright 2008 Accenture All Rights Reserved.Error Handling ERROR-STATUS field of IDMS Communication Block contains status of the DML statement just executed. The ERROR-STATUS field consists of 4 bytes. First two bytes (major code) identify the function performed. The last two bytes (minor code) describe the status of that function. A value of 0000 indicates that the DML statement was successful. Any non-zero value indicates failure. ERROR-STATUS Field Values

Condition Name

Explanation

0000

DB-STATUS-OK

Successful

0307

DB-END-OF-SET

End of set, area or index

0326

DB-REC-NOT-FOUND

No record found for given key

0001 To 9999

ANY-ERROR-STATUS

Any error, Any non-zero value

.Example: Error Handling MOVE 2000 TO DEPT-ID-0410.OBTAIN CALC DEPARTMENT. IF DB-STATUS-OK DISPLAY DEPT-NAME-0410 ELSE IF DB-REC-NOT-FOUND DISPLAY GIVEN DEPT-ID NOT FOUND ELSE PERFORM IDMS-STATUS.

Area Name and Bachman DiagramArea Name: - The area name is the name of the area into which all record occurrences of the record type are to be stored.

Bachman Diagram For Record Type:

Obtain Vs. Find and Get An OBTAIN statement is equivalent to a FIND followed by a GET.

The find function causes IDMS/R to locate the appropriate record in the database and place it in the system buffers.

GET causes IDMS/R to move the appropriate data element values from the system buffers into our programs working-storage section.

We may not follow a FIND with a GET. In some cases, we only wish to locate a record, but do not need actually to retrieve it.

MOVE 2000 TO DEPT-ID-0410. FIND CALC DEPARTMENT.GET DEPARTMENT. MOVE SUDHIR TO FACULTY-ID. FIND CALC FACULTY. GET FACULTY. Access By Walking Sets: Access Through Set Relationship Retrieving members from owner Retrieving owner from members

Retrieving members from owner:

Access the sets owner record occurrence, then to retrieve member record occurrences from the set occurrence, following syntax is used.

OBTAIN First within Last Next Prior Nth Example: Access Thru Owner Example: Display all employees names for a given department.

MOVE N TO WS-END-SET. MOVE WS-DEPT-ID TO DEPT-ID-0410. OBTAIN CALC DEPARTMENT. IF DB-STATUS-OK PERFORM RETRIEVE-REC UNTIL WS-END-SET = Y ELSE IF DB-REC-NOT-FOUND DISPLAY GIVEN DEPT-ID NOT FOUND ELSE PERFORM IDMS-STATUS. RETRIEVE-REC. OBTAIN NEXT EMPLOYEE WITHIN DEPT-EMPLOYEE. IF DB-STATUS-OK DISPLAY EMP-NAME-0415 ELSE IF DB-END-OF-SET MOVE Y TO WS-END-SET ELSE PERFORM IDMS-STATUS. .Retrieving Owner From MembersOBTAIN OWNER WITHIN Example:Move 0001 to EMP-CODE.Obtain calc EMP....Obtain owner within DEPT-EMP.

Retrieval By Sort-Key Value If we are retrieving member records and the set type is with order option of SORTED, we can base retrievals on sort-key values.

OBTAIN WITHIN USING .

Expected return-codes are DB-STATUS-OK, DB-REC-NOT-FOUND.

The search for a record is limited to the current set occurrence. IDMS/R does not search other set occurrences for a member having the specified sort-key value.

IDMS/R begins searching member records from the first member record occurrence in the set occurrence.

Indexed Set To implement an index, IDMS/R builds an index file that contains the database key values of member record occurrences.

IDMS/R uses an array of database pointers to quickly access member records. DBMS locates the data by searching the index rather than the actual member record.

E.g. Employee record has an index built on last-name and first-name fields, apart from CALC key.

The use of indexes can simplify processing in the following situations:

Random retrieval by key value. Partial or generic key value can be used. Sorted retrieval by key value. Multiple-key access. Sometimes we need to access records based on more than one key. .Retrieval Using Indexed Set Each entry in the index contains an index-key data element value and the db-key value of its corresponding record occurrence.

Random Retrieval OBTAIN SKILL WITHIN SKILL-NAME-NDX USING SKILL-NAME-0455.

Expected return-codes are DB-STATUS-OK, DB-REC-NOT-FOUND. Sequential Retrieval OBTAIN NEXT EMPLOYEE WITHIN EMP-NAME-NDX.

Expected return codes are DB-STATUS-OK, DB-END-OF-SET. Generic-Key Retrieval Same as Sorted Set.

Retrieval By Sweeping Areas IDMS/R scans through all the records in an area in physical sequence.

Area sweeps are useful when we want to retrieve all the records in an area without regard to the order in which we get them.

OBTAIN First within Last Next Prior Nth

Pointers are not used in performing an area sweep, so prior pointers are not necessary for executing OBTAIN PRIOR WITHIN AREA statements.

Expected return-codes are DB-STATUS-OK, DB-END-OF-SET. Retrieval By Sweeping AreasExample: Retrieve all Course record occurrences. OBTAIN FIRST COURSE WITHIN COURSE-AREA. PERFORM 2000-RETRIEVE-REC UNTIL WS-END-OF-COURSE-AREA = Y. . .2000-RETRIEVE-REC. IF DB-STATUS-OK DISPLAY COURSE-ID OBTAIN NEXT COURSE WITHIN COURSE-AREA ELSE IF DB-END-OF-SET MOVE Y TO WS-END-OF-COURSE-AREA ELSE PERFORM IDMS-STATUS. Storing and Retrieval By DB-Key Value ACCEPT FROM CURRENCY MOVE DBKEY TO ws-db-key-v.

The field ws-db-key-v should be defined in working-storage as follows.

01 ws-db-key-v PIC S9(8) COMP SYNC.

To reestablish the currency to stored value, use following statement.

FIND / OBTAIN DB-KEY IS ws-db-key-v.The record-name is optional.

CurrenciesCurrencies are maintained in form of DBKEYS of most recently accessed records by application programs. The currencies enable application programs to position itself and move about record occurrences within the database.

Types of Currencies:-

1)Run Unit 2)Record Type 3)Set 4)Area. CurrenciesRUN UNITmost recently accessed record by the programRECORD TYPEmost recent record occurrence accessed for each record typeSETmost recent record occurrence accessed in each set,either the owner or the memberAREAmost recent record occurrence accessed in each area accessed by the program. CurrenciesBIND RUN-UNIT statement sets all the currencies to NULL.

Successful DML statement changes the currencies involved. The other currencies remain null until some future database access sets them.

Using the currencies and the NPO pointers stored in record occurrences, IDMS/R DBMS accesses records in the database.

FINISH statement nullifies all the currencies. .Currency Loss Example: Display last Course of all Subjects. . Obtain first subject within course-area. Perform next-subject-para until ws-course-area-end = y. ..Next-subject-para. If db-status-ok Perform disp-course-para Obtain next subject within course-area Else If db-end-of-set Move y to ws-course-area-end Else Perform idms-status. Disp-course-para. Obtain last course within sub-course. If db-status-ok Display course-id Else If db-end-of-set Display No Course Else Perform idms-status. .Re-establishing CurrencyEx.: To solve the area currency loss.

Next-subject-para. If db-status-ok Accept ws-db-key-v from course-area currency Perform disp-course-para Obtain subject db-key is ws-db-key-vPerform idms-status Obtain next subject within course-area Else ..Reestablishing Run-Unit Currency: FIND / OBTAIN CURRENT WITHIN WITHIN

After this statement, issue PERFORM IDMS-STATUS. IF EMPTY statementSyntax:If memberIf not member

After you have retrieved a owner record occurrence in a set, you can issue the IF EMPTY statement to determine if the set has any member record occurrences. Example:Move 0001 to EMP-CODE.Obtain calc EMP....If DEPT-EMP member

To determine if a set is empty, perform the following steps:

Establish currency for the set. Issue the IF EMPTY statement. Perform further processing as specified. IF Member statementIF [NOT] MEMBER Imperative statement

You can issue the IF member statement to ensure that a record occurrence currently participates as a member of a specified set occurrence.

To determine if a record participates as a member in a set, perform the following steps:

Establish run unit currency for the specified member record. Issue the IF MEMBER statement. Perform further processing, as specified.

DML Data Update Functions

READYIt is an equivalent to an OPEN statement for a conventional file.

It makes the required area of the database available to the program.

SHARED READY USAGE-MODE IS PROTECTED RETRIEVAL ALL EXCLUSIVE UPDATE

This statement begins a run-unit.

Usage-Mode Is Retrieval: The program will retrieve data only and will not modify data for the specified area. Usage-Mode Is Update: It informs IDMS/R that the program intends to update records from the specified area. Additional usage mode options that control the way in which database areas can be concurrently accessed by two or more run units.

STORESTORE

It is used to add a new record occurrence to the database. Adding a new record occurrence to the database is a simple threestep process:

Construct the new record occurrence in the working-storage section. Establish currency of the set types in which the new record participates as an automatic member. We can use FIND for this purpose. Execute the STORE function specifying the record type name. Example:Move 0001 to DEPT-CODE.Move Finance to DEPT-NAME.Move 120 to DEPT-COUNT.Store DEPT.Notes:Creates record in the databaseConnects stored record to owner in Automatic setsOwner records of those sets need to be made currentSet currency needs to be establishedCalc key and sort field should be populated

. MODIFYSyntax:Modify Example:Move 0001 to DEPT-CODE.Obtain calc DEPT.......Find current DEPT.Move 20 to DEPT-COUNTModify DEPTNotes:Record should be accessed by Obtain before ModifyRecord should be populated before ModifyRecord should be current of run-unit before ModifyCalc key should not be modifiedModification of record in sorted set may be expensive

. ERASEThis is used to delete a record occurrence from database.

PERMANENTERASE SELECTIVE MEMBERS ALL

Retrieve the record we want to erase, making it current of run unit. Issue an ERASE, naming the record type.

IDMS/R first disconnects the record from any sets in which it participates as a member, then removes the record occurrence from the database.

If the record we are erasing is the owner of any sets, the record will be erased only if those sets are empty.

If we try to erase an owner record of a nonempty set, IDMS/R returns an error status code value.

. ERASEThe ERASE ALL Option

It first causes the object record to be removed from the database. Then all its members, both mandatory and optional, will be removed, whether or not they are members in other set occurrences. If we execute an ERASE ALL for an Employee record, IDMS/R also removes all its member records, along with all their members.

The ERASE PERMANENT Option

IDMS/R erases the record that is the object of the ERASE. It erases all mandatory members in all sets owned by the object record. It does not erase optional members; it disconnects them instead. If an erased member is the owner of any sets, it is treated as if an ERASE PERMANENT were issued for it. Its mandatory members will be erased, and its optional members disconnected. This process continues until all members have been processed.

. ERASEThe ERASE SELECTIVE Option

An ERASE SELECTIVE always erases the record that is the object of the ERASE, and it always erases mandatory members in all sets owned by the object record.

It erases optional members if they do not participate in any other sets.

If the erased member is the owner of any sets, it is treated as if an ERASE SELECTIVE were issued for it. Its mandatory members will be erased, and its optional members will be erased if they do not participate in any other sets.

Remark: - Run unit and area currencies remain unchanged. It nullifies current pointers for:

-- All record types involved in Erase-- All sets in which the erased record participates

. CONNECTIt is used to establish a record occurrence as a member in a set occurrence. CONNECT TO . The CONNECT function can be used in conjunction with STORE for records that must be manually connected to sets. CONNECT connects the record that is current of run unit to the named set.

Membership option must not be MA (mandatory automatic).

All areas affected must be readied in UPDATE usage mode.

. DISCONNECTIt is used to disconnect a record occurrence from a set occurrence of which it is a member.

DISCONNECT FROM .

The DISCONNECT statement removes the record occurrence that is current of run unit from the named set.

The DISCONNECT statement cancels the membership of a record occurrence in a set occurrence in which it currently participates as a member.

The record that is the object of a DISCONNECT function must be defined as an optional member of that set. Otherwise, IDMS/R returns an error status code.

All areas affected must be readied in UPDATE usage mode.

. How to Access DB-KEY for record occurrencesSyntax:Accept from currencyAccept from currencyAccept from currencyAccept from [next/prior/owner] currency

Example:Move 0001 to EMP-CODE.Obtain calc EMP.Accept WS-EMP-DBKEY from EMP currency.Notes:Accesses database key for a recordStorage format for database key is S9(8) COMP.

. BIND STATEMENTS BIND RUN-UNIT

identifies IDMS communication block of program to DBMSidentifies subschema to be loaded for run-unitenables program to sign on to database

Bind

establishes addressability of record structure with DBMStells DBMS the address of record in variable storage

READY STATEMENTSReady Usage ModeSHARED/PROTECTED/EXCLUSIVERETRIEVAL/UPDATErequests access to database areas, and in turn recordsspecifies modes of access of areasRETRIEVAL:read only operationsUPDATE:read and create/modify/deleteSHARED:other run units can concurrently accessPROTECTED:other run units cannot ready in UPDATEEXCLUSIVE:other run units cannot ready in ANY FINISH STATEMENTSterminates run-unitreleases all resources associated with run-unitwrites checkpoint to journal

COMMIT STATEMENTSCommit requests IDMS to write checkpoint, makes changes to database permanent for the unit of work. Commit has two variations, i.e Commit and Commit AllCommitreleases all locks except implicit shared lockswrites a checkpointdoes not affect currenciesCommit Allreleases all lockswrites a checkpointnullifies currencies

ROLLBACK STATEMENTSRollbackRollback requests IDMS recovery of unit of work, undoes the changes to database. Rollback has two variations, i.e. Rollback and Rollback ContinueRollbackrequest recovery of unit of workterminates run unitRollback Continuerequests recovery of unit of work does not terminate run unit IDMS returns a 4 character error code after executing every DML statement. When DML statements are embedded in COBOL programs, IDMS returns error code in a variable called ERROR-STATUS, error code 0000 indicates that the DML statement has executed successfully.