Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Compiling code entered at runtime by user

Former Member
0 Likes
928

Hi

I am trying to create a program to use for the ABAP developers at my work. We want to be able to enter small snippets of code and for the program to run the code and send back the database results. Kind of like a test program for data in the DB. We also want to be able to do direct table updates with it (Z tables only).

I am creating a text editor on my screen to enter the code to compile. The user will then enter their select statement which will return the results of the database on screen.

However I am unsure how to compile code that the user has entered? I know how to retrieve the text from the editor but how do I use the code that I retrieve? Is there a way to do this? I want to try run whatever code the user enters.

1 ACCEPTED SOLUTION
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
814

You can use another option of using giving the user parameters Iike table names where clause fiels etc and in back end you can use dynamic queries. I m loking into your problem will get back to you soon. It is way arounf which i provided.

Nabheet

4 REPLIES 4
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
815

You can use another option of using giving the user parameters Iike table names where clause fiels etc and in back end you can use dynamic queries. I m loking into your problem will get back to you soon. It is way arounf which i provided.

Nabheet

Read only

0 Likes
814

I just write my own code and check how Sap does it. Check following classes.

1 cl_wb_pgeditor method check_source

2 cl_wb_editor.

For more detail write a statement and before activating enable debugging.

Nabheet

Read only

0 Likes
814

These look hopeful indeed, thanks if I can get working example with what you have provided I'll let you know and give you 10.

Cheers

Read only

Former Member
0 Likes
814

I got it to work.. here is the code I used.

  

TRY.
      GENERATE SUBROUTINE POOL source_tmp NAME prog
      MESSAGE msg
      LINE lin
      WORD wrd
      OFFSET off.
*      editor-call for report prog display-mode.


      IF sy-subrc <> 0.
        v_textname = 'Syntax Error!'.
        REFRESH i_tline.
        lin = lin - 2. " 2 lines added at generation
        CONCATENATE 'Error during generation in line' lin
               INTO i_tline-tdline.
        APPEND i_tline.
        i_tline-tdline = msg.
        APPEND i_tline.
*   CONCATENATE 'Word:' wrd 'at offset' off
*            INTO I_TLINE-TDLINE.
*   APPEND I_TLINE.

        CALL FUNCTION 'POPUP_WITH_TABLE'
          EXPORTING
            endpos_col   = 120
            endpos_row   = 25
            startpos_col = 35
            startpos_row = 5
            titletext    = v_textname
          TABLES
            valuetab     = i_tline
          EXCEPTIONS
            break_off    = 1.

      ELSE.
        GET TIME STAMP FIELD v_timestamp1.
        PERFORM dyn1 IN PROGRAM (prog) TABLES <l_table>.
        GET TIME STAMP FIELD v_timestamp2.
        v_timeresult = v_timestamp2 - v_timestamp1.
      ENDIF.
    CATCH cx_sy_generate_subpool_full.
      gen_error = 'X'.
      MESSAGE s012(s7).
      EXIT.
  ENDTRY.