abap 动态创建Subroutine以及report(转载)

创建子程序
DATA:
code type TABLE OF string,
subrtnm(10) type c,
prog type program,
msg(20) type c,
line(10) type c,
word(10) type c,
off(3) type c,
lw_string type string.
" for concatenate

* prepare the ”Dynamic Subroutine sentence”
append 'PROGRAM SUBPOOL.' to code.

subrtnm = 'TEST'.
CONCATENATE 'FORM' subrtnm '.' into lw_string SEPARATED BY space.
"CONCATENATE ’FORM’ ’TEST’ ’.’ into lw_string SEPARATED BY space.
APPEND lw_string to code.

append 'Write:/10 ''This is one transient subroutine''.' to code.

APPEND 'ENDFORM.' to code.

* create subroutine dynamically
GENERATE SUBROUTINE POOL code NAME prog MESSAGE msg LINE line WORD word OFFSET off. ”生成子程序
IF sy-subrc <> 0 .
write:/ 'Error occurs in line:',line,
/ msg,
/'Word:', word,
/ 'Offset:', off.
ENDIF.


创建report
DATA:
code type TABLE OF string,
prgnm(10) type c,
lw_string type string.
" for concatenate

prgnm = 'ZTEST_SUB'.
* form the dynamic-program
CONCATENATE 'PROGRAM' prgnm '.' INTO lw_string SEPARATED BY space.
APPEND lw_string to code.

APPEND 'WRITE:/10 ''Hello, this is the transient program!''.' to code.

INSERT REPORT prgnm from code."从内表code里面生成report

* call the transiet program
SUBMIT (prgnm) AND RETURN."执行程序

* append the transient program
READ REPORT prgnm into code.
APPEND 'WRITE:/10 ''Hello, this is the transient program! 2nd Time append.''.'
to code.
INSERT REPORT prgnm from code.

"GENERATE REPORT prgnm.

* call the transiet program
SUBMIT (prgnm) AND RETURN.

原文地址:http://scnblogs.techweb.com.cn/tcsapbw/archives/368.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值