Sunday, July 14, 2013

SAP BOM Explosion Report

*&---------------------------------------------------------------------*
*& Report  ZMM_BOM_EXPOSIN
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZMM_BOM_EXPOSIN.

*REPORT ZMM_BOM_SCHDL_AGRMNT.







TABLESt418mastsscrfieldstcspr.

TYPE-POOLSslisicon.

DATABEGIN OF sav_stb OCCURS 100.
        INCLUDE STRUCTURE stpox.
DATAEND OF sav_stb.

DATABEGIN OF cl_clstab OCCURS 0,
         class LIKE klah-class,
         klart LIKE klah-klart,
         chked LIKE csdata-xfeld,
         noobj LIKE csdata-xfeld,
         dsply LIKE csdata-xfeld,
      END OF cl_clstab.

DATABEGIN OF stb_orig.
        INCLUDE STRUCTURE stpox.
DATAEND OF stb_orig.

DATABEGIN OF stb_add.
        INCLUDE STRUCTURE stpol_add.
DATAEND OF stb_add.

DATABEGIN OF cl_objmemo OCCURS 0,
         class LIKE klah-class,
         klart LIKE klah-klart.
        INCLUDE STRUCTURE ckssk.
DATAEND OF cl_objmemo.

DATABEGIN OF sum_stb,
         bmtyp LIKE stpox-bmtyp,
         ttidx LIKE stpox-ttidx,
         ojtxp LIKE stpox-ojtxp,
         mtart LIKE stpox-mtart,
         werks LIKE stpox-werks,
         vpsta LIKE stpox-vpsta,
         fstat LIKE stpox-fstat,
         mmein LIKE stpox-mmein,
         bwtty LIKE stpox-bwtty,
         vprsv LIKE stpox-vprsv,
         stprs LIKE stpox-stprs,
         verpr LIKE stpox-verpr,
         preih LIKE stpox-preih,
         sbdkz LIKE stpox-sbdkz,
         xchar LIKE stpox-xchar,
         mstae LIKE stpox-mstae,
         mstde LIKE stpox-mstde,
         mmsta LIKE stpox-mmsta,
         mmstd LIKE stpox-mmstd,
         sernp LIKE stpox-sernp,
         prctr LIKE stpox-prctr,
         mschg LIKE stpox-mschg,
         fxpru LIKE stpox-fxpru,
         kzech LIKE stpox-kzech,
         kzwsm LIKE stpox-kzwsm,
         kzeff LIKE stpox-kzeff,
         mcuob LIKE stpox-mcuob,
         matkl LIKE stpox-matkl,
         zeinr LIKE stpox-zeinr,
         zeivr LIKE stpox-zeivr,
         zeiar LIKE stpox-zeiar,
         zeifo LIKE stpox-zeifo,
         disst LIKE stpox-disst,
         dismm LIKE stpox-dismm,
         mnglg LIKE stpox-mnglg,
         msign LIKE stpox-msign,
         ausss LIKE stpox-ausss,
         kausf LIKE stpox-kausf,
         sobsl LIKE stpox-sobsl,
         sobsk LIKE stpox-sobsk,
         kzaus LIKE stpox-kzaus,
         ausdt LIKE stpox-ausdt,
         nfmat LIKE stpox-nfmat,
         rgekz LIKE stpox-rgekz,
         kzdkz LIKE stpox-kzdkz,
         lgpro LIKE stpox-lgpro,
         revlv LIKE stpox-revlv,
         kzkfg LIKE stpox-kzkfg,
         fbskz LIKE stpox-fbskz,
         stawn LIKE stpox-stawn,
         prefe LIKE stpox-prefe,
         stabk LIKE stpox-stabk,
         dostx LIKE stpox-dostx,
         idnrk LIKE stpox-idnrk,
         postp LIKE stpox-postp,
         sortf LIKE stpox-sortf,
         meins LIKE stpox-meins,
         potx1 LIKE stpox-potx1,
         potx2 LIKE stpox-potx2,
         objty LIKE stpox-objty,
         dokar LIKE stpox-dokar,
         doknr LIKE stpox-doknr,
         dokvr LIKE stpox-dokvr,
         doktl LIKE stpox-doktl,
         class LIKE stpox-class,
         klart LIKE stpox-klart,
         intrm LIKE stpox-intrm,
         xtlnr LIKE stpox-xtlnr,
         xloek LIKE stpox-xloek,
         sumkz LIKE stpox-sumkz,
         index LIKE sy-tabix,
      END OF sum_stb.

DATABEGIN OF ausnm_stb OCCURS 10,
         objty LIKE stpox-objty,
         idnrk LIKE stpox-idnrk,
         revlv LIKE stpox-revlv,
         doknr LIKE draw-doknr,
         dokar LIKE draw-dokar,
         doktl LIKE draw-doktl,
         dokvr LIKE draw-dokvr,
         class LIKE klah-class,
         klart LIKE klah-klart,
         intrm LIKE stpox-intrm,
         ojtxp LIKE stpox-ojtxp,
         xtlal LIKE stpox-stlal,
         ausnm LIKE stpox-ausnm,
       END OF ausnm_stb.

DATABEGIN OF i_mast OCCURS 0,
        matnr LIKE mast-matnr,
      END OF i_mast.

DATABEGIN OF i_stb_out OCCURS 0.
        INCLUDE STRUCTURE stpox.
DATA:   matnr LIKE cstmat-matnr,
        bmeng LIKE cstmat-bmeng,
        maktx LIKE cstmat-maktx,
      END OF i_stb_out.

DATABEGIN OF alv_stb OCCURS 0.
        INCLUDE STRUCTURE stpox_alv.
DATA:   matnr LIKE cstmat-matnr,
        bmeng(25TYPE c,
        maktx LIKE cstmat-maktx,
      END OF alv_stb.

DATA:  wa_topmat LIKE cstmat,
      i_stb LIKE stpox OCCURS WITH HEADER LINE,
      i_matcat  LIKE cscmat OCCURS WITH HEADER LINE.

DATABEGIN OF ftab OCCURS 200.
        INCLUDE STRUCTURE dfies.
DATAEND   OF ftab.

DATAgt_fieldcat TYPE slis_t_fieldcat_alv,
      gt_events   TYPE slis_t_event,
      gs_layout   TYPE slis_layout_alv,
      h_file     LIKE rlgrap-filename,
      sum_modus(2)   TYPE c,
      summ_flag(1)   TYPE c,
      hlp_tabix LIKE sy-tabix,
      max_num(7)  TYPE DECIMALS VALUE '9999999999.999',
      min_num(7)  TYPE DECIMALS VALUE '9999999999.999-',
      otyp_mat(1TYPE VALUE '1',
      ootyp_mat(1TYPE VALUE 'M',
      otyp_noo(1TYPE VALUE '2',
      otyp_doc(1TYPE VALUE '3',
      otyp_kla(1TYPE VALUE '4',
      otyp_ntm(1TYPE VALUE '5',
      anz_meins LIKE stpo-meins,
      anz_ktext LIKE makt-maktx,
      b_flag(1TYPE VALUE 'X',
      ueberl_kz(1TYPE VALUE '*',
      ueberl_flg(1TYPE c,
      plant_all  LIKE mast-werks VALUE '*   ',
      alvlo_stb        TYPE slis_layout_alv,
      alvvr            LIKE disvariant,
      alvvr_sav        TYPE c,
      exit_by_caller   TYPE c,
      exit_by_user     TYPE slis_exit_by_user,
      alvvr_sav_all    TYPE VALUE 'A',
      alvvr_sav_no_usr TYPE VALUE 'X',
      alv_evnt_tb_cmpl TYPE slis_t_event,
      wa_stb_fields_tb TYPE slis_fieldcat_alv,
      stb_fields_tb TYPE slis_t_fieldcat_alv,
      ecfld(250TYPE c,
      functxt TYPE smp_dyntxt,
      txt_report LIKE dokhl-object.   "Reportname für Erläuterungsaufruf

SELECTION-SCREENBEGIN OF SCREEN 100 AS SUBSCREEN.
SELECT-OPTIONSs_matnr FOR mast-matnr."" OBLIGATORY.
PARAMETERS:  p_werks LIKE mast-werks OBLIGATORY,
             p_stlan LIKE mast-stlan DEFAULT '1' OBLIGATORY,
             p_stlal LIKE mast-stlal DEFAULT '01' OBLIGATORY,
             p_capid LIKE tc04-capid DEFAULT 'PP01',
             p_datuv LIKE stko-datuv DEFAULT sy-datum.
*             S_MATNR LIKE MAST-MATNR OBLIGATORY.
SELECTION-SCREENEND OF SCREEN 100.

SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME NO INTERVALS.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-s00 NO INTERVALS.
SELECTION-SCREENBEGIN OF LINE,
                  POSITION 1.
PARAMETERS  p_altvo LIKE rc29l-altvo.
SELECTION-SCREENCOMMENT 3(12text-001,
                  COMMENT 15(11text-002,
                  POSITION 26.
PARAMETERS  p_stlal2 LIKE rc29l-stlal.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREENBEGIN OF LINE,
                  POSITION 1.
PARAMETERS  p_ausss LIKE rc29l-ausss.
SELECTION-SCREENCOMMENT 3(12text-003.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-s01 NO INTERVALS.
SELECTION-SCREENBEGIN OF LINE,
                  POSITION 1.
PARAMETERSp_brems LIKE rc29l-brems.
SELECTION-SCREENCOMMENT 3(15text-005,
                  COMMENT 18(13text-006,
                  POSITION 34.
PARAMETERSp_postp LIKE rc29l-postp.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREENBEGIN OF LINE,
                  POSITION 1.
PARAMETERS  p_sanko LIKE rc29l-sanko.
SELECTION-SCREENCOMMENT 3(11text-007,
                  COMMENT 18(16text-008,
                  POSITION 34.
PARAMETERS p_sanka LIKE rc29l-sanka.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREENBEGIN OF LINE,
                  POSITION 1.
PARAMETERS p_sanfe LIKE rc29l-sanfe.
SELECTION-SCREENCOMMENT 3(10text-009.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREENBEGIN OF LINE,
                  POSITION 1.
PARAMETERS p_sanin LIKE rc29l-sanin.
SELECTION-SCREENCOMMENT 3(12text-011,
                  COMMENT 18(5text-012,
                  POSITION 34.
PARAMETERS p_rvrel LIKE rc29l-rvrel.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREENBEGIN OF LINE,
                  POSITION 1.
PARAMETERS p_schgt LIKE rc29l-schgt.
SELECTION-SCREENCOMMENT 3(13text-015,
                  COMMENT 18(13text-016,
                  POSITION 34.
PARAMETERS p_erskz LIKE rc29l-erskz.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREENBEGIN OF LINE,
                  POSITION 1.
PARAMETERS p_stkkz LIKE rc29l-stkkz.
SELECTION-SCREENCOMMENT 3(11text-017,
                  COMMENT 18(15text-018,
                  POSITION 34.
PARAMETERS p_erssl LIKE rc29l-erssl.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREENBEGIN OF LINE,
                  COMMENT 18(15text-019,
                  POSITION 34.
PARAMETERS p_beikz LIKE rc29l-beikz.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREENBEGIN OF LINE,
                  COMMENT 18(15text-020,
                  POSITION 34.
PARAMETERS p_bessl LIKE rc29l-bessl.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
SELECTION-SCREENBEGIN OF LINE.
SELECTION-SCREENCOMMENT 1(8text-021,
                  POSITION 18.
PARAMETERS p_bagrp LIKE rc29l-bagrp.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
SELECTION-SCREENBEGIN OF LINE.
SELECTION-SCREENCOMMENT 1(15text-023,
                  POSITION 18.
PARAMETERS p_maxst LIKE rc29l-maxst.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b3.
SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-s03 NO INTERVALS.
SELECTION-SCREENBEGIN OF LINE,
                  POSITION 1.
PARAMETERS p_valst LIKE rc29l-valst.
SELECTION-SCREEN COMMENT 3(13text-024.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b4.
SELECTION-SCREEN BEGIN OF BLOCK b5 WITH FRAME TITLE text-s04 NO INTERVALS.
SELECTION-SCREENBEGIN OF LINE,
                  POSITION 1.
PARAMETERS p_ltext LIKE rc29l-ltext.
SELECTION-SCREEN COMMENT 3(15text-027.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREENBEGIN OF LINE,
                  POSITION 1.
PARAMETERS p_dspco LIKE rc29l-dspco.
SELECTION-SCREEN COMMENT 3(20text-031.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b5.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN END OF SCREEN 200.

SELECTION-SCREENBEGIN OF TABBED BLOCK mytab FOR 35  LINES,
                TAB (20button1 USER-COMMAND push1
                                 DEFAULT SCREEN 100,
                TAB (20button2 USER-COMMAND push2
                                 DEFAULT SCREEN 200,
                END OF BLOCK mytab.

INITIALIZATION.
  button1 'Selction Screen'.
  button2 'View'.

AT SELECTION-SCREEN.

  SELECT matnr FROM mast
    INTO TABLE i_mast
    WHERE matnr IN s_matnr
    AND   werks p_werks
    AND   stlan p_stlan
    AND   stlal p_stlal.

  IF sy-subrc <> 0.
    MESSAGE e001(k5WITH 'No Data Selected'.
  ENDIF.

START-OF-SELECTION.
  LOOP AT i_mast.
    CLEAR sum_stb.                                          "DV1K912037
    PERFORM get_data.
    PERFORM build_output.
    PERFORM append_stb_out.
  ENDLOOP.

  PERFORM get_user_prof.
  PERFORM cs13_alv.

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data .
BREAK 10115.
  CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
    EXPORTING
      altvo  p_altvo
      aufsw  ' '
      auskz  p_ausss
      bagrp  p_bagrp
      beikz  p_beikz
      bessl  p_bessl
      brems  p_brems
      capid  p_capid
      datuv  p_datuv
      ehndl  '1'
      erskz  p_erskz
      erssl  p_erssl
      mbwls  ' '
      mtnrv  i_mast-matnr
      mehrs  'X'
      mmory  '1'
      postp  p_postp
      sanko  p_sanko
      sanfr  p_sanfe
      sanka  p_sanka
      sanin  p_sanin
      rndkz  tcspr-amekz
      rvrel  p_rvrel
      schgt  p_schgt
      stkkz  p_stkkz
      stlal  p_stlal
      stlan  p_stlan
      stpst  p_maxst
      werks  p_werks
    IMPORTING
      topmat wa_topmat
    TABLES
      stb    i_stb
      matcat i_matcat.

ENDFORM.                    " GET_DATA

*&---------------------------------------------------------------------*
*&      Form  BUILD_OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_output .
BREAK 10115.
  SORT i_stb ASCENDING BY msign
       idnrk ASCENDING
       dokar ASCENDING
       doknr ASCENDING
       dokvr ASCENDING
       doktl ASCENDING
       class ASCENDING
       klart ASCENDING
       postp ASCENDING
       potx1 ASCENDING
       potx2 ASCENDING
       werks ASCENDING
       sortf ASCENDING.

  PERFORM stb_erweitern.
  PERFORM cs13_vorbereiten.

ENDFORM.                    " BUILD_OUTPUT

*-----------------------------------------------------------------------
*    FORM PF_STATUS_SET
*-----------------------------------------------------------------------
FORM whole_toolbar USING extab TYPE slis_t_extab.           "#EC CALLED
  SET PF-STATUS 'WHOLE_TOOLBAR' EXCLUDING extab.
ENDFORM.                    "whole_toolbar

*---------------------------------------------------------------------*
*       FORM user_command                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  RF_UCOMM                                                      *
*  -->  RS_SELFIELD                                                   *
*---------------------------------------------------------------------*
FORM user_command USING rf_ucomm    LIKE sy-ucomm
                        rs_selfield TYPE slis_selfield.     "#EC CALLED

  CASE rf_ucomm.

    WHEN 'ERLE'.
      txt_report 'Z_FI_CUSTOMER_INVOICE_LIST'.
      CALL FUNCTION 'ERGO_TEXT_SHOW'
        EXPORTING
          textname txt_report
          id       'RE'
          langu    sy-langu.


  ENDCASE.
ENDFORM.                    "user_command

*&---------------------------------------------------------------------*
*&      Form  STB_ERWEITERN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM stb_erweitern .

  DATAhlf_rechf TYPE f.
  DATAlst_index LIKE sy-tabix.

* ---------------------------------

  CLEARsum_modus.
  CLEARcl_clstab,
         cl_objmemo.
  REFRESHcl_clstab,
           cl_objmemo.

  DESCRIBE TABLE i_stb LINES lst_index.

  LOOP AT i_stb.
    hlp_tabix sy-tabix.
    PERFORM obj_ident.

    CHECK i_stb-sumkz NE '*'.

    PERFORM cl_clstab_maint.
    sy-tabix hlp_tabix.

    IF NOT i_stb-ausnm IS INITIAL.
      PERFORM ausnahme_merken.
    ENDIF.

    CLEARsumm_flag.
    PERFORM summ_flag_setzen.

    IF summ_flag EQ 'x'.
      IF sum_stb-sumkz IS INITIAL.
        CLEARhlf_rechf.
      ENDIF.

      PERFORM stb_markieren.

      IF hlf_rechf < max_num.
        hlf_rechf hlf_rechf + i_stb-mnglg.
      ENDIF.
    ELSE.
      IF sum_stb-sumkz '*'.
        hlf_rechf hlf_rechf + sum_stb-mnglg.
        IF hlf_rechf < max_num.
          sum_stb-mnglg hlf_rechf.
        ELSE.
          sum_stb-mnglg max_num.
        ENDIF.

        sum_stb-index lst_index + .
        PERFORM sumsatz_aufnehmen.
        hlf_rechf i_stb-mnglg.
        lst_index lst_index + .
      ENDIF.

      MOVE-CORRESPONDING i_stb TO sum_stb.
    ENDIF.
  ENDLOOP.

  IF sum_stb-sumkz '*'.
    hlf_rechf hlf_rechf + sum_stb-mnglg.
    IF hlf_rechf < max_num.
      sum_stb-mnglg hlf_rechf.
    ELSE.
      sum_stb-mnglg max_num.
    ENDIF.

    sum_stb-index lst_index + .
    PERFORM sumsatz_aufnehmen.
    CLEARhlf_rechf.
  ENDIF.
ENDFORM.                    " STB_ERWEITERN

*&---------------------------------------------------------------------*
*&      Form  AUSNAHME_MERKEN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM ausnahme_merken .
  BREAK 10115.
  ausnm_stb-objty i_stb-objty.
  ausnm_stb-idnrk i_stb-idnrk.
  ausnm_stb-revlv i_stb-revlv.
  ausnm_stb-doknr i_stb-doknr.
  ausnm_stb-dokar i_stb-dokar.
  ausnm_stb-doktl i_stb-doktl.
  ausnm_stb-dokvr i_stb-dokvr.
  ausnm_stb-class i_stb-class.
  ausnm_stb-klart i_stb-klart.
  ausnm_stb-intrm i_stb-intrm.
  ausnm_stb-ojtxp i_stb-ojtxp.
  IF i_stb-ausnm EQ 'NOTX'.
    ausnm_stb-xtlal i_stb-xtlal.
  ENDIF.
  ausnm_stb-ausnm i_stb-ausnm.
  hlp_tabix sy-tabix.
  COLLECT ausnm_stb.
  sy-tabix hlp_tabix.
ENDFORM.                    " AUSNAHME_MERKEN

*&---------------------------------------------------------------------*
*&      Form  OBJ_IDENT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM obj_ident .
BREAK 10115.
  CHECKi_stb-objty NE otyp_mat,
         i_stb-objty NE ootyp_mat,
         i_stb-objty NE otyp_doc,
         i_stb-objty NE otyp_ntm.

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

*  ?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
    i_stb-objty '1'.
*     PosKurztext in ObjKurztext uebernehmen.
    i_stb-ojtxp i_stb-potx1.
    MODIFY i_stb.
  ELSE.
    IF i_stb-objty IS INITIAL.
      i_stb-objty '2'.
      MODIFY i_stb.
    ENDIF.
  ENDIF.
ENDFORM.                    " OBJ_IDENT

*&---------------------------------------------------------------------*
*&      Form  T418_LESEN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_STB_POSTP  text
*----------------------------------------------------------------------*
FORM t418_lesen  USING    lkl_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
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM cl_clstab_maint .
*  nur fuer Klassenpositionen
  CHECK i_stb-objty EQ otyp_kla.

*  Teilkey der Klassenpositionentabelle
  cl_clstab-class i_stb-class.
  cl_clstab-klart i_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  SUMM_FLAG_SETZEN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM summ_flag_setzen .
  BREAK 10115.
  CASE sum_modus.

    WHEN '  '.
      IF     i_stb-msign EQ sum_stb-msign
         AND i_stb-postp EQ sum_stb-postp
         AND i_stb-werks EQ sum_stb-werks
         AND i_stb-idnrk EQ sum_stb-idnrk
         AND i_stb-dokar EQ sum_stb-dokar
         AND i_stb-doknr EQ sum_stb-doknr
         AND i_stb-dokvr EQ sum_stb-dokvr
         AND i_stb-doktl EQ sum_stb-doktl
         AND i_stb-class EQ sum_stb-class
         AND i_stb-klart EQ sum_stb-klart
         AND i_stb-intrm EQ sum_stb-intrm
         AND NOT sum_stb IS INITIAL.

        IF     i_stb-idnrk IS INITIAL
           AND i_stb-msign EQ sum_stb-msign
           AND i_stb-postp EQ sum_stb-postp
           AND i_stb-dokar EQ sum_stb-dokar
           AND i_stb-doknr EQ sum_stb-doknr
           AND i_stb-dokvr EQ sum_stb-dokvr
           AND i_stb-doktl EQ sum_stb-doktl
           AND i_stb-class EQ sum_stb-class
           AND i_stb-klart EQ sum_stb-klart
           AND i_stb-intrm EQ sum_stb-intrm.
          IF     sum_stb-potx1 EQ i_stb-potx1
             AND sum_stb-potx2 EQ i_stb-potx2.
            summ_flag 'x'.
          ENDIF.
        ELSE.
          summ_flag 'x'.
        ENDIF.
      ENDIF.
    WHEN 'x '.
      IF     i_stb-msign EQ sum_stb-msign
         AND i_stb-postp EQ sum_stb-postp
         AND i_stb-werks EQ sum_stb-werks
         AND i_stb-idnrk EQ sum_stb-idnrk
         AND i_stb-dokar EQ sum_stb-dokar
         AND i_stb-doknr EQ sum_stb-doknr
         AND i_stb-dokvr EQ sum_stb-dokvr
         AND i_stb-doktl EQ sum_stb-doktl
         AND i_stb-class EQ sum_stb-class
         AND i_stb-klart EQ sum_stb-klart
         AND i_stb-intrm EQ sum_stb-intrm
         AND i_stb-sortf EQ sum_stb-sortf
         AND NOT sum_stb IS INITIAL.

        IF    i_stb-idnrk IS INITIAL
           AND i_stb-msign EQ sum_stb-msign
           AND i_stb-postp EQ sum_stb-postp
           AND i_stb-dokar EQ sum_stb-dokar
           AND i_stb-doknr EQ sum_stb-doknr
           AND i_stb-dokvr EQ sum_stb-dokvr
           AND i_stb-doktl EQ sum_stb-doktl
           AND i_stb-class EQ sum_stb-class
           AND i_stb-klart EQ sum_stb-klart
           AND i_stb-intrm EQ sum_stb-intrm.
          IF     sum_stb-potx1 EQ i_stb-potx1
             AND sum_stb-potx2 EQ i_stb-potx2.
            summ_flag 'x'.
          ENDIF.
        ELSE.
          summ_flag 'x'.
        ENDIF.
      ENDIF.
    WHEN ' x'.
      IF     i_stb-msign EQ sum_stb-msign
         AND i_stb-postp EQ sum_stb-postp
         AND i_stb-werks EQ sum_stb-werks
         AND i_stb-idnrk EQ sum_stb-idnrk
         AND i_stb-dokar EQ sum_stb-dokar
         AND i_stb-doknr EQ sum_stb-doknr
         AND i_stb-dokvr EQ sum_stb-dokvr
         AND i_stb-doktl EQ sum_stb-doktl
         AND i_stb-class EQ sum_stb-class
         AND i_stb-klart EQ sum_stb-klart
         AND i_stb-intrm EQ sum_stb-intrm
         AND i_stb-potx1 EQ sum_stb-potx1
         AND i_stb-potx2 EQ sum_stb-potx2.
        summ_flag 'x'.
      ENDIF.
    WHEN 'xx'.
      IF     i_stb-msign EQ sum_stb-msign
         AND i_stb-postp EQ sum_stb-postp
         AND i_stb-werks EQ sum_stb-werks
         AND i_stb-idnrk EQ sum_stb-idnrk
         AND i_stb-dokar EQ sum_stb-dokar
         AND i_stb-doknr EQ sum_stb-doknr
         AND i_stb-dokvr EQ sum_stb-dokvr
         AND i_stb-doktl EQ sum_stb-doktl
         AND i_stb-class EQ sum_stb-class
         AND i_stb-klart EQ sum_stb-klart
         AND i_stb-intrm EQ sum_stb-intrm
         AND i_stb-potx1 EQ sum_stb-potx1
         AND i_stb-potx2 EQ sum_stb-potx2
         AND i_stb-sortf EQ sum_stb-sortf.
        summ_flag 'x'.
      ENDIF.
  ENDCASE.

ENDFORM.                    " SUMM_FLAG_SETZEN

*&---------------------------------------------------------------------*
*&      Form  STB_MARKIEREN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM stb_markieren .

  BREAK 10115.
  DATAread_index LIKE sy-tabix.

* ----------------------------------
  CLEARread_index.

  i_stb-sumkz 's'.

  IF i_stb-werks NE sum_stb-werks.
    sum_stb-werks plant_all.
  ENDIF.

  MODIFY i_stb INDEX sy-tabix.

  IF sum_stb-sumkz NE '*'.
    sum_stb-sumkz '*'.

    sav_stb i_stb.

    read_index sy-tabix .
    READ TABLE i_stb INDEX read_index.

    sum_stb-mnglg i_stb-mnglg.

    i_stb-sumkz 's'.
    MODIFY i_stb INDEX sy-tabix.

    i_stb sav_stb.
  ENDIF.
ENDFORM.                    " STB_MARKIEREN

*&---------------------------------------------------------------------*
*&      Form  SUMSATZ_AUFNEHMEN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM sumsatz_aufnehmen .
  sav_stb i_stb.

  CLEARi_stb.

  MOVE-CORRESPONDING sum_stb TO i_stb.

  CLEARi_stb-datuv,
         i_stb-datub.
  APPEND i_stb.

  i_stb sav_stb.
ENDFORM.                    " SUMSATZ_AUFNEHMEN

*&---------------------------------------------------------------------*
*&      Form  CS13_VORBEREITEN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM cs13_vorbereiten .
  SORT i_stb ASCENDING BY objty
             idnrk ASCENDING
             dokar ASCENDING
             doknr ASCENDING
             dokvr ASCENDING
             doktl ASCENDING
             ojtxp ASCENDING
             potx1 ASCENDING
             potx2 ASCENDING
             sortf ASCENDING
             sumkz ASCENDING.
ENDFORM.                    "CS13_VORBEREITEN

*&---------------------------------------------------------------------*
*&      Form  CS13_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM cs13_alv .
  LOOP AT i_stb_out.
*   Uebergabestrukturen initialisieren
    CLEAR:
      stb_orig,
      stb_add.

    IF i_stb-ttidx <> i_matcat-index.
      READ TABLE i_matcat INDEX i_stb-ttidx.
    ENDIF.

    CHECK i_stb_out-xtlnr IS INITIAL.

*   STB-Eintrag in Uebergabestruktur uebernehmen
    stb_orig i_stb_out.

    PERFORM alv_stb_prep.
  ENDLOOP.

  PERFORM stb_fields_tb_prep.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      sy-repid
      i_structure_name        'STPOX_ALV'
      is_layout               alvlo_stb
      i_save                  alvvr_sav_all
      is_variant              alvvr
      it_events               alv_evnt_tb_cmpl
      it_fieldcat             stb_fields_tb
    IMPORTING
      e_exit_caused_by_caller exit_by_caller
      es_exit_caused_by_user  exit_by_user
    TABLES
      t_outtab                alv_stb
    EXCEPTIONS
      program_error           1
      OTHERS                  2.

  IF sy-subrc 0.
    IF exit_by_caller 'X'.
*     Forced Exit by calling program
*     <do_something>.
    ELSE.
*     User left list via F3, F12 or F15
      IF exit_by_user-back 'X'.       "F3
*       <do_something>.
      ELSE.
        IF exit_by_user-exit 'X'.     "F15
*         <do_something>.
        ELSE.
          IF exit_by_user-cancel 'X'"F12
*           <do_something>.
          ELSE.
*           should not occur!
*           <do_Abnormal_End>.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
  ELSE.
*   Fatal error callin ALV
*   MESSAGE AXXX(XY) WITH ...
  ENDIF.

  IF sy-subrc <> 0.
    MESSAGE s513(29WITH 'E: '.
    EXIT.
  ENDIF.
ENDFORM.                                                    " CS13_ALV

*&---------------------------------------------------------------------*
*&      Form  ALV_STB_PREP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM alv_stb_prep.

  CHECK i_stb_out-sumkz NE 's'.

  IF i_stb_out-idnrk IS INITIAL.
    IF i_stb_out-doknr IS INITIAL.
      IF i_stb_out-class IS INITIAL.
        anz_meins i_stb_out-meins.
        anz_ktext i_stb_out-potx1.
      ELSE.
        anz_meins i_stb_out-meins.
        anz_ktext i_stb_out-ojtxp.
      ENDIF.
    ELSE.
      anz_meins i_stb_out-meins.
      anz_ktext i_stb_out-ojtxp.
    ENDIF.
  ELSE.
    anz_meins i_stb_out-mmein.
    anz_ktext i_stb_out-ojtxp.
  ENDIF.

  IF i_stb_out-mnglg >= max_num.
    ueberl_flg ueberl_kz.
  ELSE.
    IF i_stb_out-mnglg <= min_num.
      ueberl_flg ueberl_kz.
    ELSE.
      CLEARueberl_flg.
    ENDIF.
  ENDIF.

  CLEAR:
    stb_add-dobjt,
    stb_add-objic.

  CASE i_stb_out-objty.
    WHEN otyp_mat.
      WRITEstb_orig-idnrk TO ecfld.

      IF NOT stb_orig-hdnfo IS INITIAL.
        CALL FUNCTION 'ICON_CREATE'
          EXPORTING
            name                  'ICON_BOM'
            info                  text-074
          IMPORTING
            RESULT                stb_add-objic
          EXCEPTIONS
            icon_not_found        1
            outputfield_too_short 2
            OTHERS                3.
      ELSE.

        CALL FUNCTION 'ICON_CREATE'
          EXPORTING
            name                  'ICON_MATERIAL'
            info                  text-070
          IMPORTING
            RESULT                stb_add-objic
          EXCEPTIONS
            icon_not_found        1
            outputfield_too_short 2
            OTHERS                3.
      ENDIF.

    WHEN 'M'.
      WRITEstb_orig-idnrk TO ecfld.

      IF NOT stb_orig-hdnfo IS INITIAL.
        CALL FUNCTION 'ICON_CREATE'
          EXPORTING
            name                  'ICON_BOM'
            info                  text-074
          IMPORTING
            RESULT                stb_add-objic
          EXCEPTIONS
            icon_not_found        1
            outputfield_too_short 2
            OTHERS                3.
      ELSE.

        CALL FUNCTION 'ICON_CREATE'
          EXPORTING
            name                  'ICON_MATERIAL'
            info                  text-070
          IMPORTING
            RESULT                stb_add-objic
          EXCEPTIONS
            icon_not_found        1
            outputfield_too_short 2
            OTHERS                3.
      ENDIF.

    WHEN otyp_noo.
      WRITEstb_orig-potx1 TO ecfld.

      CALL FUNCTION 'ICON_CREATE'
        EXPORTING
          name                  'ICON_CHANGE_TEXT'
          info                  text-073
        IMPORTING
          RESULT                stb_add-objic
        EXCEPTIONS
          icon_not_found        1
          outputfield_too_short 2
          OTHERS                3.

    WHEN otyp_doc.
      WRITE stb_orig-doknr TO ecfld.

      IF ecfld CP '*# 'ENDIF.
      sy-fdpos sy-fdpos + 1.

      CONCATENATE
        stb_orig-dokar
        stb_orig-doktl
        stb_orig-dokvr
        INTO ecfld+sy-fdpos
        SEPARATED BY space.

      CALL FUNCTION 'ICON_CREATE'
        EXPORTING
          name                  'ICON_DOCUMENT'
          info                  text-071
        IMPORTING
          RESULT                stb_add-objic
        EXCEPTIONS
          icon_not_found        1
          outputfield_too_short 2
          OTHERS                3.

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

      CALL FUNCTION 'ICON_CREATE'
        EXPORTING
          name                  'ICON_OO_CLASS'
          info                  text-072
        IMPORTING
          RESULT                stb_add-objic
        EXCEPTIONS
          icon_not_found        1
          outputfield_too_short 2
          OTHERS                3.

    WHEN otyp_ntm.
      WRITEstb_orig-intrm TO ecfld.

    WHEN OTHERS.
  ENDCASE.

  stb_add-dobjt ecfld(40).
  CLEARecfld.

  stb_add-ovfls ueberl_flg.
  stb_add-dunit anz_meins.

  IF NOT stb_orig-xtlnr IS INITIAL.
    stb_add-bomfl b_flag.
  ENDIF.

  IF NOT stb_orig-knobj IS INITIAL.
    stb_add-knofl 'X'.
  ENDIF.

  MOVE-CORRESPONDING stb_add TO alv_stb.
  MOVE-CORRESPONDING stb_orig TO alv_stb.

  WRITE i_stb_out-bmeng TO alv_stb-bmeng.
  WRITE i_stb_out-matnr TO alv_stb-matnr.
  alv_stb-maktx i_stb_out-maktx.

  APPEND alv_stb.
ENDFORM.                    " ALV_STB_PREP

*&---------------------------------------------------------------------*
*&      Form  STB_FIELDS_TB_PREP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM stb_fields_tb_prep .
  CALL FUNCTION 'DDIF_FIELDINFO_GET'
    EXPORTING
      langu     sy-langu
      tabname   'STPOX_ALV'
    TABLES
      dfies_tab ftab
    EXCEPTIONS
      OTHERS    1.



  LOOP AT ftab.
    CLEARwa_stb_fields_tb.

    CASE ftab-fieldname.
      WHEN 'OBJIC'.
        wa_stb_fields_tb-fieldname 'OBJIC'.
        wa_stb_fields_tb-outputlen .
        wa_stb_fields_tb-icon       =  'X' .
        wa_stb_fields_tb-key        =  'X' .
        wa_stb_fields_tb-fix_column =  'X' .
        wa_stb_fields_tb-col_pos   =  1.
        APPEND wa_stb_fields_tb TO stb_fields_tb.

      WHEN 'DOBJT'.
        wa_stb_fields_tb-fieldname 'DOBJT'.
        wa_stb_fields_tb-outputlen 23 .
        wa_stb_fields_tb-key        =  'X' .
        wa_stb_fields_tb-fix_column =  'X' .
        wa_stb_fields_tb-col_pos   =  2.
        APPEND wa_stb_fields_tb TO stb_fields_tb.

      WHEN 'OJTXP'.
        wa_stb_fields_tb-fieldname 'OJTXP'.
        wa_stb_fields_tb-outputlen 32.
        wa_stb_fields_tb-col_pos   =  3.
        APPEND wa_stb_fields_tb TO stb_fields_tb.

      WHEN 'OVFLS'.
        wa_stb_fields_tb-fieldname 'OVFLS'.
        wa_stb_fields_tb-outputlen .
        wa_stb_fields_tb-just      'R' .
        wa_stb_fields_tb-col_pos   4.
        APPEND wa_stb_fields_tb TO stb_fields_tb.

      WHEN 'MNGLG'.
        wa_stb_fields_tb-fieldname 'MNGLG'.
        wa_stb_fields_tb-col_pos   5.
        wa_stb_fields_tb-outputlen 18.
        wa_stb_fields_tb-no_sum    'X'.
        APPEND wa_stb_fields_tb TO stb_fields_tb.

      WHEN 'SUMKZ'.
        wa_stb_fields_tb-fieldname 'SUMKZ'.
        wa_stb_fields_tb-just      'R' .
        wa_stb_fields_tb-outputlen .
        wa_stb_fields_tb-col_pos   6.
        APPEND wa_stb_fields_tb TO stb_fields_tb.

      WHEN 'DUNIT'.
        wa_stb_fields_tb-fieldname 'DUNIT'.
        wa_stb_fields_tb-outputlen .
        wa_stb_fields_tb-col_pos   7.
        APPEND wa_stb_fields_tb TO stb_fields_tb.

      WHEN OTHERS.
        wa_stb_fields_tb-fieldname ftab-fieldname.
        wa_stb_fields_tb-no_out    'X'.
        wa_stb_fields_tb-no_sum    'X'.
        APPEND wa_stb_fields_tb TO stb_fields_tb.

    ENDCASE.

  ENDLOOP.

  CLEAR ftab.
  REFRESH ftab.

  CALL FUNCTION 'DDIF_FIELDINFO_GET'
    EXPORTING
      langu     sy-langu
      tabname   'CSTMAT'
    TABLES
      dfies_tab ftab
    EXCEPTIONS
      OTHERS    1.

  LOOP AT ftab.

    CLEARwa_stb_fields_tb.

    CASE ftab-fieldname.

      WHEN 'BMENG'.
        wa_stb_fields_tb-fieldname    'BMENG'.
        wa_stb_fields_tb-datatype  'QUAN'.
        wa_stb_fields_tb-seltext_s ftab-scrtext_s.
        wa_stb_fields_tb-col_pos   8.
        wa_stb_fields_tb-cfieldname    'MMEIN'.
        APPEND wa_stb_fields_tb TO stb_fields_tb.

      WHEN 'MATNR'.
        wa_stb_fields_tb-fieldname    'MATNR'.
        wa_stb_fields_tb-seltext_s ftab-scrtext_s.
        wa_stb_fields_tb-col_pos   9.
        APPEND wa_stb_fields_tb TO stb_fields_tb.

      WHEN 'MAKTX'.
        wa_stb_fields_tb-fieldname    'MAKTX'.
        wa_stb_fields_tb-seltext_s ftab-scrtext_s.
        wa_stb_fields_tb-col_pos   10.
        APPEND wa_stb_fields_tb TO stb_fields_tb.

    ENDCASE.

  ENDLOOP.

ENDFORM.                    " STB_FIELDS_TB_PREP

*&---------------------------------------------------------------------*
*&      Form  APPEND_STB_OUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM append_stb_out .
  LOOP AT i_stb.
    MOVE-CORRESPONDING i_stb TO i_stb_out.
    i_stb_out-matnr =  wa_topmat-matnr.
    i_stb_out-bmeng =  wa_topmat-bmeng.
    i_stb_out-maktx =  wa_topmat-maktx.
    APPEND i_stb_out.
    CLEAR i_stb_out.
  ENDLOOP.
ENDFORM.                    " APPEND_STB_OUT

*&---------------------------------------------------------------------*
*&      Form  GET_USER_PROF
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_user_prof .

  SELECT SINGLE FROM tcspr
    WHERE csusr sy-uname.

  IF sy-subrc 0.

    IF NOT tcspr-zbgrp IS INITIAL.
      p_stlal2 'X'.
    ENDIF.

    IF NOT tcspr-ltext IS INITIAL.                          "HGA127128
      p_ltext 'X'.                                        "HGA127128
    ENDIF.                                                  "HGA127128

    IF NOT tcspr-dspco IS INITIAL.                          "HGA246532
      p_dspco 'X'.                                        "HGA246532
    ENDIF.                                                  "HGA246532

    IF NOT tcspr-valst IS INITIAL.                          "HGA246532
      p_valst 'X'.                                        "HGA246532
    ENDIF.                                                  "HGA246532

  ENDIF.

ENDFORM.                    " GET_USER_PROF

No comments:

Post a Comment