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

fetch from variable (dynamic)

Former Member
0 Likes
1,461

Hi,

I have data with 4 fields in one internal table.

Last field have 108 records.like (040.952,957......).

i want to fetch each record from internal table and concatenate 'A' and lastfield in one variable.

First time variable have value A040.(A040 is a data base table).

i want to fetch all values from A040 with the input of first field of internal table and place it into main internal table.

(each time variable having diferent values,value acts as database table,those are having different structures)

EX:

Main itab.(i written code for itab)

f1 f2 f3 f4

200 1 dfg 040

234 2 dfgh 952

235 3 asd 040

241 5 wer 957

now i need like this.

loop at itab.

concatenate A itab-f4 into V_var.

select * from (v_var)

into ........? (please fill here )

where f1 = itab-f1.

And final output i need.

f1 f2 f3 f4 k1 k2 k 3 k4 k5

200 1 dfg 040 v a cvb 125

234 2 dfgh 952 X t 125 material

235 3 asd 040 n a cvn 125

241 5 wer 957 c material 123

in variable different values are stored,and those having deiffernet structure.my problem with into statement.

Please help me ....

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,080

FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,

<ls_outtab> TYPE ANY,

<l_fld> TYPE ANY.

DATA:struct_type TYPE REF TO cl_abap_structdescr,

comp_tab TYPE cl_abap_structdescr=>component_table.

  • Creation of the output table.

struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).

comp_tab = struct_type->get_components( ),

comp_fld TYPE cl_abap_structdescr=>component.

struct_type = cl_abap_structdescr=>create( comp_tab ).

itab_type = cl_abap_tabledescr=>create( struct_type ).

l_wa_name = 'l_WA'.

CREATE DATA dref TYPE HANDLE itab_type.

ASSIGN dref->* TO <lt_outtab>.

CREATE DATA dref TYPE HANDLE struct_type.

ASSIGN dref->* TO <ls_outtab>.

  • THE dynamic select

SELECT *

FROM (p_tabnam)

INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>

WHERE (lt_where).

*display of the results

LOOP AT <lt_outtab> ASSIGNING <ls_outtab>.

LOOP AT comp_tab INTO comp_fld.

ASSIGN COMPONENT comp_fld-name OF STRUCTURE <ls_outtab> TO <l_fld>.

WRITE: <l_fld>.

ENDLOOP.

SKIP.

ENDLOOP.

for more information check

https://webphl07.phl.sap.corp/~sapidb/011000358700002805272003E

6 REPLIES 6
Read only

Former Member
0 Likes
1,081

FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,

<ls_outtab> TYPE ANY,

<l_fld> TYPE ANY.

DATA:struct_type TYPE REF TO cl_abap_structdescr,

comp_tab TYPE cl_abap_structdescr=>component_table.

  • Creation of the output table.

struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).

comp_tab = struct_type->get_components( ),

comp_fld TYPE cl_abap_structdescr=>component.

struct_type = cl_abap_structdescr=>create( comp_tab ).

itab_type = cl_abap_tabledescr=>create( struct_type ).

l_wa_name = 'l_WA'.

CREATE DATA dref TYPE HANDLE itab_type.

ASSIGN dref->* TO <lt_outtab>.

CREATE DATA dref TYPE HANDLE struct_type.

ASSIGN dref->* TO <ls_outtab>.

  • THE dynamic select

SELECT *

FROM (p_tabnam)

INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>

WHERE (lt_where).

*display of the results

LOOP AT <lt_outtab> ASSIGNING <ls_outtab>.

LOOP AT comp_tab INTO comp_fld.

ASSIGN COMPONENT comp_fld-name OF STRUCTURE <ls_outtab> TO <l_fld>.

WRITE: <l_fld>.

ENDLOOP.

SKIP.

ENDLOOP.

for more information check

https://webphl07.phl.sap.corp/~sapidb/011000358700002805272003E

Read only

0 Likes
1,080

Hi TT,

Thanks for ur logic,i have one doubt...

see th 5th line in ur logic:

comp_tab TYPE cl_abap_structdescr=>component_table.

component _table means what?No method exists like that.

Read only

0 Likes
1,080

hi...its not a method...its an attribute...see the attribute COMPONENTS_CACHE in the class CL_ABAP_STRUCTDESCR.

component_table is a table of structure like dis...

begin of abap_componentdescr,

name type string,

type type ref to cl_abap_datadescr,

as_include type abap_bool,

suffix type string,

end of abap_componentdescr,

Read only

0 Likes
1,080

Hi TT,

i m wrking in 4.6c.

that attribute (components_cache) is not available in 4.6c,but available in 6.0.

what to do.

Read only

Former Member
0 Likes
1,080

HI,

Please follow the steps below carefully.

1) types: begin of final,

f1

f2

f3

-


k1---k5,

end of final.

data: it_final type standard table of final,

it_final1 type standard table of final,

wa_final type final.

loop at itab.

concatenate A itab-f4 into V_var.

free it_final1

select * from (v_var)

into it_final1

where f1 = itab-f1.

append lines of it_final1 to it_final.

endloop.

it_final will contains all the values.

Please let me know if you find any difficulties

Read only

Former Member
0 Likes
1,080

Hi...for ur case i think...u can do like dis...

DATA: BEGIN OF nametab OCCURS 0.

INCLUDE STRUCTURE dntab.

DATA: END OF nametab.

DATA: d_ref TYPE REF TO data,

d_ref2 TYPE REF TO data ,

lt_alv_cat TYPE TABLE OF lvc_s_fcat,

ls_alv_cat LIKE LINE OF lt_alv_cat.

FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE, u201C Dynamic internal table name

loop at itab.

concatenate A itab-f4 into V_var.

REFRESH nametab.

CALL FUNCTION u2018NAMETAB_GETu2019

EXPORTING

langu = sy-langu

tabname = v_var

TABLES

nametab = nametab

EXCEPTIONS

no_texts_found = 1.

LOOP AT nametab .

ls_alv_cat-fieldname = nametab-fieldname .

ls_alv_cat-ref_table = tab_name.

ls_alv_cat-ref_field = nametab-fieldname .

APPEND ls_alv_cat TO lt_alv_cat.

ENDLOOP.

  • internal table build

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING it_fieldcatalog = lt_alv_cat

IMPORTING ep_table = d_ref .

ASSIGN d_ref->* TO <t_dyntable>.

select * from (v_var)

into <t_dyntable>

where f1 = itab-f1.