Regarding joining of two tables with same feilds
hello gurus
i am new to abap programming. i have to extract data from two tables ie coss and cosp tables . one table has 180 records and another table has 500 records i want to extract these two table records into internal table(680 records) and then i have to populate it to flatfile through gui download. can any one give me use code to work on it.these two tables has same set of feilds.
Hi,
First you should verify if you want to get all the data from both tables regardless if its the same record. If it is, then you can follow this logic:
select * from coss into table it_coss_cosp. "step 1
select * from cosp appending table it_coss_cosp. "step 2
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
filename = data.txt
FILETYPE = 'ASC'
APPEND = ' '
WRITE_FIELD_SEPARATOR = ' '
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
IMPORTING
FILELENGTH =
tables
data_tab = it_coss_cosp
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
But if you plan to get those record which exists in both tables then use a join condition for your select statement.
Hope this helps...
P.S. Please award points for useful answers.
Similar Messages
-
Populate two table with same method
Hi
I have two tables in my iview. Both have same column structure but populates data from two different folders.
The context nodes are also similair only difference being change in the node name.
I was thinking about one single method which can be used to fill both the tables.
But I am having difficulty in passing the arguments to this method.
Can any1 guide me...
Regards
BobuHi Bobu,
You can create a method with the two parameters
1. IWDNode
2.IWDNodeElement
You need to call these methods when you want to fill the table. While calling this method you need to send the above two parameters with different Node and Node element references.. We can take referecne of different node with A and B as the node names as
IWDNode refA = wdContect.NodeA();
IWDNode refB = wdContect.NodeB();
IWDNodeElemtn refelemA = refA.createElement();
IWDNodeElemtn refelemB = refB.createElement();
Thanks,
Raju Bonagiri -
How to use common object from two tables with out join.
HI,
I have two tables called A & B In A table i have the following objects
1.weekend
2.S1(measure)
3.S2(measure)
4.S3(measure)
5.S4(measure)
And In B table i have followning columns
1.week end
2.p1(measure)
3.p2(measure)
4.p3(measure)
5.p4(measure)
Now in universe i created all the measure objects i.e.s1,s2,s3,s4,p1,p2,p3,p4 A.weekend,B.weekend.
instead of using week end two times i wnt to use only once because this is common in both table.
if i use join between these tables i am getting values fine
But With out join is there any thing to do in universe level to create common objects to use from both the tables..I tried using aggregate awareness but while reporting it is taking as two SQL.which is not synchronized.
Please help me on this ...hi,
Although Weekend column is present in both tables, by creating a single Object in Universe, Universe can identify relationship with only table referenced in Object Creation.
So, there will be no identification of relationship with other table measures.
Obviously, you need to create 2 Weekend objects in Universe (in two classes).
Case 1: You need not join these two tables in Universe. When you create 2 Queries in WEBI, automatcially Weekend objects are synchronized (if both are of same datatype)
Case 2: If you join these two tables in Universe, Obviously,
your SQL may contain Weekend from Table1, measures from Table 2
or
your SQL may contain Weekend from Table2, measures from Table 1
Finally, You need to create 2 objects in Universe. But your query may contain a single Object based on Case 2.
Regards,
Vamsee -
Get the Common from Two Internal Tables with same structure
Hi ,
I need to get the Common data from Two Internal Tables with same structure with using the looping method.
For e.g.
I have two internal table say ITAB1 and ITAB2.
ITAB1 has values A,B,C,D,E,F
ITAB2 has values A,H,B,Y,O
Output at runtime should be : A,BHi mohit,
1. If u want to compare all fields,
for matching purpose,
then we can do like this.
2.
report abc.
data : a like t001 occurs 0 with header line.
data : b like t001 occurs 0 with header line.
loop at a.
LOOP AT B.
IF A = B.
WRITE :/ 'SAME'.
ENDIF.
endloop.
ENDLOOP.
regards,
amit m. -
Join two tables with no matching records
Hi All,
I have two tables which have got data as below. Now I need to join those two tables but there are no matching rows or columns in those tables. I have used OUTER JOIN but query was taking more than 5 mnts to run. Whats the best way to join two tables where
there are no matching records.
Table : Sections &Table : orders
I am expecting the final output like I have mentioned below.
How can i write a JOIN. Note there are no matching records from both the tables.
Pls.This is a very urgent requirement.Regards
-pepThanks Elrand. I have one question. What if I want to add 10 more parameters in @Section table then
the logic I have written below will not work. I will have to make it dynamic. Any suggestions.?
declare @test table (RowNo INT,CokeType NVARCHAR(MAX),BeginUsage dateTIME)
declare @Section table (SectionName NVARCHAR(100))
insert into @Section values ('CokeType')
insert into @Section values ('BeginUsage')
insert into @test values (1,'OMV - 02E (04/2012)','01-02-2014')
insert into @test values (2,'OMV - 02E (04/2012)','01-03-2014')
insert into @test values (3,'PCIC - 01 (01E/2013)','01-04-2014')
insert into @test values (4,'PCIC - 01 (01E/2013)','01-05-2014')
insert into @test values (5,'PCIC - 01 (E) - 07/2011 & Alba /2010 (C/F) 05/2011','01-06-2014')
select * from @Section
select * from @test
SELECT
RowNo,SectionName,
CASE
WHEN(SectionName = 'CokeType') THEN CokeType
ELSE
CAST (BeginUsage AS VARCHAR(MAX))
END
AS DATA
FROM @Section AS S
CROSS APPLY
(SELECT T.RowNo,T.CokeType,T.BeginUsage FROM @test T) P
ORDER BY SectionName DESC -
To split a table as two tables with equal no of records
Hi Everyone,
I have a table with size of 100000 records which is reterieved from different tables thats why idx is not in a sequential order. for example
idx
1
5
100 and so on
i want to create two different tables with same number of records but i dont want any duplicate records. Please anyone can help how can i get it.
Best Regards,Please check the following script - hope that will help you --
SQL>
SQL> set serveroutput on
SQL>
SQL>
SQL> create table test_vaneeza
2 as
3 (
4 select 1 idx,'55 Mary Road' address from dual
5 union all
6 select 2, '10 Glenhuntly Road' from dual
7 union all
8 select 3, '5 Terrace' from dual
9 union all
10 select 100, '1212 Dandenong Road' from dual
11 union all
12 select 1000, '12 Liverpool Street' from dual
13 );
Table created.
SQL>
SQL>
SQL> set lin 1000
SQL>
SQL> select * from test_vaneeza;
IDX ADDRESS
1 55 Mary Road
2 10 Glenhuntly Road
3 5 Terrace
100 1212 Dandenong Road
1000 12 Liverpool Street
SQL>
SQL>
SQL> drop table gghh;
Table dropped.
SQL>
SQL>
SQL> create table gghh(a number(10),
2 b varchar2(100));
Table created.
SQL>
SQL>
SQL> drop table ggyy;
Table dropped.
SQL>
SQL>
SQL> create table ggyy(c number(10),
2 d varchar2(100));
Table created.
SQL>
SQL>
SQL> select count(*) from ggyy;
COUNT(*)
0
SQL>
SQL>
SQL> select count(*) from gghh;
COUNT(*)
0
SQL>
SQL> insert all
2 when rownum<=(select count(distinct idx) from test_vaneeza)/2
3 then
4 into gghh
5 else
6 into ggyy
7 select distinct idx,address
8 from test_vaneeza;
5 rows created.
SQL>
SQL>
SQL> commit;
Commit complete.
SQL>
SQL>
SQL> select count(*) from ggyy;
COUNT(*)
3
SQL>
SQL>
SQL> select count(*) from gghh;
COUNT(*)
2
SQL>
SQL>
SQL> select * from ggyy;
C D
3 5 Terrace
100 1212 Dandenong Road
1000 12 Liverpool Street
SQL>
SQL>
SQL> select * from gghh;
A B
1 55 Mary Road
2 10 Glenhuntly Road
SQL> Regards.
Satyaki De. -
How to give relationship between two tables with comon column with between oprator
Hi Folks,
I am using Sql Server 2008R2. I am getting a problem to establish relationship between two tables.
I have two Tables, 1.Inventory Details Table another one is Inventory Header Table.
Inventory Details Table having a column Card No and inventory Header Table having columns From card No and To Card No.
I want to give relationship between these two tables with Card no. Could you please provide me the Sql Query.
Your help would be greatly appreciated .
Regards
hasthi.
email:[email protected]Hi Raju,
We have two way that we can relate to the table either join or quality condition use following syntax/Query for relating two tables
select * from Inventory_Details ID inner join Inventory_Header IH on ID.CardNo between IH.FrmCardno and IH.ToCardNo
or
Select * from Inventory_Details ID ,Inventory_Header IH where ID.CardNo=IH.CardNo OrSelect * from Inventory_Details ID ,Inventory_Header IH where ID.CardNo between IH.FrmCardno and IH.ToCardNo
Hope this will help you
Niraj Sevalkar -
Two records with same key (Infocube)
Hi,
I was trying to do, in a update rule, an "IF" condition with two key figures.
IF Kf1 > Kf2. result = Kf1 else result = Kf2.
But the data in the source (datamart Infocube to infocube) have tow records with the same characteristics combination (the same keys)and different amount in the keyfigures, then the result of my "if" condition is not the expected because I understood in the infocube only exists one characteristics combination. :S
I was seeing those records in the manage transaction of the infocube.
Some reason for this?
Thanks and regards
Victoria LeóThis can happen with parallel loads. Two rows with same set of Char values but in different packets of the same Request, being loaded at the same time.
It really shouldn't be an issue - your update rule will make the KF change as desired. Your queries aggregate KFs based characteristic values, not Dim IDs, so you'll get the totals you expect.
Here's some more info:
There is an RSRV Test that lets you check a dimension for a cube to see if multiple DIM IDs exist for the same combination of Chars - <b>Multiple Entries in Dimensions of a (Basis) InfoCube</b>
Output looks like:
12:02:24 o'clock on 08/25/2006: Start test run for user PIZZAMAN:)
Dimension ZFM_C521: DIMID 61,215 and 61,214 have same characteristic values
Dimension ZFM_C521: DIMID 61,880 and 61,879 have same characteristic values
Dimension ZFM_C521: DIMID 61,366 and 61,365 have same characteristic values
Dimension ZFM_C521: DIMID 61,368 and 61,367 have same characteristic values
12:02:24 on 08/25/2006: Test run for user PIZZAMAN:) completed
You can run the Correct Error option to have it update fact rows to use one of the DimIDs if you want, but unless you have lots of them, I even wouldn't bother.
Here's the description of the test:
<u>Description</u>
This elementary test recognizes whether there are several lines that have different DIMIDs(dimension table key), but have the same SIDs for the selected dimension table for the InfoCube specified. (This can occur by using parallel loading jobs). This has nothing to do with an inconsistency. However, unnecessary storage space is occupied in the database.
<u>Repairs</u>
Since the different DIMIDs with the same SIDs are normally used in the fact tables, they cannot simply be deleted. Therefore, all of the different DIMIDS in the fact tables are replaced by one DIMID that is randomly selected from the equivalent ones. Before a change can be made to the database, the consent of the user is requested.
DIMIDs that have become unnecessary are deleted in the connection. In doing so, not only are the DIMDs deleted that were released in the first part of the repair, but so are all of those that are no longer used in the fact tables (including aggregates). The consent of the user is again requested before this change is made. -
Search help value restriction in two tables having same value table
Hi Gurus,
I have two tables containing same field having same domain with value table. My requirement is to restrict the values in the tables. For example the field contains 4 values:
1) A
2) B
3) C
4) D
For table 1, only A and C should be seen in F4 and for table 2, only B and D should be seen. Also if somebody forces B or D
in 1st table should not be allowed and the same for 2nd table ( A & C are not allowed ). How to do this using search help exit . Which event should I use. I don't want to create two separate check tables containing only the required values.
Regards,
DebopriyoHi Gurus,
I have two tables containing same field having same domain with value table. My requirement is to restrict the values in the tables. For example the field contains 4 values:
1) A
2) B
3) C
4) D
For table 1, only A and C should be seen in F4 and for table 2, only B and D should be seen. Also if somebody forces B or D
in 1st table should not be allowed and the same for 2nd table ( A & C are not allowed ). How to do this using search help exit . Which event should I use. I don't want to create two separate check tables containing only the required values.
Regards,
Debopriyo -
We migrated Packages from SSIS 2008 to 2012. The Package is working fine in all the environments except in one of our environment.
SSIS 2012 is intermittently failing with below error while importing data from a source table into a Destination table with same exact schema.
Error: 2014-01-28 15:52:05.19
Code: 0x80004005
Source: xxxxxxxx SSIS.Pipeline
Description: Unspecified error
End Error
Error: 2014-01-28 15:52:05.19
Code: 0xC0202009
Source: Process xxxxxx Load TableName [48]
Description: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "Invalid date format".
End Error
Error: 2014-01-28 15:52:05.19
Code: 0xC020901C
Source: Process xxxxxxxx Load TableName [48]
Description: There was an error with Load TableName.Inputs[OLE DB Destination Input].Columns[Updated] on Load TableName.Inputs[OLE DB Destination Input]. The column status returned was: "Conversion failed because the data value overflowed
the specified type.".
End Error
But when we reorder the column in "Updated" in Destination table, the package is importing data successfully.
This looks like bug to me, Any suggestion?Hi Mohideen,
Based on my research, the issue might be related to one of the following factors:
Memory pressure. Check there is a memory challenge when the issue occurs. In addition, if the package runs in 32-bit runtime on the specific server, use the 64-bit runtime instead.
A known issue with SQL Native Client. As a workaround, use .NET data provider instead of SNAC.
Hope this helps.
Regards,
Mike Yin
If you have any feedback on our support, please click
here
Mike Yin
TechNet Community Support -
MATERIALIZED view on two tables with Fast Refresh
i Wanted to create MV on two tables with Fast refresh on commit.
I followed below steps
create materialized view log on t1 WITH PRIMARY KEY, rowid;
create materialized view log on t2 WITH PRIMARY KEY, rowid;
CREATE MATERIALIZED VIEW ETL_ENTITY_DIVISION_ASSO_MV
REFRESH fast ON commit
ENABLE QUERY REWRITE
AS
select A.ROWID B.ROWID,a.c1, DECODE(a.c1,'aaa','xxx','aaa') c2
from t1 A
join t2 b
on AB.c1= CD.c2;
i am getting below error.
Error report:
SQL Error: ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view
12054. 00000 - "cannot set the ON COMMIT refresh attribute for the materialized view"
*Cause: The materialized view did not satisfy conditions for refresh at
commit time.
*Action: Specify only valid options.
Basically i want to take record in MV by joinig two tables and if both of the base tables will updated then record should reflect in materialised view.
Please do the needfull.does the table support PCT? the other restrictions on joins look to be ok in your statement.
maybe try creating first with on demand instead of commit to see does it create.
http://docs.oracle.com/cd/B19306_01/server.102/b14223/basicmv.htm
>
Materialized Views Containing Only Joins
Some materialized views contain only joins and no aggregates, such as in Example 8-4, where a materialized view is created that joins the sales table to the times and customers tables. The advantage of creating this type of materialized view is that expensive joins will be precalculated.
Fast refresh for a materialized view containing only joins is possible after any type of DML to the base tables (direct-path or conventional INSERT, UPDATE, or DELETE).
A materialized view containing only joins can be defined to be refreshed ON COMMIT or ON DEMAND. If it is ON COMMIT, the refresh is performed at commit time of the transaction that does DML on the materialized view's detail table.
If you specify REFRESH FAST, Oracle performs further verification of the query definition to ensure that fast refresh can be performed if any of the detail tables change. These additional checks are:
A materialized view log must be present for each detail table unless the table supports PCT. Also, when a materialized view log is required, the ROWID column must be present in each materialized view log.
The rowids of all the detail tables must appear in the SELECT list of the materialized view query definition.
If some of these restrictions are not met, you can create the materialized view as REFRESH FORCE to take advantage of fast refresh when it is possible. If one of the tables did not meet all of the criteria, but the other tables did, the materialized view would still be fast refreshable with respect to the other tables for which all the criteria are met. -
Two methods with same name but different return type?
Can I have two methods with same name but different return type in Java? I used to do this in C++ (method overloading or function overloading)
Here is my code:
import java.io.*;
public class Test{
public static void main(String ar[]){
try{
//I give an invalid file name to throw IO error.
File file = new File("c:/invalid file name becasue of spaces");
FileWriter writer = new FileWriter(file ,true);
writer.write("Test");
writer.close();
} catch (IOException IOe){
System.out.println("Failure");
//call first method - displays stack trace on screen
showerr(NPe);
//call second method - returns stack trace as string
String msg = showerr(NPe);
System.out.println(msg);
} // end of main
public static void showerr(Exception e){
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
try{
pw.close();
sw.close();
catch (IOException IOe){
IOe.printStackTrace();
String stackTrace = sw.toString();
System.out.println("Null Ptr\n" + stackTrace );
}//end of first showerr
public static String showerr(Exception e){
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
try{
pw.close();
sw.close();
catch (IOException IOe){
IOe.printStackTrace();
return sw.toString();
}//end of second showerr
} // end of class
[\code]Overloading is when you have multiple methods that have the same name and the same return type but take different parameters. See example
public class Overloader {
public String buildError(Exception e){
java.util.Date now = new java.util.Date() ;
java.text.DateFormat format = java.text.DateFormat.getInstance() ;
StringBuffer buffer = new StringBuffer() ;
buffer.append(format.format(now))
.append( " : " )
.append( e.getClass().getName() )
.append( " : " )
.append( e.getMessage() ) ;
return buffer.toString() ;
public String buildError(String msg){
java.util.Date now = new java.util.Date() ;
java.text.DateFormat format = java.text.DateFormat.getInstance() ;
StringBuffer buffer = new StringBuffer() ;
buffer.append(format.format(now))
.append( " : " )
.append( msg ) ;
return buffer.toString() ;
public String buildErrors(int errCount){
java.util.Date now = new java.util.Date() ;
java.text.DateFormat format = java.text.DateFormat.getInstance() ;
StringBuffer buffer = new StringBuffer() ;
buffer.append(format.format(now))
.append( " : " )
.append( "There have been " )
.append( errCount )
.append( " errors encountered.") ;
return buffer.toString() ;
}Make sense ???
Regards, -
SQL 2008 how to compare & identify data among 2 tables with same structure ?
Hello is there a TSQL way of comparing row by row for example comparing DateTimeStamp field in 2 separate tables with same structure in identifying if it's data was changed (If Table1.DateField > Table2.DateField THEN UPDATE it's entire row to match it's
corresponding Table1 row.) ?
Probably thinking would need a cursor to loop through or are there other better ways via TSQL ?
Thanks in advance.Hi,
I am assuming you have a PRIMARY KEY field or a UNIQUE field in both tables, which you should!
You can do this using "UPDATE with INNER JOIN". (SQL Server – Update Table with INNER JOIN)
Working example:
USE [TestDatabase]
GO
/* Create Temp Tables */
CREATE TABLE [dbo].[Table1]
[ID] INT
,[Name] VARCHAR(10)
,[ModifyDate] DATETIME
CREATE TABLE [dbo].[Table2]
[ID] INT
,[Name] VARCHAR(10)
,[ModifyDate] DATETIME
GO
INSERT INTO [dbo].[Table1] ([ID], [Name], [ModifyDate]) VALUES (1, 'Vishal', GETDATE())
INSERT INTO [dbo].[Table2] ([ID], [Name], [ModifyDate]) VALUES (1, 'Gajjar', GETDATE() + 1)
GO
SELECT [ID], [Name], [ModifyDate] FROM [dbo].[Table1]
SELECT [ID], [Name], [ModifyDate] FROM [dbo].[Table2]
GO
UPDATE T1
SET T1.[Name] = T2.[Name]
FROM [dbo].[Table1] T1
INNER JOIN [dbo].[Table2] T2 ON T1.[ID] = T2.[ID] /* Join on Key field */
WHERE T2.[ModifyDate] > T1.[ModifyDate] /* Update criteria */
GO
/* CleanUp - Drop Tables
DROP TABLE [dbo].[Table1], [dbo].[Table2]
This Updates Table1 with latest values from Table2, You need to change the UPDATE statement for your scenario.
- Vishal
SqlAndMe.com -
2 tables with same primary key
Hi,
2 tables with same primary key is possible,but when is wise to go for such ?
is that a bad desisn ?
eg:
Personal_details_employee
Official_details_employee
these 2 tables have same Primary key emp_id.
plz. reply me at [email protected] also
thanx
vikramhi Vikram,
In this case u can have then in one table itself and why do want to have two tables.
- Suresh.A -
Two idocs with same idoc number in idx5
We are using an idoc to file scenario where idocs are bundled using bpm and posted to ftp. here the issue is we are getting two idocs with same idoc number in idx5. due to which the file in ftp is getting overwritten.
Could anyone suggest me what to do in this regard.Hi,
>>>check your sender system is sending same IDoc twice ?
if you send the same IDOC twice they both get different numbers as IDOC number is taken from the IDOC num range
unless you're able to send the same IDOC twice with the same IDOC num somehow
Regards,
Michal Krawczyk
Maybe you are looking for
-
I am getting "invalid signature" error when i try updating itunes. How do I fix?
I received a notice that an update was available for itunes. I went through the installation process and then near the end an error message came up telling me that it would not be installed because of an invalid signature I tried doing this again onl
-
Why I can no longer save videos (*.flv) from my cache folder?
Well, I don't speak English. I'm sorry. Até o Firefox 3.6.16 eu conseguia salvar um vídeo (*.flv), do Youtube por exemplo, a partir da pasta cache. Por que não posso mais fazê-lo no Firefox 4.0? A partir disso, desinstalei o Firefox 4.0, voltei para
-
I purchased an explicit version of a song by mistake. I then went back on line and purchased the clean version. I've deleted it from my itunes library but when I sync it with my phone, it reappears. How do I remove it permanently? It almost seems
-
Will iphone 5 support fm radio in hyderabad
Hi All, I am an iphone 5 user. I have onedoubt coul any one give me answer. I need to use FM Radio in my Iphone 5. Please let me know the solution. Have a blessed day.
-
I am creating a SharePoint site collection that will house sites for customer portals (one site per customer). What I would like to do is create a template site that has a couple of key variables (i.e. a customer ID, customer name, etc) that can be a