Sebastian Wey,

Account Balance FS-CD

In the classic, text-based FS-CD account balance there is a practical context menu with the most important commands. Unfortunately, this context menu does not exist in the ALV-based account balance. In this blog post I show how this context menu can be easily retrofitted.

FS-CD account balance has been implemented by SAP in function group FKL9. Because the data objects we need access to are defined as global variables in the TOP include of this function group, we can access them using external assignments.

The solution consists of a function module that is to be called from FS-CD at event 1205 and a local class that should be stored in the same function group (or, of course, a global class).

Definition of the local class

This class registers the ALV-based account balance of transaction FPL9 for the events CONTEXT_MENU_REQUEST and USER_COMMAND and reacts to these events when they are triggered. The event CONTEXT_MENU_REQUEST is triggered when the user presses the right mouse button. In this event it is possible to create the context menu entries. When the user selects a command from the context menu, we can trigger the appropriate functionality in the event handler for USER_COMMAND.

CLASS lcl_event_listener DEFINITION.

  PUBLIC SECTION.

    CLASS-METHODS subscribe.

  PRIVATE SECTION.

    CLASS-METHODS on_context_menu_request
    FOR EVENT context_menu_request OF cl_gui_alv_grid
    IMPORTING
      e_object
      sender.

    CLASS-METHODS on_user_command
      FOR EVENT user_command OF cl_gui_alv_grid
      IMPORTING
        e_ucomm
        sender.

    CLASS-METHODS get_current_item
      IMPORTING
        value(io_alv)  TYPE REF TO cl_gui_alv_grid
      RETURNING
        value(rs_item) TYPE fkkepos.

ENDCLASS.

Register events

This method is called from the function module for event 1205 and registers itself with the ALV Grid control of the account balance for both events. Since the ALV Grid control was not created when event 1205 was first called, we do this at this point using an external perform.

METHOD subscribe.

  FIELD-SYMBOLS <o_alv> TYPE REF TO cl_gui_alv_grid.

  " Generating the ALV Grid now
  PERFORM grid_pbo_311 IN PROGRAM saplfkl9.

  " Determine reference to ALV grid
  ASSIGN ('(SAPLFKL9)GR_ALV_GRID_0311') TO <o_alv>.
  IF <o_alv> IS NOT ASSIGNED OR <o_alv> IS NOT BOUND.
    RETURN.
  ENDIF.

  " Register Event Handlers
  SET HANDLER on_context_menu_request FOR <o_alv>.
  SET HANDLER on_user_command         FOR <o_alv>.

ENDMETHOD.  

Setting Up the Context Menu

The context-dependent menu is set up in this method. An auxiliary method is used to determine the current line of the account balance. Entries are added to the context menu depending on the origin of the document and the clearing status of the item. The structure is based on the usual context menu of the classic account balance.

METHOD on_context_menu_request.

  DATA(ls_item) = get_current_item( sender ).
  IF ls_item IS INITIAL.
    RETURN. " No context menu for rows with ALV subtotals
  ENDIF.

  " Determine origin key
  SELECT SINGLE herkf FROM dfkkko WHERE opbel = @ls_item-opbel INTO @DATA(lv_source).

  "Add context menu (see FuGr FKL9, FORM on_ctmenu_request)
  e_object->add_separator( ).

  IF lv_source = '12'.
    e_object->add_function( fcode = 'INST' text = 'Installment plan'(001) ).
    e_object->add_function( fcode = 'RATP' text = 'Original items'(002) ).
  ELSE.
    e_object->add_function( fcode = 'BELG' text = 'Show position'(003) ).
    e_object->add_function( fcode = 'FPE2' text = 'Change position'(004) ).
    e_object->add_function( fcode = 'FP08' text = 'Cancel'(005) ).

    IF ls_item-augst IS NOT INITIAL.
      e_object->add_function( fcode = 'FP07' text = 'Undo clearing'(006) ).
    ENDIF.
  ENDIF.

  e_object->add_function( fcode = 'BELZ'  text = 'Payments/returns'(007) ).
  e_object->add_function( fcode = 'DUNH'  text = 'Dunning history'(008) ).
  e_object->add_function( fcode = 'ZHIS'  text = 'Interest history'(009) ).
  e_object->add_separator( ).
  e_object->add_function( fcode = 'STMM'  text = 'Business partner'(010) ).
  e_object->add_function( fcode = 'VKON'  text = 'Contract account'(011) ).
  e_object->add_function( fcode = '1201'  text = 'Contract'(012) ).
  e_object->add_separator( ).
  e_object->add_function( fcode = 'FPE2M' text = 'Mass change'(013) ).
  e_object->add_function( fcode = 'FP06'  text = 'Account maintenance'(014) ).
  e_object->add_separator( ).

  CASE lv_source.
    WHEN '05'.
      e_object->add_function( fcode = 'BAZS' text  = 'Payment lot position'(015) ).
    WHEN '06'.
      e_object->add_function( fcode = 'BAZL' text  = 'Payment run'(016) ).
    WHEN '08'.
      e_object->add_function( fcode = 'BARL' text  = 'Returns detail'(017) ).
  ENDCASE.

ENDMETHOD.   

Handling User Commands

This method is called when the user has selected a command from the context menu. We trigger the desired function by passing the OK code to function group FKL9 via external assign and performing an external perform. This simulates that the user would have called the command from the menu bar.

METHOD on_user_command.

  FIELD-SYMBOLS <v_ok_code> TYPE c.

  " Pass on user command to FPL9
  ASSIGN ('(SAPLFKL9)OK-CODE') TO <v_ok_code>.
  IF <v_ok_code> IS ASSIGNED.
    <v_ok_code> = e_ucomm.
  ENDIF.

  PERFORM ucomm_general IN PROGRAM saplfkl9.

ENDMETHOD.

Determine current item

In this auxiliary method, the current row is determined from the account balance. There are two internal tables in the function group, one with the summarized items and one with the unsummarized items. The method returns the unsummarized item, if possible, otherwise the summarized item.

METHOD get_current_item.

  TYPES t_postab TYPE TABLE OF fkkepos WITH NON-UNIQUE DEFAULT KEY .

  FIELD-SYMBOLS <t_postab>   TYPE t_postab.
  FIELD-SYMBOLS <s_item_alv> LIKE LINE OF <t_postab>.
  FIELD-SYMBOLS <s_item_db>  LIKE LINE OF <t_postab>.

  " Get current line
  io_alv->get_current_cell( IMPORTING es_row_no = DATA(ls_row_info) ).

  " First access to the table of summarized items
  ASSIGN ('(SAPLFKL9)GT_POSTAB[]') TO <t_postab>.
  IF <t_postab> IS NOT ASSIGNED.
    RETURN.
  ENDIF.

  READ TABLE <t_postab> INDEX ls_row_info-row_id ASSIGNING <s_item_alv>.
  IF sy-subrc <> 0.
    RETURN.
  ENDIF.

  " then access to the table of unsummarized items
  ASSIGN ('(SAPLFKL9)POSTAB[]') TO <t_postab>.
  IF <t_postab> IS NOT ASSIGNED.
    RETURN.
  ENDIF.

  READ TABLE <t_postab> WITH KEY orisp = <s_item_alv>-oriso ASSIGNING <s_item_db>.
  IF sy-subrc = 0.
    rs_item = <s_item_db>  " Return unsummarized items
  ELSE.
    rs_item = <s_item_alv>. " Return summarized items
  ENDIF.

ENDMETHOD.   

Include in event 1205

To include the context menu in the ALV account balance, you must finally add the following lines to the customer function module in event 1205:

IF i_first_call = abap_true AND i_fkkl1-xgrid = abap_true AND i_fkkeposc-tcode = 'FPL9' AND i_fkkeposc-varnr IS NOT INITIAL.
  lcl_event_listener=>subscribe( ).
ENDIF.

Translated with DeepL


Back to list < Debit entry with closed posting period Fire Protection Tax >