Previous | Contents | Index |
The first exchange step directs DECforms to display a panel that prompts the user for the employee number of the record to be updated. This employee number is passed to the first processing step, which retrieves the specified record from the RMS file and displays it to the user.
To define the first exchange step:
GET_EMPL_NUMBER: EXCHANGE RECEIVE FORM RECORD EMPLOYEE_INFO_RECORD IN EMPLOYEE_INFO_PROMPT_LABEL RECEIVING EMPLOYEE_INFO_WKSP WITH RECEIVE CONTROL QUIT_WORKSPACE; |
CONTROL FIELD IS QUIT_WORKSPACE.QUIT_KEY " FQUT" : EXIT TASK; END CONTROL FIELD; |
The first processing step calls a COBOL procedure that retrieves an employee record from the RMS master file. The retrieved record corresponds to the employee number that the user entered. The user then has an opportunity to modify employee information on the panel that displays this record.
Add the following processing step next as the second step in your task definition file. To simplify referencing this step in the task, begin the step with the label RETRIEVE_UPDATE_INFO:
RETRIEVE_UPDATE_INFO: PROCESSING CALL GET_EMPL_INFO IN EMPL_SERVER USING EMPLOYEE_INFO_WKSP, EMPLOYEE_INFO_COMPARE_WKSP, CONTROL_WORKSPACE; |
GET_EMPL_INFO is the name of the COBOL procedure that retrieves a
record from the RMS file. It runs in the server EMPL_SERVER and uses
three workspaces. The procedure and these workspaces are discussed
later in the chapter.
8.2.3 Defining the Second Exchange Step
The second exchange step directs DECforms to display the retrieved employee record on a panel. The user can then modify that information. When the user finishes modifying employee information, this exchange step then directs DECforms to return the updated information to ACMS.
Next, add the second exchange step to your task definition file. To simplify referencing this step in the task, begin the step with the label GET_UPDATE_INFO_FROM_USER:
GET_UPDATE_INFO_FROM_USER: EXCHANGE TRANSCEIVE FORM RECORD EMPLOYEE_INFO_RECORD, EMPLOYEE_INFO_RECORD IN EMPLOYEE_INFO_LABEL SENDING EMPLOYEE_INFO_WKSP RECEIVING EMPLOYEE_INFO_WKSP WITH RECEIVE CONTROL QUIT_WORKSPACE; CONTROL FIELD IS QUIT_WORKSPACE.QUIT_KEY " FQUT" : EXIT TASK; END CONTROL FIELD; |
The second exchange step begins with a TRANSCEIVE FORM RECORD call to DECforms naming the SEND record and the RECEIVE record involved in the TRANSCEIVE operation (in both cases here, EMPLOYEE_INFO_RECORD). The name EMPLOYEE_INFO_LABEL specifies which form to use.
The SENDING clause names the workspace sent to the form: EMPLOYEE_INFO_WKSP. The RECEIVING clause names the workspace received from the form: also EMPLOYEE_INFO_WKSP. The latter workspace contains any modifications that a user makes to the data items displayed on the form.
As you did for the first exchange step, include a CONTROL FIELD clause
in your task definition so that the user can press a key to exit from
the task without saving any entries.
8.2.4 Defining the Second Processing Step
The second processing step calls a COBOL procedure that processes the update information and places it in the RMS file.
Next, add the second processing step to your task definition file. To simplify referencing this step in the task, begin the step with the label PROCESS_UPDATE_INFO:
PROCESS_UPDATE_INFO: PROCESSING CALL PUT_EMPL_INFO IN EMPL_SERVER USING EMPLOYEE_INFO_WKSP, EMPLOYEE_INFO_COMPARE_WKSP, CONTROL_WORKSPACE; IF (CONTROL_WORKSPACE.ERROR_STATUS_FIELD EQ "CHNG") THEN MOVE "Changed by another user. Ctrl/Z to repeat, PF4 to quit." TO CONTROL_WORKSPACE.MESSAGEPANEL; ELSE EXIT TASK; END IF; |
PUT_EMPL_INFO is the name of the COBOL procedure that writes a changed record to the RMS file. It runs in EMPL_SERVER and uses the same workspaces as the retrieval procedure. The procedure and these workspaces are discussed later in the chapter.
The procedure PUT_EMPL_INFO reads this record from the RMS file and locks it. The procedure then compares this record to a copy of the original record stored in a workspace.
If the two records do not match, the record in the RMS file has been changed since the user first saw it. In that case, the user is attempting to modify an outdated version of the record. The user is notified (by means of the "changed" message) and given the opportunity to repeat (with the current version of the record) or quit (cancel the task).
If the records do match, the procedure writes the modified record to the RMS file.
The IF THEN ELSE clause tests for the CHNG value in the field
ERROR_STATUS_FIELD. If the value is present, a message is stored in the
MESSAGEPANEL field, and the task moves on to the third exchange step to
display the message. Otherwise, if the CHNG value is not in the
workspace field, control passes to the ELSE statement and ends the task
successfully.
8.2.5 Defining the Third Exchange Step
The third exchange step is nearly the same as the second exchange step in the data entry task discussed in Chapter 7. The purpose of this step is to display an error message, if the user tries to modify a record that another user just changed.
Add the following lines to your source file. To simplify referencing this step in the task, begin with the label DISPLAY_ERROR_MESSAGE:
DISPLAY_ERROR_MESSAGE: EXCHANGE SEND FORM RECORD CONTROL_WORKSPACE IN EMPLOYEE_INFO_LABEL SENDING CONTROL_WORKSPACE WITH RECEIVE CONTROL QUIT_WORKSPACE; ACTION IS IF (QUIT_WORKSPACE.QUIT_KEY EQ " FQUT") THEN EXIT TASK; ELSE REPEAT TASK; END IF; |
To complete the inquiry/update task definition, you need to add some lines at the beginning of your file and at the end of your file. These lines define the block step and the remaining elements of the definition. As described in Section 7.4.4, the block step consists of the exchange and processing steps, which constitute the block work.
REPLACE TASK EMPLOYEE_INFO_UPDATE_TASK USE WORKSPACES EMPLOYEE_INFO_WKSP, EMPLOYEE_INFO_COMPARE_WKSP, QUIT_WORKSPACE, CONTROL_WORKSPACE; BLOCK WORK WITH FORM I/O |
END BLOCK WORK; END DEFINITION; |
8.3 Compiling the Task Definition
Compiling the task definition in ADU allows ADU to check for syntax
errors in the source file EMPLOYEE_INFO_UPDATE_TASK.TDF. If there are
no errors, ADU inserts your task definition into CDD. To do this,
perform the following steps:
$ ADU |
ADU> SET LOG ADU> SET VERIFY |
ADU> @EMPLOYEE_INFO_UPDATE_TASK.TDF |
The procedures used in the inquiry/update task are similar in many respects to the COBOL procedure EMPLOYEE_INFO_ADD.COB, which is called from the data entry task discussed in Chapter 7. Consequently, this section does not discuss the basic details again. This section concentrates instead on the processing and error handling in the Procedure Division of each program.
The first processing step in the inquiry/update task calls a COBOL procedure that retrieves a record from an RMS file. (You must retrieve the record before calling DECforms to display it.) This COBOL procedure is called EMPLOYEE_INFO_UPDATE_GET.COB.
The second processing step calls a COBOL procedure that writes the
updated record to the RMS file. This COBOL procedure is called
EMPLOYEE_INFO_UPDATE_PUT.COB. The following sections explain these two
procedures.
8.4.1 Defining the Retrieval Procedure
The Identification Division, the Environment Division, and the File Section of the Data Division for the retrieval procedure are almost identical to those for the data entry procedure (see Example 7-1). The only difference is the PROGRAM-ID, which for the retrieval procedure is GET_EMPL_INFO. Because the data entry and retrieval procedures use the same RMS file, they must define the file identically in the SELECT and FD statements.
Create the COBOL retrieval procedure as follows:
Example 8-1 COBOL Retrieval Procedure |
---|
***************************************************************** IDENTIFICATION DIVISION. PROGRAM-ID. GET_EMPL_INFO. ***************************************************************** ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. VAX-11. OBJECT-COMPUTER. VAX-11. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMPLOYEE-FILE ORGANIZATION INDEXED ACCESS RANDOM FILE STATUS IS FILE-STAT ASSIGN TO "xxx_FILES:EMPLOYEE.DAT". I-O-CONTROL. APPLY LOCK-HOLDING ON EMPLOYEE-FILE. ***************************************************************** DATA DIVISION. FILE SECTION. FD EMPLOYEE-FILE EXTERNAL DATA RECORD IS EMPLOYEE_INFO_WKSP RECORD KEY EMPL_NUMBER OF EMPLOYEE_INFO_WKSP. COPY "EMPLOYEE_INFO_WKSP" FROM DICTIONARY. WORKING-STORAGE SECTION. 01 FILE-STAT PIC XX IS EXTERNAL. 88 OK VALUE "00". 88 REC-LOCK VALUE "92". LINKAGE SECTION. COPY "EMPLOYEE_INFO_WKSP" FROM DICTIONARY REPLACING ==EMPLOYEE_INFO_WKSP. == BY ==EMPLOYEE_INFO_LINKAGE_WKSP. ==. COPY "EMPLOYEE_INFO_WKSP" FROM DICTIONARY REPLACING ==EMPLOYEE_INFO_WKSP. == BY ==EMPLOYEE_INFO_COMPARE_WKSP. ==. COPY "CONTROL_WORKSPACE" FROM DICTIONARY. ***************************************************************** PROCEDURE DIVISION USING EMPLOYEE_INFO_LINKAGE_WKSP, EMPLOYEE_INFO_COMPARE_WKSP, CONTROL_WORKSPACE. DECLARATIVES. EMPLOYEE-USE SECTION. USE AFTER STANDARD ERROR PROCEDURE ON EMPLOYEE-FILE. EMPLOYEE-CHECKING. EVALUATE TRUE WHEN REC-LOCK MOVE "LOCK" TO ERROR_STATUS_FIELD END-EVALUATE. END DECLARATIVES. MAIN SECTION. 000-SET-STATUS. MOVE SPACES TO ERROR_STATUS_FIELD. 010-GET-RECORD. MOVE EMPL_NUMBER OF EMPLOYEE_INFO_LINKAGE_WKSP TO EMPL_NUMBER OF EMPLOYEE_INFO_WKSP. READ EMPLOYEE-FILE INTO EMPLOYEE_INFO_LINKAGE_WKSP ALLOWING NO OTHERS. MOVE EMPLOYEE_INFO_WKSP TO EMPLOYEE_INFO_COMPARE_WKSP. 100-EXIT-PROGRAM. UNLOCK EMPLOYEE-FILE. EXIT PROGRAM. |
Recall that the Linkage Section lists the workspaces that ACMS passes to the procedure. The linkage workspace and the file workspace must have different names; therefore, the COPY statement includes the REPLACING clause to assign a different name to the EMPLOYEE_INFO_WKSP workspace. Like the data entry procedure, the retrieval procedure also uses CONTROL_WORKSPACE for error handling and reporting.
In the retrieval procedure, you make a copy of the record displayed to the user and store it in another workspace. The copied record is called EMPLOYEE_INFO_COMPARE_WKSP, and ACMS passes it to the update procedure to be compared with the corresponding record in the RMS file. If the the record in the RMS file has changed since this task began, ACMS notifies the user that the displayed record is no longer current.
In the Main Section of the Procedure Division, the retrieval procedure performs the following actions:
Use the COBOL command to compile the retrieval procedure. By appending the /DEBUG qualifier to this command, you create the capability to debug the procedure later with the OpenVMS Debugger. By appending the /LIST qualifier, you generate a listing of your program showing any errors. (The listing file has the file type .LIS.)
Compile the source file EMPLOYEE_INFO_UPDATE_GET.COB as follows:
$ COBOL/DEBUG/LIST EMPLOYEE_INFO_UPDATE_GET $ |
If the source file contains syntax errors, continue to edit the source
file and recompile it until the program compiles successfully.
8.4.3 Defining the Update Procedure
Except for the PROGRAM-ID, the update procedure is identical to the retrieval procedure until the Main Section of the Procedure Division.
Create the update procedure as follows:
Example 8-2 COBOL Update Procedure |
---|
IDENTIFICATION DIVISION. PROGRAM-ID. PUT_EMPL_INFO. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. VAX-11. OBJECT-COMPUTER. VAX-11. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMPLOYEE-FILE ORGANIZATION INDEXED ACCESS RANDOM FILE STATUS IS FILE-STAT ASSIGN TO "xxx_FILES:EMPLOYEE.DAT". I-O-CONTROL. APPLY LOCK-HOLDING ON EMPLOYEE-FILE. DATA DIVISION. FILE SECTION. FD EMPLOYEE-FILE EXTERNAL DATA RECORD IS EMPLOYEE_INFO_WKSP RECORD KEY EMPL_NUMBER OF EMPLOYEE_INFO_WKSP. COPY "EMPLOYEE_INFO_WKSP" FROM DICTIONARY. WORKING-STORAGE SECTION. 01 FILE-STAT PIC XX IS EXTERNAL. 88 OK VALUE "00". 88 REC-LOCK VALUE "92". LINKAGE SECTION. COPY "EMPLOYEE_INFO_WKSP" FROM DICTIONARY REPLACING ==EMPLOYEE_INFO_WKSP. == BY ==EMPLOYEE_INFO_LINKAGE_WKSP. ==. COPY "EMPLOYEE_INFO_WKSP" FROM DICTIONARY REPLACING ==EMPLOYEE_INFO_WKSP. == BY ==EMPLOYEE_INFO_COMPARE_WKSP. ==. COPY "CONTROL_WORKSPACE" FROM DICTIONARY. PROCEDURE DIVISION USING EMPLOYEE_INFO_LINKAGE_WKSP, EMPLOYEE_INFO_COMPARE_WKSP, CONTROL_WORKSPACE. DECLARATIVES. EMPLOYEE-USE SECTION. USE AFTER STANDARD ERROR PROCEDURE ON EMPLOYEE-FILE. EMPLOYEE-CHECKING. EVALUATE TRUE WHEN REC-LOCK MOVE "LOCK" TO ERROR_STATUS_FIELD END-EVALUATE. END DECLARATIVES. MAIN SECTION. 000-SET-STATUS. MOVE SPACES TO ERROR_STATUS_FIELD. 010-GET-RECORD. MOVE EMPL_NUMBER OF EMPLOYEE_INFO_LINKAGE_WKSP TO EMPL_NUMBER OF EMPLOYEE_INFO_WKSP. READ EMPLOYEE-FILE ALLOWING NO OTHERS. IF ERROR-STATUS_FIELD EQUAL "LOCK" THEN GO TO 100-EXIT-PROGRAM. 020-CHECK-FOR-CHANGES. PERFORM 070-CHECK-RECORD. IF ERROR-STATUS_FIELD EQUAL "CHNG" THEN MOVE EMPLOYEE_INFO_WKSP TO EMPLOYEE_INFO_LINKAGE_WKSP MOVE EMPLOYEE_INFO_WKSP TO EMPLOYEE_INFO_COMPARE_WKSP GO TO 100-EXIT-PROGRAM. 030-REWRITE-RECORD. REWRITE EMPLOYEE_INFO_WKSP FROM EMPLOYEE_INFO_LINKAGE_WKSP ALLOWING NO OTHERS. GO TO 100-EXIT-PROGRAM. 070-CHECK-RECORD. EVALUATE EMPLOYEE_INFO_WKSP EQUAL EMPLOYEE_INFO_COMPARE_WKSP WHEN FALSE MOVE "CHNG" TO ERROR_STATUS_FIELD END-EVALUATE. 100-EXIT-PROGRAM. UNLOCK EMPLOYEE-FILE. EXIT PROGRAM. |
In the Procedure Division, the update procedure performs the following actions:
Use the COBOL command to compile the update procedure. By appending the /DEBUG qualifier to this command, you create the capability to debug the procedure later with the OpenVMS Debugger. By appending the /LIST qualifier, you generate a listing of your program showing any errors. (The listing file has the file type .LIS.)
Compile the source file EMPLOYEE_INFO_UPDATE_PUT.COB as follows:
$ COBOL/DEBUG/LIST EMPLOYEE_INFO_UPDATE_PUT $ |
If the source file contains syntax errors, continue to edit the source file and recompile it until the COBOL compiler completes successfully.
Previous | Next | Contents | Index |