REPORT

zalv_document_segment LINE-SIZE 180.

******************/ TYPE POOLS DECLARATION /***************
TYPE-POOLS: slis.
******************/ TYPES DECLARATION /********************
TYPES: BEGIN OF ty_mseg,
"Document Segment: Material
mblnr TYPE mseg-mblnr,
mjahr TYPE mseg-mjahr,
bwart TYPE mseg-bwart,
matnr TYPE mseg-matnr,
werks TYPE mseg-werks,
ebeln TYPE mseg-ebeln,
ebelp TYPE mseg-ebelp,
END OF ty_mseg.
TYPES: BEGIN OF ty_mkpf,
mblnr TYPE mkpf-mblnr,
mjahr TYPE mkpf-mjahr,
budat TYPE mkpf-budat,
END OF ty_mkpf.

"Header:Material Document

TYPES: BEGIN OF ty_makt,
matnr TYPE makt-matnr,
maktx TYPE makt-maktx,
END OF ty_makt.

"Material Descriptions

TYPES: BEGIN OF ty_ekko,
ebeln TYPE ekko-ebeln,
lifnr TYPE ekko-lifnr,
END OF ty_ekko.

"Purchasing Document Header

TYPES: BEGIN OF ty_lfa1,
lifnr TYPE lfa1-lifnr,
name1 TYPE lfa1-name1,
END OF ty_lfa1.

"Vendor Master (General Section)

TYPES: BEGIN OF
mblnr TYPE
mjahr TYPE
bwart TYPE
matnr TYPE
werks TYPE
ebeln TYPE
ebelp TYPE
budat TYPE
maktx TYPE
lifnr TYPE
name1 TYPE

"Final Table

ty_final,
mseg-mblnr,
mseg-mjahr,
mseg-bwart,
mseg-matnr,
mseg-werks,
mseg-ebeln,
mseg-ebelp,
mkpf-budat,
makt-maktx,
ekko-lifnr,
lfa1-name1,

tt_makt. ty_lfa1. tt_ekko TYPE STANDARD TABLE OF ty_ekko. ty_mkpf. PERFORM screen_validations. slis_fieldcat_alv. ******************/ PARAMETERS /**************************** PARAMETERS: p_werks TYPE mseg-werks. tt_makt TYPE STANDARD TABLE OF ty_makt. ******************/ SELECTION-SCREEN DESIGN /*************** SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. SELECTION-SCREEN END OF BLOCK b1. ty_ekko. . PERFORM display_output. tt_final TYPE STANDARD TABLE OF ty_final. tt_lfa1. ty_final. tt_ekko. slis_t_fieldcat_alv. ******************/ SELECT-OPTIONS /************************ SELECT-OPTIONS: s_mblnr FOR wa_mseg-mblnr. PERFORM getdata. ty_makt. ******************/ DATA: it_mseg TYPE it_mkpf TYPE it_makt TYPE it_ekko TYPE it_lfa1 TYPE it_final TYPE it_fcat TYPE INTERNAL TABLE DECLARATION /*********** tt_mseg. tt_mkpf.END OF ty_final. ******************/ DATA: wa_mseg TYPE wa_mkpf TYPE wa_makt TYPE wa_ekko TYPE wa_lfa1 TYPE wa_final TYPE wa_fcat TYPE WORKAREA DECLARATION /***************** ty_mseg. ******************/ GET_DATA_FROM_TABLES /******************* START-OF-SELECTION. ******************/ SELECTION-SCREEN VALIDATION /************ AT SELECTION-SCREEN. tt_mkpf TYPE STANDARD TABLE OF ty_mkpf. tt_final. ******************/ DISPLAY_DATA_FROM_FINAL_TABLE /*********** END-OF-SELECTION. PERFORM fieldcat. ******************/ TABLE TYPES DECLARATION /************** TYPES: tt_mseg TYPE STANDARD TABLE OF ty_mseg. PERFORM process_data. tt_lfa1 TYPE STANDARD TABLE OF ty_lfa1.

MESSAGE 'Enter plant number' TYPE 'E'. IF sy-subrc NE 0. ENDIF. ENDFORM. PERFORM getdata_from_mkpf. ELSE.p2 text *----------------------------------------------------------------------* FORM getdata . ENDFORM. PERFORM getdata_from_mseg. IF p_werks IS INITIAL.p2 text *----------------------------------------------------------------------* FORM screen_validations . ENDIF. PERFORM get_data_from_ekko. MESSAGE 'Plant not available' TYPE 'E'. " GETDATA *&---------------------------------------------------------------------* *& Form GETDATA_FROM_MSEG *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-. PERFORM get_data_from_makt. " SCREEN_VALIDATIONS *&---------------------------------------------------------------------* *& Form GETDATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-. DATA: gv_werks TYPE mseg-werks. SELECT mblnr mjahr bwart matnr werks . SELECT SINGLE werks FROM t001w INTO gv_werks WHERE werks EQ p_werks.p2 text *----------------------------------------------------------------------* FORM getdata_from_mseg .*&---------------------------------------------------------------------* *& Form SCREEN_VALIDATIONS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-. PERFORM get_data_from_lfa1.

SORT it_mkpf BY mblnr mjahr. IF sy-subrc EQ 0.ebeln ebelp FROM mseg INTO TABLE it_mseg WHERE mblnr IN s_mblnr AND werks EQ p_werks. ENDIF. SELECT matnr maktx FROM makt INTO TABLE it_makt FOR ALL ENTRIES IN it_mseg WHERE matnr EQ it_mseg-matnr AND spras EQ sy-langu. SORT it_makt BY matnr. IF sy-subrc EQ 0. " GETDATA_FROM_MSEG *&---------------------------------------------------------------------* *& Form GETDATA_FROM_MKPF *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-. ENDIF. MESSAGE 'No data found for the given details' TYPE 'E'.p2 text *----------------------------------------------------------------------* FORM getdata_from_mkpf .p2 text *----------------------------------------------------------------------* FORM get_data_from_makt . IF it_mseg IS NOT INITIAL. ENDIF. SELECT mblnr mjahr budat FROM mkpf INTO TABLE it_mkpf FOR ALL ENTRIES IN it_mseg WHERE mblnr EQ it_mseg-mblnr AND mjahr EQ it_mseg-mjahr. IF it_mseg IS NOT INITIAL. IF sy-subrc NE 0. ENDIF. ENDFORM. " GET_DATA_FROM_MAKT . ENDIF. " GETDATA_FROM_MKPF *&---------------------------------------------------------------------* *& Form GET_DATA_FROM_MAKT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-. ENDFORM. ENDFORM.

IF sy-subrc EQ 0. ENDIF. ENDIF. ENDFORM. ENDIF. " GET_DATA_FROM_LFA1 *&---------------------------------------------------------------------* *& Form PROCESS_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-. SELECT ebeln lifnr FROM ekko INTO TABLE it_ekko FOR ALL ENTRIES IN it_mseg WHERE ebeln EQ it_mseg-ebeln. IF sy-subrc EQ 0. IF it_ekko IS NOT INITIAL. SELECT lifnr name1 FROM lfa1 INTO TABLE it_lfa1 FOR ALL ENTRIES IN it_ekko WHERE lifnr EQ it_ekko-lifnr.p2 text *----------------------------------------------------------------------* FORM get_data_from_lfa1 . ENDFORM. ENDIF. SORT it_ekko BY ebeln. IF it_mseg IS NOT INITIAL.*&---------------------------------------------------------------------* *& Form GET_DATA_FROM_EKKO *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-. LOOP AT it_mseg INTO wa_mseg. .p2 text *----------------------------------------------------------------------* FORM process_data .p2 text *----------------------------------------------------------------------* FORM get_data_from_ekko . " GET_DATA_FROM_EKKO *&---------------------------------------------------------------------* *& Form GET_DATA_FROM_LFA1 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-. SORT it_lfa1 BY lifnr. MOVE-CORRESPONDING wa_mseg TO wa_final.

READ TABLE it_lfa1 INTO wa_lfa1 WITH KEY lifnr = wa_ekko-lifnr BINARY SEA RCH. wa_final-name1 = wa_lfa1-name1. IF sy-subrc EQ 0.p2 text *----------------------------------------------------------------------* FORM display_output . CLEAR: wa_mseg. APPEND wa_final TO it_final. ENDLOOP. wa_final. wa_ekko. wa_final-lifnr = wa_ekko-lifnr. wa_mkpf. READ TABLE it_makt INTO wa_makt WITH KEY matnr = wa_mseg-matnr BINARY SEA RCH. wa_makt. ENDIF. ENDIF.READ TABLE it_mkpf INTO wa_mkpf WITH KEY mblnr = wa_mseg-mblnr mjahr = wa_mseg-mjahr BINARY SEA RCH. IF sy-subrc EQ 0. ENDFORM. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = ' ' * I_BUFFER_ACTIVE = ' ' * I_CALLBACK_PROGRAM = ' ' * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' * I_STRUCTURE_NAME = * I_BACKGROUND_ID = ' ' * I_GRID_TITLE = * I_GRID_SETTINGS = . " PROCESS_DATA *&---------------------------------------------------------------------* *& Form DISPLAY_OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-. ENDIF. READ TABLE it_ekko INTO wa_ekko WITH KEY ebeln = wa_mseg-ebeln BINARY SEA RCH. ENDIF. wa_lfa1. wa_final-maktx = wa_makt-maktx. IF sy-subrc EQ 0. IF sy-subrc EQ 0. wa_final-budat = wa_mkpf-budat.

" DISPLAY_OUTPUT *&---------------------------------------------------------------------* *& Form FIELDCAT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-. ENDFORM. PERFORM fill_fieldcat USING 'MBLNR' 'Material Document' 15. IF sy-subrc <> 0.p2 text *----------------------------------------------------------------------* FORM fieldcat . Implement suitable error handling here ENDIF. .* * * * * * * * * * * * * * * * * * * * * * * * * * * * IS_LAYOUT = it_fieldcat = it_fcat IT_EXCLUDING = IT_SPECIAL_GROUPS = IT_SORT = IT_FILTER = IS_SEL_HIDE = I_DEFAULT = 'X' I_SAVE = ' ' IS_VARIANT = IT_EVENTS = IT_EVENT_EXIT = IS_PRINT = IS_REPREP_ID = I_SCREEN_START_COLUMN = 0 I_SCREEN_START_LINE = 0 I_SCREEN_END_COLUMN = 0 I_SCREEN_END_LINE = 0 I_HTML_HEIGHT_TOP = 0 I_HTML_HEIGHT_END = 0 IT_ALV_GRAPHICS = IT_HYPERLINK = IT_ADD_FIELDCAT = IT_EXCEPT_QINFO = IR_SALV_FULLSCREEN_ADAPTER = IMPORTING E_EXIT_CAUSED_BY_CALLER = ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = it_final EXCEPTIONS program_error = 1 OTHERS = 2 .

wa_fcat-outputlen = length. PERFORM fill_fieldcat USING 'MAKTX' 'Material Description' 40. ENDFORM. wa_fcat-seltext_m = ftext. PERFORM fill_fieldcat USING 'NAME1' 'Vendor Name' 35. PERFORM fill_fieldcat USING 'EBELN' 'PO Number' 10. PERFORM fill_fieldcat USING 'BUDAT' 'Posting Date' 10. ENDFORM. wa_fcat-tabname = 'IT_FINAL'. PERFORM fill_fieldcat USING 'LIFNR' 'Vendor No' 9. " FILL_FIELDCAT . PERFORM fill_fieldcat USING 'EBELP' 'PO Item No' 10. PERFORM fill_fieldcat USING 'WERKS' 'Plant' 4. CLEAR wa_fcat. APPEND wa_fcat TO it_fcat. wa_fcat-fieldname = fnam. PERFORM fill_fieldcat USING 'MATNR' 'Material Number' 18. " FILL_FIELDCAT *&---------------------------------------------------------------------* *& Form FILL_FIELDCAT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_0673 text * -->P_0674 text * -->P_15 text *----------------------------------------------------------------------* FORM fill_fieldcat USING fnam ftext length. PERFORM fill_fieldcat USING 'BWART' 'Movement Type' 13.PERFORM fill_fieldcat USING 'MJAHR' 'Document Year' 13.