cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Abap code to get data from table EKKO

MSadri
Participant
0 Likes
1,866

Hi,

I am trying to check supplier purchasing history from table EKKO.

Unfortunately data is too huge to output in Excel or flat file. 

I am trying to write query in SQ02 to sort data in table EKKO according to its creation date and then select one row per supplier with latest PO date.

I am not quite familiar with ABAP so struggling to write the code.

Can someone please help or guide on this ?

SELECT LIFNR FROM EKKO
WHERE LIFNR EQ 'XXXX'.

In above statement its saying INTO is missing but I don't want to insert data I just want to modify selection criteria and output table.

Br,

Murtuza

View Entire Topic
lou_
Explorer

Hello MSadri ,

I'm not sure if I understand clearly your need, but if the goal is to have a query with one row per supplier with his latest PO creation date you can do as follow:

First create your Infoset in SQ02 with table EKKO (like you seem already did).

Next, go to Extra/Code:

1.png

In this area put the following code:

field-symbols <output_table> type any table.

assign ('%G00[]') to <output_table>. " %G00[] represent the final alv

sort <output_table>
  descending by   " To get the latest date on top
  ('EKKO-LIFNR')  " Supplier's account number
  ('EKKO-AEDAT'). " Creation date

" Keep the first line (with latest PO creation based on previous sort) and
" delete all the duplicate line comparing supplier's account number
delete adjacent duplicates from <output_table>
  comparing ('EKKO-LIFNR').

I choose LIFNR and AEDAT but it can be any fields in EKKO table.

You must add this fields in the corresponding field group (SQ02), and you must check the fields for displaying it in you final view (SQ01), if you don't you will get a dump.

2.png3.png

Regards.