05-03-2005 9:53 PM
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
05-03-2005 10: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 <a href="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 ]</a>
05-03-2005 10: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
05-04-2005 12:30 AM
Use
<b>INSERT TEXTPOOL <i>prog</i> ...FROM <i>itab</i> ...LANGUAGE <i>lg</i>.</b>
for text elements.
<b>INSERT REPORT <i>prog</i> FROM <i>itab</i>.</b>
for reports.
Rishi
05-04-2005 6:38 AM
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!
05-04-2005 7: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.
05-04-2005 9: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
05-04-2005 11:19 AM
05-04-2005 2: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
05-04-2005 2:09 PM
Hi Chandra,
You might want mark your post as a question!
Maybe then the BEST answer will arrive.
No guarantees of course....
Brad