Application Development 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: 

Create Internal table with fields coming as query result of multiple tables

Former Member
0 Kudos
299

Hi

I want to create internal table with the fileds which come as a result of a select query from multiple tables

1 ACCEPTED SOLUTION

Former Member
0 Kudos
73

Hi Anjul

Please consider using Field-Symbols. It can help you using any field dynamically.

Kind Regards

Eswar

8 REPLIES 8

Former Member
0 Kudos
73

create types with all the fields u want and create internal table.

ex: Types: begin of ty_tab,

f1 type c,

f2 type c....

end of ty_tab.

data: itab type table of ty_tab.

Former Member
0 Kudos
73

the p[roblem is that the fields that have to be selected come from an external excel sheet.

0 Kudos
73

take the fields whatever u want and declare it according to the associated types they have.

Former Member
0 Kudos
74

Hi Anjul

Please consider using Field-Symbols. It can help you using any field dynamically.

Kind Regards

Eswar

Former Member
0 Kudos
73

Hi you need to figure out what are the fields you required from diff tables and need to create an internal table.

Then again while fetching you need to fetch data bye first select query as you rqueired, for the remaining fields you need to modify the internal table Or else you need to have join statement to link all tables as you needed move data at a time.

Rgds,

Hemanth

jayanthi_jayaraman
Active Contributor
0 Kudos
73

Hi,

As suggested Field symbold will help you in this.

Former Member
0 Kudos
73

hi ,

in short i can put it as creation of dynamic internal table with varying fields in it...

for this u need to dynamically assign field types to the fields of the itab .

ASSIGN COMPONENT idx  OF STRUCTURE struc TO <fs>. 

ASSIGN COMPONENT name OF STRUCTURE struc TO <fs>.

then u need to create the internal table as

DATA: ptr_itab TYPE REF TO data.

FIELD-SYMBOLS: <fs_itab> TYPE STANDARD TABLE. "ANY TABLE.

CREATE DATA ptr_itab TYPE STANDARD TABLE OF (tabname).

ASSIGN ptr_itab->* TO <fs_itab>.

using <b>create data</b> u need to create ur internal table .

regards,

Vijay

Former Member
0 Kudos
73

My code is something like this. I need the data from various fields of diff tables depending on the excel file. This data is then to be put in a internal table

&----


*& Report Z_EXTC

*&

&----


*&

*&

&----


report z_extc.

type-pools : abap.

parameter: objname(25) type c.

data : idetails type abap_compdescr_tab,

xdetails type abap_compdescr.

data : ref_table_des type ref to cl_abap_structdescr.

data: p_table type string.

data:l_string type string,

l_filename(200) type c,

dy_line type ref to data,

xfc type lvc_s_fcat,

ifc type lvc_t_fcat.

types:begin of itab,

tabname type dd03l-tabname,

fieldname type dd03l-fieldname,

end of itab.

types:begin of atab,

tabname type dd03l-tabname,

cnt type string,

end of atab.

field-symbols: <dyn_table> type table,

<dyn_table1> type standard table,

<dyn_wa>,

<dyn_field>.

data: dy_table type ref to data,

dy_table1 type ref to data.

data: itab1 type itab occurs 0 with header line.

data atab1 type atab occurs 0 with header line.

data frstrec type i value 0.

data lastrec type i value 0.

l_string = ''.

call function 'GUI_UPLOAD'

exporting

filename = 'C:\excel_files\FIELDS_CC.TXT'

  • filetype = 'TXT'

has_field_separator = 'X' .

if sy-subrc <> 0.

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

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

endif.

*Refresh itab1.

loop at itab1.

on change of: itab1-tabname.

if lastrec = 1.

move l_string to atab1-cnt.

  • move itab1-tabname to atab1-tabname.

append atab1.

l_string = ''.

endif.

move itab1-tabname to atab1-tabname.

frstrec = 1.

endon.

if frstrec = 1.

concatenate l_string itab1-fieldname into l_string separated by

space.

lastrec = 1.

endif.

*write:/ itab1-tabname,40 itab1-fieldname.

endloop.

move l_string to atab1-cnt.

append atab1.

loop at atab1.

write:/ atab1-tabname,5 atab1-cnt.

endloop.

*