‎2008 Apr 28 12:02 PM
Hi,
I want to write a query in ABAP language .
There are two tables T1 and T2
T1 has following data: 3 roles
Groupname |
-
ROLE1 |
ROLE2 |
ROLE3 |
T2 has following data
Groupname desc language
ROLE1 e1desc ,EN
ROLE1 d1desc ,DE
ROLE1 s1desc ,SP
ROLE2 e2desc ,EN
ROLE2 d2desc ,DE
ROLE2 s2desc ,SP
ROLE3 e3desc ,EN
ROLE3 s3desc ,SP
Now i want the o/p as
ROLE1 d1desc
ROLE2 d2desc
ROLE3 NULL
ROLE3 NULL
I could write the following sql query:
select distinct T1.groupname ,T2.groupdesc from T1 ,T2 where
T1.groupname = T2.groupname AND T1.groupname NOT IN (
select T2.groupname from T2 where langauge='DE')
UNION
select T1.groupname,T2.groupdesc from T1,T2 where T1.groupname = T2.groupname and langauge='DE'
I want the same to be written in ABAP editor.
Please help
Best Regards
Manoj
‎2008 Apr 28 12:06 PM
select distint afield1 bfield2 b~field3
from tab1 as a left outer join tab2 as b
on afield1 = bfield1
into corresponding fields of table lt_itab
where language = sy-language.
Let me know if this was helpful.
‎2008 Apr 28 12:07 PM
Hi Manoj,
DATA:
itab1 TYPE TABLE OF T1,
itab2 TYPE TABLE OF T2.
SELECT *
FROM T1
INTO TABLE itab1.
SELECT *
FROM T2
INTO TABLE itab2
FOR ALL ENTRIES IN itab1
WHERE role EQ itab1-role
AND lang EQ 'DE'.
or using Join:
SELECT T1~Groupname T2~desc
FROM T1 LEFT OUTER JOIN T2
ON T1~groupname = T2~groupname
AND T2~language EQ 'DE'.
Regards,
Sunil
‎2008 Apr 28 12:09 PM
u can write two diff Queries depending upon ur selection or else write Join
select distint T1field1 T2field2 T2~field3
from table1 as T1 left outer join table2 as T2
on T1field1 = T2field1
(here list all the possible common fields)
into corresponding fields of table lt_itab
where language = sy-language.
Hope this helps u .
‎2008 Apr 28 12:59 PM
Hi all,
Thanks for the reply.
But if you see the table contents the 'ROLE3' is not there in T2 table.
As a result i would loose ROLE3.
My aim is as follows:
a)In a single query ,i shoudl be able to get all the role names in T1 table
b)If i give language as query parameter i shoudl be able to get the dec in that particulra lang from T2.
though 'ROLE3' does not have any description in 'DE' ,i should not loose 'ROLE3'
‎2008 Apr 28 1:51 PM
Sorry if i have not told the problem clearly.
I am writing a BAPI which ABAP code.
The table in which is should collect data is as follows:
AGR_NAME CHAR(30)
SPACE CHAR(1)
TEXT CHAR(80)
I want the code to behave as follows:
=============================
select groupname from t1;
While(Entires in T1 not finished)
{
select desc from T2 where groupname = t<i>.groupname and
language = 'lang'
if(record found)
{
AGR_NAME = t<i>.groupname ;
TEXT = desc
}
else
{
AGR_NAME = t<i>.groupname ;
TEXT = desc ="";
}
}
Now the entire table has to be returned