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 query

Former Member
0 Likes
825

Hi frnds

i hav 2 tables and in the braces their respective fields

ekpo( ebeln , ebelp ) & ekkn ( ebeln, ebelp , sakto , kostl )

so i hav to write select query with the following condition

-


> the key fields are ebeln and ebelp.

-


> the join condition is ( Outer join with EKPO on EBELN & EBELP (One to many) )

Frnds can anyone help me regarding this.

thnak u .

regards,

karan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
736

SELECT a~ebeln

a~ebelp

b~sakto

b~kostl

INTO CORRESPONDING FIELDS OF TABLE it_itab

FROM ekpo AS a LEFT OUTER JOIN ekkn AS b

ON aebeln = bebeln

AND aebelp = bebelp

WHERE a~ebeln = '4500000001'

AND a~ebelp = '00010'

6 REPLIES 6
Read only

Former Member
0 Likes
736

Hi,

Try this..

DATA: BEGIN OF itab OCCURS 0,

ebeln LIKE ekpo-ebeln,

ebelp LIKE ekpo-ebelp,

sakto LIKE ekkn-sakto,

kostl LIKE ekkn-kostl,

END OF itab.

SELECT aebeln aebelp bsakto bkostl

INTO TABLE itab

FROM ekpo AS a LEFT OUTER JOIN ekkn AS b

ON aebeln = bebeln

AND aebelp = bebelp

WHERE a~ebeln = '4500000001'

AND a~ebelp = '00010'.

Thanks,

Naren

Read only

0 Likes
736

Hi Naren,

Thnks for ur reply .

i hav one more issue its having like this.

ekkn( ebeln ebelp sakto kostl ) csks ( kostl ltext datbl datab verak anred name1 )

so condition is

---> key field is kostl

-


> Inner join with EKKN-KOSTL (One to many – select according to validity )

SELECT akostl bltext bdatbl bdatab bverak banred b~name1

INTO TABLE itab

FROM ekkn AS a LEFT OUTER JOIN csks AS b

ON akostl = bkostl where a~kostl = ' XXXXX '...............

so naren can u just tell me wht shuld be done for the condition select according to validity.

can u plzz help me regarding this.

thnk u ..

regards,

karan

Read only

Former Member
0 Likes
737

SELECT a~ebeln

a~ebelp

b~sakto

b~kostl

INTO CORRESPONDING FIELDS OF TABLE it_itab

FROM ekpo AS a LEFT OUTER JOIN ekkn AS b

ON aebeln = bebeln

AND aebelp = bebelp

WHERE a~ebeln = '4500000001'

AND a~ebelp = '00010'

Read only

0 Likes
736

Hi,

... or just a bit more transparent:


SELECT 
  ekpo~ebeln 
  ekpo~ebelp 
  ekkn~sakto 
  ekkn~kostl
  INTO CORRESPONDING FIELDS OF TABLE it_itab
  FROM ekpo 
    LEFT OUTER JOIN ekkn 
    ON ekpo~ebeln = ekkn~ebeln AND
       ekpo~ebelp = ekkn~ebelp
  WHERE ekpo~ebeln = '4500000001'
    AND ekpo~ebelp = '00010'.

Note: Although people almost always use an ALIAS (<tabname> as <alias>) this is not at all necessary. Only if you select from different records of the same table at the same time you need an alias to distinguish different join conditions.

I know that SAP uses alias in the example: Millions of flies can't do wrong: Eat what?

Regards,

Clemens

Read only

Former Member
0 Likes
736

Hi,

Try this..

DATA: BEGIN OF ITAB OCCURS 0,

EBELN LIKE EKKN-EBELN,

EBELP LIKE EKKN-EBELP,

SAKTO LIKE EKKN-SAKTO,

KOSTL LIKE EKKN-KOSTL,

LTEXT LIKE CSKS-LTEXT,

DATBL LIKE CSKS-DATBL,

END OF ITAB.

SELECT AEBELN AEBELP ASAKTO AKOSTL BLTEXT BDATBL

INTO TABLE ITAB

FROM EKKN AS A INNER JOIN CSKS AS B

ON AKOSTL = BKOSTL

WHERE A~KOSTL = '0000049000'.

Thanks,

Naren

Read only

0 Likes
736

Naren wht about the condition statement "select according to validity " wht shuld be done in the select query for this thing.

thnk u again.

regards,

karan