Read table index sy-tabix

Hi Experts,
As per my requirment I need fetch two different categories of matnr based on movment type
from mseg..
For eg: If I have two itab's : itab1 and itab2.
In itab1 the available records are:    
matnr    werks     lifnr
mat1     unit1      ABC
mat2     unit1      ABC
mat3     unit1      ABC
mat4     unit1      ABC
In itab2 the available records are:  
matnr_1  werks_1  lifnr_1
mat5       unit1       ABC
mat6       unit1       ABC
mat7       unit1       ABC
mat8       unit1       ABC
and I want to move this itab1 and itab2 to another itab ie. itab3.
and my o/p shud look like:
matnr    werks     lifnr     matnr_1
mat1     unit1     ABC     mat5
mat2     unit1     ABC     mat6
mat3     unit1     ABC     mat7
mat4     unit1     ABC     mat8.
Please advice
Karthik
Edited by: Karthik R on Jun 18, 2009 6:33 PM

Hi Suhas,
Thanks a lot !! Ur logic is working.. but I have some other problem now:
ie. If in itab 1 I have
matnr    werks     lifnr
mat1     unit1      ABC
mat2     unit1      ABC
In itab2 the available records are:
matnr_1  werks_1  lifnr_1
mat5       unit1       ABC
mat6       unit1       ABC
mat7       unit1       ABC
mat8       unit1       ABC
I want my o/p as :
matnr    werks     lifnr    matnr_1
mat1     unit1      ABC    mat5
mat2     unit1      ABC    mat6
                           mat7
                           mat8.
But as per ur logic I got the o/p as:
matnr    werks     lifnr    matnr_1
mat1     unit1      ABC    mat5
mat2     unit1      ABC    mat6
Please advice
Karthik
Edited by: Karthik R on Jun 18, 2009 7:07 PM
Edited by: Karthik R on Jun 18, 2009 7:08 PM

Similar Messages

  • 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

  • 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

  • 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

  • Read Table ITAB with key Dynamic Value index 1

    Here is sample Intenral table
    Columnname-C01 / C02 / C03
    Value-123 / 456 /789
    I would like to search value of the internal table according to dynamic value given by the code.
    i.e.
    read table ITAB with key <Dynamic Value> index 1.

    Hi,
    Apart from read, you can also use <b>SEARCH</b> statement.
    Syntax
    SEARCH
    Searches for strings.
    Syntax
    SEARCH <f>|<itab> FOR <g> [ABBREVIATED]
                              [STARTING AT <n1>]
                              [ENDING AT <n2>]
                              [AND MARK]
                              [IN BYTE MODE|IN CHARACTER MODE].
    Searches the field <f> or table <itab> for the string in the field <g>. The result is stored in SY-FDPOS. The additions let you hide intermediate characters, search from and to a particular position, and convert the found string into uppercase. In Unicode programs, you must specify whether the statement is a character or byte operation, using the IN BYTE MODE or IN CHARACTER MODE (default) additions.
    Hope this information is useful to you.
    Regards,
    Saumya

  • 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

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

  • Read Table Vs Loop at

    Dear All,
    Please let me know which one of the two should I use to improve the performance, for tables containing a lot of data ?
    Regards,
    Thanks in anticipation.
    Alok.

    Hi,
        Follow below steps.
        In se30 transaction you can look for
        Tip&TRicks button on application toolbar
        apart from below conventions
       Follow below steps
    1) Remove corresponding from select satement
    2) Remove * from select
    3) Select field in sequence as defined in database
    4) Avoid unnecessary selects
    i.e check for internal table not initial
    5) Use all entries and sort table by key fields
    6) Remove selects ferom loop and use binary search
    7) Try to use secondary index when you don't have
    full key.
    8) Modify internal table use transporting option
    9) Avoid nested loop . Use read table and loop at itab
    from sy-tabix statement.
    10) free intrenal table memory wnen table is not
    required for further processing.
    11)
    Follow below logic.
    FORM SUB_SELECTION_AUFKTAB.
    if not it_plant[] is initial.
    it_plant1[] = it_plant[].
    sort it_plant1 by werks.
    delete adjacent duplicates from it_plant1 comparing werks
    SELECT AUFNR KTEXT USER4 OBJNR INTO CORRESPONDING FIELDS OF TABLE I_AUFKTAB
    FROM AUFK
    FOR ALL ENTRIES IN it_plant1
    WHERE AUFNR IN S_AUFNR AND
    KTEXT IN S_KTEXT AND
    WERKS IN S_WERKS AND
    AUART IN S_AUART AND
    USER4 IN S_USER4 AND
    werks eq it_plant1-werks.
    free it_plant1.
    Endif.
    ENDFORM. "SUB_SELECTION_AUFKTAB
    Regards
    Amole

  • Invalid Cursor when I want to modify itab with READ TABLE ?

    Following code causes a core dump and says invalid cursor.
    What should I do if I want to change gt_itab .?
    REPORT  ZEV_READ_TABLE.
    data: begin of gt_itab occurs 0,
           key like vbrk-vbeln,
           name(10) type C,
           amount type i,
          end of gt_itab .
    start-of-SELECTION.
          gt_itab-key = 1.
          gt_itab-name = 'erkan'.
          gt_itab-amount = 10.
          append gt_itab.
          gt_itab-key = 2.
          gt_itab-name = 'dilem'.
          gt_itab-amount = 20.
          append gt_itab.
          LOOP AT gt_itab.
            write:/ gt_itab-key,
                    gt_itab-name,
                    gt_itab-amount.
          ENDLOOP.
          Read table gt_itab with key Key = 1.
           if sy-subrc = 0.
              gt_itab-amount = 100.
              modify gt_itab.
           endif.
    Kind Regards.
    Erkan VAROL

    Change the code this way & try
    modify gt_itab index sy-tabix.

  • Read table statement

    hi,
    while reading the internal table, if the subrc value is 8 .
    what does it mean.
    any help will be appreciated.

    Hi rajkumar,
    here's an example :
    *in progtab are 2 entries
    *now entry is'nt found:
    sy-subrc = <b>8</b> , sy-tabix = number of entries + 1 = <b>3</b>.
    DATA:  BEGIN OF PROGTAB OCCURS 10,
           NAME LIKE TRDIR-NAME,
           END OF PROGTAB.
    MOVE TRDIR-NAME TO PROGTAB-NAME.
    READ TABLE PROGTAB WITH KEY PROGTAB BINARY SEARCH.  
    IF SY-SUBRC <> 0.                                   
       INSERT PROGTAB INDEX SY-TABIX.                    
    ENDIF.
    regards Andreas

  • Read table

    i have to fetch belnr from bkpf table, and tax amount(fwste) from bset table.
    if for a particular belnr suppose if this belnr 1700000000 has 5 line items in bset table than i need tax amount for all those 5 line items it means i need addition of that tax amount in output
    for eg in bset table
    belnr fwste lifnr curr
    17000000000 0.00 0002300000 usd
    2.00
    0.00
    4.00
    in ouput i should get only subtotal has
    1700000000 6.00 00023000000 usd
    please help how to do its urgent
    below is the code
    SELECT      bukrs
                  belnr
                  gjahr
                  xblnr
                  waers
                  budat
                  usnam
                  tcode
                  awkey
                  FROM bkpf
                  INTO TABLE gt_bkpf
                  WHERE bukrs IN s_bukrs
                  AND   gjahr IN s_gjahr
                  AND   tcode EQ 'MIRO'.
      SELECT   bukrs
               belnr
               gjahr
               buzei
               koart
               lifnr
               zlspr
               FROM bseg
               INTO TABLE gt_bseg
               FOR ALL ENTRIES IN gt_bkpf
               WHERE bukrs EQ gt_bkpf-bukrs
               AND belnr EQ  gt_bkpf-belnr
               AND   gjahr EQ gt_bkpf-gjahr
               AND   lifnr IN s_lifnr
               AND   zlspr IN s_zlspr
                and koart  eq 'K'.
             AND   bschl EQ '31'.
      gt_bseg1[] = gt_bseg[].
      SORT gt_bseg1[] BY lifnr.
      DELETE ADJACENT DUPLICATES FROM gt_bseg1[] COMPARING lifnr.
      IF gt_bseg1[] IS NOT INITIAL.
        SELECT  lifnr
                    name1
                    FROM lfa1
                    INTO TABLE gt_lfa1
                    FOR ALL ENTRIES IN gt_bseg1
                    WHERE lifnr EQ gt_bseg1-lifnr.
              and lifnr eq s_lifnr.
      ENDIF.
      IF gt_bkpf[] IS NOT INITIAL.
        SELECT belnr
                gjahr
                tcode
                WAERS
                zuonr
                FROM rbkp
                INTO TABLE gt_rbkp
                FOR ALL ENTRIES IN gt_bkpf
                WHERE gjahr EQ gt_bkpf-gjahr
                AND   tcode EQ gt_bkpf-tcode
                AND   belnr EQ gt_bkpf-awkey+0(10).
       tax amount
        SELECT bukrs
                  belnr
                  gjahr
                  buzei
                  fwste
                  FROM bset
                  INTO TABLE gt_bset
                  FOR ALL ENTRIES IN gt_bkpf
                  WHERE bukrs EQ gt_bkpf-bukrs
                  AND   belnr EQ gt_bkpf-belnr
                  AND   gjahr EQ gt_bkpf-gjahr.
                 and fwste ne 0 .
      ENDIF.
      IF gt_rbkp[] IS NOT INITIAL.
        SELECT  belnr
                gjahr
                buzei
                cobl_nr
                wrbtr
                menge
                mwskz
                meins
                FROM rbco
                INTO TABLE gt_rbco
                FOR ALL ENTRIES IN gt_rbkp
                WHERE belnr EQ gt_rbkp-belnr.
      ENDIF.
      SELECT ebeln
             ernam
             FROM ekko
             INTO TABLE gt_ekko
             FOR ALL ENTRIES IN gt_rbkp
             WHERE ebeln EQ gt_rbkp-zuonr+0(10).
      IF gt_ekko[] IS NOT INITIAL.
        SELECT  banfn
                bnfpo
                ernam
                ebeln
                FROM eban
                INTO TABLE gt_eban
                FOR ALL ENTRIES IN gt_ekko
                WHERE ebeln EQ gt_ekko-ebeln.
      ENDIF.
    ENDFORM.                    " RETRIEVE_DATA
    *&      Form  MODIFY_DATA
          text
    -->  p1        text
    <--  p2        text
    FORM modify_data .
    *Sorting all Internal Tables .
      SORT gt_bseg BY  bukrs belnr gjahr.
      SORT gt_bkpf BY  bukrs belnr gjahr.
      SORT gt_lfa1 BY lifnr.
      SORT gt_rbkp BY belnr.
      SORT gt_rbco BY belnr.
      SORT gt_ekko BY ebeln.
      SORT gt_bset BY belnr.
      SORT gt_bset
      SORT gt_eban BY ebeln.
    SORT gt_bkpf .
    SORT gt_bseg .
    SORT gt_lfa1 .
    SORT gt_rbkp .
    SORT gt_rbco .
    SORT gt_ekko .
    SORT gt_bset.
    SORT gt_eban .
    LOOP AT GT_BSEG WHERE BELNR NE ' '.
         MOVE gt_bseg-pswsl  TO  gt_final-pswsl.
          MOVE gt_bseg-lifnr  TO  gt_final-lifnr.
          MOVE gt_bseg-zlspr  TO  gt_final-zlspr.
      READ TABLE GT_BKPF WITH KEY BELNR = GT_BSEG-BELNR BINARY SEARCH.
        IF SY-SUBRC = 0.
        MOVE gt_bkpf-bukrs TO gt_final-bukrs.
        MOVE gt_bkpf-belnr TO gt_final-belnr.
        MOVE gt_bkpf-xblnr TO gt_final-xblnr.
        MOVE gt_bkpf-budat TO gt_final-budat.
        MOVE gt_bkpf-usnam TO gt_final-usnam.
        ENDIF.
          READ TABLE gt_lfa1 WITH KEY lifnr = gt_bseg-lifnr BINARY SEARCH.
          IF sy-subrc = 0.
            MOVE gt_lfa1-name1 TO gt_final-name1.
          ENDIF.
            READ TABLE gt_rbkp WITH KEY belnr = gt_bkpf-awkey+0(10)
                                        gjahr = gt_bkpf-gjahr
            BINARY SEARCH.
            IF sy-subrc = 0.
              MOVE gt_rbkp-belnr TO gt_final-rbelnr.
              MOVE gt_rbkp-waers TO gt_final-waers.
              MOVE gt_rbkp-zuonr TO gt_final-zuonr.
            endif.
          READ TABLE gt_rbco WITH KEY belnr = gt_rbkp-belnr BINARY SEARCH.
              IF sy-subrc = 0.
                MOVE gt_rbco-buzei TO gt_final-buzei.
                MOVE gt_rbco-wrbtr TO gt_final-wrbtr.
                MOVE gt_rbco-menge TO gt_final-menge.
                MOVE gt_rbco-meins TO gt_final-meins.
                MOVE gt_rbco-mwskz TO gt_final-mwskz.
          endif.
              READ TABLE gt_ekko WITH KEY ebeln = gt_rbkp-zuonr+0(10) BINARY SEARCH.
                IF sy-subrc = 0.
                  MOVE gt_ekko-ernam TO gt_final-ernam.
                  endif.
                  READ TABLE gt_eban WITH KEY ebeln = gt_ekko-ebeln BINARY SEARCH.
                  IF sy-subrc = 0.
                    MOVE gt_eban-ernam TO gt_final-ernam.
                  ENDIF.
       READ TABLE GT_BSET WITH KEY BELNR = GT_BKPF-BELNR BINARY SEARCH.
       IF SY-SUBRC = 0.
            MOVE GT_BSET-FWSTE TO GT_FINAL-FWSTE.
       ENDIF.
          APPEND gt_final.
    endloop.
    please help where to add code and how to write
    thanks in advance

    declare itab with fields belnr and fwste.... and write code as below...!!!
    SELECT bukrs
    belnr
    gjahr
    xblnr
    waers
    budat
    usnam
    tcode
    awkey
    FROM bkpf
    INTO TABLE gt_bkpf
    WHERE bukrs IN s_bukrs
    AND gjahr IN s_gjahr
    AND tcode EQ 'MIRO'.
    SELECT bukrs
    belnr
    gjahr
    buzei
    koart
    lifnr
    zlspr
    FROM bseg
    INTO TABLE gt_bseg
    FOR ALL ENTRIES IN gt_bkpf
    WHERE bukrs EQ gt_bkpf-bukrs
    AND belnr EQ gt_bkpf-belnr
    AND gjahr EQ gt_bkpf-gjahr
    AND lifnr IN s_lifnr
    AND zlspr IN s_zlspr
    and koart eq 'K'.
    AND bschl EQ '31'.
    gt_bseg1[] = gt_bseg[].
    SORT gt_bseg1[] BY lifnr.
    DELETE ADJACENT DUPLICATES FROM gt_bseg1[] COMPARING lifnr.
    IF gt_bseg1[] IS NOT INITIAL.
    SELECT lifnr
    name1
    FROM lfa1
    INTO TABLE gt_lfa1
    FOR ALL ENTRIES IN gt_bseg1
    WHERE lifnr EQ gt_bseg1-lifnr.
    and lifnr eq s_lifnr.
    ENDIF.
    IF gt_bkpf[] IS NOT INITIAL.
    SELECT belnr
    gjahr
    tcode
    WAERS
    zuonr
    FROM rbkp
    INTO TABLE gt_rbkp
    FOR ALL ENTRIES IN gt_bkpf
    WHERE gjahr EQ gt_bkpf-gjahr
    AND tcode EQ gt_bkpf-tcode
    AND belnr EQ gt_bkpf-awkey+0(10).
    tax amount
    SELECT bukrs
    belnr
    gjahr
    buzei
    fwste
    FROM bset
    INTO TABLE gt_bset
    FOR ALL ENTRIES IN gt_bkpf
    WHERE bukrs EQ gt_bkpf-bukrs
    AND belnr EQ gt_bkpf-belnr
    AND gjahr EQ gt_bkpf-gjahr.
    and fwste ne 0 .
    ENDIF.
    IF gt_rbkp[] IS NOT INITIAL.
    SELECT belnr
    gjahr
    buzei
    cobl_nr
    wrbtr
    menge
    mwskz
    meins
    FROM rbco
    INTO TABLE gt_rbco
    FOR ALL ENTRIES IN gt_rbkp
    WHERE belnr EQ gt_rbkp-belnr.
    ENDIF.
    SELECT ebeln
    ernam
    FROM ekko
    INTO TABLE gt_ekko
    FOR ALL ENTRIES IN gt_rbkp
    WHERE ebeln EQ gt_rbkp-zuonr+0(10).
    IF gt_ekko[] IS NOT INITIAL.
    SELECT banfn
    bnfpo
    ernam
    ebeln
    FROM eban
    INTO TABLE gt_eban
    FOR ALL ENTRIES IN gt_ekko
    WHERE ebeln EQ gt_ekko-ebeln.
    ENDIF.
    ENDFORM. " RETRIEVE_DATA
    *& Form MODIFY_DATA
    text
    --> p1 text
    <-- p2 text
    FORM modify_data .
    *Sorting all Internal Tables .
    SORT gt_bseg BY bukrs belnr gjahr.
    SORT gt_bkpf BY bukrs belnr gjahr.
    SORT gt_lfa1 BY lifnr.
    SORT gt_rbkp BY belnr.
    SORT gt_rbco BY belnr.
    SORT gt_ekko BY ebeln.
    SORT gt_bset BY belnr.
    SORT gt_bset
    SORT gt_eban BY ebeln.
    SORT gt_bkpf .
    SORT gt_bseg .
    SORT gt_lfa1 .
    SORT gt_rbkp .
    SORT gt_rbco .
    SORT gt_ekko .
    SORT gt_bset.
    SORT gt_eban .
    <b>sort gt_bset by belnr.
    loop at gt_bset.
    at end of belnr.
    itab-belnr = gt_bset-belnr.
    sum.
    itab-fwste = gt_bset-fwste.
    append itab.
    clear itab.
    endat.
    endloop.
    delete adjacent duplicates from gt_bset comparing belnr.
    loop at gt_bset.
    read table itab with key belnr = gt_bset-belnr.
    if sy-subrc = 0.
    gt_bset-fwste = itab-fwste.
    modify gt_bset index sy-tabix.
    endif.
    endloop.</b>
    LOOP AT GT_BSEG WHERE BELNR NE ' '.
    MOVE gt_bseg-pswsl TO gt_final-pswsl.
    MOVE gt_bseg-lifnr TO gt_final-lifnr.
    MOVE gt_bseg-zlspr TO gt_final-zlspr.
    READ TABLE GT_BKPF WITH KEY BELNR = GT_BSEG-BELNR BINARY SEARCH.
    IF SY-SUBRC = 0.
    MOVE gt_bkpf-bukrs TO gt_final-bukrs.
    MOVE gt_bkpf-belnr TO gt_final-belnr.
    MOVE gt_bkpf-xblnr TO gt_final-xblnr.
    MOVE gt_bkpf-budat TO gt_final-budat.
    MOVE gt_bkpf-usnam TO gt_final-usnam.
    ENDIF.
    READ TABLE gt_lfa1 WITH KEY lifnr = gt_bseg-lifnr BINARY SEARCH.
    IF sy-subrc = 0.
    MOVE gt_lfa1-name1 TO gt_final-name1.
    ENDIF.
    READ TABLE gt_rbkp WITH KEY belnr = gt_bkpf-awkey+0(10)
    gjahr = gt_bkpf-gjahr
    BINARY SEARCH.
    IF sy-subrc = 0.
    MOVE gt_rbkp-belnr TO gt_final-rbelnr.
    MOVE gt_rbkp-waers TO gt_final-waers.
    MOVE gt_rbkp-zuonr TO gt_final-zuonr.
    endif.
    READ TABLE gt_rbco WITH KEY belnr = gt_rbkp-belnr BINARY SEARCH.
    IF sy-subrc = 0.
    MOVE gt_rbco-buzei TO gt_final-buzei.
    MOVE gt_rbco-wrbtr TO gt_final-wrbtr.
    MOVE gt_rbco-menge TO gt_final-menge.
    MOVE gt_rbco-meins TO gt_final-meins.
    MOVE gt_rbco-mwskz TO gt_final-mwskz.
    endif.
    READ TABLE gt_ekko WITH KEY ebeln = gt_rbkp-zuonr+0(10) BINARY SEARCH.
    IF sy-subrc = 0.
    MOVE gt_ekko-ernam TO gt_final-ernam.
    endif.
    READ TABLE gt_eban WITH KEY ebeln = gt_ekko-ebeln BINARY SEARCH.
    IF sy-subrc = 0.
    MOVE gt_eban-ernam TO gt_final-ernam.
    ENDIF.
    READ TABLE GT_BSET WITH KEY BELNR = GT_BKPF-BELNR BINARY SEARCH.
    IF SY-SUBRC = 0.
    MOVE GT_BSET-FWSTE TO GT_FINAL-FWSTE.
    ENDIF.
    APPEND gt_final.
    endloop.

  • How to read table fields form a table  having length of 7 characters

    HI all,
    could you please tell me how to read table fields from a table having length 7 characters, i have requirement that in my ztable i have 30 fields out of which 20 fields are location fields, i want to select 20 fields which have 7 characters length.
    please could any body suggest me on this issue.
    thanks,
    sre.

    hi,
    try like this
    create a data variable of type i as
    data: len type i.
    create internal table for 20 fields as
    data:begin of itab,
               fld 1 type .......
            end of itab.
    data:itab type itab1 occurs 0 with header line.
    loop at itab2. // original internal table which all fields.
    read table itab2 with index sy-tabix.
    len = strlen (itab2-fld).
    if len eq 7.
          move itab2 itab1.
          append itab1.
    endif.
    endloop.
    if helpful reward some points.
    with regards,
    Suresh.A

  • 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

Maybe you are looking for