ABAP Help Document(20):10.1Screen

10.User Dialogs

          基于SAP GUI的用户对话框。类型:Screens;Selection screens;Classic lists;Messages;Conversion routines。

示例:

100屏幕

 

"定义屏幕
SELECTION-SCREEN BEGIN OF SCREEN 1100.
  PARAMETERS input(12) TYPE c DEFAULT 'Hello World!'.
SELECTION-SCREEN END OF SCREEN 1100.

CLASS c_user_dialogs DEFINITION.
  PUBLIC SECTION.
    METHODS:m_user_dialog.
ENDCLASS.
CLASS c_user_dialogs IMPLEMENTATION.
   METHOD m_user_dialog.
     "selection screen 1100
     CALL SELECTION-SCREEN 1100 STARTING AT 10 10.
     IF sy-subrc <> 0.
       LEAVE PROGRAM.
     ENDIF.
     "dynpro
     CALL SCREEN 100.
     "message
     MESSAGE 'hello world' TYPE 'I'.
     "List
     WRITE 'hello world'.
   ENDMETHOD.
ENDCLASS

10.1 Screens

1.GUI Status

 

每个标准Window包含a menu bar,a standard toolbar,an application toolbar。

当前GUI STATUS,在sy-pfkey可以找到。

右键创建GUI Title。

 

右键创建GUI Status。

设置Menu Bar

 

设置Application Toolbar

 

设置Function Key

 

最顶上就是Menu Bar,第二行为Function Keys,第三行为Application Toolbar。

编辑Screen 100,创建module:Status_0100,user_command_0100。

 

MODULE STATUS_0100 OUTPUT.
   SET PF-STATUS 'STATUS_100'.
   SET TITLEBAR '100'.
ENDMODULE.                 " STATUS_0100  OUTPUT

屏幕OK_CODE,接收交换function。report全局定义ok_code变量和屏幕100的ok_code绑定。

DATA:ok_code TYPE sy-ucomm.

实现Module:user_command_0100,通过ok_code获取用户点击function按钮。

MODULE USER_COMMAND_0100 INPUT.
  DATA:save_ok LIKE ok_code.
  DATA:dd_list TYPE C LENGTH 20.
  DATA:dd_list1 TYPE C LENGTH 20.

  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
      LEAVE PROGRAM.
    WHEN OTHERS.
      input = save_ok.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT 

2.screen and elements

 

示例:Status Icons

创建Input/Output Elements,设置Output only,勾选With Icon。点击不同function key,修改input的值,set_icon修改output的Icon and text。

   

MODULE SET_ICON OUTPUT.
  "根据input,设置output
  DATA:output TYPE icons-text,
       icon_name(20) TYPE c,
       icon_text(10) TYPE c.
  DATA:lv_len TYPE I.
  lv_len = strlen( input ) MOD 3.
  IF lv_len = 0.
    icon_name = 'ICON_GREEN_LIGHT'.
    icon_text = '绿色'.
  ELSEIF lv_len = 1.
    icon_name = 'ICON_YELLOW_LIGHT'.
    icon_text = '黄色'.
  ELSEIF lv_len = 2.
    icon_name = 'ICON_RED_LIGHT'.
    icon_text = '红色'.
  ENDIF.
  "function,创建ICON
  CALL FUNCTION 'ICON_CREATE'
    EXPORTING
         name = icon_name
         text = icon_text
         info = 'Status'
         add_stdinf = 'X'
    IMPORTING
         result = output
    EXCEPTIONS
         icon_not_found        = 1
         outputfield_too_short = 2
         OTHERS                = 3.
ENDMODULE.                 " SET_ICON  OUTPUT 

示例:Context Menu

创建上下文菜单,为window中Element添加上下文菜单。

 

实现上下文菜单Form

"callback routine
FORM on_ctmenu_output USING lmenu TYPE REF TO cl_ctmenu.
  DATA:lo_submenu TYPE REF TO cl_ctmenu.
  CREATE OBJECT lo_submenu.
  lo_submenu->add_function(
    EXPORTING fcode = 'FCODE1'
              text = '右键function1'
  ).
  lo_submenu->add_function(
    EXPORTING fcode = 'FCODE2'
              text = '右键function2'
  ).
  "添加子menu
  lmenu->add_submenu(
    EXPORTING menu = lo_submenu
              text = '右键function'
  ).
  "添加CONTEXT Menu
  lmenu->load_gui_status(
    EXPORTING program = sy-repid
              status = 'CONTEXT_MENU_SELE'
              menu = lmenu
   ).
  "添加CONTEXT Menu
  lmenu->load_gui_status(
    EXPORTING program = sy-repid
              status = 'CONTEXT_MENU_MARK'
              menu = lmenu
   ).
  "设置默认选中
   lmenu->set_default_function( EXPORTING fcode = 'SELE' ).
ENDFORM.

右键创建GUI Status,选择Context Menu。

 

 

 

 

 

选择output这个component,通过Shift+F10,调出菜单。

 

示例:demo_cfw,customer control使用

显示图片,用到MIME中图片。或者使用Tcode:SMW0,上传图片。

1.选择Tcode:SE80,MIME Repository,右键创建folder

 

 

 2.选择创建的Folder,右键->Import MIME Objects

 

 

 url路径:/SAP/PUBLIC/TOM_TEST/pic.jpg

2.通过Tcode:SMW0,上传图片,这里必须是bmp格式。

 

 

 "event handler类
CLASS c_event_handler DEFINITION.
  PUBLIC SECTION.
    "picture event
    "图片点击
    METHODS:event_picture_click
      FOR EVENT picture_click OF cl_gui_picture
      IMPORTING mouse_pos_x mouse_pos_y sender.
    "图片双击
    METHODS:event_picture_dblclick
      FOR EVENT picture_dblclick OF cl_gui_picture
      IMPORTING mouse_pos_x mouse_pos_y sender.
    "图片右键菜单
    METHODS:event_context_menu
      FOR EVENT context_menu OF cl_gui_picture
      IMPORTING sender.
    "图片右键菜单功能
    METHODS:event_context_menu_sel
      FOR EVENT context_menu_selected OF cl_gui_picture
      IMPORTING fcode sender.
ENDCLASS.

CLASS c_event_handler IMPLEMENTATION.
  METHOD:event_picture_click.
    DATA:lv_msg TYPE C LENGTH 20.
    lv_msg = 'click,X:' && mouse_pos_x && ';Y:' && mouse_pos_y.
    MESSAGE lv_msg TYPE 'I'.
  ENDMETHOD.

  METHOD:event_picture_dblclick.
    DATA:lv_msg TYPE C LENGTH 20.
    lv_msg = 'double click,X:' && mouse_pos_x && ';Y:' && mouse_pos_y.
    MESSAGE lv_msg TYPE 'I'.
  ENDMETHOD.

  METHOD:event_context_menu.
    DATA:lv_menu TYPE REF TO cl_ctmenu.
    "创建右键菜单对象
    CREATE OBJECT lv_menu.
    "添加菜单项
    CALL METHOD lv_menu->add_function
      EXPORTING
        fcode = 'NORMAL'
        TEXT  = '正常'.
    CALL METHOD lv_menu->add_function
      EXPORTING
        FCODE = 'STRETCH'
        TEXT  = '伸展'.
    CALL METHOD lv_menu->add_function
      EXPORTING
        FCODE = 'FIT'
        TEXT  = '适应'.
    CALL METHOD lv_menu->add_function
      EXPORTING
        FCODE = 'NORMAL_CENTER'
        TEXT  = '正常居中'.
    CALL METHOD lv_menu->add_function
      EXPORTING
        FCODE = 'FIT_CENTER'
        TEXT  = '适应居中'.
    "设置右键menu
    sender->display_context_menu( lv_menu ).
  ENDMETHOD.

  METHOD:event_context_menu_sel.
    DATA:lv_display_mode TYPE I.
    IF fcode = 'NORMAL'.
      lv_display_mode = CL_GUI_PICTURE=>DISPLAY_MODE_NORMAL.
    ENDIF.
    IF fcode = 'STRETCH'.
      lv_display_mode = CL_GUI_PICTURE=>DISPLAY_MODE_STRETCH.
    ENDIF.
    IF fcode = 'FIT'.
      lv_display_mode = CL_GUI_PICTURE=>DISPLAY_MODE_FIT.
    ENDIF.
    IF fcode = 'NORMAL_CENTER'.
      lv_display_mode = CL_GUI_PICTURE=>DISPLAY_MODE_NORMAL_CENTER.
    ENDIF.
    IF fcode = 'FIT_CENTER'.
      lv_display_mode = CL_GUI_PICTURE=>DISPLAY_MODE_FIT_CENTER.
    ENDIF.
    "设置picture显示模式
    sender->set_display_mode( lv_display_mode ).
  ENDMETHOD.
ENDCLASS.

CLASS c_cfw DEFINITION.
  PUBLIC SECTION.
    METHODS:constructor.
    "加载html
    METHODS:load_html IMPORTING input_url TYPE CHAR255.
    "加载picture
    METHODS:load_picture.
    "加载tree
    METHODS:load_tree.
    "method event
    METHODS:event_node_double_click
     FOR EVENT node_double_click OF cl_gui_simple_tree
     IMPORTING node_key.
    METHODS:event_close_box
      FOR EVENT close OF cl_gui_dialogbox_container.
  PRIVATE SECTION.
    "容器类型
    "用户自定义容器
    DATA:lo_container TYPE REF TO cl_gui_custom_container.
    "弹窗容器
    DATA:lo_container_box TYPE REF TO cl_gui_dialogbox_container.
    "可变大小容器
    DATA:lo_docking TYPE REF TO cl_gui_docking_container.
    "可拆分容器
    DATA:lo_splitter TYPE REF TO cl_gui_splitter_container.
    "通用容器,父类
    DATA:lo_container_top TYPE REF TO cl_gui_container.
    DATA:lo_container_bottom TYPE REF TO cl_gui_container.

    "html组件
    DATA:lo_html_viewer TYPE REF TO cl_gui_html_viewer.
    "图片组件
    DATA:lo_picture TYPE REF TO cl_gui_picture.
    "树状目录
    DATA:lo_tree TYPE REF TO cl_gui_simple_tree.
    "alv grid
    DATA:lo_alv_grid TYPE REF TO cl_gui_alv_grid.
    "事件handler
    DATA:lo_event_handler TYPE REF TO c_event_handler.
ENDCLASS.

CLASS c_cfw IMPLEMENTATION.
  METHOD constructor.
    "父容器
    CREATE OBJECT lo_container EXPORTING container_name = 'CUSTOM_CONTROL'.
    "可变大小容器
    CREATE OBJECT lo_docking
      EXPORTING "设置align
                side =  cl_gui_docking_container=>align_at_left
                "宽度
                extension = 140.
    "可拆分容器
    CREATE OBJECT lo_splitter
      EXPORTING "拆分父容器
                parent = lo_docking
                "行数
                rows = 2
                columns = 1.
    "设置容器样式
    lo_splitter->set_border( EXPORTING border = cl_gui_cfw=>false ).
    lo_splitter->set_row_mode( EXPORTING mode = lo_splitter->mode_absolute ).
    lo_splitter->set_row_height( EXPORTING id = 1 height = 180 ).
    "获取分拆容器对象
    lo_container_top = lo_splitter->get_container( row = 1 column = 1 ).
    lo_container_bottom = lo_splitter->get_container( row = 2 column = 1 ).

    "事件对象
    CREATE OBJECT lo_event_handler.
  ENDMETHOD.
  "加载html
  METHOD load_html.
    IF lo_html_viewer IS INITIAL.
      CREATE OBJECT lo_html_viewer EXPORTING parent = lo_container.
    ENDIF.
    lo_html_viewer->show_url( EXPORTING url = input_url ).
  ENDMETHOD.
  "加载picture
  METHOD load_picture.
    DATA:lo_mime_api   TYPE REF TO if_mr_api.
    DATA:lv_xstring TYPE xstring.
    DATA:lv_url TYPE C LENGTH 256.
    DATA:lv_x1024 TYPE x LENGTH 1024.
    DATA:lt_x1024 LIKE TABLE OF lv_x1024.
    DATA:lt_event TYPE cntl_simple_events.
    DATA:ls_event LIKE LINE OF lt_event.

    IF lo_picture IS INITIAL.
      CREATE OBJECT lo_picture EXPORTING parent = lo_container_top.
    ENDIF.
    "mime repository api对象
    lo_mime_api = cl_mime_repository_api=>get_api( ).
    "mime中图片
    lo_mime_api->get(
      EXPORTING
         i_url = '/SAP/PUBLIC/TOM_TEST/pic1.jpg'
      IMPORTING
         e_content = lv_xstring
    ).
    DO.
      IF xstrlen( lv_xstring ) > 1024.
        lv_x1024 = lv_xstring(1024).
        APPEND lv_x1024 TO lt_x1024.
        SHIFT lv_xstring BY 1024 PLACES LEFT IN BYTE MODE.
      ELSE.
        APPEND lv_xstring TO lt_x1024.
        EXIT.
      ENDIF.
    ENDDO.
    "获取url
    CALL FUNCTION 'DP_CREATE_URL'
      EXPORTING
        type    = 'IMAGE'
        subtype = 'GIF'
      TABLES
        data    = lt_x1024
      CHANGING
        url     = lv_url.

    "使用smw0图片ZTOM_TEST
*    CALL FUNCTION 'DP_PUBLISH_WWW_URL'
*      EXPORTING
*        OBJID    = 'ZTOM_TEST'
*        LIFETIME = cndp_lifetime_transaction
*      IMPORTING
*        URL      = lv_url
*      EXCEPTIONS
*        OTHERS   = 1.

    "加载picture
    "lo_picture->load_picture_from_url( lv_url ).
    "异步加载
    lo_picture->load_picture_from_url_async( lv_url ).
    "设置样式
    lo_picture->set_display_mode( cl_gui_picture=>display_mode_stretch ).

    "设置事件
    ls_event-eventid = cl_gui_picture=>eventid_picture_click.
    APPEND ls_event TO lt_event.
    ls_event-eventid = cl_gui_picture=>eventid_picture_dblclick.
    APPEND ls_event TO lt_event.
    ls_event-eventid = cl_gui_picture=>eventid_context_menu.
    APPEND ls_event TO lt_event.
    ls_event-eventid = cl_gui_picture=>eventid_context_menu_selected.
    APPEND ls_event TO lt_event.
    lo_picture->set_registered_events( lt_event ).
    "设置事件处理handler
    SET HANDLER lo_event_handler->event_picture_click FOR lo_picture.
    SET HANDLER lo_event_handler->event_picture_dblclick FOR lo_picture.
    SET HANDLER lo_event_handler->event_context_menu FOR lo_picture.
    SET HANDLER lo_event_handler->event_context_menu_sel FOR lo_picture.
  ENDMETHOD.

  "加载tree
  METHOD load_tree.
    DATA:lt_event TYPE cntl_simple_events.
    DATA:ls_event LIKE LINE OF lt_event.
    "节点创建structure,包含结构:TREEV_NODE
    DATA:lt_node TYPE TABLE OF abdemonode.
    DATA:ls_node LIKE LINE OF lt_node.
    "航班信息
    DATA:lt_spfli TYPE SORTED TABLE OF spfli WITH UNIQUE KEY carrid connid.
    DATA:ls_spfli LIKE LINE OF lt_spfli.
    SELECT carrid connid FROM spfli INTO CORRESPONDING FIELDS OF TABLE lt_spfli.

    IF lo_tree IS INITIAL.
      CREATE OBJECT lo_tree
        EXPORTING parent = lo_container_bottom
        "选择模式,单选
        node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single.
    ENDIF.

    "设置事件
    ls_event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
    ls_event-appl_event = ' '.   "system event, does not trigger PAI
    APPEND ls_event TO lt_event.
    lo_tree->set_registered_events( lt_event ).
    "事件处理handler
    SET HANDLER me->event_node_double_click FOR lo_tree.

    "设置节点
    ls_node-hidden = ''.   "All nodes are visible,
    ls_node-disabled = ''. "selectable,
    ls_node-isfolder = 'X'. "是否活页夹
    ls_node-expander = ''.  "是否显示+
    LOOP AT lt_spfli INTO ls_spfli.
      AT NEW carrid.
        ls_node-node_key = ls_spfli-carrid.
        CLEAR ls_node-relatkey.
        CLEAR ls_node-relatship.
        ls_node-text = ls_spfli-carrid.
        ls_node-n_image = ' '.
        ls_node-exp_image = ' '.
        APPEND ls_node TO lt_node.
      ENDAT.
      "TYPE-POOLS:ICON.
      "点击icon,获取内部icon值
      AT NEW connid.
        ls_node-node_key = ls_spfli-carrid && ls_spfli-connid.
        ls_node-relatkey = ls_spfli-carrid.
        ls_node-relatship = cl_gui_simple_tree=>relat_last_child.
        ls_node-text = ls_spfli-connid.
        ls_node-n_image = '@AV@'.
        ls_node-exp_image = '@AV@'.
      ENDAT.
      APPEND ls_node TO lt_node.
    ENDLOOP.
    lo_tree->add_nodes(
     table_structure_name = 'ABDEMONODE'
     node_table = lt_node
     ).
  ENDMETHOD.

  "加载list
  METHOD event_node_double_click.
    DATA:lv_carrid TYPE sflight-carrid.
    DATA:lv_connid TYPE sflight-connid.
    DATA:lt_sflight TYPE TABLE OF sflight.
    DATA:ls_sflight LIKE LINE OF lt_sflight.
    DATA:ls_layout TYPE lvc_s_layo.
    lv_carrid = node_key+0(2).
    lv_connid = node_key+2(4).

    IF lv_connid IS NOT INITIAL.
      "查询数据
      SELECT * FROM sflight INTO TABLE lt_sflight
        WHERE carrid = lv_carrid
        AND   connid = lv_connid.
       IF lo_container_box IS INITIAL.
        "创建list容器弹窗
        CREATE OBJECT lo_container_box
          EXPORTING
            width = 400
            height = 200
            top = 40
            left = 40
            caption = 'Flight info'.
        SET HANDLER event_close_box FOR lo_container_box.
      ENDIF.
      IF lo_alv_grid IS INITIAL.
        CREATE OBJECT lo_alv_grid
          EXPORTING
            i_parent = lo_container_box.
      ENDIF.
      ls_layout-grid_title = lv_carrid && ':' && lv_connid.
      ls_layout-smalltitle = 'X'.    "The list title has small fonts,
      ls_layout-cwidth_opt = 'X'.    "the column width is adjusted,
      ls_layout-no_toolbar = 'X'.    "the toolbar is suppressed.
      lo_alv_grid->set_table_for_first_display(
        EXPORTING
          i_structure_name = 'SFLIGHT'
          is_layout = ls_layout
        CHANGING
          it_outtab = lt_sflight
      ).
    ENDIF.
  ENDMETHOD.

  METHOD event_close_box.
    "从里到外初始化
    lo_alv_grid->free( ).
    lo_container_box->free( ).
    CLEAR lo_alv_grid.
    CLEAR lo_container_box.
  ENDMETHOD.
ENDCLASS

示例:List Box

创建下拉选择框,屏幕100创建DD_LIST,DD_LIST1两个Listbox。对应Function code设置分别为DD_LIST,DD_LIST1。

 

 

 100屏幕module

PROCESS ON VALUE-REQUEST.
  FIELD DD_LIST MODULE f4_value_help.

 

MODULE F4_VALUE_HELP INPUT.
  TYPES:BEGIN OF s_list,
       "需要table字段,默认帮助
       id TYPE spfli-carrid,
       name TYPE C LENGTH 20,
      END OF s_list.
  DATA:lt_list TYPE TABLE OF s_list.
  DATA:ls_list LIKE LINE OF lt_list.
  IF lt_list IS INITIAL.
    ls_list-id = '11'.
    ls_list-name = '重庆'.
    APPEND ls_list TO lt_list.
    ls_list-id = '21'.
    ls_list-name = '北京'.
    APPEND ls_list TO lt_list.
  ENDIF.
  "设置f4 help
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
         retfield        = 'ID'
         value_org       = 'S'
    TABLES
         value_tab       = lt_list
    EXCEPTIONS
         parameter_error = 1
         no_values_found = 2
         OTHERS          = 3.
  IF sy-subrc <> 0.
    WRITE:/ 'error'.
  ENDIF.
ENDMODULE.                 " F4_VALUE_HELP  INPUT 

DD_LIST1的F4帮助

MODULE DD_LIST1_F4 OUTPUT.
  DATA:lv_name TYPE vrm_id.
  DATA:lt_values  TYPE vrm_values.
  DATA:ls_values LIKE LINE OF lt_values.

  IF lt_values IS INITIAL.
    ls_values-key = 'K1'.
    ls_values-text = 'value1'.
    APPEND ls_values TO lt_values.
    ls_values-key = 'K2'.
    ls_values-text = 'value2'.
    APPEND ls_values TO lt_values.
  ENDIF.
  lv_name = 'DD_LIST1'.
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id     = lv_name
      values = lt_values.
ENDMODULE.  " DD_LIST1_F4  OUTPUT

用户User Command,这里定义dd_list,dd_list1变量和屏幕100中component IO绑定,相当于全局变量。

MODULE USER_COMMAND_0100 INPUT.
  DATA:save_ok LIKE ok_code.
  DATA:dd_list TYPE C LENGTH 20.
  DATA:dd_list1 TYPE C LENGTH 20.

  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
      LEAVE PROGRAM.
    WHEN 'DD_LIST'.
      MESSAGE dd_list TYPE 'I'.
    WHEN 'DD_LIST1'.
      MESSAGE dd_list1 TYPE 'I'.
    WHEN OTHERS.
      input = save_ok.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT 

示例:HTML Brower

100屏幕PBO

MODULE HTML_BROWER.

实现代码弹出Document浏览框

MODULE HTML_BROWER OUTPUT.
  DATA:lv_html TYPE string.
  DATA:lv_title TYPE cl_abap_browser=>title.
  DATA:lt_ext_data TYPE cl_abap_browser=>load_tab.
  DATA:ls_ext_line TYPE cl_abap_browser=>load_tab_line.
  DATA:lt_error_list TYPE cl_abap_browser=>html_table.
  DATA:lo_mime_api TYPE REF TO if_mr_api.
  DATA:lv_xstring TYPE xstring.
  DATA:lv_x1024 TYPE X LENGTH 1024.
  DATA:lt_x1024 LIKE TABLE OF lv_x1024.

  lv_html = '<html><body><h>标题1</h><p>第一段落<b>html</b></p>'
   && '<p><a href = "https://www.baidu.com">百度一下</a></p>'
   && '<img src = "PIC.JPG"></img>'
   && '</html></body>'.

  "mime repository api对象
  lo_mime_api = cl_mime_repository_api=>get_api( ).
  "mime中图片
  lo_mime_api->get(
    EXPORTING
       i_url = '/SAP/PUBLIC/TOM_TEST/pic1.jpg'
    IMPORTING
       e_content = lv_xstring
  ).
  DO.
    IF xstrlen( lv_xstring ) > 1024.
      lv_x1024 = lv_xstring(1024).
      APPEND lv_x1024 TO lt_x1024.
      SHIFT lv_xstring BY 1024 PLACES LEFT IN BYTE MODE.
    ELSE.
      APPEND lv_xstring TO lt_x1024.
      EXIT.
    ENDIF.
  ENDDO.
  ls_ext_line-name = 'PIC.JPG'.
  ls_ext_line-type = 'image'.
  GET REFERENCE OF lt_x1024 INTO ls_ext_line-dref.
  APPEND ls_ext_line TO lt_ext_data.

  cl_abap_browser=>show_html(
      EXPORTING
        html_string = lv_html
        title       = lv_title
        buttons     = cl_abap_browser=>navigate_html
        format      = cl_abap_browser=>landscape
        size        = cl_abap_browser=>medium
        data_table  = lt_ext_data
      IMPORTING
         html_errors = lt_error_list ).
  IF lt_error_list IS INITIAL.
    MESSAGE 'error' TYPE 'E'.
  ENDIF.
ENDMODULE. " HTML_BROWER  OUTPUT

示例:CheckBox,Radio,Input

创建CheckBox,Raido Button,Input参考数据库表字段

复选框:CHECKBOX;

单选按钮组:RADIO1,RADIO2,RADIO3;

创建按钮组,选择所有按钮,右键->Radio Button Group->Define

带系统表帮助字段:LS_SPFLI-CARRID;

NAME:LS_SPFLI-CARRID;

在PBO程序:

MODULE INIT_RADIO_CHECK.

 

实现代码:

MODULE INIT_RADIO_CHECK OUTPUT.
  DATA:radio1 TYPE C LENGTH 1.
  DATA:radio2 TYPE C LENGTH 1.
  DATA:checkbox TYPE C LENGTH 1.
  DATA:lt_spfli TYPE TABLE OF spfli.
  DATA:ls_spfli LIKE LINE OF lt_spfli.
  radio1 = 'X'.
  checkbox = 'X'.
  CLEAR: radio2,radio3.
ENDMODULE. " INIT_RADIO_CHECK  OUTPUT 

3.PROCESS

          屏幕dynpro绑定field,可以定义为string,xstring,最大字符类型长度132。

语法:

PROCESS { {BEFORE OUTPUT}
      | { AFTER INPUT }
      | { ON HELP-REQUEST }
      | { ON VALUE-REQUEST } }.

PROCESS BEFORE OUTPUT(PBO):屏幕输出前执行Mudule;

PROCESS AFTER INPUT(PAI):相应用户屏幕输入;

PROCESS ON HELP-REQUEST(POH):F1帮助触发;

PROCESS ON VALUE-REQUEST(POV):F4帮助触发;

4.MODULE

语法:

MODULE mod [ AT {EXIT-COMMAND|CURSOR-SELECTION} ]
           [ ON {CHAIN-INPUT|CHAIN-REQUEST} ]
           [ SWITCH switch ].

 

 

 在PAI下,设置GUI STATUS中BACK,EXIT,CANCEL的Functional Type设置为E类型,点击时,触发AT EXIT-COMMAND的module。如果具有多个 module,执行执行第一个module。

MODULE mod AT EXIT-COMMNAD.

 

MODULE AT CURSOR-SELECTION,Function Code:CS 或者Functional Type为S触发Module代码。

MODULE ON CHAIN-INPUT,MODULE ON CHAIN-REQUEST,在字段输入,字段修改时触发Module代码。

示例:

PROCESS BEFORE OUTPUT.
  MODULE STATUS_0100.

PROCESS AFTER INPUT.
  "user command
  MODULE USER_COMMAND_0100.
  "exit command
  MODULE BACK AT EXIT-COMMAND.
  MODULE EXIT_COMMAND AT EXIT-COMMAND.
  "cursor
  "选择input1,触发cursor
  FIELD INPUT1 MODULE INPUT1_CURSOR AT CURSOR-SELECTION.
  "其他组件,触发cursor
  MODULE CURSOR AT CURSOR-SELECTION.
  "chain
  CHAIN.
    FIELD:INPUT1,INPUT2.
    "chain field 输入触发
    MODULE module_1 ON CHAIN-INPUT.
    "input3输入*触发,??
    FIELD INPUT3 MODULE module_* ON *-INPUT.
    "chain field 修改触发
    MODULE module_2 ON CHAIN-REQUEST.
  ENDCHAIN.
  "这种写法也可,INPUT在screen刷新时,都会触发;
  "REQUEST在字段值改变时触发
  CHAIN.
    FIELD:INPUT1 MODULE module_3 ON INPUT.
    FIELD:INPUT2 MODULE module_4 ON REQUEST.
  ENDCHAIN. 

5.FIELD

语法:

FIELD dynp_field { [ MODULE mod [] ]| [ [MODULE mod] WITH hlp ] }.

FIELD dynp_field MODULE mod [ {ON INPUT}
                            | {ON REQUEST}
                            | {ON *-INPUT}
                            | {ON {CHAIN-INPUT|CHAIN-REQUEST}}
                            | {AT CURSOR-SELECTION}.

示例:

 "没有指定filed
  "只能获取input2值
  MODULE module_input.
  "指定field
  FIELD:INPUT1.
  "之后该module可以获取到input1,input2值
  "但是input3值不能获取到
  MODULE:module_input1.
  FIELD:INPUT3.
  "该module可以获取到input1~3值
  MODULE:module_input3. 

示例:根据DDIC字典,字段检查及帮助

Format:设置字段格式,检查字段格式检查。

From dict:设置字段对应table字段,可以输入值检查,辅助输入。

Search Help:指定SE11创建的Search help;

 

 

 

空白:show Possible Entres,当Possible Entries勾选显示可选值;

0:不显示Possible Entries;

1:Show at Selection,点击帮助显示列表;

2:一直显示帮助方块;

示例:PAI中动态指定字段帮助

创建INPUT/OUTPUT,

NAME:CARRID,CONNID,在PAI定义帮助。

示例:

 "帮助可选值AA,AZ,QF-UA
   FIELD CARRID VALUES ('AA','AZ',NOT 'QZ',BETWEEN 'QF' AND 'UA' ).
   "CONNID帮助可选值为CARRID查询对应值
   FIELD CONNID SELECT  * FROM  SPFLI
                  WHERE CARRID = CARRID AND CONNID = CONNID.

示例:PAI指定module实现F4帮助

创建INPUT/OUTPUT,

NAME:CAR,CON,在PAI定义帮助。

 

全局变量定义:

"F4 help module
TYPES: BEGIN OF s_val,
         car TYPE spfli-carrid,
         con TYPE spfli-connid,
       END OF s_val.
DATA:lt_val TYPE TABLE OF s_val.
DATA:car TYPE C LENGTH 3.
DATA:con TYPE N LENGTH 4.
DATA:lv_prog TYPE sy-repid.
DATA:lv_dynnr TYPE sy-dynnr.
"保存dyn屏幕字段值
DATA:lt_dynpro_val TYPE TABLE OF dynpread.
DATA:ls_dynpro_val LIKE LINE OF lt_dynpro_val. 

PAI中F4帮助:

 "f4帮助
   PROCESS ON VALUE-REQUEST.
    FIELD CAR MODULE value_car.
    FIELD CON MODULE value_con.

Module实现:CAR参考SPFLI-CARRID字段,

MODULE VALUE_CAR INPUT.
  CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
    EXPORTING
      TABNAME = 'SPFLI' "表名
      FIELDNAME = 'CARRID' "字段名
*     SEARCHHELP = ' '
*     SHLPPARAM = ' '
      DYNPPROG = sy-repid "program
      DYNPNR = sy-dynnr "屏幕dyn
      DYNPROFIELD = 'CAR' "屏幕字段
*     STEPL = 0
*     VALUE = ' '
*     MULTIPLE_CHOICE = ' '
*     DISPLAY = ' '
*     SUPPRESS_RECORDLIST = ' '
*     CALLBACK_PROGRAM = ' '
*     CALLBACK_FORM = ' '
*     CALLBACK_METHOD =
*     SELECTION_SCREEN = ' '
*   IMPORTING
*     USER_RESET  =
*   TABLES
*     RETURN_TAB  =
*   EXCEPTIONS
*     FIELD_NOT_FOUND = 1
*     NO_HELP_FOR_FIELD = 2
*     INCONSISTENT_HELP = 3
*     NO_VALUES_FOUND = 4
*     OTHERS = 5
            .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.
ENDMODULE. " VALUE_CAR  INPUT

 

MODULE VALUE_CON INPUT.
  "屏幕字段值读取
  ls_dynpro_val-fieldname = 'CAR'.
  APPEND ls_dynpro_val TO lt_dynpro_val.
  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      DYNAME = sy-repid "program
      DYNUMB = sy-dynnr "屏幕dyn
      TRANSLATE_TO_UPPER = 'X' "转换大写
*     REQUEST = ' '
*     PERFORM_CONVERSION_EXITS = ' '
*     PERFORM_INPUT_CONVERSION = ' '
*     DETERMINE_LOOP_INDEX = ' '
*     START_SEARCH_IN_CURRENT_SCREEN = ' '
*     START_SEARCH_IN_MAIN_SCREEN = ' '
*     START_SEARCH_IN_STACKED_SCREEN = ' '
*     START_SEARCH_ON_SCR_STACKPOS = ' '
*     SEARCH_OWN_SUBSCREENS_FIRST = ' '
*     SEARCHPATH_OF_SUBSCREEN_AREAS = ' '
    TABLES
      DYNPFIELDS = lt_dynpro_val
    EXCEPTIONS
      INVALID_ABAPWORKAREA = 1
      INVALID_DYNPROFIELD = 2
      INVALID_DYNPRONAME = 3
      INVALID_DYNPRONUMMER = 4
      INVALID_REQUEST  = 5
      NO_FIELDDESCRIPTION  = 6
      INVALID_PARAMETER = 7
      UNDEFIND_ERROR = 8
      DOUBLE_CONVERSION = 9
      STEPL_NOT_FOUND = 10
      OTHERS = 11
            .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.
  READ TABLE lt_dynpro_val INTO ls_dynpro_val
   WITH KEY fieldname = 'CAR'.
  "查询数据
  SELECT carrid AS car connid AS con
    INTO CORRESPONDING FIELDS OF TABLE lt_val
    FROM spfli
    WHERE carrid = ls_dynpro_val-fieldvalue.

  "设置帮助
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
*     DDIC_STRUCTURE = ' '
      RETFIELD = 'CON' "返回表字段
*     PVALKEY = ' '
      DYNPPROG = sy-repid "program
      DYNPNR = sy-dynnr "屏幕dyn
      DYNPROFIELD = 'CON' "屏幕字段
*     STEPL = 0
*     WINDOW_TITLE =
*     VALUE = ' '
      VALUE_ORG = 'S' "返回结构,C:返回cell值
*     MULTIPLE_CHOICE = ' '
*     DISPLAY  = ' '
*     CALLBACK_PROGRAM = ' '
*     CALLBACK_FORM = ' '
*     CALLBACK_METHOD =
*     MARK_TAB =
*   IMPORTING
*     USER_RESET =
    TABLES
      VALUE_TAB  = lt_val
*     FIELD_TAB =
*     RETURN_TAB =
*     DYNPFLD_MAPPING =
*   EXCEPTIONS
*     PARAMETER_ERROR        = 1
*     NO_VALUES_FOUND        = 2
*     OTHERS                 = 3
            .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.
ENDMODULE. " VALUE_CON  INPUT

示例:PAI中Filed检查逻辑

示例:

 

 

 

   "INPUT1单独检查,如果检查出错,仅input1可输入,其他不可输入
   FIELD INPUT1 MODULE module_check1.
   "INPUT2,INPUT3一起检查,
   "module_check2检查INPUT2,如果出错,input2,3都可输入,其他不可;
   "module_check2检查通过,才执行module_check;
   CHAIN.
      FIELD INPUT2.
      MODULE module_check2.
      FIELD INPUT3.
      MODULE module_check.
   ENDCHAIN.

6.Table Controls

          Table Controls每行最多255个screen elements。

语法:

LOOP [AT itab [INTO wa] [CURSOR top_line] [FROM n1] [TO n2]]
     WITH CONTROL contrl.
ENDLOOP.

          在PBO可以使用INTO,CURSOR,FROM,TO等,PAI不可以;

          如果没有INTO wa,那么itab必须是有表头行的index table;

          sy-stepl,当前row, sy-loopc,table control显示行总数;

          CURSOR,FROM,TO没有必要,如果使用FROM n1,CURRENT_LINE = sy-stepl+ (TOP_LINE - 1) + (n1 - 1);

 

 

 拖动创建Table Control,Name:TBC_FLIGHTS

示例:主过程定义变量

"Table Control
CONTROLS tbc_flights TYPE TABLEVIEW USING SCREEN 100.
TYPES:BEGIN OF s_flight,
        carrid TYPE sflight-carrid,
        connid TYPE sflight-connid,
        fldate TYPE sflight-fldate,
        price TYPE sflight-price,
        seatsmax TYPE sflight-seatsmax,
      END OF s_flight.
"内表
DATA:lt_flights TYPE TABLE OF s_flight.
DATA:ls_flights LIKE LINE OF lt_flights. 

示例:PBO模块

  "table control,填充数据然后输出
  MODULE init_table_control.
  "方式1
  LOOP WITH CONTROL tbc_flights.
    MODULE fill_table_control.
  ENDLOOP.
*  "方式2
*  LOOP AT lt_flights INTO ls_flights WITH CONTROL tbc_flights.
*  ENDLOOP.

MODULE INIT_TABLE_CONTROL OUTPUT.
  DATA:lv_lines TYPE I.
  DESCRIBE TABLE lt_flights LINES lv_lines.
  tbc_flights-lines = lv_lines.
ENDMODULE.                 " INIT_TABLE_CONTROL  OUTPUT

MODULE FILL_TABLE_CONTROL OUTPUT.
  READ TABLE lt_flights INTO ls_flights INDEX tbc_flights-current_line.
ENDMODULE. " FILL_TABLE_CONTROL  OUTPUT

示例:PAI模块

"table control,更新用户输入数据到内表
  "方式1
  LOOP WITH CONTROL tbc_flights.
    MODULE modify_table_control.
  ENDLOOP.
*  "方式2
*  LOOP AT lt_flights.
*    MODULE modify_table_control.
*  ENDLOOP.

MODULE MODIFY_TABLE_CONTROL INPUT.
  lv_pagelines = sy-loopc.

MODIFY lt_flights FROM ls_flights INDEX tbc_flights-current_line.
ENDMODULE.                 " MODIFY_TABLE_CONTROL  INPUT

page换页,编辑,是否可见,排序等控制

 

注意:自定义Table Control中有日期字段,或金额字段时,下拉滚动条滚动到最后行,需要添加空白行时,程序就会dump。日期和金额处理格式错误。

User command计算top_line,上一行,下一行,上一页,下一页,第一页,最后页。

CASE ok_save.
    WHEN 'PREV_LINE'.
      IF tbc_flights-top_line - 1 > 0.
        tbc_flights-top_line = tbc_flights-top_line - 1.
      ELSE.
        tbc_flights-top_line = 0.
      ENDIF.
    WHEN 'NEXT_LINE'.
      tbc_flights-top_line = tbc_flights-top_line + 1.
      IF tbc_flights-top_line > ( lv_lines - lv_pagelines + 1 ).
        tbc_flights-top_line = lv_lines - lv_pagelines + 1.
      ENDIF.
    WHEN 'PREV_PAGE'.
      tbc_flights-top_line = tbc_flights-top_line - lv_pagelines.
      IF tbc_flights-top_line < 0.
        tbc_flights-top_line = 0.
      ENDIF.
    WHEN 'NEXT_PAGE'.
      tbc_flights-top_line = tbc_flights-top_line + lv_pagelines.
      IF tbc_flights-top_line > ( lv_lines - lv_pagelines + 1 ).
        tbc_flights-top_line = lv_lines - lv_pagelines + 1.
      ENDIF.
    WHEN 'FIRST_PAGE'.
      tbc_flights-top_line = 0.
    WHEN 'LAST_PAGE'.
      tbc_flights-top_line = lv_lines - lv_pagelines + 1.

    WHEN 'EDIT'.
      LOOP AT tbc_flights-cols INTO ls_cols.
        IF ls_cols-screen-name = 'LS_FLIGHTS-SEATSMAX'.
          IF ls_cols-screen-input = 0.
            "可输入
            ls_cols-screen-input = 1.
          ELSE.
            "不可输入
            ls_cols-screen-input = 0.
          ENDIF.
        ENDIF.
        MODIFY tbc_flights-cols FROM ls_cols TRANSPORTING screen.
      ENDLOOP.
    WHEN 'DIS'.
      LOOP AT tbc_flights-cols INTO ls_cols.
        "将指定列隐藏
        "INVISIBLE :X 为隐藏,0显示
        IF ls_cols-screen-name = 'LS_FLIGHTS-SEATSMAX'.
          IF ls_cols-invisible = 'X'.
            ls_cols-invisible = ''.
          ELSE.
            ls_cols-invisible = 'X'.
          ENDIF.
          MODIFY tbc_flights-cols FROM ls_cols TRANSPORTING invisible.
        ENDIF.
        "通过设置可见长度设置列隐藏,有时失效
        "设置vislength为0,实现隐藏;要显示设置显示字段长度即可
*        IF ls_cols-screen-name = 'LS_FLIGHTS-SEATSMAX'.
*          IF ls_cols-vislength = 0.
*            ls_cols-vislength = 8.
*          ELSE.
*            ls_cols-vislength = 0.
*          ENDIF.
*          MODIFY tbc_flights-cols FROM ls_cols TRANSPORTING vislength.
*        ENDIF.
      ENDLOOP.
    WHEN 'SORT'.
      "获取选择的列
      LOOP AT tbc_flights-cols INTO ls_cols WHERE selected = 'X'.
        SORT lt_flights STABLE BY (ls_cols-screen-name+11) DESCENDING.
        ls_cols-selected = ''.
        MODIFY tbc_flights-cols FROM ls_cols.
      ENDLOOP

7.Subscreen & Tabstrip

语法:

CALL SUBSCREEN sub_area [INCLUDING prog dynnr.].

在PBO:

1. CALL SUBSCREEN sub_area INCLUDING prog dynnr.. 

在PAI:

2. CALL SUBSCREEN sub_area. 

 

 

 创建Tabstrip,

NAME:TAB1,TAB2,对应FctCode:TAB1,TAB2;FctType='';(等于P时,不触发User command)。

指定Ref.Field,就是每个Tabstrip包含的Subscreen Name;

创建Subscreen,

NAME:SUB

创建screen:110,120,screen type 为subscreen;

主程序:

"Tabstrip
CONTROLS tabsp TYPE TABSTRIP.
"屏幕号
DATA:lv_dynnum TYPE sy-dynnr.
"设定初始活动tab
tabsp-activetab = 'TAB2'.
lv_dynnum = '0120'

PBO模块:

  "子屏幕
  CALL SUBSCREEN SUB INCLUDING sy-repid lv_dynnum.

PAI模块:

  "子屏幕
  CALL SUBSCREEN SUB

USER COMMAND,处理用户点击,ok_save等于FctCode。

WHEN 'TAB1'.
      tabsp-activetab = ok_save.
      lv_dynnum = '0110'.
    WHEN 'TAB2'.
      tabsp-activetab = ok_save.
      lv_dynnum = '0120'.

8.Splitter Controls

示例:DEMO_DYNPRO_SPLITTER_CONTROL

9.ABAP Statements for Screens

1.CALL SCREEN

语法:

CALL SCREEN dynnr
            [STARTING AT col1 lin1
            [ENDING   AT col2 lin2]].

2.SET PF-STATUS

语法:

SET PF-STATUS status [OF PROGRAM prog] [EXCLUDING fcode].

当前GUI Status,sy-pfkey。

语法:

GET PF-STATUS status [PROGRAM prog] [EXCLUDING fcode].

fcode可以是标准表

示例:

"GUI Status
DATA:lt_fcode TYPE STANDARD TABLE OF sy-ucomm
      WITH NON-UNIQUE KEY table_line.
DATA:lv_status TYPE string.

设置或获取GUI STATUS

   SET PF-STATUS 'STATUS_100' EXCLUDING 'EXEC'.
   GET PF-STATUS lv_status PROGRAM lv_prog EXCLUDING lt_fcode.

3.SET TITLEBAR

语法:

SET TITLEBAR title [OF PROGRAM prog]
                   [WITH text1 ... text9].

title最长70个字符,系统变量sy-title。

4. SUPPRESS DIALOG

语法:

SUPPRESS DIALOG.

          在PBO中有效,处理当前dynpro但是不显示screen。

5.LOOP AT SCREEN

语法:

LOOP AT SCREEN INTO wa.
ENDLOOP.

SCREEN结构:

 

使用LOOP SCREEN,MODIFY SCREEN,循环更新屏幕component。

6. SET CURSOR

语法:

SET CURSOR { { FIELD field [LINE line] [[DISPLAY] OFFSET off] }
           | { col lin } }.

设置光标,PBO

7.GET CURSOR

GET CURSOR { {FIELD field [field_properties]}

           | { LINE line } }.

[field_properties]:

[VALUE val] [LENGTH len] [OFFSET off] [LINE lin] [AREA area].

获取光标,PAI

8.CONTROLS

语法:
1. CONTROLS contrl TYPE TABLEVIEW USING SCREEN dynnr.

2. CONTROLS contrl TYPE TABSTRIP.

table control 和 tabstrip定义。

定义在Type group:CXTAB;table control对应CXTAB_CONTROL;tabstrip对应CXTAB_TABSTRIP。

示例:

TYPE-POOL CXTAB .
TYPES:
       CXTAB_COLUMN type scxtab_column,
       CXTAB_CONTROL type scxtab_control,
       CXTAB_TABSTRIP type scxtab_tabstrip.

9.REFRESH CONTROL

语法:

REFRESH CONTROL contrl FROM SCREEN dynnr.

初始化table control。

10.EXIT FROM STEP-LOOP

语法:

EXIT FROM STEP-LOOP.

处理table controls or step loops,执行跳出loop。

11.SET HOLD DATA

语法:

SET HOLD DATA {ON|OFF}.

PBO设置系统功能是否可用:

System → User specifications → Hold data

设置保存用户输入field字段值。

System → User specifications → Set data

设置保存用户输入field字段值,然后field不可输入。

System → User specifications → Delete data

删除用户保存field字段值

12. SET SCREEN

语法:

SET SCREEN dynnr.

设置next screen。

13.LEAVE SCREEN

语法:

LEAVE { SCREEN | {TO SCREEN dynnr} }.

LEAVE SCREEN:离开screen,到下一screen。

LEAVE TO SCREEN dynnr:离开screen,到指定screen。

posted @ 2021-04-24 11:27  渔歌晚唱  阅读(304)  评论(0编辑  收藏  举报