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: 

reg :sorting of internal table

Former Member
0 Kudos

Hi all ,

I have requirement of having to take the latest creation date from the internal table .In the internal table i have multiple batch numbers for a particular plant and material number .I want to take one record for each material-batch combination for the given plant.So i have taken the field creation date as criteria .But how to take a single record if there are mutliple records having different batch numbers but same plant and material number .

data :itab_mchb TYPE STANDARD TABLE OF MCHB WITH HEADER LINE.

SORT itab_mchb DESCENDING BY ersda.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You can use the following sample code:

data :itab_mchb TYPE STANDARD TABLE OF MCHB WITH HEADER LINE,

wa_mchb type mchb,

itab_mchb1 TYPE STANDARD TABLE OF MCHB WITH HEADER LINE.

SORT itab_mchb DESCENDING BY ersda descending.

loop at itab_mvhb.

move-corresponding itab_mvhb into wa_mchb.

at new matnr.

append wa_mchb to itab_mchb1.

endat.

endloop.

just check the structure of mchb.

Thanks and Regards,

Saurabh Chhatre

6 REPLIES 6

Former Member
0 Kudos

hi

u can use MIN and MAX funtion to get the smaaleest date on that field of ur table

Cheers

Snehi

0 Kudos

can you please give a sample code for min and max functions .dont how to use it .

thanx in advance.

Former Member
0 Kudos

Hi,

After SORTING use INDEX to read data..

Link

http://help.sap.com/saphelp_nw70/helpdata/en/9f/db9eaa35c111d1829f0000e829fbfe/content.htm

Regards,

anirban

former_member188685
Active Contributor
0 Kudos

SORT itab_mchb DESCENDING BY matnr werks charg ersda DESCENDING.

delete adjacent dfuplicates from itab_mchb comparing matnr werks.

Former Member
0 Kudos

Hi,

You can use the following sample code:

data :itab_mchb TYPE STANDARD TABLE OF MCHB WITH HEADER LINE,

wa_mchb type mchb,

itab_mchb1 TYPE STANDARD TABLE OF MCHB WITH HEADER LINE.

SORT itab_mchb DESCENDING BY ersda descending.

loop at itab_mvhb.

move-corresponding itab_mvhb into wa_mchb.

at new matnr.

append wa_mchb to itab_mchb1.

endat.

endloop.

just check the structure of mchb.

Thanks and Regards,

Saurabh Chhatre

Former Member
0 Kudos

Dear Ambarish

usee as follows

SORT itab_mchb DESCENDING BY ersda.

read table itab_mchb INDEX sy-index INTO wa_mchb.

then you can find 1st record in wa_mchb.

wa_mchb should be same structure like itab_mchb.

Rewards if helpful.