2014 Apr 09 5:02 AM
Hi guys
EMPLOYEE table:
empname empid mangerid
peter 001 003
king 002 003
raju 003 002
how to display empname and his manger name from above table using select statement
thanks
2014 Apr 09 5:20 AM
Hi,
Please refer the link for how to use join.
You need to put join condition on manager and employee table.
Thanks,
Vikrant.
2014 Apr 09 5:27 AM
Hi,
where is the manager name in your table?is there any link of your table with manager name which is another table.give more information
2014 Apr 09 5:33 AM
Hi vishnu,
In empname column manger name is also there like
example peter manager id is 003 and 003 is raju
it should display like for peter manger is raju.
thanks..
2014 Apr 09 5:41 AM
Hello Prasnth,
You can Fetch Employee name directly from the table using select statement.
and for Manager name fetch manager ID for Each Employee and Pass Manager ID as Employee ID In the Same table You will get Manager Name.
for Example ,
EMPLOYEE table:
empname empid mangerid
peter 001 003
king 002 003
raju 003 002
if you want to Print employee 001 then fetch row with Empid 001, you will get Empname as 'peter' then take Manager ID as 003 and again pass to the same table as empid.
then row with Empid 003 will be fetched. and empname of that employee is your manager name
regards,
Pritesh Raut
2014 Apr 09 5:48 AM
Hi Pritesh,
can u please write the select statement for above..
Thanks,
Kiran
2014 Apr 09 5:57 AM
Dear Prasnth,
EMPLOYEE table:
empname empid mangerid
peter 001 003
king 002 003
raju 003 002
for Printing employee details and manager details of Employee with ID '001'
data wa_employee type employee. ""Work Area for Employee to store Manger ID.
Data wa_employee1 type employee. ""Work area for Manger Details.
select * from employee into wa_employee where empid = '001'.
then wa_employee contains = peter 001 003
then
select * from employee into wa_employee1 where empid = wa_employee-mangerid.
so wa_employee1 contain = raju 003 002
wa_employee-empno == 001 ==Employee id
wa_employee-empname == peter == employee name
wa_employee-mangerid == 003 == manger id
wa_employee1-empname == raju == manger name
regards,
Pritesh Raut
2014 Apr 09 5:58 AM
Hi prasnth kumar,
What will be your Input given?
If your input is empid then, and you want to display peter manger is raju, then
data : emp type table-empname.
data : mgnr type table-empname.
data : mgnr_id type table-mangerid
data : gwa type str.
data : git type table of str.
select single * from table into gwa where empid = <input number>.
emp = gwa-empname . -----------> has the employee name
mgnr_id = gwa_mangerid.
select single * from table into gwa where empid = mgnr_id .
mgnr = gwa-empname. -----------> has the manager name
Regards,
Sindhuja
2014 Apr 09 6:01 AM
Hi pritesh,
If you are going you are going to fetch data appending to a Workarea, then you have use SINGLE in your select query, or you can use select...end select.
Regards,
Sindhuja
2014 Apr 09 6:29 AM
Hi pritesh,
your's is correct but i want to get data from only single select statement using subquery concept.
Regards,
Kiran.
2014 Apr 09 6:19 AM
types:begin of t_final,
emp_name type <employee>,
man_name type <manager>,
end of t_final.
data :lt_final type TABLE OF t_final,
l_final TYPE t_final,
l_manager type <manager>.
LOOP AT lt_table INTO wa_table . "this is your table mentioned,make a work area of it too"
READ TABLE lt_table INTO l_manager WITH TABLE KEY empname = wa_table-empname.
l_final-emp_name = wa_table-empname.
l_final-man_name = l_manager.
APPEND l_final to lt_final.
ENDLOOP.
hope it helps...for more help do reply...
2014 Apr 09 6:25 AM
Hi vishnu,
here manger name is not in another table it is in employee table only.
regards,
Kiran
2014 Apr 09 6:42 AM
ya , the code which i have written is where, manager and employee are in the same internal table.if you are fetching from database table then
write
select manid emplid name from <yourdbtable> into lt_final.
this solves ur query.
2014 Apr 09 6:05 PM
EMPLOYEE table:
empname empid mangerid
peter 001 003
king 002 003
raju 003 002
how to display empname and his manger name from above table using select statement
first get the data into a internal table
once the data is already present in your internal table then use read statement inside your loop to display manager name.
loop at it_employee into wa_employee.
read it_employee into wa_employee1 with key empid = wa_employee-managerid.
*** you have employee name in wa_employee and manger name in wa_employee1.
endloop.