创建子程序
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