供应商主数据 同步接口
Posted 学习笔记
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了供应商主数据 同步接口相关的知识,希望对你有一定的参考价值。
FUNCTION zrfc_mm007. *"---------------------------------------------------------------------- *"*"Local interface: *" IMPORTING *" VALUE(CALLNO) TYPE ZCALLNO *" VALUE(ZDATE) TYPE SY-DATUM OPTIONAL *" EXPORTING *" VALUE(FLAG) LIKE BAPIRET2-TYPE *" VALUE(MESSAGE) LIKE BAPIRET2-MESSAGE *" TABLES *" ZLFA1 STRUCTURE ZLFA1 *"---------------------------------------------------------------------- TYPES:BEGIN OF ty_lifnr, lifnr TYPE lfa1-lifnr, END OF ty_lifnr. DATA: BEGIN OF ls_lfa1. INCLUDE TYPE zlfa1. DATA: name2 TYPE lfa1-name2, name3 TYPE lfa1-name3, name4 TYPE lfa1-name4, street TYPE adrc-street, str_suppl1 TYPE adrc-str_suppl1. DATA: END OF ls_lfa1. DATA:lt_lfa1 LIKE TABLE OF ls_lfa1, ls_zlfa1 TYPE zlfa1, lv_datano TYPE zdatano. DATA:lt_cdhdr TYPE TABLE OF cdhdr, ls_cdhdr TYPE cdhdr, lt_lifnr TYPE TABLE OF ty_lifnr, ls_lifnr TYPE ty_lifnr. DATA:lt_lfa2 TYPE TABLE OF lfa1, lt_lfb1 TYPE TABLE OF lfb1, lt_lfm1 TYPE TABLE OF lfm1, lt_lfbk TYPE TABLE OF lfbk, lt_adrc TYPE TABLE OF adrc, lt_bnka TYPE TABLE OF bnka, ls_lfa2 TYPE lfa1, ls_lfb1 TYPE lfb1, ls_lfm1 TYPE lfm1, ls_lfbk TYPE lfbk, ls_adrc TYPE adrc, ls_bnka TYPE bnka. FIELD-SYMBOLS <fs> TYPE zlfa1. *--取得所有银行主数据 SELECT * INTO TABLE lt_bnka FROM bnka. SORT lt_bnka BY banks bankl. IF zdate IS INITIAL. *---全量查询 SELECT lfa1~lifnr lfb1~bukrs lfa1~ktokk lfm1~ekorg lfa1~name1 lfa1~stras lfa1~telf1 lfm1~verkf lfa1~stceg lfbk~banks lfbk~bankl lfbk~bankn lfbk~koinh lfb1~zterm lfb1~zwels lfb1~akont lfa1~loevm lfa1~name2 lfa1~name3 lfa1~name4 lfa1~name4 adrc~street adrc~str_suppl1 INTO CORRESPONDING FIELDS OF TABLE lt_lfa1 FROM lfa1 LEFT JOIN lfb1 ON lfa1~lifnr = lfb1~lifnr LEFT JOIN lfbk ON lfa1~lifnr = lfbk~lifnr LEFT JOIN lfm1 ON lfa1~lifnr = lfm1~lifnr LEFT JOIN adrc ON lfa1~adrnr = adrc~addrnumber. zlfa1[] = lt_lfa1. SORT lt_lfa1 BY lifnr. LOOP AT zlfa1 ASSIGNING <fs>. READ TABLE lt_lfa1 INTO ls_lfa1 WITH KEY lifnr = <fs>-lifnr BINARY SEARCH. IF sy-subrc = 0. *---公司名称 CONCATENATE ls_lfa1-name1 ls_lfa1-name2 ls_lfa1-name3 ls_lfa1-name4 INTO <fs>-name1. *---地址街道 CONCATENATE ls_lfa1-street ls_lfa1-str_suppl1 INTO <fs>-stras. ENDIF. *--银行名称 READ TABLE lt_bnka INTO ls_bnka WITH KEY banks = <fs>-banks bankl = <fs>-bankl BINARY SEARCH. IF sy-subrc = 0. <fs>-banka = ls_bnka-banka. ENDIF. ENDLOOP. *----增量查询 ELSE. SELECT * INTO TABLE lt_cdhdr FROM cdhdr WHERE objectclas = ‘KRED‘ AND udate = zdate. SORT lt_cdhdr BY objectid. DELETE ADJACENT DUPLICATES FROM lt_cdhdr COMPARING objectid. LOOP AT lt_cdhdr INTO ls_cdhdr. ls_lifnr-lifnr = ls_cdhdr-objectid+0(10). APPEND ls_lifnr TO lt_lifnr. ENDLOOP. IF lt_lifnr IS NOT INITIAL. SELECT * INTO TABLE lt_lfa2 FROM lfa1 " 供应商一般数据据 FOR ALL ENTRIES IN lt_lifnr WHERE lifnr = lt_lifnr-lifnr. SELECT * INTO TABLE lt_lfb1 FROM lfb1 "供应商财务数据 FOR ALL ENTRIES IN lt_lifnr WHERE lifnr = lt_lifnr-lifnr. SELECT * INTO TABLE lt_lfm1 FROM lfm1 "供应商主记录采购数据 FOR ALL ENTRIES IN lt_lifnr WHERE lifnr = lt_lifnr-lifnr. SELECT * INTO TABLE lt_lfbk FROM lfbk "供应商银行数据 FOR ALL ENTRIES IN lt_lifnr WHERE lifnr = lt_lifnr-lifnr. IF lt_lfa2 IS NOT INITIAL. SELECT * INTO TABLE lt_adrc FROM adrc "地址 FOR ALL ENTRIES IN lt_lfa2 WHERE addrnumber = lt_lfa2-adrnr. ENDIF. ENDIF. SORT lt_lfb1 BY lifnr. SORT lt_lfm1 BY lifnr. SORT lt_lfbk BY lifnr. SORT lt_adrc BY addrnumber. LOOP AT lt_lfa2 INTO ls_lfa2. ls_zlfa1-lifnr = ls_lfa2-lifnr. ls_zlfa1-ktokk = ls_lfa2-ktokk. ls_zlfa1-stras = ls_lfa2-stras. ls_zlfa1-stceg = ls_lfa2-stceg. ls_zlfa1-loevm = ls_lfa2-loevm. ls_zlfa1-telf1 = ls_lfa2-telf1. *---公司名称 CONCATENATE ls_lfa2-name1 ls_lfa2-name2 ls_lfa2-name3 ls_lfa2-name4 INTO ls_zlfa1-name1. READ TABLE lt_lfb1 INTO ls_lfb1 WITH KEY lifnr = ls_lfa2-lifnr BINARY SEARCH. IF sy-subrc = 0. ls_zlfa1-bukrs = ls_lfb1-bukrs. ls_zlfa1-zterm = ls_lfb1-zterm. ls_zlfa1-zwels = ls_lfb1-zwels. ls_zlfa1-akont = ls_lfb1-akont. ENDIF. READ TABLE lt_lfm1 INTO ls_lfm1 WITH KEY lifnr = ls_lfa2-lifnr BINARY SEARCH. IF sy-subrc = 0. ls_zlfa1-ekorg = ls_lfm1-ekorg. ls_zlfa1-verkf = ls_lfm1-verkf. ENDIF. READ TABLE lt_lfbk INTO ls_lfbk WITH KEY lifnr = ls_lfa2-lifnr BINARY SEARCH. IF sy-subrc = 0. ls_zlfa1-banks = ls_lfbk-banks. ls_zlfa1-bankl = ls_lfbk-bankl. ls_zlfa1-bankn = ls_lfbk-bankn. ls_zlfa1-koinh = ls_lfbk-koinh. ENDIF. READ TABLE lt_adrc INTO ls_adrc WITH KEY addrnumber = ls_lfa2-adrnr BINARY SEARCH. IF sy-subrc = 0. *---地址街道 CONCATENATE ls_adrc-street ls_adrc-str_suppl1 INTO ls_zlfa1-stras. ENDIF. *--银行名称 READ TABLE lt_bnka INTO ls_bnka WITH KEY banks = ls_zlfa1-banks bankl = ls_zlfa1-bankl BINARY SEARCH. IF sy-subrc = 0. ls_zlfa1-banka = ls_bnka-banka. ENDIF. APPEND ls_zlfa1 TO zlfa1. ENDLOOP. ENDIF. *---返回消息 IF zlfa1[] IS NOT INITIAL. flag = ‘S‘. message = ‘查询成功‘. ELSE. flag = ‘E‘. message = ‘没有数据‘. ENDIF. *----*日志记录 CLEAR:gs_log,gt_log. LOOP AT zlfa1 ASSIGNING <fs>. lv_datano = lv_datano + 1. gs_log-datano = lv_datano. gs_log-name = ‘ZRFC_MM007‘. gs_log-cdate = sy-datum. GET TIME. gs_log-ctime = sy-uzeit. gs_log-callno = callno. gs_log-flag = flag. gs_log-log = message. CONCATENATE zdate <fs>-lifnr <fs>-bukrs <fs>-ktokk <fs>-ekorg <fs>-name1 <fs>-stras <fs>-telf1 <fs>-verkf <fs>-stceg <fs>-banks <fs>-bankl <fs>-banka <fs>-bankn <fs>-koinh <fs>-zterm <fs>-zwels <fs>-akont <fs>-loevm INTO gs_log-content SEPARATED BY ‘|‘. CONDENSE gs_log-content NO-GAPS. gs_log-length = STRLEN( gs_log-content ). APPEND gs_log TO gt_log. CLEAR gs_log. ENDLOOP. IF gt_log IS NOT INITIAL. INSERT zrfc_mm01in_log FROM TABLE gt_log. IF sy-subrc = 0. COMMIT WORK. ENDIF. ENDIF. ENDFUNCTION.
以上是关于供应商主数据 同步接口的主要内容,如果未能解决你的问题,请参考以下文章