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: 

Using for all entries

mariano_gallicchio2
Participant
0 Kudos

Hello experts,

i have this code

TYPES: BEGIN OF st_r,
             a LIKE table-a,
             b LIKE table-b,
             c LIKE table-c,
             d LIKE table-d,
             e LIKE table-e,
             END OF st_r,

data t1 type table of st_r.
data t2 type table of st_r.
...

select a b c 
   from database
   into corresponding fields table of t1
   where condition

select d e
   into corresponding fields table of t2
   from cluster_table
   for all entries in t1
   where condition

what i want to do, is that the values of the field a b and c be copied to the table t2, because now i only get the fields d and e only.

Any idea?

Thanks!

Edited by: Matt on Feb 11, 2009 2:51 PM - fixed formatting

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

In the query

select d e

into corresponding fields table of t2

from cluster_table

for all entries in t1

where condition you will be having atleast one common field with int tab t2.

ie. for example say 'a' is the common field, so in your query you will be having

...
for all entries in t1
where a = t1-a...

Therefore you can have your second query as

select a d e
into corresponding fields table of t2
from cluster_table
for all entries in t1
where a = t1-a ... "on the assumption that a is the common field
                         "Now t2 contains field a also 

Now you can have this logic:

loop at t2 into wa_t2.
read table t1 into wa_t1 key a = wa_t2-a.
"Move only b and c as a is ther already
wa_t2-b = wa_t1-b.
wa_t2-c = wa_t1-c.
modify t2 from wa_t2 transporting b c.
endloop.

Hope this works.

Regards,

Manoj Kumar P

13 REPLIES 13

Former Member
0 Kudos

hi ,

see this example.

TYPES :

BEGIN OF type_s_lvbak,

vbeln TYPE vbak-vbeln, " Sales Document Number

vkorg TYPE vbak-vkorg, " Sales Organisation

vtweg TYPE vbak-vtweg, " Distribution channel

spart TYPE vbak-spart, " Division

posnr TYPE vbap-posnr, " Sales document Item Number

matnr TYPE vbap-matnr, " Material

END OF type_s_lvbak.

DATA :

fs_lvbak TYPE type_s_lvbak, " Field String to hold vbak

" structure

w_vbeln LIKE vbak-vbeln. " Holds sales document number

DATA :

t_lvbak LIKE

STANDARD TABLE

OF fs_lvbak. " Internal table to hold vbak

" records

SELECT vbeln " Sales Document Number

vkorg " Sales Organisation

vtweg " Distribution channel

spart " Division

FROM vbak

INTO CORRESPONDING FIELDS OF TABLE t_lvbak

WHERE auart EQ p_sdtype.

SELECT

vbeln " Sales Document Number

posnr " Sales document Item Number

matnr " Material

FROM vbap

INTO CORRESPONDING FIELDS OF fs_lvbak

FOR ALL ENTRIES IN t_lvbak

WHERE vbeln EQ t_lvbak-vbeln.

APPEND fs_lvbak TO t_lvbak.

CLEAR fs_lvbak.

ENDSELECT.

Former Member
0 Kudos

Hi,

Create a 3rd internal table with structure same as t1.

move all fileds in t3.

t3-a = t1-a.

t3-b = t1-b.

t3-c = t1-c.

t3-d = t2-d.

t3-e = t2-e.

this would be better for the performance too.

hope it helps.

thanx.

Pritha.

Edited by: Pritha Agrawal on Feb 11, 2009 6:54 PM

viquar_iqbal
Active Contributor
0 Kudos

Hi

I think we can move the contents of one table to another by move statement as the structure is the same . Later you can run the second select statement

Thanks

Viquar Iqbal

Former Member
0 Kudos

hi,

apply t2 = t1.

or move t1 to t2.

Former Member
0 Kudos

Use this logic

Loop at t1.

read table t2 index v_index.

t2-a = t1-a.

t2-b = t2-b.

t2-c = t2-c.

modify t2.

vindex = vindex + 1.

endloop.

Regards,

Prashant

Former Member
0 Kudos

hi.

i think first u get all entries in tab1 and tab2 by select statement with ur required condition.

then loop at tab2 and in loop read tab1 and get the fields which u want and then modify the tab2.

ThomasZloch
Active Contributor
0 Kudos

I've heard that driver and result table can be the same since 6.10, so try

select d e

into corresponding fields of table t1

from cluster_table

for all entries in t1

where condition

and please tell us if it works

Thomas

former_member404244
Active Contributor
0 Kudos

Hi,

do like this

loop at itab1.

move three fields a,b,c from itab1 to itab2

move two fields d,e from itab1 to itab3.

append itab2.

append itab3.

endloop.

now itab2 will have a,b,c and itab3 will have d and e.

Regards,

Nagaraj

Former Member
0 Kudos

Hi,

You try this code ---

loop at t1 into field_string.
MODIFY t2  INDEX sy-tabix  FROM  field_string  TRANSPORTING  a b c.
endloop.

If a ,b and c are key fields the above will not work and for that you have to declare table t2 differently means you need to define that key as TABLE KEY.

Regards

Pinaki

Edited by: Pinaki Mukherjee on Feb 11, 2009 2:46 PM

Former Member
0 Kudos

Hi,

In the query

select d e

into corresponding fields table of t2

from cluster_table

for all entries in t1

where condition you will be having atleast one common field with int tab t2.

ie. for example say 'a' is the common field, so in your query you will be having

...
for all entries in t1
where a = t1-a...

Therefore you can have your second query as

select a d e
into corresponding fields table of t2
from cluster_table
for all entries in t1
where a = t1-a ... "on the assumption that a is the common field
                         "Now t2 contains field a also 

Now you can have this logic:

loop at t2 into wa_t2.
read table t1 into wa_t1 key a = wa_t2-a.
"Move only b and c as a is ther already
wa_t2-b = wa_t1-b.
wa_t2-c = wa_t1-c.
modify t2 from wa_t2 transporting b c.
endloop.

Hope this works.

Regards,

Manoj Kumar P

Former Member
0 Kudos

Hi,

Instead of using two different select queries use inner join to fetch the data and create an internal table with all the fields you want in it.

0 Kudos

Would be nice, but "cluster_table" prevents that.

Thomas

Former Member
0 Kudos

Hi Mariano,


TYPES: BEGIN OF st_r,
             a LIKE table-a,
             b LIKE table-b,
             c LIKE table-c,
             d LIKE table-d,
             e LIKE table-e,
             END OF st_r,
 
data t1 type table of st_r.
data t2 type table of st_r.
...
 
select a b c 
   from database
   into corresponding fields table of t1
   where condition
 
select d e
   into corresponding fields table of t2
   from cluster_table
   for all entries in t1
   where condition

loop at t1 into st_r.
modify t2 index idx from st_r 
                     transporting a b c .
add 1 to idx.
 endloop. 

Regards,

Mdi.Deeba