Mar 27, 2015

Creating BADI

Procedure

  1.  Start the Object Navigator (SE80).
  2.  Open an enhancement spot. For more information, see Creating, Editing, and Deleting Enhancement Spots.
  3.  Select the Enh. Spot Element Definitions tab page.
  4.  Choose Create BAdI.
A dialog box appears.
  5.  Enter a name and a short text for the BAdI.
BAdIs are in the same namespace as global data types from the ABAP Dictionary, global classes, or interfaces. For BAdIs, we recommend using the prefix “BADI_” (or “ZBADI_”, and so on, in the customer namespace).
The new BAdI appears as a node in the tree display of the tab page.
  6.  On the right-hand side of the page, do the following:
  a.  Enter the attribute for multiple use.
  b.  Enter the instance creation mode.
  c.  Enter the attribute for internal SAP BAdIs (only SAP internal use).
  d.  Optional: Enter a Fallback Class.
  e.  In the tree, expand the BAdI and choose the Interface node. Enter the name of an existing BAdI.
  7.  Optional: Choose the function Create Filter to create a filter.
Here you can:
  a.  Enter the filter name, filter type, and description.
  b.  Optional: If you choose Constant Filter Value During Call, you may only specify a constant value at the respective filter when using GET BADI. This is provided for future performance improvements of the statement.
  c.  Optional: Enter either a data element or a domain with fixed values, or a search help. Alternatively, enter a check or input help class, and a length (together with decimal places). In this way, the filter values specified at GET BADIcan be checked during the BAdI implementation.
  8.  Optional: Choose the function Create Screen Enhancement in order to create the BAdI as a screen enhancement.
The BAdI must not be of a multiple use type.
  a.  Enter Calling ProgramScreen NumberSubscreen Area, and Description.
  b.  Optional: Select Default Value to specify a screen of a program that is used if no active implementation is found at runtime.
  9.  Optional: Choose Create Function Code Enhancement to create the BAdI as a function code enhancement.
The BAdI must not have any filters and must not be of the type for multiple use.
  a.  Enter ProgramFunction Code, and Description.
  b.  Optional: Select Default Value to specify an icon, a menu text, a pushbutton text, and a quick info, all of which are used when no active implementation is found at runtime.
  10.  Optional: Create an example implementation.
  a.  Select the BAdI, and choose Create Example Class from the context menu.
  b.  Enter the name of a BAdI implementation class and a description.


ref: http://help.sap.com/saphelp_nw70/helpdata/en/32/a83942424dac04e10000000a1550b0/content.htm

Mar 16, 2015

ALV GRID Set Row and Column Position in Editing

Problem:
I have editable ALV, after edit I refresh ALV, but problem is, that position is set to position 1.1. I need to keep cursor at edited position.

Answer:
In order to refresh the ALV and keep the scroll position, read the scroll position before refresh and set the scroll position after the refresh..

The codes:

*&---------------------------------------------------------------------*
*&      Form  refresh_table_display
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM refresh_table_display .

  DATA: li_rows    TYPE lvc_s_roid,
        li_col     TYPE lvc_s_col,
        lws_row_id TYPE lvc_s_roid,
        lws_col_id TYPE lvc_s_col,
        ls_col     TYPE lvc_s_col,
        ls_num     TYPE lvc_s_roid.

* Get the latest field position
  CALL METHOD c_grid->get_current_cell
    IMPORTING
      es_col_id li_col
      es_row_no li_rows.

  CALL METHOD c_grid->get_scroll_info_via_id
    IMPORTING
      es_col_info ls_col
      es_row_no   ls_num.

* refresh ALV
  CALL METHOD c_grid->refresh_table_display
    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.

* Position back to the latest field
  CALL METHOD c_grid->set_scroll_info_via_id
    EXPORTING
      is_col_info ls_col
      is_row_no   ls_num.

  lws_row_id-row_id    li_rows-row_id.
  lws_col_id-fieldname li_col-fieldname.

  CALL METHOD c_grid->set_current_cell_via_id
    EXPORTING
      is_column_id lws_col_id
      is_row_no    lws_row_id.

ENDFORM.                    " refresh_table_display