二维码

[ooalv] 使用Docking Container展示alv

Twilight发表于 2014-08-28 15:49Twilight 最后回复于 2014-08-28 15:49 [复制链接] 5072 0

目的:
有时我们需要把container 放在任意角落,并可调整大小,例如,ALV和选择屏幕都放在相同的屏幕上,为了实现这样的目的我们就需要用docking container
介绍:
我们都知道SAP Container是个 control,包含一些控件,例如,SAP Tree Control, SAP Picture Control, SAP Text edit Control, SAP Splitter Control等等,他集中地逻辑管理这些控件,并提供一个物理空间用于展示他们。所有的控件都依赖于一个container,因为这些container都是他们控制,你能嵌套他们,下面列举了5种SAP Containers:
1、SAP Custom Container
    The SAP Custom Container allows you to display controls in an area defined on a normal screen
    using the Screen Painter.
    Class: CL_GUI_CUSTOM_CONTAINER
2、 SAP Dialog Box Container
    The SAP Dialog Box container allows you to display controls in an amodal dialog box or
    fullscreen.
    Class: CL_GUI_DIALOGBOX_CONTAINER
3、SAP Docking Container
    The SAP Docking Container allows you to attach a control to any of the four edges of a screen as
    a resizable screen area. You can also detach it so that it becomes an  independent amodal     
    dialog box.
    Class: CL_GUI_DOCKING_CONTAINER
4、SAP Splitter Container
    The SAP Splitter Container allows you to display more than one control in a given area by
     dividing it into cells.
     Class: CL_GUI_SPLITTER_CONTAINER
5、SAP Easy Splitter Container
    The SAP Easy Splitter Container allows you to divide an area into two cells with a control in
    each. The cells are separated by a moveable splitter bar.
    Class: CL_GUI_EASY_SPLITTER_CONTAINER
SAP Control Framework.jpg

程序代码:
  1. TABLES: mara.
  2. *---------------------------------------------------------------------*
  3. *                        W O R K  A R E A S                           *
  4. *---------------------------------------------------------------------*
  5. DATA:
  6. *  Material Data
  7.    BEGIN OF wa_mara,
  8.      matnr    TYPE   mara-matnr,         " Material No.
  9.      mtart    TYPE   mara-mtart,         " Material Type
  10.      bismt    TYPE   mara-bismt,         " Old material No.
  11.      matkl    TYPE   mara-matkl,         " Material group
  12.      meins    TYPE   mara-meins,         " Base Unit of Measure
  13.      brgew    TYPE   mara-brgew,         " Gross Weight
  14.      ntgew    TYPE   mara-ntgew,         " Net Weight
  15.      gewei    TYPE   mara-gewei,         " Weight Unit
  16.    END OF wa_mara,
  17. * Field Catalog
  18. wa_fieldcat   TYPE lvc_s_fcat.
  19. *---------------------------------------------------------------------*
  20. *                   I N T E R N A L   T A B L E S                     *
  21. *---------------------------------------------------------------------*
  22. DATA:
  23. * For Material Data
  24.    t_mara LIKE STANDARD TABLE OF wa_mara,
  25. * For Field Catalog
  26.    t_fieldcat  TYPE lvc_t_fcat.

  27. *---------------------------------------------------------------------*
  28. *                     W O R K  V A R I A B L E S                      *
  29. *---------------------------------------------------------------------*
  30. DATA:
  31. * User Command
  32.    ok_code TYPE sy-ucomm,
  33. * Reference Variable for Docking Container
  34.    r_dock_container  TYPE REF TO cl_gui_docking_container,
  35. * Reference Variable for alv grid
  36.    r_grid  TYPE REF TO cl_gui_alv_grid.
  37. *---------------------------------------------------------------------*
  38. *                S T A R T   O F   S E L E C T I O N                  *
  39. *---------------------------------------------------------------------*
  40. START-OF-SELECTION.
  41. * To Display the Data
  42.   PERFORM display_output.
  43. *&--------------------------------------------------------------------*
  44. *&      Form  display_output                                          *
  45. *&--------------------------------------------------------------------*
  46. *       To Call the  screen & display the output                      *
  47. *---------------------------------------------------------------------*
  48. *   There are no interface parameters to be passed to this subroutine.*
  49. *---------------------------------------------------------------------*
  50. FORM display_output .
  51. * To fill the Field Catalog
  52.   PERFORM fill_fieldcat USING :
  53.       'MATNR'    'T_MARA'         'Material No.',
  54.       'MTART'    'T_MARA'         'Material Type',
  55.       'BISMT'    'T_MARA'         'Old Material No.',
  56.       'MATKL'    'T_MARA'         'Material Group',
  57.       'MEINS'    'T_MARA'         'Base Unit of Measure',
  58.       'BRGEW'    'T_MARA'         'Gross Weight',
  59.       'NTGEW'    'T_MARA'         'Net Weight',
  60.       'GEWEI'    'T_MARA'         'Weight Unit'.
  61.   CALL SCREEN 500.
  62. ENDFORM.                               " Display_output
  63. *&--------------------------------------------------------------*
  64. *&      Form  FILL_FIELDCAT                                     *
  65. *&--------------------------------------------------------------*
  66. *       To Fill the Field Catalog                               *
  67. *---------------------------------------------------------------*
  68. *  Three Parameters are passed                                  *
  69. *  pv_field   TYPE any for Field                                *
  70. *  pv_tabname TYPE any for Table Name                           *
  71. *  pv_coltext TYPE any for Header Text                          *
  72. *---------------------------------------------------------------*
  73. FORM fill_fieldcat  USING   pv_field   TYPE any
  74.                              pv_tabname TYPE any
  75.                              pv_coltext TYPE any .

  76.   wa_fieldcat-fieldname  = pv_field.
  77.   wa_fieldcat-tabname    = pv_tabname.
  78.   wa_fieldcat-coltext    = pv_coltext.
  79.   APPEND wa_fieldcat TO t_fieldcat.
  80.   CLEAR  wa_fieldcat.
  81. ENDFORM.                               " FILL_FIELDCAT
  82. *CREATE the screen 0500.
  83. *flow logic for screen 500.
  84. *&---------------------------------------------------------------------*
  85. *&      Module  STATUS_0500  OUTPUT                                    *
  86. *&---------------------------------------------------------------------*
  87. *       To Set GUI Status & Title                                      *
  88. *----------------------------------------------------------------------*
  89. MODULE status_0500 OUTPUT.
  90.   SET PF-STATUS 'STATUS'.
  91.   SET TITLEBAR 'TITLE'.
  92. ENDMODULE.                             " STATUS_0500  OUTPUT
  93. *&---------------------------------------------------------------------*
  94. *&      Module  CREATE_OBJECTS  OUTPUT                                 *
  95. *&---------------------------------------------------------------------*
  96. *       To Call the Docking Container & Display Method                 *
  97. *----------------------------------------------------------------------*
  98. MODULE create_objects OUTPUT.
  99. * Create a Docking container and dock the control at right side of screen
  100.   CHECK r_dock_container IS  INITIAL.
  101.   CREATE OBJECT r_dock_container
  102.     EXPORTING
  103.    side                        = cl_gui_docking_container=>dock_at_right
  104.       extension                   = 780
  105.       caption                     = 'Materials'
  106.     EXCEPTIONS
  107.       cntl_error                  = 1
  108.       cntl_system_error           = 2
  109.       create_error                = 3
  110.       lifetime_error              = 4
  111.       lifetime_dynpro_dynpro_link = 5
  112.       OTHERS                      = 6.
  113.   IF sy-subrc <> 0.
  114.     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  115.               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  116.   ENDIF.                               "  IF sy-subrc <> 0.
  117. * To Create the Grid Instance
  118.   CREATE OBJECT r_grid
  119.     EXPORTING
  120.       i_parent          = r_dock_container
  121.     EXCEPTIONS
  122.       error_cntl_create = 1
  123.       error_cntl_init   = 2
  124.       error_cntl_link   = 3
  125.       error_dp_create   = 4
  126.       OTHERS            = 5.
  127.   IF sy-subrc <> 0.
  128.     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  129.                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  130.   ENDIF.                               " IF sy-subrc <> 0.
  131. * Formatted Output Table is Sent to Control
  132.   CALL METHOD r_grid->set_table_for_first_display
  133.     CHANGING
  134.       it_outtab                      =  t_mara
  135.       it_fieldcatalog                =  t_fieldcat
  136. *      it_sort                       =
  137. *      it_filter                     =
  138.     EXCEPTIONS
  139.       invalid_parameter_combination = 1
  140.       program_error                 = 2
  141.       too_many_lines                = 3
  142.       OTHERS                        = 4
  143.           .
  144.   IF sy-subrc <> 0.
  145.     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  146.                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  147.   ENDIF.                               " IF sy-subrc <> 0.
  148. ENDMODULE.                             " CREATE_OBJECTS  OUTPUT
  149. *&---------------------------------------------------------------------*
  150. *&      Module  USER_COMMAND_0500  INPUT                               *
  151. *&---------------------------------------------------------------------*
  152. *     To Fetch the Material Data & Refresh Table after get User Command*
  153. *----------------------------------------------------------------------*
  154. MODULE user_command_0500 INPUT.
  155.   CASE ok_code.
  156.     WHEN 'EXECUTE'.
  157.       SELECT matnr                     " material no.
  158.              mtart                     " material type
  159.              bismt                     " old material no.
  160.              matkl                     " material group
  161.              meins                     " base unit of measure
  162.              brgew                     " gross weight
  163.              ntgew                     " net weight
  164.              gewei                     " weight unit
  165.         FROM mara
  166.         INTO TABLE t_mara
  167.         WHERE  mtart = mara-mtart.
  168.       IF sy-subrc <> 0.
  169.       ENDIF.                           " IF sy-subrc EQ 0.
  170.       CALL METHOD r_grid->refresh_table_display.
  171.     WHEN 'BACK' OR 'CANCEL' OR 'EXIT'.
  172.       LEAVE TO SCREEN 0.
  173.   ENDCASE.                             " CASE ok_code.
  174. ENDMODULE.                             " USER_COMMAND_0500  INPUT
复制代码

ps:
1、定义按钮
STATUS.png
2、设计屏幕
Screen 500 1.png
Screen 500 2.png
Screen 500 3.png
程序执行效果:
output.png
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表