Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Hotspot-clicking (Insert function) plus ALV Sorting

Former Member
0 Kudos

Hi,

I have a requirement where the ALV display has to be SORTED based on values entered/changed on a certain column. The sort works ok when used with a custom APPEND button for new records (always inserted at the bottom of the list).

However, it does not work correctly when used with the Hotspot-click (INSERT functionality). It looks like if you CLICK on a particular record onscreen, you are actually addressing the original record in that position before the SORT was effected.

Is the Hotspot-clicking (Insert functionality) possible with ALV sorting? The ideal solution would be to have the ALV sorted at PBO and also at PAI so that the user can change existing records and add new ones with the sorting being updated everytime ON_DATA_CHANGED is triggered.

Will appreciate any help on this.

Thanks!

Michael

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Uwe,

Thank you for the prompt response. Your answer was very helpful to me in understanding the concept. However, it is not the exact solution to my problem... or maybe there is no solution for it at the moment.

Please allow me to illustrate:

Sorting will be on the Percent column in DESCENDING order. There will be 2 levels of sorting. The first one is on the rows mark as Hotspots (1rst level - with the @), and the other one on the components (2nd level - without the @)

Unsorted:

Hotspot Row Number Percent

@ 01 AA01 40

02 AA02 20

03 AA03 80

@ 04 AA04 60

05 AA05 30

06 AA06 70

Sorted: (already displayed at PBO)

Hotspot Row Number Percent

@ 04 AA04 60 - 1rst level

06 AA06 70 - component of AA04

05 AA05 30 - component of AA04

@ 01 AA01 40 - 1rst level

03 AA03 80 - component of AA01

02 AA02 20 - component of AA01

Using the above example, in the SORTED alv display, I will Click on the Hotspot on the first row (that's AA04). I would expect that a NEW row will be INSERTED after AA05.

Adopting the logic of your program, the NEW row will instead be INSERTED after AA02 (at the very bottom of the list). Hence, it will form part as a component of AA01 instead of AA04.

Kind regards,

Michael

4 REPLIES 4

uwe_schieferstein
Active Contributor
0 Kudos

Hello Michael

I am not sure if my sample report ZUS_SDN_ALVGRID_HOTSPOT_SORT is the solution to your problem. However, the report shows how sorting and hotspot function can work together.

The list is sorted according to the net value of the sales order. When you click on the hotspot the selected row is copied, the net value is reduced by 500 and the new record appended to the list (i.e. should be at the end). According to the sorting, however, the new record should always be before the selected record which is indeed the case.


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_ALVGRID_HOTSPOT_SORT
*&
*&---------------------------------------------------------------------*
*& Thread: Hotspot-clicking (Insert function) plus ALV Sorting
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1159431"></a>
*&---------------------------------------------------------------------*

REPORT  zus_sdn_alvgrid_hotspot_sort.


TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE vbak.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab    TYPE STANDARD TABLE OF ty_s_outtab
                      WITH DEFAULT KEY.

DATA: gt_outtab    TYPE ty_t_outtab.

DATA:
  gd_okcode        TYPE ui_func,
  gd_repid         TYPE syrepid,
*
  gt_sort          TYPE lvc_t_sort,
  gt_fcat          TYPE lvc_t_fcat,
  gs_layout        TYPE lvc_s_layo,
  gs_variant       TYPE disvariant,
  go_docking       TYPE REF TO cl_gui_docking_container,
  go_grid          TYPE REF TO cl_gui_alv_grid.



*----------------------------------------------------------------------*
*       CLASS lcl_eventhandler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
  PUBLIC SECTION.

    CLASS-DATA:
      ms_sel_row    TYPE lvc_s_row. " selected row


    CLASS-METHODS:
      handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
        IMPORTING
          er_data_changed
          e_onf4
          e_onf4_before
          e_onf4_after
          e_ucomm
          sender,

      handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
        IMPORTING
          e_row_id
          e_column_id
          es_row_no
          sender.

ENDCLASS.                    "lcl_eventhandler DEFINITION


*----------------------------------------------------------------------*
*       CLASS lcl_eventhandler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.

  METHOD handle_data_changed.

    FIELD-SYMBOLS: <lt_outtab>  TYPE ty_t_outtab.



    BREAK-POINT.

  ENDMETHOD.                    "handle_data_changed


  METHOD handle_hotspot_click.
    " define local data
    DATA: ls_outtab    TYPE ty_s_outtab,
          ld_msg        TYPE bapi_msg.

    BREAK-POINT.
    CLEAR: lcl_eventhandler=>ms_sel_row.
    ms_sel_row = e_row_id.

    READ TABLE gt_outtab INTO ls_outtab INDEX e_row_id-index.

    CONCATENATE 'Selected Sales Order = ' ls_outtab-vbeln
      INTO ld_msg.
    MESSAGE ld_msg TYPE 'I'.

    " Trigger PAI
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'INSERT'
*      IMPORTING
*        rc       =
        .


  ENDMETHOD.                    "handle_hotspot_click

ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION



PARAMETERS:
  p_vkorg      TYPE vkorg  DEFAULT '1000'  OBLIGATORY.



START-OF-SELECTION.

  SELECT  * FROM  vbak INTO CORRESPONDING FIELDS OF TABLE gt_outtab
    UP TO 200 ROWS
         WHERE  vkorg = p_vkorg.


  PERFORM init_controls.


* Build fieldcatalog and set hotspot for field KUNNR
  PERFORM build_fieldcatalog.

  PERFORM set_layout_and_variant.
  PERFORM set_sorting.

  " Register EDIT event
  CALL METHOD go_grid->register_edit_event
    EXPORTING
      i_event_id = cl_gui_alv_grid=>mc_evt_enter
    EXCEPTIONS
      error      = 1
      OTHERS     = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  SET HANDLER:
    lcl_eventhandler=>handle_data_changed  FOR go_grid,
    lcl_eventhandler=>handle_hotspot_click FOR go_grid.




* Display data
  CALL METHOD go_grid->set_table_for_first_display
    EXPORTING
      i_bypassing_buffer            = abap_true
      is_variant                    = gs_variant
      i_save                        = 'A'
*      i_default                     = 'X'
      is_layout                     = gs_layout
*      is_print                      =
*      it_special_groups             =
*      it_toolbar_excluding          =
*      it_hyperlink                  =
*      it_alv_graphics               =
*      it_except_qinfo               =
*      ir_salv_adapter               =
    CHANGING
      it_outtab                     = gt_outtab
      it_fieldcatalog               = gt_fcat
      it_sort                       = gt_sort
*      it_filter                     =
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.






* Link the docking container to the target dynpro
  gd_repid = syst-repid.
  CALL METHOD go_docking->link
    EXPORTING
      repid                       = gd_repid
      dynnr                       = '0100'
*      CONTAINER                   =
    EXCEPTIONS
      OTHERS                      = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* ok-code field = GD_OKCODE
  CALL SCREEN '0100'.


END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS_0100'.
*  SET TITLEBAR 'xxx'.

  CALL METHOD go_grid->refresh_table_display
*        EXPORTING
*          IS_STABLE      =
*          I_SOFT_REFRESH =
    EXCEPTIONS
      finished       = 1
      OTHERS         = 2
          .
  IF sy-subrc <> 0.
*       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE gd_okcode.
    WHEN 'BACK' OR
         'EXIT'  OR
         'CANC'.
      SET SCREEN 0. LEAVE SCREEN.

    WHEN 'INSERT'.
      PERFORM insert_row.


    WHEN OTHERS.
      " Check for changed data at the frontend (= grid control)
      go_grid->check_changed_data( ).



  ENDCASE.

  CALL METHOD go_grid->refresh_table_display
*    EXPORTING
*      IS_STABLE      =
*      I_SOFT_REFRESH =
    EXCEPTIONS
      finished       = 1
      OTHERS         = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


  CLEAR: gd_okcode.

ENDMODULE.                 " USER_COMMAND_0100  INPUT


*&---------------------------------------------------------------------*
*&      Form  INIT_CONTROLS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM init_controls .

* Create docking container
  CREATE OBJECT go_docking
    EXPORTING
      parent = cl_gui_container=>screen0

      ratio  = 90
    EXCEPTIONS
      OTHERS = 6.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  CALL METHOD go_docking->set_extension
    EXPORTING
      extension  = 99999
    EXCEPTIONS
      cntl_error = 1
      OTHERS     = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.



* Create ALV grid
  CREATE OBJECT go_grid
    EXPORTING
      i_parent = go_docking
    EXCEPTIONS
      OTHERS   = 5.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " INIT_CONTROLS


*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_fieldcatalog.
* define local data
  DATA:
    ls_fcat        TYPE lvc_s_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'VBAK'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = gt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 2
      OTHERS                       = 3.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  LOOP AT gt_fcat INTO ls_fcat.
    CASE ls_fcat-fieldname.
      WHEN 'VBELN'  OR
           'ERDAT'  OR
           'ERZET'  OR
           'ERNAM'  OR
           'AUART'  OR
           'NETWR'  OR
           'WAERK'.
        CONTINUE.

      WHEN OTHERS.
        ls_fcat-no_out = abap_true.
    ENDCASE.

    MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
  ENDLOOP.


* Only non-key fields are editable
**  ls_fcat-edit = 'X'.
**  MODIFY gt_fcat FROM ls_fcat
**    TRANSPORTING edit
**    WHERE ( fieldname NE space ).
  ls_fcat-hotspot = abap_true.
  MODIFY gt_fcat FROM ls_fcat
    TRANSPORTING hotspot
    WHERE ( fieldname = 'AUART' ).


**  DELETE gt_fcat FROM 15 TO 99.


ENDFORM.                    " BUILD_FIELDCATALOG_KNB1
*&---------------------------------------------------------------------*
*&      Form  SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM set_layout_and_variant .

  CLEAR: gs_layout,
         gs_variant.

  gs_layout-cwidth_opt = abap_true.

  gs_variant-report = syst-repid.
  gs_variant-handle = 'GRID'.

ENDFORM.                    " SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
*&      Form  SET_SORTING
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM set_sorting .
* define local data
  DATA: ls_sort   TYPE lvc_s_sort.

  ls_sort-spos = 1.
  ls_sort-fieldname = 'NETWR'.
  ls_sort-up = abap_true.
  APPEND ls_sort TO gt_sort.

ENDFORM.                    " SET_SORTING
*&---------------------------------------------------------------------*
*&      Form  INSERT_ROW
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM insert_row .
* define local data
  DATA: ls_outtab   TYPE ty_s_outtab.


  READ TABLE gt_outtab INTO ls_outtab
                       INDEX lcl_eventhandler=>ms_sel_row-index.

" NOTE: Reduce amount => new entry should be before selected entry
"       due to sorting
  ls_outtab-netwr = ls_outtab-netwr - 500.

" NOTE: added at the end of the list
  append ls_outtab to gt_outtab.

" NOTE: insert new row AFTER selected row => works, too
**  INSERT ls_outtab INTO gt_outtab
**                   INDEX lcl_eventhandler=>ms_sel_row-index.


ENDFORM.                    " INSERT_ROW

Regards

Uwe

Former Member
0 Kudos

Hi Uwe,

Thank you for the prompt response. Your answer was very helpful to me in understanding the concept. However, it is not the exact solution to my problem... or maybe there is no solution for it at the moment.

Please allow me to illustrate:

Sorting will be on the Percent column in DESCENDING order. There will be 2 levels of sorting. The first one is on the rows mark as Hotspots (1rst level - with the @), and the other one on the components (2nd level - without the @)

Unsorted:

Hotspot Row Number Percent

@ 01 AA01 40

02 AA02 20

03 AA03 80

@ 04 AA04 60

05 AA05 30

06 AA06 70

Sorted: (already displayed at PBO)

Hotspot Row Number Percent

@ 04 AA04 60 - 1rst level

06 AA06 70 - component of AA04

05 AA05 30 - component of AA04

@ 01 AA01 40 - 1rst level

03 AA03 80 - component of AA01

02 AA02 20 - component of AA01

Using the above example, in the SORTED alv display, I will Click on the Hotspot on the first row (that's AA04). I would expect that a NEW row will be INSERTED after AA05.

Adopting the logic of your program, the NEW row will instead be INSERTED after AA02 (at the very bottom of the list). Hence, it will form part as a component of AA01 instead of AA04.

Kind regards,

Michael

0 Kudos

Hello Michael

Thanks for further specifying your requirements. I have created the sample variant ZUS_SDN_ALVGRID_HOTSPOT_SORT_1 which contains two differences as compared to its template:

  • Replace table VBAK with VBAP (so we have two levels of sorting: VBELN, POSNR)

  • Move SET_TABLE_FOR_FIRST_DISPLAY method call into PBO

When I click on the hotspot (VBELN) a new row entry for the order number is created. The sorting (VBELN, POSNR) is kept even though the new row has been appended to the itab.


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_ALVGRID_HOTSPOT_SORT
*&
*&---------------------------------------------------------------------*
*& Thread: Hotspot-clicking (Insert function) plus ALV Sorting
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1159431"></a>
*&---------------------------------------------------------------------*

REPORT  zus_sdn_alvgrid_hotspot_sort.


TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE vbap.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab    TYPE STANDARD TABLE OF ty_s_outtab
                      WITH DEFAULT KEY.

DATA: gt_outtab    TYPE ty_t_outtab.

DATA:
  gd_okcode        TYPE ui_func,
  gd_repid         TYPE syrepid,
*
  gt_sort          TYPE lvc_t_sort,
  gt_fcat          TYPE lvc_t_fcat,
  gs_layout        TYPE lvc_s_layo,
  gs_variant       TYPE disvariant,
  go_docking       TYPE REF TO cl_gui_docking_container,
  go_grid          TYPE REF TO cl_gui_alv_grid.



*----------------------------------------------------------------------*
*       CLASS lcl_eventhandler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
  PUBLIC SECTION.

    CLASS-DATA:
      ms_sel_row    TYPE lvc_s_row. " selected row


    CLASS-METHODS:
      handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
        IMPORTING
          er_data_changed
          e_onf4
          e_onf4_before
          e_onf4_after
          sender,

      handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
        IMPORTING
          e_row_id
          e_column_id
          es_row_no
          sender.

ENDCLASS.                    "lcl_eventhandler DEFINITION


*----------------------------------------------------------------------*
*       CLASS lcl_eventhandler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.

  METHOD handle_data_changed.

    FIELD-SYMBOLS: <lt_outtab>  TYPE ty_t_outtab.



    BREAK-POINT.

  ENDMETHOD.                    "handle_data_changed


  METHOD handle_hotspot_click.
    " define local data
    DATA: ls_outtab    TYPE ty_s_outtab,
          ld_msg        TYPE bapi_msg.

    BREAK-POINT.
    CLEAR: lcl_eventhandler=>ms_sel_row.
    ms_sel_row = e_row_id.

    READ TABLE gt_outtab INTO ls_outtab INDEX e_row_id-index.

    CONCATENATE 'Selected Sales Order = ' ls_outtab-vbeln ' / '
                                          ls_outtab-posnr
      INTO ld_msg.
      message i398(00) with ld_msg.

    " Trigger PAI
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'INSERT'
*      IMPORTING
*        rc       =
        .


  ENDMETHOD.                    "handle_hotspot_click

ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION



PARAMETERS:
  p_vkorg      TYPE vkorg  DEFAULT '0001'  OBLIGATORY.



START-OF-SELECTION.


**  SELECT  * FROM  vbak INTO CORRESPONDING FIELDS OF TABLE gt_outtab
**    UP TO 200 ROWS
**         WHERE  vkorg = p_vkorg.
  SELECT * FROM vbap INTO CORRESPONDING FIELDS OF TABLE gt_outtab
    UP TO 100 ROWS.


  PERFORM init_controls.


* Build fieldcatalog and set hotspot for field KUNNR
  PERFORM build_fieldcatalog.

  PERFORM set_layout_and_variant.
  PERFORM set_sorting.

  " Register EDIT event
  CALL METHOD go_grid->register_edit_event
    EXPORTING
      i_event_id = cl_gui_alv_grid=>mc_evt_enter
    EXCEPTIONS
      error      = 1
      OTHERS     = 2.
  IF sy-subrc NE 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  SET HANDLER:
    lcl_eventhandler=>handle_data_changed  FOR go_grid,
    lcl_eventhandler=>handle_hotspot_click FOR go_grid.





* Link the docking container to the target dynpro
  gd_repid = syst-repid.
  CALL METHOD go_docking->link
    EXPORTING
      repid                       = gd_repid
      dynnr                       = '0100'
*      CONTAINER                   =
    EXCEPTIONS
      OTHERS                      = 4.
  IF sy-subrc NE 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* ok-code field = GD_OKCODE
  CALL SCREEN '0100'.


END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS_0100'.
*  SET TITLEBAR 'xxx'.

* Display data
  CALL METHOD go_grid->set_table_for_first_display
    EXPORTING
      i_bypassing_buffer            = abap_true
      is_variant                    = gs_variant
      i_save                        = 'A'
*      i_default                     = 'X'
      is_layout                     = gs_layout
*      is_print                      =
*      it_special_groups             =
*      it_toolbar_excluding          =
*      it_hyperlink                  =
*      it_alv_graphics               =
*      it_except_qinfo               =
*      ir_salv_adapter               =
    CHANGING
      it_outtab                     = gt_outtab
      it_fieldcatalog               = gt_fcat
      it_sort                       = gt_sort
*      it_filter                     =
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4.
  IF sy-subrc NE 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

**  CALL METHOD go_grid->refresh_table_display
***        EXPORTING
***          IS_STABLE      =
***          I_SOFT_REFRESH =
**    EXCEPTIONS
**      finished       = 1
**      OTHERS         = 2.
**  IF sy-subrc ne 0.
***       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
***                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
**  ENDIF.

ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE gd_okcode.
    WHEN 'BACK' OR
         'EXIT'  OR
         'CANC'.
      SET SCREEN 0. LEAVE SCREEN.

    WHEN 'INSERT'.
      PERFORM insert_row.


    WHEN OTHERS.
      " Check for changed data at the frontend (= grid control)
      CALL METHOD go_grid->check_changed_data( ).



  ENDCASE.

  CALL METHOD go_grid->refresh_table_display
*    EXPORTING
*      IS_STABLE      =
*      I_SOFT_REFRESH =
    EXCEPTIONS
      finished       = 1
      OTHERS         = 2.
  IF sy-subrc NE 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


  CLEAR: gd_okcode.

ENDMODULE.                 " USER_COMMAND_0100  INPUT


*&---------------------------------------------------------------------*
*&      Form  INIT_CONTROLS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM init_controls .

* Create docking container
  CREATE OBJECT go_docking
    EXPORTING
      parent = cl_gui_container=>screen0

      ratio  = 90
    EXCEPTIONS
      others = 6.
  IF sy-subrc NE 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  CALL METHOD go_docking->set_extension
    EXPORTING
      extension  = 99999
    EXCEPTIONS
      cntl_error = 1
      OTHERS     = 2.
  IF sy-subrc NE 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.



* Create ALV grid
  CREATE OBJECT go_grid
    EXPORTING
      i_parent = go_docking
    EXCEPTIONS
      others   = 5.
  IF sy-subrc NE 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " INIT_CONTROLS


*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_fieldcatalog.
* define local data
  DATA:
    ls_fcat        TYPE lvc_s_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'VBAP'  " 'VBAK'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = gt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 2
      OTHERS                       = 3.
  IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

**  LOOP AT gt_fcat INTO ls_fcat.
**    CASE ls_fcat-fieldname.
**      WHEN 'VBELN'  OR
**           'ERDAT'  OR
**           'ERZET'  OR
**           'ERNAM'  OR
**           'AUART'  OR
**           'NETWR'  OR
**           'WAERK'.
**        CONTINUE.
**
**      WHEN OTHERS.
**        ls_fcat-no_out = abap_true.
**    ENDCASE.
**
**    MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
**  ENDLOOP.


* Only non-key fields are editable
**  ls_fcat-edit = 'X'.
**  MODIFY gt_fcat FROM ls_fcat
**    TRANSPORTING edit
**    WHERE ( fieldname NE space ).
  ls_fcat-hotspot = abap_true.
  MODIFY gt_fcat FROM ls_fcat
    TRANSPORTING hotspot
    WHERE ( fieldname = 'AUART'   OR
            fieldname = 'VBELN' ).


**  DELETE gt_fcat FROM 15 TO 99.


ENDFORM.                    " BUILD_FIELDCATALOG_KNB1
*&---------------------------------------------------------------------*
*&      Form  SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM set_layout_and_variant .

  CLEAR: gs_layout,
         gs_variant.

  gs_layout-cwidth_opt = abap_true.

  gs_variant-report = syst-repid.
  gs_variant-handle = 'GRID'.

ENDFORM.                    " SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
*&      Form  SET_SORTING
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM set_sorting .
* define local data
  DATA: ls_sort   TYPE lvc_s_sort.

  REFRESH: gt_sort.

  CLEAR: ls_sort.
  ls_sort-spos = 1.
  ls_sort-fieldname = 'VBELN'.
  ls_sort-up = abap_true.
  APPEND ls_sort TO gt_sort.
*
  CLEAR: ls_sort.
  ls_sort-spos = 1.
  ls_sort-fieldname = 'POSNR'.
  ls_sort-up = abap_true.
  APPEND ls_sort TO gt_sort.

ENDFORM.                    " SET_SORTING
*&---------------------------------------------------------------------*
*&      Form  INSERT_ROW
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM insert_row .
* define local data
  DATA: ls_outtab   TYPE ty_s_outtab,
        ld_order    TYPE vbeln.


  READ TABLE gt_outtab INTO ls_outtab
                       INDEX lcl_eventhandler=>ms_sel_row-index.

  ld_order = ls_outtab-vbeln.
  " Find last item of sales order
  LOOP AT gt_outtab INTO ls_outtab
                    WHERE ( vbeln = ld_order ).
  ENDLOOP.

  " Create next item:
  add 10 to ls_outtab-posnr.


  " NOTE: added at the end of the list
  APPEND ls_outtab TO gt_outtab.

  " NOTE: insert new row AFTER selected row => works, too
**  INSERT ls_outtab INTO gt_outtab
**                   INDEX lcl_eventhandler=>ms_sel_row-index.


ENDFORM.                    " INSERT_ROW

Former Member
0 Kudos

Hello Uwe,

I would consider my problem as solved since you were able to provide the proper way to handle ALV 2 level sorting with hotspot-clicking insert function. Of course I have to do a workaround (from 1 field sort to 2 fields sort) to implement that solution.

Thanks again and kind regards,

Michael