Table innerjoin
hi,
how to use innerjoin for matching six tables
Moderator message: please do more research before asking.
[Rules of engagement|http://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngagement]
[Asking Good Questions in the Forums to get Good Answers|/people/rob.burbank/blog/2010/05/12/asking-good-questions-in-the-forums-to-get-good-answers]
Edited by: Thomas Zloch on May 21, 2011 12:55 PM
In Oracle it's pretty simple to look for the previous month, using ADD_MONTHS:
SQL> select sysdate now
2 , add_months(sysdate, -1) now_a_month_ago
3 , to_char(sysdate, 'Month') this_month
4 , to_char(add_months(sysdate, -1), 'Month') last_month
5 from dual;
NOW NOW_A_MONTH_AGO THIS_MONTH LAST_MONTH
11-02-2010 01:28:36 11-01-2010 01:28:36 February January
1 row selected.
Similar Messages
-
How to use Innerjoin b/w these 2 tables VBAK and CDHDR ?
Hi,
How to use Innerjoin b/w these 2 tables VBAK and CDHDR for retrieving of changed sales order data ?I nned the A select stmt with INNER JOIN for changed sales data.
Thanks & Regards,
gopi.Hi Gopi,
You can use the code similar to below to read the changes to Sales order from CDHDR AND CDPOS
FORM GET_CHANGES .
* Get all the changes to Sales Order as well as Deliveries. Suppress
* Non relevant change
DATA : BEGIN OF SO_VBELN OCCURS 0 ,
VBELN LIKE CDHDR-OBJECTID,
END OF SO_VBELN.
DATA : BEGIN OF DL_VBELN OCCURS 0 ,
VBELN LIKE CDHDR-OBJECTID,
END OF DL_VBELN.
DATA TEMP_SO_VBELN LIKE SO_VBELN OCCURS 0 WITH HEADER LINE.
DATA DATE_UNTIL LIKE SY-DATUM.
DATA TIME_UNTIL LIKE SY-UZEIT .
DATA DATE_FROM LIKE SY-DATUM.
READ TABLE S_CHADT INDEX 1.
LOOP AT IT_VBAP.
AT NEW VBELN.
MOVE IT_VBAP-VBELN TO TEMP_SO_VBELN.
COLLECT TEMP_SO_VBELN.
ENDAT.
ENDLOOP.
IF TEMP_SO_VBELN[] IS NOT INITIAL.
SELECT OBJECTID AS VBELN FROM CDHDR
INTO TABLE SO_VBELN
FOR ALL ENTRIES IN TEMP_SO_VBELN
WHERE OBJECTCLAS EQ 'VERKBELEG'
AND OBJECTID EQ TEMP_SO_VBELN-VBELN
AND USERNAME IN S_CHABY
AND UDATE IN S_CHADT.
ENDIF.
LOOP AT IT_LIPS INTO WA_LIPS.
AT NEW VBELN.
MOVE WA_LIPS-VBELN TO DL_VBELN.
COLLECT DL_VBELN.
ENDAT.
ENDLOOP.
* Changes in Sales Order.
IF NOT SO_VBELN[] IS INITIAL.
* Get partner functions
SELECT * INTO TABLE IT_TPART
FROM TPART WHERE SPRAS EQ SY-LANGU.
SELECT A~TABNAME A~FIELDNAME A~DATATYPE B~DDTEXT
INTO CORRESPONDING FIELDS OF TABLE IT_FIELD
FROM DD03L AS A INNER JOIN
DD04T AS B
ON A~ROLLNAME EQ B~ROLLNAME
AND A~AS4LOCAL EQ B~AS4LOCAL
WHERE ( A~TABNAME EQ 'VBAK'
OR A~TABNAME EQ 'VBAP'
OR A~TABNAME EQ 'VBEP'
OR A~TABNAME EQ 'VBPA'
OR A~TABNAME EQ 'VBUK'
OR A~TABNAME EQ 'VBKD' )
AND A~AS4LOCAL EQ 'A'
AND A~AS4VERS EQ '0000'
AND A~ROLLNAME NE SPACE
AND B~DDLANGUAGE EQ SY-LANGU.
* Preapare the exclusion table
R_EXCL_FIELDS-OPTION = 'EQ'.
R_EXCL_FIELDS-SIGN = 'I'.
LOOP AT IT_FIELD WHERE DATATYPE EQ 'CURR'.
R_EXCL_FIELDS-LOW = IT_FIELD-FIELDNAME.
APPEND R_EXCL_FIELDS.
ENDLOOP.
R_EXCL_FIELDS-LOW = 'ARKTX'.
APPEND R_EXCL_FIELDS.
R_EXCL_FIELDS-LOW = 'LGORT'.
APPEND R_EXCL_FIELDS.
R_EXCL_FIELDS-LOW = 'TDDAT'.
APPEND R_EXCL_FIELDS.
R_EXCL_FIELDS-LOW = 'LDDAT'.
APPEND R_EXCL_FIELDS.
R_EXCL_FIELDS-LOW = 'MBDAT'.
APPEND R_EXCL_FIELDS.
R_EXCL_TABL-OPTION = 'EQ'.
R_EXCL_TABL-SIGN = 'I'.
R_EXCL_TABL-LOW = 'KONVC'.
APPEND R_EXCL_TABL.
R_EXCL_TABL-LOW = 'VBKD'.
APPEND R_EXCL_TABL.
LOOP AT SO_VBELN.
REFRESH ITAB_CDHDR.
DATE_FROM = S_CHADT-LOW.
DATE_UNTIL = S_CHADT-HIGH.
CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'
EXPORTING
DATE_OF_CHANGE = DATE_FROM
OBJECTCLASS = 'VERKBELEG'
OBJECTID = SO_VBELN-VBELN
TIME_OF_CHANGE = TIME_UNTIL
DATE_UNTIL = DATE_UNTIL
USERNAME = ' '
TABLES
I_CDHDR = ITAB_CDHDR
EXCEPTIONS
NO_POSITION_FOUND = 1
WRONG_ACCESS_TO_ARCHIVE = 2
TIME_ZONE_CONVERSION_ERROR = 3
OTHERS = 4.
IF SY-SUBRC NE 0.
CONTINUE.
ENDIF.
LOOP AT ITAB_CDHDR WHERE USERNAME IN S_CHABY.
REFRESH IT_CDSHW.
CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'
EXPORTING
CHANGENUMBER = ITAB_CDHDR-CHANGENR
TABLES
EDITPOS = IT_CDSHW
EXCEPTIONS
NO_POSITION_FOUND = 1
WRONG_ACCESS_TO_ARCHIVE = 2
OTHERS = 3.
IF SY-SUBRC EQ 0.
PERFORM GET_ACTION .
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
* Changes in Delivery
IF NOT DL_VBELN[] IS INITIAL.
REFRESH : IT_CDHDR , IT_CDPOS.
SELECT OBJECTCLAS OBJECTID CHANGENR USERNAME UDATE
FROM CDHDR INTO CORRESPONDING FIELDS OF TABLE IT_CDHDR
FOR ALL ENTRIES IN DL_VBELN
WHERE OBJECTCLAS EQ 'LIEFERUNG'
AND OBJECTID EQ DL_VBELN-VBELN
AND USERNAME IN S_CHABY
AND UDATE IN S_CHADT
AND CHANGE_IND EQ 'U'.
LOOP AT IT_CDHDR.
CONCATENATE SY-MANDT IT_CDHDR-OBJECTID
INTO IT_CDHDR-TABKEY .
CONDENSE IT_CDHDR-TABKEY.
MODIFY IT_CDHDR.
ENDLOOP.
IF NOT IT_CDHDR[] IS INITIAL.
SELECT * INTO TABLE IT_CDPOS FROM CDPOS
FOR ALL ENTRIES IN IT_CDHDR
WHERE OBJECTCLAS EQ IT_CDHDR-OBJECTCLAS
AND OBJECTID EQ IT_CDHDR-OBJECTID
AND CHANGENR EQ IT_CDHDR-CHANGENR
AND TABNAME EQ 'LIKP'
AND TABKEY EQ IT_CDHDR-TABKEY
AND FNAME IN ('WADAT','LFDAT','ROUTE','VSBED')
AND CHNGIND EQ 'U' .
LOOP AT IT_CDPOS .
CLEAR IT_DL_CHG-FLAG_RED.
CASE IT_CDPOS-FNAME.
WHEN 'WADAT'.
MOVE 'Goods issue date changed' TO IT_DL_CHG-ACTION.
WHEN 'LFDAT'.
MOVE 'Delivery date changed' TO IT_DL_CHG-ACTION.
MOVE 'X' TO IT_DL_CHG-FLAG_RED.
WHEN 'ROUTE'.
MOVE 'Route Changed' TO IT_DL_CHG-ACTION.
WHEN 'VSBED'.
MOVE 'Shipping Condition Changed' TO IT_DL_CHG-ACTION.
WHEN OTHERS.
ENDCASE.
AT NEW CHANGENR .
READ TABLE IT_CDHDR WITH KEY OBJECTCLAS = IT_CDPOS-OBJECTCLAS
OBJECTID = IT_CDPOS-OBJECTID
CHANGENR = IT_CDPOS-CHANGENR
BINARY SEARCH.
MOVE IT_CDHDR-USERNAME TO IT_DL_CHG-ERNAM.
WRITE IT_CDHDR-UDATE TO IT_DL_CHG-ERDAT.
ENDAT.
IT_DL_CHG-COUNTER = IT_DL_CHG-COUNTER + 1.
MOVE IT_CDPOS-OBJECTID TO IT_DL_CHG-VBELN.
MOVE IT_CDPOS-VALUE_OLD TO IT_DL_CHG-OLD_VAL.
MOVE IT_CDPOS-VALUE_NEW TO IT_DL_CHG-NEW_VAL.
INSERT TABLE IT_DL_CHG.
ENDLOOP.
ENDIF.
ENDIF.
ENDFORM. " GET_CHANGES
Cheers
VJ -
How to use innerjoin between 5 tables the syntax pls
pls let me know
See the syntax :
REPORT ZTEST3 line-size 400.
TABLES: EKKO, LFA1, MAKT, EKET, EKPO, cdhdr.
*Data Declaration
TYPES: BEGIN OF FINAL,
ebeln type ekko-ebeln,
BEDAT type ekko-bedat,
lifnr type ekko-lifnr,
ernam type ekko-ernam,
name1 type lfa1-name1,
matnr type ekpo-matnr,
eindt type eket-eindt,
MAKTX type MAKT-MAKTX,
MBLNR type MSEG-MBLNR,
eldat type eket-eindt,
end of FINAL.
DATA: ITAB TYPE STANDARD TABLE OF FINAL INITIAL SIZE 10 WITH HEADER LINE.
all ALV declarations
type-pools: slis. "ALV Declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv with header line,
G_REPID TYPE SY-REPID,
GS_PRINT TYPE SLIS_PRINT_ALV,
GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
GT_EVENTS TYPE SLIS_T_EVENT,
GT_SORT TYPE SLIS_T_SORTINFO_ALV,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
COL_POS TYPE I.
-----------------SELECTION SCREEN----------------------
selection-screen begin of block b1 with frame title text-001.
select-options podate for EKKO-bedat.
selection-screen end of block b1.
*................... GET DATA..................
SELECT EKKO~EBELN
EKKO~BEDAT
EKKO~LIFNR
EKKO~ERNAM
LFA1~NAME1
MAKT~MATNR
EKET~EINDT
MAKT~MAKTX
MSEG~MBLNR
eket~eindt
INTO CORRESPONDING FIELDS OF ITAB
FROM
( EKKO INNER JOIN LFA1
ON EKKOLIFNR = LFA1LIFNR
INNER JOIN MSEG
ON EKKOEBELN = MSEGEBELN
INNER JOIN MKPF
ON MSEGMBLNR = MKPFMBLNR
INNER JOIN EKPO
ON EKKOEBELN = EKPOEBELN
INNER JOIN MAKT
ON EKPOMATNR = MAKTMATNR
INNER JOIN EKET
ON EKKOEBELN = EKETEBELN
WHERE EKKO~BEDAT IN PODATE .
APPEND ITAB. CLEAR ITAB.
ENDSELECT.
Do not use joins more than 3 tables ,if you use you get bad performance.
Thanks
Seshu -
Need help with an innerjoin issue
Hello;
I am writting a small app for my web site and have run into
an issue with an innerjoin. Let me explain what the function is for
this so maybe you can understand what I am doing.
There are 2 pages to this. Page 1, is a category selection
page. It loads all the categories on the page with a link that
passes a category ID to page 2. Page 2, then allows you to view all
the projects that are associated to the specific category. There is
a numbered navigation on this page, kind of like google, 1 2 3 4
More> Next>
Now what I am trying to do it create a select function that
allows you to choose another category to look through on page 2 so
you don't have to go back to page 1 and select another category
there.
Right now, I have the innerjoin working well with page 1
going to page 2 and the numbered nav, it is doing what it is
supposed to. BUT the select function is working off the where
clause and not working independantly from what the numbered nav and
body is supposed to be doing. There is also a spot I added to this
page that kind of works like the select function, it puts the name
of the category your viewing on the page.
What is happening with the select function and this name
function is lets say there are 5 project records tied to the
category you selected, then the select function gets 5 names of the
same category in it and so does the category name function.
(Follow this?)
Let me post the code for page 1 and page 2. also will add
what the tables are in the db.
DB tables:
Table1: Categories
Name (this is the actual category name), MYFile(the file that
give an image of the category), Description(a description of this
category), CategoryID (this is added to the projects table for each
project that is connected to each category)
Table 2: Projects
ProjectID (this is the ID of the projects), Name (this is the
name of the project) Body (thi sis the description and picture of
the project), CategoryID (this is the id of what category the
project falls under, also assigned to tproject from the categories
table)
There is a lot of code that goes in this, so I am going to
post the code that is pertinent to this question, 90% of it is
working at this time, just not the select function and category
name on page 2.
Page1 Code:
<CFQUERY name="GetRecord"
datasource="#APPLICATION.dataSource#">
select Name, MYFile, Description, CategoryID
FROM Categories
</CFQUERY>
<head>
</head>
<body>
<cfloop query="GetRecord" startRow="#URL.startRow#"
endRow="#endRow#"><cfoutput>
<img src="../img/cat/#MYFile#" width="50" height="50">
<a
href="portfolio-detail.cfm?CategoryID=#CategoryID#">#Name#</a>
#Description#
</cfoutput></cfloop>
<!--- there is a numbered nav on this page, it works nice
so I didn't add the code, that is why I am using a cfloop --->
Page2 code:
<CFQUERY name="getProjects"
datasource="#APPLICATION.dataSource#">
SELECT Projects.ProjectID, Projects.Name, Projects.Body,
Projects.CategoryID,
Categories.CategoryID AS catID, Categories.Name AS cat_name
FROM Projects
INNER JOIN Categories
ON Categories.CategoryID = Projects.CategoryID
WHERE Projects.CategoryID = #categoryID#
ORDER BY ProjectID
</CFQUERY>
<cfif getProjects.recordCount is 0>
No projects in this category.
<cfabort>
</cfif>
<head>
<!--- this script is for the select function so when you
make a selection, it goes to the next category without having to
hit a submit button --->
<script language="Javascript">
function changeRecord(){
document.category.submit();
</script>
</head>
<body>
<!--- here are the Category name and select functions that
aren't working properly yet --->
<cfoutput
query="getProjects">#cat_name#</cfoutput>
<form Name="category" method="post"
Action="portfolio-detail.cfm?CategoryID=true">
<select name="CategoryID" size="1"
onChange="category.submit();">
<option value=""> --Select a Category--
</option>
<CFOUTPUT query= "getProjects">
<option value="#CategoryID#">#cat_name#</option>
</CFOUTPUT>
</select>
</form>
<!--- this part is working properly, it also has a
numbered nav, like google that is working properly at this point
--->
<cfoutput query="GetProjects" startRow="#startRow#"
maxRows="#maxRows#">
#Name#
#Body#
</cfoutput>
<!--- next is the cfmodule for the nav, the nav is a lot
of code, a whole page on it's own so I am not posting it --->
<cfmodule
template="../CFdocs/PageNav.cfm"
totalItems="#numRows#"
numPerPage="#maxRows#"
startRow="#startRow#"
url="#cgi.script_name#?categoryID=#categoryID#&startRow=#startRow#">
The main part that is not working properly is the select, and
category name. How to I get those to work independantly from my
where clause? (I need the where clause for the numbered nav and
cycling through the projects tied to the category you called up
from page 1.
Can someone help me tweek my code from this point? I am
stumped, I looked at the cf docs and I can't find a solution. I am
using CF 8.
Any help would be appreciated. Thank you!
CFmongerI fixed a lot of this since I posted it this morning. Now all
that isn't working properly is the select, it isn't passing the
proper variable to make the query work.
This is what I have now:
Page 2:
<CFQUERY name="getProjects"
datasource="#APPLICATION.dataSource#">
SELECT Projects.ProjectID, Projects.Name, Projects.Body,
Projects.CategoryID,
Categories.CategoryID AS catID, Categories.Name AS cat_name
FROM Projects
INNER JOIN Categories
ON Categories.CategoryID = Projects.CategoryID
WHERE Projects.CategoryID = #categoryID#
ORDER BY ProjectID
</CFQUERY>
<!--- I will add the <cfqueryparam> in a bit --->
<cfif getProjects.recordCount is 0>
No projects in this category.
<cfabort>
</cfif>
<!--- This query populates the select nav --->
<CFQUERY name="cata"
datasource="#APPLICATION.dataSource#">
select Name, MYFile, Description, CategoryID
FROM Categories
</CFQUERY>
<head>
<script language="Javascript">
function changeRecord(){
document.category.submit();
</script>
</head>
<body>
<!--- this output works well now, gives me what I need and
changes when you select a category from page 1 --->
<cfoutput query="getProjects"
maxrows="1">#cat_name#</cfoutput>
<!-- the select isn't passing the CategoryID properly, it
is now throwing an error --->
<form Name="category" method="post"
Action="portfolio-detail.cfm?CategoryID=#CategoryID#">
<select name="CategoryID" size="1"
onChange="category.submit();">
<option value=""> --Select a Category--
</option>
<CFOUTPUT query= "cata">
<option value="#CategoryID#">#Name#</option>
</CFOUTPUT>
</select>
</form>
<!-- the rest of the code goes after this, it ias all
working --->
The error I get when using the select is this:
Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC
Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error
(missing operator) in query expression 'Projects.CategoryID ='.
The error occurred in C:\Websites\folio\portfolio-detail.cfm:
line 12
10 : INNER JOIN Categories
11 : ON Categories.CategoryID = Projects.CategoryID
12 : WHERE Projects.CategoryID = #categoryID#
13 : ORDER BY ProjectID
14 : </CFQUERY>
I also tried doing it this way:
<form Name="category" method="post"
Action="portfolio-detail.cfm?CategoryID=true"
This way didn't work at all, it only made the numbered nav on
the page cycle through all the projects in all the categories.
What do I need to change to pass the proper variable from the
select nav to the innerjoin query and my where statement? -
How to retreive data from a table and a structure
Hi experts,
I have a requirement to create an ALV report. I have to include fields from two tables 'PA0001' and 'CATSDB' and from one structure 'CATSAPPR'. I am able to retrieve data from tables using INNERJOIN. But i have no idea how to deal with Structure.
I know that structure does not contain any data.
But i am not able to find any transparent table which has field 'ORDERTEXT' . I found field 'ORDERTEXT' only in structure 'CATSAPPR'.
So please anyone tell me, either any transparent table which has field 'ORDERTEXT' or please tell me how to deal with structure, in this case.
Please help me,
Thanks in advance
Anucheck this
Table-Fields Short descriptn
AUFK- KTEXT Order master data
COCH- KTXT Process Management: Control Recipe Header
COCHP- KTXT PI sheet: Control Recipe Header
COMPHDR- KTEXT OCM: Comparison results, indiv. records for order headers
HIKO- KTEXT Order master data history
MAAVC_MDO- KTEXT MPO: Individual Master Data for Orders
MCHPVS- AUFTEXT Batch Record: Shadow Table for Link to Archive
OCMHOMO_ARCH- KFELD Backup Table of Homogeneity List in Case of Archiving
PSJHIEDATA- KTEXT Hierarchy data to test LDB PSJ
TEWOCODEST- DESCRIPTION Order Codes (Texts)
TEWOCODET- KTEXT Allocation of Message Codes to Order
VLCSMORDER- KTEXT VELO : Service Order
VSAUFK_CN- KTEXT Version: Order master data
Yogesh N -
Getting an ABAP error while using innerjoins.
Hi,
Please find out the error in the following script.
I have two tables VBAK and VBAP and i am considering these fields.
VBAK -- ERDAT,HANDLE.
VBAP -- ERDAT.
Since ERDAT is been compared from 2 tables i.e.VBAK and VBAP, and if the dates are same then print the values of 'HANDLE' field
I have written the following program using innerjoin between 2 tables and i am geting an error saying that
""ITEM_TABLE-HANDLE" cannot be converted to a character-type field."
Please correct my program.and tell me the error.
and one more thing HANDLE field is there nly in VBAK not in VBAP.
REPORT Z_TEST4 .
TYPES: BEGIN of STRUCT,
ERDAT TYPE VBAP,
VBAP,
ERDAT TYPE VBAP,
HANDLE TYPE VBAK,
END OF STRUCT.
DATA: item_table TYPE STANDARD TABLE OF STRUCT WITH HEADER LINE.
SELECT AERDAT BERDAT B~HANDLE INTO TABLE ITEM_TABLE FROM VBAP AS A
INNER JOIN VBAK AS B ON AERDAT = BERDAT.
*WHERE AERDAT = BERDAT.
IF SY-SUBRC NE 0.
WRITE: /'No Entries Found'.
ENDIF.
LOOP AT ITEM_TABLE.
WRITE: / ITEM_TABLE-HANDLE.
ENDLOOP.Hi
Kindly check the following code:
DATA: BEGIN OF item_table OCCURS 0,
erdat LIKE vbak-erdat,
handle LIKE vbak-handle,
END OF item_table.
SELECT a~erdat a~handle INTO TABLE item_table
FROM vbak AS a INNER JOIN vbap AS b
ON b~vbeln = a~vbeln
AND b~erdat = a~erdat.
IF sy-subrc NE 0.
WRITE: /'No Entries Found'.
ENDIF.
LOOP AT item_table.
WRITE: / item_table-handle.
ENDLOOP.
<b>Declaration</b>
You can do the declaration of the internal table this way too...
In your declaration of the structure, you have given the whole table as a single field.
<b>Query</b>
Try the above inner join query...
Hope this helps!
best regards,
Thangesh -
Hi,
I am working on a report where I have to retrieve data from 3 tables(marc,mara,makt).For this I have used 3 select statements for retriving data from 3 tables.There r some fields which r not present in marc table where as present in mara and makt tables.So added thos fields in marc internal table t_marc.I have looped at marc table and used the read statement to read the data from mara table using the key field matnr from both the tables.This read statement is giving the sy-subrc value as 4.Could u pls tell me why this is happening?I am sending my code.
SELECT matnr
werks
pstat
lvorm
FROM marc
INTO TABLE t_marc
PACKAGE SIZE 500
WHERE matnr IN s_matnr
AND werks IN s_werks.
IF NOT t_marc[] IS INITIAL.
SELECT matnr
ersda
laeda
meins
FROM mara
INTO TABLE t_mara
FOR ALL ENTRIES IN t_marc
WHERE matnr = t_marc-matnr
AND ersda IN s_ersda
AND laeda IN s_laeda.
IF NOT t_mara[] IS INITIAL.
SELECT matnr
maktx
FROM makt
INTO TABLE t_makt
FOR ALL ENTRIES IN t_mara
WHERE matnr = t_mara-matnr.
LOOP AT t_marc INTO wa_marc.
READ TABLE t_mara INTO wa_mara WITH KEY matnr = t_marc-matnr.
IF sy-subrc IS INITIAL.
wa_marc-meins = wa_mara-meins.
MODIFY t_marc.
APPEND wa_marc TO t_output.
ENDIF.
READ TABLE t_makt INTO wa_makt WITH KEY matnr = t_marc-matnr.
IF sy-subrc IS INITIAL.
wa_marc-maktx = wa_makt-maktx.
MODIFY t_marc.
APPEND wa_marc TO t_output.
ENDIF.
ENDLOOP.hi hema,
Dont use three select stements for this scenario.
Just use innerjoin and join all the three tables.
Three tables should contain MATNR (material number).
By using that retrieve data from 3 tables by using a single select statement.
Eg:
SELECT DISTINCT a~matnr "MATERIAL NUMBER
a~ersda "CREATED ON
a~mtart "MATERIAL TYPE
a~meins "BASE UNIT OF MEASURE
a~bstme "ORDER UNIT
b~maktx "MATERIAL DESCRIPTION
c~bwkey "VALUATION AREA
c~lbkum "TOTAL VALUED STOCK
c~salk3 "VALUE OF TOTAL VALUED STOCK
c~stprs "STANDARD PRICE
c~peinh "PRICE UNIT
c~bklas "VALUATION CLASS
INTO TABLE it_matdetails
FROM mara AS a INNER JOIN makt AS b ON a~matnr = b~matnr
INNER JOIN mbew AS c ON a~matnr = c~matnr
INNER JOIN marc AS d ON a~matnr = d~matnr
INNER JOIN mard AS e ON a~matnr = e~matnr
WHERE b~spras = sy-langu AND a~matnr IN matnr AND d~werks IN werks AND e~lgort IN lgort.
pls reward if helpful. -
How to include two different tables in view concept..
I have to make the innerjoin between these two tables.. i.e, BUT000-PARTNER = PA0002-PERNR.. here PARTNER is CHAR(10) and PERNR is NUMC(8)..in this i had two probs..one is how to convert this PERNR into CHAR(10) and second is how to match those fields..in VIEWS concept..
regards
ravi..Kiran,
Usually Views are created where there are two columns of the same type exist in the JOIN CONDITION. In this case your results when you create a VIEW in SE11, you cannot specify the offset so that it considers only the last 8 chars.
So, in this case , you are better off taking care of this in the code, where you can mentiond to consider the first / last 8 chars of the string.
Regards,
Ravi
Note :Please mark all the helpful answers -
Append two structures in an internal table.
hi,
if i join two tables by innerjoining will it effect the performance?If such,how i can join these with better performance?can i get the data from different tables in a single internal table by appending different structures in this case?Please answer me.If inner Join has a performance issue the best thing u can do is...
Create 3 int tables. "This is to avoid 'INTO CORRESPONDING FIELDS' select query which will affect performance.
itab1 with the structure of table1
itab2 with the structure of table2
itab3 with the structure of table1 & table2
Select from 1st table into itab1.
if itab1 is not initial.
select from table 2 into itab2 for all entries in itab1 where field = itab1-field.
sort itab2 by field. "For binary search
loop itab1.
move-corresponding itab1 to itab3.
read itab2 with key field = itab1-field binary search.
move-corresponding itab2 to itab3.
append itab3.
endloop.
Regards
Sathar
Edited by: Sathar RA on Sep 8, 2008 9:10 AM -
Hi Friends,
please suggest me in performance innerjoin is better or for all entries is better to get data from two transparent tables.
Krishna.hi,
<b>for all entries is the better method.</b>
FOR ALL ENTRIES is an effective way of doing away with using JOIN on two tables.
You can check the below code -
SELECT BUKRS BELNR GJAHR AUGDT
FROM BSEG
INTO TABLE I_BSEG
WHERE BUKRS = ....
SELECT BUKRS BELNR BLART BLDAT
FROM BKPF
INTO TABLE I_BKPF
FOR ALL ENTRIES IN I_BSEG
WHERE BUKRS = I_BSEG-BUKRS
AND BELNR = I_BSEG-BELNR
AND BLDAT IN SO_BLDAT.
*******************************8
look another example
what is the use of FOR ALL ENTRIES
1. INNER JOIN
DBTAB1 <----
> DBTAB2
It is used to JOIN two DATABASE tables
having some COMMON fields.
2. Whereas
For All Entries,
DBTAB1 <----
> ITAB1
is not at all related to two DATABASE tables.
It is related to INTERNAL table.
3. If we want to fetch data
from some DBTABLE1
but we want to fetch
for only some records
which are contained in some internal table,
then we use for alll entries.
1. simple example of for all entries.
2. NOTE THAT
In for all entries,
it is NOT necessary to use TWO DBTABLES.
(as against JOIN)
3. use this program (just copy paste)
it will fetch data
from T001
FOR ONLY TWO COMPANIES (as mentioned in itab)
4
REPORT abc.
DATA : BEGIN OF itab OCCURS 0,
bukrs LIKE t001-bukrs,
END OF itab.
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
itab-bukrs = '1000'.
APPEND itab.
itab-bukrs = '1100'.
APPEND itab.
SELECT * FROM t001
INTO TABLE t001
FOR ALL ENTRIES IN itab
WHERE bukrs = itab-bukrs.
LOOP AT t001.
WRITE :/ t001-bukrs.
ENDLOOP.
Hope this helps!
Regards,
Anver -
Inner join on Buffred table and not buffered table.
Hi guys,
Can you suggest me how can i write select query using inner join on buffered table and not buffered table. i written like this. is it right?
SELECT a~vbeln
a~vkorg
a~kunnr
a~kunag
a~wadat_ist
a~xblnr
b~bukrs
FROM likp AS a INNER JOIN tvko AS b
ON avkorg = bvkorg BYPASSING BUFFER
INTO TABLE itab_likp
WHERE vbeln = s_vbeln.
Thanks.
RAJHi Raj ,
Please find below my Commentes :
1. When you use "Bypassing buffer" clause in Select statement , the data what is there in the buffer of application sever is always ignored and Read is performed from the Physical database always. This Clause is advisable where you require realtime data (Not recommended generally in reporting)
2. It is advisable that you should not use small table in the innerjoin with big table. In the query you have written there are 2 tables:- LIKP and TVKO outof which TVKO is a master table containing very few records than LIKP (Contains huge data for Delivery header).
So my recommendation will be : -
1. Eliminate the "Bypassing Buffer" clause from your Query
2. Break the select query into 2 select queries breaking the join and with some ABAP logic populate the Internal table "itab_likp".
This will be optimum way inwhich you can write the select query for your senarion. Also Ensure that indexes are being used for better selectivity.
Hope this will help to you.
Regards,
Nikhil -
Replacing innerjoins with for all entries
can any one help me in replacing the below
innerjoins with for all entries
SELECT avbeln aposnr amatnr apstyv a~werks
FROM vbap AS a INNER JOIN marc AS b
ON amatnr = bmatnr AND
awerks = bwerks
INTO TABLE vbap_itab
WHERE a~vbeln = i_vbeln-vbeln
AND a~uepos = 0
AND b~umrsl = 'VBOM'.
and please tell me which table we need to select first in vbap and marc and why
Edited by: ram reddy on Apr 30, 2008 9:27 AMhi check this one
data:
begin of vbap_itab,
vbeln type vbap_-vbeln,
posnr type vbap_posnr,
matnr type vbap_matnr,
pstyv type vbap_pstvy,
werks type vbap_werks,
end of itab,
begin of marc_itab,
matnr type marc-matnr,
werks type marc-werks,
end of marc_itab.
select matnr
werks
from marc
into table marc-itab
where umrsl = 'VBOM'.
if marc_itab is initial.
exit.
else.
select vbeln
posnr
matnr
pstvy
werks
from vbap
into table vbap_itab
for all entries in marc_itab
where matnr = marc_itab-matnr
and werks = marc_itab-werks
and vbeln = i_vbeln-vbeln
and uepos = 0.
endif.
Edited by: ravi kumar on Apr 30, 2008 9:51 AM -
How to avoid data repetation when using select statements with innerjoin
how to avoid data repetation when using select statements with innerjoin.
thanks in advance,
satheeshyou can use a query like this...
SELECT DISTINCT
frg~prc_group1 "Product Group 1
frg~prc_group2 "Product Group 2
frg~prc_group3 "Product Group 3
frg~prc_group4 "Product Group 4
frg~prc_group5 "Product Group 5
prc~product_id "Product ID
txt~short_text "Product Description
UP TO 10 ROWS
INTO TABLE l_i_data
FROM
Joining CRMM_PR_SALESG and
COMM_PR_FRG_ROD
crmm_pr_salesg AS frg
INNER JOIN comm_pr_frg_rod AS prd
ON frgfrg_guid = prdfragment_guid
Joining COMM_PRODUCT and
COMM_PR_FRG_ROD
INNER JOIN comm_product AS prc
ON prdproduct_guid = prcproduct_guid
Joining COMM_PRSHTEXT and
COMM_PR_FRG_ROD
INNER JOIN comm_prshtext AS txt
ON prdproduct_guid = txtproduct_guid
WHERE frg~prc_group1 IN r_zprc_group1
AND frg~prc_group2 IN r_zprc_group2
AND frg~prc_group3 IN r_zprc_group3
AND frg~prc_group4 IN r_zprc_group4
AND frg~prc_group5 IN r_zprc_group5.
reward it it helps
Edited by: Apan Kumar Motilal on Jun 24, 2008 1:57 PM -
what is the difference between view & innerjoin ?explain plz ?
innerjoin
The data that can be selected with a view depends primarily on whether the view implements an inner join or an outer join. With an inner join, you only get the records of the cross-product for which there is an entry in all tables used in the view. With an outer join, records are also selected for which there is no entry in some of the tables used in the view.
The set of hits determined by an inner join can therefore be a subset of the hits determined with an outer join.
Database views implement an inner join. The database therefore only provides those records for which there is an entry in all the tables used in the view. Help views and maintenance views, however, implement an outer join.
view
A view describes the layout and behavior of a rectangular area of a user interface.
Use
Every Web Dynpro application has at least one view. The layout of a view is made up of different user interface elements, which can be nested in each other. The positioning of interface elements in one view is supported by the supplied layout variants.
In addition to the visible part, the layout, a view also contains a controller and a context. The data to which the elements of the view can be bound are stored and managed in the view context, enabling them to be represented or used on the screen. The view controller can contain methods for data retrieval or for processing user input.
Multiple views can be classified in view sets.
A view also has inbound and outbound plugs so that views can connected with each other, or so that a view can be linked with an interface view. These plugs can be linked with each other using navigation links.
Empty View
The empty view is a special type of view. It is always generated automatically in a window or a view set area, provided that no view has been embedded manually. It may also be preferable to embed an empty view in a non-empty window as well. Just like a normal view, the empty view occupies a certain area of a window at runtime and can be used to hide a different view, for example, using specific controls.
When you create an empty view, an inbound plug with the default name ShowEmptyView is created. -
Hello,
For my website I use "dynamic" menu's which are stored in a
SQL table. When a certain product is shown on the detail page the
menu according to the product categorie (dutch for category) is
shown.
The products themselves and all their information are stored
in the 'product' table, the menu's for the different product
categories are stored in the 'index' table.
On the detail page a get is used to show the right product
information. I wanted to do the same thing for the menu and came up
with this SQL:
SELECT product_2.*
FROM (product INNER JOIN index ON product.categorie =
index.categorie) INNER JOIN product AS product_2 ON index.index =
product_2.categorie
WHERE product.slug = colname2
Table fields used:
product.categorie
product.slug (this is the name of the product which is used
in the GET to show the right product)
index.categorie (this variable is the same as the product
table counterpart. When a product category "hat" exists, there is
also a "hat" row in the index table)
index.index (this is where the HTML of the actual menu is
stored)
When I show it like this the following error pops up:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to
use near 'index ON product.categorie = index.categorie) INNER JOIN
product AS product_2 ON' at line 1
I kind of copied and renamed the variables which worked for
an older website of mine (didnt write it myself, dont have that
much knowledge of SQL/PHP), this code works when used to show
comparable products, instead of the "categorie" variable an "id"
variable is used which is a short number.
I cant figure out what's going wrong, maybe u guyz can tell
me. If you need any additional information please let me know.
Thanks!SyKeSnr1 posted in macromedia.dreamweaver:
> Can anyone tell me if this has to do with faulty SQL, or
is it
> simply not possible to do an innerjoin with two
non-number
> variables or something? I cant figure out why this isnt
working..
I'm not much good with JOINs for some reason.
If you don't get an answer in here, then, if you have access
to a
Usenet NewsServer, there are newsgroups that are devoted to
databases
and SQL
comp.databases.mysql
alt.php.sql
and probably more. You'll need to mention which database
you're using.
Mark A. Boyd
Keep-On-Learnin' :)
Maybe you are looking for
-
I think i understand "artwork size & resolution exceeds the max" problem.
Hi all, "the combination of artwork size and resolution exceeds the maximum that can be rasterized". Have you ever gotten this error message? After running into this problem constantly and getting support from you great guys, i think i understand w
-
JTextPane key bindings override JMenuItem accelerators
hi all, I have a JTextPane subclass, sitting on a JPanel, sitting on a JFrame which has a JMenu attached. One of my menu commands has an accelerator PgDn... I am trying to disable the PgDn default behaviour in the JTextPane so that the keystroke then
-
Nokia Lumia 1020 screen doesn't light up when i re...
title says it all, and no I will not do a reset on it so don't even suggest that.
-
I have not been able to use the apple app,
CAN NOT USE THE APPLE APP. PEOPLE ARE NOT GETTING MY TEXT, ECT. I AM VERY DISAPPOINTED WITH THESE ISSUES. FIX!!!!!
-
Tiff images I used in trial version are now blurry in full version of InDesign CS5.5
I placed two tiff images (visual poems I made) into a file (a manuscript) using a trial version of InDesign CS5.5, and they appeared clear and crisp. Then I bought the full version of InDesign (the Education product as part of Adobe Creative Suite),