简体   繁体   English

从数据库表中获取单个字段到 itab

[英]Fetch a single field from DB table into itab

I want to fetch the a field say excep_point from a transparent table z_accounts for the combination of company_code and account_number .我想从透明表z_accounts获取一个字段,比如excep_point ,用于company_codeaccount_number的组合。 How can I do this in ABAP SQL?如何在 ABAP SQL 中执行此操作?

Assume that table structure is假设表结构是

|company_code | account_number | excep_point |

Assuming you have the full primary key...假设你有完整的主键......

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.

if you don't have the full PK and there could be multiple values for excep_point如果您没有完整的 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.

There is at least another variation, but those are 2 I use most often.至少还有另一种变体,但那些是我最常使用的 2 个。

For information only.仅供参考。 When you selects data into table you can write complex expressions to combine different fields.当您选择数据到表中时,您可以编写复杂的表达式来组合不同的字段。 For example, you have internal table (itab) with two fields "A" and "B".例如,您有包含两个字段“A”和“B”的内部表 (itab)。 And you are going to select data from DB table (dbtab) wich have 6 columns - "z","x","y","u","v","w".你将从数据库表 (dbtab) 中选择数据,它有 6 列——“z”、“x”、“y”、“u”、“v”、“w”。 And for example each field is type char2 You aim to cimbine "z","x","y","u" in "A" field of internal table and "v","w" in "B" field.例如,每个字段都是 char2 类型您的目标是在内部表的“A”字段中将“z”、“x”、“y”、“u”和“B”字段中的“v”、“w”进行组合。 You can write simple code:您可以编写简单的代码:

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>.

This simple code makes you job done very simple这个简单的代码让你的工作变得非常简单

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

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

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