Application Development and Automation 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: 
Read only

selecting all the fields using outerjoin

deepthi_b
Participant
0 Likes
727

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
Read only

Former Member
0 Likes
704

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
Read only

Former Member
0 Likes
705

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>

Read only

0 Likes
704

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

Read only

0 Likes
704

Hi,

APFO TABLE does not exist .

debjani

Read only

0 Likes
704

its AFPO table not APFO.