<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ALV - Drilldown After Sort in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490933#M228445</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;exactly you don't require to build internal table&lt;/P&gt;&lt;P&gt;with create_dynamic_table. it is required only when you don't know the no of fields you have in your internal table.  like if you want to have fields depending on the clients in your r/3 system here you don't know how many clients you have in your system you have to know fileds dynamically(during run time only).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 Sep 2006 22:00:24 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-09-05T22:00:24Z</dc:date>
    <item>
      <title>ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490919#M228431</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello friends,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In ALV reports (using either cl_salv_table or cl_gui_alv_grid) I always face a problem when a drilldown is performed on sorted output list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I retrieve the sort columns and the selected row-column values using event-handler. Now, when I sort my internal table based on the sort columns it results in different sorted order...meaning, it is not the same as the sorted-order on the screen. What could be the reason? Please help me out!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Aug 2006 23:36:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490919#M228431</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-08-30T23:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490920#M228432</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sam, that is very weird, I've just tested one of my programs using the ALV Object Model, and it is working fine when I sort.  I believe that I've tested this before when using CL_GUI_ALV_GRID as well and had no problems.  Can you post your code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Aug 2006 23:51:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490920#M228432</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-08-30T23:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490921#M228433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yeah Rich, it is weird &lt;SPAN __jive_emoticon_name="sad"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I will post my code, please look at it and let me know where I am going wrong.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Aug 2006 23:59:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490921#M228433</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-08-30T23:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490922#M228434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi sam,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   i worked on somany reports in saplabs using cl_salv* classes, i never faced such problem.&lt;/P&gt;&lt;P&gt;If you can send the code we will test it...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Aug 2006 00:09:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490922#M228434</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-08-31T00:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490923#M228435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, I couldn't post this yesterday. Please take a look!&lt;/P&gt;&lt;P&gt;(There are three different sources: one main program and two includes)&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT ztest NO STANDARD PAGE HEADING.

INCLUDE: ztesttop,
         ztest_drill_down.

*----------------------------------------------------------------------*
* START OF SELECTION                                                   *
*----------------------------------------------------------------------*
START-OF-SELECTION.
*-Get Output/Data
  PERFORM get_data.

END-OF-SELECTION.

*-Display Output Data
  PERFORM display_data.

*----------------------------------------------------------------------*
* GET OUTPUT DATA                                                      *
*----------------------------------------------------------------------*
FORM get_data .

  SELECT ebeln bukrs ekorg ekgrp lifnr zterm
    FROM ekko
    INTO TABLE i_output
    WHERE bsart = 'NB'.

ENDFORM.                    " get_data


*----------------------------------------------------------------------*
* DISPLAY DATA IN OUTPUT TABLE USING ALV OBJECT MODEL                  *
*----------------------------------------------------------------------*
FORM display_data.

*-Build Field Catalog
  PERFORM build_catalog.

*-Assign A Reference To The Internal Table With Field Catalog
  CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table
    EXPORTING
      it_fieldcatalog = i_fcat
    IMPORTING
      ep_table        = dref.

  ASSIGN  dref-&amp;gt;* TO &amp;lt;output_table&amp;gt;.

  &amp;lt;output_table&amp;gt; = i_output[].

*-Generate ALV Factory Object
  TRY.
      CALL METHOD cl_salv_table=&amp;gt;factory
        EXPORTING
          list_display = if_salv_c_bool_sap=&amp;gt;false
        IMPORTING
          r_salv_table = o_alv_table
        CHANGING
          t_table      = &amp;lt;output_table&amp;gt;.
    CATCH cx_salv_msg.
  ENDTRY.

*-Activate ALV Generic Functions
  o_functions = o_alv_table-&amp;gt;get_functions( ).
  o_functions-&amp;gt;set_all( abap_true ).
  o_functions-&amp;gt;set_export_xml( abap_true ).

*-Display Settings
  o_display = o_alv_table-&amp;gt;get_display_settings( ).
  o_display-&amp;gt;set_striped_pattern( abap_true ).

*-Handle Events
  o_events = o_alv_table-&amp;gt;get_event( ).
  CREATE OBJECT event_receiver.
  SET HANDLER event_receiver-&amp;gt;handle_double_click FOR o_events.

*-Customize Columns
  o_columns = o_alv_table-&amp;gt;get_columns( ).
  o_columns-&amp;gt;set_optimize( abap_true ).

*-Set Up Report Headers
  PERFORM create_headers.

*-Display The Output Table
  o_alv_table-&amp;gt;display( ).

ENDFORM.                    " display_data

*----------------------------------------------------------------------*
* BUILD FIELD CATALOG FOR ALV DISPLAY                                  *
*----------------------------------------------------------------------*
FORM build_catalog .

  CLEAR: wa_fcat.
  REFRESH: i_fcat.

*-Purchasing Doc No
  wa_fcat-col_id    = '1'.
  wa_fcat-fieldname = 'EBELN'.
  wa_fcat-ref_field = 'EBELN'.
  wa_fcat-ref_table = 'EKKO'.
  wa_fcat-tabname   = 'I_OUTPUT'.
  APPEND wa_fcat TO i_fcat .
  CLEAR wa_fcat.

*-Company Code
  wa_fcat-col_id    = '2'.
  wa_fcat-fieldname = 'BUKRS'.
  wa_fcat-ref_field = 'BUKRS'.
  wa_fcat-ref_table = 'EKKO'.
  wa_fcat-tabname   = 'I_OUTPUT'.
  APPEND wa_fcat TO i_fcat .
  CLEAR wa_fcat.

*-Purchasing Org
  wa_fcat-col_id    = '3'.
  wa_fcat-fieldname = 'EKORG'.
  wa_fcat-ref_field = 'EKORG'.
  wa_fcat-ref_table = 'EKKO'.
  wa_fcat-tabname   = 'I_OUTPUT'.
  APPEND wa_fcat TO i_fcat .
  CLEAR wa_fcat.

*-Purchasing Group
  wa_fcat-col_id    = '4'.
  wa_fcat-fieldname = 'EKGRP'.
  wa_fcat-ref_field = 'EKGRP'.
  wa_fcat-ref_table = 'EKKO'.
  wa_fcat-tabname   = 'I_OUTPUT'.
  APPEND wa_fcat TO i_fcat .
  CLEAR wa_fcat.

*-Vendor
  wa_fcat-col_id    = '5'.
  wa_fcat-fieldname = 'LIFNR'.
  wa_fcat-ref_field = 'LIFNR'.
  wa_fcat-ref_table = 'EKKO'.
  wa_fcat-tabname   = 'I_OUTPUT'.
  APPEND wa_fcat TO i_fcat .
  CLEAR wa_fcat.

*-Purchasing Term
  wa_fcat-col_id    = '6'.
  wa_fcat-fieldname = 'ZTERM'.
  wa_fcat-ref_field = 'ZTERM'.
  wa_fcat-ref_table = 'EKKO'.
  wa_fcat-tabname   = 'I_OUTPUT'.
  APPEND wa_fcat TO i_fcat .
  CLEAR wa_fcat.

ENDFORM.                    " build_catalog


*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      CREATE ALV TOP-OF-PAGE HEADERS                                 *
*&amp;amp;---------------------------------------------------------------------*
FORM create_headers .

  DATA: l_system(12) TYPE c.

  CREATE OBJECT o_header.
  o_header-&amp;gt;create_header_information( row = 1 column = 1 text = sy-title tooltip = sy-title ).

*-Create a grid in the cell [2,1]
  o_header_1 = o_header-&amp;gt;create_grid( row = 2 column = 1 ).

*-R3 System
  CONCATENATE sy-sysid sy-mandt INTO l_system SEPARATED BY space.
  o_flow  = o_header_1-&amp;gt;create_flow( row = 1 column = 1 ).
  o_label = o_flow-&amp;gt;create_label( text = 'System:'(t02) tooltip = 'System:'(t02) ).
  o_text  = o_flow-&amp;gt;create_text( text = l_system tooltip = l_system ).

*-User
  o_flow  = o_header_1-&amp;gt;create_flow( row = 1 column = 2 ).
  o_label = o_flow-&amp;gt;create_label( text = 'User  :'(t03) tooltip = 'User  :'(t03) ).
  o_text  = o_flow-&amp;gt;create_text( text = sy-uname tooltip = sy-uname ).

*-Date
  o_flow  = o_header_1-&amp;gt;create_flow( row = 2 column = 1 ).
  o_label = o_flow-&amp;gt;create_label( text = 'Date  :'(t04) tooltip = 'Date  :'(t04) ).
  o_text  = o_flow-&amp;gt;create_text( text = sy-datum tooltip = sy-datum ).

*-Time
  o_flow  = o_header_1-&amp;gt;create_flow( row = 2 column = 2 ).
  o_label = o_flow-&amp;gt;create_label( text = 'Time  :'(t05) tooltip = 'Time  :'(t05) ).
  o_text  = o_flow-&amp;gt;create_text( text = sy-uzeit tooltip = sy-uzeit ).

  o_alv_table-&amp;gt;set_top_of_list( o_header ).

ENDFORM.                    " CREATE_HEADERS
&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;  Include           ZTESTTOP
*&amp;amp;---------------------------------------------------------------------*

*-------------------------------------------------------------------------------------*
* TYPES                                                                               *
*-------------------------------------------------------------------------------------*
*------Document Header Data
TYPES: 
*-------Output Data
       BEGIN OF ty_output,
         ebeln TYPE ekko-ebeln,
         bukrs TYPE ekko-bukrs,
         ekorg TYPE ekko-ekorg,
         ekgrp TYPE ekko-ekgrp,
         lifnr TYPE ekko-lifnr,
         zterm TYPE ekko-zterm,
       END OF ty_output,

       BEGIN OF ty_sort_columns,
         name  TYPE lvc_fname,
         order TYPE i,
       END OF ty_sort_columns.

*-------------------------------------------------------------------------------------*
* INTERNAL TABLES, STRUCTURES &amp;amp; WORKAREAS                                             *
*-------------------------------------------------------------------------------------*
*-----Output Data
DATA: i_output   TYPE STANDARD TABLE OF ty_output,
      wa_output  TYPE ty_output.

*-ALV DECLARATIONS
*-----Field Catalog
DATA: i_fcat         TYPE lvc_t_fcat,
      wa_fcat        TYPE lvc_s_fcat,

*-----Output/Display Table Object
      o_alv_table    TYPE REF TO cl_salv_table,

*-----Output List Sort Objects
      o_sort_defined  TYPE sap_bool,
      o_sort_table    TYPE salv_t_sort_ref,
      o_sort_column   TYPE salv_s_sort_ref,
      i_sort_columns  TYPE STANDARD TABLE OF ty_sort_columns,
      wa_sort_columns TYPE ty_sort_columns,

*-----Top Of Page Objects
      o_header      TYPE REF TO cl_salv_form_layout_grid,
      o_header_1    TYPE REF TO cl_salv_form_layout_grid,

*-----End Of List Object
      o_footer      TYPE REF TO cl_salv_form_layout_grid,

*-----Top Of Page &amp;amp; End Of List Texts/Grid Objects
      o_flow        TYPE REF TO cl_salv_form_layout_flow,
      o_label       TYPE REF TO cl_salv_form_label,
      o_text        TYPE REF TO cl_salv_form_text,
      g_text        TYPE string.

*----------------------------------------------------------------------*
*       CLASS alv_æ&amp;#137;§vent_receiver DEFINITION
*----------------------------------------------------------------------*
CLASS alv_event_receiver DEFINITION.

  PUBLIC SECTION.
    METHODS:

    handle_double_click
        FOR EVENT double_click OF cl_salv_events_table
            IMPORTING row column.

  PRIVATE SECTION.

ENDCLASS.                    "alv_event_receiver DEFINITION

*-------------------------------------------------------------------------------------*
* GLOBAL VARIABLE                                                                     *
*-------------------------------------------------------------------------------------*

*-ALV DECLARATIONS
DATA : dref           TYPE REF TO data,
       o_functions    TYPE REF TO cl_salv_functions_list,
       o_events       TYPE REF TO cl_salv_events_table,
       o_display      TYPE REF TO cl_salv_display_settings,
       o_sorts        TYPE REF TO cl_salv_sorts,
       o_columns      TYPE REF TO cl_salv_columns,
       o_selections   TYPE REF TO cl_salv_selections,
       event_receiver TYPE REF TO alv_event_receiver,
       columns_table  TYPE salv_t_column_ref,
       column         TYPE salv_s_column_ref.

FIELD-SYMBOLS : &amp;lt;output_table&amp;gt; TYPE table,
                &amp;lt;sort_column&amp;gt;  TYPE string.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;  Include           ZTEST_DRILL_DOWN
*&amp;amp;---------------------------------------------------------------------*

*----------------------------------------------------------------------*
*       CLASS alv_event_receiver IMPLEMENTATION                        *
*----------------------------------------------------------------------*
CLASS alv_event_receiver IMPLEMENTATION.

  METHOD handle_double_click.

    PERFORM get_sort_sequence.
    PERFORM adjust_output_table.

    READ TABLE i_output INDEX row INTO wa_output.
    IF sy-subrc = 0.

      CASE column.
        WHEN 'EBELN'.
          CALL FUNCTION 'ME_DISPLAY_PURCHASE_DOCUMENT'
            EXPORTING
              i_ebeln              = wa_output-ebeln
              i_enjoy              = 'X'
            EXCEPTIONS
              not_found            = 1
              no_authority         = 2
              invalid_call         = 3
              preview_not_possible = 4
              OTHERS               = 5.

        WHEN 'LIFNR'.
          CALL FUNCTION 'MMPUR_VENDOR_DISPLAY'
            EXPORTING
              im_lifnr = wa_output-lifnr
              im_ekorg = wa_output-ekorg.
      ENDCASE.

    ENDIF.

  ENDMETHOD.                           "handle_double_click

ENDCLASS.                    "alv_event_receiver IMPLEMENTATION

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Get Sort Sequence From ALV Output                              *
*&amp;amp;---------------------------------------------------------------------*
FORM get_sort_sequence .

  DATA: l_no_of_sorts TYPE i.

*-Instantiate An Object To Handle Sorts
  o_sorts = o_alv_table-&amp;gt;get_sorts( ).

*-Get An Handler To The Sorts Defined
  o_sort_defined = o_sorts-&amp;gt;is_sort_defined( ).

  IF o_sort_defined = abap_true.

    o_sort_table = o_sorts-&amp;gt;get( ).

*---Collect Sort Columns And Corresponding Order (Asc or Desc)
    LOOP AT o_sort_table INTO o_sort_column.

      wa_sort_columns-name  = o_sort_column-columnname.
      wa_sort_columns-order = o_sort_column-r_sort-&amp;gt;get_sequence( ).

      APPEND wa_sort_columns TO i_sort_columns.
      CLEAR wa_sort_columns.

    ENDLOOP.

  ENDIF.

ENDFORM.                    " get_sort_sequence


*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Sort Output Table Based On ALV-Sort Columns
*&amp;amp;---------------------------------------------------------------------*
FORM adjust_output_table .

  CONSTANTS: c_ascending  TYPE i VALUE 1,
             c_descending TYPE i VALUE 2.

  DATA: i_pool        TYPE STANDARD TABLE OF string,
        wa_pool       TYPE string,
        l_program     TYPE string,
        "l_routine     TYPE string  VALUE 'SORT_OUTPUT',
        l_message     TYPE string,
        l_sid         TYPE string,
        l_line        TYPE i,
        l_sort_string TYPE string,
        l_mem_id      TYPE char17 VALUE 'ZTEST_SORT_OUTPUT'.

  l_sort_string = 'SORT I_OUTPUT BY'.

  IF i_sort_columns[] IS NOT INITIAL.

*---Build The Sort Command
    LOOP AT i_sort_columns INTO wa_sort_columns.

      CONCATENATE l_sort_string wa_sort_columns-name INTO l_sort_string SEPARATED BY space.

      CASE wa_sort_columns-order.
        WHEN c_ascending.
          CONCATENATE l_sort_string 'ASCENDING' INTO l_sort_string SEPARATED BY space.
        WHEN c_descending.
          CONCATENATE l_sort_string 'DESCENDING' INTO l_sort_string SEPARATED BY space.
      ENDCASE.

    ENDLOOP.

    CONCATENATE l_sort_string '.' INTO l_sort_string.

*-Upload output table to memory
    EXPORT i_output[] TO MEMORY ID l_mem_id.

*---Build Source For Subroutine-Pool
    APPEND 'PROGRAM SUBPOOL.'  TO i_pool.
    APPEND 'LOAD-OF-PROGRAM.'  TO i_pool.
    APPEND 'FORM LOOP_AT_TAB.' TO i_pool.
    APPEND 'DATA: BEGIN OF I_OUTPUT OCCURS 0,'  TO i_pool.
    APPEND '       ebeln TYPE ekko-ebeln,' TO i_pool.
    APPEND '       bukrs TYPE ekko-bukrs,' TO i_pool.
    APPEND '       ekorg TYPE ekko-ekorg,' TO i_pool.
    APPEND '       ekgrp TYPE ekko-ekgrp,' TO i_pool.
    APPEND '       lifnr TYPE ekko-lifnr,' TO i_pool.
    APPEND '       zterm TYPE ekko-zterm,' TO i_pool.
    APPEND '      END OF I_OUTPUT.' TO i_pool.
    APPEND 'DATA: l_mem_id TYPE char17.' TO i_pool.
    APPEND 'l_mem_id = ' &amp;amp; '''ZTEST_SORT_OUTPUT''.' TO i_pool.
    APPEND 'IMPORT i_output[] FROM MEMORY ID l_mem_id.' TO i_pool.
    APPEND 'FREE MEMORY ID l_mem_id.' TO i_pool.
    APPEND l_sort_string TO i_pool.
    APPEND 'ENDFORM.' TO i_pool.

    GENERATE SUBROUTINE POOL i_pool NAME l_program MESSAGE l_message LINE l_line SHORTDUMP-ID l_sid.
    IF sy-subrc = 0.
      PERFORM ('LOOP_AT_TAB') IN PROGRAM (l_program) IF FOUND.
    ELSEIF sy-subrc = 4.
      MESSAGE l_message TYPE 'I'.
    ELSEIF sy-subrc = 8.
      MESSAGE l_sid TYPE 'I'.
    ENDIF.

  ENDIF.

ENDFORM.                    " adjust_output_table
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Aug 2006 20:57:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490923#M228435</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-08-31T20:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490924#M228436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sam, first I liked to say.... very nice coding &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;  It is not often that I see coding like this.  Very nice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now to your problem,  I am a little confused about the need for these two forms.  Can you explain to me what is the use of these?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

METHOD handle_double_click.
 
&amp;lt;b&amp;gt;    PERFORM get_sort_sequence.
    PERFORM adjust_output_table.&amp;lt;/b&amp;gt;
 
    READ TABLE i_output INDEX row INTO wa_output.
    IF sy-subrc = 0.
 
      CASE column.
        WHEN 'EBELN'.
          CALL FUNCTION 'ME_DISPLAY_PURCHASE_DOCUMENT'
            EXPORTING
              i_ebeln              = wa_output-ebeln
              i_enjoy              = 'X'
            EXCEPTIONS
              not_found            = 1
              no_authority         = 2
              invalid_call         = 3
              preview_not_possible = 4
              OTHERS               = 5.
 
        WHEN 'LIFNR'.
          CALL FUNCTION 'MMPUR_VENDOR_DISPLAY'
            EXPORTING
              im_lifnr = wa_output-lifnr
              im_ekorg = wa_output-ekorg.
      ENDCASE.
 
    ENDIF.
 
  ENDMETHOD.                           "handle_double_click


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That fact that you are applying a sort between the time that you double clicking and actually reading the table with row index, I think this is causing your problem.  Not sure why you have this coding here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you did this to try to handle the sorting of your internal table, there is no need, the ALV handles this for you.  Try commenting out the calls to these PERFORMS and try again.  I think you will see that the row being passed to your event handler is the correct row regardless of sorting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;RIch Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Sep 2006 00:57:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490924#M228436</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-09-01T00:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490925#M228437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, what can I say! I am greatly excited &amp;amp; happy to hear this from you! Thanks much &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did comment out those those performs and tried again. But it didnt work. Is there something wrong in the way I declare my internal table? I am confused!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Sep 2006 17:11:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490925#M228437</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-05T17:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490926#M228438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sam,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have encountered the same issue.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Change this statement:&lt;/P&gt;&lt;P&gt;l_sort_string = 'SORT I_OUTPUT BY'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;l_sort_string = 'SORT I_OUTPUT STABLE BY'.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Sep 2006 17:26:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490926#M228438</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-05T17:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490927#M228439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No luck this time too! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rich / John - If you have any working code, can I please look at it?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Sep 2006 18:57:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490927#M228439</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-05T18:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490928#M228440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sure check this sample.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report ZTE_DEMO_2.

data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions_list.
data: gr_display_settings type ref to cl_salv_display_settings.
data: gr_columns type ref to cl_salv_columns.
data: gr_column  type ref to cl_salv_column.
data: gr_selections type ref to cl_salv_selections.
data: gr_sorts type ref to cl_salv_sorts.
data: gr_sort type ref to cl_salv_sort.
data: gr_agg type ref to cl_salv_aggregations.
data: gr_events type ref to cl_salv_events_table.
data: gr_dialog_table type ref to cl_salv_table.

*----------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_event_handler definition.

  public section.

    methods: handle_doubleclick for event double_click
                       of cl_salv_events_table
                           importing  row column.

endclass.                    "lcl_event_handler DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_event_handler implementation.

  method handle_doubleclick.

    data: xspfli type spfli.
    data: isbook type table of sbook.

    read table ispfli into xspfli index row.
    if sy-subrc = 0.

      select * into table isbook from sbook
                 where carrid = xspfli-carrid
                   and connid = xspfli-connid.

      cl_salv_table=&amp;gt;factory(
                             importing r_salv_table  = gr_dialog_table
                              changing  t_table      = isbook ).
      gr_dialog_table-&amp;gt;set_screen_popup( start_column = 1
                                         end_column   = 100
                                         start_line   = 1
                                         end_line     = 20 ).
      gr_dialog_table-&amp;gt;display( ).

    endif.

  endmethod.                    "handle_doubleclick



endclass.                    "lcl_event_handler IMPLEMENTATION

data: o_event_handler type ref to lcl_event_handler.

start-of-selection.

  select * into corresponding fields of table ispfli from spfli.

  cl_salv_table=&amp;gt;factory( importing r_salv_table = gr_table
                          changing  t_table      = ispfli ).


  gr_functions = gr_table-&amp;gt;get_functions( ).
  gr_functions-&amp;gt;set_all( abap_true ).

  gr_display_settings = gr_table-&amp;gt;get_display_settings( ).
  gr_display_settings-&amp;gt;set_list_header( 'This is the list header' ).


  gr_columns = gr_table-&amp;gt;get_columns( ).
  gr_column = gr_columns-&amp;gt;get_column( 'CITYTO' ).
  gr_column-&amp;gt;set_long_text( 'This is the cityto' ).


  gr_selections = gr_table-&amp;gt;get_selections( ).
  gr_selections-&amp;gt;set_selection_mode( '4' ).


  data: icol type table of lvc_fname.
  data: xcol type lvc_fname.
  data: irow type salv_t_row.
  data: xrow like line of irow.

  xcol = 'CITYTO'.  append xcol to icol.
  xcol = 'CARRID'.  append xcol to icol.
  gr_selections-&amp;gt;set_selected_columns( icol ).

  xrow = '2'.  append xrow to irow.
  xrow = '8'.  append xrow to irow.
  gr_selections-&amp;gt;set_selected_rows( irow ).


  gr_sorts = gr_table-&amp;gt;get_sorts( ).
  gr_sorts-&amp;gt;add_sort( columnname = 'CARRID'
                      subtotal = 'X' ).


  gr_agg = gr_table-&amp;gt;get_aggregations( ).
  gr_agg-&amp;gt;add_aggregation( 'DISTANCE' ).

  gr_events = gr_table-&amp;gt;get_event( ).

  create object o_event_handler.
  set handler o_event_handler-&amp;gt;handle_doubleclick for gr_events.

  gr_table-&amp;gt;display( ).

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Sep 2006 20:01:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490928#M228440</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-09-05T20:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490929#M228441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So what happened Sam?  What was the problem?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Sep 2006 20:46:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490929#M228441</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-09-05T20:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490930#M228442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;what rich is told is correct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;use &lt;/P&gt;&lt;P&gt;  gr_sorts-&amp;gt;add_sort( columnname = 'CARRID'&lt;/P&gt;&lt;P&gt;                      subtotal = 'X' ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    gr_sorts-&amp;gt;add_sort( columnname = 'another column'&lt;/P&gt;&lt;P&gt;                      subtotal = 'X' ).&lt;/P&gt;&lt;P&gt;this is how you need to build sort sequence before calling display method.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;and remove&lt;/P&gt;&lt;P&gt;    PERFORM get_sort_sequence.&lt;/P&gt;&lt;P&gt;    PERFORM adjust_output_table. from double click method...no need of generating subroutine pool to sort...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try this and let us know whether its working or not...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Sep 2006 20:49:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490930#M228442</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-05T20:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490931#M228443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First of all - Thank you! I modified my code based on yours and it worked. Here is the modified version:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT ztemp NO STANDARD PAGE HEADING.

TYPES: BEGIN OF ty_output,
         ebeln TYPE ekko-ebeln,
         bukrs TYPE ekko-bukrs,
         ekorg TYPE ekko-ekorg,
         ekgrp TYPE ekko-ekgrp,
         lifnr TYPE ekko-lifnr,
         zterm TYPE ekko-zterm,
       END OF ty_output.

*-----Output Data
DATA: i_output  TYPE STANDARD TABLE OF ty_output,
      wa_output TYPE ty_output.

DATA: gr_table            TYPE REF TO cl_salv_table.
DATA: gr_functions        TYPE REF TO cl_salv_functions_list.
DATA: gr_display_settings TYPE REF TO cl_salv_display_settings.
DATA: gr_columns          TYPE REF TO cl_salv_columns.
DATA: gr_events           TYPE REF TO cl_salv_events_table.


*----------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.

  PUBLIC SECTION.

    METHODS: handle_doubleclick FOR EVENT double_click
                       OF cl_salv_events_table
                           IMPORTING  row column.

ENDCLASS.                    "lcl_event_handler DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.

  METHOD handle_doubleclick.

    READ TABLE i_output INTO wa_output INDEX row.
    IF sy-subrc = 0.

      CASE column.
        WHEN 'EBELN'.
          CALL FUNCTION 'ME_DISPLAY_PURCHASE_DOCUMENT'
            EXPORTING
              i_ebeln              = wa_output-ebeln
              i_enjoy              = 'X'
            EXCEPTIONS
              not_found            = 1
              no_authority         = 2
              invalid_call         = 3
              preview_not_possible = 4
              OTHERS               = 5.

        WHEN 'LIFNR'.
          CALL FUNCTION 'MMPUR_VENDOR_DISPLAY'
            EXPORTING
              im_lifnr = wa_output-lifnr
              im_ekorg = wa_output-ekorg.
      ENDCASE.

    ENDIF.

  ENDMETHOD.                    "handle_doubleclick

ENDCLASS.                    "lcl_event_handler IMPLEMENTATION

DATA: o_event_handler TYPE REF TO lcl_event_handler.

*----------------------------------------------------------------------*
* START OF SELECTION                                                   *
*----------------------------------------------------------------------*
START-OF-SELECTION.
*-Get Output/Data
  PERFORM get_data.

*-Display Output Data
  PERFORM display_data.


*----------------------------------------------------------------------*
* GET OUTPUT DATA                                                      *
*----------------------------------------------------------------------*
FORM get_data .

  SELECT ebeln bukrs ekorg ekgrp lifnr zterm
    FROM ekko
    INTO TABLE i_output
    WHERE bsart = 'NB'.

ENDFORM.                    " get_data


*----------------------------------------------------------------------*
* DISPLAY DATA IN OUTPUT TABLE USING ALV OBJECT MODEL                  *
*----------------------------------------------------------------------*
FORM display_data.

  TRY.
      cl_salv_table=&amp;gt;factory( EXPORTING list_display = if_salv_c_bool_sap=&amp;gt;false
                              IMPORTING r_salv_table = gr_table
                              CHANGING  t_table      = i_output ).
    CATCH cx_salv_msg.
  ENDTRY.

  gr_functions = gr_table-&amp;gt;get_functions( ).
  gr_functions-&amp;gt;set_all( abap_true ).

  gr_display_settings = gr_table-&amp;gt;get_display_settings( ).
  gr_display_settings-&amp;gt;set_list_header( 'Purchase Orders' ).
  gr_display_settings-&amp;gt;set_striped_pattern( abap_true ).

  gr_columns = gr_table-&amp;gt;get_columns( ).
  gr_columns-&amp;gt;set_optimize( abap_true ).

  gr_events = gr_table-&amp;gt;get_event( ).
  CREATE OBJECT o_event_handler.
  SET HANDLER o_event_handler-&amp;gt;handle_doubleclick FOR gr_events.

  gr_table-&amp;gt;display( ).

ENDFORM.                    " display_data
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Sep 2006 21:02:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490931#M228443</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-05T21:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490932#M228444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I believe my approach to display the output made the difference. I did not use the method "create_dynamic_table" using the field catalog to get an output reference. Previously, I assigned this reference to a field symbol and equate it to my output table contents. Instead, called the factory method directly (like in your sample). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks Rich!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Sep 2006 21:08:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490932#M228444</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-05T21:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Drilldown After Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490933#M228445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;exactly you don't require to build internal table&lt;/P&gt;&lt;P&gt;with create_dynamic_table. it is required only when you don't know the no of fields you have in your internal table.  like if you want to have fields depending on the clients in your r/3 system here you don't know how many clients you have in your system you have to know fileds dynamically(during run time only).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Sep 2006 22:00:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-drilldown-after-sort/m-p/1490933#M228445</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-05T22:00:24Z</dc:date>
    </item>
  </channel>
</rss>

