Previous Topic: Storing a Bill-of-Materials StructureNext Topic: Locking Records


Retrieving a Bill-of-Materials Structure

A bill-of-materials structure can contain a variable number of levels. Tracing all records under a given record (for example, finding a manager and all subordinates, and all of their subordinates, and so on) is called an explosion of the structure for that record. Tracing all records above a given record (for example, finding an employee and manager, and the manager's manager, and so on) is called an implosion of the structure for that record.

To perform a multilevel explosion or implosion, you must maintain a stack of db-keys in order to reestablish the appropriate currencies.

Steps to Retrieve One Bill-of-Materials Level

To retrieve a manager and one level of employees, perform the following steps:

  1. Retrieve the manager's EMPLOYEE record:
    MOVE 15 TO EMP-ID-0415.
    OBTAIN CALC EMPLOYEE.
    
  2. Retrieve the first STRUCTURE record in the MANAGES set:
    FIND NEXT STRUCTURE WITHIN MANAGES.
    
  3. Because REPORTS-TO is defined as OM, you must test for set membership:
    IF NOT REPORTS-TO MEMBER
       GO TO A100-EXIT.
    
  4. Retrieve the owner EMPLOYEE record in the REPORTS-TO set:
    OBTAIN OWNER WITHIN REPORTS-TO.
    
  5. FIND the current STRUCTURE record to reestablish the original currency within the MANAGES set:
    FIND CURRENT STRUCTURE.
    
  6. Retrieve the next STRUCTURE record in the MANAGES set:
    FIND NEXT STRUCTURE WITHIN MANAGES.
    

    Perform steps 3 through 6 iteratively until step 6 returns a status of 0307 (DB-END-OF-SET).

Example of One Bill-of-Materials Level

The figure below shows the relationship between manager and employees by showing all the employees managed by employee 15.

Steps to Retrieve Additional Levels

To retrieve an EMPLOYEE record, its manager's EMPLOYEE record, its manager's manager, and so on, perform the following steps:

  1. Retrieve the specified EMPLOYEE record:
    MOVE 91 TO EMP-ID-0415.
    OBTAIN CALC EMPLOYEE.
    
  2. Retrieve the STRUCTURE record in the REPORTS-TO set:
    FIND NEXT STRUCTURE WITHIN REPORTS-TO.
    IF ERROR-STATUS = '0307'
       GO TO A100-EXIT.
    
  3. Optionally, test the junction record for predetermined criteria (for example, if you only want managers for a specific project). Testing for selection criteria in the junction record can prevent looping if there are any circular structures defined.
  4. Retrieve the owner EMPLOYEE record in the MANAGES set:
    OBTAIN OWNER EMPLOYEE WITHIN MANAGES.
    

    Perform steps 2 through 4 iteratively until step 2 returns a status of 0307, indicating that the REPORTS-TO set is empty.

Example of Retrieving Additional Levels

The figure below shows the relationship between an employee and all managers on the P2 project by showing the hierarchy of managers above EMPLOYEE 91 on the project.