Question about statement for all entries
Hi Abap experts,
I have a question concerning the ABAP statement for all entries.
Explanations:
Let’s say that my source package (Source table) contains 2 types of data:
-type1
-type2
I would like to use the statement select from table into internal table
For all entries in source package
But the where statement changes depending on the data type (2 keys when data type is 1 and only 1 key when data type is 2) .
So that would be:
Type1:
Select fields
From table into internal table
Where field1 = source_package-field1
And field2 = source_package-field2.
Type2:
Select fields
From table into internal table
Where field1 = source_package-field1
How can I merge them assming that the field od data type is ftype?
Thanks.
Amine
Hi amine,
i think this is helpful for you.
there are 2 ways to use the for all entries...
1. with header line: this method is old one. in this method the internal table (ITAB) is automatically create workarea (WA) with same name, this method 1 drawback is there where we can use WA and ITAB confused that's why this is come difficult.
2. without header line : this is nowadays we can use this method. in this method we create separate ITAb and WA. very clear this method.
EXAMPLES:
1.WITH HEADER LINE METHOD:
PARAMETERS p_kunnr TYPE kna1-kunnr.
DATA:it_kna1 LIKE kna1 OCCURS 0 WITH HEADER LINE,
it_adrc LIKE adrc OCCURS 0 WITH HEADER LINE,
it_adr2 LIKE adr2 OCCURS 0 WITH HEADER LINE,
it_adr6 LIKE adr6 OCCURS 0 WITH HEADER LINE.
START-OF-SELECTION.
SELECT * FROM kna1 INTO TABLE it_kna1
UP TO 100 ROWS.
IF NOT it_kna1[] IS INITIAL.
SELECT * FROM adrc INTO TABLE it_adrc
FOR ALL ENTRIES IN it_kna1
WHERE addrnumber = it_kna1-adrnr.
ENDIF.
IF NOT it_adrc[] IS INITIAL.
SELECT * FROM adr2 INTO TABLE it_adr2
FOR ALL ENTRIES IN it_adrc
WHERE addrnumber = it_adrc-addrnumber.
ENDIF.
IF NOT it_adr2[] IS INITIAL.
SELECT * FROM adr6 INTO TABLE it_adr6
FOR ALL ENTRIES IN it_adr2
WHERE addrnumber = it_adr2-addrnumber.
ENDIF.
LOOP AT it_kna1.
READ TABLE it_adrc WITH KEY addrnumber = it_kna1-adrnr.
IF sy-subrc = 0.
ENDIF.
READ TABLE it_adr2 WITH KEY addrnumber = it_kna1-adrnr.
IF sy-subrc = 0.
ENDIF.
READ TABLE it_adr6 WITH KEY addrnumber = it_kna1-adrnr.
IF sy-subrc = 0.
ENDIF.
WRITE : it_kna1-kunnr, it_kna1-name1, it_adrc-city1, it_adrc-street, it_adrc-po_box_reg,
it_adr2-telnr_long, it_adr6-smtp_addr.
ENDLOOP.
2. WITH OUT HEADER LINE:
TABLES: KNA1 , ADRC.
DATA : IT_KNA1 TYPE STANDARD TABLE OF KNA1,
IT_ADRC TYPE STANDARD TABLE OF ADRC,
WA_KNA1 TYPE KNA1,
WA_ADRC TYPE ADRC.
DATA: BEGIN OF STRTYPE ,
CUSTMERNO LIKE KNA1-KUNNR,
FIRSTNAME LIKE KNA1-NAME1,
LASTNAME TYPE NAME2,
CITY TYPE ORT01,
STATE TYPE REGIO,
COUNTRY TYPE LAND1,
ADDRESS LIKE ADRC-ADDRNUMBER,
END OF STRTYPE.
DATA : IT_1 LIKE TABLE OF STRTYPE.
SELECT-OPTIONS K_kunnr FOR kna1-kunnr NO-EXTENSION.
SELECT * FROM KNA1 INTO TABLE IT_KNA1 WHERE KUNNR IN K_KUNNR.
IF NOT IT_KNA1[] IS INITIAL.
SELECT * FROM ADRC INTO WA_ADRC FOR ALL ENTRIES IN IT_KNA1 WHERE ADDRNUMBER = IT_KNA1-ADRNR.
ENDSELECT.
ENDIF.
LOOP AT IT_KNA1 INTO WA_KNA1.
READ TABLE IT_ADRC INTO WA_ADRC WITH KEY ADDRNUMBER = WA_KNA1-ADRNR.
IF SY-SUBRC = 0.
STRTYPE-ADDRESS = WA_ADRC-ADDRNUMBER.
ENDIF.
APPEND STRTYPE TO IT_1.
WRITE : / WA_KNA1-KUNNR, WA_KNA1-NAME1, WA_KNA1-NAME2, WA_KNA1-ORT01, WA_KNA1-REGIO, WA_KNA1-LAND1, WA_ADRC-ADDRNUMBER.
ENDLOOP.
regards,
roopa.k
Similar Messages
-
Performance Issue in Select Statement (For All Entries)
Hello,
I have a report where i have two select statement
First Select Statement:
Select A B C P Q R
from T1 into Table it_t1
where ....
Internal Table it_t1 is populated with 359801 entries through this select statement.
Second Select Statement:
Select A B C X Y Z
from T2 in it_t2 For All Entries in it_t1
where A eq it_t1-A
and B eq it_t1-B
and C eq it_t1-C
Now Table T2 contains more than 10 lac records and at the end of select statement it_t2 is populated with 844003 but it takes a lot of time (15 -20 min) to execute second select statement.
Can this code be optimized?
Also i have created respective indexes on table T1 and T2 for the fields in Where Condition.
Regards,If you have completed all the steps mentioned by others, in the above thread, and still you are facing issues then,.....
Use a Select within Select.
First Select Statement:
Select A B C P Q R package size 5000
from T1 into Table it_t1
where ....
Second Select Statement:
Select A B C X Y Z
from T2 in it_t2 For All Entries in it_t1
where A eq it_t1-A
and B eq it_t1-B
and C eq it_t1-C
do processing........
endselect
This way, while using for all entries on T2, your it_t1, will have limited number of entries and thus the 2nd select will be faster.
Thanks,
Juwin -
Nested statement "for all entries in"
Hi,
is ist possiple to nest "for all entries in" statements ?
At the moment I have the following SELECT-Statement:
select * from /rtc/tm_inusk
appending table gt_zrtc4inusk
for all entries in lt_trkorrdesti
where trkorr = lt_trkorrdesti-trkorr and
objname in lv_selk_copy.
Sometimes the statement dumps because the range table "lv_selk_copy" is to big.
In another thread I was told to use "for all entries in" instead of a range when the range is to big.
If do so I have to use two "for all entries in" statements in my select. But I think this is not possible.
So any idea ?
Thanks
ArnfriedHi,
Using two for all entries in not possible... Its better that you split up your range into smaller chunks..
or..
select * from /rtc/tm_inusk
appending table gt_zrtc4inusk
for all entries in lt_trkorrdesti
where trkorr = lt_trkorrdesti-trkorr .
Once you have selected delete the records where objname Not in lv_selk_copy. -
SQL- Statement: for all entries, where
Hi all, I have a Statement
SELECT * FROM ltak
INTO TABLE lt_help for all entries in gt_tree
WHERE bdatu = gt_tree-node_key.
It doesnt want to compile, because the field bdatu is not of the same type like my field node_key.
How can I process this statement, or how can I convert it ?
Thanks,
Regards,
HProkoph
Edited by: Rob Burbank on Dec 17, 2009 9:26 AMHello,
This is what you were suggested before
"Add a extra field in the internal table gt_tree
data: begin of gt_tree occurs 0,
bdatu1 like ltak-bdatu,
end of gt_tree.
"before the select statement
loop at gt_tree.
gt_tree-bdatu1 = gt_tree-node_key.
modify gt_tree.
endloop.
SELECT * FROM ltak
INTO TABLE lt_help for all entries in gt_tree
WHERE bdatu = gt_tree-bdatu1.
Vikranth -
Doubt about using for all entries
I have to retrieve 3 columns from 2 tables(MARA and MAKT). How should i device the FOR ALL ENTRIES statement for such a situation??
What i need to retrieve is:
MATNR from MAKT
MAKTG from MAKT
MEINS from MARA.HI
in final internal table you declare what ever you want from that 2 tables
MATNR
MAKTG
MEINS
and 2 more internal tables like this
1st : MATNR
MEINS from MARA
2nd : MATNR
MAKTG from MAKT
write a select query for 1st like this
SELECT MATNR MEINS from mara into itab1 where matnr = p_matnr.
if not itab1[] is initial.
SELECT MATNR MAKTG from MAKT into table itab2 FOR ALL ENTRIES IN itab1 where MATNR in itab1-matnr
endif.
loop at 1st itab1
read on itab2
move fields to final internal table only required fields
<b>reward if usefull</b> -
For all entries in source package merge
Hi experts,
I have one question regarding statement for all entries in source package where …..
Explanations:
Let’s say that my source package contains 2 types of data:
-type1
-type2
I would like to use the statement select from table into internal table
For all entries in source package
But the where statement changes depending on the data type (2 keys when data type is 1 and only 1 key when data type is 2) .
So that would be:
Type1:
Select fields
From table into internal table
Where field1 = source_package-field1
And field2 = source_package-field2.
Type2:
Select fields
From table into internal table
Where field1 = source_package-field1
How can I merge them?
Thanks.
AmineHi Amine,
Didn't try that before but there are some idea for you to reference.
I assume source_packet have a field which indicate the data type which call source_packet-dtype
1) Write SQL like this... (Notes: never try that, not sure if it will work)
Select fields
From table into internal table
Where ( source_packet-dtype = 1 and field1 = source_package-field1 and field2 = source_package-field2 )
OR ( source_packet-dtype = 2 and field1 = source_package-field1 ).
2) Try to split the source_packet into 2 itab, one contain type 1 and another contain type 2 data and then read with 2 sql and merge with appending key word, but this idea assume the record will be difference
Select fields
From table into internal table
Where field1 = itab_type1-field1
And field2 = itab_type1-field2.
Select fields
From table APPENDING internal table
Where field1 = itab_type2-field1
BTW, you may have better luck in the ABAP space.
Regards
Bill
Message was edited by: Chie Bill -
Two questions :
<b>(1) I use join with for all entries: the performance will go down?:</b>
SELECT t1~MBLNR t1~MJAHR ZEILE BUDAT
INTO TABLE gt_mseg
FROM MSEG as T1 INNER JOIN MKPF AS T2
ON T1~MBLNR = T2~MBLNR and
T2~MJAHR = T2~MJAHR
FOR ALL ENTRIES IN gt_coss
WHERE T1~MJAHR = gt_coss-GJAHR AND
T1~AUFNR = gt_coss-aufnr AND
( BWART = '261' OR
BWART = '262' ) AND
T2~BUDAT IN r_budat.
<b>(2) With "For all entries", if itab is too long, performance will go down?. In affirmative case. What can I do?</b>Hi Jose,
You'll have to make sure your global table gt_coss isn't empty.
A nasty little habit of the IN statement (for all entries is a kind of IN statement)
is that when it is empty, the system selekts all records.
You might know this when u use Select-Options in your statement (like r_budat).
Also there is an OSS note on he for all entries (531337) problems on i-series database.
Greetings Fred. -
Hi All,Pre-requisite of using FOR ALL ENTRIES
Hi All,
What are the Pre-requisite of using FOR ALL ENTRIES in the select statement .pls its Urgent .
thanks®ards.
Bharathi,
For using for all entries in below statement for all entries in itab_mara it will retrieve record corresponding fields of table itab_marc.
In this case if we have duplicate records in mara .For that also it will retrieve the value in itab_marc.
select matnr erdat from table itab_mara where matnr in s_matnr.
if not itab_mara is initial.
select matnr werks from table itab_marc for all entries of table itab_mara
where werks in s_werks and
matnr in s_matnr.
Reward with points if helpful. -
Select ... for all entries problem
Hi,
I'm making select statements to BKPF and BSEG, but I can't do an inner join between this two table because BSEG it's a cluster table so I have to do a SELECT... FOR ALL ENTRIES, but in SE16 I make the same query that I have writen in my program as shown below,
SELECT BUKRS BELNR GJAHR BUDAT MONAT
FROM BKPF INTO CORRESPONDING FIELDS OF TABLE it_bkpf
WHERE BUKRS = 'XXX'
AND GJAHR = '2005'
AND BELNR = '0000000250'. "just for proof
AND MONAT = '10'
The above query returns me 1 row in program and in SE16 and then I make the next query for BSEG to do the join
SELECT BUKRS BELNR GJAHR BSCHL SHKZG WRBTR HKONT
FROM BSEG INTO CORRESPONDING FIELDS OF TABLE IT_BSEG
FOR ALL ENTRIES IN it_bkpf
WHERE bukrs = it_bkpf-bukrs
and gjahr = it_bkpf-gjahr
and belnr = it_bkpf-belnr.
this query returns 897 rows and in SE16 this same query returns 901 rows
Why SELECT...FOR ALL ENTRIES brings me less rows affected by the query in SE16
Thanks for your help!!Hi,
Please use the following code for selcting the exact number of rows.
IF it_bkpf[] IS NOT INITIAL.
SELECT *
FROM BSEG INTO CORRESPONDING FIELDS OF TABLE IT_BSEG
FOR ALL ENTRIES IN it_bkpf
WHERE bukrs = it_bkpf-bukrs
and gjahr = it_bkpf-gjahr
and belnr = it_bkpf-belnr.
ENDIF.
Instead of * ,you can specify the exact fields required along with all the key fields as selection fields.Also it is must to check the condition it_bkpf[] IS NOT INITIAL before using the statement FOR ALL ENTRIES IN it_bkpf.Suppose if this condition is not used and if it_bkpf is initial,it will fetch all entries from the table.
Reward if helpful.
Regards,
Aravind -
Select FOR ALL ENTRIES statement cannot get duplicates entries
Hi all,
t_yxapy_fields consist of
inty field
0001 kostl
0002 perid
0008 ansal
0008 preas
0008 trfst
The following is the code for me to transfer the contents of t_yxapy_fields into t_pa_fields.
SELECT dbtab
FROM t777d
INTO TABLE t_pa_fields
FOR ALL ENTRIES IN t_yxapy_fields
WHERE infty = t_yxapy_fields-infty.
And t_pa_fields just ended up with
field infty
pa0001
pa0002
pa0008
Question:The first table have 3 similar infotype 0008 but the result table only have one pa0008. I need to filled up acordingly as what table 1 have. I need another 2 pa0008 in my 2nd table. What is wrng with my Select for all entries statement here?
Edited by: Siong Chao on Mar 27, 2010 10:35 AMThis has nothing to do with duplicates in t777d.
Correct, I failed to recognize that table t777d has only infty as key as pointed out by Aby. Thus in your particular case my comment was misleading. In general though FOR ALL ENTRIES removes all duplicate rows from your result set.
If you want the other 2 values just loop t_yxapy_fields this table and read t_pa_fields and if record found add the other values to t_pa_fields table. --> will trigger performance tuning issue
I'm pretty sure if you'd code this, you won't run into any performance issues, so follow Aby's recipe. To be more concrete, here's what I'd do: Define a mapping table t777d_tab, which holds the translation from infty to dbtab:
types:
begin of T_T777D_VIEW,
INFTY type T777D-INFTY,
DBTAB type T777D-DBTAB,
end of T_T777D_VIEW.
data:
T777D_TAB type hashed table of T_T777D_VIEW with unique key INFTY.
Fill table t_pa_fields, typed using t_t777d_tab from above, from table t777d. Then loop over your table t_yxapy_fields (I'd use [LOOP AT ... ASSIGNING|http://help.sap.com/abapdocu_70/en/ABAPLOOP_AT_ITAB_RESULT.htm] instead of LOOP AT ... INTO) and for each entry get the corresponding DBTAB value from t777d_tab (again use the [READ TABLE ... ASSIGNING|http://help.sap.com/abapdocu_70/en/ABAPREAD_TABLE_OUTDESC.htm] variant) and build your result table t_pa_fields.
Anyhow, I suspect that even with less optimal coding (e.g. using just standard table for lookup of DBTAB values) you'd not see much of an performance impact, because it seems that your internal tables are most likely rather small...
Cheers, harald -
About for all entries in itab usage issue
hi
i will get a lot of material information first.
the next i will get inforamtion about table MARC AND MBEW.
one statement i use sap function to get MARC:
CALL FUNCTION 'MARC_ARRAY_READ'
EXPORTING
KZRFB = ' '
NEUFLAG = ' '
SPERRMODUS = ' '
STD_SPERRMODUS = ' '
EXCEPTION_ON_LOCK = ' '
IMPORTING
RETC = ret
TABLES
IPRE01 = ipre
MARC_TAB = disp
EXCEPTIONS
ENQUEUE_MODE_CHANGED = 1
LOCK_ON_MARC = 2
LOCK_SYSTEM_ERROR = 3
OTHERS = 4.
two statement if i use:
select matnr dispo ekgrp plifz
into table disp
from marc
for all entries in ipre
where werks = ipre-werks and
matnr = ipre-matnr.
which one will get better performce.
and
if ipre table have a lot of data, so in sap what about for all entries of Limit?
and will lose data to use for all entries of statements?
have function in sap to get data like 'MARC_ARRAY_READ' about MEBW.
THANK YOU!thank you!
what about for all entries of Limit?
and will lose data to use for all entries of statements?
exist function about get MEBW ARRAY?? -
Can a JOIN statement be rewritten using FOR ALL ENTRIES in any case ?
I had a SELECT statement, like:
select p~key1 t~col3 t~col4 p~col2 p~col3
into table itab1
from ( table1 as p left outer join table2 as t
on p~key1 = t~key1 and t~col2 = someValue ).
Among which, table1 and table2 are fully buffered.
Code Inspector suggests that this statement should be, e.g., rewritten using FOR ALL ENTRIES.
Since FOR ALL ENTRIES is only possible for WHERE conditions of the SELECT statement, which means the internal table right after it is not available for the RESULT clause of the SELECT statement, can the above statement be rewritten? If yes, how?
Thanks!hi ,
select pkey1 tcol3 tcol4 pcol2 p~col3
into table itab1
from ( table1 as p left outer join table2 as t
on pkey1 = tkey1 and t~col2 = someValue ).
<i>look below code</i>
select * from table2 into table int_tab2 where col2 = someValue.
select key1 col2 col3 into table int_tab1
FOR ALL ENTRIES IN int_tab2
WHERE key = int_tab2-key1.
then use read statements for manipulations
rgds
Anver -
'FOR ALL ENTRIES' in SELECT statements
Hi,
I got a doubt in working of the 'FOR ALL ENTRIES' option in the SELECT statement. Here is my scenarion.
Table A - Document Header Level (Key: Doc Number)
Internal Table B - Document Item level (Keys: Doc num and Doc Item).
So, for each record in Table A, table B will have multiple records.
In this situation, how the below SELECT will work.
SELECT <field names> INTO <some internal table>
FROM A
FOR ALL ENTRIES in B
WHERE doc_num = B-doc_num.
Will the above SELECT result in duplicate records or not?
(I tested it and found that it doesn't! I was lil surprised and wanted to confirm that)
Thanks & Regards,
SreeHi,
For all entries option basically sorts out the entries in the internal tbale based on the where condition and thus it only picks the unique entries based on the list.
so indeed your table A is a header one so it will give you only single value. if you go by the reverse way where in look for B for all entries in A it will give you multiple values as table B has multiple values for each value in A.
Regards,
Jagath -
Problem with FOR ALL ENTRIES statement
Hi all
please find the problem in the select statement.
SELECT vbbe~vbeln
vbap~vstel
marc~dispo
vbbe~matnr
vbbe~kunnr
vbbe~werks
vbbe~mbdat
vbbe~omeng
INTO TABLE l_t_dvbeln
FROM vbbe
INNER JOIN vbak
ON
vbbe~vbeln = vbak~vbeln
inner join vbap
on
vbbe~vbeln = vbap~vbeln and
vbbe~matnr = vbap~matnr
inner join marc
on
vbbe~matnr = marc~matnr and
vbbe~werks = marc~werks
FOR ALL entries IN g_t_stock
WHERE vbbe~matnr = g_t_stock-matnr
AND vbbe~werks = g_t_stock-werks
AND vbak~vkorg = g_t_stock-vkorg
AND vbak~vtweg = g_t_stock-vtweg
AND vbbe~kunnr = g_t_stock-kunnr
AND vbbe~mbdat IN r_mbdat.
g_t_stock is having only one record i.e.,
g_t_stock-vstel = 'DF01'.
g_t_stock-dispo = 'DEI'.
g_t_stock-matnr = '00100833'.
g_t_stock-maktx = 'SAC (300X400)'.
g_t_stock-kunnr = '0000600431'.
g_t_stock-werks = 'PF71'.
g_t_stock-labst = '7727'.
g_t_stock-vkorg = 'SF71'.
g_t_stock-vtweg = 'IC'.
and r_mbdat has the date range as
r_mbdat-sign = I
r_mbdat-option = BT
r_mbdat-low = 15.05.2008
r_mbdat-high = 08.06.2008
In vbak vbap & marc tables i have only one record as per the above selection criteria.
in VBBE table i have 7 records which satisfies the above criteria. But the select staement retrieves only 5 records.
if we remove for all entries and hardcode the values in the select statement then it retrieves all 7 records.
can anybody help me.
what is the reason it is showing only 5 records.Hi all
actually it has to retrieve the following records
VBELN MATNR KUNNR WERKS MBDAT LABST
30001417 00100833 600431 PF71 15.05.2008 20.000
30001417 00100833 600431 PF71 15.05.2008 20.000
30001417 00100833 600431 PF71 22.05.2008 5.000
30001417 00100833 600431 PF71 22.05.2008 7.000
30001417 00100833 600431 PF71 27.05.2008 10.000
30001417 00100833 600431 PF71 27.05.2008 10.000
30001417 00100833 600431 PF71 29.05.2008 10.000
But it is retrieving only 5 records as below
VBELN MATNR KUNNR WERKS MBDAT LABST
30001417 00100833 600431 PF71 15.05.2008 20.000
30001417 00100833 600431 PF71 22.05.2008 5.000
30001417 00100833 600431 PF71 22.05.2008 7.000
30001417 00100833 600431 PF71 27.05.2008 10.000
30001417 00100833 600431 PF71 29.05.2008 10.000
Please give the reason -
Performance issue in 'Selelect statement with for all entries'
Hi,
The following SELECT statement is taking too much time.
SELECT * FROM /rb04/yc5_mver
INTO TABLE g_it_mver
FOR ALL ENTRIES IN l_it_inva
WHERE matnr EQ l_it_inva-matnr AND
werks EQ l_it_inva-werks AND
indei EQ l_it_inva-indei AND
gjahr IN g_r_gjahr.
Internal table l_it_inva is having too many records.
Is there any way to optimize it.
Regards,
TintuHi Tintu,
check table l_it_inva for initial.
sort internal table l_it_inva with key matnr werks indei gjahr.
delete adjacent duplicates from l_it_inva comparing matnr werks indei gjahr.
Then use following select query.
SELECT * FROM /rb04/yc5_mver
INTO TABLE g_it_mver
FOR ALL ENTRIES IN l_it_inva
WHERE matnr EQ l_it_inva-matnr AND
werks EQ l_it_inva-werks AND
indei EQ l_it_inva-indei AND
gjahr IN g_r_gjahr.
Regards,
Vijay
Maybe you are looking for
-
Retention Policy to delete both backup sets and archivelogs automatically
I configured the Recovery Window-Based Retention Policy for my database for the window=14 days. I also set up a crontab to do a full backup every Monday. So say in a month, there will be 30 archive logs and 4 full DB backup sets. Now that I understan
-
I have an iPod touch 4G. I have been trying to skype with my friends with skype 5.0 and I was the only one that could not download it. Then I researched why and it says I need iOS 5.0. I then went back to research how to download it and on here it sa
-
Could someone please point me in the direction of a tutorial or example of how to create and implement a search box into a website. The website is HTML and am hosted on a server which permit php. I am a novice and need a good step by step guide to fo
-
I Mac G5 Intel compatability?
Need to know if I Mac G5 Intel will work with Minolta Dimage scan dual III slide scanner? Thank you Power Mac G4, Quicksilver (2002) Dual Mac OS X (10.4.8) see Biography
-
Can anyone let me know how to integrate javahelp .hs in a jsp?