To display report with ALV Grid and standard list view report :
*&---------------------------------------------------------------------*
*& Report ZTEST_PROGRAM_ALV2
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
INCLUDE ZTEST_PROGRAM_ALV2_TOP . " Global Data
INCLUDE ZTEST_PROGRAM_ALV2_F01 . " FORM-Routines
AT SELECTION-SCREEN.
SELECT COUNT(*) FROM kna1 WHERE kunnr = p_kunnr.
IF sy-subrc NE 0.
MESSAGE e001 WITH p_kunnr.
ENDIF.
SELECT SINGLE erdat FROM vbak INTO gv_erdat WHERE erdat IN s_erdat.
IF sy-subrc NE 0.
MESSAGE e002 WITH s_erdat.
ENDIF.
START-OF-SELECTION.
*Retrieving Data from database and populating into final internal table
PERFORM data_selection.
END-OF-SELECTION.
*Displaying Output In ALV Grid Format
* PERFORM alv_output.
IF NOT it_vbak IS INITIAL.
PERFORM f_fieldcat_alv.
PERFORM f_display_alv.
ENDIF.
------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include ZTEST_PROGRAM_ALV2_TOP - Report ZTEST_PROGRAM_ALV2
*&---------------------------------------------------------------------*
REPORT ztest_program_alv2 MESSAGE-ID zsd_msg.
TYPE-POOLS:slis.
TABLES:vbak.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS:p_kunnr TYPE kunnr.
SELECT-OPTIONS:s_erdat FOR vbak-erdat.
PARAMETERS: rb1 RADIOBUTTON GROUP rb1,
rb2 RADIOBUTTON GROUP rb1.
SELECTION-SCREEN END OF BLOCK b1.
TYPES:BEGIN OF ty_vbak, "Structure for holding header details of sales order
vbeln TYPE vbeln_va, "Sales order number
erdat TYPE erdat, "Creation Date
ernam TYPE ernam, "Creator Name
auart TYPE auart, "Order Type
vkorg TYPE vkorg, "Sales Organization
vtweg TYPE vtweg, "Distribution Channel
spart TYPE spart, "Division
END OF ty_vbak,
BEGIN OF ty_vbap, "Structure for holding Item details of sales order
vbeln TYPE vbeln_va, "Sales Order Number
posnr TYPE posnr_va, "Item Number
matnr TYPE matnr, "Material Number
meins TYPE meins, "Unit of measure
netwr TYPE netwr_ap, "Net Weight
END OF ty_vbap,
BEGIN OF ty_final, "Structure for final output
flag TYPE c,
vbeln TYPE vbeln_va,
erdat TYPE erdat,
ernam TYPE ernam,
auart TYPE auart,
vkorg TYPE vkorg,
vtweg TYPE vtweg,
spart TYPE spart,
posnr TYPE posnr_va,
matnr TYPE matnr,
meins TYPE meins,
netwr TYPE netwr_ap,
END OF ty_final.
DATA:gv_erdat TYPE erdat, "Creation Date
gv_count TYPE i. "Counter Value
DATA:it_vbak TYPE STANDARD TABLE OF ty_vbak,
it_vbap TYPE STANDARD TABLE OF ty_vbap,
it_final TYPE STANDARD TABLE OF ty_final,
it_header TYPE TABLE OF slis_listheader.
DATA:wa_vbak TYPE ty_vbak,
wa_vbap TYPE ty_vbap,
wa_final TYPE ty_final,
it_fcat TYPE slis_t_fieldcat_alv,
wa_fcat TYPE slis_fieldcat_alv.
-----------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include ZTEST_PROGRAM_ALV2_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form DATA_SELECTION
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM data_selection .
REFRESH : it_vbak.
CLEAR : wa_vbak.
SELECT vbeln erdat ernam auart vkorg vtweg spart FROM vbak INTO TABLE it_vbak WHERE kunnr = p_kunnr AND erdat IN s_erdat.
IF sy-subrc EQ 0.
SORT it_vbak BY vbeln.
SELECT vbeln posnr matnr meins netwr FROM vbap INTO TABLE it_vbap FOR ALL ENTRIES IN it_vbak WHERE vbeln = it_vbak-vbeln.
IF sy-subrc EQ 0.
SORT it_vbap BY vbeln posnr.
ENDIF.
ENDIF.
LOOP AT it_vbap INTO wa_vbap.
READ TABLE it_vbak INTO wa_vbak WITH KEY vbeln = wa_vbap-vbeln.
IF sy-subrc EQ 0.
MOVE wa_vbak-vbeln TO wa_final-vbeln.
MOVE wa_vbak-erdat TO wa_final-erdat.
MOVE wa_vbak-ernam TO wa_final-ernam.
MOVE wa_vbak-auart TO wa_final-auart.
MOVE wa_vbak-vkorg TO wa_final-vkorg.
MOVE wa_vbak-vtweg TO wa_final-vtweg.
MOVE wa_vbak-spart TO wa_final-spart.
MOVE wa_vbap-posnr TO wa_final-posnr.
MOVE wa_vbap-matnr TO wa_final-matnr.
MOVE wa_vbap-meins TO wa_final-meins.
MOVE wa_vbap-netwr TO wa_final-netwr.
APPEND wa_final TO it_final.
CLEAR:wa_final.
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_FIELDCAT_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM f_fieldcat_alv .
REFRESH: it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '1'.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Sales Document'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '2'.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Created Date'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '3'.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Created Name'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '4'.
wa_fcat-fieldname = 'AUART'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Order Type'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '5'.
wa_fcat-fieldname = 'VKORG'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Sales Org.'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '6'.
wa_fcat-fieldname = 'VTWEG'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Distribution Channel'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '7'.
wa_fcat-fieldname = 'SPART'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Division'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '8'.
wa_fcat-fieldname = 'POSNR'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Item Number'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '9'.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Material Number'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '10'.
wa_fcat-fieldname = 'MEINS'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'UOM'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '11'.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Net Weight'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_DISPLAY_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM f_display_alv .
IF rb1 = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fcat
i_save = 'A'
TABLES
t_outtab = it_final
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ELSEIF rb2 = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fcat
i_save = 'A'
TABLES
t_outtab = it_final
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDFORM.
------------------------------------------------------------------------------
Output with grid option as below:
Output with List view as below:
*&---------------------------------------------------------------------*
*& Report ZTEST_PROGRAM_ALV2
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
INCLUDE ZTEST_PROGRAM_ALV2_TOP . " Global Data
INCLUDE ZTEST_PROGRAM_ALV2_F01 . " FORM-Routines
AT SELECTION-SCREEN.
SELECT COUNT(*) FROM kna1 WHERE kunnr = p_kunnr.
IF sy-subrc NE 0.
MESSAGE e001 WITH p_kunnr.
ENDIF.
SELECT SINGLE erdat FROM vbak INTO gv_erdat WHERE erdat IN s_erdat.
IF sy-subrc NE 0.
MESSAGE e002 WITH s_erdat.
ENDIF.
START-OF-SELECTION.
*Retrieving Data from database and populating into final internal table
PERFORM data_selection.
END-OF-SELECTION.
*Displaying Output In ALV Grid Format
* PERFORM alv_output.
IF NOT it_vbak IS INITIAL.
PERFORM f_fieldcat_alv.
PERFORM f_display_alv.
ENDIF.
------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include ZTEST_PROGRAM_ALV2_TOP - Report ZTEST_PROGRAM_ALV2
*&---------------------------------------------------------------------*
REPORT ztest_program_alv2 MESSAGE-ID zsd_msg.
TYPE-POOLS:slis.
TABLES:vbak.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS:p_kunnr TYPE kunnr.
SELECT-OPTIONS:s_erdat FOR vbak-erdat.
PARAMETERS: rb1 RADIOBUTTON GROUP rb1,
rb2 RADIOBUTTON GROUP rb1.
SELECTION-SCREEN END OF BLOCK b1.
TYPES:BEGIN OF ty_vbak, "Structure for holding header details of sales order
vbeln TYPE vbeln_va, "Sales order number
erdat TYPE erdat, "Creation Date
ernam TYPE ernam, "Creator Name
auart TYPE auart, "Order Type
vkorg TYPE vkorg, "Sales Organization
vtweg TYPE vtweg, "Distribution Channel
spart TYPE spart, "Division
END OF ty_vbak,
BEGIN OF ty_vbap, "Structure for holding Item details of sales order
vbeln TYPE vbeln_va, "Sales Order Number
posnr TYPE posnr_va, "Item Number
matnr TYPE matnr, "Material Number
meins TYPE meins, "Unit of measure
netwr TYPE netwr_ap, "Net Weight
END OF ty_vbap,
BEGIN OF ty_final, "Structure for final output
flag TYPE c,
vbeln TYPE vbeln_va,
erdat TYPE erdat,
ernam TYPE ernam,
auart TYPE auart,
vkorg TYPE vkorg,
vtweg TYPE vtweg,
spart TYPE spart,
posnr TYPE posnr_va,
matnr TYPE matnr,
meins TYPE meins,
netwr TYPE netwr_ap,
END OF ty_final.
DATA:gv_erdat TYPE erdat, "Creation Date
gv_count TYPE i. "Counter Value
DATA:it_vbak TYPE STANDARD TABLE OF ty_vbak,
it_vbap TYPE STANDARD TABLE OF ty_vbap,
it_final TYPE STANDARD TABLE OF ty_final,
it_header TYPE TABLE OF slis_listheader.
DATA:wa_vbak TYPE ty_vbak,
wa_vbap TYPE ty_vbap,
wa_final TYPE ty_final,
it_fcat TYPE slis_t_fieldcat_alv,
wa_fcat TYPE slis_fieldcat_alv.
-----------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include ZTEST_PROGRAM_ALV2_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form DATA_SELECTION
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM data_selection .
REFRESH : it_vbak.
CLEAR : wa_vbak.
SELECT vbeln erdat ernam auart vkorg vtweg spart FROM vbak INTO TABLE it_vbak WHERE kunnr = p_kunnr AND erdat IN s_erdat.
IF sy-subrc EQ 0.
SORT it_vbak BY vbeln.
SELECT vbeln posnr matnr meins netwr FROM vbap INTO TABLE it_vbap FOR ALL ENTRIES IN it_vbak WHERE vbeln = it_vbak-vbeln.
IF sy-subrc EQ 0.
SORT it_vbap BY vbeln posnr.
ENDIF.
ENDIF.
LOOP AT it_vbap INTO wa_vbap.
READ TABLE it_vbak INTO wa_vbak WITH KEY vbeln = wa_vbap-vbeln.
IF sy-subrc EQ 0.
MOVE wa_vbak-vbeln TO wa_final-vbeln.
MOVE wa_vbak-erdat TO wa_final-erdat.
MOVE wa_vbak-ernam TO wa_final-ernam.
MOVE wa_vbak-auart TO wa_final-auart.
MOVE wa_vbak-vkorg TO wa_final-vkorg.
MOVE wa_vbak-vtweg TO wa_final-vtweg.
MOVE wa_vbak-spart TO wa_final-spart.
MOVE wa_vbap-posnr TO wa_final-posnr.
MOVE wa_vbap-matnr TO wa_final-matnr.
MOVE wa_vbap-meins TO wa_final-meins.
MOVE wa_vbap-netwr TO wa_final-netwr.
APPEND wa_final TO it_final.
CLEAR:wa_final.
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_FIELDCAT_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM f_fieldcat_alv .
REFRESH: it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '1'.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Sales Document'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '2'.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Created Date'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '3'.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Created Name'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '4'.
wa_fcat-fieldname = 'AUART'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Order Type'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '5'.
wa_fcat-fieldname = 'VKORG'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Sales Org.'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '6'.
wa_fcat-fieldname = 'VTWEG'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Distribution Channel'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '7'.
wa_fcat-fieldname = 'SPART'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Division'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '8'.
wa_fcat-fieldname = 'POSNR'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Item Number'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '9'.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Material Number'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '10'.
wa_fcat-fieldname = 'MEINS'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'UOM'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-row_pos = '1'.
wa_fcat-col_pos = '11'.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-tabname = 'it_final'.
wa_fcat-seltext_m = 'Net Weight'."TEXT-002.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_DISPLAY_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM f_display_alv .
IF rb1 = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fcat
i_save = 'A'
TABLES
t_outtab = it_final
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ELSEIF rb2 = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fcat
i_save = 'A'
TABLES
t_outtab = it_final
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDFORM.
------------------------------------------------------------------------------
Output with grid option as below:
Output with List view as below:
No comments:
Post a Comment