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

divide fields from 2 tables

Former Member
0 Likes
796

hallow

i have 2 difrent tables (itab_1,itab_2)with fields from a1....a12 and i wont to divide all the fields from itab_1 and itab_2 and put them in itab 3

what is the best way to do that

i give example

itab1

a1--a2-a3---a4.....

10--20-30---40

itab2

b1--b2b3---b4......

2----2--4-----5

<b>itab3 <----


result of divide fileds c1=a1/b1</b>

c1--c2c3---c4......

5----10-7.5--8

Regards

<b>i reward</b>

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
764

Hi!

If you don't have keys in the tables, but the lines are exatly in the same row, then you could use this way:

LOOP AT it1.

READ TABLE it2 INDEX sy-tabix.

CLEAR it3.

it3-c1 = it1-a1 / it2-b1.

it3-c2 = it1-a2 / it2-b2.

...

APPEND it3.

ENDLOOP.

Regards

Tamá

7 REPLIES 7
Read only

Former Member
0 Likes
764

HI,

do like this.

loop at itab1.

read table itab2 index sy-index.

itab3-c1 = itab1-a1 / itab2-b1.

itab3-c2 = itab1-a2 / itab2-b2.

itab3-c3 = itab1-a3 / itab2-b3.

itab3-c4 = itab1-a4 / itab2-b4.

append itab3.

endloop.

reward if helpful

rgds,

bharat.

Read only

Former Member
0 Likes
765

Hi!

If you don't have keys in the tables, but the lines are exatly in the same row, then you could use this way:

LOOP AT it1.

READ TABLE it2 INDEX sy-tabix.

CLEAR it3.

it3-c1 = it1-a1 / it2-b1.

it3-c2 = it1-a2 / it2-b2.

...

APPEND it3.

ENDLOOP.

Regards

Tamá

Read only

Former Member
0 Likes
764

data: my_tabix like sy-tabix.

loop at itab1.

my_tabix = sy-tabix.

read table itab2 index my_tabix.

if sy-subrc eq 0.

itab3-c1 = itab1-a1 / itab2-b1.

itab3-c1 = itab1-a1 / itab2-b1.

itab3-c1 = itab1-a1 / itab2-b1.

....

append itab3

endif.

endloop.

Reward points if useful, get back in case of query...

Cheers!!!

Message was edited by:

Tripat Pal Singh

Read only

Former Member
0 Likes
764

Try this,

loop at t_a.

read TABLE t_b index sy-index.

t_c-c1 = t_a-a1 / t_b-b1.

t_c-c2 = t_a-a2 / t_b-b2.

t_c-c3 = t_a-a3 / t_b-b3.

append t_c.

ENDLOOP.

Regards,

Vimal

Read only

Former Member
0 Likes
764

Forget everything,

Just use:

DIVIDE-CORRESPONDING ITAB1 BY ITAB2.

      • Plz reward if u find it useful

Read only

Former Member
0 Likes
764

Hi

loop at itab1.
my_tabix = sy-tabix.
read table itab2 index my_tabix.
if sy-subrc eq 0.
itab3-c1 = itab1-a1 / itab2-b1.
itab3-c1 = itab1-a1 / itab2-b1.
itab3-c1 = itab1-a1 / itab2-b1.
....
append itab3
endif.
endloop.

reward if usefull

Read only

Former Member
0 Likes
764

Hi

or try like this

LOOP AT itab1.
READ TABLE itab2 INDEX sy-tabix.
itab3-c1 = itab1-a1 / itab2-b1.
itab3-c2 = itab1-a2 / itab2-b2.
itab3-c3 = itab1-a3 / itab2-b3.
itab3-c4 = itab1-a4 / itab2-b4.
APPEND itab3.
CLEAR itab3
ENDLOOP.

reward if useful