如果需要用代码完成类似 F-04 过账并清账的操作,可以顺序调用下面的三个函数:
- POSTING_INTERFACE_START - POSTING_INTERFACE_CLEARING - POSTING_INTERFACE_END首先我们对这三个函数改装封装一下
第一个函数:POSTING_INTERFACE_START
FUNCTION zfm_posting_interface_start. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" VALUE(I_CLIENT) LIKE SY-MANDT DEFAULT SY-MANDT *" VALUE(I_FUNCTION) LIKE RFIPI-FUNCT *" VALUE(I_GROUP) LIKE APQI-GROUPID DEFAULT SPACE *" VALUE(I_HOLDDATE) LIKE APQI-STARTDATE DEFAULT SPACE *" VALUE(I_KEEP) LIKE APQI-QERASE DEFAULT SPACE *" VALUE(I_MODE) LIKE RFPDO-ALLGAZMD DEFAULT 'N' *" VALUE(I_UPDATE) LIKE RFPDO-ALLGVBMD DEFAULT 'S' *" VALUE(I_USER) LIKE APQI-USERID DEFAULT SPACE *" VALUE(I_XBDCC) LIKE RFIPI-XBDCC DEFAULT SPACE *" VALUE(I_BDC_APP_AREA) TYPE BDC_APP_AREA DEFAULT SPACE *" EXCEPTIONS *" CLIENT_INCORRECT *" FUNCTION_INVALID *" GROUP_NAME_MISSING *" MODE_INVALID *" UPDATE_INVALID *" USER_INVALID *"---------------------------------------------------------------------- GET RUN TIME FIELD runtime. *------- Vorhergehende Mappe schließen? -------------------------------- IF group_open = 'X'. PERFORM mappe_schliessen. * falls kein Startdatum und keine Zeit übergeben werden soll * erwartet der 'JOB_CLOSE' nicht initial sondern SPACE IF bdcstrtdt IS INITIAL. MOVE space TO bdcstrtdt. ENDIF. IF bdcstrttm IS INITIAL. MOVE space TO bdcstrttm. ENDIF. IF ( funct = 'B' AND bdcimmed = 'X' ) OR ( funct = 'B' AND bdcstrtdt NE space ). PERFORM mappe_abspielen_im_batch. ENDIF. ENDIF. mandt = i_client. funct = i_function. group = i_group. holdd = i_holddate. xkeep = i_keep. mode = i_mode. update = i_update. usnam = i_user. xbdcc = i_xbdcc. bdc_app_area = i_bdc_app_area. *------- Prüfung der Schnittstellenfelder ------------------------------ IF mandt NE sy-mandt. MESSAGE e001 WITH mandt sy-mandt RAISING client_incorrect. ENDIF. IF funct CN 'BCI'. MESSAGE e002 WITH funct RAISING function_invalid. ENDIF. CASE funct. *------- Funktion: Batch-Input ----------------------------------------- WHEN 'B'. IF group = space. MESSAGE e003 RAISING group_name_missing. ENDIF. PERFORM mappe_oeffnen. *------- Funktion: Call Transaction ... Using ... ---------------------- WHEN 'C'. IF mode CN 'ANE'. MESSAGE e004 WITH mode RAISING mode_invalid. ENDIF. IF update CN 'SAL'. MESSAGE e005 WITH update RAISING update_invalid. ENDIF. IF xbdcc = 'X' AND group IS INITIAL. MESSAGE e003 RAISING group_name_missing. ENDIF. *------- Funktion: Interaktive Buchungsschnittstelle WHEN 'I'. ENDCASE. *------- NewGL active ? ----------------------------------- Note1605537* IF glflex_active IS INITIAL. CALL FUNCTION 'FAGL_CHECK_GLFLEX_ACTIVE' IMPORTING e_glflex_active = glflex_active EXCEPTIONS error_message = 1. ENDIF. ENDFUNCTION.
第二个函数:POSTING_INTERFACE_CLEARING
FUNCTION ZFM_POSTING_INTERFACE_CLEARING. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" VALUE(I_AUGLV) LIKE T041A-AUGLV *" VALUE(I_TCODE) LIKE SY-TCODE *" VALUE(I_SGFUNCT) LIKE RFIPI-SGFUNCT DEFAULT SPACE *" VALUE(I_NO_AUTH) DEFAULT SPACE *" REFERENCE(I_XSIMU) TYPE CHAR1 DEFAULT SPACE *" EXPORTING *" VALUE(E_MSGID) LIKE SY-MSGID *" VALUE(E_MSGNO) LIKE SY-MSGNO *" VALUE(E_MSGTY) LIKE SY-MSGTY *" VALUE(E_MSGV1) LIKE SY-MSGV1 *" VALUE(E_MSGV2) LIKE SY-MSGV2 *" VALUE(E_MSGV3) LIKE SY-MSGV3 *" VALUE(E_MSGV4) LIKE SY-MSGV4 *" VALUE(E_SUBRC) LIKE SY-SUBRC *" TABLES *" T_BLNTAB STRUCTURE BLNTAB *" T_FTCLEAR STRUCTURE FTCLEAR *" T_FTPOST STRUCTURE FTPOST *" T_FTTAX STRUCTURE FTTAX *" T_BDCDATA STRUCTURE BDCDATA *" EXCEPTIONS *" CLEARING_PROCEDURE_INVALID *" CLEARING_PROCEDURE_MISSING *" TABLE_T041A_EMPTY *" TRANSACTION_CODE_INVALID *" AMOUNT_FORMAT_ERROR *" TOO_MANY_LINE_ITEMS *" COMPANY_CODE_INVALID *" SCREEN_NOT_FOUND *" NO_AUTHORIZATION *"---------------------------------------------------------------------- *------- Belegdaten initialisieren ------------------------------------- tcode = i_tcode. auglv = i_auglv. sgfunct = i_sgfunct. xsimu = i_xsimu. PERFORM init_posting. CLEAR: xftclear, defsize. REFRESH: xftclear. CLEAR: yftclear. "31i *------- Transactionscode prüfen --------------------------------------- IF tcode NE 'FB05' AND tcode NE 'FB05L'. "1527033 MESSAGE e006 WITH tcode RAISING transaction_code_invalid. ENDIF. *------- Reportname setzen ----------------------------------------- rep_name = rep_name_a. " Belegvorerfassung *------- Tabellendaten übertragen -------------------------------------- LOOP AT t_ftpost. xftpost = t_ftpost. APPEND xftpost. ENDLOOP. LOOP AT t_ftclear. *------- Data without selection field to be appended after sort -------- *------- Only one such item is allowed and it must be last -------- *------- Additionally, the all-inclusive selection must be last also -- IF t_ftclear-selfd = space. "31i yftclear = t_ftclear. ELSEIF t_ftclear-selfd = 'BELNR' "all other o/i via lbox AND t_ftclear-selvon = space AND t_ftclear-selbis = 'ZZZZZZZZZZ'. yftclear = t_ftclear. ELSE. xftclear = t_ftclear. APPEND xftclear. ENDIF. ENDLOOP. SORT xftclear BY agkoa agkon agbuk xnops agums. IF NOT yftclear = space. "31i APPEND yftclear TO xftclear. ENDIF. PERFORM auglv_tabix_ermitteln. LOOP AT t_fttax. xfttax = t_fttax. APPEND xfttax. ENDLOOP. DESCRIBE TABLE xfttax LINES tfill_xfttax. *------- Buchungsdatentabelle (XFTPOST) abarbeiten im Loop ------------- PERFORM xftpost_loop. *------- Letzte Belegzeile übertragen ---------------------------------- PERFORM position_uebertragen. *------- Ausgleichsdaten (XFTCLEAR) abarbeiten ------------------------- CLEAR dynnr. LOOP AT xftclear. AT NEW agkoa. PERFORM fcode_f06_f07. ENDAT. AT NEW agkon. PERFORM fcode_f06_f07. ENDAT. AT NEW agbuk. PERFORM fcode_f06_f07. ENDAT. AT NEW xnops. PERFORM fcode_f06_f07. ENDAT. AT NEW agums. PERFORM fcode_f06_f07. ENDAT. IF dynnr = '0710'. PERFORM bselk_uebergeben. CLEAR dynnr. ENDIF. loopc = ( loopc + 1 ) MOD 18. IF loopc = 0. loopc = 18. ENDIF. IF loopc = 1. PERFORM fcode_f05. ENDIF. PERFORM bselp_uebergeben. DESCRIBE TABLE ft LINES index. ENDLOOP. *------- Transaktion abschließen --------------------------------------- PERFORM fcode_f11. IF xsimu = 'X'. PERFORM document_simulation. ENDIF. *------- chang clear dmbtr add bdc--------------------------------------- APPEND LINES OF t_bdcdata[] TO ft. PERFORM transaktion_beenden USING i_no_auth. *------- Exportparameter zurückgeben (bei Call Transaction .. Using ..)- IF funct = 'C' OR sgfunct = 'C'. e_subrc = subrc. e_msgty = msgty. e_msgid = msgid. e_msgno = msgno. e_msgv1 = msgv1. e_msgv2 = msgv2. e_msgv3 = msgv3. e_msgv4 = msgv4. LOOP AT xbltab. t_blntab = xbltab. APPEND t_blntab. ENDLOOP. ENDIF. ENDFUNCTION.
第三个函数:POSTING_INTERFACE_END
FUNCTION ZFM_POSTING_INTERFACE_END. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" VALUE(I_BDCIMMED) LIKE RFIPI-BDCIMMED DEFAULT SPACE *" VALUE(I_BDCSTRTDT) LIKE TBTCJOB-SDLSTRTDT DEFAULT NO_DATE *" VALUE(I_BDCSTRTTM) LIKE TBTCJOB-SDLSTRTTM DEFAULT NO_TIME *" EXCEPTIONS *" SESSION_NOT_PROCESSABLE *"---------------------------------------------------------------------- BDCIMMED = I_BDCIMMED. BDCSTRTDT = I_BDCSTRTDT. BDCSTRTTM = I_BDCSTRTTM. * falls kein Startdatum und keine Zeit übergeben werden soll * erwartet der 'JOB_CLOSE' nicht initial sondern SPACE IF BDCSTRTDT IS INITIAL. MOVE SPACE TO BDCSTRTDT. ENDIF. IF BDCSTRTTM IS INITIAL. MOVE SPACE TO BDCSTRTTM. ENDIF. IF GROUP_OPEN = 'X'. CALL FUNCTION 'BDC_CLOSE_GROUP'. CLEAR GROUP_OPEN. IF ( FUNCT = 'B' AND BDCIMMED = 'X' ) OR ( FUNCT = 'B' AND BDCSTRTDT NE SPACE ). * fuer die IDOC-Verarbeitung soll sichergestellt werden, dass * die Mappe existiert. COMMIT WORK. PERFORM MAPPE_ABSPIELEN_IM_BATCH. ENDIF. ENDIF. CLEAR: BDCIMMED. BDCSTRTDT = SPACE. BDCSTRTTM = SPACE. ENDFUNCTION.
调用代码
LOOP AT lt_output ASSIGNING FIELD-SYMBOL(<fs_output>). CLEAR: gt_blntab , gt_ftclear, gt_ftpost , gt_fttax , gt_bdcdata. CALL FUNCTION 'ZFMPOSTING_INTERFACE_START' EXPORTING i_function = 'C' i_keep = 'X' i_mode = lv_mode "A for step by step,N default,for background EXCEPTIONS client_incorrect = 1 function_invalid = 2 group_name_missing = 3 mode_invalid = 4 update_invalid = 5 OTHERS = 6. "抬头 mcr_populate_ftpost: 'K' 1 'BKPF-BUKRS' <fs_output>-bukrs, "Company code 'K' 1 'BKPF-BLART' 'AB', 'K' 1 'BKPF-BLDAT' sy-datum, 'K' 1 'BKPF-BUDAT' sy-datum, 'K' 1 'BKPF-WAERS' <fs_output>-waers, 'K' 1 'BKPF-XBLNR' '清帐凭证-ZFIE001D' . "收款凭证 LOOP AT lt_bsid_rec ASSIGNING FIELD-SYMBOL(<fs_bsid_rec>) WHERE bukrs = <fs_output>-bukrs AND kunnr = <fs_output>-kunnr AND waers = <fs_output>-waers. mcr_populate_ftclear 'D' <fs_bsid_rec>-bukrs <fs_bsid_rec>-kunnr <fs_bsid_rec>-belnr <fs_bsid_rec>-gjahr <fs_bsid_rec>-buzei. ENDLOOP. "发票凭证 LOOP AT lt_output_tmp INTO gs_output WHERE bukrs = <fs_output>-bukrs AND kunnr = <fs_output>-kunnr AND waers = <fs_output>-waers. LOOP AT gt_so ASSIGNING FIELD-SYMBOL(<fs_so>) WHERE zrelno = gs_output-zrelno. mcr_populate_ftclear 'D' <fs_so>-bukrs <fs_so>-kunnr <fs_so>-belnr <fs_so>-gjahr <fs_so>-buzei. ENDLOOP. ENDLOOP. "保存 mcr_frm_bdc_dynpro 'SAPDF05X' '3100' 'X'.
mcr_frm_bdc_field 'BDC_OKCODE' '=BU'. mcr_frm_bdc_field 'BDC_SUBSCR' 'SAPDF05X 6104PAGE'. mcr_frm_bdc_field 'BDC_CURSOR' 'DF05B-PSZAH(01)'. mcr_frm_bdc_field 'RF05A-ABPOS' '9'.
EXPORT line = 'X' TO MEMORY ID 'MF05AI00_D0730_OKCODE'.
CALL FUNCTION 'ZFMPOSTING_INTERFACE_CLEARING' EXPORTING i_auglv = 'UMBUCHNG' i_tcode = 'FB05' i_sgfunct = 'C' IMPORTING e_msgid = sy-msgid e_msgno = sy-msgno e_msgty = sy-msgty e_msgv1 = sy-msgv1 e_msgv2 = sy-msgv2 e_msgv3 = sy-msgv3 e_msgv4 = sy-msgv4 * E_SUBRC = SY-SUBRC TABLES t_blntab = gt_blntab t_ftclear = gt_ftclear t_ftpost = gt_ftpost t_fttax = gt_fttax t_bdcdata = gt_bdcdata EXCEPTIONS clearing_procedure_invalid = 1 clearing_procedure_missing = 2 table_t041a_empty = 3 transaction_code_invalid = 4 amount_format_error = 5 too_many_line_items = 6 company_code_invalid = 7 screen_not_found = 8 no_authorization = 9 OTHERS = 10.
IF sy-subrc = 0 AND gt_blntab IS NOT INITIAL. LOOP AT gt_output ASSIGNING FIELD-SYMBOL(<fs_output_tmp>) WHERE bukrs = <fs_output>-bukrs AND kunnr = <fs_output>-kunnr AND waers = <fs_output>-waers. * <fs_output_tmp>-icon = icon_green_light. READ TABLE gt_blntab INTO gs_blntab INDEX 1. * <fs_output_tmp>-gjahr_hx = gs_blntab-gjahr. * <fs_output_tmp>-belnr_hx = gs_blntab-belnr. IF sy-subrc EQ 0. UPDATE zfit001_rec SET gjahr_hx = gs_blntab-gjahr belnr_hx = gs_blntab-belnr zrkzt = '3' WHERE dtlseq = <fs_output>-dtlseq. ENDIF. DELETE gt_output. ENDLOOP. DELETE gt_so WHERE bukrs = <fs_output>-bukrs AND kunnr = <fs_output>-kunnr. ELSE . LOOP AT gt_output ASSIGNING <fs_output_tmp> WHERE bukrs = <fs_output>-bukrs AND kunnr = <fs_output>-kunnr AND waers = <fs_output>-waers. <fs_output_tmp>-icon = icon_red_light.
MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO <fs_output_tmp>-message. ENDLOOP.
ENDIF.
FREE MEMORY ID 'MF05AI00_D0730_OKCODE'.
CALL FUNCTION 'ZFMPOSTING_INTERFACE_END' EXCEPTIONS session_not_processable = 1 OTHERS = 2. ENDLOOP.