I trying to get one field from interal table like this:
READ TABLE tbl_peps TRANSPORTING ususap INTO lv_responsable WITH KEY usr03 = wa_tbl_prps-usr03.
This sentence is wrong, it gives me an error
tbl_peps and lv_responsable are incompatibles
.
Is there a way to achieve that using "transporting fields"?
With the new syntax (At least ABAP 7.40) you do not need a workarea anymore. The coding for your example would be:
try.
lv_responsable = tbl_peps[ usr03 = wa_tbl_prps-usr03 ]-ususap.
catch CX_SY_ITAB_LINE_NOT_FOUND.
endtry.
Further info of the new table expressions can be found here.
According to the ABAP Documentation on READ TABLE
, if you use the transporting-option the work area receiving the data must be compatible with the line type of the table you read from. Your declared variable lv_responsable
seems to be incompatible with tbl_peps
, therefore the error when checking your code.
This should work:
DATA:
wa_peps like line of tbl_peps.
READ TABLE tbl_peps TRANSPORTING ususap INTO wa_peps WITH KEY usr03 = wa_tbl_prps-usr03.
MOVE wa_peps-ususap TO lv_responsable.
The reason you would want to transport only one field is to save memory and speed up processing. There is a better way to do that, use field symbols:
READ TABLE tbl_peps
ASSIGNING FIELD-SYMBOL(<fs_responsable>)
WITH KEY usr03 = wa_tbl_prps-usr03.
The inline definition only works with ABAP 740 and up, but you can do this in earlier versions:
FIELD-SYMBOLS: <fs_responsable> LIKE LINE OF tbl_peps.
READ TABLE tbl_peps
ASSIGNING <fs_responsable>
WITH KEY usr03 = wa_tbl_prps-usr03.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With