Usage of binary key in the read statement
Hi Experts,
For usage of binary search in the read statement, what is the minimum number of records (availablity) should be available in the internal table itab as per the below Example..
SYNTAX: Read table itab with key X binary search.
For eg: we have to use 16 primary keys only while creating a table.
Regards,
Maha
Hi Pushpraj,
I am sorry to say this. I am not at all speaking about the number of keys in the read statement.
I am talking abt "number of records to be there in the internal table to use binary search"
Generally, we use binary search when there is more data in the internal table. Can u specify what is the minimum records available in the internal table for using the binary search???
For Eg: Read table itab with key X binary search.
Iam talking abt the number of records in the internal table ITAB available if we want to use BINARY SEARCH(keyword).
Similar Messages
-
Binary search option with Read statement
Hi,
There are any chances that the Read statement with Binary search option to fail, even though the key exists??
Here the itab is sorted in descending order. and then some duplicates are removed using the delete adjacent statement.
Regards,
Sandhip.Hi,
Here is an example:
sort itab1 by a b c.
loop at itab2 into wa_itab2.
read table itab1 into wa_itab1
with key a = wa_itab2-a
b = wa_itab2-b
c = wa_itab2-c
binary search.
if sy-subrc = 0.
wa_output-a = wa_itab1-a.
endif.
endloop.
Another alternative is to use sorted tables.
Hope it helps...
P.S. Please award points if it helps... -
How to pass select-options in key while using Read Statement.
Hi SAP gurus,
I was using a select stmt. with were clause of Select-options it was working fine,
now my scenerio is changed i need to read an internal table
with key of select-options....
how to read internal table with key S_MATNR (Select-options).Hi,
We can certainly do this.
We need to loop the internal table with select-options condition.
Example :
LOOP AT ITAB WHERE FIELD = S_FIELD.
ENDLOOP.
This should solve your problem.
Plz reward if useful.
Thanks,
Dhanashri. -
Usage of Sorted Keys in standard tables
Hi,
If I have a sorted secondary key (unique or non-unique) in my internal table, and use the secondary key with my DELETE statement (DELETE ... WITH TABLE KEY <secondary_key_name> COMPONENTS ... = ...), I still get a prio 2 checkman error saying possible sequential read. My question:
1. What's the difference between usages of sorted key and a sorted table with regards to a READ statement?
2. Would I still have to do a SORT on the standard table by the secondary key components and then do a BINARY search to avoid the possible sequential read? (in that case why should i mention the key to be "sorted"?
Thanks in advance,
Best Regards
Anantharaman LHi Anantharaman ,
When we define sorted secondary keys, we do not have to sort it explicitly and use a binary search. we just have to define the sorted secondary keys and read based on that keys. The read statement should be as follows:
read TABLE <internal table>INTO <work area/field symbol>WITH KEY <secondary key name> COMPONENTS <comp1 = value>.
eg : read TABLE lt_tab INTO lw_tab WITH KEY key_1 COMPONENTS carrid1 = 'CC'
Complete Code :
REPORT YTEST.
DATA: lt_tab TYPE YSTRU1_TT,
lw_tab LIKE LINE OF lt_tab.
lw_tab-carrid1 = 'BB'.
lw_tab-connid = '50'.
APPEND lw_tab to lt_tab.
lw_tab-carrid1 = 'ZZ'.
lw_tab-connid = '50'.
APPEND lw_tab to lt_tab.
lw_tab-carrid1 = 'WW'.
lw_tab-connid = '50'.
APPEND lw_tab to lt_tab.
lw_tab-carrid1 = 'AA'.
lw_tab-connid = '50'.
APPEND lw_tab to lt_tab.
lw_tab-carrid1 = 'XX'.
lw_tab-connid = '50'.
APPEND lw_tab to lt_tab.
lw_tab-carrid1 = 'CC'.
lw_tab-connid = '50'.
APPEND lw_tab to lt_tab.
CLEAR lw_tab.
read TABLE lt_tab INTO lw_tab WITH KEY key_1 COMPONENTS carrid1 = 'CC'.
Note : Table type ystru1_tt is defined with a unique-sorted secondary key carrid1.
Hope this will be helpful.
Warm Regards,
Jenny -
READ statement with binary search
Hi friends,
I know that while using the READ statement that we have to sort data and use BINARY SEARCH for faster search.
I have a situation
following are internal table contents
belnr agent action
9000001 name1 BRW
9000001 name1 API
when i use READ statement with where condition ( ( belnr - 9000001 ) and ( action = 'BRW' ) ) with binary search then the SY_SUBRC value is 4.
if i remove the binary search then its giving SY-SUBRC value 0.
Can anybody explain why BINARY SEARCH fails.
Points will be rewarded for correct answers.
Thanks and regards,
Murthytry this i am not getting sy-subrc 4
TYPES:BEGIN OF TY_ITAB,
BELNR TYPE BELNR,
AGENT(30),
ACTION(5),
END OF TY_ITAB.
DATA:IT_TAB TYPE TABLE OF TY_ITAB,
WA_TAB TYPE TY_ITAB.
WA_TAB-BELNR = 9000001.
WA_TAB-AGENT = 'name1'.
WA_TAB-ACTION = 'BRW'.
APPEND WA_TAB TO IT_TAB.
CLEAR WA_TAB.
WA_TAB-BELNR = 9000002.
WA_TAB-AGENT = 'name 2'.
WA_TAB-ACTION = 'API'.
APPEND WA_TAB TO IT_TAB.
loop at it_tab into wa_tab.
read table it_tab into wa_tab with key belnr = wa_tab-belnr binary search .
write: sy-subrc, wa_tab-agent.
endloop. -
Read statement with repeated key field
Hi Experts ,
We are in the process of UCCHECK in an upgrade program and come across an issue with read statement using repeated key fields which is not allowed in a unicode compatable environment.
READ TABLE it_vbpa WITH KEY
vbeln = l_vbeln
parvw = '0'
parvw = 'ZN'.
I checked this in 4.6c environment and observed that the Read statement uses the last key value for reading and doesnt consider other values even if the last value is not present in the table .
I want to know if I can use only that last value for read statement ? If so, what was the use of the repeated key fields in a read statement?
Thanks and Regards
SanuHi,
Your main aim in a upgrade would be to successfully replicate the 4.6x functionalities in the ECC 6 version with the unicode checks. So it would be a safe option to only consider the last key condition. I dont have access to a 4.6C environment. May be it was a mistake corrected by SAP in the new version.
Vikranth -
Can put condition in read statement for a particular fild please suggest?
hi i have a requirement as belo
1 ) i am reading a table with read statement now i want to read with one more condition like
where status<> Z
to add to this read statement as below can i add the above condition to the below statement?? let me know
how to check on this one more condition in below read statement
loop at itrecord1 into wa_Record
READ TABLE it_main INTO wa_inv_master WITH KEY
/' CUSIP = wa_record-primarykeyfield1 BINARY SEARCH.
here one more condition i need to put whilereading that where statu <>z which is best way todo
IF SY-SUBRC = 0.
APPEND wa_record TO itrecord1.
clear wa_record.
else.
APPEND wa_record TO itrecord2.
clear : wa_record.
ENDIF.
ENDLOOP.
so how to put the condition in above statment can put in the read statement as that is most convinient will that work?
regards
aroraHello arora.
You can restrict the READ to an internal table, using "n" conditions in WITH KEY statement.
Use:
READ TABLE it_main INTO wa_inv_master
WITH KEY cusip = wa_record-primarykeyfield1
field2 = wa_record-field2
fieldn = wa_record-fieldn
BINARY SEARCH.
Remember that if you want restrictions like ">=", "<=", "<" or "<", must use LOOP, not READ.
Regards.
Valter Oliveira. -
what is the exact use of read statement. How it is used in int.table & database table.
Hi
Reading Lines of Tables
To read a single line of any table, use the statement:
READ TABLE <itab> <key> <result>.
For the statement to be valid for any kind of table, you must specify the entry using the key and not the index. You specify the key in the <key> part of the statement. The <result> part can specify a further processing option for the line that is retrieved. If the system finds an entry, it sets SY-SUBRC to zero, if not, it takes the value 4, as long as it is not influenced by one of the possible additions. If the internal table is an index table, SY-TABIX is set to the index of the line retrieved. If the table has a non-unique key and there are duplicate entries, the first entry is read. Specifying the Search Key The search key may be either the table key or another key.
Using the Table Key To use the table key of <itab> as a search key, enter <key> as follows:
READ TABLE <itab> FROM <wa> <result>.
or as follows
READ TABLE <itab> WITH TABLE KEY <k1> = <f1> ... <kn> = <fn> <result>.
In the first case, <wa> must be a work area compatible with the line type of <itab>. The values of the key fields are taken from the corresponding components of the work area. In the second case, you have to supply the values of each key field explicitly. If you do not know the name of one of the key fields until runtime, you can specify it as the content of a field <ni> using the form (<ni>) = <fi>. If the data types of <fi> are not compatible with the key fields, the system converts them. The system searches for the relevant lines as follows:
Standard tables
Linear search, where the runtime is in linear relation to the number of table entries.
Sorted tables
Binary search, where the runtime is in logarithmic relation to the number of table entries.
Hashed tables
The entry is found using the hash algorithm of the internal table. The runtime is
independent of the number of table entries.
Using a Different Search Key
To use a key other than the table key as a search key, enter <key> as follows:
READ TABLE <itab> WITH KEY = <f> <result>.
or as follows
READ TABLE <itab> WITH KEY <k1> = <f1> ... <kn> = <fn> <result>.
BC - ABAP Programming SAP AG
In the first case, the whole line of the internal table is used as the search key. The contents of the entire table line are compared with the contents of field <f>. If <f> is not compatible with the line type of the table, the value is converted into the line type. The search key allows you to find entries in internal tables that do not have a structured line type, that is, where the line is a single field or an internal table type. In the second case, the search key can consist of any of the table fields <k1>...<kn>. If you do not know the name of one of the components until runtime, you can specify it as the content of a field <ni> using the form (<ni>) = <fi>. If <ni> is empty when the statement is executed, the search field is ignored. If the data types of <fi> are not compatible with the components in the internal table, the system converts them. You can restrict the search to partial fields by pecifying offset and length.The search is linear for all table types. The runtime is in linear relation to the number of table lines. Specifying the Extra Processing Option
You can specify an option that specifies what the system does with the table entry that it finds. Using a Work Area You can write the table entry read from the table into a work area by specifying <result> as follows:
READ TABLE <itab> <key> INTO <wa> [COMPARING <f1> <f2> ...
|ALL FIELDS]
[TRANSPORTING <f1> <f2> ...
|ALL FIELDS
|NO FIELDS].
If you do not use the additions COMPARING or TRANSPORTING, the contents of the table line must be convertible into the data type of the work area <wa>. If you specify COMPARING or TRANSPORTING, the line type and work area must be compatible. You should always use a work area that is compatible with the line type of the relevant internal table. If you use the COMPARING addition, the specified table fields <fi> of the structured line type are compared with the corresponding fields of the work area before being transported. If you use
the ALL FIELDS option, the system compares all components. If the system finds an entry with the specified key <key> and if the contents of the compared fields are the same, SY-SUBRC is set to 0. If the contents of the compared fields are not the same, it returns the value 2. If the system cannot find an entry, SY-SUBRC is set to 4. If the system finds an entry, it copies it into the target work area regardless of the result of the comparison. If you use the TRANSPORTING addition, you can specify the table fields of the structured line type that you want to transport into the work area. If you specify ALL FIELDS without RANSPORTING, the contents of all of the fields are transported. If you specify NO FIELDS, no fields are transported. In the latter case, the READ statement only fills the system fields SYSUBRC and SY-TABIX. Specifying the work area <wa> with TRANSPORTING NO FIELDS is unnecessary, and should be omitted.
In both additions, you can specify a field <fi> dynamically as the contents of a field <ni> in the form (<ni>). If <ni> is empty when the statement is executed, it is ignored. You can restrict the search to partial fields by specifying offset and length.
Using a Field SymbolYou can assign the table entry read from the table to a field symbol by specifying <result> as
follows:
READ TABLE <itab> <key> ASSIGNING <FS>.
After the READ statement, the field symbol points to the table line. If the line type is structured, you should specify the same type for the field symbol when you declare it. This allows you to address the components of the field symbol. If you cannot specify the type statically, you must use further field symbols and the technique of assigning components of structures to address the components of the structure.For further information about assigning table lines to field symbols, refer to Access Using Field Symbols.
SORT ITAB.
READ TABLE ITAB WITH KEY VAR1 <= SYDATUM BINARY SEARCH.
OR
READ ITAB WITH KEY VAR1 <= SYDATUM
YOU CAN USE ANY ONE READ STATEMENT
1ST ONE IS BINARY SEARCH IT IS BETTER IN PERFORMANCE
YOU HAVE TO SORT THAT ITAB BEFORE THIS STATEMENT
2ND ONE IS NORMAL SEARCHIN TECH IT IS NOT GOOD IN THE PERFORMANCE POINT OF VIEW -
When i am using read statement to read the contents of a table using a key field
I am getting a warning in Code Inspector as "Sequential read access possible for a sorted table" Can anyone provide me a solutionhi ,
Reading Lines of Tables
To read a single line of any table, use the statement:
READ TABLE <itab> <key> <result>.
For the statement to be valid for any kind of table, you must specify the entry using the key and not the index. You specify the key in the <key> part of the statement. The <result> part can specify a further processing option for the line that is retrieved. If the system finds an entry, it sets SY-SUBRC to zero, if not, it takes the value 4, as long as it is not influenced by one of the possible additions. If the internal table is an index table, SY-TABIX is set to the index of the line retrieved. If the table has a non-unique key and there are duplicate entries, the first entry is read. Specifying the Search Key The search key may be either the table key or another key.
Using the Table Key To use the table key of <itab> as a search key, enter <key> as follows:
READ TABLE <itab> FROM <wa> <result>.
or as follows
READ TABLE <itab> WITH TABLE KEY <k1> = <f1> ... <kn> = <fn> <result>.
In the first case, <wa> must be a work area compatible with the line type of <itab>. The values of the key fields are taken from the corresponding components of the work area. In the second case, you have to supply the values of each key field explicitly. If you do not know the name of one of the key fields until runtime, you can specify it as the content of a field <ni> using the form (<ni>) = <fi>. If the data types of <fi> are not compatible with the key fields, the system converts them. The system searches for the relevant lines as follows:
Standard tables
Linear search, where the runtime is in linear relation to the number of table entries.
Sorted tables
Binary search, where the runtime is in logarithmic relation to the number of table entries.
Hashed tables
The entry is found using the hash algorithm of the internal table. The runtime is
independent of the number of table entries.
Using a Different Search Key
To use a key other than the table key as a search key, enter <key> as follows:
READ TABLE <itab> WITH KEY = <f> <result>.
or as follows
READ TABLE <itab> WITH KEY <k1> = <f1> ... <kn> = <fn> <result>.
BC - ABAP Programming SAP AG
In the first case, the whole line of the internal table is used as the search key. The contents of the entire table line are compared with the contents of field <f>. If <f> is not compatible with the line type of the table, the value is converted into the line type. The search key allows you to find entries in internal tables that do not have a structured line type, that is, where the line is a single field or an internal table type. In the second case, the search key can consist of any of the table fields <k1>...<kn>. If you do not know the name of one of the components until runtime, you can specify it as the content of a field <ni> using the form (<ni>) = <fi>. If <ni> is empty when the statement is executed, the search field is ignored. If the data types of <fi> are not compatible with the components in the internal table, the system converts them. You can restrict the search to partial fields by pecifying offset and length.The search is linear for all table types. The runtime is in linear relation to the number of table lines. Specifying the Extra Processing Option
You can specify an option that specifies what the system does with the table entry that it finds. Using a Work Area You can write the table entry read from the table into a work area by specifying <result> as follows:
READ TABLE <itab> <key> INTO <wa> [COMPARING <f1> <f2> ...
|ALL FIELDS]
[TRANSPORTING <f1> <f2> ...
|ALL FIELDS
|NO FIELDS].
If you do not use the additions COMPARING or TRANSPORTING, the contents of the table line must be convertible into the data type of the work area <wa>. If you specify COMPARING or TRANSPORTING, the line type and work area must be compatible. You should always use a work area that is compatible with the line type of the relevant internal table. If you use the COMPARING addition, the specified table fields <fi> of the structured line type are compared with the corresponding fields of the work area before being transported. If you use
the ALL FIELDS option, the system compares all components. If the system finds an entry with the specified key <key> and if the contents of the compared fields are the same, SY-SUBRC is set to 0. If the contents of the compared fields are not the same, it returns the value 2. If the system cannot find an entry, SY-SUBRC is set to 4. If the system finds an entry, it copies it into the target work area regardless of the result of the comparison. If you use the TRANSPORTING addition, you can specify the table fields of the structured line type that you want to transport into the work area. If you specify ALL FIELDS without RANSPORTING, the contents of all of the fields are transported. If you specify NO FIELDS, no fields are transported. In the latter case, the READ statement only fills the system fields SYSUBRC and SY-TABIX. Specifying the work area <wa> with TRANSPORTING NO FIELDS is unnecessary, and should be omitted.
In both additions, you can specify a field <fi> dynamically as the contents of a field <ni> in the form (<ni>). If <ni> is empty when the statement is executed, it is ignored. You can restrict the search to partial fields by specifying offset and length.
Using a Field SymbolYou can assign the table entry read from the table to a field symbol by specifying <result> as
follows:
READ TABLE <itab> <key> ASSIGNING <FS>.
After the READ statement, the field symbol points to the table line. If the line type is structured, you should specify the same type for the field symbol when you declare it. This allows you to address the components of the field symbol. If you cannot specify the type statically, you must use further field symbols and the technique of assigning components of structures to address the components of the structure.For further information about assigning table lines to field symbols, refer to Access Using Field Symbols.
Kishi. -
How to give read statement checking condition
hi,
i am trying to give like this, but it throws an error can u tell me how to give a read statement checking two conditions.
READ TABLE I_RSEG INTO WA_TAB_RSEG WITH KEY BELNR = WA_TAB_RBCO-BELNR
AND GJAHR = WA_TAB_RBCO-GJAHR
AND BUZEI = WA_TAB_RBCO-BUZEI.Hi Anitha,
READ statement wont have 'AND's in them. Your statement will work fine without having 'AND's. Lets try by omitting 'AND's in ur statement.
Please change the code as follows.
1)
READ TABLE I_RSEG INTO WA_TAB_RSEG WITH KEY BELNR = WA_TAB_RBCO-BELNR
GJAHR = WA_TAB_RBCO-GJAHR
BUZEI = WA_TAB_RBCO-BUZEI.
2)sort i_resg by belnr gjahr buzei.
READ TABLE I_RSEG INTO WA_TAB_RSEG WITH KEY BELNR = WA_TAB_RBCO-BELNR
GJAHR = WA_TAB_RBCO-GJAHR
BUZEI = WA_TAB_RBCO-BUZEI binary search.
The above statement will fetch u particular record faster than the above READ statement.
Thanks,
Vinay
Message was edited by: Vinaykumar Gorrela -
Significance of read statement
Hi all,
Can any one explain me the significance of read statement in detai?Hi,
Reading Lines of Tables
To read a single line of any table, use the statement:
READ TABLE <itab> <key> <result>.
For the statement to be valid for any kind of table, you must specify the entry using the key and not the index. You specify the key in the <key> part of the statement. The <result> part can specify a further processing option for the line that is retrieved.
If the system finds an entry, it sets SY-SUBRC to zero, if not, it takes the value 4, as long as it is not influenced by one of the possible additions. If the internal table is an index table, SY-TABIX is set to the index of the line retrieved. If the table has a non-unique key and there are duplicate entries, the first entry is read.
Specifying the Search Key
The search key may be either the table key or another key.
Using the Table Key
To use the table key of <itab> as a search key, enter <key> as follows:
READ TABLE <itab> FROM <wa> <result>.
or as follows
READ TABLE <itab> WITH TABLE KEY <k1> = <f 1> ... <k n> = <f n> <result>.
In the first case, <wa> must be a work area compatible with the line type of <itab>. The values of the key fields are taken from the corresponding components of the work area.
In the second case, you have to supply the values of each key field explicitly. If you do not know the name of one of the key fields until runtime, you can specify it as the content of a field <n i > using the form (<n i >) = <f i >. If the data types of <f i > are not compatible with the key fields, the system converts them.
The system searches for the relevant lines as follows:
Standard tables
Linear search, where the runtime is in linear relation to the number of table entries.
Sorted tables
Binary search, where the runtime is in logarithmic relation to the number of table entries.
Hashed tables
The entry is found using the hash algorithm of the internal table. The runtime is independent of the number of table entries.
Using a Different Search Key
To use a key other than the table key as a search key, enter <key> as follows:
READ TABLE <itab> WITH KEY = <f> <result>.
or as follows
READ TABLE <itab> WITH KEY <k1> = <f1> ... <k n> = <f n> <result>.
In the first case, the whole line of the internal table is used as the search key. The contents of the entire table line are compared with the contents of field <f>. If <f> is not compatible with the line type of the table, the value is converted into the line type. The search key allows you to find entries in internal tables that do not have a structured line type, that is, where the line is a single field or an internal table type.
In the second case, the search key can consist of any of the table fields <k 1 >...<k n >. If you do not know the name of one of the components until runtime, you can specify it as the content of a field <n i > using the form (<n i >) = <f i >. If <n i > is empty when the statement is executed, the search field is ignored. If the data types of <f i > are not compatible with the components in the internal table, the system converts them. You can restrict the search to partial fields by specifying offset and length.
The search is linear for all table types. The runtime is in linear relation to the number of table lines.
Specifying the Extra Processing Option
You can specify an option that specifies what the system does with the table entry that it finds.
Using a Work Area
You can write the table entry read from the table into a work area by specifying <result> as follows:
READ TABLE <itab> <key> INTO <wa> [COMPARING <f1> <f 2> ...
|ALL FIELDS]
[TRANSPORTING <f1> <f 2> ...
|ALL FIELDS
|NO FIELDS].
If you do not use the additions COMPARING or TRANSPORTING, the contents of the table line must be convertible into the data type of the work area <wa>. If you specify COMPARING or TRANSPORTING, the line type and work area must be compatible. You should always use a work area that is compatible with the line type of the relevant internal table.
If you use the COMPARING addition, the specified table fields <f i > of the structured line type are compared with the corresponding fields of the work area before being transported. If you use the ALL FIELDS option, the system compares all components. If the system finds an entry with the specified key <key> and if the contents of the compared fields are the same, SY-SUBRC is set to 0. If the contents of the compared fields are not the same, it returns the value 2. If the system cannot find an entry, SY-SUBRC is set to 4. If the system finds an entry, it copies it into the target work area regardless of the result of the comparison.
If you use the TRANSPORTING addition, you can specify the table fields of the structured line type that you want to transport into the work area. If you specify ALL FIELDS without TRANSPORTING, the contents of all of the fields are transported. If you specify NO FIELDS, no fields are transported. In the latter case, the READ statement only fills the system fields SY-SUBRC and SY-TABIX. Specifying the work area <wa> with TRANSPORTING NO FIELDS is unnecessary, and should be omitted.
In both additions, you can specify a field <f i > dynamically as the contents of a field <n i > in the form (<n i >). If <n i > is empty when the statement is executed, it is ignored. You can restrict the search to partial fields by specifying offset and length.
Using a Field Symbol
You can assign the table entry read from the table to a field symbol by specifying <result> as follows:
READ TABLE <itab> <key> ASSIGNING <FS>.
After the READ statement, the field symbol points to the table line. If the line type is structured, you should specify the same type for the field symbol when you declare it. This allows you to address the components of the field symbol. If you cannot specify the type statically, you must use further field symbols and the technique of assigning components of structures to address the components of the structure.
Reward If Helpfull,
Naresh. -
I have doubt in Read statement
Hi All.
I have doubt in Read statement .i need to convert following select statement as read statement .how can i change help me.
IF p_field1 IS INITIAL
AND p_field2 IS INITIAL
AND p_field3 IS INITIAL
AND p_field4 IS INITIAL
AND p_field5 IS INITIAL.
SELECT *
FROM zdbt
INTO TABLE itab
WHERE field5 = p_field5
ORDER BY PRIMARY KEY.
IF sy-subrc <> 0.
MESSAGE s035.
ENDIF.
ENDIF.
regards,
Jay.hi
The READ statement is as below:
When u have a table already with values and to improve the performance u need to use this.
Reading Lines of Tables
To read a single line of any table, use the statement:
READ TABLE <itab> <key> <result>.
For the statement to be valid for any kind of table, you must specify the entry using the key and
not the index. You specify the key in the <key> part of the statement. The <result> part can
specify a further processing option for the line that is retrieved.
If the system finds an entry, it sets SY-SUBRC to zero, if not, it takes the value 4, as long as it is
not influenced by one of the possible additions. If the internal table is an index table, SY-TABIX
is set to the index of the line retrieved. If the table has a non-unique key and there are duplicate
entries, the first entry is read.
Thanks
Shiva -
Hello Experts,
Can I use both index and key addition in READ statment like
Read table itab from index i with key id = 'XYZ'.
Actually I am using that but the read statement is not following both the addition.Is there any other way out in which I can do that.I dont want to use LOOP...ENDLOOPHi *priya singh *.
You are not able to use index and with key parley in read statement. you should use LOOP..END LOOP only..
See following...
I think in your requirement you want i th record which is satisfied id = 'XYZ'.
use following code...
loop at itab into wa where id = 'XYZ'.
if sy-index eq = i.
" Assign/take values here
EXIT. " --> Immediately exit the loop after satisfied your condition
exit.
endloop.
Regards,
Mahi. -
HI Friends,
I am using a code like as below
loop at itab assigning <fl_itab>.
read table inttab assigning <fl_inttab> with key matnr = <fl_itab-matnr>.
material = <fl_inttab>-matnr.
endloop.
my questio is .
i am reading inttab internal table .if (suppose) this internal table has duplicate records for a material number which value will be assigned to output field(material).will read statement will take only the first record of many duplicate record...
please help meYes it will take the first record.
you can check the sy-subrc value after the execution of the READ statement.
loop at itab assigning <fl_itab>.
read table inttab assigning <fl_inttab> with key matnr = <fl_itab-matnr>.
if sy-subrc eq 0.
material = <fl_inttab>-matnr.
endif.
endloop. -
Problem in writing a Read Statement
Hi,
In my Table control I have a POSITION button which is used to find the record in the table.
I have written the following code.
CALL FUNCTION 'POPUP_GET_VALUES'
EXPORTING
* NO_VALUE_CHECK = ' '
popup_title = 'Find the record'
* START_COLUMN = '5'
* START_ROW = '5'
* IMPORTING
* RETURNCODE =
TABLES
fields = lt_tab
EXCEPTIONS
error_in_fields = 1
OTHERS = 2
I have five primary keys in my table, so that in the pop up I am getting all the five fields.
The user will enter any of the five fields , I want to write a read statement based on the fields entered by the user.
Could anybody help in writing the Read statement.
Or could any one help me in writing out the FIND functionality for a table control
Regards
Edited by: SAP LEARNER on Jun 15, 2010 1:40 PMHi,
I do not know what fields will be filled up.
as there are 5 PK fields so 5! chances will be there for the where condition in the READ statement.
How can I do it.
I tried in the following way.
I created a structure with the primary key fields and I filled the structure with the user filled values.
Then I used it in the read statement as below, but it did not work.
LOOP AT lt_tab .
IF lt_tab-fieldname = 'SOCIEDAD'.
lw_pk-sociedad = lt_tab-value.
ENDIF.
IF lt_tab-fieldname = 'NATURAL_YEAR'.
lw_pk-natural_year = lt_tab-value.
ENDIF.
IF lt_tab-fieldname = 'CICLO_DE_VENTAS'.
lw_pk-ciclo_de_ventas = lt_tab-value.
ENDIF.
IF lt_tab-fieldname = 'MODEL_VERSION'.
lw_pk-model_version = lt_tab-value.
ENDIF.
ENDLOOP.
DATA:lw_yrwbw010 TYPE ty_yrwbw010.
READ TABLE t_yrwbw010 INTO lw_yrwbw010 WITH KEY lw_pk.
IF sy-subrc = 0.
table-top_line = sy-tabix.
ENDIF.
ENDIF.
@Rob Burbank
Could you please help me !! I could not find that in F1 help.
@ Keshav.T
Could you please elaborate it please
Maybe you are looking for
-
Change GR/IR Account for Special Order PO Type
I've had a request from our FI department. They would like a new PO type for special orders that will post to a different GR/IR Account. In our configuration, the GR/IR account is determined based upon valuation class of the article. But if they spec
-
STO and delivery is getting created in the foreground instead of background
Hi experts, In return document (with reference to Work Order), When user is selecting recommended action u2018YAu2019 and clicking the u2018returnu2019 button, an STO and delivery is getting created in the foreground instead of generating them in bac
-
How can i see how many song i have in my iTunes library
i have just downloaded the new software update for itunes and i cant see how many songs i have in my library. is there a way i can check that or put that back on?
-
When using Artwork Frames, how can you change the color of the frame?
-
How to my free movies in to iphone, how to my free movies in to iphone
plz find this i want free vidoes into my phone i dont need app store