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 loop in ABAP CDS for a join

0 Kudos
4,867

Hi,

I need to join matdoc table to mbewh table with matnr (material number) in both tables and matdoc.werks (plant) to mbewh.bwkey and alongwith that, I need to pass year and month part of matdoc.budat to lfgja(posting year) and lfmon (posting month) in mbewh(budat gives calendar date while lfgja/lfmon are posting year and month respectively as per financial year but I convert this in previous cds views) and fetch salk3 and lkmon from mbewh. Straightforward so far if I substring budat to fetch the month and year.

Now the issue is that not all values of lfmon/lfgja combinations are present in the mbewh table. In this case, I need to find the last prior entry where lfmon/lfgja combination is populated and fetch the values for these.

Typically in coding this would use a loop. Is there a way to replicate this in ABAP CDS?

What I observe is that since lfmon and lfgja are joins, I cannot do a calculation in the view where I have made the join and if lfmon and lfgja are not added to join, then all possible values are brought in which would mean unnecessary and incorrect data being brought in.

So how do I create the loop that would bring me the last populated values for the posting year and month to fetch the respective values I am looking for?

Regards,

Tejaswini

2 REPLIES 2

Harit_Bhasin
Explorer
0 Kudos
625

Hello Tejaswini,

Did you get the solution for this?

Regards,

Harit Bhasin

0 Kudos
625

Hello Tejaswini,

I did a join with scal_tt_date and kept a restriction on year to keep low number of records.