Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Re:Select statement

In my td they are giving a select statement to retrive data by using inner join, but i need to write those statement using for all entries and how i will write for that can any one give me the code for this .

SELECT MDKPBESKZ MDKPDISMM MDKPDSDAT MDKPMATNR MDKP~MSGAR

MDKPMSGID MDKPMSGNR MDKPMSGV1 MDKPMSGV2 MDKP~MSGV3

MDKPMSGV4 MDKPPLSCN MDKPPLWRK MDKPSOBSL T100~ARBGB

T100MSGNR T100SPRSL T100TEXT MAKTMAKTX MAKTMATNR MAKTSPRAS

MARCMATNR MARCMMSTA MARC~WERKS

INTO (MDKP-BESKZ , MDKP-DISMM , MDKP-DSDAT , MDKP-MATNR , MDKP-MSGAR

, MDKP-MSGID , MDKP-MSGNR , MDKP-MSGV1 , MDKP-MSGV2 , MDKP-MSGV3

, MDKP-MSGV4 , MDKP-PLSCN , MDKP-PLWRK , MDKP-SOBSL , T100-ARBGB

, T100-MSGNR , T100-SPRSL , T100-TEXT , MAKT-MAKTX , MAKT-MATNR

, MAKT-SPRAS , MARC-MATNR , MARC-MMSTA , MARC-WERKS )

FROM ( MDKP

INNER JOIN T100

ON T100ARBGB = MDKPMSGID

AND T100MSGNR = MDKPMSGNR

INNER JOIN MAKT

ON MAKTMATNR = MDKPMATNR

AND MAKTSPRAS = T100SPRSL

INNER JOIN MARC

ON MARCMATNR = MDKPMATNR

AND MARCWERKS = MDKPPLWRK )

WHERE MDKP~DSDAT IN SP$00003

AND MDKP~PLSCN IN SP$00001

AND MDKP~PLWRK IN so_werks

AND T100~SPRSL IN SP$00004.

Tags:
Former Member
replied

Try to do like this:

REPORT  ZTEST_NP.

DATA: BEGIN OF IT_MDKP OCCURS 0,
      BESKZ  TYPE MDKP-BESKZ,
      DISMM  TYPE MDKP-DISMM,
      DSDAT  TYPE MDKP-DSDAT,
      MATNR  TYPE MDKP-MATNR,
      MSGAR  TYPE MDKP-MSGAR,
      MSGID  TYPE MDKP-MSGID,
      MSGNR  TYPE MDKP-MSGNR,
      MSGV1  TYPE MDKP-MSGV1,
      MSGV2  TYPE MDKP-MSGV2,
      MSGV3  TYPE MDKP-MSGV3 ,
      MSGV4  TYPE MDKP-MSGV4 ,
      PLSCN  TYPE MDKP-PLSCN,
      PLWRK  TYPE MDKP-PLWRK ,
      SOBSL  TYPE MDKP-SOBSL ,
      END   OF IT_MDKP.

DATA: BEGIN OF IT_T100 OCCURS 0,
      ARBGB TYPE T100-ARBGB,
      MSGNR TYPE T100-MSGNR ,
      SPRSL TYPE T100-SPRSL ,
      TEXT  TYPE T100-TEXT ,
      END   OF IT_T100.

DATA: BEGIN OF IT_MAKT OCCURS 0,
      MATNR TYPE MAKT-MATNR,
      MKATX TYPE MAKT-MAKTX ,
      SPRAS TYPE MAKT-SPRAS ,
      END   OF IT_MAKT.

DATA: BEGIN OF IT_MARC OCCURS 0,
      MATNR TYPE MARC-MATNR ,
      WERKS TYPE MARC-WERKS,
      MMSTA TYPE MARC-MMSTA ,
      END   OF IT_MARC.

SELECT BESKZ DISMM DSDAT MATNR MSGAR MSGID MSGNR MSGV1 MSGV2 MSGV3
       MSGV4 PLSCN PLWRK SOBSL
       INTO TABLE IT_MDKP
       FROM  MDKP.
       WHERE DSDAT IN SP[code]REPORT  ZTEST_NP.

DATA: BEGIN OF IT_MDKP OCCURS 0,
      BESKZ  TYPE MDKP-BESKZ,
      DISMM  TYPE MDKP-DISMM,
      DSDAT  TYPE MDKP-DSDAT,
      MATNR  TYPE MDKP-MATNR,
      MSGAR  TYPE MDKP-MSGAR,
      MSGID  TYPE MDKP-MSGID,
      MSGNR  TYPE MDKP-MSGNR,
      MSGV1  TYPE MDKP-MSGV1,
      MSGV2  TYPE MDKP-MSGV2,
      MSGV3  TYPE MDKP-MSGV3 ,
      MSGV4  TYPE MDKP-MSGV4 ,
      PLSCN  TYPE MDKP-PLSCN,
      PLWRK  TYPE MDKP-PLWRK ,
      SOBSL  TYPE MDKP-SOBSL ,
      END   OF IT_MDKP.

DATA: BEGIN OF IT_T100 OCCURS 0,
      ARBGB TYPE T100-ARBGB,
      MSGNR TYPE T100-MSGNR ,
      SPRSL TYPE T100-SPRSL ,
      TEXT  TYPE T100-TEXT ,
      END   OF IT_T100.

DATA: BEGIN OF IT_MAKT OCCURS 0,
      MATNR TYPE MAKT-MATNR,
      MKATX TYPE MAKT-MAKTX ,
      SPRAS TYPE MAKT-SPRAS ,
      END   OF IT_MAKT.

DATA: BEGIN OF IT_MARC OCCURS 0,
      MATNR TYPE MARC-MATNR ,
      WERKS TYPE MARC-WERKS,
      MMSTA TYPE MARC-MMSTA ,
      END   OF IT_MARC.

SELECT BESKZ DISMM DSDAT MATNR MSGAR MSGID MSGNR MSGV1 MSGV2 MSGV3
       MSGV4 PLSCN PLWRK SOBSL
       INTO TABLE IT_MDKP
       FROM  MDKP.
       WHERE DSDAT IN SP$00003
       AND   PLSCN IN SP$00001
       AND   PLWRK IN so_werks.

IF NOT IT_MDKP[] IS INITIAL.
SELECT ARBGB MSGNR SPRSL TEXT
       INTO TABLE IT_T100
       FROM T100
       FOR   ALL ENTRIES IN IT_MDKP
       WHERE ARBGB = IT_MDKP-MSGID
       AND   MSGNR = IT_MDKP-MSGNR
       AND   SPRSL = SY-LANGU.

SELECT MATNR MAKTX SPRAS
       INTO TABLE IT_MAKT
       FROM MAKT
       FOR  ALL ENTRIES IN IT_MDKP
       WHERE MATNR = it_MDKP-MATNR
       AND   SPRAS = SY-LANGU.

SELECT MATNR WERKS MMSTA
       INTO TABLE IT_MARC
       FROM MARC
       FOR ALL ENTRIES IN IT_MDKP
       WHERE MATNR = IT_MDKP-MATNR
       AND   WERKS = IT_MDKP-PLWRK.
ENDIF.[/code]3
       AND   PLSCN IN SPREPORT  ZTEST_NP.

DATA: BEGIN OF IT_MDKP OCCURS 0,
      BESKZ  TYPE MDKP-BESKZ,
      DISMM  TYPE MDKP-DISMM,
      DSDAT  TYPE MDKP-DSDAT,
      MATNR  TYPE MDKP-MATNR,
      MSGAR  TYPE MDKP-MSGAR,
      MSGID  TYPE MDKP-MSGID,
      MSGNR  TYPE MDKP-MSGNR,
      MSGV1  TYPE MDKP-MSGV1,
      MSGV2  TYPE MDKP-MSGV2,
      MSGV3  TYPE MDKP-MSGV3 ,
      MSGV4  TYPE MDKP-MSGV4 ,
      PLSCN  TYPE MDKP-PLSCN,
      PLWRK  TYPE MDKP-PLWRK ,
      SOBSL  TYPE MDKP-SOBSL ,
      END   OF IT_MDKP.

DATA: BEGIN OF IT_T100 OCCURS 0,
      ARBGB TYPE T100-ARBGB,
      MSGNR TYPE T100-MSGNR ,
      SPRSL TYPE T100-SPRSL ,
      TEXT  TYPE T100-TEXT ,
      END   OF IT_T100.

DATA: BEGIN OF IT_MAKT OCCURS 0,
      MATNR TYPE MAKT-MATNR,
      MKATX TYPE MAKT-MAKTX ,
      SPRAS TYPE MAKT-SPRAS ,
      END   OF IT_MAKT.

DATA: BEGIN OF IT_MARC OCCURS 0,
      MATNR TYPE MARC-MATNR ,
      WERKS TYPE MARC-WERKS,
      MMSTA TYPE MARC-MMSTA ,
      END   OF IT_MARC.

SELECT BESKZ DISMM DSDAT MATNR MSGAR MSGID MSGNR MSGV1 MSGV2 MSGV3
       MSGV4 PLSCN PLWRK SOBSL
       INTO TABLE IT_MDKP
       FROM  MDKP.
       WHERE DSDAT IN SP$00003
       AND   PLSCN IN SP$00001
       AND   PLWRK IN so_werks.

IF NOT IT_MDKP[] IS INITIAL.
SELECT ARBGB MSGNR SPRSL TEXT
       INTO TABLE IT_T100
       FROM T100
       FOR   ALL ENTRIES IN IT_MDKP
       WHERE ARBGB = IT_MDKP-MSGID
       AND   MSGNR = IT_MDKP-MSGNR
       AND   SPRSL = SY-LANGU.

SELECT MATNR MAKTX SPRAS
       INTO TABLE IT_MAKT
       FROM MAKT
       FOR  ALL ENTRIES IN IT_MDKP
       WHERE MATNR = it_MDKP-MATNR
       AND   SPRAS = SY-LANGU.

SELECT MATNR WERKS MMSTA
       INTO TABLE IT_MARC
       FROM MARC
       FOR ALL ENTRIES IN IT_MDKP
       WHERE MATNR = IT_MDKP-MATNR
       AND   WERKS = IT_MDKP-PLWRK.
ENDIF.
       AND   PLWRK IN so_werks.

IF NOT IT_MDKP[] IS INITIAL.
SELECT ARBGB MSGNR SPRSL TEXT
       INTO TABLE IT_T100
       FROM T100
       FOR   ALL ENTRIES IN IT_MDKP
       WHERE ARBGB = IT_MDKP-MSGID
       AND   MSGNR = IT_MDKP-MSGNR
       AND   SPRSL = SY-LANGU.

SELECT MATNR MAKTX SPRAS
       INTO TABLE IT_MAKT
       FROM MAKT
       FOR  ALL ENTRIES IN IT_MDKP
       WHERE MATNR = it_MDKP-MATNR
       AND   SPRAS = SY-LANGU.

SELECT MATNR WERKS MMSTA
       INTO TABLE IT_MARC
       FROM MARC
       FOR ALL ENTRIES IN IT_MDKP
       WHERE MATNR = IT_MDKP-MATNR
       AND   WERKS = IT_MDKP-PLWRK.
ENDIF.

Regards,

Naimesh Patel

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question