Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

data from employee table

Former Member
0 Likes
2,432

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

13 REPLIES 13
Read only

vikrant_mohite
Active Contributor
0 Likes
2,280

Hi,

Please refer the link for how to use join.

ABAP Keyword Documentation

You need to put join condition on manager and employee table.

Thanks,

Vikrant.

Read only

Former Member
0 Likes
2,280

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

Read only

0 Likes
2,280

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..

Read only

Former Member
0 Likes
2,280

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

Read only

0 Likes
2,280

Hi Pritesh,

can u please write the select statement for above..

Thanks,

Kiran

Read only

0 Likes
2,280

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

Read only

0 Likes
2,280

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

Read only

0 Likes
2,280

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

Read only

0 Likes
2,280

Hi pritesh,

your's is correct but i want to get data from only single select statement using subquery concept.

Regards,

Kiran.

Read only

Former Member
0 Likes
2,280

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...

Read only

0 Likes
2,280

Hi  vishnu,

here manger name is not in another table it is in employee table only.

regards,

Kiran

Read only

0 Likes
2,280

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.

Read only

Former Member
0 Likes
2,280

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.