1.定义

  1. data:zprog like abapsource occurs with header line,
  2.  
  3. prog() type c,
  4.  
  5. msg() type c.

2.动态语句

  1. zprog-line = 'PROGRAM ZRICOO.'. append zprog.
  2.  
  3. zprog-line = 'START-OF-SELECTION.'. append zprog.
  4.  
  5. zprog-line = 'FORM RICOO.'. append zprog.
  6.  
  7. zprog-line = 'UPDATE ZSDT0001 SET… WHERE … .'. append zprog.
  8.  
  9. zprog-line = 'ENDFORM.'. append zprog.
  10.  
  11. generate subroutine pool zprog
  12.  
  13. name prog
  14.  
  15. message msg.

3.全部代码

  1. *&---------------------------------------------------------------------*
  2. *& Report ZSDA073_DO_RICO
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *&
  7. *&---------------------------------------------------------------------*
  8.  
  9. REPORT ZSDA073_DO_RICO.
  10.  
  11. data container1 type ref to cl_gui_custom_container.
  12. data editor1 type ref to cl_gui_textedit.
  13. data container2 type ref to cl_gui_custom_container.
  14. data editor2 type ref to cl_gui_textedit.
  15. data container3 type ref to cl_gui_custom_container.
  16. data editor3 type ref to cl_gui_textedit.
  17.  
  18. data: gt_fieldcat like lvc_s_fcat occurs with header line,
  19. gs_layout type lvc_s_layo.
  20. data: cuscontainer type ref to cl_gui_custom_container,
  21. alv_grid type ref to cl_gui_alv_grid,
  22. ls_vari type disvariant.
  23. data:lt_excl_func type ui_functions.
  24.  
  25. types:begin of t_texttable,
  26. line() type c,
  27. end of t_texttable.
  28. data i_texttable type table of t_texttable.
  29.  
  30. data: zprog like abapsource occurs with header line.
  31. data: zinclude like abapsource occurs with header line.
  32.  
  33. data:data() type c occurs ,
  34. sql() type c occurs ,
  35. dline() type c,
  36. sline() type c,
  37. confirm type c,
  38. prog() type c,
  39. msg() type c,
  40. sqlinclude() type c,
  41. zmsg() type c,
  42. zt1 type string,
  43. zt2 type string,
  44. exflg type c,
  45. zcom type string,
  46. znam type string.
  47. data:lin type i,
  48. flg type c,
  49. zln type char10,
  50. zcode type string,
  51. zn type string,
  52. zsn type string,
  53. z type string.
  54.  
  55. start-of-selection.
  56. z = ''''.
  57. z = z+().
  58.  
  59. call screen .
  60.  
  61. module status_0100 output.
  62. set pf-status ''.
  63.  
  64. if container1 is initial.
  65. create object container1
  66. exporting
  67. container_name = 'DATACON'.
  68. create object editor1
  69. exporting
  70. parent = container1
  71. wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
  72. wordwrap_position =
  73. wordwrap_to_linebreak_mode = cl_gui_textedit=>true.
  74.  
  75. call method editor1->set_readonly_mode
  76. exporting
  77. readonly_mode = cl_gui_textedit=>false.
  78.  
  79. call method editor1->set_toolbar_mode
  80. exporting
  81. toolbar_mode = cl_gui_textedit=>false
  82. exceptions
  83. others = .
  84.  
  85. call method editor1->set_statusbar_mode
  86. exporting
  87. statusbar_mode = cl_gui_textedit=>false
  88. exceptions
  89. others = .
  90. endif.
  91.  
  92. clear:i_texttable.
  93.  
  94. append 'DATA:BEGIN OF TAB OCCURS 0,' to i_texttable.
  95. append 'MANDT LIKE MARA-MANDT,' to i_texttable.
  96. append 'MATNR LIKE MARA-MATNR,' to i_texttable.
  97. append 'MAKTX LIKE MAKT-MAKTX,' to i_texttable.
  98. append 'END OF TAB.' to i_texttable.
  99. append 'DATA:MANDT LIKE SY-MANDT.' to i_texttable.
  100. append 'MANDT = SY-MANDT.' to i_texttable.
  101.  
  102. call method editor1->set_text_as_r3table
  103. exporting
  104. table = i_texttable.
  105.  
  106. if container2 is initial.
  107. create object container2
  108. exporting
  109. container_name = 'SQLCON'.
  110. create object editor2
  111. exporting
  112. parent = container2
  113. wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
  114. wordwrap_position =
  115. wordwrap_to_linebreak_mode = cl_gui_textedit=>true.
  116.  
  117. call method editor2->set_readonly_mode
  118. exporting
  119. readonly_mode = cl_gui_textedit=>false.
  120.  
  121. call method editor2->set_toolbar_mode
  122. exporting
  123. toolbar_mode = cl_gui_textedit=>false
  124. exceptions
  125. others = .
  126.  
  127. call method editor2->set_statusbar_mode
  128. exporting
  129. statusbar_mode = cl_gui_textedit=>false
  130. exceptions
  131. others = .
  132. endif.
  133.  
  134. clear:i_texttable.
  135. append 'SELECT A.MANDT,A.MATNR,B.MAKTX INTO :TAB FROM MARA A INNER ' to i_texttable.
  136. append 'JOIN MAKT B ON A.MATNR = B.MATNR ' to i_texttable.
  137. append 'WHERE A.MATNR like ''%33%'' AND A.MANDT = :MANDT ' to i_texttable.
  138.  
  139. call method editor2->set_text_as_r3table
  140. exporting
  141. table = i_texttable.
  142.  
  143. if container3 is initial.
  144. create object container3
  145. exporting
  146. container_name = 'SMCON'.
  147. create object editor3
  148. exporting
  149. parent = container3
  150. wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
  151. wordwrap_position =
  152. wordwrap_to_linebreak_mode = cl_gui_textedit=>true.
  153.  
  154. call method editor3->set_readonly_mode
  155. exporting
  156. readonly_mode = cl_gui_textedit=>true.
  157.  
  158. call method editor3->set_toolbar_mode
  159. exporting
  160. toolbar_mode = cl_gui_textedit=>false
  161. exceptions
  162. others = .
  163.  
  164. call method editor3->set_statusbar_mode
  165. exporting
  166. statusbar_mode = cl_gui_textedit=>false
  167. exceptions
  168. others = .
  169. endif.
  170.  
  171. clear:i_texttable.
  172. append '注意:' to i_texttable.
  173. append '1.先定义输出内表,然后定义变量' to i_texttable.
  174. append '2.内表名:TAB' to i_texttable.
  175. append '3.SQL语句变量前需加 '':''.' to i_texttable.
  176. append '4.自定义数据表中需有''MANDT''字段,否则会操作多个''CLIENT''.' to i_texttable.
  177. append ' ' to i_texttable.
  178. append '如左边实例:' to i_texttable.
  179. append ' ' to i_texttable.
  180. append ' ' to i_texttable.
  181. append '修改如下:' to i_texttable.
  182. append 'UPDATE MAKT SET MAKTX = ''RICOO'' WHERE MATNR LIKE ''%RICO%'' AND MANDT = :MANDT ' to i_texttable.
  183. call method editor3->set_text_as_r3table
  184. exporting
  185. table = i_texttable.
  186.  
  187. endmodule.
  188.  
  189. module user_command_0100 input.
  190. case sy-ucomm.
  191. when '&EXEC'.
  192. clear:data,sql,dline,sline,confirm,zt1,zt2,exflg,zprog,zinclude.
  193. refresh:data,sql,zprog,zinclude.
  194.  
  195. call method editor1->get_text_as_r3table
  196. importing
  197. table = data.
  198.  
  199. call method editor2->get_text_as_r3table
  200. importing
  201. table = sql.
  202.  
  203. call function 'POPUP_TO_CONFIRM_STEP'
  204. exporting
  205. textline1 = 'DO YOU WANT TO REALLY EXEC?'
  206. titel = 'EXIT'
  207. importing
  208. answer = confirm.
  209. case confirm.
  210. when 'N'.
  211. exit.
  212. when 'A'.
  213. exit.
  214. when 'J'.
  215. endcase.
  216.  
  217. loop at sql into sline.
  218. if sline <> ''.
  219. translate sline to upper case.
  220. split sline at space into zt1 zt2.
  221. if zt1 = 'SELECT'.
  222. perform include_sql.
  223. perform s_data.
  224. else.
  225. select single count(*) from zsdt021 where uname = sy-uname and unmtx = 'X'.
  226. if sy-subrc = .
  227. perform u_data.
  228. else.
  229. message e001() with '您无权限执行此操作!!!'.
  230. endif.
  231. endif.
  232. exit.
  233. endif.
  234. clear:sline.
  235. endloop.
  236. when '&EXIT'.
  237. leave to screen .
  238. endcase.
  239. endmodule.
  240.  
  241. form s_data.
  242.  
  243. clear:lin,zt1,zt2,zn,zln.
  244.  
  245. ZPROG-LINE = 'PROGRAM ZSQL_EXEC_RICOO.'. APPEND ZPROG.
  246. ZPROG-LINE = 'DATA:ZN TYPE STRING,'. APPEND ZPROG.
  247. ZPROG-LINE = 'LIN TYPE I,'. APPEND ZPROG.
  248. ZPROG-LINE = 'ZJS TYPE I.'. APPEND ZPROG.
  249. ZPROG-LINE = 'START-OF-SELECTION.'. APPEND ZPROG.
  250.  
  251. loop at data into dline.
  252. translate dline to upper case.
  253. search dline for 'BEGIN OF'.
  254. if sy-subrc = .
  255. split dline at 'OF' into zt1 zt2.
  256. shift zt2 left deleting leading space.
  257. split zt2 at space into zt1 zt2.
  258. endif.
  259. zprog-line = dline.
  260. append zprog.
  261. clear:dline.
  262. endloop.
  263.  
  264. ZPROG-LINE = 'FORM RICOO.'. APPEND ZPROG.
  265.  
  266. clear:flg.
  267. loop at data into dline.
  268. translate dline to upper case.
  269. if flg = 'X'.
  270. zprog-line = dline.
  271. append zprog.
  272. endif.
  273. search dline for 'END OF'.
  274. if sy-subrc = .
  275. flg = 'X'.
  276. endif.
  277. clear:dline.
  278. endloop.
  279.  
  280. * ZPROG-LINE = 'MANDT = SY-MANDT.'. APPEND ZPROG.
  281. zprog-line = 'EXEC SQL PERFORMING APP_TAB.'. append zprog.
  282. loop at sql into sline.
  283. translate sline to upper case.
  284. zprog-line = sline.
  285. append zprog.
  286. clear:sline.
  287. endloop.
  288. * zprog-line = ' AND MANDT = :MANDT'. append zprog.
  289. zprog-line = 'ENDEXEC.'. append zprog.
  290. CLEAR:ZSN.
  291. * CONCATENATE 'APPEND ' ZT1 '.' INTO ZSN SEPARATED BY SPACE.
  292. * zprog-line = ZSN. append zprog.
  293. clear:ZSN.
  294. concatenate 'EXPORT ' ZT1 ' TO MEMORY ID ''RICOO''.' INTO ZSN SEPARATED BY SPACE.
  295. zprog-line = ZSN. append zprog.
  296. zprog-line = 'DESCRIBE TABLE TAB LINES LIN.'. append zprog.
  297. zprog-line = 'EXPORT LIN TO MEMORY ID ''RICOOLIN''.'. append zprog.
  298. zprog-line = 'SUBMIT ZMMT2099_EXEC_RICOO_CALL AND RETURN.'. APPEND ZPROG.
  299. * zprog-line = 'MESSAGE S001(00) WITH ''Exec success ! ^_^ ''.'. append zprog.
  300. zprog-line = 'ENDFORM.'. append zprog.
  301. zprog-line = 'FORM APP_TAB.'. append zprog.
  302. CLEAR:ZSN.
  303. CONCATENATE 'APPEND ' ZT1 '.' INTO ZSN SEPARATED BY SPACE.
  304. zprog-line = ZSN. append zprog.
  305. zprog-line = 'ENDFORM.'. append zprog.
  306. CLEAR:ZCODE.
  307. generate subroutine pool zprog
  308. name prog
  309. message msg.
  310. if sy-subrc <> .
  311. message e001() with msg.
  312. else.
  313. perform ricoo in program (prog).
  314. endif.
  315.  
  316. endform.
  317.  
  318. form u_data.
  319.  
  320. zprog-line = 'PROGRAM ZRICOO.'. append zprog.
  321. * zprog-line = 'DATA:MANDT LIKE SY-MANDT.'. append zprog.
  322. zprog-line = 'START-OF-SELECTION.'. append zprog.
  323.  
  324. loop at data into dline.
  325. translate dline to upper case.
  326. zprog-line = dline.
  327. append zprog.
  328. clear:dline.
  329. endloop.
  330.  
  331. zprog-line = 'FORM RICOO.'. append zprog.
  332.  
  333. clear:flg.
  334. loop at data into dline.
  335. translate dline to upper case.
  336. if flg = 'X'.
  337. zprog-line = dline.
  338. append zprog.
  339. endif.
  340. search dline for 'END OF'.
  341. if sy-subrc = .
  342. flg = 'X'.
  343. endif.
  344. clear:dline.
  345. endloop.
  346.  
  347. * zprog-line = 'EXEC SQL.'. append zprog.
  348.  
  349. loop at sql into sline.
  350. translate sline to upper case.
  351. zprog-line = sline.
  352. append zprog.
  353. clear:sline.
  354. endloop.
  355.  
  356. * zprog-line = 'ENDEXEC.'. append zprog.
  357.  
  358. zprog-line = 'MESSAGE S001(00) WITH ''Exec success ! ^_^ ''.'. append zprog.
  359. zprog-line = 'ENDFORM.'. append zprog.
  360.  
  361. generate subroutine pool zprog
  362. name prog
  363. message msg.
  364.  
  365. if sy-subrc <> .
  366. message e001() with msg.
  367. else.
  368. perform ricoo in program (prog).
  369. endif.
  370.  
  371. endform.
  372.  
  373. form include_sql.
  374. clear:zinclude.
  375. clear:lin,zt1,zt2,zn,zln.
  376. refresh:zinclude.
  377.  
  378. zinclude-LINE = 'PROGRAM ZSQL_RICOO_INCLUED.'. APPEND zinclude.
  379. zinclude-LINE = 'DATA:ZN TYPE STRING,'. APPEND zinclude.
  380. zinclude-LINE = 'ZJS TYPE I.'. APPEND zinclude.
  381. zinclude-LINE = 'TYPES CODE_TYPE TYPE RSSOURCE-LINE.'. APPEND zinclude.
  382. zinclude-LINE = 'DATA CODE LIKE TABLE OF RSSOURCE WITH HEADER LINE.'. APPEND zinclude.
  383. zinclude-LINE = 'DATA:ZLIN TYPE I,'. APPEND zinclude.
  384. zinclude-LINE = 'ZT TYPE I.'. APPEND zinclude.
  385. zinclude-LINE = 'FORM ZRICOO_SQL_INCLUDE.'. APPEND zinclude.
  386. zinclude-LINE = 'READ REPORT ''ZSQL_INCLUDE'' INTO CODE.'. APPEND zinclude.
  387. zinclude-LINE = 'DESCRIBE TABLE CODE LINES ZLIN.'. APPEND zinclude.
  388. zinclude-LINE = 'DO ZLIN TIMES.'. APPEND zinclude.
  389. zinclude-LINE = 'ZT = ZT + 1.'. APPEND zinclude.
  390. zinclude-LINE = 'MODIFY CODE INDEX ZT FROM ''''.'. APPEND zinclude.
  391. zinclude-LINE = 'ENDDO.'. APPEND zinclude.
  392. zinclude-LINE = 'INSERT REPORT ''ZSQL_INCLUDE'' FROM CODE.'. APPEND zinclude.
  393.  
  394. loop at data into dline.
  395. zn = zn + .
  396. concatenate z dline z into dline.
  397. concatenate 'ZJS = ' ZN '.' INTO ZSN SEPARATED BY SPACE.
  398. zinclude-LINE = ZSN. APPEND zinclude.
  399. zinclude-line = 'IF ZJS > ZLIN.'. APPEND zinclude.
  400. CONCATENATE 'CODE-LINE = ' DLINE '.' INTO ZSN SEPARATED BY SPACE.
  401. zinclude-LINE = ZSN. APPEND zinclude.
  402. zinclude-LINE = 'APPEND CODE.'. APPEND zinclude.
  403. zinclude-LINE = 'ELSE.'. APPEND zinclude.
  404. concatenate 'MODIFY CODE INDEX ZJS FROM ' DLINE '.' INTO ZCODE SEPARATED BY SPACE.
  405. zinclude-line = zcode. append zinclude. clear:zcode.
  406. zinclude-LINE = 'ENDIF.'.APPEND zinclude.
  407.  
  408. search dline for 'END OF'.
  409. if sy-subrc = .
  410. exit.
  411. endif.
  412. clear:dline,zcode.
  413. endloop.
  414. CLEAR:ZSN.
  415. zinclude-LINE = 'ZJS = ZJS + 1.'. APPEND zinclude.
  416. ZSN = '''RICOO'''.
  417. CONCATENATE Z ZSN Z '.' INTO ZSN .
  418. CONCATENATE 'IMPORT TAB FROM MEMORY ID ' ZSN INTO ZSN SEPARATED BY SPACE.
  419. zinclude-line = 'IF ZJS > ZLIN.'. APPEND zinclude.
  420. CONCATENATE Z ZSN Z INTO ZSN SEPARATED BY SPACE.
  421. zinclude-line = 'CODE-LINE = '. APPEND ZINCLUDE.
  422. CONCATENATE ' ' ZSN '.' INTO ZSN SEPARATED BY SPACE.
  423. zinclude-LINE = ZSN. APPEND zinclude.
  424. zinclude-LINE = 'APPEND CODE.'. APPEND zinclude.
  425. zinclude-LINE = 'ELSE.'. APPEND zinclude.
  426. concatenate 'MODIFY CODE INDEX ZJS FROM ' ZSN INTO ZCODE SEPARATED BY SPACE.
  427. zinclude-line = zcode. append zinclude. clear:zcode.
  428. zinclude-LINE = 'ENDIF.'.APPEND zinclude.
  429.  
  430. zinclude-LINE = 'INSERT REPORT ''ZSQL_INCLUDE'' FROM CODE.'. APPEND zinclude.
  431. zinclude-LINE = 'INCLUDE ZSQL_INCLUDE.'. APPEND zinclude.
  432. zinclude-LINE = 'COMMIT WORK.'. APPEND zinclude.
  433. zinclude-LINE = 'ENDFORM.'. APPEND zinclude.
  434. clear:zsn,zn,zcode,dline.
  435. generate subroutine pool zinclude
  436. name sqlinclude
  437. message zmsg.
  438.  
  439. if sy-subrc <> .
  440. message e001() with zmsg.
  441. else.
  442. perform ZRICOO_SQL_INCLUDE in program (sqlinclude).
  443. endif.
  444.  
  445. endform.

ABAP-Generate subroutine的更多相关文章

  1. 动态生成ABAP程序-资料

    参考程序: Tcode ABAPdocu--> BC - ABAP Programming--> The ABAP Programming Language--> Special T ...

  2. ABAP动态生成经典应用之Dynamic SQL Excute 程序

    [转自http://blog.csdn.net/mysingle/article/details/678598]开发说明:在SAP的系统维护过程中,有时我们需要修改一些Table中的数据,可是很多Ta ...

  3. PA教材提纲 TAW12-1

    Unit1 Introduction to Object-Oriented Programming(面向对象编程介绍) 1.1 Explaining the Object-Oriented Progr ...

  4. ABAP-动态编程

    转载:http://www.cnblogs.com/jiangzhengjun/p/4293407.html 动态编程 动态的基本语法 多种不同的动态编程 动态字段 动态类型 指定结构.内表组件字段的 ...

  5. ABAP-动态创建DATABASE/FUNCTION(风险)

    警告:此程序仅供研究,请谨慎操作,切勿对系统标准数据表及功能函数进行测试(可能无法修复). 程序:EWUCINS REPORT EWUCINS MESSAGE-ID US NO STANDARD PA ...

  6. [SAP ABAP开发技术总结]Form(subroutine)、Function参数传值传址

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  7. Automatically generate serial number in abap

    流水号的产生:   在ABAP开发中,很多地方都需要按照自己的规则生成流水号,把这些流水号保存进透明表,作为唯一标示. 一. 系统中设定流水号 使用T-Code SNRO来创建一个流水号标识对象. 输 ...

  8. ABAP基础4:模块化

    子程序定义 以form开始,以endform结束,用perform语句调用,from语句可以在程序内部/外部,perform一定要写在前面 perform. from. 子程序模块 endform. ...

  9. ABAP关键字和ABAP词汇

    下表为ABAP的词汇概览(包括关键字): ABAP-SOURCE ABBREVIATED ABS ABSTRACT ACCEPT ACCEPTING ACCORDING ACOS ACTIVATION ...

随机推荐

  1. 按的第一个greasemonkey插件:评论时可以粘贴啦~~

    原来的样子:如果按ctrl+V会跳出错误

  2. Servlet 简介

    1. 如下图 2. 每一个Servlent都必须实现Servlent接口. GenericServlet是个通用的.不特定于任何协议的Servlet, 它实现了Servlet接口,而Httpservl ...

  3. Angular 4 表单

    一. 模板表单 1. 如下图 2. code 3. 效果图 二.响应式表单 1. 增加ReactiveFormsModule 2.响应式表单用到的类和指令 3. 控制器代码 4. html <! ...

  4. [转]Nginx负载均衡原理初解

    什么是负载均衡 我们知道单台服务器的性能是有上限的,当流量很大时,就需要使用多台服务器来共同提供服务,这就是所谓的集群. 负载均衡服务器,就是用来把经过它的流量,按照某种方法,分配到集群中的各台服务器 ...

  5. [转]StarWind模拟iSCSI设备

    StarWind模拟iSCSI设备 url: http://jimshu.blog.51cto.com/3171847/590412/  标签:职场 iSCSI 休闲 StarWind 原创作品,允许 ...

  6. asp.net如何使用cookie(创建、保存、读取)

    Cookie的用法也和ASP中差不多.比如我们建立一个名为aspcn,值为大众的cookie HttpCookie cookie = new HttpCookie("aspcn") ...

  7. sql 判断 数据库 表 字段 是否存在

    select * From master.dbo.sysdatabases where name='数据库名'select * from sysobjects where id = object_id ...

  8. HttpClient连接池

    HttpClient连接池,发现对于高并发的请求,效率提升很大.虽然知道是因为建立了长连接,导致请求效率提升,但是对于内部的原理还是不太清楚.后来在网上看到了HTTP协议的发展史,里面提到了一个属性C ...

  9. Android启动过程中背景图片显示

    转自:http://blog.csdn.net/zhangzhikaixinya/article/details/17001321 大部分Android App启动过程中,都会设置一个背景图片,直到A ...

  10. CSS Grid布局入门

    相信大家都比较熟悉flex布局了,最近有空研究了波grid布局,感觉虽然兼容性还不是太高,应用不是太普遍,但是功能非常强大.未来应该是grid+flex为主流,grid是二维布局,很灵活,适合整体构架 ...