SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

BOM multi-level detail report



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> PP
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sat Sep 29, 2007 4:04 pm    Post subject: BOM multi-level detail report Reply with quote

You need to use MAST ,STKO,STPO Table
Try to use FM : CS_BOM_EXPL_MAT_V2
Here is the report similar to CS12 .

Code:

REPORT zppr_bom_infol_report NO STANDARD PAGE HEADING
LINE-SIZE 160
LINE-COUNT 60.

*======================================================================*
* *
* Program Name : ZPPR_BOM_INFOL_REPORT
*----------------------------------------------------------------------*
* Table definition *
*----------------------------------------------------------------------*

TABLES: mast,
stko,
stpo,
t418,
makt.

* TYPE - POOLS
TYPE-POOLS: slis.

* Constants
CONSTANTS : c_tcode(4) TYPE c VALUE 'CS03',
gc_formname_top_of_page TYPE slis_formname
VALUE 'TOP_OF_PAGE'.

* Variables
DATA : v_maktx LIKE makt-maktx,
wa_stko LIKE stko.

DATA:
* Objekttyp 'Material'
otyp_mat(1) TYPE c VALUE '1',
ootyp_mat(1) TYPE c VALUE 'M',
* Objekttyp 'kein Objekt'
otyp_noo(1) TYPE c VALUE '2',
* Objekttyp 'Dokument'
otyp_doc(1) TYPE c VALUE '3',
* Objekttyp 'Klasse'
otyp_kla(1) TYPE c VALUE '4',
* Objekttyp 'Intramaterial'
otyp_ntm(1) TYPE c VALUE '5'.

* maximal anzeigbare Menge
DATA: max_num(7) TYPE p DECIMALS 3 VALUE '9999999999.999',
ueberl_kz(1) TYPE c VALUE '*',
min_num(7) TYPE p DECIMALS 3 VALUE '9999999999.999-',
b_flag(1) TYPE c VALUE 'X',
ecfld(250) TYPE c,
v_flag TYPE c.
* ALV Variables
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,
gs_layout TYPE slis_layout_alv,
gs_keyinfo TYPE slis_keyinfo_alv,
gt_sp_group TYPE slis_t_sp_group_alv,
gt_events TYPE slis_t_event.

DATA: g_repid LIKE sy-repid.
DATA: gt_list_top_of_page TYPE slis_t_listheader,
g_tabname_header TYPE slis_tabname,
g_tabname_item TYPE slis_tabname,
g_save(1) TYPE c,
gx_variant LIKE disvariant,
g_variant LIKE disvariant,
g_default(1) TYPE c,
g_exit(1) TYPE c.



*----------------------------------------------------------------------*
* Includes *
*----------------------------------------------------------------------*

INCLUDE <icon>.
INCLUDE <symbol>.

*----------------------------------------------------------------------*
* Internal Table Declaration *
*----------------------------------------------------------------------*

DATA: t_mast LIKE STANDARD TABLE OF mast WITH HEADER LINE.

*DATA: t_makt LIKE STANDARD TABLE OF makt WITH HEADER LINE.

* BOM Function module Related
DATA: t_matcat LIKE cscmat OCCURS 0 WITH HEADER LINE.

* Internal Table for Level by Level Function module
DATA: t_stb LIKE stpox OCCURS 0 WITH HEADER LINE.

* Get the Relevant data from FM
DATA: BEGIN OF hd_tab OCCURS 0,
stufe LIKE stpox-stufe,
vwegx LIKE stpox-vwegx,
END OF hd_tab.

* Final Output
DATA: BEGIN OF alv_stb OCCURS 0.
        INCLUDE STRUCTURE stpox_alv.
DATA: info(3) TYPE c,
END OF alv_stb.

DATA: BEGIN OF stb_orig.
        INCLUDE STRUCTURE stpox.
DATA: END OF stb_orig.

DATA: BEGIN OF stb_add.
        INCLUDE STRUCTURE stpol_add.
DATA: END OF stb_add.


* Internal Table for STPO


*-- BOM Line item
TYPES: BEGIN OF ty_stpo,
stlty TYPE stpo-stlty,
stlnr TYPE stpo-stlnr,
stlkn TYPE stpo-stlkn,
stpoz TYPE stpo-stpoz,
idnrk TYPE stpo-idnrk,
meins TYPE stpo-meins,
menge TYPE stpo-menge, "Component Qty
END OF ty_stpo.

DATA: t_stpo TYPE STANDARD TABLE OF ty_stpo WITH HEADER LINE.

*-- BOM Header
TYPES: BEGIN OF ty_stko,
stlty TYPE stko-stlty,
stlnr TYPE stko-stlnr,
stlal TYPE stko-stlal,
stkoz TYPE stko-stkoz,
bmein TYPE stko-bmein,
bmeng TYPE stko-bmeng,
END OF ty_stko.

DATA: t_stko TYPE STANDARD TABLE OF ty_stko WITH HEADER LINE .

DATA : t_makt LIKE makt OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF cl_clstab OCCURS 0,                          "YHG079407
class LIKE klah-class,                                      "YHG079407
klart LIKE klah-klart,                                      "YHG079407
chked LIKE csdata-xfeld,                                    "YHG079407
noobj LIKE csdata-xfeld,                                    "YHG079407
dsply LIKE csdata-xfeld,                                    "YHG079407
END OF cl_clstab.


*-- Header table
TYPES: BEGIN OF ty_main_material,
matnr TYPE mast-matnr, "Material
werks TYPE mast-werks, "Plant
maktx TYPE makt-maktx, "Description
stlal TYPE mast-stlal, "Alternative BOM
stlnr TYPE stko-stlnr, "BOM Number
bmein TYPE stko-bmein, "UOM
bmeng TYPE stko-bmeng, "Base Qty
expand(1) TYPE c, "Expanding Field
END OF ty_main_material.

DATA: t_main_material TYPE STANDARD TABLE OF ty_main_material WITH
HEADER LINE.

*-- Item (Component) Table
TYPES: BEGIN OF ty_item_material,
matnr TYPE mast-matnr, "Material
werks TYPE mast-werks, "Plant
idnrk TYPE stpo-idnrk, "Component (Material)
maktx TYPE makt-maktx, "Description
stlal TYPE mast-stlal, "Alternative BOM
stlnr TYPE stpo-stlnr, "BOM Number
meins TYPE stpo-meins, "UOM
menge TYPE stpo-menge, "Base Qty
END OF ty_item_material.

DATA: t_item_material TYPE STANDARD TABLE OF ty_item_material WITH
HEADER LINE.



*----------------------------------------------------------------------*
* Selection Screen *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_werks LIKE marc-werks DEFAULT '1000' OBLIGATORY.
SELECT-OPTIONS s_stlal FOR mast-stlal .
SELECT-OPTIONS s_stlan FOR mast-stlan DEFAULT '1'.

SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
SELECTION-SCREEN SKIP.
PARAMETERS: p_bomlst RADIOBUTTON GROUP g1 DEFAULT 'X'.
SELECT-OPTIONS s_matnr FOR mast-matnr.

SELECTION-SCREEN SKIP.
PARAMETERS: p_compon RADIOBUTTON GROUP g1.
SELECT-OPTIONS: s_idnrk FOR stpo-idnrk.
SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN END OF BLOCK b1.


SELECTION-SCREEN BEGIN OF BLOCK b03 WITH FRAME TITLE text-b03.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(40) text-005.
PARAMETERS: p_all RADIOBUTTON GROUP r1 DEFAULT 'X'.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(40) text-006.
PARAMETERS: p_one RADIOBUTTON GROUP r1 .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b03.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
PARAMETERS: p_vari LIKE disvariant-variant.
SELECTION-SCREEN END OF BLOCK b3.

*----------------------------------------------------------------------*
* At slection screen events *
*----------------------------------------------------------------------*
*-- Process on value request
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.
  PERFORM f4_for_variant.



*----------------------------------------------------------------------*
* Intitialisation
*----------------------------------------------------------------------*
INITIALIZATION.

  g_repid = sy-repid.
  g_tabname_header = 'T_MAIN_MATERIAL'.
  g_tabname_item = 'T_ITEM_MATERIAL'.
*-- define keyinformation
  CLEAR gs_keyinfo.
  gs_keyinfo-header01 = 'MATNR'.
  gs_keyinfo-item01 = 'MATNR'.


  PERFORM e03_eventtab_build USING gt_events[].
  PERFORM e04_comment_build USING gt_list_top_of_page[].
  PERFORM e07_sp_group_build USING gt_sp_group[].
  PERFORM e08_layout_build USING gs_layout.

* Set Options: save variants userspecific or general
  g_save = 'A'.
  PERFORM variant_init.
* Get default variant
  gx_variant = g_variant.
  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
       EXPORTING
            i_save     = g_save
       CHANGING
            cs_variant = gx_variant
       EXCEPTIONS
            not_found  = 2.
  IF sy-subrc = 0.
    p_vari = gx_variant-variant.
  ENDIF.


************************************************************************
**************** S T A R T - O F - S E L E C T I O N *******************
************************************************************************

START-OF-SELECTION.

  IF p_all = 'X'.

* Get the data from MAST and MAKT Table
    IF p_bomlst = 'X'.
* Get the data Based On Material #
      PERFORM get_data.
    ELSE.
* Get the data Based On Component
      PERFORM get_data_component.
    ENDIF.

  ELSE.
* Get the Single Level Report

*-- Moved the fiedl catalog here inorder to change the layout based on
*-- Selection
    PERFORM e01_fieldcat_init USING gt_fieldcat[].

    PERFORM select_data.


  ENDIF.

************************************************************************
************ E N D - O F - S E L E C T I O N *******************
************************************************************************

END-OF-SELECTION.

  IF p_one = 'X'.

    PERFORM alv.

  ENDIF.

* User Command
AT LINE-SELECTION.

* Interactive to CS03 Transaction
  CASE sy-ucomm.

    WHEN 'PICK' OR 'F2'.

      IF NOT alv_stb-idnrk IS INITIAL .
        IF NOT alv_stb-werks IS INITIAL.
          IF NOT alv_stb-objty IS INITIAL.

            SET PARAMETER ID 'MAT' FIELD alv_stb-idnrk.

            SET PARAMETER ID 'WRK' FIELD alv_stb-werks.

            SET PARAMETER ID 'CSV' FIELD alv_stb-objty.

            CALL TRANSACTION c_tcode AND SKIP FIRST SCREEN.
          ENDIF.
        ENDIF.
      ENDIF.
      CLEAR alv_stb.
  ENDCASE.



*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* Get data from MAST and MAKT Table
*----------------------------------------------------------------------*
FORM get_data.

  DATA : wa_lines TYPE sy-index.

  REFRESH : t_mast,
  t_stb,
  t_matcat,
  alv_stb.

  CLEAR : t_mast,
  t_stb,
  t_matcat,
  alv_stb.

* Get the data from MAST Table

* Get all the information from MAST - BOM Table
  SELECT * FROM mast INTO TABLE t_mast WHERE matnr IN s_matnr AND
  werks = p_werks AND
  stlan IN s_stlan AND
  stlal IN s_stlal.


  DESCRIBE TABLE t_mast LINES wa_lines.

  IF wa_lines IS INITIAL.
    WRITE:/2 'List contains no data'.
    STOP.
  ENDIF.

  LOOP AT t_mast.

    CLEAR : v_maktx.
* Start of change Seshu
* Reason - Remove the new page option
    IF sy-tabix NE 1.
      SKIP 1.
    ENDIF.
* End of Change Seshu

* Get the material Description
    SELECT SINGLE maktx FROM makt INTO v_maktx
    WHERE matnr = t_mast-matnr
    AND spras = 'E'.
* Get the material details from STKO Table
    SELECT SINGLE * FROM stko INTO wa_stko
    WHERE stlty = 'M'
    AND stlnr = t_mast-stlnr
    AND stlal = t_mast-stlal.

* Main Header for Each Material
    FORMAT COLOR 5 ON.
    WRITE:/2 'Material',20 'Material Description',65 'Alternative BOM',
    90 'Base Qty', 115 'Base Unit'.
    FORMAT COLOR 5 OFF.

    FORMAT COLOR 1 ON.

    WRITE:/2 t_mast-matnr,20 v_maktx,65 wa_stko-stlal, 85 wa_stko-bmeng,
    115 wa_stko-bmein.
    FORMAT COLOR 1 OFF.

* Use the Function Module and get the format level by level

    PERFORM get_level_level.

  ENDLOOP.



ENDFORM. " get_data

*----------------------------------------------------------------------*
* Top of page *
*----------------------------------------------------------------------*
TOP-OF-PAGE.

  PERFORM report_header .
*&---------------------------------------------------------------------*
*& Form report_header
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM report_header.

  NEW-PAGE LINE-SIZE 160 .

  FORMAT COLOR COL_HEADING INTENSIFIED ON.

  WRITE:/ sy-uline(160) .

*--- Write Company Name.
  PERFORM calc_col_and_write USING text-h00
  sy-linsz.

*--- Write Report Title.
  PERFORM calc_col_and_write USING sy-title
  sy-linsz.

*--- Write User Id, Date / Time, Program Id, Page etc.
  PERFORM write_other_hdr_details.

  WRITE:/ sy-uline(160) .


ENDFORM. " report_header
*&---------------------------------------------------------------------*
*& Form calc_col_and_write
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_TEXT_H00 text
* -->P_SY_LINSZ text
*----------------------------------------------------------------------*
FORM calc_col_and_write USING p_text
p_linsz.

  DATA: col1 TYPE i,
* col2 type i,
  len TYPE i,
  str TYPE i.

  str = strlen( p_text ).
  col1 = ( p_linsz / 2 ) - ( str / 2 ) .
  len = p_linsz - col1 - 2.

  WRITE: AT /1 '|'.
  WRITE: AT col1 p_text,
  AT sy-colno(len) space.
  WRITE AT 160 '|'.


ENDFORM. " calc_col_and_write
*&---------------------------------------------------------------------*
*& Form write_other_hdr_details
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM write_other_hdr_details.

  DATA: col1 TYPE i,
  col2 TYPE i,
  len TYPE i.

  col1 = 3.

  WRITE:/1 '|'.

  WRITE: AT col1 'UserId : ',
  sy-uname.
  len = sy-linsz - 1.
  WRITE AT sy-colno(len) space.
  col2 = sy-linsz - 18.
  WRITE: AT col2 'Date: ',
  sy-datum MM/DD/YYYY.
  WRITE: AT sy-linsz '|'.

  WRITE:/1 '|'.
  WRITE: AT col1 'ReportId: ',
  sy-repid.
  WRITE AT sy-colno(len) space.
  col2 = sy-linsz - 18.
  WRITE: AT col2 'Page: ',
  sy-pagno.
  WRITE: AT sy-linsz '|'.


ENDFORM. " write_other_hdr_details
*&---------------------------------------------------------------------*
*& Form get_data_component
*&---------------------------------------------------------------------*
* Get the data based on Component level
*----------------------------------------------------------------------*
FORM get_data_component.

  DATA wa_lines TYPE i.
*-- Get the BOM item details
  SELECT stlty stlnr stlkn stpoz idnrk meins menge
  FROM stpo
  INTO TABLE t_stpo
  WHERE idnrk IN s_idnrk.


  IF sy-subrc = 0.

    CLEAR wa_lines.
    DESCRIBE TABLE t_stpo LINES wa_lines.

    IF wa_lines > 0.
      SELECT stlty stlnr stlal stkoz bmein bmeng
      FROM stko
      INTO TABLE t_stko
      FOR ALL ENTRIES IN t_stpo
      WHERE stlnr = t_stpo-stlnr.

      CLEAR wa_lines.
      DELETE ADJACENT DUPLICATES FROM t_stko COMPARING ALL FIELDS.
      DESCRIBE TABLE t_stko LINES wa_lines.

      IF wa_lines > 0.
*-- Get the BOM item details
        SELECT * FROM mast INTO TABLE t_mast FOR ALL ENTRIES IN t_stko
        WHERE werks = p_werks AND
        stlnr = t_stko-stlnr
        AND stlal IN s_stlal.


      ENDIF.

    ENDIF.

  ELSE.
    WRITE:/2 'List contains no data'.
    STOP.
  ENDIF.


  LOOP AT t_mast.

    CLEAR : v_maktx.
* Start of change Seshu
* Reason - Remove the new page option
    IF sy-tabix NE 1.
      SKIP 1.
    ENDIF.
* End of change Seshu
* Get the material Description
    SELECT SINGLE maktx FROM makt INTO v_maktx
    WHERE matnr = t_mast-matnr
    AND spras = 'E'.
* Get the material details from STKO Table
    SELECT SINGLE * FROM stko INTO wa_stko
    WHERE stlty = 'M'
    AND stlnr = t_mast-stlnr
    AND stlal = t_mast-stlal.

* Main Header for Each Material
    FORMAT COLOR 5 ON.
    WRITE:/2 'Material',20 'Material Description',65 'Alternative BOM',
    90 'Base Qty', 115 'Base Unit'.
    FORMAT COLOR 5 OFF.

    FORMAT COLOR 1 ON.

    WRITE:/2 t_mast-matnr,20 v_maktx,65 wa_stko-stlal, 85 wa_stko-bmeng,
    115 wa_stko-bmein.
    FORMAT COLOR 1 OFF.

* Use the Function Module and get the format level by level

    PERFORM get_level_level.

    CLEAR : t_mast.
  ENDLOOP.

ENDFORM. " get_data_component
*&---------------------------------------------------------------------*
*& Form obj_ident
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM obj_ident.

* weder Mat noch Doc
  CHECK: t_stb-objty NE otyp_mat,
  t_stb-objty NE ootyp_mat,
  t_stb-objty NE otyp_doc,
  t_stb-objty NE otyp_ntm.

* ?T418-WA schon ok
* nein
  IF t_stb-postp NE t418-postp.
* T418 einlesen
    PERFORM t418_lesen USING t_stb-postp.
  ENDIF.


  PERFORM cl_clstab_maint.

* ?MatNr-Eingabe bei diesem PosTyp moeglich
* und keine Textposition
* trifft zu
  IF t418-matin NE '-'
  AND t418-txpos IS INITIAL.

* aktuelles Objekt ist Material NLAG
    t_stb-objty = '1'.
* PosKurztext in ObjKurztext uebernehmen.
    t_stb-ojtxp = t_stb-potx1.
    MODIFY t_stb.
  ELSE.
    IF t_stb-objty IS INITIAL.
      t_stb-objty = '2'.
      MODIFY t_stb.
    ENDIF.
  ENDIF.


ENDFORM. " obj_ident
*&---------------------------------------------------------------------*
*& Form t418_lesen
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_T_STB_POSTP text
*----------------------------------------------------------------------*
FORM t418_lesen USING lkl_postp LIKE stpo-postp.


* T418-WA initialisieren
  CLEAR:
  t418.

* Key angeben
  t418-postp = lkl_postp.
* PosTypDefinition lesen
  READ TABLE t418.


ENDFORM. " t418_lesen
*&---------------------------------------------------------------------*
*& Form cl_clstab_maint
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM cl_clstab_maint.

* nur fuer Klassenpositionen
  CHECK t_stb-objty EQ otyp_kla.

* Teilkey der Klassenpositionentabelle
  cl_clstab-class = t_stb-class.
  cl_clstab-klart = t_stb-klart.

* Klassenpositionentabelle lesen
  READ TABLE cl_clstab
  WITH KEY cl_clstab(21)
  BINARY SEARCH.

* aktuelle Klassenposition bereits in Klassenpositionentabelle
* nein
  IF sy-subrc <> 0.
* Klassenposition in Klassenpositionentabelle hinzufuegen
    INSERT cl_clstab INDEX sy-tabix.
  ENDIF.


ENDFORM. " cl_clstab_maint
*&---------------------------------------------------------------------*
*& Form alv_stb_prep
*&---------------------------------------------------------------------*
* Printing the data as LEVEL BY LEVEL
*----------------------------------------------------------------------*
FORM alv_stb_prep.

  CLEAR:
  alv_stb,
  stb_orig,
  stb_add.

  IF t_stb-hdnfo IS INITIAL.
    stb_orig = t_stb.

    IF t_stb-mngko >= max_num.
      stb_add-ovfls = ueberl_kz.
    ELSE.
      IF t_stb-mngko <= min_num.
        stb_add-ovfls = ueberl_kz.
      ELSE.
        CLEAR: stb_add-ovfls.
      ENDIF.
    ENDIF.

    IF NOT t_stb-xtlnr IS INITIAL.
      stb_add-bomfl = b_flag.
    ENDIF.

    IF NOT t_stb-knobj IS INITIAL
    OR NOT t_stb-class IS INITIAL
    OR NOT t_stb-kzclb IS INITIAL.

      stb_add-knofl = 'X'.
    ENDIF.
  ELSE.
    CHECK t_stb-stufe > 1.

    alv_stb-info = 'C30'.
    IF t_stb-ttidx <> t_matcat-index.
      READ TABLE t_matcat INDEX t_stb-ttidx.
    ENDIF.

    stb_orig-hdnfo = t_stb-hdnfo.
    stb_orig-stufe = t_stb-stufe - 1 .
    stb_orig-ojtxp = t_stb-ojtxb.

    IF NOT t_stb-altst IS INITIAL.
      stb_orig-stlal = t_stb-stlal.

      IF stb_orig-stlal(1) EQ '0'.
        stb_orig-stlal(1) = ' '.
      ENDIF.
    ENDIF.

    stb_orig-idnrk = t_matcat-matnr.
  ENDIF.

  CLEAR:
  stb_add-dobjt,
  stb_add-objic.

  CASE t_stb-objty.

    WHEN otyp_mat.
      WRITE: stb_orig-idnrk TO ecfld.
      stb_add-objic = '@A6@'.

    WHEN 'M'.
      WRITE: stb_orig-idnrk TO ecfld.
      stb_add-objic = '@A6@'.

    WHEN otyp_noo.
      WRITE: stb_orig-potx1 TO ecfld.
      stb_add-objic = '@0Q@'.

    WHEN otyp_doc.
      WRITE stb_orig-doknr TO ecfld. "note 489354

      IF ecfld CP '*# '. ENDIF. "note 489354
      sy-fdpos = sy-fdpos + 1. "note 489354

      CONCATENATE
*d stb_orig-doknr "note 489354
      stb_orig-dokar
      stb_orig-doktl
      stb_orig-dokvr
*d INTO ecfld "note 489354
      INTO ecfld+sy-fdpos "note 489354
      SEPARATED BY space.

      stb_add-objic = '@AR@'.

    WHEN otyp_kla.
      CONCATENATE
      stb_orig-class
      stb_orig-klart
      INTO ecfld
      SEPARATED BY space.

      stb_add-objic = '@7C@'.

    WHEN otyp_ntm.
      WRITE: stb_orig-intrm TO ecfld.

    WHEN OTHERS.
  ENDCASE.

*d CONDENSE ecfld. "note 515408
  stb_add-dobjt = ecfld(40).
  CLEAR: ecfld.

  WRITE stb_orig-stufe TO stb_add-dstuf NO-SIGN.

*d MOVE-CORRESPONDING stb_orig TO alv_stb. "note 331962
  MOVE-CORRESPONDING stb_add TO alv_stb.
  MOVE-CORRESPONDING stb_orig TO alv_stb. "note 331962

  APPEND alv_stb.


ENDFORM. " alv_stb_prep


*&---------------------------------------------------------------------*
*& Form get_level_level
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_level_level.

  REFRESH : t_stb,
  t_matcat,
  alv_stb.

  CLEAR : t_stb,
  t_matcat,
  alv_stb.
  CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
       EXPORTING
            capid                 = 'PP01'
            datuv                 = sy-datum
            mktls                 = 'X'
            mehrs                 = 'X'
            mtnrv                 = t_mast-matnr
            stlal                 = '01'
            stlan                 = '1'
            stpst                 = 0
            svwvo                 = 'X'
            werks                 = p_werks
            vrsvo                 = 'X'
       TABLES
            stb                   = t_stb
            matcat                = t_matcat
       EXCEPTIONS
            alt_not_found         = 1
            call_invalid          = 2
            material_not_found    = 3
            missing_authorization = 4
            no_bom_found          = 5
            no_plant_data         = 6
            no_suitable_bom_found = 7
            conversion_error      = 8
            OTHERS                = 9.

  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  CLEAR: hd_tab.
* Entry der KlassenstatusTab. initialisieren
* cl_clstab,
* Entry 'Objekte von Klassen' initialisieren
* cl_objmemo.
  REFRESH: hd_tab.

  SORT t_matcat BY index ASCENDING.

* Get the All levels
  LOOP AT t_stb.


    IF NOT t_stb-hdnfo IS INITIAL.
      EXIT.
    ENDIF.

* Object Identification
    PERFORM obj_ident.

    READ TABLE hd_tab
    WITH KEY stufe = t_stb-stufe
    vwegx = t_stb-vwegx
    BINARY SEARCH
    TRANSPORTING NO FIELDS.

* ?gibt es diesen Satz schon
* nein
    IF sy-subrc <> 0.
* dann in SFP-Infosatzverweistab. aufnehmen
*d APPEND HD_TAB. "HGH054648

      hd_tab-stufe = t_stb-stufe.
                                                            "HGH054648
      hd_tab-vwegx = t_stb-vwegx.
                                                            "HGH054648
      INSERT hd_tab                                         "HGH054648
      INTO hd_tab                                           "HGH054648
      INDEX sy-tabix.                                       "HGH054648

* PosNr initialisieren
      CLEAR: t_stb-posnr.
* SFP-InfosatzKz setzen
      t_stb-hdnfo = 'X'.
* stb-objty = otyp_mat.
                                                            "HGE246532
* als SFP-Infosatz in die STB aufnehmen
      APPEND t_stb.
    ENDIF.
*del ENDIF.
    CLEAR t_stb.
  ENDLOOP.


  SORT t_stb ASCENDING BY stufe
  index ASCENDING
*del POSNR ASCENDING. "HGC062735
  posnr ASCENDING                                           "HGC062735
  hdnfo DESCENDING.

  LOOP AT t_stb.
    t_stb-index = sy-tabix.
    MODIFY t_stb.

    PERFORM alv_stb_prep.
  ENDLOOP.


* Displays the Value as Level by Level

  LOOP AT alv_stb.

    IF sy-tabix = 1.
      FORMAT COLOR 3 ON.
      WRITE:/2 'Level',12 'Item',22 'Component',
      42 'Material Description',82 'Base Qty',
      107 'Base Unit',120 'Assembly Indicator'.

      FORMAT COLOR 3 ON.
    ENDIF.

    IF alv_stb-meins IS INITIAL.
      v_flag = 'X'.
    ENDIF.


    IF v_flag = 'X'.

      FORMAT COLOR 5 ON.
      WRITE:/2 alv_stb-stufe,12 alv_stb-posnr,22 alv_stb-idnrk,
      42 alv_stb-ojtxp.
      FORMAT COLOR 1 OFF.


    ELSE.
      IF alv_stb-stufe = '1'.
        FORMAT COLOR 1 ON.
        WRITE:/2 alv_stb-stufe,12 alv_stb-posnr,22 alv_stb-idnrk,
        42 alv_stb-ojtxp,72 alv_stb-mngko,
        107 alv_stb-meins, 120 alv_stb-bomfl .
        FORMAT COLOR 1 OFF.
      ELSEIF alv_stb-stufe = '2'.
        FORMAT COLOR 2 ON.
        WRITE:/2 alv_stb-stufe,12 alv_stb-posnr,22 alv_stb-idnrk,
        42 alv_stb-ojtxp,72 alv_stb-mngko,
        107 alv_stb-meins,120 alv_stb-bomfl.
        FORMAT COLOR 2 OFF.
      ELSEIF alv_stb-stufe = '3'.
        FORMAT COLOR 3 ON.
        WRITE:/2 alv_stb-stufe,12 alv_stb-posnr,22 alv_stb-idnrk,
        42 alv_stb-ojtxp,72 alv_stb-mngko,
        107 alv_stb-meins,120 alv_stb-bomfl .
        FORMAT COLOR 3 OFF.
      ELSEIF alv_stb-stufe = '4'.

        FORMAT COLOR 4 ON.
        WRITE:/2 alv_stb-stufe,12 alv_stb-posnr,22 alv_stb-idnrk,
        42 alv_stb-ojtxp,72 alv_stb-mngko,
        107 alv_stb-meins,120 alv_stb-bomfl .
        FORMAT COLOR 4 OFF.
      ELSEIF alv_stb-stufe = '5'.

        FORMAT COLOR 5 ON.
        WRITE:/2 alv_stb-stufe,12 alv_stb-posnr,22 alv_stb-idnrk,
        42 alv_stb-ojtxp,72 alv_stb-mngko,
        107 alv_stb-meins,120 alv_stb-bomfl .
        FORMAT COLOR 5 OFF.

      ELSEIF alv_stb-stufe = '6'.

        FORMAT COLOR 7 ON.
        WRITE:/2 alv_stb-stufe,12 alv_stb-posnr,22 alv_stb-idnrk,
        42 alv_stb-ojtxp,72 alv_stb-mngko,
        107 alv_stb-meins,120 alv_stb-bomfl.
        FORMAT COLOR 6 OFF.
      ELSEIF alv_stb-stufe = '7'.

        FORMAT COLOR 7 ON.
        WRITE:/2 alv_stb-stufe,12 alv_stb-posnr,22 alv_stb-idnrk,
        42 alv_stb-ojtxp,72 alv_stb-mngko,
        107 alv_stb-meins,120 alv_stb-bomfl .
        FORMAT COLOR 7 OFF.
      ELSE.
        FORMAT COLOR 1 ON.
        WRITE:/2 alv_stb-stufe,12 alv_stb-posnr,22 alv_stb-idnrk,
        42 alv_stb-ojtxp,72 alv_stb-mngko,
        107 alv_stb-meins,120 alv_stb-bomfl .
        FORMAT COLOR 1 OFF.
      ENDIF.

    ENDIF.

    HIDE: alv_stb.
    CLEAR : alv_stb.

    CLEAR v_flag.
  ENDLOOP.

ENDFORM. " get_level_level
*&---------------------------------------------------------------------*
*& Form f4_for_variant
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f4_for_variant.

  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
  EXPORTING
  is_variant = g_variant
  i_save = g_save
  i_tabname_header = g_tabname_header
  i_tabname_item = g_tabname_item
* it_default_fieldcat =
  IMPORTING
  e_exit = g_exit
  es_variant = gx_variant
  EXCEPTIONS
  not_found = 2.
  IF sy-subrc = 2.
    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    IF g_exit = space.
      p_vari = gx_variant-variant.
    ENDIF.
  ENDIF.


ENDFORM. " f4_for_variant
*---------------------------------------------------------------------*
* FORM E03_EVENTTAB_BUILD *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> E03_LT_EVENTS *
*---------------------------------------------------------------------*
FORM e03_eventtab_build USING e03_lt_events TYPE slis_t_event.
  DATA: ls_event TYPE slis_alv_event.
*
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
       EXPORTING
            i_list_type = 0
       IMPORTING
            et_events   = e03_lt_events.
  READ TABLE e03_lt_events WITH KEY name = slis_ev_top_of_page
  INTO ls_event.
  IF sy-subrc = 0.
    MOVE gc_formname_top_of_page TO ls_event-form.
    APPEND ls_event TO e03_lt_events.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
* FORM E04_COMMENT_BUILD *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> E04_LT_TOP_OF_PAGE *
*---------------------------------------------------------------------*
FORM e04_comment_build USING e04_lt_top_of_page TYPE slis_t_listheader.
  DATA: ls_line TYPE slis_listheader.
*
* Listenьberschrift: Typ H
  CLEAR ls_line.
  ls_line-typ = 'H'.
* LS_LINE-KEY: not used for this type
  ls_line-info = text-001.
  APPEND ls_line TO e04_lt_top_of_page.
* Kopfinfo: Typ S
  CLEAR ls_line.
  ls_line-typ = 'S'.
  ls_line-key = text-050.
  ls_line-info = text-010.
  APPEND ls_line TO e04_lt_top_of_page.
  ls_line-key = text-051.
  APPEND ls_line TO e04_lt_top_of_page.
* Aktionsinfo: Typ A
  CLEAR ls_line.
  ls_line-typ = 'A'.
* LS_LINE-KEY: not used for this type
  ls_line-info = text-002.
  APPEND ls_line TO e04_lt_top_of_page.
ENDFORM.

*---------------------------------------------------------------------*
* FORM E07_SP_GROUP_BUILD *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> E07_LT_SP_GROUP *
*---------------------------------------------------------------------*
FORM e07_sp_group_build USING e07_lt_sp_group TYPE slis_t_sp_group_alv.
  DATA: ls_sp_group TYPE slis_sp_group_alv.
*
  CLEAR ls_sp_group.
  ls_sp_group-sp_group = 'A'.
  ls_sp_group-text = text-005.
  APPEND ls_sp_group TO e07_lt_sp_group.
ENDFORM.


*&---------------------------------------------------------------------*
*& Form e08_layout_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GT_LAYOUT[] text
*----------------------------------------------------------------------*
FORM e08_layout_build USING gs_layout TYPE slis_layout_alv.

  gs_layout-f2code = 'GDET'. "define hotspot
  gs_layout-zebra = 'X'.
  gs_layout-colwidth_optimize = 'X'.
  gs_layout-no_hotspot = ' '.
  gs_layout-detail_popup = 'X'.
  gs_layout-no_input = ' '.
  gs_layout-no_colhead = ' '.
  gs_layout-lights_condense = ' '.
  gs_layout-totals_only = ' '.
  gs_layout-key_hotspot = ' '.
  gs_layout-group_buttons = ' '.
  gs_layout-no_vline = ' '.
* gs_layout-max_linesize = '350'.
  gs_layout-no_totalline = ' '.
* gs_layout-totals_text = 'UnRes Total'.
* gs_layout-subtotals_text = 'Material Type Total'.
  gs_layout-numc_sum = 'X'.
  gs_layout-no_unit_splitting = 'X'.
  gs_layout-no_sumchoice = ' '.
  gs_layout-no_subchoice = ' '.
  gs_layout-totals_before_items = ' '.
  gs_layout-no_subtotals = ' '.
  gs_layout-totals_only = ' '.
  gs_layout-item_text = ' '.
  gs_layout-default_item = 'X'.
  gs_layout-expand_fieldname = 'EXPAND'.


ENDFORM. " e08_layout_build

*&---------------------------------------------------------------------*
*& Form VARIANT_INIT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM variant_init.
*
  CLEAR g_variant.
  g_variant-report = g_repid.
ENDFORM. " VARIANT_INIT


*---------------------------------------------------------------------*
* FORM E01_FIELDCAT_INIT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> E01_LT_FIELDCAT *
*---------------------------------------------------------------------*
FORM e01_fieldcat_init USING e01_lt_fieldcat TYPE slis_t_fieldcat_alv.
  DATA: ls_fieldcat TYPE slis_fieldcat_alv.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'MATNR'.
  ls_fieldcat-tabname = 'T_MAIN_MATERIAL'.
  ls_fieldcat-key = 'X'.
  ls_fieldcat-ref_tabname = 'MAST'.
* ls_fieldcat-reptext_ddic = 'Main Material'.
* ls_fieldcat-no_out = 'X'.
* ls_fieldcat-no_sum = 'X'.
* ls_fieldcat-sp_group = 'A'.
  APPEND ls_fieldcat TO e01_lt_fieldcat.
**
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'WERKS'.
  ls_fieldcat-tabname = 'T_MAIN_MATERIAL'.
* ls_fieldcat-key = 'X'.
  ls_fieldcat-ref_tabname = 'MAST'.
* ls_fieldcat-reptext_ddic = 'Plant'.
  ls_fieldcat-no_out = 'X'.
* ls_fieldcat-no_sum = 'X'.
* ls_fieldcat-sp_group = 'A'.
  APPEND ls_fieldcat TO e01_lt_fieldcat.


  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'MAKTX'.
  ls_fieldcat-tabname = 'T_MAIN_MATERIAL'.
  ls_fieldcat-ref_tabname = 'MAKT'.
* ls_fieldcat-reptext_ddic = 'Material Description'.
* w_fieldcat-just = 'R'.
* w_fieldcat-outputlen = 16.
  APPEND ls_fieldcat TO e01_lt_fieldcat.


  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'STLAL'.
  ls_fieldcat-tabname = 'T_MAIN_MATERIAL'.
  ls_fieldcat-ref_tabname = 'STKO'.
* ls_fieldcat-reptext_ddic = 'Alt.BOM'.
* w_fieldcat-just = 'R'.
* w_fieldcat-outputlen = 16.
  APPEND ls_fieldcat TO e01_lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'STLNR'.
  ls_fieldcat-tabname = 'T_MAIN_MATERIAL'.
* ls_fieldcat-reptext_ddic = 'BOM #'.
  ls_fieldcat-ref_tabname = 'STPO'.
  ls_fieldcat-no_out = 'X'.
* w_fieldcat-just = 'R'.
* w_fieldcat-outputlen = 16.
  APPEND ls_fieldcat TO e01_lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'BMENG'.
  ls_fieldcat-tabname = 'T_MAIN_MATERIAL'.
  ls_fieldcat-ref_tabname = 'STKO'.
* ls_fieldcat-reptext_ddic = 'Base Qty'.
* ls_fieldcat-just = 'R'.
* w_fieldcat-outputlen = 16.
  APPEND ls_fieldcat TO e01_lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'BMEIN'.
  ls_fieldcat-tabname = 'T_MAIN_MATERIAL'.
  ls_fieldcat-ref_tabname = 'STKO'.
* ls_fieldcat-reptext_ddic = 'Base Qty'.
* ls_fieldcat-just = 'R'.
* w_fieldcat-outputlen = 16.
  APPEND ls_fieldcat TO e01_lt_fieldcat.


* CLEAR ls_fieldcat.
* ls_fieldcat-fieldname = 'MATNR'.
* ls_fieldcat-tabname = 'T_ITEM_MATERIAL'.
* ls_fieldcat-reptext_ddic = 'Book Value'.
** w_fieldcat-reptext_ddic = 'Total (-) Value'.
** w_fieldcat-just = 'R'.
** w_fieldcat-outputlen = 16.
* APPEND ls_fieldcat TO e01_lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'IDNRK'.
  ls_fieldcat-tabname = 'T_ITEM_MATERIAL'.
  ls_fieldcat-ref_tabname = 'STPO'.
* ls_fieldcat-reptext_ddic = 'BOM Component'.
* w_fieldcat-reptext_ddic = 'Total (-) Value'.
* w_fieldcat-just = 'R'.
* w_fieldcat-outputlen = 16.
  APPEND ls_fieldcat TO e01_lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'WERKS'.
  ls_fieldcat-tabname = 'T_ITEM_MATERIAL'.
  ls_fieldcat-ref_tabname = 'MAST'.
  ls_fieldcat-no_out = 'X'.
* ls_fieldcat-reptext_ddic = 'Plant'.
* w_fieldcat-just = 'R'.
* w_fieldcat-outputlen = 16.
  APPEND ls_fieldcat TO e01_lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'MAKTX'.
  ls_fieldcat-tabname = 'T_ITEM_MATERIAL'.
  ls_fieldcat-ref_tabname = 'MAKT'.
* ls_fieldcat-reptext_ddic = 'BOM Component Description'.
* ls_fieldcat-just = 'L'.
* ls_fieldcat-outputlen = 40.
  APPEND ls_fieldcat TO e01_lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'STLAL'.
  ls_fieldcat-tabname = 'T_ITEM_MATERIAL'.
  ls_fieldcat-ref_tabname = 'STKO'.
* ls_fieldcat-no_out = 'X'.
* ls_fieldcat-reptext_ddic = 'Alt.BOM'.
* w_fieldcat-just = 'R'.
* w_fieldcat-outputlen = 16.
  APPEND ls_fieldcat TO e01_lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'STLNR'.
  ls_fieldcat-tabname = 'T_ITEM_MATERIAL'.
  ls_fieldcat-ref_tabname = 'STPO'.
  ls_fieldcat-no_out = 'X'.
* ls_fieldcat-reptext_ddic = 'BOM #'.
* w_fieldcat-just = 'R'.
* w_fieldcat-outputlen = 16.
  APPEND ls_fieldcat TO e01_lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'MENGE'.
  ls_fieldcat-tabname = 'T_ITEM_MATERIAL'.
  ls_fieldcat-ref_tabname = 'STPO'.
* ls_fieldcat-reptext_ddic = 'Component Qty'.
* ls_fieldcat-just = 'R'.
* w_fieldcat-outputlen = 16.
  APPEND ls_fieldcat TO e01_lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'MEINS'.
  ls_fieldcat-tabname = 'T_ITEM_MATERIAL'.
  ls_fieldcat-ref_tabname = 'STPO'.
* ls_fieldcat-reptext_ddic = 'Base Qty'.
* ls_fieldcat-just = 'R'.
* w_fieldcat-outputlen = 16.
  APPEND ls_fieldcat TO e01_lt_fieldcat.


ENDFORM.

*&---------------------------------------------------------------------*
*& Form select_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM select_data.

  DATA: wa_lines TYPE i.

  IF p_bomlst = 'X'.


    SELECT * FROM makt INTO TABLE t_makt WHERE matnr IN s_matnr.



* Get all the information from MAST - BOM Table
    SELECT * FROM mast INTO TABLE t_mast WHERE matnr IN s_matnr AND
    werks = p_werks AND
    stlan IN s_stlan AND
    stlal IN s_stlal.

    IF sy-subrc = 0.

      CLEAR wa_lines.
      DESCRIBE TABLE t_mast LINES wa_lines.

      IF wa_lines > 0.
        SELECT stlty stlnr stlal stkoz bmein bmeng
        FROM stko
        INTO TABLE t_stko
        FOR ALL ENTRIES IN t_mast
        WHERE stlnr = t_mast-stlnr.

        CLEAR wa_lines.
        DESCRIBE TABLE t_mast LINES wa_lines.

        IF wa_lines > 0.
*-- Get the BOM item details
          SELECT stlty stlnr stlkn stpoz idnrk meins menge
          FROM stpo
          INTO TABLE t_stpo
          FOR ALL ENTRIES IN t_stko
          WHERE stlty = t_stko-stlty AND
          stlnr = t_stko-stlnr AND
          idnrk IN s_idnrk.

          SELECT * FROM makt APPENDING TABLE t_makt
          FOR ALL ENTRIES IN t_stpo
          WHERE matnr = t_stpo-idnrk.

        ENDIF.

      ENDIF.

    ENDIF.

*-- Move into the internal table according to selection
*-- for Material BOM list - Add the materials in the header and the
*-- list in the items table

    LOOP AT t_mast.

      MOVE t_mast-werks TO t_main_material-werks.
      MOVE t_mast-matnr TO t_main_material-matnr.
      MOVE t_mast-stlal TO t_main_material-stlal.
      MOVE t_mast-stlnr TO t_main_material-stlnr.

      READ TABLE t_stko WITH KEY stlnr = t_mast-stlnr
      stlal = t_mast-stlal.
      MOVE t_stko-bmeng TO t_main_material-bmeng.
      MOVE t_stko-bmein TO t_main_material-bmein.

      READ TABLE t_makt WITH KEY matnr = t_mast-matnr
      spras = 'EN'.
      MOVE t_makt-maktx TO t_main_material-maktx. "Description
      t_main_material-expand = space.
      APPEND t_main_material.
    ENDLOOP.
*-- Move the
    LOOP AT t_mast.
      MOVE t_mast-matnr TO t_item_material-matnr.
      MOVE t_mast-werks TO t_item_material-werks.
      MOVE t_mast-stlal TO t_item_material-stlal.
      MOVE t_mast-stlnr TO t_item_material-stlnr.

      LOOP AT t_stpo WHERE stlnr = t_mast-stlnr.
        MOVE t_stpo-menge TO t_item_material-menge.
        MOVE t_stpo-meins TO t_item_material-meins.
        MOVE t_stpo-idnrk TO t_item_material-idnrk.

        READ TABLE t_makt WITH KEY matnr = t_stpo-idnrk
        spras = 'EN'.
        MOVE t_makt-maktx TO t_item_material-maktx. "Description

        APPEND t_item_material.
      ENDLOOP.
    ENDLOOP.

  ELSE.
*-- Now the components where used list selected



*-- Get BOM description
    SELECT * FROM makt INTO TABLE t_makt WHERE matnr IN s_idnrk.

* Get all the information from MAST - BOM Table
* SELECT * FROM mast INTO TABLE t_mast FOR ALL ENTRIES IN t_stko
* WHERE matnr IN s_matnr AND
* werks = p_werks AND
* stlan IN s_stlan AND
* stlal IN s_stlal.
*-- Get the BOM item details
    SELECT stlty stlnr stlkn stpoz idnrk meins menge
    FROM stpo
    INTO TABLE t_stpo
    WHERE idnrk IN s_idnrk.

    IF sy-subrc = 0.

      CLEAR wa_lines.
      DESCRIBE TABLE t_stpo LINES wa_lines.

      IF wa_lines > 0.
        SELECT stlty stlnr stlal stkoz bmein bmeng
        FROM stko
        INTO TABLE t_stko
        FOR ALL ENTRIES IN t_stpo
        WHERE stlnr = t_stpo-stlnr.

        CLEAR wa_lines.
        DELETE ADJACENT DUPLICATES FROM t_stko COMPARING ALL FIELDS.
        DESCRIBE TABLE t_stko LINES wa_lines.

        IF wa_lines > 0.
*-- Get the BOM item details
         SELECT * FROM mast INTO TABLE t_mast FOR ALL ENTRIES IN t_stko
          WHERE werks = p_werks AND
          stlnr = t_stko-stlnr AND
          matnr IN s_matnr.

          SELECT * FROM makt APPENDING TABLE t_makt
          FOR ALL ENTRIES IN t_mast
          WHERE matnr = t_mast-matnr.

        ENDIF.

      ENDIF.

    ENDIF.

*-- Move into the internal table according to selection
*-- for Material BOM list - Add the materials in the header and the
*-- list in the items table

    LOOP AT t_mast.

      MOVE t_mast-werks TO t_main_material-werks.
      MOVE t_mast-matnr TO t_main_material-matnr.
      MOVE t_mast-stlal TO t_main_material-stlal.
      MOVE t_mast-stlnr TO t_main_material-stlnr.

      READ TABLE t_stko WITH KEY stlnr = t_mast-stlnr
      stlal = t_mast-stlal.
      MOVE t_stko-bmeng TO t_main_material-bmeng.
      MOVE t_stko-bmein TO t_main_material-bmein.
      READ TABLE t_makt WITH KEY matnr = t_mast-matnr
      spras = 'EN'.
      MOVE t_makt-maktx TO t_main_material-maktx. "Description
      t_main_material-expand = space.
      APPEND t_main_material.
    ENDLOOP.
*-- Move the
    LOOP AT t_mast.
      MOVE t_mast-matnr TO t_item_material-matnr.
      MOVE t_mast-werks TO t_item_material-werks.
      MOVE t_mast-stlal TO t_item_material-stlal.
      MOVE t_mast-stlnr TO t_item_material-stlnr.

      LOOP AT t_stpo WHERE stlnr = t_mast-stlnr.
        MOVE t_stpo-menge TO t_item_material-menge.
        MOVE t_stpo-idnrk TO t_item_material-idnrk.
        MOVE t_stpo-meins TO t_item_material-meins.
        READ TABLE t_makt WITH KEY matnr = t_stpo-idnrk
        spras = 'EN'.
        MOVE t_makt-maktx TO t_item_material-maktx. "Description

        APPEND t_item_material.
      ENDLOOP.
    ENDLOOP.
  ENDIF. "p_bomlst
ENDFORM.

*&---------------------------------------------------------------------*
*& Form alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv.
* Call ABAP/4 List Viewer
  CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
  EXPORTING
  i_callback_program = g_repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
  is_layout = gs_layout
  it_fieldcat = gt_fieldcat[]
* IT_EXCLUDING =
* it_special_groups = gt_sp_group[]
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* i_default = g_default
  i_save = g_save
* is_variant = g_variant
  it_events = gt_events[]
* IT_EVENT_EXIT =
  i_tabname_header = g_tabname_header
  i_tabname_item = g_tabname_item
  is_keyinfo = gs_keyinfo
* IS_PRINT =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
  TABLES
  t_outtab_header = t_main_material
  t_outtab_item = t_item_material.


ENDFORM. " alv


Text elements :

selection-text :

P_ALL ?...
P_BOMLST BOM Components List
P_COMPON Components Where Used List
P_ONE ?...
P_VARI Layout
P_WERKS Plant
S_IDNRK Component
S_MATNR Material
S_STLAL Alternative BOM
S_STLAN BOM usage

Text elements :

001 Enter The Required Parameters
002 To Display the Components List Report
003 Enter the Selection Variant (Hierarchal ALV)
005 Multi Level
006 Single Level
B03 Enter Report Option
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> PP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.