开发者

Fetch a single field from DB table into itab

开发者 https://www.devze.com 2023-01-18 21:14 出处:网络
I want to fetch the a field say excep_point from a transparent table z_accounts 开发者_JS百科for the combination of company_code and account_number. How can I do this in ABAP SQL?

I want to fetch the a field say excep_point from a transparent table z_accounts 开发者_JS百科for the combination of company_code and account_number. How can I do this in 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

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.


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". And you are going to select data from DB table (dbtab) wich have 6 columns - "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. 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


In addition to Bryans answer, here is the official online documentation about Open SQL.

0

精彩评论

暂无评论...
验证码 换一张
取 消