Thursday, February 14, 2013

How to Use Filters

Recalling from the previous post (How to Implement a BAdI), you need a way to select between different BAdI implementations. This is where you need the BAdI filter.
What you need is to change the BAdI definition. You can define one or many filters for a BAdI. For the purpose of this example, you create only one filter. Therefore, in this step you define the filter in the BAdI definition, determine filter values for the respective BAdI implementation, and use the filter in the instantiation of the BAdI handle.


When modifying your example you do not take into account the differentiation between the BAdI provider and the implementer. In real life it is the BAdI provider who defines a BAdI with a filter or adds a filter to an existing BAdI. It is also part of this role to use the filter condition to select the respective BAdI implementation in the ABAP code. It is the implementer who determines the filter value(s) or an interval for one or many BAdI implementations.
...
       1.      Navigate to your enhancement spot and open the Enh. Spot Element Definition tab that shows a list of all the enhancement elements of the spot.
       2.      Switch to a change mode, select your BAdI in the list, and in the small toolbar above choose Create BAdI Subobject icon and then Filter.
This graphic is explained in the accompanying text
       3.      The following dialog appears, where you fill in the corresponding fields:
This graphic is explained in the accompanying text
       4.      Confirm the entries.
The filter is now visible as a property below the BAdI.
       5.      Activate the enhancement spot, double-click on the implementation and navigate to the respective BAdI implementation by double-clicking the respective row in the table of BAdI implementations.
This graphic is explained in the accompanying text
       6.      Switch to change mode, double-click the triangle in front of the BAdI implementation in the tree and then double-click on the filter icon below.
       7.      On the Filter Values screen, choose the Create Filter Combination pushbutton.
       8.      Select Country as the filter and confirm
       9.      Double-click on the row below Combination 1.
This graphic is explained in the accompanying text
A new dialog opens:
This graphic is explained in the accompanying text

   10.      Activate the (simple) enhancement implementation and navigate back to the spot.
The other implementation, that is the one for USA, also needs the respective filter value. So you go to the respective (simple) enhancement implementation and change the BAdI implementation in the same way as you just did above. The respective filter value for this country is 'US'.
   11.      Return to your program and adapt it to the modified BAdI. Running the syntax check shows you that you need to have a filter parameter in the GET BADI command if the BAdI you try to instantiate is defined with a filter. The required addition to the GET BADI command is FILTERS. It is after this keyword that you insert the name of the BAdI filter and a value the filter is compared to. You also have to take care that an appropriate value can be passed to the GET BADI routine:
REPORT  Z_DEMO_ENH.
parameters: ctry(2) type c.
DATA: handle TYPE REF TO z_badi_calc_vat,
sum TYPE p,
vat TYPE p,
percent TYPE p.
sum = 50.
GET BADI handle FILTERS Country = ctry.
CALL BADI handle->get_vat
  EXPORTING im_amount = sum
  IMPORTING ex_amount_vat = vat
         ex_percent_vat = percent.
WRITE: 'percentage:', percent, 'VAT:' ,vat.
If you pass GB to the parameter ctry, you get a VAT rate of 17.5 percent. If the value of the parameter ctry is US, the VAT rate is 4 percent. When the parameter ctry has any other value, you still get a calculated value for the data field percent. This is because you have defined a fallback class for your BAdI. The fallback class is not only selected if no BAdI implementation is available, but also if none of the existing BAdI implementations meets the filter conditions in the GET BADI command. Accordingly, you get a VAT rate of 20 percent, which is the VAT rate you have implemented in the method get_vat in the fallback class.

How to Implement a BAdI

In the previous post (Building Your First BAdI) you defined a BAdI, provided a fallback class, instantiated the BAdI and called a BAdI method. You also provided an enhancement spot to serve as a container for the BAdI.
As you already know, the fallback class is chosen in case no BAdI implementation is available. As you have not created a BAdI implementation so far, the method implementation of the fallback class is used in your example code.
In this section you will learn how to create a BAdI implementation. As soon as there is a suitable BAdI implementation, the methods of the fallback class are not used any longer.
The entries you have so far are:
      Enhancement spot z_es_calc_tax, in which the BAdI z_badi_calc_vat lives.
      Interface z_if_calc_vat with one method get_vat().
The BAdI interface defines an important part of the BAdI identity. It defines the BAdI methods that can be used.

Create a Container for the Implementation

The definition and the implementation of BAdIs have one similarity – just as you need an enhancement spot to act as a container for the BAdI, you cannot build a BAdI implementation unless you have the relevant container first.
The relevant container type for BAdI implementations is called a (simple) enhancement implementation. A simple enhancement implementation can keep many different BAdI implementations, but with one restriction: a simple enhancement implementation is uniquely assigned to an enhancement spot. That is, a (simple) enhancement implementation can keep only BAdI implementations of BAdIs that belong to the spot the simple enhancement implementation is assigned to. Therefore, a (simple) enhancement implementation cannot keep BAdI implementations that implement BAdIs belonging to different spots.
That is why you have to create a container that is uniquely assigned to the enhancement spot to which your BAdI belongs. The respective tool in the SE80 has paved a smooth way to do this:
...
       1.      In the Object Navigator (transaction SE80), open the enhancement spot you have already created and choose the Create Enhancement Implementation pushbutton.
This graphic is explained in the accompanying text
       2.      In the new dialog that appears, create a (simple) enhancement implementation:
       3.      This graphic is explained in the accompanying text
This graphic is explained in the accompanying text
The following new window opens:
This graphic is explained in the accompanying text
What are you asked to enter here?
So far you have created a container for BAdI implementations- an enhancement implementation. This container is uniquely assigned to your enhancement spot. Once this connection is established, you can create a BAdI implementation for the BAdI within the enhancement spot. Since you have defined only one BAdI within the enhancement spot, you have no choice. If you had more BAdIs in your enhancement spot, this will be the point where you would select which BAdI you want to implement.
       4.      Enter z_bdi_calc_vat_us as the name of the BAdI implementation, confirm and save the enhancement spot in the next figure, which shows a (simple) enhancement implementation that contains the BAdI implementation z_bdi_calc_vat_us:
This graphic is explained in the accompanying text
The appearance of a (simple) enhancement implementation in the tool is pretty much like the one of an enhancement spot. Under the Enh. Implementation Elements tab there is a tree with the BAdI implementation(s) contained on the right-hand side. On the left, you see the properties of the marked BAdI implementation.


Select the property Implementation is active in the Runtime Behavior pane in the figure above. If you do this, the text below changes to Implementation is called. This is intended to help you understand what the selection you have just made is for. Further below, there is a list that shows the properties of the BAdI definition your BAdI implementation is assigned to.

The Implementing Class

Now that you have a BAdI implementation, you need an implementing class.
...
       1.      Choose the triangle in front of the name of the BAdI implementation in the tree.
       2.      In the Implementing Class field, enter z_cl_calc_vat_us and choose the Change pushbutton.
This graphic is explained in the accompanying text
The Class Builder opens. The relevant interface methods are already defined there. In your case it is only the method get_vat().
       3.      Implement the method using the following source snippet:
DATA: percent type p value 4 .
ex_amount_vat = im_amount * percent / 100 .
ex_percent_vat = percent .
       4.      Save and activate the class.
       5.      Return to the program and enter the following code:
DATA: handle TYPE REF TO z_badi_calc_vat,
sum TYPE p,
vat TYPE p,
percent TYPE p.
sum = 50.
GET BADI handle.
CALL BADI handle->get_vat
EXPORTING im_amount = sum
IMPORTING ex_amount_vat = vat
         ex_percent_vat = percent.
WRITE: 'percentage:', percent, 'VAT:', vat.
       6.      Run the program.
The result is a percentage of four percent. This is because the fallback class is not selected when there is an active BAdI implementation.

Creating a Second BAdI Implementation

...
       1.      Create another BAdI implementation, this time with the VAT rate of Great Britain.
To make your example more like real world programming, you create another enhancement implementation, that is, another container. This is because implementing the taxes for different countries most probably belongs to different projects and because the structure of the (simple) enhancement implementations must mirror the project structure.
       2.      Navigate to your enhancement spot and use the same button as you have done above. Name the BAdI implementation z_bdi_calc_vat_gb, and the implementing class Z_CL_CALC_VAT_GB. The implementation of the method get_vat is the same as for USA except for the VAT rate, which you assume to be 17.5%.
       3.      After saving and activating the enhancement implementation and the class, return to the program and run it again.
This time you get a short dump with the exception cx_badi_multiply_implemented.


You have defined a single-use BAdI by deselecting the Multiple Use option. When instantiating a single-use BAdI, you have to make sure that there is only one active non-default implementation. Otherwise, you get the respective exceptions at runtime.

Building Your First BAdI

A developer needs to calculate the VAT of different ledger entries. The entries have to be passed to a method that calculates and returns the VAT. Since the developer does not know what the VAT in a specific country is, he or she defines a BAdI with the method get_vat. This method must return the VAT for a particular value that is passed to the method get_vat.

Creating an Enhancement Spot

The first thing you need when creating a BAdI is a container for the BAdI. For that purpose, you need to create a (simple) enhancement spot. This is the container in which you develop your BAdI.
...
       1.      In the Object Navigator (transaction SE80), navigate to the package in which you want to create the enhancement spot.
       2.      In the context menu of the package, choose Create ® Enhancement ® Enhancement Spot.
The following dialog appears:
This graphic is explained in the accompanying text
       3.      Enter a name and a short text description for the enhancement spot.

Creating a BAdI

...
       1.      To create a BAdI within the new enhancement spot, choose the Create BAdI pushbutton on the left, as shown in the figure below:
This graphic is explained in the accompanying text

       2.      In the dialog window that appears, enter the BAdI name z_badi_calc_vat and a short description.
You now have a BAdI in your enhancement spot.
       3.      Deselect the Multiple Use option because for the current calculation you need a single-use BAdI:

The BAdI Interface

Up to now, you still do not have a BAdI. You need an interface where you can define the methods which determine what you can do with your BAdI.
...
       1.      Choose the arrow in front of the BAdI name.
       2.      Double-click on the Interface icon.
Enter a name for the interface. You can choose an existing name or create a new one.
This graphic is explained in the accompanying text
       3.      Choose the Change pushbutton.

This leads you to the Class Builder where you can create the methods you need for your BAdI. You simply need to type in the name of the method get_vat and enter the parameters you need.
A BAdI interface has to implement the interface if_badi_interface. But if you create a BAdI interface in the way shown above, this marker interface is already integrated in the BAdI interface.
This graphic is explained in the accompanying text
       4.      Determine the parameters of the method:
This graphic is explained in the accompanying text
       5.      Save and activate the interface and the spot.
By completing the steps above, you have created an enhancement spot and a BAdI with an interface. The interface has one method so far.
However, just building a BAdI is not enough as it does not do anything. You need a BAdI instance and this instance must be called somewhere in the code. Since the BAdI only defines an interface, you need a class that implements this interface.


A BAdI definition is the place to insert an object plug-in that does something at runtime. You still need an object that is plugged in to get something done.

Writing the Source Code

Now you need to write some ABAP code to use the BAdI. You need a variable that can refer to the BAdI and some variables that are given as actual parameters to the BAdI method.
Next, you need to create a handle for that BAdI and call the BAdI method get_vat. The respective commands are GET BADI and CALL BADI.
DATA: handle TYPE REF TO z_badi_calc_vat,
sum TYPE p,
vat TYPE p,
percent TYPE p.
sum = 50.
GET BADI handle.
CALL BADI handle->get_vat
EXPORTING im_amount = sum
IMPORTING ex_amount_vat = vat
         ex_percent_vat = percent.
WRITE: 'percentage:', percent, 'VAT:', vat.

A Fallback Class

If you run the program at this stage, it dumps. This is because it is mandatory to have exactly one active implementation for a single-use BAdI. You can handle this error by catching the respective exception cx_badi_not_implemented.
The better solution is to use a fallback class. This class is used if there is no active BAdI implementation.
The GET BADI command returns a handle to an instance of the fallback class and the respective CALL BADI calls the methods of the fallback class instance. As soon as there is an active BAdI implementation, the fallback class is no longer used at runtime.
Using a fallback class serves two functions at once:
      The program runs with a single-use BAdI without throwing an exception.
      It is guaranteed that the fallback class is not used any more as soon as a BAdI implementation is supplied. The fallback class is selected conditionally. This is important because in most cases the BAdI provider does not know the details of some process. This is why a BAdI is used.
To add a fallback class, proceed as follows:
...
       1.      Select the Call fallback class if no implementation is executed option and enter a name for the class:
This graphic is explained in the accompanying text
       2.      Choose Change to go back to the Class Builder.
The respective method of the BAdI interface is already automatically defined. You only have to implement it:
DATA: percent TYPE p VALUE 20.
ex_amount_vat = im_amount * percent / 100.
ex_percent_vat = percent.
       3.      Save and activate the class.
       4.      Navigate back to the enhancement spot and activate it.
       5.      Run the program.
The result should be:
percentage: 20 VAT: 10.

EXPORT / IMPORT FROM DATABASE/SHARED BUFFER

Import / Export from Database 
TYPES:
  BEGIN OF tab_type,
    col1 TYPE i,
    col2 TYPE i,
  END OF tab_type.

DATA:
  wa_indx TYPE demo_indx_table,
  wa_itab TYPE tab_type,
  itab  TYPE STANDARD TABLE OF tab_type.

WHILE sy-index 100.
  wa_itab-col1 sy-index.
  wa_itab-col2 sy-index ** 2.
  APPEND wa_itab TO itab.
ENDWHILE.

wa_indx-timestamp sy-datum && sy-uzeit.
wa_indx-userid    sy-uname.

EXPORT tab itab
  TO DATABASE demo_indx_table(SQ)
  FROM wa_indx
  ID 'TABLE'.

TYPES:
  BEGIN OF tab,
    col1 TYPE i,
    col2 TYPE i,
  END OF tab.

DATA:
  wa_indx TYPE demo_indx_table,
  wa_itab TYPE tab,
  itab    TYPE STANDARD TABLE OF tab.

IMPORT tab itab
  FROM DATABASE demo_indx_table(SQ)
  TO   wa_indx
  ID 'TABLE'.

WRITEwa_indx-timestampwa_indx-userid.
ULINE.
LOOP AT itab INTO wa_itab.
  WRITE/ wa_itab-col1wa_itab-col2.
ENDLOOP.

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 Import / Export from Shared Buffer

TABLES INDX.
DATAINDXKEY LIKE INDX-SRTFD VALUE 'KEYVALUE',
      F1(4)F2 TYPE P,
      BEGIN OF ITAB3 OCCURS 2,
        CONT(4),
      END OF ITAB3.
* Before export, fill the data fields
* before CLUSTR.
INDX-AEDAT SY-DATUM.
INDX-USERA SY-UNAME.
* Export data.
EXPORT F1 F2 ITAB3 TO
       SHARED BUFFER INDX(STID INDXKEY.

TABLES INDX.
DATAINDXKEY LIKE INDX-SRTFD VALUE 'KEYVALUE',
      F1(4)F2 TYPE P,
      BEGIN OF ITAB3 OCCURS 2,
        CONT(4),
      END OF ITAB3.
* Import data.
IMPORT F1 F2 ITAB3 FROM
       SHARED BUFFER INDX(STID INDXKEY.

Editable ALV through OOPS

TABLESmara.
DATABEGIN OF it_tab OCCURS 0,
      matnr LIKE mara-matnr,
      ersda LIKE mara-ersda,  "creation date
      ernam LIKE mara-ernam,  "person created
      pstat LIKE mara-pstat,  "maint stat
      lvorm LIKE mara-lvorm,  "flg for deletion
      mtart LIKE mara-mtart,  "mat type
      meins LIKE mara-meins,  "uom
      END OF it_tab.
DATAwa_it_tab LIKE LINE OF it_tab.  "making work area
DATAi_modified TYPE STANDARD TABLE OF mara,"For getting modified rows
      w_modified TYPE mara.
CLASS lcl_events_d0100 DEFINITION DEFERRED.
DATAevent_receiver1  TYPE REF TO lcl_events_d0100,
      i_selected_rows TYPE lvc_t_row,                "Selected Rows
      w_selected_rows TYPE lvc_s_row.

*---------------------------------------------------------------------*
*       CLASS lcl_events_d0100 DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_events_d0100 DEFINITION.
  PUBLIC SECTION.
    METHODS
        handle_hotspot_click
        FOR EVENT hotspot_click OF cl_gui_alv_grid
        IMPORTING
             e_row_id
             e_column_id
             es_row_no
             sender.
*---code addition for ALV pushbuttons
*--for placing buttons
    METHODS handle_toolbar_set
        FOR EVENT toolbar OF cl_gui_alv_grid
        IMPORTING
              e_object
              e_interactive.
*---user command on clicking a button
    METHODS handle_user_command
        FOR EVENT user_command OF cl_gui_alv_grid
        IMPORTING
             e_ucomm.
ENDCLASS.                    "lcl_events_d0100 DEFINITION

TYPE-POOLS cndp.
DATA ok_code TYPE sy-ucomm.


*----------------------------------------------------------------------*
*                       FOR VARIANT
*----------------------------------------------------------------------*
DATA st_var TYPE disvariant .
DATA save TYPE c.
st_var-report 'YKC_ALV_OOPS'.
save 'A'.

*----------------------------------------------------------------------*
*         FOR LAYOUT
*----------------------------------------------------------------------*
DATA loyo TYPE lvc_s_layo.
loyo-zebra 'X'.
loyo-detailinit 'X'.
loyo-info_fname 'RED'.

*----------------------------------------------------------------------*
*           FOR FIELD CATALOG
*----------------------------------------------------------------------*
DATA fcat TYPE lvc_t_fcat.
DATA wa_fcat LIKE LINE OF fcat.
*--Declaration for toolbar buttons
DATA ty_toolbar      TYPE stb_button.
DATA e_object        TYPE REF TO cl_alv_event_toolbar_set,
       io_alv_toolbar  TYPE REF TO cl_alv_event_toolbar_set.
*---custom container
DATA container TYPE REF TO cl_gui_custom_container.
DATA ref_grid TYPE REF TO cl_gui_alv_grid.
CREATE OBJECT container
  EXPORTING
    container_name 'CONTAINER'."name of container in module pool
CREATE OBJECT ref_grid
  EXPORTING
    i_parent container.

*---------------------------------------------------------------------*
*       CLASS lcl_events_d0100 IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_events_d0100 IMPLEMENTATION.
*---method for hotspot
  METHOD handle_hotspot_click.
    DATA:ls_col_id   TYPE lvc_s_col.
    READ TABLE it_tab INTO wa_it_tab
                             INDEX e_row_id-index.
    IF sy-subrc 0.
      CHECK wa_it_tab-matnr IS NOT INITIAL ).
      CASE e_column_id-fieldname.
        WHEN 'MATNR'.
          LEAVE PROGRAM.
*---put your own logic as per requirement on hotspot click
        WHEN OTHERS.
*       do nothing
      ENDCASE.
      CALL METHOD ref_grid->set_current_cell_via_id
        EXPORTING
          is_row_id    e_row_id
          is_column_id ls_col_id.
    ENDIF.
  ENDMETHOD.                    "handle_hotspot_click
**---method for handling toolbar
  METHOD handle_toolbar_set.
    CLEAR ty_toolbar.
    ty_toolbar-function 'EDIT'"name of btn to  catch click
    ty_toolbar-butn_type 0.
    ty_toolbar-text 'EDIT'.
    APPEND ty_toolbar    TO e_object->mt_toolbar.
  ENDMETHOD.                    "handle_toolbar_set
  METHOD handle_user_command.
    DATAwr_data_changed TYPE REF TO cl_alv_changed_data_protocol.
    DATAlt_rows TYPE lvc_t_row,
          lt_index TYPE  lvc_s_row-index.
    CASE e_ucomm.
      WHEN 'EDIT'.
        PERFORM save_database.
        CALL METHOD ref_grid->refresh_table_display.
    ENDCASE.
  ENDMETHOD.                    "handle_user_command
ENDCLASS.                    "lcl_events_d0100 IMPLEMENTATION

START-OF-SELECTION.
  PERFORM get_data.
  PERFORM field_catalog.

*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text : getting data into internal table
*----------------------------------------------------------------------*
FORM get_data .
  SELECT matnr ersda ernam pstat lvorm mtart meins
         INTO TABLE it_tab
         FROM mara
         WHERE matnr GE '000000000000000001'.
ENDFORM.                    " get_data

*&---------------------------------------------------------------------*
*&      Form  field_catalog
*&---------------------------------------------------------------------*
*       text  :setting field cat
*----------------------------------------------------------------------*
FORM field_catalog .
  REFRESH fcat.
  DATAlv_pos TYPE i.
  lv_pos lv_pos + 1.
  wa_fcat-fieldname 'MATNR'.
  wa_fcat-coltext 'Material No'.
  wa_fcat-col_pos lv_pos.
  wa_fcat-hotspot 'X'.
  wa_fcat-outputlen 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos lv_pos + 1.
  wa_fcat-fieldname 'ERSDA'.
  wa_fcat-coltext 'Creation Date'.
  wa_fcat-col_pos lv_pos.
  wa_fcat-edit 'X'.
  wa_fcat-outputlen 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos lv_pos + 1.
  wa_fcat-fieldname 'ERNAM'.
  wa_fcat-coltext 'Person Created'.
  wa_fcat-col_pos lv_pos.
  wa_fcat-outputlen 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos lv_pos + 1.
  wa_fcat-fieldname 'PSTAT'.
  wa_fcat-coltext 'Maint Stat'.
  wa_fcat-col_pos lv_pos.
  wa_fcat-outputlen 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos lv_pos + 1.
  wa_fcat-fieldname 'LVORM'.
  wa_fcat-coltext 'Flag For Deletion'.
  wa_fcat-col_pos lv_pos.
  wa_fcat-outputlen 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos lv_pos + 1.
  wa_fcat-fieldname 'MTART'.
  wa_fcat-coltext 'Material Type'.
  wa_fcat-col_pos lv_pos.
  wa_fcat-outputlen 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos lv_pos + 1.
  wa_fcat-fieldname 'MEINS'.
  wa_fcat-coltext 'UOM'.
  wa_fcat-col_pos lv_pos.
  wa_fcat-outputlen 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  CREATE OBJECT event_receiver1.
*---setting event handlers
  SET HANDLER event_receiver1->handle_toolbar_set   FOR ref_grid.
  SET HANDLER event_receiver1->handle_user_command  FOR ref_grid.
  SET HANDLER event_receiver1->handle_hotspot_click FOR ref_grid.

*----------------------------------------------------------------------*
*           ALV GRID DISPLAY
*----------------------------------------------------------------------*
  CALL METHOD ref_grid->set_table_for_first_display
    EXPORTING
      is_variant      st_var
      i_save          save
      is_layout       loyo
    CHANGING
      it_outtab       it_tab[]
      it_fieldcatalog fcat.
  CALL SCREEN 100.
ENDFORM.                    " field_catalog

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
*  CREATE OBJECT gr_events_d0100.
*
*  SET HANDLER gr_events_d0100->double_click
*
*                 FOR ref_grid.
  CALL METHOD ref_grid->register_edit_event
    EXPORTING
      i_event_id cl_gui_alv_grid=>mc_evt_modified.
  SET PF-STATUS 'S100'.
  SET TITLEBAR 'XXX'.
ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  exit  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE exit INPUT.
  CASE ok_code.
    WHEN 'EXI' .
      CLEAR ok_code.
      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.                 " exit  INPUT

*&---------------------------------------------------------------------*
*&      Form  SAVE_DATABASE
*&---------------------------------------------------------------------*
*       text : saving into DDIC from internal table
*----------------------------------------------------------------------*
*  -->  p1        text
*  <-- nbsp="" p2="" span="" text="">
*----------------------------------------------------------------------*
FORM save_database .
*--- Getting the selected rows index
  CALL METHOD ref_grid->get_selected_rows
    IMPORTING
      et_index_rows i_selected_rows.
*--- Through the index capturing the values of selected rows
  LOOP AT i_selected_rows INTO w_selected_rows.
    READ TABLE it_tab INTO wa_it_tab INDEX w_selected_rows-index.
    IF sy-subrc EQ 0.
      MOVE-CORRESPONDING wa_it_tab TO w_modified.
      APPEND w_modified TO i_modified.
    ENDIF.
  ENDLOOP.
  MODIFY mara FROM TABLE i_modified.
ENDFORM.                    " SAVE_DATABASE