1.调用程序
*&---------------------------------------------------------------------*
*& Report ZTEST_CALL_PROG
*&
*&---------------------------------------------------------------------*
*& Create by : 冯飞剑
*& Create date : 2010-1-2
*& Descriptions : 测试调用外部程序(调用程序)
*&---------------------------------------------------------------------*
REPORT ZTEST_CALL_PROG.
*----------------------------------------------------------------------*
* define internal tables
* 定义内表
*
*----------------------------------------------------------------------*
DATA : BEGIN OF W_DATA,
FID1 TYPE STRING,
NUM1 TYPE I ,
NUM2 TYPE I ,
END OF W_DATA.
DATA : T_OUT LIKE W_DATA OCCURS 0 WITH HEADER LINE .
*----------------------------------------------------------------------*
* assign value to internal tables
* 给内表赋值
*
*----------------------------------------------------------------------*
DO 10 TIMES .
IF SY-INDEX < 4 .
T_OUT-FID1 = 'A' .
T_OUT-NUM1 = SY-INDEX .
T_OUT-NUM2 = SY-INDEX + 1 .
ELSEIF SY-INDEX < 7 .
T_OUT-FID1 = 'B' .
T_OUT-NUM1 = SY-INDEX + 1 .
T_OUT-NUM2 = SY-INDEX + 2 .
ELSE .
T_OUT-FID1 = 'C' .
T_OUT-NUM1 = SY-INDEX .
T_OUT-NUM2 = SY-INDEX - 1 .
ENDIF .
APPEND T_OUT.
ENDDO .
*-----------------------------------------------------------------------*
* call extenral program
* 调用外部程序
*
*-----------------------------------------------------------------------*
*** 使用ABAP内存进行数据传递
EXPORT T_OUT TO MEMORY ID 'T_OUT' .
*** 以下两种情况是调用程序被结束,被调用程序开始执行
* SUBMIT ZWRITE_DATA.
*** 如果使用这种情况程序之间的数据访问就不能ABAP内存访问了
* LEAVE TO TRANSACTION 'ZGET_DATA'.
*** 以下两种情况是调用程序被打断,当被调用程序执行完毕之后,调用程序继续执行
* 插入一个新的INTERNAL SESSION,被调用程序运行完删除SESSION,继续执行调用程序
SUBMIT Zwrite_data AND RETURN .
*** 调用事物代码(和SUBMIT <PROGRAM> AND RETURN的效果一样)
* CALL TRANSACTION 'ZGET_DATA'.
2、被调用程序
*&---------------------------------------------------------------------*
*& Report ZWRITE_DATA
*&
*&---------------------------------------------------------------------*
*& Create by : 冯飞剑
*& Create date: 2010-1-2
*& Descriptions: 测试调用外部程序(被调用程序)
*&---------------------------------------------------------------------*
REPORT ZWRITE_DATA.
*----------------------------------------------------------------------*
* define internal tables
* 定义内表
*
*----------------------------------------------------------------------*
data : begin of w_data, "这里定义一个跟调用程序一样的内表结构
fid1 type string,
num1 type i ,
num2 type i ,
end of w_data.
data : t_out like w_data occurs 0 with header line .
*----------------------------------------------------------------------*
* get data from sap memory and write out
* 从SAP内存读取数据然后打印输出
*
*----------------------------------------------------------------------*
import t_out from memory id 'T_OUT' .
FREE MEMORY ID 'T_OUT' .
write : sy-uline .
WRITE : '从调用程序取到的数据如下:' .
LOOP AT T_OUT.
write : / ' ' ,t_out-fid1, t_out-num1, t_out-num2.
ENDLOOP .
write : sy-uline .
*** 退出程序
* leave program.
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/F122300349/archive/2010/04/22/5516205.aspx