How to link STKO and STPO for BOM in SAP

pieces of the puzzle 592779 1280

How to link STKO and STPO : Find the link between STKO and STPO is a common requirement in SAP PP for example. This post will guide through the SAP Tables Diagram for SAP BOM.

SAP BOM Tables: Header, items and links

The main SAP tables involved in this topic will be

  • STKO?SAP BOM Header
  • STPO?SAP BOM Items
  • STAS: SAP?BOMs – Item Selection

You can also, just use the following join without using the STAS link Table.

? ? ? ? STKO-STLTY = STPO-STLTY
AND STKO-STLNR = STPO-STLNR

Check SAP BOM Overview for details or Bill of Material (BOM)?.

Here an example how to retrieve Data with a sample ABAP Select code

READ SAP BOM Header Table

Read Data for BOM Header STKO from a SAP Production Version:

*----------------------------------------------------*
* READ STKO
*----------------------------------------------------*
IF NOT lt_mast[] IS INITIAL.
  SELECT * FROM stko INTO TABLE lt_stko
   WHERE stlnr = IV_stlnr
     AND stlal = IV_stlal.
  
  DELETE ADJACENT DUPLICATES FROM lt_stko COMPARING ALL FIELDS.
ENDIF.

READ SAP BOM LINK PLAS Table

Read the different link STAS between BOM header STKO and BOM components STPO.

*----------------------------------------------------*
* READ STAS
*----------------------------------------------------*
IF NOT lt_stko[] IS INITIAL.
SELECT * FROM stas INTO TABLE lt_stas
FOR ALL ENTRIES IN lt_stko
WHERE stlty = lt_stko-stlty
AND stlnr = lt_stko-stlnr
AND stlal = lt_stko-stlal.
DELETE ADJACENT DUPLICATES FROM lt_stas COMPARING ALL FIELDS.
ENDIF.

READ SAP BOM Component STPO

Read the BOM Components STPO using the link from STAS

*----------------------------------------------------*
* READ STPO
*----------------------------------------------------*
IF NOT lt_stas[] IS INITIAL.
   SELECT * FROM stpo INTO TABLE lt_stpo
     FOR ALL ENTRIES IN lt_stas
     WHERE stlty = lt_stas-stlty
       AND stlnr = lt_stas-stlnr
       AND stlkn = lt_stas-stlkn.
   
   DELETE ADJACENT DUPLICATES FROM lt_stpo COMPARING ALL FIELDS.
   SORT lt_stpo BY posnr DESCENDING.
ENDIF.

How to link STKO and STPO Sample Code

Here a sample ABAP code to retrieve the SAP BOM component used for Production version

READ TABLE lt_stko INTO ls_stko
  WITH KEY stlnr = ls_mast-stlnr
          stlal = ls_mast-stlal.
IF SY-SUBRC = 0 .
    LOOP AT lt_stpo INTO ls_stpo
      WHERE stlty = ls_stko-stlty
        AND stlnr = ls_stko-stlnr.
    ENDLOOP.
ENDIF.

STPO Table in SAP, STKO Table in SAP, STPO BOM Component, STKO BOM