Google Search - Blog...........

ABAP - Dynamic Code Generator -Dynamic Code Upload To Any Server

This report helps to reduce the number of transport requests released for better tesing in other servers.
report zdynamic_code_upload
selection-screen begin of block b1 with frame.
parameters: p_rep like trdir-name obligatory,
p_file like rlgrap-filename,
p_ftype like rlgrap-filetype default 'ASC'.
selection-screen end of block b1.

data: begin of dt_code occurs 0,
line(72) type c,
end of dt_code.

data: dg_fname like rlgrap-filename,
dg_errmsg(240) type c,
dg_errline type i,
dg_errword(72) type c.

---------------------------------------------------------------------
at selection-screen on value-request for p_file.
---------------------------------------------------------------------
call function 'F4_FILENAME'
exporting
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
importing
file_name = p_file.

---------------------------------------------------------------------
start-of-selection.
---------------------------------------------------------------------
clear dg_fname.
if p_file is initial.
call function 'UPLOAD'
exporting

* CODEPAGE = ' '
filename = ' '
filetype = 'ASC'
* ITEM = ' '
* FILEMASK_MASK = ' '
* FILEMASK_TEXT = ' '
* FILETYPE_NO_CHANGE = ' '
* FILEMASK_ALL = ' '
* FILETYPE_NO_SHOW = ' '
* LINE_EXIT = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* SILENT = 'S'
importing
* FILESIZE =
* CANCEL =
act_filename = dg_fname
* ACT_FILETYPE =
tables
data_tab = dt_code
exceptions
conversion_error = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
others = 7.

if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
else.
call function 'WS_UPLOAD'
exporting

* CODEPAGE = ' '
filename = p_file
filetype = 'ASC'
* HEADLEN = ' '
* LINE_EXIT = ' '
* TRUNCLEN = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* DAT_D_FORMAT = ' '
* IMPORTING
* FILELENGTH =
tables
data_tab = dt_code
exceptions
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
others = 10.

if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

dg_fname = p_file.
endif.

if dt_code[] is initial.
write:/ 'No code to generate from', dg_fname.
exit.
endif.
insert report p_rep from dt_code.
if sy-subrc <> 0.
write:/ 'Could not create program', p_rep.
exit.
endif.

syntax-check for dt_code
message dg_errmsg
line dg_errline
word dg_errword.

if sy-subrc <> 0.
write:/ 'Program', p_rep, 'Contains syntax errors:',
/ dg_errmsg,
/ 'Error at line', dg_errline, 'Error:', dg_errword.

exit.
endif.

generate report p_rep.
if sy-subrc <> 0.
write:/ 'Could not generate program', p_rep.
exit.
endif.
submit (p_rep) via selection-screen and return.

write:/ 'Report', p_rep, 'generated'.

No comments:

Post a Comment