04-10-2008 9:41 PM
We've got the following code trying to transfer two different structure of internal tables respectively to one same function as input parameter in one same form, but can't make them work and for the below code, get the error "itab has already been declared." at the 2nd statement to define itab "DATA: itab2 TYPE STANDARD TABLE OF ty2 WITH HEADER LINE.".
Any idea to make it work by transferring two different structure internal tables respectively to one same function in one same form?
<REMOVED BY MODERATOR>
TYPES: BEGIN OF ty1,
f1 like ztab1-f1,
f2 like ztab1-f2,
END OF ty1.
DATA: itab1 TYPE STANDARD TABLE OF ty1 WITH HEADER LINE.
TYPES: BEGIN OF ty2,
f3 like ztab2-f3,
END OF ty1.
DATA: itab2 TYPE STANDARD TABLE OF ty2 WITH HEADER LINE.
Fill in data to itab1...
Fill in data to itab2...
Perform Data_Download Using 1.
Perform Data_Download Using 2.
FORM Data_Download USING v type i.
If v = 1.
DATA: itab TYPE STANDARD TABLE OF ty1 WITH HEADER LINE.
itab = itab1.
Else.
DATA: itab TYPE STANDARD TABLE OF ty2 WITH HEADER LINE.
itab = itab2.
EndIf.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'xxx'
write_field_separator = '|'
TABLES
data_tab = itab.
ENDFORM.
Edited by: Alvaro Tejada Galindo on Apr 10, 2008 4:46 PM
04-10-2008 10:44 PM
Hi,
Try this..
TYPES: BEGIN OF ty1,
f1 like ztab1-f1,
f2 like ztab1-f2,
END OF ty1.
DATA: itab1 TYPE STANDARD TABLE OF ty1 WITH HEADER LINE.
TYPES: BEGIN OF ty2,
f1 like ztab1-f1,
f2 like ztab1-f2,
END OF ty2.
DATA: itab2 TYPE STANDARD TABLE OF ty2 WITH HEADER LINE.
Perform Data_Download TABLES itab1[].
Perform Data_Download TABLES itab2[].
FORM Data_Download TABLES rt_itab.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'xxx'
write_field_separator = '|'
TABLES
data_tab = rt_itab[].
ENDFORM.
Thanks
Naren
04-10-2008 10:33 PM
Doing it dynamically will require a bit more work but if you're determined to go down this path, you can create a dynamic type on the fly using 'CREATE DATA', then then assign it to a field-symbol to work with. However, in order to read from the table, you'll need to use 'ASSIGN COMPONENT'. Standard ABAP help has good details on how you can do this.
constants: gc_type1(3) type c value 'TY1',
gc_type2(3) type c value 'TY2'.
data: gv_type(3) type c.
data: dyn_itab type ref to data.
FIELD-SYMBOLS:
<fs_data> type any.
FORM Data_Download USING v type i.
If v = 1.
gv_type = gc_type1.
CREATE DATA dyn_itab TYPE standard table of (gv_type).
ASSIGN dyn_itab->* TO <fs_data>.
endif.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'xxx'
write_field_separator = '|'
TABLES
data_tab = <fs_data>.
The reason your program doesn't work, is that the data declarations are first scanned from the source code, and you can't have variables of the same name in one processing block (form, function module, method, etc).
04-11-2008 3:18 AM
hi Daniel,
We don't quite understand your code. We are using the following two types to define these two different structure internal tables, but in you code, we can't find these two types and also where is the statements to fill in data to these two internal tables?
TYPES: BEGIN OF ty1,
f1 like ztab1-f1,
f2 like ztab1-f2,
END OF ty1.
DATA: itab1 TYPE STANDARD TABLE OF ty1 WITH HEADER LINE.
TYPES: BEGIN OF ty2,
f3 like ztab2-f3,
END OF ty2.
Thanks and looking forward to hearing from you!
04-10-2008 10:44 PM
Hi,
Try this..
TYPES: BEGIN OF ty1,
f1 like ztab1-f1,
f2 like ztab1-f2,
END OF ty1.
DATA: itab1 TYPE STANDARD TABLE OF ty1 WITH HEADER LINE.
TYPES: BEGIN OF ty2,
f1 like ztab1-f1,
f2 like ztab1-f2,
END OF ty2.
DATA: itab2 TYPE STANDARD TABLE OF ty2 WITH HEADER LINE.
Perform Data_Download TABLES itab1[].
Perform Data_Download TABLES itab2[].
FORM Data_Download TABLES rt_itab.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'xxx'
write_field_separator = '|'
TABLES
data_tab = rt_itab[].
ENDFORM.
Thanks
Naren
04-11-2008 3:13 AM
hi Narendran Muthukumaran,
Maybe you didn't notice that our itab1 and itab2 structures are different. But you gave an example of the same structure ty1 and ty2. Therefore your example will not work if ty1 and ty2 structures are different.
Any idea?
Thanks anyway!
04-11-2008 4:23 AM
Hi Kevin,
Narendran's approach is valid because the table parameter in the routine isn't typed, so you can pass any table you want into that form. I would even lean more to that if it meets your needs because it is easier to understand and maintain over dynamic ABAP.
In my example, I didn't give all the code necessary, but I was showing that you can create data types, including tables, dynamically by using the names of the types. The code isn't complete, but assumes that you have already declared your TY1 and TY2 types. Whenever you see parentheses ( ) with a variable inside that holds a literal, during runtime it will be substituted with the value in the literal.
Goodluck.
04-11-2008 5:04 AM
hi Daniel,
Narendran's approach is Not right! Once again, he used two same structure for these two internal tables. But we are using two different structures of internal tables.
11-30-2011 6:34 AM
Hi,
Were you able to resolve this requirement? If so then please share the details as I am facing a similar situation right now where in I need to download a ALV report data to a single excel file. I want to have the 1st row of file to contain the description and then the details for each field.
Thanks.
Pradipta K Mishra
04-11-2008 3:57 AM
Try the following code.
Perform Data_Download Using itab1.
Perform Data_Download Using itab2.
FORM Data_Download USING p_itab type any table.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'xxx'
write_field_separator = '|'
TABLES
data_tab = p_itab.
ENDFORM.
04-11-2008 4:57 AM
hi Harshu Madap,
Are you sure that the defination of the Form: FORM Data_Download USING p_itab type any table.
Would work? Have you tried it before?
Thanks!
04-11-2008 4:01 AM
I may be missing something here, but why not just put the GUI_DOWNLOAD inside the "If" test instead e.g.
FORM Data_Download USING v type i.
If v = 1.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'xxx'
write_field_separator = '|'
TABLES
data_tab = itab1.
Else.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'xxx'
write_field_separator = '|'
TABLES
data_tab = itab2.
EndIf.
endform.
Jonathan
04-11-2008 5:02 AM
hi Jonathan Coleman,
We only give one simple example code of download data to flat file, but actually we are downloading data to XML file and the code is long. But we can consider your suggestion to do that.
Thanks a lot!