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

Internal Table

Former Member
0 Likes
1,138

Hi experts,

Im new to ABAP. I have probelm with my internal table. Consider the following example.

My First Internal Table following structure and Data's.

Mat_name Qty Unit_Price

Pen 5 6.00

Pencil 2 3.00

In second Internal table structure is,

Mat_name Qty Unit_Price Net_price

My requirement is I need to calculete the net_price using Qty and Unit_price.

For material Pen ( 5 * 6.00 ) = 30.00(net_price).

So my Final internal table datas sholud be stored like,

Mat_name Qty Unit_Price Net_price

Pen 5 6.00 30.00

Pencil 2 3.00 6.00

How can I do that. Any body give me your valuable suggestions.

Thanks,

Points assured.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,122

hi

first of all ,

<b>move itab1 to itab2</b> after that

<b>loop at itab2

itab2-netprice = ( itab2-qty * itab2-price)

modify itab index sy-tabix

endloop.</b>

13 REPLIES 13
Read only

Former Member
0 Likes
1,122

HI,


LOOP AT first_itab INTO struct1.
struct2-matname = struct1-matname.
struct2-qty = struct1-qty.
struct2-netprice = struct1-unit * struct1-qty.
append struct2 TO second_itab.
clear struct2.
ENDLOOP.

rgs

Read only

Former Member
0 Likes
1,122

Hi.. use this

Loop at itab1.

wa_itab2-mat = itab1-mat.

wa_itab2-qunt = itab1-qunt.

wa_itab2-unitp = itab1-unitp.

wa_itab2-netp = itab1-qunt * itab1-unitp.

append wa_itab2 to itab2.

clear wa_itab2.

endloop.

Read only

Former Member
0 Likes
1,122

loop at itab.

itab_new-name = itab-name.

itab_new-qty = itab-gty.

itab_new-unit = itab-unit.

itab_new -net = itab-unit * itab-gty.

append itab_new .

clear itab_new.

endloop.

Read only

Former Member
0 Likes
1,122

if ur itab is already populated with all other fields except net_price....the use...

loop at itab.

itab-Net_price = itab-qty * itab-unit_price.

modify itab index sy-tabix.

endloop.

Read only

Former Member
0 Likes
1,123

hi

first of all ,

<b>move itab1 to itab2</b> after that

<b>loop at itab2

itab2-netprice = ( itab2-qty * itab2-price)

modify itab index sy-tabix

endloop.</b>

Read only

0 Likes
1,122

Hi,

Thanks for the replies.

My Internal tables don't have the header line.

That is the probelm.

Thanks.

Read only

0 Likes
1,122

loop at itab1 into wa.

wa-net_price = ( wa_qty * wa-unit_price ).

modify itab index sy-tabix from wa.

endloop.

Read only

0 Likes
1,122

Hi

declare work areas for both internal tables n use this code

Loop at itab1 into wa_itab1.

wa_itab2-mat = wa_itab1-mat.

wa_itab2-qunt = wa_itab1-qunt.

wa_itab2-unitp = wa_itab1-unitp.

wa_itab2-netp = wa_itab1-qunt * wa_itab1-unitp.

append wa_itab2 to itab2.

clear wa_itab2,wa_itab1.

endloop.

<b>please reward if helpful</b>

Read only

Former Member
0 Likes
1,122

Hi,

loop at itab into wa.

wa-net_price = wa-qty * wa-unit_price.

append wa-net_price to itab.

endloop.

rewards if useful

kavitha

Read only

Former Member
0 Likes
1,122

Hi,

follow the sample code.

loop at itab1.

itab2-Mat_name = itab1-Mat_name.

itab2-Qty = itab1-Qty.

itab2-Unit_Price = itab1-Unit_price.

itab2-Net_price = itab1-Unit_price * itab1-Qty.

append itab2.

clear: itab1,

itab2.

endloop.

loop at itab2.

write:/ itab2-Mat_name,

itab2-Qty,

itab2-Unit_Price,

itab2-Net_price,

clear itab2.

endloop.

pls reward if needful.

Thanks,

Sreeram.

Read only

Former Member
0 Likes
1,122

Hi Jasmine,

Let the first Internal table be itab1 and second one be itab2

Code:

DATA: wa_itab LIKE LINE OF itab2.

LOOP AT itab1 INTO wa_itab.

wa_itab-Net_price = wa_itab-Qty * wa_itab-Unit_Price.

INSERT wa_itab INTO TABLE itab2.

END LOOP.

Thanks

Ravi

Read only

Former Member
0 Likes
1,122

Hi,

Check this simple program..


DATA : BEGIN OF itab OCCURS 100,
        matnr type eban-matnr,
        menge type eban-menge,
        price(10) type p decimals 2,
       END OF itab.

DATA : BEGIN OF itab2 OCCURS 100,
        matnr type eban-matnr,
        menge type eban-menge,
        price(10) type p decimals 2,
        total(10) type p decimals 2,
       END OF itab2.

itab-matnr = 'PEN'.
itab-menge = '5'.
itab-price = '6.00'.
APPEND itab.

itab-matnr = 'PENCIL'.
itab-menge = '2'.
itab-price = '3.00'.
APPEND itab.

LOOP AT itab.
itab2-total =  itab-menge * itab-price .
MOVE-CORRESPONDING itab to itab2.
APPEND itab2.
ENDLOOP.

Read only

Former Member
0 Likes
1,122

Hi jasmine,

Loop at first_int_table.

second_int_table-mat_name = first_int_table-mat_name.

second_int_table-qty = first_int_table-qty.

second_int_table-unit_price = first_int_table-unit_price.

second_int_table-net_price = first_int_table-qty * first_int_table-unit_price.

ENDLOOP.

loop at second_int_table.

write:/ second_int_table-mat_name ,

second_int_table-qty,

second_int_table-unit_price.

second_int_table-net_price.

endloop.