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: 

Select single with Join??

Former Member
0 Kudos

Hi,

Can we use SELECT SINGLE stataement with INNER JOIN??

Please give me a sample example.

Regards,

RH

1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor
0 Kudos

Obviously you can:

PARAMETERS: p_matnr TYPE matnr.

DATA:
      BEGIN OF st_mat,
        matnr TYPE matnr,
        matkl TYPE matkl,
        maktx TYPE maktx,
      END OF st_mat.

SELECT SINGLE a~matnr a~matkl b~maktx
  INTO st_mat
  FROM mara AS a INNER JOIN makt AS b
  ON b~matnr = a~matnr
  WHERE a~matnr = p_matnr
  AND   spras = sy-langu.

IF sy-subrc = 0.
  WRITE st_mat.
ENDIF.

It does not give a SLIN error as well

BR,

Suhas

7 REPLIES 7

Former Member

Hello,

Why dont you just try once and see if its working or not before posting?

Vikranth

Former Member
0 Kudos

Hello,

This is possible.

Of course you have to pay attention with this, because only 1 record from the join will be shown in the result.

Extract from the SAP help:

If SINGLE is specified, the resulting set has a single line. If the remaining additions to the SELECT command select more than one line from the database, the first line that is found is entered into the resulting set.

Wim

0 Kudos

I tied but it gave me syntax error " Incorrect structure of FROM clause"

I tried as follows:

SELECT tobukrs t1periv INTO (ws_bukrs , ws_periv)

FROM TVKO as to

INNER JOIN t001 as t1

WHERE to~vkorg = p_vkorg.

ws_bukrs and ws_periv are globally declared.

Regards,

RH

0 Kudos

Two things:

1- TO is a reserved word in many languages... try to not use it as an alias

2- I miss the ON clause of your JOIN

The main point is the 2nd one: if you don't say the DBMS which fields must compare to join the tables, it will become angry with you and will not help you to fetch the data

0 Kudos

Hello,

Change your select query this way,



parameters: p_vkorg type tvko-vkorg.

data: ws_bukrs type tvko-bukrs,
      ws_periv type t001-periv.

SELECT single to~bukrs t1~periv INTO
(ws_bukrs , ws_periv)
FROM TVKO as to
INNER JOIN t001 as t1
on to~bukrs = t1~bukrs
WHERE to~vkorg = p_vkorg.


write: ws_bukrs, ws_periv.

You dint mention the ON condition and SINGLE addition in your query

Vikranth

SuhaSaha
Advisor
Advisor
0 Kudos

Obviously you can:

PARAMETERS: p_matnr TYPE matnr.

DATA:
      BEGIN OF st_mat,
        matnr TYPE matnr,
        matkl TYPE matkl,
        maktx TYPE maktx,
      END OF st_mat.

SELECT SINGLE a~matnr a~matkl b~maktx
  INTO st_mat
  FROM mara AS a INNER JOIN makt AS b
  ON b~matnr = a~matnr
  WHERE a~matnr = p_matnr
  AND   spras = sy-langu.

IF sy-subrc = 0.
  WRITE st_mat.
ENDIF.

It does not give a SLIN error as well

BR,

Suhas

Former Member
0 Kudos

Am not understanding whats the purpose though..If all you need is a SINGLE record , why bother with a join ?

regards,

Deepthi