2022 Dec 07 10:06 AM
How do I read the last entry of an internal table? Assuming that sometimes the entries of the internal is not fixed as sometime it has 1,2,3, or 4 entries.
I want to read the the last entry of T_EKBE table. Sorting the Material Document Number is prohibited as the material document numbers is not always in sequential form. Here's my code and I believe that READ TABLE only selects the first entry.
READ TABLE t_ekko_ekpo ASSIGNING FIELD-SYMBOL(<lfs_ekko_ekpo>)
WITH KEY ebeln = t_ekbe-ebeln
ebelp = t_ekbe-ebelp
waers = t_ekbe-waers
BINARY SEARCH.
Currently, the first line is being read here. I want the last line to be read instead.
2022 Dec 07 10:14 AM
2022 Dec 07 10:23 AM
Is there a reason why you need the last entry? A problem is that modern databases not always return in the right order. I had several problems when I forgot to sort the selected entries. So, I am not sure if the solution from Dominik will work if you don't have a (somehow) sorted table.
2022 Dec 07 10:44 AM
2022 Dec 07 10:47 AM
mschwingenschloegl because the last entry of T_EKBE contains latest payment made on the Purchase Order. But yeah there are better ways. Cheers!
2022 Dec 07 12:19 PM
3a9e4ce873a94034b33dc62b0ce600ee Can SORT BY and DESCENDING co-exist in a single line?
Initially, the code is like this but I need to get the latest entry by sorting its date and time so I added CPUDT, CPUTM. However, the internal table t_ekbe still is not sorted in descending order.
Initial code:
SORT t_ekbe BY ebeln ebelp.
Newly modified code:
SORT t_ekbe BY ebeln ebelp DESCENDING cpudt cputm.
2022 Dec 07 12:48 PM
walkerist As per SAP Help documentation on SORT statement, your code
SORT t_ekbe BY ebeln ebelp DESCENDING cpudt cputm.
is sorting by
If you want to sort by ebeln and ebelp ascending and by cpudt and cputm descending, you should go like:
SORT t_ekbe BY ebeln ebelp cpudt DESCENDING cputm DESCENDING.
Or better yet specify sort directions of all the fields explicitly. It's a bit superfluous as ASCENDING is the default sort direction but it is more readable.
SORT t_ekbe BY ebeln ASCENDING ebelp ASCENDING cpudt DESCENDING cputm DESCENDING.
2022 Dec 08 7:04 AM
Data lv_count type i.
Describe table t_ekko_ekpo lines lv_count
READ TABLE t_ekko_ekpo ASSIGNING FIELD-SYMBOL(<lfs_ekko_ekpo>) index lv_count.
2022 Dec 08 7:46 AM
2022 Dec 08 9:22 AM
matthew.billingham Speaking of 20th vs 21st century - SAP has introduced all those shiny new features to ABAP. Still ABAP is very space or white character sensitive, e.g.
READ TABLE t_ekko_ekpo INDEX lines( t_ekko_ekpo ) ASSIGNING FIELD-SYMBOL(<lfs_ekko_ekpo>).
is not the same as
READ TABLE t_ekko_ekpo INDEX lines(t_ekko_ekpo) ASSIGNING FIELD-SYMBOL(<lfs_ekko_ekpo>).
The latter will trigger a syntax error. It is "so 20th century" 😉
I wonder if there are any plans to improve ABAP syntax and get rid off those space dependencies.