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.

Similar Messages

  • 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

  • How to make use of a global internal table in SAP BW during transfer rules

    HI friends,
    I am ABAP consultant working on some APO info cubes. I have an issue during the upload of planning area data into APO info cube.
    Please help.
    I am using a transfer routine to find the TECHWEEK from a data base table ZGC_CALWEEK based on the on the calender month and calender week.
    Code I am writing is like below.
    *       FORM COMPUTE_/BIC/ZCALWEEK
    * Compute value of InfoObject ZCALWEEK
    * in communication structure /BIC/CSZT6DPPA
    * Technical properties:
    *     field name      = /BIC/ZCALWEEK
    *     data element    = /BIC/OIZCALWEEK
    *     data type       = NUMC
    *     length          = 000006
    *     decimals        = 000000
    *     ABAP type       = N
    *     ABAP length     = 000006
    *     reference field =
    * Parameters:
    *  -->  RECORD_NO       Record number
    *  -->  TRAN_STRUCTURE  Transfer structure
    *  <--  RESULT          Return value of InfoObject
    *  <->  G_T_ERRORLOG    Error log
    *  <--  RETURNCODE      Return code (to skip one record)
    *  <--  ABORT           Abort code (to skip whole data package)
    FORM COMPUTE_/BIC/ZCALWEEK
      USING    RECORD_NO LIKE SY-TABIX
               TRAN_STRUCTURE TYPE TRANSFER_STRUCTURE
               G_S_MINFO TYPE RSSM_S_MINFO
      CHANGING RESULT TYPE /BIC/OIZCALWEEK
               G_T_ERRORLOG TYPE rssm_t_errorlog_int
               RETURNCODE LIKE SY-SUBRC
               ABORT LIKE SY-SUBRC. "set ABORT <> 0 to cancel datapackage
    *$*$ begin of routine - insert your code only below this line        *-*
    * DATA: l_s_errorlog TYPE rssm_s_errorlog_int.
    DATA: LV_WEEK         TYPE ZGC_CALWEEK-APOWEEK,
            LV_MONTH        TYPE ZGC_CALWEEK-APOMONTH,
            LV_TECH_WEEK    TYPE ZGC_CALWEEK-TECHWEEK.
      LV_WEEK   = TRAN_STRUCTURE-CALWEEK.
      LV_MONTH  = TRAN_STRUCTURE-CALMONTH.
      SELECT SINGLE TECHWEEK INTO LV_TECH_WEEK
        FROM ZGC_CALWEEK CLIENT SPECIFIED
        WHERE  MANDT = SY-MANDT
        AND  APOWEEK  = LV_WEEK
        AND   APOMONTH = LV_MONTH.
      IF SY-SUBRC IS INITIAL.
        RESULT = LV_TECH_WEEK.
      ELSE.
        RETURNCODE = 1.
        ENDIF.
    *$*$ end of routine - insert your code only before this line         *-*
    ENDFORM.
    There are more than 50-80 million records that wil be transferred from planning area to info cube. The select statment is giving pathetic performance as this has to run 50-80 million times.
    After adding the select statment to find the TECHWEEK it is taking 4 times the time that used to take before writing the select statment.
    Is there a way that I can first fetch the data from ZGC_CALWEEK to one internal table and that internal table can be used using read statment during the transfer routine instead of writing select statement here.
    Please help in this case?

    Hi Ashutosh,
    Thanks for the reply,
    The structure of the ZGC_CALWEEK is as below. I have already created a secondary index on the table for this table for the fields APO WEEK and APO MONTH. This didn't help much on the performance.
    I am also planning to keep the ZGC_CALWEEK database table to be fully buffered and this may definitely improve the performance but I need to reduce the data base hits as less as possible.
    MANDT                           MANDT                           CLNT     3     0     Client
    TECHWEEK                           ZTECHWEEK                           NUMC     6     0     Technical Week
    FROMDATE_TECH     DATUM                           DATS     8     0     Date
    TODATE_TECH     DATUM                           DATS     8     0     Date
    APOWEEK                           /BI0/OICALWEEK     NUMC     6     0     Calendar year / week
    FROMDATE_APO     DATUM                            DATS     8     0     Date
    TODATE_APO     DATUM                            DATS     8     0     Date
    APOMONTH                           /BI0/OICALMONTH     NUMC     6     0     Calendar year/month
    The table ZGC_CALWEEK is in APO system, where the transfer rules are being executed.
    As you mentioned START ROUTINE, In the start routine Can I create an internal table let's say GT_CALWEEK with structure ZGC_CALWEEK and pull all the records (I have a max of 2000 records in this table) from ZGC_CALWEEK to GT_CALWEEK and Can I used the same internal table GT_CALWEEK in the transfer routine to read the TECHWEEK from internal table.
    Thank you very much again for you reply. Any help regarding this would be greatly appreciated.
    Best regards,
    Siva

  • Regarding Secondary Index in a Table

    hi
    if i create a secondary index in a table is it obligatory or optional to have first field as MANDT (Client field) if the table is client dependent & how many secondary indexes(MAXIMUM) can be created for a table.
    Regards

    Hi,
    Check the below Link
    How to transport a secondary index on P master data table?
    Hope this helps you.
    Regards,
    Anki Reddy

  • Creation of secondary index on RSPCPROCESSLOG table

    Hello guys,
    We have detected severe performance issues while executing the transaction ST03n in our BW 3.5 System.
    Looking in the OSS notes we found the note "SAP Note 841324 - ST03N: poor performance for process chain profile" where it recommends the creation of a secondary index in the table RSPCPROCESSLOG  with the following features:
    Create another secondary index on the RSPCPROCESSLOG table with the
    following fields:
    - INSTANCE
    - TYPE
    Can you please let us know what is the step by step to proceed with the creation of this secondary index?
    Thanks for your help.
    Kind regards

    Please ask questions about Oracle Text (formerly interMedia text) in the Oracle Text forum. You will get a quicker, more expert answer there.

  • How to make use of Index of a table in report to fetch data?

    Hi,
    I need a sample code for select statement which is making use of INDEX of a table
    to fetch data.
    Doubt:
    Can I fetch all the fields in the table by passing certain key fields of INDEX in where condition?

    Hi Raja,
    1) Mention the fields that you wish from database table (incase you don't need all the fields from the database table).
    2) Don't use the INTO CORRESPONDING FIELDS OF TABLE ztable clause.
    3)Instead use INTO TABLE ztable (But take care that during the declaration of the ztable, the fields declared are in order that in database table to fetch the Records in sequence).
    Please Find the Syntax and Code Below..
    SELECT *  FROM <TABLE>
      WHERE  <WHERE>
        %_HINTS ORACLE 'INDEX("<TABLE>~<INDEX ID")'.
    SELECT carrid
    INTO TABLE t_spfli
    FROM spfli
    WHERE carrud IN s_carrid AND
    connid IN s_connid
    %_HINTS ORACLE 'INDEX("&SPFLI&" "SPFLI~XXX")'.
    Hope this Is helpFul
    Thanks
    kalyan

  • How to use aggregate function on internal table

    hi experts,
    I am beginner in abap.I want to use sum function on internal table.
    I have structure as follow:
    types: begin of ty_ftab,
           docno TYPE bkpf-belnr,
           comcode TYPE bkpf-bukrs,
           year TYPE bkpf-gjahr,
           line_itm type bsad-buzei,
           cust type bsad-kunnr,
           amt type bsad-dmbtr,
    end of ty_ftab.
    data: it_ftab type table of ty_ftab,
               wa_ftab type ty_ftab.
    i fetched data successfully into it_ftab from bkpf and bsad table and displyed into alv.
    now i want sum of amt using group by cust and want to display like
    cust        total_amt      
    in next screen...
    displying part is not important but how can i do sum of amt according to cust value? Is there in way to query on internal table?

    Hi,
    try this code,
    data : i_sort  TYPE TABLE OF slis_sortinfo_alv
      w_sort like LINE OF i_sort.
    sort it_ftab by cust.
    w_sort-subtot = 'X'.
    w_sort-fieldname = 'AMT'.
    w_sort-tabname = 'it_ftab'.
    APPEND w_sort to i_sort.
    In fieldcatalog :
    w_fcat-fieldname = 'AMT'.
    w_fcat-tabname  = 'it_ftab'.
    w_fcat-do_sum = 'X'.
    In REUSE_ALV_GRID_DISPLAY  FUNCTION MODULE  provide the it_sort.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    *  EXPORTING
    *    I_INTERFACE_CHECK                = ' '
    *    I_BYPASSING_BUFFER                = ' '
    *    I_BUFFER_ACTIVE                  = ' '
    *    I_CALLBACK_PROGRAM                = ' '
    *    I_CALLBACK_PF_STATUS_SET          = ' '
    *    I_CALLBACK_USER_COMMAND          = ' '
    *    I_CALLBACK_TOP_OF_PAGE            = ' '
    *    I_CALLBACK_HTML_TOP_OF_PAGE      = ' '
    *    I_CALLBACK_HTML_END_OF_LIST      = ' '
    *    I_STRUCTURE_NAME                  =
    *    I_BACKGROUND_ID                  = ' '
    *    I_GRID_TITLE                      =
    *    I_GRID_SETTINGS                  =
    *    IS_LAYOUT                        =
    *    IT_FIELDCAT                      =
    *    IT_EXCLUDING                      =
    *    IT_SPECIAL_GROUPS                =
        IT_SORT                          =  i_sort
    *    IT_FILTER                        =
    *    IS_SEL_HIDE                      =
    *    I_DEFAULT                        = 'X'
    *    I_SAVE                            = ' '
    *    IS_VARIANT                        =
    *    IT_EVENTS                        =
    *    IT_EVENT_EXIT                    =
    *    IS_PRINT                          =
    *    IS_REPREP_ID                      =
    *    I_SCREEN_START_COLUMN            = 0
    *    I_SCREEN_START_LINE              = 0
    *    I_SCREEN_END_COLUMN              = 0
    *    I_SCREEN_END_LINE                = 0
    *    I_HTML_HEIGHT_TOP                = 0
    *    I_HTML_HEIGHT_END                = 0
    *    IT_ALV_GRAPHICS                  =
    *    IT_HYPERLINK                      =
    *    IT_ADD_FIELDCAT                  =
    *    IT_EXCEPT_QINFO                  =
    *    IR_SALV_FULLSCREEN_ADAPTER        =
    *  IMPORTING
    *    E_EXIT_CAUSED_BY_CALLER          =
    *    ES_EXIT_CAUSED_BY_USER            =
        TABLES
          t_outtab                          =
    *  EXCEPTIONS
    *    PROGRAM_ERROR                    = 1
    *    OTHERS                            = 2
      IF sy-subrc <> 0.
    * Implement suitable error handling here
      ENDIF.

  • Secondary Index for the table MSEG

    Hi folks,
             One of my report is comparetively very slow when it is executed in the production server. when i chked, a query related to the MSEG table is taking more time to execute. I want to create a secondary index for that table. Could any body tell  me the procedure of creating the seconday index for the table MSEG, as i am not aware of that.
    Thanks in advance,
    Shyam.

    Dear shyam,
    Search SDN before posting any thread their are 10k threads available for your question anyhow for your reference here is one link
    http://help.sap.com/search/highlightContent.jsp
    Cheers
    fareed

  • 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

  • Is it worth creating secondary index on BKPF table ?

    Hello,
    One of my clients is using ECC version 5.0. I have a requirement wherein I need to fetch the data from BKPF table based on AWKEY, BUKRS and GJAHR. There is no standard secondary index available.
    I have decided to create a secondary index on these fields in the following order:
    1) MANDT
    2) AWKEY
    3) BUKRS
    4) GJAHR
    I know that creating secondary indexes does improve performance during data retrieval. But when I checked the total number of entries in BKPF table in production system, there are more than 20 lac 2 million records.
    I am worried that creation of secondary index will create another table of such a large size in production that has data sorted on the above fields. Also, the RAM of production system is 6 GB.
    Please suggest if creation of secondary index is a good measure OR should I recommend the client to increase the system RAM?
    Regards,
    Danish.
    Edited by: Thomas Zloch on Oct 3, 2011 3:01 PM

    Hi,
    Secondary Index on BKPF-AWKEY has been successfully created in production. The report which used to timeout in foreground as well as in background is now executing in less than 10 seconds !!
    Client is very much satisfied with this. But, there is one problem that we are facing now is that when the user is changing an existing billing document via VF02, on SAVE, system takes a very long time to save the changes done.
    We monitored the processes via SM50 and found that there was a sequential read on BKPF table.
    Before transporting the index in production, system approximately took not more than 5 seconds to save the Billing Document. But now system takes more than 20 minutes just to save the billing document via VF02.
    I really don't know what has gone wrong. I can't figure out if I have missed any step while creating the index.
    I did the following,
    1) Created a Secondary index on BKPF, saved it in the transport request and activated it. Since the index was not existing in database ORACLE, I activated and adjusted the table via SE14. Now, index exists on database as well. Working perfectly in development.
    2) Imported the transport request to Production. Checked in SE11. Index was existing and active. Also, index existed in database ORACLE.
    Have I missed anything ? Is it required to activate and adjust the database via SE14 in production too ?
    Regards,
    Danish.

  • Using Secondary Index

    Hi,
    I have a secondary index with 3 key fields.While wrting the select query with these 3 key fields I am providing 2 more non-key fields. Now the problem is that the secondary index in not used in this case. Can anybody help me why it is not using the secondary index.
    For example:
    Seconday Index fields are : fd1, fd2, fd3
    In select query:
    select A B C from  <XYZ> into table I_XYZ
    where  fd1 = 'a'     " key field
    and fd2 = 'b'         " key field
    and fd3 = 'c'         " key field
    and fd4 = 'd'         " non-key field
    and fd5 = 'e'.        " non-key field
    Problem : Query is not using the seconday index.
    Regards
    Sanjay

    hi,
    Check if your secondary index is having mandt field or not.
    system changes your select as
    select A B C from <XYZ> into table I_XYZ
    where <b>mandt = sy-mandt  and</b>
    fd1 = 'a' " key field
    and fd2 = 'b' " key field
    and fd3 = 'c' " key field
    and fd4 = 'd' " non-key field
    and fd5 = 'e'. " non-key field
    so, secondary index will be chosen only if mandt is there in the list of fields in secondary index.
    Regards
    sailaja.

  • Secondary index on vbfa table

    I have very expensive statement running against VBFA table. It comes from a customer report and doing SQL:
    SELECT /*+ FIRST_ROWS */ "VBELV"
    FROM "VBFA"
    WHERE "MANDT" = :A0 AND "VBELN" = :A1 AND ROWNUM <= :A2
    It has execution plan:
    SELECT STATEMENT ( Estimated Costs = 96.009 , Estimated #Rows = 41 )
    |
    --- COUNT STOPKEY
    |
    INDEX RANGE SCAN VBFA~0
    As you can see it is very expensive statement because VBFA is huge table and because I have only VBFA~0 index with columns:
    UNIQUE Index VBFA~0
    COLUMN DISTINCT VALUES
    MANDT      1
    VBELV       1.589.207
    POSNV      4.184
    VBELN       3.202.114
    POSNN       58.173
    VBTYP_N    18
    In order to improve performance of this report , would you recomend creating secondary index and would it be on columns: MANDT, VBELN, VBELV
    I have not seen this type of secondary index in SAP community (most of the time I see sec.index on mandt, vbeln and posnn columns) so that is why I want to double check it before I deploy it.
    Regards,
    Andrija

    Hi,
    Indexes speed up access to rows in a table. They can be created for a single column or for a series of columns.
    MANDT AND VBELN does not have index then create indexes on these columns.
    The explain statement can be used to check the effect of creating or deleting indexes (see index) on the choice of search strategy for the specified SQL statement. You can also estimate the time needed by the database system to process the specified SQL statement. The specified QUERY or SINGLE SELECT statement is not executed while the EXPLAIN statement is being executed.
    To be frank to analyze you shd generate trace file and you need to analyze.
    Oracle claims that <b>first_rows_n</b> optimization results in faster response time for certain queries, we must remember that the performance is achieved via a change to the costing.
    Use the FIRST_ROWS hint when you need only the first few hits of a query. When you need the entire result set, do not use this hint as it might result in poorer performance.
    So collect stats,Analyze table create index your query will execute faster.
    Analyze in trace file generated.Want to know indexes are used or not have a look on Explain Plan.
    Regards
    Vinod

  • Secondary index on aggregate table and cube

    Hi to all,
    I have small doubt.
    1. Primary index created in F and E table of CUBE by system.
      then how secondary index in created in F and E table of cube,
      or
    is that B* tree index created as secondary index on F/E table of cube, when we use process type create / deleted index in PC for CUBE
    or if we do manually under performance tab for cube.
    2. Primary index also created on F and E table of aggregate by system.
      then how secondary index in created in F and E table of aggregate,
      or
    is that B* tree index created as secondary index on F/E table of aggregate, when we use process type create / deleted index in PC for CUBE
    or if we do manually under performance tab for aggregate
    Regards
    Pavneet Rana

    Hi,
    Thru process chains you can't handle them.
    You can do it by manual with help basis or ABAP team.
    BW server--> T code  SE11, Select table - Enter table name and display it.
    On next screen on tool bar you can see indexes --> click on it.
    Thanks

  • Use of substr function will avoid the use of indexes in a table

    i have one table which will contain some 3,00,000 records, it contains some 11 primary keys i am using some update statements to update some fields in the records (of 3,00,000 i will compare some 1,50,000 records with 1,50,000 another records) i am using substr function in all the select statements. whether usage of substr function will avoid the use of index
    can any one clarify?

    contains some 11 primary keys by this I suppose you mean to say the table has a composite PK on 11 columns.
    i am using substr function in all the select statementsCould you please post your SQL statement?

  • Using COLLECT on a internal table

    Hello,
    I have fetched records from a table into my internal table through, " SELECT * FROM .... INTO TABLE FOR ALL ENTRIES IN ...... "
    There are two columns in my internal table against which i need a total of the column. COLLECT sums the amounts . But how can i use COLLECT in this scenario ?
    Can anyone kindly guide me ...Thanks
    Shehryar Dahar

    Hi,
    COLLECT add the numeric entries for the corresponding table keys..
    Example.
    DATA: BEGIN OF ITAB OCCURS 0,
    MATNR TYPE MATNR,
    COUNT TYPE I,
    END OF ITAB.
    ITAB-MATNR = 'ABC'.
    ITAB-COUNT = 2.
    COLLECT ITAB.
    ITAB-MATNR = 'ABC'.
    ITAB-COUNT = 1.
    COLLECT ITAB.
    ITAB-MATNR = 'ABCD'.
    ITAB-COUNT = 2.
    COLLECT ITAB.
    ITAB-MATNR = 'ABCD'.
    ITAB-COUNT = 3.
    COLLECT ITAB.
    LOOP AT ITAB.
    WRITE: / ITAB-MATNR, ITAB-COUNT.
    ENDLOOP.
    For more information on Collect, check this site:
    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/collect.htm
    Hope this would help you out.
    Regards,
    Varun.

Maybe you are looking for