Read Statement with key

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

Similar Messages

  • 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.

  • 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,
    Murthy

    try 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.

  • 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

  • Issue with read statement with one more key missing in mapping

    Hi All ,
    I have such data in two internals table :
    IT_bdc
    vbeln            posnr
    90000593     10
    90000576     10
    90000672     10
    90000672     20
    90000672     30
    it_konv
    kbetr          vbeln
    6250          90000576
    12160000          90000593
    500000          90000672
    600000          90000672
    700000          90000672
    My current program statement is :
    LOOP AT it_bdc.
    READ TABLE it_konv WITH KEY
          vbeln = it_bdocs-vbeln.
      currency =   it_konv-waers.
    endloop.
    as you can see the posnr is missing in it_konv how can i modify this read statement so
    that vbeln posnr from it_bdc should get correct kbetr from it_konv.
    Kindly help in this mapping.

    Hi
    sort it_konv by vbeln
    then
    loop at it_bdc.
    read table it_konv with key vbeln = it_bdc-vbeln binary search.
    if sy-subrc = 0.
    perform your logic/task.
    endif.
    endloop.
    also it depends what you want to do after reading it_konv.
    in my logic if there is a vbeln in it_konv which s present in it_bdc then sy-subrc will be 0
    and you can perform your logic.
    and if there will be no matching vbeln in it_konv then sy-subrc will not be 0.
    check the values in debugging.
    Thanks
    Lalit

  • 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
    Sanu

    Hi,
    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

  • Read Statement with Single key with multiple values

    Dear Friends,
    In ECC 4.6c, I wrote statement like this.
    Read table message with key type = 'E' or 'S'.
    if sy-subrc = 0.
    Populated the message log to output internal table.
    endif.
    But when i transported to QA which is ECC 6.0, it is giving error.
    Can any one help me in modifying this qurey.
    Plse read my question thoroughly and reply me back.
    Regards,
    Santosh Kumar M

    Hi,
    You can't use OR condition with READ table. it is always AND condition.
    Here 2 ways for ur problem.
    If u want to have just one message in the log then use multiple reads.
    READ TABLE message WITH KEY type = 'E'.
    If sy-subrc IS INITIAL.
    populate log.
    ELSE.
    READ TABLE message WITH KEY type = 'S'.
    If sy-subrc IS INITIAL.
    populate log.
    ENDIF.
    ENDIF.
    If u want all messages then u have to loop through and populate the log as sugested by Vijay but
    Without exit in loop.(Since u need all the messages)
    LOOP AT message into wa WHERE type = 'E' or type = 'S'.
    populate log.
    ENDLOOP.
    Thanks,
    Vinod.

  • READ statement with dynamic key

    Can i READ a dynamic table with a dynamic key combination?
    READ TABLE <dyn_sel_table>
      INTO       <dyn_sel_wa>
      WITH KEY   ? .

    yes i guess u can do it
    READ TABLE <dyn_sel_table>
    <b>ASSIGNING</b> <dyn_sel_wa>
    WITH KEY <field1> eq ...

  • 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

  • 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,
    John

    Hi 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,
    Matt

    Refer to example link below:
    http://sap.ittoolbox.com/groups/technical-functional/sap-dev/read-deep-structure-736023.
    Regards,
    Venkat.

  • Read statement with duplicate key fields

    Hello,
    I have an internal table(EKBE) with 8 fields
    ebeln ebelp vgabe gjahr belnr budat wrbtr refkey
    populating the first 7 fields from EKBE table with VGABE = 2 and PO#, concatenating the WRBTR and GJAHR to get the Refkey and passing this to the 8th field.
    Using this refkey, getting the document numbers from BKPF.
    I am looping another internal table into a work area and reading the above internal table by passing the ebeln field and I am doing some calculations ,etc.
    A custom table is getting updated from the above work area.
    The issue is-
    The internal table EKBE can have the same PO numbers with the same line item numbers but with different ref key's.
    So, when I am reading the int. tab, it is reading only one record, since I have no other key's to read except EBELN. So for one PO# it is reading only 1 ref key, I cannot use the line item# as a key, as the line item#'s never match, even if they match they could be same PO# with same line item# and different ref key.
    Any inputs highly appreciated.
    Regards,
    Kiran

    Loop on EKBE Internal table as well to fetch all entries of PO. Use Parallel cursor to optmize performance.
    http://wiki.sdn.sap.com/wiki/display/Snippets/ABAPCodeforParallelCursor-Loop+Processing

  • Problem with READ Statement in the field routine of the Transformation

    Hi,
    I have problem with read statement with binary search in the field routine of the transformation.
    read statement is working well when i was checked in the debugging mode, it's not working properly for the bulk load in the background. below are the steps i have implemented in my requirement.
    1. I selected the record from the lookuo DSO into one internal table for all entried in source_packeage.
    2.i have read same internal table in the field routine for each source_package entry and i am setting the flag for that field .
    Code in the start routine
    select source accno end_dt acctp from zcam_o11
    into table it_zcam
    for all entries in source_package
    where source = source_package-source
         and accno = source_package-accno.
    if sy-subrc = 0.
    delete it_zcam where acctp <> 3.
    delete it_zcam where end_dt initial.
    sort it_zcam by surce accno.
    endif.
    field routine code:
    read table it_zcam with key source = source_package-source
                                                 accno  = source_package-accno
                                                 binary search
                                                 transportin no fields.
    if sy-subrc = 0.
    RESULT  = 'Y'.
    else.
    RESULT = 'N'.
    endif.
    this piece of code exist in the other model there its working fine.when comes to my code it's not working properly, but when i debug the transformation it's working fine for those accno.
    the problem is when i do full load the code is not working properly and populating the wrong value in the RESULT field.
    this field i am using in the report filter.
    please let me know if anybody has the soluton or reason for this strage behaviour.
    thanks,
    Rahim.

    i suppose the below is not the actual code. active table of dso would be /bic/azcam_o1100...
    1. is the key of zcam_o11 source and accno ?
    2. you need to get the sortout of if endif (see code below)
    select source accno end_dt acctp from zcam_o11
    into table it_zcam
    for all entries in source_package
    where source = source_package-source
    and accno = source_package-accno.
    if sy-subrc = 0.
    delete it_zcam where acctp 3.
    delete it_zcam where end_dt initial.
    endif.
    sort it_zcam by surce accno.
    field routine code:
    read table it_zcam with key source = source_package-source
    accno = source_package-accno
    binary search
    transportin no fields.
    if sy-subrc = 0.
    RESULT = 'Y'.
    else.
    RESULT = 'N'.
    endif.

  • 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...

  • For a READ TABLE how to build a dynamic WITH KEY condition?

    Hi All,
    I have a Z table with 6 fields. The first field is the Plant and is the key field. This field can be matched with the field from selection screen. Now I have 4 character fields which can contain various values. Now I have another field at the end of the table and this field is the one which I will need for further processing.
    Now this last field will be selected based on the data for first 5 fields.
    This Read is performed in a loop and the data for all the 4 character fields may not be present.
    Now my problem is how to build a Read statement for this table where I need to get the value of the Last field based on the values of first 5 fields?

    Hi,
        Use
    IF    you have internal table With header line then use
          REad Tablename  with key  field1 = value1   field2 = value2      field3 = value3        field4 = value4    field5 = value5.
      If sy-subrc = 0.
    endif.
    if  you have internal table WithOut header line then use
         REad Tablename into workArea  with key  field1 = value1   field2 = value2      field3 = value3        field4 = value4    field5 = value5.
      If sy-subrc = 0.
    endif.
    regards,
    Amit

Maybe you are looking for

  • Address Matching Using Oracle Text

    Hi, I am a newbie to Oracle Text. Hence please pardon my ignorance if this is a "RTFM" Query. We would like to clash our customer addresses against a table (GEO) that has addresses and geographic coordinates (latitude, longitude etc). The customer ad

  • Regarding BAPI_ENTRYSHEET_CREATE .

    Hi All, We are trying to create Service entry sheet using BAPI_ENTRYSHEET_CREATE using the follwonig code: DATA: wa_header TYPE bapiessrc,   i_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE,   ws_entrysheet_no TYPE bapiessr-sheet_no,   i_service TYPE

  • The best surround sound solution for my room?

    I have a 32" HDTV but the speakers seem to be weak to my ears. I'm looking to get a few speakers and a receiver for my bedroom but have no idea on what exactly I should get. My T.V. sits in front of my bed on my dresser with my PS3 next to it. I thou

  • FEBAN change of document type

    Hi Fi guys, Can anyone tell me if is is possible to change the document type, when posting from FEBAN ?. It is possibe ein FEBA, but I cannot find the way to do it in FEBAN. Please adcvice, thanks Best regards Pernille

  • I have a MacBook Pro with OS 10.8.5.  If I update to Mavricks will I be able to run Microsoft Office for Home 2008?

    I have a MacBook Pro running OS 10.8.5.  If I upgrade to Mavricks will I still be able to run Microsoft Office for Home?