Reports - Inner Joins
Dear Friends,
I need to prepare a classic report based on the following parameters :
I would like to know, how to join these three tables using Inner Joins - MARA, MARC, MSTA.
I should be able to view the fields from these tables.
I tried out with the common fields from these tables, viz. MARA - MATNR - MARC, MARC - WERKS - MSTA.
I would appreciate, if anyone replies me with the select statement using the above mentioned tables using Inner Joins statement with any common fields .
Thanking you in anticipation.
Dear dinesh kumar
1. We can join the three tables with matnr field.
2. WERKS has to be provided from the program - (plant).
ie. For which plant, data is required.
3. Due to MSTA table, you may get multiple records
for same MATNR. bcos of maintenance records
by different departments in MSTA Table.
If it helps, pls give points.
REPORT abc.
data : begin of itab occurs 0,
matnr like mara-matnr,
"---- Other Fields
end of itab.
data : matnr like mara-matnr.
data : werks like marc-werks.
Query
select a~matnr
into table itab
from mara as a
inner join marc as b
on amatnr = bmatnr
inner join msta as c
on amatnr = cmatnr
Required Conditions From Program
where a~matnr = matnr
and b~werks = werks.
Thanks & Regards,
Amit Mittal.
Similar Messages
-
Hi,
In my report List of Block Customer's, INNER JOIN is not working..
Code:----
SELECT DISTINCT M1KUNNR M1KTOKD M1NAME1 M1CASSD M1AUFSD M1LIFSD M1~FAKSD INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM KNA1 AS M1 INNER JOIN KNVV AS M2 ON M1KUNNR = M2KUNNR
WHERE M1~KTOKD IN ('0001' , 'KTOKD')
AND M1~CASSD EQ 'X'
OR M1~AUFSD NE ''
OR M1~LIFSD NE ''
OR M1~FAKSD NE ''
OR (M2~AUFSD NE ''
OR M2~LIFSD NE ''
OR M2~FAKSD NE ''
OR M2~CASSD EQ 'X'.
Here, condition on 0001 is not matching..
Plz tell me, what is the problem in it..
Thanks
Edited by: Prince Kumar on Oct 20, 2008 9:37 AMhi,
please use " FOR ALL ENTRIES " as it is better performance wise also rather then inner joins
and for syntax refer this code:
Exporting all flight data for a specified departure city. The relevant airlines and flight numbers are first put in an internal table entry_tab, which is evaluated in the WHERE condition of the subsquent SELECT statement.
PARAMETERS p_city TYPE spfli-cityfrom.
TYPES: BEGIN OF entry_tab_type,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
END OF entry_tab_type.
DATA: entry_tab TYPE TABLE OF entry_tab_type,
sflight_tab TYPE SORTED TABLE OF sflight
WITH UNIQUE KEY carrid connid fldate.
SELECT carrid connid
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE entry_tab
WHERE cityfrom = p_city.
SELECT carrid connid fldate
FROM sflight
INTO CORRESPONDING FIELDS OF TABLE sflight_tab
FOR ALL ENTRIES IN entry_tab
WHERE carrid = entry_tab-carrid AND
connid = entry_tab-connid.
thanks and regards
RAHUL -
hi,
this is report i created in this i used two tables and used inner join to make relation b/t these tables...
so my doubt is ..if we r using three diff.. tables without inner join we can do this report ......if u can.. plz can u show me wit example...
TABLES: VBAP,VBAK.
DATA : BEGIN OF ITAB OCCURS 0,
vbeln like VBAK-VBELN, "Sales Document No.
kunnr like VBAK-KUNNR,"customerno
VKORG like VBAK-VKORG,"salesorg
audat like VBAK-AUDAT,"documentdate
matnr like VBAP-MATNR,"materialno
netwr like VBAK-NETWR,"netamount
end of itab.
selection-screen : begin of block a1. "SCREEN 500 AS WINDOW..
select-options : KUNNR for VBAK-kunnr.
select-options : VKORG FOR VBAK-vkorg.
select-options : AUDAT for VBAK-audat.
select-options : MATNR for VBAP-matnr.
select-options : NETWR FOR VBAK-netwr.
SELECTION-SCREEN :end of block a1.
SELECT vbakvbeln vbakkunnr vbakvkorg vbakaudat vbapmatnr vbaknetwr into table itab from vbak
INNER JOIN vbap on vbakvbeln = vbapvbeln
where
VBAK~kunnr in kunnr
AND
VBAK~VKORG in VKORG
and vbak~audat in audat
AND vbap~matnr in matnr.
write sy-dbcnt.
write:/ 'CUSTOMERNO' ,20 'SALESORG',40 'DOCUMENTDATE',60 'MATERIAL',80 'NETAMOUNT'.
ULINE.
loop at itab.
write :/ itab-kunnr,20 itab-vkorg, 40 itab-audat, 60 itab-matnr, 80 itab-netwr.
endloop.
thanx
bhanuRefer to this psuedo code
SELECT vbak~vbeln vbak~kunnr vbak~vkorg vbak~audat vbap~matnr vbak~netwr into table itab from vbak
INNER JOIN vbap on vbak~vbeln = vbap~vbeln
where
VBAK~kunnr in kunnr
AND
VBAK~VKORG in VKORG
and vbak~audat in audat
AND vbap~matnr in matnr.
SELECT vbak~vbeln vbak~kunnr vbak~vkorg vbak~audat vbak~netwr vbak~matnr
into table itab
from vbak
where kunnr in kunnr....
select vbeln matnr
into table itab2
from vbap
for all entries in itab
where vbap~matnr = itab~matnr....
loop at itab assigning <fs_itab>.
read table itab2 into wa_itab2 with key vbeln = <fs_itab>-vbeln
matnr = <fs_itab>-matnr.
" your move's to final table
endloop. -
INNER JOIN PROBLEM IN Microsoft SQL Server 2008 R2 Report Builder 3.0
SELECT
,maximo_tbl_matrectrans.ponum
,maximo_tbl_po.description AS [maximo_tbl_po description]
,maximo_tbl_matrectrans.polinenum
,maximo_tbl_matrectrans.itemnum
,maximo_tbl_item.description AS [maximo_tbl_item description]
FROM
maximo_tbl_matrectran
INNER JOIN maximo_tbl_po
ON maximo_tbl_matrectrans.ponum = maximo_tbl_po.ponum
INNER JOIN maximo_tbl_item
ON maximo_tbl_matrectrans.itemnum = maximo_tbl_item.itemnum
can you advise below picture in itemnum in show one value more time
ponum polinenum maximo_tbl_a_po_description itemnum maximo_tbl_a_item_description
D33-1021425 5 ASL REORDER HAZMAT 91G8110000071 DRUM, PLASTIC
D33-1021425 5 ASL REORDER HAZMAT 91G8110000071 DRUM, PLASTIC
D33-1020817 2 ASL REPLENISHMENT, D 91G6685000371 THERMOSTAT
D33-1020817 2 ASL REPLENISHMENT, D 91G6685000371 THERMOSTAT
D33-1020817 2 ASL REPLENISHMENT, D 91G6685000371 THERMOSTAT
D33-1021365 2 ASL - D33DFAC STOCK 91G3920000081 CART, BIG WHEEL
D33-1021365 2 ASL - D33DFAC STOCK 91G3920000081 CART, BIG WHEEL
D33-1021425 5 ASL REORDER HAZMAT 91G8110000071 DRUM, PLASTIC
D33-1020817 1 ASL REPLENISHMENT, D 91G5330002011 SEAL, THERMOSTAT
D33-1022346 2 ASL STOCK REORDER E 92G6145000998 CABLE, POWER,
D33-1022346 2 ASL STOCK REORDER E 92G6145000998 CABLE, POWER,
D33-1020817 1 ASL REPLENISHMENT, D 91G5330002011 SEAL, THERMOSTAT
D33-1020817 1 ASL REPLENISHMENT, D 91G5330002011 SEAL, THERMOSTAT
D33-1022346 2 ASL STOCK REORDER E 92G6145000998 CABLE, POWER,
but original we need..
ponum polinenum maximo_tbl_a_po_description itemnum maximo_tbl_a_item_description
D33-1021425 5 ASL REORDER HAZMAT 91G8110000071 DRUM, PLASTIC
D33-1020817 2 ASL REPLENISHMENT, D 91G6685000371 THERMOSTAT
D33-1021365 2 ASL - D33DFAC STOCK 91G3920000081 CART, BIG WHEEL
D33-1020817 1 ASL REPLENISHMENT, D 91G5330002011 SEAL, THERMOSTAT
D33-1022346 2 ASL STOCK REORDER E 92G6145000998 CABLE, POWER,Try below:
SELECT DISTINCT
maximo_tbl_matrectrans.ponum
,maximo_tbl_po.description AS [maximo_tbl_po description]
,maximo_tbl_matrectrans.polinenum
,maximo_tbl_matrectrans.itemnum
,maximo_tbl_item.description AS [maximo_tbl_item description]
FROM
maximo_tbl_matrectran
INNER JOIN maximo_tbl_po
ON maximo_tbl_matrectrans.ponum = maximo_tbl_po.ponum
INNER JOIN maximo_tbl_item
ON maximo_tbl_matrectrans.itemnum = maximo_tbl_item.itemnum
-Vaibhav Chaudhari -
Data is not fetching in inner join
Hi Experts,
I developed a select query using inner joins, all the fields data is gettting appended, but one field DISPO data is not getting appeneded. please check the innerjoin and suggest me ur soluitons.
MODULE GET_DATA OUTPUT.
select arbpl
sptag
aufnr
plnum
posnr
plnfl
werks from s022
into table it_s022
where arbpl in s_arbpl
and werks in s_werks
and sptag in s_sptag
and matnr in s_matnr.
if sy-subrc eq 0.
select a~aufnr
a~posnr
a~kdauf
a~pgmng
a~plnum
a~strmp
b~plnty
b~gamng
b~igmng
b~iasmg
b~rmnga
b~gstrp
b~rsnum
b~plnbez
b~dispo
c~maktx
b~plnnr
b~plnty
b~zaehl
d~vornr
d~ltxa1
b~aufpl
b~aplzt
e~astnr
into corresponding fields of table it_afpo from afko as b
inner join afpo as a
on a~aufnr = b~aufnr
inner join makt as c
on b~plnbez = c~matnr
inner join plpo as d
on b~plnnr = d~plnnr
and b~plnty = d~plnty
and b~zaehl = d~zaehl
inner join aufk as e
on b~aufnr = e~aufnr
inner join marc as f
on bplnty = fmatnr
for all entries in it_s022
where b~aufnr = it_s022-aufnr.
and e~erdat = it_s022-sptag
and a~posnr = it_s022-posnr
and a~plnum = it_s022-plnum . .
if sy-subrc eq 0.
it_afpo1[] = it_afpo[].
sort it_afpo1 by aufpl." aplzt."""
delete ADJACENT DUPLICATES FROM it_afpo1 COMPARING aufpl." aplzt ."""
select aufpl
aplzl
fsavd
fsavz
ssedd
ssedz
mgvrg
FROM afvv INTO TABLE It_afvv
FOR ALL ENTRIES IN IT_afpo1
WHERE aufpl = IT_afpo1-aufpl.
and aplzl = it_afpo1-aplzt.
endif.
loop at it_afpo into wa_afpo.
DATA : G_SLNO(8) TYPE C.
G_SLNO = G_SLNO + 1.
wa_afpo-slno = g_slno.
move-corresponding wa_afpo to wa_final.
move-corresponding wa_afko to wa_final.
read table it_afvv into wa_afvv with key
aufpl = wa_afpo-aufpl binary search."aplzl = wa_afpo-aplzt binary search."""
*read table it_afko into wa_afko with key aufnr = wa_final-aufnr.
IF SY-SUBRC EQ 0.
move-corresponding wa_afvv to wa_final.
bal_qty = wa_final-gamng - wa_final-igmng.
move : wa_afpo-slno to wa_final-slno,
wa_afpo-aufnr to wa_final-aufnr,
wa_afpo-posnr to wa_final-posnr,
wa_afpo-kdauf to wa_final-kdauf, " Sales order Number
wa_afpo-pgmng to wa_final-pgmng, " Order item qty
wa_afpo-plnum to wa_final-plnum, " Planned Order Qty
wa_afpo-strmp to wa_final-strmp, " Planned Order Date
wa_afpo-gstrp to wa_final-gstrp, " Basic Finish date
wa_afpo-rsnum to wa_final-rsnum, " Number of Reservation
wa_afpo-plnbez to wa_final-plnbez, " Material Number
wa_afpo-maktx to wa_final-maktx,
wa_afpo-plnnr to wa_final-plnnr,
wa_afpo-plnty to wa_final-plnty,
wa_afpo-zaehl to wa_final-zaehl,
wa_afpo-vornr to wa_final-vornr,
wa_afpo-ltxa1 to wa_final-ltxa1,
wa_afpo-aufpl to wa_final-aufpl,
wa_afvv-fsavd to wa_final-fsavd,
wa_afvv-fsavz to wa_final-fsavz,
wa_afvv-ssedd to wa_final-ssedd,
wa_afvv-ssedz to wa_final-ssedz,
wa_afvv-mgvrg to wa_final-mgvrg,
wa_afko-igmng to wa_final-igmng,
wa_afko-iasmg to wa_final-iasmg,
wa_afko-rmnga to wa_final-rmnga,
wa_afko-dispo to wa_final-dispo,
wa_afko-bal_qty to wa_final-bal_qty,
wa_aufk-astnr to wa_final-astnr,
wa_afpo-text to wa_final-text.
*bal_qty = wa_final-gamng - wa_final-igmng.
*bal_qty = wa_afko-bal_qty.
endif.
append wa_final to it_final.
clear:wa_final ,wa_afpo,wa_afvv,wa_aufk,wa_afko.
endloop.
endif.
ENDMODULE. " GET_DATA OUTPUT
*& Module DISPLAY_DATA OUTPUT
text
MODULE DISPLAY_DATA OUTPUT.
IF REF_CONTAINER IS INITIAL.
PERFORM FIELD_CAT.
CREATE OBJECT REF_CONTAINER
EXPORTING
PARENT =
CONTAINER_NAME = 'CUSTOM_CONTROL'
STYLE =
LIFETIME = lifetime_default
REPID =
DYNNR =
NO_AUTODEF_PROGID_DYNNR =
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
LIFETIME_DYNPRO_DYNPRO_LINK = 5
others = 6
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
L_LAYO-ZEBRA = 'X'.
L_LAYO-GRID_TITLE = 'JOB CARD'.
data: variant type disvariant.
CREATE OBJECT REF_ALV_GRID
EXPORTING
I_SHELLSTYLE = 0
I_LIFETIME =
I_PARENT = REF_CONTAINER
I_APPL_EVENTS = space
I_PARENTDBG =
I_APPLOGPARENT =
I_GRAPHICSPARENT =
I_NAME =
I_FCAT_COMPLETE = SPACE
EXCEPTIONS
ERROR_CNTL_CREATE = 1
ERROR_CNTL_INIT = 2
ERROR_CNTL_LINK = 3
ERROR_DP_CREATE = 4
others = 5
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
l_variant-report = sy-cprog.
*data: l_prnt type lvc_s_prnt.
*l_prnt-print = 'X'.
SORT T_FCAT.
call method ref_alv_grid->set_ready_for_input
exporting
i_ready_for_input = 1.
create object event_receiver.
set handler event_receiver->handle_top_of_page for ref_alv_grid.
CALL METHOD REF_ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
is_variant = variant "l_variant
i_save = 'X'
I_DEFAULT = 'X'
IS_LAYOUT = L_LAYO
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
IR_SALV_ADAPTER =
CHANGING
IT_OUTTAB = IT_final[]
IT_FIELDCATALOG = T_FCAT
IT_SORT =
IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
others = 4
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
create object g_event_receiver.
set handler g_event_receiver->handle_user_command for ref_alv_grid.
set handler g_event_receiver->handle_toolbar for ref_alv_grid.
§ 4.Call method 'set_toolbar_interactive' to raise event TOOLBAR.
call method ref_alv_grid->set_toolbar_interactive.
call method cl_gui_control=>set_focus exporting control = ref_alv_grid.
ENDIF.
ENDMODULE. " DISPLAY_DATA OUTPUT
*& Module STATUS_0100 OUTPUT
text
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'MAIN001'.
SET TITLEBAR 'xxx'.
Regards,
Bharath KumarI agree with Shiva Kumar - most likely there is no such field in it_afpo. A few more suggestions though:
1) Do not post large pieces of code here - if you have a question about a particular SELECT statement, post only that statement and relevant data definitions. No one is going to read your whole program anyway - we have work to do too.
2) Your JOIN is way too big and would be difficult to analyze if anything goes wrong. You might want to start with smaller SELECTs and, when you're sure everything is working correctly, then combine them into one. Also huge JOINT is not necessarily more efficient.
3) You don't have to use aliases "AS a... AS b", etc. Instead, just use the table name, e.g. AFKO... AFPO... .It is much easier to read this way. The aliases are needed only if you're joining the same table more than once. Also they're not limited to one letter either. -
Relationship between tables while using inner joins.
Hi,
I had a few clarifications on "inner joins", and as i was going through the forum, i came across two points,
1. In one of the threads it said " inner joins is applicable for tables that have a parent child relationship.
2. In another thread it said " inner join is established from master table (the table on the left) to the transcation table (the table on the right)".
I have two clarifications based on the above points.
1. Is it necessary that the tables on which im performing an inner join should have a parent-child/children relationship or is it enough that the tables just have a common field.
2. Also is it necessary that the master table should come first, (or can i use any child table from where i can fetch the records when there is a mater table in my report) as shown below.
Eg: select * <fields> from <master table> inner join <table> on <field> into <itab>.
Edited by: Narayananchandran on Dec 27, 2010 12:31 PMhave two clarifications based on the above points.
1. Is it necessary that the tables on which im performing an inner join should have a parent-child/children relationship or is it enough that the tables just have a common field.
2. Also is it necessary that the master table should come first, (or can i use any child table from where i can fetch the records when there is a mater table in my report) as shown below.
Eg: select * <fields> from <master table> inner join <table> on <field> into <itab>
1) NO
2) NO -
I'm having an incredibly hard time with this, mostly because I'm very new with MDX.
I created a simple report (with AdventureWorksDW) whose datasource is an SSAS cube. I select a datekey from the dropdown menu, and the report displays [Measures].[Order Quantity] for that day.
The problem is that the dropdown displays every single value from the dimdate dimension. DimDate goes from 20050101 to 20201231, so the dropdown is very long.
How can I alter the SSRS-generated MDX so that it does an INNER JOIN with Fact table and only the dates shown in the dropdown are the ones where there's data in the Fact table?
Currently, the fact table only has 2 days of data (20141015, 20141016), which means that the dropdown should only display those two dates. I'm including the generated code MDX that populates the dropdown menu:
WITH MEMBER [Measures].[ParameterCaption] AS
[Dim Date].[Date Key].CURRENTMEMBER.MEMBER_CAPTION
MEMBER [Measures].[ParameterValue] AS
[Dim Date].[Date Key].CURRENTMEMBER.UNIQUENAME
MEMBER [Measures].[ParameterLevel] AS
[Dim Date].[Date Key].CURRENTMEMBER.LEVEL.ORDINAL
SELECT {[Measures].[ParameterCaption],
[Measures].[ParameterValue], [Measures].[ParameterLevel]}
ON COLUMNS , [Dim Date].[Date Key].ALLMEMBERS ON ROWS
FROM [Adventure Works cube]
Any help is appreciated.
VMHi vmhatup,
you can get rid of blank data using nonempty function and get rid of negative values using filter function nonempty should be inside of filter so it applies first, otherwise it is too slow.
Your statement could look like this
WITH MEMBER [Measures].[ParameterCaption] AS
[Dim Date].[Date Key].CURRENTMEMBER.MEMBER_CAPTION
MEMBER [Measures].[ParameterValue] AS
[Dim Date].[Date Key].CURRENTMEMBER.UNIQUENAME
MEMBER [Measures].[ParameterLevel] AS
[Dim Date].[Date Key].CURRENTMEMBER.LEVEL.ORDINAL
SELECT {[Measures].[ParameterCaption],
[Measures].[ParameterValue], [Measures].[ParameterLevel]}
ON COLUMNS
, filter(
nonempty([Dim Date].[Date Key].[Date Key],measures.measureName)
,measure.measurename >0
ON ROWS
FROM [Adventure Works cube]
Jiri Neoral -
Crystal Report: Multiple Join in Table
Hi experts,
I have a problem adding a table in a report.
The layout I'm modifing is the Purchase Order (CR). The report contains the necessary tables linked via the Database Expert to OPOR master table.
I need to add the Vendor Item Code in the OSCN table. To reach he correct code I have TWO values: ItemCode and CardCode.
ItemCode is in the POR1 row, and CardCode is in OPOR table.
I tried to add the table and link CardCode between OPOR and OSCN, and the field ItemCode between POR1 and OSCN but crystal say me that, he cannot join a just joined table!
So, how can I add the table OSCN linked correctly in the existing report ti dislay the correct Vendor Item Code near the ItemCode from OITM?
Thanks for your answers.hi Jonny,
paste this to your SQL query window to create this Stored Procedure
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[YourSP_Name]
AS
BEGIN
SET NOCOUNT ON;
SELECT OPOR.DocNum, POR1.DocEntry, POR1.LineNum, POR1.ItemCode, OPOR.CardCode, OSCN.Substitute
FROM OPOR INNER JOIN
POR1 ON OPOR.DocEntry = POR1.DocEntry INNER JOIN
OSCN ON OPOR.CardCode = OSCN.CardCode AND POR1.ItemCode = OSCN.ItemCode INNER JOIN
OITM ON OSCN.ItemCode = OITM.ItemCode
ORDER BY POR1.DocEntry
END
GO
then call this stored procedure in Crystal report
regards,
Fidel -
Hi ABAPers,
I was trying to develop a report for which query is something like this.
*& Report ZT_SERIAL
REPORT ZT_SERIAL.
TABLES : SER01,SER03,OBJK,LIKP,LIPS. " LIKP - SD invoice header table, LIPS - SD invoice details table
TYPE-POOLS: SLIS.
DATA: AFIELD TYPE SLIS_FIELDCAT_ALV.
DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
MANDATORY WHILE DECLARING ALV ***
DATA: L_FIELDCAT TYPE SLIS_FIELDCAT_ALV..
DATA: V_EVENTS TYPE SLIS_T_EVENT.
DATA: LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: P_FIELDTAB TYPE SLIS_T_FIELDCAT_ALV.
DATA: I_TITLE_SL_NO_TRACK TYPE LVC_TITLE VALUE 'SERIAL NO TRACKER'.
DATA : BEGIN OF ITAB OCCURS 0,
OBKNR LIKE OBJK-OBKNR, "OBJECT LIST
OBZAE LIKE OBJK-OBZAE, "OBJECT COUNTER
KUNDE LIKE SER01-KUNDE, "CUSTOMER NO
MATNR LIKE OBJK-MATNR, "PART NO
SERNR LIKE OBJK-SERNR, "SERIAL NO
MBLNR LIKE SER03-MBLNR, "GRN/MATERIAL DOC NO
LIEF_NR LIKE SER01-LIEF_NR,"OUTBOUND DELV NO
DATUM LIKE SER01-DATUM, "OUTBOUND DELV DATE
TASER LIKE OBJK-TASER, "HEADER TABLE
ANZSN LIKE SER01-ANZSN, "NO OF SERIAL NOS
VGBEL LIKE LIPS-VGBEL, "SALES ORDER NO
END OF ITAB.
SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_KUNDE FOR SER01-KUNDE,
S_VGBEL FOR LIPS-VGBEL,
S_MATNR FOR OBJK-MATNR,
S_SERNR FOR OBJK-SERNR,
S_MBLNR FOR SER03-MBLNR,
S_LIFNR FOR SER01-LIEF_NR,
S_DATUM FOR SER01-DATUM.
SELECTION-SCREEN : END OF BLOCK B1.
PERFORM TRACKING.
PERFORM FLDCAT.
PERFORM BUILD_LAYOUT.
***CALL FUNCTION TO DISPLAY IN ALV FORMAT*******
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_GRID_TITLE = I_TITLE_SL_NO_TRACK
IS_LAYOUT = LAYOUT
IT_FIELDCAT = P_FIELDTAB[]
I_SAVE = 'A'
IT_EVENTS = V_EVENTS
TABLES
T_OUTTAB = ITAB.
***END OF CALL FUNCTION
FORM TRACKING.
SELECT OBJKOBKNR OBJKOBZAE OBJKMATNR OBJKSERNR OBJK~TASER
SER01KUNDE SER01LIEF_NR SER01DATUM SER01ANZSN
SER03~MBLNR
LIPS~VGBEL
INTO TABLE ITAB FROM OBJK
INNER JOIN SER01 ON OBJKOBKNR = SER01OBKNR
INNER JOIN SER03 ON OBJKOBKNR = SER03OBKNR
INNER JOIN LIPS ON SER01LIEF_NR = LIPSVBELN
WHERE
OBJKTASER = 'SER01' OR OBJKTASER = 'SER03'.
OBJK~MATNR IN S_MATNR AND
OBJK~SERNR IN S_SERNR AND
SER01~KUNDE IN S_KUNDE AND
SER01~LIEF_NR IN S_LIFNR AND
SER01~DATUM IN S_DATUM AND
SER03~MBLNR IN S_MBLNR AND
LIPS~VGBEL IN S_VGBEL.
ENDFORM.
*& Form fldcat
text
FORM FLDCAT.
PERFORM FLDCAT1 USING 'KUNDE' 'Customer No'.
PERFORM FLDCAT1 USING 'VGBEL' 'Sales Order No'.
PERFORM FLDCAT1 USING 'MATNR' 'Tejas Part No'.
PERFORM FLDCAT1 USING 'SERNR' 'Serial No'.
PERFORM FLDCAT1 USING 'MBLNR' 'Material Doc No'.
PERFORM FLDCAT1 USING 'LIEF_NR' 'Outbound Delv No'.
PERFORM FLDCAT1 USING 'DATUM' 'Outbound Delv Date'.
ENDFORM. "fldcat
*& Form fldcat1
text
-->FNAM text
-->FTEXT text
FORM FLDCAT1 USING FNAM FTEXT.
DATA: L_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
L_FIELDCAT-FIELDNAME = FNAM.
L_FIELDCAT-SELTEXT_M = FTEXT.
IF FNAM EQ 'MATNR'."OR fnam EQ 'PKUNAG'.
L_FIELDCAT-KEY = 'X'.
ENDIF.
LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
APPEND L_FIELDCAT TO P_FIELDTAB.
CLEAR fldcat1.
ENDFORM. "fldcat1
*& Form build_layout
text
FORM BUILD_LAYOUT .
LAYOUT-NO_INPUT = 'X'.
LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
LAYOUT-ZEBRA = 'X'.
LAYOUT-TOTALS_TEXT = 'Totals'(256).
layout-coltab_fieldname = 'CELL_COLOUR'.
*clear layout.
ENDFORM.
But when I run this query,the program gets terminated.Can you please help me in rectifying the query and generate the output?
Thanks in advance
BhavinHi
I have corrected the code please copy and past it and then try.
Report ZT_SERIAL.
TABLES : SER01,SER03,OBJK,LIKP,LIPS.
" LIKP - SD invoice header table, LIPS - SD invoice details table
TYPE-POOLS: SLIS.
DATA: AFIELD TYPE SLIS_FIELDCAT_ALV.
DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
+ MANDATORY WHILE DECLARING ALV ***
DATA: L_FIELDCAT TYPE SLIS_FIELDCAT_ALV..
DATA: V_EVENTS TYPE SLIS_T_EVENT.
DATA: LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: P_FIELDTAB TYPE SLIS_T_FIELDCAT_ALV.
DATA: I_TITLE_SL_NO_TRACK TYPE LVC_TITLE VALUE 'SERIAL NO TRACKER'.
DATA : BEGIN OF ITAB OCCURS 0,
OBKNR LIKE OBJK-OBKNR, "OBJECT LIST
OBZAE LIKE OBJK-OBZAE, "OBJECT COUNTER
KUNDE LIKE SER01-KUNDE, "CUSTOMER NO
MATNR LIKE OBJK-MATNR, "PART NO
SERNR LIKE OBJK-SERNR, "SERIAL NO
MBLNR LIKE SER03-MBLNR, "GRN/MATERIAL DOC NO
LIEF_NR LIKE SER01-LIEF_NR,"OUTBOUND DELV NO
DATUM LIKE SER01-DATUM, "OUTBOUND DELV DATE
TASER LIKE OBJK-TASER, "HEADER TABLE
ANZSN LIKE SER01-ANZSN, "NO OF SERIAL NOS
VGBEL LIKE LIPS-VGBEL, "SALES ORDER NO
END OF ITAB.
SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_KUNDE FOR SER01-KUNDE,
S_VGBEL FOR LIPS-VGBEL,
S_MATNR FOR OBJK-MATNR,
S_SERNR FOR OBJK-SERNR,
S_MBLNR FOR SER03-MBLNR,
S_LIFNR FOR SER01-LIEF_NR,
S_DATUM FOR SER01-DATUM.
SELECTION-SCREEN : END OF BLOCK B1.
PERFORM TRACKING.
PERFORM FLDCAT.
PERFORM BUILD_LAYOUT.
***CALL FUNCTION TO DISPLAY IN ALV FORMAT*******
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_GRID_TITLE = I_TITLE_SL_NO_TRACK
IS_LAYOUT = LAYOUT
IT_FIELDCAT = P_FIELDTAB[]
I_SAVE = 'A'
IT_EVENTS = V_EVENTS
TABLES
T_OUTTAB = ITAB.
***END OF CALL FUNCTION
FORM TRACKING.
*SELECT OBJK~OBKNR
OBJK~OBZAE
OBJK~MATNR
OBJK~SERNR
OBJK~TASER
SER01~KUNDE
SER01~LIEF_NR
SER01~DATUM
SER01~ANZSN
SER03~MBLNR
LIPS~VGBEL
INTO TABLE ITAB FROM OBJK
INNER JOIN SER01 ON OBJKOBKNR = SER01OBKNR
INNER JOIN SER03 ON OBJKOBKNR = SER03OBKNR
INNER JOIN LIPS ON SER01LIEF_NR = LIPSVBELN
WHERE
*( OBJKTASER = 'SER01' OR OBJKTASER = 'SER03' ) and
*OBJK-MATNR IN S_MATNR AND
*OBJK~SERNR IN S_SERNR AND
*SER01~KUNDE IN S_KUNDE AND
*SER01~LIEF_NR IN S_LIFNR AND
*SER01~DATUM IN S_DATUM AND
*SER03~MBLNR IN S_MBLNR AND
*LIPS~VGBEL IN S_VGBEL.
SELECT a~OBKNR "OBJK
a~OBZAE
a~MATNR
a~SERNR
a~TASER
b~KUNDE "SER01
b~LIEF_NR
b~DATUM
b~ANZSN
c~MBLNR "SER03
D~VGBEL "LIPS
INTO TABLE ITAB FROM ( OBJK as a
INNER JOIN SER01 as b ON aOBKNR = bOBKNR
INNER JOIN SER03 as c ON aOBKNR = cOBKNR
INNER JOIN LIPS as d ON bLIEF_NR = dVBELN )
WHERE
( aTASER = 'SER01' OR aTASER = 'SER03' ) and
a~MATNR IN S_MATNR AND
a~SERNR IN S_SERNR AND
b~KUNDE IN S_KUNDE AND
b~LIEF_NR IN S_LIFNR AND
b~DATUM IN S_DATUM AND
c~MBLNR IN S_MBLNR AND
d~VGBEL IN S_VGBEL.
ENDFORM.
*& Form fldcat
* text
FORM FLDCAT.
PERFORM FLDCAT1 USING 'KUNDE' 'Customer No'.
PERFORM FLDCAT1 USING 'VGBEL' 'Sales Order No'.
PERFORM FLDCAT1 USING 'MATNR' 'Tejas Part No'.
PERFORM FLDCAT1 USING 'SERNR' 'Serial No'.
PERFORM FLDCAT1 USING 'MBLNR' 'Material Doc No'.
PERFORM FLDCAT1 USING 'LIEF_NR' 'Outbound Delv No'.
PERFORM FLDCAT1 USING 'DATUM' 'Outbound Delv Date'.
ENDFORM. "fldcat
*& Form fldcat1
text
-->FNAM text
-->FTEXT text
FORM FLDCAT1 USING FNAM FTEXT.
DATA: L_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
L_FIELDCAT-FIELDNAME = FNAM.
L_FIELDCAT-SELTEXT_M = FTEXT.
IF FNAM EQ 'MATNR'."OR fnam EQ 'PKUNAG'.
L_FIELDCAT-KEY = 'X'.
ENDIF.
LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
APPEND L_FIELDCAT TO P_FIELDTAB.
* CLEAR fldcat1.
ENDFORM. "fldcat1
*& Form build_layout
* text
FORM BUILD_LAYOUT .
LAYOUT-NO_INPUT = 'X'.
LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
LAYOUT-ZEBRA = 'X'.
LAYOUT-TOTALS_TEXT = 'Totals'(256).
* layout-coltab_fieldname = 'CELL_COLOUR'.
*clear layout.
ENDFORM.
Regards,
Venkat -
Reply to vj (qery on the inner joins v/s performane test)
this is ravi shiva's friend.
hi vj,
u r working for intelli group....and i had met u twice. by the way give u r contact number i want to speak to u personally.
here is the code...
REPORT rv_sid_purchase_order_status NO STANDARD PAGE HEADING MESSAGE-ID zrv_message_cl LINE-COUNT 65 LINE-SIZE 110 .
This include contains declarations
INCLUDE zrv_sid_purchase_order_t.
This include contains code for the performs
INCLUDE zrv_sid_purchase_order_f.
Initialization
INITIALIZATION.
This perform will initialize the values.
PERFORM f_initilaize.
This perform will initialize the field catalog.
PERFORM f_e01_fieldcat_init USING gt_fieldcat[].
Start-Of-Selection
START-OF-SELECTION.
This perform will read the values from the database.
PERFORM f_selection.
This perform will call the function module to display the values on the list.
PERFORM f_display.
End-Of-Selection
END-OF-SELECTION.
*& Include ZRV_SID_PURCHASE_ORDER_T *
T a b l e s D e c l a r a t i o n s *
TABLES: ekko,ekpo,ekbe,ekkn,mkpf.
Type Pools D e c l a r a t i o n s *
TYPE-POOLS: slis.
Selection Screen Declaration
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-100.
SELECT-OPTIONS: ebeln FOR ekko-ebeln,
aedat FOR ekko-aedat.
SELECTION-SCREEN END OF BLOCK b1.
V a r i a b l e s *
DATA : gt_fieldcat TYPE slis_t_fieldcat_alv,
g_repid LIKE sy-repid,
gs_keyinfo TYPE slis_keyinfo_alv,
g_tabname_header TYPE slis_tabname,
g_tabname_item TYPE slis_tabname,
ls_layout TYPE slis_layout_alv,
gt_list_top_of_page TYPE slis_t_listheader.
I n t e r n a l T a b l e s *
DATA: BEGIN OF itab OCCURS 0,
ebeln LIKE ekko-ebeln,
lifnr LIKE ekko-lifnr,
aedat LIKE ekko-aedat,
submi LIKE ekko-submi,
name1 LIKE lfa1-name1,
netwr LIKE erev-netwr,
END OF itab.
DATA: BEGIN OF jtab OCCURS 0,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
aedat LIKE ekpo-aedat,
txz01 LIKE ekpo-txz01,
menge1 LIKE ekpo-menge,
menge2 LIKE ekbe-menge,
effwr1 LIKE ekpo-effwr,
mwskz1 LIKE ekpo-mwskz,
ps_psp_pnr LIKE ekkn-ps_psp_pnr,
bewtp1 LIKE ekbe-bewtp,
belnr1 LIKE ekbe-belnr,
dmbtt LIKE ekbe-dmbtr,
mblnr1 LIKE mkpf-mblnr,
bldat1 LIKE mkpf-bldat,
xblnr1 LIKE mkpf-xblnr,
frbnr LIKE mkpf-frbnr,
END OF jtab.
*& Include ZRV_SID_PURCHASE_ORDER_F *
FORM f_initilaize .
g_repid = sy-repid.
g_tabname_header = 'itab'.
g_tabname_item = 'jtab'.
CLEAR gs_keyinfo.
gs_keyinfo-header01 = 'EBELN'.
gs_keyinfo-item01 = 'EBELN'.
gs_keyinfo-header02 = space.
gs_keyinfo-item02 = 'EBELP'.
ls_layout-group_change_edit = 'X'.
ls_layout-colwidth_optimize = 'X'.
ls_layout-zebra = 'X'.
ls_layout-detail_popup = 'X'.
ls_layout-get_selinfos = 'X'.
ls_layout-window_titlebar = 'PURCHASE ORDER STATUS'.
ls_layout-no_keyfix = 'X'.
ENDFORM. " f_INITILAIZE
*& Form f_e01_fieldcat_init
text
-->E01_LT_FIELtext
FORM f_e01_fieldcat_init USING e01_lt_fieldcat TYPE slis_t_fieldcat_alv.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SUBMI'.
ls_fieldcat-tabname = g_tabname_header.
ls_fieldcat-ref_fieldname = 'SUBMI'.
ls_fieldcat-ref_tabname = 'EKKO'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'EBELN'.
ls_fieldcat-tabname = g_tabname_header.
ls_fieldcat-ref_fieldname = 'EBELN'.
ls_fieldcat-ref_tabname = 'EKPO'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'LIFNR'.
ls_fieldcat-tabname = g_tabname_header.
ls_fieldcat-ref_fieldname = 'LIFNR'.
ls_fieldcat-ref_tabname = 'EKKO'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'NAME1'.
ls_fieldcat-tabname = g_tabname_header.
ls_fieldcat-ref_fieldname = 'NAME1'.
ls_fieldcat-ref_tabname = 'LFA1'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'NETWR'.
ls_fieldcat-tabname = g_tabname_header.
ls_fieldcat-ref_fieldname = 'NETWR'.
ls_fieldcat-ref_tabname = 'EREV'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-do_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'EBELP'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'EBELP'.
ls_fieldcat-ref_tabname = 'EKPO'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TXZ01'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'TXZ01'.
ls_fieldcat-ref_tabname = 'EKPO'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-just = 'L'.
ls_fieldcat-fieldname = 'MWSKZ1'.
ls_fieldcat-seltext_l = 'Tax code'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'MWSKZ1'.
ls_fieldcat-ref_tabname = 'EKPO'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-just = 'L'.
ls_fieldcat-fieldname = 'PS_PSP_PNR'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'PS_PSP_PNR'.
ls_fieldcat-ref_tabname = 'EKKN'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MENGE1'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-seltext_l = 'Po quantity'.
ls_fieldcat-ref_fieldname = 'MENGE1'.
ls_fieldcat-ref_tabname = 'EKPO'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'MENGE1'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'EFFWR1'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-seltext_l = 'Po value'.
ls_fieldcat-ref_fieldname = 'EFFWR1'.
ls_fieldcat-ref_tabname = 'EKPO'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BEWTP1'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-seltext_l = 'Cat'.
ls_fieldcat-ref_fieldname = 'BEWTP1'.
ls_fieldcat-ref_tabname = 'EKBE'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BELNR1'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-seltext_l = 'GR/IR MDoc'.
ls_fieldcat-ref_fieldname = 'BELNR1'.
ls_fieldcat-ref_tabname = 'EKBE'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MENGE2'.
ls_fieldcat-seltext_l = 'GR/IR quantity'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'MENGE2'.
ls_fieldcat-ref_tabname = 'EKBE'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MBLNR1'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-seltext_l = 'GR No'.
ls_fieldcat-ref_fieldname = 'MBLNR1'.
ls_fieldcat-ref_tabname = 'MKPF'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BLDAT1'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-seltext_l = 'GR Date'.
ls_fieldcat-ref_fieldname = 'BLDAT1'.
ls_fieldcat-ref_tabname = 'MKPF'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'FRBNR'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'FRBNR'.
ls_fieldcat-ref_tabname = 'MKPF'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'XBLNR1'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-seltext_l = 'Invoice No in GR'.
ls_fieldcat-ref_fieldname = 'XBLNR1'.
ls_fieldcat-ref_tabname = 'MKPF'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'DMBTT'.
ls_fieldcat-seltext_l = 'Invoice value W/O tax'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'DMBTT'.
ls_fieldcat-ref_tabname = 'EKBE'.
ls_fieldcat-key = 'X'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-no_sum = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO e01_lt_fieldcat.
ENDFORM. " f_e01_fieldcat_init
*& Form f_selection
text
FORM f_selection .
SELECT ekko~ebeln
ekko~lifnr
ekko~aedat
ekko~submi
lfa1~name1
erev~netwr
FROM ekko INNER JOIN lfa1 ON ( ekkolifnr = lfa1lifnr )
INNER JOIN erev ON ( ekkoebeln = erevedokn )
INTO TABLE itab WHERE ekko~ebeln IN ebeln AND
ekko~aedat IN aedat AND
bsart <> 'AN'.
SELECT
ekpo~ebeln
ekpo~ebelp
ekpo~aedat
ekpo~txz01
ekpo~menge
ekbe~menge
ekpo~effwr
ekpo~mwskz
ekkn~ps_psp_pnr
ekbe~bewtp
ekbe~belnr
ekbe~dmbtr
mkpf~mblnr
mkpf~bldat
mkpf~xblnr
mkpf~frbnr
FROM ekpo INNER JOIN ekkn ON ( ekpoebeln = ekknebeln
AND
ekknebelp = ekpoebelp )
INNER JOIN ekbe ON ( ekknebeln = ekbeebeln
AND
ekknebelp = ekbeebelp )
LEFT OUTER JOIN mkpf ON ( ekbebelnr = mkpfmblnr )
INTO TABLE jtab FOR ALL ENTRIES IN itab WHERE ekpo~ebeln = itab-ebeln AND
ekpo~aedat = itab-aedat.
ENDFORM. " f_selection
*& Form f_display
text
FORM f_display .
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_callback_program = g_repid
it_fieldcat = gt_fieldcat[]
i_tabname_header = g_tabname_header
i_tabname_item = g_tabname_item
is_keyinfo = gs_keyinfo
is_layout = ls_layout
TABLES
t_outtab_header = itab
t_outtab_item = jtab.
ENDFORM. " f_displayHi Ravi,
1. To check performance of a report we use the perfromance trace. The transaction code is ST05.
You can also refer the link :
http://help.sap.com/saphelp_erp2005/helpdata/en/8a/3b834014d26f1de10000000a1550b0/content.htm
2. Also we can do the run time analysis of the code uising transaction code SE30.
3. To do a general check on the code , you can use the SAP Code Inspector. The transaction code for this is SCI. This will defentely give you a detailed analysis of the program.
4 . To have a general idea about the performance tuning of a report , you should refer the link :
http://www.sapgenie.com/abap/performance.htm.
Hope this solves yopur query.
Regards,
Kunal. -
Very Slow Query with CTE inner join
I have 2 tables (heavily simplified here to show relevant columns):
CREATE TABLE tblCharge
(ChargeID int NOT NULL,
ParentChargeID int NULL,
ChargeName varchar(200) NULL)
CREATE TABLE tblChargeShare
(ChargeShareID int NOT NULL,
ChargeID int NOT NULL,
TotalAmount money NOT NULL,
TaxAmount money NULL,
DiscountAmount money NULL,
CustomerID int NOT NULL,
ChargeShareStatusID int NOT NULL)
I have a very basic View to Join them:
CREATE VIEW vwBASEChargeShareRelation as
Select c.ChargeID, ParentChargeID, s.CustomerID, s.TotalAmount, isnull(s.TaxAmount, 0) as TaxAmount, isnull(s.DiscountAmount, 0) as DiscountAmount
from tblCharge c inner join tblChargeShare s
on c.ChargeID = s.ChargeID Where s.ChargeShareStatusID < 3
GO
I then have a view containing a CTE to get the children of the Parent Charge:
ALTER VIEW [vwChargeShareSubCharges] AS
WITH RCTE AS
SELECT ParentChargeId, ChargeID, 1 AS Lvl, ISNULL(TotalAmount, 0) as TotalAmount, ISNULL(TaxAmount, 0) as TaxAmount,
ISNULL(DiscountAmount, 0) as DiscountAmount, CustomerID, ChargeID as MasterChargeID
FROM vwBASEChargeShareRelation Where ParentChargeID is NULL
UNION ALL
SELECT rh.ParentChargeID, rh.ChargeID, Lvl+1 AS Lvl, ISNULL(rh.TotalAmount, 0), ISNULL(rh.TaxAmount, 0), ISNULL(rh.DiscountAmount, 0) , rh.CustomerID
, rc.MasterChargeID
FROM vwBASEChargeShareRelation rh
INNER JOIN RCTE rc ON rh.PArentChargeID = rc.ChargeID and rh.CustomerID = rc.CustomerID
Select MasterChargeID as ChargeID, CustomerID, Sum(TotalAmount) as TotalCharged, Sum(TaxAmount) as TotalTax, Sum(DiscountAmount) as TotalDiscount
from RCTE
Group by MasterChargeID, CustomerID
GO
So far so good, I can query this view and get the total cost for a line item including all children.
The problem occurs when I join this table. The query:
Select t.* from vwChargeShareSubCharges t
inner join
tblChargeShare s
on t.CustomerID = s.CustomerID
and t.MasterChargeID = s.ChargeID
Where s.ChargeID = 1291094
Takes around 30 ms to return a result (tblCharge and Charge Share have around 3.5 million records).
But the query:
Select t.* from vwChargeShareSubCharges t
inner join
tblChargeShare s
on t.CustomerID = s.CustomerID
and t.MasterChargeID = s.ChargeID
Where InvoiceID = 1045854
Takes around 2 minutes to return a result - even though the only charge with that InvoiceID is the same charge as the one used in the previous query.
The same thing occurs if I do the join in the same query that the CTE is defined in.
I ran the execution plan for each query. The first (fast) query looks like this:
The second(slow) query looks like this:
I am at a loss, and my skills at decoding execution plans to resolve this are lacking.
I have separate indexes on tblCharge.ChargeID, tblCharge.ParentChargeID, tblChargeShare.ChargeID, tblChargeShare.InvoiceID, tblChargeShare.ChargeShareStatusID
Any ideas? Tested on SQL 2008R2 and SQL 2012>> The database is linked [sic] to an established app and the column and table names can't be changed. <<
Link? That is a term from pointer chains and network databases, not SQL. I will guess that means the app came back in the old pre-RDBMS days and you are screwed.
>> I am not too worried about the money field [sic], this is used for money and money based calculations so the precision and rounding are acceptable at this level. <<
Field is a COBOL concept; columns are totally different. MONEY is how Sybase mimics the PICTURE clause that puts currency signs, commas, period, etc in a COBOL money field.
Using more than one operation (multiplication or division) on money columns will produce severe rounding errors. A simple way to visualize money arithmetic is to place a ROUND() function calls after
every operation. For example,
Amount = (Portion / total_amt) * gross_amt
can be rewritten using money arithmetic as:
Amount = ROUND(ROUND(Portion/total_amt, 4) *
gross_amt, 4)
Rounding to four decimal places might not seem an
issue, until the numbers you are using are greater
than 10,000.
BEGIN
DECLARE @gross_amt MONEY,
@total_amt MONEY,
@my_part MONEY,
@money_result MONEY,
@float_result FLOAT,
@all_floats FLOAT;
SET @gross_amt = 55294.72;
SET @total_amt = 7328.75;
SET @my_part = 1793.33;
SET @money_result = (@my_part / @total_amt) *
@gross_amt;
SET @float_result = (@my_part / @total_amt) *
@gross_amt;
SET @Retult3 = (CAST(@my_part AS FLOAT)
/ CAST( @total_amt AS FLOAT))
* CAST(FLOAT, @gross_amt AS FLOAT);
SELECT @money_result, @float_result, @all_floats;
END;
@money_result = 13525.09 -- incorrect
@float_result = 13525.0885 -- incorrect
@all_floats = 13530.5038673171 -- correct, with a -
5.42 error
>> The keys are ChargeID(int, identity) and ChargeShareID(int, identity). <<
Sorry, but IDENTITY is not relational and cannot be a key by definition. But it sure works just like a record number in your old COBOL file system.
>> .. these need to be int so that they are assigned by the database and unique. <<
No, the data type of a key is not determined by physical storage, but by logical design. IDENTITY is the number of a parking space in a garage; a VIN is how you identify the automobile.
>> What would you recommend I use as keys? <<
I do not know. I have no specs and without that, I cannot pull a Kabbalah number from the hardware. Your magic numbers can identify Squids, Automobile or Lady Gaga! I would ask the accounting department how they identify a charge.
>> Charge_Share_Status_ID links [sic] to another table which contains the name, formatting [sic] and other information [sic] or a charge share's status, so it is both an Id and a status. <<
More pointer chains! Formatting? Unh? In RDBMS, we use a tiered architecture. That means display formatting is in a presentation layer. A properly created table has cohesion – it does one and only one data element. A status is a state of being that applies
to an entity over a period time (think employment, marriage, etc. status if that is too abstract).
An identifier is based on the Law of Identity from formal logic “To be is to be something in particular” or “A is A” informally. There is no entity here! The Charge_Share_Status table should have the encoded values for a status and perhaps a description if
they are unclear. If the list of values is clear, short and static, then use a CHECK() constraint.
On a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, this is literally that silly and wrong.
>> I understand what a CTE is; is there a better way to sum all children for a parent hierarchy? <<
There are many ways to represent a tree or hierarchy in SQL. This is called an adjacency list model and it looks like this:
CREATE TABLE OrgChart
(emp_name CHAR(10) NOT NULL PRIMARY KEY,
boss_emp_name CHAR(10) REFERENCES OrgChart(emp_name),
salary_amt DECIMAL(6,2) DEFAULT 100.00 NOT NULL,
<< horrible cycle constraints >>);
OrgChart
emp_name boss_emp_name salary_amt
==============================
'Albert' NULL 1000.00
'Bert' 'Albert' 900.00
'Chuck' 'Albert' 900.00
'Donna' 'Chuck' 800.00
'Eddie' 'Chuck' 700.00
'Fred' 'Chuck' 600.00
This approach will wind up with really ugly code -- CTEs hiding recursive procedures, horrible cycle prevention code, etc. The root of your problem is not knowing that rows are not records, that SQL uses sets and trying to fake pointer chains with some
vague, magical non-relational "id".
This matches the way we did it in old file systems with pointer chains. Non-RDBMS programmers are comfortable with it because it looks familiar -- it looks like records and not rows.
Another way of representing trees is to show them as nested sets.
Since SQL is a set oriented language, this is a better model than the usual adjacency list approach you see in most text books. Let us define a simple OrgChart table like this.
CREATE TABLE OrgChart
(emp_name CHAR(10) NOT NULL PRIMARY KEY,
lft INTEGER NOT NULL UNIQUE CHECK (lft > 0),
rgt INTEGER NOT NULL UNIQUE CHECK (rgt > 1),
CONSTRAINT order_okay CHECK (lft < rgt));
OrgChart
emp_name lft rgt
======================
'Albert' 1 12
'Bert' 2 3
'Chuck' 4 11
'Donna' 5 6
'Eddie' 7 8
'Fred' 9 10
The (lft, rgt) pairs are like tags in a mark-up language, or parens in algebra, BEGIN-END blocks in Algol-family programming languages, etc. -- they bracket a sub-set. This is a set-oriented approach to trees in a set-oriented language.
The organizational chart would look like this as a directed graph:
Albert (1, 12)
Bert (2, 3) Chuck (4, 11)
/ | \
/ | \
/ | \
/ | \
Donna (5, 6) Eddie (7, 8) Fred (9, 10)
The adjacency list table is denormalized in several ways. We are modeling both the Personnel and the Organizational chart in one table. But for the sake of saving space, pretend that the names are job titles and that we have another table which describes the
Personnel that hold those positions.
Another problem with the adjacency list model is that the boss_emp_name and employee columns are the same kind of thing (i.e. identifiers of personnel), and therefore should be shown in only one column in a normalized table. To prove that this is not
normalized, assume that "Chuck" changes his name to "Charles"; you have to change his name in both columns and several places. The defining characteristic of a normalized table is that you have one fact, one place, one time.
The final problem is that the adjacency list model does not model subordination. Authority flows downhill in a hierarchy, but If I fire Chuck, I disconnect all of his subordinates from Albert. There are situations (i.e. water pipes) where this is true, but
that is not the expected situation in this case.
To show a tree as nested sets, replace the nodes with ovals, and then nest subordinate ovals inside each other. The root will be the largest oval and will contain every other node. The leaf nodes will be the innermost ovals with nothing else inside them
and the nesting will show the hierarchical relationship. The (lft, rgt) columns (I cannot use the reserved words LEFT and RIGHT in SQL) are what show the nesting. This is like XML, HTML or parentheses.
At this point, the boss_emp_name column is both redundant and denormalized, so it can be dropped. Also, note that the tree structure can be kept in one table and all the information about a node can be put in a second table and they can be joined on employee
number for queries.
To convert the graph into a nested sets model think of a little worm crawling along the tree. The worm starts at the top, the root, makes a complete trip around the tree. When he comes to a node, he puts a number in the cell on the side that he is visiting
and increments his counter. Each node will get two numbers, one of the right side and one for the left. Computer Science majors will recognize this as a modified preorder tree traversal algorithm. Finally, drop the unneeded OrgChart.boss_emp_name column
which used to represent the edges of a graph.
This has some predictable results that we can use for building queries. The root is always (left = 1, right = 2 * (SELECT COUNT(*) FROM TreeTable)); leaf nodes always have (left + 1 = right); subtrees are defined by the BETWEEN predicate; etc. Here are
two common queries which can be used to build others:
1. An employee and all their Supervisors, no matter how deep the tree.
SELECT O2.*
FROM OrgChart AS O1, OrgChart AS O2
WHERE O1.lft BETWEEN O2.lft AND O2.rgt
AND O1.emp_name = :in_emp_name;
2. The employee and all their subordinates. There is a nice symmetry here.
SELECT O1.*
FROM OrgChart AS O1, OrgChart AS O2
WHERE O1.lft BETWEEN O2.lft AND O2.rgt
AND O2.emp_name = :in_emp_name;
3. Add a GROUP BY and aggregate functions to these basic queries and you have hierarchical reports. For example, the total salaries which each employee controls:
SELECT O2.emp_name, SUM(S1.salary_amt)
FROM OrgChart AS O1, OrgChart AS O2,
Salaries AS S1
WHERE O1.lft BETWEEN O2.lft AND O2.rgt
AND S1.emp_name = O2.emp_name
GROUP BY O2.emp_name;
4. To find the level and the size of the subtree rooted at each emp_name, so you can print the tree as an indented listing.
SELECT O1.emp_name,
SUM(CASE WHEN O2.lft BETWEEN O1.lft AND O1.rgt
THEN O2.sale_amt ELSE 0.00 END) AS sale_amt_tot,
SUM(CASE WHEN O2.lft BETWEEN O1.lft AND O1.rgt
THEN 1 ELSE 0 END) AS subtree_size,
SUM(CASE WHEN O1.lft BETWEEN O2.lft AND O2.rgt
THEN 1 ELSE 0 END) AS lvl
FROM OrgChart AS O1, OrgChart AS O2
GROUP BY O1.emp_name;
5. The nested set model has an implied ordering of siblings which the adjacency list model does not. To insert a new node, G1, under part G. We can insert one node at a time like this:
BEGIN ATOMIC
DECLARE rightmost_spread INTEGER;
SET rightmost_spread
= (SELECT rgt
FROM Frammis
WHERE part = 'G');
UPDATE Frammis
SET lft = CASE WHEN lft > rightmost_spread
THEN lft + 2
ELSE lft END,
rgt = CASE WHEN rgt >= rightmost_spread
THEN rgt + 2
ELSE rgt END
WHERE rgt >= rightmost_spread;
INSERT INTO Frammis (part, lft, rgt)
VALUES ('G1', rightmost_spread, (rightmost_spread + 1));
COMMIT WORK;
END;
The idea is to spread the (lft, rgt) numbers after the youngest child of the parent, G in this case, over by two to make room for the new addition, G1. This procedure will add the new node to the rightmost child position, which helps to preserve the idea
of an age order among the siblings.
6. To convert a nested sets model into an adjacency list model:
SELECT B.emp_name AS boss_emp_name, E.emp_name
FROM OrgChart AS E
LEFT OUTER JOIN
OrgChart AS B
ON B.lft
= (SELECT MAX(lft)
FROM OrgChart AS S
WHERE E.lft > S.lft
AND E.lft < S.rgt);
7. To find the immediate parent of a node:
SELECT MAX(P2.lft), MIN(P2.rgt)
FROM Personnel AS P1, Personnel AS P2
WHERE P1.lft BETWEEN P2.lft AND P2.rgt
AND P1.emp_name = @my_emp_name;
I have a book on TREES & HIERARCHIES IN SQL which you can get at Amazon.com right now. It has a lot of other programming idioms for nested sets, like levels, structural comparisons, re-arrangement procedures, etc.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Hi all,
In a report program i have used a inner join. I am getting error in the where condition. Here I have furnished part of my code for ur reference.
Tables : mara, makt, mard.
data : begin of itab occurs 0,
matnr like mara-matnr,
maktx like makt-maktx,
lgort like mard-lgort,
labst like mard-labst,
end of itab.
parameters : matnr like mara-matnr.
start-of-selection.
select maramatnr maktmaktx mardlgort mardlabst into corresponding fields of iab from mara inner join maktx on maramatnr = maktmatnr inner join mard on maktmatnr = mardmatnr where matnr eq matnr.
in the where condition I am getting the following error message.
matnr has two meanings in data dictionary.
Please help me in sort out this problem and also tell me more abt inner joins.
thanks.HI,
You can achieve this in two ways:
1st:
into corresponding fields of TABLE itab
2nd:
if you have inner join you don't need where any more at all! you already have connections.
if you still need then use:
tablename~fieldname
for both sides!
if in your example matnr from left side is local or global variable then you have problem with some naming conventions which usually are used in SAP.
try 1st points at the beggining
i'd write your select in this style
Code:
select mara~matnr
makt~maktx
mardlgort mardlabst
into corresponding fields of table itab
from ( mara
inner join makt on maktmatnr = maramatnr
and makt~spras = sy-langu )
inner join mard on mardmatnr = maramatnr.
OR
Code:
select mara~matnr
makt~maktx
mardlgort mardlabst
into corresponding fields of table itab
from ( mara
inner join makt on maktmatnr = maramatnr )
inner join mard on mardmatnr = maramatnr
where
makt~spras = sy-langu.
Cheers,
Chandra Sekhar. -
Inner join with for-all entries
Why is the below inner join-for all entries does not result in expected output ?
REPORT ZTST3 .
tables : ztst1,ztst2 .
* table ztst1 has 4 fields : mandt,ebeln,ebelp,etenr,char4. ; ztst2 has
* 3 fields : mandt,ebeln,ebelp,matnr
*Entries in ztst1
* EBELN EBELP ETERN CHAR4
* 5000000000 00010 0001 abc
* 5000000000 00010 0002 cbd
* 5000000000 00010 0003 efg
*Entries in ztst2
* EBELN EBELP matnr
* 5000000000 00010 matabc
*expected itab after inner join
* EBELN EBELP CHAR4 MAtnr
* 5000000000 00010 abc matabc
* 5000000000 00010 cbd matabc
* 5000000000 00010 efg matabc
data : begin of itab1 occurs 0,
ebeln type ebeln,
ebelp type ebelp,
end of itab1.
data : begin of itab occurs 0,
ebeln type ebeln,
ebelp type ebelp,
char4 type char4,
matnr type matnr,
end of itab.
start-of-selection.
itab1-ebeln = '5000000000'.
itab1-ebelp = '00010'.
append itab1.
select ztst1~ebeln
ztst1~ebelp
ztst1~char4
ztst2~matnr into corresponding fields of table itab
from ztst1 inner join ztst2
on ztst1~ebeln = ztst2~ebeln and
ztst1~ebeln = ztst2~ebelp
for all entries in itab1
where
ztst1~ebeln eq itab1-ebeln and
ztst1~ebelp eq itab1-ebelp .
* why does it return no entries;
break-point.For example in the bellow case
*Entries in ztst1
EBELN EBELP ETERN CHAR4
5000000000 00010 0001 abc
5000000000 00010 0002 cbd
5000000000 00010 0003 efg
5000000002 00020 0003 efg
5000000002 00020 0003 efg
*Entries in ztst2
EBELN EBELP matnr
5000000000 00010 matabc
5000000002 00020 abc
may it will return you 2 records yes, than I think you have under stand the working of u201Cfor all entriesu201D ?
And the following case I think it will work fine.
*Entries in ztst1
key EBELN EBELP ETERN CHAR4
1 5000000000 00010 0001 abc
2 5000000000 00010 0002 cbd
3 5000000000 00010 0003 efg
4 5000000002 00020 0003 efg
5 5000000002 00020 0003 efg
*Entries in ztst2
EBELN EBELP matnr
5000000000 00010 matabc
5000000002 00020 abc
select ztst1~key
ztst1~ebeln
ztst1~ebelp
ztst1~char4
ztst2~matnr into corresponding fields of table itab
from ztst1 inner join ztst2
on ztst1~ebeln = ztst2~ebeln and
ztst1~ebelp = ztst2~ebelp
for all entries in itab1
where
ztst1~ebeln eq itab1-ebeln and
ztst1~ebelp eq itab1-ebelp .
Sorry, I donu2019t have system with me right now and I am sending you with out testing but I am sure that it is working the same way.
Please Reply if any problem
Kind Regards,
Faisal -
Program without inner join..
hi frds...
i need help in the programming without using the inner join and views,
i want to take data from 2 different table without join and views, give some sample codes or links
it will help to us.
by
pari..
Edited by: Alvaro Tejada Galindo on Feb 22, 2008 12:18 PMHi pari,
This is the sample code 'for all entries'
in alv report.
TYPE-POOLS:SLIS.
DATA:BODY TYPE SLIS_T_FIELDCAT_ALV,
HEADER TYPE SLIS_FIELDCAT_ALV.
DATA:BEGIN OF ITAB OCCURS 0,
MATNR LIKE MARA-MATNR,
ERSDA LIKE MARA-ERSDA,
MEINS LIKE MARA-MEINS,
END OF ITAB.
DATA:BEGIN OF ITAB1 OCCURS 0,
MATNR LIKE MAKT-MATNR,
MAKTX LIKE MAKT-MAKTX,
END OF ITAB1.
DATA:BEGIN OF ITAB2 OCCURS 0,
MATNR LIKE MARA-MATNR,
ERSDA LIKE MARA-ERSDA,
MEINS LIKE MARA-MEINS,
MAKTX LIKE MAKT-MAKTX,
END OF ITAB2.
SELECT-OPTIONS:SMATNR FOR ITAB-MATNR.
PERFORM FETCH_MARA.
PERFORM FETCH_MAKT.
PERFORM READ.
PERFORM FIELDCATALOG.
PERFORM ALVDISPLAY.
*& Form FETCH_MARA
form FETCH_MARA .
SELECT MATNR ERSDA MEINS FROM MARA INTO TABLE ITAB WHERE MATNR IN SMATNR
endform. " FETCH_MARA
*& Form FETCH_MAKT
form FETCH_MAKT .
IF ITAB[] IS NOT INITIAL.
SELECT MATNR MAKTX FROM MAKT INTO TABLE ITAB1 FOR ALL ENTRIES IN ITAB
WHERE MATNR = ITAB-MATNR.
ENDIF.
endform. " FETCH_MAKT
FORM READ.
LOOP AT ITAB.
READ TABLE ITAB1 WITH KEY MATNR = ITAB-MATNR.
IF SY-SUBRC = 0.
MOVE ITAB-MATNR TO ITAB2-MATNR.
MOVE ITAB-ERSDA TO ITAB2-ERSDA.
MOVE ITAB-MEINS TO ITAB2-MEINS.
MOVE ITAB1-MAKTX TO ITAB2-MAKTX.
ENDIF.
APPEND ITAB2.
ENDLOOP.
ENDFORM.
*& Form FIELDCATALOG
text
--> p1 text
<-- p2 text
form FIELDCATALOG .
HEADER-COL_POS = '1'.
HEADER-SELTEXT_L = 'MATNR1'.
HEADER-TABNAME = 'ITAB2'.
HEADER-FIELDNAME = 'MATNR'.
APPEND HEADER TO BODY.
CLEAR HEADER.
HEADER-COL_POS = '2'.
HEADER-SELTEXT_L = 'ERSDA'.
HEADER-TABNAME = 'ITAB2'.
HEADER-FIELDNAME = 'ERSDA'.
APPEND HEADER TO BODY.
CLEAR HEADER.
HEADER-COL_POS = '3'.
HEADER-SELTEXT_L = 'MEINS'.
HEADER-TABNAME = 'ITAB2'.
HEADER-FIELDNAME = 'MEINS'.
APPEND HEADER TO BODY.
CLEAR HEADER.
HEADER-COL_POS = '4'.
HEADER-SELTEXT_L = 'MAKTX'.
HEADER-TABNAME = 'ITAB2'.
HEADER-FIELDNAME = 'MAKTX'.
APPEND HEADER TO BODY.
CLEAR HEADER.
endform. " FIELDCATALOG
*& Form ALVDISPLAY
form ALVDISPLAY .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = 'ZALVREPORT'
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
I_STRUCTURE_NAME =
IS_LAYOUT =
IT_FIELDCAT = BODY
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = ITAB2
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. -
Inner join query used with 7 Database tables
HI All,
In a report they used the Inner join Query with 6 Data base table..now there is a performance issue with at query.
its taking so much of time to trigger that query. Please help how to avoid that performance issue for that.
In that 2 database tables containing lakhs of records..
According to my knowledge it can be avoided by using secondary indexs for those 2 database tables..
and by replacing the Inner join Query with FOR ALL ENTRIES statement.
i want how to use the logic by using FORALL ENTRIES statement for this..
So, please give you proper suggestion to avoid this issue..
Thanking you.
Moderator message: Please Read before Posting in the Performance and Tuning Forum
Edited by: Thomas Zloch on Oct 16, 2011 10:27 PMHi,
And what do you mean with "they used"? If "SAP used" then yo will need to ask a SAP for note
FOR ALL ENTRIES is quite good described in help. Please search forum also.
Without query it won't be possible to tell how it can be optimized, however you can try to use SE30/SAT and ST05. Maybe it will help you.
BR
Marcin Cholewczuk
Maybe you are looking for
-
Hi I am currently making a website and I have created a nav bar in fireworks using slices and pop-up menus etc. Anyway I have imported it to my website in Dreamweaver, but I cant figure out how to make a hyperlink from the from down and nav bar butto
-
Please help me figure out why I can't update my apps or get new ones...Thanks. I recently cancelled my mobile me account and a lot of strange and frustrating changes have taken place
-
How do I install a Canon driver?
Hi, I'm new to Mac and I just bought a MacBook Pro with Tiger installed and with the Leopard upgrade disc included. I have a Canon MF4120 connected via USB, downloaded a Canon UFR II Printer Driver v1.50 for Macintosh and it appears in my Downloads f
-
Text in header and text in footer in sap scipt ?
how to print header in ist page and footer in last page in sap script?
-
Problem with BAPI_DOCUMENT_CREATE2
HI, I am creating document using FM BAPI_DOCUMENT_CREATE2. In IDES, i am able to create with new status. But i am getting an error message as 'The status set requires a previous status'. What could be the problem? is it due to the additional pacthes