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: 

Get One Column from an internal table without looping

Former Member
0 Kudos
7,260

Hi All,

I have a Huge Internal Table with several columns and would like to get Just two columns from it to another internal table that has just two columns.

Something like this:


Table A;
	
Fld1	Fld2	Fld3	Fld4
1	11	21	31
2	12	22	32
3	13	23	33
4	14	24	34
5	15	25	35
6	16	26	36

And the resulting second table after the move.


Table B;

Fld1	Fld2	
1	11	
2	12	
3	13	
4	14	
5	15	
6	16

But as the Table A is huge with about a 100,000 records; Looping through takes up a lot of resources. And

TableA[] = TableB[] doesn't work for me as the Flds have a different structure in the two tables.

Is there any other way to get around this.?

Thanks in advance..!

Jr

1 ACCEPTED SOLUTION

Former Member
0 Kudos
1,873

Hi

The answer is NO. Cant achieve that without looping at the huge table.

But, looping on that internal table and populating the second table will not have any issues if records are more...

Regards,

Raj

19 REPLIES 19

Former Member
0 Kudos
1,874

Hi

The answer is NO. Cant achieve that without looping at the huge table.

But, looping on that internal table and populating the second table will not have any issues if records are more...

Regards,

Raj

0 Kudos
1,873

Would you be able to populate the second internal table simultaneously with populating the first?

former_member181962
Active Contributor
1,873

I guess you have to loop it .there is no other way.

Anyway, you must have already looped some other table when you have built the first table. Populate the second table as well in the same step.

regards,

ravi

0 Kudos
1,873

I have the first one from a select statement and that statement also takes up considerable amount of time to get executed.

Thanks though..!

Jr.

0 Kudos
1,873

hi,

Paste the code here .. i.e, select statement which is used to get the data on to your first internal table ..

let us modify that so that it takes less time to get the data in to that one

Regards,

Santosh

Message was edited by: Santosh Kumar P

0 Kudos
1,873

Hi

Can't you load both tables in the select statament?

If you're using INTO TABLE option you can't do it, but if you use SELECT/ENDSELCT you can. How are you doing the SELECT statament?

Max

1,873

hi,

i have tried it like this,

data : begin of it_ekko occurs 0,
        ebeln type ebeln,
        bstyp type bstyp,
        bsart type bsart,
        statu type statu,
       end of it_ekko.
data : begin of t_ekko occurs 0,
        ebeln type ebeln,
       end of t_ekko.  

start-of-selection.
  SELECT EBELN
         BSTYP
         BSART
         STATU
    FROM EKKO
    INTO TABLE IT_EKKO
   WHERE EBELN IN S_EBELN.

   t_ekko[] = it_ekko[].

it assign the ebeln to t_ekko.

it is working fine. if you are having different field then how can you assign different fields.

Regards,

Richa

Former Member
0 Kudos
1,873

Hi

I don't believe you can do it without looping the table

Max

Former Member
0 Kudos
1,873

try this .... not sure

<b>

APPEND LINES OF ITAB1 to ITAB2.

</b>

but as the structures are differnt it may not waor , anywayz give it a try

Former Member
0 Kudos
1,873

Hi jr,

1. It can be done.

2. Provided the following simple things are fulfilled.

a) Table A should have also have

FIELD1, FIELD2 (of internal table B)

As the FIRST TWO FIELDS (Starting from Left)

3. Then

tableb[] = tablea[]

will work PERFECTLY FINE.

4. To get a taste of it, just copy paste

5.

report abc.

data : t001 like t001 occurs 0 with header line.

data : begin of itab occurs 0,

mandt like t001-mandt,

bukrs like t001-bukrs,

end of itab.

*-------

select * from t001

into table t001.

itab[] = t001[].

break-point.

regards,

amit m.

0 Kudos
1,873

Hi

Some guys are right and I was wrong.

I tried this code and worked fine:

DATA: BEGIN OF ITAB1 OCCURS 0,

FIELD1(4) TYPE N,

FIELD2(4) TYPE N,

FIELD3(4) TYPE N,

FIELD4(4) TYPE N,

END OF ITAB1.

DATA: BEGIN OF ITAB2 OCCURS 0,

FIELD1(4) TYPE N,

FIELD2(4) TYPE N,

END OF ITAB2.

DO 1000 TIMES.

MOVE SY-INDEX TO ITAB1-FIELD1.

ITAB1-FIELD2 = ITAB1-FIELD3 = ITAB1-FIELD4 = ITAB1-FIELD1.

APPEND ITAB1.

ENDDO.

ITAB2[] = ITAB1[].

LOOP AT ITAB2.

WRITE: / ITAB2.

ENDLOOP.

Max

Former Member
0 Kudos
1,873

HI

Try out this code. Its working fine.

Data : begin of it_vbak occurs 0,

vbeln like vbak-vbeln,

ernam like vbak-ernam,

end of it_vbak.

Data : begin of it_final occurs 0,

vbeln like vbak-vbeln,

end of it_final.

select vbeln ernam from vbak into table it_vbak.

it_final[] = it_vbak[].

loop at it_final.

write:/ it_final-vbeln.

endloop.

Regards

Haritha

0 Kudos
1,873

Thanks Everyone..!

Really Helpful advice..!

My fields are of different lengths.


data: begin of t_eqst_stpo occurs 0,
        idnrk   type  stpo-idnrk,            "Component Material
        anlnr   type  iloa-anlnr,            "Asset Number
        bukrs   type  iloa-bukrs,            "Company Code
............................        
prdha   type  mara-prdha,            "Product Hierarchy
        stprs   type  mbew-stprs,            "Standard price
        peinh   type  mbew-peinh,            "Unit Price
      end of t_eqst_stpo.

data: begin of t_anla_dummy occurs 0,
        anlnr   type  anla-anln1,
        idnrk   type  anla-invnr,
      end of t_anla_dummy.

So t_anla_dummy[] = t_eqst_stpo[].

doesn't quite work.

Looping through the t_eqst_stpo table more comfortable than i thought. It doesn't hog up the system. But i expect the volume to grow in future and then it would be a problem again.

Thanks again for all the help..!

Jr.

0 Kudos
1,873

Loop is not all that bad a statement.

Statements like loop-in-loop..select-in-loop are.

NO problem even if the volume is large.

Regards,

ravi

0 Kudos
1,873

Hi Ravi,

Yes i agree looping is a way but i want to know any other method apart from looping like some direct one line statements like ITAB1 IN ITAB2 etc.. which should give me the common values of both the internal table . and here both the internal table have same structure also

Rgds

Mohit

Former Member
0 Kudos
1,873

Hi,

If in both the internal tables if the common columns are placed leftmost of their structure you can directly use the body operator..THis will work fine..

TABLEB[] = TABLEA[].

Thanks,

Naren

Former Member
0 Kudos
1,873

Hi ,

I have some what same scenario where i have two internal tables of exactly the same structure and i want to get only the common data of the two internal table.

apart from looping is thier any other way.

0 Kudos
1,873

MOVE-CORRESPONDING

will work

manishagb
Explorer
0 Kudos
1,873

lt_tab2 = CORRESPONDING #( lt_tab1 ). " columns from the tables need to match, irrespective of position