get one field from itab with read table TRANSPORTING

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.

Solving the underlying problem

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.

Tags:

Abap