使用动态键字段读取表? [英] READ TABLE with dynamic key fields?

查看:20
本文介绍了使用动态键字段读取表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表的名称 DATA lv_tablename TYPE tabname VALUE 'xxxxx',以及一个通用的 FIELD-SYMBOLS: <lt_table>TYPE ANY TABLE. 包含从相应表中选择的条目.

I have the name of a table DATA lv_tablename TYPE tabname VALUE 'xxxxx', and a generic FIELD-SYMBOLS: <lt_table> TYPE ANY TABLE. which contains entries selected from that corresponding table.

我已经定义了我的行结构 FIELD-SYMBOLS: <ls_line>TYPE ANY. 我会用它来读取表格.

I've defined my line structure FIELD-SYMBOLS: <ls_line> TYPE ANY. which i'd use for reading from the table.

有没有办法在 上创建 READ 语句并完全指定关键字段?

Is there a way to create a READ statement on <lt_table> fully specifying the key fields?

我知道语句/添加 READ TABLE xxxx WITH KEY (lv_field_name) = 'asdf'.,但是这对于动态数量的关键字段不起作用(afaik),并且我不想创建大量具有越来越多的关键字段规范的 READ TABLE 语句.

I am aware of the statement / addition READ TABLE xxxx WITH KEY (lv_field_name) = 'asdf'., but this however wouldn't work (afaik) for a dynamic number of key fields, and I wouldn't like to create a large number of READ TABLE statements with an increasing number of key field specifications.

这能做到吗?

推荐答案

其实我觉得这个方法可行

Actually i found this to work

DATA lt_bseg TYPE TABLE OF bseg.
DATA ls_bseg TYPE bseg.
DATA lv_string1 TYPE string.
DATA lv_string2 TYPE string.

lv_string1 = `    `.
lv_string2 = lv_string1.

SELECT whatever FROM wherever INTO TABLE lt_bseg.

READ TABLE lt_bseg INTO ls_bseg
    WITH  KEY ('MANDT') = 800
              ('  ')    = ''
              ('BUKRS') = '0005'
              ('BELNR') = '0100000000'
              ('GJAHR') = 2005
              ('BUZEI') = '002'
              ('')      = ''
              ('     ') = ''
              ('    ') = '         '
              (lv_string1) = '1'
              (lv_string2) = ''.

通过使用这种语法,您可以根据需要指定尽可能多的关键字段.如果某些字段为空,那么即使为这些空字段指定了值,这些字段也会被忽略.

By using this syntax one can just specify as many key fields as required. If some fields will be empty, then these will just get ignored, even if values are specified for these empty fields.

必须注意,使用这种精确的语法(静态定义),不允许使用 2 个完全相同名称(甚至是空白名称)的字段.

One must pay attention that using this exact syntax (static definitions), 2 fields with the exact same name (even blank names) will not be allowed.

如变量 lv_string1lv_string2 所示,在运行时这没有问题.

As shown with the variables lv_string1 and lv_string2, at run-time this is no problem.

最后,您可以按任何顺序指定字段(我不知道使用此语法可能会获得哪些性能优势或损失)

And lastly, one can specify the fields in any order (i don't know what performance benefits or penalties one might get while using this syntax)

这篇关于使用动态键字段读取表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆