分类: Web开发
2015-09-02 13:26:11
一、语法格式详解
调用CALL TRANSACTION,调用事务码,如果想从调用的事务中返回,可以使用“LEAVE PROGRAM”语句。
调用格式如下:
CALL TRANSACTION TCODE ,参数如下:
1、...AND SKIP FIRST SCREEN
Skips the first screen in the transaction (provided all the required fields have been assigned values by the SPA/GPA process)。2、...USING ITAB
Calls the Transaction tcod and passes the internal table itab , which contains one or several screens in batch input format.
The return code value is set as follows:
SY-SUBRC = 0 Processing was successful.
SY-SUBRC <> 0 Transaction ended with an error.
3、...MODE mode
The specified processing mode can accept the following values:
'A' Display screen
'E' Display screen only if an error occurs
'N' No display
If the addition MODE is not specified, the processing mode is set to 'A' .
4、...UPDATE upd
The specified update mode upd defines the update type. This can have one of the following values:
'A' Asynchronous update
'S' Synchronous update
If the addition UPDATE is not specified, the processing mode is set to 'A' .
5、...MESSAGES INTO messtab
The specified internal table contains all system messages that occur during CALL TRANSACTION USING ... . The internal table messtab must have the structure BDCMSGCOLL .
二、调用三种方法详解
有三种方法调用事务。分别如下:
1、使用BDC屏幕
先通过事务码 SHDB,记录事务中BDC所对应的程序、屏幕、字段、字段值,如图所示(小图请点击放大):
代码如下:
DATA : bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE,
messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
REFRESH bdcdata.
CLEAR bdcdata.
bdcdata-program = 'SAPLCOIH'.bdcdata-dynpro = '0101'.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-fnam = 'BDC_CURSOR'.bdcdata-fval = 'CAUFVD-AUFNR'.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-fnam = 'BDC_OKCODE'.bdcdata-fval = '/00'.
APPEND bdcdata.
CLEAR bdcdata.
bdcdata-fnam = 'CAUFVD-AUFNR'.bdcdata-fval = '300000001066'.
APPEND bdcdata.
CALL TRANSACTION 'IW32' USING bdcdata MODE 'E' MESSAGES INTO messtab.
2、使用PARAMETERS,个人认为这种方式最简单。代码如下:
SET PARAMETER ID 'ANR' FIELD '300000001066'.
CALL TRANSACTION 'IW32' AND SKIP FIRST SCREEN.
其中ID可以通过F1,“参数ID”找到,如图:
3、使用MEMORY
DATA para TYPE caufvd.
para-aufnr = '300000001066'.
EXPORT para TO MEMORY ID 'IWO'.
CALL TRANSACTION 'IW32' AND SKIP FIRST SCREEN.
由于对于事务中MEMORY ID不能找到,因此不推荐这种方法,如果有朋友知道的话,请您告诉我,万分感谢。