37 Flares Twitter 0 Facebook 37 Google+ 0 LinkedIn 0 Email -- Pin It Share 0 37 Flares ×

Inner Joins:

Inner Joins are usually used for extracting data from more than one table where the tables are having foreign key relation.

Inner join fetch the data based on ON condition first next is based on WHERE condition.

Ex: Retrieve the data from mara , marc and mard tables using Inner Joins.

Step 1: Go to SE38 create a program (Program name starts must with Z or Y).

Step 2: Copy and paste the below code in your program.

 REPORT  ZINNERJOIN_MARD NO STANDARD PAGE HEADING.

*//table declaration
TABLES:mara.

*//types declaration for final internal table
TYPES :BEGIN OF ty_material,
matnr TYPE  matnr,
ersda TYPE  ersda,
ernam TYPE ernam,
laeda TYPE laeda,
aenam TYPE aenam,
mtart TYPE mtart,
matkl TYPE matkl,
werks  TYPE werks_d,
pstat  TYPE pstat_d,
lvorm  TYPE lvowk,
mmstd  TYPE mmstd,
ekgrp  TYPE ekgrp,
lgort  TYPE lgort_d,
lfgja  TYPE lfgja,
lfmon  TYPE lfmon,
sperr  TYPE sperr,
labst TYPE  labst,
END OF ty_material.

*//internal table declaration
DATA:lt_material TYPE TABLE OF ty_material.
*//work area declaration
DATA:wa_material TYPE ty_material.

*// selection screen design
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-100.
SELECT-OPTIONS s_matnr FOR mara-matnr.
SELECTION-SCREEN END OF BLOCK blk1.
*//retrieve data from mara marc mard
SELECT a~matnr a~ersda a~ernam a~laeda a~aenam a~mtart a~matkl
b~matnr b~werks b~pstat b~lvorm b~mmstd b~ekgrp
c~matnr c~werks c~lgort c~lvorm c~lfgja c~lfmon c~sperr c~labst
INTO CORRESPONDING FIELDS OF TABLE lt_material
from mara as a
INNER JOIN marc as b
on a~matnr = b~matnr
inner join mard as c
on a~matnr = c~matnr
where a~matnr in s_matnr.

*//display output
LOOP AT lt_material INTO wa_material.
WRITE :  / wa_material-matnr,wa_material-ersda,wa_material-ernam,wa_material-laeda,wa_material-aenam,wa_material-mtart,
wa_material-matkl,wa_material-werks,wa_material-pstat,wa_material-lvorm,wa_material-mmstd,wa_material-ekgrp,
wa_material-lgort,wa_material-lfgja,wa_material-lfmon,wa_material-sperr,wa_material-labst.

ENDLOOP.

Output:

Save activate and Execute the program.

Provide the sample input values and click on execute.

Inner Joins in ABAPThat’s it.

Also Read:

Blocked ALV in SAP ABAP.

Converting and downloading Internal Table data into HTML format.

37 Flares Twitter 0 Facebook 37 Google+ 0 LinkedIn 0 Email -- Pin It Share 0 37 Flares ×