Help with Inner join problem
The following query works fine as long as there is a value in the subID field, which is at the end of the inner join statement. If the subID is blank then no data is output, even though it is there. Try as I may, I can not get the right solution in the where statement to get the data to show without the subID. What am I missing?
<cfquery name="getInfo" datasource="#application.database#">
select page_id, pageName, pages.content, pages.cat_id, pages.seo_title,pages.seo_desc,pages.seo_words,pages.h1_title,pages.pic,pages.brochure,pa ges.video,catagories.catagory,subcat.subID,subcat.sub_category
from (pages INNER JOIN catagories ON pages.cat_id = catagories.cat_id) INNER JOIN subcat ON pages.subID = subcat.subID
where pages.page_id = #page_id#
</cfquery>
Rick,
Looks like you need a LEFT OUTER join to the "subcat" table, so that all records for "pages" and "catagories" are returned even if no matching "subcat" records exist. INNER joins will only return selected records when the tables on both sides of the join statement have matching values, while a LEFT OUTER (sometimes also known simply as a LEFT join) join will return *all* selected records from the table(s) on the left side of the join statement regardless of whether there are matching records from the table on the right side of the join statement. When there are no matching records from the table on the right side of the join statement, any columns in your SELECT clause that are from the table on the right side of the join statement will contain NULLs.
HTH,
-Carl V.
Similar Messages
-
Help with inner join PLEASE IGNORE
Hi I was doing a select with a subquery but I need that the where clause check to values so I couldn't get it so I decided to create a INNER JOIN
Before
insert into BPMTEMP (select * from ODS_VIEWER.BAN_EVENTOS_CONFIRMACION@DBLINK1 where id_solicitud and accion not in (select (id_solicitud, accion) from ODS_VIEWER.BAN_CONFIRMA_RESPUESTA@DBLINK1) and rownum <=200);but the problem with the inner join is that it doesn't accept me the external database source
insert into BPMTEMP (select ODS_VIEWER.BAN_EVENTOS_CONFIRMACION@DBLINK1.*, ODS_VIEWER.BAN_CONFIRMA_RESPUESTA@DBLINK1.*
from ODS_VIEWER.BAN_EVENTOS_CONFIRMACION@DBLINK1
INNER JOIN ODS_VIEWER.BAN_CONFIRMA_RESPUESTA@DBLINK1
ON [email protected]_solicitud = [email protected]_solicitud
ON [email protected] = [email protected]
AND rownum <=200); it shows an:
ORA-02084:
database name is missing a component
Cause: supplied database name cannot contain a leading '.', trailing '.' or '@', or two '.' or '@' in a row.
how can I solve this????
thanks for your help
Edited by: Diego Guillen on 29/12/2009 11:14 AMHi
Please remove the @dblink stuff in the column descrptions or use a table alias. This should help.
drop database link lokal;
create database link lokal
CONNECT TO whateveruserineed IDENTIFIED BY whateverthing
USING 'lokal11g';
select HR.COUNTRIES.* from HR.COUNTRIES@lokal;
select x.* from HR.COUNTRIES@lokal x;And as Dan Morgans says, pls. post you ? in the right forum next time :-))
Mette -
Help with Inner Join query in SQL
Hope someone can help with this, as this is quite an involved project for me, and I'm just about there with it.
My table structure is :
table_packages
packageID
package
packageDetails
etc
table_destinations
destinationID
destination
destinationDetails
etc
table_packagedestinations
packageID
destinationID
..so nothing that complicated.
So the idea is that I can have a package details page which shows the details of the package, along any destinations linked to that package via the packagedestinations table.
So this is the last part really - to get the page to display the destinations, but I'm missing something along the way....
This is the PHP from the header, including my INNER JOIN query....
PHP Code:
<?php
$ParampackageID_WADApackages = "-1";
if (isset($_GET['packageID'])) {
$ParampackageID_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
$ParamSessionpackageID_WADApackages = "-1";
if (isset($_SESSION['WADA_Insert_packages'])) {
$ParamSessionpackageID_WADApackages = (get_magic_quotes_gpc()) ? $_SESSION['WADA_Insert_packages'] : addslashes($_SESSION['WADA_Insert_packages']);
$ParampackageID2_WADApackages = "-1";
if (isset($_GET['packageID'])) {
$ParampackageID2_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
mysql_select_db($database_connPackages, $connPackages);
$query_WADApackages = sprintf("SELECT packageID, package, costperpax, duration, baselocation, category, dateadded, agerange, hotel, educational_tours, field_trips, corporate_outings, plant_visits, budget_package, rollingtours, teambuilding, description, offer FROM packages WHERE packageID = %s OR ( -1= %s AND packageID= %s)", GetSQLValueString($ParampackageID_WADApackages, "int"),GetSQLValueString($ParampackageID2_WADApackages, "int"),GetSQLValueString($ParamSessionpackageID_WADApackages, "int"));
$WADApackages = mysql_query($query_WADApackages, $connPackages) or die(mysql_error());
$row_WADApackages = mysql_fetch_assoc($WADApackages);
$totalRows_WADApackages = mysql_num_rows($WADApackages);
$colname_educationalDestinations = "1";
if (isset($_GET['PackageID'])) {
$colname_educationalDestinations = (get_magic_quotes_gpc()) ? packageID : addslashes(packageID);
mysql_select_db($database_connPackages, $connPackages);
$query_educationalDestinations = sprintf("SELECT * FROM destinations INNER JOIN (packages INNER JOIN packagedestinations ON packages.packageID = packagedestinations.packageID) ON destinations.destinationID = packagedestinations.destinationID WHERE packages.packageID = %s ORDER BY destination ASC", GetSQLValueString($colname_educationalDestinations, "int"));
$educationalDestinations = mysql_query($query_educationalDestinations, $connPackages) or die(mysql_error());
$row_educationalDestinations = mysql_fetch_assoc($educationalDestinations);
$totalRows_educationalDestinations = mysql_num_rows($educationalDestinations);
?>
And where I'm trying to display the destinations themselves, I have :
<table>
<tr>
<td>Destinations :</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_educationalDestinations['destination']; ?></td>
</tr>
<?php } while ($row_educationalDestinations = mysql_fetch_assoc($educationalDestinations)); ?>
</table>
If anyone could have a quick look and help me out that would be much appreciated - not sure if its my SQL at the top, or the PHP in the page, but either way it would be good to get it working.
Thanks.First off, you need to get the database tables so that there is a relationship between them.
In fact, if there is a one to one relationship, then it may be better to store all of your information in one table such as
table_packages
packageID
package
packageDetails
destination
destinationDetails
etc
If there is a one to many relationship, then the following would be true
packages
packageID
package
packageDetails
etc
destinations
destinationID
packageID
destination
destinationDetails
etc
The above assumes that there are many destinations to one package with the relationship coloured orange.
Once you have the above correct you can apply your query as follows
SELECT *
FROM packages
INNER JOIN destinations
ON packages.packageID = destinations.packageID
WHERE packages.packageID = %s
ORDER BY destination ASC
The above query will show all packages with relevant destinations -
Need help with inner join and distinct rows
Hey Guys,
i have
1) BaseEnv Table
2) Link Table
3) BaseData Table
Link table has three columns Id,BaseEnvId,BaseDataId
the BaseEnvID is unique in the table where as BaseDataId can be repeated i.e multile rows of BaseEnv Table can point to same BaseData table row
Now i want to do BaseEnvTable inner join Link Table inner join BaseData Table and select 5 columsn ; Name,SyncName,Version,PPO,DOM from the BaseData table.. the problem is that after i do the inner join I get duplciate records..
i want to eliminate the duplicate records , can any one help me herePlease post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums. Now we have to guess and type, guess and type, etc. because of your bad manners.
CREATE TABLE Base_Env
(base_env_id CHAR(10) NOT NULL PRIMARY KEY,
Think about the name Base_Data; do you have lots of tables without data? Silly, unh?
CREATE TABLE Base_Data
(base_data_id CHAR(10) NOT NULL PRIMARY KEY,
Your Links table is wrong in concept and implementation. The term “link” refers to a pointer chain structure used in network databases and makes no sense in RDBMS. There is no generic, magic, universal “id” in RDBMS! People that do this are called “id-iots”
in SQL slang.
We can model a particular relationship in a table by referencing the keys in other tables. But we need to know if the relationship is 1:1, 1:m, or n:m. This is the membership of the relationship. Your narrative implies this:
CREATE TABLE Links
(base_env_id CHAR(10) NOT NULL UNIQUE
REFERENCES Base_Env (base_env_id),
base_data_id CHAR(10) NOT NULL
REFERENCES Base_Data (base_data_id));
>> The base_env_id is unique in the table where as base_data_id can be repeated I.e multiple rows of Base_Env Table can point [sic] to same Base_Data table row. <<
Again, RDBMS has no pointers! We have referenced an referencing tables. This is a fundamental concept.
That narrative you posted has no ON clauses! And the narrative is also wrong. There is no generic “name”, etc. What tables were used in your non-query? Replace the ?? in this skeleton:
SELECT ??.something_name, ??.sync_name, ??.something_version,
??.ppo, ??.dom
FROM Base_Env AS E, Links AS L, Base_Data AS D
WHERE ?????????;
>> I want to eliminate the duplicate records [sic], can any one help me here?<<
Where is the sample data? Where is the results? Please read a book on RDBMS so you can post correct SQL and try again.
--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,
Can some one explain me this issue
SELECT COUNT(*) FROM "ECCDATA"."CUST1" O/P = 800
SELECT COUNT(*) FROM "ECCDATA"."CUST1" WHERE MANDT = '800' O/P = 800
SELECT COUNT(*) FROM "ECCDATA"."CUST2" O/P = 13779
SELECT COUNT(*) FROM "ECCDATA"."CUST2" WHERE MANDT = '800' O/p = 13751
SELECT COUNT(*) FROM ( SELECT T1."A1", T2."MANDT" FROM "ECCDATA"."CUST1" AS T1
INNER JOIN "ECCDATA"."A2" AS T2
ON T1."A1" = T2."A1" AND
T2."MANDT" = '800' ) O/P = 13783
SELECT COUNT(*) FROM ( SELECT T1."A1", T2."MANDT" FROM "ECCDATA"."CUST1" AS T1
INNER JOIN "ECCDATA"."A2" AS T2
ON T1."A1" = T2."A1" AND
T1."MANDT" = T2."MANDT") O/P = 13779
ThanksHi Hari,
SELECT COUNT(*) FROM "ECCDATA"."CUST2" O/P = 13779
SELECT COUNT(*) FROM "ECCDATA"."CUST2" WHERE MANDT = '800' O/p = 13751
The table "ECCDATA"."CUST2" must be having client specific data other than of 800 client. Try the below query and check it.
SELECT DISTINCT MANDT from "ECCDATA"."CUST2";
May be you check the same for other tables too.
Sreehari -
SUBQUERY with INNER JOIN in ABAP
Hi Expert
How Can I write SUBQUERY with INNER JOIN in ABAP.
thanksThanks Sidhharth for your Respose
Actually I need data from VBAP, VBAK, VBUP, VBUK and VBKD with all functional validation satisfied for a sales order item data. The requirement is to report all item data with other information from table VBAK, VBUP, VBUK and VBKD in a corresponding record with ALL data in VBAP.
Your help is appriciated.
see the below query for reference
select alias_vbap~vbeln from vbap as
alias_vbap inner join vbak as alias_vbak
on alias_vbapvbeln eq alias_vbakvbeln
"and alias_vbak~bukrs_vf eq '2400'
inner join vbuk as alias_vbuk
on alias_vbukvbeln = alias_vbapvbeln
inner join vbup as alias_vbup
on alias_vbupvbeln = alias_vbapvbeln
and alias_vbupposnr = alias_vbapposnr
left OUTER join veda as alias_veda
on alias_vedavbeln = alias_vbapvbeln
and alias_vedavposn = alias_vbapposnr
left outer join vbkd as alias_vbkd
on alias_vbkdvbeln = alias_vbapvbeln
and alias_vbkdposnr = alias_vbapposnr -
hi friends,
can we use where clause in select statement with inner join.
i am using following code which gives error (The column name "WERKS" has two meanings . .).
SELECT AMATNR ACHARG AERSDA BMENGE B~MEINS
FROM MCHA AS A INNER JOIN CHVW AS B
ON ACHARG = BCHARG
INTO TABLE T_OUTPUT1
WHERE WERKS = PLANT AND CHARG = P_CHARG.
thanks.Yes u can use where clause in select statement with inner join.
SELECT AMATNR ACHARG AERSDA BMENGE B~MEINS
FROM MCHA AS A INNER JOIN CHVW AS B
ON ACHARG = BCHARG
INTO TABLE T_OUTPUT1
WHERE WERKS = PLANT AND CHARG = P_CHARG.
" mention the table name in where condition also like awerks or bwerks.
egards
Rajendra -
I need help with a browser problem
I am was given a new iMac G3 (from 2001) which was really never used.I have not yet had any serious problems with it, but really could use some help with a browser problem.
I have 4 different web browsers that needs the macro media flash player update. The browsers I use are internet explorer, iCab, Netscape, and the original Mozilla Firefox.
It would be of great appreciation for the readers of this post to answer my question.
I am also having the problem with installing the plug - ins for the browsers. Thank You For Taking the Time To read This!Hi, rynodino -
As Tom has suggested, plugins need to be installed in the Plug-Ins folder for the browser.
Typically each browser will have its own Plug-Ins folder, usually located in the same folder containing the browser itself. In order for each of several browsers to access the same plugins, the plugins must be replicated and placed in each of the Plug-Ins folders for each of the browsers. The easy way to do that is to hold down the Option key while dragging a plugin to the new location - a copy (not an alias) of the plugin will be generated at the location it is dragged to.
Most plugins will display a Netscape icon regardless of where they are located - this is normal.
It is not unusual for the installer for a plugin to default its install to the Plug-Ins folder for Internet Explorer. So be it. Just replicate the new plugin to the other Plug-Ins folders as needed.
Note that some plugin installs will involve more than one item. For those, be sure to replicate all items for it. Using labels can help identify what is new, what has been most recently added, in a Plug-Ins folder. -
Performance problem with inner join
Hi
With this Query
SELECT *
FROM TABLE1
INNER JOIN TABLE2
ON TABLE1.Col1 = TABLE2.Col2 AND TABLE1.Col2 = TABLE2.Col2
WHERE TABLE1.Col3 = 'AB' AND
TABLE2.Col4 = 'ZZ';
TABLE1 have 6,000,000 of records
TABLE2 have 9,000,000 of records
when I run this query the result take 30 secs
If I change the Optimizer_mode for 'RULE'
the result take 4 secs
All statistics is ok
Primary Key exists for TABLE1 and TABLE2 base-on Col1 and Col2
And index on Table1.Col3,Table1.Col4
somebody can help me ?Analyze tables compute statistics
and analyze index compute statistics
I join explain plan
STATEMENT_ID TIMESTAMP REMARKS OPERATION OPTIONS OBJECT_NODE OBJECT_OWNER OBJECT_NAME OBJECT_INSTANCE OBJECT_TYPE OPTIMIZER SEARCH_COLUMNS ID PARENT_ID POSITION COST CARDINALITY BYTES
OTHER_TAG PARTITION_START PARTITION_STOP PARTITION_ID OTHER DISTRIBUTION CPU_COST IO_COST TEMP_SPACE
WithRule1 2004-01-19 16:28:43 SELECT STATEMENT RULE 0
WithRule1 2004-01-19 16:28:43 SORT AGGREGATE 1 0 1
WithRule1 2004-01-19 16:28:43 NESTED LOOPS 2 1 1
WithRule1 2004-01-19 16:28:43 TABLE ACCESS BY INDEX ROWID MICRODEV T088_INSC 1 ANALYZED 3 2 1
WithRule1 2004-01-19 16:28:43 INDEX RANGE SCAN MICRODEV IX4_T088_INSC NON-UNIQUE ANALYZED 2 4 3 1
WithRule1 2004-01-19 16:28:43 TABLE ACCESS BY INDEX ROWID MICRODEV T090_CPOS_DEM 2 ANALYZED 5 2 2
WithRule1 2004-01-19 16:28:43 INDEX UNIQUE SCAN MICRODEV PK_T090_CPOS_DEM UNIQUE ANALYZED 2 6 5 1
7 rows selected.
STATEMENT_ID TIMESTAMP REMARKS OPERATION OPTIONS OBJECT_NODE OBJECT_OWNER OBJECT_NAME OBJECT_INSTANCE OBJECT_TYPE OPTIMIZER SEARCH_COLUMNS ID PARENT_ID POSITION COST CARDINALITY BYTES
OTHER_TAG PARTITION_START PARTITION_STOP PARTITION_ID OTHER DISTRIBUTION CPU_COST IO_COST TEMP_SPACE
WithChoose1 2004-01-19 16:29:37 SELECT STATEMENT CHOOSE 0 21680 21680 1 40
21680
WithChoose1 2004-01-19 16:29:37 SORT AGGREGATE 1 0 1 1 40
WithChoose1 2004-01-19 16:29:37 HASH JOIN 2 1 1 21680 59050 2362000
21680 3875000
WithChoose1 2004-01-19 16:29:37 TABLE ACCESS BY INDEX ROWID MICRODEV T088_INSC 1 ANALYZED 3 2 1 7031 96727 2708356
7031
WithChoose1 2004-01-19 16:29:37 INDEX RANGE SCAN MICRODEV IX4_T088_INSC NON-UNIQUE ANALYZED 2 4 3 1 232 96727
232
WithChoose1 2004-01-19 16:29:37 TABLE ACCESS FULL MICRODEV T090_CPOS_DEM 2 ANALYZED 5 2 2 11224 5662693 67952316
11224
6 rows selected. -
Help: Modifying inner join
Hello Folks,
I have an Access Query and am rewriting the whole query in Oracle to run a report.The thing is Am a beginner in oracle and am scratching my head on how to modify this inner join. please help me in rewriting this inner join in oracle. thanks a million
((Debtor INNER JOIN MAX_TRANS_DATE AS MAX_TRANS_DATE_1 ON Debtor .
EVENT_ID = MAX_TRANS_DATE_1.EVENT_ID) INNER JOIN
TMP$ALL_RECOVERY_TYPE
ON(Debtor . EVENT_CASE_ID = TMP$ALL_RECOVERY_TYPE . EVENT_CASE_ID) AND
(Debtor . EVENT_ID = TMP$ALL_RECOVERY_TYPE . EVENT_ID))
INNER JOIN CUBS TRANSACTIONS
ON (Debtor . EVENT_ID = CUBS TRANSACTIONS . EVENT_ID)
AND (Debtor . EVENT_CASE_ID = CUBS TRANSACTIONS . EVENT_CASE_ID)Thanks for getting back. But still am unable to get the correct data. I will try to break it down.
Microsoft Access Table MAX_TRANS_DATE menitoned above in the inner join was originally coming from table called TRANSACTIONS i.e.( MAX_TRANS_DATE = SELECT [Transactions].[EVENT_ID], Max([Transactions].[TRANSDATE]) AS MaxOfTRANSDATE
FROM Debtor INNER JOIN Transactions ON [Debtor].[EVENT_ID]=[Transactions].[EVENT_ID]
GROUP BY [Transactions].[EVENT_ID];
Here the problem is am recreating the access database query in oracle database and we dont have MAX_TRANS_DATE in the Oracle database but we do have TRANSACTIONS table.
So i just used TRANSACTIONS in the inner join instead of MAX_TRANS_DATE.
But the result is wrong.The Field Transdate from TRANSACTIONS is pulling dates as 10/5/2006 instead of 02/01/2010. I suspect something is wrong with the joins.Please help me. I can provide the old access query and the new oracle query that i have created.
Thanks
Edited by: user11961230 on Mar 5, 2010 11:49 AM -
Update statement with inner join issues
I have searched for the answer on this and not really 100%....so figured I would ask...be nice :)
what have I done wrong? Or am I just going about this the wrong way? I have looked at the oracle docs and I can't find an example showing me this. I do see where you SET values based on the select query results. I want to update the result of a query based on the join with static values....
UPDATE table.a
SET table.a_STATUS=9,table.a.INDEX = 'N'
WHERE (SELECT table.a INNER JOIN table.b ON (table.a.COMPANY = table.b.COMPANY) AND (table.a.PO_NUMBER =table.b.PO_NUMBER) AND (table.a.PO_RELEASE =table.b.PO_RELEASE) AND (table.a.PO_CODE =table.b.PO_CODE) AND (table.a_STATUS=1) AND (table.b.CLOSED_FL = 'Y'));Hi,
Welcome to the forum!
user11360811 wrote:
I have searched for the answer on this and not really 100%....so figured I would ask...be nice :)
what have I done wrong? Or am I just going about this the wrong way? I have looked at the oracle docs and I can't find an example showing me this. I do see where you SET values based on the select query results. I want to update the result of a query based on the join with static values....
UPDATE table.aThat's updating a table called A in a schema called TABLE (which is not a good name for any user-named object). Are those really your table and schema names? Perhaps you meant to have an underscore instead of a dot:
UPDATE table_ais much, much more reasonable. It means the table name is TABLE_A (a perfectly good name) in the current schema.
SET table.a_STATUS=9,table.a.INDEX = 'N'
WHERE ( ...There's a syntax error. You can't just say
"WHERE (sub-query)"; it has to be
"WHERE EXISTS (sub-suery)" or
"WHERE (sub-query) = some_value" or
"WHERE some_value IN (sub_query)", or something similar. WHERE can never be used without some kind of comparison operator, such as EXISTS, = or IN.
SELECT table.a INNER JOIN table.b ON ...Here are some more syntax errors. The correct syntax for any query is
SELECT column_list
FROM table_name ...If table.a is your (first) table name, then you're missing the list of columns to SELECT, and the mandatory keyword FROM.
(table.a.COMPANY = table.b.COMPANY) AND (table.a.PO_NUMBER =table.b.PO_NUMBER) AND (table.a.PO_RELEASE =table.b.PO_RELEASE) AND (table.a.PO_CODE =table.b.PO_CODE) AND (table.a_STATUS=1) AND (table.b.CLOSED_FL = 'Y'));Some general advice about UPDATE:
If it's not obvious how to use UPDATE to do what you want, then there's a good chance that UPDATE is the wrong tool for the job. MERGE might be much simpler, and more efficient as well. This is especially likely if you need to join the table that's being updated to some other table.
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved. That way, the people who want to help you can re-create the problem and test their ideas.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
If you're asking about a DML statement, such as UPDATE, the CREATE TABLE and INSERT statements should re-create the tables as they are before the DML, and the results will be the contents of the changed table(s) when everything is finished.
Always say which version of Oracle you're using (for example, 11.2.0.2.0).
See the forum FAQ {message:id=9360002}
Edited by: Frank Kulash on Jan 17, 2013 4:58 PM -
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 -
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 -
Dear Experts,
I have writen a inner join code with MKPF and MSEG which taking too much time, while I have used index.
Indexes are:
MSEG
MATNR
WERKS
LGORT
BWART
SOBKZ
MKPF
BUDAT
MBLNR
My Select Query is :
SELECT B~MATNR
B~MAT_KDAUF
B~MAT_KDPOS
B~BWART
B~MENGE
B~MEINS
B~AUFNR
INTO TABLE IT_MSEG
FROM MKPF AS A
INNER JOIN MSEG AS B
ON AMBLNR EQ BMBLNR
AND AMJAHR EQ BMJAHR
WHERE A~BUDAT IN BUDAT
AND B~MATNR IN MATNR
AND B~WERKS IN WERKS
AND B~LGORT IN LGORT
AND B~BWART IN BWART.hi,
you can use for all entries it will work faster then joins
About it:*
FOR ALL ENTRIES WHERE
Syntax
... FOR ALL ENTRIES IN itab WHERE ... col operator itab-comp ...
Effect
If the addition FOR ALL ENTRIES is specified before the language element WHERE, then the components comp of the internal table itab can be used as operands when comparing with relational operators.
The internal table itab must have a structured line type and the component comp must be compatible with the column col.
The logical expression sql_cond of the WHERE condition can comprise various logical expressions by using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one Comparison with a column of the internal table itab, which can be specified either statistically or dynamically (Release 6.40 and higher). In a statement with a SELECTstatement with FOR ALL ENTRIES, the addition ORDER BY can only be used with the addition PRIMARY KEY.
The whole logical expression sql_cond is evaluated for each individual line of the internal table itab. The resulting set of the SELECT statement is the union of the resulting sets from the individual evaluations. Duplicate lines are automatically removed from the resulting set. If the internal table itab is empty, the whole WHERE statement is ignored and all lines in the database are put in the resulting set.
Notes
In Release 6.10 and higher, the same internal table can be specified after FOR ALL ENTRIES and after INTO.
The addition FOR ALL ENTRIES is only possible before WHERE conditions of the SELECT statement.
Example
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.
hope it will help you
Rahul sharma
Edited by: RAHUL SHARMA on Sep 11, 2008 8:10 AM -
Hi Friends,
I have given the innerjoin between BKPF & BSEG tables,
And i am fetching BUKRS, BELNR,GJAHR, BLART,BLDAT,BUDAT fields from BKPF and BUZEi from BSEG table, but it is showing error as u cannot create inner join for BSEG table,
Kindly help me on this .
Thanks & Regards,Hi,
I using the code like this,
It displaying the output without displaying any data in BUZEI field, Even i have given the field name in the field catalog.
Could u plz help me on this,
Waiting for ur reply.
TYPES : BEGIN OF T_BKPF,
BUKRS TYPE BKPF-BUKRS,
BELNR TYPE BKPF-BELNR,
GJAHR TYPE BKPF-GJAHR,
BLART TYPE BKPF-BLART,
BLDAT TYPE BKPF-BLDAT,
BUDAT TYPE BKPF-BUDAT,
BUZEI TYPE BSEG-BUZEI,
END OF T_BKPF.
types: begin of t_bseg,
BUKRS TYPE BSEG-BUKRS,
BELNR TYPE BSEG-BELNR,
GJAHR TYPE BSEG-GJAHR,
end of t_bseg.
DATA : it_bkpf TYPE STANDARD TABLE OF t_bkpf with header line,
wa_bkpf TYPE t_bkpf,
it_bseg type standard table of t_bseg.
wa_bseg type t_bseg.
select bukrs belnr gjahr from bseg into table it_bseg.
perform data_retrieval_bseg.
perform data_retrieval.
form data_retrieval_bseg .
select buzei from bseg into table it_bkpf.
endform. " data_retrieval_bseg
*& Form DATA_RETRIEVAL
form data_retrieval.
IF it_bseg[] IS NOT INITIAL.
select bukrs belnr gjahr blart bldat budat from bkpf into
table it_bkpf for all entries in it_bseg
where bukrs = it_bseg-bukrs
and belnr = it_bseg-belnr
and gjahr = it_bseg-gjahr.
endif.
endform.
Maybe you are looking for
-
Error while creating a web proxy service using wsdl
Hi folks, In my use case I should create a web service proxy using the wsdl. While I am creating the web service proxy I am getting some error like the binding method does not have the SOAP extension. I am giving the error below for more clarity Caus
-
Does sender file adapter loose files/ miss them??
HI All, I am in a file to IDOC scenario. Xi is picking files from a network folder and creating each file into a single IDOC and sends to R/3. All seems fine when we do testing for 1 file at a time However I realised that if more than 20 or 40+ files
-
Better ripper than iTunes on Leopard?
hi guys, i love iTunes and am not interested in starting another flame war... but i was never quite satisfied with the ripping and encoding quality. on my Linux box I use cdparanoia (a ripper based on cdda2wav) and LAME (mp3encoder) and i like the fl
-
will there or are there any new game updates on the mini?
-
Exception from httpclusterservlet - please help
Hi, We are getting the following exception under one scenario. We are using jsps on wls 451 sp9 on Solaris 2.7. This happens with jdk1.2.2 but goes away with jdk 1.1.7. We are desperate to use jdk 122 for performance rea