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.

Similar Messages

  • 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

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

  • Select SQL statement with variable syntax error

    Hi All,
    I am running a Web Application with a java bean to connect to a mysql database. i have compiled a test .java file whcih works using the same statement that has a problem in my web application. Taking the statement out of the Web App makes it work so it must be this stetment:
    String SQLStatement = "SELECT * FROM MASTER WHERE USERNAME LIKE '"+data+"' ";
    This works fine in testing a separate java file, but it does not compile when running ant build to compile the same line of code for my Web App.
    I have tried many possibilities of changing the syntax to no avail, its a puzzle!
    Many thanks for any swift reply.
    ChrisG

    prepare:
    copy:
    build:
    [javac] Compiling 1 source file to C:\jwsdp-1.3\garland\build\WEB-INF\classe
    s
    [javac] C:\jwsdp-1.3\garland\src\LogonBean.java:20: cannot resolve symbol
    [javac] symbol : variable data
    [javac] location: class logonApp.LogonBean
    [javac] String SQLState2 = "SELECT PASSWORD FROM MASTER WHERE PASSWORD L
    IKE '"+data+"' ";
    [javac]
    ^
    [javac] C:\jwsdp-1.3\garland\src\LogonBean.java:79: cannot resolve symbol
    [javac] symbol : variable SQLState1
    [javac] location: class logonApp.LogonBean
    [javac] rs = stmt.executeQuery(SQLState1);
    [javac] ^
    [javac] 2 errors
    Thats the compiler error, but it still works on a normal java file. ill try a prepared statement in the mean time.
    ChrisG

  • Update statement with Case syntax

    I want to put case statement in an update statement using Oracle 10g
    I'm getting a syntax error on the last line Ora-00933: SQL command not properly ended
    Help please
    UPDATE EMP a
    SET EMP.TYPE = CASE
    WHEN 'Y' = 'A' THEN 'DIV'
    WHEN 'Y' = '1' THEN 'DEF'
    END CASE;

    Hi,
    Samim wrote:
    I want to put case statement in an update statement using Oracle 10g
    I'm getting a syntax error on the last line Ora-00933: SQL command not properly ended
    Help please
    UPDATE EMP a
    SET EMP.TYPE = CASE
    WHEN 'Y' = 'A' THEN 'DIV'
    WHEN 'Y' = '1' THEN 'DEF'
    END CASE;The closing keyword that corresponds to "CASE" is "END", not "END *CASE* ".
    The string 'Y' is never equal to 'A', or to '1'.
    If you have a column named y in the table, then you might want to say:
    UPDATE EMP
    SET EMP.TYPE = CASE
                        WHEN Y = 'A' THEN 'DIV'
                        WHEN Y = '1' THEN 'DEF'
                  END;I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statemnts to re-create your emp table as it exists before the UPDATE), and the results you want from that data (that is, the contents of the emp table after the UPDATE).

  • Site System Status Error Message on SiteStat.log : SQL statement with Incorrect Syntax

    Hi Folks,
    We are getting the below system status error in the primary servers site status log (SiteStat.log) every minute. It relates to the updating of a secondary site.
    I have worked out where the SQL syntax is wrong (TimeReported=,) and that it more than likely relates to the day light saving settings last weekend on the secondary sites virtual's host which caused the secondary site server time to go way
    into the future, this has now been fixed.
    Is there anyway of removing/deleting this system status/SQL query?  I have restarted Primary, Secondary and SQL server, to no avail.
    Any help would be greatly appreciated.
    *** [42000][102][Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ','. SMS_SITE_SYSTEM_STATUS_SUMMARIZER 01/11/2012 14:45:58 5756 (0x167C)
    ---->: Could not execute the SQL command:
    UPDATE Summarizer_SiteSystem SET Status=0,SiteCode='001',SiteSystem='["Display=\\SERVER\"]MSWNET:["SMS_SITE=001"]\\SERVER\',SiteObject='["Display=\\SERVER\D$\SCCM\"]MSWNET:["SMS_SITE=001"]\\SERVER\D$\SCCM\',ObjectType=0,Role='SMS Component 847496,DownSince=NULL,Replicate=1,PercentFree=76,WarnLevel=102400,ErrorLevel=51200,TimeReported=,AvailabilityState=4
    WHERE SiteCode='001' AND SiteSystem='["Display=\\SERVER\"]MSWNET:["SMS_SITE=001"]\\SERVER\' AND SiteObject='["Display=\\SERVER\D$\SCCM\"]MSWNET:["SMS_SITE=001"]\\SERVER\D$\SCCM\' AND Role='SMS Component Server' AND ObjectType=0. Will try again in 60 seconds. SMS_SITE_SYSTEM_STATUS_SUMMARIZER 01/11/2012
    14:45:58 5756 (0x167C)
    ---->: Clearing lost SQL connection and reinitializing it SMS_SITE_SYSTEM_STATUS_SUMMARIZER 01/11/2012 14:46:58 5756 (0x167C)
    Thanks
    JTeQ

    Yes, I know this is an old post, but I’m trying to clean them up.
    There is not supported way to fix this. As such I recommend that you contract CSS directly, they will work with you to solve this problem.
    Garth Jones | My blogs: Enhansoft and
    Old Blog site | Twitter:
    @GarthMJ

Maybe you are looking for

  • Parse xml file

    Hi, Is there any way to get the attributes of the tag. For eg: <Exam Name="xxx" Id="3"> <\Exam> i need the attributes of the exam tag. (i.e) name and id

  • In-Browser Editing Sync Issue - Muse CC 2014

    I'm hosting on a third party solution and encountered this problem. I made a few minor edits to the page at http://www.fresnoincomeproperties.com/listings.html with IBE. Changes were processed and accepted on the live page without issue. When I go ba

  • Strange measurement input fields behaviour

    Hello, I have a Czech version of Illustrator CC on Windows 7 Pro. Some measurement input fields are not working as expected, for example: When creating a new document: Decimal marks in document dimensions have disappeared (instead 210.00 mm it shows

  • LED notification

    Excuse the pathetically simple question but the led on my phone does not flash when I have missed a call. I have set up the notification profile for led flashing but it doesn't!!!!! Please help this is driving me mad, I only use my phone for calls an

  • How do you add meta tags to your website in Iweb

    I have always created websites in frontpage where you can add meta tags to help search engines find the website.   How do you add meta tags to the Iweb website I have created?