从 DB 表中获取单个字段到 itab 中

Bun*_*bit 5 abap opensql

excep_point我想从透明表中获取 a 字段,z_accounts用于company_code和的组合account_number。我怎样才能在ABAP SQL 中做到这一点?

假设表结构为

|company_code | account_number | excep_point |
Run Code Online (Sandbox Code Playgroud)

Bry*_*ain 5

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

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.
Run Code Online (Sandbox Code Playgroud)

如果您没有完整的 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.
Run Code Online (Sandbox Code Playgroud)

至少还有另一种变体,但这是我最常使用的两种。