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: 

Internal Table related query

Former Member
0 Kudos

Hi Guys,

I have a 1st Internal Table with all shipments details.

I have 2nd internal table shipments details along with pallets details.

My 2nd Internal table looks like below.

PN TKNUM

1 1144

2 1144 and many more than this

3 1145

4 1145

I need to calculate that TKNUM 1144 has total 2 PN's and TKNUM 1145 has total 2 PN's

Thanks,

Prasad.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI,

Check this Code..

SORT itab by  TKNUM.
LOOP AT itab.

  COUNT = COUNT + 1.

AT END OF TKNUM.
"  Move total PN count to another internal table
  ITAB2-PN = COUNT.
  ITAB2-TKNUM = ITAB1-TKNUM.
  APPEND ITAB2.
  CLEAR COUNT.
ENDAT.

ENDLOOP.

8 REPLIES 8

former_member156446
Active Contributor
0 Kudos

see the help on at statement....

loop at itab into wa_itab.

at new tknum / at last tknum....etc...

count.....and move...

enddat.

0 Kudos

Hi Jay,

Thanks for your reply.

Can you give me any example.

Thanks,

Prasad.

0 Kudos

>[Click Here|https://forums.sdn.sap.com/search.jspa?q=at%20endat&dateRange=last90days&searchID=22926323&rankBy=10001&start=0]<

alternative:


loop at itab into wa_itab.
itab1[] = itab[].

delete itab1 where tknum NE wa_itab-tknum.
describe table itab1 lines lv_lines.
write: 'No. of records:', wa_itab-tknum , lv_lines.

endloop.

Former Member
0 Kudos

HI,

Check this Code..

SORT itab by  TKNUM.
LOOP AT itab.

  COUNT = COUNT + 1.

AT END OF TKNUM.
"  Move total PN count to another internal table
  ITAB2-PN = COUNT.
  ITAB2-TKNUM = ITAB1-TKNUM.
  APPEND ITAB2.
  CLEAR COUNT.
ENDAT.

ENDLOOP.

0 Kudos

Hi Avinash,

Its not working.

Let me give my internal table details once again.

PN TKNUM

8 |0000001144

8 |0000001144

8 |0000001144

8 |0000001144

7 |0000001144

7 |0000001144

7 |0000001144

7 |0000001144

I need to get count as 2 for TKNUM .

Plz can you let me know.

Thanks,

Prasad.

Private_Member_14913
Contributor
0 Kudos

Hello,

You can do this way.

Loop at 2nd internal table.

At new TKNUM.

if flag is initial. " at 1st loop also AT new control break event occurs.

" 1st loop pass count should not be displayed

write:/ count, tknum.

endif.

flag = 'X'.

endat.

count = count + 1.

endllop.

Regards,

Sameer

0 Kudos

Thanks for ur answer sameer.

Prasad.

Former Member
0 Kudos

Thanks to all....