Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
Below are the steps to be followed if you want to provide sorting in the table maintenance generator.

  • Please go through the below blog to add a new custom button in TMG screen


https://blogs.sap.com/2014/11/11/how-to-create-custom-button-in-tmg/

  • Then create one custom FM with following logic that will popup the dialog box for the user to select the columns of table control in SM30.



  • This FM should have view name of type DD02L-TABNAME as importing parameter and exporting parameter of type ABAP_SORTORDER_TAB  that contains the field names to be sorted.



  • Define one global internal table of type DFIES to retrieve the structure of the table and then use the same in the custom screen



  • Inside this FM use FM 'VIEW_GET_FIELDTAB' to get the list of the columns of table currently edited/viewed in SM30.



  • Then create one custom screen of type dialog inside this FM.



  • Create one table control using wizard with multiple selection on the screen that displays the column names for the user to select. Also add two radio buttons for ascending or descending as shown below.




  • Below is the code written inside the custom FM


 FUNCTION zca_common_tmg_sort.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_VAR_VIEW_NAME) TYPE DD02L-TABNAME
*" EXPORTING
*" VALUE(E_TAB_SORTORDER) TYPE ABAP_SORTORDER_TAB
*"----------------------------------------------------------------------

CALL FUNCTION 'VIEW_GET_FIELDTAB'
EXPORTING
view_name = i_var_view_name
TABLES
fieldtab = g_tab_fields
EXCEPTIONS
table_not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
DELETE g_tab_fields WHERE datatype = 'CLNT'.
CALL SCREEN 9000 STARTING AT 5 3.
ENDIF.

e_tab_sortorder = g_tab_sortorder.


  • Below is the code written inside the PAI module of custom screen.
    MODULE user_command_9000 INPUT.

    FIELD-SYMBOLS: <l_wa_sortorder> LIKE LINE OF g_tab_sortorder.

    CLEAR g_tab_sortorder[].

    CASE sy-ucomm.

    WHEN 'OK'.

    LOOP AT g_tab_fields INTO g_wa_fields
    WHERE inttype = 'X'.

    APPEND INITIAL LINE TO g_tab_sortorder ASSIGNING <l_wa_sortorder>.

    <l_wa_sortorder>-name = g_wa_fields-fieldname.

    IF g_var_descend IS NOT INITIAL.
    <l_wa_sortorder>-descending = abap_true.
    ENDIF.

    CLEAR g_wa_fields.

    ENDLOOP.
    SET SCREEN 0.

    WHEN 'CAN'.
    SET SCREEN 0.

    ENDCASE.

    ENDMODULE. " USER_COMMAND_9000 INPUT

     

  • After creating the above FM and custom screen, we need to go back to table maintenance generator of respective table and go to Environment->Modification->Maintenance Screens and double on the screen.

  • Then create one PAI module in the screen layout and call the custom FM in this module.



  • Note: Only this PAI module statement(Module sort In process after input) in screen layout needs to be re-written once we regenerate the maintenance screen again. Rest everything remains intact on regeneration.



  • Below is the code to be written in the module


MODULE sort INPUT.

DATA: l_tab_agent TYPE STANDARD TABLE OF zsdc_frght_agent,
l_tab_sortorder TYPE abap_sortorder_tab..

FIELD-SYMBOLS: <ls_xfrom> TYPE x, "Hexadecimal value of from value
<ls_xto> TYPE x. "Hexadecimal value of to value

CLEAR: l_tab_agent[], l_tab_sortorder[].

CASE function.

WHEN 'SORT'.

CALL FUNCTION 'ZCA_COMMON_TMG_SORT'
EXPORTING
i_var_view_name = vim_view_name
IMPORTING
e_tab_sortorder = l_tab_sortorder.

IF l_tab_sortorder[] IS NOT INITIAL.

LOOP AT extract.

APPEND INITIAL LINE TO l_tab_agent ASSIGNING <ls_xto> CASTING.
ASSIGN extract TO <ls_xfrom> CASTING.

<ls_xto> = <ls_xfrom>.

ENDLOOP.

SORT l_tab_agent BY (l_tab_sortorder).

REFRESH extract.
LOOP AT l_tab_agent INTO zsdc_frght_agent.

APPEND INITIAL LINE TO extract ASSIGNING <ls_xto> CASTING.
ASSIGN zsdc_frght_agent TO <ls_xfrom> CASTING.

<ls_xto> = <ls_xfrom>.

ENDLOOP.

ENDIF.

ENDCASE.

ENDMODULE. " SORT INPUT

After successful activation of all the above codes, you will be able to see below output in SM30.






1 Comment
Labels in this area