We can join tables in abap in 2 ways . They are Inner joint and left outer joint.
Lets learn inner joint first.
When you want to join 2 tables with inner joint means the system wil giveout the value only for the entry which is common in both tables
for eg
Table 1
a 4 akdshk
b 3 aksdnf
f 8 akjsdhf
g 4 jasdkfhl
Table 2
a 1.00
c 4.21
d 8.01
f 1.21
g 2.10
If you want to join 2 tables by inner joint, then the resulting table is going to be
a 4 akdshk 1.00
f 8 akjsdhf 1.21
g 4 jasdkfhl 2.10
so the prog for this is.
TYPES: BEGIN OF stu,
matnr TYPE mara-matnr,
laeda TYPE mara-laeda,
pstat TYPE mara-pstat,
mtart TYPE mara-mtart,
maktx TYPE makt-maktx,
END OF stu.
DATA: wa type stu,
itab TYPE TABLE OF stu.
SELECT a~matnr
a~laeda
a~pstat
a~mtart
b~maktx INTO TABLE itab from mara as a INNER JOIN makt as b on a~matnr = b~matnr.
LOOP AT itab INTO wa.
WRITE:/ wa-matnr, wa-laeda,wa-pstat,wa-mtart,wa-maktx.
ENDLOOP.
matnr TYPE mara-matnr,
laeda TYPE mara-laeda,
pstat TYPE mara-pstat,
mtart TYPE mara-mtart,
maktx TYPE makt-maktx,
END OF stu.
DATA: wa type stu,
itab TYPE TABLE OF stu.
SELECT a~matnr
a~laeda
a~pstat
a~mtart
b~maktx INTO TABLE itab from mara as a INNER JOIN makt as b on a~matnr = b~matnr.
LOOP AT itab INTO wa.
WRITE:/ wa-matnr, wa-laeda,wa-pstat,wa-mtart,wa-maktx.
ENDLOOP.
LEFTOUTER JOIN
In the above table eg if we want to use left outer join the result is going to be.
a 4 akdshk 1.00
f 8 akjsdhf 1.21
g 4 jasdkfhl 2.10
b 3 aksdnf 0.00
the code is the same for both inner and left outer join join except for the words inner and left outer in the prog.
TYPES: BEGIN OF stu,
matnr TYPE mara-matnr,
laeda TYPE mara-laeda,
pstat TYPE mara-pstat,
mtart TYPE mara-mtart,
maktx TYPE makt-maktx,
END OF stu.
DATA: wa type stu,
itab TYPE TABLE OF stu.
SELECT a~matnr
a~laeda
a~pstat
a~mtart
b~maktx INTO TABLE itab from mara as a LEFT OUTER JOIN makt as b on a~matnr = b~matnr.
LOOP AT itab INTO wa.
WRITE:/ wa-matnr, wa-laeda,wa-pstat,wa-mtart,wa-maktx.
ENDLOOP.
matnr TYPE mara-matnr,
laeda TYPE mara-laeda,
pstat TYPE mara-pstat,
mtart TYPE mara-mtart,
maktx TYPE makt-maktx,
END OF stu.
DATA: wa type stu,
itab TYPE TABLE OF stu.
SELECT a~matnr
a~laeda
a~pstat
a~mtart
b~maktx INTO TABLE itab from mara as a LEFT OUTER JOIN makt as b on a~matnr = b~matnr.
LOOP AT itab INTO wa.
WRITE:/ wa-matnr, wa-laeda,wa-pstat,wa-mtart,wa-maktx.
ENDLOOP.
STANDARD SAP FUNCTION MODULE
Standard function modules are modules inbuilt by SAP like reuse_ALV_grid_display.
CUSTOM FUNCTION MODULE
To create function module you require function group.
To create function group goto se80. Select function group hit enter, it will ask for creation hit ok. Then give a short description.
Right click on the tree at the bottom on the right and activate.
Now got to se37 for function module.
Function Module = fin MOD_test
Import
A type i
B type i
C type i
Export
D type i
Source Code
d = a + b + c
write d.
In se38
Parameters: x type i,
y type i,
z type i.
data r type i.
call function 'z fun_Mod_Test' "Go call this function from the pattern."
Exporting
a=x
b=y
c=z
Importing
d=r.
Lets learn more about function modules in the next post.
No comments:
Post a Comment