Work Center in Routing - Search through all the routing for the material and component allocation used

REPORT XXXXX
       LINE-SIZE 170 NO STANDARD PAGE HEADING LINE-COUNT 058(001).
*
*  Author by  : SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips
*                https://www.gotothings.com
*
TABLES: PLPO,     "Task list - operation/activity
        KAZY,            "Interval of Available Capacity
        CRHD,            "Work Center Header
        CRTX,             "Text for the Work Center or Production Resource/Tool
        MAPL,             "Allocation of task lists to materials
        PLMZ,              "Allocation of bill of material items to operations
        STPO,              "BOM Item
        MARC.             "Material Master: C Segment

SELECT-OPTIONS: S_ENDDA FOR CRHD-ENDDA    DEFAULT SY-DATUM  OPTION GE,
                S_WERKS FOR PLPO-WERKS    DEFAULT 'XX',
                S_ARBPL FOR CRHD-ARBPL,
                S_KTEXT FOR CRTX-KTEXT(9) DEFAULT 'TEXT TEXT'.
PARAMETERS P_COMP AS CHECKBOX.

DATA: BEGIN OF ITAB-PLPO OCCURS 0,
      ARBPL LIKE CRHD-ARBPL,
      KTEXT LIKE CRTX-KTEXT(9),
      MATNR LIKE MAPL-MATNR,
      BMSCH LIKE PLPO-BMSCH,
      VGW01 LIKE PLPO-VGW01,
      VGE01 LIKE PLPO-VGE01,
      LAR01 LIKE PLPO-LAR01,
      VGW02 LIKE PLPO-VGW02,
      VGE02 LIKE PLPO-VGE02,
      LAR02 LIKE PLPO-LAR02,
      VGW03 LIKE PLPO-VGW03,
      VGE03 LIKE PLPO-VGE03,
      LAR03 LIKE PLPO-LAR03,
      VGW04 LIKE PLPO-VGW04,
      VGE04 LIKE PLPO-VGE04,
      LAR04 LIKE PLPO-LAR04,
      WERKS LIKE PLPO-WERKS,
      DATUV LIKE PLPO-DATUV,
      ENDDA LIKE CRHD-ENDDA,
      LOEKZ LIKE PLPO-LOEKZ,
      PLNTY LIKE PLPO-PLNTY,
      PLNNR LIKE PLPO-PLNNR,
      END OF ITAB-PLPO.

SELECT * FROM PLPO WHERE LOEKZ = SPACE.
   CHECK S_WERKS.

   CLEAR CRHD.
   SELECT SINGLE * FROM CRHD WHERE OBJID = PLPO-ARBID
                               AND OBJTY = 'A'.
   CHECK S_ARBPL.
   CHECK S_ENDDA.

   CLEAR CRTX.
   SELECT SINGLE * FROM CRTX WHERE OBJTY = 'A'
                               AND OBJID = PLPO-ARBID
                               AND SPRAS = 'E'.
   CHECK S_KTEXT.

   CLEAR KAZY.
   SELECT SINGLE * FROM KAZY WHERE KAPID = PLPO-ARBID.

   CLEAR MAPL.
   SELECT SINGLE * FROM MAPL WHERE WERKS = PLPO-WERKS
                               AND PLNTY = PLPO-PLNTY
                               AND PLNNR = PLPO-PLNNR.
   CHECK SY-SUBRC = 0.

   CLEAR MARC.
   SELECT SINGLE * FROM MARC WHERE MATNR = MAPL-MATNR
                               AND WERKS = PLPO-WERKS.
   CHECK MARC-LVORM = SPACE.

   ITAB-PLPO-ARBPL = CRHD-ARBPL.
   ITAB-PLPO-KTEXT = CRTX-KTEXT(9).
   ITAB-PLPO-MATNR = MAPL-MATNR.
   ITAB-PLPO-BMSCH = PLPO-BMSCH.
   ITAB-PLPO-VGW01 = PLPO-VGW01.
   ITAB-PLPO-VGE01 = PLPO-VGE01.
   ITAB-PLPO-LAR01 = PLPO-LAR01.
   ITAB-PLPO-VGW02 = PLPO-VGW02.
   ITAB-PLPO-VGE02 = PLPO-VGE02.
   ITAB-PLPO-LAR02 = PLPO-LAR02.
   ITAB-PLPO-VGW03 = PLPO-VGW03.
   ITAB-PLPO-VGE03 = PLPO-VGE03.
   ITAB-PLPO-LAR03 = PLPO-LAR03.
   ITAB-PLPO-VGW04 = PLPO-VGW04.
   ITAB-PLPO-VGE04 = PLPO-VGE04.
   ITAB-PLPO-LAR04 = PLPO-LAR04.
   ITAB-PLPO-WERKS = PLPO-WERKS.
   ITAB-PLPO-DATUV = PLPO-DATUV.
   ITAB-PLPO-ENDDA = CRHD-ENDDA.
   ITAB-PLPO-LOEKZ = PLPO-LOEKZ.
   ITAB-PLPO-PLNTY = PLPO-PLNTY.
   ITAB-PLPO-PLNNR = PLPO-PLNNR.

   APPEND ITAB-PLPO.
   CLEAR  ITAB-PLPO.

ENDSELECT.

DELETE ADJACENT DUPLICATES FROM ITAB-PLPO.

SORT ITAB-PLPO BY ARBPL MATNR.
LOOP AT ITAB-PLPO.
   WRITE: / ITAB-PLPO-ARBPL UNDER 'Work Center',
            ITAB-PLPO-KTEXT,
            ITAB-PLPO-MATNR UNDER 'Material',
       (12) ITAB-PLPO-BMSCH UNDER 'Base Quantity',
        (6) ITAB-PLPO-VGW01,
        (3) ITAB-PLPO-VGE01,
        (6) ITAB-PLPO-LAR01,
        (6) ITAB-PLPO-VGW02,
        (3) ITAB-PLPO-VGE02,
        (6) ITAB-PLPO-LAR02,
        (6) ITAB-PLPO-VGW03 UNDER 'Activities',
        (3) ITAB-PLPO-VGE03,
        (6) ITAB-PLPO-LAR03,
        (6) ITAB-PLPO-VGW04,
        (3) ITAB-PLPO-VGE04,
        (6) ITAB-PLPO-LAR04,
            ITAB-PLPO-WERKS UNDER 'Plnt',
            ITAB-PLPO-DATUV UNDER 'From Date',
            ITAB-PLPO-ENDDA UNDER 'To   Date',
            ITAB-PLPO-LOEKZ.

   IF P_COMP = 'X'.
      CLEAR PLMZ.
      SELECT * FROM PLMZ WHERE PLNTY = ITAB-PLPO-PLNTY
                           AND PLNNR = ITAB-PLPO-PLNNR.
         CLEAR STPO.
         SELECT * FROM STPO WHERE STLTY = PLMZ-STLTY
                              AND STLNR = PLMZ-STLNR
                              AND STLKN = PLMZ-STLKN.
             WRITE: / STPO-IDNRK UNDER 'Material',
                 (12) STPO-MENGE UNDER 'Base Quantity',
                      STPO-MEINS.
         ENDSELECT.
      ENDSELECT.
   ENDIF.
ENDLOOP.

TOP-OF-PAGE.
   FORMAT COLOR COL_TOTAL.
   WRITE: / SY-DATUM, SY-UZEIT, SY-REPID, SY-UNAME,
        60 'Work Center in Routing',
       120 SY-PAGNO.
   SKIP.
   WRITE: /1  'Work Center',
           22 'Material',
           42 'Base Quantity',
          100 'Activities',
          140 'Plnt',
          145 'From Date',
          156 'To   Date'.
    ULINE.

More Function Module
Functions / SAP Script / ALV

Tables
Database Table

ABAP Books List
ABAP/4 Certification, Programming, Smartforms, Sapscripts and Object Oriented Programming Books

Smart Forms
SAP Smartforms

ABAP Menu:
ABAP Example Hints and Tips

Return to Index:-
SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.