*&---------------------------------------------------------------------*
*& Progarm : ZSDRSP001 Author : David Liao
*& Created : 2012-08-23 App : SD
*& Title : deliver information for shipment plan and daily shipping report
*& Description : deliver information for shipment plan and daily shipping report
*&---------------------------------------------------------------------*
*& Version Author Date description
*& David 23 Aug 2012 the first version
*& M1 Jimmy 10 Oct 2012 chang list to Alv
*& M2 Jimmy 12 Nov 2012 Enhance refresh button
*& M3 Jimmy 14 Nov 2012 Enhance DN Item Split duplication
*& M4 Jimmy 20 Nov 2012 Add field Serial No. Status
*& M5 Jimmy 27 Nov 2012 Add field POItem "POSEX"
*& M6 Jimmy 30 Nov 2012 Remark Billing status = 'C' Chekc
*& M7 Jimmy 02 Dec 2012 Ehance execute speed
*& M8 Jimmy 13 Dec 2012 Add column SO Item & DN Item Size/dimensions
*& M9 Jimmy 26 Dec 2012 gross/net weight CBM by mara get add total carton
*& M10 Jimmy 30 Jan 2013 Unloading Point find so item
*& M11 Jimmy 25 Feb 2013 Add column Credit limit used (>100 PMT No Approved) & SO Price (PMT Display)
*& & Dun. level (=3 pmt not approved)
*& M12 Jimmy M11 change Warning
*& the last update time 2013.03.12 12:00
*&---------------------------------------------------------------------*
report zsdrsp001 ."line-count 30 line-size 430.
*-----------Table declaration----------------begin---------------------*
tables: likp, "SD Document: Delivery Header Data
lips, "SD document: Delivery: Item data
kna1, "General Data in Customer Master
t173t, "Routes: Mode of Transport by Shipping Type: Texts
vbak, "Sales Document: Header Data
vbup, "Sales Document: Item Status
marc, "Plant Data for Material
vbfa, "Sales Document Flow
vbkd, "Sales Document: Business Data
tvzbt .
*-----------Internal table declaration--------begin--------------------*
type-pools:slis.
data: wa_alv_field1 type slis_fieldcat_alv , " 相当于工作区
wa_alv_fieldcat1 type slis_t_fieldcat_alv . " 存放列名的捏表
data:wa_alv_t_event1 type slis_extab,
wa_alv_event1 type standard table of slis_extab with header line .
data: lw_layout type slis_layout_alv,
gs_status type slis_formname value 'FRM_PF_STATUS_SET'.
data: is_variant type disvariant.
is_variant-report = sy-repid.
data: sla type lvc_s_layo.
data: begin of itab1 occurs 0,
uecha like lips-uecha,
kunnr_sd like likp-kunnr, "Sold to
name_sd like kna1-name1, "Sold to name "M2 add
kunnr like likp-kunnr, "Ship to
name1 like kna1-name1, "Ship to name
vkorg like likp-vkorg, "Sales Org.
landx like t005t-landx, "Country
auart like vbak-auart, "Order type
vgbel like lips-vgbel, "REFERENCE DOC.
vgpos like lips-vgpos, "REFERENCE DOC item
vbeln like lips-vbeln, "Delivery
matnr like lips-matnr, "Material
arktx like lips-arktx, "Description
kdmat like knmt-kdmat, "Customer P/N
vrkme like lips-vrkme, "Sales unit
lfimg like lips-lfimg, "Delivery qty
volum like likp-volum, "Volume
vsart like likp-vsart, "Shipping type
vsart_dn like likp-vsart, "Shipping type
bezei like t173t-bezei, "Description
brgew like lips-brgew, "Gross weight
ntgew like lips-ntgew, "Net weight
bstnk like vbak-bstnk, "PO
lifsk like likp-lifsk, "Delivery block (document header)
kosta like vbup-kosta, "Picking status/Putaway status
wbsta like vbup-wbsta, "GI status
fksta like vbup-fksta, "Billing status
sernp like marc-sernp, "Serial Number Profile
rfmng like vbfa-rfmng, "Pick qty
inco1 like vbkd-inco1, "incoterms
inco2 like vbkd-inco2, "incoterms 2
zterm like vbkd-zterm, "payment terms
wadat like likp-wadat, "Planed GI date
wauhr like likp-wauhr, "Planed GI time "M2 add
wadat_ist like likp-wadat_ist, "Actual GI date
vtext like tvzbt-vtext,
tdline(700) type c,
posnr like lips-posnr,
vbeln_vf type c length 11,"like vbrp-vbeln,
sel,
ablad like vbpa-ablad, "Unloading Point
land1 like kna1-land1,
gewei like lips-gewei, "weight unit,
status like bsvx-sttxt,"Serial No. Status "M4 add
werks like lips-werks, "Plant "M4 add
posex like vbap-posex, "POItem
groes like mara-groes,
ctnno type i,
kbetr like komv-kbetr, "M11 add
kpein like komv-kpein, "M11 add
klprz type p decimals 2, "M11 add
knumv like konv-knumv, "M11 add
mahns like knkkf1-mahns, "M11
end of itab1.
data: itab2 like itab1 occurs 0 with header line,
itab3 like itab1 occurs 0 with header line,
wa_itab like itab1,
lines type tline occurs 0 with header line,
it_split like itab1 occurs 0 with header line.
data: begin of it_select occurs 0,
sel,
vbeln like lips-vbeln, "Delivery
end of it_select.
data: vl_tdname like thead-tdname .
data: vl_id like thead-tdid .
data: vl_obj like thead-tdobject .
data: vl_lang like thead-tdspras.
data: lv_i type i.
data: lv_tabix like sy-tabix,
lv_vbeln like lips-vbeln,
is_success type c,
p_lifsk like likp-lifsk,
lv_price type c.
data:begin of it_t173t occurs 200,
vsart like t173t-vsart,
bezei like t173t-bezei, "Description
end of it_t173t.
data:begin of it_vbpa occurs 0,
vbeln like vbpa-vbeln,
posnr like vbpa-posnr, "M10
ablad like vbpa-ablad,
end of it_vbpa.
data:begin of it_kna1 occurs 0,
kunnr like kna1-kunnr,
name1 like kna1-name1,
land1 like kna1-land1,
end of it_kna1.
data:begin of it_t005t occurs 0,
land1 like t005t-land1,
landx like t005t-landx ,
end of it_t005t.
data:begin of it_vbfa occurs 0,
vbelv like vbfa-vbelv,
posnv like vbfa-posnv ,
rfmng like vbfa-rfmng, "Pick qty
end of it_vbfa.
data:begin of it_vbrp occurs 0,
vgbel like vbrp-vgbel,
vgpos like vbrp-vgpos ,
vbeln like vbrp-vbeln,
end of it_vbrp.
data:begin of it_vbup occurs 0,
vbeln like vbup-vbeln,
posnr like vbup-vbeln,
kosta like vbup-vbeln, "Pick status
wbsta like vbup-vbeln, "GI status
fksta like vbup-vbeln, "Billing status
uecha like lips-uecha,
end of it_vbup.
data: begin of gt_serial occurs 0,
vbeln like lips-vbeln,
posnr like lips-posnr,
sernr like objk-sernr,
matnr like mara-matnr,
werks like eqbs-b_werk,
objnr like equi-objnr,
status like bsvx-sttxt,
end of gt_serial.
data: begin of it_mara occurs 0, "M8 add
matnr like mara-matnr,
brgew like mara-brgew,
ntgew like mara-ntgew,
volum like mara-volum ,
gewei like mara-gewei,
groes like mara-groes,
end of it_mara.
data: begin of it_konv occurs 0, "M11 add
knumv like konv-knumv,
kposn like konv-kposn,
kbetr like konv-kbetr,
kpein like konv-kpein,
end of it_konv.
data: begin of it_knkk occurs 0, "M11 add
kunnr like knkk-kunnr,
klimk like knkk-klimk,
sauft like knkk-sauft,
skfor like knkk-skfor,
ssobl like knkk-ssobl,
knkli like knkk-knkli,
end of it_knkk.
data: begin of it_knkkf1 occurs 0, "M11 add
kunnr like knkkf1-kunnr,
knkli like knkk-knkli,
mahns like knkkf1-mahns,
end of it_knkkf1 .
data:it_vbup1 like it_vbup occurs 0 with header line.
data:it_vbkd type standard table of vbkd with header line.
data:it_vbap type standard table of vbap with header line. "M5 add
ranges:s_ddate2 for likp-wadat.
data: lv_kosta like vbup-kosta, "Picking status/Putaway status
lv_wbsta like vbup-wbsta, "GI status
lv_fksta like vbup-fksta. "Billing status
data:lv_total_line type i,
lv_line type p decimals 3.
constants:c_chk_num like pa0001-ename value '0123456789.'.
*-----------SELECTION-SCREEN------------------begin--------------------*
selection-screen begin of block b1 with frame title text-001.
select-options: s_ddate for likp-wadat . "Planed GI date
select-options: s_spoint for likp-vstel. "Shipping Point
select-options: s_sorg for likp-vkorg. "Sales Org
select-options: s_chan for likp-vtwiv. "Channel
select-options: s_div for lips-spart. "Division
select-options: s_sparty for vbak-kunnr. "Sold to/Bill to
select-options: s_shipt for vbak-kunnr. "Ship to
select-options: s_desti for likp-ablad no-display. "Destination
select-options: s_vbeln for likp-vbeln. "DN
select-options: s_so for lips-vgbel. "SO
select-options: s_auart for vbak-auart. "Sale Document type "M5 add
select-options: s_kosta for vbup-kosta. "Pick status
select-options: s_wbsta for vbup-wbsta . "GI status
select-options: s_fksta for vbup-fksta. "Billing status
select-options: s_lifsk for likp-lifsk. "delivery block status
select-options: s_vsart for likp-vsart. "shiping type
parameter : s_refsh type char1 no-display. "M2 add
selection-screen skip.
parameters: p1 radiobutton group g1 user-command u1 default 'X',
p2 radiobutton group g1 ,
p3 radiobutton group g1 ,
p4 radiobutton group g1.
selection-screen end of block b1.
initialization.
at selection-screen output.
if s_refsh is initial. "M2 add
refresh s_ddate.
case 'X'.
when p1.
s_ddate-high = sy-datum + 7.
when p2.
s_ddate-high = sy-datum + 3.
when p3.
s_ddate-high = sy-datum + 1.
when p4.
s_ddate-high = sy-datum .
endcase.
s_ddate-low = sy-datum.
s_ddate-sign = 'I'.
s_ddate-option = 'BT'.
append s_ddate.
endif.
*-----------INITIALIZATION------------------EVENT----------------------*
start-of-selection.
clear:lv_price.
authority-check object 'ZDNAPP01'
id 'ACTVT' field '02'
id 'VKBUR' field '3101'
id 'VKGRP' field '102'.
if sy-subrc eq 0.
lv_price = 'X'.
endif.
perform get_data.
describe table itab3 lines lv_i.
if lv_i = 0.
message 'No Data Found' type 'I'.
exit.
endif.
perform process_data.
describe table itab2 lines lv_i.
if lv_i = 0.
message 'No Data Found' type 'I'.
exit.
endif.
perform display_data.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form get_data.
clear:itab2,itab2[],itab3,itab3[].
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Getting Data........'.
select distinct
p~kunnr
* k~name1 "CUSTOMER
p~vkorg "LOCATION
* t~landx "COUNTRY
p~kunag as kunnr_sd
v~auart "Order type
s~vgbel "SO NO
s~vgpos "SO item
p~vbeln "DN
s~matnr "MATNR
s~arktx "Short text for sales order item
s~vrkme "Sales unit
s~lfimg "Actual quantity delivered (in sales units)
* p~volum "CBM "M9 Remark
* s~brgew "Gross weigth
* s~ntgew "Net weight
* s~gewei "weight Unit
v~bstnk "PO
r~sernp "Serial number profile "?
p~lifsk "delivery block status
* b~kosta "Pick status
* b~wbsta "GI status
* b~fksta "Billing status
* f~rfmng "PICK Quantity
* d~inco1 "incoterms
* d~inco2 "incoterms2
* d~zterm "payment terms
p~wadat "Planed GI Date
p~wauhr "Planed GI Time "M2 add
p~wadat_ist "Actual Goods Movement Date
* d~vsart
p~vsart as vsart_dn
* z~vtext
s~posnr "DN Item
s~kdmat "customer Material
s~uecha "split item
s~werks
v~knumv
into corresponding fields of table itab3
from likp as p inner join lips as s
on p~vbeln = s~vbeln
inner join vbak as v
on s~vgbel = v~vbeln
inner join marc as r
on r~matnr = s~matnr and r~werks = s~werks
where p~wadat in s_ddate and
p~vstel in s_spoint and
p~vkorg in s_sorg and
s~vtweg in s_chan and
p~kunnr in s_shipt and
p~kunag in s_sparty and
s~spart in s_div and
p~vbeln in s_vbeln and
s~vgbel in s_so and
p~lifsk in s_lifsk and
v~auart in s_auart.
sort itab2 by vbeln posnr.
endform. "get_data
*&---------------------------------------------------------------------*
*& Form process_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form process_data.
data: thead like thead,
lv_size type i,
lv_p type p decimals 2,
lv_i type i,
lv_olikw like s067-olikw,
lv_ofakw like s067-ofakw,
lv_oeikw like s066-oeikw,
lv_bill type c.
thead-tdid = 'Z002'.
thead-tdspras = sy-langu.
thead-tdobject = 'VBBK'.
select vsart bezei into table it_t173t
from t173t
where spras = sy-langu.
sort it_t173t by vsart.
select vbeln posnr ablad
into corresponding fields of table it_vbpa
from vbpa
for all entries in itab3
where vbeln = itab3-vgbel
and posnr = itab3-vgpos "M10 add
and parvw = 'WE'.
sort it_vbpa by vbeln posnr.
select vbelv posnv rfmng
into corresponding fields of table it_vbfa
from vbfa
for all entries in itab3
where vbelv = itab3-vbeln
and posnv = itab3-posnr
and vbtyp_n = 'Q'.
sort it_vbfa by vbelv posnv.
select kunnr name1 land1
into corresponding fields of table it_kna1
from kna1.
sort it_kna1 by kunnr.
select land1 landx into table it_t005t
from t005t
where spras = sy-langu.
sort it_t005t by land1.
select a~vgbel a~vgpos a~vbeln "M7 remove distinct
into corresponding fields of table it_vbrp
from vbrp as a inner join vbrk as b on a~vbeln = b~vbeln
for all entries in itab3
where b~fksto ne 'X'
and a~aubel = itab3-vgbel "M7 add
and a~aupos = itab3-vgpos
and a~vgbel = itab3-vbeln
and a~vgpos = itab3-posnr.
* and ( a~vbeln like '08%' or a~vbeln like '05%' ). "M7 remark
sort it_vbrp by vbeln descending vgbel vgpos ascending.
select * into corresponding fields of table it_vbkd
from vbkd
for all entries in itab3
where vbeln = itab3-vgbel.
sort it_vbkd by vbeln posnr.
select a~vbeln a~posnr a~kosta a~wbsta a~fksta
into corresponding fields of table it_vbup1
from vbup as a
for all entries in itab3
where a~vbeln = itab3-vbeln
and a~posnr = itab3-posnr.
sort it_vbup1 by vbeln posnr.
*M4 Add
select b~sernr a~posnr a~lief_nr as vbeln
into corresponding fields of table gt_serial
from ser01 as a join objk as b
on a~obknr = b~obknr
for all entries in itab3
where a~lief_nr = itab3-vbeln
and a~posnr = itab3-posnr
and b~taser = 'SER01'.
sort gt_serial by vbeln posnr sernr.
delete adjacent duplicates from gt_serial comparing all fields.
*M4 End
*M5 add
select * into corresponding fields of table it_vbap
from vbap
for all entries in itab3
where vbeln = itab3-vgbel
and posnr = itab3-vgpos.
sort it_vbap by vbeln posnr.
*M5 end
*M8 add
select matnr brgew ntgew volum gewei groes into corresponding fields of table it_mara
from mara
for all entries in itab3
where matnr = itab3-matnr.
sort it_mara by matnr.
*M8 end
*M11 add
if lv_price = 'X'.
select knumv kposn kbetr kpein
into corresponding fields of table it_konv
from konv
for all entries in itab3
where knumv = itab3-knumv
and kposn = itab3-vgpos
and ( kschl = 'PR00'
or kschl like 'Z%').
sort it_konv by knumv kposn.
endif.
select kunnr klimk sauft skfor ssobl knkli
into corresponding fields of table it_knkk
from knkk
for all entries in itab3
where kunnr = itab3-kunnr_sd
and kkber = '8000'.
loop at it_knkk.
move-corresponding it_knkk to it_knkkf1 .
select single mahns into it_knkkf1-mahns
from knkkf1
where kunnr = it_knkkf1-knkli
and kkber = '8000'.
append it_knkkf1.
if it_knkk-kunnr ne it_knkk-knkli.
clear:it_knkk-klimk,it_knkk-skfor,it_knkk-ssobl .
select single klimk skfor ssobl into (it_knkk-klimk,it_knkk-skfor,it_knkk-ssobl )
from knkk
where kunnr = it_knkk-knkli
and kkber = '8000'.
endif.
call function 'SD_CREDIT_EXPOSURE'
exporting
flag_open_delivery = 'X'
flag_open_invoice = 'X'
flag_open_order = 'X'
horizon_date = '20120101'
* HORIZON_DATE = '99991231'
kkber = '8000'
knkli = it_knkk-knkli
importing
open_delivery = lv_olikw
open_invoice = lv_ofakw
open_order = lv_oeikw.
it_knkk-sauft = lv_olikw + lv_ofakw + lv_oeikw.
modify it_knkk.
endloop.
sort it_knkk by kunnr .
sort it_knkkf1 by kunnr .
*M11 End