Reading internal tables

Hi all
i am using internal table itab1,
i want to add the similar contents of itab1 from itab2 into itab3
how to do it?
thanks
raghvendra bhanap

Hi,
This is a documentation regarding reading internal tables.
Hope this will be useful...
When the size of the record or the number of records in the internal table is large, doing a linear search is time consuming. It is always a good practice to search a record by binary search (Always Sort the table before doing a binary search). The difference is felt especially in the production environment where the live data is usually huge. As of release 4.0 there are new types of internal tables like SORTED and HASHED which can be effectively used to further reduce the search time and processing time.
e.g.     Do not use the following statement:-
Select matnr from mara
Into table i_mara
Where matnr in s_matnr.
     Select matnr werks from marc
          Into table i_marc
          For all entries in i_mara
          Where matnr eq i_mara-matnr.
     Loop at I_mara.
          Read table i_marc with key matnr = I_mara-matnr.
     Endloop.
Instead use the following statement:-
     Select matnr from mara
          Into table i_mara
          Where matnr in s_matnr.
                                   Select matnr werks from marc
                                        Into table i_marc
                                        For all entries in i_mara
                                       Where matnr eq i_mara-matnr.
                                   Sort I_marc by matnr.
                                   Loop at I_mara.
                                        Read table i_marc with key
matnr = I_mara-matnr
binary search.
                                   Endloop.
It is a good practice to search records from internal tables using a binary search. But extreme caution needs to be applied as it may either increase the time or may cause run time termination if it is not sorted.
Always the sort the internal table by the required keys before performing a binary search.                                                                               
e.g.     Do not use the following statement:-
Select matnr from mara
Into table i_mara
Where matnr in s_matnr.
     Select matnr werks from marc
          Into table i_marc
          For all entries in i_mara
          Where matnr eq i_mara-matnr.
     Loop at I_mara.
          Read table i_marc with key matnr = I_mara-matnr binary search.
     Endloop.
Instead use the following statement:-
     Select matnr from mara
          Into table i_mara
          Where matnr in s_matnr.
                                   Select matnr werks from marc
                                        Into table i_marc
                                        For all entries in i_mara
                                       Where matnr eq i_mara-matnr.
                                   Sort I_marc by matnr.
                                   Loop at I_mara.
                                        Read table i_marc with key
matnr = I_mara-matnr
binary search.
                                   Endloop.
It is a general practice to use           Read table <itab>…     This statement populates all the values of the structure in the workarea.
The effect is many fold:-
•     It increases the time to retrieve data from internal table
•     There is large amount of unused data in work area
•     It increases the processing time from work area later
It is always a good practice to retrieve only the required fields. Always use the syntax      Read table <itab> transporting f1 f2  …  FN …          If just a check is being performed for existence of a record use      Read table <itab> transporting no fields …
e.g.     Do not use the following statement:-
data: i_vbak like vbak occurs 0 with header line.
data: i_vbap like vbap occurs 0 with header line.
Loop at i_vbak.
     read table i_vbap with key
vbeln = i_vbak-vbeln binary search.
     If sy-subrc = 0 and i_vbap-posnr = ‘00010’.
     endif.
Endloop.
Instead use the following statement:-
data: i_vbak like vbak occurs 0 with header line.
data: i_vbap like vbap occurs 0 with header line.
Loop at i_vbak.
                              read table i_vbap transporting posnr with key
vbeln = i_vbak-vbeln binary search.
                              If sy-subrc = 0 and i_vbap-posnr = ‘00010’.
                              endif.
Endloop.
There are many ways in which a select statement can be optimized. Effective use of primary and secondary indexes is one of them. Very little attention is paid especially to the secondary indexes. The following points should be noted before writing a select statement:-
•     Always use the fields in the where clause in the same order as the keys in the database table
•     Define the secondary indexes in the database for the fields which are most frequently used in the programs
•     Always try to use the best possible secondary index in the where clause if it exists
•     Do not have many secondary indexes defined for a table
•     Use as many keys both primary and secondary as possible to optimize data retrieval
As of release 4.5 it is now possible to define the secondary index in the where clause using %_HINT.
e.g.     Do not use the following statement:-
     Assuming a secondary index is defined on the field vkorg in table vbak
     Select vbeln vkorg from vbak
          Into table i_vbak
          Where vbeln in s_vbeln.
     Loop at i_vbak.
          Case i_vbak-vkorg.
          When ‘IJI1’.
          When ‘IJI2’.
          Endcase.
     Endloop.
Instead use the following statement:-
                                   Select vbeln vkorg from vbak
                                        Into table i_vbak
                                        Where vbeln in s_vbeln and
                                             Vkorg in (‘IJI1’,’IJI2’).
                                   Loop at i_vbak.
                                        Case i_vbak-vkorg.
                                        When ‘IJI1’.
                                        When ‘IJI2’.
                                        Endcase.
                                   Endloop.

Similar Messages

  • Ho to read intern table in update rule?

    Hello experts,
    I have the following start routine:
    PROGRAM UPDATE_ROUTINE.
    $$ begin of global - insert your declaration only below this line  -
    TABLES: /BIC/AZD_ODS_C00.
    DATA: ITEM_TABLE TYPE STANDARD TABLE OF /BIC/AZD_ODS_C00
          WITH HEADER LINE
          WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 0.
    DATA: gv_flag type c.
    $$ end of global - insert your declaration only before this line   -
    $$ begin of routine - insert your code only below this line        -
    fill the internal tables "MONITOR" and/or "MONITOR_RECNO",
    to make monitor entries
    SELECT * FROM  /BIC/AZD_ODS_C00 INTO TABLE ITEM_TABLE.
    SORT ITEM_TABLE BY /BIC/ZABOOKID ASCENDING.  
           LOOP AT ITEM_TABLE.
            AT NEW /BIC/ZABOOKID.
            GV_FLAG = 'X'.
            ENDAT.
           ENDLOOP.
    if abort is not equal zero, the update process will be canceled
      ABORT = 0.
    How can I read intern table ITEM_TABLE in a update rule?
    And will gv_flag be still available in update rule?
    thanx
    hiza
    Message was edited by:
            Hiza
    Message was edited by:
            Hiza

    Hi,
    I am just giving you a sample code which I had used
    just try to read this will help you
    PROGRAM UPDATE_ROUTINE.
    $$ begin of global - insert your declaration only below this line  -
    TABLES: ...
    DATA:   ...
    $$ end of global - insert your declaration only before this line   -
    The follow definition is new in the BW3.x
    TYPES:
      BEGIN OF DATA_PACKAGE_STRUCTURE.
         INCLUDE STRUCTURE /BIC/CSZRINF001.
    TYPES:
         RECNO   LIKE sy-tabix,
      END OF DATA_PACKAGE_STRUCTURE.
    DATA:
      DATA_PACKAGE TYPE STANDARD TABLE OF DATA_PACKAGE_STRUCTURE
           WITH HEADER LINE
           WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 0.
    FORM startup
      TABLES   MONITOR STRUCTURE RSMONITOR "user defined monitoring
               MONITOR_RECNO STRUCTURE RSMONITORS " monitoring with record n
               DATA_PACKAGE STRUCTURE DATA_PACKAGE
      USING    RECORD_ALL LIKE SY-TABIX
               SOURCE_SYSTEM LIKE RSUPDSIMULH-LOGSYS
      CHANGING ABORT LIKE SY-SUBRC. "set ABORT <> 0 to cancel update
    $$ begin of routine - insert your code only below this line        -
    fill the internal tables "MONITOR" and/or "MONITOR_RECNO",
    to make monitor entries
    break-point.loop at DATA_PACKAGE.if DATA_PACKAGE-/BIC/ZREMPID GE 5.delete DATA_PACKAGE.endif.endloop.
    if abort is not equal zero, the update process will be canceled
      ABORT = 0.
    $$ end of routine - insert your code only before this line         -
    Regards
    Rahul

  • Read internal table with key not equal to

    Hi,
    How can I read internal table with key not equal to some other field.
    Basically in read statement we can read only fields equal to others fields.

    Hi,
    Test the following Code you can Use Loop at for this But not Read Table
    DATA: BEGIN OF it_test OCCURS 10,
      f1(4),
      f2 TYPE i,
      f3(2),
      END OF it_test.
    DATA: it_test2 LIKE STANDARD TABLE OF it_test WITH HEADER LINE.
    it_test-f1 = '1000'.
    it_test-f2 = 10.
    it_test-f3 = 'B'.
    APPEND it_test TO it_test.
    it_test-f1 = '2000'.
    it_test-f2 = 10.
    it_test-f3 = 'A'.
    APPEND it_test TO it_test.
    it_test-f1 = '1000'.
    it_test-f2 = 10.
    it_test-f3 = 'B'.
    APPEND it_test TO it_test.
    it_test-f1 = '1000'.
    it_test-f2 = 10.
    it_test-f3 = 'A'.
    APPEND it_test TO it_test.
    it_test-f1 = '1000'.
    it_test-f2 = 40.
    it_test-f3 = 'A'.
    APPEND it_test TO it_test.
    LOOP AT it_test INTO it_test WHERE f3 NE 'A'.
      WRITE: / it_test-f1, it_test-f2, it_test-f3.
    ENDLOOP.
    Kind Regards,
    Faisal

  • Read internal table from report.

    Hi all.
    I want to know is it possible to read internal table from report without modifying the report. is there any function module by which we can run the report and read data from internal table?
    Thanks.

    hi
    hope it will help you.
    <REMOVED BY MODERATOR>
    Read table doesn't allow ne operator.
    It reads only one record...Either by index or key.
    READ TABLE MY_TAB INDEX 1.
    READ TABLE MY_TAB WITH KEY CODE = 'ATG'.
    these are the results for SY-SUBRC checks after read table
    SY-SUBRC = 0:
    An entry was read.
    SY-TABIX is set to the index of the entry.
    SY-SUBRC = 2:
    An entry was read.
    SY-TABIX is set to the index of the entry. This return code can only occur when you use the COMPARING addition. For further detauls, refer to the COMPARING section of the additions
    SY-SUBRC = 4:
    No entry was read.
    The value of SY-TABIX depends on the table type and whether the BINARY SEARCH addition was specified.
    If the table is a SORTED TABLE or a table sorted in ascending order of the type STANDARD TABLE with the BINARY SEARCH addition, SY-TABIX refers to the next-highest index.
    Otherwise, SY-TABIX is undefined.
    SY-SUBRC = 8:
    No entry was read.
    This return code only occurs with a SORTED TABLE or a STANDARD TABLE with the BINARY SEARCH addition. SY-TABIX is set to the number of all entries plus 1.
    Reading records with keys
    http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm
    Reading lines with Index
    http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3730358411d1829f0000e829fbfe/content.htm
    Edited by: Alvaro Tejada Galindo on Feb 19, 2008 5:43 PM

  • Loop using index read ( internal table)

    Hi,
    I thought of impelementing loop at ITAB using read statements, Here it goes.
    REPORT Z_LOOP_IMPROVE.
    DATA : T_OUTPUT TYPE STANDARD TABLE OF MARC WITH HEADER LINE,
    L_TABIX TYPE SY-TABIX.
    DEFINE ILOOP.
    DO.
    IF SY-INDEX EQ '1'.
    READ TABLE &1 WITH KEY &2 = &3 BINARY SEARCH.
    IF SY-SUBRC <> 0.
    EXIT.
    ENDIF.
    ELSE.
    L_TABIX = SY-TABIX + 1.
    READ TABLE &1 INDEX L_TABIX.
    IF SY-SUBRC NE 0 OR &1-&2 NE &3.
    EXIT.
    ENDIF.
    ENDIF.
    END-OF-DEFINITION.
    DEFINE IENDLOOP.
    ENDDO.
    END-OF-DEFINITION.
    DATA : T1 TYPE I, T2 TYPE I.
    SELECT * FROM MARC INTO TABLE T_OUTPUT.
    SORT T_OUTPUT BY WERKS.
    GET RUN TIME FIELD T1.
    ILOOP T_OUTPUT WERKS '0001'.
    WRITE : / T_OUTPUT-MATNR, T_OUTPUT-WERKS.
    IENDLOOP.
    GET RUN TIME FIELD T2.
    T2 = T2 - T1.
    WRITE : / T2.
    *C----
    But sadly it takes more time than a normal loop with
    where condition.
    can anyone suggest some ideas to improve execution speed?

    You can use a binary read to get the first record. Then read each record sequentially until you have proccessed all the records that meet your critera. You will have to have the internal table sorted so that the binary search and subsequent reads will work:
          READ TABLE itab WITH KEY
            field = whatever
            BINARY SEARCH.
          IF sy-subrc = 0.
            itab_index = sy-tabix.
            DO.
              IF sy-subrc = 0.
                IF itab_data-field = whatever
                  itab_index = itab_index + 1.
                  READ TABLE itab_data INDEX itab_index.
                ELSE.
                  EXIT.
                ENDIF.
              ELSE.
                EXIT.
              ENDIF.
            ENDDO.
          ENDIF.
    Rob

  • How to read internal table other program (assign?)

    Hello techies,
    The problem >
    I have 2 Sap standard programs A & B
    I'm editing a userexit in program B but I need to read
    data from program A that is also running.
    While using the debugger, I can ask for the folowing
           (A)internaltable
            example : (SAPLMEPO)pot
    this shows the content of internal table "pot" of the program "SAPLMEPO".
    The question>
    How can I copy the content of a table(ex. pot) in program "A"(ex. SAPLMEPO) to a internal table pot2 of program "B"?
    Possible sollution (does not work in 5.0)
    CODE SAMPLE *************
    Fields          **
    data: w_name type char50,"help field
          w_recpot like ekpo."help structure
    Internal tables **
    data: Begin of it_pot2 occurs 0.
       include structure it_pot2.
    data: End of it_pot2
    field-symbols <fs_pot> type any table.
    w_structure_name = '(SAPLMEPO)pot'.
    assign (w_structure_name) to <fs_pot>.
    loop at <fs_pot> into w_recpot.
    it_pot2 = w_recpot.
    append it_pot2
    Endloop.
    END CODE SAMPLE *************
    Thanks in advance,
    Frederik

    Hi again,
    1. Simple.
    2. In your case, u should use
      <b>[]</b>
      DATA : myitab LIKE TABLE OF t001 WITH HEADER LINE.
      DATA : w_struct_name(100) TYPE c.
      BREAK-POINT.
      FIELD-SYMBOLS <fs_pot> TYPE ANY TABLE.
    <b>  w_struct_name = '(ZAM_TEMP0)ITAB[]'.</b>
      ASSIGN (w_struct_name) TO <fs_pot>.
    3. No need to use Loop etc.
    4. *----
    In your case
    CODE SAMPLE *************
    Fields **
    data: w_name type char50,"help field
    w_recpot like ekpo."help structure
    Internal tables **
    data: Begin of it_pot2 occurs 0.
    include structure it_pot2.
    data: End of it_pot2
    field-symbols <fs_pot> type any table.
    w_structure_name = '<b>(SAPLMEPO)POT[]</b>'.
    assign (w_structure_name) to <fs_pot>.
    NOT REQUIRED
    *loop at <fs_pot> into w_recpot.
    *it_pot2 = w_recpot.
    *append it_pot2
    *Endloop.
    END CODE SAMPLE *************
    regards,
    amit m.

  • Reading internal table into File Adapter

    Hi,
    I would like to read an internal table from RFC function (sender), and write all the rows into the file by using File Adapter. Here is the scenerio;
    RFC Adapter -> XI -> File adapter
    Internal table content, below;
    FLD1  FLD2   FLD3
    1        A        B
    2        X        Y
    I expect the result, below;
    <?xml version="1.0" encoding="UTF8" ?>
    <rfc:Z_RFC xmlns:rfc="urn:sapcom:document:sap:rfc:functions">
    <ITAB_ZSUBS001>
      <item>
       <FLD1>1</FLD1>
       <FLD2>A</FLD2>
       <FLD3>B</FLD3>
      </item>
      <item>
       <FLD1>2</FLD1>
       <FLD2>X</FLD2>
       <FLD3>Y</FLD3>
      </item>
    </ITAB_ZSUBS001>
    </rfc:Z_RFC>
    I see all the records in payload, but cannot write into file. Anybody have any suggestion? Thank you.
    Regards,
    Orkun Gedik
    Message was edited by:
            Orkun GEDIK

    Hi,
    Thank you for the feedback. From now on I am getting the error, below;
    Error> occured [1] >Thu Apr 05 09:24:21,046<   
    RfcException:
        message: Commit fault: com.sap.aii.af.rfc.afcommunication.RfcChannelMismatchException: Wrong Sender Agreement:The Sender agreement does not have channel Rfc_Fiyat_Sender configured for the functionmodule Z_RFC
        Return code: RFC_CLOSED(6)
        error group: 108
        key: RFC_ERROR_INTERNAL
    Please see the last configuration, below;
    Message mappings:
    RFC Message:
    Messages 1..1
    Message1 1..1
    Z_RFC 1..1
    ITAB_ZSUBS001 1..1
    item 0..unbounded
    TXTKOD 0..1
    TXTAD 0..1
    TXTADDR 0..1
    Message Type: Malzeme
    Messages 1..1
    Message1 1..1
    Malzeme 0..unbounded
    TXTKOD 1..1
    TXTAD 1..1
    TXTADDR 1..1
    Interface mappings:
    Source Interface: Z_RFC Occurrence 1
    Target Interface: MI_MAlzeme_In_Asyn Occurrence 0..unbounded
    I bound the items below;
    item -> Malzeme
    TXTKOD -> TXTKOD
    TXTAD -> TXTAD
    TXTADDR -> TXTADDR
    Also,I refreshed the adapter cache and full cache by using SXI_CACHE and restart the RFC adapter thorugh Visual Admin in order to solve the problem, but it couldn't be a solution for the problem. Do you have any suggestion about it?
    Regards
    Message was edited by:
            Orkun GEDIK

  • Reg - Reading internal table with multiple record in a single field

    Dear Guru's,
                        i want to read a internal table with field having mutilple entries like
    read table READ TABLE LT_T2 INTO LT_T2_WA WITH KEY HKONT IN ( '0001152430', '0001152930', '0001152410' ).
    But it says comma without preceding colon (after READ?).
    please guide me.....
    thanks & Regards,
    Balaji.S

    ya this is inside the loop.
    plz check....
    loop at lt_t2 into lt_t2_wa.
    READ TABLE LT_T2 INTO LT_T2_WA WITH KEY HKONT IN ( '0001152430', '0001152930', '0001152410' ).
    endloop.
    thanks & Regards,
    Balaji.S

  • Reading internal table issue?

    SELECT PERNR WERKS ABKRS BUKRS KOSTL ENAME GSBER FROM PA0001
                INTO TABLE GT_0001
                FOR ALL ENTRIES IN GT_0709
               WHERE PERNR = GT_0709-PERNR
                 AND ENDDA >= P_DATE
                 AND BEGDA <= P_DATE.
             READ TABLE GT_0001 INTO LS_0001 WITH TABLE KEY PERNR = LS_0709-PERNE
             IF SY-SUBRC = 0.
            CALL FUNCTION 'PA03_PCR_READ'
          EXPORTING
            F_ABKRS         = LS_0001-ABKRS
          IMPORTING
            F_CURRENT_BEGDA = GV_BEGINDATE
            F_CURRENT_ENDDA = GV_ENDDATE.
            ENDIF.
    IN THIS CODE WHILE READING THE INTERNAL TABLE IT IS SHOWING ERROR?
    PLEASE CORRECT THE CODE.
    REGARDS
    REDDY

    Hi,
    Please remove 'TABLE' keyword from your syntax.
    Check the datatype of field PERNR & PERNE. It shoud be same.
    Check the value which is in PERNE fied shoud be available in PERNR Field or not?
    Hope by this things you will be able to resolve issue.
    Regards,
    Narendra

  • SELECT-OPTIONS can u use it to read internal table ?????

    Hello All,
       I am trying to read an internal table with the select-options statement. I am getting a syntax error so i am hoping i am just coding it incorrectly. Can someone tell me what is wrong here is the if statement :
    if p_begdte in t_rpt-datab and
           p_enddte in t_rpt-datbi.
        else.
           exit.
        endif.
    thanks scott

    This is not working?
    tables: a916.
    * Beg valid date *
    data text021(29).
    selection-screen begin of line.
    selection-screen comment 1(30) text-021 for field p_begdte.
    selection-screen position 32.
    select-options: p_begdte for a916-datab default '20041101' to
    '99991231'.
    selection-screen end of line.
    * End valid date *
    data text022(29).
    selection-screen begin of line.
    selection-screen comment 1(30) text-022 for field p_enddte.
    selection-screen position 32.
    select-options: p_enddte for a916-datbi default '20041101' to
    '99991231'.
    selection-screen end of line.
    start-of-selection.
    <b>Loop at t_rpt.
    if t_rpt-datab in p_begdte
      and t_rpt-datbi in p_endte.
    * do something
    else.
    exit.
    endif
    Endloop.</b>
    Regards,
    Rich Heilman

  • READ Internal Table

    Hi
      I face many situations where i have to issue a READ statement on an Internal Table where i have to use "<" or ">" operators. READ just allows to use keys with all "=" operators.But at the same time i need to get just one record. I know that READ is to get only one record.
    Any suggestion ?

    Ok if you have exactly pasted your problem  then try this , it will be much more fast . Also see F1 help on read and sy-subrc value , you will get the clue here.
    <i>REPORT ZTEST.
    DATA : BEGIN OF WA_TAB,
           DATE LIKE SY-DATUM,
           TIME LIKE SY-UZEIT,
           AMOUNT TYPE P DECIMALS 2,
    END OF WA_TAB.
    DATA ITAB1 LIKE SORTED TABLE OF WA_TAB WITH UNIQUE DEFAULT KEY WITH HEADER LINE..
    DATA ITAB2 LIKE SORTED TABLE OF WA_TAB WITH UNIQUE DEFAULT KEY WITH HEADER LINE..
    DATA COUNT TYPE I.
    ITAB1-DATE = '20050919'.
    ITAB1-TIME = '010000'.
    ITAB1-AMOUNT = 50.
    APPEND ITAB1.
    ITAB1-DATE = '20050919'.
    ITAB1-TIME = '020000'.
    ITAB1-AMOUNT = 60.
    APPEND ITAB1.
    ITAB1-DATE = '20050919'.
    ITAB1-TIME = '030000'.
    ITAB1-AMOUNT = 70.
    APPEND ITAB1.
    ITAB2-DATE = '20050918'.
    ITAB2-TIME = '021000'.
    APPEND ITAB2.
    LOOP AT ITAB2 .
      READ TABLE ITAB1 WITH KEY DATE = ITAB2-DATE
                                TIME = ITAB2-TIME.
      IF SY-SUBRC = 4 OR SY-SUBRC = 8 .
        COUNT = SY-TABIX - 1 .
      ENDIF.
      IF COUNT GE 1.
        READ TABLE ITAB1 INDEX COUNT .
        MOVE ITAB1-AMOUNT TO ITAB2-AMOUNT.
        MODIFY ITAB2.
        WRTIE ITAB2-AMOUNT.
      ENDIF.
    ENDLOOP.</i>
    Try changing the date and time values in ITAB2 and see the desired result.
    Cheers

  • Read Internal Table based on Multiple Values for Key Field

    Hi Gurus,
    i have one query can you tell me how read an internal table it_kna1 for multiple values of land1 DE US IND etc.
    i had tried as below but i could not can you try and let me knwo at the earliest.
    here i want read the values with DE or US and want further prosess them.
    REPORT  YC001.
    tables kna1.
    select-options: cust for kna1-kunnr.
    data: begin of it_kna1 occurs 0,
            kunnr like kna1-kunnr,
            name1 like kna1-name1,
            land1 like kna1-land1,
            end of it_kna1.
    select kunnr name1 land1 into table it_kna1 from kna1 where kunnr in cust.
    read table it_kna1 with key land1 = ( 'DE' OR 'US' ) .
    can anybody suggest me some solution.
    Thanks,
    Jeevi.

    This should be what you need:
    REPORT ztest NO STANDARD PAGE HEADING LINE-SIZE 80 MESSAGE-ID 00.
    TABLES kna1.
    SELECT-OPTIONS: cust FOR kna1-kunnr.
    DATA: BEGIN OF it_kna1 OCCURS 0,
            kunnr LIKE kna1-kunnr,
            name1 LIKE kna1-name1,
            land1 LIKE kna1-land1,
          END OF it_kna1.
    DATA: itab_index LIKE sy-tabix.
    SELECT kunnr name1 land1
      INTO TABLE it_kna1
      FROM kna1
      WHERE kunnr IN cust.
    SORT it_kna1 BY land1.
    READ TABLE it_kna1 WITH KEY
      land1 = 'DE'
      BINARY SEARCH.
    itab_index = sy-tabix.
    WHILE sy-subrc = 0.
      itab_index = itab_index + 1.
      WRITE: /001 it_kna1-kunnr, it_kna1-land1, it_kna1-name1.
      READ TABLE it_kna1 INDEX itab_index.
      IF it_kna1-land1 <> 'DE'.
        sy-subrc = 99.
      ENDIF.
    ENDWHILE.
    SKIP 1.
    READ TABLE it_kna1 WITH KEY
      land1 = 'US'
      BINARY SEARCH.
    itab_index = sy-tabix.
    WHILE sy-subrc = 0.
      itab_index = itab_index + 1.
      WRITE: /001 it_kna1-kunnr, it_kna1-land1, it_kna1-name1.
      READ TABLE it_kna1 INDEX itab_index.
      IF it_kna1-land1 <> 'US'.
        sy-subrc = 99.
      ENDIF.
    ENDWHILE.
    Rob

  • Need help in reading internal table data

    Hi All,
    I have two internal tables, it_cdhdr and it_cdpos. Data as follows:
    it_cdhdr:
    Objectclass     ObjectId          Changenr         Udate      Change_ind
    EINKBELEG    4500057161    0003273002    20131129    U
    EINKBELEG    4500057161    0003273001    20131129    U
    EINKBELEG    4500057161    0003272995    20131129    U
    EINKBELEG    4500057161    0003178904    20131030    U
    EINKBELEG    4500057161    0003178903    20131030    U
    it_cdpos
    Objectclas       ObjectId          Changenr      Tabname   Fname Value_new Value_old
    EINKBELEG    4500057161    0003178903    EKKO    FRGKE         A                B
    EINKBELEG    4500057161    0003178903    EKKO    FRGZU          X
    EINKBELEG    4500057161    0003178903    EKKO    PROCSTAT    05                03
    EINKBELEG    4500057161    0003178903    EKKO    RLWRT       800.00            0.00
    EINKBELEG    4500057161    0003178904    EKET    MENGE      1000.000         800.000
    EINKBELEG    4500057161    0003178904    EKKN    MENGE       500.000          400.000
    EINKBELEG    4500057161    0003178904    EKKN    NETWR            500.00        400.00
    EINKBELEG    4500057161    0003178904    EKKO    FRGKE          B                 A
    EINKBELEG    4500057161    0003178904    EKKO    FRGZU          X
    EINKBELEG    4500057161    0003178904    EKKO    PROCSTAT    03                 05
    EINKBELEG    4500057161    0003178904    EKKO    RLWRT       1000.00              800.00
    EINKBELEG    4500057161    0003178904    EKPO    BRTWR       1000.00            800.00
    EINKBELEG    4500057161    0003178904    EKPO    MENGE      1000.000           800.000
    EINKBELEG    4500057161    0003178904    EKPO    NETWR      1000.00            800.00
    EINKBELEG    4500057161    0003272995    EKKO    FRGKE        A                       B
    EINKBELEG    4500057161    0003272995    EKKO    FRGZU        X
    EINKBELEG    4500057161    0003272995    EKKO    PROCSTAT    05    03
    EINKBELEG    4500057161    0003273001    EKET    MENGE          2000.000          1000.000
    EINKBELEG    4500057161    0003273001    EKKN    MENGE          1000.000           500.000
    EINKBELEG    4500057161    0003273001    EKKN    NETWR           1000.00            500.00
    EINKBELEG    4500057161    0003273001    EKKO    FRGKE    B    A
    EINKBELEG    4500057161    0003273001    EKKO    FRGZU        X
    EINKBELEG    4500057161    0003273001    EKKO    PROCSTAT    03    05
    EINKBELEG    4500057161    0003273001    EKKO    RLWRT             2000.00             1000.00
    EINKBELEG    4500057161    0003273001    EKPO    AEDAT    20131129    20131030
    EINKBELEG    4500057161    0003273001    EKPO    BRTWR           2000.00           1000.00
    EINKBELEG    4500057161    0003273001    EKPO    MENGE          2000.000          1000.000
    EINKBELEG    4500057161    0003273001    EKPO    NETWR           2000.00           1000.00
    EINKBELEG    4500057161    0003273002    EKKO    FRGKE    A    B
    EINKBELEG    4500057161    0003273002    EKKO    FRGZU    X
    EINKBELEG    4500057161    0003273002    EKKO    PROCSTAT    05    03
    As per requirement, the main focus is on Changes to EKKN and EKPO tables and I have to get the latest changes.
    If you observe in above it_cdpos internal table data, it has two records,
    EINKBELEG    4500057161    0003178904    EKKN    NETWR            500.00        400.00
    EINKBELEG    4500057161    0003178904    EKPO    NETWR      1000.00            800.00
    EINKBELEG    4500057161    0003273001    EKKN    NETWR           1000.00            500.00
    EINKBELEG    4500057161    0003273001    EKPO    NETWR           2000.00           1000.00
    Now I have read only the latest changenr data. Say 0003273001 , in this case.
    My question is how do I know, the latest changenr has EKKN table changes, if you look at it_cdpos data above, the latest one is 0003273002, which doesnt have EKKN changes.
    Kindly let me know how to read latest EKKN or EKPO data from IT_CDPOS table.
    Thanks in advance,
    Rgs,
    Priya

    Hi Priya ,
    I guess your requirement is to find the latest change number ,that has got change in both ekkn and ekkpo .
    1- Sort it_cdhdr descending .
    Loop at it_chdr into w_cdhdr
      read table it_cdpos into w_cdpos with key changenr = w_cdhdr Tabname = ekkn .
       if sy-subrc=0 .
         read table it_cdpos into w_cdpos with key changenr = w_cdhdr Tabname = ekkpo .
           if sy-subrc=0 .
            "use convenient  way to return change number (using varaiable)"
             exit .
           endif .
       endif.
      endloop .
    By this way change number send will be the latest having both ekkn and ekkpo . If what i assumed is wrong ,then sorry for that . 

  • How to read internal table data and use to retrive from other table.

    Hi all,
        I am trying to generate a report using ooabap.
    In this scenario, I retrieved data from one standard table (zcust) and successfully displayed using structure 'i_zcust_final' ( i_zcust_final is similar structure of zcust).  
        Now I want to get some other data from other standard table  (zpurch) using the data in i_zcust_final. How....???? I am unable to read data from i_zcust_final even i kept in loop.
        I am attaching the code here.. even it too long, please look at the code and suggest me what to do.
    code  **************************
    REPORT  ZBAT_OOPS_REPORT1.
    TABLES: ZCUST.
        D E F I N I T I O N     *****
    CLASS BATLANKI_CLS DEFINITION.
      PUBLIC SECTION.
      DATA : ITAB_ZCUST TYPE STANDARD TABLE OF ZCUST,
             I_ZCUST_FINAL LIKE LINE OF ITAB_ZCUST,
             ITAB_ZCUST1 TYPE STANDARD TABLE OF ZCUST.
      TYPES: BEGIN OF IT_ZPURCH,
              CUSTNUM   TYPE ZPURCH-CUSTNUM,
              PURC_DOC  TYPE ZPURCH-PURC_DOC,
              VENDOR    TYPE ZPURCH-VENDOR,
              STATUS    TYPE ZPURCH-STATUS,
              PURC_ORG  TYPE ZPURCH-PURC_ORG,
            END OF IT_ZPURCH.
      DATA : ITAB_ZPURCH TYPE TABLE OF IT_ZPURCH,
             I_ZPURCH_FINAL LIKE LINE OF ITAB_ZPURCH.
      METHODS: GET_ZCUST,
               PRINT_ZCUST,
               GET_ZPURCH.
    ENDCLASS.
    I N I T I A L I Z T I O N   *****
        SELECT-OPTIONS:S_CUSNUM FOR ZCUST-CUSTNUM.
    INITIALIZATION.
    S_CUSNUM-LOW = '0100'.
    S_CUSNUM-HIGH = '9999'.
    S_CUSNUM-OPTION = 'BT'.
    S_CUSNUM-SIGN   = 'I'.
    APPEND S_CUSNUM.
    CLEAR S_CUSNUM.
    I M P L E M E N T A T I O N *****
    CLASS BATLANKI_CLS IMPLEMENTATION.
      METHOD GET_ZCUST.
      SELECT * FROM ZCUST
        INTO TABLE ITAB_ZCUST
       WHERE CUSTNUM IN S_CUSNUM.
    ENDMETHOD.
      METHOD PRINT_ZCUST.
       LOOP AT ITAB_ZCUST INTO I_ZCUST_FINAL.
       WRITE:/ I_ZCUST_FINAL-CUSTNUM,
               I_ZCUST_FINAL-CUSTNAME,
               I_ZCUST_FINAL-CITY,
               I_ZCUST_FINAL-EMAIL.
       ENDLOOP.
      ENDMETHOD.
       METHOD GET_ZPURCH.
    LOOP AT ITAB_ZCUST INTO ITAB_ZCUST1.
      SELECT CUSTNUM
             PURC_DOC
             VENDOR
             STATUS
             PURC_ORG
        FROM ZPURCH
        INTO CORRESPONDING FIELDS OF TABLE ITAB_ZPURCH
        WHERE CUSTNUM EQ I_ZCUST_FINAL-CUSTNUM.
    ENDLOOP.
         LOOP AT ITAB_ZPURCH INTO I_ZPURCH_FINAL.
         WRITE:/ I_ZPURCH_FINAL-CUSTNUM,
                 I_ZPURCH_FINAL-PURC_DOC,
                 I_ZPURCH_FINAL-VENDOR,
                 I_ZPURCH_FINAL-STATUS,
                 I_ZPURCH_FINAL-PURC_ORG.
         ENDLOOP.
    ENDMETHOD.
    ENDCLASS.
      O B J E C T   *****
    DATA: BATLANKI_OBJ TYPE REF TO BATLANKI_CLS.
    START-OF-SELECTION.
    CREATE OBJECT BATLANKI_OBJ.
    CALL METHOD:
                 BATLANKI_OBJ->GET_ZCUST,
                 BATLANKI_OBJ->PRINT_ZCUST,
                 BATLANKI_OBJ->GET_ZPURCH.
    Can anyone suggest me..
      Thanks in advance,
      Surender.

    Hi Surendar..
    There is mistake in the Work area specification in this method.
    METHOD GET_ZPURCH.
    LOOP AT ITAB_ZCUST INTO ITAB_ZCUST1.
    SELECT CUSTNUM
    PURC_DOC
    VENDOR
    STATUS
    PURC_ORG
    FROM ZPURCH
    INTO CORRESPONDING FIELDS OF TABLE ITAB_ZPURCH
    <b>WHERE CUSTNUM EQ      ITAB_ZCUST1-CUSTNUM.</b>           
                                   "Instead of  I_ZCUST_FINAL-CUSTNUM.
    ENDLOOP.
    LOOP AT ITAB_ZPURCH INTO I_ZPURCH_FINAL.
    WRITE:/ I_ZPURCH_FINAL-CUSTNUM,
    I_ZPURCH_FINAL-PURC_DOC,
    I_ZPURCH_FINAL-VENDOR,
    I_ZPURCH_FINAL-STATUS,
    I_ZPURCH_FINAL-PURC_ORG.
    ENDLOOP.
    ENDMETHOD.
    Now it should work..
    One more thing : From performance point of view you have to Replace that loop using FOR ALL ENTRIES . And avoid CORRESPONDING FIELDS. it will be slow.
    This is the code.
    LOOP AT ITAB_ZCUST INTO ITAB_ZCUST1.
    if ITAB_ZCUST[] IS NOT INITIAL.
    SELECT CUSTNUM
    PURC_DOC
    VENDOR
    STATUS
    PURC_ORG
    FROM ZPURCH
    INTO TABLE ITAB_ZPURCH
    <b>for all entries in ITAB_ZCUST1</b>
    <b>WHERE CUSTNUM EQ      ITAB_ZCUST1-CUSTNUM.</b>           
                                   "Instead of  I_ZCUST_FINAL-CUSTNUM.
    ENDIF.
    ENDLOOP.
    <b>Reward if Helpful.</b>

  • System error on reading internal table DYNTAB, screen 7313

    Hello,
    I'm trying to create a customer master in batch mode. I get this error when saving. If I create the customer on-line, I'm able to create with no errors. When I create using a program, I get the error and have to exit.
    Does anyone have a clue on what to do?
    Thanks,
    Theresa

    Looks like its having a hard time doing something with the tabstrip on the screen.  Does your XD01 screen look the same as it does during the BDC recording?  If not, you may have to compensate.  I don't really now exactly what your problem is, but I can make some guesses.  During the recording,  do you click on the tabs or do you switch tabs by using the tab selector on the right of the tabstrip?
    Regards,
    Rich Heilman

Maybe you are looking for

  • WCM Error while saving Project

    Hi, I am getting following error while saving new created project in cProject. Saving is not possible because the WFM Core data could not be adjusted Message no. PRP086 Diagnosis When checking the project role or project role staffing, differences to

  • To display condition types in sales order

    Hi Gurus, When the condition records are maintained for the condition types they are displayed in the sales order,here user has to create the condition records, without knowing the condition types he cannot create the records. One method is creating

  • MDM or XI for a workflow consultant...

    Hi there, I have been working in SAP ABAP workflow for 3+ years now. Now I am looking to add some more skills. I am thinking of either taking up MDM  (work with MDM workflows) or XI (work with ccBPM). I am confused, please help me. Thanks, Sukumar.

  • IWeb Photo Download

    From an iWeb page can you download photos onto a computer? It used to work if you right click and you could save a picture, but now the pictures are only in .gif format and they are transparent. Are there any settings that I should choose or correct?

  • Transport and storage of battery

    Hello I will shortly be shipping various equipment from the UK to New Zealand, including my PowerBook G4. The anticipated shipping will take 9-12 weeks. Should I fully remove the battery from my laptop or leave it insitu? I am not sure, and wondered