Anda di halaman 1dari 6

*&---------------------------------------------------------------------*

*& Report Z_SANDI_ALV


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT Z_SANDI_ALV.
*REPORT ZS_A609299_ALV_6.

type-pools : slis .

*--------------------------------------------------------------------*
* Types Declaration
*--------------------------------------------------------------------*
TYPES: BEGIN OF ts_vbak,
vbeln TYPE vbak-vbeln,

erdat TYPE vbak-erdat,


erzet TYPE vbak-erzet,
ernam TYPE vbak-ernam,
anzdt TYPE vbak-angdt,
END OF ts_vbak,

BEGIN OF ts_vbap,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
END OF ts_vbap,

BEGIN OF ts_final_data,
vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
erzet TYPE vbak-erzet,
ernam TYPE vbak-ernam,
anzdt TYPE vbak-angdt,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
END OF ts_final_data.

*--------------------------------------------------------------------*
* Global Internal Table Declaration
*--------------------------------------------------------------------*
DATA: gt_vbak TYPE STANDARD TABLE OF ts_vbak,
gt_vbap TYPE STANDARD TABLE OF ts_vbap,
gt_final TYPE STANDARD TABLE OF ts_final_data.

*--------------------------------------------------------------------*
* Global Workarea Declaration
*--------------------------------------------------------------------*
DATA: gs_vbak TYPE ts_vbak,
gs_vbap TYPE ts_vbap,
gs_final TYPE ts_final_data.
*--------------------------------------------------------------------*
**Data declarations for ALV
*--------------------------------------------------------------------*

DATA: c_ccont TYPE REF TO cl_gui_custom_container, "Custom container


c_alvgd TYPE REF TO cl_gui_alv_grid, "ALV grid object
it_fcat TYPE lvc_t_fcat, "Field catalogue
it_layout TYPE lvc_s_layo. "Layout

*--------------------------------------------------------------------*
* Global Variable Declaration
*--------------------------------------------------------------------*
DATA: gv_kunnr TYPE vbak-kunnr.

*--------------------------------------------------------------------*
* Selection Screen
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-t01.
SELECT-OPTIONS: s_kunnr FOR gv_kunnr OBLIGATORY.
PARAMETERS: p_matnr TYPE mara-matnr.
SELECTION-SCREEN END OF BLOCK blk1.

*--------------------------------------------------------------------*
*-------------START-OF-SELECTION.------------------------------------*
*--------------------------------------------------------------------*
START-OF-SELECTION.
* fetching data from VBAK database table
REFRESH: gt_vbak[].
SELECT vbeln

erdat
erzet
ernam
angdt
FROM vbak
INTO TABLE gt_vbak
WHERE kunnr IN s_kunnr.
IF sy-subrc NE 0 OR gt_vbak[] IS INITIAL.
MESSAGE 'No Data Found' TYPE 'I'.
EXIT.
ELSE.
SORT gt_vbak BY vbeln.
ENDIF.

* fetching data from VBAP database table


REFRESH: gt_vbap[].
SELECT vbeln
posnr
matnr
FROM vbap
INTO TABLE gt_vbap
FOR ALL ENTRIES IN gt_vbak
WHERE vbeln EQ gt_vbak-vbeln
AND matnr EQ p_matnr.
IF sy-subrc NE 0 OR gt_vbak[] IS INITIAL.
MESSAGE 'No Data Found' TYPE 'I'.
EXIT.
ELSE.
SORT gt_vbap BY vbeln posnr.
ENDIF.

* Let us consolidate and preprare the final internal table


REFRESH: gt_final[].
LOOP AT gt_vbap INTO gs_vbap.
CLEAR gs_vbak.
READ TABLE gt_vbak INTO gs_vbak WITH KEY vbeln = gs_vbap-vbeln
BINARY SEARCH.
IF sy-subrc NE 0.
CONTINUE.
ENDIF.
CLEAR gs_final.
gs_final-vbeln = gs_vbak-vbeln.
gs_final-ernam = gs_vbak-ernam.
gs_final-erdat = gs_vbak-erdat.
gs_final-erzet = gs_vbak-erzet.
gs_final-anzdt = gs_vbak-anzdt.
gs_final-posnr = gs_vbap-posnr.
gs_final-matnr = gs_vbap-matnr.
APPEND gs_final TO gt_final.
ENDLOOP.

CREATE OBJECT c_ccont


EXPORTING
container_name = 'CL'.
CREATE OBJECT c_alvgd
EXPORTING
i_parent = c_ccont.
* SET field for ALV
PERFORM alv_build_fieldcat.
*Set ALV attributes FOR LAYOUT
PERFORM alv_report_layout.
CHECK NOT c_alvgd IS INITIAL.
* Call ALV GRID
CALL METHOD c_alvgd->set_table_for_first_display
EXPORTING
is_layout = it_layout
CHANGING
it_outtab = GT_FINAL
it_fieldcatalog = it_fcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*calling screen for alv display
call screen 500.
*&---------------------------------------------------------------------*
*& Module STATUS_0500 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0500 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_0500 OUTPUT


" ALV_GRID OUTPUT
*&---------------------------------------------------------------------*
*& Module ALV_GRID OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE ALV_GRID OUTPUT.

ENDMODULE. " ALV_GRID OUTPUT

*&---------------------------------------------------------------------*
*& Form ALV_BUILD_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ALV_BUILD_FIELDCAT .

DATA lv_fldcat TYPE lvc_s_fcat.


CLEAR lv_fldcat.
lv_fldcat-row_pos = '1'.
lv_fldcat-col_pos = '1'.
lv_fldcat-fieldname = 'VBELN'.
lv_fldcat-tabname = 'GT_FINAL'.
lv_fldcat-outputlen = '10'.
lv_fldcat-scrtext_m = 'SALES dOC'.
lv_fldcat-icon = 'X'.
APPEND lv_fldcat TO it_fcat.

CLEAR lv_fldcat.
lv_fldcat-row_pos = '1'.
lv_fldcat-col_pos = '2'.
lv_fldcat-fieldname = 'ERDAT'.
lv_fldcat-tabname = 'GT_FINAL'.
lv_fldcat-outputlen = '8'.
lv_fldcat-scrtext_m = 'DATE'.
lv_fldcat-icon = ''.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
lv_fldcat-row_pos = '1'.
lv_fldcat-col_pos = '3'.
lv_fldcat-fieldname = 'ERZET'.
lv_fldcat-tabname = 'GT_FINAL'.
lv_fldcat-outputlen = '6'.
lv_fldcat-scrtext_m = 'TIME'.
lv_fldcat-icon = ''.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
lv_fldcat-row_pos = '1'.
lv_fldcat-col_pos = '4'.
lv_fldcat-fieldname = 'ERNAM'.
lv_fldcat-tabname = 'GT_FINAL'.
lv_fldcat-outputlen = '12'.
lv_fldcat-scrtext_m = 'CREATER NAME'.
lv_fldcat-icon = ''.
APPEND lv_fldcat TO it_fcat.

CLEAR lv_fldcat.
lv_fldcat-row_pos = '1'.
lv_fldcat-col_pos = '5'.
lv_fldcat-fieldname = 'ANZDT'.
lv_fldcat-tabname = 'GT_FINAL'.
lv_fldcat-outputlen = '12'.
lv_fldcat-scrtext_m = 'QUTATION'.
lv_fldcat-icon = ''.
APPEND lv_fldcat TO it_fcat.

CLEAR lv_fldcat.
lv_fldcat-row_pos = '1'.
lv_fldcat-col_pos = '6'.
lv_fldcat-fieldname = 'POSNR'.
lv_fldcat-tabname = 'GT_FINAL'.
lv_fldcat-outputlen = '6'.
lv_fldcat-scrtext_m = 'SALES dOC ITEM'.
lv_fldcat-icon = ''.
APPEND lv_fldcat TO it_fcat.

CLEAR lv_fldcat.
lv_fldcat-row_pos = '1'.
lv_fldcat-col_pos = '7'.
lv_fldcat-fieldname = 'MATNR'.
lv_fldcat-tabname = 'GT_FINAL'.
lv_fldcat-outputlen = '18'.
lv_fldcat-scrtext_m = 'MATERIAL NO'.
lv_fldcat-icon = ''.
APPEND lv_fldcat TO it_fcat.

ENDFORM. " ALV_BUILD_FIELDCAT

*&---------------------------------------------------------------------*
*& Form ALV_REPORT_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ALV_REPORT_LAYOUT .
it_layout-cwidth_opt = 'X'.
it_layout-zebra = 'X'.
it_layout-col_opt = 'X'.
ENDFORM. " ALV_REPORT_LAYOUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0500 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0500 INPUT.

ENDMODULE. " USER_COMMAND_0500 INPUT