*---------------------------------------------------------------------*
* FORM get_vendor *
*---------------------------------------------------------------------*
* 取供应商主数据 *
*---------------------------------------------------------------------*
FORM get_vendor.
DATA: BEGIN OF itab_object OCCURS 0,
objectid LIKE lfa1-lifnr ,
END OF itab_object.
DATA: BEGIN OF itab_adrc OCCURS 0,
addrnumber LIKE adrc-addrnumber,
name1 LIKE adrc-name1,
name3 LIKE adrc-name3,
str_suppl1 LIKE adrc-str_suppl1,
smtp_addr LIKE adr6-smtp_addr,
END OF itab_adrc.
DATA: BEGIN OF itab_knvk OCCURS 0,
lifnr LIKE lfa1-lifnr,
name2 LIKE knvk-name1,
END OF itab_knvk.
DATA: BEGIN OF itab_bnka OCCURS 0,
lifnr LIKE lfbk-lifnr,
banka LIKE bnka-banka,
bankn LIKE lfbk-bankn,
END OF itab_bnka.
DATA: BEGIN OF itab_lfb1 OCCURS 0,
lifnr LIKE lfb1-lifnr,
bukrs LIKE lfb1-bukrs,
zterm LIKE lfb1-zterm,
END OF itab_lfb1.
DATA: BEGIN OF itab_temp OCCURS 0 ,
adrnr LIKE lfa1-adrnr.
INCLUDE STRUCTURE itab_vendor.
DATA: END OF itab_temp.
SELECT cdhdr~objectid
INTO CORRESPONDING FIELDS OF TABLE itab_object
FROM cdhdr
WHERE cdhdr~objectclas = 'KRED' AND
cdhdr~udate = p_date .
LOOP AT itab_object.
IF itab_object-objectid+0(1) = 'B'. "B开头为员工
DELETE itab_object.
ENDIF.
ENDLOOP.
SORT itab_object.
DELETE ADJACENT DUPLICATES FROM itab_object.
CHECK NOT itab_object[] IS INITIAL.
SELECT lfa1~spras
lfa1~lifnr
lfa1~stceg
lfa1~regio
lfa1~stras
lfa1~pstlz
lfa1~telf1
lfa1~telfx
lfa1~adrnr
lfa1~ernam AS buy_id
lfa1~ktokk AS vendor_type
INTO CORRESPONDING FIELDS OF TABLE itab_temp
FROM lfa1
FOR ALL ENTRIES IN itab_object
WHERE lfa1~lifnr = itab_object-objectid.
SELECT
knvk~lifnr
knvk~name1 AS knname1
INTO CORRESPONDING FIELDS OF TABLE itab_knvk
FROM knvk
FOR ALL ENTRIES IN itab_object
WHERE knvk~lifnr = itab_object-objectid.
SELECT lfbk~lifnr
bnka~banka
lfbk~bankn
INTO CORRESPONDING FIELDS OF TABLE itab_bnka
FROM lfbk INNER JOIN bnka
ON lfbk~banks = bnka~banks AND
lfbk~bankl = bnka~bankl
FOR ALL entries IN itab_object
WHERE lfbk~lifnr = itab_object-objectid.
CHECK NOT itab_temp[] IS INITIAL.
SELECT adrc~addrnumber
adrc~str_suppl1
adrc~name1
adrc~name3
adr6~smtp_addr
INTO CORRESPONDING FIELDS OF TABLE itab_adrc
FROM adrc LEFT JOIN adr6 ON adrc~addrnumber = adr6~addrnumber
FOR ALL entries IN itab_temp
WHERE adrc~addrnumber = itab_temp-adrnr .
LOOP AT itab_temp.
READ TABLE itab_knvk WITH KEY lifnr = itab_temp-lifnr.
IF sy-subrc = 0.
itab_temp-knname1 = itab_knvk-name2.
ENDIF.
READ TABLE itab_bnka WITH KEY lifnr = itab_temp-lifnr.
IF sy-subrc = 0.
itab_temp-banka = itab_bnka-banka.
itab_temp-bankn = itab_bnka-bankn.
ENDIF.
READ TABLE itab_adrc WITH KEY addrnumber = itab_temp-adrnr.
IF sy-subrc = 0.
itab_temp-name1 = itab_adrc-name1.
itab_temp-name3 = itab_adrc-name3.
itab_temp-str_suppl1 = itab_adrc-str_suppl1.
itab_temp-smtp_addr = itab_adrc-smtp_addr.
ENDIF.
MOVE-CORRESPONDING itab_temp TO itab_vendor.
APPEND itab_vendor .
CLEAR itab_temp.
ENDLOOP.
ENDFORM.
阅读(1192) | 评论(0) | 转发(0) |