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

first record from itab

Former Member
0 Likes
1,259

hi experts,

i have many items and many values for those items .but i want to take the first value of each item in an internal table .

example

item1 100

item1 50

item1 200

item2 300

item2 100

i want to take

item1 100

item2 300

what is the code for it .

at new item.it is not printing the value.what to do ?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,237

Hi,

Sort itab by item

At new item

read table itab with key item = xxxx binary search.

Don't forget to reward if useful...

hi experts,

i have many items and many values for those items .but i want to take the first value of each item in an internal table .

example

item1 100

item1 50

item1 200

item2 300

item2 100

i want to take

item1 100

item2 300

what is the code for it .

at new item.it is not printing the value.what to do ?

11 REPLIES 11
Read only

Former Member
0 Likes
1,237

Hi,

U can use like this,

loop at <itab1>.

loop at <itab2> upto 1 row.

...

endloop.

endloop.

Regards,

Padmam.

Read only

Former Member
0 Likes
1,237

hi,

here ATNew doesnt work out.

U can go for ON CHANGE OF FIELD1.

Revert back if any issues,

Reward with points if helpful ,

Regards,

Naveen

Read only

Former Member
0 Likes
1,237

hi

for this you can use the control break statement <b>AT NEW</b> or <b>ON CHANGE OF<field1>

</b>

Thanks

Ashu

Message was edited by:

Ashu

Read only

Former Member
0 Likes
1,237

Hello,

Do like this.

data: wa_itab like itab,
        itab1 like itab occurs 0 with header line.
sort itab by item.
loop at itab.
wa_itab = itab.
at new item.
move-corresponding wa_itab to itab1.
append itab1.
endat.
endloop.
loop at itab1.
write: itab1-item , itab1-value.
endloop.

If useful reward.

Vasanth

Read only

Former Member
0 Likes
1,237

Hi manikandan ,

if u use at new ,the values will not display rather it willl dispaly as ****. to avoid this copy to another work area and then loop it .

reward points if useful

reena

Read only

Former Member
0 Likes
1,237
sort itab by fld1 fld2.

loop at itab.
 at new fld1.
  read table itab index sy-tabix.
  write : itab-fld1 , itab-fld2.
 endat.
endloop.
Read only

Former Member
0 Likes
1,237

data : wtab like itab,

ifinal like itab occurs 0 with header line.

sort itab by item.

loop at itab.

move-corresponding itab to wtab.

at new.

append wtab to ifinal.

endat.

endloop.

now check ifinal.

regards

shiba dutta

Read only

Former Member
0 Likes
1,237
sort  itab by  item .
loop at itab  .
At new  item.

move  itab to  itab1.
endat .
endloop.

Reward points if it is usefull ..

Girish

Read only

Former Member
0 Likes
1,237

Hi Manikandan,

Kindly check the structure of the table , that meams the field which is storing ITEM1 ITEM2 etc. should be the first field in the table or all the fields which are to the left of the field should change when this field is changing.

You can check in debugging what is exactly happening.

If you do not want to change the structure of the table just sort the table by that field and perform delete adjacent duplicates comparing the same field.

For any further queries please revert back.

Regards,

Saurabh

Read only

Former Member
0 Likes
1,238

Hi,

Sort itab by item

At new item

read table itab with key item = xxxx binary search.

Don't forget to reward if useful...

Read only

Former Member
0 Likes
1,237

hi,

You can use

sort itab by item

ON CHANGE OF ITAB-ITEM.

READ TABLE ITAB WITH KEY ITEM = XXXXX BINARY SEARCH.

ENDON.