SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Controls Technology



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dialog Programming
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Fri Nov 23, 2007 11:02 pm    Post subject: Controls Technology Reply with quote

I. Create custom control container & name it via screen painter with the custom control tool (icon with C)



II. Data variables that reference container
(CL_GUI_CUSTOM_CONTAINER) & specific control of interest (text edit or ALV, etc)

Code:
DATA w_container TYPE REF TO cl_gui_custom_container. " container variable

DATA w_editor TYPE REF TO cl_gui_textedit. " text editor

or

Code:
DATA w_grid TYPE REF TO cl_gui_alv_grid " ALV grid


III. In your screen's PBO create the container object & the specific control object of interest

Code:
IF w_editor IS INITIAL. " this is important! Instantiate ONCE only!
    w_repid = sy-repid.
    CREATE OBJECT w_container
      EXPORTING
        container_name              = 'MYCONTAINER1'
       EXCEPTIONS
         cntl_error                  = 1
         cntl_system_error           = 2
         create_error                = 3
         lifetime_error              = 4
         lifetime_dynpro_dynpro_link = 5
         others                      = 6.
    IF sy-subrc <> 0.
*     Create object & error &
      MESSAGE i493(zz) WITH 'w_container' sy-subrc.
      STOP.
    ENDIF.
    CREATE OBJECT w_editor
      EXPORTING
         wordwrap_mode          =
                   cl_gui_textedit=>wordwrap_at_fixed_position
         wordwrap_position      = c_line_length
         wordwrap_to_linebreak_mode = cl_gui_textedit=>true
         parent                 = w_container
      EXCEPTIONS
        error_cntl_create      = 1
        error_cntl_init        = 2
        error_cntl_link        = 3
        error_dp_create        = 4
        gui_type_not_supported = 5
        others                 = 6.
    IF sy-subrc <> 0.
*     Create object & error &
      MESSAGE i493(zz) WITH 'w_editor' sy-subrc.
      STOP.
    ENDIF.
  ENDIF.  " It hasn't been created yet


or

Code:
CREATE OBJECT w_grid
    EXPORTING
      i_parent          = w_container
    EXCEPTIONS
      error_cntl_create = 1
      error_cntl_init   = 2
      error_cntl_link   = 3
      error_dp_create   = 4
      others            = 5 .
  IF sy-subrc <> 0.
    MESSAGE a170.
  ENDIF.


IV. Depending upon control object, you might need to register an event in PBO & capture it in PAI

Register an event - first define & implement local class for event handling in top module (below is a static method)
Code:
*---------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS: catch_dblclick FOR EVENT dblclick
    OF cl_gui_textedit IMPORTING sender.
ENDCLASS.




Code:
* w_event_handler never referenced in the tutorial!
* I thought I would be able to use it if I changed the handler method
* from a static method (CLASS-MEHTODS) to an instance method by
* removing the CLASS- and by instantiating the object w_event_handler
* but this did not work!

DATA w_event_handler TYPE REF TO lcl_event_handler.
*---------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
*       When dblclick is captured g_event_type is populated with text *
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
  METHOD catch_dblclick.
    g_event_type = text-002.  " input/output field on screen
  ENDMETHOD.
ENDCLASS.


Link the local static method to the event in the control object once from PBO within If initial statement

Code:
SET HANDLER lcl_event_handler=>catch_dblclick FOR w_editor.


Register event as an application event
- declare internal table for events of interest & structure for one line in internal table

Code:
DATA t_events TYPE cntl_simple_events.
DATA st_events TYPE cntl_simple_event.
- assign static attribute for event to eventid & define as application event from PBO within If initial statement

st_events-eventid = cl_gui_textedit=>event_double_click.
st_events-appl_event = 'X'.
APPEND st_events TO t_events.
- register event once (within the if initial statement) in PBO
    CALL METHOD w_editor->set_registered_events
      EXPORTING
        events                    = t_events
       EXCEPTIONS
         cntl_error                = 1
         cntl_system_error         = 2
         illegal_event_combination = 3
         OTHERS                    = 4.
    IF sy-subrc <> 0.
*     Call Method & error &
      MESSAGE i494(zz) WITH 'cl_gui_textedit=>set_registered_events'
                            sy-subrc.
    ENDIF.


Capture the event in the PAI by calling method DISPATCH in class cl_gui_cfw (Control Framework Basic Class)

Code:
  CASE ok_code.
    WHEN 'EXIT'.
      LEAVE TO SCREEN 0.
    WHEN 'IMP'.
      PERFORM load_tab.
    WHEN OTHERS.
      CALL METHOD cl_gui_cfw=>dispatch
         IMPORTING
           return_code = w_return_code.
      IF w_return_code <> 0.
        MESSAGE i999(zz) WITH 'Bad return code from DISPATCH'
                              w_return_code ok_code.
      ENDIF.
  ENDCASE.


Switch from Application Event to System Event
Code:

*---------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
*       When dblclick is captured g_event_type is populated with text *
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
  METHOD catch_dblclick.
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING new_code = 'SHOW'.
  ENDMETHOD.
ENDCLASS.


In pbo
Code:
st_events-appl_event = space.

In pai
Code:
   CASE ok_code.
    WHEN 'EXIT'.
      LEAVE TO SCREEN 0.
    WHEN 'IMP'.
      PERFORM load_tab.
    WHEN 'SHOW'.
      event_type = text-003. " Doubleclick
  ENDCASE.


V. Depending upon control object, you might need to populate it in PBO

First define & implement local class for event handling in top module (below is an instance method)
Code:
*- Predefine a local class for event handling to allow the
*  declaration of a reference variable before the class is defined.
CLASS lcl_w_event_receiver DEFINITION DEFERRED.

DATA w_event_receiver TYPE REF TO lcl_w_event_receiver.

*---------------------------------------------------------------------*
*       CLASS lcl_w_event_receiver DEFINITION
*---------------------------------------------------------------------*
*       local event receiver definition                               *
*---------------------------------------------------------------------*
class lcl_w_event_receiver definition.
 public section.
*- define toolbar handler
   methods:
   handle_toolbar
   for event toolbar of cl_gui_alv_grid
   importing e_object e_interactive,
*- define user event handler
   handle_user_command
   for event user_command of cl_gui_alv_grid
   importing e_ucomm.
 private section.
endclass.

*---------------------------------------------------------------------*
*       CLASS lcl_w_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
*       local event receiver implementation                           *
*---------------------------------------------------------------------*
class lcl_w_event_receiver implementation.
*- add additional functions to toolbar
  METHOD handle_toolbar.
    DATA: ls_toolbar  TYPE stb_button.     " Toolbar Button (mt_toolbar)
*- add a separator to normal toolbar
    CLEAR ls_toolbar.
    MOVE 3 TO ls_toolbar-butn_type.        " 3 is Separator
    APPEND ls_toolbar TO e_object->mt_toolbar.
* append an icon for displaying work order
   CLEAR ls_toolbar.
   MOVE c_displaywo TO ls_toolbar-function. " ZPMORD3 is transaction
   MOVE icon_select_detail TO ls_toolbar-icon.
   MOVE 'Display WO'(003) TO ls_toolbar-quickinfo.
   MOVE 'Display WO'(003) TO ls_toolbar-text.
   MOVE ' ' TO ls_toolbar-disabled. " not disabled
   APPEND ls_toolbar TO e_object->mt_toolbar.
* append an icon for displaying billed services (display JVs)
   MOVE c_displayjv TO ls_toolbar-function. " FB03 is transaction
   MOVE icon_display TO ls_toolbar-icon.
   MOVE 'Display JV'(004) TO ls_toolbar-quickinfo.
   MOVE 'Display JV'(004) TO ls_toolbar-text.
   MOVE ' ' TO ls_toolbar-disabled.
   APPEND ls_toolbar TO e_object->mt_toolbar.
* append an icon for displaying computer equipment
   MOVE c_displaypc TO ls_toolbar-function. " IE03 is transaction
   MOVE icon_biw_monitor TO ls_toolbar-icon.
   MOVE 'Display Computer'(005) TO ls_toolbar-quickinfo.
   MOVE 'Display Computer'(005) TO ls_toolbar-text.
   MOVE ' ' TO ls_toolbar-disabled.
   APPEND ls_toolbar TO e_object->mt_toolbar.
* append an icon for printing work order
   MOVE c_print TO ls_toolbar-function. " PRINT is command
   MOVE icon_print TO ls_toolbar-icon.
   MOVE 'Print WO'(007) TO ls_toolbar-quickinfo.
   MOVE 'Print WO'(007) TO ls_toolbar-text.
   MOVE ' ' TO ls_toolbar-disabled.
   APPEND ls_toolbar TO e_object->mt_toolbar.
 ENDMETHOD.

  METHOD handle_user_command.
*- user event handling, react to users selection on toolbar
    DATA: lt_rows TYPE lvc_t_row.  " ALV control: Table rows

    CASE e_ucomm.
      WHEN c_displaywo.                          " ZPMORD3 display wo
        CALL METHOD w_grid->get_selected_rows
                 IMPORTING et_index_rows = lt_rows.
*       no exceptions
        CALL METHOD cl_gui_cfw=>flush
           EXCEPTIONS
             OTHERS            = 1.
        IF sy-subrc NE 0.
          PERFORM error_in_flush.
        ELSE.
          PERFORM display_workorder TABLES lt_rows.
        ENDIF.
      WHEN c_displaypc.                         " IE03 display computer
        CALL METHOD w_grid->get_selected_rows
                 IMPORTING et_index_rows = lt_rows.
*       no exceptions
        CALL METHOD cl_gui_cfw=>flush
           EXCEPTIONS
             OTHERS            = 1.
        IF sy-subrc NE 0.
          PERFORM error_in_flush.
        ELSE.
          PERFORM display_equipment TABLES lt_rows.
        ENDIF.
      WHEN c_displayjv.                          " FB03 display billing doc
        CALL METHOD w_grid->get_selected_rows
                 IMPORTING et_index_rows = lt_rows.
*       no exceptions
        CALL METHOD cl_gui_cfw=>flush
           EXCEPTIONS
             OTHERS            = 1.
        IF sy-subrc NE 0.
          PERFORM error_in_flush.
        ELSE.
          PERFORM display_jv TABLES lt_rows.
        ENDIF.
      WHEN c_print.                             " print work order
        CALL METHOD w_grid->get_selected_rows
                 IMPORTING et_index_rows = lt_rows.
*       no exceptions
        CALL METHOD cl_gui_cfw=>flush
           EXCEPTIONS
             OTHERS            = 1.
        IF sy-subrc NE 0.
          PERFORM error_in_flush.
        ELSE.
          PERFORM print_workorder TABLES lt_rows.
        ENDIF.
     ENDCASE.
   ENDMETHOD.
ENDCLASS.


Define structure for ALV Layout & Display Variant

Code:
DATA st_layout type lvc_s_layo.
DATA st_variant type disvariant.

Within PBO set the grid attributes, the display variant report name & call the method to display report

Code:

* if I don't implement multiple row selection functionality then
* selection mode 'B' would make more sense! See page 320 in Controls
* Technology book for definition of different values
* Page 274 explains the exception field name & outputing exceptions
*- set general grid attributes
  st_layout-zebra      = 'X'.        " Alternating line color
  st_layout-cwidth_opt = 'X'.        " Optimize column width
  st_layout-sel_mode   = c_multrows. " Selection Mode D cell selection
  st_layout-excp_fname = c_traffic.  " exceptions field name
* set up the ability for them to create variants
   st_variant-report = c_zpmworpt. " layout variants for this report
*- call the method to display the GRID
  CALL METHOD w_grid->set_table_for_first_display
    EXPORTING
      i_structure_name              = c_structure  " dict struc ZPMWOALL
      is_variant                    = st_variant   " display variant
      i_save                        = c_all     " user can save variants
      is_layout                     = st_layout    " grid attributes
    CHANGING
      it_outtab                     = t_zpmwoall[] " table with data
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4.
  IF sy-subrc <> 0.
    MESSAGE a171. " Error with grid display generation
  ENDIF.
  CHECK w_event_receiver IS INITIAL.  " instantiate once & only once!

*- create object to receive events and link them to handler methods.
CREATE OBJECT w_event_receiver.

* When the ALV Control raises the event for the specified instance
* the corresponding method is automatically called.
SET HANDLER w_event_receiver->handle_user_command FOR w_grid.
SET HANDLER w_event_receiver->handle_toolbar FOR w_grid.

*- call method 'set_toolbar_interactive' to raise event TOOLBAR.
CALL METHOD w_grid->set_toolbar_interactive.
* no exceptions
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dialog Programming All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.