Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Subquery in ABAP

ayan_chaudhuri
Participant
0 Likes
2,224

Hi experts,

I have a subquery which has to be written in ABAP.

select single TARIF_TYPE from table ZTARIFF where (TARIFTYP = xxx and ANLART = mn)

Where xxx = select TARIFTYP from table EANLH where (ANLAGE = select ANLAGE from table EVER where VKONTO = Contract account Number)

Where mn = select ANLART from EANL where where (ANLAGE = select ANLAGE from table EVER where VKONTO = Contract account Number)

Can anyone give me the corresponding ABAP code for this?

Thanks

Ayan

<MOVED FROM PI FORUMS>

Edited by: Prateek Raj Srivastava on Feb 8, 2011 2:33 AM

Hi experts,

I have a subquery which has to be written in ABAP.

select single TARIF_TYPE from table ZTARIFF where (TARIFTYP = xxx and ANLART = mn)

Where xxx = select TARIFTYP from table EANLH where (ANLAGE = select ANLAGE from table EVER where VKONTO = Contract account Number)

Where mn = select ANLART from EANL where where (ANLAGE = select ANLAGE from table EVER where VKONTO = Contract account Number)

Can anyone give me the corresponding ABAP code for this?

Thanks

Ayan

<MOVED FROM PI FORUMS>

Edited by: Prateek Raj Srivastava on Feb 8, 2011 2:33 AM

5 REPLIES 5
Read only

Former Member
0 Likes
958

Hi Ayan,

you should ask that in an ABAP forum.

Regards,

Udo

Read only

Former Member
0 Likes
958

use internal tables & work area for this requirement

select ANLAGE from table EVER INTO <Internal table IT1> where VKONTO = Contract account Number.

select ANLART from EANL INTO <Internal table IT2>

For all entries in IT1 where ANLAGE = IT1-ANLAGE.

select ANLAGE from table EVER INTO <Internal table IT3> where VKONTO = Contract account Number.

select TARIFTYP from table EANLH INTO <Internal table IT4>

For all entries in IT4 where ANLAGE = IT3-ANLAGE.

select single TARIF_TYPE from table ZTARIFF INTO <IT5>

for all entries in table IT4

where TARIFTYP = IT4-xxx.

loop at it3 into wa_it3.

Read table IT5 into WA_IT5 with key ANLART = wa_it3-mn.

if sy-subrc is initial.

TARIF_TYPE = wa_it5-TARIF_TYPE .

Endif.

Endloop.

Read only

former_member182670
Contributor
0 Likes
958

I'd say it's doable in one select.

Read documentation on subqueries [http://help.sap.com/saphelp_NW04/helpdata/en/dc/dc7614099b11d295320000e8353423/content.htm|http://help.sap.com/saphelp_NW04/helpdata/en/dc/dc7614099b11d295320000e8353423/content.htm]

and this syntax

SELECT  SINGLE city latitude longitude
  INTO  (city, lati, longi)
  FROM  sgeocity
  WHERE city IN ( select  cityfrom
                    FROM  spfli
                    WHERE carrid = carr_id AND
                          connid = conn_id      ).

Read only

Former Member
0 Likes
958

sorry i have no means of testing this, but you could try this one.


select single TARIF_TYPE from ZTARIFF where 
  TARIFTYP = ( select single TARIFTYP from EANLH where ANLAGE = ( select single ANLAGE from EVER where VKONTO = Contract_account_Number ) ) 
  and ANLART = ( select single ANLART from EANL where ANLAGE = ( select single ANLAGE from EVER where VKONTO = Contract_account_Number ) ).

Read only

former_member186741
Active Contributor
0 Likes
958

I think you can joins for this:

select ztariff~tarif_type

from ever

join eanlh on eanlanlage = everanlage

join eanl on eanlanlage = everanlage

join ztariff on ztarifftariftyp = eanlhtariftyp

and ztariffanlart = eanlanlart

where ever~vkonto in s_vkonto.