Get all the Details of a Routing Group regardless of Change Requests

Jimbo's picture

Routings are an odd object within SAP in that changes don't necessarily delete records from the tables. Removing an operation with a change number causes the operation to stop appearing after the effective date of the change number, but the record remains in the table PLPO table.

The CARO_ROUTING_READ function can be used to populate internal tables with all the details of a Routing based on an effective date. This eliminates the need to compare records in the associated tables with Change Masters to determine which are active and which are obsolete.

For this example an LSMW object is created to delete existing QM operations from Routings. The code first identifies all of the operations on the standard sequence (PLNFL equals zero) and then flags the QM operations for deletion using a BDC.

Creating the recording is the easiest part. Add a QM operation to a random Routing. Then, in recording mode, open the routing with the change number, select the new QM operation, delete it and save the routing. A great explanation of how to add selection boxes to a recording is available in this whitepaper.
Delete selected operations recording explained.

Next, create the variables in the Global Definitions and Declarations section. These internal tables and variables are used to store the information from the existing routing during processing.

parameters: p_Verbos as checkbox, p_Break as checkbox.
 ltOPR type standard table of CAPP_OPR initial size 0,
 lOPR like CAPP_OPR,
 nOperation type i.

The effective date, Routing type and Routing group are enough to coax the desired information related to the Routing from SAP. In this case only the internal table related to operations is populated as the others are not used.

lOPR-DATUV = sy-datum.
shift lOPR-PLNAL right deleting trailing space.
overlay lOPR-PLNAL with '00'.
          DATE_FROM          = lOPR-DATUV "Reference time range
          PLNTY              = lOPR-plNty
          PLNNR              = lOPR-PLNNR "Reference  Routing
          PLNAL              = lOPR-PLNAL "Reference Routing
          OPR_TAB            = ltOPR
          NOT_FOUND          = 1
          REF_NOT_EXP        = 2
          NOT_VALID          = 3
          OTHERS             = 4.
if sy-subrc ne 0.
  write: / TQMR-PLNNR, TQMR-PLNAL, 'Invalid routing.'.

The operations are ordered in the internal table by an internal number understood only by SAP. Sorting the operations by the operation number or VORNR is an easy task.

sort ltOPR by VORNR.

Now the selection flags are checked according to the filter. If the P_VERBOS parameter is checked then the conversion log contains information about what operations are to be deleted.

move 0 to nOperation.
loop at ltOPR into lOPR where PLNFL eq 0.
  add 1 to nOperation.
  if lOPR-VORNR ge 30 and lOPR-VORNR le 49.
    perform SetFlag using nOperation.
    if p_verbos eq 'X'.
      write: / TQMR-PLNNR, TQMR-PLNAL, lOPR-VORNR color 7,
       lOPR-STEUS, lOPR-LTXA1.

Routings without QM operations to be deleted are skipped.

if  CA02D-FLG_SEL_01 ne 'X'
and CA02D-FLG_SEL_02 ne 'X'
and CA02D-FLG_SEL_03 ne 'X'
and CA02D-FLG_SEL_04 ne 'X'
and CA02D-FLG_SEL_05 ne 'X'
and CA02D-FLG_SEL_06 ne 'X'
and CA02D-FLG_SEL_07 ne 'X'
and CA02D-FLG_SEL_08 ne 'X'
and CA02D-FLG_SEL_09 ne 'X'.
  if p_verbos eq 'X'.
    write: / TQMR-PLNNR, TQMR-PLNAL, 'No QM operations.' color 3.
  skip_transaction. "No records to delete.

Finally a form that checks selection flags based on a number is added to the Form Routines section. The flag associated with the parameter lvOperation is checked.

form SetFlag using lvOperation.
  case lvOperation.
    when 1. CA02D-FLG_SEL_01 = 'X'.
    when 2. CA02D-FLG_SEL_02 = 'X'.
    when 3. CA02D-FLG_SEL_03 = 'X'.
    when 4. CA02D-FLG_SEL_04 = 'X'.
    when 5. CA02D-FLG_SEL_05 = 'X'.
    when 6. CA02D-FLG_SEL_06 = 'X'.
    when 7. CA02D-FLG_SEL_07 = 'X'.
    when 8. CA02D-FLG_SEL_08 = 'X'.
    when 9. CA02D-FLG_SEL_09 = 'X'.

The recording follows the selection screen with a click on the delete button and then on the Save button. The rest is validation.
Delete selected operations.

Programming Language: