.

.*&---------------------------------------------------------------------* *& Report ZSTOCK_REGISTER *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZSTOCK_REGISTER.

"PURCHASE DOCUMENT NO kostl TYPE mseg-kostl."UNIT werks TYPE mseg-werks."MOVEMENT TYPE END OF zstruc."MATERIAL NO. MBLNR TYPE MSEG-MBLNR. TYPE-POOLS: slis."QUANTITY erfme TYPE mseg-erfme."COST CENTER lifnr TYPE mseg-lifnr. makt."VENDOR ACC. maktx TYPE makt-maktx. bwart TYPE mseg-bwart. t156t."POSTING DATE bktxt TYPE mkpf-bktxt. erfmg TYPE mseg-erfmg."PLANT NO lgort TYPE mseg-lgort."MATERIAL NO.*REPORT zstock."HEADER TEXT btext TYPE t156t-btext.NO. matnr TYPE mseg-matnr. TYPES: BEGIN OF zstruc. TABLES: mseg."QUANTITY erfme TYPE mseg-erfme. mkpf."MOVEMENT TYPE TEXT ebeln TYPE mseg-ebeln."UNIT ."MATERIAL DESCRIPTION spras type makt-spras . TYPES: BEGIN OF zstruc1."STORAGE LOCATION budat TYPE mkpf-budat. matnr TYPE mseg-matnr. erfmg TYPE mseg-erfmg.

MBLNR TYPE MKPF-MBLNR."STORAGE LOCATION ebeln TYPE mseg-ebeln."PLANT NO lgort TYPE mseg-lgort."MOVEMENT TYPE END OF zstruc1.NO."MATERIAL DESCRIPTION SPRAS TYPE MAKT-SPRAS."POSTING DATE bktxt TYPE mkpf-bktxt."PURCHASE DOCUMENT NO kostl TYPE mseg-kostl. budat TYPE mkpf-budat. TYPES: BEGIN OF zstruc2. MATNR TYPE MSEG-MATNR. END OF zstruc2. SPRAS TYPE T156T-SPRAS."COST CENTER lifnr TYPE mseg-lifnr.werks TYPE mseg-werks."HEADER TEXT END OF zstruc3. bwart TYPE mseg-bwart."MOVEMENT TYPE TEXT END OF zstruc4. TYPES: BEGIN OF zstruc3. maktx TYPE makt-maktx. TYPES: BEGIN OF zstruc4. btext TYPE t156t-btext."VENDOR ACC. .

wa_fieldcat TYPE slis_fieldcat_alv. SELECTION-SCREEN: END OF BLOCK b1.DATA: v_CPROG TYPE sy-CPROG. SELECT-OPTIONS: MATERIAL FOR mseg-matnr OBLIGATORY. DATA: K TYPE I. wa_events TYPE slis_alv_event. itab1 type standard table of zstruc. SELECT-OPTIONS: date FOR mkpf-budat OBLIGATORY. WA_sort TYPE slis_sortinfo_alv. It_sort TYPE slis_t_sortinfo_alv. *provide select-options SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. . DATA: fn TYPE slis_fieldname. layout_in TYPE slis_layout_alv. itab TYPE standard TABLE OF zstruc. *v_CPROG = sy-CPROG. it_fieldcat TYPE slis_t_fieldcat_alv. it_events TYPE slis_t_event.

*select g~matnr * k_maktx * g~erfmg * g~erfme * g~werks * g~lgort * f~budat * f~bktxt * t1~btext * g~ebeln * g~kostl * g~lifnr * g~bwart * into table itab from mseg as g inner join makt as k * on g~mandt = k~mandt * inner join mkpf as f on g~mandt = f~mandt "it is for field catalog . * SELECT DISTINCT kna1~name1 makt~maktx zweigh~lgort SUM( zweigh~ntwht ) * INTO TABLE itab FROM * kna1 INNER JOIN zweigh ON kna1~kunnr = zweigh~kunnr INNER JOIN makt ON makt~matnr = zweigh~matnr *WHERE zweigh~erdat IN date GROUP BY zweigh~lgort kna1~name1 makt~maktx.START-OF-SELECTION.

"it is for events " DATA SORTING AND SUBTOTAL K = SY-DBCNT. * ENDIF. PERFORM field_cat. *END-OF-SELECTION. PERFORM build_layout. PERFORM sub_get_event. * SORT itab BY matnr. *&---------------------------------------------------------------------* *& Form fetch *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-. * IF sy-subrc = 0. PERFORM DISPLAY_ALV_REPORT. PERFORM sub_populate_sort. perform fetch.p2 text *----------------------------------------------------------------------* .

FORM fetch . itab1[] = itab[]. SELECT mseg~matnr "MATERIAL NO. NO. mseg~kostl "COST CENTER mseg~lifnr "VENDOR ACC. makt~maktx "MATERIAL DESCRIPTION makt~spras mseg~erfmg "QUANTITY mseg~erfme "UNIT mseg~werks "PLANT NO mseg~lgort mkpf~budat "STORAGE LOCATION "POSTING DATE mkpf~bktxt "HEADER TEXT t156t~btext "MOVEMENT TYPE TEXT mseg~ebeln "PURCHASE DOCUMENT NO. mseg~bwart "MOVEMENT TYPE INTO TABLE itab FROM mseg INNER JOIN makt ON mseg~matnr = makt~matnr INNER JOIN mkpf ON mseg~mblnr = mkpf~mblnr INNER JOIN t156t ON mseg~bwart = t156t~bwart WHERE mkpf~budat IN date AND MSEG~MATNR IN MATERIAL AND makt~SPraS = 'E'. .

wa_fieldcat-col_pos = 1. wa_fieldcat-fieldname = 'MATNR'.'. .sort itab1 by matnr. wa_fieldcat-key = 'X'.p2 *text *----------------------------------------------------------------------* FORM field_cat . wa_fieldcat-seltext_l = 'MATERIAL NO. ENDFORM. wa_fieldcat-tabname = 'ITAB1'. delete adjacent duplicates from itab1 comparing matnr. " fetch *&---------------------------------------------------------------------* *& *Form FIELD_CAT. *&---------------------------------------------------------------------* * *text *----------------------------------------------------------------------* * --> p1 *text * <-.

wa_fieldcat-tabname = 'ITAB1'. CLEAR wa_fieldcat. APPEND wa_fieldcat TO it_fieldcat. wa_fieldcat-tabname = 'ITAB1'. wa_fieldcat-fieldname = 'ERFMG'. wa_fieldcat-col_pos = 4. wa_fieldcat-datatype = 'QUAN'. . wa_fieldcat-seltext_l = 'MATERIAL DESC'. CLEAR wa_fieldcat. wa_fieldcat-tabname = 'ITAB1'. APPEND wa_fieldcat TO it_fieldcat. wa_fieldcat-fieldname = 'ERFME'. CLEAR wa_fieldcat. wa_fieldcat-fieldname = 'MAKTX'. wa_fieldcat-col_pos = 2.APPEND wa_fieldcat TO it_fieldcat. "provide field catalog perform wa_fieldcat-col_pos = 3. * wa_fieldcat-do_sum = 'X'. APPEND wa_fieldcat TO it_fieldcat. wa_fieldcat-seltext_l = 'UNIT'. wa_fieldcat-seltext_l = 'QUANTITY.'.

CLEAR wa_fieldcat. wa_fieldcat-seltext_l = 'PLANT NO. APPEND wa_fieldcat TO it_fieldcat. wa_fieldcat-seltext_l = 'STORAGE LOCATION'. wa_fieldcat-col_pos = 5. wa_fieldcat-tabname = 'ITAB1'. wa_fieldcat-col_pos = 7. wa_fieldcat-fieldname = 'BUDAT '. wa_fieldcat-seltext_l = 'POSTING DATE'. wa_fieldcat-seltext_l = 'HEADER TEXT'. wa_fieldcat-tabname = 'ITAB1'. CLEAR wa_fieldcat. APPEND wa_fieldcat TO it_fieldcat. wa_fieldcat-col_pos = 6. CLEAR wa_fieldcat. APPEND wa_fieldcat TO it_fieldcat. wa_fieldcat-fieldname = 'BKTXT '. . wa_fieldcat-fieldname = 'LGORT'. wa_fieldcat-fieldname = 'WERKS'. CLEAR wa_fieldcat.'. wa_fieldcat-col_pos = 8. wa_fieldcat-tabname = 'ITAB1'. wa_fieldcat-tabname = 'ITAB1'.

wa_fieldcat-fieldname = 'BTEXT'. wa_fieldcat-col_pos = 10. wa_fieldcat-fieldname = 'EBELN'. CLEAR wa_fieldcat. APPEND wa_fieldcat TO it_fieldcat. wa_fieldcat-seltext_l = 'PURCHASE DOC. wa_fieldcat-seltext_l = 'MOVEMENT TYPE TEXT'. wa_fieldcat-fieldname = 'LIFNR'. wa_fieldcat-tabname = 'ITAB1'. CLEAR wa_fieldcat. CLEAR wa_fieldcat. APPEND wa_fieldcat TO it_fieldcat. wa_fieldcat-col_pos = 11. wa_fieldcat-seltext_l = 'COST CENTER'. CLEAR wa_fieldcat. wa_fieldcat-col_pos = 9. wa_fieldcat-tabname = 'ITAB1'. wa_fieldcat-tabname = 'ITAB1'. wa_fieldcat-tabname = 'ITAB1'. NO. .APPEND wa_fieldcat TO it_fieldcat.'. APPEND wa_fieldcat TO it_fieldcat. wa_fieldcat-fieldname = 'KOSTL'. wa_fieldcat-col_pos = 12.

ENDFORM. NO." FIELD_CAT *&---------------------------------------------------------------------* *& *Form BUILD_LAYOUT **&---------------------------------------------------------------------* ** *text **----------------------------------------------------------------------* ** --> p1 *text ** <-. APPEND wa_events TO it_events. wa_fieldcat-fieldname = 'BWART'. wa_events-form = 'TOP_PAGE'. APPEND wa_fieldcat TO it_fieldcat.'. wa_fieldcat-col_pos = 13. CLEAR wa_fieldcat. APPEND wa_fieldcat TO it_fieldcat. wa_events-name = 'TOP_OF_PAGE'. CLEAR wa_fieldcat.wa_fieldcat-seltext_l = 'VENDOR ACC. wa_fieldcat-seltext_l = 'MOVEMENT TYPE'.p2 *text . wa_fieldcat-tabname = 'ITAB1'.

clear layout_in. "Sets fcode for when double "click(press f2) layout_in-zebra = 'X'. endform. * Set layout field for row attributes(i. layout_in-f2code = 'DISP'. * layout_in-totals_text *= 'Totals'(201). * layout_in-totals_only *= 'X'. * layout_in-group_change_edit = 'X'. " BUILD_LAYOUT *&---------------------------------------------------------------------* *& *Form SUB_POPULATE_SORT **&---------------------------------------------------------------------* ** *text * **----------------------------------------------------------------------* ** --> p1 .e. color) layout_in-info_fieldname = 'LINE_COLOR'.*----------------------------------------------------------------------* form BUILD_LAYOUT . layout_in-header_text = 'helllllo'. layout_in-colwidth_optimize = 'X'. layout_in-no_input = 'X'.

* gs_sort-spos = '02'. CLEAR WA_sort. * gs_sort-up = 'X'. "****CRUCIAL STATEMENT***** * APPEND gs_sort TO gt_sort. * gs_sort-fieldname = 'NTWHT'. WA_sort-tabname = 'itab1'. * gs_sort-fieldname = 'LGORT'. * gs_sort-tabname = 'itab'. * gs_sort-subtot = 'X'. * gs_sort-subtot = 'X'. * gs_sort-tabname = 'itab'. APPEND WA_SORT TO IT_SORT.p2 *text *----------------------------------------------------------------------* form SUB_POPULATE_SORT . "****CRUCIAL STATEMENT***** . WA_sort-up = 'X'. WA_sort-subtot = 'X'. WA_sort-fieldname = 'MATNR'. * gs_sort-spos = '01'.*text ** <-. * gs_sort-up = 'X'.

*CONSTANTS : c_formname_subtotal_text TYPE slis_formname VALUE 'SUBTOTAL_TEXT'. . *CALL FUNCTION 'REUSE_ALV_EVENTS_GET' *EXPORTING *i_list_type = 4 *IMPORTING * et_events *= it_events *EXCEPTIONS *list_type_wrong = 0 *OTHERS *= 0. *DATA: l_s_event TYPE slis_alv_event. " SUB_POPULATE_SORT *&---------------------------------------------------------------------* *& *Form SUB_GET_EVENT **&---------------------------------------------------------------------* ** *text **----------------------------------------------------------------------* ** --> p1 *text ** <-.p2 *text **----------------------------------------------------------------------* form SUB_GET_EVENT .endform.

IF sy-subrc = 0. * Subtotal READ TABLE it_events INTO wa_events WITH KEY name = 'SUBTOTAL_TEXT'. ENDIF. endform. IF SY-SUBRC <> 0. WA_EVENTS-FORM = 'SUBTOTAL'. " SUB_GET_EVENT *&---------------------------------------------------------------------* *& *Form DISPLAY_ALV_REPORT .CALL FUNCTION 'REUSE_ALV_EVENTS_GET' EXPORTING I_LIST_TYPE =4 IMPORTING ET_EVENTS = it_events EXCEPTIONS LIST_TYPE_WRONG OTHERS =1 =2 . * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. MODIFY it_events FROM WA_eventS INDEX sy-tabix TRANSPORTING FORM. ENDIF.

p2 *text *----------------------------------------------------------------------* form DISPLAY_ALV_REPORT .**&---------------------------------------------------------------------* ** *text **----------------------------------------------------------------------* ** --> p1 *text ** <-. IF sy-subrc <> 0. v_CPROG = sy-CPROG. . MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = V_CPROG is_layout = layout_in it_fieldcat = it_fieldcat i_default = 'X' i_grid_title = 'STOCK REGISTER' IT_SORT = IT_SORT TABLES t_outtab = itab1 EXCEPTIONS program_error = 1 OTHERS = 2.

endform.ENDIF. " DISPLAY_ALV_REPORT .

Sign up to vote on this title
UsefulNot useful