如何从一个表中获取两个字段的组合

问题描述:

我应该从表z_accounts中为company_code和account_number的组合提取excep_point。如何在abap中执行此操作? 为了本示例,假设表结构为zaccounts(company_code,account_number,excep_point)。如何从一个表中获取两个字段的组合

假设你有完整的主键...

data: gv_excep_point type zaccounts-excep_point. 

select single excep_point 
into gv_excep_point 
from zaccounts 
where company_code = some_company_code 
and account_number = some_account_number. 

,如果你不具备完整的PK,而且有可能对excep_point

data: gt_excep_points type table of zaccounts-excep_point. 

select excep_point 
into table gt_excep_points 
from zaccounts 
where company_code = some_company_code 
and account_number = some_account_number. 

至少有另一种是多值变化,但那些是我经常使用的2。

除了Bryans的回答,here是关于Open SQL的官方在线文档。

仅供参考。当您将数据选入表格时,您可以编写复杂的表达式来组合不同的字段。例如,您有两个字段“A”和“B”的内部表(itab)。你将从数据库表(dbtab)中选择数据,它有6列 - “z”,“x”,“y”,“u”,“v”,“w”。例如,每个字段都是char2类型。您的目标是在内部表的“A”字段中“z”,“x”,“y”,“u”以及“B”字段中的“v”,“w”。

select z as A+0(2) 
     x as A+2(2) 
     y as A+4(2) 
     u as A+6(2) 
     v as B+0(2) 
     w as B+2(2) FROM dbtab 
     INTO CORRESPONDING FIELDS OF TABLE itab 
      WHERE <where condition>. 

这个简单的代码,让你完成任务很简单

+0

部分z为A + 0(2) X作为A + 2(2) ... 非常:你可以写简单的代码很好,从来没有见过这种棘手的选择方法。万分感谢。 – Hartmut 2011-02-04 13:05:31