+++++++++++++++++++++++ 实例RFC ++++++++++++++++++++++++++++++++++++++++++++++
*建立临时表ZTEST1,字段为:
* ZUSERID CHAR 20
* ZPASSWD CHAR 20
*-------------------------------------------------
FUNCTION ZRFC_01.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(ACTION) TYPE /1SAP1/CL_ACH0001 传入参数ACTION,表示CREATE、EDIT、DELETE记录
*" VALUE(WHEREUSERID) TYPE /GC1/DTE_MSG_TXT 传入参数WHEREUSERID,按照USERID来查找关键字
*" EXPORTING
*" VALUE(RETURN) TYPE /AIN/ACT_PUB_PARAMNAME 传出参数RETURN,返回是否成功,空串表示成功,非空串表示未成功
*" VALUE(ERRNUM) TYPE /AIN/ACTIVITY_COUNTER 传出参数ERRNUM,返回错误代码
*" TABLES
*" ZTEMPTABLE STRUCTURE ZTEST1 传入、传出表,以表为参数
*"----------------------------------------------------------------------
TABLES:ZTEST1.
DATA:
WA_ZTEMPTABLE LIKE ZTEMPTABLE,
TRANSACTION_ID LIKE ARFCTID,
V_VAILD(1) TYPE C.
V_VAILD = 'X'.
* OPEN A DATA TRANSACTION
CALL FUNCTION 'TRANSACTION_BEGIN'
IMPORTING
TRANSACTION_ID = TRANSACTION_ID.
CASE ACTION .
*按照关键字ZUSERID查询
WHEN 'QUERY'.
SELECT * FROM ZTEST1 INTO TABLE ZTEMPTABLE where ZUSERID = WHEREUSERID.
IF SY-SUBRC = 0.
ELSE.
V_VAILD = ''.
ERRNUM = SY-SUBRC.
ENDIF.
*选择所有的记录
WHEN 'SELECTALL'.
SELECT * FROM ZTEST1 INTO TABLE ZTEMPTABLE.
IF SY-SUBRC = 0.
ELSE.
V_VAILD = ''.
ERRNUM = SY-SUBRC.
ENDIF.
*插入记录
WHEN 'CREATE'.
LOOP AT ZTEMPTABLE INTO WA_ZTEMPTABLE.
INSERT ZTEST1 FROM WA_ZTEMPTABLE.
IF SY-SUBRC = 0.
ELSE.
V_VAILD = ''.
ERRNUM = SY-SUBRC.
ENDIF.
ENDLOOP.
*修改记录
WHEN 'EDIT'.
LOOP AT ZTEMPTABLE INTO WA_ZTEMPTABLE.
UPDATE ZTEST1 FROM WA_ZTEMPTABLE.
IF SY-SUBRC = 0.
ELSE.
V_VAILD = ''.
ERRNUM = SY-SUBRC.
ENDIF.
ENDLOOP.
*删除记录
WHEN 'DELETE'.
LOOP AT ZTEMPTABLE INTO WA_ZTEMPTABLE.
DELETE ZTEST1 FROM WA_ZTEMPTABLE.
IF SY-SUBRC = 0.
ELSE.
V_VAILD = ''.
ERRNUM = SY-SUBRC.
ENDIF.
ENDLOOP.
WHEN OTHERS.
ENDCASE.
*如果V_VALID为X,则表示成功,否则表示失败,并返回RETURN错误代码
IF V_VAILD = 'X'.
CALL FUNCTION 'TRANSACTION_END'
EXPORTING
TRANSACTION_ID = TRANSACTION_ID.
RETURN = ''.
ELSE.
CALL FUNCTION 'TRANSACTION_ABORT'
EXPORTING
TRANSACTION_ID = TRANSACTION_ID.
RETURN = 'THE CURRENT ACTION IS FAILURE!'.