Report for PO - GR/IR clearing account
Report for GR/IR clearing values for purchase orders. It gives GR amount, Invoice amount and GR/IR clearing amount.
tables: ekko, ekpo, ekbe, ekkn.
types: begin of ty_output,
ebeln like ekko-ebeln,
ebelp like ekpo-ebelp,
ekgrp like ekko-ekgrp,
kostl like ekkn-kostl,
ablad like ekkn-ablad,
menge like ekpo-menge,
docty(12),
belnr like ekbe-belnr,
budat like ekbe-budat,
g_wemng like ekbes-wemng,
g_wewrt like ekbes-wewrt,
i_remng like ekbes-remng,
arewr like ekbes-arewr,
i_rewrt like ekbes-rewrt,
cudays like ekbe-wrbtr,
30days like ekbe-wrbtr,
60days like ekbe-wrbtr,
90days like ekbe-wrbtr,
end of ty_output.
types: begin of ty_poitem,
ebeln LIKE ekko-ebeln,
bukrs LIKE ekko-bukrs,
bstyp LIKE ekko-bstyp,
lifnr LIKE ekko-lifnr,
ekorg LIKE ekko-ekorg,
ekgrp LIKE ekko-ekgrp,
ebelp LIKE ekpo-ebelp,
matnr LIKE ekpo-matnr,
menge LIKE ekpo-menge,
meins LIKE ekpo-meins,
bprme LIKE ekpo-bprme,
netpr LIKE ekpo-netpr,
peinh LIKE ekpo-peinh,
webre LIKE ekpo-webre,
wepos LIKE ekpo-wepos,
repos LIKE ekpo-repos,
waers LIKE ekko-waers,
weunb LIKE ekpo-weunb,
elikz LIKE ekpo-elikz,
retpo LIKE ekpo-retpo,
* Item category in purchasing document and
* Indicator for service-based invoice verification
pstyp like ekpo-pstyp,
lebre like ekpo-lebre,
vrtkz LIKE ekpo-vrtkz,
END OF ty_poitem.
types: begin of ty_ekkn,
ebeln type ekkn-ebeln,
ebelp type ekkn-ebelp,
kostl type ekkn-kostl,
ablad type ekkn-ablad,
end of ty_ekkn.
data: it_poitem type standard table of ty_poitem,
wa_poitem type ty_poitem.
field-symbols: <wa_poitem> type ty_poitem.
data: it_ekbes type standard table of ekbes,
wa_ekbes type ekbes.
data: it_ekbe type standard table of ekbe,
wa_ekbe type ekbe.
data: it_ekkn type hashed table of ty_ekkn with unique key ebeln ebelp,
wa_ekkn type ty_ekkn.
data: it_output type standard table of ty_output,
wa_output type ty_output.
data: v_count type I.
data: it_alv type ref to cl_salv_table.
class lcl_handle_events definition deferred.
data: gr_events type ref to lcl_handle_events.
select-options : s_bukrs for ekko-bukrs,
s_ebeln for ekko-ebeln,
s_ekgrp for ekko-ekgrp,
s_aedat for ekko-aedat.
*----------------------------------------------------------------------*
* CLASS lcl_handle_events DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
METHODS
on_link_click FOR EVENT link_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS. "lcl_handle_events DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_handle_events IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_handle_events IMPLEMENTATION.
METHOD on_link_click.
PERFORM show_cell_info USING row column.
ENDMETHOD. "on_link_click
ENDCLASS. "lcl_handle_events IMPLEMENTATION
start-of-selection.
perform get_data.
perform display_data.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form GET_DATA .
SELECT ekko~ebeln ekko~bukrs ekko~bstyp
ekko~lifnr ekko~ekorg ekko~ekgrp
ekpo~ebelp ekpo~matnr ekpo~menge
ekpo~meins ekpo~bprme ekpo~netpr
ekpo~peinh ekpo~webre ekpo~wepos
ekpo~repos ekko~waers ekpo~weunb
ekpo~elikz ekpo~retpo
* Item category PO and flag for service-based IV
ekpo~pstyp ekpo~lebre
ekpo~vrtkz
INTO CORRESPONDING FIELDS OF TABLE it_poitem
FROM ekko INNER JOIN ekpo
ON ekko~mandt = ekpo~mandt
AND ekko~ebeln = ekpo~ebeln
WHERE ekko~bukrs IN s_bukrs
AND ekko~ekgrp IN s_ekgrp
AND ekko~aedat in s_aedat
AND ekpo~ebeln IN s_ebeln
AND ekpo~wepos <> space
AND ekpo~repos <> space
AND ekpo~weunb = space.
* and ekpo~elikz = 'X'.
if it_poitem[] is initial.
exit.
endif.
select ebeln ebelp kostl ablad from ekkn into corresponding fields of table it_ekkn
for all entries in it_poitem
where ebeln = it_poitem-ebeln and
ebelp = it_poitem-ebelp.
loop at it_poitem assigning <wa_poitem>.
clear: it_ekbe[], it_ekbes[].
CALL FUNCTION 'ME_READ_HISTORY'
EXPORTING
ebeln = <wa_poitem>-ebeln
EBELP = <wa_poitem>-ebelp
webre = <wa_poitem>-webre
I_BYPASSING_BUFFER = 'X'
I_REFRESH_BUFFER = 'X'
* I_EKBEH =
* LFGJA =
* LFBNR =
* LFPOS =
* VRTKZ =
* I_NO_EXPAND_MA = ' '
TABLES
XEKBE = it_ekbe
XEKBES = it_ekbes
* XEKBEZ =
* XEKBNK =
* XEKBZ =
* XRSEG =
* XEKBE_MA =
* XEKBZ_MA =
* XEKBES_MA =
* XEKBNK_MA =
.
loop at it_ekbes into wa_ekbes where zekkn eq space.
if ( wa_ekbes-wemng <> wa_ekbes-remng ) or ( wa_ekbes-rewrt <> wa_ekbes-wewrt ) .
wa_output-ebeln = <wa_poitem>-ebeln.
wa_output-ebelp = <wa_poitem>-ebelp.
wa_output-ekgrp = <wa_poitem>-ekgrp.
wa_output-menge = <wa_poitem>-menge.
sort it_ekbe descending.
read table it_ekbe into wa_ekbe with key ebeln = <wa_poitem>-ebeln
ebelp = <wa_poitem>-ebelp.
if wa_ekbe-bewtp = 'E'.
wa_output-docty = 'Goods Receipt'.
elseif wa_ekbe-bewtp = 'Q' or wa_ekbe-bewtp = 'R'.
wa_output-docty = 'Invoice'.
endif.
wa_output-belnr = wa_ekbe-belnr.
wa_output-budat = wa_ekbe-budat.
wa_output-g_wemng = wa_ekbes-wemng.
wa_output-g_wewrt = wa_ekbes-wewrt * -1 .
wa_output-i_remng = wa_ekbes-remng.
wa_output-i_rewrt = wa_ekbes-rewrt.
wa_output-arewr = wa_ekbes-arewr.
read table it_ekkn into wa_ekkn with key ebeln = <wa_poitem>-ebeln
ebelp = <wa_poitem>-ebelp.
wa_output-kostl = wa_ekkn-kostl.
wa_output-ablad = wa_ekkn-ablad.
v_count = sy-datum - wa_ekbe-budat.
if v_count < 30 .
wa_output-cudays = ( wa_ekbes-wewrt * -1 ) + wa_ekbes-arewr.
elseif v_count >= 30 and v_count < 60 .
wa_output-30days = ( wa_ekbes-wewrt * -1 ) + wa_ekbes-arewr.
elseif v_count >= 60 and v_count < 90.
wa_output-60days = ( wa_ekbes-wewrt * -1 ) + wa_ekbes-arewr.
elseif v_count >= 90.
wa_output-90days = ( wa_ekbes-wewrt * -1 ) + wa_ekbes-arewr.
endif.
append wa_output to it_output.
clear wa_output.
endif.
endloop.
clear: it_ekbe[], it_ekbes[], wa_ekbes, wa_poitem, wa_ekbe, v_count, wa_ekkn.
endloop.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form SHOW_CELL_INFO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ROW text
* -->P_COLUMN text
*----------------------------------------------------------------------*
FORM show_cell_info USING p_row TYPE i
p_column TYPE lvc_fname.
DATA: l_row_string TYPE string,
l_col_string TYPE string,
l_row TYPE char128.
WRITE p_row TO l_row LEFT-JUSTIFIED.
READ TABLE it_output INTO wa_output INDEX p_row.
SET PARAMETER ID 'BES' FIELD wa_output-ebeln.
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
CLEAR wa_output.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form DISPLAY_DATA .
** creating instance
cl_salv_table=>factory(
IMPORTING
r_salv_table = it_alv
CHANGING
t_table = it_output ).
**... §3.1 activate ALV generic Functions
DATA: lr_functions TYPE REF TO cl_salv_functions_list.
DATA: lr_layout type ref to CL_SALV_LAYOUT.
data: ls_key type SALV_S_LAYOUT_KEY.
lr_functions = it_alv->get_functions( ).
lr_functions->set_all( 'X' ).
lr_layout = it_alv->get_layout( ).
ls_key-report = sy-repid.
lr_layout->set_key( ls_key ).
lr_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).
PERFORM set_columns.
*... set the columns technical
DATA: lr_columns TYPE REF TO cl_salv_columns,
lr_column TYPE REF TO cl_salv_column_table.
lr_columns = it_alv->get_columns( ).
*... §4 set hotspot column
TRY.
lr_column ?= lr_columns->get_column( 'EBELN' ).
lr_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
*... §6 register to the events of cl_salv_table
DATA: lr_events TYPE REF TO cl_salv_events_table.
lr_events = it_alv->get_event( ).
CREATE OBJECT gr_events.
*... §6.5 register to the event LINK_CLICK
SET HANDLER gr_events->on_link_click FOR lr_events.
it_alv->display( ).
endform. " DISPLAY_DATA
*&---------------------------------------------------------------------*
*& Form SET_COLUMNS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form SET_COLUMNS .
**... set the columns technical
DATA: lr_columns TYPE REF TO cl_salv_columns.
lr_columns = it_alv->get_columns( ).
lr_columns->set_optimize( abap_true ).
DATA: lr_column TYPE REF TO cl_salv_column.
lr_column = lr_columns->get_column( 'CUDAYS' ).
lr_column->set_short_text( ' < 30 days' ).
lr_column = lr_columns->get_column( 'CUDAYS' ).
lr_column->set_medium_text( 'Less than 30 days' ).
lr_column = lr_columns->get_column( 'CUDAYS' ).
lr_column->set_long_text( 'Less than 30 days' ).
lr_column = lr_columns->get_column( '30DAYS' ).
lr_column->set_short_text( '30 to 60' ).
lr_column = lr_columns->get_column( '30DAYS' ).
lr_column->set_medium_text( '30 to 60 days' ).
lr_column = lr_columns->get_column( '30DAYS' ).
lr_column->set_long_text( '30 to 60 days' ).
lr_column = lr_columns->get_column( '60DAYS' ).
lr_column->set_short_text( '60 to 90' ).
lr_column = lr_columns->get_column( '60DAYS' ).
lr_column->set_medium_text( '60 to 90 days' ).
lr_column = lr_columns->get_column( '60DAYS' ).
lr_column->set_long_text( '60 to 90 days' ).
lr_column = lr_columns->get_column( '90DAYS' ).
lr_column->set_short_text( ' > 90 days' ).
lr_column = lr_columns->get_column( '90DAYS' ).
lr_column->set_medium_text( 'More than 90 days' ).
lr_column = lr_columns->get_column( '90DAYS' ).
lr_column->set_long_text( 'More than 90 days' ).
lr_column = lr_columns->get_column( 'DOCTY' ).
lr_column->set_short_text( 'Doc Type' ).
lr_column = lr_columns->get_column( 'DOCTY' ).
lr_column->set_medium_text( 'Document Type' ).
lr_column = lr_columns->get_column( 'DOCTY' ).
lr_column->set_long_text( 'Document Type' ).
lr_column = lr_columns->get_column( 'MENGE' ).
lr_column->set_short_text( 'PO Qty' ).
lr_column = lr_columns->get_column( 'MENGE' ).
lr_column->set_medium_text( 'PO Quantity' ).
lr_column = lr_columns->get_column( 'MENGE' ).
lr_column->set_long_text( 'PO Quantity' ).
endform. " SET_COLUMNS
Comments
Post a Comment