Chinaunix首页 | 论坛 | 博客
  • 博客访问: 224861
  • 博文数量: 23
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 311
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-29 20:09
文章分类

全部博文(23)

文章存档

2009年(5)

2008年(18)

我的朋友

分类:

2008-04-15 16:42:06

动态生成ABAP程序.
参考程序:
Tcode ABAPdocu-->
BC - ABAP Programming-->
The ABAP Programming Language-->
Special Techniques-->
Generating Programs Dynamically.
1.仅动态生成程序代码:
   REPORT demo_special_tech_dyn_insert.
DATA: code TYPE TABLE OF rssource-line.
* type of an editor line: rssource-line
APPEND  'REPORT ZDYN1.'
         TO code.
APPEND  'WRITE / ''Hello, I am dynamically created!''.'
         TO code.
INSERT REPORT 'demo_special_tech_ZDYN1' FROM code.
WRITE: text-001, 'demo_special_tech_ZDYN1'.
2.动态更改程序代码
REPORT demo_special_tech_dyn_read_rep .
DATA: code TYPE TABLE OF rssource-line.
* type of an editor line: rssource-line
READ REPORT 'demo_special_tech_ZSTRUC1' INTO code.
APPEND 'SKIP.' TO code.
APPEND 'WRITE / ''And I am a dynamic extension!''.' TO code.
INSERT REPORT 'demo_special_tech_ZDYN2' FROM code.
WRITE: text-001, 'demo_special_tech_ZDYN2'.
3 动态生成 并 调用
REPORT demo_special_tech_dyn_start.
DATA: code TYPE TABLE OF rssource-line.
* type of an editor line: rssource-line
DATA lin TYPE i.
READ REPORT 'demo_special_tech_zdyn1' INTO code.
SUBMIT demo_special_tech_zdyn1 AND RETURN.
DESCRIBE TABLE code LINES lin.
MODIFY code INDEX lin FROM
           'WRITE / ''Dynamic Program Changed!''.'.
INSERT REPORT 'demo_special_tech_zdyn1' FROM code.
SUBMIT demo_special_tech_zdyn1.
4 生成并增加include
REPORT demo_special_tech_include_1.
TYPES code_type TYPE rssource-line.
* type of an editor line: rssource-line
DATA code TYPE TABLE OF code_type.

DATA lin TYPE i.
READ REPORT 'demo_special_tech_ZINCLUD1' INTO code.
DESCRIBE TABLE code LINES lin.
MODIFY code INDEX lin FROM
            'WRITE / ''Changed INCLUDE program!''.'.
INSERT REPORT 'demo_special_tech_ZINCLUD1' FROM code.
INCLUDE demo_special_tech_zinclud1.
5. 调用其他程序的子程序
REPORT demo_special_tech_include_2 .
TYPES code_type(72) TYPE c.
DATA code TYPE TABLE OF code_type.
READ REPORT 'demo_special_tech_ZINCLUD1' INTO code.
APPEND 'WRITE / ''Extension of INCLUDE program!''.' TO code.
INSERT REPORT 'demo_special_tech_ZINCLUD1' FROM code.
PERFORM sub1(demo_special_tech_zform1).
6. 生成动态 临时 子程序 并调用(生成的代码有错 writ 应该是 write).
REPORT demo_special_tech_subroutine_1.
DATA: code TYPE TABLE OF rssource-line,
      prog(8) TYPE c, msg(120) TYPE c, lin(3) TYPE c,
      wrd(10) TYPE c, off(3) TYPE c.
APPEND 'PROGRAM SUBPOOL.'
        TO code.
APPEND 'FORM DYN1.'
        TO code.
APPEND
   'WRITE / ''Hello, I am the temporary subroutine DYN1!''.' "#EC NOTEXT
        TO code.
APPEND 'ENDFORM.'
        TO code.
APPEND 'FORM DYN2.'
        TO code.
APPEND
   'WRIT / ''Hello, I am the temporary subroutine DYN2!''.'  "#EC NOTEXT
        TO code.
APPEND 'ENDFORM.'
        TO code.
GENERATE SUBROUTINE POOL code NAME prog
                         MESSAGE msg
                         LINE    lin
                         WORD    wrd
                         OFFSET  off.
IF sy-subrc <> 0.
  WRITE: / 'Error during generation in line', lin,           "#EC NOTEXT
         / msg,
         / 'Word:', wrd, 'at offset', off.                   "#EC NOTEXT
ELSE.
  WRITE: / 'The name of the subroutine pool is', prog.       "#EC NOTEXT
  SKIP 2.
  PERFORM dyn1 IN PROGRAM (prog).
  SKIP 2.
  PERFORM dyn2 IN PROGRAM (prog).
ENDIF.
----------------------------------------
核心代码 :
GENERATE SUBROUTINE POOL code NAME prog
                         MESSAGE msg
                         LINE    lin
                         WORD    wrd
                         OFFSET  off.
生成 子程序池,检查代码错误.
_____________________________
7. 生成动态 临时 子程序 并调用(生成的代码正确).
REPORT demo_special_tech_subroutine_2.
DATA: code TYPE TABLE OF rssource-line,
      prog(8) TYPE c, msg(120) TYPE c, lin(3) TYPE c,
      wrd(10) TYPE c, off(3) TYPE c.
APPEND 'PROGRAM SUBPOOL.'
        TO code.
APPEND 'FORM DYN1.'
        TO code.
APPEND
   'WRITE / ''Hello, I am the temporary subroutine DYN1!''.' "#EC NOTEXT
        TO code.
APPEND 'ENDFORM.'
        TO code.
APPEND 'FORM DYN2.'
        TO code.
APPEND
   'WRITE / ''Hello, I am the temporary subroutine DYN2!''.' "#EC NOTEXT
        TO code.
APPEND 'ENDFORM.'
        TO code.
GENERATE SUBROUTINE POOL code NAME prog
                         MESSAGE msg
                         LINE    lin
                         WORD    wrd
                         OFFSET  off.
IF sy-subrc <> 0.
  WRITE: / 'Error during generation in line', lin,           "#EC NOTEXT
         / msg,
         / 'Word:', wrd, 'at offset', off.                   "#EC NOTEXT
ELSE.
  WRITE: / 'The name of the subroutine pool is', prog.       "#EC NOTEXT
  SKIP 2.
  PERFORM dyn1 IN PROGRAM (prog).
  SKIP 2.
  PERFORM dyn2 IN PROGRAM (prog).
ENDIF.(完)
 
阅读(3514) | 评论(1) | 转发(0) |
0

上一篇:ICWC为何物

下一篇:逻辑路径常用函数

给主人留下些什么吧!~~

chinaunix网友2010-01-24 22:38:50

我想问您一个问题,我对这篇文章非常感兴趣,我现在也想做一个通用的ABAP接口,接口的参数比如是一个字符串,使用SAP JCO API传过来的(就是JAVA调用ABAP的开发包)。这个字符串实际上就是一堆ABAP的代码,我想使用ABAP翻译这个字符串并且执行,你说这个可以达到嘛?总的一句话:我在JAVA端编写ABAP代码,发送代码到ABAP再由ABAP执行。可以办到嘛?我的邮箱是:neuswc20063500@gmail.com,请务必回复,谢谢了!万分万分感谢啊