‎2007 Apr 18 12:42 PM
Hi Freinds,
Can any one explain me ? what is the above statement means, and can u give me sample program. points for sure...
<b>Read table itab with key k1 = v1....kn = vn[Binary Search]</b>
Thanks and reagrds
Vijaya
‎2007 Apr 18 12:43 PM
hi,
it reads the internal table with the key you specify. It uses binary serach for searching the record.see that you sort the internal table before using binary search for effective output.
regards,
Navneeth.K
‎2007 Apr 18 12:45 PM
hi,
here k1... kn denotes the field of the internal table and v1...vn denotes the value it is compared with.
regards,
Navneeth.K
‎2007 Apr 18 12:46 PM
‎2007 Apr 18 12:46 PM
Hi,
I must add, that it reads only one record from the internal table (the one that fulfills the conditions you declared after KEY).
‎2007 Apr 18 12:44 PM
Hi,
Reading a value in the internal table with the condition mentioned in the with key.
And if u use Binary search, then the table should be sorted compulsory.
Regards,
Krishna K.
‎2007 Apr 18 12:45 PM
hi
this is to read the data from the internal table with the keys specified.
The BINARY SEARCH addition means that you can access a record in a table by its key as quickly as you would be able to in a sorted table
ex:
REPORT demo_int_tables_read_index_bin.
DATA: BEGIN OF line,
col1 TYPE i,
col2 TYPE i,
END OF line.
DATA itab LIKE STANDARD TABLE OF line.
DO 4 TIMES.
line-col1 = sy-index.
line-col2 = sy-index ** 2.
APPEND line TO itab.
ENDDO.
SORT itab BY col2.
READ TABLE itab WITH KEY col2 = 16 INTO line BINARY SEARCH.
WRITE: 'SY-SUBRC =', sy-subrc.
regards,
madhu
‎2007 Apr 18 12:58 PM
‎2007 Apr 18 12:45 PM
Hi,
This is to read a record from an internal table based on certain key fields e.g. k1, k2 etc.
Read table itab with key matnr = '43243223'.
If you are using Binary search, then u need to sort the internal table by that field mentioned in the key fields
eg.
SORT ITAB by MATNR.
Read table itab with key matnr = '43243223'.
Best regards,
Prashant
‎2007 Apr 18 12:46 PM
Read table ITABB with key K1 = V1...means the table itab will be read for the key k1 whose value would be V1<b> Linearly</b>
By adding Binary search we try to improve the performance of the read stament by reducing the number of comparisions...mind u the table should be sorted first..
read table returns sy-subrc if failed
read table stmt exits any search after it has found atleast one record inthe concerened table.
santhosh
‎2007 Apr 18 12:46 PM
Here an internal table itab has multiple records.
Each Record is uniquey identified by the combination of key fields k1 through kn.
This statement would retrun you the record that matches to the values that are specified in v1 through vn.
The binary search will speed up the search process.
example.
do 10 times.
itab-number = sy-index.
append itab.
enddo.
sort itab by number.
read table itab with key number = 5 binary search.
if sy-subrc = 0.
write:/ itab-number. "Outputs 5
endif.
Regards,
Ravi
‎2007 Apr 18 12:46 PM
Hi
Reads the internal Table with key fields
Move the data to Final Output Internal Table
loop at i_bsis.
i_final-belnr = i_bsis-belnr. " FI Document
i_final-monat = i_bsis-monat. " Period
i_final-budat = i_bsis-budat. " Rec. Date
Read the Transaction Currency from BKPF Internal Table
read table i_bkpf with key bukrs = i_bsis-bukrs
belnr = i_bsis-belnr
gjahr = i_bsis-gjahr
binary search.
if sy-subrc = 0.
i_final-waers = i_bkpf-waers. " Tran.Currency
Read the Movement Type for all Material Related
Documents from MSEG Internal Table
if i_bkpf-awtyp = c_mkpf.
read table i_mseg with key mblnr = i_bkpf-awkey(10)
mjahr = i_bkpf-awkey+10(4).
if sy-subrc = 0.
i_final-bwart = i_mseg-bwart. " Movement Type
endif.
endif.
endif.
Read Vendor, Plant, PO Document, Local And Trans.Amounts
from BSEG Internal Table
read table i_bseg with key bukrs = i_bsis-bukrs
belnr = i_bsis-belnr
gjahr = i_bsis-gjahr
buzei = i_bsis-buzei
binary search.
if sy-subrc = 0.
i_final-lifnr = i_bseg-lifnr. " Vendor
i_final-werks = i_bseg-werks. " Plant
i_final-ebeln = i_bseg-ebeln. " PO
i_final-dmbtr = i_bseg-dmbtr. " Local Amount
i_final-wrbtr = i_bseg-wrbtr. " Tran.Amount
i_final-menge = i_bseg-menge. " Quantity
i_final-meins = i_bseg-meins. " UOM
For Credit Indicator(SHKZG = H) amounts should be (-)ve
if i_bseg-shkzg = c_h.
i_final-dmbtr = i_final-dmbtr * -1.
i_final-wrbtr = i_final-wrbtr * -1.
i_final-menge = i_final-menge * -1.
endif.
Read the Material and its Description from EKPO Internal Table
read table i_ekpo with key ebeln = i_bseg-ebeln
ebelp = i_bseg-ebelp
matnr = i_bseg-matnr
binary search.
if sy-subrc = 0.
i_final-matnr = i_ekpo-matnr. " Material Number
i_final-txz01 = i_ekpo-txz01. " Material Text
Populate the Material Status depending on the Input Checkbox
On Selection Screen
if not i_ekpo-matnr is initial.
i_final-status = c_x.
endif.
endif.
Read the PO related Cost Element and Cost Centers
from EKKN Internal Table
read table i_ekkn with key ebeln = i_bseg-ebeln
ebelp = i_bseg-ebelp
binary search.
if sy-subrc = 0.
i_final-kostl = i_ekkn-kostl. " Cost Center
i_final-sakto = i_ekkn-sakto. " Cost Element
endif.
Read the Valuation Class from MBEW Internal Table
read table i_mbew with key matnr = i_bseg-matnr
werks = i_bseg-werks
binary search.
if sy-subrc = 0.
i_final-bklas = i_mbew-bklas. " Val Class
endif.
Read the Vendor Name from LFA1 Internal Table
read table i_lfa1 with key lifnr = i_bseg-lifnr
binary search.
if sy-subrc = 0.
i_final-name1 = i_lfa1-name1. " Vendor Name
endif.
endif.
append i_final.
clear i_final.
endloop.
sort i_final by lifnr werks monat matnr.
reward if useful
regards,
Anji
‎2007 Apr 18 12:49 PM
Hai ,
Read table helps you to get a particular record in an internal table.
Here is the sample code:
DATA: BEGIN OF line,
col1 TYPE i,
col2 TYPE i,
END OF line.
DATA itab LIKE HASHED TABLE OF line WITH UNIQUE KEY col1.
DO 4 TIMES.
line-col1 = sy-index.
line-col2 = sy-index ** 2.
INSERT line INTO TABLE itab.
ENDDO.
line-col1 = 2.
line-col2 = 3.
READ TABLE itab FROM line INTO line COMPARING col2.
WRITE: 'SY-SUBRC =', sy-subrc.
SKIP.
WRITE: / line-col1, line-col2.
Reward points if it helps you.
Regds,
Rama.Pammi
‎2007 Apr 18 12:49 PM
HI,
Read table itab with key k1 = v1....kn = vn[Binary Search]
example
table itab
c1 c2 c3 c4
-
w1 w2 w3 w4
v1 v2 v3 v4
u1 u2 u3 u4
sort itab by c1 c2.
clear wa.
<b>read itab into wa with key c1 = 'v1' c2 = 'v2' binary search.</b>
gives you the perfect output .. wa = v1 v2 v3 v4.
clear wa.
<b>read itab into wa with key c1 = 'v1' c2 = 'w2' binary search.</b>
No result found..
The above statement READs the table ITAB with key you specify and the serach is binary search.
Sorting the table is mandatory.
reward if useful
regards,
nazeer.
‎2007 Apr 18 12:50 PM
Hi Vijaya,
This is a READ statement which will get an entry from the internal table for the values specified for the keys.
If you have more than one entry with the specified values for the keys, it will only fetch the first successful entry from the internal table.
The addition BINARY SEARCH makes you faster to search on a particular field with the value. Prior to using BINARY SEARCH on a field, it should be SORTed on that field on the internal table.
REPORT demo_int_tables_read_index_bin.
DATA: BEGIN OF line,
col1 TYPE i,
col2 TYPE i,
END OF line.
DATA itab LIKE STANDARD TABLE OF line.
DO 4 TIMES.
line-col1 = sy-index.
line-col2 = sy-index ** 2.
APPEND line TO itab.
ENDDO.
SORT itab BY col2.
READ TABLE itab WITH KEY col2 = 16 INTO line BINARY SEARCH.
WRITE: 'SY-SUBRC =', sy-subrc.
Thanks,
Vinay
‎2007 Apr 18 12:55 PM
Hi,
Read table is used to read table contents........
DATA: BEGIN OF line,
col1 TYPE i,
col2 TYPE i,
END OF line.
DATA itab LIKE STANDARD TABLE OF line.
DO 4 TIMES.
line-col1 = sy-index.
line-col2 = sy-index ** 2.
APPEND line TO itab.
ENDDO.
SORT itab BY col2.
READ TABLE itab WITH KEY col2 = 16 INTO line BINARY SEARCH.
WRITE: 'SY-SUBRC =', sy-subrc.
with regards,
Jay
‎2007 Apr 18 1:05 PM
hi,
With addition to my above post chk out the following code
data: itab like vbak occurs 0 with header line.
select *
into table itab
from vbak
up to 100 rows.
sort itab by vbeln.
read table itab with key vbeln = '0000004969' binary search.
if sy-subrc eq 0.
write:/ itab-vbeln.
endif.
hope it clears your concept.
regards,
Navneeth.K