How to Link Between PLKO and PLPO for Routine in SAP

calendar 1231038 1280 e1458046112993

Link between PLKO and PLPO for Routine in SAP will be explain in this post with the definition of each tables involved and a sample ABAP Code to retrieve for a Production Version the Routine.

SAP Routines Tables

Let first introduce the SAP Tables used for Production:

TableSAP Routine Tables
PLKOTask list – header
PLPOTask list – operation/activity
PLMZAllocation of bill of material items to operations
PLASTask list – selection of operations/activities
PLABRelationships
PLAFPlanned order
PLFHTask list – production resources/tools
PLFLTask list – sequences
PLFTProcess Instructions
PLFVPI Characteristics/Sub-Operation Parameter Values
PLKVView of planned order header data
PLKZTask list main header
PLMKInspection plan characteristics
PLMWMAPL-Dependent Charac. Specifications (Inspection Plan)
PLPHCAPP Sub-operations
PLPBLong-term planning Independent requirements versions
PLPWIndex of the production/delivery plant in the planned order
PLSRScheduling results
PLSTStatus table for planned order processing
PLZURouting data for group

The next step is how to link between theses SAP main tables in SAP PP.

Main Keys fields for

In order to figure out the Link Between PLKO and PLPO, it is important to know the Main keys fields for are:

Key FieldsSAP Routines Tables Key Fields
PLNTYTask List Type Number (for orders from AFKO, for notifications from
PLNNRGroup (for orders from AFKO, for notifications from QMIH)
PLNALGroup Counter (for orders from AFKO, for notifications from QMIH)

Link between PLKO and PLPO

This section will cover the relationship between PLPO and PLKO.
The link between PLKO : Routine Header and PLPO Routine Post is done in the table PLAS.

An example of SAP Select how to retrieve PLAS : Link between PLPO and PLKO

*----------------------------------------------------*
* READ PLAS
*----------------------------------------------------*
IF NOT lt_plko[] IS INITIAL.
  SELECT * FROM plas INTO TABLE lt_plas
   FOR ALL ENTRIES IN lt_plko
   WHERE plnty = lt_plko-plnty
     AND plnnr = lt_plko-plnnr
     AND plnal = lt_plko-plnal
     AND loekz NE 'X'.

  DELETE ADJACENT DUPLICATES FROM lt_plas COMPARING ALL FIELDS.
ENDIF.

An example SAP Select to retrieve the PLPO with the PLAS-link to PLKO.

*----------------------------------------------------*
* READ PLPO
*----------------------------------------------------*
IF NOT lt_plas[] IS INITIAL.
  SELECT * FROM plpo INTO TABLE lt_plpo
    FOR ALL ENTRIES IN lt_plas
    WHERE plnty = lt_plas-plnty
      AND plnnr = lt_plas-plnnr
      AND plnkn = lt_plas-plnkn
      AND zaehl = lt_plas-zaehl.
  DELETE ADJACENT DUPLICATES FROM lt_plpo COMPARING ALL FIELDS.
ENDIF.

An ABAP sample code to retrieve the different link between PLKO and PLPO using PLAS can be :

READ TABLE lt_plko INTO ls_plko
    WITH KEY plnnr = IV_plnnr " Input 
             plnty = IV_plnty " Input .
IF sy-subrc = 0 .
" write your ABAP Custom Logic 
ENDIF.


" LINK BETWEEN PLKO AND PLPO -> PLAS
LOOP AT lt_plas INTO ls_plas WHERE plnnr = ls_plko-plnnr
                               AND plnty = ls_plko-plnty.

  READ TABLE lt_plpo INTO ls_plpo
   WITH KEY plnty = ls_plas-plnty
            plnnr = ls_plas-plnnr
            plnkn = ls_plas-plnkn
            zaehl = ls_plas-zaehl.
  IF sy-subrc = 0 .
  " CUSTOM LOGIC HERE
  ENDIF.
ENDLOOP

Link Between PLKO and PLMZ

PLPO is the SAP Table Routine lines and PLMZ Table stores the relationship between the Routine line and the BOM Component.

*----------------------------------------------------*
* READ PLMZ
*----------------------------------------------------*
IF NOT lt_plpo[] IS INITIAL.
 SELECT * FROM plmz INTO TABLE lt_plmz
  FOR ALL ENTRIES IN lt_plpo
   WHERE plnty = lt_plpo-plnty
     AND plnnr = lt_plpo-plnnr
     AND loekz NE 'X'
     AND plnkn = lt_plpo-plnkn.
  DELETE ADJACENT DUPLICATES FROM lt_plmz COMPARING ALL FIELDS.
ENDIF.

LOOP AT lt_plmz INTO ls_plmz WHERE plnnr = ls_plko-plnnr
                               AND plnty = ls_plko-plnty.

  READ TABLE lt_plpo INTO ls_plpo_2
    WITH KEY plnty = ls_plmz-plnty
             plnnr = ls_plmz-plnnr
             plnkn = ls_plmz-plnkn.
  IF SY-SUBRC = 0.
  ENDIF.
ENDLOOP

PLPO Table in SAP, PLKO Table in SAP, PLPO & PLKO Link, PLOK Task List