ABAP:VF02销售发票过账BDC
VF02销售发票过账BDC:
FUNCTION zsdfu010. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" VALUE(I_ID) TYPE ZRFC_LOGID OPTIONAL *" VALUE(I_CANUM) TYPE CANUM OPTIONAL *" EXPORTING *" VALUE(E_CODE) TYPE MSGTY *" VALUE(E_MSG) TYPE MSGTXT *" VALUE(E_FLOW_END) TYPE CHAR01 *" TABLES *" ET_RETURN STRUCTURE ZRFCT005 OPTIONAL *"---------------------------------------------------------------------- DATA:ls_zsdt021 TYPE zsdt021, lt_zsdt017 TYPE TABLE OF zsdt017, ls_zsdt017 LIKE LINE OF lt_zsdt017, lt_zsdt019 TYPE TABLE OF zsdt019, ls_zsdt019 LIKE LINE OF lt_zsdt019. DATA:BEGIN OF ls_objkey, objkey TYPE zsdt008-objkey. DATA:END OF ls_objkey. DATA lt_objkey LIKE TABLE OF ls_objkey. DATA:BEGIN OF ls_zrfc_logid, zrfc_logid TYPE zrfc_logid, END OF ls_zrfc_logid. DATA lt_zrfc_logid LIKE TABLE OF ls_zrfc_logid. DATA:ls_zrfct002 TYPE zrfct002. DATA:ls_creatordatain TYPE bapicreatordata, lt_billing TYPE STANDARD TABLE OF bapivbrk, ls_billing TYPE bapivbrk. DATA:lv_vbeln TYPE zsdt019-vbeln. DATA:lv_belnr TYPE bkpf-belnr. SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_zsdt019 FROM zsdt019 WHERE zrfc_logid = i_id. IF lt_zsdt019 IS INITIAL. e_code = 'E'. e_msg = '无可执行数据'. RETURN. ENDIF. SORT lt_zsdt019 BY vbeln posnr. LOOP AT lt_zsdt019 INTO ls_zsdt019. ls_objkey-objkey = ls_zsdt019-vbeln. APPEND ls_objkey TO lt_objkey. ls_zsdt019-zposnr = ''. MODIFY lt_zsdt019 FROM ls_zsdt019. ENDLOOP. DELETE ADJACENT DUPLICATES FROM lt_objkey COMPARING ALL FIELDS. CALL METHOD zcl_rfc=>get_source EXPORTING i_id = i_id i_canum = i_canum IMPORTING e_zrfct002 = ls_zrfct002. SELECT SINGLE zzrfcid zcanum INTO (ls_zsdt021-zzrfcid,ls_zsdt021-zcanum) FROM zsdt021 WHERE zrfcid = ls_zrfct002-zrfcid AND canum = i_canum. SELECT zrfc_logid INTO TABLE lt_zrfc_logid FROM zsdt017 FOR ALL ENTRIES IN lt_objkey WHERE objkey = lt_objkey-objkey AND zrfcid = ls_zsdt021-zzrfcid. IF lt_zrfc_logid IS INITIAL. e_code = 'E'. e_msg = '无可执行数据'. RETURN. ENDIF. SELECT * INTO TABLE lt_zsdt017 FROM zsdt017 FOR ALL ENTRIES IN lt_zrfc_logid WHERE zrfc_logid = lt_zrfc_logid-zrfc_logid AND canum = ls_zsdt021-zcanum. SORT lt_zsdt017 BY objkey. * LOOP AT LT_zsdt019 INTO LS_zsdt019. * AT END OF VBELN. * LOOP AT LT_zsdt017 INTO LS_zsdt017 WHERE OBJKEY = LS_zsdt019-VBELN. LOOP AT lt_zsdt017 INTO ls_zsdt017. CLEAR:e_code,e_msg. * PERFORM POST_BL TABLES ET_RETURN USING LS_zsdt019-VBELN CHANGING E_CODE E_MSG E_FLOW_END. lv_vbeln = ls_zsdt017-objkey. CLEAR:lv_belnr. PERFORM post_bl TABLES et_return USING lv_vbeln CHANGING e_code e_msg e_flow_end. IF e_code = 'S'. * ls_zsdt017-belnr = lv_vbeln. SELECT SINGLE belnr INTO ls_zsdt017-belnr "会计凭证 FROM bkpf WHERE awkey = lv_vbeln. MODIFY lt_zsdt017 FROM ls_zsdt017. ENDIF. ENDLOOP. MODIFY zsdt017 FROM TABLE lt_zsdt017. REFRESH:lt_zsdt017. ENDFUNCTION. FORM post_bl TABLES p_et_return STRUCTURE zrfct005 USING vbeln TYPE vbrk-vbeln CHANGING p_e_code p_e_msg p_e_flow_end. DATA:lv_flag TYPE c LENGTH 1 VALUE 'X'. DATA:message TYPE c LENGTH 200. DATA:mtext TYPE c LENGTH 200. DATA:ls_zrfct005 TYPE zrfct005. REFRESH:messtab,bdcdata. PERFORM bdc_dynpro USING 'SAPMV60A' '0101'. PERFORM bdc_field USING 'BDC_CURSOR' 'VBRK-VBELN'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'VBRK-VBELN' vbeln. PERFORM bdc_dynpro USING 'SAPMV60A' '0104'. PERFORM bdc_field USING 'BDC_CURSOR' 'VBRK-FKART'. PERFORM bdc_field USING 'BDC_OKCODE' '=FKFR'. PERFORM bdc_dynpro USING 'SAPMV60A' '0104'. PERFORM bdc_field USING 'BDC_CURSOR' 'VBRK-FKART'. PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'. gwa_ctu-defsize = 'X'. gwa_ctu-dismode = 'N'. gwa_ctu-updmode = 'S'. EXPORT lv_flag TO MEMORY ID 'ZSDU003'. CALL TRANSACTION 'VF02' USING bdcdata OPTIONS FROM gwa_ctu MESSAGES INTO messtab. LOOP AT messtab WHERE msgtyp = 'E' OR msgtyp = 'X' OR msgtyp = 'A'. MESSAGE ID messtab-msgid TYPE messtab-msgtyp NUMBER messtab-msgnr INTO mtext WITH messtab-msgv1 messtab-msgv2 messtab-msgv3 messtab-msgv4. CONCATENATE message mtext INTO message SEPARATED BY '/'. ENDLOOP. IF sy-subrc <> '0'. p_e_code = 'S'. CONCATENATE '发票:' vbeln '过账成功' INTO p_e_msg. CLEAR:ls_zrfct005. ls_zrfct005-status = '53'. ls_zrfct005-msgty = p_e_code. ls_zrfct005-msgid = '00'. ls_zrfct005-msgno = '001'. ls_zrfct005-msgv1 = p_e_msg. ls_zrfct005-msgv4 = vbeln. APPEND ls_zrfct005 TO p_et_return. ELSE. p_e_code = 'E'. p_e_msg = message. ENDIF. ENDFORM. " DOCUMENT_BL