09-08-2008 6:43 AM
Hi,
I am using the GUI_DOWNLOAD and WS_DOWNLOAD for lower versions. I need to download data from different internal tables. So for the tables parameter "data_tab" I would like to pass the table name in some variable. How to achieve it?
Thanks.
09-08-2008 6:46 AM
Hi,
If you want to download data from multiple internal tables into the same file.. then create a final output internal table & build the logic to populate the final output internal table.
Else call GUI_DOWNLOAD as many times as the no. of internal tables & pass APPEND = 'X' parameter from the 2nd call of GUI_DOWNLOAD.
Best regards,
Prashant
09-08-2008 6:47 AM
Hi,
This is the normal way
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
FILENAME = filename_converted
FILETYPE = 'ASC'
APPEND = ' '
WRITE_FIELD_SEPARATOR = ' '
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = '4301' "HERE YOU HAVE TO ENTER SAP INTERNAL CODE PAGE!!!
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
SHOW_TRANSFER_STATUS = ABAP_TRUE
IMPORTING
FILELENGTH =
TABLES
DATA_TAB = ITAB_DATA "YOUR INTERNAL TABLE
FIELDNAMES =
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
Regrads
Guru
09-08-2008 7:10 AM
Thanks for your replies. Let me explain in detail. I have to call the FM 3 times (say) for 3 different internal tables. It has to create 3 files as the output.
Now I want to create a subroutine to call this FM. I will be having the internal table name in a variable say w_it_name. Let the internal table be it_test say.
Instead of calling
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = w_path
filetype = 'ASC'
TABLES
data_tab = it_test
I want to pass it as,
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = w_path
filetype = 'ASC'
TABLES
data_tab = ( w_it_name ) (I am not sure something like this)
How to achieve this? Please let me know.
09-08-2008 7:27 AM
Hi
PERFORM download USING fname
CHANGING t_name.
FORM download USING p_fname
CHANGING p_tname TYPE STANDARD TABLE .
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE = BIN_FILESIZE
filename = p_fname
* FILETYPE = 'ASC'
* APPEND = ' '
* WRITE_FIELD_SEPARATOR = ' '
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* IMPORTING
* FILELENGTH = FILELENGTH
TABLES
data_tab = p_tname
* FIELDNAMES = FIELDNAMES
* 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
.
ENDFORM. " download
Check the above snippet (subroutine)
Regards
Pavan
09-08-2008 7:44 AM
Hi Pavan,
the p_tname is declared as table, whereas this variable will only contain the internal table name and not the internal table itself.
I have written a sample code,
data: BEGIN OF wa_t,
first type string,
end of wa_t,
it_t like table of wa_t,
it_t2 like table of wa_t,
w_para TYPE any.
wa_t-first = 'A'.
Append wa_t to it_t.
wa_t-first = 'B'.
Append wa_t to it_t.
wa_t-first = 'C'.
Append wa_t to it_t.
wa_t-first = '1'.
Append wa_t to it_t2.
wa_t-first = '2'.
Append wa_t to it_t2.
w_para = 'it_t'. - here the table name might change.
PERFORM download changing w_para.
&----
*& Form download
&----
form download changing p_w_para type standard table.
Program - General data download
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = 'D:\DHL\Test'
filetype = 'ASC'
TABLES
data_tab = p_w_para
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 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.
endform. " download
Here the table it_t and it_t2 are of same structure but in my original program it's not the case. Please let me know what should be done?
09-08-2008 7:46 AM
Hi,
You can do it in this way and i am sure it will definitely work:
**Data declaration is just given for your reference.....However do make sure that your internal table declaration is inline with the given one....
Example: DATA: it_test TYPE STANDARD TABLE OF <xyz>.
PERFORM download_data USING w_path it_test.
FORM download_data USING p_w_path TYPE <data_element for file path>
p_it_test TYPE STANDARD TABLE.
Try to implement the given code...
Regards,
Kunjal
09-08-2008 8:00 AM
Hi,
The problem is not with passing different file names but with passing different internal tables. I have around 30 internal tables.
I would like to put this FM in subroutine. Call this subroutine 30 times with different internal table each time. So to achieve this i need to find out how to pass the internal table name instead of the table itself.
Thanks.
09-08-2008 8:07 AM
Hi,
Its quite simple then....
However if you pass the internal table name then you will have to create the reference of the same using Field symbols.....
You can do the same using the code snippet provided.....
Regards,
Kunjal
09-08-2008 10:18 AM
Hi Kunjal,
Could you please explain how to create reference using field symbol? If possible please give the code.
Thanks.
09-08-2008 10:23 AM
Hi,
In the subroutine itself if you pass the internal table name, following is the way to use a dynamic reference...
FORM download_data USING tab_name TYPE string.
DATA: <fs> TYPE ANY TABLE.
ASSIGN (tab_name) TO <fs>.
CHECK <fs> IS ASSIGNED.
**Call GUI Download using the field symbol in the tables....
Here, I am not so sure that GUI DOWNLOAD will allow the usage of Field Symbol....
Try it...if not possible here try using the same thing before calling the Subroutine and pass the Field symbol to the subroutine...
Regards,
Kunjal
09-08-2008 7:33 AM
Hi,
PARAMETERS:
p_file1 TYPE string OBLIGATORY
DEFAULT 'D:\text1.txt',
p_file2 TYPE string OBLIGATORY
DEFAULT 'D:\text2.txt'.
TYPES:
BEGIN OF type_itab1,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
END OF type_itab1.
DATA:
wa_itab1 TYPE type_itab1,
itab1 TYPE STANDARD TABLE OF type_itab1,
itab2 LIKE itab1.
SELECT vbeln
posnr
UP TO 5 ROWS
FROM vbap
INTO TABLE itab1.
MOVE itab1 TO itab2.
CHECK sy-subrc EQ 0.
PERFORM output_file TABLES itab1 USING p_file1.
PERFORM output_file TABLES itab2 USING p_file2.
*&---------------------------------------------------------------------*
*& Form output_file
*&---------------------------------------------------------------------*
FORM output_file TABLES p_itab USING p_p_file.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = p_p_file
filetype = 'ASC'
write_field_separator = 'X'
TABLES
data_tab = p_itab
EXCEPTIONS
OTHERS = 1.
ENDFORM. " output_file
Regards
Adil
09-08-2008 7:34 AM
Hello There.
You can simply populate all in a single internal table and Use perform statement for the function module instead of a variable.
I suggest, it needs to be run 3 times. I mean the function module, so perform statement is a better way.
Good Luck & Regards.
Harsh Dave
09-08-2008 10:28 AM
If you have multiple internal tables data and want to download to one excel sheet which contains multiple tab strips, you can do so using OLE concepts.
Check the blog posted by one of my collegue....
[https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/5394] [original link is broken] [original link is broken] [original link is broken];
11-25-2008 5:15 AM
Declare the following field symbol
FIELD-SYMBOLS : < w_it_name > TYPE ANY TABLE.
then each time call your routine 'download' for example to download it_test1 , it_test2, it_test3 as follows:
ASSIGN it_test1 TO < w_it_name >.
CHECK < w_it_name > IS ASSIGNED.
PERFORM download USING file_name < w_it_name >.
*some code
ASSIGN it_test2 TO < w_it_name >.
CHECK < w_it_name > IS ASSIGNED.
PERFORM download USING file_name < w_it_name >.
*some code
ASSIGN it_test3 TO < w_it_name >.
CHECK < w_it_name > IS ASSIGNED.
PERFORM download USING file_name < w_it_name >.
Here variable file_name can be assigned a desired value before you call the subroutine and then cleared and reassigned a new value for the next routine call.
the routine download is declared with "TYPE STANDARD TABLE" as shown below.
FORM download USING p_file_name
p_tabname TYPE STANDARD TABLE.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = p_file_name
* FILETYPE = 'ASC'
* APPEND = ' '
write_field_separator = 'X'
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
* SHOW_TRANSFER_STATUS = ABAP_TRUE
* IMPORTING
* FILELENGTH =
TABLES
data_tab = p_tabname
* FIELDNAMES =
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.
ENDFORM.