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

determine youngest date

Former Member
0 Likes
909

Hello!

Can this following code work with this logic to determine the

youngest date ?

Regards

Ilhan

DATA it_hs TYPE ty_hsnr occurs 0 with header line.          
DATA wa_hs TYPE ty_hsnr.     
                               
FORM hsnr_determine using mater type MATNR
                    changing nr type stawn.
 select matnr valid stawn from /G2A/LDM_VL_MAT
          into table it_hs WHERE
          MATNR = mater .
<b>sort it_hs by VALID.</b>
read table it_hs INTO wa_hs INDEX 1 .
nr = wa_hs-STAWN.
ENDFORM.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
856

sort it_hs by VALID

i dont know what u mean by youngest date ?

but

1.

sort it_hs by VALID

will give the old date ( previous date " -->before )

2.sort it_hs by VALID descending.

will give u the latest date ( recent used date )

Hello!

Can this following code work with this logic to determine the

youngest date ?

Regards

Ilhan

DATA it_hs TYPE ty_hsnr occurs 0 with header line.          
DATA wa_hs TYPE ty_hsnr.     
                               
FORM hsnr_determine using mater type MATNR
                    changing nr type stawn.
 select matnr valid stawn from /G2A/LDM_VL_MAT
          into table it_hs WHERE
          MATNR = mater .
<b>sort it_hs by VALID.</b>
read table it_hs INTO wa_hs INDEX 1 .
nr = wa_hs-STAWN.
ENDFORM.

6 REPLIES 6
Read only

Former Member
0 Likes
856

Hi IIhan,

If you sort the internal table in ascending order with repect to the Valid date and read the first index, then it should return you data corresponding to oldest date.

If you sort the internal table in descending order with repect to the Valid date and read the first index, then it should return you data with the latest date.

Regards,

George

    • reward for all helpful tips

Read only

Former Member
0 Likes
857

sort it_hs by VALID

i dont know what u mean by youngest date ?

but

1.

sort it_hs by VALID

will give the old date ( previous date " -->before )

2.sort it_hs by VALID descending.

will give u the latest date ( recent used date )

Read only

0 Likes
856

For Youngest / recent date you should use

SORT <itab> BY <Field> DESCENDING.

This will bring the row with largest date on the first row.

Now you can do a READ on the first row.

READ TABLE <itab> INDEX 1.

Hope it will help.

Vishal

Read only

Former Member
0 Likes
856

Hi.....

if u write

<b>sort it_hs by VALID</b>

here first record will give u the oldest date.

and if u write

<b>sort it_hs by VALID descending </b>

here first record will give u the youngest date.

Reward points if useful......

Suresh......

Read only

Former Member
0 Likes
856

Hi,

If u want the latest date then u must sort the table byu descending in addition this will give u the latest date if index is 1,other wise u have to read the valid from

the last index .

Regards,

Ravi

Read only

Former Member
0 Likes
856

THOUGH SORT COMMAND WILL SORT IN ASCENDING ORDER BURT FOR YOUR REQUIREMENT YOU CAN ADD ASCENDING OPTION IN SORT ALSO.

sort it_hs by VALID ASCENDING.

read table it_hs INTO wa_hs INDEX 1 .

IT WILL GIVE YOU THE DATA WITH SMALLEST DATE.

REGARDS

SHIBA DUTTA