04-11-2006 8:11 AM
HI ,
I am currently new to this field and i have finished my training and want to excercise .i want to know how we write the real time codes , suppose i have 4 tables for example mara,marc,mard,makt and in the selection screen i have to select a range of materials and the report output should conain the respective plant,storage location, material description and the stock(mard-labst).given the materials the output shuld provide the above all like plant,st loc. etc., please give a code to join these tables and display the report.
thanks in advance
bye
04-11-2006 8:14 AM
04-11-2006 8:17 AM
hi,
just read the SAP help on Joins.
http://help.sap.com/saphelp_nw04/helpdata/en/cf/21ec77446011d189700000e8322d00/content.htm
regards
Vijay
04-11-2006 8:18 AM
Hi,
Check these demo programs.
<b>DEMO_SELECT_INNER_JOIN
DEMO_SELECT_LEFT_OUTER_JOIN</b>
Regards
vijay
04-11-2006 8:20 AM
Rocky,
Look at the T-Code ABAPDOCU, you will find quite a few examples.
Regards,
Ravi
Note : Please mark the helpful answers
04-11-2006 8:21 AM
Hi Rocky,
Please try with the following code
REPORT zs_stockreport3
NO STANDARD PAGE HEADING
LINE-SIZE 255
MESSAGE-ID zz1.
************************************************************************
Table Declaration *
************************************************************************
TABLES: mara,
marc,
mard.
************************************************************************
Types Declaration *
************************************************************************
TYPES: BEGIN OF typ_mara,
matnr TYPE mara-matnr, "Material Number"
mbrsh TYPE mara-mbrsh, "Industrial Sector"
mtart TYPE mara-mtart, "Material Type"
meins TYPE mara-meins, "Base Unit of Measure"
END OF typ_mara.
TYPES: BEGIN OF typ_makt,
matnr TYPE makt-matnr, "Material Number"
maktx TYPE makt-maktx, "Material Description"
END OF typ_makt.
TYPES: BEGIN OF typ_marc,
matnr TYPE marc-matnr, "Material Number"
werks TYPE marc-werks, "Plant Number"
END OF typ_marc.
TYPES: BEGIN OF typ_mard,
matnr TYPE marc-matnr, "Material Number"
werks TYPE marc-werks, "Plant Number"
lgort TYPE mard-lgort, "Storage Location"
END OF typ_mard.
************************************************************************
Intrnal tables Declaration *
************************************************************************
DATA: it_mara TYPE STANDARD TABLE OF typ_mara WITH HEADER LINE.
DATA: it_makt TYPE STANDARD TABLE OF typ_makt WITH HEADER LINE.
DATA: it_marc TYPE STANDARD TABLE OF typ_marc WITH HEADER LINE.
DATA: it_mard TYPE STANDARD TABLE OF typ_mard WITH HEADER LINE.
************************************************************************
Variable Declaration *
************************************************************************
DATA: v_count TYPE i.
************************************************************************
Selection Screen *
************************************************************************
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_matnr FOR mara-matnr.
SELECTION-SCREEN : SKIP.
PARAMETERS : p_mtart LIKE mara-mtart.
SELECTION-SCREEN : END OF BLOCK b1.
************************************************************************
Start Events *
************************************************************************
************************************************************************
Initialization *
************************************************************************
INITIALIZATION.
***
PERFORM initial_input.
************************************************************************
At Selection-screen *
************************************************************************
AT SELECTION-SCREEN.
***
PERFORM validte_inputdata.
************************************************************************
Start of Selection *
************************************************************************
START-OF-SELECTION.
***
SELECT matnr
mbrsh
mtart
meins
INTO TABLE it_mara
FROM mara
WHERE matnr IN s_matnr and
mtart = p_mtart.
if sy-subrc = 0.
sort it_mara by matnr.
else.
MESSAGE e001 WITH 'No data Found' ' For the Given'
'Selection Criteria'(400).
endif.
IF NOT it_mara[] IS INITIAL.
SELECT matnr
maktx
INTO TABLE it_makt FROM makt
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-matnr
AND spras = sy-langu.
if sy-subrc = 0.
sort it_makt by matnr.
endif.
ENDIF.
IF NOT it_mara[] IS INITIAL.
select matnr
werks
from marc
into table it_marc
for all entries in it_mara
where matnr = it_mara-matnr.
if sy-subrc = 0.
sort it_marc by matnr werks.
endif.
endif.
IF NOT it_marc[] IS INITIAL.
select matnr
werks
lgort
from mard
into table it_mard
for all entries in it_marc
where matnr = it_marc-matnr and
werks = it_marc-werks.
if sy-subrc = 0.
sort it_mard by matnr werks lgort.
endif.
endif.
DATA: a TYPE i.
loop at it_mara.
a = sy-tabix MOD 2.
IF a = 1.
FORMAT COLOR 5.
ELSE.
FORMAT COLOR OFF.
ENDIF.
read table it_marc with key matnr = it_mara-matnr
binary search.
if sy-subrc = 0.
read table it_mard with key matnr = it_marc-matnr
werks = it_marc-werks
binary search.
if sy-subrc = 0.
read table it_makt with key matnr = it_mara-matnr
binary search.
if sy-subrc = 0.
WRITE:/ sy-vline.
WRITE: 2 it_mara-matnr,
18 sy-vline, it_mara-mbrsh,
38 sy-vline, it_mara-mtart,
54 sy-vline, it_mara-meins,
78 sy-vline, it_makt-maktx,
120 sy-vline, it_marc-werks,
135 sy-vline, it_mard-lgort, 155 sy-vline.
clear : it_mara.
endif.
clear : it_makt.
endif.
endif.
endloop.
WRITE: /(155) sy-uline.
************************************************************************
Top of Page *
************************************************************************
TOP-OF-PAGE.
***
FORMAT COLOR 1.
WRITE: /(155) sy-uline.
WRITE:/ sy-vline.
WRITE: 2 'Material Number',
18 sy-vline, 'Industrial Sector',
38 sy-vline, 'Material Type',
54 sy-vline, 'Base Unit of Measure',
78 sy-vline, 'Material Description',
120 sy-vline, 'Plant',
135 sy-vline, 'Storage Location',155 sy-vline.
WRITE: /(155) sy-uline.
FORMAT RESET.
************************************************************************
End of Page *
************************************************************************
&----
*& Form Initial_Input
&----
Initailization of Select Option
----
FORM initial_input .
CLEAR s_matnr.
REFRESH s_matnr.
s_matnr-low = '100-100'.
s_matnr-high = '111-111'.
s_matnr-sign = 'I'.
s_matnr-option = 'BT'.
APPEND s_matnr.
p_mtart = 'ROH'.
ENDFORM. " Initial_Input
&----
*& Form Validte_Inputdta
&----
Validation of Select Option
----
FORM validte_inputdata .
SELECT SINGLE * FROM mara
WHERE matnr IN s_matnr.
IF sy-subrc <> 0.
MESSAGE e001 WITH 'Material'(002) 'Type'(003) 'Does Not Exit'(400).
ENDIF.
ENDFORM. " Validte_Inputdta
************************************************************************
End of Selection *
************************************************************************
Thanks & Regards
Sreenivasulu Ponnadi.