Previous Topic: Dynamically Modifying Video Properties in Online ProceduresNext Topic: Design for Ease of Use


Restart in Batch Procedures

The following illustration represents the Dialog Flow Diagram for a batch process-implementing procedure named Batch Maintenance. This procedure handles checkpointing and restart at last checkpoint.

Dialog Flow Diagram - Batch Maintenance

Dialog Flow Diagram - Batch Maintenance

A fully commented Procedure Action Diagram for the procedure Batch Maintenance is represented in the following sample code.

Procedure Action Diagram - Batch Maintenance (Part 1)

BATCH_MAINTENANCE
     IMPORTS:   Work View  returned_from_transfer work
     EXPORTS:   Work View  sent_through_transfer work
     LOCALS:    Work View  restart work
                Work View  target work
                Work View  returned work
                Work View  returned customer
                Work View  commit ief_supplied
                Work View  message work
EXIT STATE IS requested_operation_complete
NOTE 
     ... FIRST, check to see if this is a RESTARTED procedure. If the number 
         written to the restart file by WRITE RESTART RECORD in a previous 
         execution is greater than zero, it means that BATCH MAINTENANCE 
         previously failed in mid-execution.
IF returned from transfer work restart_count IS EQUAL TO 0
USE get_restart_number
     WHICH EXPORTS: Work View target_work
NOTE
     Get RESTART NUMBER is an external action block which reads the restart    
     file (written by WRITE RESTART NUMBER at the end of the action block). It    
     passes back a value of zero if the restart file is empty.
NOTE
     GET TRANSACTION is an external action block that reads a sequential file 
     of CUSTOMERS. It returns CUSTOMER details (in RETURNED CUSTOMER) and a   
     request code (in RETURNED WORK).
     Possible values of REQUEST TYPE are:
     - A=Add (CREATE) this customer
     - C=Change (UPDATE) this customer
     - D=Delete this customer
     - E=End of input file reached
USE get_transaction
     WHICH EXPORTS: Entity View returned customer
                    Work View returned work
NOTE
     ... NEXT. If we are restarted, spin through the transaction
         file until you get to the first one that was not processed
         properly the first time.

Procedure Action Diagram for Batch Maintenance (Part 2)

WHILE restart work restart_count IS LESS THAN target work
     restart count
AND returned work request_type IS NOT EQUAL TO E
SET restart work restart_count TO restart work
     restart_count + 1
USE get transaction
     WHICH EXPORTS: Work View returned work
                    Entity View returned customer
NOTE
     ... NOW, you must be positioned at the first customer transaction not yet 
         processed. If this is not a restarted execution, that will be the 
         first transaction on the input file; if it IS a restart, it will be 
         the transaction right after the last one for which a commit took 
         place.
WHILE commit_ief_supplied count IS LESS THAN 100
AND returned work request_type IS NOT EQUAL TO E
EXIT STATE IS requested_operation_complete
SET message work result TO OPERATION COMPLETED
NOTE
     CREATE CUSTOMER, UPDATE CUSTOMER, and DELETE CUSTOMER are Elementary 
     Processes for which Process Action Diagrams were created during BAA.
CASE OF returned work request_type
CASE A
USE create_customer
     WHICH IMPORTS: Entity View returned customer
          IF EXIT STATE IS NOT EQUAL TO
               requested_operation_complete
          SET message work result TO NOT ADDED
CASE C
USE update customer
     WHICH IMPORTS: Entity View returned customer
          IF EXIT STATE IS NOT EQUAL TO
               requested_operation_complete
          SET message work result TO NOT CHANGED

Procedure Action Diagram for Batch Maintenance (Part 3)

CASE D
USE delete customer
     WHICH IMPORTS: Entity View returned customer
          IF EXIT STATE IS NOT EQUAL TO
               requested_operation_complete
          SET message work result TO “NOT DELETED”
NOTE
     WRITE MESSAGE is an external action block that writes a result message to 
     a message file it forms the message based on REQUEST TYPE (in RETURNED 
     WORK), the details in RETURNED CUSTOMER and RESULT (in MESSAGE WORK).
USE write message
     WHICH IMPORTS: Entity View returned customer
                    Work View message work
                    Work View returned work

SET commit_ief_supplied count TO commit_ief_supplied_count +1
USE get_transaction
     WHICH EXPORTS: Entity View returned customer
                    Work View returned work
     IF returned work request type IS EQUAL TO e
     SET sent_through_transfer work restart_count TO 0
     ELSE
     SET sent_through_transfer_work restart_count TO
          returned_from_transfer work restart_count +
          commit_ief_supplied_count + restart work
          restart_count
EXIT STATE IS process_commit
SET target work restart_count TO sent_through_transfer
     work restart_count
NOTE
     WRITE RESTART NUMBER is an external action block that records the number 
     of input transactions for which database updates have been committed.
USE write_restart_number
     WHICH IMPORTS: Work View target work
...
NOTE
     WRITE RESTART NUMBER is an external action block that records the number 
     of input transactions for which database updates have been committed.
USE write_restart_number
     WHICH IMPORTS: Work View target work

The views used by Batch Maintenance are presented in the following sample code. Note that the technique for using external action blocks for sequential file processing is also illustrated in these samples.

View Definitions for Batch Maintenance

Import View
----------------------------------------------------------------------------
View RETURNED_FROM_TRANSFER of work group WORK Attributes:
     RESTART_COUNT
----------------------------------------------------------------------------
Export Views
----------------------------------------------------------------------------
View SENT_THROUGH_TRANSFER of work group WORK Attributes:
     RESTART_COUNT
----------------------------------------------------------------------------

Local Views
----------------------------------------------------------------------------
View RESTART of work group WORK Attributes:
     RESTART_COUNT

View Target of work group WORK Attributes:
     RESTART_COUNT

View RETURNED of work group WORK Attributes:
     REQUEST_TYPE

View RETURNED of entity CUSTOMER Attributes:
     NUMBER
     NAME
     STATUS
     CREDIT_RATING
     BILL_TO_ADDRESS_LINE_1
     BILL_TO_ADDRESS_LINE_2
     BILL_TO_ADDRESS_LINE_3
     BILL_TO_CITY
     BILL_TO_STATE
     BILL_TO_ZIP

View COMMIT of work group COMPOSER_SUPPLIED Attributes:
     COUNT

View MESSAGE of work group WORK Attributes
     RESULT

More information:

Designing the Data Structure