ALV Report: (Using EKKO, EKPO and MAKT Tables)
*&---------------------------------------------------------------------*
*& REPORT Z_ALV_DISPLAY
*&
*&---------------------------------------------------------------------*
*& REPORT Z_ALV_DISPLAY
*&
*&---------------------------------------------------------------------*
REPORT Z_ALV_DISPLAY.
TYPES : SLIS.
TABLES: EKKO, EKPO, LFA1, MAKT.
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 SLIS_T_FIELDCAT_ALV,
W_FCAT TYPE SLIS_FIELDCAT_ALV.
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.
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.
PERFORM SUB_GET_EKKO.
PERFORM SUB_GET_EKPO.
PERFORM SUB_GET_LFA1.
PERFORM SUB_GET_MAKT.
PERFORM SUB_GET_FINAL.
PERFORM SUB_GET_FCAT.
END-OF-SELECTION.
PERFORM SUB_DISPLAY_ALV.
FORM SUB_GET_EKKO .
SELECT EBELN LIFNR BUKRS ZTERM
FROM EKKO
INTO TABLE T_EKKO
WHERE EBELN IN PURCHASE
AND LIFNR IN VENDOR.
ENDFORM.
FORM SUB_GET_EKPO .
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.
ENDFORM.
FORM SUB_GET_LFA1 .
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.
ENDFORM.
FORM SUB_GET_MAKT .
SELECT MATNR MAKTX
FROM MAKT
INTO TABLE T_MAKT FOR ALL ENTRIES IN T_EKPO
WHERE MATNR = T_EKPO-MATNR.
ENDFORM.
FORM SUB_GET_FCAT .
W_FCAT-FIELDNAME = 'EBELN'.
W_FCAT-SELTEXT_M = 'PURCHSING NO'.
W_FCAT-COL_POS = 1.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'LIFNR'.
W_FCAT-SELTEXT_M = 'VENDOR NO'.
W_FCAT-COL_POS = 2.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'BUKRS'.
W_FCAT-SELTEXT_M = 'COMPANY CODE'.
W_FCAT-COL_POS = 3.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'ZTERM'.
W_FCAT-SELTEXT_M = 'PAYMENT KEY'.
W_FCAT-COL_POS = 4.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'EBELP'.
W_FCAT-SELTEXT_M = 'PURCHSING ITEM NO'.
W_FCAT-COL_POS = 5.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MATNR'.
W_FCAT-SELTEXT_M = 'MATERIAL NO'.
W_FCAT-COL_POS = 6.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'LGORT'.
W_FCAT-SELTEXT_M = 'STORAGE LOCATION'.
W_FCAT-COL_POS = 7.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MATKL'.
W_FCAT-SELTEXT_M = 'MATERIAL GROUP'.
W_FCAT-COL_POS = 8.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MENGE'.
W_FCAT-SELTEXT_M = 'QUANTITY'.
W_FCAT-COL_POS = 9.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MATKX'.
W_FCAT-SELTEXT_M = 'MATERIAL DESCRIPTION'.
W_FCAT-COL_POS = 10.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'NAME1'.
W_FCAT-SELTEXT_M = 'PLANT NAME'.
W_FCAT-COL_POS = 11.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
ENDFORM.
FORM SUB_GET_FINAL .
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.
ENDFORM.
FORM SUB_DISPLAY_ALV .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = T_FCAT
TABLES
T_OUTTAB = T_FINAL.
ENDFORM.
TYPES : SLIS.
TABLES: EKKO, EKPO, LFA1, MAKT.
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 SLIS_T_FIELDCAT_ALV,
W_FCAT TYPE SLIS_FIELDCAT_ALV.
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.
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.
PERFORM SUB_GET_EKKO.
PERFORM SUB_GET_EKPO.
PERFORM SUB_GET_LFA1.
PERFORM SUB_GET_MAKT.
PERFORM SUB_GET_FINAL.
PERFORM SUB_GET_FCAT.
END-OF-SELECTION.
PERFORM SUB_DISPLAY_ALV.
FORM SUB_GET_EKKO .
SELECT EBELN LIFNR BUKRS ZTERM
FROM EKKO
INTO TABLE T_EKKO
WHERE EBELN IN PURCHASE
AND LIFNR IN VENDOR.
ENDFORM.
FORM SUB_GET_EKPO .
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.
ENDFORM.
FORM SUB_GET_LFA1 .
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.
ENDFORM.
FORM SUB_GET_MAKT .
SELECT MATNR MAKTX
FROM MAKT
INTO TABLE T_MAKT FOR ALL ENTRIES IN T_EKPO
WHERE MATNR = T_EKPO-MATNR.
ENDFORM.
FORM SUB_GET_FCAT .
W_FCAT-FIELDNAME = 'EBELN'.
W_FCAT-SELTEXT_M = 'PURCHSING NO'.
W_FCAT-COL_POS = 1.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'LIFNR'.
W_FCAT-SELTEXT_M = 'VENDOR NO'.
W_FCAT-COL_POS = 2.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'BUKRS'.
W_FCAT-SELTEXT_M = 'COMPANY CODE'.
W_FCAT-COL_POS = 3.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'ZTERM'.
W_FCAT-SELTEXT_M = 'PAYMENT KEY'.
W_FCAT-COL_POS = 4.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'EBELP'.
W_FCAT-SELTEXT_M = 'PURCHSING ITEM NO'.
W_FCAT-COL_POS = 5.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MATNR'.
W_FCAT-SELTEXT_M = 'MATERIAL NO'.
W_FCAT-COL_POS = 6.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'LGORT'.
W_FCAT-SELTEXT_M = 'STORAGE LOCATION'.
W_FCAT-COL_POS = 7.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MATKL'.
W_FCAT-SELTEXT_M = 'MATERIAL GROUP'.
W_FCAT-COL_POS = 8.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MENGE'.
W_FCAT-SELTEXT_M = 'QUANTITY'.
W_FCAT-COL_POS = 9.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'MATKX'.
W_FCAT-SELTEXT_M = 'MATERIAL DESCRIPTION'.
W_FCAT-COL_POS = 10.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'NAME1'.
W_FCAT-SELTEXT_M = 'PLANT NAME'.
W_FCAT-COL_POS = 11.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
ENDFORM.
FORM SUB_GET_FINAL .
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.
ENDFORM.
FORM SUB_DISPLAY_ALV .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = T_FCAT
TABLES
T_OUTTAB = T_FINAL.
ENDFORM.
Output:
Input Screen |
Output Screen (ALV List Display) |
No comments:
Post a Comment