SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Динамическое выполнение abap-кода



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dynamic Programming | Динамическое программирование
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sat Feb 09, 2008 11:10 pm    Post subject: Динамическое выполнение abap-кода Reply with quote

В окне редактора пишите abap код, например.
Code:
DATA: IT TYPE TABLE OF BKPF WITH HEADER LINE.
SELECT * FROM BKPF INTO TABLE IT UP TO 10 ROWS.
LOOP AT IT.
  WRITE: / IT-BELNR.
ENDLOOP.


результат выполнения выдается на экране.

Code:
REPORT zselect .

DATA: container  TYPE REF TO cl_gui_custom_container.
DATA: editor     TYPE REF TO cl_gui_textedit.

DATA: select_src TYPE STANDARD TABLE OF abapsource.
FIELD-SYMBOLS:   <sel> LIKE LINE OF select_src.


INITIALIZATION.
*  CHECK sy-sysid = 'XAP'  OR sy-sysid = 'X01'.
*  CHECK sy-uname  = 'LOLITA' OR
*        sy-uname  = 'GUTE FEE'.


START-OF-SELECTION.
  IMPORT select_src FROM MEMORY ID 'ZSELECT'.
  IF sy-subrc NE 0 OR select_src IS INITIAL.
    APPEND 'SELECT' TO select_src.
  ENDIF.
  WHILE NOT select_src IS INITIAL.
    CALL SCREEN 100.
    CHECK NOT select_src IS INITIAL.
    PERFORM select.
  ENDWHILE.


*&---------------------------------------------------------------------*
*&      Module  status_0100  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  IF container IS INITIAL.
    CREATE OBJECT container
      EXPORTING
        container_name = 'CONTAINER'.
  ENDIF.
  IF NOT container IS INITIAL AND editor IS INITIAL.
    CREATE OBJECT editor
      EXPORTING
       wordwrap_mode              =
         cl_gui_textedit=>wordwrap_at_fixed_position
       wordwrap_position          = 72
       wordwrap_to_linebreak_mode = cl_gui_textedit=>true
       parent                     = container.
    IF NOT editor IS INITIAL.
      CALL METHOD editor->set_text_as_r3table
        EXPORTING
          table = select_src.
      CALL METHOD cl_gui_textedit=>set_focus
        EXPORTING
          control = editor.
    ENDIF.
  ENDIF.
ENDMODULE.                 " status_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  user_command_0100  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  IF NOT editor IS INITIAL.
    CALL METHOD editor->get_text_as_r3table
       IMPORTING
         table = select_src.
    LOOP AT select_src ASSIGNING <sel>.
      TRANSLATE <sel> TO UPPER CASE.
    ENDLOOP.
    SEARCH select_src FOR 'UPDATE'.
    IF sy-subrc = 0. REFRESH select_src. ENDIF.
    SEARCH select_src FOR 'DELETE'.
    IF sy-subrc = 0. REFRESH select_src. ENDIF.
    SEARCH select_src FOR 'INSERT'.
    IF sy-subrc = 0. REFRESH select_src. ENDIF.
    SEARCH select_src FOR 'MODIFY'.
    IF sy-subrc = 0. REFRESH select_src. ENDIF.
    SEARCH select_src FOR 'CALL'.
    IF sy-subrc = 0. REFRESH select_src. ENDIF.
    SEARCH select_src FOR 'CREATE'.
    IF sy-subrc = 0. REFRESH select_src. ENDIF.
    SEARCH select_src FOR 'EXPORT'.
    IF sy-subrc = 0. REFRESH select_src. ENDIF.
    SEARCH select_src FOR 'REPORT'.
    IF sy-subrc = 0. REFRESH select_src. ENDIF.
    CALL METHOD editor->free.
    FREE editor.
  ENDIF.
  IF NOT container IS INITIAL.
    CALL METHOD container->free.
    FREE container.
  ENDIF.
  LEAVE TO SCREEN 0.
ENDMODULE.                 " user_command_0100  INPUT

*&---------------------------------------------------------------------*
*&      Form  select
*&---------------------------------------------------------------------*
FORM select.
  DATA: prog     LIKE sy-repid.
  DATA: l_select LIKE select_src.
  DATA: msg(20).
  DATA: lin TYPE i.
  DATA: wrd(20).
  DATA: off TYPE i.
  APPEND 'PROGRAM Z%%SEL. FORM SEL.' TO l_select.
  APPEND LINES OF select_src         TO l_select.
  APPEND 'ENDFORM.'                  TO l_select.
  GENERATE SUBROUTINE POOL l_select NAME prog
           MESSAGE msg
           LINE    lin
           WORD    wrd
           OFFSET  off.
  IF sy-subrc NE 0.
    MESSAGE s398(00) WITH msg lin wrd off.
  ELSE.
    PERFORM sel IN PROGRAM (prog).
    EXPORT select_src TO MEMORY ID 'ZSELECT'.
    REFRESH select_src.
  ENDIF.
ENDFORM.                    " select



zselect_0100.txt
 Description:
100 Экран.

Download
 Filename:  zselect_0100.txt
 Filesize:  24.72 KB
 Downloaded:  1955 Time(s)

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dynamic Programming | Динамическое программирование All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.