funkeeiads
funkeeiads

Reputation: 437

get one field from itab with read table TRANSPORTING

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

Upvotes: 7

Views: 42809

Answers (4)

Dirk Trilsbeek
Dirk Trilsbeek

Reputation: 6023

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.

Upvotes: 5

András
András

Reputation: 1380

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.

Upvotes: 3

Alexander J&#228;ger
Alexander J&#228;ger

Reputation: 219

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.

Upvotes: 15

Jagger
Jagger

Reputation: 10524

There is no way. Lv_responsable has to be defined as follows.

DATA: lv_responsable LIKE LINE OF tbl_peps.

Only then can you assign the value in field lv_responsable-ususap to another variable of the field type.

Upvotes: 0

Related Questions