How to get a field from a table for a combination of two fields

I should get the field a, say excep_point, from the z_accounts table for a combination of company_code and account_number. How can i do this in abap? Suppose the table structure is zaccounts (company_code, account_number, excep_point) for this example.

+3
source share
3 answers

Assuming you have a complete 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 do not have full PK, and there may be several 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 one more variation, but these are the ones that I use most often.

+3
source

. , . , (itab) "A" "B". DB (dbtab), 6 - "z", "x", "y", "u", "v", "w". , , char2. "z", "x", "y", "u" "A" "v", "w" "B". :

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

+3

Bryans, - Open SQL.

+1
source

Source: https://habr.com/ru/post/1767543/


All Articles