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: 

getting last record from mseg

Former Member
0 Kudos

Hi,

Can any one tell me how to get last record from any db(MSEG) table?

reward guaranteed

kaki

1 ACCEPTED SOLUTION

roland_spindler
Participant
0 Kudos

Hello,

Entries have no "natural order" within a database, apart from the primary key. If you need the "last entry" then you need to know what defines the last entry. If the last entry is the one with the highest year (MJAHR) the you could select it like this:

data: ls_mseg type mseg.

select * from mseg into ls_mseg.

where bwart = 321

and ebeln = 400000005

and mjahr = ( select max( mjahr ) from mseg

where bwart = 321

and ebeln = 400000005 ).

"process result in ls_mseg

endselect.

Note: This is a loop because there might be more than one matching entry.

best regards

Roland

3 REPLIES 3

Former Member
0 Kudos

Please check if my answer to your previous post solves your problem.

0 Kudos

hi srinivas,

still my problem was not solved.ekbe is no use for me.

Can u tell me how to get LAST record from mseg where bwart = 321 and ebeln = 400000005.

kaki

roland_spindler
Participant
0 Kudos

Hello,

Entries have no "natural order" within a database, apart from the primary key. If you need the "last entry" then you need to know what defines the last entry. If the last entry is the one with the highest year (MJAHR) the you could select it like this:

data: ls_mseg type mseg.

select * from mseg into ls_mseg.

where bwart = 321

and ebeln = 400000005

and mjahr = ( select max( mjahr ) from mseg

where bwart = 321

and ebeln = 400000005 ).

"process result in ls_mseg

endselect.

Note: This is a loop because there might be more than one matching entry.

best regards

Roland