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: 

selecting all the fields using outerjoin

deepthi_b
Participant
0 Kudos

Hi All

I have a requirement to join two tables using outer join .I need to select all the fields from one of the table and few fields from other table.

Kindly let me know how to write the query using outerjoin by selecting all the fields from one of the table .

Regards

Deepthi

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Use the following code . Change table/fields anme accordingly.

PARAMETERS p_cityfr TYPE spfli-cityfrom. 

DATA: BEGIN OF wa, 
        carrid   TYPE scarr-carrid, 
        carrname TYPE scarr-carrname, 
        connid   TYPE spfli-connid, 
      END OF wa, 
      itab LIKE SORTED TABLE OF wa 
                WITH NON-UNIQUE KEY carrid. 

SELECT s~carrid s~carrname p~connid 
       INTO CORRESPONDING FIELDS OF TABLE itab 
       FROM scarr AS s 
       LEFT OUTER JOIN spfli AS p ON s~carrid   =  p~carrid 
                                  AND p~cityfrom = p_cityfr. 

LOOP AT itab INTO wa. 
  IF wa-connid = '0000'. 
    WRITE: / wa-carrid, wa-carrname. 
  ENDIF. 
ENDLOOP. 


<i><b>regards

Debjani

Reward point for helpful answer</b></i>

4 REPLIES 4

Former Member
0 Kudos

Hi,

Use the following code . Change table/fields anme accordingly.

PARAMETERS p_cityfr TYPE spfli-cityfrom. 

DATA: BEGIN OF wa, 
        carrid   TYPE scarr-carrid, 
        carrname TYPE scarr-carrname, 
        connid   TYPE spfli-connid, 
      END OF wa, 
      itab LIKE SORTED TABLE OF wa 
                WITH NON-UNIQUE KEY carrid. 

SELECT s~carrid s~carrname p~connid 
       INTO CORRESPONDING FIELDS OF TABLE itab 
       FROM scarr AS s 
       LEFT OUTER JOIN spfli AS p ON s~carrid   =  p~carrid 
                                  AND p~cityfrom = p_cityfr. 

LOOP AT itab INTO wa. 
  IF wa-connid = '0000'. 
    WRITE: / wa-carrid, wa-carrname. 
  ENDIF. 
ENDLOOP. 


<i><b>regards

Debjani

Reward point for helpful answer</b></i>

0 Kudos

Hi Debjani,

as per ur suggestion i will get selected fields from two tables.but my reqirement is to select AUFNR,POSNR,KDAUF,KDPOS fields from APFO table and all fields from VBEP table.

Regrads

Deepthi

0 Kudos

Hi,

APFO TABLE does not exist .

debjani

0 Kudos

its AFPO table not APFO.