SAP ABAP - Custom Report Vendor Invoice
1. Table Maintenance For Document Type
#Main Program
*&---------------------------------------------------------------------*
*& Report ZVIMR001
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report zvimr001.
include zvimr001_01. "Class Variable Declaration
include zvimr001_02. "Class Definition and Implementation
*&---------------------------------------------------------------------*
*& INITIALIZATION
*&---------------------------------------------------------------------*
initialization.
create object g_ref_main.
*&---------------------------------------------------------------------*
*& AT SELECTION-SCREEN
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& AT SELECTION-SCREEN OUTPUT
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& AT SELECTION-SCREEN ON VALUE-REQUEST
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
start-of-selection.
if rb01 = abap_true.
g_ref_main->get_data_summary( ).
else.
g_ref_main->get_data_details( ).
endif.
*&---------------------------------------------------------------------*
*& END-OF-SELECTION
*&---------------------------------------------------------------------*
end-of-selection.
g_ref_main->display_alv( ).
#Include zvimr001_01
*&---------------------------------------------------------------------*
*& Include ZVIMR001_01
*&---------------------------------------------------------------------*
tables : bsik, lfa1, ztvim004.
selection-screen begin of block sel1 with frame title text-001.
select-options :
s_bukrs for bsik-bukrs,
s_gjahr for bsik-gjahr,
s_ktokk for lfa1-ktokk,
s_lifnr for lfa1-lifnr,
s_vgrop for ztvim004-vimgroup,
s_waers for bsik-waers.
parameters :
p_kdate type datum default sy-datum.
selection-screen end of block sel1.
selection-screen begin of block sel2 with frame title text-002.
selection-screen begin of line.
parameters: rb01 radiobutton group rb.
selection-screen comment 3(15) text-rb1.
parameters: rb02 radiobutton group rb.
selection-screen comment 21(15) text-rb2.
selection-screen end of line.
selection-screen end of block sel2.
class lcl_main definition deferred.
*&---------------------------------------------------------------------*
*& Types
*&---------------------------------------------------------------------*
types :
begin of ty_bsak,
bukrs type bukrs,
belnr type bsak-belnr,
gjahr type bsak-gjahr,
buzei type bsak-buzei,
lifnr type lifnr,
zuonr type bsak-zuonr,
budat type budat,
bldat type bldat,
zfbdt type bsak-zfbdt,
dmbtr type bsak-dmbtr,
wrbtr type bsak-wrbtr,
waers type bsak-waers,
shkzg type bsak-shkzg,
sgtxt type bsak-sgtxt,
zterm type bsak-zterm,
cpudt type bsak-cpudt,
zoved type i,
end of ty_bsak.
*&---------------------------------------------------------------------*
*& Work Areas
*&---------------------------------------------------------------------*
data :
ls_data type zsvimr001,
ls_data_tmp type zsvimr001,
ls_data_summ type zsvimr001_dtl,
ls_bsak type ty_bsak,
ls_bsik type ty_bsak,
ls_outp type ty_bsak,
ls_head type ty_bsak,
ls_ztvim003 type ztvim003.
data:
lt_fieldcat type slis_t_fieldcat_alv,
lt_sort type slis_t_sortinfo_alv,
ls_fieldcat type slis_fieldcat_alv,
is_layout type slis_layout_alv,
ls_sort type slis_sortinfo_alv.
*&---------------------------------------------------------------------*
*& Internal Tables
*&---------------------------------------------------------------------*
data :
lt_data type table of zsvimr001,
lt_data_tmp type table of zsvimr001,
lt_data_summ type table of zsvimr001_dtl,
lt_outp type table of ty_bsak,
lt_bsak type table of ty_bsak,
lt_bsik type table of ty_bsak,
lt_head type table of ty_bsak,
lt_ztvim003 type table of ztvim003.
*&---------------------------------------------------------------------*
*& Variables
*&---------------------------------------------------------------------*
data :
indx type i,
icount type i,
idate type i.
*&---------------------------------------------------------------------*
*& Constants
*&---------------------------------------------------------------------*
constants:
yes type flag value 'X',
no type flag value space.
*&---------------------------------------------------------------------*
*& Field Symbols
*&---------------------------------------------------------------------*
field-symbols:
<fs_drseg> type mmcr_drseg.
*&---------------------------------------------------------------------*
*& Object
*&---------------------------------------------------------------------*
data: g_ref_main type ref to lcl_main.
#Include zvimr001_02
*&---------------------------------------------------------------------*
*& Include ZVIMR001_02
*&---------------------------------------------------------------------*
class lcl_main definition final.
public section.
methods:
get_data_summary,
get_data_details,
display_alv.
endclass.
class lcl_main implementation.
method get_data_summary.
refresh : lt_data, lt_bsak, lt_bsik, lt_outp, lt_ztvim003, lt_head.
select * from ztvim003 into table lt_ztvim003
where lifnr in s_lifnr and ktokk in s_ktokk and vimgroup in s_vgrop.
sort lt_ztvim003 by lifnr.
check lt_ztvim003 is not initial.
"BSIK
select a~bukrs a~belnr a~gjahr a~buzei a~lifnr a~zuonr a~budat a~bldat a~zfbdt a~dmbtr a~wrbtr a~waers a~shkzg
from bsik as a left join bkpf as b
on a~belnr = b~belnr and a~gjahr = b~gjahr and a~bukrs = b~bukrs
inner join ztvim007 as c on a~blart = c~blart
into table lt_bsik
for all entries in lt_ztvim003
where a~lifnr = lt_ztvim003-lifnr and
a~bukrs in s_bukrs and a~gjahr in s_gjahr and a~waers in s_waers.
"BSAK
* select a~bukrs a~belnr a~gjahr a~buzei a~lifnr a~zuonr a~budat a~bldat a~zfbdt a~dmbtr a~wrbtr a~waers a~shkzg
* from bsak as a left join bkpf as b
* on a~belnr = b~belnr and a~gjahr = b~gjahr and a~bukrs = b~bukrs
* into table lt_bsak
* for all entries in lt_ztvim003
* where a~lifnr = lt_ztvim003-lifnr and
* a~bukrs in s_bukrs and a~gjahr in s_gjahr and a~waers in s_waers.
* if lt_bsak is not initial.
* append lines of lt_bsak to lt_outp.
* endif.
if lt_bsik is not initial.
append lines of lt_bsik to lt_outp.
endif.
append lines of lt_outp to lt_head.
sort lt_head by bukrs lifnr.
delete adjacent duplicates from lt_head comparing bukrs lifnr.
sort lt_outp by bukrs ascending gjahr ascending belnr ascending buzei ascending.
delete adjacent duplicates from lt_outp comparing bukrs gjahr belnr buzei.
sort lt_outp by bukrs lifnr.
loop at lt_head into ls_head.
clear ls_outp.
read table lt_outp into ls_outp with key bukrs = ls_head-bukrs lifnr = ls_head-lifnr binary search.
if sy-subrc = 0.
clear : indx, icount.
indx = sy-tabix.
clear : ls_data, ls_ztvim003.
read table lt_ztvim003 into ls_ztvim003 with key lifnr = ls_head-lifnr binary search.
ls_data-name1 = ls_ztvim003-name1.
ls_data-vimgroup = ls_ztvim003-vimgroup.
ls_data-waers = ls_head-waers.
ls_data-lifnr = ls_head-lifnr.
ls_data-bukrs = ls_head-bukrs.
select single zdesc from ztvim004 into ls_data-zdesc where vimgroup = ls_ztvim003-vimgroup.
loop at lt_outp into ls_outp from indx.
if ls_outp-bukrs <> ls_head-bukrs or ls_outp-lifnr <> ls_head-lifnr.
exit.
endif.
icount = icount + 1.
if ls_outp-shkzg = 'S'.
ls_outp-dmbtr = ls_outp-dmbtr * -1.
ls_outp-wrbtr = ls_outp-wrbtr * -1.
endif.
ls_data-ivtotal = ls_data-ivtotal + ls_outp-dmbtr.
idate = p_kdate - ls_outp-zfbdt.
* if idate < 0.
* ls_data-ivamount1 = ls_data-ivamount1 + ls_outp-dmbtr.
* else
if idate >= 0 and idate <= 30.
ls_data-ivamount2 = ls_data-ivamount2 + ls_outp-dmbtr.
elseif idate >= 31 and idate <= 60.
ls_data-ivamount3 = ls_data-ivamount3 + ls_outp-dmbtr.
elseif idate >= 61 and idate <= 90.
ls_data-ivamount4 = ls_data-ivamount4 + ls_outp-dmbtr.
elseif idate >= 91 and idate <= 120.
ls_data-ivamount5 = ls_data-ivamount5 + ls_outp-dmbtr.
elseif idate > 120.
ls_data-ivamount6 = ls_data-ivamount6 + ls_outp-dmbtr.
endif.
* move-corresponding ls_outp to ls_data.
* ls_data-nourut = icount.
clear ls_outp.
endloop.
append ls_data to lt_data.
endif.
clear ls_head.
endloop.
refresh lt_data_tmp.
append lines of lt_data to lt_data_tmp.
sort lt_data_tmp by vimgroup.
delete adjacent duplicates from lt_data_tmp comparing vimgroup.
sort lt_data_tmp by vimgroup.
loop at lt_data_tmp into ls_data_tmp.
clear : ls_data, icount.
clear ls_data.
loop at lt_data into ls_data where vimgroup = ls_data_tmp-vimgroup.
icount = icount + 1.
clear ls_data-nourut.
ls_data-nourut = icount.
modify lt_data from ls_data transporting nourut
where vimgroup = ls_data-vimgroup and lifnr = ls_data-lifnr and bukrs = ls_data-bukrs.
clear ls_data.
endloop.
endloop.
sort lt_data by vimgroup nourut ascending.
endmethod.
method get_data_details.
refresh : lt_data, lt_bsak, lt_bsik, lt_outp, lt_ztvim003, lt_head.
select * from ztvim003 into table lt_ztvim003
where lifnr in s_lifnr and ktokk in s_ktokk and vimgroup in s_vgrop.
sort lt_ztvim003 by lifnr.
check lt_ztvim003 is not initial.
"BSIK
select a~bukrs a~belnr a~gjahr a~buzei a~lifnr a~zuonr a~budat a~bldat a~zfbdt a~dmbtr a~wrbtr a~waers a~shkzg
a~sgtxt a~zterm a~cpudt
from bsik as a left join bkpf as b
on a~belnr = b~belnr and a~gjahr = b~gjahr and a~bukrs = b~bukrs
inner join ztvim007 as c on a~blart = c~blart
into table lt_bsik
for all entries in lt_ztvim003
where a~lifnr = lt_ztvim003-lifnr and
a~bukrs in s_bukrs and a~gjahr in s_gjahr and a~waers in s_waers.
"BSAK
* select a~bukrs a~belnr a~gjahr a~buzei a~lifnr a~zuonr a~budat a~bldat a~zfbdt a~dmbtr a~wrbtr a~waers a~shkzg
* a~sgtxt a~zterm a~cpudt
* from bsak as a left join bkpf as b
* on a~belnr = b~belnr and a~gjahr = b~gjahr and a~bukrs = b~bukrs
* into table lt_bsak
* for all entries in lt_ztvim003
* where a~lifnr = lt_ztvim003-lifnr and
* a~bukrs in s_bukrs and a~gjahr in s_gjahr and a~waers in s_waers.
* if lt_bsak is not initial.
* append lines of lt_bsak to lt_outp.
* endif.
if lt_bsik is not initial.
append lines of lt_bsik to lt_outp.
endif.
clear : icount, ls_outp.
loop at lt_outp into ls_outp.
clear : ls_ztvim003.
read table lt_ztvim003 into ls_ztvim003 with key lifnr = ls_outp-lifnr binary search.
icount = icount + 1.
if ls_outp-shkzg = 'S'.
ls_outp-dmbtr = ls_outp-dmbtr * -1.
ls_outp-wrbtr = ls_outp-wrbtr * -1.
endif.
clear idate.
idate = p_kdate - ls_outp-zfbdt.
clear ls_data_summ.
move-corresponding ls_outp to ls_data_summ.
ls_data_summ-nourut = icount.
ls_data_summ-vimgroup = ls_ztvim003-vimgroup.
ls_data_summ-name1 = ls_ztvim003-name1.
ls_data_summ-iovdue = idate.
select single zdesc from ztvim004 into ls_data_summ-zdesc where vimgroup = ls_ztvim003-vimgroup.
ls_data_summ-lwaers = 'IDR'.
append ls_data_summ to lt_data_summ.
clear ls_outp.
endloop.
endmethod.
method display_alv.
if rb01 = abap_true.
refresh lt_fieldcat.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'ZSVIMR001'
changing
ct_fieldcat = lt_fieldcat
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
clear ls_fieldcat.
loop at lt_fieldcat into ls_fieldcat.
if ls_fieldcat-fieldname = 'VIMGROUP' or ls_fieldcat-fieldname = 'BUKRS' or ls_fieldcat-fieldname = 'LIFNR'
or ls_fieldcat-fieldname = 'ZDESC'.
ls_fieldcat-key = 'X'.
ls_fieldcat-fix_column = 'X'.
if ls_fieldcat-fieldname = 'ZDESC'.
clear : ls_fieldcat-seltext_l, ls_fieldcat-seltext_m, ls_fieldcat-seltext_s.
ls_fieldcat-seltext_s = ls_fieldcat-seltext_m = ls_fieldcat-seltext_l = 'Vendor Group Name'.
endif.
if ls_fieldcat-fieldname = 'VIMGROUP'.
ls_fieldcat-no_out = 'X'.
endif.
elseif ls_fieldcat-fieldname = 'NOURUT'.
ls_fieldcat-key = 'X'.
ls_fieldcat-fix_column = 'X'.
clear : ls_fieldcat-seltext_l, ls_fieldcat-seltext_m, ls_fieldcat-seltext_s.
ls_fieldcat-seltext_l = ls_fieldcat-seltext_m = ls_fieldcat-seltext_s = 'No'.
elseif ls_fieldcat-fieldname = 'IVTOTAL'.
ls_fieldcat-do_sum = 'X'.
* elseif ls_fieldcat-fieldname = 'IVAMOUNT1'.
* clear : ls_fieldcat-seltext_l, ls_fieldcat-seltext_m, ls_fieldcat-seltext_s.
* ls_fieldcat-seltext_s = ls_fieldcat-seltext_m = ls_fieldcat-seltext_l = 'Not Yet Due'.
* ls_fieldcat-do_sum = 'X'.
* ls_fieldcat-no_out = 'X'.
elseif ls_fieldcat-fieldname = 'IVAMOUNT2'.
clear : ls_fieldcat-seltext_l, ls_fieldcat-seltext_m, ls_fieldcat-seltext_s.
ls_fieldcat-seltext_l = ls_fieldcat-seltext_m = ls_fieldcat-seltext_s = '0-30 Days'.
ls_fieldcat-do_sum = 'X'.
elseif ls_fieldcat-fieldname = 'IVAMOUNT3'.
clear : ls_fieldcat-seltext_l, ls_fieldcat-seltext_m, ls_fieldcat-seltext_s.
ls_fieldcat-seltext_l = ls_fieldcat-seltext_m = ls_fieldcat-seltext_s = '31-60 Days'.
ls_fieldcat-do_sum = 'X'.
elseif ls_fieldcat-fieldname = 'IVAMOUNT4'.
clear : ls_fieldcat-seltext_l, ls_fieldcat-seltext_m, ls_fieldcat-seltext_s.
ls_fieldcat-seltext_l = ls_fieldcat-seltext_m = ls_fieldcat-seltext_s = '61-90 Days'.
ls_fieldcat-do_sum = 'X'.
elseif ls_fieldcat-fieldname = 'IVAMOUNT5'.
clear : ls_fieldcat-seltext_l, ls_fieldcat-seltext_m, ls_fieldcat-seltext_s.
ls_fieldcat-seltext_l = ls_fieldcat-seltext_m = ls_fieldcat-seltext_s = '91-120 Days'.
ls_fieldcat-do_sum = 'X'.
elseif ls_fieldcat-fieldname = 'IVAMOUNT6'.
clear : ls_fieldcat-seltext_l, ls_fieldcat-seltext_m, ls_fieldcat-seltext_s.
ls_fieldcat-seltext_l = ls_fieldcat-seltext_m = ls_fieldcat-seltext_s = '> 120 Days'.
ls_fieldcat-do_sum = 'X'.
endif.
modify lt_fieldcat from ls_fieldcat
transporting key fix_column seltext_s seltext_m seltext_l do_sum no_out
where fieldname = ls_fieldcat-fieldname.
clear ls_fieldcat.
endloop.
clear is_layout.
is_layout-colwidth_optimize = 'X'.
is_layout-zebra = 'X'.
refresh lt_sort.
* clear ls_sort.
* ls_sort-spos = 1.
* ls_sort-fieldname = 'VIMGROUP'.
* ls_sort-up = 'X'.
* ls_sort-group = 'UL'. "or '*'.
* ls_sort-subtot = 'X'.
** ls_sort-expa = 'X'.
* append ls_sort to lt_sort.
clear ls_sort.
ls_sort-spos = 2.
ls_sort-fieldname = 'ZDESC'.
ls_sort-up = 'X'.
ls_sort-group = 'UL'. "or '*'.
ls_sort-subtot = 'X'.
* ls_sort-expa = 'X'.
append ls_sort to lt_sort.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
is_layout = is_layout
it_fieldcat = lt_fieldcat
it_sort = lt_sort
tables
t_outtab = lt_data
exceptions
program_error = 1
others = 2.
else.
refresh lt_fieldcat.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'ZSVIMR001_DTL'
changing
ct_fieldcat = lt_fieldcat
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
clear ls_fieldcat.
loop at lt_fieldcat into ls_fieldcat.
if ls_fieldcat-fieldname = 'VIMGROUP' or ls_fieldcat-fieldname = 'NAME1' or ls_fieldcat-fieldname = 'LIFNR'
or ls_fieldcat-fieldname = 'ZDESC'.
ls_fieldcat-key = 'X'.
ls_fieldcat-fix_column = 'X'.
if ls_fieldcat-fieldname = 'ZDESC'.
clear : ls_fieldcat-seltext_l, ls_fieldcat-seltext_m, ls_fieldcat-seltext_s.
ls_fieldcat-seltext_s = ls_fieldcat-seltext_m = ls_fieldcat-seltext_l = 'Vendor Group Name'.
endif.
if ls_fieldcat-fieldname = 'VIMGROUP'.
ls_fieldcat-no_out = 'X'.
endif.
elseif ls_fieldcat-fieldname = 'NOURUT'.
ls_fieldcat-key = 'X'.
ls_fieldcat-fix_column = 'X'.
clear : ls_fieldcat-seltext_l, ls_fieldcat-seltext_m, ls_fieldcat-seltext_s.
ls_fieldcat-seltext_l = ls_fieldcat-seltext_m = ls_fieldcat-seltext_s = 'No'.
elseif ls_fieldcat-fieldname = 'DMBTR'.
ls_fieldcat-do_sum = 'X'.
elseif ls_fieldcat-fieldname = 'IOVDUE'.
clear : ls_fieldcat-seltext_l, ls_fieldcat-seltext_m, ls_fieldcat-seltext_s.
ls_fieldcat-seltext_s = ls_fieldcat-seltext_m = ls_fieldcat-seltext_l = 'Days Over Due'.
* ls_fieldcat-do_sum = 'X'.
endif.
modify lt_fieldcat from ls_fieldcat
transporting key fix_column seltext_s seltext_m seltext_l do_sum no_out
where fieldname = ls_fieldcat-fieldname.
clear ls_fieldcat.
endloop.
clear is_layout.
is_layout-colwidth_optimize = 'X'.
is_layout-zebra = 'X'.
* refresh lt_sort.
* clear ls_sort.
* ls_sort-spos = 3.
* ls_sort-fieldname = 'LIFNR'.
* ls_sort-up = 'X'.
* ls_sort-group = 'UL'. "or '*'.
* ls_sort-subtot = 'X'.
** ls_sort-expa = 'X'.
* append ls_sort to lt_sort.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
is_layout = is_layout
it_fieldcat = lt_fieldcat
it_sort = lt_sort
tables
t_outtab = lt_data_summ
exceptions
program_error = 1
others = 2.
endif.
endmethod.
endclass.
Report output
Comments
Post a Comment