Search code examples
abapopensql

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

Assume that table structure is

|company_code | account_number | excep_point |

Solution

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