Sunday, May 18, 2014

Table Control BDC

*&---------------------------------------------------------------------*
*& Report  ZMM_MI04_BDC
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZMM_MI04_BDC.




DATA:  bdcdata_wa  TYPE bdcdata,
       bdcdata_tab TYPE TABLE OF bdcdata,
       opt         TYPE ctu_params.


DATA: it_bdcdata  LIKE bdcdata OCCURS 0 WITH HEADER LINE.

*----- Messages of call transaction
DATA: it_bdcmsgcoll  LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.


*----- Local Variable to Capture the G/L Account Data
DATA:      lv_dynnr      LIKE t019-dynnr,   "Screen Number
           lv_winfk      LIKE t019w-winfk,  "Window Function Code
           lv_winnr      LIKE t019w-winnr,  "Window Number
           lv_mpool      LIKE t019w-mpool,  "Module Pool
           lv_opt        LIKE ctu_params.   "Screen Mode
*lv_opt = 'N'.
*----- To Capture the File Path into the string
DATA:    lv_file_string  TYPE string,
         lv_messg        TYPE string,
         lv_ok_code(5)   TYPE c.

DATA: V_COUNT1 TYPE I.
DATA: V_COUNT(3) TYPE C.
DATA: V_CHAR(25).

*----------------------------------------------------------------------*
*  Constants Declaration
*----------------------------------------------------------------------*
CONSTANTS:  c_delim      TYPE c                  VALUE cl_abap_char_utilities=>horizontal_tab,
            c_nodata                             VALUE ' ',
            c_char_a     TYPE c                  VALUE 'A',
            c_char_d     TYPE c                  VALUE 'D',
            c_char_f     TYPE c                  VALUE 'F',
            c_char_k     TYPE c                  VALUE 'K',
            c_char_o     TYPE c                  VALUE 'O',
            c_char_p     TYPE c                  VALUE 'P',
            c_char_m     TYPE c                  VALUE 'M',
            c_char_s     TYPE c                  VALUE 'S',
            c_char_w     TYPE c                  VALUE 'W',
            c_char_x     TYPE c                  VALUE 'x'.

TYPES: begin of ty_final,
* data element: IBLNR
        IBLNR_001(010),
* data element: GJAHR
        GJAHR_002(004),
* data element: DZLDAT
        ZLDAT_003(010),
* data element: I_ERFMG
        ERFMG(017),
*  * data element: XNULL
        XNULL(001),
     end of ty_final.

 TYPES :BEGIN OF ty_final_temp,
* data element: I_ERFMG
        ERFMG(017),
*  * data element: XNULL
        XNULL(001),
END OF ty_final_temp.

          DATA : it_final TYPE STANDARD TABLE OF ty_final,
                 wa_final TYPE ty_final,
                 it_final_temp TYPE STANDARD TABLE OF ty_final_temp,
                 wa_final_temp TYPE ty_final_temp.
*          Data: v_matnr like wa_final-matnr,
*       v_werks like wa_final-werks,
*       v_vornr like wa_final-vornr value '0010'.

daTA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.


PARAMETERS: P_FILE TYPE LOCALFILE DEFAULT 'D:\BDC\MI04.TXT'.
   START-OF-SELECTION.
DATA: W_FILE TYPE STRING.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      file_name = p_file.

START-OF-SELECTION.

*  v_mode = p_mode.
  w_file = p_file.

CALL FUNCTION 'GUI_UPLOAD'
   EXPORTING
      filename                = w_file
      filetype                = 'DAT'
      has_field_separator     = 'X'
   TABLES
     DATA_TAB                      = IT_FINAL
          .
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*  CALL FUNCTION 'F4_FILENAME'
*    IMPORTING
*      file_name = p_file.

BREAK 10115.
LOOP AT it_final INTO wa_final.

  MOVE-CORRESPONDING wa_final to wa_final_temp.

  APPEND wa_final_temp to it_final_temp.
ENDLOOP.


*PERFORM getdata.
PERFORM bdc.

END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  BDC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BDC .


*  BREAK 10115.
*if sy-subrc <> 0. exit. endif.
*  READ TABLE it_final INTO wa_final INDEX sy-tabix.
LOOP AT it_final INTO wa_final.

perform bdc_dynpro      using 'SAPMM07I' '0701'.
perform bdc_field       using 'BDC_CURSOR'
                              'RM07I-IBLNR'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'RM07I-IBLNR'
                              wa_final-IBLNR_001.
perform bdc_field       using 'RM07I-GJAHR'
                              wa_final-GJAHR_002.
perform bdc_field       using 'RM07I-ZLDAT'
                              wa_final-ZLDAT_003.
perform bdc_dynpro      using 'SAPMM07I' '0731'.
perform bdc_field       using 'BDC_CURSOR'
                              'ISEG-XNULL(06)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=P++'.
*endon.



LOOP at it_final_temp INTO wa_final_temp.
  BREAK 10115.
 IF  V_COUNT = 7.
  CLEAR V_COUNT.
  CLEAR V_COUNT1.
perform bdc_dynpro      using 'SAPMM07I' '0731'.
perform bdc_field       using 'BDC_CURSOR'
                              'ISEG-XNULL(06)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=P++'.
 ENDIF.
*IF  v_count LE 8.
V_COUNT1 = V_COUNT1 + 1.
V_COUNT = V_COUNT1.
CONDENSE V_COUNT.
CLEAR V_CHAR.

*perform bdc_field       using 'ISEG-MATNR(01)'
*                              wa_final-MATNR_01_008.
*perform bdc_field       using 'ISEG-ERFMG(01)'
*                              record-ERFMG_01_004.

CLEAR V_CHAR.
CONCATENATE 'ISEG-ERFMG(' V_COUNT ')' INTO V_CHAR.
perform bdc_field       using v_char
                            wa_final_TEMP-ERFMG.

*perform bdc_field       using 'ISEG-XNULL(01)'
*                              record-XNULL_01_010.

CLEAR V_CHAR.
CONCATENATE 'ISEG-XNULL(' V_COUNT ')' INTO V_CHAR.
perform bdc_field       using v_char
                            wa_final_TEMP-XNULL.

*IF  V_COUNT GE 16.
*
*
*
*perform bdc_dynpro      using 'SAPMM07I' '0721'.
*perform bdc_field       using 'BDC_CURSOR'
*                              'ISEG-MATNR(02)'.
*perform bdc_field       using 'BDC_OKCODE'
*                              '=P++'.
*
*CLEAR V_CHAR.
*CONCATENATE 'ISEG-MATNR(' V_COUNT ')' INTO V_CHAR.
*perform bdc_field       using v_char
*                            wa_final_TEMP-MATNR.
*
*
*perform bdc_field       using 'ISEG-MATNR(01)'
*                              wa_final_TEMP-MATNR.
*ENDIF.







*ENDIF.



endloop.
perform bdc_dynpro      using 'SAPMM07I' '0731'.
perform bdc_field       using 'BDC_CURSOR'
                              'ISEG-ERFMG(01)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=BU'.


lv_opt = 'A'.
*------ Call the Tcode for the data upload
     CALL TRANSACTION 'MI04'
          USING it_bdcdata
          OPTIONS FROM lv_opt
          MESSAGES INTO it_bdcmsgcoll.

     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
       EXPORTING
         wait = 'X'.
*perform bdc_field   using 'BDC_OKCODE'
*                               '=BU'.
    REFRESH it_bdcdata.
*  endat.
*ENDLOOP.
COMMIT WORK.

*ENDIF.
ENDLOOP.

*------ Looping at BDCMSGCOLL to Track the Errors
   LOOP AT it_bdcmsgcoll.
     CALL FUNCTION 'FORMAT_MESSAGE'
       EXPORTING
         id        = it_bdcmsgcoll-msgid
         lang      = it_bdcmsgcoll-msgspra
         no        = it_bdcmsgcoll-msgnr
         v1        = it_bdcmsgcoll-msgv1
         v2        = it_bdcmsgcoll-msgv2
         v3        = it_bdcmsgcoll-msgv3
         v4        = it_bdcmsgcoll-msgv4
       IMPORTING
         msg       = lv_messg
       EXCEPTIONS
         not_found = 1
         OTHERS    = 2.
     IF sy-subrc <> 0.                                       "#EC
       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
     ELSE.
       WRITE:/ it_bdcmsgcoll-msgtyp, lv_messg.
     ENDIF.
   ENDLOOP.

ENDFORM.                    " BDC
*&---------------------------------------------------------------------*
**&      Form  BDC_DYNPRO
**&---------------------------------------------------------------------*
**       text
**----------------------------------------------------------------------*
**      -->P_0323   text
**      -->P_0324   text
**----------------------------------------------------------------------*
FORM bdc_dynpro  USING  program dynpro.
*                          value(p_0324).

   CLEAR it_bdcdata.
   it_bdcdata-program  = program.
   it_bdcdata-dynpro   = dynpro.
   it_bdcdata-dynbegin = 'X'.
   APPEND it_bdcdata.
ENDFORM.                    " BDC_DYNPRO
*&---------------------------------------------------------------------*
*&      Form  BDC_FIELD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0328   text
*      -->P_0329   text
*----------------------------------------------------------------------*
FORM bdc_field  USING   fnam fval.
   "  value(p_0328)
   "value(p_0329).
  BREAK 10115.
   IF fval <> c_nodata.
     CLEAR it_bdcdata.
     it_bdcdata-fnam = fnam.
     it_bdcdata-fval = fval.
     APPEND it_bdcdata.
  ENDIF.

ENDFORM.

Saturday, July 27, 2013

Data UPload or Download using Dataset

ENHANCEMENT 1  ZVF01_DATA_DOWNLOAD_RFC.    "active version
*REQ NO: DEVK904147 DATE: 21.06.2013
*

TYPE-POOLSTRUXS.

 TYPE-POOLSTRUXS.
*  DATA: P_FILE LIKE SAPB-SAPPFAD.
  DATAL_STRING TYPE STRING.
  DATA CON_TAB  TYPE VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

  DATA HEX(1TYPE VALUE ';'"Tab Space
  V_CON TYPE STRING," TRUXS_T_TEXT_DATA," type c occurs 0.,
  SEP(2TYPE C  VALUE ';'.
  DATAIT_TEMP TYPE TRUXS_T_TEXT_DATA.


TYPESBEGIN OF ty_vbrp,
   vbeln TYPE vbrp-vbeln,
   posnr TYPE VBRP-POSNR,
   matnr TYPE  VBRP-MATNR,
   arktx TYPE VBRP-ARKTX,
   fkimg TYPE  VBRP-FKIMG,
   vgbel TYPE vBRP-VGBEL,
   END OF ty_vbrp.


 TYPESBEGIN OF TY,
    VBELN TYPE  VBRK-VBELN,
    FKART TYPE  VBRK-FKART,
    POSNR TYPE   VBRP-POSNR,
    MATNR TYPE   VBRP-MATNR,
    ARKTX TYPE   VBRP-ARKTX,
    FKIMG(17)," TYPE   VBRP-FKIMG,
    VGBEL TYPE   VBRP-VGBEL,
    zdate(10),
    ztime(8),
    KUNAG TYPE  VBRK-KUNAG,
    zdate1(10),
    ztime1(8),
    ERNAM TYPE   VBRK-ERNAM,
    END OF TY.

  TYPESBEGIN OF ITAB,
   F1(25),
 END OF ITAB.

  DATAIT TYPE TABLE OF TY,
        WA LIKE LINE OF IT,
        it_vbrp TYPE TABLE OF ty_vbrp,
        WA_VBRK like xVBRK,
        WA_VBRP like LINE OF it_VBRP,
        ITAB1 TYPE TABLE OF ITAB,
        W1 LIKE LINE OF ITAB1.

  DATAP_FILE TYPE SAPB-SAPPFAD."RLGRAP-FILENAME.
  DATASTR(30),
        fol(15),
        clnt(15),
        STRING1(15),
        STRING2(5),
        FILE_NAME TYPE STRING.

 DATA:   V_DATE(10TYPE C,
         V_DATE1(10TYPE C,
         V_DATE2(10TYPE C,
         V_DATE3(8TYPE C,
         V_DATE4(8TYPE C,
         ZYY(4TYPE C,
         ZMM(2TYPE C,
         ZDD(2TYPE C,
         ZYY1(4TYPE C,
         ZMM1(2TYPE C,
         ZDD1(2TYPE C,
         ZYY3(2TYPE C,
         ZMM3(2TYPE C,
         ZDD3(2TYPE C,
         ZYY4(2TYPE C,
         ZMM4(2TYPE C,
         ZDD4(2TYPE C,
         ZDATE(10TYPE C,
         ZDATE1(10TYPE C,
         ZTIME(8TYPE C,
         ZTIME1(8TYPE C.



if sy-tcode eq 'VF01'." or sy-tcode eq 'VF02'.

    STRING1  xVBRK-VBELN.
    V_DATE   xVBRK-FKDAT.
    V_DATE1  xVBRK-ERDAT.
    V_DATE3  xVBRK-ERZET.
    V_DATE4  xVBRK-ERZET.

  if xvbrk-mandt eq '200'.
    clnt '/DEV:/'.
  ELSEIF XVBRK-MANDT EQ '110'.
    clnt '/qas/'.
  ELSEIF XVBRK-MANDT EQ '100'.
    clnt '/pas/'.
  ENDIF.

  FOL 'Billing/'.
  STRING2 '.txt'.
  TRANSLATE STRING2 TO LOWER CASE.
  CONCATENATE clnt fol string1 string2 into p_file." file_name.

  ZYY V_DATE+0(4).
  ZMM V_DATE+4(2).
  ZDD V_DATE+6(2).
  ZYY1 V_DATE1+0(4).
  ZMM1 V_DATE1+4(2).
  ZDD1 V_DATE1+6(2).
  ZYY3 V_DATE3+0(2).
  ZMM3 V_DATE3+2(2).
  ZDD3 V_DATE3+4(2).
  ZYY3 V_DATE4+0(2).
  ZMM3 V_DATE4+2(2).
  ZDD3 V_DATE4+4(2).
  CONCATENATE ZDD '.' ZMM '.' ZYY INTO ZDATE.
  CONCATENATE ZDD1 '.' ZMM1 '.' ZYY1 INTO ZDATE1.
  CONCATENATE ZYY3 ':' ZMM3 ':' ZDD3 INTO ZTIME.
  CONCATENATE ZYY4 ':' ZMM4 ':' ZDD4 INTO ZTIME1.

  select vbeln POSNR  MATNR ARKTX FKIMG VGBEL
    from vbrp
    INTO CORRESPONDING FIELDS OF TABLE it_vbrp
    WHERE vbeln xvbrk-vbeln.

OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

CONCATENATE 'Biilig No' 'Bill Type' 'Item No' 'Material Code' 'Materail Desc' 'Bill Qty'  'Ref Doc(DeliveryNo)' 'Billing Date'  'Billing Time'  'Sold To Party' 'Entry Date'  'Entry Time'  'Entered By'
  INTO V_CON SEPARATED BY CON_TAB.
  TRANSFER V_CON TO P_FILE.

  LOOP AT it_VBRP INTO WA_VBRP.
    WA-VBELN =  wa_VBRP-VBELN.
    WA-POSNR =  wa_VBRP-POSNR.
    WA-MATNR =  wa_VBRP-MATNR.
    WA-ARKTX =  wa_VBRP-ARKTX.
    WA-FKIMG =  wa_VBRP-FKIMG.
    WA-VGBEL =  wa_VBRP-VGBEL.
    WA-FKART =  xVBRK-FKART.
    WA-zdate =  ZDATE.
    WA-ztime =  ZTIME.
    WA-KUNAG =  xVBRK-KUNAG.
    WA-zdate1 ZDATE1.
    WA-ztime1 =  ZTIME.
    WA-ERNAM =  xVBRK-ERNAM.

   CONCATENATE WA-VBELN WA-POSNR WA-MATNR WA-ARKTX WA-FKIMG WA-VGBEL WA-FKART
   WA-zdate WA-ztime WA-KUNAG WA-zdate1 WA-ztime1 WA-ERNAM
    INTO V_CON SEPARATED BY CON_TAB.
    TRANSFER V_CON TO P_FILE.
    CLEARWAWA_VBRPWA_VBRK.
  ENDLOOP.

CLOSE DATASET P_FILE.
ENDIF.



ENDENHANCEMENT.
*$*$-End:   (1)---------------------------------------------------------------------------------$*$*
ENDFUNCTION.

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