Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch a single field from DB table into itab

Tags:

abap

opensql

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. How can I do this in ABAP SQL?

Assume that table structure is

|company_code | account_number | excep_point |
like image 392
Bunny Rabbit Avatar asked Feb 27 '23 03:02

Bunny Rabbit


1 Answers

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.

like image 72
Bryan Cain Avatar answered Mar 01 '23 23:03

Bryan Cain