Usage of Sorted Keys in standard tables

Hi,
  If I have a sorted secondary key (unique or non-unique) in my internal table, and use the secondary key with my DELETE statement (DELETE ... WITH TABLE KEY <secondary_key_name> COMPONENTS ... = ...), I still get a prio 2 checkman error saying possible sequential read. My question:
1. What's the difference between usages of sorted key and a sorted table with regards to a READ statement?
2. Would I still have to do a SORT on the standard table by the secondary key components and then do a BINARY search to avoid the possible sequential read? (in that case why should i mention the key to be "sorted"?
Thanks in advance,
Best Regards
Anantharaman L

Hi Anantharaman ,
When we define sorted secondary keys, we do not have to sort it explicitly and use a binary search. we just have to define the sorted secondary keys and read based on that keys. The read statement should be as follows:
read TABLE <internal table>INTO <work area/field symbol>WITH KEY <secondary key name> COMPONENTS <comp1 = value>.
eg : read TABLE lt_tab INTO lw_tab WITH KEY key_1 COMPONENTS carrid1 = 'CC'
Complete Code :
REPORT  YTEST.
DATA: lt_tab TYPE YSTRU1_TT,
      lw_tab LIKE LINE OF lt_tab.
lw_tab-carrid1 = 'BB'.
lw_tab-connid =  '50'.
APPEND lw_tab to lt_tab.
lw_tab-carrid1 = 'ZZ'.
lw_tab-connid =  '50'.
APPEND lw_tab to lt_tab.
lw_tab-carrid1 = 'WW'.
lw_tab-connid =  '50'.
APPEND lw_tab to lt_tab.
lw_tab-carrid1 = 'AA'.
lw_tab-connid =  '50'.
APPEND lw_tab to lt_tab.
lw_tab-carrid1 = 'XX'.
lw_tab-connid =  '50'.
APPEND lw_tab to lt_tab.
lw_tab-carrid1 = 'CC'.
lw_tab-connid =  '50'.
APPEND lw_tab to lt_tab.
CLEAR lw_tab.
read TABLE lt_tab INTO lw_tab WITH KEY key_1 COMPONENTS carrid1 = 'CC'.
Note : Table type ystru1_tt is defined with a unique-sorted secondary key carrid1.
Hope this will be helpful.
Warm Regards,
Jenny

Similar Messages

  • Usage of sort key in FS00

    Hi,
    Can the Sort key (31 - Customer Number) be used in GL account type, for getting the assignment field in the Line item to be populated with customer number.
    I tried it but did not work.
    Can any one tell how to (standard way) populate the custmer number in the line item of GL account (account type S)?
    Regards
    Seshadri

    Hi Seshadri,
    Sort key in the GL master will guides the system to display line items of the business partners or GL account in a specific sort order in reports FBL1N, FBL3N and FBL5N.
    If you want the system to populate the assignment field in the customer line item report, go to Tcode FBL5N and select menu item settings-> special filelds
    Press new entries and add the entry for table BSID - ZUONR and BSAD - ZUONR
    This might solves your requirement.
    Post again for more details.
    Thanks,
    Srinu

  • Differences between Standard , sorted and hashed internal tables

    Can any body please tell me what are the main Differences between
    1) <b>Standard internal table</b>
    2) <b>Hashed internal table</b>
    3) <b>Sorted internal table</b>
    Please give me a clear idea about these Three.
    Thanks
    Prabhudutta<b></b>

    Hi,
    <b>Standard Internal Tables</b>
    Standard tables have a linear index. You can access them using either the index or the key. If you use the key, the response time is in linear relationship to the number of table entries. The key of a standard table is always non-unique, and you may not include any specification for the uniqueness in the table definition.
    This table type is particularly appropriate if you want to address individual table entries using the index. This is the quickest way to access table entries. To fill a standard table, append lines using the (APPEND) statement. You should read, modify and delete lines by referring to the index (INDEX option with the relevant ABAP command).  The response time for accessing a standard table is in linear relation to the number of table entries. If you need to use key access, standard tables are appropriate if you can fill and process the table in separate steps. For example, you can fill a standard table by appending records and then sort it. If you then use key access with the binary search option (BINARY), the response time is in logarithmic relation to
    the number of table entries.
    <b>Sorted Internal Tables</b>
    Sorted tables are always saved correctly sorted by key. They also have a linear key, and, like standard tables, you can access them using either the table index or the key. When you use the key, the response time is in logarithmic relationship to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique, or non-unique, and you must specify either UNIQUE or NON-UNIQUE in the table definition.  Standard tables and sorted tables both belong to the generic group index tables.
    This table type is particularly suitable if you want the table to be sorted while you are still adding entries to it. You fill the table using the (INSERT) statement, according to the sort sequence defined in the table key. Table entries that do not fit are recognised before they are inserted. The response time for access using the key is in logarithmic relation to the number of
    table entries, since the system automatically uses a binary search. Sorted tables are appropriate for partially sequential processing in a LOOP, as long as the WHERE condition contains the beginning of the table key.
    <b>Hashed Internal Tables</b>
    Hashes tables have no internal linear index. You can only access hashed tables by specifying the key. The response time is constant, regardless of the number of table entries, since the search uses a hash algorithm. The key of a hashed table must be unique, and you must specify UNIQUE in the table definition.
    This table type is particularly suitable if you want mainly to use key access for table entries. You cannot access hashed tables using the index. When you use key access, the response time remains constant, regardless of the number of table entries. As with database tables, the key of a hashed table is always unique. Hashed tables are therefore a useful way of constructing and
    using internal tables that are similar to database tables.
    Regards
    Sudheer

  • Standard tables hashed tables

    in SORT we will not use sorted tables like where we will not use STANDARD TABLES and HASDED TABLES ........CAN U EXPLAIN IN DETAIL .......

    <b>Standard Internal Tables</b>
    Standard tables have a linear index. You can access them using either the index or the key. If you use the key, the response time is in linear relationship to the number of table entries. The key of a standard table is always non-unique, and you may not include any specification for the uniqueness in the table definition.
    This table type is particularly appropriate if you want to address individual table entries using the index. This is the quickest way to access table entries. To fill a standard table, append lines using the (APPEND) statement. You should read, modify and delete lines by referring to the index (INDEX option with the relevant ABAP command).  The response time for accessing a standard table is in linear relation to the number of table entries. If you need to use key access, standard tables are appropriate if you can fill and process the table in separate steps. For example, you can fill a standard table by appending records and then sort it. If you then use key access with the binary search option (BINARY), the response time is in logarithmic relation to
    the number of table entries.
    <b>Sorted Internal Tables</b>
    Sorted tables are always saved correctly sorted by key. They also have a linear key, and, like standard tables, you can access them using either the table index or the key. When you use the key, the response time is in logarithmic relationship to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique, or non-unique, and you must specify either UNIQUE or NON-UNIQUE in the table definition.  Standard tables and sorted tables both belong to the generic group index tables.
    This table type is particularly suitable if you want the table to be sorted while you are still adding entries to it. You fill the table using the (INSERT) statement, according to the sort sequence defined in the table key. Table entries that do not fit are recognised before they are inserted. The response time for access using the key is in logarithmic relation to the number of
    table entries, since the system automatically uses a binary search. Sorted tables are appropriate for partially sequential processing in a LOOP, as long as the WHERE condition contains the beginning of the table key.
    <b>Hashed Internal Tables</b>
    Hashes tables have no internal linear index. You can only access hashed tables by specifying the key. The response time is constant, regardless of the number of table entries, since the search uses a hash algorithm. The key of a hashed table must be unique, and you must specify UNIQUE in the table definition.
    This table type is particularly suitable if you want mainly to use key access for table entries. You cannot access hashed tables using the index. When you use key access, the response time remains constant, regardless of the number of table entries. As with database tables, the key of a hashed table is always unique. Hashed tables are therefore a useful way of constructing and
    using internal tables that are similar to database tables.
    <b>Index Tables</b>
    Index table is only used to specify the type of generic parameters in a FORM or FUNCTION. That means that you can't create a table of type INDEX.
    Internal tables are not DB tables. Standard and Sorted tables in combined are basically called as Index tables and there nothing else. Here is the hierarchy
              ANY TABLE
                                                |
                         |                                                    |
                 Index Tables                                    Hashed Table
                         |          
        |                                                     |
    Standard Table                      Sorted Table
    Reward  points if  it is usefull .....
    Girish

  • Memory and performance  when copying a sorted table to a standard table

    Hello,
    As you all probably know, it's not possible to use a sorted table as a tables parameter of a function module, but sometimes you want to use a sorted table in your function module for performance reasons, and at the end of the function module, you just copy it to a standard table to return to the calling program.
    The problem with this is that at that moment, the contents of the table is in memory twice, which could result in the well known STORAGE_PARAMETERS_WRONG_SET runtime exception.                                                                               
    I've been looking for ways to do this without using an excessive amount of memory and still being performant.  I tried four methods, all have their advantages and disadvantages, so I was hoping someone here could help me come up with the best way to do this.  Both memory and performance are an issue. 
    Requirements :
    - Memory usage must be as low as possible
    - Performance must be as high as possible
    - Method must work on all SAP versions from 4.6c and up
    So far I have tried 3 methods.
    I included a test report to this message, the output of this on my dev system is :
    Test report for memory usage of copying tables    
    table1[] = table2[]                                        
    Memory :    192,751  Kb                                    
    Runtime:    436,842            
    Loop using workarea (with delete from original table)      
    Memory :    196,797  Kb                                    
    Runtime:  1,312,839        
    Loop using field symbol (with delete from original table)  
    Memory :    196,766  Kb                                    
    Runtime:  1,295,009                                                                               
    The code of the program :
    I had some problems pasting the code here, so it can be found at [http://pastebin.com/f5e2848b5|http://pastebin.com/f5e2848b5]
    Thanks in advance for the help.
    Edited by: Dries Horions on Jun 19, 2009 1:23 PM
    Edited by: Dries Horions on Jun 19, 2009 1:39 PM
    Edited by: Dries Horions on Jun 19, 2009 1:40 PM
    Edited by: Dries Horions on Jun 19, 2009 1:40 PM

    I've had another idea:
    Create a RFC function like this (replace SOLI_TAB with your table types):
    FUNCTION Z_COPY_TABLE .
    *"*"Lokale Schnittstelle:
    *"  IMPORTING
    *"     VALUE(IT_IN) TYPE  SOLI_TAB
    *"  EXPORTING
    *"     VALUE(ET_OUT) TYPE  SOLI_TAB
    et_out[] = it_in[].
    ENDFUNCTION.
    and then try something like this in your program:
    DATA: gd_copy_done TYPE c LENGTH 1.
    DATA: gt_one TYPE soli_tab.
    DATA: gt_two TYPE soli_tab.
    PERFORM move_tables.
    FORM move_tables.
      CLEAR gd_copy_done.
      CALL FUNCTION 'Z_COPY_TABLE'
        STARTING NEW TASK 'ztest'
        PERFORMING copy_done ON END OF TASK
        EXPORTING
          it_in = gt_one[].
      CLEAR gt_one[].
      WAIT UNTIL gd_copy_done IS NOT INITIAL.
    ENDFORM.
    FORM copy_done USING ld_task TYPE clike.
      RECEIVE RESULTS FROM FUNCTION 'Z_COPY_TABLE'
       IMPORTING
         et_out        = gt_two[].
      gd_copy_done = 'X'.
    ENDFORM.
    Maybe this is a little bit faster than the Memory-Export?
    Edited by: Carsten Grafflage on Jul 20, 2009 11:06 AM

  • Sort without BY addition & Table Key

    Experts,
    From SAP Help,
    If no explicit sort key is entered using the BY addition, the internal table itab is sorted according to the table key.
    I have code as below,
    data: lt_vkonto type table of VKONT_KK. "Cont Acc No
    "Fetch Cont Acc no against Contract
    select vkonto from ever into table lt_vkonto where vertrag = wa_data-vertrag.
    if sy-subrc eq 0.
    sort lt_vkonto.
    endif.
    As seen above, I have sort statement without BY addition for internal table lt_vkonto which does not have a UNIQUE or NON UNIQUE key.
    Will adding BY addition --> SORT lt_vkonto by vkonto imrpove the performance of sort statement.
    Please share your valuable inputs.
    BR,
    Aspire

    Hi
    I don't know if you'll imporve the performace in your case, you should do some measurement, the problem should be the table key for a standard internal table (like yours) is the set of all CHAR fields.
    In you situation you've only one fields, but probably if the table has several char fields the performance can be improved
    Anyway I suppose it's always better to explicit an option else the system will have to deduct it by itself, so the system will do an additional step: in your case without BY, the system has to deduct the key to be used for the sorting.
    Max

  • Let me know the standary primary key tables in standard table??

    let me know the standary primary key tables in standard table??

    Hi,
    You can go and check the primary keys of a table in SE11 by entering the table name and pressing display.
    You will get to see that there will be some fields with a tick mark in the primary key column.The fields which have such tick marks are the primary keys of that table.
    As far as I know there is nothing called primary key tables.All tables have some fields as primary keys based upon which a record is uniquely defined in that table.
    Hope it was useful.
    Thanks,
    Sandeep.

  • CM25: Sort standard table based on custom table.

    Hi Experts,
    I need to sort the CM25 capacity table based on a ZTABLE where we will define the sequence number of each material. So when CM25 is executed the material should get sorted based on sequence number maintained in Ztable. Now the challenge is how to achieve this sorting before we display the capacity table.
    anybody has faced such scenerio please help us.
    There are few user exits available but not able to find out how to achieve the required functionality.
    Regards,
    Raghav
    Edited by: Julius Bussche on Jul 30, 2009 9:29 AM
    In future threads with meaningless subject titles will simply be deleted as you appear to be doing this intentionally

    First, let me say that I have no experience with this CM25 table and where/how it is used or displayed, but here's how I look at it:
    But what is the real problem?
    1. Don't know the user exit / BAdI to be used?
    2. Don't know how to do the sorting?
    3. .....?
    Answer:
    1. This will be a matter of trying I would say and reading the documentation of the exit/BAdI.
    2. You can do dynamic sorting of an internal table (if it is an internal table that is used before displaying it).
    DATA: lv_sort1 TYPE CHAR10 VALUE 'NAME_OF_COLUMN_FROM_ZTABLE',
               lv_sort2 TYPE CHAR10 VALUE 'NAME_OF_OTHER_COLUMN_FROM_ZTABLE'.
    SORT itab BY (lv_sort1) ASCENDING (lv_sort2) DESCENDING.
    Edited by: Micky Oestreich on Jul 30, 2009 7:34 AM

  • How do I read this "standard" table in my Function Module?

    I have a remote-enable Function Module (RFC).  I am receiving two tables as part of the parameters.  Table "A" is header information, and Table "B" is detail information.  So for every 1 "A" header record, I may have 1 to many "B" detail records.  I have a field we'll call "vendor_number" that is the common link between the two tables.
    Here's what I want to do:  I want to loop through table "A", and for each record, I want to do a READ on table "B", using the "ref_doc_no" from "A" as my key, to get the position of the first matching record.  I hold onto the value of the table index and then start looping table "B", adding 1 to the saved table index each time to process all of the detail records.
    Here's the problem:  This worked great as an ABAP program.  I had my "B" table declared with "ref_doc_no" as a non-unique key.  But when I ported my code over to the RFC, it told me that the RFC could only deal with standard tables.  I had to remove the "ref_doc_no" key declaration.  So now when I try to activate, I get an error similar to this:
    The declaration for the key field "another_field" is incomplete; however, "another_field" is contained in the key of table "B" and must be filled.
    I don't understand that.  I've not declared any keys for table "B".  I don't understand why it's thinking I need to populate "another_field" (I don't even know what the value would be).  My code to read the table (i.e. the line getting the error) is this:
    Priming read on table (sets the initial sy-tabix index value)
        READ TABLE it_incoming_invoice_line_item "table 'B'
          WITH TABLE KEY ref_doc_no =
                         wa_incoming_invoice_header-ref_doc_no
                    INTO wa_incoming_invoice_line_item.
    Is it possible for me to do some sort of direct read on a table in an RFC?  The only alternative I can think of would be to have to loop through table "B" until I find the first occurrence of a match.  Is that what I need to do?
    Thanks everyone.  Points, as always, awarded for helpful answers.

    Dave,
    1. You can fire SELECTS in an RFC as well, but in your case the data exists in SYSTEM A and the RFC is in System B, so you can't do that. You can fire SELECTS on tables in the same system.
    2. Quick example of two table loops - EKKO (HEADER) EKPO (ITEM).
    LOOP AT EKKO.
    LOOP AT EKPO WHERE EBELN = EKKO-EBELN.
    ENDLOOP.
    ENDLOOP.
    I hope this is clear now.
    Regards,
    Ravi

  • ABAP XSLT transformation - XML to deep structure/nested standard table

    Hi all,
    I was struggling with this topic recently and couldn't find a single working example or description of a possible solution. So now that I've sorted it out, I did a quick example to elustrate how it works. Here is the code with XML embeded in it and the XSLT follows:
    <HR>
    <PRE>
    *& Report  Z_XML2ABAP
    *& Author: Jayanta Roy
    *& Date: 03/02/2010
    REPORT  z_xml2abap.
    DATA input_xml TYPE string.
    TYPES: BEGIN OF t_address,
            house_no TYPE string,
            street_name TYPE string,
            city_name TYPE string,
            phone_no TYPE string,
          END OF t_address.
    TYPES: t_addresses TYPE STANDARD TABLE OF t_address with NON-UNIQUE KEY house_no.
    TYPES: BEGIN OF t_person,
            firstname TYPE string,
            surname TYPE string,
            addresses TYPE t_addresses,
          END OF t_person.
    input_xml = '&lt;Friends&gt;' &&
      '&lt;People&gt;' &&
        '&lt;FirstName&gt;Homer&lt;/FirstName&gt;' &&
        '&lt;Surname&gt;Simpson&lt;/Surname&gt;' &&
          '&lt;Address&gt;' &&
            '&lt;HouseNo&gt;123&lt;/HouseNo&gt;' &&
            '&lt;Street&gt;Evergreen Terrace&lt;/Street&gt;' &&
            '&lt;City&gt;Springfield&lt;/City&gt;' &&
            '&lt;PhoneNo&gt;011212321&lt;/PhoneNo&gt;' &&
          '&lt;/Address&gt;' &&
          '&lt;Address&gt;' &&
            '&lt;HouseNo&gt;7G&lt;/HouseNo&gt;' &&
            '&lt;Street&gt;Neuclear Power Plant&lt;/Street&gt;' &&
            '&lt;City&gt;Spring Field&lt;/City&gt;' &&
            '&lt;PhoneNo&gt;911&lt;/PhoneNo&gt;' &&
          '&lt;/Address&gt;' &&
      '&lt;/People&gt;' &&
      '&lt;People&gt;' &&
         '&lt;FirstName&gt;Bart&lt;/FirstName&gt;' &&
         '&lt;Surname&gt;Simpson&lt;/Surname&gt;' &&
           '&lt;Address&gt;' &&
             '&lt;HouseNo&gt;123x&lt;/HouseNo&gt;' &&
             '&lt;Street&gt;Evergreen Terracex&lt;/Street&gt;' &&
             '&lt;City&gt;Springfieldx&lt;/City&gt;' &&
             '&lt;PhoneNo&gt;011212321x&lt;/PhoneNo&gt;' &&
           '&lt;/Address&gt;' &&
       '&lt;/People&gt;' &&
    '&lt;/Friends&gt;' .
    DATA lt_person TYPE STANDARD TABLE OF t_person.
    TRY.
        CALL TRANSFORMATION xslt_person
        SOURCE XML input_xml
        RESULT  all_people = lt_person.
      CATCH cx_root.
        WRITE 'Problemo!'.
    ENDTRY.
    WRITE 'Now, debug the program to see the values read from the XML'.
    </PRE>
    <HR>
    and here is the XSLT Transformation program (xslt_person):
    <HR>
    <PRE>
    &lt;xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                        xmlns:sap="http://www.sap.com/sapxsl" version="1.0"&gt;
      &lt;xsl:strip-space elements="*"/&gt;
      &lt;xsl:template match="/"&gt;
        &lt;asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0"&gt;
          &lt;asx:values&gt;
            &lt;ALL_PEOPLE&gt;
              &lt;xsl:apply-templates select="//People"/&gt;
            &lt;/ALL_PEOPLE&gt;
          &lt;/asx:values&gt;
        &lt;/asx:abap&gt;
      &lt;/xsl:template&gt;
      &lt;xsl:template match="People"&gt;
        &lt;ALLMYFRIENDS&gt;  &lt;!This element name is not relevent... needed to just group the loop&gt;
          &lt;FIRSTNAME&gt;
            &lt;xsl:value-of select="FirstName"/&gt;
          &lt;/FIRSTNAME&gt;
          &lt;SURNAME&gt;
            &lt;xsl:value-of select="Surname"/&gt;
          &lt;/SURNAME&gt;
          &lt;ADDRESSES&gt;
            &lt;xsl:for-each select="Address"&gt;
              &lt;ADDRESS&gt; &lt;!This element name is not relevent... needed to just group the loop&gt;
                &lt;HOUSE_NO&gt;
                  &lt;xsl:value-of select="HouseNo"/&gt;
                &lt;/HOUSE_NO&gt;
                &lt;STREET_NAME&gt;
                  &lt;xsl:value-of select="Street"/&gt;
                &lt;/STREET_NAME&gt;
                &lt;CITY_NAME&gt;
                  &lt;xsl:value-of select="City"/&gt;
                &lt;/CITY_NAME&gt;
                &lt;PHONE_NO&gt;
                  &lt;xsl:value-of select="PhoneNo"/&gt;
                &lt;/PHONE_NO&gt;
              &lt;/ADDRESS&gt;
            &lt;/xsl:for-each&gt;
          &lt;/ADDRESSES&gt;
        &lt;/ALLMYFRIENDS&gt;
      &lt;/xsl:template&gt;
    &lt;/xsl:transform&gt;
    </PRE>
    <HR>
    HTH,
    Jayanta.

    thanks a LOT Jayanta..
    I was looking for an XSLT example for some time.. this one atleast got me started in the right direction..
    THANKS

  • Default key in internal tables

    what is 'Default key'? for what type of internal tables it is used? Can you please explain with examples?
    Thanks a lot.

    <i>Key
    The key identifies table rows. There are two kinds of key for internal tables - the standard key and a user-defined key. You can specify whether the key should be UNIQUE or NON-UNIQUE. Internal tables with a unique key cannot contain duplicate entries. The uniqueness depends on the table access method.
    <b>At tables with structured row type, the standard key is formed from all character-type columns of the internal table.</b> If a table has an elementary line type, the default key is the entire line. The default key of an internal table whose line type is an internal table, the default key is empty. At tables with non-structured row type, the standard key consists of the entire row. If the row type is also a table, an empty key is defined.
    The user-defined key can contain any columns of the internal table that are no internal table themselves, and do not contain internal tables. References are allowed as table keys. Internal tables with a user-defined key are called key tables. When you define the key, the sequence of the key fields is significant. You should remember this, for example, if you intend to sort the table according to the key.</i>
    Regards,
    Rich Heilman

  • Generic standard table type

    Anybody please resolve my doubt
    types tb_std_type type table of sflight.
    -->this i understand as not a generic table type.'NON-UNIQUE" and DEFAULT KEYS are implicity defined .
    data it_std type tb_std.-->Since i could declare an internal table of tb_std_type,i strongly belive tb_std_type is not a genric table type.
    But when i try to declare another type of same table type tb_std_type ie
    types tb2_type type tb_std_type.
    This is giving me an error saying\
    tb_std_type has a generic type.Use of this type is only possible for typing field symbols and  formal parameters.
    If thats true then how was i able to create a internal table  out of it...
    In case of sorted and hashed tables it behaves as exactly as it is defined.(Like if  generic,can only  be used for typing formal params.field symbold..and if non generic--internal tables declaration and normal typing is possible)
    Please resolve this
    *Would be great if could avoid a copy paste from std.help..because i have been through it..

    Hello Teenu,
    Query#1
    types tb2_type type tb_std_type.
    This is giving me an error saying\
    tb_std_type has a generic type.Use of this type is only possible for typing field symbols and formal parameters.
    Why is the table generic? An excerpt from SAP documentation clearly states that:
    An internal table that has no table key or an incomplete table key is generic with respect to the table key. A table type of this nature can be used only for typing formal parameters or field symbols.
    Query#2
    If thats true then how was i able to create a internal table out of it...
    SAP says:
    A standard table type with a generic primary table key can only be specified after TYPE when DATA is used.
    Source: [http://help.sap.com/abapdocu_70/en/ABAPTYPES_KEYDEF.htm|http://help.sap.com/abapdocu_70/en/ABAPTYPES_KEYDEF.htm]
    BR,
    Suhas

  • Usage of field-symbol to internal table generically.

    Hi gurus,
    please tell the usage of field symbol to an internall table.
    how do i use field symbol generically , so that i can use same field symbol for many different internal tables.
    regards,
    krishna
    TABLES: EKKO.
    DATA: ITAB TYPE STANDARD TABLE OF EKKO INITIAL SIZE 1.
    SELECT-OPTIONS: P_EBELN FOR EKKO-EBELN OBLIGATORY.
    FIELD-SYMBOLS <FS> TYPE any.
    SELECT *
    FROM EKKO
    INTO TABLE ITAB
    WHERE EBELN IN P_EBELN.
    LOOP AT ITAB ASSIGNING <FS> casting ekko.
      WRITE:/ <FS>-EBELN, <FS>-BUKRS, <FS>-LIFNR, <FS>-AEDAT, <FS>-EKGRP, <FS>-STATU, <FS>-SPRAS.
    ENDLOOP.

    How about something SIMPLE like this.
    This creates a dynamic table and displays it in an editable grid.
    The key to a real Generic internal table is to use the RTTI  functionality to generate a field catalog of the structure you want to use as an internal table and then create a dynamic table based on the FCAT created from your structure.
    For the code shown below code a simple screen ( SE51) with a custom container on it  called CCONTAINER1.
    Code also a standard status (SE41) with just the BACK, EXIT and CANCEL buttons on it.
    You can use this type of program as a model for ANY dynamic table. Note however that you still can't include DEEP structure in your dynamic table.
    With the program shown below you can edit the grid but you'll have to add your own functionality such as cell selection, double click etc etc.
    All the code is showning you really is how to take any user defined structure and simply without a whole load of fuss, buld an FCAT, a DYNAMIC TABLE, Populate it and display a grid.
    DO NOT EVER USE AGAIN THE OLD SLIS MODULES SUCH AS FM REUSE_ALV_etc.   Go for OO either cl_gui_alv_grid or if you don't need to edit anything the new SALV class.
    If you are still on 4.6 then the SALV class won't exist but the cl_gui_alv_grid class is fine.
    You can see also just by changing a few lines of codeyou can   display a grid of almost any structure you can think of (or populate another dynamic table).
    Note also if you have an actual table defined you can also always code something like your_itab[] = <dyn_table>  so you can retrieve your data easily enough via standard abap.
    All you need to do is define your structure, create the fcat and populate the dynamic table.
    Even if you don't want a a GRID you've got your data in a dynamic table which is what I believe you wanted in the first place. You don't have to display or use a GRID if you don't need to but I've added the code here as lots of applications need to display data in just these types of lists.
    Now surprise your Boss by coding in 10 mins a program he / she thought would take you 1 week. !!!!!.
    program zzz_simple_editable_grid.
    * Define any structure
    types:  begin of s_elements,
      vbeln   type vapma-vbeln,
      posnr   type vapma-posnr,
      matnr   type vapma-matnr,
      kunnr   type vapma-kunnr,
      werks   type vapma-werks,
      vkorg   type vapma-vkorg,
      vkbur   type vapma-vkbur,
      status  type c,
    end of  s_elements.
    * end of your structure
    data lr_rtti_struc type ref to cl_abap_structdescr .
    data:
        zog                     like line of lr_rtti_struc->components .
    data:
      zogt                    like table of zog,
    wa_it_fldcat type lvc_s_fcat,
    it_fldcat type lvc_t_fcat ,
    dy_line            type ref to data,
    dy_table           type ref to data.
    data:  dref               type ref to data.
    field-symbols: <fs> type any,
       <dyn_table>    type  standard table,
       <dyn_wa>.
    data grid_container1 type ref to cl_gui_custom_container .
    data grid1 type ref to cl_gui_alv_grid .
    data: ok_code type sy-ucomm.
    data: struct_grid_lset type lvc_s_layo.
    *now I want to build a field catalog
    * First get your data structure into a field symbol
    create data dref type s_elements.
    assign dref->* to <fs>.
    lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( <fs> ).
    * Now get the structure details into a table.
    * table zogt[] contains the structure details
    * From which we can build the field catalog
    zogt[]  = lr_rtti_struc->components.
    loop at zogt into zog.
      clear wa_it_fldcat.
      wa_it_fldcat-fieldname = zog-name .
      wa_it_fldcat-datatype = zog-type_kind.
      wa_it_fldcat-inttype = zog-type_kind.
      wa_it_fldcat-intlen = zog-length.
      wa_it_fldcat-decimals = zog-decimals.
      wa_it_fldcat-coltext = zog-name.
      wa_it_fldcat-lowercase = 'X'.
      append wa_it_fldcat to it_fldcat .
    endloop.
    * You can perform any modifications / additions to your field catalog
    * here such as your own column names etc.
    * Now using the field catalog created above we can
    * build a dynamic table
    * and populate it
    * First build the dynamic table
    * the table will contain entries for
    * our structure defined at the start of the program
    call method cl_alv_table_create=>create_dynamic_table
           exporting
                it_fieldcatalog = it_fldcat
           importing
                ep_table = dy_table.
    assign dy_table->* to <dyn_table>.
    create data dy_line like line of <dyn_table>.
    assign dy_line->* to <dyn_wa>.
    * Now fill our table with data
    select vbeln posnr matnr kunnr werks vkorg vkbur
           up to 200 rows
           from vapma
           into  corresponding fields of table <dyn_table>.
    * Call the screen to display the grid
    call screen 100.
    * PBO module
    module status_0100 output.
    data: off type int4.
    break-point 1.
    if sy-batch = 'X'.
    call method cl_gui_alv_grid=>offline
    receiving
    e_offline = off.
    endif.
    if sy-batch = 'X'.
    if ( off is initial ).
        create object grid_container1
                exporting
                   container_name = 'CCONTAINER1'.
        create object  grid1
           exporting
              i_parent = grid_container1.
    endif.
    endif.
    if sy-batch ne 'X'.
       if grid_container1 is initial.
         create object grid_container1
                 exporting
                    container_name = 'CCONTAINER1'.
      endif.
        create object  grid1
           exporting
              i_parent = grid_container1.
       if sy-batch ne 'X'.
        struct_grid_lset-edit = 'X'.    "To enable editing in ALV
      endif.
      endif.
        call method grid1->set_table_for_first_display
          exporting is_layout =  struct_grid_lset
          changing
                     it_outtab       = <dyn_table>
                     it_fieldcatalog = it_fldcat.
      set pf-status '001'.
      set titlebar '000'.
    endmodule.
    * PAI module
    module user_command_0100 input.
      case sy-ucomm.
        when 'BACK'.
          leave program.
        when 'EXIT'.
          leave program.
        when 'RETURN'.
          leave program.
        when others.
      endcase.
    endmodule.
    Cheers
    jimbo

  • Line item display and sort key

    Hello,
       can anybody pls let me know how can we change layout for f-53 ad f-28 and what is the significance of using sort keys and how can we use them.
    please let me know,
    thanks

    IMG: Financial Accounting -> General Ledger Accounting -> G/L Accounts -> Line Items -> Line Items -> Line Item Display -> Determine Standard Sorting for Line Items
        (Transaction OB16)
    You can define sort keys that are used to determine the structure of the assignment number.
    Typical fields for the assignment number are posting date, document number, fiscal
    year, purchase order, cost center, document header text.
    The possible values for the sort key are saved in field TZUN-ZUAWA.
    You can define a sort key in the master record of a G/L, customer, or vendor account  (Transactions FS01, FD01, FK01)(Table Fields SKB1-ZUAWA, KNB1-ZUAWA, LFB1-ZUAWA).
    Assignment Number
    The assignment number is used as a sort criterion. For example, the list for clearing      open items (FB05) or the line item list  (FBL3N, FBL5N, FBL1N) can be sorted by this  field. Besides this the assignment number is used as a group criterium for automatic
        clearing. During document posting, the assignment number is either determined from the sort key of the account master record or you can enter it manually (a manual entry overwrites the derived value).
    Hope above clarifies your doubts..
    Regards
    Siva

  • About binary search in standard table

    To improve the performance, we usually sort a standard table and do binary search when READ TABLE.
    Does this only work on key fields that are specified in the table definition.
    If I sort the table by a non-key field and do binary search, is it also helpful in performance improvement?

    Dear Ming,
    If you  sort the table by a non-key field and do binary search,
    it is also helpful to improve the performance.
    but You have to use same keys in read statement which you have used in sorting internal table.(k1, k2)
    Eg.
    SORT itab BY k1 k2.
    then you have to use same key in read statement other wise it returns wrong result.
    READ TABLE itab INTO wa_itab
    WITH KEY k1 = itab2-k1
                      k2 = itab2-k2
    BINARY SEARCH.
    Please find below more points:
    1. Don't forget to SORT internal table.
    2. Arrange the fields in WITH KEY same with sorting.
    3. Put SORT right before READ with BINARY SEARCH or before the loop stament to optimize
    Thanks,
    Vikas.

Maybe you are looking for

  • F110 Open Items wont close up

    While generating payment proposal i get all the lines registered in my system as open items... i have paid most of them but they still appear as open and i have to block them manually one by one... this occurs in Tx code F110... is this a common trou

  • Account assignment search help in SC.

    We currently implement stand-alone scenario and looking for solution how to maintain account assignment data in EBP. As far as I know account assignment data managed in back-end system and not replicated into EBP. We would like to manage account assi

  • I have 2 accounts and want to delete/remove one.  How do I do this?

    I have 2 accounts and want to delete/remove one.  How do I do this?

  • How do I get Photos to Completely  Fill TV Screen

    I have a 50" Samsung Plasma TV and a 40 G ATV. The pics look great but don't entirely fill the screen in Horizontal view. There is black on both sides of the pics. Is there a way to fix this so they fill the whole TV Screen? They are Hi-Res 2.5 to 3.

  • ESS Errro : Hrxssce_Service_Appl_Path doesnt exits

    Hi forum When i enter in ESS > Workint Time > Time Statement for a Chosen Period   OR ESS > Workint Time > Time Statement I got this error Type com.sap.pcuigp.xssutils.pernr.model.grpinfo.types.Hrxssce_Service_Appl_Path does not exist Someone knows,