In this section: |
With the FOCUS MODIFY and Maintain facilities, you can add new records to a data source, update field values for specific records, or delete specific records.
The adapter processes a MODIFY or Maintain transaction with the following steps:
In MODIFY, you must use the NEXT command to process a multi-record answer set one record at a time. Each NEXT command puts you physically at the next logical record in the answer set created by the most recent MATCH command for this segment. In Maintain, one NEXT command can process a multi-record answer set without a prior MATCH.
In this section: |
In response to a MATCH command, the adapter selects the first record in the data source that meets the MATCH criteria.
The MATCH command compares incoming data with one or more field values and then performs actions that depend on whether or not a record with matching field values exists in the data source.
The syntax of the MATCH command in MODIFY is
MATCH field1 [ field2...fieldn ] ON MATCH action_1 ON NOMATCH action_2
where:
Are fields in any segment of the Master File. FOCUS compares incoming data values against existing field values. The fields can be any combination of key and/or non-key fields. Specify complete field names; MATCH does not support truncated names.
Is the operation to perform when the values in a record match the incoming data values.
Is the operation to perform when the existing values in a record do not match the incoming data values.
The FOCUS Maintaining Databases manual discusses these actions in detail.
MATCH processing for multi-segment Master Files is the same as for a multi-segment FOCUS data source.
Acceptable actions for MATCH commands fall into eight groups. They are operations that:
In MODIFY requests, there are two major differences in the way MATCH commands function for the adapter and for native FOCUS:
Note: In Maintain, MATCH functions identically for the adapter and for native FOCUS.
Consider a MODIFY request that maintains the EMPWRITE data source. It prompts for an employee ID and for a new number of leave days. Then it processes the incoming data. The annotated request contains the following MATCH commands:
MODIFY FILE EMPWRITE PROMPT EMPLOYEE_ID LEAVE_DUE 1. MATCH EMPLOYEE_ID 2. ON MATCH UPDATE LEAVE_DUE 3. ON NOMATCH REJECT DATA
The incoming transaction contains the following values:
EMPLOYEE_ID = 12345678 LEAVE_DUE = 20
The request processes as follows:
In Maintain, you do not have to include an ON NOMATCH command in order to reject a transaction; Maintain automatically rejects a transaction that does not satisfy the MATCH criteria.
In this section: |
In MODIFY, the NEXT command provides a flexible means of processing multi-record answer sets by moving the current position in the answer set from one record to the next.
The syntax is
NEXT field ON NEXT action_1 ON NONEXT action_2
where:
Is any field in the current segment. This field does not affect subsequent actions.
Is the operation to perform when there is a subsequent record in the answer set. May be any of the acceptable actions listed for MATCH in The MATCH Command.
Is the operation to perform when no more records exist in the answer set.
The CALLTYPE parameter in the Access File controls the sort order for NEXT. It determines whether to retrieve records in physical order (CALLTYPE=FIND) or sorted by the unique key (CALLTYPE=RL).
Your choice of MATCH and NEXT command combinations determines the contents of the answer set. Subsequent sections explain these choices in more detail:
You can also use NEXT commands with multi-segment structures (FOCUS views) to modify or display data in either case logic or non-case logic requests. If your MATCH or NEXT specifies a record from a parent segment in a multi-segment structure, that record becomes the current position in the parent segment. A subsequent NEXT on a field in a descendant of that segment retrieves the first descendant record in the related segment. In MODIFY:
You can trace case logic with the FOCUS trace facility. To invoke the trace facility, include the TRACE command on a separate line after the MODIFY FILE command. You can also use the adapter trace facilities, described in Technical Memo 7966, Adabas Interface: Using Traces.
The following sections illustrate different combinations of MATCH and NEXT commands with annotated examples. The MODIFY requests have been kept simple for purposes of illustration. You can create more sophisticated procedures.
Note: In Maintain:
For complete details, see the Maintaining Databases manual.
If you use a NEXT command without a previous MATCH command in a MODIFY request, Adabas returns an answer set consisting of all records in the data source in physical order (CALLTYPE=FIND) or sorted by the unique key (CALLTYPE=RL). Use the ON NEXT command to view each record in the order determined by the CALLTYPE attribute. In a Maintain request, the FOR and WHERE phrases in the NEXT command determine the number of records retrieved, in the order determined by the CALLTYPE attribute.
In this MODIFY example, the NEXT command retrieves each record in physical order because the Access File contains the attribute CALLTYPE=FIND:
MODIFY FILE EMPWRITE NEXT EMPLOYEE_ID ON NEXT TYPE "EMPLOYEE ID: <D.EMPLOYEE_ID LAST NAME: <D.LAST_NAME " ON NONEXT GOTO EXIT DATA END
The TYPE commands display the following on the screen:
EMPLOYEE ID: 50005800 LAST NAME: GUENTER EMPLOYEE ID: 50005500 LAST NAME: BRAUN EMPLOYEE ID: 50004900 LAST NAME: CAOUDAL EMPLOYEE ID: 50004600 LAST NAME: VERDIE EMPLOYEE ID: 50004300 LAST NAME: GUERIN EMPLOYEE ID: 50004200 LAST NAME: VAUZELLE EMPLOYEE ID: 50004100 LAST NAME: CHAPUIS EMPLOYEE ID: 50004000 LAST NAME: MONTASSIER EMPLOYEE ID: 50003800 LAST NAME: JOUSSELIN EMPLOYEE ID: 50006900 LAST NAME: BAILLET . . .
If the Access File contained the attribute CALLTYPE=RL, the records would be retrieved in order of employee ID number.
The following Maintain procedure retrieves the same answer set into a stack named INSTACK and displays the retrieved values on a Winform named WIN1 (consult the Maintaining Databases manual for instructions on creating Winforms):
MAINTAIN FILE EMPWRITE INFER EMPLOYEE_ID LAST_NAME INTO INSTACK FOR ALL NEXT EMPLOYEE_ID INTO INSTACK WINFORM SHOW WIN1 END
The following Winform displays as a result of this procedure:
In MODIFY, NEXT processing is identical for either MATCH on a full unique key or MATCH on a superset (full unique key plus a non-key field).
When the initial MATCH is successful, Adabas retrieves one record. This establishes the logical position in the data source. The subsequent NEXT command causes Adabas to retrieve all records following the matched record in physical order (CALLTYPE=FIND) or key sequence (CALLTYPE=RL).
The following is an example of NEXT processing after a MATCH on a full unique key, the EMPLOYEE_ID field:
MODIFY FILE EMPWRITE CRTFORM LINE 1 " PLEASE ENTER VALID EMPLOYEE ID </1" 1. " EMP: <EMPLOYEE_ID " 2. MATCH EMPLOYEE_ID ON NOMATCH REJECT 3. ON MATCH GOTO GETREST CASE GETREST 4. NEXT EMPLOYEE_ID ON NEXT CRTFORM LINE 10 " EMPLOYEE_ID: <D.EMPLOYEE_ID LAST_NAME: <D.LAST_NAME " ON NEXT GOTO GETREST 5. ON NONEXT GOTO EXIT ENDCASE DATA END
The MODIFY procedure processes as follows:
The output after executing this MODIFY procedure with CALLTYPE=FIND is:
PLEASE ENTER VALID EMPLOYEE ID (line 1)
EMP: 20009000 (line 3)
EMPLOYEE_ID: 50005800 LAST_NAME: GUENTER (line 10)
EMPLOYEE_ID: 50005500 LAST_NAME: BRAUN (line 10)
EMPLOYEE_ID: 50004900 LAST_NAME: CAOUDAL (line 10)
EMPLOYEE_ID: 50004600 LAST_NAME: VERDIE (line 10)
EMPLOYEE_ID: 50004300 LAST_NAME: GUERIN (line 10)
Because of the NEXT command, all employees whose records are physically after 20009000 display one at a time on the screen.
The output after executing this MODIFY procedure with CALLTYPE=RL is:
PLEASE ENTER VALID EMPLOYEE ID (line 1)
EMP: 20009000 (line 3)
EMPLOYEE_ID: 20009100 LAST_NAME: JENSON (line 10)
EMPLOYEE_ID: 20009200 LAST_NAME: MEYER (line 10)
EMPLOYEE_ID: 20009300 LAST_NAME: SMITH (line 10)
EMPLOYEE_ID: 20009400 LAST_NAME: OLLE (line 10)
EMPLOYEE_ID: 20009500 LAST_NAME: RAY (line 10)
Notice that the employee IDs after 20009000 are retrieved in key sequence.
The following Maintain procedure retrieves the same answer set into a stack named EMPSTACK. Assume that when Maintain displays the Winform called WIN1, the user enters the transaction value, 20009000, into a stack named TRANS and clicks the NextRecs button to invoke the NEXTRECS case:
MAINTAIN FILE EMPWRITE INFER EMPLOYEE_ID LAST_NAME INTO EMPSTACK WINFORM SHOW WIN1 CASE NEXTRECS FOR ALL NEXT EMPLOYEE_ID INTO EMPSTACK WHERE EMPLOYEE_ID GT TRANS.EMPLOYEE_ID ENDCASE END
The following Winform displays when 20009000 is entered in the EMPLOYEE_ID field with CALLTYPE=FIND:
In a MODIFY request processed by the adapter, you do not have to MATCH on the full set of unique key fields. You can match on a non-key field or non-unique key. (Maintain always matches on the full unique key, regardless of which fields you specify in the MATCH command.)
When you MATCH on a non-unique key, multiple records may satisfy the MATCH condition. The MATCH operation retrieves the first record of the answer set, and the NEXT command makes the remaining records in the answer set available to the program in physical order. In this case, the order of retrieval for NEXT is always the physical sequence. MATCH on a non-key field should always be processed using CALLTYPE=FIND to prevent the adapter from issuing an inefficient Read Physical call. For more information see the Adapter for ADABAS Installation Guide.
This annotated procedure is the same procedure described in NEXT Processing After MATCH on a Unique Key, altered to MATCH on the non-unique key field LAST_NAME. The NEXT operation retrieves the subsequent records from the answer set in physical sequence:
MODIFY FILE EMPWRITE CRTFORM LINE 1 " PLEASE ENTER A LAST NAME </1 " 1. " LAST NAME: <LAST_NAME </1" 2. MATCH LAST_NAME ON NOMATCH REJECT 3. ON MATCH CRTFORM LINE 5 " EMPLOYEE_ID: <D.EMPLOYEE_ID LAST_NAME: <D.LAST_NAME " 4. ON MATCH GOTO GETSAME CASE GETSAME 5. NEXT LAST_NAME ON NEXT CRTFORM LINE 10 " EMPLOYEE_ID: <D.EMPLOYEE_ID LAST_NAME: <D.LAST_NAME " ON NEXT GOTO GETSAME 6. ON NONEXT GOTO EXIT ENDCASE DATA END
The MODIFY procedure processes as follows:
The output from this MODIFY procedure follows:
PLEASE ENTER A LAST NAME LAST_NAME smith EMPLOYEE_ID 40000311 LAST_NAME: SMITH EMPLOYEE_ID: 20009300 LAST_NAME: SMITH EMPLOYEE_ID: 20014100 LAST_NAME: SMITH . . . EMPLOYEE_ID: 30038013 LAST_NAME: SMITH
A line displays on the screen for each employee with the last name SMITH. Employee ID 40000311 is the result of the MATCH operation; employee ID 20009300 is the result of the NEXT operation, employee ID 30038013 is the result of the last NEXT operation. Notice that the records are retrieved in physical sequence, and order is not dependent on the CALLTYPE attribute.
The following Maintain procedure retrieves the entire answer set into a stack named EMPSTACK. Assume that when Maintain displays the Winform named WINA, the user enters the transaction value (SMITH) into the first record of a stack named TRANS and clicks the NextRecs button to invoke the NEXTRECS case:
MAINTAIN FILE EMPWRITE INFER EMPLOYEE_ID LAST_NAME INTO EMPSTACK WINFORM SHOW WINA CASE NEXTRECS FOR ALL NEXT EMPLOYEE_ID INTO EMPSTACK WHERE LAST_NAME EQ TRANS.LAST_NAME ENDCASE END
The following Winform displays when the NexRecs button is pressed with SMITH entered in the Last_Name field:
In this section: Reference: |
While MATCH and NEXT operations in MODIFY can operate on unique key or non-unique key fields and return single or multi-record answer sets, the MODIFY commands INCLUDE, UPDATE, and DELETE must always identify the target records by their unique key. Therefore, in MODIFY, each update operation affects at most one record. (In Maintain, the FOR phrase in the update command determines the number of records affected.)
The unique key field value is used to insert the target segment. If any additional MATCH criteria are supplied for a segment in the path, they will be used to qualify that path segment.
An attempt to use MATCH on a non-unique key before an INCLUDE command generates the following error message:
(FOC4563) INCORRECT INCLUDE REQUEST FOR NON UNIQUE KEY
If you want to insert an additional record for an existing key field, you must MATCH on the key field and specify ON MATCH INCLUDE.
(FOC4564) THIS OCCURRENCE ALREADY EXISTS. USE UPDATE COMMAND.
You should use the UPDATE command instead of INCLUDE in this case.
Note: The Master File does not identify the level of an MU field because if the MU field belongs to a simple group, the Master File does not describe this group. (However, if AUTOADBS created the Master File, there will be a commented declaration for the group.) Therefore, FOCUS cannot determine whether Adabas will add an empty occurrence for the corresponding segment. You must be aware of the options in the Adabas FDT to understand the behavior that occurs in response to an INCLUDE command for an MU segment.
The UNQKEYNAME attribute in the Access File determines how the adapter presents an INCLUDE command to Adabas. The option UQ in the Adabas FDT and the specific fields used in the MATCH command determine whether Adabas actually inserts the segment instance. The following table describes how these factors affect the result of the INCLUDE command. Assume that the Access File specifies UNQKEYNAME=EMPLOYEE_ID and that the employee ID value EMPID005 already exists in the data source:
Result of INCLUDE Command for Existing EMPLOYEE_ID EMPID005 | ||
---|---|---|
EMPLOYEE_ID has option UQ in FDT |
Fields in MATCH command |
Instance Inserted(ON NOMATCH) |
No |
EMPLOYEE_ID only |
ON MATCH case performed |
Yes |
EMPLOYEE_ID only |
ON MATCH case performed |
No |
EMPLOYEE_ID plus fields with values that do not already exist |
Yes |
Yes |
EMPLOYEE_ID plus fields with values that do not already exist |
No - error (FOC4561), RC=198 |
This table describes INCLUDE actions when EMPLOYEE_ID is not in the MATCH field list:
Result of INCLUDE Command Without Matching on Field EMPLOYEE_ID | |
---|---|
UNQKEYNAME = EMPLOYEE_ID? |
Instance Inserted |
Yes |
No - error (FOC4563) |
No |
Yes |
Suppose you want to display all the employees in a department and update the amount of leave they have taken:
MODIFY FILE EMPWRITE CRTFORM LINE 1 " PLEASE ENTER A VALID DEPARTMENT </1" 1. " DEPARTMENT: <DEPARTMENT " 2. MATCH DEPARTMENT ON NOMATCH REJECT ON MATCH CRTFORM LINE 10 3. "ID: <D.EMPLOYEE_ID LEAVE DUE: <D.LEAVE_DUE> TAKEN <T.LEAVE_TAKEN> " 4. ON MATCH UPDATE LEAVE_TAKEN ON MATCH GOTO GETREST CASE GETREST 5. NEXT EMPLOYEE_ID ON NEXT CRTFORM LINE 10 "ID: <D.EMPLOYEE_ID LEAVE DUE: <D.LEAVE_DUE> TAKEN <T.LEAVE_TAKEN> " ON NEXT UPDATE LEAVE_TAKEN ON NEXT GOTO GETREST 6. ON NONEXT GOTO EXIT ENDCASE DATA END
The MODIFY procedure processes as follows:
In Maintain, you can use stack columns as turnaround values to update a data source. The following annotated Maintain request updates the same records as the preceding MODIFY request:
MAINTAIN FILE EMPWRITE INFER EMPLOYEE_ID LEAVE_DUE LEAVE_TAKEN INTO EMPSTACK 1. WINFORM SHOW WIN1 2. CASE MATCHREC FOR ALL NEXT EMPLOYEE_ID INTO EMPSTACK WHERE DEPARTMENT EQ VALSTACK.DEPARTMENT ENDCASE 3. CASE UPDLV FOR ALL UPDATE LEAVE_TAKEN FROM EMPSTACK ENDCASE END
The Maintain procedure processes as follows:
The following Winform displays when the GetEmp button (or PF4) is pressed with PROD entered in the Department field:
The user can update the LEAVE_TAKEN field for all of the listed employees and update them all in one step with the Update button (or PF6).
In this section: |
The adapter supports the Logical Unit of Work (LUW) concept. An LUW consists of one or more FOCUS maintenance actions (UPDATE, INCLUDE, or DELETE) that process as a single unit. The maintenance operations within the LUW can operate on the same or separate data sources.
In MODIFY, all records read by MATCH and NEXT commands are held by Adabas in a hold record queue for a user. To prevent overflow of this queue, the user should periodically issue the SQL COMMIT WORK command to propagate the changes to the Adabas data source and clear the queue.
In Maintain, records are not held when they are read into a stack. They are held only in response to an updating command.
A transaction is defined as all actions taken since the application first accessed Adabas, last issued an SQL COMMIT WORK command in MODIFY or a COMMIT command in Maintain, or last issued an SQL ROLLBACK WORK command in MODIFY or a ROLLBACK command in Maintain.
Within a Logical Unit of Work, Adabas either executes all commands completely, or else it executes none of them. If Adabas detects no errors in any of the commands within the LUW:
In response to unsuccessful execution of any command in the transaction, the adapter:
Adabas and the adapter provide a level of automatic transaction management but, in many cases, this level of management alone is not sufficient. FOCUS supports explicit control of Adabas transactions with the commands SQL COMMIT WORK and SQL ROLLBACK WORK in MODIFY, and with the commands COMMIT and ROLLBACK in Maintain.
Note: SQL COMMIT WORK and SQL ROLLBACK WORK are adapter commands. Do not confuse these commands with the FOCUS COMMIT WORK and ROLLBACK WORK commands that apply to FOCUS data sources only. The adapter ignores COMMIT WORK and ROLLBACK WORK without the SQL qualifier.
Unless you specify SQL COMMIT WORK and/or SQL ROLLBACK WORK in your MODIFY procedure (or COMMIT and/or ROLLBACK in your Maintain procedure), all FOCUS maintenance actions until the END command constitute a single LUW. If the procedure completes successfully, the adapter automatically transmits an ET command to Adabas, and the changes become permanent. If the procedure terminates abnormally, the adapter issues a BT command to Adabas, and the database remains untouched. Since locks are not released until the end of the program, a long MODIFY or Maintain procedure that relies on the default, end-of-program ET can interfere with concurrent access to data. In addition:
The SQL COMMIT WORK command signals the successful completion of a transaction at the request of the procedure. Execution of a COMMIT command makes changes to the data sources permanent. The syntax in a MODIFY request is:
SQL COMMIT WORK
You can issue a COMMIT WORK as an ON MATCH, ON NOMATCH, ON NEXT, or ON NONEXT condition, after an update operation (INCLUDE, UPDATE, DELETE), or within cases of a case logic request.
Note: In Maintain, you must use the Maintain facility COMMIT command to transmit an ET (End of Transaction) command to Adabas.
A COMMIT WORK example using Case Logic follows:
CASE PROCESS CRTFORM MATCH field1 ... ON MATCH insert, update, delete, ... GOTO EXACT ENDCASE CASE EXACT SQL COMMIT WORK GOTO TOP ENDCASE
The PROCESS case handles the MATCH, ON MATCH, and ON NOMATCH processing. Then it transfers to CASE EXACT, which commits the data instructing Adabas to write the entire Logical Unit of Work to the database.
The SQL ROLLBACK WORK command signals the unsuccessful completion of a transaction at the request of the procedure. Execution of a ROLLBACK command backs out all changes made to the data sources since the last COMMIT command. The syntax in a MODIFY request is:
SQL ROLLBACK WORK
You can design a MODIFY procedure to issue a ROLLBACK WORK command if you detect an error. For example, if a FOCUS VALIDATE test finds an inaccurate input value, you may choose to exit the transaction, backing out all changes since the last COMMIT. You can issue ROLLBACK WORK as an ON MATCH, ON NOMATCH, ON NEXT, or ON NONEXT condition, or within cases of a case logic request.
Note: In Maintain, you must use the Maintain facility ROLLBACK command to transmit a BT command (Back out Transaction) to Adabas.
The adapter automatically executes an SQL ROLLBACK WORK command when you exit from a transaction early. For example, if you exit a CRTFORM without specifying some action, the adapter automatically issues a ROLLBACK WORK command on your behalf.
The adapter automatically issues a BT command in case of system failure or when it detects a fatal data error, such as a reference to a field or data source that does not exist.
The following is an example of the ROLLBACK WORK command using Case Logic:
ON NOMATCH CRTFORM ... ON NOMATCH VALIDATE ... ON INVALID GOTO ROLLCASE . . . CASE ROLLCASE SQL ROLLBACK WORK GOTO TOP ENDCASE
Code the ROLLBACK WORK command before a REJECT command. FOCUS ignores any action following the rejection of a transaction, except for GOTO or PERFORM.
For example:
ON MATCH SQL ROLLBACK WORK ON MATCH REJECT
Each time an employee takes leave days, the following example updates the LEAVE_TAKEN field in the root segment of the EMPWRITE data source and posts a record for the leave start and end dates in the related AW0401 segment. To ensure that both updates complete or neither one does, the MODIFY procedure places both actions prior to a COMMIT WORK command. If the descendant data source is not processed, ROLLBACK WORK discards the whole logical transaction.
MODIFY FILE EMPWRITE CRTFORM LINE 1 "</2 <25 MODIFY FOR LEAVE TAKEN </2 " "<20 ENTER THE EMPLOYEE ID <EMPLOYEE_ID " MATCH EMPLOYEE_ID ON MATCH CRTFORM LINE 7 "<D.FIRST_NAME <D.LAST_NAME> LEAVE TAKEN <T.LEAVE_TAKEN> </1 " ON MATCH UPDATE LEAVE_TAKEN ON MATCH COMPUTE AW0401_OCC =0; ON NOMATCH REJECT MATCH AW0401_OCC ON NOMATCH CRTFORM LINE 10 "PLEASE ENTER LEAVE DATES" "LEAVE_START: <T.LEAVE_START> " "LEAVE_END: <T.LEAVE_END> " ON NOMATCH INCLUDE ON NOMATCH SQL COMMIT WORK ON MATCH SQL ROLLBACK WORK ON MATCH REJECT DATA END
FOCUS stores the return code from the updating commands INCLUDE, DELETE, and UPDATE in the variable FOCERROR:
A return code of zero indicates successful completion of the last updating command issued.
You can test the FOCERROR variable and take appropriate action if you encounter a non-fatal error. This condition might indicate the need to rollback the transaction or re-prompt the user for new input values. In Maintain, all errors after updating commands are non-fatal, and you should always test FOCERROR after issuing an updating command. In MODIFY, you can issue the SQL SET ERRORRUN ON command to make these errors non-fatal. If you do not issue this command, all errors after updating commands in MODIFY will be fatal.
All errors that result from retrieval commands such as MATCH or NEXT are fatal errors. An example of a command that causes a retrieval error is attempting to read a record held by another user. These errors terminate MODIFY and Maintain procedures.
For a list of common Adabas response codes, see Adabas Response Codes.
How to: |
With SET ERRORRUN ON, MODIFY processing continues even when a serious error occurs, allowing applications to handle their own errors in the event that an Adabas error is part of the normal application flow. Code this command explicitly within the MODIFY procedure, preferably in CASE AT START, where it executes once.
Note: Maintain does not support the SET ERRORRUN command. All errors after updating commands are non-fatal.
When SET ERRORRUN is ON, the MODIFY procedure reports the error but continues execution. The MODIFY code can then test the value of FOCERROR to determine the cause of the error and take appropriate action. Be careful in evaluating the contents of FOCERROR, to prevent unpredictable errors in subsequent MODIFY processing.
SET ERRORRUN returns to its default setting of OFF at the end of the MODIFY procedure.
CASE AT START
SQL SET ERRORRUN {OFF|ON}
ENDCASE
where:
Stops MODIFY processing when the adapter detects a fatal error. OFF is the default.
Enables MODIFY processing to continue despite fatal errors. Test the value of FOCERROR to determine the desired action after an updating command fails. After the procedure ends, ERRORRUN returns to its default value of OFF.
Adabas permits data sources with duplicate records. Such data sources cannot possibly have a unique key, since no combination of field values can make a given record unique.
The adapter provides a way of maintaining data sources with duplicate records. However, only the first record encountered will be affected by data maintenance commands.
Note: Maintain does not support modifying unkeyed data sources.
Information Builders |