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

ABAP SQL query on

Former Member
0 Likes
877


Hi,

     Can anyone tell me what is the SELECT statement for getting the latest time records based on date and other parameter.

Table data
DATETIMESOURCEDESTPRDQTY
10.03.201413:18:51UHAABDHDXCC17B1,000.00
10.03.201413:24:56UHAABDHDXCC17B3,000.00
10.03.201413:24:56UHAABDHDXCC16B1,000.00
11.03.201413:18:35UHAABDHDXCC17B1,000.00
11.03.201413:24:20UHAABDHDXCC17B3,000.00
11.03.201413:24:30UHAABDHDXCC17B1,000.00
11.03.201413:24:30UMECHKHDXCC17B1,000.00
11.03.201413:24:30UMECHKHDXCC16B1,000.00

My selection screen input as

Input
Source locUHAUME
Dest locABDHCHKH
Date10.03.201411.03.2014

Output must be

Source and destination and date wise latest time records shoul be extracted by SELECT Statment.

Expected output as below

Output
DATETIMESOURCEDESTPRDQTY
10.03.201413:24:56UHAABDHDXCC17B3,000.00
10.03.201413:24:56UHAABDHDXCC16B1,000.00
11.03.201413:24:30UHAABDHDXCC17B1,000.00
11.03.201413:24:30UMECHKHDXCC17B1,000.00
11.03.201413:24:30UMECHKHDXCC16B1,000.00

Thanks

Ajit

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
847


Hi,

   thanks for attending my query .

   I got the answer & it is working.  I Will  check further with more records and cases.

     select * from <database table>

                  into table <Internal table>

                  where source in s_source

                   and desti in s_dest
                   and date in s_date
                   and time in ( select max( time ) from  <database table> group by date ).

Regards,

Ajit

6 REPLIES 6
Read only

vigneshwar_reddy
Active Participant
0 Likes
847


Hi Ajit,

You can use statement like below.

select * from table up to 5 rows into corresponding fields of it_table

               where XXXXXXXXXXX

               order by date descending time descending.

Regards,

Vigneshwar

Read only

Former Member
0 Likes
847

Hi Ajit,

As Vigneshwar puts it:

select date time source dest prd qty

          from <table> up to 5 rows

     into corresponding fields of <internal table>

where date in sel_date

and source in sel_source

and dest     in sel_dest

order by date descending time descending.

Read only

0 Likes
847

Hi,

   I don't want records in descending order. If you see my example give above, you can find the no. of records in the database table and my expected results are different.

I want based on the input selection (i.e. Input Date wise) it should fetch the latest time records, then it should fetch all records of latest time.

So In my input i have given  date range as 10 & 11. and For the date 10 and 11th, ther are 2 and 3 different time set of records are there. Finally it should getch latest time records for 10th and 11th date.

Regards,

Ajit

Read only

Former Member
0 Likes
848


Hi,

   thanks for attending my query .

   I got the answer & it is working.  I Will  check further with more records and cases.

     select * from <database table>

                  into table <Internal table>

                  where source in s_source

                   and desti in s_dest
                   and date in s_date
                   and time in ( select max( time ) from  <database table> group by date ).

Regards,

Ajit

Read only

RaymondGiuseppi
Active Contributor
0 Likes
847

Did you find my answer(s) in select entire fields with aggregate functions (max,...) and similar threads.

Regards,
Raymond

Read only

asim_isik
Active Participant
0 Likes
847

SORT itab by DATE SOURCE DEST PRD QTY.

DELETE ADJACENT DUPLICATES FROM itab comparing DATE SOURCE DEST PRD QTY.