09-25-2007 7:10 AM
Hi All,
I am bringing the employee details with required selection criteria into an internal master table IT_EMPDETAILS.
Now, I would want to fill the other columns of this internal table, using FOR ALL ENTRIES as below:
SELECT ZRCODE FROM PA9001
INTO CORRESPONDING FIELDS OF TABLE IT_EMPDETAILS
FOR ALL ENTRIES IN IT_EMPDETAILS
WHERE PERNR = IT_EMPDETAILS-PERNR
AND ENDDA = '99991231'.
but while i use this, it is actually clearing the IT_EMPDETAILS instead of filling the column of IT_EMPDETAILS table.
what could be going wrong??
Thanks in advance,
Mohan
09-25-2007 7:21 AM
Hi,
when u go for for all entries then u need to take two different tables.so instead of going for for all entries...u can do like this..
Loop at IT_EMPDETAILS.
select single zrcode FROM PA9001 into v_zrcode
where pernr = it_empdetails-pernr and ENDDA = '99991231'.
it_empdetails-zrcode = v_zrcode.
modify it_empdetails.
clear : it_empdetails.
endloop.
go through the link about for all entries.
http://www.sap-img.com/abap/usage-of-for-all-entries-in-select-statement.htm
Regards,
Nagaraj
09-25-2007 7:26 AM
HI
Normally we use for all entries for two internal tables
it will requires two internaltable fields to compare and fill one internal table
columns....
in this you used the it-empdetails u r clearing all the values but u should use the alias names or other names u can fill by directly
it should be
select zrcode
from pa9001
into corresponding fields of table it_empdetails
where pernr = it_emdetails-pernr
and endda = '99991231'
09-25-2007 7:26 AM
Hi,
Create an internal table IT_EMPDET and store employee details first
and then use
SELECT ZRCODE FROM PA9001
INTO TABLE IT_EMPDETAILS
FOR ALL ENTRIES IN IT_EMPDET
WHERE PERNR = IT_EMPDET-PERNR
AND ENDDA = '99991231'.
Dont use corresponding in select for all entries.
With select for all entries, u can compare one internal table and retrive data from another.
But u can use a single internal table for doing al these things.
Hope this will help u.
Please reward points if helpful.
09-25-2007 7:30 AM
Hi,
INTO will always clear the content of the table and add the contents from the selection criteria.
When you want earlier contents as well as contents from the SELECT you need to use APPENDING , BUT it will not suit your requirement,
Better take the approach suggested by others as get the data in one internal table and then use LOOP.. ENDLOOP.
Regards,
Atish
09-25-2007 7:31 AM
Hi,
you are using for all entries in 1 table to fill the very same table.
now whenever you wite <u><b>into corresponding fields of table</b></u>
the system clears and refreshes the table outomatically. now see you code....
you are refreshing the table on which you are writing the for all entries.
so it would be better if you write some select single and then MODIFY your internal table with that entry
Thnaks
REWARD IF HELPFUL
<u><i><b>vivekanand</b></i></u>
09-25-2007 7:33 AM
Say, there are 1lakh records, would using loop still be effective?
09-25-2007 7:38 AM
Hi,
Yes it can be effective based on the number of fields in the internal table.
Otherwise you can restrict the selection using PACKAGE SIZE.
Regards,
Atish
09-25-2007 7:34 AM
Buddy,
Whenever data selected by select statement is to be stored in an internal table, SAP refreshes the internal table and then stores new data into it. This happens even before the select query is fired, so even if you get no data from select table, SAP does refresh it. So you get an empty table if not data is selected.
In your case, you are trying to select the data in the internal table IT_EMPDETAILS which already has data and is used in for all entries clause. As per above system behaviour, the internal table IT_EMPDETAILS will be refreshed, and then the data thus selected will be stored in IT_EMPDETAILS. So you cannot merge selected data with already existing data.
Use another internal table to store selected data and then run a loop moving the data thus selected over to IT_EMPDETAILS.
<b>Reward if useful.</b>
Regards,
09-25-2007 7:36 AM
For 1 lakh records, the system will take a lot of time to read the data from database table since it will start using sequential read. Please be careful while using for all entries for 100 thousand records.
Regards
09-25-2007 7:37 AM
SELECT ZRCODE FROM PA9001
INTO CORRESPONDING FIELDS OF TABLE IT_EMPDETAILS
FOR ALL ENTRIES IN IT_EMPDETAILS
WHERE PERNR = IT_EMPDETAILS-PERNR
AND ENDDA = '99991231'.
REPLACE WITH
DATA : IT_EMPDETAILS1 LIKE STANDARD TABLE OF IT_EMPDETAILS WITH HEADER LINE.
IT_EMPDETAILS1[] = IT_EMPDETAILS[].
SELECT ZRCODE FROM PA9001
INTO CORRESPONDING FIELDS OF TABLE IT_EMPDETAILS
FOR ALL ENTRIES IN IT_EMPDETAILS1
WHERE PERNR = IT_EMPDETAILS1-PERNR
AND ENDDA = '99991231'.
REWARD IF USEFUL
AMIT SINGLA
09-25-2007 7:37 AM
Hi,
loop.......... end loop can low ur performance,if u don't want loop ....endloop then better create another internal table and make for all entries in that..check the same
Store employee details in the internal table it_emp
if nit it_emp[] is initial.
SELECT ZRCODE FROM PA9001
INTO TABLE IT_EMPDETAILS
FOR ALL ENTRIES IN IT_EMP
WHERE PERNR = IT_EMP-PERNR
AND ENDDA = '99991231'.
endif.
reward points if u find useful
Regards,
Nagaraj
09-25-2007 7:38 AM
USE THIS
DATA : IT_EMPDETAILS1 LIKE STANDARD TABLE OF IT_EMPDETAILS WITH HEADER LINE.
IT_EMPDETAILS1[] = IT_EMPDETAILS[].
SELECT ZRCODE FROM PA9001
INTO CORRESPONDING FIELDS OF TABLE IT_EMPDETAILS
FOR ALL ENTRIES IN IT_EMPDETAILS1
WHERE PERNR = IT_EMPDETAILS1-PERNR
AND ENDDA = '99991231'.
09-25-2007 7:44 AM
Hi
1st of all the order of structure must be the same as ur select query fields
2nd if is there any unnessary fields which your not retriving and used in structure delete that fields from that dtructure
there is no prblem with ur select query
just do the above things and don't use CORRESPONDING FIELDS
<b>Select fields from table into table itab for all entries of itab1
where condition</b>
because last time when i am writing the query by ueing the HR tables i got the same problem
there is no wrong with the select query , then i had deleted extra unwanted fields from structure and i had put the fields in order with corresponding to the select query then the output came sucessfully
<b>reward if usefull</b>
09-25-2007 7:57 AM
Dear All,
Thanks for the amazing replies, yesterday's world cup match is really doing wonders i guess!
To give more insight at what i am looking for and what is done so far:
I tried creating another Internal table and then filled that with only PERNR.
and then using that. tried to fill IT_EMPDETAILS internal table using for all entries,
alas it did not work, and it did not work with APPENDING CORRESPONDING either.
now, coming to using LOOP, if I use loop, I am going run the loop for 1lakh emp(approx..and going high everyday) and modify the internal table for 1lakh records. AND not only that, I am going to loop another 9 tables in similar manner. that is 9lakh loops AND thats not all,
after that I have to again loop the master internal table to loop and fill other employee details like 'text' instead of 'code' from a master table.
This is one of the most query intensive, realtime, online comprehensive employee report that i am making.
Appreciate replies from ABAP performance tuning experts and gurus in advance.
Cheers,
Mohan
10-03-2007 12:23 PM
As, INTO CORRESPONDING FIELDS takes more time,
I used INTO FIELDS..for the tables.