Read table with key doubt
Hi guys!
Please, what can i do when i use the
Read table xxxx WITH KEY tab_key = value ASSIGNING <fs>
statement and there is more than one entry with the specified selection criteria? How can i return the values to an internal table?
I need to get all the entries and i don't have the full table key.
thanks!
Hi Fabio,
An efficient way to do this is to have your table sorted by a specific key. Let's say I have a table with the feild material number.
You can do this:
data: lv_index like sy-tabix.
sort itab by material_number.
ready table itab with key material_number = yournumber
binary search.
if sy-subrc eq 0.
move sy-tabix to lv_index. " this holds the index of your first material record
now we loop at the table start at that index
loop at itab index lv_index.
perform your processing
if we come accross a different material number - exit the loop.
if itab-material_number ne yournumber.
exit.
endif.
endloop.
endif.
This way you only processes the records you are looking for.
thanks.
JB
Similar Messages
-
Replacemnt for read table with key binary search
as read table with
READ TABLE gt_INT_CURR_VALUE into gs_int_curr_value
WITH KEY gs_FS_EINA_KEY BINARY SEARCH.
the statement read tabel with key is absolute in ecc 6 so how to replace it .Hi subratt,
internal tables with header lines are obsolete and in oo context (CLASS / METHOD code) forbidden.
OK, you'd better use SORTED TABLE and FIELD-SYMBOLS to gt optimal code::
READ TABLE gt_INT_CURR_VALUE into gs_int_curr_value
WITH KEY gs_FS_EINA_KEY BINARY SEARCH.
may be replaced with
DATA:
gt_INT_CURR_VALUE_SORTED LIKE SORTED TABLE OF gs_int_curr_value
WITH [NON-]UNIQUE KEY <fields of gs_FS_EINA_KEY>.
FIELD-SYMBOLS:
<nt_curr_value> LIKE gs_int_curr_value.
gt_INT_CURR_VALUE_SORTED = gt_INT_CURR_VALUE.
READ TABLE gt_INT_CURR_VALUE_SORTED ASSIGNING <nt_curr_value>
WITH TABLE KEY <key1> = gs_FS_EINA_KEY-<key1> .. <keyn> = gs_FS_EINA_KEY-<keyn>.
Regards,
Clemens -
Read Table with key field - question
Hi,
Can you use the same key field more than once?
For example:
READ TABLE I_TVKWZ INTO I_TVKWZ_2 WITH KEY WERKS = '1004'
Werks = '1002'.
I get an error when trying this.
Is there an alternative?
Thanks,
JohnHi John,
try this:
DATA: begin of itab occurs 0,
werks like mseg-werks,
i type i,
end of itab.
itab-werks = '1000'. itab-i = itab-i + 1. append itab.
itab-werks = '1000'. itab-i = itab-i + 1. append itab.
itab-werks = '2000'. itab-i = itab-i + 1. append itab.
itab-werks = '3000'. itab-i = itab-i + 1. append itab.
itab-werks = '5000'. itab-i = itab-i + 1. append itab.
itab-werks = '5000'. itab-i = itab-i + 1. append itab.
itab-werks = '7000'. itab-i = itab-i + 1. append itab.
itab-werks = '7000'. itab-i = itab-i + 1. append itab.
itab-werks = '9000'. itab-i = itab-i + 1. append itab.
itab-werks = '9000'. itab-i = itab-i + 1. append itab.
itab-werks = '9000'. itab-i = itab-i + 1. append itab.
loop at itab where werks = '1000' or werks = '9000'.
write: / itab-werks, itab-i.
endloop.
Regards, Dieter -
Read Table with Key in a Deep Structure
Hello,
I'd like to read a table while comparing a value in a deep structure. So in the following code the key ID is a deep structure within cs_purchase_order_message-purchase_order-item-value.
For some reason code check returns no errors with the following code, but I get a short dump with a syntax error on id-value when I execute the code.
read table cs_purchase_order_message-purchase_order-item assigning <fs_xml_item> with key id-value = <fs_item>-number_int.
How do I use "with key" when the value is in a deep structure?
Thanks,
MattRefer to example link below:
http://sap.ittoolbox.com/groups/technical-functional/sap-dev/read-deep-structure-736023.
Regards,
Venkat. -
Read internal table with key not equal to
Hi,
How can I read internal table with key not equal to some other field.
Basically in read statement we can read only fields equal to others fields.Hi,
Test the following Code you can Use Loop at for this But not Read Table
DATA: BEGIN OF it_test OCCURS 10,
f1(4),
f2 TYPE i,
f3(2),
END OF it_test.
DATA: it_test2 LIKE STANDARD TABLE OF it_test WITH HEADER LINE.
it_test-f1 = '1000'.
it_test-f2 = 10.
it_test-f3 = 'B'.
APPEND it_test TO it_test.
it_test-f1 = '2000'.
it_test-f2 = 10.
it_test-f3 = 'A'.
APPEND it_test TO it_test.
it_test-f1 = '1000'.
it_test-f2 = 10.
it_test-f3 = 'B'.
APPEND it_test TO it_test.
it_test-f1 = '1000'.
it_test-f2 = 10.
it_test-f3 = 'A'.
APPEND it_test TO it_test.
it_test-f1 = '1000'.
it_test-f2 = 40.
it_test-f3 = 'A'.
APPEND it_test TO it_test.
LOOP AT it_test INTO it_test WHERE f3 NE 'A'.
WRITE: / it_test-f1, it_test-f2, it_test-f3.
ENDLOOP.
Kind Regards,
Faisal -
Read the internal table with key
Hi friends,
decleration of internal table is :
TYPES : BEGIN OF ty_qmel,
qmart TYPE qmel-qmart,
qmnum TYPE qmel-qmnum,
qmtxt TYPE qmel-qmtxt,
strmn TYPE qmel-strmn,
ltrmn TYPE qmel-ltrmn,
objnr TYPE qmel-objnr,
qmdat TYPE qmel-qmdat,
END OF ty_qmel.
i have written the query as follows .
SELECT qmart qmnum qmtxt strmn ltrmn FROM qmel
INTO CORRESPONDING FIELDS OF TABLE i_qmel
FOR ALL ENTRIES IN i_qmel
WHERE qmart EQ i_qmel-qmart.
I am getting the data into 1_qmel.
Let me know how to read this table with key...?
Thanks in advance...Hi,
Refer this code.
*& Form SUB_COLLECT_DATA
text
FORM sub_collect_data.
*--Local variables
DATA : lv_count(3) TYPE c.
IF NOT it_fpltc[] IS INITIAL.
LOOP AT it_fpltc INTO wa_fpltc.
lv_count = wa_fpltc-fpltr+3(3).
wa_final-ccnum = wa_fpltc-ccnum.
wa_final-rfzei = lv_count.
CLEAR : wa_vbrk.
READ TABLE it_vbrk INTO wa_vbrk WITH KEY rplnr = wa_fpltc-fplnr
BINARY SEARCH.
IF sy-subrc EQ 0.
wa_final-vbeln = wa_vbrk-vbeln.
wa_final-bukrs = wa_vbrk-bukrs.
ENDIF.
APPEND wa_final TO it_final.
CLEAR : wa_vbrk,
wa_fpltc,
lv_count.
ENDLOOP.
Regards,
PRashant -
Question about reading generic tables with keys
Hello
I'm wondering if it's possible to read a generic table with key statement:
FIELD-SYMBOLS:
<lv_key> TYPE zconf_key,
<lt_data_bi> TYPE INDEX TABLE,
<lt_data_ai> TYPE INDEX TABLE,
<ls_data_bi> TYPE any,
<ls_data_ai> TYPE any.
* create data types
CREATE DATA lt_data_bi TYPE (ls_node-data_table_type).
ASSIGN lt_data_bi->* TO <lt_data_bi>.
CREATE DATA lt_data_ai TYPE (ls_node-data_table_type).
ASSIGN lt_data_ai->* TO <lt_data_ai>.
* do check
LOOP AT <lt_data_ai> ASSIGNING <ls_data_ai>.
ASSIGN COMPONENT 'KEY' OF STRUCTURE <ls_data_ai> TO <lv_key>.
READ TABLE <lt_data_bi> WITH KEY key = <lv_key>
ASSIGNING <ls_data_bi> BINARY SEARCH.
I receive the message: "The specified type has no structure and therefore no component called KEY" in the read statement above.
Does anyone has an idea what I can do here?
Regards,
MathiasMathias Glockner wrote:
> READ TABLE <lt_data_bi> WITH KEY key = <lv_key>
In your structure ls_data_bi there is no field called KEY . please check whether you have field KEY in structure
a®s -
How to use Read table with out key fields
Hi Experts,
I need to retrieve the 2 internal tables data into single table.
I have 3 common fields between the 2 tables but I don't have the Key fields. Then how to use the read table in this.
Thanks in Advance.
Edited by: satish4abap on Mar 10, 2010 9:39 AMHi Satish,
Key fields are nothing but the common fields with which you can pick the data from the second internal table.
If you can paste your Internal table fields then we will be able to assit you better.
However, in genral scenarios you can use it as below :
In this scenario, we are putting data from 3 internal table to another single internal table.
LOOP AT T_PRGEN INTO WA_PRGEN.
WA_FINAL-GUID_PR = WA_PRGEN-GUID_PR.
WA_FINAL-ATTR20A = WA_PRGEN-ATTR20A.
WA_FINAL-ATTR05A = WA_PRGEN-ATTR05A.
WA_FINAL-ATTR05B = WA_PRGEN-ATTR05B.
WA_FINAL-ATTR05C = WA_PRGEN-ATTR05C. " + DG1K902190
WA_FINAL-ATTR10A = WA_PRGEN-ATTR10A.
READ TABLE T_V_TCAV201 INTO WA_V_TCAV201 WITH KEY ATTRV20 = WA_PRGEN-ATTR20A BINARY SEARCH.
IF SY-SUBRC = 0.
WA_FINAL-TEXT1 = WA_V_TCAV201-TEXT1. "SUBID-TEXT1
ENDIF.
READ TABLE T_PNTPR INTO WA_PNTPR WITH KEY GUID_PR = WA_PRGEN-GUID_PR BINARY SEARCH.
IF SY-SUBRC = 0.
WA_FINAL-PRVSY = WA_PNTPR-PRVSY. "PROD NO
WA_FINAL-GRVSY = WA_PNTPR-GRVSY. "LOGICAL SYS GROUP
ENDIF.
append wa_final to t_final.
endloop. -
Field symbols and READ TABLE with system code 4
Hi,
I have a hashed table and I am using field symbols to point to it to retrieve the field content. I then use it in the READ TABLE statement in the following way:
Loop at x_data assign <fs>.
ASSIGN COMPONENT 'xxx' OF STRUCTURE <fs> TO <c1>.
ASSIGN COMPONENT 'xxx' OF STRUCTURE <fs> TO <c2>.
READ TABLE ZZZZ assign <fs> with table key a1 = <c1>
a2 = <c2>.
If sy-subrc = 0.
endif.
I ran the debugger and I keep getting a 4. I am not able to get the value from a1 and a2 to see what it is and why it is causing a 4 sy-subrc. I know the value from the hashed table and the values c1 and c2 are the same, so the sy-subrc should be 0.
How would I read a hashed table using field symbols? I know that usig a standard table, I have to sort the table on the key fields() before I actually can do the READ TABLE using the binary search.
Please advise. Thanks
RTHai Rob
Go through the following Code
Field-Symbols are place holders for existing fields.
A Field-Symbol does not physically reserve space for a field but points to a field, which is not known until run time of the program.
Field-Symbols are like Pointers in Programming language C .
Syntax check is not effective.
Syntax :
Data : v1(4) value abcd.
Field-symbols <fs>.
Assign v1 to <fs>.
Write:/ <fs>.
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING <FS>.
<FS>-COL2 = 100.
READ TABLE ITAB WITH TABLE KEY COL1 = 3 ASSIGNING <FS>.
DELETE ITAB INDEX 3.
IF <FS> IS ASSIGNED.
WRITE '<FS> is assigned!'.
ENDIF.
LOOP AT ITAB ASSIGNING <FS>.
WRITE: / <FS>-COL1, <FS>-COL2.
ENDLOOP.
The output is:
1 1
2 100
4 16
Thanks & regards
Sreenivasulu P -
Read statement with key syntax
Hi all,
In read statement, is there a possibility to use 'contains string (CS)' instead of '=' in with key?
I have a requirement to fetch from an internal table, the record whose field1 value contains a particular string.
Thanks,
David.HI
it won't accept CS in read table clause. syntax error will be displayed.
for more clarity just execute the falloing code.
DATA: BEGIN OF ITAB OCCURS 0,
MATNR LIKE MARA-MATNR,
ERSDA LIKE MARA-ERSDA,
ERNAM LIKE MARA-ERNAM,
END OF ITAB.
SELECT MATNR
ERSDA
ERNAM
FROM MARA
INTO TABLE ITAB
WHERE ERNAM = 'BOHNSTEDT'.
IF SY-SUBRC EQ 0.
SORT ITAB BY MATNR ASCENDING.
READ TABLE ITAB WITH KEY MATNR CS '3'.
IF SY-SUBRC EQ 0.
WRITE: ITAB.
ENDIF.
ENDIF. -
Pros and cons of creating a table with key
Hi Folks
I have some tables where there is no key defined in the source system. What is the best way to build such tables. In my case the source system is Teradata.
I have 25-30 columns in dimension and what is the best way to load this data where there is no.
What will be the Pros and Cons if I have a table without a key or if I create a table with 25-30 keys.
regards
PoonamI recently purchased a Mac Mini and am using it with my TV. Here's what I found:
Using the HDMI connection on the Mac Mini, the image on the TV is very harsh. It's very bright, high contrast and garish colors. I did a lot of testing and am convinced this is due to the HDMI Display Profile in OS X Yosemite. I could not find any way to change the display profile in the Mac Mini as long as HDMI was the connection.
Using the miniDisplayport/Thunderbolt connection on the Mac Mini, with the Apple miniDisplayPort-DVI adapter and a DVI-HDMI cable the picture is perfect. (Note, however, that this connection only carries video; if you want audio you will have to use a separate cable to connect the Mac Mini audio line out port to your TV's audio line in port.)
That said, the larger the TV the less quality you will have displaying text. I suggest using a 21" or smaller TV as a monitor if you will be doing text work.
My setup is with a 40" Sony Bravia 1080p HDTV and the primary use is for video (concerts, movies, Skype, etc), not office apps. As I said earlier, the picture is perfect - brightness, contrast, colors, resolution are as nice as I could ask for. -
Hi,
can i write a Read table like for example,
read table itab into wa_itab with key matnr ne '4'.
as its giving me an error.
can suggest any other way to write the Read Table statement.
Thanks in advance.
RobertHi,
it is not possible.
try this way..
"delete the material which is not equal to 4 ..now itab contains values matnr ne4
delete table itab where matnr ne '4'.
or
loop at itab into wa_itab wher matnr ne '4'.
"move to another table
endloop.
or
loop at itab into wa_itab .
if wa_itab-matnr ne '4'.
continue
"move to another table
else.
delete itab index sy-tabix.
endif.
endloop.
prabhudas -
I would like to have this in my report in ABAP 7:
READ TABLE ti_prococolos WITH KEY
protocol = lc_protocol
status = 'abc'
status = 'ced'.
But I receive the following error, when verifying the syntax:
Key field "STATUS" has been used more than once. This is not allowed .
How can I solve this?
Thanks!The READ statement is used to read a specific row of the internal table, in this case it appears that you are saying that you want a record if the STATUS is either abc or def. You can't do that with the READ. You would need to use the LOOP.
Loop at ti_prococolos where protocol = lc_protocal
and ( status = 'abc' or status = 'ced' ).
* do what ever here, and EXIT after since you only want one row.
EXIT.
endloop.
Regards,
RIch Heilman -
Hi,
How can I modify this Read statement as Read with same
keys is not allowed.
DATA: BEGIN OF itab OCCURS 0,
matnr LIKE marc-matnr,
werks LIKE marc-werks,
steuc LIKE marc-steuc,
END OF itab.
wgc_werk = 'BR10',
wgc_werk1 ='BR20'.
READ TABLE itab WITH KEY matnr = it_mvke-matnr
werks = wgc_werk
werks = wgc_werks1
BINARY SEARCH.Hi,
You are trying to use read statement inorder to fetch a single record isn't it? if you are trying to search for a record having either
WERKS = 'BR10' or WERKS = 'BR20' then you need to modify your code.
i.e. as below
DATA: BEGIN OF itab OCCURS 0,
matnr LIKE marc-matnr,
werks LIKE marc-werks,
steuc LIKE marc-steuc,
END OF itab.
wgc_werk = 'BR10'.
wgc_werk1 ='BR20'.
READ TABLE itab WITH KEY matnr = it_mvke-matnr
werks = wgc_werk.
if sy-subrc ne 0.
READ TABLE itab WITH KEY matnr = it_mvke-matnr
werks = wgc_werk1.
if sy-subrc eq 0.
"your post reading process here
endif.
endif.
BINARY SEARCH.
Reward points if this helps,
Kiran -
How to update database table with key field?
Hello Experts,
I have a database table with following fields
MATNR - Key
SSOUR - Key
KUNNR - Key
MENG1
MENG2
MENG3
And this table contains records like...
MSD50001 R 1000001 5.30 2.30 5.25
MSD50002 R 1000002 5.30 2.30 5.25
MSD50003 R 1000003 5.30 2.30 5.25
MSD50005 R 1000004 5.30 2.30 5.25
MSD50004 R 1000005 5.30 2.30 5.25
I have an internal table with same fields of above database table.
MSD50001 A 1000001 5.30 2.30 5.25
MSD50002 A 1000002 5.30 2.30 5.25
MSD50003 A 1000003 5.30 2.30 5.25
MSD50005 A 1000004 5.30 2.30 5.25
MSD50004 A 1000005 5.30 2.30 5.25
MSD50006 A 1000006 5.30 2.30 5.25
I want to update the DB table with following internal table records.
If internal table records = db table records are same then Update....else insert from internal table to db table.
But here, SSOUR is key field so i am not able to use
MODIFY dbtab from itab.
It results me , entries in internal table are inserted into db table.
So i have double records.
Is there any statement which updates the key field? and if no fields in db table then insert it?
Regards
RHhi,
u cannot update akey field.u can update only non key fields by using key field as a selection criteria.For example if u go to sm30 if u enter any table for inserting values, the key field will always be greyed out it is not succumbed to chnges.but u can insert value into ,if ur inserting and in the insert staemnet if u have key field which is already present in the table it will return sy-subrc = 4 otherwise it will insert the record and return 0.
eg for update :
UPDATE zdm_wtyprof SET upload_status = 'S'
WHERE spart = wa_upd-spart.
here spart is the key field and it will update the status field in the table as S.
if updated succesfully it will return 0.
SIMILARLY U CAN USE select.
Maybe you are looking for
-
I have received this message several times through CFERROR. The cause of this output exception was that: ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error. How can I fix this?
-
Hi, I'm trying to load contents to BAM via the BAM WS. I am using SOAP UI and used this service - http://localhost:8888/OracleBAMWS/WebServices/DataObjectOperationsByName. I used the payload below. <soap:Envelope xmlns:soap="http://schemas.xmlsoap.or
-
Finding authorization problems in iTunes
Well I was certainly blindsided by this. First, I am the only user on this machine and have never plugged another device into it. I decided to sync my new 3GS to iTunes. At the end of my 5500 song sync I get the message 30 songs could not be transfer
-
Hi, Can anybody explain the significnace of these.... ls_layout-get_selinfos = 'X'. ls_layout-info_fieldname = 'COLOR'. ls_layout-detail_popup = 'X'. ls_layout-detail_initial_lines = 'X'. ls_layout-coltab
-
ORA-00904 while reading from Excel with ODI
Hi all I'm trying to read data from some simple Excel files and to write the data into a 10g DB, but I get errors that don't make sense to me. Hope someone can give me an idea how I could get around them. For some files the transfer works as expected