This blog is use-full to Learn ABAP Programming basics.. -------------------------------------------------------------------------- Mahesh R
Joins
Joins:
Joins are used to join multiple tables with condition.
In ABAP we can observe two types of Joins
1. Inner Join.
2.Left Outer Join.
First know about what is inner join
The data that can be selected with a view depends primarily on whether the view implements an inner join or an outer join. With an inner join, you only get the records of the cross-product for which there is an entry in all tables used in the view. With an outer join, records are also selected for which there is no entry in some of the tables used in the view. The set of hits determined by an inner join can therefore be a subset of the hits determined with an outer join.
Example for Inner join:
SELECT A~EBELN A~LIFNR A~KNUMV B~EBELP B~NETWR B~NETPR B~WERKS B~MATNR
L~NAME1 L~NAME2
FROM EKKO AS A
INNER JOIN EKPO AS B ON A~EBELN = B~EBELN
INNER JOIN LFA1 AS L ON L~LIFNR = A~LIFNR
* INNER JOIN EKKN AS C ON C~EBELN = A~EBELN
INTO CORRESPONDING FIELDS OF TABLE itab
WHERE B~BUKRS = 'company code' .
Left outer join
Usually, when defining InfoSets, the objects are linked via inner join operators. However, you can also use left outer joins. Inner join and left outer join are only different in the situation where one of the involved tables does not contain any suitable record which meets the join conditions.
With an inner join (table 1 inner join table 2), no record is included in the result set in this case. However, this means that the corresponding record from tables 1 is not considered in the results set.
With an left outer join (table 1 left outer join table2), exactly one record is included in the results set in this case´. In this record, the fields from table 1 contain the values of the record from table 1 and the fields from table 2 are all filled with the initial value.
Example of left outer join:
DATA: CUSTOMER TYPE SCUSTOM,
BOOKING TYPE SBOOK.
SELECT SCUSTOM~NAME SCUSTOM~POSTCODE SCUSTOM~CITY
SBOOK~FLDATE SBOOK~CARRID SBOOK~CONNID SBOOK~BOOKID
INTO (CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID)
FROM SCUSTOM LEFT OUTER JOIN SBOOK
ON SCUSTOM~ID = SBOOK~CUSTOMID AND
SBOOK~FLDATE = '20081015'
ORDER BY SCUSTOM~NAME SBOOK~FLDATE.
WRITE: / CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID.
ENDSELECT.
For more Information:
http://help.sap.com/saphelp_470/helpdata/en/fc/eb39c4358411d1829f0000e829fbfe/content.htm
Subscribe to:
Posts (Atom)
No comments:
Post a Comment