ABAP-Generate subroutine
1.定义
- data:zprog like abapsource occurs with header line,
- prog() type c,
- msg() type c.
2.动态语句
- zprog-line = 'PROGRAM ZRICOO.'. append zprog.
- zprog-line = 'START-OF-SELECTION.'. append zprog.
- zprog-line = 'FORM RICOO.'. append zprog.
- zprog-line = 'UPDATE ZSDT0001 SET… WHERE … .'. append zprog.
- zprog-line = 'ENDFORM.'. append zprog.
- generate subroutine pool zprog
- name prog
- message msg.
3.全部代码
- *&---------------------------------------------------------------------*
- *& Report ZSDA073_DO_RICO
- *&
- *&---------------------------------------------------------------------*
- *&
- *&
- *&---------------------------------------------------------------------*
- REPORT ZSDA073_DO_RICO.
- data container1 type ref to cl_gui_custom_container.
- data editor1 type ref to cl_gui_textedit.
- data container2 type ref to cl_gui_custom_container.
- data editor2 type ref to cl_gui_textedit.
- data container3 type ref to cl_gui_custom_container.
- data editor3 type ref to cl_gui_textedit.
- data: gt_fieldcat like lvc_s_fcat occurs with header line,
- gs_layout type lvc_s_layo.
- data: cuscontainer type ref to cl_gui_custom_container,
- alv_grid type ref to cl_gui_alv_grid,
- ls_vari type disvariant.
- data:lt_excl_func type ui_functions.
- types:begin of t_texttable,
- line() type c,
- end of t_texttable.
- data i_texttable type table of t_texttable.
- data: zprog like abapsource occurs with header line.
- data: zinclude like abapsource occurs with header line.
- data:data() type c occurs ,
- sql() type c occurs ,
- dline() type c,
- sline() type c,
- confirm type c,
- prog() type c,
- msg() type c,
- sqlinclude() type c,
- zmsg() type c,
- zt1 type string,
- zt2 type string,
- exflg type c,
- zcom type string,
- znam type string.
- data:lin type i,
- flg type c,
- zln type char10,
- zcode type string,
- zn type string,
- zsn type string,
- z type string.
- start-of-selection.
- z = ''''.
- z = z+().
- call screen .
- module status_0100 output.
- set pf-status ''.
- if container1 is initial.
- create object container1
- exporting
- container_name = 'DATACON'.
- create object editor1
- exporting
- parent = container1
- wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
- wordwrap_position =
- wordwrap_to_linebreak_mode = cl_gui_textedit=>true.
- call method editor1->set_readonly_mode
- exporting
- readonly_mode = cl_gui_textedit=>false.
- call method editor1->set_toolbar_mode
- exporting
- toolbar_mode = cl_gui_textedit=>false
- exceptions
- others = .
- call method editor1->set_statusbar_mode
- exporting
- statusbar_mode = cl_gui_textedit=>false
- exceptions
- others = .
- endif.
- clear:i_texttable.
- append 'DATA:BEGIN OF TAB OCCURS 0,' to i_texttable.
- append 'MANDT LIKE MARA-MANDT,' to i_texttable.
- append 'MATNR LIKE MARA-MATNR,' to i_texttable.
- append 'MAKTX LIKE MAKT-MAKTX,' to i_texttable.
- append 'END OF TAB.' to i_texttable.
- append 'DATA:MANDT LIKE SY-MANDT.' to i_texttable.
- append 'MANDT = SY-MANDT.' to i_texttable.
- call method editor1->set_text_as_r3table
- exporting
- table = i_texttable.
- if container2 is initial.
- create object container2
- exporting
- container_name = 'SQLCON'.
- create object editor2
- exporting
- parent = container2
- wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
- wordwrap_position =
- wordwrap_to_linebreak_mode = cl_gui_textedit=>true.
- call method editor2->set_readonly_mode
- exporting
- readonly_mode = cl_gui_textedit=>false.
- call method editor2->set_toolbar_mode
- exporting
- toolbar_mode = cl_gui_textedit=>false
- exceptions
- others = .
- call method editor2->set_statusbar_mode
- exporting
- statusbar_mode = cl_gui_textedit=>false
- exceptions
- others = .
- endif.
- clear:i_texttable.
- append 'SELECT A.MANDT,A.MATNR,B.MAKTX INTO :TAB FROM MARA A INNER ' to i_texttable.
- append 'JOIN MAKT B ON A.MATNR = B.MATNR ' to i_texttable.
- append 'WHERE A.MATNR like ''%33%'' AND A.MANDT = :MANDT ' to i_texttable.
- call method editor2->set_text_as_r3table
- exporting
- table = i_texttable.
- if container3 is initial.
- create object container3
- exporting
- container_name = 'SMCON'.
- create object editor3
- exporting
- parent = container3
- wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
- wordwrap_position =
- wordwrap_to_linebreak_mode = cl_gui_textedit=>true.
- call method editor3->set_readonly_mode
- exporting
- readonly_mode = cl_gui_textedit=>true.
- call method editor3->set_toolbar_mode
- exporting
- toolbar_mode = cl_gui_textedit=>false
- exceptions
- others = .
- call method editor3->set_statusbar_mode
- exporting
- statusbar_mode = cl_gui_textedit=>false
- exceptions
- others = .
- endif.
- clear:i_texttable.
- append '注意:' to i_texttable.
- append '1.先定义输出内表,然后定义变量' to i_texttable.
- append '2.内表名:TAB' to i_texttable.
- append '3.SQL语句变量前需加 '':''.' to i_texttable.
- append '4.自定义数据表中需有''MANDT''字段,否则会操作多个''CLIENT''.' to i_texttable.
- append ' ' to i_texttable.
- append '如左边实例:' to i_texttable.
- append ' ' to i_texttable.
- append ' ' to i_texttable.
- append '修改如下:' to i_texttable.
- append 'UPDATE MAKT SET MAKTX = ''RICOO'' WHERE MATNR LIKE ''%RICO%'' AND MANDT = :MANDT ' to i_texttable.
- call method editor3->set_text_as_r3table
- exporting
- table = i_texttable.
- endmodule.
- module user_command_0100 input.
- case sy-ucomm.
- when '&EXEC'.
- clear:data,sql,dline,sline,confirm,zt1,zt2,exflg,zprog,zinclude.
- refresh:data,sql,zprog,zinclude.
- call method editor1->get_text_as_r3table
- importing
- table = data.
- call method editor2->get_text_as_r3table
- importing
- table = sql.
- call function 'POPUP_TO_CONFIRM_STEP'
- exporting
- textline1 = 'DO YOU WANT TO REALLY EXEC?'
- titel = 'EXIT'
- importing
- answer = confirm.
- case confirm.
- when 'N'.
- exit.
- when 'A'.
- exit.
- when 'J'.
- endcase.
- loop at sql into sline.
- if sline <> ''.
- translate sline to upper case.
- split sline at space into zt1 zt2.
- if zt1 = 'SELECT'.
- perform include_sql.
- perform s_data.
- else.
- select single count(*) from zsdt021 where uname = sy-uname and unmtx = 'X'.
- if sy-subrc = .
- perform u_data.
- else.
- message e001() with '您无权限执行此操作!!!'.
- endif.
- endif.
- exit.
- endif.
- clear:sline.
- endloop.
- when '&EXIT'.
- leave to screen .
- endcase.
- endmodule.
- form s_data.
- clear:lin,zt1,zt2,zn,zln.
- ZPROG-LINE = 'PROGRAM ZSQL_EXEC_RICOO.'. APPEND ZPROG.
- ZPROG-LINE = 'DATA:ZN TYPE STRING,'. APPEND ZPROG.
- ZPROG-LINE = 'LIN TYPE I,'. APPEND ZPROG.
- ZPROG-LINE = 'ZJS TYPE I.'. APPEND ZPROG.
- ZPROG-LINE = 'START-OF-SELECTION.'. APPEND ZPROG.
- loop at data into dline.
- translate dline to upper case.
- search dline for 'BEGIN OF'.
- if sy-subrc = .
- split dline at 'OF' into zt1 zt2.
- shift zt2 left deleting leading space.
- split zt2 at space into zt1 zt2.
- endif.
- zprog-line = dline.
- append zprog.
- clear:dline.
- endloop.
- ZPROG-LINE = 'FORM RICOO.'. APPEND ZPROG.
- clear:flg.
- loop at data into dline.
- translate dline to upper case.
- if flg = 'X'.
- zprog-line = dline.
- append zprog.
- endif.
- search dline for 'END OF'.
- if sy-subrc = .
- flg = 'X'.
- endif.
- clear:dline.
- endloop.
- * ZPROG-LINE = 'MANDT = SY-MANDT.'. APPEND ZPROG.
- zprog-line = 'EXEC SQL PERFORMING APP_TAB.'. append zprog.
- loop at sql into sline.
- translate sline to upper case.
- zprog-line = sline.
- append zprog.
- clear:sline.
- endloop.
- * zprog-line = ' AND MANDT = :MANDT'. append zprog.
- zprog-line = 'ENDEXEC.'. append zprog.
- CLEAR:ZSN.
- * CONCATENATE 'APPEND ' ZT1 '.' INTO ZSN SEPARATED BY SPACE.
- * zprog-line = ZSN. append zprog.
- clear:ZSN.
- concatenate 'EXPORT ' ZT1 ' TO MEMORY ID ''RICOO''.' INTO ZSN SEPARATED BY SPACE.
- zprog-line = ZSN. append zprog.
- zprog-line = 'DESCRIBE TABLE TAB LINES LIN.'. append zprog.
- zprog-line = 'EXPORT LIN TO MEMORY ID ''RICOOLIN''.'. append zprog.
- zprog-line = 'SUBMIT ZMMT2099_EXEC_RICOO_CALL AND RETURN.'. APPEND ZPROG.
- * zprog-line = 'MESSAGE S001(00) WITH ''Exec success ! ^_^ ''.'. append zprog.
- zprog-line = 'ENDFORM.'. append zprog.
- zprog-line = 'FORM APP_TAB.'. append zprog.
- CLEAR:ZSN.
- CONCATENATE 'APPEND ' ZT1 '.' INTO ZSN SEPARATED BY SPACE.
- zprog-line = ZSN. append zprog.
- zprog-line = 'ENDFORM.'. append zprog.
- CLEAR:ZCODE.
- generate subroutine pool zprog
- name prog
- message msg.
- if sy-subrc <> .
- message e001() with msg.
- else.
- perform ricoo in program (prog).
- endif.
- endform.
- form u_data.
- zprog-line = 'PROGRAM ZRICOO.'. append zprog.
- * zprog-line = 'DATA:MANDT LIKE SY-MANDT.'. append zprog.
- zprog-line = 'START-OF-SELECTION.'. append zprog.
- loop at data into dline.
- translate dline to upper case.
- zprog-line = dline.
- append zprog.
- clear:dline.
- endloop.
- zprog-line = 'FORM RICOO.'. append zprog.
- clear:flg.
- loop at data into dline.
- translate dline to upper case.
- if flg = 'X'.
- zprog-line = dline.
- append zprog.
- endif.
- search dline for 'END OF'.
- if sy-subrc = .
- flg = 'X'.
- endif.
- clear:dline.
- endloop.
- * zprog-line = 'EXEC SQL.'. append zprog.
- loop at sql into sline.
- translate sline to upper case.
- zprog-line = sline.
- append zprog.
- clear:sline.
- endloop.
- * zprog-line = 'ENDEXEC.'. append zprog.
- zprog-line = 'MESSAGE S001(00) WITH ''Exec success ! ^_^ ''.'. append zprog.
- zprog-line = 'ENDFORM.'. append zprog.
- generate subroutine pool zprog
- name prog
- message msg.
- if sy-subrc <> .
- message e001() with msg.
- else.
- perform ricoo in program (prog).
- endif.
- endform.
- form include_sql.
- clear:zinclude.
- clear:lin,zt1,zt2,zn,zln.
- refresh:zinclude.
- zinclude-LINE = 'PROGRAM ZSQL_RICOO_INCLUED.'. APPEND zinclude.
- zinclude-LINE = 'DATA:ZN TYPE STRING,'. APPEND zinclude.
- zinclude-LINE = 'ZJS TYPE I.'. APPEND zinclude.
- zinclude-LINE = 'TYPES CODE_TYPE TYPE RSSOURCE-LINE.'. APPEND zinclude.
- zinclude-LINE = 'DATA CODE LIKE TABLE OF RSSOURCE WITH HEADER LINE.'. APPEND zinclude.
- zinclude-LINE = 'DATA:ZLIN TYPE I,'. APPEND zinclude.
- zinclude-LINE = 'ZT TYPE I.'. APPEND zinclude.
- zinclude-LINE = 'FORM ZRICOO_SQL_INCLUDE.'. APPEND zinclude.
- zinclude-LINE = 'READ REPORT ''ZSQL_INCLUDE'' INTO CODE.'. APPEND zinclude.
- zinclude-LINE = 'DESCRIBE TABLE CODE LINES ZLIN.'. APPEND zinclude.
- zinclude-LINE = 'DO ZLIN TIMES.'. APPEND zinclude.
- zinclude-LINE = 'ZT = ZT + 1.'. APPEND zinclude.
- zinclude-LINE = 'MODIFY CODE INDEX ZT FROM ''''.'. APPEND zinclude.
- zinclude-LINE = 'ENDDO.'. APPEND zinclude.
- zinclude-LINE = 'INSERT REPORT ''ZSQL_INCLUDE'' FROM CODE.'. APPEND zinclude.
- loop at data into dline.
- zn = zn + .
- concatenate z dline z into dline.
- concatenate 'ZJS = ' ZN '.' INTO ZSN SEPARATED BY SPACE.
- zinclude-LINE = ZSN. APPEND zinclude.
- zinclude-line = 'IF ZJS > ZLIN.'. APPEND zinclude.
- CONCATENATE 'CODE-LINE = ' DLINE '.' INTO ZSN SEPARATED BY SPACE.
- zinclude-LINE = ZSN. APPEND zinclude.
- zinclude-LINE = 'APPEND CODE.'. APPEND zinclude.
- zinclude-LINE = 'ELSE.'. APPEND zinclude.
- concatenate 'MODIFY CODE INDEX ZJS FROM ' DLINE '.' INTO ZCODE SEPARATED BY SPACE.
- zinclude-line = zcode. append zinclude. clear:zcode.
- zinclude-LINE = 'ENDIF.'.APPEND zinclude.
- search dline for 'END OF'.
- if sy-subrc = .
- exit.
- endif.
- clear:dline,zcode.
- endloop.
- CLEAR:ZSN.
- zinclude-LINE = 'ZJS = ZJS + 1.'. APPEND zinclude.
- ZSN = '''RICOO'''.
- CONCATENATE Z ZSN Z '.' INTO ZSN .
- CONCATENATE 'IMPORT TAB FROM MEMORY ID ' ZSN INTO ZSN SEPARATED BY SPACE.
- zinclude-line = 'IF ZJS > ZLIN.'. APPEND zinclude.
- CONCATENATE Z ZSN Z INTO ZSN SEPARATED BY SPACE.
- zinclude-line = 'CODE-LINE = '. APPEND ZINCLUDE.
- CONCATENATE ' ' ZSN '.' INTO ZSN SEPARATED BY SPACE.
- zinclude-LINE = ZSN. APPEND zinclude.
- zinclude-LINE = 'APPEND CODE.'. APPEND zinclude.
- zinclude-LINE = 'ELSE.'. APPEND zinclude.
- concatenate 'MODIFY CODE INDEX ZJS FROM ' ZSN INTO ZCODE SEPARATED BY SPACE.
- zinclude-line = zcode. append zinclude. clear:zcode.
- zinclude-LINE = 'ENDIF.'.APPEND zinclude.
- zinclude-LINE = 'INSERT REPORT ''ZSQL_INCLUDE'' FROM CODE.'. APPEND zinclude.
- zinclude-LINE = 'INCLUDE ZSQL_INCLUDE.'. APPEND zinclude.
- zinclude-LINE = 'COMMIT WORK.'. APPEND zinclude.
- zinclude-LINE = 'ENDFORM.'. APPEND zinclude.
- clear:zsn,zn,zcode,dline.
- generate subroutine pool zinclude
- name sqlinclude
- message zmsg.
- if sy-subrc <> .
- message e001() with zmsg.
- else.
- perform ZRICOO_SQL_INCLUDE in program (sqlinclude).
- endif.
- endform.
ABAP-Generate subroutine的更多相关文章
- 动态生成ABAP程序-资料
参考程序: Tcode ABAPdocu--> BC - ABAP Programming--> The ABAP Programming Language--> Special T ...
- ABAP动态生成经典应用之Dynamic SQL Excute 程序
[转自http://blog.csdn.net/mysingle/article/details/678598]开发说明:在SAP的系统维护过程中,有时我们需要修改一些Table中的数据,可是很多Ta ...
- PA教材提纲 TAW12-1
Unit1 Introduction to Object-Oriented Programming(面向对象编程介绍) 1.1 Explaining the Object-Oriented Progr ...
- ABAP-动态编程
转载:http://www.cnblogs.com/jiangzhengjun/p/4293407.html 动态编程 动态的基本语法 多种不同的动态编程 动态字段 动态类型 指定结构.内表组件字段的 ...
- ABAP-动态创建DATABASE/FUNCTION(风险)
警告:此程序仅供研究,请谨慎操作,切勿对系统标准数据表及功能函数进行测试(可能无法修复). 程序:EWUCINS REPORT EWUCINS MESSAGE-ID US NO STANDARD PA ...
- [SAP ABAP开发技术总结]Form(subroutine)、Function参数传值传址
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- Automatically generate serial number in abap
流水号的产生: 在ABAP开发中,很多地方都需要按照自己的规则生成流水号,把这些流水号保存进透明表,作为唯一标示. 一. 系统中设定流水号 使用T-Code SNRO来创建一个流水号标识对象. 输 ...
- ABAP基础4:模块化
子程序定义 以form开始,以endform结束,用perform语句调用,from语句可以在程序内部/外部,perform一定要写在前面 perform. from. 子程序模块 endform. ...
- ABAP关键字和ABAP词汇
下表为ABAP的词汇概览(包括关键字): ABAP-SOURCE ABBREVIATED ABS ABSTRACT ACCEPT ACCEPTING ACCORDING ACOS ACTIVATION ...
随机推荐
- 按的第一个greasemonkey插件:评论时可以粘贴啦~~
原来的样子:如果按ctrl+V会跳出错误
- Servlet 简介
1. 如下图 2. 每一个Servlent都必须实现Servlent接口. GenericServlet是个通用的.不特定于任何协议的Servlet, 它实现了Servlet接口,而Httpservl ...
- Angular 4 表单
一. 模板表单 1. 如下图 2. code 3. 效果图 二.响应式表单 1. 增加ReactiveFormsModule 2.响应式表单用到的类和指令 3. 控制器代码 4. html <! ...
- [转]Nginx负载均衡原理初解
什么是负载均衡 我们知道单台服务器的性能是有上限的,当流量很大时,就需要使用多台服务器来共同提供服务,这就是所谓的集群. 负载均衡服务器,就是用来把经过它的流量,按照某种方法,分配到集群中的各台服务器 ...
- [转]StarWind模拟iSCSI设备
StarWind模拟iSCSI设备 url: http://jimshu.blog.51cto.com/3171847/590412/ 标签:职场 iSCSI 休闲 StarWind 原创作品,允许 ...
- asp.net如何使用cookie(创建、保存、读取)
Cookie的用法也和ASP中差不多.比如我们建立一个名为aspcn,值为大众的cookie HttpCookie cookie = new HttpCookie("aspcn") ...
- sql 判断 数据库 表 字段 是否存在
select * From master.dbo.sysdatabases where name='数据库名'select * from sysobjects where id = object_id ...
- HttpClient连接池
HttpClient连接池,发现对于高并发的请求,效率提升很大.虽然知道是因为建立了长连接,导致请求效率提升,但是对于内部的原理还是不太清楚.后来在网上看到了HTTP协议的发展史,里面提到了一个属性C ...
- Android启动过程中背景图片显示
转自:http://blog.csdn.net/zhangzhikaixinya/article/details/17001321 大部分Android App启动过程中,都会设置一个背景图片,直到A ...
- CSS Grid布局入门
相信大家都比较熟悉flex布局了,最近有空研究了波grid布局,感觉虽然兼容性还不是太高,应用不是太普遍,但是功能非常强大.未来应该是grid+flex为主流,grid是二维布局,很灵活,适合整体构架 ...