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: 

fetching data from one internal table and populating into other table

Former Member
0 Kudos

hi

i am working on a report program.

here,i have my data in a internal table(having only one field) i.e. only one column in the table.

now i want to populate this data into other internal internal table that has 13fields i.e. 13 columns.

so could anyone let me know how can i work on this.

i am looping the internal table with one field into a work area from there i am not able to proceed ahead.

thanks in advance

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Moorty,

u want to add tht field to the internal table data i.e for each record ,

if tht is the case just loop ur 2nd internal table and read the first internal table and

declare a field in 2nd internal table i.e there in first internal table and move that value into work area of 2nd internal table , then use modify statement .

MODIFY internal table(2nd) from work area(2nd) TRANSPORTING field1(field name of 1st internal table which is added to 2nd internal table).

This ill solve ur problem, otherwise let me know with further issues.

Regards Niranjan.G

9 REPLIES 9

Former Member
0 Kudos

Hi,

Declare a work area for the second Internal table and use APPEND statement inside the first loop.

Do F1 on APPEND statement for more details

Regards

former_member305388
Active Contributor
0 Kudos

Suppose u have 2 tables as:

tb_tab1 which has one fld fld1

tb_tab2 which has some 3 flds fld1, fld2 and fld3.

Now,

LOOP AT tb_tab1 INTO wa_tab1.

wa_tab2-fld1 = wa_tab1-fld1.

APPEND wa_tab2 TO tb_tab2.

MODIFY tb_tab2.

CLEAR tb_tab2.

ENDLOOP.

Hope this helps..

0 Kudos

hi

thanks for the reponse. the problem is i am making the program work dynamically so my internal table is a dynamic one with no. of fields based on the text file that i am uploading.

so initially i am uploading these fields into a internal table having one field and now i want to populate this data into internal table the fields i.e. here i dont know the no. of fields of the internal table.

thanks in advance

0 Kudos

Can you plzz paste your code?

Peranandam
Contributor
0 Kudos

Hi,

just loop your first internal table which is having one field and map with corresponding field of your second internal table like below specified.

loop at itab1 into wa_itab1.

wa_itab2-f1 = wa -itab1-f1

append wa_itab2 to itba2.

endiloop.

Regards,

Peranandam

0 Kudos

hi

i would like to clear one point here i.e. my internal table into which i want to populate data is a dynamic internal table....so i cant give the fieldnames here..

here i am pasting the code..so that u may get some idea...

"generating dynamic internal table :

ref_descr ?= cl_abap_typedescr=>describe_by_data( it_itab ).

it_details[] = ref_descr->components[].

loop at it_details into wa_comp.

cnt = cnt + 1.

wa_fcat-col_pos = cnt.

wa_fcat-fieldname = wa_comp-name.

append wa_fcat to t_fcat.

endloop.

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

I_STYLE_TABLE =

IT_FIELDCATALOG = t_fcat

I_LENGTH_IN_BYTE =

IMPORTING

EP_TABLE = lo_table

E_STYLE_FNAME =

EXCEPTIONS

GENERATE_SUBPOOL_DIR_FULL = 1

others = 2

so lo_table is my dynamic internal table.

ASSIGN lo_table->* TO <f_tab>.

using the GUI_UPLOAD i have uploaded the data file(separated by semicolon) from presentation server and its in the table itab.

with the following logic i am capturing the data in between the semicolon's.

LOOP AT itab INTO wa_itab.

find all occurrences of c_semicolon in wsg_string results result_tab.

loop at result_tab into wa_reslt.

if sy-tabix = 1.

str1 = wsg_string+0(wa_reslt-offset).

wa_prev_offset = wa_reslt-offset.

wa_prev_offset = wa_prev_offset + 1.

clear str1.

else.

count = wa_reslt-offset - wa_prev_offset.

count = count.

str2 = wsg_string+wa_prev_offset(count).

clear str2.

wa_prev_offset = wa_reslt-offset.

wa_prev_offset = wa_prev_offset + 1.

enddo.

endif.

endloop.

data is there in the fields str1 and str2.now i want to populate this data into dynamic internal table row-wise.

could anyone suggest me how can i do this

0 Kudos

hi

any suggestions please???

Former Member
0 Kudos

Hi Moorty,

u want to add tht field to the internal table data i.e for each record ,

if tht is the case just loop ur 2nd internal table and read the first internal table and

declare a field in 2nd internal table i.e there in first internal table and move that value into work area of 2nd internal table , then use modify statement .

MODIFY internal table(2nd) from work area(2nd) TRANSPORTING field1(field name of 1st internal table which is added to 2nd internal table).

This ill solve ur problem, otherwise let me know with further issues.

Regards Niranjan.G

Former Member
0 Kudos

resolved