Skip to Content
author's profile photo Former Member
Former Member

Dynamic Generation of ABAP program

Hi ABAPers,

I have a query for you.Which is the best way to generate ABAP program dynamically.I know, I can use SE38 batch session but it stops after 2nd screen with error "Program xxxx not found",message ID ED 524.I don't know any other ways.

So please participate & contribute your great ideas.

Chandra

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Posted on May 03, 2005 at 09:08 PM

    Hi Chandra

    Basically, to generate persistent programs you can use:

    <b>INSERT REPORT <prog> FROM <itab>.</b>

    <u>e.g.</u>

    REPORT dynamic_program_generation .
    
    DATA: lt_code TYPE TABLE OF rssource-line.
    
    APPEND  'REPORT ZMY_DYN_PROG.' TO lt_code.
    
    APPEND  'WRITE / ''Hello, I am dynamically created!''.'
             TO lt_code.
    
    INSERT REPORT 'ZMY_DYN_PROG' FROM lt_code.

    For temporary program generation, you can use

    <b>GENERATE SUBROUTINE POOL <itab> NAME <prog> [<options>].</b>

    For more information, you can refer to F1 help for <b>GENERATE</b> and <b>INSERT</b> statements.

    Regards

    *--Serdar https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 03, 2005 at 09:29 PM

    Hi Serdar,

    Thanks for your quick answer.But I want to generate like a<b> Trasportable program with text elements</b>.Is there is any ther way.

    Thanks again for your help

    Chandra

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member
      GENERATE SUBROUTINE POOL

      generates a transint subroutine pool that can only be called from the context it was generated it. After the end of this context (e.g. report) the subroutine won´t exist.

      INSERT REPORT

      inserts a new report into the repository or overwrites an existing report. This report cann be called from other contexts, too. It can even be edited afterwards as it really has a TADIR entry and normal program attributes.

      ATTENTION: Existing programs with the same name will be overwritten without comment! So: check whether the report already exists before inserting it!

  • Posted on May 04, 2005 at 06:36 AM

    Hi,

    Try this one

    <b>Basic ABAP syntax for manipulating reports dynamically:

    INSERT REPORT <prog> FROM <itab>.

    READ REPORT <prog> INTO <itab>.

    DELETE REPORT <prog>.</b>

    *Dynamic manipulation of report programs

    *......................................................................

    *: Report ZDYNAMICCODE :

    *:.....................................................................

    *: Execute ABAP from a PC file(.txt) :

    *: Therefor allowing any abap code to be executed on any client :

    *: which contains this program :

    *: :

    *.....................................................................:

    REPORT zdynamiccode .

    TABLES rlgrap.

    *selection screen creation

    PARAMETER: p_file(200) TYPE c,

    p_temp(30) TYPE c DEFAULT 'Z123TEMP_REPORT_FOR_CODE'.

    *data declaration

    DATA: it_tab TYPE filetable,

    gd_subrc TYPE i,

    answer TYPE c.

    TYPES: BEGIN OF t_abapcode,

    row(72) TYPE c,

    END OF t_abapcode.

    DATA: it_abapcode TYPE STANDARD TABLE OF t_abapcode INITIAL SIZE 0,

    it_store TYPE STANDARD TABLE OF t_abapcode INITIAL SIZE 0.

    DATA: filename TYPE string.

    ************************************************************************

    *AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

    *Selecting a File, plus inserting default file extension

    REFRESH: it_tab.

    CALL METHOD cl_gui_frontend_services=>file_open_dialog

    EXPORTING

    window_title = 'Select File'

    default_filename = '*.txt'

    multiselection = ' '

    CHANGING

    file_table = it_tab

    rc = gd_subrc.

    LOOP AT it_tab INTO p_file.

    ENDLOOP.

    ************************************************************************

    *START-OF-SELECTION.

    START-OF-SELECTION.

    *move file name into a field with type compatable with FM

    filename = p_file.

    *upload file from PC

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    filename = filename

    TABLES

    data_tab = it_abapcode

    EXCEPTIONS

    file_open_error = 1

    file_read_error = 2

    no_batch = 3

    gui_refuse_filetransfer = 4

    invalid_type = 5

    no_authority = 6

    unknown_error = 7

    bad_data_format = 8

    header_not_allowed = 9

    separator_not_allowed = 10

    header_too_long = 11

    unknown_dp_error = 12

    access_denied = 13

    dp_out_of_memory = 14

    disk_full = 15

    dp_timeout = 16

    OTHERS = 17.

    IF sy-subrc EQ 0.

    • Check if report name being used fro temorary code already exists as

    • any code will be over written and lost

    <b> READ REPORT p_temp INTO it_store.</b>

    IF sy-subrc NE 0.

    • Please note any existing code in the program will be lost!!!!

    <b>INSERT REPORT p_temp FROM it_abapcode.</b> SUBMIT (p_temp) AND RETURN.

    <b> DELETE REPORT p_temp.</b> ELSE.

    CALL FUNCTION 'POPUP_TO_CONFIRM'

    EXPORTING

    text_question = 'Report used to store temporary code already

    exists!!! Do you want to overwrite it?'

    IMPORTING

    answer = answer.

    IF sy-subrc EQ 0.

    IF answer EQ '1'. "yes

    • Please note any existing code in the program will be lost!!!!

    <b>INSERT REPORT p_temp FROM it_abapcode.</b> SUBMIT (p_temp) AND RETURN.

    <b> DELETE REPORT p_temp.</b> ENDIF.

    ENDIF.

    ENDIF.

    ENDIF.

    Thanks & Regards,

    Judith.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 04, 2005 at 08:30 AM

    Hi Chandra,

    I guess, it's not possible to automatically a transport request for a dynamical program - seems just like two different concepts.

    But with little manual aid you can have a transport request:

    - either you create a empty report (-> you have immediately a request), which you change later by read report ... insert report dynamical

    - or you change your dynamical report later manual -> you can assign a request afterwards.

    Maybe that's just the fastest way to get some text elements, too.

    Regards,

    Christian

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 04, 2005 at 01:00 PM

    Hi All,

    Thanks for your response,Still I'm in the same position and I'm not getting perfect answer.So if you find BEST solution ,please submit.Please ask your friends and colleagues.

    Thanks to Rishi Joseph,Mike Schernbeck,Judith Jessie Selvi,Christian Wohlfahrt,Mike Schernbeck and Serdar Simsekler.

    Chandra

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.