Sy-tabix vs sy-index

Hi all,
I have one LOOP and two READ statements inside of it. After each READ statement i need to MODIFY some lines. In one of MODIFY statements i use MODIFY...INDEX sy-tabix but it seems that is not a good way to correctly modify line that I would like to. Can you please give me any suggestions?
KR,
Maja
eg. of Code is below:
LOOP AT it_srret INTO wa_srret.
      READ TABLE it_srret1 INTO wa_srret1 WITH KEY obknr = wa_srret-obknr.
      wa_srret-mblnr = wa_srret1-mblnr.
      wa_srret-mjahr = wa_srret1-mjahr.
      wa_srret-zeile = wa_srret1-zeile.
      wa_srret-datum = wa_srret1-datum.
      MODIFY it_srret FROM wa_srret.
      READ TABLE it_list INTO wa_list WITH KEY sernr = wa_srret-sernr.
      IF sy-subrc = 0.
        wa_list-returned = 'D'.
        MODIFY it_list FROM wa_list INDEX sy-tabix.
        CLEAR wa_list.
        wa_list-lfdat = wa_srret-datum.
        wa_list-sernr = wa_srret-sernr.
        wa_list-mblnr = wa_srret-mblnr.
        wa_list-zeile = wa_srret-zeile.
        APPEND wa_list TO it_list.
      ENDIF.
    ENDLOOP.

HI,
If you can use Field-symbols... then there is no need to use the MODIFY statements.
field-symbols: <fs_srret> like wa_srret.
field-symbols: <fs_srret1> like wa_srret.
field-symbols: <fs_list> like w_list.
LOOP AT it_srret assigning <fs_srret>.
READ TABLE it_srret1 INTO <fs_srret1> WITH KEY obknr = <fs_srret>-obknr.
lf sy-subrc eq 0.
<fs_srret1>-mblnr = <fs_srret>-mblnr.
<fs_srret1>-mjahr = <fs_srret>-mjahr.
<fs_srret1>-zeile = <fs_srret>-zeile.
<fs_srret1>-datum = <fs_srret>-datum.
endif.
READ TABLE it_list assigning <fs_list> WITH KEY sernr = <fs_srret>-sernr.
IF sy-subrc = 0.
<fs_list>-returned = 'D'.
CLEAR wa_list.
wa_list-lfdat = wa_srret-datum.
wa_list-sernr = wa_srret-sernr.
wa_list-mblnr = wa_srret-mblnr.
wa_list-zeile = wa_srret-zeile.
APPEND wa_list TO it_list.
ENDIF.
ENDLOOP.
Regards,
Venkatesh

Similar Messages

  • What is the diffrence betweensy-tabix and sy-index

    hi
    can any one suggest me
    what is the diffrence betweensy-tabix and sy-index
    Thanks & Regards
    kalyan.

    Hi Kalyan,
    This question has been answered many times on SCN. Please make a search before posting a thread.
    Read the Rules of Engagement.
    Happy Posting.
    Regards,
    Chandra Sekhar

  • ABAP-- diff between sy-sy-tabix and sy-index

    Hi Guru's,
    Pleae can anybody expalins me what is the difference between sy-tabix and sy-index(Loop Index) ?
    Because in one case i am Modifyimg the internal table inside the do loop by giving sy-index ((Index of Internal Tables)(MODIFY scarr_tab INDEX sy-index FROM scarr_wa TRANSPORTING currcode. )  in the syntax and in other case inside loop statement i am modifyng same record by giving sy-tabix MODIFY scarr_tab INDEX  sy-tabix FROM scarr_wa TRANSPORTING currcode.) in the syntax.
    in both cases its working fine but i am not getting which one i have to use  where to modify the internal table?
    regards
    SATYA

    Hi Henry,
    SY-INDEX is the value of the current iteration. It is applicable for the following programming constructs in ABAP -
    DO...ENDDO.
    WHILE...ENDWHILE.
    SY-TABIX (TABle IndeX) is applicable to internal tables. If you scroll down in the link which Eddie has given, you will find a more detailed explanation for sy-tabix and which statements affect its value.
    Regards,
    Anand Mandalika.

  • What is difference between sy-tabix and sy-index.

    SAP Seniors,
    Can you please let me know what is difference between sy-index and sy-tabix.
    I read the SAP help, it is confusing for me. it looks like both are same from help. please help me.
    Thank you
    Anitha.

    HI,
        Here is a brief description of difference between SY_TABIX and SY_INDEX and using them with several conditions.
    SY-TABIX
    Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables. The field is either not set or is set to 0 for hashed tables.
    APPEND sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table.
    COLLECT sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.
    LOOP AT sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE.
    READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.
    SEARCH <itab> FOR sets SY-TABIX to the index of the table line in which the search string is found.
    SY-INDEX
    In a DO or WHILE loop, SY-INDEX contains the number of loop passes including the current pass.
    Hope this helps.
    Thank you,
    Pavan.

  • Difference between sy-tabix and sy-index?

    tell me about sy-tabix and sy-index?what is the difference between sy-tabix and sy-index?
    Moderator Message: Please search before posting. Read the [Forum Rules Of Engagement |https://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngagement] for further details.
    Edited by: Suhas Saha on Jun 18, 2011 5:33 PM

    HI,
        Here is a brief description of difference between SY_TABIX and SY_INDEX and using them with several conditions.
    SY-TABIX
    Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables. The field is either not set or is set to 0 for hashed tables.
    APPEND sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table.
    COLLECT sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.
    LOOP AT sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE.
    READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.
    SEARCH <itab> FOR sets SY-TABIX to the index of the table line in which the search string is found.
    SY-INDEX
    In a DO or WHILE loop, SY-INDEX contains the number of loop passes including the current pass.
    Hope this helps.
    Thank you,
    Pavan.

  • INDEX vs TABIX

    Hi,
    Can some body explain the CLEAR difference between Sy-index and Sy-tabix. And one or two small examples. I am little bit confused.
    Thanx.

    Hi,
    SY-INDEX
    In a DO or WHILE loop, SY-INDEX contains the number of loop passes including the current pass.
    SY-TABIX
    Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables. The field is either not set or is set to 0 for hashed tables.
    APPEND sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table.
    COLLECT sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.
    LOOP AT sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE.
    READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.
    SEARCH <itab> FOR sets SY-TABIX to the index of the table line in which the search string is found.
    regards,
    madhu

  • What is diff b/w sy-index and sy-tabix

    Hi all,
    Can u plz give me the diff b/w sy-index and sy-tabix exactly and how it works.
    Thanks & Regards
    Venkat

    Hi Venkat,
    <b>1.SY-INDEX</b>
    <b>-></b>Current loop pass
    <b>-></b>In a DO or WHILE loop, SY-INDEX contains the number of loop passes including the current pass.
    <b>2.SY-TABIX</b>
    <b>-></b>Current line index
    Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables.
    The field is either not set or is set to 0 for hashed tables.
    <b>APPEND</b> sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table.
    <b>
    COLLECT</b> sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.
    <b>LOOP AT</b> sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE.
    <b>READ TABLE</b> sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.
    <b>
    SEARCH</b> <itab> FOR sets SY-TABIX to the index of the table line in which the search string is found.
    I think that it clears ur doubt.
    <b>Thanks,
    Venkat.O</b>

  • What is difference between sy-index and sy-tabix and where both are using ?

    what is difference between sy-index and sy-tabix and where both are using ?

    hi nagaraju
    sy-tabix is in Internal table, current line index. So it can only be used while looping at the internal table.
    sy-index is in Loops, number of current pass. This you can use in other loop statements also (like do-enddo loop, while-endwhile)
    SY-INDEX is a counter for following loops: do...enddo, while..endwhile
    SY-TABIX is a counter for LOOP...ENDLOOP, READ TABLE...
    Here is an example from which you can understand the difference between sy-tabix and sy-index.
    Itab is an internal table with the following data in it.
    id Name
    198 XYZ
    475 ABC
    545 PQR.
    loop at itab where id > 300.
    write :/ itab-id, itab-name , sy-tabix, sy-index.
    endloop.
    My output will be :
    475 ABC 2 1
    545 PQR 3 2
    Sy-tabix is the index of the record in internal table.
    sy-index gives the no of times of loop passes.
    So, for the first record in the output (475 ABC), 2 is the index of the record in internal table and as it is first time loop pass occured, sy-index value is 1.
    Regards,
    navjot
    award points

  • Difference b/w sy-index and sy-tabix

    hai all,
    Could u explain the difference b/w sy-index and sy-tabix?
    regards,
    Selva

    Hi,
    sy-index - For Loops, Current Loop Pass.
    sy-tabix - For Internal Table, Current Line Index in internal table.
    sy-tabix is used at internal table operations (READ TABLE ... LOOP AT ...), sy-index is used at cycles (DO...n TIMES).
    SY-TABIX:
    Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables. The field is either not set or is set to 0 for hashed tables.
    it can be set by using the following:
    1.append
    2.collect
    3.loop at
    4. read
    5.search
    APPEND sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table.
    COLLECT sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.
    LOOP AT sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE.
    READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.
    SEARCH <itab> FOR sets SY-TABIX to the index of the table line in which the search string is found.
    SY-INDEX:
    SY-INDEX is used to describe the number of iteration with in the DO..ENDDO, WHILE ...ENDWHILE....
    for example,
    DO.
    WRITE SY-INDEX.
    IF SY-INDEX = 3.
    EXIT.
    ENDIF.
    ENDDO.
    it gives output as:
    1 2 3
    Regards,
    Raj.

  • Regarding sy-index and sy-tabix

    Hi,
    What is the major difference between sy-index and sy-tabix ,
      can you give me one good example with code..
    Regards,
    Reddy.

    Hi,
    SY-TABIX - Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables. The field is either not set or is set to 0 for hashed tables.
    APPEND sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table.
    COLLECT sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.
    LOOP AT sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE.
    READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.
    SEARCH FOR sets SY-TABIX to the index of the table line in which the search string is found.
    SY_INDEX - In a DO or WHILE loop, SY-INDEX contains the number of loop passes including the current pass.
    sy-tabix is the tab index - the index of the record in the internal table you are accessing,
    sy-index is the loop counter.
    If you use a condition in LOOP the sy-index will go from 1 to n, but sy-tabix will refer to the line in the internal table.
    Hope this helps u.
    Thanks,
    Ruthra

  • Difference between sy-index & sy-tabix

    Dear friends,
    Please tell me the difference between sy-index & sy-tabix
    Actually my problem is i don't know how to compare for example between first record'field n and second record'field n when u r in loop so i can take particular action based on result
    on current recor
    if possible send me sample code.
    Regards;
    Parag Gavkar.

    SY-TABIX:
    Current line in an internal table. With the following statements SY-TABIX is set for index tables. With hashed tables, SY-TABIX is not filled or it is set to 0.
    - APPEND sets SY-TABIX to the index of the last table row, that is the total number of entries in the target table.
    - COLLECT sets SY-TABIX to the index of the existing or appended table row. With hashed tables, SY-TABIX is set to 0.
    - LOOP AT sets SY-TABIX to the index of the current table row at the beginning of every loop pass. After leaving a loop, SY-TABIX is set to the value it had before entering the loop. With hashed tables, SY-TABIX is set to 0.
    - READ TABLE sets SY-TABIX to the index of the table row read. If no row is found with binary search while reading, SY-TABIX contains the index of the next-highest row or the total number of rows +1. If no row is found with linear search while reading, SY-TABIX is undefined.
    - SEARCH itab FOR sets SY-TABIX to the index of the table row, in which the search string was found.
    SY-INDEX:
    SY-INDEX contains the number of loop passes in DO and WHILE loops, including the current loop pass.
    Regards,
    Santosh

  • Sy-index vs sy-tabix

    hi,
    i a bit confused of these 2. can let me know the difference?
    normally used in internal table?
    what keyword can use these 2? read, insert, delete,loop, append, modify.
    thanks

    hi,
    SY-INDEX
    The system field sy-index contains the number of loop passes, including the current loop pass.
    There are four kinds of loops in ABAP:
    · Unconditional loops using the DO statement.
    · Conditional loops using the WHILE statement.
    · Loops through internal tables and extract datasets using the LOOP statement.
    · Loops through datasets from database tables using the SELECT statement.
    SY-TABIX
    If the internal table is an index table, SY-TABIX is set to the index of the line retrieved.
    READ
    chk out this link http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm
    APPEND sets SY-TABIX to the index of the last table row, that is the total number of entries in the target table.
    LOOP AT sets SY-TABIX to the index of the current table row at the beginning of every loop pass. After leaving a loop, SY-TABIX is set to the value it had before entering the loop. With hashed tables, SY-TABIX is set to 0.
    INSERT
    chk out this link
    http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb361f358411d1829f0000e829fbfe/content.htm
    DELETE
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb37d9358411d1829f0000e829fbfe/content.htm
    MODIFY
    http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb35eb358411d1829f0000e829fbfe/content.htm</u> 
    hope this ll help u.
    Regards,
    Viji

  • Sy-tabix & sy-index

    hi all,
    what is the basic difference between sy-tabix & sy-index

    hi shantanu,
    SY-TABIX:
    Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables. The field is either not set or is set to 0 for hashed tables. 
    it can be set by using  the following:
    1.append
    2.collect
    3.loop at
    4. read
    5.search
    APPEND sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table. 
    COLLECT sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.
    LOOP AT sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE. 
    READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry. 
    SEARCH <itab> FOR sets SY-TABIX to the index of the table line in which the search string is found.
    SY-INDEX:
    SY-INDEX is used to describe the number of iteration with in the DO..ENDDO, WHILE ...ENDWHILE....
    for example,
    DO.
    WRITE SY-INDEX.
      IF SY-INDEX = 3.
        EXIT.
      ENDIF.
    ENDDO.
    it gives output as:
    1   2  3
    rewards points if useful.
    regards,
    sandhya

  • Sy-index sy-tabix

    can any body tell me diff bw sy-tabex and sy-index. pls

    SY-INDEX
    In a loop, a statement block is executed several times in succession. There are four kinds of loops in ABAP:
    Unconditional loops using the DO statement.
    Conditional loops using the WHILE statement.
    Loops through internal tables and extract datasets using the LOOP statement.
    Loops through datasets from database tables using the SELECT statement.
    This section deals with DO and WHILE loops. SELECT is an Open SQL statement, and is described in the Open SQL section. The LOOP statement is described in the sections on internal tables and extract datasets.
    Unconditional Loops
    To process a statement block several times unconditionally, use the following control structure:
    DO [<n> TIMES] [VARYING <f> FROM <f1> NEXT <f 2>].
      <Statement block>
    ENDDO.
    If you do not specify any additions, the statement block is repeated until it reaches a termination statement such as EXIT or STOP (see below). The system field SY-INDEX contains the number of loop passes, including the current loop pass.
    SY-TABIX
    You can use the LOOP statement to process special loops for any internal table.
    LOOP AT <itab> <result> <condition>.
      <statement block>
    ENDLOOP.
    This reads the lines of the table one by one as specified in the <result> part of the LOOP statement. You can then process them in the statements within the LOOP... ENDLOOP control structure. You can either run the loop for all entries in the internal table, or restrict the number of lines read by specifying a <condition>. Control level processing is allowed within the loop.
    The sequence in which the lines are processed depends on the table type:
    Standard tables and sorted tables
    The lines are processed according to the linear index. Within the processing block, the system field SY-TABIX contains the index of the current line.
    Hashed tables
    As long as the table has not been sorted, the lines are processed in the order in which you added them to the table. Within the processing block, the system field SY-TABIX is always 0.

  • 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

Maybe you are looking for

  • Set up ID with wrong email...

    Dear apple, In the process of setting up an iphone with new details, I set up my wife's apple ID with the wrong email (ending .co.uk when it should have been .com), I then went and veryfied my own email address which is now linked to that account. On

  • Syncing apps crash!!!

    i have about 170 apps and an ipod touch 2g. when i try to select the sync applications option in itunes it instantly crashes. ive tried to wait but no luck please help i dont want to reinstall each and every app onto mt ipod through the mobile app st

  • Policy Agent Error

    Version: Solaris: 8 IS 6.0 Policy Agent 2.0 Webserver: iWS 6.0 I installed the agent, configured a policy protecting the resources on the webserver. When I access any resource, it throws me a login page (as it should). Once I submit the credentials,

  • Can't use templates due to some issue with "sites"

    I'm trying to create a website from a template on dreamweaver, but my computer is giving me some grief about "adding a site". I already entered the information for my site in the "configure server" box. I've entered the proper info for ftp host and h

  • What is wrong with wifi after iOS 6 update on the new iPad ?

    Since I upgraded to iOS 6 my iPad ***** at connecting to Wi- Fi.  I have been using iPads since the original launch and I currently own the 3rd gen iPad. Since the upgrade to iOS 6.0 the performance of Wi-Fi is terrible. My iPad often cannot find net