**----------------------------------------------------------
field-symbols:
**----------------------------------------------------------
clear ent_retco.
if nast-aende eq space.
l_druvo = '1'.
else.
l_druvo = '2'.
endif.
call function 'ME_READ_PO_FOR_PRINTING'
exporting
ix_nast = nast
ix_screen = ent_screen
importing
ex_retco = ent_retco
ex_nast = l_nast
doc = l_doc
changing
cx_druvo = l_druvo
cx_from_memory = l_from_memory.
check ent_retco eq 0.
**& Modify by TLY 20100306.
loop at l_doc-xekpo assigning
gt_out-ebeln =
gt_out-bedat = l_doc-xekko-bedat. "採購文件日期.
gt_out-lifnr = l_doc-xekko-lifnr. "供應商帳號.
gt_out-adrnr = l_doc-xekko-adrnr. "地址號碼.
gt_out-waers = l_doc-xekko-waers. "幣別碼.
gt_out-ebelp =
gt_out-matnr =
gt_out-verkf = l_doc-xekko-verkf. "銷售員.Add by TLY 20100312.
gt_out-telf1 = l_doc-xekko-telf1. "銷售員電話.Add by TLY 20100312.
gt_out-ekorg = l_doc-xekko-ekorg. "採購組織.Add by TLY 20100312.
gt_out-ekgrp = l_doc-xekko-ekgrp. "採購群組.Add by TLY 20100312.
* gt_out-maktx =
gt_out-meins =
gt_out-netpr =
gt_out-peinh =
gt_out-menge =
gt_out-netwr =
gt_out-mwskz =
gt_out-lgort =
gt_out-adrn2 =
gt_out-werks =
gt_out-txz01 =
gt_out-bpumz =
gt_out-bpumn =
gt_out-snetwr = l_doc-xpekko-netwr.
append gt_out.
clear gt_out.
endloop.
**& Address NO. in DB table T001W.
select werks adrnr pstlz ort01 stras
from t001w
into table gt_t001w.
**& Address Infor.
loop at gt_out.
**& Address NO. exit or not.
if gt_out-adrnr is not initial.
gt_addr-addrnumber = gt_out-adrnr.
else.
select single adrnr
from lfa1
into gt_addr-addrnumber
where lifnr = gt_out-lifnr
and adrnr <> space.
if sy-subrc = 0.
* ELSEIF gt_out-kadrnr IS NOT INITIAL.
* gt_addr-addrnumber = gt_out-kadrnr.
* gt_out-adrnr = gt_out-kadrnr.
gt_out-adrnr = gt_addr-addrnumber.
elseif gt_out-adrn2 is not initial.
gt_addr-addrnumber = gt_out-adrn2.
gt_out-adrnr = gt_out-adrn2.
else.
**& Address NO. in DB table T001W.
read table gt_t001w with key werks = gt_out-werks.
if sy-subrc = 0. "Read success.
gt_addr-addrnumber = gt_t001w-adrnr.
gt_out-adrnr = gt_t001w-adrnr.
clear: gt_t001w.
endif.
endif.
endif.
append gt_addr.
clear:gt_addr.
**& Delivery date.
gt_ddate-ebeln = gt_out-ebeln.
gt_ddate-ebelp = gt_out-ebelp.
append gt_ddate.
clear gt_ddate.
**& Tax rate.
gt_taxr-mwskz = gt_out-mwskz.
append gt_taxr.
clear: gt_taxr.
**& Description of Storage Location.
gt_lgort-werks = gt_out-werks.
gt_lgort-lgort = gt_out-lgort.
append gt_lgort.
clear: gt_lgort.
**& Material description.
gt_maktx-matnr = gt_out-matnr.
append gt_maktx.
clear gt_maktx.
**& Vendor name.
gt_vendort-lifnr = gt_out-lifnr.
append gt_vendort.
clear gt_vendort.
**& Add by TLY 20100312.
* gt_manuf-lifnr = gt_out-lifnr.
* gt_manuf-ekorg = gt_out-ekorg.
* APPEND gt_manuf.
* CLEAR gt_manuf.
gt_porepre-ekgrp = gt_out-ekgrp.
append gt_porepre.
clear gt_porepre.
**& End add by TLY 20100312.
modify gt_out.
clear:gt_out.
endloop.
*& Sort Address NO.
if gt_addr[] is not initial. "Get address infor.
sort gt_addr.
delete adjacent duplicates from gt_addr.
select addrnumber city1 street str_suppl3
tel_number fax_number post_code1
from adrc
into corresponding fields of table gt_addr
for all entries in gt_addr
where addrnumber = gt_addr-addrnumber.
endif.
**& Get Delivery date.
if gt_ddate[] is not initial.
select ebeln ebelp etenr eindt
from eket
into corresponding fields of table gt_ddate
for all entries in gt_ddate
where ebeln = gt_ddate-ebeln
and ebelp = gt_ddate-ebelp.
sort gt_ddate.
endif.
**& Tax rate.
if gt_taxr[] is not initial.
sort gt_taxr.
delete adjacent duplicates from gt_taxr.
select mwskz kursr
from ztmm02
into table gt_taxr
for all entries in gt_taxr
where mwskz = gt_taxr-mwskz
and mwart = 'V'.
endif.
**& Description of Storage Location.
if gt_lgort[] is not initial.
sort gt_lgort.
delete adjacent duplicates from gt_lgort.
select werks lgort lgobe
from t001l
into table gt_lgort
for all entries in gt_lgort
where werks = gt_lgort-werks
and lgort = gt_lgort-lgort.
endif.
**& Add by TLY 20100312.
**& 抓取採購代表及電話.
if gt_porepre[] is not initial.
sort gt_porepre.
delete adjacent duplicates from gt_porepre.
select ekgrp eknam tel_number tel_extens
from t024
into table gt_porepre
for all entries in gt_porepre
where ekgrp = gt_porepre-ekgrp.
endif.
**& 抓取廠商聯絡人及電話.
* IF gt_manuf[] IS NOT INITIAL.
* SORT gt_manuf.
* DELETE ADJACENT DUPLICATES FROM gt_manuf.
* SELECT lifnr ekorg verkf telf1
* FROM lfm1
* INTO TABLE gt_manuf
* FOR ALL ENTRIES IN gt_manuf
* WHERE lifnr = gt_manuf-lifnr
* AND ekorg = gt_manuf-ekorg.
* ENDIF.
**& End add by TLY 20100312.
**& Get user name.
select single a~name_last a~name_first
into (lv_lname, lv_fname )
from usr21 as u
inner join adrp as a on a~persnumber = u~persnumber
where u~bname = sy-uname.
if sy-subrc = 0. "Get successful.
concatenate lv_lname lv_fname into gv_name.
condense gv_name.
endif.
**& Get Material descriptions.
if gt_maktx[] is not initial.
sort gt_maktx.
delete adjacent duplicates from gt_maktx.
select matnr maktx
from makt
into table gt_maktx
for all entries in gt_maktx
where matnr = gt_maktx-matnr
and spras = sy-langu.
endif.
**& Get vendor name.
if gt_vendort[] is not initial.
sort gt_vendort.
delete adjacent duplicates from gt_vendort.
select lifnr name1 adrnr
from lfa1
into table gt_vendort
for all entries in gt_vendort
where lifnr = gt_vendort-lifnr.
endif.
**========== Process data =======================
**& Sort Purchase order infor.
sort gt_out by ebeln lgort.
**& Loop table.
loop at gt_out assigning
**& Delivery date.
at new ebeln.
read table gt_ddate with key ebeln =
if sy-subrc = 0. "Read successful.
lv_eindt = gt_ddate-eindt.
endif.
clear:gt_ddate.
endat.
**& Storage Description.
at new lgort.
read table gt_lgort with key werks =
lgort =
if sy-subrc = 0.
endif.
endat.
**& Material description.
if
endif.
**& Address infor.
read table gt_addr with key addrnumber =
if sy-subrc = 0. "Read successful.
*
*
*
*
clear:gt_addr.
endif.
**& Add by TLY 20100315.
read table gt_t001w with key werks =
if sy-subrc = 0. "Read successful.
clear gt_t001w.
endif.
**& End add by TLY 20100315.
**-------------------------------------------------------------------
**& Currency converting factor.
perform. currency_converting using
changing
** Uint price.
if
*
endif.
**& Add by TLY 20100312.
**& 採購代表及電話.
read table gt_porepre with key ekgrp =
if sy-subrc = 0.
clear: gt_porepre.
endif.
**& 廠商聯絡人及電話.
* READ TABLE gt_manuf WITH KEY lifnr =
* ekorg =
* IF sy-subrc = 0.
*
*
* CLEAR: gt_manuf.
* ENDIF.
**& End add by TLY 20100312.
**& Net Order Value in PO Currency.
lv_netwr = lv_netwr +
**& Tax value.
read table gt_taxr with key mwskz =
if sy-subrc = 0. "Read successful.
lv_taxva = lv_taxva +
endif.
**& Read Purchase Order Item text .
perform. read_text using
changing
**& Read Material description.
if
read table gt_maktx with key matnr =
if sy-subrc = 0. "Read successful.
clear: gt_maktx.
endif.
endif.
**& Read vendor name.
read table gt_vendort with key lifnr =
if sy-subrc = 0.
**& Add by TLY 20100312.
* SELECT SINGLE tel_number fax_number
* FROM adrc
* INTO (
* WHERE addrnumber = gt_vendort-adrnr.
**& End add by TLY 20100312.
clear: gt_vendort.
endif.
at end of ebeln.
**& Read Purchase Order Header text .
perform. read_text using
changing
***& Total value.
clear: lv_netwr, lv_taxva, lv_total, lv_eindt.
endat.
endloop.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/13547743/viewspace-630967/ ,如需转载,请注明出处,否则将追究法律责任。