关于客户主数据的批量更新
转自:http://scnblogs.techweb.com.cn/abaplv/archives/276.html/comment-page-1
客户主数据有很多复杂的维护功能,比如客户的合作伙伴维护,没有相关的bapi实现,做bdc或catt实现起来也比较困难,通过分析源代码,发现这些数据的修改是通过FM:customer_update来实现,然后通过fm:DEBI_WRITE_DOCUMENT来记录主数据的修改历史记录,我做了个测试小程序,用来实现维护客户的合作伙伴,当然其他相关的数据也可以通过这个FM来维护,示例程序如下:
REPORT ZTESTCUSTOMERUPDATE .
DATA: I_KNA1 TYPE KNA1,
I_KNB1 TYPE KNB1,
I_KNVV TYPE KNVV,
I_YKNA1 TYPE KNA1,
I_YKNB1 TYPE KNB1,
T_XKNAS TYPE TABLE OF FKNAS,
T_XKNB5 TYPE TABLE OF FKNB5,
T_XKNBK TYPE TABLE OF FKNBK,
T_XKNVA TYPE TABLE OF FKNVA,
T_XKNVD TYPE TABLE OF FKNVD,
T_XKNVI TYPE TABLE OF FKNVI,
T_XKNVK TYPE TABLE OF FKNVK,
T_XKNVL TYPE TABLE OF FKNVL,
T_XKNVP TYPE TABLE OF FKNVP,
T_XKNVS TYPE TABLE OF FKNVS,
T_XKNEX TYPE TABLE OF FKNEX,
T_XKNZA TYPE TABLE OF FKNZA,
T_YKNAS TYPE TABLE OF FKNAS,
T_YKNB5 TYPE TABLE OF FKNB5,
T_YKNBK TYPE TABLE OF FKNBK,
T_YKNVA TYPE TABLE OF FKNVA,
T_YKNVD TYPE TABLE OF FKNVD,
T_YKNVI TYPE TABLE OF FKNVI,
T_YKNVK TYPE TABLE OF FKNVK,
T_YKNVL TYPE TABLE OF FKNVL,
T_YKNVP TYPE TABLE OF FKNVP,
T_YKNVS TYPE TABLE OF FKNVS,
T_YKNEX TYPE TABLE OF FKNEX,
T_YKNZA TYPE TABLE OF FKNZA,
T_XKNAT TYPE TABLE OF FKNAT,
T_YKNAT TYPE TABLE OF FKNAT,
T_XKNBW TYPE TABLE OF FKNBW,
T_YKNBW TYPE TABLE OF FKNBW,
WA_KNVP TYPE FKNVP,
OBJECTID TYPE CDHDR-OBJECTID.
PARAMETERS: P_KUNNR TYPE KNVP-KUNNR OBLIGATORY,
P_VKORG TYPE KNVP-VKORG OBLIGATORY,
P_VTWEG TYPE KNVP-VTWEG OBLIGATORY,
P_SPART TYPE KNVP-SPART OBLIGATORY,
P_PARVW TYPE KNVP-PARVW OBLIGATORY,
P_PARZA TYPE KNVP-PARZA OBLIGATORY,
P_KUNN2 TYPE KNVP-KUNN2 OBLIGATORY.
START-OF-SELECTION.
WA_KNVP-MANDT = SY-MANDT.
WA_KNVP-KUNNR = P_KUNNR.
WA_KNVP-VKORG = P_VKORG.
WA_KNVP-VTWEG = P_VTWEG.
WA_KNVP-SPART = P_SPART.
WA_KNVP-PARZA = P_PARZA.
WA_KNVP-KUNN2 = P_KUNN2.
WA_KNVP-PARVW = P_PARVW.
WA_KNVP-KZ = ‘I’.
APPEND WA_KNVP TO T_XKNVP.
CALL FUNCTION ‘CUSTOMER_UPDATE’
EXPORTING
I_KNA1 = I_KNA1
I_KNB1 = I_KNB1
I_KNVV = I_KNVV
I_YKNA1 = I_YKNA1
I_YKNB1 = I_YKNB1
TABLES
T_XKNAS = T_XKNAS
T_XKNB5 = T_XKNB5
T_XKNBK = T_XKNBK
T_XKNVA = T_XKNVA
T_XKNVD = T_XKNVD
T_XKNVI = T_XKNVI
T_XKNVK = T_XKNVK
T_XKNVL = T_XKNVL
T_XKNVP = T_XKNVP
T_XKNVS = T_XKNVS
T_XKNEX = T_XKNEX
T_XKNZA = T_XKNZA
T_YKNAS = T_YKNAS
T_YKNB5 = T_YKNB5
T_YKNBK = T_YKNBK
T_YKNVA = T_YKNVA
T_YKNVD = T_YKNVD
T_YKNVI = T_YKNVI
T_YKNVK = T_YKNVK
T_YKNVL = T_YKNVL
T_YKNVP = T_YKNVP
T_YKNVS = T_YKNVS
T_YKNEX = T_YKNEX
T_YKNZA = T_YKNZA
.
OBJECTID = P_KUNNR.
CALL FUNCTION ‘DEBI_WRITE_DOCUMENT’
EXPORTING
OBJECTID = OBJECTID
TCODE = ‘VD02′
UTIME = SY-UZEIT
UDATE = SY-DATUM
USERNAME = SY-UNAME
* PLANNED_CHANGE_NUMBER = ‘ ‘
OBJECT_CHANGE_INDICATOR = ‘U’
* PLANNED_OR_REAL_CHANGES = ‘ ‘
* NO_CHANGE_POINTERS = ‘ ‘
N_KNA1 = I_KNA1
O_YKNA1 = I_KNA1
* UPD_KNA1 = ‘ ‘
* UPD_KNAS = ‘ ‘
* UPD_KNAT = ‘ ‘
N_KNB1 = I_KNB1
O_YKNB1 = I_KNB1
* UPD_KNB1 = ‘ ‘
* UPD_KNB5 = ‘ ‘
* UPD_KNBK = ‘ ‘
* UPD_KNBW = ‘ ‘
* UPD_KNEX = ‘ ‘
* UPD_KNVA = ‘ ‘
* UPD_KNVD = ‘ ‘
* UPD_KNVI = ‘ ‘
* UPD_KNVK = ‘ ‘
* UPD_KNVL = ‘ ‘
UPD_KNVP = ‘X’
* UPD_KNVS = ‘ ‘
N_KNVV = I_KNVV
O_YKNVV = I_KNVV
* UPD_KNVV = ‘ ‘
* UPD_KNZA = ‘ ‘
TABLES
XKNAS = T_XKNAS
YKNAS = T_YKNAS
XKNAT = T_XKNAT
YKNAT = T_YKNAT
XKNB5 = T_XKNB5
YKNB5 = T_YKNB5
XKNBK = T_XKNBK
YKNBK = T_YKNBK
XKNBW = T_XKNBW
YKNBW = T_YKNBW
XKNEX = T_XKNEX
YKNEX = T_YKNEX
XKNVA = T_XKNVA
YKNVA = T_YKNVA
XKNVD = T_XKNVD
YKNVD = T_YKNVD
XKNVI = T_XKNVI
YKNVI = T_YKNVI
XKNVK = T_XKNVK
YKNVK = T_YKNVK
XKNVL = T_XKNVL
YKNVL = T_YKNVL
XKNVP = T_XKNVP
YKNVP = T_YKNVP
XKNVS = T_XKNVS
YKNVS = T_YKNVS
XKNZA = T_XKNZA
YKNZA = T_YKNZA
.
COMMIT WORK AND WAIT.