ALV Report with OOPs
How To Create ALV Report With OOPs
For the Creation Of T-Code go through below link -
Below screen display important includes and object for creating of ALV with OOPs .
REPORT zmmr001_test.
TYPE-POOLS :slis.
INCLUDE <icon>.
TABLES: ekko ,eket ,vbak.
TYPES :
BEGIN OF ty_result,
ebeln TYPE ekpo-ebeln,
message TYPE string,
END OF ty_result ,
BEGIN OF ty_vbap,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
prctr TYPE vbap-prctr,
vgbel TYPE vbap-vgbel,
END OF ty_vbap,
BEGIN OF ty_vbak,
DATA : it_result TYPE TABLE OF ty_result,BEGIN OF ty_vbak,
vbeln TYPE vbak-vbeln,
kunnr TYPE vbak-kunnr,
vkorg TYPE vbak-vkorg,
vbtyp TYPE vbak-vbtyp,
vkgrp TYPE vbak-vkgrp,
knumv TYPE vbak-knumv,
auart TYPE vbak-auart,
END OF ty_vbak.
BEGIN OF ty_ekko,
ebeln TYPE ekko-ebeln,
ebelp TYPE ekpo-ebelp,
lifnr TYPE ekko-lifnr,
knumv TYPE ekko-knumv,
menge TYPE ekpo-menge,
matnr TYPE ekpo-matnr,
ekgrp TYPE ekko-ekgrp,
bukrs TYPE ekko-bukrs,
netwr TYPE ekpo-netwr,
END OF ty_ekko.
BEGIN OF ty_ekkn,
ebeln TYPE ekkn-ebeln,
ebelp TYPE ekkn-ebelp,
vbeln TYPE ekkn-vbeln,
vbelp TYPE ekkn-vbelp,
frgke TYPE ekko-frgke,
sakto TYPE ekkn-sakto,
END OF ty_ekkn .
BEGIN OF ty_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
zzvbeln TYPE ekpo-zzvbeln,
zzposnr TYPE ekpo-zzposnr,
knumv TYPE ekko-knumv,
lifnr TYPE ekko-lifnr,
menge TYPE ekpo-menge,
matnr TYPE ekpo-matnr,
ekgrp TYPE ekko-ekgrp,
bukrs TYPE ekko-bukrs,
frgke TYPE ekko-frgke,
netwr TYPE ekpo-netwr,
END OF ty_ekpo.
BEGIN OF ty_ekko1,
ebeln TYPE ekko-ebeln,
ebelp TYPE ekkn-ebelp,
frggr TYPE ekko-frggr,
frgsx TYPE ekko-frgsx,
sakto TYPE ekkn-sakto,
frgzu TYPE ekko-frgzu,
bukrs TYPE ekko-bukrs,
END OF ty_ekko1.
BEGIN OF ty_po,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
vbeln TYPE vbak-vbeln,
posnr TYPE vbap-posnr,
knumv TYPE ekko-knumv,
lifnr TYPE ekko-lifnr,
menge TYPE ekpo-menge,
matnr TYPE ekpo-matnr,
ekgrp TYPE ekko-ekgrp,
bukrs TYPE ekko-bukrs,
netwr TYPE ekpo-netwr,
sakto TYPE ekkn-sakto,
END OF ty_po.
BEGIN OF tys_t024,
ekgrp TYPE t024-ekgrp,
eknam TYPE t024-eknam,
END OF tys_t024,
BEGIN OF ty_eket,
ebeln TYPE eket-ebeln,
ebelp TYPE eket-ebelp,
eindt TYPE eket-eindt,
END OF ty_eket.
BEGIN OF tys_tvgrt,
vkgrp TYPE tvgrt-vkgrp,
bezei TYPE tvgrt-bezei,
END OF tys_tvgrt.
BEGIN OF ty_t16fs,
frggr TYPE t16fs-frggr,
frgsx TYPE t16fs-frgsx,
frgc1 TYPE t16fs-frgc1,
frgc2 TYPE t16fs-frgc2,
frgc6 TYPE t16fs-frgc6,
frgc7 TYPE t16fs-frgc7,
END OF ty_t16fs.
BEGIN OF ty_final,
bukrs TYPE ekko-bukrs,
ekgrp TYPE string,
ebeln TYPE ekko-ebeln,
ebelp TYPE ekpo-ebelp,
menge TYPE ekpo-menge,
vkgrp TYPE string,
icon(12) TYPE c,
icon1(12) TYPE c,
frgc1 TYPE t16fs-frgc1,
frgc2 TYPE t16fs-frgc2,
frgc6 TYPE t16fs-frgc6,
frgc7 TYPE t16fs-frgc7,
zdsso TYPE string,
zdspo TYPE string,
eindt TYPE eket-eindt,
avg TYPE ekpo-menge,
END OF ty_final.
BEGIN OF ty_ekko,
ebeln TYPE ekko-ebeln,
ebelp TYPE ekpo-ebelp,
lifnr TYPE ekko-lifnr,
knumv TYPE ekko-knumv,
menge TYPE ekpo-menge,
matnr TYPE ekpo-matnr,
ekgrp TYPE ekko-ekgrp,
bukrs TYPE ekko-bukrs,
netwr TYPE ekpo-netwr,
END OF ty_ekko.
BEGIN OF ty_ekkn,
ebeln TYPE ekkn-ebeln,
ebelp TYPE ekkn-ebelp,
vbeln TYPE ekkn-vbeln,
vbelp TYPE ekkn-vbelp,
frgke TYPE ekko-frgke,
sakto TYPE ekkn-sakto,
END OF ty_ekkn .
BEGIN OF ty_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
zzvbeln TYPE ekpo-zzvbeln,
zzposnr TYPE ekpo-zzposnr,
knumv TYPE ekko-knumv,
lifnr TYPE ekko-lifnr,
menge TYPE ekpo-menge,
matnr TYPE ekpo-matnr,
ekgrp TYPE ekko-ekgrp,
bukrs TYPE ekko-bukrs,
frgke TYPE ekko-frgke,
netwr TYPE ekpo-netwr,
END OF ty_ekpo.
BEGIN OF ty_ekko1,
ebeln TYPE ekko-ebeln,
ebelp TYPE ekkn-ebelp,
frggr TYPE ekko-frggr,
frgsx TYPE ekko-frgsx,
sakto TYPE ekkn-sakto,
frgzu TYPE ekko-frgzu,
bukrs TYPE ekko-bukrs,
END OF ty_ekko1.
BEGIN OF ty_po,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
vbeln TYPE vbak-vbeln,
posnr TYPE vbap-posnr,
knumv TYPE ekko-knumv,
lifnr TYPE ekko-lifnr,
menge TYPE ekpo-menge,
matnr TYPE ekpo-matnr,
ekgrp TYPE ekko-ekgrp,
bukrs TYPE ekko-bukrs,
netwr TYPE ekpo-netwr,
sakto TYPE ekkn-sakto,
END OF ty_po.
BEGIN OF tys_t024,
ekgrp TYPE t024-ekgrp,
eknam TYPE t024-eknam,
END OF tys_t024,
BEGIN OF ty_eket,
ebeln TYPE eket-ebeln,
ebelp TYPE eket-ebelp,
eindt TYPE eket-eindt,
END OF ty_eket.
BEGIN OF tys_tvgrt,
vkgrp TYPE tvgrt-vkgrp,
bezei TYPE tvgrt-bezei,
END OF tys_tvgrt.
BEGIN OF ty_t16fs,
frggr TYPE t16fs-frggr,
frgsx TYPE t16fs-frgsx,
frgc1 TYPE t16fs-frgc1,
frgc2 TYPE t16fs-frgc2,
frgc6 TYPE t16fs-frgc6,
frgc7 TYPE t16fs-frgc7,
END OF ty_t16fs.
BEGIN OF ty_final,
bukrs TYPE ekko-bukrs,
ekgrp TYPE string,
ebeln TYPE ekko-ebeln,
ebelp TYPE ekpo-ebelp,
menge TYPE ekpo-menge,
vkgrp TYPE string,
icon(12) TYPE c,
icon1(12) TYPE c,
frgc1 TYPE t16fs-frgc1,
frgc2 TYPE t16fs-frgc2,
frgc6 TYPE t16fs-frgc6,
frgc7 TYPE t16fs-frgc7,
zdsso TYPE string,
zdspo TYPE string,
eindt TYPE eket-eindt,
avg TYPE ekpo-menge,
END OF ty_final.
wa_result TYPE ty_result,
it_vbap TYPE TABLE OF ty_vbap,
wa_vbap TYPE ty_vbap,
it_alv TYPE TABLE OF ty_alv,
wa_alv TYPE ty_alv.
it_vbak TYPE TABLE OF ty_vbak,
wa_vbak TYPE ty_vbak,
it_slgrp TYPE TABLE OF ty_vbak,
wa_slgrp TYPE ty_vbak.
it_ekpo TYPE TABLE OF ty_ekpo,
wa_ekpo TYPE ty_ekpo,
it_po TYPE STANDARD TABLE OF ty_po,
wa_po TYPE ty_po,
it_tyst024 TYPE TABLE OF tys_t024,
wa_tyst024 TYPE tys_t024,
it_ekko1 TYPE TABLE OF ty_ekko1,
wa_ekko1 TYPE ty_ekko1,
it_eket TYPE TABLE OF ty_eket,
wa_eket TYPE ty_eket,
it_tvgrt TYPE TABLE OF tys_tvgrt,
wa_tvgrt TYPE tys_tvgrt,
it_t16fs TYPE TABLE OF ty_t16fs,
wa_t16fs TYPE ty_t16fs.
it_final TYPE TABLE OF ty_final,
wa_final TYPE ty_final.
it_ekko TYPE TABLE OF ty_ekko,
wa_ekko TYPE ty_ekko.
it_ekkn TYPE TABLE OF ty_ekkn,
wa_ekkn TYPE ty_ekkn.
c_ccont TYPE REF TO cl_gui_custom_container,
c_alvgd1 TYPE REF TO cl_gui_alv_grid,
c_alvgd TYPE REF TO cl_gui_alv_grid,
o_dyndoc_id TYPE REF TO cl_dd_document,
gt_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader,
o_html_cntrl TYPE REF TO cl_gui_html_viewer,
o_parent_top TYPE REF TO cl_gui_container,
o_splitter TYPE REF TO cl_gui_splitter_container,
o_parent_grid TYPE REF TO cl_gui_container.
it_fcat TYPE lvc_t_fcat,
it_fcaterror TYPE lvc_t_fcat,
it_layout TYPE lvc_s_layo ,
i_variant TYPE disvariant,
wa_layo TYPE lvc_s_layo.
it_sort TYPE lvc_t_sort,
wa_sort TYPE lvc_s_sort.
* Initialization Event
INITIALIZATION .
* selection screen
SELECTION-SCREEN BEGIN OF BLOCK main WITH FRAME TITLE text-001.
PARAMETERS pa_vkorg TYPE vbak-vkorg OBLIGATORY.
SELECT-OPTIONS : so_eindt FOR eket-eindt OBLIGATORY,
so_lifnr FOR ekko-lifnr,
so_ekgrp FOR ekko-ekgrp,
so_vkgrp FOR vbak-vkgrp.
SELECTION-SCREEN END OF BLOCK main.
CLASS lcl_event_handler DEFINITION DEFERRED.
DATA: event_receiver TYPE REF TO lcl_event_handler.
*----------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION .
*
* METHODS:
* print_top_of_page FOR EVENT print_top_of_page
* OF cl_gui_alv_grid.
*
* METHODS:
**Event Handler for Top of page
*
* top_of_page FOR EVENT top_of_page
* OF cl_gui_alv_grid
* IMPORTING e_dyndoc_id.
METHODS:
handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row
e_column.
ENDCLASS. "lcl_event_handler DEFINITION
********************* END
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_double_click.
READ TABLE it_final
INTO wa_final
INDEX e_row-index.
IF sy-subrc EQ 0.
* Call to perform a CALL TRANSACTION based on the selected Column Value
PERFORM call_tx USING e_column.
ENDIF.
ENDMETHOD. "handle_double_click
ENDCLASS. "LCL_EVENT_HANDLER IMPLEMENTATION
****************** for header
DATA : g_handler TYPE REF TO lcl_event_handler. "handler
**************************end
START-OF-SELECTION.
* create a screen using se51 (screen painter ) or click on screen no as example in below case 1001 and you *get option for create screen .After creating screen u create custom container for display on grid , i mean *defie size of your grid using painter pencil in edit mode of se51 and there is tool for creation of custom *container (right hand side second no from below in given tool)
CALL SCREEN 1001.
* Once screen is created u come in flow logic and get PBO and PAI event .
*&---------------------------------------------------------------------*
*& Module STATUS_1001 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_1001 OUTPUT.
* SET PF-STATUS 'STANDARD'.
SET PF-STATUS 'STATUS_1001'.
SET TITLEBAR '1001' OF PROGRAM sy-repid WITH text-001.
IF c_alvgd IS INITIAL.
PERFORM create_alv_inv .
ENDIF.
ENDMODULE. " STATUS_1001 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1001 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_1001 INPUT.
DATA: it_sel_rows TYPE lvc_t_row,
wa_sel_rows LIKE LINE OF it_sel_rows.
DATA: lv_ponum TYPE bapimmpara-po_number,
lv_rel_code TYPE bapimmpara-po_rel_cod.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'CANCEL'.
EXIT.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'RELEASE'.
CALL METHOD c_alvgd->get_selected_rows
IMPORTING
et_index_rows = it_sel_rows.
LOOP AT it_sel_rows INTO wa_sel_rows.
CLEAR wa_final.
READ TABLE it_final INTO wa_final INDEX wa_sel_rows-index.
CLEAR wa_ekko1.
READ TABLE it_ekko1 INTO wa_ekko1 WITH KEY ebeln = wa_final-ebeln." ebelp = wa_final-ebelp.
IF wa_ekko1-sakto = '0050000000'.
IF wa_ekko1-frgzu = ''.
PERFORM release_po USING wa_final-ebeln '12'.
ELSEIF wa_ekko1-frgzu = 'X'.
PERFORM release_po USING wa_final-ebeln '12'.
ENDIF.
ELSE.
IF wa_ekko1-frgzu = ''.
PERFORM release_po USING wa_final-ebeln '12'.
ELSEIF wa_ekko1-frgzu = 'X'.
PERFORM release_po USING wa_final-ebeln '12'.
ENDIF.
ENDIF.
ENDLOOP.
IF it_result[] IS INITIAL.
* CALL SCREEN 1003 STARTING AT 4 5.
MESSAGE 'PO released succesfully!!!' TYPE 'I'.
ENDIF.
ENDCASE.
ENDMODULE. " USER_COMMAND_1001 INPUT
*&---------------------------------------------------------------------*
*& Form CREATE_ALV_INV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_alv_inv .
"Code for top of page
* create object for alv grid
CREATE OBJECT c_alvgd
EXPORTING
i_parent = cl_gui_container=>screen0."o_parent_grid.
PERFORM form_set_grid_vari CHANGING i_variant.
********** Open for header
CREATE OBJECT g_handler.
"end code for top of page
CHECK NOT c_alvgd IS INITIAL.
*********** End of Header
PERFORM fetch_it_data.
PERFORM alv_build_fieldcat1.
* Set ALV attributes FOR LAYOUT
PERFORM alv_report_layout.
* lv_variant-report = sy-repid.
* Call ALV GRID
CALL METHOD c_alvgd->set_table_for_first_display
EXPORTING
is_layout = it_layout
is_variant = i_variant
i_save = 'A'
CHANGING
it_outtab = it_final " change for some time testing it_final
it_fieldcatalog = it_fcat
it_sort = it_sort
EXCEPTIONS
invalid_parameter_combination = 1 " it_sort = it_sort
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.
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_double_click
FOR c_alvgd.
*~ Grid Ready for input or not ??
CALL METHOD c_alvgd->set_ready_for_input
EXPORTING
i_ready_for_input = 0.
"Code for top of page
* CALL METHOD o_dyndoc_id->initialize_document
* EXPORTING
* background_color = cl_dd_area=>col_textarea.
* Processing events
* CALL METHOD c_alvgd->list_processing_events
* EXPORTING
* i_event_name = 'TOP_OF_PAGE'
* i_dyndoc_id = o_dyndoc_id.
"end code for top of page
ENDFORM. " CREATE_ALV_INV
*&---------------------------------------------------------------------*
*& Form FETCH_IT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fetch_it_data .
SELECT ekpo~ebeln ebelp zzvbeln zzposnr knumv lifnr menge matnr ekgrp ekko~bukrs frgke netwr
FROM ekpo INNER JOIN ekko
ON ekpo~ebeln = ekko~ebeln
INTO TABLE it_ekpo
WHERE ekpo~loekz = ''
AND frgke EQ 'N'
AND lifnr IN so_lifnr
AND ekko~bukrs EQ pa_vkorg
AND ekgrp IN so_ekgrp.
DELETE it_ekpo[] WHERE zzvbeln IS INITIAL.
LOOP AT it_ekpo INTO wa_ekpo.
wa_po-ebeln = wa_ekpo-ebeln.
wa_po-ebelp = wa_ekpo-ebelp.
wa_po-vbeln = wa_ekpo-zzvbeln.
wa_po-posnr = wa_ekpo-zzposnr.
wa_po-knumv = wa_ekpo-knumv.
wa_po-lifnr = wa_ekpo-lifnr.
wa_po-netwr = wa_ekpo-netwr.
wa_po-menge = wa_ekpo-menge.
wa_po-matnr = wa_ekpo-matnr.
wa_po-ekgrp = wa_ekpo-ekgrp.
wa_po-bukrs = wa_ekpo-bukrs.
APPEND wa_po TO it_po.
CLEAR wa_po.
ENDLOOP.
SELECT ekkn~ebeln ebelp vbeln vbelp frgke sakto
FROM ekkn INNER JOIN ekko
ON ekkn~ebeln EQ ekko~ebeln
INTO TABLE it_ekkn
WHERE bukrs EQ pa_vkorg
AND frgke EQ 'N'
AND sakto = '0050000000'.
DELETE it_ekkn[] WHERE vbeln IS INITIAL.
IF it_ekkn[] IS NOT INITIAL.
SELECT ekko~ebeln ebelp lifnr knumv menge matnr ekgrp ekko~bukrs netwr
FROM ekko INNER JOIN ekpo
ON ekko~ebeln EQ ekpo~ebeln
INTO TABLE it_ekko
FOR ALL ENTRIES IN it_ekkn
WHERE ekko~ebeln EQ it_ekkn-ebeln
AND ekpo~loekz = ''
AND lifnr IN so_lifnr .
ENDIF.
LOOP AT it_ekkn INTO wa_ekkn.
CLEAR wa_ekko.
READ TABLE it_ekko INTO wa_ekko WITH KEY ebeln = wa_ekkn-ebeln ebelp = wa_ekkn-ebelp.
IF sy-subrc IS INITIAL.
wa_po-ebeln = wa_ekkn-ebeln.
wa_po-ebelp = wa_ekkn-ebelp.
wa_po-vbeln = wa_ekkn-vbeln.
wa_po-posnr = wa_ekkn-vbelp.
wa_po-knumv = wa_ekko-knumv.
wa_po-lifnr = wa_ekko-lifnr.
wa_po-menge = wa_ekko-menge.
wa_po-netwr = wa_ekko-netwr.
wa_po-matnr = wa_ekko-matnr.
wa_po-ekgrp = wa_ekko-ekgrp.
wa_po-bukrs = wa_ekko-bukrs.
wa_po-sakto = wa_ekkn-sakto.
APPEND wa_po TO it_po.
CLEAR wa_po.
ENDIF.
ENDLOOP.
DELETE it_po WHERE vbeln IS INITIAL .
DELETE it_po WHERE posnr IS INITIAL.
SORT it_po BY vbeln posnr .
IF it_po IS NOT INITIAL.
SELECT ekgrp eknam
FROM t024
INTO TABLE it_tyst024
FOR ALL ENTRIES IN it_po
WHERE ekgrp = it_po-ekgrp.
ENDIF.
IF it_po IS NOT INITIAL .
SELECT ebeln ebelp eindt
FROM eket
INTO TABLE it_eket
FOR ALL ENTRIES IN it_po
WHERE ebeln = it_po-ebeln
AND ebelp = it_po-ebelp
AND eindt IN so_eindt.
ENDIF.
SELECT vbeln kunnr vkorg vbtyp vkgrp knumv auart
FROM vbak
INTO TABLE it_vbak
WHERE "vbtyp = 'B'
vkorg = pa_vkorg
AND vkgrp IN so_vkgrp.
it_slgrp[] = it_vbak[].
DELETE it_vbak[] WHERE vbtyp NE 'B'.
* Sales Group Description
SELECT vkgrp bezei
FROM tvgrt
INTO TABLE it_tvgrt
FOR ALL ENTRIES IN it_vbak
WHERE vkgrp = it_vbak-vkgrp.
IF it_po IS NOT INITIAL.
*vbap~vbeln posnr matnr prctr
SELECT vbap~vbeln posnr matnr prctr vgbel
FROM vbap
INTO TABLE it_vbap
FOR ALL ENTRIES IN it_po
WHERE vbap~vbeln = it_po-vbeln .
ENDIF.
IF it_po IS NOT INITIAL .
SELECT ekko~ebeln ebelp frggr frgsx sakto frgzu bukrs
FROM ekko INNER JOIN ekkn
ON ekko~ebeln = ekkn~ebeln
INTO TABLE it_ekko1
FOR ALL ENTRIES IN it_po
WHERE ekko~ebeln = it_po-ebeln
AND sakto IN ('0050000000').
ENDIF.
IF it_ekko1 IS NOT INITIAL.
SELECT frggr frgsx frgc1 frgc2
FROM t16fs
INTO TABLE it_t16fs
FOR ALL ENTRIES IN it_ekko1
WHERE frggr = it_ekko1-frggr
AND frgsx = it_ekko1-frgsx .
ENDIF.
sort it_po by ebeln ebelp vbeln posnr knumv lifnr menge matnr ekgrp bukrs netwr sakto DESCENDING .
DELETE ADJACENT DUPLICATES FROM it_po COMPARING ebeln ebelp vbeln posnr knumv lifnr menge matnr ekgrp bukrs netwr .
LOOP AT it_po INTO wa_po.
wa_final-ebeln = wa_po-ebeln.
wa_final-ebelp = wa_po-ebelp.
CLEAR wa_eket.
READ TABLE it_eket INTO wa_eket WITH KEY ebeln = wa_final-ebeln ebelp = wa_final-ebelp .
IF sy-subrc IS NOT INITIAL.
CLEAR wa_final.
CONTINUE.
ENDIF.
wa_final-eindt = wa_eket-eindt.
CLEAR wa_tyst024.
READ TABLE it_tyst024 INTO wa_tyst024 WITH KEY ekgrp = wa_po-ekgrp.
wa_final-ekgrp = wa_tyst024-eknam.
wa_final-menge = wa_po-menge.
CLEAR wa_ekko1.
READ TABLE it_ekko1 INTO wa_ekko1 WITH KEY ebeln = wa_po-ebeln ebelp = wa_po-ebelp." sakto = '0023000000'.
CLEAR wa_vbap.
READ TABLE it_vbap INTO wa_vbap WITH KEY vbeln = wa_po-vbeln ."posnr = wa_po-posnr .
CLEAR wa_vbak .
READ TABLE it_vbak INTO wa_vbak WITH KEY vbeln = wa_vbap-vgbel .
CLEAR wa_slgrp.
READ TABLE it_slgrp INTO wa_slgrp WITH KEY vbeln = wa_po-vbeln.
IF ( so_vkgrp IS NOT INITIAL ) AND ( wa_slgrp-vkgrp NOT IN so_vkgrp ).
CLEAR wa_final.
CONTINUE.
ENDIF.
CLEAR wa_tvgrt .
READ TABLE it_tvgrt INTO wa_tvgrt WITH KEY vkgrp = wa_slgrp-vkgrp.
IF sy-subrc IS INITIAL.
wa_final-vkgrp = wa_tvgrt-bezei.
ENDIF.
End
IF wa_ekko1-frgzu IS INITIAL.
wa_final-icon = icon_checked.
ELSEIF wa_ekko1-frgzu = 'X'.
wa_final-icon1 = icon_checked.
ENDIF.
wa_final-avg = wa_po-netwr / wa_po-menge .
APPEND wa_final TO it_final.
CLEAR wa_final.
ENDLOOP.
ENDFORM. " FETCH_IT_DATA
*&---------------------------------------------------------------------*
*& Form ALV_BUILD_FIELDCAT1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv_build_fieldcat1 .
DATA lv_fldcat TYPE lvc_s_fcat.
wa_sort-fieldname = 'EBELN'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort .
CLEAR wa_sort.
lv_fldcat-col_pos = '1'.
lv_fldcat-fieldname = 'EBELN'.
lv_fldcat-tabname = 'IT_FINAL'.
lv_fldcat-outputlen = 15.
lv_fldcat-scrtext_m = 'PO'.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
lv_fldcat-col_pos = '2'.
lv_fldcat-fieldname = 'EBELP'.
lv_fldcat-tabname = 'IT_FINAL'.
lv_fldcat-outputlen = 15.
lv_fldcat-scrtext_m = 'PO Item'.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
lv_fldcat-col_pos = '3'.
lv_fldcat-fieldname = 'EKGRP'.
lv_fldcat-tabname = 'IT_FINAL'.
lv_fldcat-outputlen = 15.
lv_fldcat-scrtext_m = 'Purchase Grp'.
* lv_fldcat-key = 'X'.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
lv_fldcat-col_pos = '4'.
lv_fldcat-fieldname = 'MENGE'.
lv_fldcat-tabname = 'IT_FINAL'.
lv_fldcat-outputlen = 15.
lv_fldcat-scrtext_m = 'PO Quantity'.
* lv_fldcat-key = 'X'.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
lv_fldcat-col_pos = '5'.
lv_fldcat-fieldname = 'AVG'.
lv_fldcat-tabname = 'IT_FINAL'.
lv_fldcat-outputlen = 15.
lv_fldcat-scrtext_m = 'Unit Price'.
* lv_fldcat-key = 'X'.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
lv_fldcat-col_pos = '6'.
lv_fldcat-fieldname = 'EINDT'.
lv_fldcat-tabname = 'IT_FINAL'.
lv_fldcat-outputlen = 15.
lv_fldcat-scrtext_m = 'PO Del. Date'.
* lv_fldcat-key = 'X'.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
lv_fldcat-col_pos = '7'.
lv_fldcat-fieldname = 'VKGRP'.
lv_fldcat-tabname = 'IT_FINAL'.
lv_fldcat-outputlen = 15.
lv_fldcat-scrtext_m = 'Sale Group'.
* lv_fldcat-key = 'X'.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
lv_fldcat-col_pos = '8'.
* lv_fldcat-value = 'LIGHT'.
lv_fldcat-fieldname = 'ICON'.
lv_fldcat-tabname = 'IT_FINAL'.
lv_fldcat-outputlen = 15.
lv_fldcat-scrtext_m = 'Not Yet Release'.
* lv_fldcat-key = 'X'.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
ENDFORM. " ALV_BUILD_FIELDCAT1
*&---------------------------------------------------------------------*
*& Form ALV_REPORT_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv_report_layout .
*CONSTANTS: lc_alv_header TYPE c LENGTH 70 VALUE 'PO Release'."#EC *
CLEAR it_layout.
it_layout-col_opt = 'X'.
it_layout-zebra = 'X'.
it_layout-sel_mode = 'A'.
* it_layout-grid_title = lc_alv_header. "To add a Grid Title
ENDFORM. " ALV_REPORT_LAYOUT
*&---------------------------------------------------------------------*
*& Form top_of_page_event
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->DG_DYNDOC_ID text
*----------------------------------------------------------------------*
FORM top_of_page_event USING dg_dyndoc_id TYPE REF TO cl_dd_document.
DATA : dl_text(255) TYPE c. "Text
DATA : vtext(255) TYPE c.
CLEAR vtext.
SELECT SINGLE vtext
FROM tvkot
INTO vtext
WHERE vkorg = '2000' ".pa_vkorg
AND spras = sy-langu.
CONCATENATE 'XX Report for ' vtext INTO vtext SEPARATED BY space.
CALL METHOD dg_dyndoc_id->add_text
EXPORTING
text = vtext "'xx Summary'
sap_style = cl_dd_area=>heading
sap_fontsize = cl_dd_area=>large
sap_color = cl_dd_area=>list_heading_int.
CALL METHOD dg_dyndoc_id->add_gap
EXPORTING
width = 100.
CALL METHOD dg_dyndoc_id->new_line.
CLEAR : dl_text.
PERFORM show.
ENDFORM. " TOP_OF_PAGE_EVENT
*&---------------------------------------------------------------------*
*& Form SHOW
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM show .
* Creating html control
IF o_html_cntrl IS INITIAL.
CREATE OBJECT o_html_cntrl
EXPORTING
parent = o_parent_top.
ENDIF.
CALL METHOD o_dyndoc_id->merge_document.
o_dyndoc_id->html_control = o_html_cntrl.
* Display document
CALL METHOD o_dyndoc_id->display_document
EXPORTING
reuse_control = 'X'
parent = o_parent_top
EXCEPTIONS
html_display_error = 1.
IF sy-subrc NE 0.
MESSAGE 'Error in displaying top-of-page' TYPE 'E'.
ENDIF.
ENDFORM. " SHOW
*&---------------------------------------------------------------------*
*& Module fetch_data INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE fetch_data INPUT.
CALL METHOD c_ccont->free. " Container
CLEAR c_ccont.
ENDMODULE. " fetch_data INPUT
*&---------------------------------------------------------------------*
*& Form CUSTOMBUTTON
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM custombutton .
DATA lv_editbtn TYPE REF TO cl_salv_wd_fe_button.
DATA lr_buttonui TYPE REF TO cl_salv_wd_fe_button.
CREATE OBJECT lr_buttonui.
lr_buttonui->set_text( 'Details' ).
lr_buttonui->set_tooltip('Shows Detail Screen as per the View selected' ).
** Generating Function Object for Button.
*DATA btn_button TYPE REF TO cl_salv_wd_function.
*btn_button = lo_value->if_salv_wd_function_settings~create_function( id = 'DETAILS' ).
*btn_button->set_editor( lr_buttonui ).
*DATA lr_buttonui1 TYPE REF TO cl_salv_wd_fe_button.
ENDFORM. " CUSTOMBUTTON
*&---------------------------------------------------------------------*
*& Form FORM_SET_GRID_VARI
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_I_VARIANT text
*----------------------------------------------------------------------*
FORM form_set_grid_vari CHANGING cs_vari TYPE disvariant..
cs_vari-report = sy-repid.
cs_vari-handle = space.
cs_vari-log_group = space.
cs_vari-username = sy-uname.
* cs_vari-variant = 'A'.
cs_vari-text = space.
cs_vari-dependvars = space.
ENDFORM. " FORM_SET_GRID_VARI
*&---------------------------------------------------------------------*
*& Form RELEASE_PO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_FINAL_EBELN text
* -->P_0819 text
*----------------------------------------------------------------------*
FORM release_po USING p_ebeln TYPE bapimmpara-po_number
value(p_code) TYPE bapimmpara-po_rel_cod.
DATA: it_return TYPE TABLE OF bapireturn,
wa_return TYPE bapireturn.
CALL FUNCTION 'BAPI_PO_RELEASE'
EXPORTING
purchaseorder = p_ebeln
po_rel_code = p_code
use_exceptions = 'X'
no_commit = ' '
* IMPORTING
* REL_STATUS_NEW =
* REL_INDICATOR_NEW =
* RET_CODE =
TABLES
return = it_return
EXCEPTIONS
authority_check_fail = 1
document_not_found = 2
enqueue_fail = 3
prerequisite_fail = 4
release_already_posted = 5
responsibility_fail = 6
OTHERS = 7
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
COMMIT WORK.
CLEAR wa_return.
READ TABLE it_return INTO wa_return WITH KEY type = 'E'.
IF sy-subrc IS INITIAL.
wa_result-ebeln = p_ebeln.
wa_result-message = wa_return-message.
APPEND wa_result TO it_result.
CLEAR wa_result.
ELSE.
DELETE it_final WHERE ebeln EQ p_ebeln.
CALL METHOD c_alvgd->refresh_table_display.
ENDIF.
ENDFORM. " RELEASE_PO
FORM call_tx USING rs_selfield TYPE lvc_s_col.
CASE rs_selfield-fieldname.
WHEN 'EBELN'.
SET PARAMETER ID 'BES' FIELD wa_final-ebeln.
CALL TRANSACTION 'ME22N' .
* WHEN .
WHEN OTHERS.
ENDCASE.
ENDFORM. " CALL_TX
Comments
Post a Comment