Select fom table for all entries where field starts with value
Hello
I want to write a select like this
select * from bsis
into lt_bsis
for all entries in lt_itab
where xblnr like lt_itab-belnr%
I want to select all the entries from bsis where the field xblnr starts with the values found in lt_itab-belnr.
for example
ls_itab-belnr = 5100000028
bsis-xblnr = 510000002810001
510000002810002
510000002810003
520000002810001
and i want to select only the entries that start with 5100000028 in this case
Can anybody help?
Thanks
Hi,
I hope below example code will help you to fix your issue,
REPORT ytest.
TYPES : BEGIN OF ty_typ1,
val TYPE i,
END OF ty_typ1.
TYPES : BEGIN OF ty_typ2,
val1 TYPE hrobjid,
val2 TYPE hrobjid,
END OF ty_typ2.
DATA : int_typ1 TYPE TABLE OF ty_typ1,
int_typ2 TYPE TABLE OF ty_typ2,
wa_typ1 TYPE ty_typ1,
wa_typ2 TYPE ty_typ2,
int_1001 TYPE TABLE OF hrp1001,
wa_1001 TYPE hrp1001.
REFRESH : int_typ1, int_typ2, int_1001.
CLEAR : wa_typ1, wa_typ2, wa_1001.
wa_typ1-val = 500001.
APPEND wa_typ1 TO int_typ1.
wa_typ1-val = 500002.
APPEND wa_typ1 TO int_typ1.
wa_typ1-val = 500003.
APPEND wa_typ1 TO int_typ1.
wa_typ1-val = 500001.
APPEND wa_typ1 TO int_typ1.
SORT int_typ1 ASCENDING BY val.
DELETE ADJACENT DUPLICATES FROM int_typ1 COMPARING val.
LOOP AT int_typ1 INTO wa_typ1.
wa_typ2-val1 = ( wa_typ1-val * 100 ) + 1.
wa_typ2-val2 = wa_typ2-val1 + 98.
APPEND wa_typ2 TO int_typ2.
CLEAR : wa_typ1, wa_typ2.
ENDLOOP.
SELECT * FROM hrp1001 INTO TABLE int_1001
FOR ALL ENTRIES IN int_typ2 WHERE
plvar EQ '01' AND
otype EQ 'S' AND
sclas EQ 'O' AND
begda LE sy-datum AND
endda GE sy-datum AND
objid GE int_typ2-val1 AND
objid LE int_typ2-val2.
LOOP AT int_1001 INTO wa_1001.
WRITE : / wa_1001-objid.
ENDLOOP.
Thanks & Regards,
Harish Kumar N
Similar Messages
-
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 -
Performance issue with select query and for all entries.
hi,
i have a report to be performance tuned.
the database table has around 20 million entries and 25 fields.
so, the report fetches the distinct values of two fields using one select query.
so, the first select query fetches around 150 entries from the table for 2 fields.
then it applies some logic and eliminates some entries and makes entries around 80-90...
and then it again applies the select query on the same table using for all entries applied on the internal table with 80-90 entries...
in short,
it accesses the same database table twice.
so, i tried to get the database table in internal table and apply the logic on internal table and delete the unwanted entries.. but it gave me memory dump, and it wont take that huge amount of data into abap memory...
is around 80-90 entries too much for using "for all entries"?
the logic that is applied to eliminate the entries from internal table is too long, and hence cannot be converted into where clause to convert it into single select..
i really cant find the way out...
please help.chinmay kulkarni wrote:Chinmay,
Even though you tried to ask the question with detailed explanation, unfortunately it is still not clear.
It is perfectly fine to access the same database twice. If that is working for you, I don't think there is any need to change the logic. As Rob mentioned, 80 or 8000 records is not a problem in "for all entries" clause.
>
> so, i tried to get the database table in internal table and apply the logic on internal table and delete the unwanted entries.. but it gave me memory dump, and it wont take that huge amount of data into abap memory...
>
It is not clear what you tried to do here. Did you try to bring all 20 million records into an internal table? That will certainly cause the program to short dump with memory shortage.
> the logic that is applied to eliminate the entries from internal table is too long, and hence cannot be converted into where clause to convert it into single select..
>
That is fine. Actually, it is better (performance wise) to do much of the work in ABAP than writing a complex WHERE clause that might bog down the database. -
For all entries Where condition character length partilally has to be used
Hi,
I need to fetch all the data reocrds of one internal table into the other with the condition that in one of the field of first internal table only partial length of the character has to be used as a where condition.
Example:
Select xxxx
yyyyy
zzzzz
into it_tab2
for all entries in itab1
where field2 = itab1-field1(4).
where field1 of itab1 has length of 8 and field2 belongs to itab2.
As it throws the error msg :
it will ignore the length restriction mentioned in where condition of the for all entriesHi.
If you are trying to fetch from any database table based on your modified table use this logic.
Dfine another internal table same as itab1, with field one lenght as 4 char.
ex:
data: begin of it_tab2.
field1(4),
end of it_tab2.
loop at it_tab1.
it_tab2 = itab1+0(4).
append it_tab2.
clear it_tab2.
endloop.
now you can fetch from database table....using it_tab2.
Select xxxx
yyyyy
zzzzz
into it_tab3
for all entries in itab2
where field2 = itab2-field1(4).
If you only want to move the entries form one internal table to another internal table and truncate the field1 of itab1.
then no need to use any for all entries...
apply this logic
data: begin of it_tab2.
field1(4),
end of it_tab2.
loop at it_tab1.
it_tab2 = itab1+0(4).
append it_tab2.
clear it_tab2.
endloop.
Regards,
Satish -
Facin problems in the 'Select... for all entries'
I am facing problem with this piece of code, please share ur thoughts on it. I have specified the inputs.
I am extracting the open items from the BSIS table for specified 3 account number.
Inputs to the prg:
field No. of values
r_bukrs 1
r_hkont 2
r_blart 6
r_budat date range of 1 yr
r_bldat nil
v_tosdef contain 1 account number
" In each FI document posted, one line will have the 'v_tosdef' account number and one account from the 'r_hkont' values."
So will this query efficient.
SELECT bukrs
hkont
gjahr
belnr
budat
bldat
xblnr
blart
shkzg
dmbtr
FROM bsis
INTO TABLE i_bsis
WHERE bukrs IN r_bukrs " Company code
AND hkont = v_tosdef " Account number
AND budat IN r_budat " Posting date
AND bldat IN r_bldat " Document date
AND blart IN r_blart. " Document type
IF sy-subrc <> 0.
MESSAGE i003.
STOP.
ENDIF.
*@ Collecting the BELNR & GJAHR From the extracted records
li_bsis[] = i_bsis[].
SORT li_bsis BY bukrs gjahr belnr.
DELETE ADJACENT
DUPLICATES FROM li_bsis
COMPARING bukrs gjahr belnr.
IF NOT li_bsis[] IS INITIAL.
SELECT bukrs
hkont
gjahr
belnr
budat
bldat
xblnr
blart
shkzg
dmbtr
FROM bsis
APPENDING TABLE i_bsis
FOR ALL ENTRIES IN li_bsis
WHERE bukrs = li_bsis-bukrs " Company code
AND hkont IN r_hkont " Account number
AND gjahr = li_bsis-gjahr " Fiscal year
AND belnr = li_bsis-belnr. " Document num
BSIS table size around 86GB
primary index size aroung 33GB
and the index quality is 54%
the CBO shows less cost, but the actual runs takes too much disk read's / bgets..
Message was edited by:
SandyHi Sandy,
You indicated the size of the tables and index, what is the total number of records in your BSIS?
In your range tables, make sure they are postive formed.
Ex. r_bukrs : I EQ '1001', and not I NE '1000'.
You should consider coding your statements to check for input for bldat, code it with r_bldat and then another set without. It should be better performance to not have empty where conditions. So two routines, Selects with bldat and without.
Don't know if you have a Basis person to help analyze the performance, but you should look at the indexes in BSIS. You may have several indexes that contain some of your input fields but they may be spread across several indexes or there may be none. But say you have 5 indexes and it happens that just one of your parameters are in each of those indexes. Well, it can only use one index so while you think you are providing alot of parameters to help performance only one field is being used to access the index. What you need to do then is to find an index that has the most fields in your where clause and see if you can add to that, so long it's not an SAP index. If it's a z index consider adding additional fields to it, or consider creating a new index.
You can at least analyze the first Select in your DEV client. Run a trace, ST05 and then execute your code. It will show you which index it has used if any.
Also, look at the query values it is passing to the database. You said you get 6 M records on the first Select. This just seem like a lot of records, which is for just one account number (v_tosdef) along with the other parameters. I'm wondering if there's a problem with your input data. With 6M in your first table, your FOR ALL ENTRIES statement will be executed 1.2 million times. Tyically the database interface breaks down your Select-For All entries statement into 5 records per query. Again, run ST05 and you will see this.
In SE16, on your BSIS table, what is your count of records if you enter only the account number?
As a test, you might want to try entering all your parameters in SE16, run ST05 to trace the SQL to see what it is doing. You may have to kill your SE16 session or it may time out on you. You can stop your ST05 trace before your SE16 finishes and it will still show how SAP is going after the data and what index it used.
Let me know if this helped any.
Regards,
Filler -
Select query like For all Entries
Hi,
I have a requirement like:
I need to extract data (BKTXT) from table BKPF based on some criteria, into one internal table and I need to query on REGUP table for the above data, the selection criteria on REGUP as follows:
BKTXT(Document Header Text with 25 Char) is a combination of DATE and character string.
Ex: bkpf-bktxt = 20060710-PL02 (YYYYMMDD)
it is like LAUFD + LAUFI (of table REGUP)
i.e: LAUFD (REGUP) = 07/10/2006 (MM/DD/YYYY) and LAUFI(REGUP) = PL02
here I am thinking to use a select query on REGUP using FOR ALL ENTRIES of table i_bkpf..
How can I change the date format YYYYMMDD to MM/DD/YYYY for my requirement?
(( Run-on Date (REGUP-LAUFD) = the first 8 characters in the Document Header Text (BKPF- BKTXT) in MM/DD/YYYY date format (e.g. 07/10/2006)
Run ID (REGUP-LAUFI) = the 10th character through the 15th character in the Document Header Text (BKPF- BKTXT)It is not possible to do in the way you are thinking of doing. "For all entries" requires you to have the itab table field and the database table field to have the same type and length. So something like below <u>will not work</u>.
TABLES: regup.
DATA: BEGIN OF itab OCCURS 0,
text LIKE bkpf-bktxt.
DATA: END OF itab.
DATA: BEGIN OF itab_regup OCCURS 0.
INCLUDE STRUCTURE regup.
DATA: END OF itab_regup.
SELECT * INTO TABLE itab_regup
FROM regup FOR ALL ENTRIES IN itab
WHERE laufd = itab-text+0(8).
If you run this code, you will get an error as follows:
<i>"When using the addition "FOR ALL ENTRIES IN itab", the fields "LAUFD" and "ITAB-TEXT+0(8)" must have the same type and length."</i> -
Advice required on a select statement using "FOR ALL ENTRIES"
Hi,
this is really intresting ...
I have a small requirement where in i have to find out
the valid entries in my internal table (T_MATNR) by using a select statement to a check table (MARA) which has all the fields present in the internal table T_MATNR.
Select statement is
SELECT MATNR
MTART
from MARA
for all entries in T_MATNR
into table T_MATNR
where matnr eq T_MATNR-MATNR.
If you observe the itab in the option 'FOR ALL ENTRIES' and the destination table is the same. I want to know whether this is correct? will it cause any performance issue? right now this statement is working fine for me.Hi,
U have to use
SELECT MATNR
MTART
from MARA
<b>into table I_MATNR(different table)</b>
for all entries in T_MATNR
where matnr eq T_MATNR-MATNR.
If u r specifying both same table name then for what entries it will retrieve, if u have alreay selected some entries and appending u can use
SELECT MATNR
MTART
from MARA
<b>into table T_MATNR</b>where matnr eq T_MATNR-MATNR.
then
SELECT MATNR
MTART
from MARA
<b>appending table T_MATNR</b>
for all entries in T_MATNR
where matnr eq T_MATNR-MATNR.
In this way u can do.
Hope u got it. -
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 -
Select... for all entries in...
Hi,
Can anybody help me to sort out this issue. This select should work. I m filling an itab with distinct pernr. in temp it should give <b>all the records for which pernr should not be in itab.</b>
report ZTEST4.
data : begin of ITAB occurs 0,
PERNR like PA0001-PERNR,
ename like pa0001-ename,
end of ITAB.
data : temp like itab occurs 0 with header line.
clear : ITAB, TEMP.
refresh : ITAB,TEMP.
select distinct PERNR into table ITAB from PA0001 where PERNR le 10.
select PERNR ENAME into table TEMP from PA0001
for all entries in ITAB where pernr not in itab-pernr.
sort TEMP by PERNR.
break-point.Hi Sagar,
If i understand it well, you exclude all PERNR LE 10.
But first things first.
You cannot use the FOR ALL ENTRIES in your case (it doesn't allow the operator "NOT IN").
Your code should be:
REPORT ztest4.
TYPES: BEGIN OF ty_itab,
pernr TYPE persno,
ename TYPE emnam,
END OF ty_itab.
DATA : itab TYPE ty_itab occurs 0,
wtab TYPE ty_itab.
CLEAR: itab,
wtab.
SELECT pernr ename
INTO TABLE itab
FROM pa0001
WHERE pernr LE 10
ORDER BY pernr.
IF sy-subrc EQ 0.
DELETE ADJACENT DUPLICATES FROM itab COMPARING pernr.
ENDIF.
Regards,
Rob. -
Select statment using FOR ALL ENTRIES not allow to do sum,
Hi All,
SELECT DELIV_NUMB
SUM( GRS_WGT_DL )
UNIT_OF_WT
FROM /BIC/AGSSD000600
INTO TABLE I_GROSS
FOR ALL ENTRIES IN I_LAYTWO
WHERE DELIV_NUMB = I_LAYTWO-DELIV_NUMB
GROUP BY DELIV_NUMB UNIT_OF_WT.
While compiling it shows the error
The addition "FOR ALL ENTRIES" excludes all aggregate functions with
the exception of "COUNT( * )", as the single element of the SELECT
clause.
Please give some solution to do sum
with regards,
Thambe .You could just select all entries into an internal table and then loop through and use COLLECT or similar to get your sum values.
Gareth. -
Join Internal Table for all entries
Hi,
I have put the LIKP data in the internal table and then use the for all entries statement to join the table with LIPS. Besides, i specifiy an additional condition to filter empty batch.
But, i found that the empty batch record still exist in the result. Any idea??
SELECT *
FROM LIPS INTO TABLE I_DELIVERY_INFO
FOR ALL ENTRIES IN I_DELIVERY
WHERE
VBELN = I_DELIVERY-VBELN.
AND
CHARG IS NOT NULL.
Regards,
KitHi Kit,
If you are using LIKP and LIPS then you can directly join them since these tables are HEADER & ITEM table.
regd ur query you can use CHARG NE ' '.
Regards
Gopi -
Select SUM in FOR ALL ENTRIES Select Query
Hi ,
I am using for all entries select statment ,can any one guide me how can i use SUM in the select statment with for all entries .
Regards,
VeeraHi,
THis is not possible using for all entries.
Thanks,
Sriram Ponna. -
Just one sentence: How can i write a routine to fill an infoObject with value "X", for the max value key_id X_IDij of every foreign key Y_ID_i.
> More explanation------>
I have such data rows in cube with main keys Xi and foreign keys Yi, characteristic Ci
row1: X1 Y1 C1
row2: X2 Y1 C2
row3: X3 Y1 C3
row4: X4 Y2 C4
row5: X5 Y2 C5
row6: X6 Y2 C6
row7: X7 Y3 C7
row8: X8 Y3 C8
row9: X9 Y3 C9
I want to display in the query for every foreign key Yi the once row with max Xi: Max from (X1, X2, X3); Max from (X4, X5, X6)..
Those rows that will be displayed in query are row3, row6 and row9 because by Y1, X3 is the maximal value, for Y2 is X6 and for Y3 is X9.
How can i select those row in the query. So that, only one row (with max X) is diplayed for every foreign key.
Thanks for helping.
Arnaud
Edited by: Arnaud on Aug 18, 2009 7:00 AM
Edited by: Arnaud on Aug 18, 2009 1:17 PM
Edited by: Arnaud on Aug 27, 2009 9:45 AMHi Arnaud,
You can use the below code in your start routine -
DATA : IT_TAB TYPE DATA_PACKAGE OCCURS 0.
IT_TAB[] = DATA_PACKAGE[].
SORT IT_TAB BY Y DESCENDING X.
DELETE ADJACENT DUPLICATES FROM IT_TAB COMPARING Y X.
LOOP AT DATA_PACKAGE.
READ TABLE IT_TAB WITH KEY X=DATA_PACKAGE-X
Y=DATA_PACKAGE-Y
Z=DATA_PACKAGE-Z
BINARY SEARCH.
IF SY-SUBRC EQ 0.
DATA_SOURCE-FLAG = 'X'.
MODIFY DATA_SOURCE.
ENDIF.
ENDLOOP.
Here we are assuming that your data package contains the additional field FLAG.
Regards,
Saurabh -
Needed selection screen validation for all entries in the range
Hi all,
I'm using the below code for Material validation in selection-screen.
SELECT SINGLE MATNR FROM MARC INTO MARC-MATNR
WHERE MATNR IN S_MATNR.
IF sy-subrc NE 0.
MESSAGE e000(su) WITH text-035. "Invalid Material Number
ENDIF.
This validation is working only for one record in the range.
If I give multiple material numbers in the range having a record which doesn't exist in MARC, its not throwing the error.
Seems like loop should be placed at s_matnr. Is that correct procedure or any pointers on the same would be of great help.
Regards,
Vamsee Priya.Hi priya
Use this way,
REFRESH IT_LIPS. CLEAR IT_LIPS.
SELECT VBELN
POSNR
MATNR
WERKS
LFIMG
ARKTX
VGBEL
VGPOS
BWART
FROM LIPS INTO TABLE IT_LIPS
WHERE PSTYV IN
('ZZTC', 'ZTAD', 'ZMVN', 'ZCVA', 'ZCVB', 'ZCVC') AND "ASR 18721
WERKS IN ('1140', '1143', '1149').
IF IT_LIPS[] IS INITIAL.
MESSAGE E000 WITH TEXT-005.
endif.
revert back if you need any help..
Help us to help you, Manas -
Populating Empty Fields for Existing Internal Table Using For All Entries
I have an internal table called itab_extract that populates without any issues in SELECT A and SELECT B below. Trying to avoid looping, I am using select DB table 'for all entries' in itab_extract. I want the empty fields in itab_extract to populate from the values in the database. However, about 200,000 entries are being appended to the table, and, the values that existed for the already populated fields in itab_extract are gone, and the new fields are populated.
I've played with the syntax and cannot seem to get it to work. My next option is a time consuming loop.
How should the for all entries syntax look to accomplish filling the empty fields in the itab? Thank-You
*read ekko
select ebeln lifnr aedat bsart from ekko *SELECT A*
into CORRESPONDING FIELDS OF TABLE me->itab_extract
where aedat in r_aedat.
select ebeln lifnr aedat BSART from ekko *SELECT B*
appending CORRESPONDING FIELDS OF TABLE me->itab_extract
where aedat in S_DATE2 AND
BSART IN S_BSART.
select ebelp werks matnr *SELECT C*
into CORRESPONDING FIELDS OF TABLE itab_extract
from ekpo
FOR ALL ENTRIES IN itab_extract
where ebeln = itab_extract-ebeln.Hi Tom,
This SQL statement will be time consuming, Do not use a loop.
There are two options.
1. Select EKKO and EKPO details based on standard SAP view. (You can type EKKO in se11 view to find the correct view).
also use one range table populate r_aedat and s_date2 in the same. So you where condition will have r_newrange and
s_bsart. Also do not use into corresponding fields, it is not a good idea. It will increase your performance. Maintain the proper
sequence (Based on database structure of EKKO and EKPO)
2. If you are keen to use for all entries, then first select ekko then after your sy-subrc check get the data from EKPO.
Should be like this.
select ebeln bsart aedat lifnr from ekko into table gt_ekko where aedat in r_newrange and bsart in s_bsart.
if sy-subrc eq 0.
sort gt_ekko by ebeln ascending.
select ebeln ebelp werks matnr into table gt_ekpo for all entries in gt_ekko where ebeln eq gt_ekko-ebeln.
endif.
Hope it helps,
Best Regards,
Tapodipta Khan.
Maybe you are looking for
-
Hello, I created a data text variable user exit. everyting works fine, but, 1) Selection options: Year: 2010 Month: 1 to 11 The query and text variable return right values Year 2010 Month: Jan to Nov but, if i want to make new selection 2) Year : 201
-
Cant find iphoto..
i tried putting some picture on my computer today and i could not find iphoto..some how got deleted off my computer..my computer came with 2 cds.would i need to use those to have i photo back?
-
Tables headers shown Blank when merged for some cases
Hello, i was looking for an answer for this but couldnt find anything related. I am working with SAP Business Objects Enterprise XI product 12.1.0. The problem im having is that when working with tables and 2 rows of headers in order to have two titl
-
ABAP Queary Or SAP Queary Doc/ How to Create Tcode for ABAP queary report
Hi All, Please send the documentation on ABAP Queary. How to create transaction code Report developed using ABAP Queary. Regards sudheer
-
How do I get Adobe Acrobat Pro from a Windows to a Mac?
My windows computer crashed. I had purchased Adobe Acrobat Pro on my Windows laptop. Is there anyway I can get it transferred over to a Mac computer. It is Adobe Acrobat Pro version 11.