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
591

I have an internal table

I need to move selected records into another internal table

the criteria is to check bsid-xblnr and if two or more records have same xblnr then sum bsid-wrbtr

Eg

Record no bsid-xblnr bsid-wrbtr

1 111 10

2 111 20

3 111 5

I need to make this one record and move to another internal table

record no bsid-xblnr bsid-wrbtr

1 111 35

How can I do this

8 REPLIES 8
Read only

Former Member
0 Likes
573

hi,

loop at itab.

at end of xblnr.

collect...

endat.

endloop.

regards,

madhumitha

Read only

Former Member
0 Likes
573

loop at itab into wa.
  wa2-wrbtr = wa2-wrbtr + wa-wrbtr.
  wa2-xblnr = wa-xblnr.
  at new xblnr.
    append wa2 to itab2.
    clear wa2.
  endat.
endloop.
Read only

prasanth_kasturi
Active Contributor
0 Likes
573

hi,

do the following

loop at bsid.

at new xblnr.

sum.

move-corresponding bsid to <2nd itab>.

endat.

endloop.

check the following code

i populated the table according to your example, you query a SELECT statement according your need

TABLES : bsid.

DATA : BEGIN OF itab OCCURS 0,

xblnr LIKE bsid-xblnr,

wrbtr LIKE bsid-wrbtr,

END OF itab,

BEGIN OF itab1 OCCURS 0,

xblnr LIKE bsid-xblnr,

wrbtr LIKE bsid-wrbtr,

END OF itab1.

itab-xblnr = 111 .

itab-wrbtr = 10 .

APPEND itab.

CLEAR itab.

itab-xblnr = 111 .

itab-wrbtr = 20 .

APPEND itab.

CLEAR itab.

itab-xblnr = 111 .

itab-wrbtr = 5 .

APPEND itab.

CLEAR itab.

LOOP AT itab.

AT NEW xblnr.

SUM.

MOVE : itab-xblnr TO itab1-xblnr,

itab-wrbtr to itab1-wrbtr .

APPEND itab1.

endat.

ENDLOOP.

LOOP AT itab1.

WRITE : itab1-xblnr,

itab1-wrbtr.

ENDLOOP.

regards

prasanth

Read only

Former Member
0 Likes
573

loop at bsid.

if xblnr = itab1-xblnr.

itab1-wrbtr1 = itab1-wrbtr + itab1-wrbtr.

else.

itab1-wrbtr1 = itab1-wrbtr.

endif.

dont use same as like what i told.

use the logic.

Read only

Former Member
0 Likes
573

Hello,

Do this:


data: bsid2 like bsid[],
  ls_bsid like line of bsid.

sort bsid by xblnr.
loop at bsid into ls_bsid.
  collect ls_bsid into bsid2.
endloop.

.

Regards,

Read only

Former Member
0 Likes
573

loop at itab.

itab1 = itab.

collect itab1.

clear itab.

endloop.

Regards,

madan.

Read only

Former Member
0 Likes
573

Hi,

Use the below logic.

data: v_xblnr type bsid-xblnr,

v_count type bsid-wrbtr,.

v_flag.

read table itab index 1.

v_xblnr = itab-xblnr.

loop at itab.

if v_xblnr <> itab-xblnr.

v_xblnr = itab-xblnr.

itab1-wrbtr = v_count.

append itab1.

clear: itab1, v_count, v_flag.

endif.

v_count = v_count + itab-wrbtr.

if v_flag = ' '.

itab1-record = itab-record.

itab1-xblnr = itab-xblnr.

endif.

v_flag = 'X'.

endloop.

Read only

asik_shameem
Active Contributor
0 Likes
573

Hi

Do in this way.Here gt_itab will have final values.

LOOP AT gt_bsid INTO gw_bsid.
  COLLECT gw_bsid TO gt_itab.
ENDLOOP.