Condition 'or'  on  a read table

you can put a condition or the key of a table read
example.
    READ TABLE i_bsid ASSIGNING <f_bsid>
                       WITH  KEY kunnr = <f_zppo>-kunrg
                                belnr = <f_zppo>-belnr
                                bldat = <f_zppo>-zpda_von.
this instruction with 'OR'

No !!! U Cant
instead some thing like this
READ TABLE i_bsid ASSIGNING <f_bsid>
WITH KEY kunnr = <f_zppo>-kunrg.
if sy-subrc ne 0.
READ TABLE i_bsid ASSIGNING <f_bsid>
WITH KEY belnr = <f_zppo>-belnr.
if sy-subrc ne 0.
READ TABLE i_bsid ASSIGNING <f_bsid>
WITH KEY bldat = <f_zppo>-zpda_von.

Similar Messages

  • Read table and checking condition in PAI

    Hi,
    I have a requirement where I need to check and compare with (Custom table) Bankn with Partner Bank`s bankn.
    I have wrote a code in PAI like this.
    MODULE CHECK_BANKN INPUT.
       Data: l_bankn like (Custom table)-bankn.
       select bankn from (Custom Table) into l_bankn
           where recno = g_recno.
       IF NOT g_head-bankn IS INITIAL.
      Read table i_bvtyp with key bankn = i_bvtyp-bankn .
         IF l_bankn <> i_bvtyp-bankn.--------->" Comparison of (custom table) Bankn with internal table I_BVTYP-BANKN
           MESSAGE w022 WITH text-w06.
         ENDIF.
       ENDIF.
    ENDMODULE.
    My Read Table statement is seems to be wrong and my checking condition is also wrong.
    So, how to resolve this?
    regards,
    Kiran

    Hi Kiran,
    If you observe your read statement, you are comparing the field with it's own table field.
       Read table i_bvtyp with key bankn = i_bvtyp-bankn .
    Untill unless you read I_BVTYP, i_bvtyp-bankn will be initial and you cannot find the matching record with Null-Value.
    So, I think you need compare with l_bankn.
       Read table i_bvtyp with key bankn = i_bankn .
    Then you can directly raise a message using SY-SUBRC value.
       Read table i_bvtyp with key bankn = i_bankn
          if SY-SUBRC <> 0 .
              <MESSAGE>    
         endif.
    Regards,
    Vijay

  • Read Table with condition

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

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

  • Conflict: READ TABLE itab2 INDEX 1 vs  Modify itab1 from index sy-tabix

    The below simple code is for each itab1 line, create a new itab2 by using select statement, and then grab the max value of field f in itab2 and fill it into a corresponding field in itab1.
    However the statement:
    READ TABLE itab2 into gs_itab1 INDEX 1.
    causes the conflict with our another statement in the end of itab1 loop:
    Modify itab1 from gs_itab1 index sy-tabix.
    that the below Modify statement always modify itab1 at 1st row and also causes an unlimited loop that the program is hung up. Our code looks as the following:
    Loop AT itab1 into gs_itab1.
             use Select statement to fill in itab2...
             SORT itab2 BY f DESCENDING. "f is a field of itab2
             READ TABLE itab2 into gs_itab1 INDEX 1.
             Modify itab1 from gs_itab1 index sy-tabix.
    EndLoop.
    However the last two lines of statements in the itab1 loop causes the program hang!
    Any solution?
    Thanks in advance!

    Hi,
    I got confused while going thru the code...
    according to code
    first u loop itab1 and get tht in gs_itab1 and then a select query to get data from some table and store in itab2.
    Here are u using any where condition, if yes u may probably check aganst gs_itab1 rite? if yes
    first suggestion...why cant u put the select statement above the loop and get all the values to an internal table and then read the internal table in the loop stmt. Yes i can see u r sorting it based on some 'f'..just a suggestion
    Now here can u follow this code...
    Loop AT itab1 ASSIGNING <fs_itab1>,
             use Select statement to fill in itab2...
             SORT itab2 BY f DESCENDING. "f is a field of itab2
             READ TABLE itab2 into <fs_itab1> index 1.
    EndLoop.
    Please let me know if its not ok
    <REMOVED BY MODERATOR>
    Regards,
    ABAPer007
    Edited by: Alvaro Tejada Galindo on Apr 11, 2008 12:26 PM

  • Read   table and loop at

    Hi EXpert,
    I have an internal table say itab and I need to fetch a single record with some given conditions.
    Hence I have used READ table statement ,
    But on using this read table statement , I am unable to fetch the record :-(((( . It gives sy-subrc  =  4.
    And the same conditions when are put in Loop at itab  statement, then I am able to fetch the data .
    My requirement is only 1 record for the given conditions ( in where clause in case of loop at statement).
    I think I am probably missing out on some minor thing..
    <removed_by_moderator>
    Warm Regards,
    SUDHA
    Edited by: Julius Bussche on Feb 7, 2009 2:48 PM

    Hi,
    Test the following Code hope it will solve out your problem,
    PARAMETERS: key TYPE i .
    TYPES: BEGIN OF t_test,
      s_no TYPE i,
      name(15),
      END OF t_test.
    DATA: it_test TYPE STANDARD TABLE OF t_test WITH HEADER LINE.
    DO 10 TIMES.
      it_test-s_no = sy-index.
      it_test-name = 'SDN'.
      APPEND it_test TO it_test.
    ENDDO.
    READ TABLE it_test INTO it_test WITH KEY key.
    IF sy-subrc = 0.
      WRITE: 'sy-subrc = ' , sy-subrc,
             /1 it_test-s_no, 15 it_test-name.
    ELSE.
      WRITE: 'sy-subrc = ' , sy-subrc,
             / 'Sorry there is no Records with this Key'.
    ENDIF.
    Kind Regards,
    Faisal
    Edited by: Faisal Altaf on Feb 7, 2009 6:59 PM

  • Read table issue in method

    Hi,
    How can i read this table with where condition in OOPS? is it possible?
    Give some idea how to proceed?
    Inside method i have written like this.
    ret is my return parameter.
    code:
      Loop at me->s001_raw[] assigning <arr_s001>.
        read table ret[] with table key
                vkorg in me->select_parameters->SO_VKORG[]
            and ZZEMP in me->select_parameters->SO_empl[].
          assigning <arr_return>.
    Thanks

    Read will not work
    May be you can try this way
    Loop at me->s001_raw[] assigning <arr_s001>.
      loop at ret[] assigning <arr_return> where vkorg in me->select_parameters->SO_VKORG[]
                     and zzemp in me->select_parameters->SO_empl[].
        exit.
      endloop.
    endloop.

  • Hello experts read table statement is not working properly

    Hello Experts.
    my code is like this.
    sort it_matnr by matnr.
    loop at itab_result.
    read table it_matnr with key matnr = itab_result-matnr  binary search.
    endloop.
    there are nearly 2000 records in it_matnr . The records which satisfy the above condition is there here in this internal table. But it is unable to read the record which matches the condition. One thing is that , there are more than one record with the same material. ie mblnr is different but material is the same. In it_matnr table i have only 1 field ie matnr ,so i need to compare only with the matnr.I also tried by sorting it_result by matnr but of no use. Then finally I used loop at where matnr = it_result-matnr , it is working fine. But due to performance reasons we should not use this. so please tell me what to do and correct the code.

    1. Make sure that the table IT_MATNR is not getting updated inside the loop. Because it will then destroy the sorting.
    2. Secondly, if there are multiple records in IT_MATNR for the same material then it will search for the first record encountered in binary algo. So it is advisable that you may provide further filter criteria if possible. check if ITAB_RESULT & IT_MATNR have any other matching field that can be put in filter criteria.
    3.Thirdly, check if your requirement can be achieved by STABLE SORT.
    <b>SORT <itab> ... STABLE BY <f1>[ASCENDING/DESCENDING].</b>
    It will allows you to perform a stable sort, that is, the relative sequence of lines that are unchanged by the sort is not changed. If you do not use the STABLE option, the sort sequence is not preserved. If you sort a table several times by the same key, the sequence of the table entries will change in each sort. However, a stable sort takes longer than an unstable sort.
    4. Lastly, you can use parallel cursor technique of multiple loops which is given below:
    LOOP AT itab_result.
      READ TABLE it_matnr
        WITH KEY matnr = itab_result-matnr
        BINARY SEARCH.
    Process record
      LOOP AT it_matnr FROM sy-tabix.
        IF it_matnr <> itab_result-matnr.
          EXIT.
        ENDIF.
    Process record based on yuor condition
      ENDLOOP.
    ENDLOOP.

  • How will use Select-Options in Read table Concept.

    Hi All,
                  How will use Select-Options in Read table. For  example,
          Select-Options : test for bseg-prctr.
           Select * from bseg into table ITAB.
    Read table ITAB with key prctr in test.
    Last line is showing error. If any way to read ITAB as conditions given per select options.
    Thankx Advance,,,

    HI,
    you cannot use " IN " with read statement , read statement is used as:
    READ TABLE it_collect  ASSIGNING <fs_collect>
                      WITH KEY   rbpl = <fs_wkdet>-arbpl
                                 ufnr = <fs_wkdet>-aufnr.
    anyways you can use  loop at statement before read to use  " into "  statement as:
    LOOP AT it_master INTO l_master
                                           WHERE werks       = l_werks
    hope it will help you
    regards
    rahul
    Edited by: RAHUL SHARMA on Dec 30, 2008 9:14 AM

  • Need help regarding Dynamic Read Table statement

    Hello
    I know that the syntax for dymanic read table statement is
    READ TABLE  <ITAB> WITH KEY (KEY1) = VALUE1  (KEY2) = VALUE2 .....(KEYN) = VALUEN
    Here is my problem..
    I am dynamically creating an internal table based on parameter table entered by user.
    The key for this table can be determined only at runtime.
    The table entered might have by one field as key field or 10 key fields..
    How can I use the dynamic read in this situation ?
    Thanks for your help in advance,
    Santosh
    Edited by: Santosh Kulkarni on Jan 3, 2010 6:58 AM
    Edited by: Santosh Kulkarni on Jan 3, 2010 7:01 AM

    Hello Santosh,
    please check out the following solution. The program demonstrates how to use the dynamic read statement with three key field conditions. Additional key fields can be added in the same way.
    REPORT z_dynamic_read.
    DATA: gt_itab TYPE REF TO data,
          ge_key_field1 TYPE char30,
          ge_key_field2 TYPE char30,
          ge_key_field3 TYPE char30,
          go_descr_ref TYPE REF TO cl_abap_tabledescr.
    FIELD-SYMBOLS: <gt_itab> TYPE STANDARD TABLE,
                   <gs_key_comp> TYPE abap_keydescr,
                   <gs_result> TYPE ANY.
    PARAMETERS: pa_table TYPE tabname16 DEFAULT 'SPFLI',
                pa_cond1 TYPE string DEFAULT sy-mandt,
                pa_cond2 TYPE string DEFAULT 'LH',
                pa_cond3 TYPE string DEFAULT '0123'.
    START-OF-SELECTION.
    * Create and populate internal table
      CREATE DATA gt_itab TYPE STANDARD TABLE OF (pa_table).
      ASSIGN gt_itab->* TO <gt_itab>.
      SELECT * FROM (pa_table) INTO TABLE <gt_itab>.
    * Get the key components into the fields ge_key_field1, ...
      go_descr_ref ?= cl_abap_typedescr=>describe_by_data_ref( gt_itab ).
      LOOP AT go_descr_ref->key ASSIGNING <gs_key_comp>.
        CASE sy-tabix.
          WHEN 1.
            ge_key_field1 = <gs_key_comp>-name.
          WHEN 2.
            ge_key_field2 = <gs_key_comp>-name.
          WHEN 3.
            ge_key_field3 = <gs_key_comp>-name.
        ENDCASE.
      ENDLOOP.
    * Finally, perform the search
      READ TABLE <gt_itab> ASSIGNING <gs_result>
              WITH KEY (ge_key_field1) = pa_cond1
                       (ge_key_field2) = pa_cond2
                       (ge_key_field3) = pa_cond3.
      IF sy-subrc = 0.
        WRITE / 'Record found.'.
      ELSE.
        WRITE / 'No record found.'.
      ENDIF.
    One note: When an internal table is created dynamically like in my program above, the table key is not the key defined in the DDIC structure -- instead, the default key for the standard table is used (i.e. all non-numeric fields).
    Hope this helps,
    David

  • Read table itab with key

    Hi,
    Unfortunately i've been almost a year out of abap,so its kinda rusty, so pls bear with my question. I've to develop this upload program, which would read from file, but the catchy part is that to filter out the records by either pernr, bukrs, subty or any of the criteria simultaneously. I'm using select-options for  pernr, subty, bukrs, but the problem is how do i filter it out, what sort of logic/ algorithm should i be using, READ TABLE itab WITH KEY or a LOOP statement, could any 1 give any suggestions as to how i should be designing the logic. please advise

    Hi
    You want to upload data from a file on the basis of some criteria.
    In this case I think you need to upload all the data from the file to an internal table.
    Now the internal table contains all the data from the file.
    then filter the data from that table on the basis of PERNR, BUKRS or SUBTY.
    Like Below:
    delete ITAB where PERNR not in S_PERNR (S_PERNR is your select option).
    similarly for SUBTY or BUKRS.
    Or if you want all these 3 fields together then use OR condition.
    Like:
    delete ITAB where PERNR not in S_PERNR  OR
    delete ITAB where PERNR not in S_SUBTY OR
    delete ITAB where PERNR not in S_BUKRS.
    the above code will delete all the data from ITAB where the data doesn't match with the entries in S_PERNR, S_SUBTY and S_BUKRS.
    I hope this will work for you,
    If you didn't get it then post your code.
    Thanks
    LG

  • About Read table

    Can any body explain about Read table and when it can use.

    Hi,
    When u want to read a record based on some condition then u can use READ.
    LOOP AT itab.
    READ TABLE itab WITH KEY matnr = itab-matnr.
    IF sy-subrc = 0.
    ENDIF.
    ENDLOOP.
    U can read only a single record.
    U can also use
    READ TABLE itab INDEX 1.
    Reward points if this is helpful.

  • Put a condition on a form on table

    Can I put a condition on a form on table.
    I have master-detail form, but in the master I don't want to view all the row, I want to put a condition on this like where clause.......... Can I?
    Regards

    One more question.
    In master report (in master table) I have x_id column which is foreign key for a column in another table which has the another column I want to display instead of the x_id column,HOW?
    In "Query Definition"there is "Query Join Conditions" I put the condition ..... it didn't work,
    I changed the x_id attribute to change reference table and column but it didn't work too.
    What should I do?
    Regards.

  • Difficulty  While reading Table....

    Hi All,
    i trying to read data from table with multiple condition but it is giving me error,
    my code is :
    loop at struct.
      ind = sy-tabix.
      read table itabMAST with key matnr = struct-matnr and WERKS = company and stlan = '5'.
    if sy-subrc = 0.
       move itabMAST-stlnr to struct-stlnr.
      endif.
      modify struct index ind transporting stlnr.
    endloop.
    and error message is giving is
    Unable to interpret "WERKS". Possible causes: incorrect Spelling or Comma error.
    Pls Help...
    Thanks in Advance,
    Yunus

    Hi, here is another example:
    IF sy-subrc <> 0.
              MOVE it_equz-hequi TO it_equz_dum2-hequi.
              READ TABLE it_equz_dum1 WITH KEY equnr = it_equz-equnr
                                               hequi = it_equz-hequi
                                               BINARY SEARCH.
              IF sy-subrc = 0.
                SELECT SINGLE anlnr
                              shtxt
                    FROM itob
                    INTO (it_itob-anlnr, it_itob-shtxt)
                   WHERE equnr EQ it_equz_dum1-hequi.
                IF sy-subrc = 0.
                  MOVE it_itob-anlnr TO it_finaltab-asset_dum.
                  MOVE it_itob-anlnr TO it_finaltab-asset.
                  MOVE it_itob-shtxt TO it_finaltab-description.
    endif.
    endif.
    endif.

  • Sy-tabix in relation to LOOP AT and READ TABLE

    Hi All,
    As per SAP documentation,
    1) While looping through an internal table (LOOP AT), sy-tabix contains the index number of current row(for standard and sorted tables)
    2)When successfully reading from an internal table(READ TABLE), sy-tabix is set to the index of the result row.
    But what happens when READ TABLE is used while looping through another internal table?
    i.e. Loop at TAB1...
    write sy-tabix.
    READ TABLE TAB2...
    write sy-tabix.
    endloop.
    If we are looping through 1st row of TAB1 and the result of read statement is found in 3rd row of TAB2, I expected that sy-tabix before READ would be 1 and after the READ be 3.
    But, I found that sy-tabix remains unchanged at 1. Can someone expalin why?
    Thanks,
    Jagan

    Hi
    If after reading the table TAB2 the system variable SY-TABIX has still the previous value, that menas the READ TABLE fails or it was read the first record of TAB2.
    After READ TABLE TAB2 try to check the SY-SUBRC:
    LOOP AT TAB1.
       WRITE: / 'TAB1 index:', SY-TABIX.
       READ TABLE TAB2 .........
       IF SY-SUBRC = 0.
         WRITE: 'TAB2 index:', SY-TABIX.
    Try this:
    DATA: BEGIN OF ITAB OCCURS 0,
            FIELD1,
          END   OF ITAB.
    DATA: BEGIN OF ITAB2 OCCURS 0,
            FIELD1,
          END   OF ITAB2.
    DATA: INDEX TYPE I.
    DO 10 TIMES.
      APPEND ITAB.
    ENDDO.
    DO 10 TIMES.
      APPEND ITAB2.
    ENDDO.
    LOOP AT ITAB.
      WRITE: / 'ITAB:', SY-TABIX.
      INDEX = SY-TABIX + 2.
      READ TABLE ITAB2 INDEX INDEX.
      IF SY-SUBRC = 0.
        WRITE:  'ITAB2:', SY-TABIX.
      ENDIF.
    ENDLOOP.
    Max

  • How to get the number of hits ("returned rows") in read table statement

    Hi Experts
    I have the statement shown below, which seems not to work as I would like it to. My problem is that I would like to do two different things depending on weather or not a read table statement results in 0 hits or 1 (or more) hits.
        READ TABLE g_ship_item
            WITH KEY
         l_ztknum = DATA_PACKAGE-/bic/ztknum
         BINARY SEARCH.
          IF sy-subrc is initial.
          no hits found
            DATA_PACKAGE-/BIC/ZSTAGEERR = 1.
          ELSE.
          hits where found and we will do something else...
            DATA_PACKAGE-/BIC/ZSTAGEERR = 0.
    Hope someone can help me out of my problem...
    Thanks in advance, regards
    Torben

    Hi,
    As you are using READ statement with Binary search, check whether the internal table g_ship_item is sorted with field /bic/ztknum or not. If it is not sorted then the result of this READ statement is not correct.
    Below is the correct code.
    sort  g_ship_item by /bic/ztknum.
    READ table g_ship_item with key g_ship_item = xxx.
    Thanks,
    Satya

Maybe you are looking for