Skip to main content

Select with Joins

 SELECT WITH JOINS


Select with Joins

1. It is used to bring the data simultaneously from multiple tables.
2. That means the multiple tables must be joined using one or two field.
3. There should be at least one common field between tables.
4. We have 2 types of joins.

1. INNER JOIN

1. Inner Join is used to bring comparable (matching) records between tables.
2. Unmatched Records won’t be selected.

2. OUTER JOIN

1. It joins all the records from the first table or left table will be selected first.
2. If there are any comparable (matching) records from second, third tables, then the data will be displayed.
3. And if there are no matching records, the data will be displayed as blank from second and third tables.


EXAMPLE  PROGRAM ON INNER JOIN
TYPES:
      
BEGIN OF TY_VBAK_VBAP,
      VBELN 
TYPE VBAK-VBELN,
      ERDAT 
TYPE VBAK-ERDAT,
      ERZET 
TYPE VBAK-ERZET,
      ERNAM 
TYPE VBAK-ERNAM"STRUCTURE THAT HOLDS THE FIELDS OF 2 TABLES
      POSNR 
TYPE VBAP-POSNR,
      MATNR 
TYPE VBAP-MATNR,
      
END OF TY_VBAK_VBAP.


DATA:
      IT_VBAK_VBAP 
TYPE TABLE OF TY_VBAK_VBAP,  "ITAB AND WA DECLARATION
      WA_VBAK_VBAP 
TYPE TY_VBAK_VBAP.


SELECT VBAK~VBELN VBAK~ERDAT
       VBAK
~ERZET VBAK~ERNAM
       VBAP
~POSNR VBAP~MATNR    "FETCHING DATA WITH INNER JOIN ON VBELN
          
INTO TABLE
          IT_VBAK_VBAP
       
FROM VBAK
       INNER 
JOIN VBAP ON
       VBAK
~VBELN VBAP~VBELN.

LOOP AT IT_VBAK_VBAP INTO WA_VBAK_VBAP.
WRITE:/ WA_VBAK_VBAP-VBELN COLOR 3,WA_VBAK_VBAP-ERDAT,
        WA_VBAK_VBAP
-ERZET,                                                    "OUTPUT DISPLAY
        WA_VBAK_VBAP
-ERNAM,
        WA_VBAK_VBAP
-POSNR,
        WA_VBAK_VBAP
-MATNR.
ENDLOOP.





Comments

Popular posts from this blog

Rohit Means "The first rays of the sun"

Well my name is R ohit S axena I m 24. I live in Chandigarh I love to have fun. I dont like fake people. Other then that im a good person i love everyone AlL i CaN dO iS bE mE aNd HoPe YoU lIkE mE................ SAY WHAT YOU MEAN, AND MEAN WHAT YOU SAY, BECAUSE THE PEOPLE THAT MIND DON'T MATTER AND THE PEOPLE THAT MATTER DON'T MIND ..... i have no regrets in life, but if i could i would change somethings i´v done .... everything happens for a reason. My hard times makes me a stronger person .... I love life and i love my mother Don't have much to say about me here ▂ ▃ ▅ ▆ ▇ █ █ ▇ ▆ ▅ ▃ ▂ ▂▂▂▂▂▂ weird ▂▂▂▂▂▂ █ ▇ ▆ ▅ ▃ ▂▂ ▃ ▅ ▆ ▇ █