top of page
Writer's pictureERPGenie

TIP: Program to download ABAP

Sometimes you need a copy of your ABAP code written in reports or function modules. Use this simple program to download the code to a text file.


*&---------------------------------------------------------------------*

*& Report ZPGM_DOWNLOAD_WITH_TXT

*&---------------------------------------------------------------------*

REPORT zpgm_download_with_txt.


TABLES : tadir, tfdir.


DATA: BEGIN OF itab OCCURS 0,

line(255) TYPE c,

END OF itab.


DATA: BEGIN OF itab_tmp OCCURS 0,

line(255) TYPE c,

END OF itab_tmp.


DATA : BEGIN OF ipgm OCCURS 0,

pgm TYPE tadir-obj_name,

END OF ipgm.


DATA : i_tfdir TYPE STANDARD TABLE OF tfdir

WITH HEADER LINE

INITIAL SIZE 0.


DATA : l_file TYPE string,

l_ftype TYPE char10,

itab_textpool TYPE STANDARD TABLE OF textpool,

wa_textpool TYPE textpool,

wa_data(255) TYPE c.


SELECT-OPTIONS : s_pgm FOR tadir-obj_name,

s_auth FOR tadir-author,

s_func FOR tfdir-funcname,

s_dev FOR tadir-devclass.


PARAMETERS : p_rep RADIOBUTTON GROUP rg1,

p_func RADIOBUTTON GROUP rg1,

p_dir TYPE string DEFAULT 'C:\temp\'.


IF p_rep = 'X'. "Report


SELECT obj_name

FROM tadir

INTO TABLE ipgm

WHERE pgmid = 'R3TR'

AND object = 'PROG'

AND obj_name IN s_pgm

AND author IN s_auth

AND devclass IN s_dev.


LOOP AT ipgm.


REFRESH: itab, itab_textpool, itab_tmp.


READ REPORT ipgm-pgm INTO itab.


READ TEXTPOOL ipgm-pgm INTO itab_textpool.


LOOP AT itab_textpool INTO wa_textpool.

wa_data = wa_textpool.

APPEND wa_data TO itab_tmp.

ENDLOOP.


IF sy-subrc = 0.

INSERT LINES OF itab_tmp INTO itab INDEX 1.

ENDIF.


CONCATENATE p_dir ipgm-pgm '.TXT' INTO l_file.

l_ftype = 'ASC'.


CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filetype = l_ftype

filename = l_file

append = ' '

write_field_separator = 'X'

confirm_overwrite = 'X'

TABLES

data_tab = itab

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22.


IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.


ENDLOOP.


ELSEIF p_func = 'X'. "Function Module


SELECT *

FROM tfdir

INTO TABLE i_tfdir

WHERE funcname IN s_func.


LOOP AT i_tfdir.


CONCATENATE i_tfdir-pname 'U' i_tfdir-include INTO ipgm-pgm.

ipgm-pgm = ipgm-pgm+3.

READ REPORT ipgm-pgm INTO itab.


READ TEXTPOOL ipgm-pgm INTO itab_textpool.


LOOP AT itab_textpool INTO wa_textpool.

wa_data = wa_textpool.

APPEND wa_data TO itab_tmp.

ENDLOOP.


IF sy-subrc = 0.

INSERT LINES OF itab_tmp INTO itab INDEX 1.

ENDIF.


CONCATENATE p_dir i_tfdir-funcname '.TXT' INTO l_file.

l_ftype = 'ASC'.


CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filetype = l_ftype

filename = l_file

append = ' '

write_field_separator = 'X'

confirm_overwrite = 'X'

TABLES

data_tab = itab

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22.


IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.


ENDLOOP.


ENDIF.

107 views0 comments

Comments


bottom of page