2018 Nov 01 3:12 PM
Hi expert I have requirement to read the last sales amount for each MTNR
matnr werks Sales Priode
mat1 unit1 100 2018
mat2 unit1 200 2018
mat1 unit1 300 2017
I am trying to do
loop at lt_final into ls_final.
read lt_final into ls_final_1 index 1.
insert ls_final_1 into table lt_final_1.
endloop.
but it is not working.....:(
could someone guide to achieve this
Best Regards
Jenie
2018 Nov 01 3:19 PM
2018 Nov 01 3:19 PM
2018 Nov 02 8:59 AM
This is exactly what I will do, but one a little more question, if I want to select the last three records and not just the last one, What should be done in this case..?
2018 Nov 02 6:29 PM
2018 Nov 01 3:32 PM
Hi,
You're looping at a table with X amounts of records, which means the statement between loop and endloop will be executed X amount of times.
Then you read the first entry and insert that in another table X amount of times.
I suggest to position the cursor on every statement, press F1, read what it says. Then go to ABAPDOCU or DWDM transaction and spend a couple of days to get acquainted with the programming language.
Then rethink what you are trying to achieve and how the programming language can be used in getting your result.
Kind regards, Rob Dielemans
2018 Nov 02 8:57 AM
2018 Nov 01 4:51 PM
2018 Nov 02 3:22 PM
2018 Nov 02 12:29 AM
LOOP AT...GROUP BY with key is MATNR then you have group for each MATNR. loop through group and using nmax function to get the biggest amount; or without loop just get all data of group into internal table, sort it and get the first one. just about 5 lines of code.
2018 Nov 02 3:22 PM
2018 Nov 02 3:57 PM
Use like below Code .
sort lt_final by matnr & Date .
loop at lt_final into ls_final.
at new matnr . " After sort with date & material fist row is latest row . you can read first of every materiel row from use at new .
appen ls_final into table lt_final_1.
endat .
endloop.