SAP ABAP VA01/VA02/VA03销售订单行项目增强及BAPI

效果图如下:

  1. VBAP添加客制化字段。

  1. 子屏幕8459添加增强字段。

PBO更改属性。

MODULE CHANGE_ATT OUTPUT.
if T180-TRTYP eq 'A' .
  LOOP AT SCREEN .
    SCREEN-INPUT .
    MODIFY  SCREEN .
  ENDLOOP.
ENDIF .
ENDMODULE.    

.

BAPI: BAPI_SALESORDER_CREATEFROMDAT2/BAPI_SALESORDER_CHANGE添加客制化字段。

BAPI_SALESORDER_CHANGE为例子:

解释如下:

短文本

Customer Enhancement for VBAK, VBAP, VBEP

Description

You can use this parameter to transfer user-specific enhancments to a BAPI. The customer has to complete the EXTENSION structure and the system automatically continues processing it. If you have not defined any user-specific fields, then you can transfer a blank EXTENSIONIN structure.

Technical information about Customer Enhancements

The following description uses an example to explain how to proceed with customer enhancements to the SD tables VBAK, VBKD, VBAP and VBEP.

The customer has added their own fields to table VBAP using the INCLUDE structure CUTEST. This structure contains 2 fields:
CFIELD1, CHAR 10
CFIELD2, CHAR 3.

The customer also requires that these two fields can be maintained with the BAPI.

1. Maintain structure CUTEST in table VBAP

2. Because the BAPIs work with checkboxes, you must also define a CUTESTX checkbox for the customer structure. It should be structured like this:

Field name       Data element
CFIELD1            CHAR1
CFIELD2          CHAR1

3. Define these customer structures in the structures VBAPKOZ und VBAPKOZX using INCLUDE or APPEND.

4. Add the customer structures to the BAPE_VBAP and BAPE_VBAPX BAPI structures using the APPEND technique.

5. Adjust the following structures for customer enhancements to table VBAK:

a) VBAKKOZ

b) VBAKKOZX

c) BAPE_VBAK

d) BAPE_VBAKX

6. Adjust the following structures for customer enhancements to table VBEK:

a) VBEPKOZ

b) VBEPKOZX

c) BAPE_VBEP

d) BAPE_VBEPX

7. Generally, the data should be added to the BAPI interface in the internal communication structures (VBAKKOM, and so on). There, you can process the data in the SD tables (VBAK, and so on).

8. If the EXTENSIONIN parameter contains customer data, you must complete at least the key fields in the relevant standard parameters.

For example:
You want to change customer field VBAP-CFIELD2 for item 20 to "XYZ" in order 4711.
The following entries are expected:

Import:     BAPIVBELN-VBELN       = '0000004711'  Document number
            BAPISDHD1X-UPDATEFLAG = 'U'           UPDKZ for doc header
Tables:     BAPISDITM-ITM_NUMBER  = '000020'      Item number
            BAPISDITMX-ITM_NUMBER = '000020'      Item number
          + BAPISDITMX-UPDATEFLAG = 'U'           UPDKZ for item

You must complete the EXTENSION table as follows:

STRUCTURE                          VALUEPART1       1234561234567890123

BAPE_VBAP                       0000004711000020                 XYZ
BAPE_VBAPX                      0000004711000020       X

Further information

You can find more information in the BAPI programming guide in the chapter for enhancements to BAPIs.

Notes

You must complete the STRUCTURE field with the name of the relevant enhancement structure (BAPE_VBAK, BAPE_VBAP, BAPE_VBEP). You can complete the remaining fields with the append structures from the enhancement structures.

At the moment, you can use the BAPI to store enhancements in the following structures:

  • VBAK : An enhancement to header data requires an append structure to BAPE_VBAK and an enhancement to structure VBAKKOZ.
  • VBAP : An enhancement to item data requires an append structure to BAPE_VBAP and an enhancment to structure VBAPKOZ.
  • VBEP : An enhancement to schedule line data requires an append structure to BAPE_VBEP and an enhancement to structure VBEPKOZ.
  • VBKD : If you are using an enhancement for header data, you must add an append structure to BAPE_VBAK. You also need to enhance structure VBAKKOZ. If it is for item data, you need to add an append structure to BAPE_VBAP. You must also enhance structure VBAPKOZ.

If you also want to work with checkboxes, each X-structure must also contain an append structure.

For example:

A customer has created an order and wants to include the material long text (50 digits long).

The EXTENSIONIN structure must be completed with BAPE_VBAP. Two fields have fixed definitions in this structure. These are in the VBAP host key (VBELN, POSNR). The customer sets up an append structure that contains field ZMAT50.

Because the VBELN is normally blank when you create an order, the data can look like this:

STRUCTURE   |BAPE_VBAP

VALUEPART1  |          000010Customermateriallongtext50

              VBELN     POSNR ZMAT50

按照函数说明操作如下:VBAPKOZ添加客制化字段

VBAPKOZX添加客制化字段。

BAPE_VBAP添加客制化字段

BAPE_VBAPX添加客制化字段

  DATA:LT_EXTENSIONIN  LIKE TABLE OF  BAPIPAREX,
       LS_EXTENSIONIN LIKE  BAPIPAREX .

  DATA:LS_DATA TYPE  BAPE_VBAP ,
       LS_DATAX TYPE BAPE_VBAPX .

              CLEAR LS_DATA .
            LS_DATA-VBELN =  GS_OUTPUT-VBELN .
            LS_DATA-POSNR GS_OUTPUT-POSNR.
            LS_DATA-ZZABGRU GS_OUTPUT-ABGRU+0(2).

            CLEAR LS_EXTENSIONIN .
            LS_EXTENSIONIN-STRUCTURE 'BAPE_VBAP' .
            LS_EXTENSIONIN+30 LS_DATA .
            APPEND LS_EXTENSIONIN TO LT_EXTENSIONIN .

            CLEAR LS_DATAX .
            LS_DATAX-VBELN =  GS_OUTPUT-VBELN .
            LS_DATAX-POSNR =  GS_OUTPUT-POSNR.
            LS_DATAX-ZZABGRU 'X' .

            CLEAR LS_EXTENSIONIN .
            LS_EXTENSIONIN-STRUCTURE 'BAPE_VBAPX' .
            LS_EXTENSIONIN+30 LS_DATAX .
            APPEND LS_EXTENSIONIN TO LT_EXTENSIONIN .

函数其它参数如下:

Import:     BAPIVBELN-VBELN       = XXXXXXXX'  Document number
            BAPISDHD1X-UPDATEFLAG = 'U'           UPDKZ for doc header
Tables:     BAPISDITM-ITM_NUMBER  = '000020'      Item number
            BAPISDITMX-ITM_NUMBER = '000020'      Item number
          + BAPISDITMX-UPDATEFLAG = 'U'           UPDKZ for item

<think>好的,我现在需要解决用户的问题,关于如何在ABAP中使用VA01事务代码通过参考文档或示例来创建销售订单。首先,我需要回忆ABAP中创建销售订单的常规方法,特别是使用参考的方式。 用户提到VA01事务代码,这是SAP中创建销售订单的标准事务。根据参考创建销售订单通常涉及到复制现有的单据,比如之前的销售订单、询价单或合同等。这可能涉及到使用函数模块或者BAPI来实现。 根据用户提供的引用内容,特别是引用[3],里面提到了第二代增强和第三代增强,比如使用SMOD和CMOD来管理增强。这可能意味着在创建销售订单时,可能需要考虑用户出口或BADI来进增强。但用户的问题主要是如何依据参考创建,而不是增强部分,所以可能需要先关注标准方法。 首先,在ABAP中,使用BAPI可能是标准做法。例如,BAPI_SALESORDER_CREATEFROMDAT2可以用来创建销售订单,并且支持参考文档。该BAPI需要传入参考的结构,比如参考的销售文档编号(如之前的订单、询价单等)、参考的项号等参数。 其次,用户可能需要通过屏幕增强或用户出口来处理一些自定义字段或逻辑。例如,在VA01的屏幕中,可能需要通过用户出口来增强字段,如引用[2]提到的DYNP_VALUES_READ或MODX相关的函数。不过这可能属于增强部分,如果用户只是要创建订单而不涉及增强,可能不需要这部分。 另外,引用[1]提到导出数据到客户子屏幕,这可能与在创建订单时显示某些自定义数据有关,但同样属于增强范畴。 因此,核心步骤应该是使用BAPI来创建销售订单,并指定参考文档。需要确定正确的BAPI及其参数。同时,需要处理返回的消息,确保订单创建成功。 可能的问题包括:如何设置参考文档的结构,如何处理项目数据,如何激活测试模式等。另外,还需要考虑权限和授权对象,比如是否有权限创建销售订单。 接下来,需要验证这些步骤是否正确。比如,检查BAPI的参数,是否需要指定SALESDOCUMENT参数作为参考,或者是否需要在ORDER_HEADER_IN中设置参考相关的字段。可能还需要在ITEM_IN中指定参考的项。 此外,用户可能需要示例代码,因此需要提供一个基本的ABAP程序框架,调用BAPI并设置必要的参数,包括参考文档的编号和类型。 最后,根据用户的要求,生成相关问题,比如如何增强VA01的屏幕,如何处理错误消息,或者如何批量创建订单等。</think>在ABAP中通过VA01事务代码依据参考创建销售订单,可通过标准BAPI实现。以下是分步说明: 1. **核心BAPI选择** 使用$BAPI\_SALESORDER\_CREATEFROMDAT2$,支持根据参考文档(如报价单、合同)创建订单。需传入以下关键参数: ```abap DATA: ls_reference TYPE bapisdh1, lt_return TYPE TABLE OF bapiret2, lv_vbeln_va TYPE bapivbeln-vbeln. ls_reference-ref_doc = '参考单据号'."如报价单号 ls_reference-doctype = '参考单据类型'."如QT报价单 ``` 2. **数据准备** - 订单类型需与参考单据兼容,如参考报价单QT创建订单类型OR - 通过扩展结构$BAPIPAREX$传递自定义字段值 3. **增强处理** 若需修改标准逻辑,可通过第二代用户出口: - 使用事务代码$CMOD$创建增强项目 - 激活出口$SDVX0002$(订单抬头增强)或$SDVX0005$(项目增强) - 在函数模块$USEREXIT\_SAVE\_DOCUMENT$中添加校验逻辑[^3] 4. **示例代码框架** ```abap CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2' EXPORTING salesdocumentin = ls_reference IMPORTING salesdocument = lv_vbeln_va TABLES return = lt_return. IF lv_vbeln_va IS NOT INITIAL. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ENDIF. ``` 5. **关键检查点** - 检查参考单据状态是否有效(如报价单需已批准) - 确保物料主数据在目标订单工厂可用 - 使用$IDOC\_INBOUND\_ASYNCHRONOUS$处理大批量场景[^1]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值