壹佰网|ERP100 - 企业信息化知识门户

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1726|回复: 1

[ABAP] 【ABAP动态编程】ABAP中动态编程 (第二部分)

[复制链接]
发表于 2012/8/14 23:37:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622  。

您需要 登录 才可以下载或查看,没有帐号?注册

x
接上一部分,继续探讨ABAP中的动态编程
有时候,我们的ABAP程序本身就是动态创建的(特别是当我们不想物理地创建ABAP objects时),这时候,学习动态创建Subroutine甚至动态创建ABAP程序,就变得有必要。当然,正如有朋友说的那样,使用这样的动态后,我们无法使用where-used这样的功能,于SAP标准有背。
一. 【动态编程】动态创建Subroutine
测试程序:
*&———————————————————————*
*& Report ZTEST_TRANSIENT_SUBROUTINE
*&
*&———————————————————————*
REPORT ZTEST_TRANSIENT_SUBROUTINE.
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 lineWORD word OFFSET off.
IF sy-subrc <> 0 .
write:/ ‘Error occurs in line:’,line,
/ msg,
/‘Word:’, word,
/ ‘Offset:’, off.
ENDIF.
* call the subroutine dynamically
PERFORM (subrtnm) IN PROGRAM (prog).
结果:
17144169_201010191255381.jpg

二. 【动态编程】动态创建Program in Program
测试程序:
*&———————————————————————*
*& Report ZTEST_TRANSIENT_PROGRAM
*&
*&———————————————————————*
REPORT ZTEST_TRANSIENT_PROGRAM.
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.
* 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.
结果:
第一次:
17144169_201010191257131.jpg

点击回退 后:
17144169_201010191257381.jpg

本帖被以下淘专辑推荐:

发表于 2012/9/25 14:15:32 | 显示全部楼层
学习第二篇
很好  
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|手机版|壹佰网 ERP100 ( 京ICP备19053597号-2 )

Copyright © 2005-2012 北京海之大网络技术有限责任公司 服务器托管由互联互通
手机:13911575376
网站技术点击发送消息给对方83569622   广告&合作 点击发送消息给对方27675401   点击发送消息给对方634043306   咨询及人才点击发送消息给对方138011526

GMT+8, 2025/11/29 12:09 , Processed in 0.018993 second(s), 16 queries , File On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表