How to link STKO and STPO for BOM in SAP

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)?.

Related Post

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

Share
Published by
John

Recent Posts

The Most Important SAP ISU Tables

SAP ISU Tables for Technical master data, for Billing Master Data, Billing and invoicing Tables?…

December 22, 2020

SAP Fiori 3 UX and Design of SAP Fiori Apps for SAP S/4HANA, SAP TechEd Lecture

SAP Fiori 3 UX and Design of SAP Fiori Apps for SAP S/4HANA, SAP TechEd…

November 18, 2020

The Main SAP Dunning Transaction Codes

Dunning is the business practice of informing a customer of past due payment. Dunning letters…

November 28, 2019

SAP Accounts Payable Tcodes & Accounts Receivable Tcodes ( SAP AP Tcodes & SAP AR Tcodes)

SAP AP Tcodes & SAP AR Tcodes: House Banks Tcodes, Advance Payments or Down Payments,…

August 1, 2019

The Most Important SAP Payment Terms Tables (ZTERM, Text…)

What are the main SAP Payment Terms Tables ? What are the related Tables in…

October 21, 2018

The most Important SAP Work Center Tables in SAP PP

Work center consists of master data related to routing of products. It contains data related…

October 21, 2018