函数使用四:采购发票MIRO BAPI_INCOMINGINVOICE_CREATE
1. 业务处理(transaction)字段选择:
创建后续借记(subsequent debit)
ItemData DE_CRE_IND = 'X'
HeaderData INVOICE_IND = 'X'
创建后续贷记(subsequent credit)
ItemData DE_CRE_IND = 'X'
HeaderData INVOICE_IND = ' '
发票(invoice)
HeaderData INVOICE_IND = 'X'
贷方凭证(credit demo)
HeaderData INVOICE_IND = ' '
2. 标识: 货物项目/交货成本/全部(Indicator: Goods Items/Delivery Costs/Both)
货物/服务项目(Goods/service items)
ItemData COND_TYPE = ' '
COND_ST_NO = ' '
COND_COUNT = ' '
计划交货成本(Planned delivery costs)
ItemData COND_TYPE = 'X'
COND_ST_NO = 'X'
COND_COUNT = 'X'
form frm_invoice_create2 .
data: str type string.
data: ls_headerdata like bapi_incinv_create_header,
lt_itemdata like table of bapi_incinv_create_item,
ls_itemdata like bapi_incinv_create_item,
lt_return like table of bapiret2,
ls_return like bapiret2,
lv_invoicedocnumber like bapi_incinv_fld-inv_doc_no,
lv_fiscalyear like bapi_incinv_fld-fisc_year.
data: lv_price1 type bapi_rmwwr.
data: lv_item type n length 6.
data: lv_retpo type retpo.
clear:l_menge,ls_headerdata,lv_fiscalyear,lv_price1,lv_item.
* 处理退货和非退货项目
clear: gt_ret,gt_ret[],gt_inv,gt_inv[].
loop at gt_alv into gs_alv where source = 'EKBE'.
clear: lv_retpo.
select single retpo into lv_retpo from ekpo where ebeln = gs_alv-ebeln and ebelp = gs_alv-ebelp.
loop at gt_invoice into gs_invoice where ebeln = gs_alv-ebeln and ebelp = gs_alv-ebelp.
*---------根据退货标识 放入不同的内表
if lv_retpo = 'X'."退货项目
if gs_invoice-shkzg = 'H'.
gs_invoice-dmbtr = 0 - gs_invoice-dmbtr.
endif.
gt_ret-ebeln = gs_invoice-ebeln."采购订单
gt_ret-ebelp = gs_invoice-ebelp."行项目
gt_ret-lfbnr = gs_invoice-lfbnr. "参考凭证号
gt_ret-lfpos = gs_invoice-lfpos."行项目
gt_ret-lfgja = gs_invoice-lfgja."年度
gt_ret-mwskz = gs_invoice-mwskz."税码
gt_ret-dmbtr = gs_invoice-dmbtr. "金额
gt_ret-menge = gs_invoice-menge. "数量
select single meins into gt_ret-meins from ekpo where ebeln = gs_invoice-ebeln and ebelp = gs_invoice-ebelp.
collect gt_ret.
else.
if gs_invoice-shkzg = 'H'.
gs_invoice-dmbtr = 0 - gs_invoice-dmbtr.
endif.
gt_inv-ebeln = gs_invoice-ebeln."采购订单
gt_inv-ebelp = gs_invoice-ebelp."行项目
gt_inv-lfbnr = gs_invoice-lfbnr. "参考凭证号
gt_inv-lfpos = gs_invoice-lfpos."行项目
gt_inv-lfgja = gs_invoice-lfgja."年度
gt_inv-mwskz = gs_invoice-mwskz."税码
gt_inv-dmbtr = gs_invoice-dmbtr. "金额
gt_inv-menge = gs_invoice-menge. "数量
select single meins into gt_inv-meins from ekpo where ebeln = gs_invoice-ebeln and ebelp = gs_invoice-ebelp.
collect gt_inv.
endif.
endloop.
endloop.
*---正常订单发票校验
clear: ls_headerdata.
ls_headerdata-invoice_ind = 'X'. "当采购订单行项目是正常订单时该标识必为X,为miro界面上的业务处理为1.发票否则为2.贷方凭证(invoice_ind='X'表示miro界面最上部的业务处理是1.发票,invoice_ind='', 表示miro界面最上部的业务处理为2.贷方凭证)
ls_headerdata-doc_type = 'YX'.
ls_headerdata-doc_date = p_datum.
ls_headerdata-pstng_date = g_post_date.
ls_headerdata-bline_date = g_post_date. "基线日期/付款计算的起始日期
ls_headerdata-comp_code = p_bukr2.
ls_headerdata-currency = 'CNY'.
ls_headerdata-calc_tax_ind = 'X'. "自动结算税额
ls_headerdata-bus_area = '9999'.
clear: lv_item.
loop at gt_inv.
lv_item = lv_item + 1. "发票行项目号
ls_itemdata-invoice_doc_item = lv_item.
ls_itemdata-po_number = gt_inv-ebeln.
ls_itemdata-po_item = gt_inv-ebelp.
ls_itemdata-ref_doc = gt_inv-lfbnr.
ls_itemdata-ref_doc_year = gt_inv-lfgja.
ls_itemdata-ref_doc_it = gt_inv-lfpos.
ls_itemdata-item_amount = gt_inv-dmbtr.
ls_itemdata-quantity = gt_inv-menge.
ls_itemdata-po_unit = gt_inv-meins.
if gt_ret-mwskz is not initial.
ls_itemdata-tax_code = gt_inv-mwskz.
else.
ls_itemdata-tax_code = p_mwskz.
endif.
append ls_itemdata to lt_itemdata.
clear: ls_itemdata.
lv_price1 = lv_price1 + abs( gt_inv-dmbtr ).
endloop.
ls_headerdata-gross_amount = lv_price1 * ( 100 + l_mwskz ) / 100. "总金额
refresh: lt_return.clear: ls_return,invoicedocnumber.
call function 'BAPI_INCOMINGINVOICE_CREATE'
exporting
headerdata = ls_headerdata
importing
invoicedocnumber = invoicedocnumber
tables
itemdata = lt_itemdata
return = lt_return.
loop at lt_return into ls_return where type = 'E' or type = 'A'.
cp_eind = 'X'.
exit.
endloop.
if cp_eind ne 'X'.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
*---插入值到表ZTFI014
gs_ztfi014-tcode = sy-tcode.
gs_ztfi014-seqno = p_datum.
gs_ztfi014-objnr = p_bukr2.
gs_ztfi014-gjahr = p_datum(4).
gs_ztfi014-bukrs = p_bukrs.
gs_ztfi014-belnr = invoicedocnumber.
modify ztfi014 from gs_ztfi014.
else.
call function 'BAPI_TRANSACTION_ROLLBACK'.
loop at lt_return into ls_return.
clear gs_log.
gs_log-type = ls_return-type.
gs_log-docno = invoicedocnumber.
call function 'MESSAGE_TEXT_BUILD'
exporting
msgid = ls_return-id
msgnr = ls_return-number
msgv1 = ls_return-message_v1
msgv2 = ls_return-message_v2
msgv3 = ls_return-message_v3
msgv4 = ls_return-message_v4
importing
message_text_output = gs_log-message.
case gs_log-type.
when 'S'.
gs_log-icon = '3'.
when 'W'.
gs_log-icon = '2'.
when 'E' or 'A'.
gs_log-icon = '1'.
when others.
endcase.
append gs_log to gt_log.
clear ls_return.
endloop.
message e001(00) with '第一张发票预制失败,请点击显示消息查看详情!'.
endif.
*---退货订单发票校验
clear: ls_headerdata-invoice_ind,ls_headerdata-gross_amount. "发票标志 退货是该标识必须为空
clear: lv_item,ls_itemdata,ls_return,invoicedocnumber,lv_price1.
refresh: lt_itemdata,lt_return.
loop at gt_ret.
lv_item = lv_item + 1. "发票行项目号
ls_itemdata-invoice_doc_item = lv_item.
ls_itemdata-po_number = gt_ret-ebeln.
ls_itemdata-po_item = gt_ret-ebelp.
ls_itemdata-ref_doc = gt_ret-lfbnr.
ls_itemdata-ref_doc_year = gt_ret-lfgja.
ls_itemdata-ref_doc_it = gt_ret-lfpos.
ls_itemdata-item_amount = abs( gt_ret-dmbtr ).
ls_itemdata-quantity = gt_ret-menge.
ls_itemdata-po_unit = gt_ret-meins.
if gt_inv-mwskz is not initial.
ls_itemdata-tax_code = gt_ret-mwskz.
else.
ls_itemdata-tax_code = p_mwskz.
endif.
append ls_itemdata to lt_itemdata.
clear: ls_itemdata.
lv_price1 = lv_price1 + abs( gt_ret-dmbtr ).
endloop.
ls_headerdata-gross_amount = lv_price1 * ( 100 + l_mwskz ) / 100. "总金额
refresh: lt_return.clear: ls_return.
call function 'BAPI_INCOMINGINVOICE_CREATE'
exporting
headerdata = ls_headerdata
importing
invoicedocnumber = invoicedocnumber
tables
itemdata = lt_itemdata
return = lt_return.
loop at lt_return into ls_return where type = 'E' or type = 'A'.
cp_eind = 'X'.
exit.
endloop.
if cp_eind ne 'X'.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
*---插入值到表ZTFI014
gs_ztfi014-tcode = sy-tcode.
gs_ztfi014-seqno = p_datum.
gs_ztfi014-objnr = p_bukr2.
gs_ztfi014-gjahr = p_datum(4).
gs_ztfi014-bukrs = p_bukrs.
gs_ztfi014-belnr = invoicedocnumber.
modify ztfi014 from gs_ztfi014.
else.
call function 'BAPI_TRANSACTION_ROLLBACK'.
loop at lt_return into ls_return.
clear gs_log.
gs_log-type = ls_return-type.
gs_log-docno = invoicedocnumber.
call function 'MESSAGE_TEXT_BUILD'
exporting
msgid = ls_return-id
msgnr = ls_return-number
msgv1 = ls_return-message_v1
msgv2 = ls_return-message_v2
msgv3 = ls_return-message_v3
msgv4 = ls_return-message_v4
importing
message_text_output = gs_log-message.
case gs_log-type.
when 'S'.
gs_log-icon = '3'.
when 'W'.
gs_log-icon = '2'.
when 'E' or 'A'.
gs_log-icon = '1'.
when others.
endcase.
append gs_log to gt_log.
clear ls_return.
endloop.
message e001(00) with '第二张发票预制失败,请点击显示消息查看详情!'.
endif.
endform. " FRM_INVOICE_CREATE2
注意:
在PO收货后,做发票校验,发现一个问题,就是在headerdata中有个参数 calc_tax_ind ,如果将这个值‘X’,那么在
ME23N中会看不到生成的发票校验凭证invoicedocnumber的值。
headerdata中的必输值:
invoice_ind 为'X'
doc_date
pstng_date
comp_code
currency
gross_amount
itemdata中的必输值:
invoice_doc_item
po_number
po_item
item_amount
quantity
po_unit
ref_doc
ref_doc_year
ref_doc_it
函数使用四:采购发票MIRO BAPI_INCOMINGINVOICE_CREATE的更多相关文章
- swap函数的四种写法
swap 函数的四种写法 (1)经典型 --- 嫁衣法 void swap(int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; } ( ...
- C语言中返回字符串函数的四种实现方法 2015-05-17 15:00 23人阅读 评论(0) 收藏
C语言中返回字符串函数的四种实现方法 分类: UNIX/LINUX C/C++ 2010-12-29 02:54 11954人阅读 评论(1) 收藏 举报 语言func存储 有四种方式: 1.使用堆空 ...
- JavaScript高级之函数的四种调用形式
主要内容 分析函数的四种调用形式 弄清楚函数中this的意义 明确构造函对象的过程 学会使用上下文调用函数 了解函数的调用过程有助于深入学习与分析JavaScript代码. 本文是JavaScript ...
- C语言中返回字符串函数的四种实现方法
转自C语言中返回字符串函数的四种实现方法 其实就是要返回一个有效的指针,尾部变量退出后就无效了. 有四种方式: 1.使用堆空间,返回申请的堆地址,注意释放 2.函数参数传递指针,返回该指针 3.返回函 ...
- JavaScript函数的四种存在形态
函数的四种存在形态: 1.函数形态 2.方法形态 将函数赋值给某一个对象的成员,那么就称为方法 3.构造器形态 4.上下文形态 1.函数形态: var foo = function() { ale ...
- JS高级. 06 缓存、分析解决递归斐波那契数列、jQuery缓存、沙箱、函数的四种调用方式、call和apply修改函数调用方法
缓存 cache 作用就是将一些常用的数据存储起来 提升性能 cdn //-----------------分析解决递归斐波那契数列<script> //定义一个缓存数组,存储已经计算出来 ...
- JS面向对象函数的四种调用模式
函数的四种调用模式 概念 在 js 中,无论是函数, 还是方法, 还是事件, 还是构造器,...这些东西的本质都是函数 函数, 方法, 事件, 构造器,...只是所处的位置不同 这四种模式分别是 函数 ...
- 函数的四种调用模式.上下文调用.call.apply
闭包:函数就是一个闭包,一个封闭的作用域; 返回函数,要返回多个函数就用一个对象封装一下, 立即执行函数+return 回调函数 JS动态创建的DOM,不会被搜索引 ...
- MIRO发票校验BAPI_INCOMINGINVOICE_CREATE (2013-01-23 10:01:29)
form frm_invoice_create2 . data: str type string. data: ls_headerdata like bapi_incinv_creat ...
随机推荐
- Derek解读Bytom源码-Api Server接口服务
作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...
- Kylin知识点介绍
Kylin is an open source Distributed Analytics Engine from eBay Inc.that provides SQL interface and m ...
- Linux 解决 firefox 中文页面乱码问题
1.由于 firefox 默认是允许网页自己选择字体,在 Linux 上便会出现部分网站的乱码情况.因此可以取消允许页面自己选择字体这个选项便能解决部分乱码情况.
- python学习 day011打卡 迭代器
本节的主要内容: 1.函数名的使用以及第一类对象 2.闭包 3.迭代器 一.函数名的运用. 函数名是一个变量,但它是一个特殊的变量,与括号配合可以执行函数的变量. 1.函数名的内存地址 def fun ...
- android获取屏幕宽度和高度
1. WindowManager wm = (WindowManager) getContext() .getSystemService(Context.WINDOW_SERVICE); int wi ...
- JUnit 4 Vs TestNG比较
JUnit 4和TestNG都是Java中非常受欢迎的单元测试框架.两种框架在功能上看起来非常相似. 哪一个更好? 在Java项目中应该使用哪个单元测试框架? 下面表中概括了JUnit 4和TestN ...
- RN 数据持久化存储服务API
一些数据信息需要存储在手机内存中,比如用户的登录名密码 token啥的,所以这就需要了来存这些信息 在RN中 采用了AsyncStorage是一个简单的.异步的.持久化的Key-Value存储系统,它 ...
- 重温js之null和undefind区别
在JavaScript中存在这样两种原始类型:Null与Undefined.这两种类型常常会使JavaScript的开发人员产生疑惑,在什么时候是Null,什么时候又是Undefined? Undef ...
- vue--v-model表单控件绑定
原文链接:https://www.cnblogs.com/dyfbk/p/6868350.html v-model 指令在表单控件元素上创建双向数据绑定,下面一一进行示例解释. 1.v-model 双 ...
- 使用python读取yaml文件
在做APP测试时,通常需要把参数存到一个字典变量中,这时可以将参数写入yaml文件中,再读取出来. 新建yaml文件(android_caps.yaml),文件内容为: platformName: A ...