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

SELECT

Former Member
0 Likes
767

HOW TO WRITE A SINGLE SELECT STATEMENT TO RETRIEVE "PERNR FROM PA0001", "NACHN , VORNA FROM PA0002"?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
729

Hi KRITHIGA APPADURAI,

Do You want to join for these two tables?

Plzz reward if it is useful,

Mahi.

6 REPLIES 6
Read only

Former Member
0 Likes
729

performancewise it is not advisable to use single select for fetching data from these 2 tables...

use 2 selects

select pernr

from pa0001 into table it_0001

where pernr in s_pernr

and begda le s_date-high

and endda ge s_date-low.

if sy-subrc = 0.

sort it_0001 by pernr endda descending.

delete adjacent duplicates from it_0001 comparing pernr.

endif.

if not it_0001[] is initial.

select vorna nachn from pa0002 into table it_0002 for all entries in it_0001 where pernr = it_0001-pernr and endda = '99991231'.

if sy-subrc = 0.

sort it_0002 by pernr.

endif.

endif.

Read only

Former Member
0 Likes
730

Hi KRITHIGA APPADURAI,

Do You want to join for these two tables?

Plzz reward if it is useful,

Mahi.

Read only

Former Member
0 Likes
729

Hi Krithiga

I belive if you want to retrieve just NACHN and VORNA, it is already present in PA0001 itself. The ENAME is the concatenation of VORNA, NACHN and TITEL from PA0002, may be you can look at the option of splitting after getting from PA0001.

Regards

Ranganath

PS : Reward points for all useful answers !

Read only

Former Member
0 Likes
729

Hi krithiga,

use joins as we hav only two tables...

select p1pernr p2nachn p2vorna from pa0001 as p1 join pa0002 as p2 on p1pernr = p2~pernr .

pls reward if helps,

regards.

Read only

0 Likes
729

> select p1pernr p2nachn p2vorna from pa0001 as p1 join pa0002 as p2 on p1pernr =

> p2~pernr .

What sense does this join makes having pernr in pa0002 and selecting nothing else but pernr from pa0001?

Read only

rainer_hbenthal
Active Contributor
0 Likes
729

Thats not as easy as you might thought. You have to take the date ranges into account, personal subarea may have changed more often then your last name. Thats why the logical database PNP is used very often doing a provide on the records.

if you just need actual lastname and firstname you dont need to read anything from pa0001, you can just do a select on pa0002 using a where clause with pernr and endda = 99991231

Your statement is a little bit unclear, you do not need pa0001 for pernr, its in pa0002 too.