sap abap在表VBAP和VBAK上增加新字段的标准BAPI
2016-12-07 16:02
1041 查看
在表VBAP和VBAK上增加新字段的标准BAPI
If you have custom ZZ fields on VBAP and VBAK then you can update these fields using the standard BAPI to create or change the order and update these fields.
A lot has been spoken about this but nowhere does it spell out the pitfalls and give you an end-to-end procedure on how to do it. I even found some "SAP Experts - Ask
a question" on Search SAP give a complete wrong answer!!! So here is the correct way to do it.
--------------------------------------------------------------------------------
To do so you first need to ensure that the following 5 tables are in synch.
1) VBAP: In your append structure you specify your ZZFIELD with the data type as needed
2) BAPE_VBAP:
In the append structure here also add the ZZFIELD with the data type as needed with limitations. No decimals. Try and stick to char characters
3) BAPE_VBAPX:
In the append structure add the field ZZFIELD of type BAPIUPDATE
(NOTE: (2) and (3) must have the same number of fields in the same order)
4) VBAPKOZ: In the append structure here also add the ZZFIELD with the data type as needed with limitations. No decimals. Try and stick to char characters
5) VBAPKOZX: In the append structure add the field ZZFIELD of type BAPIUPDATE
(NOTE: (4) and (5) must have the same number of fields in the same order)
Similarly do for VBAK, BAPE_VBAK, BAPE_VBAKX,
VBAKKOZ and VBAKKOZX.
Next we get to the code to fill in the structure EXTENSIONIN
I will demonstrate how to call the create sales order BAPI with custom fields.
* Local definitions
DATA: wa_extensionin
TYPE bapiparex,
wa_bape_vbap
TYPE bape_vbap,
wa_bape_vbapx TYPE bape_vbapx,
wa_bape_vbak
TYPE bape_vbak,
wa_bape_vbakx TYPE bape_vbakx,
lv_posnr
TYPE posnr.
* Processing the header extension
CLEAR wa_bape_vbak.
wa_bape_vbak-ZZFIELD
= 'HDRTEST'.
wa_extensionin-structure
= 'BAPE_VBAK'.
wa_extensionin+30(960)
= wa_bape_vbak.
append wa_extensionin
to lt_extensionin.
clear wa_extensionin.
* Processing the line extension
LOOP AT line_items
INTO wa_lineitems.
ADD 10 TO lv_posnr.
CLEAR wa_bape_vbap.
wa_bape_vbap-ZZFIELD
= 'TEST'.
wa_extensionin-structure
= 'BAPE_VBAP'.
wa_bape_vbap-posnr
= lv_posnr.
wa_extensionin+30(960)
= wa_bape_vbap.
append wa_extensionin
to lt_extensionin.
clear wa_extensionin.
CLEAR wa_bape_vbapx.
wa_bape_vbapx-ZZFIELD
= 'X'.
wa_extensionin-structure
= 'BAPE_VBAPX'.
wa_bape_vbapx-posnr
= lv_posnr.
wa_extensionin+30(960)
= wa_bape_vbapx.
append wa_extensionin
to lt_extensionin.
clear wa_extensionin.
ENDLOOP.
* Then the call to the BAPI
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in =
ls_order_header_in
order_header_inx
= ls_order_header_inx
IMPORTING
salesdocument = lv_salesdocument
TABLES
return = lt_ret2
order_items_in
= lt_order_items_in
order_items_inx =
lt_order_items_inx
order_partners
= lt_order_partners
order_keys
= lt_order_keys
extensionin = lt_extensionin.
Note: If you have a need to force a different Business Object type or wish to see the extension return fields then use the function SD_SALESDOCUMENT_CREATE
instead.
CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
EXPORTING
sales_header_in
= ls_order_header_in
sales_header_inx
= ls_order_header_inx
business_object
= 'BUS2032'
IMPORTING
salesdocument_ex
= lv_salesdocument
sales_header_out
= lv_sales_header_out
sales_header_status
= lv_sales_header_status
TABLES
return = lt_ret2
sales_items_in
= lt_order_items_in
sales_items_inx
= lt_order_items_inx
sales_partners
= lt_order_partners
sales_keys
= lt_order_keys
extensionin = lt_extensionin
incomplete_log
= lt_incomplete_log
extensionex = lt_extensionex.
If you have custom ZZ fields on VBAP and VBAK then you can update these fields using the standard BAPI to create or change the order and update these fields.
A lot has been spoken about this but nowhere does it spell out the pitfalls and give you an end-to-end procedure on how to do it. I even found some "SAP Experts - Ask
a question" on Search SAP give a complete wrong answer!!! So here is the correct way to do it.
--------------------------------------------------------------------------------
To do so you first need to ensure that the following 5 tables are in synch.
1) VBAP: In your append structure you specify your ZZFIELD with the data type as needed
2) BAPE_VBAP:
In the append structure here also add the ZZFIELD with the data type as needed with limitations. No decimals. Try and stick to char characters
3) BAPE_VBAPX:
In the append structure add the field ZZFIELD of type BAPIUPDATE
(NOTE: (2) and (3) must have the same number of fields in the same order)
4) VBAPKOZ: In the append structure here also add the ZZFIELD with the data type as needed with limitations. No decimals. Try and stick to char characters
5) VBAPKOZX: In the append structure add the field ZZFIELD of type BAPIUPDATE
(NOTE: (4) and (5) must have the same number of fields in the same order)
Similarly do for VBAK, BAPE_VBAK, BAPE_VBAKX,
VBAKKOZ and VBAKKOZX.
Next we get to the code to fill in the structure EXTENSIONIN
I will demonstrate how to call the create sales order BAPI with custom fields.
* Local definitions
DATA: wa_extensionin
TYPE bapiparex,
wa_bape_vbap
TYPE bape_vbap,
wa_bape_vbapx TYPE bape_vbapx,
wa_bape_vbak
TYPE bape_vbak,
wa_bape_vbakx TYPE bape_vbakx,
lv_posnr
TYPE posnr.
* Processing the header extension
CLEAR wa_bape_vbak.
wa_bape_vbak-ZZFIELD
= 'HDRTEST'.
wa_extensionin-structure
= 'BAPE_VBAK'.
wa_extensionin+30(960)
= wa_bape_vbak.
append wa_extensionin
to lt_extensionin.
clear wa_extensionin.
* Processing the line extension
LOOP AT line_items
INTO wa_lineitems.
ADD 10 TO lv_posnr.
CLEAR wa_bape_vbap.
wa_bape_vbap-ZZFIELD
= 'TEST'.
wa_extensionin-structure
= 'BAPE_VBAP'.
wa_bape_vbap-posnr
= lv_posnr.
wa_extensionin+30(960)
= wa_bape_vbap.
append wa_extensionin
to lt_extensionin.
clear wa_extensionin.
CLEAR wa_bape_vbapx.
wa_bape_vbapx-ZZFIELD
= 'X'.
wa_extensionin-structure
= 'BAPE_VBAPX'.
wa_bape_vbapx-posnr
= lv_posnr.
wa_extensionin+30(960)
= wa_bape_vbapx.
append wa_extensionin
to lt_extensionin.
clear wa_extensionin.
ENDLOOP.
* Then the call to the BAPI
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in =
ls_order_header_in
order_header_inx
= ls_order_header_inx
IMPORTING
salesdocument = lv_salesdocument
TABLES
return = lt_ret2
order_items_in
= lt_order_items_in
order_items_inx =
lt_order_items_inx
order_partners
= lt_order_partners
order_keys
= lt_order_keys
extensionin = lt_extensionin.
Note: If you have a need to force a different Business Object type or wish to see the extension return fields then use the function SD_SALESDOCUMENT_CREATE
instead.
CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
EXPORTING
sales_header_in
= ls_order_header_in
sales_header_inx
= ls_order_header_inx
business_object
= 'BUS2032'
IMPORTING
salesdocument_ex
= lv_salesdocument
sales_header_out
= lv_sales_header_out
sales_header_status
= lv_sales_header_status
TABLES
return = lt_ret2
sales_items_in
= lt_order_items_in
sales_items_inx
= lt_order_items_inx
sales_partners
= lt_order_partners
sales_keys
= lt_order_keys
extensionin = lt_extensionin
incomplete_log
= lt_incomplete_log
extensionex = lt_extensionex.
相关文章推荐
- SD-如何在SAP标准IDOC中增加自定义字段传输
- BADI增强BAPI-BAPI_ACC_DOCUMENT_POST增加字段
- 如何在SAP标准IDOC中增加自定义字段传输
- dedecms调用新增加的内容模型字段
- 在Salesforce页面布局中添加Visualforce Pages项 - 自定义标准页面 + 获取富文本字段的图片Url
- ORACLE—001:Alter之增加字段,修改字段类型
- oracle使用sql语句增加字段示例(sql删除字段语句)_oracle
- MySql 增加字段 删除字段 修改字段名称 修改字段类型
- iOS FMDB 增加字段
- 【后台】菜单管理界面菜单项增加自定义字段
- 修改hive分区表,在分区列前增加一个字段
- MySQL中的表中增加删除字段
- 如何在Oracle中增加修改删除字段
- dataGridView增加可操作事件字段
- 909422229_ORACLE中通过SQL语句(alter table)来增加、删除、修改字段
- SQL2005中对一个记录很大的表增加一个自增字段,总是增加失败
- [乐意黎原创]Mysql 查询字段时强制区分大小写及在某字段左或右边增加内容
- SQL替换语句 批量修改、增加、删除字段内容
- mysql增加修改字段
- logstash 给时间字段增加8小时的方法