Skip to Content

To Sort Table Maintenance Before Display.

I found the below steps very useful to sort the table maintenance before display.

  • Go to SE11 and enter table name(eg. ZTEST) ->Display
  • Click UTILITIES menu->Table Maintenance Generator
  • Click on ENVIRONMENT menu->Modification->Maintenance screens->Double click on record in the popup.
  • Write one MODULE SORT_EXTRACT (in PBO of the maintenance view screen) to sort exactly before Table Control loop statement(LOOP AT EXTRACT WITH CONTROL)
  • Write the below piece of code at SORT_EXTRACT to sort Table Maintenance.

    MODULE SORT_EXTRACT OUTPUT.

    DATA : IT_ZTEST LIKE ZTEST OCCURS 1WITHHEADER LINE .

    IF NOT SY-UCOMM = ‘NEWL’.

    IT_ZTEST[] = EXTRACT[].

    SORT IT_ZTEST BY F1 F2 F3.

    EXTRACT[] = IT_ZTEST[].

    ENDIF.

    ENDMODULE” SORT_EXTRACT OUTPUT


    Source: An SAP Consultant: SAP ABAP – sorting Table maintenance

9 Comments
You must be Logged on to comment or reply to a post.
  • I have “optimized” the MODULE Content, to be able to use it more than once

    CODE:

    CASE objh-objectname.    “global field ūüôā

      WHEN ‘<YOUR_MAINTVIEW>’. 

        DATA : IT_ZTEST LIKE <YOUR_MAINTVIEW> OCCURS 1 WITH HEADER LINE .

         […]

    ENDCASE.

  • Hello Chitra, it doesn’t work, I’ve a dump¬† OBJECTS_TABLES_NOT_COMPATIBLE ( description: Two internal tables are not compatible or convertible )

  • Hi¬†Chitra / Leanid,

    I have modified above code for better performance.

      DATA lt_tab_agent TYPE STANDARD TABLE OF <YOUR TABLE NAME>.
    
      FIELD-SYMBOLS: <lfs_xfrom> TYPE x, "Hexadecimal value of from value
                     <lfs_xto>   TYPE x. "Hexadecimal value of to value
    
      IF NOT sy-ucomm = 'NEWL'.
    
        CLEAR lt_tab_agent[].
    
        LOOP AT extract.
    
          APPEND INITIAL LINE TO lt_tab_agent ASSIGNING <lfs_xto> CASTING.
          ASSIGN extract TO <lfs_xfrom> CASTING.
    
          <lfs_xto> = <lfs_xfrom>.
    
        ENDLOOP.
    
        SORT lt_tab_agent BY <REQUIRED FIELDS>.
    
        REFRESH extract.
        LOOP AT lt_tab_agent INTO <YOUR TABLE NAME>.
    
          APPEND INITIAL LINE TO extract ASSIGNING <lfs_xto> CASTING.
          ASSIGN <YOUR TABLE NAME> TO <lfs_xfrom> CASTING.
    
          <lfs_xto> = <lfs_xfrom>.
    
        ENDLOOP.
    
      ENDIF.

     

     

    • Hi Helen,

      Try like this.

        DATA: lt_tab_agent TYPE STANDARD TABLE OF zbc_mail_support,
              lrt_ucomm    TYPE RANGE OF sy-ucomm INITIAL SIZE 0,
              lwa_ucomm    LIKE LINE OF lrt_ucomm.
      
        FIELD-SYMBOLS: <lfs_xfrom> TYPE x, "Hexadecimal value of from value
                       <lfs_xto>   TYPE x. "Hexadecimal value of to value
      
        REFRESH lrt_ucomm.
        CLEAR lrt_ucomm[].
      
      * Prepare exclude list range for user command
        lwa_ucomm-sign = 'I'.   lwa_ucomm-option = 'EQ'.
        lwa_ucomm-low = 'NEWL'. lwa_ucomm-high = ''.
        APPEND lwa_ucomm TO lrt_ucomm. CLEAR lwa_ucomm.
      
        lwa_ucomm-sign = 'I'.   lwa_ucomm-option = 'EQ'.
        lwa_ucomm-low = 'DELE'. lwa_ucomm-high = ''.
        APPEND lwa_ucomm TO lrt_ucomm. CLEAR lwa_ucomm.
      
        lwa_ucomm-sign = 'I'.   lwa_ucomm-option = 'EQ'.
        lwa_ucomm-low = 'KOPE'. lwa_ucomm-high = ''.
        APPEND lwa_ucomm TO lrt_ucomm. CLEAR lwa_ucomm.
      
        lwa_ucomm-sign = 'I'.   lwa_ucomm-option = 'EQ'.
        lwa_ucomm-low = 'ORGI'. lwa_ucomm-high = ''.
        APPEND lwa_ucomm TO lrt_ucomm. CLEAR lwa_ucomm.
      
        lwa_ucomm-sign = 'I'.   lwa_ucomm-option = 'EQ'.
        lwa_ucomm-low = 'MKAL'. lwa_ucomm-high = ''.
        APPEND lwa_ucomm TO lrt_ucomm. CLEAR lwa_ucomm.
      
        lwa_ucomm-sign = 'I'.   lwa_ucomm-option = 'EQ'.
        lwa_ucomm-low = 'MKBL'. lwa_ucomm-high = ''.
        APPEND lwa_ucomm TO lrt_ucomm. CLEAR lwa_ucomm.
      
        lwa_ucomm-sign = 'I'.   lwa_ucomm-option = 'EQ'.
        lwa_ucomm-low = 'MKLO'. lwa_ucomm-high = ''.
        APPEND lwa_ucomm TO lrt_ucomm. CLEAR lwa_ucomm.
      
        IF NOT sy-ucomm IN lrt_ucomm.
      
        <Write your logic Here>
      
        ENDIF.

       

      Thanks,

      Manoj

       

  • If you want to be indepentent from regeneration, you can try event 10 with the following coding:

    form sort.
    
      data: lt_data type standard table of zdata.
    
      field-symbols: <ls_data> like line of lt_data.
    
      check sy-ucomm <> 'SAVE'.
    
      loop at total[] assigning <ls_data> casting.
        append <ls_data> to lt_data.
      endloop.
    
      sort lt_data by field.
    
      clear: total[], total.
    
      loop at lt_data into <vim_total_struc>.
        append total to total[].
      endloop.
    
    endform.

     

    Best regards,

    Christian

  • Hey, I’m a Functional Consultant so hopefully my code is not too woeful.¬† I created a cluster view using transaction SE54.¬† The records were not sorted, so I created a variation on the code above but tried to keep it generic so I can use the same module for any table to sort the underlying view by the primary index (a.k.a. key).

    *&      Module  SORT_EXTRACT_BY_KEY  OUTPUT
    *&---------------------------------------------------------------------*
    *       Sort tables by the primary index when drilling down from SM34  *
    *       view created using SE54                                        *
    *----------------------------------------------------------------------*
    MODULE sort_extract_by_key OUTPUT.
      TYPES:
        BEGIN OF lty_sortfield,
          name     TYPE fieldname,
          flg_desc TYPE char1,
        END OF lty_sortfield.
      DATA:
        lt_dd03l     TYPE STANDARD TABLE OF dd03l, "Data dictionary table fields
        ls_dd03l     LIKE LINE OF lt_dd03l,
        lt_sortfield TYPE STANDARD TABLE OF lty_sortfield, "Sort fields
        ls_sortfield LIKE LINE OF lt_sortfield,
        dref_struct  TYPE REF TO data,
        dref_table   TYPE REF TO data.
      FIELD-SYMBOLS:
        <fs_xfrom> TYPE x,              "Hexadecimal value of from value
        <fs_xto>   TYPE x,              "Hexadecimal value of to value
        <fs_struc> TYPE any,            "View being processed
        <fs_table> TYPE STANDARD TABLE. "View table
    * Do not update when creating new lines
      IF NOT sy-ucomm = 'NEWL'.
    * The view name must be available & there must be key fields
    * The field worked in my testing but may not in every scenario
        CHECK: view_name IS NOT INITIAL. 
    * Dynamically assign view to field symbol
        CREATE DATA dref_struct TYPE (view_name).
        ASSIGN dref_struct->* TO <fs_struc>.
        CREATE DATA dref_table TYPE STANDARD TABLE OF (view_name).
        ASSIGN dref_table->* TO <fs_table>.
    * Transfer hexadecimal extract to view table
        APPEND INITIAL LINE TO <fs_table> ASSIGNING <fs_struc>.
        REFRESH: <fs_table>.
        LOOP AT extract.
          APPEND INITIAL LINE TO <fs_table> ASSIGNING <fs_xto> CASTING.
          ASSIGN extract TO <fs_xfrom> CASTING.
          <fs_xto> = <fs_xfrom>.
        ENDLOOP.
    * Sort the table by the primary index
        REFRESH: lt_dd03l, lt_sortfield.
    * Firstly, get the primary index fields
        SELECT fieldname position
          FROM dd03l
          INTO CORRESPONDING FIELDS OF TABLE lt_dd03l
          WHERE tabname    = view_name
            AND keyflag    = 'X'.
    *       AND fieldname NE 'MANDT'. "No issues in testing if MANDT included
        SORT lt_dd03l BY position.
    * Build an internal table containing the fields
        LOOP AT lt_dd03l INTO ls_dd03l.
          ls_sortfield-name     = ls_dd03l-fieldname.
          ls_sortfield-flg_desc = space.
          APPEND ls_sortfield TO lt_sortfield.
        ENDLOOP.
    
    * Sort the internal table (type ANY so can't specify the fields)
        CALL FUNCTION 'C140_TABLE_DYNAMIC_SORT'
          EXPORTING
            i_flg_not_case_sensitive = 'X'
          TABLES
            i_sortfield_tab          = lt_sortfield
            x_tab                    = <fs_table>
          EXCEPTIONS
            sortfieldtab_too_big     = 1
            OTHERS                   = 2.
    * Transfer the sorted values back to the original tab in hexadecimal
        REFRESH extract[].
        LOOP AT <fs_table> ASSIGNING <fs_struc>.
          APPEND INITIAL LINE TO extract ASSIGNING <fs_xto> CASTING.
          ASSIGN <fs_struc> TO <fs_xfrom> CASTING.
          <fs_xto> = <fs_xfrom>.
        ENDLOOP.
      ENDIF.
    ENDMODULE.