Join field - 2 table to 1
Hi,
I have 2 tables:
tab1 : DocNumber1 field11 field12 field13
tab2 : DocNumber2 field21 field22
I want to join tab1 and tab2 into tab3 with only this fields.
tab3 : DocNumer1 field11 field22
Which one is the correct way to program it?
Thanks a lot!
if ur selecting from database then this is the method.
select a~docnumber1
a~field11
b~field22
into table itab3
from tab1 as a
inner join tab2 as b
where adocnumber1 = bdocnumber2.
If u have data already in tab1 & tab2...then
sort tab1 by docnumber1.
sort tab2 by docnumber2.
loop at tab1.
read table tab2 with key docnumber2 = tab1-docnumber1.
if sy-subrc = 0.
itab3-field1 = tab1-docnumber1.
itab3-field2 = tab1-field11.
itab3-field3 = tab2-field22.
append itab3.
endif.
clear : tab1, tab2, itab3.
endloop.
Similar Messages
-
How to join fields from different internal tables and display into one int
hai i have one doubt...
how to join fields from different internal tables and display into one internal table..
if anybody know the ans for this qus tell me......hii
you can read data as per condition and then can join in one internal table using READ and APPEND statement..refer to following code.
SELECT bwkey " Valuation Area
bukrs " Company Code
FROM t001k
INTO TABLE i_t001k
WHERE bukrs IN s_bukrs.
IF sy-subrc EQ 0.
SELECT bwkey " Valuation Area
werks " Plant
FROM t001w
INTO TABLE i_t001w
FOR ALL ENTRIES IN i_t001k
WHERE bwkey = i_t001k-bwkey
AND werks IN s_werks.
IF sy-subrc EQ 0.
LOOP AT i_output INTO wa_output.
READ TABLE i_t001w INTO wa_t001w WITH KEY werks = wa_output-werks.
READ TABLE i_t001k INTO wa_t001k WITH KEY bwkey = wa_t001w-bwkey.
wa_output-bukrs = wa_t001k-bukrs.
MODIFY i_output FROM wa_output.
CLEAR wa_output.
ENDLOOP. " LOOP AT i_output
ENDIF. " IF sy-subrc EQ 0
regards
twinkal -
Want field and table name for RESERVED coloum in MMBE
Hi ,
There is a RESERVED coloum in MMBE and I want this * RESERVED* coloum in MB52 .
I got to know that Field related to this RESERVED coloum is BDMNG coming from table RESB .
To confirm the field and table I checked the value in BDMNG by putting join on MARA and RESB where MATNR = BAUGR.
But I got value in BDMNG is 50 and in MMBE it is .228 for that material.
Please tell me field and table name for RESERVED coloum. and hoe to join MARA and RESB to get exact result.
Thanks and Regards,
RanuHi,
Mara-matnr is not equal to Resb-matnr and it shows no record if i do like this.
But Mara-matnr is equal to Resb-baugr, and it gives me 1 record .But porblem is that i dint get BDMNG field matching with mmbe RESEVERD coloum. -
Right way to preserve all parent table entries in a join with many tables!!
This problem is quite interesting to me. I have asked this question to others but no body is able to provide me with proper answers.
The problem is: How do I join a huge parent table with many child tables (more than 5 child tables) preserving all of the parent table entries. Lets say there is the parent table parentTable and three child tables childTable1, childTable2, childTable3. In order to get the data after joining these tables the query that I have been using was:
select parent.field1, parent.field2, parent.field3, child1.field4, child1.field5, child2.field6, child3.field7 from ParentTable parent, childTable1 child1, childTable1 child2, childTable3 child3 where parent.fielda = child1.fieldb and parent.fieldc = child.fieldd and parent.fielde = child.fieldf.
Although the tables are huge (more than 100,000 entries), this query is very fast, however those parent table entries which do not have child entries are lost. I know that I can left join a parent table with a child table and then with the next child table and then with the next child table and continue. Isn't there a simple solution for this commonly happening problem?
Please provide suggestions please...Hello Lakshmi,
Although I do not know exactly how to achieve what you want to achieve but I have seen DBAs/ABAPers in my experience can run queries/scripts using the COUNT function to give the actual number of line items per table for all your 100 or odd tables.
Rgds
CONMJI -
Display read only field in table / form from another vo
i came across couple of scenarios where i had to bring a field in a table / from from other vo than on which most fields in table / form were based. in all cases i had to display the field from another vo as read only and there was only one record in other vo which was related to previous vo in table / form. for this i created a view accessor and created a soc with model driven lov. the problem with this is that first element alwasy shows blank in soc. how can i display the filled soc with first element populated and read only in this scenario. i tried alternatively with groovy expressions but other people in team said it is not good practice to use groovy expressions to fill fields in one VO from other VO. how can i acheive this requirement with soc component / lov / view accessors. is there any other alternative as well. jdev 11 1 1 5
1) in the attribute of the VO select the 'List of values' node and edit the list attribute you see there; in the dialog select the UI Hints tad and make sure the checkmark for the 'Include "no Selection Item' is off.
2) you can base a VO on to EO which are then joined via one or more attributes (association)
Timo -
Arithmatic operations on fields in tables
Hello Members,
My query might seem pretty basic, but seems uphill to me, as i have no idea how to perform arithmatic operations between fields in tables.
I have two tables temp1 and temp2. each of these tables have 2 fields : account no. and balance
the data would resemble the following, in each of the tables:
6.28899273 0
6.28899274 0
6.28899275 0
6.28899289 625.12
6.28899292 2666.24
Can you please give me an idea how to go about doing the following:
1. Compare the tables temp1 and temp2 for their respective account numbers and balances
2. Copy the results in a new table temp3, which will have 2 columns :
account no ( common to temp1 and temp2 )
deviation: subtracted balance of temp1 and temp2
regards,
novice82user8635888 wrote:
Will be great if someone can give me a headstart on the following:
I have two tables temp1 and temp2 ( tables belonging to 2 different databases ) with two feilds
account no., ( Common in both tables )
balance ( float data type ).
1. I want to compare the balance feilds in temp1 and temp2.
print out the no. of accounts and percentage of match and mismatch.
2. output the a/c nos. whose balances dont match into a seperate table..Hello, this might be one approach for you:
First, identify those accounts that are different, and INSERT them into the table
INSERT /*+ APPEND */ INTO target_table
SELECT t1.account_no, t1.balance, t2.balance
FROM table1 t1
JOIN table2@db_link t2 ON (t1.account_no = t2.account_no)
WHERE NVL(t1.balance, -99999999999) != NVL(t2.balance, -99999999999);This assumes that -99999999999 can never be a valid balance.
Then, you can cycle through this table and print out the mismatches:
set serveroutput on size 100000 (or set serveroutput on size unlimited)
BEGIN
FOR cur_rec IN (SELECT account_no, (t1.balance / CASE t2.balance WHEN 0 THEN NULL END) * 100 percent_mismatch FROM target_table)
LOOP
DBMS_OUTPUT.PUT_LINE('Account No: ' || cur_rec.account_no || ', Percent Mismatch: ' || cur_rec.percent_mismatch);
END LOOP;
END;
/If you have a lot of records this may not be a feasible approach, and you'd be better looking at UTL_FILE if you to capture the anomolies in a file.
And alternative would be to do the whole lot in SQL:
set pagesize 5000
set linesize 300
set colsep ','
spool /tmp/your_file.csv
SELECT t1.account_no, t1.balance, t2.balance, (t1.balance / CASE t2.balance WHEN 0 THEN NULL END) * 100 percent_mismatch
FROM table1 t1
JOIN table2@db_link t2 ON (t1.account_no = t2.account_no)
WHERE NVL(t1.balance, -99999999999) != NVL(t2.balance, -99999999999);
user8635888 wrote:another question, that I have is, how does sql handle the computation, if a value in a particular field is divided by 0 You'll see from the code that if the divisor is zero, I'm substiting NULL, which means that the percent_mismatch will be NULL. -
Can we implement the custom sql query in CR for joining the two tables
Hi All,
Is there anyway to implement the custom sql query in CR for joining the two tables?
My requirement here is I need to write sql logics for joining the two tables...
Thanks,
GanaIn the Database Expert, expand the Create New Connection folder and browse the subfolders to locate your data source.
Log on to your data source if necessary.
Under your data source, double-click the Add Command node.
In the Add Command to Report dialog box, enter an appropriate query/command for the data source you have opened.
For example:
SELECT
Customer.`Customer ID`,
Customer.`Customer Name`,
Customer.`Last Year's Sales`,
Customer.`Region`,
Customer.`Country`,
Orders.`Order Amount`,
Orders.`Customer ID`,
Orders.`Order Date`
FROM
Customer Customer INNER JOIN Orders Orders ON
Customer.`Customer ID` = Orders.`Customer ID`
WHERE
(Customer.`Country` = 'USA' OR
Customer.`Country` = 'Canada') AND
Customer.`Last Year's Sales` < 10000.
ORDER BY
Customer.`Country` ASC,
Customer.`Region` ASC
Note: The use of double or single quotes (and other SQL syntax) is determined by the database driver used by your report. You must, however, manually add the quotes and other elements of the syntax as you create the command.
Optionally, you can create a parameter for your command by clicking Create and entering information in the Command Parameter dialog box.
For more information about creating parameters, see To create a parameter for a command object.
Click OK.
You are returned to the Report Designer. In the Field Explorer, under Database Fields, a Command table appears listing the database fields you specified.
Note:
To construct the virtual table from your Command, the command must be executed once. If the command has parameters, you will be prompted to enter values for each one.
By default, your command is called Command. You can change its alias by selecting it and pressing F2. -
Best approach to join multiple statistics tables into one
I have read different approaches to join multiple statistics tables into one, they all have a column "productobjectid".
I want to get all data for each product and put it to excel and output a jpg statistic with cfchart.
How would you do this, the sql part?
Thanks.A couple suggestions:
1) when joining tables, its best to list both table/fields that you are joining in the FROM clause:
FROM shopproductbehaviour_views INNER JOIN shopproductbehaviour_sails ON shopproductbehaviour_views.productobjectid = shopproductbehaviour_sails.productobjectid
2) You add tables to a SQL join by placing another join statement after the SQL above:
SELECT *
FROM TableA INNER JOIN TableB on TableA.myField = TableB.myField
INNER JOIN TableC on TableA.anotherField = TableC.anotherField
3) If you have columns in the tables that are named the same, you can use column aliases to change the way they appear in your record set:
SELECT TableA.datetimecreated 'tablea_create_date', TableB.datetimecreated 'tableb_create_date'
4) Certainly not a requirement, but you might want to look into using <cfqueryparam> in your where clause:
WHERE shopproductbehaviour_sails.productobjectid = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#all.productobjectid#">
You might want to consider checking out one of the many tutorials on SQL available online. Many of the questions you posed in your post are covered in pretty much every basic SQL tutorial. Alternately, a good SQL book is worth its weight in gold for a beginning web applications developer. -
Join two source tables and replicat into a target table with BLOB
Hi,
I am working on an integration to source transaction data from legacy application to ESB using GG.
What I need to do is join two source tables (to de-normalize the area_id) to form the transaction detail, then transform by concatenate the transaction detail fields into a value only CSV, replicate it on the target ESB IN_DATA table's BLOB content field.
Based on what I had researched, lookup by join two source tables require SQLEXEC, which doesn't support BLOB.
What alternatives are there and what GG recommend in such use case?
Any helpful advice is much appreciated.
thanks,
XiaocunXiaocun,
Not sure what you're data looks like but it's possible the the comma separated value (CSV) requirement may be solved by something like this in your MAP statement:
colmap (usedefaults,
my_blob = @STRCAT (col02, ",", col03, ",", col04)
Since this is not 1:1 you'll be using a sourcedefs file, which is nice because it will do the datatype conversion for you under the covers (also a nice trick when migrating long raws to blobs). So col02 can be varchar2, col03 a number, and col04 a clob and they'll convert in real-time.
Mapping two tables to one is simple enough with two MAP statements, the harder challenge is joining operations from separate transactions because OGG is operation based and doesn't work on aggregates. It's possible you could end up using a combination of built in parameters and funcations with SQLEXEC and SQL/PL/SQL for more complicated scenarios, all depending on the design of the target table. But you have several scenarios to address.
For example, is the target table really a history table or are you actually going to delete from it? If just the child is deleted but you don't want to delete the whole row yet, you may want to use NOCOMPRESSDELETES & UPDATEDELETES and COLMAP a new flag column to denote it was deleted. It's likely that the insert on the child may really mean an update to the target (see UPDATEINSERTS).
If you need to update the LOB by appending or prepending new data then that's going to require some custom work, staging tables and a looping script, or a user exit.
Some parameters you may want to become familiar with if not already:
COLS | COLSEXCEPT
COLMAP
OVERRIDEDUPS
INSERTDELETES
INSERTMISSINGUPDATES
INSERTUPDATES
GETDELETES | IGNOREDELETES
GETINSERTS | IGNOREINSERTS
GETUPDATES | IGNOREUPDATES
Good luck,
-joe -
How to disable some of the table fields in Table Maintenance Generator
HI,
I am creating one table which contains 10 fields.
But i wanted to disable some 2 fields in Table maintenance generator.
So can any one plz tell me how to disable those 2 fields.Generate a maintenance view for the table,
Goto- Table/Join Conditin Tab-- Put the name of your table
Goto-viewfield tab--- Put the fields whatever you required.
Then generate table maintenance for the view created.
pls chk
Thanks
Anurag -
Left outer join using multiple table
Hi,
I am trying to use left outer join with multiple tables , the join condition will be based on PERNR and BEGDA & ENDA for each infotype in selection screen.
select pa00~pernr pa00~begda pa00~endda pa00~massn pa00~massg pa00~stat2 pa00~aedtm pa00~uname
pa01~begda pa01~endda pa01~bukrs pa01~persg pa01~persk pa01~mstbr pa01~ename pa01~aedtm pa01~uname
pa02~begda pa02~endda pa02~nachn pa02~vorna pa02~midnm pa02~aedtm pa02~uname
pa016~begda pa016~endda pa016~cttyp pa016~aedtm pa016~uname
into CORRESPONDING FIELDS OF TABLE i_pall
from ( PA0000 as pa00 left OUTER JOIN pa0001 as pa01 on pa00~pernr = pa01~pernr )
left OUTER JOIN pa0002 as pa02 on pa00~pernr eq pa02~pernr )
left OUTER JOIN pa0016 as pa016 on pa00~pernr eq pa016~pernr )
where pa00~pernr in S_pernr
AND pa00~begda in s_bg0000
and pa00~endda in s_nd0000.
but this fails to fetch the value of begda enda from each pa0000,pa0001,pa0002,pa0016.
Please help!
MonirulWhy don't you use the standard logical database PNPCE and then Provide statement?
-
Select (join) into internal table with nested structures
Hello Experts,
i wonder about the correct notation of a select statement.
I have an internal table it_zoll including two structures as defined below.
The select is a join on the two tables zollp and zolls. As coded below the select is syntactically correct, but the fields
in the nested structures are not filled ....
Any ideas how to write the select statement ? (The internal table it_zoll must have the nested structures for other reasons ..)
Declaration:
TYPES: BEGIN OF ty_zollp,
belnr TYPE zollp-belnr,
werks TYPE zollp-werks,
gebnr TYPE zollp-gebnr,
END OF ty_zollp.
TYPES: BEGIN OF ty_zolls,
grnum type zolls-grnum,
werks type zolls-werks,
name1 TYPE zolls-name1,
END OF ty_zolls.
DATA: BEGIN OF wa_zoll.
DATA: zollp type ty_zollp.
DATA: zolls type ty_zolls.
DATA: END OF wa_zoll.
DATA: it_zoll LIKE TABLE OF wa_zoll.
Select:
SELECT
zollp~belnr zollp~werks zollp~gebnr
zolls~grnum zolls~werks zolls~name1
FROM zollp
JOIN zolls ON zolls~werks = zollp~werks
AND zolls~grnum = zollp~grnum
INTO CORRESPONDING FIELDS OF TABLE it_zoll
WHERE zollp~werks = werks
AND zollp~gebnr IN s-gebnr
AND ...
Thank you !DATA: BEGIN OF ty_zollp,
belnr TYPE zollp-belnr,
werks TYPE zollp-werks,
gebnr TYPE zollp-gebnr,
END OF ty_zollp.
DATA: BEGIN OF ty_zolls,
grnum type zolls-grnum,
werks type zolls-werks,
name1 TYPE zolls-name1,
END OF ty_zolls.
DATA: BEGIN OF wa_zoll.
Include structure ty_zollp.
Include structure ty_zolls.
DATA: END OF wa_zoll.
The above declaration had worked. Please try.
Regards,
Satish Kanteti -
How to use outer join on 3 tables
how to use outer join on 3 tables
say tables are mkpf,lips and vbrp
mkpf-xblnr = lips-vbeln
lips-vbeln = vbrp-vgbelrefer following querry
select a~bukrs
a~anln1
a~ord42
a~ord43
b~afabe
b~ndabj
b~kaafa
b~aafag
c~kostl
d~afasl
d~ndjar
d~ndper
into corresponding fields of table gt_master
from ( ( anla as a inner join anlc as b
on abukrs = bbukrs
and aanln1 = banln1
and aanln2 = banln2 )
inner join anlz as c
on abukrs = cbukrs
and aanln1 = canln1
and aanln2 = canln2 )
inner join anlb as d
on abukrs = dbukrs
and aanln1 = danln1
and aanln2 = danln2
where a~bukrs in s_comp. -
hi all,
i am facing the problem with the inner join in the select query for 4 tables.
can i use the inner join for tables in SAP 6.0 version,
it is going to dump.
here is my code
SELECT DISTINCT apernr abegda aendda awagetype aamount acurrency
altrctry brufnm banred bvorna bnachn cgroupcode d~vdsk1
FROM pa9011 AS a INNER JOIN pa0002 AS b ON bpernr = apernr
INNER JOIN pa9013 AS c ON cpernr = bpernr
inner join pa0001 as d on dpernr = cpernr
INTO CORRESPONDING FIELDS OF TABLE it_bonus
WHERE a~pernr IN s_pernr AND
a~begda IN s_date AND
a~subty EQ s_subty AND
a~wagetype EQ wa_perbonus AND
a~ltrctry = gc_ind AND
a~amount > 0 AND
b~endda = '99991231' AND
c~groupcode IN s_loc AND
c~endda = '99991231' and
d~endda = '99991231'
ORDER BY a~pernr.hi this is the dump ,
In a SELECT access, the read file could not be placed in the target
field provided.
Either the conversion is not supported for the type of the target field,
the target field is too small to include the value, or the data does not
have the format required for the target field. -
Cannot select the fields for table view WB2_V_MKPF_MSEG2
Hi, I have a program where the query is using join statement of MSEG and MKPF. As part of the performance enhancement I use Table View WB2_V_MKPF_MSEG2 instead.
Validation: Entries in MSEG and MKPF is the same as in WB2_V_MKPF_MSEG2 = OK (via SE16)
But upon debugging the program on SY-SUBRC breakpoint, I can see 5 rows appended in internal table T_MSEG "BUT" the entries are all blank.
The entries in my SE16 are exact data that's appearing on the filter statement in my SQL query below. SE16 is giving correct output, but using table view in my SQL does not give me the correct output.
(Note: This is my first time to use table view in ABAP-SQL)
SELECT MATNR_I BWART_I MENGE_I
FROM WB2_V_MKPF_MSEG2
INTO CORRESPONDING FIELDS OF TABLE T_MSEG
WHERE MATNR_I IN R_MATNR3
AND MATNR_I IN R_COMPNTS
AND WERKS_I EQ P_WERKS
AND BWART_I EQ '931'
AND BUDAT IN S_GSTRP
AND MJAHR EQ W_DOC_YEAR.
IF SY-SUBRC EQ 0.
ENDIF.
THANKS, appreciate your inputs.
Regards,
JunHi Suhas,
I just did a short test just now:
REPORT ZTEST_SELVIEW.
TABLES: WB2_V_MKPF_MSEG2.
TYPES: BEGIN OF Y_MSEG,
MATNR LIKE MSEG-MATNR,
BWART LIKE MSEG-BWART,
MENGE LIKE MSEG-MENGE,
END OF Y_MSEG.
DATA: T_MSEG TYPE STANDARD TABLE OF Y_MSEG.
SELECT MATNR_I
BWART_I
MENGE_I
FROM WB2_V_MKPF_MSEG2
INTO CORRESPONDING FIELDS OF TABLE T_MSEG
WHERE MATNR_I EQ '000000000000004000'
AND WERKS_I EQ '0288'
AND BWART_I EQ '931'
* AND BUDAT EQ '20071117'
AND MJAHR EQ '2007'.
IF SY-SUBRC EQ 0.
ENDIF.
In my debug, T_MSEG contains the same number of rows that my SE16>WB2_V_MKPF_MSEG2(using the hard coded statement in my SQL) "BUT" each rows does not have any entries. Bottomline, I can't only see blank entries in ITAB T_MSEG but the rows are being selected properly, so the itab contains x-number of rows with blank entries.
Thanks.
Maybe you are looking for
-
Crash on search function for HTML Help file (.chm) when connected to a Visual C++ application I use the RH_ShowHelp API command to connect a HTML Help file (.chm file generated by RoboHelp Word X 5) to my Visual C++ application. My application is abl
-
My iPad has a blue screen What's wrong with it
My iPad has a blues screen what's wrong ?
-
Urgent :Check print template not getting attched to the conc program
Oracle apps version : 11.5.10.2 XML Publisher : 5.6.2 Other XML publisher program works fine, but for check print progam rtf template doen not get attached at run time. path: Payables --> Payments --> Once you click on pay , 2 concurrent programs get
-
Hi Can the same pricing procedure be used for standard PO and Service PO? What is the purpose of creating a seperate pricing procedure for service? Regards Soumen
-
Taking a long time to recieve texts
Hi, ive had my iphone 4s for about 2 months now. all been fine until past 2 weeks. im now taking a long time to receive texts. specifically sms messages. imessages seem to work fine. but it can take up to several hours before my sms texts come throug