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: 

HOW TO FETCH PREVIOUS RECORD FROM THE PREVIOUS DATE WHICH HAS RECORD

former_member788072
Discoverer
0 Kudos

HOW TO FETCH PREVIOUS RECORD FROM THE PREVIOUS DATE WHICH HAS RECORD

SUPPOSE THE 5/10/2020 HAS A RECORD AND 6/10/2020 , 7/10/2020 DOESNT HAVE ANY VALUE/RECORD
HOW TO PASS THE PREVIOS DATE RECORD INTO THE NEXT DAYS RECORDS IF THEY ARE EMPTY ?

1 ACCEPTED SOLUTION

ThorstenHoefer
Active Contributor
0 Kudos

Hi ramprakashs,

please try following:

field-symbols: <wa_last> type any.

select *
 from yourtable
into @data(lt_data)
order by ...

loop at lt_data assigning field-symbol(<wa_data>)
  if <wa_last> is not initial.
     <wa_data>-last = <wa_last>-current.
  endif.
  assign <wa_data> to <wa_last>.
endloop.

In HANA sql, you can use also window functions

https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.00/en-US/20a353327519101495dfd0a870...

5 REPLIES 5

FredericGirod
Active Contributor
0 Kudos

Don't write in upper case

Don't ask for someone doing your job

You could ask for help, but it meens you already have started a solution, and you could post this solution using the [code] button.

This is not so complex, I am pretty sure you could imagine a way of solving this issu

ThorstenHoefer
Active Contributor
0 Kudos

Hi ramprakashs,

please try following:

field-symbols: <wa_last> type any.

select *
 from yourtable
into @data(lt_data)
order by ...

loop at lt_data assigning field-symbol(<wa_data>)
  if <wa_last> is not initial.
     <wa_data>-last = <wa_last>-current.
  endif.
  assign <wa_data> to <wa_last>.
endloop.

In HANA sql, you can use also window functions

https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.00/en-US/20a353327519101495dfd0a870...

0 Kudos

Thank you Thorsten.

BiberM
Active Participant
0 Kudos

Alternatively instead of looping afterwards you could do this in ABAP SQL directly:

select *
from yourtable
where keydate <= @iv_key_date
order by keydate descending
into @data(lt_data)
up to 1 rows.
endselect.

Depending on your other key fields in your table you might need a subquery.

0 Kudos

Thank you Michael.