*Sales Document: Header Data
data : begin of wt_vbak occurs 0,
vbeln like vbak-vbeln,
erdat like vbak-erdat,
kunnr like vbak-kunnr,
end of wt_vbak.
*Sales Document: Item Data
data : begin of wt_vbap occurs 0,
vbeln like vbap-vbeln,
posnr like vbap-posnr,
matnr like vbap-matnr,
arktx like vbap-arktx,
kwmeng like vbap-kwmeng,
werks like vbap-werks,
erdat like vbak-erdat,
kunnr like vbak-kunnr,
end of wt_vbap.
*Sales Document Flow
data : begin of wt_vbfa occurs 0,
vbelv like vbfa-vbelv,
posnv like vbfa-posnv,
vbeln like vbfa-vbeln,
posnn like vbfa-posnn,
vbtyp_n like vbfa-vbtyp_n,
end of wt_vbfa.
*Sales Document Flow
data : begin of wt_vbfa1 occurs 0,
vbelv like vbfa-vbelv,
posnv like vbfa-posnv,
vbeln like vbfa-vbeln,
posnn like vbfa-posnn,
vbtyp_n like vbfa-vbtyp_n,
end of wt_vbfa1.
*SD Document: Delivery Header Data
data : begin of wt_likp occurs 0,
vbeln like likp-vbeln,
lfdat like likp-lfdat,
end of wt_likp.
*SD document: Delivery: Item data
data : begin of wt_lips occurs 0,
vbeln like lips-vbeln,
posnr like lips-posnr,
lfimg like lips-lfimg,
meins like lips-meins,
end of wt_lips.
*Delivery Note Additional Quantity (L20)
data : begin of wt_lipso2 occurs 0,
vbeln like lipso2-vbeln,
posnr like lipso2-posnr,
msehi like lipso2-msehi,
adqntp like lipso2-adqntp,
end of wt_lipso2.
*Final Table for ALV Display
data : begin of wt_final occurs 0,
erdat like vbak-erdat,
vbeln like vbap-vbeln,
posnr like vbap-posnr,
kunnr like vbak-kunnr,
name1 like kna1-name1,
matnr like vbap-matnr ,
arktx like vbap-arktx,
kwmeng like vbap-kwmeng,
werks like vbap-werks,
delno like likp-vbeln,
delitem like lips-posnr,
deldate like likp-lfdat,
delquan like lips-lfimg,
uom like lips-meins,
altuom like lipso2-msehi,
quanl20 like lips-lfimg,
invoice like vbrk-vbeln,
invitem like vbrp-posnr,
end of wt_final.
*Billing Document: Header Data
data : begin of wt_vbrk occurs 0,
vbeln like vbrk-vbeln,
fksto like vbrk-fksto,
end of wt_vbrk.
*Customer Details
data : begin of wt_kna1 occurs 0,
kunnr like kna1-kunnr,
name1 like kna1-name1,
end of wt_kna1.
----------------------------------------------------------------------
*ALV DATA *
----------------------------------------------------------------------
data : ws_alvfield type slis_fieldcat_alv ,
wt_fieldcat type slis_t_fieldcat_alv.
----------------------------------------------------------------------
*PARAMETERS / SELECTION SCREEN *
----------------------------------------------------------------------
selection-screen begin of block b1 with frame
title text-001.
select-options s_werks for vbap-werks.
parameters p_vkorg like vbak-vkorg obligatory.
select-options : s_vtweg for vbak-vtweg,
s_spart for vbak-spart,
s_erdat for vbak-erdat obligatory.
selection-screen end of block b1.
************************************************************************
*AT SELECTION-SCREEN *
************************************************************************
at selection-screen.
*---------------------------------------------------------------------
** Form select_data
*---------------------------------------------------------------------
form select_data .
data wlt_vbak like wt_vbak occurs 0 with header line.
data wlt_vbfa1 like wt_vbfa1 occurs 0 with header line.
select vbeln erdat kunnr
from vbak
into table wt_vbak
where erdat in s_erdat
and vkorg = p_vkorg
and vtweg in s_vtweg
and spart in s_spart.
if sy-subrc = 0.
wlt_vbak = wt_vbak.
sort wlt_vbak by kunnr.
delete adjacent duplicates from wlt_vbak
comparing kunnr.
select kunnr name1 from kna1
into table wt_kna1
for all entries in wlt_vbak
where kunnr = wlt_vbak-kunnr.
if sy-subrc = 0.
sort wt_kna1 by kunnr.
endif.
sort wt_vbak by vbeln.
select vbeln posnr matnr arktx kwmeng werks
from vbap
into table wt_vbap
for all entries in wt_vbak
where vbeln = wt_vbak-vbeln
and werks in s_werks.
if sy-subrc = 0.
sort wt_vbap by vbeln posnr.
select vbelv posnv vbeln posnn vbtyp_n
into table wt_vbfa
from vbfa
for all entries in wt_vbap
where vbelv = wt_vbap-vbeln
and posnv = wt_vbap-posnr
and vbtyp_n = 'J'.
if sy-subrc = 0.
sort wt_vbfa by vbeln posnn.
delete adjacent duplicates from wt_vbfa
comparing vbeln posnn.
select vbelv posnv vbeln posnn vbtyp_n
into table wt_vbfa1
from vbfa
for all entries in wt_vbfa
where vbelv = wt_vbfa-vbeln
and posnv = wt_vbfa-posnn
and vbtyp_n = 'M'.
if sy-subrc = 0.
sort wt_vbfa1 by vbeln posnn.
wlt_vbfa1] = wt_vbfa1[.
sort wlt_vbfa1 by vbeln.
delete adjacent duplicates from wlt_vbfa1
comparing vbeln.
select vbeln fksto from vbrk
into table wt_vbrk
for all entries in wlt_vbfa1
where vbeln = wlt_vbfa1-vbeln.
endif.
select vbeln lfdat
from likp
into table wt_likp
for all entries in wt_vbfa
where vbeln = wt_vbfa-vbeln.
if sy-subrc = 0.
sort wt_likp by vbeln.
endif.
select vbeln posnr lfimg meins
from lips
into table wt_lips
for all entries in wt_vbfa
where vbeln = wt_vbfa-vbeln
and posnr = wt_vbfa-posnn.
select vbeln posnr msehi adqntp
from lipso2
into table wt_lipso2
for all entries in wt_vbfa
where vbeln = wt_vbfa-vbeln
and posnr = wt_vbfa-posnn
and msehi in ('L','L20').
endif.
endif.
endif.
endform. " select_data
*---------------------------------------------------------------------
** Form prepare_data
*---------------------------------------------------------------------
form prepare_data .
*Local Data
data wlt_vbfa like wt_vbfa occurs 0 with header line.
data : begin of wls_struct1,
vbeln like vbap-vbeln,
posnr like vbap-posnr,
end of wls_struct1.
data : begin of wls_struct2,
vbeln like vbfa-vbelv,
posnr like vbfa-posnv,
end of wls_struct2.
data : begin of wlt_delivery occurs 0,
vbeln like lips-vbeln,
posnr like lips-posnr,
order like vbap-vbeln,
oitem like vbap-posnr,
lfimg like lips-lfimg,
meins like lips-meins,
altuom like lips-meins,
quanl20 like lips-lfimg,
lfdat like likp-lfdat,
invoice like vbrk-vbeln,
invitem like vbrp-posnr,
end of wlt_delivery.
data wlv_index like sy-tabix.
data wlv_index1 like sy-tabix.
data : wlv_adqntpl like lipso2-adqntp,
wlv_adqntpl20 like lipso2-adqntp,
wlv_factor like lipso2-adqntp.
*Local Data ///
sort wt_vbrk by vbeln.
sort wt_vbfa1 by vbeln posnn.
*Delete the Cancelled Invoices
wlv_index = 1.
loop at wt_vbrk.
loop at wt_vbfa1 from wlv_index.
if wt_vbfa1-vbeln > wt_vbrk-vbeln.
wlv_index = sy-tabix.
exit.
elseif wt_vbfa1-vbeln = wt_vbrk-vbeln.
if wt_vbrk-fksto = 'X'.
wt_vbfa1-vbeln = 'X'.
modify wt_vbfa1 transporting vbeln.
clear wt_vbfa1.
endif.
endif.
endloop.
endloop.
delete wt_vbfa1 where vbeln = 'X'.
*Merge Invoices and Deliveries
sort wt_vbfa1 by vbelv posnv.
loop at wt_vbfa1.
wlt_delivery-invoice = wt_vbfa1-vbeln.
wlt_delivery-invitem = wt_vbfa1-posnn.
wlt_delivery-vbeln = wt_vbfa1-vbelv.
wlt_delivery-posnr = wt_vbfa1-posnv.
append wlt_delivery.
clear wlt_delivery.
endloop.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.