REPORT Z_OOALV_REPORT1.
TABLES: EKKO, EKPO, LFA1, MAKT.
TYPES: SLIS.
TYPES: BEGIN OF TY_EKKO,
EBELN TYPE EKKO-EBELN,
LIFNR TYPE EKKO-LIFNR,
BUKRS TYPE EKKO-BUKRS,
ZTERM TYPE EKKO-ZTERM,
END OF TY_EKKO,
BEGIN OF TY_EKPO,
EBELN TYPE EKPO-EBELN,
EBELP TYPE EKPO-EBELP,
MATNR TYPE EKPO-MATNR,
LGORT TYPE EKPO-LGORT,
MATKL TYPE EKPO-MATKL,
MENGE TYPE EKPO-MENGE,
END OF TY_EKPO,
BEGIN OF TY_LFA1,
LIFNR TYPE LFA1-LIFNR,
NAME1 TYPE NAME1_GP,
END OF TY_LFA1,
BEGIN OF TY_MAKT,
MATNR TYPE MAKT-MATNR,
MAKTX TYPE MAKT-MAKTX,
END OF TY_MAKT,
BEGIN OF TY_FINAL,
EBELN TYPE EKKO-EBELN,
LIFNR TYPE EKKO-LIFNR,
BUKRS TYPE EKKO-BUKRS,
ZTERM TYPE EKKO-ZTERM,
MATNR TYPE EKPO-MATNR,
EBELP TYPE EKPO-EBELP,
LGORT TYPE EKPO-LGORT,
MATKL TYPE EKPO-MATKL,
MENGE TYPE EKPO-MENGE,
NAME1 TYPE LFA1-NAME1,
MAKTX TYPE MAKT-MAKTX,
END OF TY_FINAL.
DATA: T_FCAT TYPE LVC_T_FCAT,
W_FCAT LIKE LINE OF T_FCAT,
WA_LAYOUT TYPE LVC_S_LAYO.
DATA: T_EKKO TYPE STANDARD TABLE OF TY_EKKO,
T_EKPO TYPE STANDARD TABLE OF TY_EKPO,
T_LFA1 TYPE STANDARD TABLE OF TY_LFA1,
T_MAKT TYPE STANDARD TABLE OF TY_MAKT,
T_FINAL TYPE STANDARD TABLE OF TY_FINAL.
DATA: W_EKKO TYPE TY_EKKO,
W_EKPO TYPE TY_EKPO,
W_LFA1 TYPE TY_LFA1,
W_MAKT TYPE TY_MAKT,
W_FINAL TYPE TY_FINAL.
DATA: OK_CODE TYPE SY-UCOMM.
DATA: GO_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
GO_ALV_GRID TYPE REF TO CL_GUI_ALV_GRID.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:PURCHASE FOR EKKO-EBELN,
VENDOR FOR EKKO-LIFNR,
MATERIAL FOR EKPO-MATNR.
SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
SELECT EBELN LIFNR BUKRS ZTERM
FROM EKKO
INTO TABLE T_EKKO
WHERE EBELN IN PURCHASE
AND LIFNR IN VENDOR.
IF T_EKKO IS NOT INITIAL.
SELECT EBELN EBELP MATNR LGORT MATKL MENGE
FROM EKPO
INTO TABLE T_EKPO FOR ALL ENTRIES IN T_EKKO
WHERE EBELN = T_EKKO-EBELN.
SORT T_EKPO.
ENDIF.
IF T_EKKO IS NOT INITIAL.
SELECT LIFNR NAME1
FROM LFA1
INTO TABLE T_LFA1 FOR ALL ENTRIES IN T_EKKO
WHERE LIFNR = T_EKKO-LIFNR.
ENDIF.
SELECT MATNR MAKTX
FROM MAKT
INTO TABLE T_MAKT FOR ALL ENTRIES IN T_EKPO
WHERE MATNR = T_EKPO-MATNR.
W_FCAT-FIELDNAME = 'EBELN'.
W_FCAT-SCRTEXT_M = 'PURCHSING NO'.
W_FCAT-COL_POS = 1.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'LIFNR'.
W_FCAT-SCRTEXT_M = 'VENDOR NO'.
W_FCAT-COL_POS = 2.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'BUKRS'.
W_FCAT-SCRTEXT_M = 'COMPANY CODE'.
W_FCAT-COL_POS = 3.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'ZTERM'.
W_FCAT-SCRTEXT_M = 'PAYMENT KEY'.
W_FCAT-COL_POS = 4.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'EBELP'.
W_FCAT-SCRTEXT_M = 'PURCHSING ITEM NO'.
W_FCAT-COL_POS = 5.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MATNR'.
W_FCAT-SCRTEXT_M = 'MATERIAL NO'.
W_FCAT-COL_POS = 6.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'LGORT'.
W_FCAT-SCRTEXT_M = 'STORAGE LOCATION'.
W_FCAT-COL_POS = 7.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MATKL'.
W_FCAT-SCRTEXT_M = 'MATERIAL GROUP'.
W_FCAT-COL_POS = 8.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MENGE'.
W_FCAT-SCRTEXT_M = 'QUANTITY'.
W_FCAT-COL_POS = 9.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MATKX'.
W_FCAT-SCRTEXT_M = 'MATERIAL DESCRIPTION'.
W_FCAT-COL_POS = 10.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'NAME1'.
W_FCAT-SCRTEXT_M = 'PLANT NAME'.
W_FCAT-COL_POS = 11.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
IF T_EKPO IS NOT INITIAL.
LOOP AT T_EKPO INTO W_EKPO.
W_FINAL-EBELP = W_EKPO-EBELP.
W_FINAL-MATNR = W_EKPO-MATNR.
W_FINAL-LGORT = W_EKPO-LGORT.
W_FINAL-MATKL = W_EKPO-MATKL.
W_FINAL-MENGE = W_EKPO-MENGE.
READ TABLE T_EKKO INTO W_EKKO WITH KEY EBELN = W_EKPO-EBELN.
IF SY-SUBRC = 0.
W_FINAL-EBELN = W_EKKO-EBELN.
W_FINAL-LIFNR = W_EKKO-LIFNR.
W_FINAL-BUKRS = W_EKKO-BUKRS.
W_FINAL-ZTERM = W_EKKO-ZTERM.
READ TABLE T_LFA1 INTO W_LFA1 WITH KEY LIFNR = W_EKKO-LIFNR.
IF SY-SUBRC = 0.
W_FINAL-NAME1 = W_LFA1-NAME1.
ENDIF.
ENDIF.
READ TABLE T_MAKT INTO W_MAKT WITH KEY MATNR = W_EKPO-MATNR.
IF SY-SUBRC = 0.
W_FINAL-MAKTX = W_MAKT-MAKTX.
ENDIF.
APPEND W_FINAL TO T_FINAL.
CLEAR W_FINAL.
ENDLOOP.
ENDIF.
CALL SCREEN 100.
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'DYNPROSTATUS'.
SET TITLEBAR 'TITLE1'.
ENDMODULE.
MODULE ALV_GRID OUTPUT.
IF GO_CONTAINER IS NOT BOUND.
CREATE OBJECT GO_CONTAINER
EXPORTING
CONTAINER_NAME = 'CONTAINER_1'
EXCEPTIONS
OTHERS = 6.
CREATE OBJECT GO_ALV_GRID
EXPORTING
I_PARENT = GO_CONTAINER
EXCEPTIONS
OTHERS = 5.
CALL METHOD GO_ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = WA_LAYOUT
CHANGING
IT_OUTTAB = T_FINAL
IT_FIELDCATALOG = T_FCAT
EXCEPTIONS
OTHERS = 4.
ENDIF.
ENDMODULE.
MODULE USER_COMMAND_0100 INPUT.
CASE OK_CODE.
WHEN 'BACK'.
SET SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
TABLES: EKKO, EKPO, LFA1, MAKT.
TYPES: SLIS.
TYPES: BEGIN OF TY_EKKO,
EBELN TYPE EKKO-EBELN,
LIFNR TYPE EKKO-LIFNR,
BUKRS TYPE EKKO-BUKRS,
ZTERM TYPE EKKO-ZTERM,
END OF TY_EKKO,
BEGIN OF TY_EKPO,
EBELN TYPE EKPO-EBELN,
EBELP TYPE EKPO-EBELP,
MATNR TYPE EKPO-MATNR,
LGORT TYPE EKPO-LGORT,
MATKL TYPE EKPO-MATKL,
MENGE TYPE EKPO-MENGE,
END OF TY_EKPO,
BEGIN OF TY_LFA1,
LIFNR TYPE LFA1-LIFNR,
NAME1 TYPE NAME1_GP,
END OF TY_LFA1,
BEGIN OF TY_MAKT,
MATNR TYPE MAKT-MATNR,
MAKTX TYPE MAKT-MAKTX,
END OF TY_MAKT,
BEGIN OF TY_FINAL,
EBELN TYPE EKKO-EBELN,
LIFNR TYPE EKKO-LIFNR,
BUKRS TYPE EKKO-BUKRS,
ZTERM TYPE EKKO-ZTERM,
MATNR TYPE EKPO-MATNR,
EBELP TYPE EKPO-EBELP,
LGORT TYPE EKPO-LGORT,
MATKL TYPE EKPO-MATKL,
MENGE TYPE EKPO-MENGE,
NAME1 TYPE LFA1-NAME1,
MAKTX TYPE MAKT-MAKTX,
END OF TY_FINAL.
DATA: T_FCAT TYPE LVC_T_FCAT,
W_FCAT LIKE LINE OF T_FCAT,
WA_LAYOUT TYPE LVC_S_LAYO.
DATA: T_EKKO TYPE STANDARD TABLE OF TY_EKKO,
T_EKPO TYPE STANDARD TABLE OF TY_EKPO,
T_LFA1 TYPE STANDARD TABLE OF TY_LFA1,
T_MAKT TYPE STANDARD TABLE OF TY_MAKT,
T_FINAL TYPE STANDARD TABLE OF TY_FINAL.
DATA: W_EKKO TYPE TY_EKKO,
W_EKPO TYPE TY_EKPO,
W_LFA1 TYPE TY_LFA1,
W_MAKT TYPE TY_MAKT,
W_FINAL TYPE TY_FINAL.
DATA: OK_CODE TYPE SY-UCOMM.
DATA: GO_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
GO_ALV_GRID TYPE REF TO CL_GUI_ALV_GRID.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:PURCHASE FOR EKKO-EBELN,
VENDOR FOR EKKO-LIFNR,
MATERIAL FOR EKPO-MATNR.
SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
SELECT EBELN LIFNR BUKRS ZTERM
FROM EKKO
INTO TABLE T_EKKO
WHERE EBELN IN PURCHASE
AND LIFNR IN VENDOR.
IF T_EKKO IS NOT INITIAL.
SELECT EBELN EBELP MATNR LGORT MATKL MENGE
FROM EKPO
INTO TABLE T_EKPO FOR ALL ENTRIES IN T_EKKO
WHERE EBELN = T_EKKO-EBELN.
SORT T_EKPO.
ENDIF.
IF T_EKKO IS NOT INITIAL.
SELECT LIFNR NAME1
FROM LFA1
INTO TABLE T_LFA1 FOR ALL ENTRIES IN T_EKKO
WHERE LIFNR = T_EKKO-LIFNR.
ENDIF.
SELECT MATNR MAKTX
FROM MAKT
INTO TABLE T_MAKT FOR ALL ENTRIES IN T_EKPO
WHERE MATNR = T_EKPO-MATNR.
W_FCAT-FIELDNAME = 'EBELN'.
W_FCAT-SCRTEXT_M = 'PURCHSING NO'.
W_FCAT-COL_POS = 1.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'LIFNR'.
W_FCAT-SCRTEXT_M = 'VENDOR NO'.
W_FCAT-COL_POS = 2.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'BUKRS'.
W_FCAT-SCRTEXT_M = 'COMPANY CODE'.
W_FCAT-COL_POS = 3.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'ZTERM'.
W_FCAT-SCRTEXT_M = 'PAYMENT KEY'.
W_FCAT-COL_POS = 4.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'EBELP'.
W_FCAT-SCRTEXT_M = 'PURCHSING ITEM NO'.
W_FCAT-COL_POS = 5.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MATNR'.
W_FCAT-SCRTEXT_M = 'MATERIAL NO'.
W_FCAT-COL_POS = 6.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'LGORT'.
W_FCAT-SCRTEXT_M = 'STORAGE LOCATION'.
W_FCAT-COL_POS = 7.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MATKL'.
W_FCAT-SCRTEXT_M = 'MATERIAL GROUP'.
W_FCAT-COL_POS = 8.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MENGE'.
W_FCAT-SCRTEXT_M = 'QUANTITY'.
W_FCAT-COL_POS = 9.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MATKX'.
W_FCAT-SCRTEXT_M = 'MATERIAL DESCRIPTION'.
W_FCAT-COL_POS = 10.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'NAME1'.
W_FCAT-SCRTEXT_M = 'PLANT NAME'.
W_FCAT-COL_POS = 11.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
IF T_EKPO IS NOT INITIAL.
LOOP AT T_EKPO INTO W_EKPO.
W_FINAL-EBELP = W_EKPO-EBELP.
W_FINAL-MATNR = W_EKPO-MATNR.
W_FINAL-LGORT = W_EKPO-LGORT.
W_FINAL-MATKL = W_EKPO-MATKL.
W_FINAL-MENGE = W_EKPO-MENGE.
READ TABLE T_EKKO INTO W_EKKO WITH KEY EBELN = W_EKPO-EBELN.
IF SY-SUBRC = 0.
W_FINAL-EBELN = W_EKKO-EBELN.
W_FINAL-LIFNR = W_EKKO-LIFNR.
W_FINAL-BUKRS = W_EKKO-BUKRS.
W_FINAL-ZTERM = W_EKKO-ZTERM.
READ TABLE T_LFA1 INTO W_LFA1 WITH KEY LIFNR = W_EKKO-LIFNR.
IF SY-SUBRC = 0.
W_FINAL-NAME1 = W_LFA1-NAME1.
ENDIF.
ENDIF.
READ TABLE T_MAKT INTO W_MAKT WITH KEY MATNR = W_EKPO-MATNR.
IF SY-SUBRC = 0.
W_FINAL-MAKTX = W_MAKT-MAKTX.
ENDIF.
APPEND W_FINAL TO T_FINAL.
CLEAR W_FINAL.
ENDLOOP.
ENDIF.
CALL SCREEN 100.
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'DYNPROSTATUS'.
SET TITLEBAR 'TITLE1'.
ENDMODULE.
MODULE ALV_GRID OUTPUT.
IF GO_CONTAINER IS NOT BOUND.
CREATE OBJECT GO_CONTAINER
EXPORTING
CONTAINER_NAME = 'CONTAINER_1'
EXCEPTIONS
OTHERS = 6.
CREATE OBJECT GO_ALV_GRID
EXPORTING
I_PARENT = GO_CONTAINER
EXCEPTIONS
OTHERS = 5.
CALL METHOD GO_ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = WA_LAYOUT
CHANGING
IT_OUTTAB = T_FINAL
IT_FIELDCATALOG = T_FCAT
EXCEPTIONS
OTHERS = 4.
ENDIF.
ENDMODULE.
MODULE USER_COMMAND_0100 INPUT.
CASE OK_CODE.
WHEN 'BACK'.
SET SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
No comments:
Post a Comment