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

select question

Former Member
0 Likes
1,180

Hi experts,

i need to do select from pa0001 where pernr = ....and

begda is the most new date

i mean if there is a row in pa0001 like this:

begda = 1.1.2009

pernr = 1234

begda = 2.2.2009

pernr = 1234

so he take the second row.

any help will be appreciated.

thanks.

Michal.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,147

Dear Michal,

You can select record as desending or max(field).

Try with this in your select query. may this will help you solve your problem.

Regards,

vijay

10 REPLIES 10
Read only

Former Member
0 Likes
1,147

hi

first short table by begda decending

now select single where <ur condition>

or select ..........upto 1 rows.

Edited by: mayank jain on May 26, 2009 12:03 PM

Read only

Former Member
0 Likes
1,147

Hi,

If you want all ways the latest entery for the PA0001 use endda = '99991231'.

else if you want the latest entey of today use begda <= sy-datum AND endda >= sy-datum.

Read only

Former Member
0 Likes
1,148

Dear Michal,

You can select record as desending or max(field).

Try with this in your select query. may this will help you solve your problem.

Regards,

vijay

Read only

Former Member
0 Likes
1,147

Try this.

tables pa0001.

select * from pa0001

up to 1 ROWS

order by begda DESCENDING.

write: / pa0001.

endselect.

Thanks,

Mahesh

Read only

Former Member
0 Likes
1,147

Hi,

Use this select statement.

select max( begda ) from pa0001 into v_begda.

Read only

agnihotro_sinha2
Active Contributor
0 Likes
1,147

hi,

Select all records......... sort BEGDA......... then delete duplicate records.

select * from PA0001

order by begda descending.

delete duplicate comparing PERNR.

ags.

Read only

Former Member
0 Likes
1,147

Check the code Below


parameters p_pernr like pa0001-pernr.

data:
  begin of wa,
    pernr like pa0001-pernr,
    begda like pa0001-begda,
  end of wa.

data v_begda like pa0001-begda.


select max( begda )
from pa0001
into v_begda
where pernr = p_pernr.
if sy-subrc eq 0.
  select single pernr begda
  from pa0001
  into wa
  where pernr = p_pernr and
        begda = v_begda.
  write: wa-pernr,wa-begda.
endif.

Read only

Former Member
0 Likes
1,147

hi,

just a sample code, try this

data: begin of itab occurs 0,

mblnr type mseg-mblnr,

bwart type mseg-bwart,

flag type c,

end of itab.

select mblnr

bwart

into CORRESPONDING FIELDS OF TABLE itab

from mseg

where mblnr = '0049000000'.

SORT itab by mblnr bwart DESCENDING.

loop at itab.

on CHANGE OF itab-mblnr.

itab-flag = 'N'.

MODIFY itab.

endon.

ENDLOOP.

delete itab where flag is INITIAL.

Read only

0 Likes
1,147


select pernr 
  from pa0001
  where pernr = 'Employee Number' and
         begda <= sy-datum and 
         endda >= sy-datum.
Read only

Former Member
0 Likes
1,147

Hi,

While selecting itself you can restrict by using the max( ) function.