此函数是在程序中调用一个事物代码,跳转或者执行事物代码的程序。
参数说明:
Import
TCODE 执行的事物代码
SKIP_SCREEN 跳转事务代码的初始屏幕,只在跳转时用
MODE_VAL BDC时使用,对应 默认A:前台,显示屏幕 E:遇到错误停止并显示 N:后台模式
UPDATE_VAL BDC时使用,对应 默认A:异步 S:同步 L:本地模式,LOCAL UPDATE
Export
SUBRC SY-SUBRC 返回值
Table
USING_TAB DBC DATA TABLE 如果调用BDC事务,BDC DATA的内容通过此表传值
SPAGPA_TAB Parameter 一般做跳转的参数设置 SET PARAMETER ID
MESS_TAB Message Table BDC 返回消息内表
"
REPORT ZABAP4_CALL_TRANSACTION.
"事务界面跳转
CALL FUNCTION ‘ABAP4_CALL_TRANSACTION’
EXPORTING
TCODE = ‘SE11’
EXCEPTIONS
CALL_TRANSACTION_DENIED = 1
TCODE_INVALID = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
ENDIF.
"功能跳转
DATA:GT_RFC_SPAGPA TYPE TABLE OF RFC_SPAGPA,
GW_RFC_SPAGPA LIKE LINE OF GT_RFC_SPAGPA.
GW_RFC_SPAGPA-PARID = ‘AUN’.
GW_RFC_SPAGPA-PARVAL = ‘10000140’.
APPEND GW_RFC_SPAGPA TO GT_RFC_SPAGPA.
CALL FUNCTION ‘ABAP4_CALL_TRANSACTION’
EXPORTING
TCODE = ‘VA03’
SKIP_SCREEN = ‘X’ "SKIP FIRST SCREEN
TABLES
SPAGPA_TAB = GT_RFC_SPAGPA
EXCEPTIONS
CALL_TRANSACTION_DENIED = 1
TCODE_INVALID = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
- Implement suitable error handling here
ENDIF.
"BDC
DATA:BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA:MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
PERFORM BDC_DYNPRO USING ‘SAPMV45A’ ‘0102’.
PERFORM BDC_FIELD USING ‘BDC_CURSOR’
‘VBAK-VBELN’.
PERFORM BDC_FIELD USING ‘BDC_OKCODE’
‘/00’.
PERFORM BDC_FIELD USING ‘VBAK-VBELN’
‘10000141’.
PERFORM BDC_DYNPRO USING ‘SAPMV45A’ ‘4001’.
CALL FUNCTION ‘ABAP4_CALL_TRANSACTION’
EXPORTING
TCODE = ‘VA03’
MODE_VAL = ‘A’
UPDATE_VAL = ‘S’
TABLES
USING_TAB = BDCDATA
MESS_TAB = MESSTAB
EXCEPTIONS
CALL_TRANSACTION_DENIED = 1
TCODE_INVALID = 2.
----------------------------------------------------------------------
-
Start new screen *
----------------------------------------------------------------------
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = ‘X’.
APPEND BDCDATA.
ENDFORM.
----------------------------------------------------------------------
-
Insert field *
----------------------------------------------------------------------
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM.