ABAP report BDC实现创建采购合同
时间: 2024-05-10 22:18:15 浏览: 172
ABAP的BDC与增强部分介绍
下面是一个简单的 ABAP Report BDC 实现创建采购合同的示例:
1. 创建一个自定义的屏幕布局,包含需要输入的采购合同信息。
2. 使用 TCODE SHDB 记录一个标准的采购合同创建过程的 BDC 数据。
3. 通过 ABAP 代码将该 BDC 数据读入内存中,并替换其中需要输入的信息为用户在屏幕上输入的信息。
4. 执行 BDC 事务,创建采购合同。
以下是一个示例 ABAP Report 代码:
```
REPORT z_create_purchase_contract.
DATA: BEGIN OF bdcdata OCCURS 0,
program LIKE sy-repid,
dynpro LIKE sy-dynnr,
dynbegin(1) TYPE c,
fnam LIKE bdcdata-fnam,
fval LIKE bdcdata-fval,
END OF bdcdata.
DATA: v_ebeln TYPE ekko-ebeln,
v_bsart TYPE ekko-bsart,
v_bukrs TYPE ekko-bukrs,
v_lifnr TYPE ekko-lifnr,
v_waers TYPE ekko-waers.
PARAMETERS: p_ebeln TYPE ekko-ebeln,
p_bsart TYPE ekko-bsart,
p_bukrs TYPE ekko-bukrs,
p_lifnr TYPE ekko-lifnr,
p_waers TYPE ekko-waers.
v_ebeln = p_ebeln.
v_bsart = p_bsart.
v_bukrs = p_bukrs.
v_lifnr = p_lifnr.
v_waers = p_waers.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = v_ebeln
IMPORTING
output = v_ebeln.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0100'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_SELECT-EKGRP'.
bdcdata-fval = v_bsart.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0101'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_SELECT-BUKRS'.
bdcdata-fval = v_bukrs.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0102'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_SELECT-LIFNR'.
bdcdata-fval = v_lifnr.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0103'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_SELECT-WAERS'.
bdcdata-fval = v_waers.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0200'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_CREATE-EBELN'.
bdcdata-fval = v_ebeln.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0200'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_CREATE-EKORG'.
bdcdata-fval = '1000'.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0200'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_CREATE-BSART'.
bdcdata-fval = v_bsart.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0200'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_CREATE-BUKRS'.
bdcdata-fval = v_bukrs.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0200'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_CREATE-LIFNR'.
bdcdata-fval = v_lifnr.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0200'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_CREATE-WAERS'.
bdcdata-fval = v_waers.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0200'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_CREATE-ABSAK'.
bdcdata-fval = 'X'.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0200'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_CREATE-BEDAT'.
bdcdata-fval = sy-datum.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0200'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_CREATE-ERNAM'.
bdcdata-fval = sy-uname.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0200'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_CREATE-LOEKZ'.
bdcdata-fval = 'X'.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0210'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_CREATE-EBELN'.
bdcdata-fval = v_ebeln.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0211'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_CREATE-EBELN'.
bdcdata-fval = v_ebeln.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLMEGUI'.
bdcdata-dynpro = '0211'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
bdcdata-fnam = 'MEPO_CREATE-PO_TEXT'.
bdcdata-fval = '采购合同文本'.
APPEND bdcdata.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
program = bdcdata-program
dynpro = bdcdata-dynpro
dynbegin = bdcdata-dynbegin
TABLES
bdcdata = bdcdata.
CALL FUNCTION 'BDC_TRANSACTION'
EXPORTING
update_task = 'S'
EXCEPTIONS
OTHERS = 1.
```
在该示例中,我们使用了 PARAMETERS 语句定义了用户需要输入的采购合同信息,然后将这些信息替换到 BDC 数据中。最后通过调用 BDC_INSERT 和 BDC_TRANSACTION 函数执行 BDC 事务,创建采购合同。
阅读全文