通用在做凭证时可以使用FB01的BAPI函数 BAPI_ACC_DOCUMENT_POST来创建凭证,但在票据凭证时,需要填入BOENO,票据到期日ZFBDT等信息时,BAPI默认不支持,网上能找到一些增加实现的方法,但后来发现FB05其实也能实现,并且有标准的BDC函数 POSTING_INTERFACE_CLEARING可以使用,我们只要不输入的清账的凭证相关信息就行。为此做了一个函数用于创建凭证及清账使用。
1.函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
FUNCTION ZFM_CM_11. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" REFERENCE(I_BBKPF) TYPE BBKPF *" REFERENCE(I_MODE) TYPE RFPDO-ALLGAZMD DEFAULT 'N' *" REFERENCE(I_UNAME) TYPE SY-UNAME OPTIONAL *" REFERENCE(I_AUGLV) TYPE AUGLV OPTIONAL *" EXPORTING *" REFERENCE(E_SUBRC) LIKE SY-SUBRC *" REFERENCE(E_MESSAGE) TYPE ESP1_MESSAGE_WA_TYPE *" TABLES *" T_BBSEG STRUCTURE BBSEG *" T_FTCLEAR STRUCTURE FTCLEAR OPTIONAL *" T_BLNTAB STRUCTURE BLNTAB OPTIONAL *"---------------------------------------------------------------------- *&---------------------------------------------------------------------* *&事务代码/Transaction code : *&程序名称/Program Name :ZFM_CM_05 *&程序描述/Program Des. :创建汇票凭证通用函数 *&申请人/Applicant :(汉得) *&申请日期/Date of App :2020.03.13 *&开发单位/Development Company :HAND(汉得) *&作者/Author :ruifeng.ren(HAND) *&---------------------------------------------------------------------* *&摘要/Abstract: *& 1).BAPI 无法创建含汇票信息的会计凭证,故采用BDC的方式进行 *& 2). *&---------------------------------------------------------------------* *&变更记录/Change record *&Date Developer ReqNo Descriptions *& ========== ================== ========== ========================* *& 2020-03-13 ruifeng.ren(Hand) ED1K903349 The initial development *&---------------------------------------------------------------------* DATA: LT_BLNTAB TYPE STANDARD TABLE OF BLNTAB, LS_BLNTAB TYPE BLNTAB, LT_FTPOST TYPE STANDARD TABLE OF FTPOST, LT_FTTAX TYPE STANDARD TABLE OF FTTAX, LT_FTCLEAR TYPE STANDARD TABLE OF FTCLEAR, LV_LINE TYPE FTPOST-COUNT. "计数器 *----取账户过账码 SELECT * INTO TABLE @DATA(LT_TBSL) FROM TBSL. *----凭证抬头赋值 LT_FTPOST = VALUE #( BASE LT_FTPOST ( STYPE = 'K' COUNT = '1' FNAM = 'BKPF-BUKRS' FVAL = I_BBKPF-BUKRS ) "公司代码 ( STYPE = 'K' COUNT = '1' FNAM = 'BKPF-BLART' FVAL = I_BBKPF-BLART ) "凭证类型 ( STYPE = 'K' COUNT = '1' FNAM = 'BKPF-BLDAT' FVAL = I_BBKPF-BLDAT ) "凭证日期 ( STYPE = 'K' COUNT = '1' FNAM = 'BKPF-BUDAT' FVAL = I_BBKPF-BUDAT ) "过账日期 ( STYPE = 'K' COUNT = '1' FNAM = 'BKPF-MONAT' FVAL = I_BBKPF-MONAT ) "会计期间 ( STYPE = 'K' COUNT = '1' FNAM = 'BKPF-XBLNR' FVAL = I_BBKPF-XBLNR ) "参考凭证 ( STYPE = 'K' COUNT = '1' FNAM = 'BKPF-BKTXT' FVAL = I_BBKPF-BKTXT ) "抬头文本 ( STYPE = 'K' COUNT = '1' FNAM = 'BKPF-NUMPG' FVAL = I_BBKPF-NUMPG ) ( STYPE = 'K' COUNT = '1' FNAM = 'BKPF-WAERS' FVAL = I_BBKPF-WAERS ) )."页数 *----凭证行赋值 CLEAR LV_LINE. LOOP AT T_BBSEG INTO DATA(LS_BSEG). ADD 1 TO LV_LINE. IF LS_BSEG-NEWBS = '40' OR LS_BSEG-NEWBS = '50'. "应收汇票总账行 LT_FTPOST = VALUE #( BASE LT_FTPOST ( STYPE = 'P' COUNT = LV_LINE FNAM = 'RF05A-NEWBS' FVAL = LS_BSEG-NEWBS )"记账码 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'RF05A-NEWKO' FVAL = LS_BSEG-NEWKO )"科目 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSEG-WRBTR' FVAL = LS_BSEG-WRBTR )"金额 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSEG-VALUT' FVAL = LS_BSEG-VALUT )"起息日 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSEG-ZUONR' FVAL = LS_BSEG-ZUONR )"分配编号 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'COBL-GSBER' FVAL = LS_BSEG-GSBER )"业务范围 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSEG-SGTXT' FVAL = LS_BSEG-SGTXT )"行文本 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'COBL-KOSTL' FVAL = LS_BSEG-KOSTL )"成本中心 ). ELSE. LT_FTPOST = VALUE #( BASE LT_FTPOST ( STYPE = 'P' COUNT = LV_LINE FNAM = 'RF05A-NEWBS' FVAL = LS_BSEG-NEWBS )"记账码 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'RF05A-NEWKO' FVAL = LS_BSEG-NEWKO )"科目 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'RF05A-NEWUM' FVAL = LS_BSEG-NEWUM )"特别总账标识 ). IF LS_BSEG-NEWBK IS NOT INITIAL. LT_FTPOST = VALUE #( BASE LT_FTPOST ( STYPE = 'P' COUNT = LV_LINE FNAM = 'RF05A-NEWBK' FVAL = LS_BSEG-NEWBK )"新公司代码 ). ENDIF. LT_FTPOST = VALUE #( BASE LT_FTPOST ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSEG-WRBTR' FVAL = LS_BSEG-WRBTR )"金额 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSEG-GSBER' FVAL = LS_BSEG-GSBER )"业务范围 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSEG-SGTXT' FVAL = LS_BSEG-SGTXT )"行文本 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSEG-ZFBDT' FVAL = LS_BSEG-ZFBDT )"到期日 ). IF LS_BSEG-XNEGP IS NOT INITIAL. LT_FTPOST = VALUE #( BASE LT_FTPOST ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSEG-XNEGP' FVAL = LS_BSEG-XNEGP )"反记账标识 ). ENDIF. IF LS_BSEG-PROJK IS NOT INITIAL."WBS LT_FTPOST = VALUE #( BASE LT_FTPOST ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSEG-PROJK' FVAL = LS_BSEG-PROJK )"WBS ). ENDIF. IF LS_BSEG-RSTGR IS NOT INITIAL. LT_FTPOST = VALUE #( BASE LT_FTPOST ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSEG-RSTGR' FVAL = LS_BSEG-RSTGR )"原因代码 ). ENDIF. IF LS_BSEG-NEWBS = '09' OR LS_BSEG-NEWBS = '39' OR LS_BSEG-NEWBS = '19'. LT_FTPOST = VALUE #( BASE LT_FTPOST ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSED-WDATE' FVAL = LS_BSEG-WDATE )"签发期日 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSED-WNAME' FVAL = LS_BSEG-WNAME )"收款人 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSED-WORT1' FVAL = LS_BSEG-WORT1 )"收款人所在城市 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSED-WBZOG' FVAL = LS_BSEG-WBZOG )"付款人 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSED-WORT2' FVAL = LS_BSEG-WORT2 )"付款人所在城市 ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSED-BOENO' FVAL = LS_BSEG-BOENO )"Check NO ( STYPE = 'P' COUNT = LV_LINE FNAM = 'BSEG-ZUONR' FVAL = LS_BSEG-ZUONR )"分配 ). ENDIF. ENDIF. ENDLOOP. *-----清账行 LT_FTCLEAR = T_FTCLEAR[]. *-----处理开始 DATA(LV_UNAME) = SY-UNAME. IF I_UNAME IS NOT INITIAL. LV_UNAME = I_UNAME. ENDIF. *-----开始处理 CALL FUNCTION 'POSTING_INTERFACE_START' EXPORTING I_FUNCTION = 'C' I_KEEP = 'X' I_MODE = I_MODE "A:显示录屏 N:后台执行 I_USER = LV_UNAME "凭证创建者 EXCEPTIONS CLIENT_INCORRECT = 1 FUNCTION_INVALID = 2 GROUP_NAME_MISSING = 3 MODE_INVALID = 4 UPDATE_INVALID = 5 OTHERS = 6. IF SY-SUBRC NE 0. E_MESSAGE = CORRESPONDING #( SY ). ELSE. *------将开发得平台调用得TCODE 输出 在标准程序调用BTE 增强时判断 *-----涉及得BTE增强为 'BOE_BTE_1030' 和 ‘BOE_BTE_1025’ IF SY-TCODE = 'ZFI001'. DATA:LV_CODE(10). LV_CODE = 'ZZFID001'. EXPORT LV_CODE TO MEMORY ID 'ZZFID001'. ENDIF. *-----执行BDC清账处理 CALL FUNCTION 'POSTING_INTERFACE_CLEARING' EXPORTING I_AUGLV = I_AUGLV 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 = E_SUBRC TABLES T_BLNTAB = LT_BLNTAB T_FTPOST = LT_FTPOST T_FTCLEAR = LT_FTCLEAR T_FTTAX = LT_FTTAX EXCEPTIONS ACCOUNT_MISSING = 1 COMPANY_CODE_MISSING = 2 POSTING_KEY_INVALID = 3 POSTING_KEY_MISSING = 4 RECORD_TYPE_INVALID = 5 TRANSACTION_CODE_INVALID = 6 AMOUNT_FORMAT_ERROR = 7 TOO_MANY_LINE_ITEMS = 8 COMPANY_CODE_INVALID = 9 SCREEN_NOT_FOUND = 10 NO_AUTHORIZATION = 11 OTHERS = 12. IF SY-MSGTY = 'S'. T_BLNTAB[] = LT_BLNTAB . E_MESSAGE = CORRESPONDING #( SY ). ELSE. *----捕获消息 E_MESSAGE = CORRESPONDING #( SY ). ENDIF. *处理结束 CALL FUNCTION 'POSTING_INTERFACE_END' EXCEPTIONS SESSION_NOT_PROCESSABLE = 1 OTHERS = 2. IF SY-SUBRC <> 0. ENDIF. ENDIF. **--------------------------------------------------------------------* **20230910 YS **新票据时把完整票据号更新到BSEG-ZSGTXT。 * READ TABLE LT_BLNTAB INTO LS_BLNTAB INDEX 1. * IF SY-SUBRC = 0 AND LS_BLNTAB-BELNR IS NOT INITIAL."清账成功 * DO 5 TIMES. * SELECT * * INTO TABLE @DATA(LT_BSEG) * FROM BSEG * WHERE BUKRS = @LS_BLNTAB-BUKRS * AND BELNR = @LS_BLNTAB-BELNR * AND GJAHR = @LS_BLNTAB-GJAHR * . * IF LT_BSEG IS NOT INITIAL. * EXIT. * ENDIF. * WAIT UP TO 1 SECONDS. * ENDDO. **表里已存在项目 * LOOP AT LT_BSEG INTO DATA(LSS_BSEG). * IF ZCL_TR_DRAFT=>ZIF_NEW( I_DRAFT = CONV #( LSS_BSEG-SGTXT ) ) <> 'N'."不是新票据 * CONTINUE. * ENDIF. * READ TABLE T_BBSEG INTO LS_BSEG WITH KEY SGTXT = LSS_BSEG-SGTXT . * IF SY-SUBRC = 0. * UPDATE BSEG * SET ZSGTXT = LSS_BSEG-ZSGTXT * WHERE BUKRS = LSS_BSEG-BUKRS * AND BELNR = LSS_BSEG-BELNR * AND GJAHR = LSS_BSEG-GJAHR. * COMMIT WORK. * ENDIF. * ENDLOOP. * * ENDIF. * * **--------------------------------------------------------------------* ENDFUNCTION. |
2.只创建凭证,不清账
在使用时,比如下面为只创建凭证,不清账。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
FORM PF_POST_SPLIT_ACC USING P_ALV TYPE TY_ALV CHANGING P_BELNR_SPLIT TYPE BELNR_D P_GJAHR_SPLIT TYPE GJAHR. DATA:LS_BKPF TYPE BBKPF, LT_BLNTAB TYPE TABLE OF BLNTAB, LT_BSEG TYPE TABLE OF BBSEG, LT_FTCLEAR TYPE TABLE OF FTCLEAR, LV_WRBTR TYPE WRBTR, LS_BSEG TYPE BBSEG, LV_AUGLV TYPE AUGLV, LV_SUBRC TYPE SY-SUBRC, LS_MSG TYPE ESP1_MESSAGE_WA_TYPE, LV_BELNR TYPE BKPF-BELNR, LV_BUKRS TYPE BKPF-BUKRS, LV_GJAHR TYPE BKPF-GJAHR, LT_LOG TYPE TABLE OF ZTCM_004, LS_LOG TYPE ZTCM_004, LV_UUID TYPE SYSUUID_X16, L_MODE TYPE ALLGAZMD VALUE 'N', LV_TZ TYPE TTZZ-TZONE VALUE 'UTC'. DATA: L_KUNNR TYPE KUNNR, L_PJYE TYPE WRBTR, "票据余额 L_ORT01 TYPE ORT01, "凭证公司城市 L_ORT02 TYPE ORT01, "项目公司城市 L_NAME3 TYPE NAME1_GP, L_ORT03 TYPE ORT01. "项目(客户)城市 DATA: L_BOE_NUMBER0 TYPE ZBOE_NUMBER, L_BOE_NUMBER1 TYPE ZBOE_NUMBER, L_BOE_NUMBER2 TYPE ZBOE_NUMBER. L_BOE_NUMBER1 = ZCL_TR_DRAFT=>ZDRAFT_SPLIT_NEW( EXPORTING IM_BOE_NUMBER = P_ALV-BOE_NUMBER IM_BANK = '' IM_WRBTR = P_ALV-WRBTR IM_ZBSJE = P_ALV-ZBSJE IM_BEF = 'X'). L_BOE_NUMBER2 = ZCL_TR_DRAFT=>ZDRAFT_SPLIT_NEW( EXPORTING IM_BOE_NUMBER = P_ALV-BOE_NUMBER IM_BANK = '' IM_WRBTR = P_ALV-WRBTR IM_ZBSJE = P_ALV-ZBSJE IM_BEF = ''). L_BOE_NUMBER0 = ZCL_TR_DRAFT=>ZDRAFT_RECAST( P_ALV-BOE_NUMBER )."去除前导0 L_BOE_NUMBER1 = ZCL_TR_DRAFT=>ZDRAFT_RECAST( I_DRAFT = L_BOE_NUMBER1 )."去除前导0 L_BOE_NUMBER2 = ZCL_TR_DRAFT=>ZDRAFT_RECAST( I_DRAFT = L_BOE_NUMBER2 )."去除前导0 *--------------------------------------------------------------------* *---凭证抬头 LS_BKPF-BUKRS = P_ALV-BUKRS. LS_BKPF-BLART = 'PJ'. LS_BKPF-BLDAT = SY-DATUM. LS_BKPF-BUDAT = SY-DATUM. LS_BKPF-MONAT = SY-DATUM+4(2). LS_BKPF-BKTXT = '汇票分包'. LS_BKPF-WAERS = P_ALV-WAERS. *--------------------------------------------------------------------* *----汇票至公司间 L_KUNNR = COND #( WHEN P_ALV-EN_INTER_ENDORSEE <> '' THEN P_ALV-EN_INTER_ENDORSEE WHEN P_ALV-EN_ENDORSEE_ID <> '' THEN P_ALV-EN_ENDORSEE_ID ). CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING INPUT = L_KUNNR IMPORTING OUTPUT = L_KUNNR. "---付款公司所在城市 SELECT SINGLE ORT01 INTO L_ORT01 FROM T001 WHERE BUKRS = P_ALV-BUKRS. IF P_ALV-EN_INTER_ENDORSEE <> ''. SELECT SINGLE ORT01 INTO L_ORT02 FROM T001 WHERE BUKRS = P_ALV-EN_INTER_ENDORSEE. ELSEIF P_ALV-EN_ENDORSEE_ID <> '' . SELECT SINGLE ORT01 INTO L_ORT02 FROM KNA1 WHERE KUNNR = P_ALV-EN_ENDORSEE_ID. SELECT SINGLE ORT01 NAME1 INTO ( L_ORT03 ,L_NAME3 ) FROM KNA1 WHERE KUNNR = P_ALV-KUNNR. ENDIF. *10 LT_BSEG = VALUE #( BASE LT_BSEG ( NEWBS = '09' "记账码 NEWKO = L_KUNNR "科目 客户 NEWUM = COND #( WHEN P_ALV-BOE_TYPE = 'C' THEN 'W' WHEN P_ALV-BOE_TYPE = 'Y' THEN 'W' WHEN P_ALV-BOE_TYPE = 'B' THEN 'V' WHEN P_ALV-BOE_TYPE = 'X' THEN 'N' ) "特别总账标识 WRBTR = P_ALV-ZBSJE "金额 SGTXT = L_BOE_NUMBER1 "行文本为汇票编号 ZFBDT = P_ALV-WEFAE "汇票到期日 WDATE = P_ALV-WDATE "汇票签发日期 WNAME = COND #( WHEN P_ALV-EN_INTER_ENDORSEE <> '' THEN P_ALV-EN_INT_ENDORSEE WHEN P_ALV-EN_ENDORSEE_ID <> '' THEN P_ALV-EN_ENDORSEE ) "收款人(被背书人名称) WORT1 = L_ORT02 "收款人城市 WBZOG = P_ALV-BUTXT "付款人(凭证公司) WORT2 = L_ORT01 "付款人城市 BOENO = P_ALV-BOE_INTERNAL_NUM "Check .NO ZUONR = P_ALV-BOE_INTERNAL_NUM ) ). *20 L_PJYE = P_ALV-WRBTR - P_ALV-ZBSJE . LT_BSEG = VALUE #( BASE LT_BSEG ( NEWBS = '09' "记账码 NEWKO = P_ALV-KUNNR "科目 客户 NEWUM = COND #( WHEN P_ALV-BOE_TYPE = 'C' THEN 'W' WHEN P_ALV-BOE_TYPE = 'Y' THEN 'W' WHEN P_ALV-BOE_TYPE = 'B' THEN 'V' WHEN P_ALV-BOE_TYPE = 'X' THEN 'N' ) "特别总账标识 WRBTR = L_PJYE "金额 SGTXT = L_BOE_NUMBER2 "行文本为汇票编号 ZFBDT = P_ALV-WEFAE "汇票到期日 WDATE = P_ALV-WDATE "汇票签发日期 WNAME = L_NAME3 WORT1 = L_ORT03 "收款人城市 WBZOG = P_ALV-BUTXT "付款人(凭证公司) WORT2 = L_ORT01 "付款人城市 BOENO = P_ALV-BOE_INTERNAL_NUM "Check .NO ZUONR = P_ALV-BOE_INTERNAL_NUM ) ). *30 L_PJYE = P_ALV-WRBTR . LT_BSEG = VALUE #( BASE LT_BSEG ( NEWBS = '19' "记账码 NEWKO = P_ALV-KUNNR "科目 客户 NEWUM = COND #( WHEN P_ALV-BOE_TYPE = 'C' THEN 'W' WHEN P_ALV-BOE_TYPE = 'Y' THEN 'W' WHEN P_ALV-BOE_TYPE = 'B' THEN 'V' WHEN P_ALV-BOE_TYPE = 'X' THEN 'N' ) "特别总账标识 WRBTR = L_PJYE "金额 SGTXT = L_BOE_NUMBER0 "行文本为汇票编号 ZFBDT = P_ALV-WEFAE "汇票到期日 WDATE = P_ALV-WDATE "汇票签发日期 WNAME = L_NAME3 WORT1 = L_ORT03 "收款人城市 WBZOG = P_ALV-BUTXT "付款人(凭证公司) WORT2 = L_ORT01 "付款人城市 BOENO = P_ALV-BOE_INTERNAL_NUM "Check .NO ZUONR = P_ALV-BOE_INTERNAL_NUM ) ). LV_AUGLV = 'AUSGZAHL'. "付款 *---调用函数进行过账 CALL FUNCTION 'ZFM_CM_11' EXPORTING I_BBKPF = LS_BKPF I_AUGLV = LV_AUGLV I_MODE = L_MODE IMPORTING E_SUBRC = LV_SUBRC E_MESSAGE = LS_MSG TABLES T_BBSEG = LT_BSEG T_FTCLEAR = LT_FTCLEAR T_BLNTAB = LT_BLNTAB. "赋值消息内容 TRY. CALL METHOD CL_SYSTEM_UUID=>IF_SYSTEM_UUID_STATIC~CREATE_UUID_X16 RECEIVING UUID = LV_UUID. . CATCH CX_UUID_ERROR INTO DATA(CX_ERROR). ENDTRY. "GET TIME STAMP FIELD DATA(LV_TIMESTAMP). CONVERT DATE SY-DATUM TIME SY-UZEIT INTO TIME STAMP DATA(LV_TIMESTAMP) TIME ZONE LV_TZ. IF LT_BLNTAB IS NOT INITIAL . CLEAR:LT_LOG, LS_LOG. "成功生成凭证号 "更新ZTFI_073 表内容 READ TABLE LT_BLNTAB INTO DATA(LS_BLNTAB) WITH KEY BUKRS = P_ALV-BUKRS. IF SY-SUBRC = 0. "生成消息内容 "凭证 &1 已过账到公司代码 &2 中 GT_MSG = VALUE #( BASE GT_MSG ( MSGID = 'F5' MSGTY = 'S' MSGNO = '312' MSGV1 = LS_BLNTAB-BELNR MSGV2 = P_ALV-BUKRS ) ). P_BELNR_SPLIT = LS_BLNTAB-BELNR. P_GJAHR_SPLIT = LS_BLNTAB-GJAHR. ENDIF. ELSE. "生成凭证号失败 APPEND LS_MSG TO GT_MSG. ENDIF. ENDFORM. |
3.创建凭证并清账
下面这段用于票据背书成功后过账并清账。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
FORM FRM_POST_ACC_DATA . DATA:LS_BKPF TYPE BBKPF, LT_BLNTAB TYPE TABLE OF BLNTAB, LT_BSEG TYPE TABLE OF BBSEG, LT_FTCLEAR TYPE TABLE OF FTCLEAR, LV_WRBTR TYPE WRBTR, LV_WRBTR2 TYPE WRBTR, LS_BSEG TYPE BBSEG, LV_AUGLV TYPE AUGLV, LV_SUBRC TYPE SY-SUBRC, LS_MSG TYPE ESP1_MESSAGE_WA_TYPE, LV_BELNR TYPE BKPF-BELNR, LV_BUKRS TYPE BKPF-BUKRS, LV_GJAHR TYPE BKPF-GJAHR, LT_LOG TYPE TABLE OF ZTCM_004, LS_LOG TYPE ZTCM_004, LV_UUID TYPE SYSUUID_X16, LV_TZ TYPE TTZZ-TZONE VALUE 'UTC'. DATA:LV_VARKEY TYPE RSTABLE-VARKEY, LV_MODE TYPE RFPDO-ALLGAZMD. DATA:LV_SUM_WRBTR TYPE WRBTR. DATA:LV_STRING TYPE STRING. DATA:LV_BOE_INTERNAL_NUM TYPE ZEINT_NUM. DATA: L_ZUONR TYPE DZUONR, LTT_BSEG TYPE TABLE OF BSEG, LT_BSIS TYPE TABLE OF BSIS. DATA: L_MODE TYPE RFPDO-ALLGAZMD VALUE 'N'. CLEAR:LS_BKPF, LT_BSEG, LT_FTCLEAR, LV_AUGLV. "判断检验是否通过 IF GT_MSG IS NOT INITIAL. "检验不通过输出消息 CALL FUNCTION 'C14Z_MESSAGES_SHOW_AS_POPUP' TABLES I_MESSAGE_TAB = GT_MSG. CLEAR:GT_MSG. RETURN. ELSE. *&---获取所有选中的信息 DATA(LT_SELECT) = GT_ALV. DELETE LT_SELECT WHERE BOX IS INITIAL. DATA(LV_LINES) = LINES( LT_SELECT ). *&---HANDZBH 业务范围取值注释 20200608 *&--获取业务范围及描述信息 * SELECT * * INTO TABLE @DATA(LT_ZTFI_011) * FROM ZTFI_011 * FOR ALL ENTRIES IN @LT_SELECT * WHERE VKORG = @LT_SELECT-BUKRS. * * SORT LT_ZTFI_011 BY VKORG VKBUR. IF LT_SELECT[] IS NOT INITIAL. *---取公司所在城市 SELECT BUKRS, ORT01 INTO TABLE @DATA(LT_BUK) FROM T001 FOR ALL ENTRIES IN @LT_SELECT WHERE BUKRS = @LT_SELECT-BUKRS. SORT LT_BUK BY BUKRS. *---取付款人所在城市 DATA(LT_TAB) = GT_ALV. SORT LT_TAB BY KUNNR. DELETE ADJACENT DUPLICATES FROM LT_TAB COMPARING KUNNR. SELECT A~KUNNR, ORT01 FROM KNA1 AS A INNER JOIN @LT_TAB AS B ON A~KUNNR = B~KUNNR INTO TABLE @DATA(LT_KUN). SORT LT_KUN BY KUNNR. *&---HANDZBH 业务范围取值注释 20200608 *---取业务范围 * LT_TAB = GT_ALV. * SORT LT_TAB BY BUKRS KUNNR. * DELETE ADJACENT DUPLICATES FROM LT_TAB COMPARING BUKRS EN_INTER_ENDORSEE. * * SELECT A~KUNNR, * A~VKORG AS BUKRS, * A~VKBUR * FROM KNVV AS A INNER JOIN @LT_TAB AS B * ON A~KUNNR = B~BUKRS * AND A~VKORG = B~EN_INTER_ENDORSEE * INTO TABLE @DATA(LT_VKB). * SORT LT_VKB BY BUKRS KUNNR. *&---获取被背书方信息 SELECT BUKRS, BOE_NUMBER, BOE_CURR_TRANS_NUM, BOE_INTERNAL_NUM FROM ZTFI_072 FOR ALL ENTRIES IN @LT_SELECT WHERE BUKRS = @LT_SELECT-EN_INTER_ENDORSEE AND BOE_NUMBER = @LT_SELECT-BOE_NUMBER AND BOE_CURR_TRANS_NUM = @LT_SELECT-BOE_CURR_TRANS_NUM INTO TABLE @DATA(LT_ZT072). SORT LT_ZT072 BY BUKRS BOE_NUMBER BOE_CURR_TRANS_NUM. ENDIF. *----一个交易事务码一张凭证 LOOP AT GT_ALV INTO DATA(LS_ITEM) WHERE BOX = GC_X. *&---获取被背书方内部汇票编号 CLEAR:LV_BOE_INTERNAL_NUM. READ TABLE LT_ZT072 INTO DATA(LS_ZT072) WITH KEY BUKRS = LS_ITEM-EN_INTER_ENDORSEE BOE_NUMBER = LS_ITEM-BOE_NUMBER BOE_CURR_TRANS_NUM = LS_ITEM-BOE_CURR_TRANS_NUM BINARY SEARCH. IF SY-SUBRC = 0. LV_BOE_INTERNAL_NUM = LS_ZT072-BOE_INTERNAL_NUM. ENDIF. LS_ITEM-BOE_NUMBER = ZCL_TR_DRAFT=>ZDRAFT_RECAST( I_DRAFT = LS_ITEM-BOE_NUMBER )."去除前导0 *---背书汇票至供应商或客户 IF LS_ITEM-EN_ENDORSE_TYPE = 'ENDORSE'. *----清账行汇票行 LT_FTCLEAR = VALUE #( BASE LT_FTCLEAR ( AGKOA = 'D' AGKON = LS_ITEM-KUNNR AGBUK = LS_ITEM-BUKRS AGUMS = COND #( WHEN LS_ITEM-BOE_TYPE = 'C' THEN 'W' WHEN LS_ITEM-BOE_TYPE = 'Y' THEN 'W' WHEN LS_ITEM-BOE_TYPE = 'B' THEN 'V' WHEN LS_ITEM-BOE_TYPE = 'X' THEN 'N' ) XNOPS = '' SELFD = 'ZUONR' SELVON = LS_ITEM-BOE_INTERNAL_NUM * SELFD = 'SGTXT' * SELVON = LS_ITEM-BOE_NUMBER ) ). ELSE. "---付款公司所在城市 READ TABLE LT_BUK INTO DATA(LS_BUK) WITH KEY BUKRS = LS_ITEM-BUKRS BINARY SEARCH.. IF SY-SUBRC EQ 0. DATA(LV_WORT1) = LS_BUK-ORT01. ENDIF. CLEAR LS_BUK. "---收款人 DATA(LV_BUK) = |{ LS_ITEM-EN_INT_ENDORSEE ALPHA = IN }|. READ TABLE LT_BUK INTO LS_BUK WITH KEY BUKRS = LV_BUK BINARY SEARCH. IF SY-SUBRC EQ 0. DATA(LV_WORT2) = LS_BUK-ORT01. ENDIF. CLEAR LV_BUK. *&---HANDZBH 业务范围取值注释 20200608 "--业务范围 * * "取业务范围逻辑 * READ TABLE LT_VKB INTO DATA(LS_VKB) WITH KEY BUKRS = LS_ITEM-BUKRS * KUNNR = LS_ITEM-EN_INTER_ENDORSEE * BINARY SEARCH. * IF SY-SUBRC EQ 0. * * "从表ZTFI_011中取出业务范围GSBER和业务范围描述GTEXT * READ TABLE LT_ZTFI_011 INTO DATA(LS_ZTFI_011) WITH KEY VKORG = LS_ITEM-BUKRS * VKBUR = LS_VKB-VKBUR * BINARY SEARCH. * IF SY-SUBRC = 0. * * DATA(LV_GSBER) = LS_ZTFI_011-GSBER. * * ENDIF. * ENDIF. *----汇票至公司间 LT_BSEG = VALUE #( BASE LT_BSEG ( NEWBS = '09' "记账码 NEWKO = GS_POST-BUKRS "科目 公司代码 NEWUM = COND #( WHEN LS_ITEM-BOE_TYPE = 'C' THEN 'W' WHEN LS_ITEM-BOE_TYPE = 'Y' THEN 'W' WHEN LS_ITEM-BOE_TYPE = 'B' THEN 'V' WHEN LS_ITEM-BOE_TYPE = 'X' THEN 'N' ) "特别总账标识 WRBTR = LS_ITEM-ZBSJE "金额 *&---HANDZBH 业务范围取值注释 20200608 * GSBER = LV_GSBER "业务范围 SGTXT = LS_ITEM-BOE_NUMBER "行文本为汇票编号 ZFBDT = LS_ITEM-WEFAE "汇票到期日 WDATE = LS_ITEM-WDATE "汇票签发日期 WNAME = LS_ITEM-EN_INT_ENDORSEE "收款人 WORT1 = LV_WORT2 "收款人城市 WBZOG = LS_ITEM-BUTXT "付款人 WORT2 = LV_WORT1 BOENO = LV_BOE_INTERNAL_NUM "Check .NO ZUONR = LV_BOE_INTERNAL_NUM ) ). * 汇票行 LT_FTCLEAR = VALUE #( BASE LT_FTCLEAR ( AGKOA = 'D' AGKON = LS_ITEM-KUNNR AGBUK = LS_ITEM-BUKRS AGUMS = COND #( WHEN LS_ITEM-BOE_TYPE = 'C' THEN 'W' WHEN LS_ITEM-BOE_TYPE = 'Y' THEN 'W' WHEN LS_ITEM-BOE_TYPE = 'B' THEN 'V' WHEN LS_ITEM-BOE_TYPE = 'X' THEN 'N' ) XNOPS = '' SELFD = 'ZUONR' SELVON = LS_ITEM-BOE_INTERNAL_NUM * SELFD = 'SGTXT' * SELVON = LS_ITEM-BOE_NUMBER ) ). ENDIF. *----金额汇总 LV_WRBTR = LV_WRBTR + LS_ITEM-ZBSJE. IF LS_ITEM-ZBSJE <> LS_ITEM-WRBTR. "把余额行重记入 CLEAR:LTT_BSEG,LT_BSIS. L_ZUONR = LS_ITEM-BOE_INTERNAL_NUM. SELECT * INTO TABLE LTT_BSEG FROM BSEG WHERE BUKRS = LS_ITEM-BUKRS AND KOART = 'D' AND KUNNR = LS_ITEM-KUNNR AND ZUONR = L_ZUONR. IF SY-SUBRC = 0. SELECT * INTO TABLE LT_BSIS FROM BSIS FOR ALL ENTRIES IN LTT_BSEG WHERE BUKRS = LTT_BSEG-BUKRS AND GJAHR = LTT_BSEG-GJAHR AND BELNR = LTT_BSEG-BELNR AND BUZEI = LTT_BSEG-BUZEI. ENDIF. LOOP AT LT_BSIS INTO DATA(LS_BSIS)."理论上这里只会有一行,如有多行按实际 情况再做考虑 READ TABLE LTT_BSEG INTO DATA(LSS_BSEG) WITH KEY BUKRS = LS_BSIS-BUKRS GJAHR = LS_BSIS-GJAHR BELNR = LS_BSIS-BELNR BUZEI = LS_BSIS-BUZEI. LV_WRBTR2 = LS_ITEM-WRBTR - LS_ITEM-ZBSJE."余额 IF LS_ITEM-EN_ENDORSE_TYPE = 'ENDORSE'. LS_BSIS-BUKRS = ''. ENDIF. LT_BSEG = VALUE #( BASE LT_BSEG ( NEWBS = LSS_BSEG-BSCHL "记账码,应该都是09 NEWKO = LSS_BSEG-KUNNR "D,客户 NEWUM = LSS_BSEG-UMSKZ"特别总账标识 WRBTR = LV_WRBTR2 "剩余金额重新记入 SGTXT = LSS_BSEG-SGTXT "行文本为汇票编号,理论上只值 应该等于BSEG-SGTXT ZFBDT = LS_ITEM-WEFAE "汇票到期日 WDATE = LS_ITEM-WDATE "汇票签发日期 WNAME = LS_ITEM-EN_INT_ENDORSEE "收款人 WORT1 = LV_WORT2 "收款人城市 WBZOG = LS_ITEM-BUTXT "付款人 WORT2 = LV_WORT1 BOENO = LSS_BSEG-ZUONR "Check .NO ZUONR = LSS_BSEG-ZUONR NEWBK = LS_BSIS-BUKRS "新公司代码 ) ). EXIT. ENDLOOP. ENDIF. ENDLOOP. *---凭证抬头 IF LS_ITEM-EN_ENDORSE_TYPE = 'ENDORSE'. LS_BKPF-BUKRS = GS_POST-BUKRS. ELSE. LS_BKPF-BUKRS = LS_ITEM-EN_INTER_ENDORSEE. ENDIF. LS_BKPF-BLART = GS_POST-BLART. LS_BKPF-BLDAT = GS_POST-BLDAT. LS_BKPF-BUDAT = GS_POST-BUDAT. LS_BKPF-MONAT = GS_POST-BUDAT+4(2). LS_BKPF-BKTXT = GS_POST-BKTXT. LS_BKPF-WAERS = GS_POST-WAERS. DATA:LV_WBS TYPE C. LOOP AT LT_SELECT INTO DATA(GS_ALV) WHERE PSPNR <> '000000'. LV_WBS = 'X'. EXIT. ENDLOOP. IF LV_WBS IS INITIAL. *---行 *---FB05收付款选项 IF LS_ITEM-EN_ENDORSE_TYPE = 'ENDORSE'. LV_AUGLV = 'AUSGZAHL'. "付款 * DATA:LV_PROJK TYPE PROJK_BI. * * CLEAR:LV_PROJK. * CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT' * EXPORTING * INPUT = LS_ITEM-PSPNR * IMPORTING * OUTPUT = LV_PROJK. LT_BSEG = VALUE #( BASE LT_BSEG ( NEWBS = GS_POST-BSCHL "记账码 NEWKO = LS_ITEM-EN_ENDORSEE_ID "科目 背书人编号 NEWUM = GS_POST-UMSKZ "特别总账标识 WRBTR = LV_WRBTR "金额 * WRBTR = LS_ITEM-WRBTR "金额 "GSBER = LS_ITEM-GSBER "业务范围 SGTXT = GS_POST-BKTXT "行文本与抬头文本一致 ZFBDT = GS_POST-BUDAT "汇票到期日 * WDATE = LS_ITEM-WDATE "汇票签发日期 "PROJK = LV_PROJK RSTGR = LS_ITEM-RSTGR "原因代码 XNEGP = COND #( WHEN LS_ITEM-EN_ACCOUNT_TYPE = 'D' THEN 'X' ) ) ). ELSEIF LS_ITEM-EN_ENDORSE_TYPE = 'IN-ENDORSE'. LV_AUGLV = 'EINGZAHL'. "收款 "被背书公司 LT_BSEG = VALUE #( BASE LT_BSEG ( NEWBS = '11' "记账码 NEWKO = GS_POST-BUKRS "科目 公司代码 "NEWUM = GS_POST-UMSKZ "特别总账标识 WRBTR = LV_WRBTR "金额 SGTXT = GS_POST-BKTXT "行文本与抬头文本一致 ZFBDT = GS_POST-BUDAT "汇票到期日 ) ). "背书公司 LT_BSEG = VALUE #( BASE LT_BSEG ( NEWBS = '21' "记账码 NEWKO = LS_ITEM-EN_INTER_ENDORSEE "科目被背书人 NEWBK = GS_POST-BUKRS "新公司代码 WRBTR = LV_WRBTR "金额 SGTXT = GS_POST-BKTXT "行文本与抬头文本一致 ZFBDT = GS_POST-BUDAT "汇票到期日 ) ). ENDIF. ELSE. LOOP AT GT_ALV INTO LS_ITEM WHERE BOX = GC_X. *---行 *---FB05收付款选项 IF LS_ITEM-EN_ENDORSE_TYPE = 'ENDORSE'. LV_AUGLV = 'AUSGZAHL'. "付款 DATA:LV_PROJK TYPE PROJK_BI. CLEAR:LV_PROJK. CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT' EXPORTING INPUT = LS_ITEM-PSPNR IMPORTING OUTPUT = LV_PROJK. LT_BSEG = VALUE #( BASE LT_BSEG ( NEWBS = GS_POST-BSCHL "记账码 NEWKO = LS_ITEM-EN_ENDORSEE_ID "科目 背书人编号 NEWUM = GS_POST-UMSKZ "特别总账标识 * WRBTR = LV_WRBTR "金额 WRBTR = LS_ITEM-ZBSJE "金额 "GSBER = LS_ITEM-GSBER "业务范围 SGTXT = GS_POST-BKTXT "行文本与抬头文本一致 ZFBDT = GS_POST-BUDAT "汇票到期日 * WDATE = LS_ITEM-WDATE "汇票签发日期 PROJK = LV_PROJK RSTGR = LS_ITEM-RSTGR "原因代码 XNEGP = COND #( WHEN LS_ITEM-EN_ACCOUNT_TYPE = 'D' THEN 'X' ) ) ). ENDIF. ENDLOOP. ENDIF. BREAK HAND_YS. * IF LV_WRBTR = LV_WRBTR2."背书金额不等于票据金额 *---调用函数进行过账 CALL FUNCTION 'ZFM_CM_11' EXPORTING I_BBKPF = LS_BKPF I_AUGLV = LV_AUGLV I_MODE = L_MODE IMPORTING E_SUBRC = LV_SUBRC E_MESSAGE = LS_MSG TABLES T_BBSEG = LT_BSEG T_FTCLEAR = LT_FTCLEAR T_BLNTAB = LT_BLNTAB. * ELSE. **---背书拆分过账,理论上,新函数 应该支持所有类型 * CALL FUNCTION 'ZFM_CM_11_N' * EXPORTING * I_BBKPF = LS_BKPF * I_AUGLV = LV_AUGLV ** I_MODE = 'D' * IMPORTING * E_SUBRC = LV_SUBRC * E_MESSAGE = LS_MSG * TABLES * T_BBSEG = LT_BSEG * T_FTCLEAR = LT_FTCLEAR * T_BLNTAB = LT_BLNTAB. * * ENDIF. "赋值消息内容 TRY. CALL METHOD CL_SYSTEM_UUID=>IF_SYSTEM_UUID_STATIC~CREATE_UUID_X16 RECEIVING UUID = LV_UUID. . CATCH CX_UUID_ERROR INTO DATA(CX_ERROR). ENDTRY. "GET TIME STAMP FIELD DATA(LV_TIMESTAMP). CONVERT DATE SY-DATUM TIME SY-UZEIT INTO TIME STAMP DATA(LV_TIMESTAMP) TIME ZONE LV_TZ. IF LT_BLNTAB IS NOT INITIAL . CLEAR:LT_LOG, LS_LOG. "成功生成凭证号 "更新ZTFI_073 表内容 READ TABLE LT_BLNTAB INTO DATA(LS_BLNTAB) WITH KEY BUKRS = GS_POST-BUKRS. IF SY-SUBRC = 0. "生成消息内容 "凭证 &1 已过账到公司代码 &2 中 GT_MSG = VALUE #( BASE GT_MSG ( MSGID = 'F5' MSGTY = 'S' MSGNO = '312' MSGV1 = LS_BLNTAB-BELNR MSGV2 = GS_POST-BUKRS ) ). ENDIF. ELSE. "生成凭证号失败 APPEND LS_MSG TO GT_MSG. ENDIF. LOOP AT GT_ALV INTO DATA(LS_ALV) WHERE BOX = GC_X. CLEAR LS_LOG. IF LS_BLNTAB-BELNR IS NOT INITIAL. "更新ZTFI_073背书已过帐 UPDATE ZTFI_073 SET BELNR = LS_BLNTAB-BELNR GJAHR = LS_BLNTAB-GJAHR BUDAT = GS_POST-BUDAT BOE_STATUS = '22' STBLG = '' STJAH = '' STODT = '' UPNAM = SY-UNAME UPDAT = SY-DATUM UPTIM = SY-UZEIT WHERE BUKRS = LS_ALV-BUKRS AND BOE_INTERNAL_NUM = LS_ALV-BOE_INTERNAL_NUM AND BOE_NUMBER = LS_ALV-BOE_NUMBER. IF SY-SUBRC NE 0. DATA(LV_ERROR) = GC_X. LS_LOG-MTYPE = 'E'. LS_LOG-MESSAGE = |{ TEXT-127 }{ TEXT-117 }{ LS_BLNTAB-BELNR }{ TEXT-136 }|. ELSE. LS_ALV-BELNR = LS_BLNTAB-BELNR. LS_ALV-GJAHR = LS_BLNTAB-GJAHR. LS_ALV-BUDAT = GS_POST-BUDAT. LS_ALV-BOE_STATUS = '22'. LS_ALV-LTEXT = TEXT-127. CLEAR: LS_ALV-STBLG, LS_ALV-STJAH, LS_ALV-STODT. MODIFY GT_ALV FROM LS_ALV. LS_LOG-MTYPE = 'E'. LS_LOG-MESSAGE = |{ TEXT-127 }{ TEXT-117 }{ LS_BLNTAB-BELNR }|. ENDIF. IF LS_ALV-EN_ENDORSE_TYPE = 'IN-ENDORSE'. "2020-06-11 baohui.zhou(Hand) 更改过账及冲销 "更新ZTFI_072 表内容 READ TABLE LT_BLNTAB INTO DATA(LS_BLNTAB_IN) WITH KEY BUKRS = LS_ALV-EN_INTER_ENDORSEE. IF SY-SUBRC = 0. UPDATE ZTFI_072 SET BELNR = LS_BLNTAB_IN-BELNR GJAHR = LS_BLNTAB_IN-GJAHR BUDAT = GS_POST-BUDAT BOE_STATUS = '11' STBLG = '' STJAH = '' STODT = '' UPNAM = SY-UNAME UPDAT = SY-DATUM UPTIM = SY-UZEIT WHERE BUKRS = LS_ALV-EN_INTER_ENDORSEE AND BOE_NUMBER = LS_ALV-BOE_NUMBER AND BOE_CURR_TRANS_NUM = LS_ALV-BOE_CURR_TRANS_NUM. IF SY-SUBRC NE 0. LV_ERROR = GC_X. LS_LOG-MTYPE = 'E'. LS_LOG-MESSAGE = |{ LS_LOG-MESSAGE }{ TEXT-138 }|. ELSE. LS_LOG-MTYPE = 'S'. LS_LOG-MESSAGE = |{ LS_LOG-MESSAGE }{ TEXT-137 }|. ENDIF. ENDIF. ENDIF. ELSE. LS_LOG-MTYPE = 'E'. MESSAGE ID LS_MSG-MSGID TYPE LS_MSG-MSGTY NUMBER LS_MSG-MSGNO INTO LS_LOG-MESSAGE WITH LS_MSG-MSGV1 LS_MSG-MSGV2 LS_MSG-MSGV3 LS_MSG-MSGV4. ENDIF. LT_LOG = VALUE #( BASE LT_LOG ( UUID = LV_UUID TIMESTAMP = LV_TIMESTAMP BUKRS = LS_ALV-BUKRS BOE_NUMBER = LS_ALV-BOE_NUMBER BOE_INTERNAL_NUM = LS_ALV-BOE_INTERNAL_NUM BOE_STATUS = LS_ALV-BOE_STATUS MTYPE = LS_LOG-MTYPE MESSAGE = LS_LOG-MESSAGE REPID = SY-REPID CRNAM = SY-UNAME RQTDD = SY-DATUM RQTDT = SY-UZEIT ) ). ENDLOOP. IF LT_BLNTAB IS NOT INITIAL . *---更新OA付款金额 LT_TAB = GT_ALV. DELETE LT_TAB WHERE BOX NE GC_X. DELETE LT_TAB WHERE ZFKSQD IS INITIAL. *&---去重 DELETE ADJACENT DUPLICATES FROM LT_TAB COMPARING BUKRS ZFKSQD. SELECT A~BUKRS, A~ZFKSQD, * SUM( A~WRBTR ) AS WRBTR SUM( A~ZBSJE ) AS WRBTR FROM ZTFI_073 AS A INNER JOIN @LT_TAB AS B ON A~ZFKSQD = B~ZFKSQD AND A~BUKRS = B~BUKRS WHERE A~BOE_STATUS = '22' AND A~BELNR IS NOT NULL AND A~LOEKZ <> 'X' GROUP BY A~BUKRS,A~ZFKSQD INTO TABLE @DATA(LT_SUM). SORT LT_SUM BY BUKRS ZFKSQD. SELECT A~BUKRS, A~ZFKSQD, SUM( A~WRBTR ) AS WRBTR FROM ZTFI_079 AS A INNER JOIN @LT_TAB AS B ON A~ZFKSQD = B~ZFKSQD AND A~BUKRS = B~BUKRS WHERE A~BOE_STATUS = '11' AND A~BELNR IS NOT NULL AND A~LOEKZ <> 'X' GROUP BY A~BUKRS,A~ZFKSQD INTO TABLE @DATA(LT_079). SORT LT_079 BY BUKRS ZFKSQD. LOOP AT LT_TAB INTO DATA(LS_TAB). CLEAR:LV_SUM_WRBTR. READ TABLE LT_SUM INTO DATA(LS_SUM) WITH KEY BUKRS = LS_TAB-BUKRS ZFKSQD = LS_TAB-ZFKSQD BINARY SEARCH. IF SY-SUBRC = 0. LV_SUM_WRBTR = LV_SUM_WRBTR + LS_SUM-WRBTR. ENDIF. READ TABLE LT_079 INTO DATA(LS_079) WITH KEY BUKRS = LS_TAB-BUKRS ZFKSQD = LS_TAB-ZFKSQD BINARY SEARCH. IF SY-SUBRC = 0. LV_SUM_WRBTR = LV_SUM_WRBTR + LS_079-WRBTR. ENDIF. UPDATE ZTFI_074 SET DMBTR = LV_SUM_WRBTR UPNAM = SY-UNAME UPDAT = SY-DATUM UPTIM = SY-UZEIT WHERE BUKRS = LS_TAB-BUKRS AND ZFKSQD = LS_TAB-ZFKSQD. IF SY-SUBRC NE 0. LV_ERROR = GC_X. ENDIF. ENDLOOP. IF LV_ERROR = GC_X. ROLLBACK WORK. CLEAR:LV_STRING. LV_STRING = |{ LV_LINES } { TEXT-142 }|. GT_MSG = VALUE #( BASE GT_MSG ( MSGID = 'ZMFI01' MSGTY = 'E' MSGNO = '000' MSGV1 = LV_STRING ) ). ELSE. COMMIT WORK AND WAIT. CLEAR:LV_STRING. LV_STRING = |{ LV_LINES } { TEXT-141 }|. GT_MSG = VALUE #( BASE GT_MSG ( MSGID = 'ZMFI01' MSGTY = 'S' MSGNO = '000' MSGV1 = LV_STRING ) ). ENDIF. ENDIF. IF LT_LOG IS NOT INITIAL. MODIFY ZTCM_004 FROM TABLE LT_LOG. IF SY-SUBRC NE 0. ROLLBACK WORK. ELSE. COMMIT WORK AND WAIT . ENDIF. ENDIF. IF GT_MSG IS NOT INITIAL. *&---输出消息 CALL FUNCTION 'C14Z_MESSAGES_SHOW_AS_POPUP' TABLES I_MESSAGE_TAB = GT_MSG. CLEAR: GT_MSG. ENDIF. ENDIF. "关闭SCREEN LEAVE TO SCREEN 0. ENDFORM. |
4.增强
在FB05创建票据的会计凭证时,系统有一段标准逻辑来检查BOENO(Check Number)有效性,所以在调用前使用EXPORT LV_CODE TO MEMORY ID ‘ZZFID001’.来票据一下,并做一个BTE增强来处理,使用之不做检查 。
以查询,事务码:FIBF 然后选择菜单“设置 -> P/S 模块 -> .. 一个 SAP 应用程序 ,中配置了,’BOE_BTE_1030′ 和 ‘BOE_BTE_1025’,所以解决办法是,可以直接在配置的这里删除这两个配置,或者是在这两个函数 ‘BOE_BTE_1030’ 和 ‘BOE_BTE_1025’的开头做自由点增加,当是我们程序运行的就退出。我当前如下BOE_BTE_1030没运行,所以没增强。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
ENHANCEMENT 1 ZFIEH_023. "active version * *--------------------------------------------- *自开发的票据平台不执行标准的BTE增强 20200602 * 内存输出点在 票据平台T-CODE 'ZFI001' 过账封装函数中 ZFM_CM_011 *--------------------------------------------- DATA:LV_CODE(10). IMPORT LV_CODE TO LV_CODE FROM MEMORY ID 'ZZFID001'. IF LV_CODE = 'ZZFID001'. FREE MEMORY ID 'ZZFID001'. RETURN. ENDIF. ENDENHANCEMENT. |