具有动态键字段的读取表? [英] READ TABLE with dynamic key fields?

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

问题描述

我有一个表的名称 DATA lv_tablename TYPE选项卡名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-符号:< ls_line> 。

是否可以在<$ c $上创建READ语句? c>< lt_table> 完全指定键字段吗?

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.

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

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_string1 lv_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天全站免登陆