05-01-2006 7:09 AM
Hi All
a lines from certification books
"For all entries works with the database in a quantity oriented manner. Initially, all data is collected in an internal table.
You must evaluate the value of sy-subrc after each select statement. If the result of the first array fetch returns no data, the following select statement will retrieve all entries from the databse."
plz tell me why we need to check value of sy-subrc if we are using for all entries??
whatz an array fetch??
Thanks
05-01-2006 7:16 AM
an array fetch is way of populating a table in one hit...i.e. it gets geneated via 'select into table'.
What the gobbledegook you have quoted is trying to warn you about is: if the table you are specifying in the 'for all entries' clause is itself empty, then all entries from the database will be considered. If you didn't know this you might think that NO ENTRIES at all would be returned if your 'for all entries' table was empty. BUT THAT IS NOT THE CASE.
05-01-2006 7:17 AM
Hai Rashmi
check with this
The return code value is set as follows:
SY-SUBRC = 0 At least one line was read.
SY_SUBRC = 4 No lines were read.
SY-SUBRC = 8 The search key was not fully qualified.
(nur bei SELECT SINGLE ). The returned single record is any line of the solution set.
************************************************************************
Table Declaration *
************************************************************************
TABLES: mara,
marc,
mard.
************************************************************************
Types Declaration *
************************************************************************
TYPES: BEGIN OF typ_mara,
matnr TYPE mara-matnr, "Material Number"
mbrsh TYPE mara-mbrsh, "Industrial Sector"
mtart TYPE mara-mtart, "Material Type"
meins TYPE mara-meins, "Base Unit of Measure"
END OF typ_mara.
TYPES: BEGIN OF typ_makt,
matnr TYPE makt-matnr, "Material Number"
maktx TYPE makt-maktx, "Material Description"
END OF typ_makt.
************************************************************************
Intrnal tables Declaration *
************************************************************************
DATA: it_mara TYPE STANDARD TABLE OF typ_mara WITH HEADER LINE.
DATA: it_makt TYPE STANDARD TABLE OF typ_makt WITH HEADER LINE.
************************************************************************
Variable Declaration *
************************************************************************
DATA: v_count TYPE i.
************************************************************************
Selection Screen *
************************************************************************
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_matnr FOR mara-matnr.
************************************************************************
START-OF-SELECTION.
***
SELECT matnr
mbrsh
mtart
meins
INTO TABLE it_mara
FROM mara
WHERE matnr IN s_matnr and
mtart = p_mtart.
if sy-subrc = 0.
sort it_mara by matnr.
else.
MESSAGE e001 WITH 'No data Found' ' For the Given'
'Selection Criteria'(400).
endif.
IF NOT it_mara[] IS INITIAL.
SELECT matnr
maktx
INTO TABLE it_makt FROM makt
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-matnr
AND spras = sy-langu.
if sy-subrc = 0.
sort it_makt by matnr.
endif.
ENDIF.
DATA: a TYPE i.
loop at it_mara.
a = sy-tabix MOD 2.
IF a = 1.
FORMAT COLOR 5.
ELSE.
FORMAT COLOR OFF.
ENDIF.
read table it_makt with key matnr = it_mara-matnr
binary search.
if sy-subrc = 0.
WRITE:/ sy-vline.
WRITE: 2 it_mara-matnr,
18 sy-vline, it_mara-mbrsh,
38 sy-vline, it_mara-mtart,
54 sy-vline, it_mara-meins,
78 sy-vline, it_makt-maktx,
155 sy-vline.
clear : it_mara.
endif.
clear : it_makt.
endloop.
WRITE: /(155) sy-uline.
Thanks & regards
Sreenivasulu P
05-01-2006 7:40 AM
hi rashmi,
if we don't check the sy-subrc it will fetch all the data from the database.instead of sy-subrc check we can check table initial condition also.
s
elect *
from vbak
into table it_vbak
where vbeln in s_vbeln.
if sy-subrc = 0.
select * from vbap
into table it_vbap
for all entries in it_vbak
where vbeln = it_vbak-vbeln.
endif.
<<<<<<<<<---- second way
select *
from vbak
into table it_vbak
where vbeln in s_vbeln.
if not it_vbak[] is initial.
select * from vbap
into table it_vbap
for all entries in it_vbak
where vbeln = it_vbak-vbeln.
endif.
Regards
vijay
05-01-2006 7:52 AM
hi rashmi ,
the use of for all entries is used to minimise the search for the specified number of records for the previous select .
suppose my first select gave me 1000 records of hits ,
so my second select which is using for all entries is to search for any hits not greater than 1000 entires ,
ur query
if sy-subrc for the first = 4 then i should not write for all entries for the second select .this is absolutely wrong as if im writing a second select with no relation from the first select .the result in this case is it performs as a select for all the entries in the table from where u r trying to fetch the data.
so i need to write
if not itab(first select total data) is not initial
before using select for all entires .
hope this helps .
regards,
vikky.
05-01-2006 8:22 AM
Hi Rashmi,
The best way to tackle this problem is to check whether ur internal table is initial. If not then fire the select query..
If not itab[] is initial.
select * from mara into table jtab for entries in itab where matnr = itab-matnr.
Endif.
If your itab is initial and u dont use the if statement.. it will select all the values in table mara..
Hope that answers your question..
Regards,
Tanveer.
Please mark helpful answers..