Application Development 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: 

Problem with Select statement.

Former Member
0 Kudos
190

hi Guys,

I am new to ABAP..need your attention in coding this following logic...

Here is the logic..i tried but i couldnt get the right coding..

Step 1. Retrieve customer number KUNNR from VBAK

Step 2. Pass customer number KUNNR to KNA1 and retrieve address number-ADANR value

Step 3. Pass ADANR value to ADRC table to retrieve NAME3

Kindly put some light onto this..

Regards

Sahil

1 ACCEPTED SOLUTION

valter_oliveira
Active Contributor
0 Kudos
80

Hello.

Try this (using JOIN to improve performance):


DATA: l_adrnr TYPE kna1-adrnr,
      l_name3 TYPE adrc-name3.

CLEAR: l_adrnr, l_name3.
SELECT SINGLE b~adrnr
  INTO (l_adrnr)
  FROM vbak AS a INNER JOIN kna1 AS b
    ON a~kunnr = b~kunnr
 WHERE a~vbeln = p_vbeln.
CHECK sy-subrc EQ 0.

SELECT SINGLE name3
  FROM adrc
  INTO (l_name3)
 WHERE ADDRNUMBER = l_adrnr.

Regards.

Valter Oliveia.

6 REPLIES 6

valter_oliveira
Active Contributor
0 Kudos
81

Hello.

Try this (using JOIN to improve performance):


DATA: l_adrnr TYPE kna1-adrnr,
      l_name3 TYPE adrc-name3.

CLEAR: l_adrnr, l_name3.
SELECT SINGLE b~adrnr
  INTO (l_adrnr)
  FROM vbak AS a INNER JOIN kna1 AS b
    ON a~kunnr = b~kunnr
 WHERE a~vbeln = p_vbeln.
CHECK sy-subrc EQ 0.

SELECT SINGLE name3
  FROM adrc
  INTO (l_name3)
 WHERE ADDRNUMBER = l_adrnr.

Regards.

Valter Oliveia.

Former Member
0 Kudos
80

select single KUNNR into v_KUNNR from VBAK

where VBELN = <pass VBELN here>.

select single ADRNR into v_ADRNR from KNA1

where KUNNR = v_KUNNR.

select single NAME3 into v_NAME3 from ADRC

where ADDRNUMBER = v_ADRNR.

Former Member
0 Kudos
80

Hi Sahil,

select single KUNNR 
into WA_KUNNR
from VBAK
where VBELN = PA_VBELN .

IF SY-SUBRC EQ 0.

select single ADRNR
into WA_ADRNR 
from KNA1
where KUNNR = WA_KUNNR.

select single NAME3 
into WA_NAME3 
from ADRC
where ADDRNUMBER = WA_ADRNR.    

ENDIF.

Best regards,

raam

Former Member
0 Kudos
80

Hi,

Declare the variables accordingly and try this..

*Step 1. Retrieve customer number KUNNR from VBAK

select vbeln

kunnr

from vbak

into table t_vbak

where vbeln in s_vbeln.

if sy-subrc eq 0.

*Step 2. Pass customer number KUNNR to KNA1 and retrieve *address number-ADANR value

select kunnr

adrnr

from kna1

into table t_kna1

for all entries in t_vbak

where kunnr = t_vbak-kunnr.

if sy-subrc eq 0.

*Step 3. Pass ADANR value to ADRC table to retrieve NAME3

select addrnumber

date_from

nation

from adrc

into t_name

for all entries in t_kna1

where addrnumber = t_kan1-adrnr.

endif.

endif.

Regards,

DhanaLakshmi M S

sachin_mathapati
Contributor
0 Kudos
80

data : wf_kunnr like vbak-kunnr,

wf_adrnr like kna1-adrnr,

wf_name3 like adrc-name3.

select single kunnr from vbak into wf_kunnr where vbeln = wf_vbeln.

If sy-subrc eq 0.

select single adrnr from kna1 into wf_adrnr where kunnr = wf_kunnr.

If sy-subrc eq 0.

select single name3 from adrc into wf_name3 where adrnr = wf_adrnr.

Endif.

Endif.

Former Member
0 Kudos
80

Hi,

1.select kunnr from vbak table and where conditions

2.For all entries in vbak.Get data from kna1 where kunnr = it_vbak-kunnr.

3.for all entries in it_kna1 get data from adanr where adanr = it_kna1-adanr and get name3.

4.loop at it_kna1.

dispaly your data.

endloop.

Thanks

Vikranth