‎2021 Nov 30 11:33 AM
‎2021 Nov 30 11:40 AM
Hi Ahmad,
what do u mean by second-to-last please clarify more
Thanks
‎2021 Nov 30 11:55 AM
For example, I have these
11384474
11333125
11648595
11648594
11405886
11354018
11648593
11648591
27547272
27547271
27547270
27547269
I want to get the max number but the second ( 27547270 )‎2021 Nov 30 12:06 PM
Hi Ahmad
you can try something like
SELECT MAX( VBRK~VBELN ) INTO ( v_VBELN )
FROM VBRK
WHERE VBRK~VBELN < ( SELECT MAX( VBRK~VBELN )
FROM VBRK ).
you may need to sort Ascending or Descending you can check base on result.
Please reward if was helpful to you.
Thanks.
‎2021 Nov 30 12:24 PM
Gave me the last number 27547269 but I need the second last 27547270
SELECT MAX( CDPOS~CHANGENR ) INTO NLL‎2021 Nov 30 12:34 PM
i have tested my query it is working perfect. if it is giving last number then try to run the query without the
where condition only use the MAX what value will get ?
make sure that TABKEY LIKE '%100010' is not causing any conflict. try to run the query without many condition so you can trace
‎2021 Nov 30 1:21 PM
‎2021 Nov 30 1:52 PM
Dear Ahmad
in your list you have the value 27547272 which is bigger than 27547269 , 27547270 , 27547271
so the max value in your list is 27547272 the second last is 27547271
Thanks
‎2021 Nov 30 2:52 PM
Good candidate for a Window function (many blog posts), depends which ABAP version you're running. In older ABAP versions, you can still do it with classic ABAP code. I guess your query is more complex than the one you ask (max value of all lines of the table), so if you provide it, people could better answer.
‎2021 Nov 30 2:53 PM
Did you try with
order by 'your_column'
up to
2 ROWSand then read the second row of the result set?