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

Similar Messages

  • Use secondary index in internal tables.

    what are the uses of secondary index in internal table?

    http://help.sap.com/saphelp_nw04/helpdata/en/cf/21eb47446011d189700000e8322d00/content.htm
    Creating Secondary Indexes
    Proceed as follows to create a secondary index on a table:
    In the field maintenance screen for the table, choose Goto --> Indexes.
    1. If you went to the field maintenance screen of the table in display mode, only correct the index (and not the table).
    If indexes already exist on the table, a list of these indexes is displayed. Choose Create. A dialog box appears in which you must enter the three-place index identifier. If there are no indexes, go directly to the dialog box.
    2. Enter the index identifier and choose Continue.
    You will go to the maintenance screen for indexes.
    3. Enter an explanatory short text in the field Short text.
    Choose TabFields.
    4. A list of all the fields of the table is displayed.
    5. Select the fields which you want to copy to the index.
    6. Choose Copy.
    The selected fields are copied to the index.
    7. If the values in the index fields already uniquely identify each record of the table, select Unique index.
    A unique index is automatically created on the database during activation because a unique index also has a functional meaning (prevents double entries of the index fields).
    8. If it is not a unique index, leave Non-unique index selected. In this case you can use the corresponding radio buttons to define whether the index should be created automatically on the database for all database systems, for selected database systems or for no database system.
    9. If you chose For selected database systems, you must specify these systems.
    You have two possibilities here:
    List of inclusions: The index is only created automatically during activation for the database systems specified in the list. The index is not created on the database for the other database systems.
    List of exclusions: The index is not created automatically on the database during activation for the specified database systems. The index is automatically created on the database for the other database systems.
    Click on the arrow symbol behind the radio buttons. A dialog box appears in which you can define up to 4 database systems. Use the corresponding radio buttons to decide whether this list should be treated as a list of inclusions or exclusions.
    10. Activate the index with Index ® Activate. The activation log tells you about the flow of the activation. Call it with Utilities ® Act.log. If an error occurred when activating the secondary index, you will automatically go to this log.
    The secondary index is automatically created on the database during activation if the corresponding table has already been created there and index creation was not excluded for the database system.
    Reward points if useful.

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

  • 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

  • USING SUM IN INTERNAL TABLE

    plz give me a simple example for using SUM in internal table and do some calculations in the same internal table.

    HI
    CHECK WITH THIS
    Syntax
    SUM.
    Effect
    The statement SUM can only be specified within a loop starting with LOOP, and is only considered within a AT- ENDAT control structure. Prerequisites for using the statement SUM include using the addition INTO in the LOOP statement, and that the specified work area wa is compatible with the row type of the internal table. In addition, SUM cannot be used when the row type of the internal table itab contains components that are tables.
    The statement SUM calculates the component total with the numeric data type (i, p, f) of all rows in the current control level and assigns these to the components of the work area wa. In the control levels FIRST, LAST, and outside of an AT-ENDAT control structure, the system calculates the sum of numeric components of all rows in the internal table.
    Example
    Control level processing for creating a list. At the end of line groups, the total of reserved places is calculated and issued.
    DATA: sflight_tab TYPE SORTED TABLE OF sflight
                      WITH UNIQUE KEY carrid connid fldate,
          sflight_wa  LIKE LINE OF sflight_tab.
    SELECT *
           FROM sflight
           INTO TABLE sflight_tab.
    LOOP AT sflight_tab INTO sflight_wa.
      AT NEW connid.
        WRITE: / sflight_wa-carrid,
                 sflight_wa-connid.
        ULINE.
      ENDAT.
      WRITE: / sflight_wa-fldate,
               sflight_wa-seatsocc.
      AT END OF connid.
        SUM.
        ULINE.
        WRITE: / 'Sum',
                  sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
        SKIP.
      ENDAT.
      AT END OF carrid.
        SUM.
        ULINE.
        WRITE: / 'Carrier Sum',
                  sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
        NEW-PAGE.
      ENDAT.
      AT LAST.
        SUM.
        WRITE: / 'Overall Sum',
                  sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
      ENDAT.
    ENDLOOP.
    Hope this solves ur problem....
    <b>do reward if useful....</b>
    regards
    dinesh

  • Indexes in Internal Tables

    Can we use primary and secondary  indexes on internal tables? If yes can anyone give me description how to use them?
    thank you.
    jeevi.

    Hi Thomas,
    please give an example.
    AFAIK starting with 4.6 ABAP uses unique and non-unique keys for internal tables of type SORTED and unique keys for hashed tables. One key per table. That means primary.
    A key is build of one or more fields or pseudo field table_line.
    I know secondary keys only with database tables.
    Regards,
    Clemens

  • Best way of Using Index on a Table.

    I am trying to understand the phenomena of using INDEX on a Table
    need some guidance!!!
    Let us take this scenario
    I have a table "MYRECORD" which has 4 attributes(or coulombs)
    1. "STATE" (varchar) // this can have 49 different values like newyork, dehli etc
    2. "YEAR" //a year like 2007
    3. "MONTH" //a month like JAN,FEB etc
    4. "CAT" (int) // type(category) of data represented by values 0 to 40
    with a PRIMARY KEY(STATE,YEAR,MONTH,CAT)
    now i will create index
    1. INX_myrecord (STATE,YEAR,MONTH) on table MYRECORD
    so now my question is
    1. what is the effect on performance of DB it makes?
    2. when I use a query
    SELECT * FROM MYRECORD WHERE STATE="dehli" AND YEAR=2007 AND MONTH="JAN";
    how will it get processed if index is created and not created.
    3. how can I refer a index by name in a query if so possible?
    Cheers,
    UD
    Message was edited by:
    UDAY

    You have edited your post. Now you have a primary key consisting of state, year, month and cat which makes an index on state, year and month useless as the already existing primary key can provide for retrieval of rows by index. If you don't have other columns - or just few other not being large varchar2 columns - you should have created the table as an IOT (Index Organized Table - avoiding to have separate table and index containing - nearly - the same data) in the first place.
    As a primary key by definition can contain only unique non null values, a query like SELECT * FROM MYRECORD WHERE STATE='dehli' AND YEAR=2007 AND MONTH='JAN' cannot give you more than the number of distinct cat values (0 .. 40) + 1 (if cat can be null - presumed one/some of the corresponding state, year and month is not null)
    The information processing depends principally of the query, the mere presence of an index does not make sure it will be used. If an index is used it means the index will be searched first then the table rows will be accessed by rowids contained in the index (usually a single row or a range of rows - a rather small number of them - is retrieved this way, your select for example). Submitting something like SELECT * FROM MYRECORD WHERE YEAR=2007 AND cat=33 would most likely produce a full table scan of myrecord table ignoring the primary key.
    Regards
    Etbin

  • Why using workarea for internal table is better in performance

    Please tell me
    why using workarea for internal table is better in performance

    Hi Vineet ,
      Why would we choose to use an internal table without a header line when it is easier to code one  with a header line?
    it has following reason.
    1)Separate Internal Table Work Area:
         The work area (staging area) defined for the internal table   is not limited to use with just one internal table.
    take ex-
    Suppose you want two internal tables for EMPLOYEE – one to contain all records and one to contain only those records where country = ‘USA’.  You could create both of these internal tables without header lines and use only one work area to load data into both of them. You would append all records from the work area into the first internal table.  You would conditionally append the ‘USA’ records from the same work area into the second internal table.
    2)  Performance Issues:  Using an internal table without a header line is more efficient than one  with a header line
    3) Nested Internal Tables:  If you want to include an internal table within a structure or another   internal table, you must use one without a header line.
    If this one is helpful ,then rewards me
    Regards
    Shambhu

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

  • 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

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

  • Looping over fields from internal table

    In a FM I have to check records of two ITABs against each other. Most fields can be checked 1:1 but some must be checked according to some business logic.
    I first want to check field-by-field and then I want to deal with exceptions.
    Question: How can I loop over fields in an ITAB in such a manner that I can compare fields?

    Hi, you can loop thru the columns(fields) of an internal table like so.
    field-symbols: <fs>.
    loop at itab.
    do.
    * Here you can use the field name instead of SY-INDEX
       assign component sy-index of structure itab to <fs>.
       if sy-subrc <>.
       exit.
       endif.
    * Now that you have access to the field via field symbol, you can compare
    * this value.
    Write:/ <fs>.
    enddo. 
    endloop.
    Regards,
    Rich Heilman

Maybe you are looking for