Skip to Content

OO ALV with check boxes, icon and popup message to modify the output at runtime.

In this post we will create an OO alv which is having the check boxes and icons, when the user checks the check box and executes it, then we will get a pop confirmation. Afterwards the the adjacent field value of the checked box will be modified at the runtime.

*********************************************************************************************************************

TYPE-POOLS cntl.

DATA: ok_code LIKE sy-ucomm,
            g_repid LIKE sy-repid,
            g_max TYPE i VALUE 50,
            gs_layout   TYPE lvc_s_layo,
            gt_fcat TYPE lvc_t_fcat,
            gs_fcat TYPE lvc_s_fcat,
            gt_events TYPE cntl_simple_events,
            custom_container TYPE REF TO cl_gui_custom_container,
             grid1  TYPE REF TO cl_gui_alv_grid.


DATA: ls_edit TYPE lvc_s_styl,
            lt_edit TYPE lvc_t_styl.

TYPES:    BEGIN OF ty_outtab,
                  carrid TYPE sflight-carrid,
                  connid TYPE sflight-connid,
                  fldate TYPE sflight-fldate,
                  price TYPE sflight-price,
                  light TYPE c,
                  checkbox TYPE c,
                  style TYPE lvc_t_styl,
                  END OF ty_outtab.


TYPES:    BEGIN OF ty_outtab1,
                  carrid TYPE sflight-carrid,
                  connid TYPE sflight-connid,
                  fldate TYPE sflight-fldate,
                  price TYPE sflight-price,
                  END OF ty_outtab1.

DATA: gt_outtab TYPE STANDARD TABLE OF ty_outtab,
            wa_outtab TYPE ty_outtab,
            gt_sflight TYPE STANDARD TABLE OF ty_outtab1,
            gs_sflight TYPE ty_outtab1,
            gt_sflight1 TYPE STANDARD TABLE OF ty_outtab,
            gs_sflight1 TYPE ty_outtab.

DATA: ls_outtab LIKE LINE OF gt_sflight1.

*———————————————————————-*
*       CLASS LCL_WRAPPER DEFINITION
*———————————————————————-*
*
*———————————————————————-*
CLASS lcl_wrapper DEFINITION.

   PUBLIC SECTION.

     METHODS : update_table1 FOR EVENT data_changed OF cl_gui_alv_grid
                           IMPORTING er_data_changed
                                     e_onf4
                                     e_onf4_before
                                     e_onf4_after.           “#EC CALLED

ENDCLASS.                    “LCL_WRAPPER DEFINITION

*———————————————————————-*
*       CLASS LCL_WRAPPER IMPLEMENTATION
*———————————————————————-*
*
*———————————————————————-*
CLASS lcl_wrapper IMPLEMENTATION.

   METHOD update_table1.

     DATA : lv_count TYPE i.
     DATA : lv_value TYPE char1.
     DATA : lv_index TYPE sy-index.
     DATA: ans TYPE char1.

     DESCRIBE TABLE gt_sflight1 LINES lv_count.

     DO lv_count TIMES.
       CLEAR lv_value.
       lv_index = sy-index.

       CALL METHOD er_data_changed->get_cell_value
                       EXPORTING
*                                       I_ROW_ID    = lv_count
                         i_tabix     = lv_index
                         i_fieldname = ‘CHECKBOX’
                       IMPORTING
                         e_value     = lv_value.

       IF lv_value = ‘X’ .

         READ TABLE gt_sflight1 INTO gs_sflight1 INDEX lv_index.
         wa_outtab-carrid =  gs_sflight1-carrid .
         wa_outtab-checkbox‘X’ .
         APPEND wa_outtab TO gt_outtab.

         CALL METHOD grid1->get_frontend_fieldcatalog
           IMPORTING
             et_fieldcatalog = gt_fcat[].


         LOOP AT gt_fcat INTO gs_fcat .

           IF gs_fcat-fieldname = ‘CHECKBOX’ .

           gs_fcat-checkbox = ‘X’.
              gs_fcat-edit = .

          ENDIF .

          MODIFY gt_fcat FROM gs_fcat .


         ENDLOOP .


CALL METHOD grid1->set_frontend_fieldcatalog
           EXPORTING
             it_fieldcatalog = gt_fcat[].

         CALL METHOD grid1->set_table_for_first_display
             EXPORTING
*           i_structure_name = ‘SFLIGHT’
                       is_layout        = gs_layout
             CHANGING  it_outtab        = gt_sflight1[]
                       it_fieldcatalog = gt_fcat .

         CALL METHOD er_data_changed->modify_cell
           EXPORTING
*            I_ROW_ID    = lv_count
             i_tabix     = lv_index
             i_fieldname = ‘CONNID’
             i_value     = ‘00001’.
       ENDIF.

     ENDDO.
     DO lv_count TIMES.
       CLEAR lv_value.

       lv_index = sy-index.

       CALL METHOD er_data_changed->get_cell_value
                       EXPORTING
*                                       I_ROW_ID    = lv_count
                         i_tabix     = lv_index
                         i_fieldname = ‘CHECKBOX’
                       IMPORTING
                         e_value     = lv_value.
       CALL METHOD er_data_changed->modify_cell
           EXPORTING
*            I_ROW_ID    = lv_count
             i_tabix     = lv_index
             i_fieldname = ‘CHECKBOX’
             i_value     = .

     ENDDO.

   ENDMETHOD.                    “UPDATE_TABLE1

ENDCLASS.                    “LCL_WRAPPER IMPLEMENTATION

DATA: g_lights_name TYPE lvc_cifnm VALUE ‘LIGHT’.
DATA : lo_wrapper TYPE REF TO lcl_wrapper.

START-OF-SELECTION.

   CALL SCREEN 100.

*———————————————————————*
*       FORM EXIT_PROGRAM                                             *
*———————————————————————*
FORM exit_program.
   CALL METHOD grid1->free.
   CALL METHOD cl_gui_cfw=>flush.
   IF sy-subrc NE 0.
* add your handling, for example
     CALL FUNCTION ‘POPUP_TO_INFORM’
       EXPORTING
         titel = g_repid
         txt2  = sy-subrc
         txt1  = ‘Error in FLush’(500).
   ENDIF.
   LEAVE PROGRAM.
ENDFORM.                    “exit_program
*&———————————————————————*
*&      Module  PBO_100  OUTPUT
*&———————————————————————*
*       text
*———————————————————————-*
MODULE pbo_100 OUTPUT.

   DATA : lw_event TYPE cntl_simple_event.

   SET PF-STATUS ‘MAIN100’.
   SET TITLEBAR ‘MAIN100’.
   g_repid = sy-repid.
   IF custom_container IS INITIAL.

     SELECT carrid
             connid
             fldate
              price
         FROM sflight INTO TABLE gt_sflight UP TO g_max ROWS.
     LOOP AT gt_sflight INTO gs_sflight.
       gs_sflight1-carrid = gs_sflight-carrid .
       gs_sflight1-connid = gs_sflight-connid .
       gs_sflight1-fldate = gs_sflight-fldate  .
       gs_sflight1-price = gs_sflight-price .
       APPEND gs_sflight1 TO gt_sflight1.
       CLEAR gs_sflight1.
     ENDLOOP.

     LOOP AT gt_sflight1 INTO gs_sflight1.
       IF gs_sflight1-carrid = ‘AA’.
         gs_sflight1-light = ‘1’.
       ELSEIF gs_sflight1-carrid = ‘AZ’.
         gs_sflight1-light = ‘3’.
       ELSE.
         gs_sflight1-light = ‘2’.
       ENDIF.
       MODIFY gt_sflight1 INDEX sy-tabix FROM gs_sflight1.
     ENDLOOP.

     PERFORM build_data .

     CREATE OBJECT custom_container
       EXPORTING
         container_name              = ‘OO_ALV’
       EXCEPTIONS
         cntl_error                  = 1
         cntl_system_error           = 2
         create_error                = 3
         lifetime_error              = 4
         lifetime_dynpro_dynpro_link = 5.
     IF sy-subrc NE 0.

* add your handling, for example
       CALL FUNCTION ‘POPUP_TO_INFORM’
         EXPORTING
           titel = g_repid
           txt2  = sy-subrc
           txt1  = ‘The control could not be created’(510).
     ENDIF.
* create an instance of alv control
     CREATE OBJECT grid1
       EXPORTING
         i_parent = custom_container.

*……………………………………….
* set some layout-values (Structure LVC_S_LAYO)
*……………………………………….

     LOOP AT gt_sflight1 INTO gs_sflight1.
       IF gs_sflight1-carrid = ‘AA’.
         ls_edit-style = cl_gui_alv_grid=>mc_style_enabled.
       ELSEIF gs_sflight1-carrid = ‘AZ’.
         ls_edit-style = cl_gui_alv_grid=>mc_style_disabled.
       ENDIF.
       ls_edit-fieldname = ‘CHECKBOX’.
       INSERT ls_edit INTO TABLE lt_edit.
       INSERT LINES OF lt_edit INTO TABLE ls_outtab-style.
       MODIFY gt_sflight1 INDEX sy-tabix
                               FROM ls_outtab TRANSPORTING style .

       CLEAR ls_outtab.
       REFRESH lt_edit.
       CLEAR ls_edit.
     ENDLOOP.
     gs_layout-grid_title = ‘Flights’(100).
     gs_layout-excp_fname = g_lights_name.
     gs_layout-no_rowmark = ‘X’.
     gs_layout-stylefname = ‘STYLE’.

     CALL METHOD grid1->get_registered_events
       IMPORTING
         events     = gt_events
       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.

     lw_event-eventid = 11.
     lw_event-appl_event = ‘UPDATE_TABLE1’.

     APPEND lw_event TO gt_events.

     CALL METHOD grid1->set_registered_events
       EXPORTING
         events                    = gt_events
       EXCEPTIONS
         cntl_error                = 1
         cntl_system_error         = 2
         illegal_event_combination = 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.

     CALL METHOD grid1->set_table_for_first_display
          EXPORTING
*           i_structure_name = ‘SFLIGHT’
                    is_layout        = gs_layout
          CHANGING  it_outtab        = gt_sflight1[]
                    it_fieldcatalog = gt_fcat .

     CREATE OBJECT lo_wrapper.

     SET HANDLER lo_wrapper->update_table1 FOR ALL INSTANCES.

   ENDIF.
   CALL METHOD cl_gui_control=>set_focus
     EXPORTING
       control = grid1.

* Control Framework flushes at the end of PBO automatically!
ENDMODULE.                             ” PBO_100  OUTPUT
*&———————————————————————*
*&      Module  PAI_100  INPUT
*&———————————————————————*
*       text
*———————————————————————-*
MODULE pai_100 INPUT.

   CASE ok_code.
     WHEN ‘BACK’.
       PERFORM exit_program.
     WHEN ‘EXIT’.
       PERFORM exit_program.
     WHEN ‘SWITCH’.
*      data: upcl1 TYPE REF TO UPDATE_TABLE1.
       DATA: ans TYPE char1.
CALL FUNCTION ‘POPUP_FOR_INTERACTION’
         EXPORTING
           headline             = ‘POPUP’
           text1                = ‘lets do it’
*         TEXT2                = ‘ ‘
*         TEXT3                = ‘ ‘
*         TEXT4                = ‘ ‘
*         TEXT5                = ‘ ‘
*         TEXT6                = ‘ ‘
*         TICON                = ‘I’
           button_1             = ‘yes’
          button_2             = ‘No’
*         BUTTON_3             = ‘ ‘
        IMPORTING
          button_pressed       = ans
                 .

       IF ans = ‘1’.
         CALL METHOD grid1->check_changed_data
*          IMPORTING
*            E_VALID   = CHANGING
*            C_REFRESH = ‘X’
                     .

       ENDIF.

*      PERFORM SWITCH_LED_STYLE.

       CLEAR ok_code.
*  p_selfield-refresh = ‘X’.
   ENDCASE.
ENDMODULE.                             ” PAI_100  INPUT
*&———————————————————————*
*&      Form  SELECT_TABLE_SFLIGHT
*&———————————————————————*
*       text
*———————————————————————-*
*      <–P_GT_SFLIGHT  text
*———————————————————————-*
*form build_data tables p_gt_outtab structure gt_outtab.
FORM build_data.

   gs_fcat-fieldname = ‘CHECKBOX’.
   gs_fcat-coltext = ‘Select Form’.
   gs_fcat-col_pos = ‘2’.
   gs_fcat-tabname = ‘GT_SFLIGHT1’.
*  gs_fcat-input     = ‘0’.
   gs_fcat-edit     = ‘X’.
   gs_fcat-checkbox     = ‘X’.
   gs_fcat-outputlen = ’11’.
   APPEND gs_fcat TO gt_fcat.
   CLEAR gs_fcat.

   gs_fcat-fieldname = ‘LIGHT’.
   gs_fcat-coltext = ‘LIGHT’.
   gs_fcat-col_pos = ‘1’.
   gs_fcat-tabname = ‘GT_SFLIGHT1’.
   APPEND gs_fcat TO gt_fcat.
   CLEAR gs_fcat.
   gs_fcat-fieldname = ‘CARRID’.
   gs_fcat-coltext = ‘PLANE’.
   gs_fcat-col_pos = ‘3’.
   gs_fcat-tabname = ‘GT_SFLIGHT1’.
   APPEND gs_fcat TO gt_fcat.
   CLEAR gs_fcat.
   gs_fcat-fieldname = ‘CONNID’.
   gs_fcat-coltext = ‘PLANE AGA’.
   gs_fcat-col_pos = ‘4’.
   gs_fcat-tabname = ‘GT_SFLIGHT1’.
   APPEND gs_fcat TO gt_fcat.
   CLEAR gs_fcat.
   gs_fcat-fieldname = ‘FLDATE’.
   gs_fcat-coltext = ‘DATE’.
   gs_fcat-col_pos = ‘5’.
   gs_fcat-tabname = ‘GT_SFLIGHT1’.
   APPEND gs_fcat TO gt_fcat.
   CLEAR gs_fcat.
   gs_fcat-fieldname = ‘PRICE’.
   gs_fcat-coltext = ‘RATE’.
   gs_fcat-col_pos = ‘6’.
   gs_fcat-tabname = ‘GT_SFLIGHT1’.
   APPEND gs_fcat TO gt_fcat.
   CLEAR gs_fcat.

ENDFORM.                               ” SELECT_TABLE_SFLIGHT

**********************************************Output screens***************************************************


Be the first to leave a comment
You must be Logged on to comment or reply to a post.