简体   繁体   English

使用读取表 TRANSPORTING 从 itab 获取一个字段

[英]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 tbl_peps 和 lv_responsable 不兼容

. .

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.使用新语法(至少 ABAP 7.40),您不再需要工作区。 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.根据READ TABLE上的ABAP 文档,如果您使用传输选项,则接收数据的工作区必须与您读取的表的行类型兼容。 Your declared variable lv_responsable seems to be incompatible with tbl_peps , therefore the error when checking your code.您声明的变量lv_responsable似乎与tbl_peps不兼容,因此检查代码时会出错。

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:内联定义仅适用于 ABAP 740 及更高版本,但您可以在早期版本中执行此操作:

FIELD-SYMBOLS: <fs_responsable> LIKE LINE OF tbl_peps.
READ TABLE tbl_peps 
  ASSIGNING <fs_responsable> 
  WITH KEY usr03 = wa_tbl_prps-usr03.

There is no way.不可能。 Lv_responsable has to be defined as follows. Lv_responsable必须定义如下。

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.只有这样,您才能将字段lv_responsable-ususap的值分配给该字段类型的另一个变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM