Left ouer join with internal table
Good morning to everybody
I need created a internal table with 2 internal table but 1 is primary.
I tried use "left outer join" but it allows only with table and not with internal tabel
I would to be this result
a a xxx
b
c c zzz
d d sss
e
f f ttt
How can i do it?
Thanks a lot for your support
Beste regatrds
Hi,
The following code is for your reference:
data: begin of wa1,
key type c,
end of wa1.
data: begin of wa2,
key type c,
var(3) type c,
end of wa2.
data: begin of wa3,
key1 type c,
key2 type c,
var(3) type c,
end of wa3.
data: itab1 like standard table of wa1,
itab2 like standard table of wa2,
itab3 like standard table of wa3.
wa1-key = 'a'.
append wa1 to itab1.
wa1-key = 'b'.
append wa1 to itab1.
wa1-key = 'c'.
append wa1 to itab1.
wa1-key = 'd'.
append wa1 to itab1.
wa1-key = 'e'.
append wa1 to itab1.
wa1-key = 'f'.
append wa1 to itab1.
clear wa1.
wa2-key = 'a'.
wa2-var = 'zzz'.
append wa2 to itab2.
wa2-key = 'c'.
wa2-var = 'yyy'.
append wa2 to itab2.
wa2-key = 'd'.
wa2-var = 'ttt'.
append wa2 to itab2.
wa2-key = 'f'.
wa2-var = 'sss'.
append wa2 to itab2.
clear wa2.
loop at itab1 into wa1.
read table itab2 into wa2
with key key = wa1-key
binary search.
if sy-subrc = 0.
wa3-key1 = wa1-key.
wa3-key2 = wa2-key.
wa3-var = wa2-var.
append wa3 to itab3.
clear wa3.
else.
append wa1 to itab3.
endif.
endloop.
loop at itab3 into wa3.
write:/ wa3-key1, wa3-key2,wa3-var.
endloop.
Hope it helps.
Regards,
Chris Gu
Similar Messages
-
Case statement resulting into Left outer join with other tables
Hi All ,
I am facing a stuation where a Case statement on one of the logical columns in Answers is resulting into a left outer join with a table in the query.
If we remove the case stmt, the table is not being acessed.
The case stmt is a simple one and no other logical column is being accessed in the case stmt.
Please advice .
Thanks.Hi Sai,
No ..we dont have any left outer join ...its just that I am selecting measure from F1 which has a confimred dimension D1 with F2.Now when I dont have case stmt on measure from F1(Case stmt is something like : CASE WHEN "- P table"."P Column" = 'Y' THEN 'Right' ELSE 'Wrong' END), then it doesnt query F2.
However as soon as I introduce the case stmt ,the query creates a left outer join with F2.
Thanks. -
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?
-
Hello,
i have to join the whole content of a table with the content of a aggregated table. i "moved" the content of the 2 dictionary tables into 2 internal tables and i want to join these 2 internal tables now.
first of all, is it generally possible to join 2 internal tables, for example with a read or loop statement?!
at second, i know how i would solve the problem in oracle 10g, but it looks like that open-sql supports not the same features like orcale. knows anyone of you how i can rebuild the following oracle statement in abap.
select a.id, a.col1, b.col2
from table_a as a, (select id, sum(col2) as col2 from table_c group by id) as b where a.id = b.id order by 1
thxHello Markus
ABAP open sql ahould be something like
select aid acol1 sum( b~col2 )
from table_a as a
join table_c as b
on aid = bid
group by b~id
not sure abour the order by; don't know oracle syntax exactly.
Try!
Regards,
Clemens -
Joining Two Internal Tables - ( Urgent )
Could anybody please give me the whole code for joining two internal tables
and putting the data in a third internal table. Please, very urgent.
Regards,
SAURAVHi,
Refer this code
*& Form SUB_READ_VBRK
text
FORM sub_read_vbrk.
SELECT vbeln
rplnr
bukrs
FROM vbrk
INTO TABLE it_vbrk
WHERE vbeln IN s_vbeln
AND rplnr NE ' '.
IF sy-subrc EQ 0.
SORT it_vbrk BY rplnr.
ENDIF.
ENDFORM. " SUB_READ_VBRK
*& Form SUB_READ_FPLTC
text
FORM sub_read_fpltc.
IF NOT it_vbrk[] IS INITIAL.
SELECT fplnr
fpltr
ccnum
FROM fpltc
INTO TABLE it_fpltc
FOR ALL ENTRIES IN it_vbrk
WHERE fplnr EQ it_vbrk-rplnr
AND ccins EQ 'GIFC'.
IF sy-subrc EQ 0.
SORT it_fpltc BY fplnr.
ENDIF.
ENDIF.
ENDFORM. " SUB_READ_FPLTC
*& Form SUB_COLLECT_DATA
text
FORM sub_collect_data.
*--Local variables
DATA : lv_count(3) TYPE c.
IF NOT it_fpltc[] IS INITIAL.
LOOP AT it_fpltc INTO wa_fpltc.
lv_count = wa_fpltc-fpltr+3(3).
wa_final-ccnum = wa_fpltc-ccnum.
wa_final-rfzei = lv_count.
CLEAR : wa_vbrk.
READ TABLE it_vbrk INTO wa_vbrk WITH KEY rplnr = wa_fpltc-fplnr
BINARY SEARCH.
IF sy-subrc EQ 0.
wa_final-vbeln = wa_vbrk-vbeln.
wa_final-bukrs = wa_vbrk-bukrs.
ENDIF.
APPEND wa_final TO it_final.
CLEAR : wa_vbrk,
wa_fpltc,
lv_count.
ENDLOOP.
ENDIF.
ENDFORM. " SUB_COLLECT_DATA
Regards,
prashant -
I am getting problem with internal table & work area declaration.
I am working with 'makt' table ..with the table makt i need to work with styles attributes ..so i declared like this
TYPES : BEGIN OF ty_makt,
matnr TYPE makt-matnr,
spras TYPE makt-spras,
maktx TYPE makt-maktx,
maktg TYPE makt-maktg,
celltab TYPE lvc_t_styl,
END OF ty_makt.
DATA : i_makt TYPE TABLE OF ty_makt.
DATA : wa_makt TYPE ty_makt .
But end of program i need to update dbtable "makt"...i am getting problem with internal table & work area declaration.
i think makt table fields mapping and internal table/work area mapping is not correct. so please help me to get out from this.Hi Nagasankar,
TYPES : BEGIN OF TY_MATNR,
MATNR TYPE MAKT-MATNR,
SPRAS TYPE MAKT-SPRAS,
MAKTX TYPE MAKT-MAKTX,
MAKTX TYPE MAKT-MAKTG,
CELLTAB TYPE LVC_T_STYL, " Its Working perfectly fine..
END OF TY_MAKT.
DATA: IT_MAKT TYPE STANDARD TABLE OF TY_MAKT,
WA_MAKT TYPE TY_MAKT.
Its working perfectly fine. if still you are facing any issue post your complete code.
Thanks,
Sandeep -
Maximum number of tables that can be outer joined with one table in a query
Hi All,
Iam new to sql, so can you please let me know What is the maximum number of tables that can be outer joined with one table in a query?
Thanks,
Srinisrinu2 wrote:
Iam new to sql, so can you please let me know What is the maximum number of tables that can be outer joined with one table in a query?
There is no limit to the number of tables you can outer join as long as you join them correctly.
SQL> with a as
2 (
3 select 1 id, 2 b_key, 3 c_key from dual union all
4 select 2 id, 1 b_key, 4 c_key from dual union all
5 select 3 id, 3 b_key, 1 c_key from dual union all
6 select 4 id, 4 b_key, 2 c_key from dual
7 ),
8 b as
9 (
10 select 1 id, 1 c_key2 from dual union all
11 select 2 id, 5 c_key2 from dual union all
12 select 3 id, 3 c_key2 from dual union all
13 select 4 id, 2 c_key2 from dual
14 ),
15 c as
16 (
17 select 1 key1, 1 key2, '1-1' dta from dual union all
18 select 1 key1, 2 key2, '1-2' dta from dual union all
19 select 1 key1, 3 key2, '1-3' dta from dual union all
20 select 1 key1, 4 key2, '1-4' dta from dual union all
21 select 2 key1, 1 key2, '2-1' dta from dual union all
22 select 2 key1, 2 key2, '2-2' dta from dual union all
23 select 2 key1, 3 key2, '2-3' dta from dual union all
24 select 2 key1, 4 key2, '2-4' dta from dual union all
25 select 3 key1, 1 key2, '3-1' dta from dual union all
26 select 3 key1, 2 key2, '3-2' dta from dual union all
27 select 3 key1, 3 key2, '3-3' dta from dual union all
28 select 3 key1, 4 key2, '3-4' dta from dual union all
29 select 4 key1, 1 key2, '4-1' dta from dual union all
30 select 4 key1, 2 key2, '4-2' dta from dual union all
31 select 4 key1, 3 key2, '4-3' dta from dual union all
32 select 4 key1, 4 key2, '4-4' dta from dual
33 )
34 select d.a_id, d.b_id, c.key1 as c_key1, c.key2 as c_key3, c.dta
35 from
36 c,
37 (
38 select
39 a.id as a_id, b.id as b_id, a.c_key, b.c_key2
40 from a, b
41 where a.b_key = b.id
42 ) d
43 where d.c_key = c.key1 (+)
44 and d.c_key2 = c.key2 (+);
A_ID B_ID C_KEY1 C_KEY3 DTA
3 3 1 3 1-3
4 4 2 2 2-2
2 1 4 1 4-1
1 2
SQL> -
ANSI Standard Join with Nested Table
Does anyone know how to (or whether you actually can) use ansi standard table joins with nested tables.
Non-ansi standard would look something like this
SELECT e.empno
FROM departments d, TABLE(d.employees) e
WHERE d.deptno = 10;
Where d.employees is a nested table.
But if I try ansi-standard I like such:
SELECT e.empno
FROM departments d
JOIN TABLE(d.employees) e
WHERE d.deptno = 10;
I get
ORA-00905: missing keyword
because I have nothing to join it on.
Your help is very much appreciatedBoth replies worked fine.
I think I will go with the NATURAL JOIN as it seems the cleanest option.
Thanks Guru 2748 -
How to join two internal table rows in alternative manner into one internal table?
How to join two internal table rows in alternative manner into one internal table?
two internal tables are suppose itab1 & itab2 & its data
Header 1
Header 2
Header 3
a
b
c
d
e
f
g
h
i
Header 1
Header 2
Header 3
1
2
3
4
5
6
7
8
9
INTO itab3 data
Header 1
Header 2
Header 3
a
b
c
1
2
3
d
e
f
4
5
6
g
h
i
7
8
9Hi Soubhik,
I have added two additional columns for each internal table.
Table_Count - It represents the Internal Table Number(ITAB1 -> 1, ITAB2 -> 2)
Row_Count - It represents the Row Count Number, increase the row count value 1 by one..
ITAB1:
Header 1
Header 2
Header 3
Table_Count
Row_Count
a
b
c
1
1
d
e
f
1
2
g
h
i
1
3
ITAB2:
Header 1
Header 2
Header 3
Table_Count
Row_Count
1
2
3
2
1
4
5
6
2
2
7
8
9
2
3
Create the Final Internal table as same as the ITAB1/ITAB2 structure.
"Data Declarations
DATA: IT_FINAL LIKE TABLE OF ITAB1. "Final Internal Table
FIELD-SYMBOLS: <FS_TAB1> TYPE TY_TAB1, "TAB1
<FS_TAB2> TYPE TY_TAB2. "TAB2
"Assign the values for the additional two column for ITAB1
LOOP AT ITAB1 ASSIGNING <FS_TAB1>.
<FS_TAB1>-TABLE_COUNT = 1. "Table value same for all row
<FS_TAB1>-ROW_COUNT = SY-TABIX. "Index value
ENDLOOP.
"Assign the values for the additional two column for ITAB2
LOOP AT ITAB2 ASSIGNING <FS_TAB2>.
<FS_TAB2>-TABLE_COUNT = 2. "Table value same for all row
<FS_TAB2>-ROW_COUNT = SY-TABIX. "Index value
ENDLOOP.
"Copy the First Internal Table 'ITAB1' to Final Table
IT_FINAL[] = ITAB1[].
"Copy the Second Internal Table 'ITAB2' to Final Table
APPEND IT
LOOP AT ITAB2 INTO WA_TAB2.
APPEND WA_TAB2 TO IT_FINAL.
ENDLOOP.
"Sort the Internal Table based on TABLE_COUNT & ROW_COUNT
SORT IT_FINAL BY ROW_COUNT TABLE_COUNT.
After sorting, check the output for IT_FINAL Table, you can find the required output as shown above.
Regards
Rajkumar Narasimman -
How to join several internal tables?
Hi,
I have several internal tables. And there is a very complex LOOP to extract data from these internal tables and many other logic inside it. The LOOP is very time-consuming.
I am thinking to join these internal tables into one big internal table, to save some logic inside the complex LOOP. But as I know there is no "join" function for internal tables.
So is there any workaround method to perform a "join" operation on internal tables?
Thanks a lot!Hi,
I have several internal tables. And there is a very complex LOOP to extract data from these internal tables and many other logic inside it. The LOOP is very time-consuming.
I am thinking to join these internal tables into one big internal table, to save some logic inside the complex LOOP. But as I know there is no "join" function for internal tables.
So is there any workaround method to perform a "join" operation on internal tables?
Thanks a lot! -
Avoid duplicates when i join with bridge table
i have a requirement with many to many relations between fact and dimention,that is the reason we have created bridge tables in the database.
if i execute only query on the fact table it is giving correct results.when ever i join with bridge tables it is returning lot of duplicate records.
Ex:
select amount from fact where column = 'xyz'
100
then it is returing one record.(this value is correct)
when ever i join this fact table with bridge table then it is returning duplicate records.
select a.amount from fact inner join bridge table b on a.fk=b.fk
100
100
100
100
100
how many number of fk's associated that many 100's are generating
in this case it is returning duplicate records.
in the RPD i have joined like one to many between fact to dimention.
if anybody face this type of situation please let me know how to resolve this?(FYI...i would have to do this before BM..because lot of other thing are coming into picture on BMM that's why i should have to achieve this in either physical or in database.
Thanks in advance
Edited by: user12077461 on Apr 3, 2011 6:39 PM
Edited by: user12077461 on Apr 17, 2011 4:51 PMI understand what you say but partially.. please explain in more detail how to do that;
How should look the adrese_nezonate block, then? I have to add a 'name' column and set copy value from item property to 'STREETS.NAME', and database_property No?
Then the post-query trigger how should look like (the order by clause)? The post-query sends the entire query (with where/order by clauses) to the server, but in that "select... where... order by" (built dynamically) there are only columns from that block (adrese_nezonate). I need to join with streets, INSIDE that query.
Thanks. -
Join with another table in pre-query
Hi,
We have a large data block and we need to order some columns based on street name for example, not id. The base table of db block contains an id_street column, and 'streets' table contains id and name.
Ok, in pre-query trigger of that block, we have a complex logic and we dynamically build the where clause. At the end, we set the order_By clause of the block, to order the rows, for example we need to order by the 'my_date' column asc (it's a date type column), and street desc; but street NAME, not id. We don't want to use a from clause query, because the dynamically where clause logic it's complex.
How can we join the db block table with 'streets' table in pre-query, so when constructing the order by clause to specify something like
set_block_property('ADRESE_NEZONATE', order_by, 'my_date, name desc');where 'name' is the name of the street, from the 'streets' table.
Is it possible in pre-query, somehow? Or, in my case where can I join with that table and use that column in pre-query at setting order by?
Thanks!
Edited by: Roger25 on 26.04.2013 12:31I understand what you say but partially.. please explain in more detail how to do that;
How should look the adrese_nezonate block, then? I have to add a 'name' column and set copy value from item property to 'STREETS.NAME', and database_property No?
Then the post-query trigger how should look like (the order by clause)? The post-query sends the entire query (with where/order by clauses) to the server, but in that "select... where... order by" (built dynamically) there are only columns from that block (adrese_nezonate). I need to join with streets, INSIDE that query.
Thanks. -
LEFT OUTER with internal tables
hi all,
I have a query to execute,
SELECT SKATSAKNR SKATTXT20
SUM( GLT0~HSLVT ) AS HSLVT
INTO CORRESPONDING FIELDS OF TABLE ITAB_ZSTMGLRACC
FROM SKAT
LEFT OUTER JOIN GLT0 ON GLT0RACCT = SKATSAKNR
AND GLT0~RYEAR = I_GJAHR
AND GLT0~BUKRS = 'comp1'
WHERE SKAT~KTOPL = 'EICA'
GROUP BY SKATSAKNR SKATTXT20.
here i want to replace GLT0~BUKRS = 'comp1' with multiple values from Internal table ITAB_T001
since i used SUM ......FOR ALL ENTRIES IN ITAB_T001 cant be used .
any one have options??
thx
Josehi all,
I have a query to execute,
SELECT SKATSAKNR SKATTXT20
SUM( GLT0~HSLVT ) AS HSLVT
INTO CORRESPONDING FIELDS OF TABLE ITAB_ZSTMGLRACC
FROM SKAT
LEFT OUTER JOIN GLT0 ON GLT0RACCT = SKATSAKNR
AND GLT0~RYEAR = I_GJAHR
AND GLT0~BUKRS = 'comp1'
WHERE SKAT~KTOPL = 'EICA'
GROUP BY SKATSAKNR SKATTXT20.
here i want to replace GLT0~BUKRS = 'comp1' with multiple values from Internal table ITAB_T001
since i used SUM ......FOR ALL ENTRIES IN ITAB_T001 cant be used .
any one have options??
thx
Jose -
Left Outer Join with more than two tables in both CR 8.5 and XIR2
I am trying to create a report and I have tried two versions of Crystal but I ultimately need the report in CR8.5 for compatibility with the client's system. I think I am starting to figure out what might be wrong and it might be my understanding of SQL, but I can't see why someone hasn't needed this in the past. Ultimately I want to see all projects and any journal entry that might be posted for that project.
Database is MySQL 5.0.38 and using MySQL ODBC driver 3.51.19.
Project header table information will be populated. Each line item on a journal entry can be tagged with the project ID. But for me to pull the journal entry date I need also to link to a third table for the journal entry header info.
I want to see all projects, whether a journal entry has been posted or not.
So the links are like this
ProjectHeader --->Left Outer Join ---> JELines ---> Inner Join ---> JEHeader
I think in this scenerio Crystal is treating the LOJ as an IJ.
I created two brand new reports today, one in CR8.5 and one in CR XIR2. Once I edited the automatic CR8.5 SQL statement (which I have been doing for years, usually without problem), they both ran properly. I linked customers to their invoices. Customers without invoices showed properly. But then I linked the invoices to the payments of the invoices and immediately lost customers without orders in both reports.
So apparently only two tables are allowed in Outer Joins. Does this make sense? I checked out the w3schools tutorial on SQL and it doesn't mention this limitation and I can't find anywhere else that it specifically indicates this but all samples of code I have seen only show two tables. I just thought for presentation as a sample that was easiest to understand and we could expand as necessary.
If this is correct, how does one go about accounting for this kind of thing? One solution that goes through my mind is creating a view at the database level for the link between journal entry lines and journal entry headers. Would this be a good solution under normal circumstances?
A second option that I had to implement because of timelines, is to use a subreport linked to the main report through the project ID to pull the information for the journal entries and just pass the totals I need to the main report through a shared variable.
These aren't normal circumstances because I don't have access to the database so I can't create the view. I have come across this concept several times and I have been able to use subreports to solve it but I am trying to find a better solution for the future as sometimes subreports can be slow. So are there any alternatives I have not considered here?
TIA rasincSo after some more work and another post. I was able to get this to work.
Items disappear when linking to another table
My issues were two fold. I was selecting on the tables on the right-side of the original Inner Join. However, I was checking for Nulls. This apparently is correct but you must check for the Nulls first eg. (IsNull (JEHeader.Field1) OR JEHeader.Field1 <= 100). I had my original statement reversed checking for <= 100 before checking for Nulls.
I also did not set all links to be Left Outer Join. I had the Inner Join. I actually have about 6 tables in this report so all the links need to be set Outer Join. So this now seems to be corrected.
Thanks -
OJ syntax for multi-table left outer join with MS Oracle Driver
I have a multi-table left outer join that works fine in SQL Server ODBC Driver, Oracle ODBC driver 8.01.07.00, but not with Microsoft ODBC Driver for Oracle 2.573.7326.0
SELECT * from { oj A LEFT OUTER JOIN B ON A.col1 = B.col1 LEFT OUTER JOIN C ON A.col1 = C.col1 }
I noticed someone had a similar problem (the proposed solution doesn't work):
http://www.justpbinfo.com/listarchive/msg02874.html
Does anyone know how to get this working with the Microsoft ODBC Driver for Oracle? Or does it just not work?The Microsoft ODBC Driver for Oracle 2.573.7326.0 does perform the same 'fix up' with {oj} in Oracle 8i. The problem is that it doesn't work when joining more than two tables:
This works:
SELECT * from { oj A LEFT OUTER JOIN B ON A.col1 = B.col1}
This doesn't work:
SELECT * from { oj A LEFT OUTER JOIN B ON A.col1 = B.col1 LEFT OUTER JOIN C ON B.col1 = C.col1 }
(The second query will work with the Oracle Oracle ODBC driver, with a bit of tweaking. But I haven't found a way to get it to work with the Microsoft ODBC Driver for Oracle 2.573.7326.0. My suspicion is that it just doesn't work.)
Gavin
Maybe you are looking for
-
Can anybody help: I just installed Oracle 10g Release 2 on Windows XP Pro SP2 and receive the following message when starting the Enterprise Manager: DBD Error: OCIServer Attach. Via SQLPlus I can work and the Instance is running. I would appreciate
-
Print fields with multiple lines
We set the field for multiple lines in a pdf form. When entering info, a scroll bar appears so they can enter multiple lines. However, the mutiple lines don't print. If we increase the field height, the scroll displays when info is typed beyond the h
-
Exit for collective search help KRED
Hi all, we have a requirement to enhance collective search help for Vendor in the TransactionsME51, ME52, ME53, ME51N, ME52N, ME53N.Collective search help for vendor is KRED.We need an exit to create extra search help in the collective search help.We
-
Schedule workbooks - results to excel
Hello, I know you can schedule workbooks through discoverer plus. The results from these can be found under File > Open > View: scheduled workbooks. Is there anyway that these can be scheduled with the reults being output to excel? Thank you sarah
-
I have restored my ipad twice and it has still not cleared any space at all what can I do help please