Examples of MODIFY Processing

In this section:

This section provides examples of MODIFY processing that add, update and delete data from a data source.

Each request indicates the data source it is modifying, the method of reading data, the transaction values it searches for in the data source, and the actions it takes depending on whether the values are in the data source or not. If it is reading a transaction data source, the request must indicate the name of the data source.

Adding Data to a Data Source

The following sample MODIFY request adds new employee data to the EMPLOYEE data source. When you run the request, it prompts you for an employee ID number, last name, and first name. After you enter these three values, the request adds the information to the data source and prompts you for three more values for the same fields. When you are finished entering data, end execution by entering the word END to any prompt.

The request is as follows:

1. MODIFY FILE EMPLOYEE  
2. PROMPT EMP_ID LAST_NAME FIRST_NAME  
3. MATCH EMP_ID  
4.    ON MATCH REJECT  
5.    ON NOMATCH INCLUDE  
6. DATA

The parts of the request are as follows:

  1. The MODIFY FILE EMPLOYEE statement indicates that the request modifies the EMPLOYEE data source.
  2. The PROMPT statement indicates that the request will prompt you for the employee's ID (EMP_ID), last name, and first name on the terminal.
  3. The MATCH EMP_ID statement searches the data source for the employee ID that you entered.
  4. If the ID is already in the data source (that is, an ID in the data source matches the ID you entered), the MATCH statement rejects your transaction.
  5. If the ID is not yet in the data source, the MATCH statement adds your transaction to the data source.
  6. The DATA statement begins prompting for data.

Updating Data in a Data Source

MODIFY requests can update data in a data source, replacing data source values with transaction (incoming data) values. The following sample request updates employee department assignments and salaries. When you run the request, it reads the data from a separate data source called EMPDEPT. Each record in the data source consists of three fields:

This is the EMPDEPT data source:

* * * TOP OF FILE * * *
071382660PRODUCTION27500.00 
112847612SALES     24800.75
451123478MARKETING 26950.00
* * * END OF FILE * * *

The request is as follows:

    MODIFY FILE EMPLOYEE  
1.  FIXFORM EMP_ID/9 DEPARTMENT/10 CURR_SAL/8  
2.  MATCH EMP_ID  
2.     ON NOMATCH REJECT  
2.       ON MATCH UPDATE DEPARTMENT CURR_SAL  
3.  DATA ON EMPDEPT  
4.  END

The parts of the request are as follows:

  1. The FIXFORM statement indicates that the transaction records are in fixed positions in the EMPDEPT data source and describes the positions of the fields in each record.
  2. The MATCH EMP_ID statement searches the data source for the employee ID in each record. If the ID is not in the data source, the request rejects the record. If the ID is in the data source, the request replaces the DEPARTMENT and CURR_SAL values in the data source with the values on the record.
  3. The DATA statement indicates that the data is contained in the data source EMPDEPT. EMPDEPT is the ddname to which the data file is allocated, and can be different from the system file name.
  4. The END statement completes the request and initiates processing.

Deleting Data From a Data Source

This sample request deletes information on employees from the data source. When you run the request, it prompts you for an employee ID. When you enter the ID, it deletes all information relating to that employee from the data source.

    MODIFY FILE EMPLOYEE  
1.  PROMPT EMP_ID  
2.  MATCH EMP_ID
       ON MATCH DELETE
       ON NOMATCH REJECT  
3.  DATA

The parts of the request are as follows:

  1. The PROMPT statement indicates that the request will prompt you for the employee's ID.
  2. The MATCH statement searches for the employee ID in the data source. If the ID is in the data source, the request deletes all information relating to the employee from the data source.
  3. The DATA statement begins prompting for data.

Information Builders