Regardin read statement

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 solution

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

Similar Messages

  • Logical expression( = , =, , ) in read statement

    Hi All,
    Is it possible to use the logical expressions like (<= , >=, <, >) in the read statement?

    While you can only use "=" with the READ statement, you can use the READ statement to position the cursor at the first record you want and then use the LOOP with your operators to get only those records you want (assuming standard tables that have been correctly sorted). This can be very efficient.
    There have been many discussion about this in the forums. Please search and you'll see them.
    Rob

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

  • 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

  • Error: unexpected XML reader state. expected: END but found: START:

    I am getting following error while invoking method 'GetVersionInfo' (.net web service over dll) which takes one input parameter(string) and gives two output parameters(both short):
    ERROR at line 1:
    ORA-29532: Java call terminated by uncaught Java exception: deserialization
    error: unexpected XML reader state. expected: END but found: START:
    {UPPLink}pnVersionMajor
    ORA-06512: at "SYS.UTL_DBWS", line 388
    ORA-06512: at "SYS.UTL_DBWS", line 385
    ORA-06512: at line 40
    Expected Request is as follows:
    POST /UPPLink/UPPLink.asmx HTTP/1.1
    Host: 172.16.1.38
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "UPPLink/GetVersionInfo"
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
    <GetVersionInfo xmlns="UPPLink">
    <ignore>string</ignore>
    </GetVersionInfo>
    </soap:Body>
    </soap:Envelope>
    EXpected Response is as follows:
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
    <GetVersionInfoResponse xmlns="UPPLink">
    <GetVersionInfoResult>
    <pnVersionMajor>short</pnVersionMajor>
    <pnVersionMinor>short</pnVersionMinor>
    </GetVersionInfoResult>
    </GetVersionInfoResponse>
    </soap:Body>
    </soap:Envelope>
    The PL/SQL code I am using is as follows:
    DECLARE
    service_ sys.utl_dbws.SERVICE;
    call_ sys.UTL_DBWS.call;
    service_qname sys.utl_dbws.QNAME;
    port_qname sys.utl_dbws.QNAME;
    operation_qname sys.utl_dbws.QNAME;
    string_type_qname sys.utl_dbws.QNAME;
    number_type_qname sys.utl_dbws.QNAME;
    retx ANYDATA;
    strEntry VARCHAR2(100);
    retx_string VARCHAR2(100);
    majorVersion NUMBER;
    minorVersion NUMBER;
    params sys.utl_dbws.ANYDATA_LIST;
    v_outputs sys.utl_dbws.anydata_list;
    BEGIN
    dbms_output.put_line('Starting Function');
    service_qname := sys.utl_dbws.to_qname(null, 'UPPLink');
    strEntry := 'vab';
    dbms_output.put_line('Creating Service');
    service_ := sys.utl_dbws.create_service(HTTPURITYPE('http://172.16.1.38/UPPLink/UPPLink.asmx?WSDL'), service_qname);
    dbms_output.put_line('Creating Operation');
    operation_qname := sys.utl_dbws.to_qname(null, 'GetVersionInfo');
    dbms_output.put_line('Calling Service');
    call_ := sys.utl_dbws.create_call(service_, null, operation_qname);
    sys.utl_dbws.set_property(call_, 'SOAPACTION_USE', 'true');
    sys.utl_dbws.set_property(call_, 'SOAPACTION_URI', 'UPPLink/GetVersionInfo');
    sys.utl_dbws.set_property(call_, 'OPERATION_STYLE', 'rpc');
    string_type_qname := sys.utl_dbws.to_qname('http://www.w3.org/2001/XMLSchema', 'string');
    number_type_qname := sys.utl_dbws.to_qname('http://www.w3.org/2001/XMLSchema', 'short');
    sys.utl_dbws.add_parameter(call_, 'ignore', string_type_qname, 'ParameterMode.IN');
    sys.utl_dbws.add_parameter(call_, 'pnVersionMinor', number_type_qname, 'ParameterMode.OUT');
    sys.utl_dbws.set_return_type(call_, number_type_qname);
    params(0) := ANYDATA.convertvarchar2(strEntry);
    dbms_output.put('Invoking with Input Parameter: ');
    dbms_output.put_line(ANYDATA.ACCESSVARCHAR2(params(0)));
    retx := sys.utl_dbws.invoke(call_, params);
    dbms_output.put_line('Invoke complete');
    majorVersion := retx.accessnumber;
    dbms_output.put_line('Major Version ' || majorVersion);
    v_outputs := SYS.utl_dbws.get_output_values(call_);
    minorVersion := ANYDATA.AccessNumber(v_outputs(1));
    dbms_output.put_line('Minor Version ' || minorVersion);
    sys.utl_dbws.release_service(service_);
    END;
    /

    Actually, the name needs to match what is specified in the WSDL file.

  • M or P master data table  to be used in routine read statement

    Hi
      I update of a DSO i had a requirment for a routine to get the Attribute of a Infoobject.
      So which master data table  M or P table i need to use in my read statement and why
    Thanks

    Use M table as it it the view on time dependent(P table) and time independent(Q table) tables.
    M table is view on time dependent and time independent attributes, you can see characteristic values and all the attributes for the Characteristic.
    The tables that go in the view are the Master Data Table and the Time-Dependent Master Data Table. If the characteristic only has time-dependent attributes, only the time-dependent master data table goes in. If the characteristic has only non-time-dependent attributes, only the master data table goes in.

  • Problem in read statement

    hi,
    my code is ;
    select vbeln audat kunnr auart
            from vbak
            into table  t_vbak2
            for all entries in t_vbfa2
            where vbeln = t_vbfa2-vbelv
            and audat in r_daterange
            and kunnr = partner_number.
            if not t_vbak2[] is initial.
              sort t_vbak2 by vbeln audat auart.
            endif.
    now if i use read statement :
    read table t_vbak2 into wa_vbak2
            with key  vbeln = wa_vbfa1-vbelv
                      audat in r_daterange
                      kunnr = partner_number binary search.
    i get a syntax error.
    can any one help me with this..
    Thanks,
    Challa.

    You can't use the IN operator in your READ statement, only  =  as you are trying to read with key.  In your case, you must use the LOOP statement.
    Loop at t_vbak2 into wa_vbak2
              where vbeln = wa_vbfa1-vbelv
                 and audat in R_daterange
                 and kunnr = Partner_Number.
    * Do whatever you need to do
    Exit.   " This is so you only read one record.
    Endloop.
    Regards,
    RIch Heilman

  • 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

  • Internal table Read statement

    Hi,
    AM using Read statement to read internal table as below.
    Read itab into wa with key x = y.
    if sy-subrc eq 0.
    do some thing.
    endif.
    However the work area wa is not useful to me in my program. when am doing extended check it is issueing warning saying wa is not used. HOW TO CLOSE THIS WARNING.
    Regards,
    AAkash

    just before read statement do
    CLEAR WA.
    This should remove the error.
    Cheers
    VJ

  • Read statement in internal table.

    PLease help me to figure out what a read statement does???
    Please show me through examples how a read statements selects data from a table ,,,puts into internal table & finally we are able to read it through work area????
    thanx... <REMOVED BY MODERATOR>
    Edited by: Alvaro Tejada Galindo on Mar 10, 2008 7:27 PM

    Hey saswat ,
       just wanted to give a simplified example of ur query , if not understood please ask
    REPORT  Z_PRGM_TRY_READ NO STANDARD PAGE HEADING.
    TABLES : MARA , MARD.
    SELECT-OPTIONS : S_MATNR FOR MARA-MATNR.
    TYPES : BEGIN OF LT_MARA ,
            MATNR LIKE MARA-MATNR ,
            ERSDA LIKE MARA-ERSDA ,
            MBRSH LIKE MARA-MBRSH ,
            END OF LT_MARA .
    DATA : TT_MARA TYPE STANDARD TABLE OF LT_MARA INITIAL SIZE 0 ,
           WA_MARA TYPE LT_MARA .
    TYPES : BEGIN OF LT_MARD ,
            MATNR LIKE MARD-MATNR ,
            WERKS LIKE MARD-WERKS ,
            LGORT LIKE MARD-LGORT ,
            PSTAT LIKE MARD-PSTAT ,
            END OF LT_MARD.
    DATA : TT_MARD TYPE STANDARD TABLE OF LT_MARD INITIAL SIZE 0 ,
           WA_MARD TYPE LT_MARD.
    TYPES : BEGIN OF LT_FINAL ,
            MATNR LIKE MARA-MATNR ,
            ERSDA LIKE MARA-ERSDA ,
            MBRSH LIKE MARA-MBRSH ,
            WERKS LIKE MARD-WERKS ,
            LGORT LIKE MARD-LGORT ,
            PSTAT LIKE MARD-PSTAT ,
            END OF LT_FINAL .
    DATA : TT_FINAL TYPE STANDARD TABLE OF LT_FINAL INITIAL SIZE 0 ,
            WA_FINAL TYPE LT_FINAL .
    SELECT MARA~MATNR
           ERSDA
           MBRSH
           INTO CORRESPONDING FIELDS OF TABLE TT_MARA FROM MARA WHERE  MARA~MATNR IN S_MATNR .
    SELECT MARD~MATNR
           WERKS
           LGORT
           PSTAT
           INTO CORRESPONDING FIELDS OF TABLE TT_MARD FROM MARD
           FOR ALL ENTRIES IN TT_MARA
           WHERE MATNR = TT_MARA-MATNR.
    LOOP AT TT_MARA INTO WA_MARA.
    READ TABLE TT_MARD INTO WA_MARD WITH KEY MATNR  = WA_MARA-MATNR .
    IF SY-SUBRC = 0.
    WA_FINAL-MATNR = WA_MARA-MATNR .
    WA_FINAL-ERSDA = WA_MARA-ERSDA.
    WA_FINAL-MBRSH = WA_MARA-MBRSH.
    WA_FINAL-WERKS = WA_MARD-WERKS.
    WA_FINAL-LGORT = WA_MARD-LGORT.
    WA_FINAL-PSTAT = WA_MARD-PSTAT.
    APPEND WA_FINAL TO TT_FINAL.
    CLEAR WA_FINAL.
    ENDIF.
    ENDLOOP.
    LOOP AT TT_FINAL INTO WA_FINAL.
    WRITE : / WA_FINAL-MATNR , WA_FINAL-ERSDA , WA_FINAL-MBRSH , WA_FINAL-WERKS ,
               WA_FINAL-LGORT , WA_FINAL-PSTAT.
    ENDLOOP.

  • Read statement in abap

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

    Hi *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.

  • Read  statement in ECC6.0

    Hi all,
    I am working on ECC6.0 , but when i use Read statement it gives me erro that it is obsolute in ECC6.0.
    So please suggest a way to proceed.
    Regards,
    Nilesh

    Hi Nilesh,
    READ statement is NOT Obsolete in ECC 6.0. It is very much in use. I think the syntax that you used might not be correct. Kindly verify with below syntax..
    READ TABLE itab INTO ls_itab WITH KEY (Key fields) BINARY SEARCH.
    WITH KEY
    can be used or
    WITH INDEX
    can also be used..
    <b>Reward points for helpful answers</b>.
    Best Regards,
    Ram.

  • Can't I use Field NE SPACE in READ statement ?

    What is wrong with the below statments 
    READ TABLE t_zdadp_rpt WITH TABLE KEY t_zdadp_rpt-zdesc NE SPACE.
       READ TABLE t_zdadp WITH TABLE KEY zdesc NE SPACE.
    Could you pleae help

    Hi,
    In the first statement u have to specify only field name also in read statement no need for table key its just key..U cannot use NE symbol for read statement.
    READ TABLE t_zdadp_rpt WITH TABLE KEY t_zdadp_rpt-zdesc NE SPACE.
    READ TABLE t_zdadp WITH TABLE KEY zdesc NE SPACE.
    plz correct the code like this
    READ TABLE t_zdadp WITH  KEY zdesc Eq SPACE.
    if sy-subrc ne 0.
    do what ever u want.
    endif.
    reward if helpful.
    Regards,
    nagaraj

  • Can we use more than one or in read statement

    READ TABLE itab_return INTO wa_return
                  WITH KEY type = 'E' or
                                          = 'i'.

    hi.
    No u cannot use 'and' or 'or' in read statement.
    you can do as
    FOR AND condition
    read table itab into wa with key  type  = 'I'.
    if sy-subrc = 0.
    read table itab into wa with key  type  = 'E'.
    endif.
    FOR OR condition
    read table itab into wa with key  type  = 'I'.
    read table itab into wa with key  type  = 'E'.
    if sy-subrc = 0.
    <code>
    endif.
    regards
    prasanth

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

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

Maybe you are looking for