Sy-index / sy-tabix wrong within loop

Hi friends,
i do a loop over a a table and am writing out the field contents like this:
LOOP AT <dyn_table> INTO <dyn_wa>.
        do.
      assign component sy-index
         of structure <dyn_wa> to <dyn_field>.
        if sy-subrc <> 0.
         EXIT.
        else.
* Here it gets the name of the field based on the sy-index of the component
        READ TABLE l_tab_fields INTO w_tab_fields INDEX sy-index.
      endif.
  ENDLOOP.
What now doesnt work is, that whenever i have the read statement uncommented the loop doesnt increment so i only get the first row but that n-times.
any idea where the error is  ?
thank you! i am awarding points generously

LOOP AT <dyn_table> INTO <dyn_wa>.
        do.
      assign component sy-index
         of structure <dyn_wa> to <dyn_field>.
        if sy-subrc <> 0.
         EXIT.
        else.
Here it gets the name of the field based on the sy-index of the component
        READ TABLE l_tab_fields INTO w_tab_fields INDEX sy-index.
      endif.
  ENDLOOP.
If i gt you rite..i would suggest this
Data: l_tabix type sy-tabix.
LOOP AT <dyn_table> INTO <dyn_wa>.
  l_tabix - sy-tabix.
      assign component l_tabix
         of structure <dyn_wa> to <dyn_field>.
        if sy-subrc <> 0.
         EXIT.
        else.
Here it gets the name of the field based on the sy-index of the component
        READ TABLE l_tab_fields INTO w_tab_fields INDEX l_tabix.
      endif.
  ENDLOOP.
santhosh

Similar Messages

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

  • Delete Itab within Loop at ITAB ?

    Hi,
    Help needed to remove this delete from within the loop.
    {code
    Loop at itab where <condition>.
    <statements>
    delete itab index sy-tabix.
    Exit.
    Endloop.
    {code}
    The functionality of the code should not be affected.
    Useful help would be awarded

    Hi,
    Instead of deleting data from itab use another internal table of same type (itab1) and append it. Use itab1 data for further processing.
    check below logic...
    {code
    Loop at itab1 into wa_itab1 where <condition>.
    <statements>
    if <condition>
    append wa_itab1 to itab2.
    exit.
    endif.
    Endloop.
    refresh itab1.
    itab1[] = itab2[].
    {code}
    regards,
    N M Poojari.

  • 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

  • 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

  • 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

  • Why "Modify itab index sy-tabix." makes internal table content blank?

    We have an internal table itab which looks like to have the following content:
    A---B---C
    1----3----
    2----2----
    We would like to get the column C value in this internal table itab by summing Column A and Column B, and then fill C column values into this internal table. We know that the program would looks like:
    Loop at itab into wa_itab.
        wa_itab-C = wa_itab-A + wa_itab-B.
        Modify itab index sy-tabix.
    EndLoop.
    But after executing the above code, all itab becomes blank. Through debugging, find it's caused by the statement "Modify itab index sy-tabix.".  Could any ABAP expert here let us know the reason and we will give you reward points!

    hi,
    what you tried is correct.but instead of using
    modify itab index sy-tabix
    use
    modify itab index sy-tabix from wa_itab.
    the reason for blank data is you are not mentioning from where that record is to be updated.your specifying the record using index.one thing is no need to use index also because in a loop you are modifying so automatically it will take you to the record.
    try the following code.
    types:begin of it,
         a type i,
         b type i,
         c type i,
         end of it.
    data:itab type standard table of it.
    data:wa_itab type it.
    wa_itab-a = 3. wa_itab-b = 4.
    append wa_itab to itab.
    Loop at itab into wa_itab.
        wa_itab-C = wa_itab-A + wa_itab-B.
    Modify itab index sy-tabix from wa_itab.
    *you can use Modify itab from wa_itab.
    EndLoop.
    loop at itab into wa_itab.
    write:wa_itab-a,wa_itab-b,wa_itab-c.
    endloop.
    <REMOVED BY MODERATOR>
    Edited by: Alvaro Tejada Galindo on Apr 8, 2008 5:49 PM

  • Insert ITAB INDEX SY-TABIX Problem

    Hi Experts,
    I have a problem in my report.
    Please look into the code.
    loop at li_basez980.
       read table i_z980 with key spmon = l_spmon
                                  matnr = li_basez980-matnr
                                  kunnr = li_basez980-kunnr
                                  werks = li_basez980-werks
                                  vkorg = li_basez980-vkorg binary search.
       if sy-subrc ne 0.
         i_z980-spmon = l_spmon.
         i_z980-matnr = li_basez980-matnr.
         i_z980-kunnr = li_basez980-kunnr.
         i_z980-werks = li_basez980-werks.
         i_z980-vkorg = li_basez980-vkorg.
         i_z980-basme = li_basez980-basme.          " 8/6/07
         i_z980-waers = c_waers.
         i_z980-cpudt = v_datum.
         i_z980-cputm = v_uzeit.
         i_z980-znetsalekg = 0.
         i_z980-znetsalevl = 0.
         insert i_z980 index sy-tabix.
         clear  i_z980.
       endif.
    endloop.
    When run my report in Foreground it runs fine. But when i run the same report in Background job gets cancelled when the index reaches to 228984 once 230070 once and 230104 once at insert statement i.e " insert i_z980 index sy-tabix." . I found this  by debugging the Job.
    Please help me if you know the solution.
    Regards,
    Ravikumar P
    Edited by: Ravikumar P on Mar 30, 2010 4:40 PM

    Hi,
    This is happening because after read you inserting the records when sy-surbc <> 0. At that time did you check the sy-tabix value. This value is comming correctly. You directly append the same.
    loop at li_basez980.
    read table i_z980 with key spmon = l_spmon
    matnr = li_basez980-matnr
    kunnr = li_basez980-kunnr
    werks = li_basez980-werks
    vkorg = li_basez980-vkorg binary search.
    if sy-subrc ne 0.
    i_z980-spmon = l_spmon.
    i_z980-matnr = li_basez980-matnr.
    i_z980-kunnr = li_basez980-kunnr.
    i_z980-werks = li_basez980-werks.
    i_z980-vkorg = li_basez980-vkorg.
    i_z980-basme = li_basez980-basme. " 8/6/07
    i_z980-waers = c_waers.
    i_z980-cpudt = v_datum.
    i_z980-cputm = v_uzeit.
    i_z980-znetsalekg = 0.
    i_z980-znetsalevl = 0.
    insert i_z980 index sy-tabix.
    clear i_z980.
    endif.
    endloop.

  • How to Edit names within Loop Library

    I've edited a MIDI Apple Loop from Jam Packs and saved it as an MIDI Apple Loop in the library.
    What I typed in as a name for the file is not what appeared in the loop library?
    1. Why did the text alter from I typed?
    2. How can I edite the name in the within loop library.
    3. How do I delete apple loops I've created from the apple loop library?
    Thank you
    - I did look in the manual and within the user help in Logic, but could find nothing. I know I must be looking under the wrong 'key word' search.
    What can I say!
    Message was edited by: StyleSupport

    StyleSupport wrote:
    1. Why did the text alter from I typed?
    You must select the green loop in the Arrange and go to Region menu "Add loop to the library" something like that or drag and drop the region to the Library in the Media dock.
    This way a new dialog will show( see the picture below ) where you need to fill new "unique" name or to add some user (sub name), choose the group etc.
    2. How can I edite the name in the within loop library.
    3. How do I delete apple loops I've created from the apple loop library?
    You "user" green loop is stored to ...user/Library/Audio/Apple Loops/User Loops.
    Browse to this dir and edit or delete the loop.
    You "user" green loop is stored to ...user/Library/Audio/Apple Loops/User Loops.
    Browse to this dir ( you will find a folder labeled as "Single" or something like that open it ) and edit or delete the loop in question.
    !http://img42.imageshack.us/img42/508/greenloops.gif!
    !http://img59.imageshack.us/img59/4967/aglogo45.gif! [www.audiogrocery.com|http://www.audiogrocery.com]

  • Skip error record within loop

    Hi all,
       How to skip error records within loop.
    Regards,
    bala

    Hi krithika,
    1. we can use this logic
    2. Loop at itab.
      check field1 = 'wrong value'
      check field3 = 'wrong value'
      *--- OTHER GOOD CODE
      ENDLOOP.
    regards,
    amit m.

  • How to refresh/initialize sy-tabix in a loop?????

    Dear all,
    Please do let me know how to refresh/initialize 'sy-tabix' for every new document in a loop statement.
    Thanx in advance.
    Alok.

    Never try to refresh or initialize system variable. It shall always lead to errors in the programs. For this I have an alternative way below.
    Please declare a variable for e.g
    data: <b>l_count</b> type sy-tabix.
    Inside loop you can write the code like this:
    say for eg. you need to refresh l_count for every new material.
    Loop at itab.
    on change of itab-material.
    clear : l_count.
    endon.
    l_count = l_count + 1.
    endloop.
    Hope this clarifies your issue.
    Lakshminarayanan

  • Decrease sy-tabix value in Loop

    Hi Experts,
    I need to know that is it possible that we can decrease or change value of SY-TABIX.
    EXAMPLE:
    I am using a;
    loop at itab.  --> at this stage sy-tabix is 1.
    for instance current value of sy-tabix is changed to 4 and now I want to make it 3.
    in this case I want to read the 3 value in loop again.
    So is it possible that I can change my SY-TABIX value from 4 to 3 and read that 3rd record in the loop?
    endloop.
    can anyone let me know.
    thanks in advance.
    Regards,
    Yahya

    Hi
    this is not possible directly to change the values of system variables
    but the other way is there
    what you can do is to move the valuw of sy-tabix in a variable and then loop through the table to that value,
    like:
    lv_tabix like sy-tabix.
    loop at itab into wa where sy-tabix = lv_tabix.
    after loop statement.
    lv-tabix = sy-tabix.
    you code............
    before enloop .
    lv_tabix = sy-tabix - 1.
    endloop.
    I am not sure about the above code but you can try something like above.
    Thanks
    Lalit

  • GB won't open- This is what I get... Path does not exist: /Library/Audio/Apple Loops Index  st: /Library/Audio/Apple Loops Index w/out this directory you cannot use the Loop Browser

    Path does not exist: /Library/Audio/Apple Loops Index  st: /Library/Audio/Apple Loops Index w/out this directory you cannot use the Loop Browser.  Then I get this message...
    Instrument Library Invalid
    GarageBand Ecpects a valid instrument foledr in /Libraty/Application Support/GarageBand
    Please choose a valid instrument Library folder or quit and re-install GB
    Any solutions?

    Is this a new installation of GarageBand or has it worked before on the same computer?
    Or have you transferrred your GarageBand from a different computer?
    The error message is saying, that your GarageBand installation is incomplete. There are essential foldrs missing in your system library. 
    Check, if indeed both folders are missing or if only the permissions are set incorrectly.
    Your system library (the folder "System" directly on your system drive) should have the following folders inside the folder "Audio", and they need to be readable by the system and by administrators.
    And in the folder /Library/Application Support there should be the Instrument Library.
    If these folders do not exist (or no longer exist), restore them from your backup-  If your GarageBand version is a new installation, the application may not hve been downloaded or installed completely, then reinstall GarageBand.
    What is your GarageBAnd version, and how did you install it originally?
    Regards
    Léonie

  • Trap error within loop and process next record

    Hi,
    I am processing each record inside a loop. Now if any exception occurs processing with a single record within loop I want to continue with the next record with proper error message in the log.
    How to achieve the above scenario? Shall I create a savepoint and whenever any error occurs inside the loop I will rollback to that savepoint. Once it is done shall it process the next record automatically?
    Thanks in advance for your reply.
    Thanks,
    Mrinmoy

    Relational databases are about sets.
    They are not about files and records
    Processing records in a loop will make your code slow, and you should avoid using this strategy.
    That said
    Simply enclose the code in it's own begin end block.
    beginn
    <your code>
    exception
    when <your exception> then
    <process the exception not reraising it>
    end;
    No savepoints required.
    Sybrand Bakker
    Senior Oracle DBA

  • Can we put subroutines within loops?

    q]     Can we put subroutines within loops?- i mean not the PERFORM Statement  but the FORMENDFORM statement

    Hi
    If your question means .. calling Performs within Loops ?
    Then its possible..
    LOOP.
    PERFORM P1. ( THIS IS OK )
    ENDLOOP.
    But this is not correct..
    LOOP.
    FORM P1.
    ENDFORM.
    ENDLOOP.
    Thanks
    Hope it Helps.
    Praveen

Maybe you are looking for

  • QTD, MTD functions

    Hi All, I have a logical table based on Time and created a corresponding Dimension. These are the columns 1) Year 2) Quarter 3) Month 4) Week 5) Day In the properties of Time Dimension, I made as the dimension as TIme Dimension CHECKED. Default Root

  • If you get an iPad with the 3G do you have to pay for internet service?

    If you get an iPad with the 3G do you have to pay for internet service?

  • Change MM PR or PO Item Category Settings

    Hi all, I know the standard SAP doesn't allow creation of new item categories. However, is there a configuration within SPRO that allows changing of their individual settings? If this question was previously answered in this forum, please kindly poin

  • Converting Vector shapes from Photoshop to Indesign

    I am trying to convert a Photoshop document to an Indesign document. I have vector shapes that I want to transfer to the new INDD document. However, I cannot seem to find a workaround that maintains the ability to edit the vector shapes once placed i

  • Facebook notification stuck on screen

    I have a Facebook notification stuck on the screen.  I can select "later" or "open," but nothing happens when I press either of these buttons.  Without closing out this application, I am unable to use any other functions of iPad including unable to p