Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get one field from itab with read table TRANSPORTING

Tags:

abap

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"?

like image 723
funkeeiads Avatar asked Jan 08 '15 16:01

funkeeiads


3 Answers

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.

like image 91
Alexander Jäger Avatar answered Oct 20 '22 20:10

Alexander Jäger


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.
like image 35
Dirk Trilsbeek Avatar answered Oct 20 '22 22:10

Dirk Trilsbeek


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.
like image 23
András Avatar answered Oct 20 '22 21:10

András