Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Call function 'Download' using different internal tables

Former Member
0 Likes
1,520

Hi everyone!

i declare 10 different internal tables, with the same structure but different data.

i need to create 10 different files (one from each internal table)

i dont want to call 10 times the function download.

is there someway to put a variable name(that refeer to my internal table)

something like this.

PERFORM Create_file USING mytable.

PERFORM Create_file USING mytable2.

PERFORM Create_file USING mytable3.

PERFORM Create_file USING etc....

FORM create_file USING table.

DATA: file(128),

zcancel(1).

archivo = 'c:\loans.dat'.

CALL FUNCTION 'DOWNLOAD'

EXPORTING

bin_filesize = ' '

codepage = ' '

filemask_all = ' '

filemask_mask = ' '

filemask_text = ' '

filename = file

filetype = 'dat'

filetype_no_change = ' '

filetype_no_show = ' '

item = ' '

mode = ' '

wk1_n_format = ' '

wk1_n_size = ' '

wk1_t_format = ' '

wk1_t_size = ' '

IMPORTING

cancel = zcancel

TABLES

data_tab = <b>TABLE</b>

EXCEPTIONS

invalid_filesize = 01

invalid_table_width = 02

invalid_type = 03

no_batch = 04

unknown_error = 05.

ENDFORM.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
916

You can pass generically using TABLES parameters.

PERFORM Create_file TABLES mytable.
PERFORM Create_file TABLES mytable2.
PERFORM Create_file TABLES mytable3.

FORM create_file TABLES table.


Regards,

Rich Heilman

7 REPLIES 7
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
917

You can pass generically using TABLES parameters.

PERFORM Create_file TABLES mytable.
PERFORM Create_file TABLES mytable2.
PERFORM Create_file TABLES mytable3.

FORM create_file TABLES table.


Regards,

Rich Heilman

Read only

0 Likes
916

You may also want to make sure that you change the file name everytime you call it, you can pass this value to the subroutine also using the USING keyword.

REgards,

Rich Heilman

Read only

0 Likes
916

Here is an example.....



report zrich_0001 .

types: begin of ttab,
       fld1 type c,
       fld2 type c,
       fld3 type c,
       end of ttab.

data: itab1 type table of ttab with header line.
data: itab2 type table of ttab with header line.
data: itab3 type table of ttab with header line.

itab1 = 'ABC'.  append itab1.
itab1 = 'DEF'.  append itab1.

itab2 = 'QRS'.  append itab2.
itab2 = 'TUV'.  append itab2.

itab3 = '123'.  append itab3.
itab3 = '456'.  append itab3.

perform download tables itab1
                 using 'C:itab1.txt'.

perform download tables itab2
                 using 'C:itab2.txt'.

perform download tables itab3
                 using 'C:itab3.txt'.
*&---------------------------------------------------------------------*
*&      Form  download
*&---------------------------------------------------------------------*
form download tables   table  using file.

  data: file_str type string.

file_str = file.

 call function 'GUI_DOWNLOAD'
   exporting
     filename                      = file_str
   tables
     data_tab                      = table.




endform.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
916

Hi,

Check this example..

It download t_mara1 & t_mara2..Modify the code according to your requirement..

DATA: t_mara1 LIKE mara OCCURS 0 WITH HEADER LINE.

DATA: t_mara2 LIKE mara OCCURS 0 WITH HEADER LINE.

DATA: v_filename LIKE rlgrap-filename.

DATA: v_char5(5).

FIELD-SYMBOLS: <fs> TYPE table.

DATA: v_variable(30).

DO 2 TIMES.

CLEAR: v_filename.

v_char5 = sy-index.

SHIFT v_char5 LEFT DELETING LEADING space.

CONDENSE v_char5.

CONCATENATE 'C:\TEST' v_char5 '.TXT' INTO v_filename.

CONCATENATE 'T_MARA' v_char5 '[]' INTO v_variable.

ASSIGN (v_variable) TO <fs>.

CALL FUNCTION 'DOWNLOAD'

EXPORTING

filename = v_filename

filetype = 'DAT'

TABLES

data_tab = <fs>

EXCEPTIONS

invalid_filesize = 1

invalid_table_width = 2

invalid_type = 3

no_batch = 4

unknown_error = 5

gui_refuse_filetransfer = 6

customer_error = 7

OTHERS = 8.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDDO.

Thanks,

Naren

Read only

Former Member
0 Likes
916

tks for the help, now i have another problem.

PERFORM CREATE_FILE TABLES ti_semanal using 'c:\semanal.dat'.

PERFORM CREATE_FILE TABLES ti_quincenal using 'c:\quincenal.dat'.

PERFORM CREATE_FILE TABLES ti_maestras using 'c:\maestras.dat'

FORM CREATE_FILE using c_table.

c_table-loan = c_table-loan / months.

....

....

....

Call function download

......

TABLES

data_tab = c_table

......

ENDFORM

the following error is displayed

The data object "c_table" has no structure and therefore no component

called "loan".

i can used for call the download function, but i cant access their structure components?

Read only

0 Likes
916

That's right, they are being passed gernerically to the FORM, I would suggest making sure that everything is calculated in the internal tables prior to calling the DOWNLOAD subrontine.

Regards,

Rich heilman

Read only

Former Member
0 Likes
916

Hi,

If all the internal tables is of the same structure..Then check this example..

DATA: BEGIN OF ITAB OCCURS 0,

MATNR TYPE MATNR,

END OF ITAB.

ITAB-MATNR = '1212'.APPEND ITAB.

PERFORM FORM1 TABLES ITAB.

FORM FORM1 TABLES CT_TAB LIKE ITAB[].

LOOP AT CT_TAB WHERE NOT MATNR IS INITIAL.

WRITE: / CT_TAB-MATNR.

ENDLOOP.

ENDFORM.

Thanks,

Naren