BAPI 一些笔记

2022-09-15 11:28:17 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

  • vendor 供应商号:长度必须和系统一致,10位。如 2000025要写成 0002000025传递给参数。

CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’

EXPORTING input = poheader-vendor IMPORTING output = poheader-vendor.

poheaderx-vendor = abap_true.

  • POITEM 中的 PO_ITEM 参数,在 POITEMX中对应的不是X,而是相同的 采购凭证的项目编号.

poitem-po_item = lv_ebelp.”行项目 poitemx-po_item = lv_ebelp.

  • POHEADER中的参数在 POHEADERX一定要有对应的参数。POITEM也一样。
  • 增强字段在extensionin里

“抬头增强字段 ls_te_head-zpslx = ls_head-zpslx. ls_te_head-zzekkoyl0 = ls_head-zwxsh.”无需送货标识 ls_te_headx-zpslx = abap_true. ls_te_headx-zzekkoyl0 = abap_true. lt_extensionin-structure = ‘BAPI_TE_MEPOHEADER’. lt_extensionin-valuepart1 = ls_te_head. APPEND lt_extensionin. CLEAR:ls_te_head,lt_extensionin. lt_extensionin-structure = ‘BAPI_TE_MEPOHEADERX’. lt_extensionin-valuepart1 = ls_te_headx. APPEND lt_extensionin. CLEAR:ls_te_headx,lt_extensionin.

“行项目增强字段 ls_te_item-po_item = lv_ebelp. ls_te_item-zzeanme = lt_data-zzeanme . ls_te_item-zzcd = lt_data-zzcd. ls_te_item-zzjsean = lt_data-ean11. ls_te_item-zzjssl = lt_data-zzeanme. ls_te_item-zzjsdw = lt_data-meins. ls_te_item-zzdgean = lt_data-zzdgean. ls_te_item-zzeanme = lt_data-zzdgsl. ls_te_item-zzdgdw = lt_data-zzdgdw. ls_te_item-zmd = lt_data-zmd. ls_te_item-zzekpoyl6 = lt_data-zzekpoyl6.”城市代码 CLEAR:lt_data,poaccount,poaccountx.

lt_extensionin-structure = ‘BAPI_TE_MEPOITEM’. CALL METHOD cl_abap_container_utilities=>fill_container_c EXPORTING im_value = ls_te_item IMPORTING ex_container = lt_extensionin-valuepart1 EXCEPTIONS illegal_parameter_type = 1 OTHERS = 2. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. APPEND lt_extensionin. CLEAR lt_extensionin.

ls_te_itemx-po_item = lv_ebelp. ls_te_itemx-zzeanme = abap_true. ls_te_itemx-zzcd = abap_true. ls_te_itemx-zzjsean = abap_true. ls_te_itemx-zzjssl = abap_true. ls_te_itemx-zzjsdw = abap_true. ls_te_itemx-zzdgean = abap_true. ls_te_itemx-zzeanme = abap_true. ls_te_itemx-zzdgdw = abap_true. ls_te_itemx-zmd = abap_true. ls_te_itemx-zzekpoyl6 = abap_true. lt_extensionin-structure = ‘BAPI_TE_MEPOITEMX’. lt_extensionin-valuepart1 = ls_te_itemx. APPEND lt_extensionin. CLEAR lt_extensionin.

BAPI的结构,BAPI里的代码可以分为这样两部分:

1、一部分是数据校核,检查传入的数据是否满足创建相关业务对象的条件,并且把错误消息反馈出来;

2、另一部分是更新数据库,即UPDATE/INSERT/DELETE dbtab这样的操作。

1 BAPI的优点

bapi是面向对象的设计;

bapi是固定的,一般不能修改;

bapi可以被sap内部部件和非sap程序使用;

bapi的成功和错误信息始终通过RETURN返回;

bapi可以被许多开发平台使用;

2 何时该考虑使用BAPI设计程序

用VB/JAVA?C 等语言编写非SAPGUI程序访问和处理sap数据;

SAP不同部件之间通讯;

与非sap程序或者老系统交换数据:

使用异步通信分发数据如:ALE

可以通过SAP Business Connector or Internet Application Components 与因特网程序集成;

3 关于RETURN

RETURN用于BAPI返回错误和成功的消息,它可以是BAPIRETURN,BAPIRETURN,BAPIRET1,BAPIRET2和BAPIRET2_FIX中的一种类型.这些结构一般都包括以下字段:

SORT return BY type number row.

LOOP AT return WHERE type = ‘E’ OR type = ‘A’.

ENDLOOP.

如果sy-subrc = 0,CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.

否则

CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’

EXPORTING

wait = ‘X’ “参数wait赋值‘X’,提交完之后才回进行后面的代码

IMPORTING

return = ls_commit_return.

TYPE

CHAR 1

S= success message E = error message W = warning message I = information message A = termination message (abort)终止消息(中止)

ID

CHAR 20

Message ID The structure BAPIRET2 takes into account the name space extension for the message class as of Release 4.0. If you want messages to be compatible with earlier R/3 Releases, use the message classes before Release 4.0.

NUMBER

NUMC 3

Message number

MESSAGE

CHAR 220

Full message text from the message table. All variables (in fields Message_V1 to Message_V4) have been replaced with text.

MESSAGE_V1 MESSAGE_V2 MESSAGE_V3 MESSAGE_V4

CHAR 50

Fields for the variable texts of the message

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/163905.html原文链接:https://javaforall.cn

0 人点赞