Previous Topic: EXCEXTFUN User Function

Next Topic: EXCINTFUN User Function

Using Batch Processing

The following information is an example of how to use an EXCEXTFUN to process records using a batch process:

Assume the following:

Use the RTVOBJ function, Process All Unpaid Orders, to process the records in the Order file. The access path attached to the RTVOBJ determines the order in which the records on the order file are read.

Assume that the Retrieval access path of the Order file is keyed by Order Number. It would not be advisable to use this access path for the RTVOBJ as there is no need to process all the Orders in the Order file.

Consequently, you can create and use alternative access paths such as the following:

  1. A Retrieval (RTV) access path with select or omit criteria selecting only Unpaid Orders.
  2. A Resequence (RSQ) access path keyed by Order status and Customer code.

The second access path is preferable because a restrictor parameter of Order Status with a supplied condition EQ Unpaid for the RTVOBJ has the equivalent select or omit effect on the records retrieved.

Furthermore, having the Customer code as the secondary key presents Unpaid Order records for each Customer in sequence. This allows the change of Customer code to indicate the end of a list of Order records belonging to a customer.

This allows the total unpaid value for a Customer to be accumulated and the corresponding Customer record updated only when all Unpaid Orders for that Customer are processed resulting in a significant reduction in database I/O.

The logic required in the RTVOBJ, Process All Unpaid Orders, is as follows:

.> USER: Process Data record ..— ...-CASE .. |-DB1.Customer code EQ WRK. Saved Customer code .. | Continue to accumulate ... ..| WRK.Cust. value unpaid Orders = WRK.Cust. value unpaid orders .. | + DB1. Order total value .. |-*OTHERWISE .. | Update Cust.unpaid value - Customer * .. | | Customer code = WRK.Saved Customer code .. | B Cust. value unpaid Orders = WRK.Cust. value unpaid Orders .. | Save new customer code ... .. | WRK.Saved Customer code = DB1.Customer code .. | Reset accumulator ... .. | WRK.Cust. value unpaid Orders = DB1.Order total value .. '-ENDCASE .. Set Order status to ‘P’ (Still unpaid but Customer updated) ... .. Change Order - Order * .. | Order number = DB1.Order number .. | Customer code = DB1.Customer code .. | Order status = CND.Unpaid(Customer updated) .. | Order total value = DB1.Order total value .'—

Since the value for a customer is only updated for a change in Customer, the last customer record must be accounted for as follows:

. USER: Exit processing ..— .. Update last Customer ... .. Update Cust. unpaid value - Customer * .. I Customer code = WRK.Saved Customer code .. B Cust. value unpaid orders = WRK.Cust. value unpaid order .'—

The CHGOBJ Change Order is the default CHGOBJ for the function with no additional user logic.

The CHGOBJ Update Cust. unpaid value has the following user logic to ensure that the total value is accumulated onto what is already present for the customer on file as follows:

> USER: Processing after Data read .— . Add to Customers unpaid value ... . PAR. Cust. value unpaid Orders = PAR.Cust. value unpaid Orders . + DB1.Cust. value unpaid Orders '—

Once the functions and logic have been defined, the RTVOBJ, Process All Unpaid Orders, can be embedded within an EXCEXTFUN Batch process, Unpaid Orders as follows:

> Batch process unpaid orders .— . Restrict to process only UNPAID orders (i.e. Order status = 'U') ... . Process all unpaid orders - Orders * . I RST Order status= CND.Unpaid '—

After generating and compiling the EXCEXTFUN, it can be executed in batch using the i OS SBMJOB or equivalent command. You can choose to execute this command from another function, such as a PMTRCD acting as a menu, by using the Execute Message function to submit the function to batch.

For more information about: