2025 Jan 04 2:39 PM - edited 2025 Jan 04 2:42 PM
Dear experts:
How can get the two last record of a internal table and pass to other table?
I have those two options:
DATA: it_tabla_interna TYPE TABLE OF your_type, " Table original
it_tabla_destino TYPE TABLE OF your_type, " Table target
lv_count TYPE i.
lv_count = lines( it_tabla_interna ).
IF lv_count >= 2.
READ TABLE it_tabla_interna INDEX lv_count TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
APPEND it_tabla_interna[ lv_count ] TO it_tabla_destino.
ENDIF.
READ TABLE it_tabla_interna INDEX lv_count - 1 TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
APPEND it_tabla_interna[ lv_count - 1 ] TO it_tabla_destino.
ENDIF.
ENDIF.
And I have other option using LOOP and with access Indice:
DATA: it_tabla_interna TYPE TABLE OF your_type, " Table original
it_tabla_destino TYPE TABLE OF your_type, " Tabla target
lv_count TYPE i.
lv_count = lines( it_tabla_interna ).
IF lv_count >= 2.
APPEND it_tabla_interna[ lv_count ] TO it_tabla_destino.
APPEND it_tabla_interna[ lv_count - 1 ] TO it_tabla_destino.
ENDIF.
However I want know if exist other options different?
Regards
Request clarification before answering.
Hello @PTecnico ,
In terms of performance, Approach 2 is the most efficient method to fetch the last two records from an internal table. Based on the current capabilities of SAP ABAP and HANA, these are the primary approaches available for this use case. As of now, there are no additional or more advanced syntaxes specifically designed to directly fetch the last two records from an internal table.
Thanks & regards,
Satya.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this:
DATA: lt_from TYPE stringtab.
DATA: lt_to TYPE stringtab.
lt_from = VALUE #( ( |hic| ) ( |hik| ) ( |hok| ) ).
APPEND LINES OF lt_from FROM lines( lt_from ) - 1
TO lines( lt_from )
TO lt_to.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi juan_surosThe system generate error when the table have a record this code:
DATA: lt_from TYPE stringtab.
DATA: lt_to TYPE stringtab.
* lt_from = VALUE #( ( |hic| ) ( |hik| ) ( |hok| ) ).
lt_from = VALUE #( ( |hic| ) ).
APPEND LINES OF lt_from FROM lines( lt_from ) - 1
TO lines( lt_from )
TO lt_to.
| User | Count |
|---|---|
| 11 | |
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.