07-19-2014 11:35 AM
REPORT Z_EMPL_PERSONAL.
TABLES : zemployees , zpersonal_detail.
TYPES: BEGIN OF ty_details1,
employee TYPE zemployees-employee,
title TYPE zemployees-title,
forename TYPE zemployees-forename,
surname TYPE zemployees-surname,
gender TYPE zemployees-gender,
salary TYPE zemployees-salary,
END OF ty_details1,
BEGIN OF ty_details2,
employee TYPE zemployees-employee,
address2 TYPE zpersonal_detail-address2,
address3 TYPE zpersonal_detail-address3,
email TYPE zpersonal_detail-email,
contact TYPE zpersonal_detail-contact,
END OF ty_details2,
BEGIN OF ty_details3,
employee TYPE zemployees-employee,
title TYPE zemployees-title,
forename TYPE zemployees-forename,
surname TYPE zemployees-surname,
gender TYPE zemployees-gender,
salary TYPE zemployees-salary,
address2 TYPE zpersonal_detail-address2,
address3 TYPE zpersonal_detail-address3,
email TYPE zpersonal_detail-email,
contact TYPE zpersonal_detail-contact,
END OF ty_details3.
DATA: it_details1 TYPE TABLE OF ty_details1,
wa_details1 TYPE ty_details1,
it_details2 TYPE TABLE OF ty_details2,
wa_details2 TYPE ty_details2,
it_details3 TYPE TABLE OF ty_details3,
wa_details3 TYPE ty_details3.
SELECT-OPTIONS s_Emplye for zemployees-employee.
IF sy-subrc = 0.
SELECT employee title forename surname gender salary
from zemployees
into corresponding fields of it_details1
where zemployees-employee in s_Emplye.
select employee address2 address3 email contact
from zpersonal_detail
into corresponding fields of it_details2
FOR ALL ENTRIES IN it_details1
WHERE employee = zemployees-employee.
ENDIF.
LOOP AT it_details1 INTO wa_details1.
READ TABLE it_details2 into wa_details2 with KEY employee = wa_details1-employee.
IF sy-subrc = 0.
MOVE wa_details2-employee to wa_details3-employee .
MOVE wa_details2-address2 to wa_details3-address2.
MOVE wa_details2-address3 to wa_details3-address3.
MOVE wa_details2-email to wa_details3-email.
MOVE wa_details2-contact to wa_details3-contact.
ENDIF.
move wa_details1-title to wa_details3-title.
move wa_details1-forename to wa_details3-forename.
move wa_details1-surname to wa_details3-surname.
move wa_details1-gender to wa_details3-gender.
move wa_details1-salary to wa_details3-salary.
append wa_details3 to it_details3.
ENDLOOP.
LOOP AT it_details3 to wa_details3.
write: / wa_details2-employee,
wa_details3-title,
wa_details3-forename,
wa_details3-surname,
wa_details3-gender,
wa_details3-salary,
wa_details3-address2,
wa_details3-address3,
wa_details3-email,
wa_details3-contact.
ENDLOOP.
this program gives errors on select statement ( " You cannot use an internal table as a work area" )
07-19-2014 11:48 AM
Hi Yash,
Change the Syntex in the last loop.
LOOP AT it_details3 into wa_details3.
write: / wa_details3-employee,
wa_details3-title,
wa_details3-forename,
wa_details3-surname,
wa_details3-gender,
wa_details3-salary,
wa_details3-address2,
wa_details3-address3,
wa_details3-email,
wa_details3-contact.
ENDLOOP.
Regards,
Venkat.
07-19-2014 11:54 AM
hi , venkat
error occures over here
SELECT employee title forename surname gender salary
from zemployees
into corresponding fields of it_details1
where zemployees-employee in s_Emplye.
regards.
07-20-2014 10:59 AM
Hi Yash,
Change your code for this one:
SELECT employee title forename surname gender salary
from zemployees
into corresponding fields of TABLE it_details1
where zemployees-employee in s_Emplye.
select employee address2 address3 email contact
from zpersonal_detail
into corresponding fields of TABLE it_details2
FOR ALL ENTRIES IN it_details1
WHERE employee = zemployees-employee.
Best regards.
07-19-2014 11:57 AM
Hi Yash,
U have forgot to add word Table in both Select Query
into corresponding fields of table
Regards:
Somendra
07-19-2014 12:02 PM
07-19-2014 12:12 PM
Hello Abaper,
you can not use a workarea as table so this error comes.
before table name use table key word.
As in work area it hold only record at a time but as per select query more than one record should hold.
hope this help you
07-20-2014 7:15 PM
Hi Shah,
Replace your code like this.
Understand you are using For all entries for fetching the respective details from second table not any details.
SELECT employee title forename surname gender salary
from zemployees
into corresponding fields of table it_details1
where zemployees-employee in s_Emplye.
If you are using For all entries ensure sy-Subrc check.
If sy-surc eq 0.
select employee address2 address3 email contact
from zpersonal_detail
into corresponding fields of table it_details2
FOR ALL ENTRIES IN it_details1
WHERE employee = zemployees-employee it_details1-employee.
Endif.
Tip --> you can for inner joins as it can joins two tables in single select.Remember to add table in front of internal tables so that it can accommodate more values.
If you specifically want only first record use Select single and pass it to work area in your select query.
Hope it will make it clear for you.
Regards,
Kannan
07-20-2014 7:31 PM
SELECT */<f1>, <f2>....... FROM <DBTABLE> INTO COREESPONDING FIELDS OF
TABLE it_details1/it_details2/it_details3.....
is the correct syntax.
07-20-2014 7:39 PM
Hi Ranjana,
Seems like you addressed the wrong person.
Regards,
Kannan
07-20-2014 8:07 PM
07-20-2014 8:09 PM
Select * FROM <DBTABLE> INTO CORRESPONDING FIELD OF TABLE it_details1....
is the correct syntax.
07-21-2014 11:04 AM