创建FPM应用 – 页面控制

==因时间、工作等原因,各项功能详细介绍只能留待以后空闲时再做了。下面只贴了相关代码,根据具体实例来看用法。==

页面添加按钮

IF_FPM_GUIBB_LIST~GET_DEFINITION

APPEND INITIAL LINE TO et_action_definition ASSIGNING <fs_action>.
    IF sy-subrc = 0.
      <fs_action>-id       = 'BTN_CONFIRM_BATCH'.
      <fs_action>-text     = '批量确认'.
      <fs_action>-enabled  = abap_true.
    ENDIF.
    APPEND INITIAL LINE TO et_action_definition ASSIGNING <fs_action>.
    IF sy-subrc = 0.
      <fs_action>-id       = 'BTN_XD'.
      <fs_action>-text     = '下达'.
      <fs_action>-enabled  = abap_true.
    ENDIF.
    APPEND INITIAL LINE TO et_action_definition ASSIGNING <fs_action>.
    IF sy-subrc = 0.
      <fs_action>-id       = 'BTN_BACK'.
      <fs_action>-text     = '退回'.
      <fs_action>-enabled  = abap_true.
    ENDIF.

列表添加过滤、合计等功能

LOOP AT lo_structdescr->components INTO DATA(ls_component).
     IF mv_wd_configid = 'ZRRE_WDAC_PLAN_PERYEAR_SUMMARY'.
       exit.
     ENDIF.
     APPEND INITIAL LINE TO et_field_description ASSIGNING <fs_field_des>.
     <fs_field_des>-name              = ls_component-name.
     <fs_field_des>-allow_sort        = abap_true.
     <fs_field_des>-allow_aggregation = abap_true.
     <fs_field_des>-allow_filter      = abap_true.
     <fs_field_des>-null_as_blank     = abap_true.
     <fs_field_des>-read_only         = abap_true.
     CASE  <fs_field_des>-name.
       WHEN 'PLVER' or 'PLSTA' or 'PLTYP'.

       WHEN OTHERS.
     ENDCASE.
   ENDLOOP.

工具栏按钮状态控制

METHOD set_toolbar_usages.
  DATA:
    lv_action_id          TYPE string,
    lr_action_props       TYPE REF TO /bofu/if_fbi_view_instance_new=>ts_action_properties,
    lo_cnr_oif            TYPE REF TO if_fpm_cnr_oif,
    lo_cnr_gaf            TYPE REF TO if_fpm_cnr_gaf,
    lo_cnr_ovp            TYPE REF TO if_fpm_cnr_ovp,
    lt_buttons_oif        TYPE if_fpm_cnr_oif=>t_button,
    lt_button_choice_oif  TYPE if_fpm_cnr_oif=>t_button_choice,
    ls_buttons_oif        TYPE if_fpm_cnr_oif=>s_button,
    lr_button_choice_oif  TYPE REF TO if_fpm_cnr_oif=>s_button_choice,
    ls_menu_act_itm_oif   TYPE if_fpm_cnr_oif=>s_menu_action_items,
    lt_buttons_gaf        TYPE if_fpm_cnr_gaf=>t_button,
    ls_buttons_gaf        TYPE if_fpm_cnr_gaf=>s_button,
    lt_button_choice_gaf  TYPE if_fpm_cnr_gaf=>t_button_choice,
    lr_button_choice_gaf  TYPE REF TO if_fpm_cnr_gaf=>s_button_choice,
    ls_menu_act_itm_gaf   TYPE if_fpm_cnr_gaf=>s_menu_action_items,
    lt_toolbar_ovp        TYPE if_fpm_ovp=>ty_t_toolbar_element,
    ls_toolbar_ovp        TYPE if_fpm_ovp=>ty_s_toolbar_element,
    lv_enabled            TYPE boole_d,
    lt_buttons            TYPE tt_buttons,
    ls_buttons            TYPE ts_buttons,
    lr_button             TYPE REF TO ts_buttons,
    lt_change_buttons     TYPE tt_buttons,
    ls_change_buttons     TYPE ts_buttons,
    lt_toolbar_ovp_button TYPE if_fpm_ovp=>ty_t_toolbar_button,
    ls_toolbar_ovp_button TYPE if_fpm_ovp=>ty_s_toolbar_button,
    lt_ch_button_oif      TYPE tt_buttons,
    lt_ch_button_gaf      TYPE tt_buttons,
    lv_last_element_id    TYPE string,
    lt_menu_act_itm_oif   TYPE if_fpm_cnr_oif=>t_menu_action_items,
    lt_menu_act_itm_gaf   TYPE if_fpm_cnr_gaf=>t_menu_action_items,
    ls_button_choice_ovp  TYPE if_fpm_ovp=>ty_s_toolbar_button_choice,
    lt_button_ch_itm_ovp  TYPE if_fpm_ovp=>ty_t_toolbar_element_sub_item,
    ls_button_ch_itm_ovp  TYPE if_fpm_ovp=>ty_s_toolbar_element_sub_item,
    lr_el_sub_item        TYPE REF TO if_fpm_ovp=>ty_s_toolbar_element_sub_item,
    lt_ovp_button_choice  TYPE tt_ovp_button_choice,
    ls_ovp_button_choice  TYPE ts_ovp_button_choice,
    lr_ovp_button_choice  TYPE REF TO ts_ovp_button_choice,
    lv_oif_enabled        TYPE boole_d,
    lv_gaf_enabled        TYPE boole_d,
    lv_action_visibility  TYPE fpm_visibility,
    lv_oif_visible        TYPE fpm_visibility,
    lv_gaf_visible        TYPE fpm_visibility,
    ls_content_area       TYPE if_fpm_ovp=>ty_s_content_area,
    lo_fpm                TYPE REF TO if_fpm.

* Get FPM instance
    lo_fpm = cl_fpm_factory=>get_instance( ).
* Get all configured buttons
*--------------------------------------------------------------------*
* Get CNR API
  lo_cnr_oif ?= lo_fpm->get_service( cl_fpm_service_manager=>gc_key_cnr_oif ).
  IF lo_cnr_oif IS BOUND.
    lo_cnr_oif->get_buttons(
      IMPORTING
        et_buttons    = lt_buttons_oif ).
    lo_cnr_oif->get_button_choices(
      IMPORTING
        et_button_choices = lt_button_choice_oif ).
    IF NOT lt_buttons_oif[] IS INITIAL.
      LOOP AT lt_buttons_oif INTO ls_buttons_oif.
        MOVE-CORRESPONDING ls_buttons_oif TO ls_buttons.
        INSERT ls_buttons INTO TABLE lt_buttons.
        CLEAR: ls_buttons_oif, ls_buttons.
      ENDLOOP.
    ENDIF.
    IF NOT lt_button_choice_oif[] IS INITIAL.
      LOOP AT lt_button_choice_oif REFERENCE INTO lr_button_choice_oif.
        LOOP AT lr_button_choice_oif->menu_action_items INTO ls_menu_act_itm_oif.
          ls_buttons-ch_element_id = lr_button_choice_oif->element_id.
          ls_buttons-function      = lr_button_choice_oif->function.
          ls_buttons-on_action     = ls_menu_act_itm_oif-on_action.
          ls_buttons-enabled       = ls_menu_act_itm_oif-enabled.
          ls_buttons-visibility    = ls_menu_act_itm_oif-visible.
          ls_buttons-text          = ls_menu_act_itm_oif-text.
          IF ls_menu_act_itm_oif-element_id IS INITIAL.
            ls_buttons-element_id  = lr_button_choice_oif->element_id.
          ELSE.
            ls_buttons-element_id  = ls_menu_act_itm_oif-element_id.
          ENDIF.
          INSERT ls_buttons INTO TABLE lt_buttons.
          CLEAR ls_buttons.
        ENDLOOP.
      ENDLOOP.
    ENDIF.
  ELSE.
*   Get CNR API
    lo_cnr_gaf ?= lo_fpm->get_service( cl_fpm_service_manager=>gc_key_cnr_gaf ).
    IF lo_cnr_gaf IS BOUND.
      lo_cnr_gaf->get_buttons(
        IMPORTING
          et_buttons    = lt_buttons_gaf ).
      lo_cnr_gaf->get_button_choices(
        IMPORTING
          et_button_choices = lt_button_choice_gaf ).
      IF NOT lt_buttons_gaf[] IS INITIAL.
        LOOP AT lt_buttons_gaf INTO ls_buttons_gaf.
          IF ls_buttons_gaf-function = if_fpm_constants=>gc_button-finish.
            ls_buttons_gaf-function = if_fpm_constants=>gc_button-activation_function.
          ENDIF.
          MOVE-CORRESPONDING ls_buttons_gaf TO ls_buttons.
          INSERT ls_buttons INTO TABLE lt_buttons.
        ENDLOOP.
      ENDIF.
      IF NOT lt_button_choice_gaf[] IS INITIAL.
        LOOP AT lt_button_choice_gaf REFERENCE INTO lr_button_choice_gaf.
          LOOP AT lr_button_choice_gaf->menu_action_items INTO ls_menu_act_itm_gaf.
            ls_buttons-ch_element_id = lr_button_choice_gaf->element_id.
            ls_buttons-function      = lr_button_choice_gaf->function.
            ls_buttons-on_action     = ls_menu_act_itm_gaf-on_action.
            ls_buttons-enabled       = ls_menu_act_itm_gaf-enabled.
            ls_buttons-visibility    = ls_menu_act_itm_gaf-visible.
            ls_buttons-text          = ls_menu_act_itm_gaf-text.
            IF ls_menu_act_itm_gaf-element_id IS INITIAL.
              ls_buttons-element_id  = lr_button_choice_gaf->element_id.
            ELSE.
              ls_buttons-element_id  = ls_menu_act_itm_gaf-element_id.
            ENDIF.
            INSERT ls_buttons INTO TABLE lt_buttons.
            CLEAR ls_buttons.
          ENDLOOP.
        ENDLOOP.
      ENDIF.
    ELSE.
*     Get CNR API
      lo_cnr_ovp ?= lo_fpm->get_service( cl_fpm_service_manager=>gc_key_cnr_ovp ).
      IF lo_cnr_ovp IS BOUND.
        TRY .
*           Get next content area
            ls_content_area = lo_cnr_ovp->get_current_content_area( ).
            IF mo_controller->mo_flush_event->mv_event_id = if_fpm_constants=>gc_event-leave_initial_screen OR
               mo_controller->mo_flush_event->mv_event_id = if_fpm_constants=>gc_event-change_content_area.
              mo_controller->get_target_content_area(
                CHANGING
                  cv_content_area = ls_content_area-id ).
            ENDIF.
            lo_cnr_ovp->get_toolbar_elements(
              EXPORTING
                iv_content_area           = ls_content_area-id
              IMPORTING
                et_toolbar_element        = lt_toolbar_ovp ).
          CATCH cx_fpm_floorplan.    " Floorplan exceptions
        ENDTRY.

        IF NOT lt_toolbar_ovp[] IS INITIAL.
          LOOP AT lt_toolbar_ovp INTO ls_toolbar_ovp.
            TRY.
                IF ls_toolbar_ovp-type = if_fpm_constants=>gc_toolbar_element_type-button.
                  lo_cnr_ovp->get_toolbar_button(
                    EXPORTING
                      iv_content_area           = ls_content_area-id
                      iv_toolbar_element_id     = ls_toolbar_ovp-element_id
                    IMPORTING
                      es_toolbar_button         = ls_toolbar_ovp_button ).
                ENDIF.
                IF ls_toolbar_ovp-type = if_fpm_constants=>gc_toolbar_element_type-button_choice.
                  lo_cnr_ovp->get_toolbar_button_choice(
                    EXPORTING
                      iv_content_area               = ls_content_area-id
                      iv_toolbar_element_id         = ls_toolbar_ovp-element_id
                    IMPORTING
                      es_toolbar_button_choice      = ls_button_choice_ovp
                      et_toolbar_button_choice_item = lt_button_ch_itm_ovp ).
                ENDIF.
              CATCH cx_fpm_floorplan.    " Floorplan exceptions
            ENDTRY.
*Button (OVP)
            IF NOT ls_toolbar_ovp_button IS INITIAL.
              INSERT ls_toolbar_ovp_button INTO TABLE lt_toolbar_ovp_button.
              MOVE-CORRESPONDING ls_toolbar_ovp_button TO ls_buttons.
              ls_buttons-on_action  = ls_toolbar_ovp_button-event_id.
              CASE ls_toolbar_ovp_button-event_id.
                WHEN if_fpm_constants=>gc_event-save.                  "FPM_SAVE
                  ls_buttons-function = if_fpm_constants=>gc_button-activation_function.
                WHEN if_fpm_constants=>gc_event-edit.                  "FPM_EDIT
                  ls_buttons-function = if_fpm_constants=>gc_button-edit.
                WHEN if_fpm_constants=>gc_event-read_only.             "FPM_READ_ONLY
                  ls_buttons-function = if_fpm_constants=>gc_button-read_only.
                WHEN if_fpm_constants=>gc_event-create.                "FPM_CREATE
                  ls_buttons-function = if_fpm_constants=>gc_button-create.
                WHEN if_fpm_constants=>gc_event-delete_current_object. "FPM_DELETE
                  ls_buttons-function = if_fpm_constants=>gc_button-delete.
                WHEN OTHERS.
                  ls_buttons-function = if_fpm_constants=>gc_button-other_function.
              ENDCASE.
              INSERT ls_buttons INTO TABLE lt_buttons.
              CLEAR ls_toolbar_ovp_button.
            ENDIF.
*Button choice (OVP)
            IF NOT ls_button_choice_ovp IS INITIAL.
              CLEAR ls_ovp_button_choice.
              ls_ovp_button_choice-s_button_choice = ls_button_choice_ovp.
              ls_ovp_button_choice-el_sub_item     = lt_button_ch_itm_ovp.
              INSERT ls_ovp_button_choice INTO TABLE lt_ovp_button_choice.
              LOOP AT lt_button_ch_itm_ovp INTO ls_button_ch_itm_ovp.
                ls_buttons-ch_element_id = ls_button_choice_ovp-element_id.
                ls_buttons-element_id    = ls_button_choice_ovp-element_id.
                ls_buttons-on_action     = ls_button_ch_itm_ovp-event_id.
                ls_buttons-enabled       = ls_button_ch_itm_ovp-enabled.
                ls_buttons-visibility    = ls_button_ch_itm_ovp-visibility.
                ls_buttons-text          = ls_button_ch_itm_ovp-text.
                CASE ls_button_ch_itm_ovp-event_id.
                  WHEN if_fpm_constants=>gc_event-save.                  "FPM_SAVE
                    ls_buttons-function = if_fpm_constants=>gc_button-activation_function.
                  WHEN if_fpm_constants=>gc_event-edit.                  "FPM_EDIT
                    ls_buttons-function = if_fpm_constants=>gc_button-edit.
                  WHEN if_fpm_constants=>gc_event-read_only.             "FPM_READ_ONLY
                    ls_buttons-function = if_fpm_constants=>gc_button-read_only.
                  WHEN if_fpm_constants=>gc_event-create.                "FPM_CREATE
                    ls_buttons-function = if_fpm_constants=>gc_button-create.
                  WHEN if_fpm_constants=>gc_event-delete_current_object. "FPM_DELETE
                    ls_buttons-function = if_fpm_constants=>gc_button-delete.
                  WHEN OTHERS.
                    ls_buttons-function = if_fpm_constants=>gc_button-other_function.
                ENDCASE.
                INSERT ls_buttons INTO TABLE lt_buttons.
              ENDLOOP.
              CLEAR ls_button_choice_ovp.
            ENDIF.
          ENDLOOP.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
* Identify change buttons(actions)
*--------------------------------------------------------------------*
  LOOP AT lt_buttons REFERENCE INTO lr_button.
    CLEAR lv_action_id.
    CASE lr_button->function.
      WHEN if_fpm_constants=>gc_button-activation_function.       "'ACTIVATION_FUNCTIONS'.
        IF mo_controller->ms_appconfig_settings-save_button_control = abap_true.
          IF lr_button->ON_ACTION eq 'FPM_SAVE'.
            IF mv_read_only eq ABAP_TRUE.
*       With new change mode concept
          lv_action_id = /bofu/if_fbi_runtime_c=>sc_events-read_only.
            else.
           lv_action_id = /bofu/if_fbi_runtime_c=>sc_events-read_only.
            mo_controller->MV_EDIT_UIBB_EXISTS = ABAP_TRUE.
            ENDIF.
            ELSE.
*              With new change mode concept
          lv_action_id = /bofu/if_fbi_runtime_c=>sc_events-read_only.
          ENDIF.
        ENDIF.
      WHEN if_fpm_constants=>gc_button-edit.
        IF mv_read_only eq ABAP_TRUE.                      "'EDIT'.
          lv_action_id = /bofu/if_fbi_runtime_c=>sc_events-edit.
        ELSE.
          lv_action_id = /bofu/if_fbi_runtime_c=>sc_events-edit.
          mo_controller->MV_EDIT_UIBB_EXISTS = ABAP_TRUE.
*     Use this flag to make EDIT button visible whenever there is a UIBB that is not READ-ONLY.
        ENDIF.
      WHEN if_fpm_constants=>gc_button-read_only.                 "'READ_ONLY'.
        lv_action_id = /bofu/if_fbi_runtime_c=>sc_events-read_only.
      WHEN if_fpm_constants=>gc_button-create.                    "'CREATE'.
        lv_action_id = /bofu/if_fbi_runtime_c=>sc_events-create.
      WHEN if_fpm_constants=>gc_button-delete.                    "'DELETE_OBJECT'.
        lv_action_id = /bofu/if_fbi_runtime_c=>sc_events-delete.
      WHEN if_fpm_constants=>gc_button-other_function.
        lv_action_id = lr_button->ON_ACTION.          "'OTHER_FUNCTIONS'.
          IF lr_button->ON_ACTION eq 'FPM_CANCEL' AND mv_read_only ne ABAP_TRUE.
            mo_controller->MV_EDIT_UIBB_EXISTS = ABAP_TRUE.
          ENDIF.
    ENDCASE.
    READ TABLE it_action_properties WITH TABLE KEY action = lv_action_id
                                    REFERENCE INTO lr_action_props.
    IF sy-subrc = 0.
         IF mo_controller->MV_EDIT_UIBB_EXISTS eq ABAP_TRUE AND ( lr_button->ON_ACTION eq 'FPM_SAVE' OR lr_button->ON_ACTION eq 'FPM_EDIT' OR lr_button->ON_ACTION eq 'FPM_CANCEL').
           lv_action_visibility = sc_action_visible.
         ELSE.
            IF lr_action_props->is_visible = abap_true.
        lv_action_visibility = sc_action_visible.
      ELSE.
        lv_action_visibility = sc_action_invisible.
           ENDIF.
         ENDIF.
      IF lr_button->enabled    <> lr_action_props->is_enabled OR
         lr_button->visibility <> lv_action_visibility.
        lr_button->enabled    = lr_action_props->is_enabled.
        lr_button->visibility = lv_action_visibility.
        INSERT lr_button->* INTO TABLE lt_change_buttons.
        CLEAR lv_action_visibility.
      ENDIF.
    ENDIF.
  ENDLOOP.
*Set action usage
*--------------------------------------------------------------------*
  IF lo_cnr_oif IS BOUND.
    LOOP AT lt_change_buttons INTO ls_change_buttons.
      IF ls_change_buttons-ch_element_id IS INITIAL.
        lo_cnr_oif->define_button(
          EXPORTING
            iv_function       = ls_change_buttons-function
            iv_element_id     = ls_change_buttons-element_id
            iv_enabled        = ls_change_buttons-enabled
            iv_on_action      = ls_change_buttons-on_action
            iv_visibility     = ls_change_buttons-visibility ).
      ELSE.
        INSERT ls_change_buttons INTO TABLE lt_ch_button_oif.
      ENDIF.
    ENDLOOP.
  ELSEIF lo_cnr_gaf IS BOUND.
    LOOP AT lt_change_buttons INTO ls_change_buttons.
      IF ls_change_buttons-function = if_fpm_constants=>gc_button-activation_function.
        ls_change_buttons-function = if_fpm_constants=>gc_button-finish.
      ENDIF.
      IF ls_change_buttons-ch_element_id IS INITIAL.
        lo_cnr_gaf->define_button(
          EXPORTING
            iv_function       = ls_change_buttons-function
            iv_element_id     = ls_change_buttons-element_id
            iv_enabled        = ls_change_buttons-enabled
            iv_on_action      = ls_change_buttons-on_action
            iv_visibility     = ls_change_buttons-visibility ).
      ELSE.
        INSERT ls_change_buttons INTO TABLE lt_ch_button_gaf.
      ENDIF.
    ENDLOOP.
  ELSEIF lo_cnr_ovp IS BOUND.
    LOOP AT lt_change_buttons INTO ls_change_buttons.
      READ TABLE lt_toolbar_ovp_button INTO ls_toolbar_ovp_button WITH KEY
        element_id = ls_change_buttons-element_id
        event_id = ls_change_buttons-on_action.
      IF sy-subrc = 0.
        ls_toolbar_ovp_button-enabled     = ls_change_buttons-enabled.
        ls_toolbar_ovp_button-visibility  = ls_change_buttons-visibility.
        TRY .
            lo_cnr_ovp->change_toolbar_button(
              EXPORTING
                iv_content_area             = ls_content_area-id
                is_toolbar_button           = ls_toolbar_ovp_button
                iv_override_existing_action = 'X' ).
          CATCH cx_fpm_floorplan.
        ENDTRY.
      ELSE.
        LOOP AT lt_ovp_button_choice REFERENCE INTO lr_ovp_button_choice.
          IF lr_ovp_button_choice->s_button_choice-element_id = ls_change_buttons-ch_element_id.
            READ TABLE lr_ovp_button_choice->el_sub_item WITH KEY
              event_id = ls_change_buttons-on_action REFERENCE INTO lr_el_sub_item.
            IF sy-subrc EQ 0.
              lr_el_sub_item->enabled     = ls_change_buttons-enabled.
              lr_el_sub_item->visibility  = ls_change_buttons-visibility.
            ENDIF.
          ENDIF.
          TRY .
              lo_cnr_ovp->change_toolbar_button_choice(
                  EXPORTING
                    iv_content_area               = ls_content_area-id
                    is_toolbar_button_choice      = lr_ovp_button_choice->s_button_choice
                    it_toolbar_button_choice_item = lr_ovp_button_choice->el_sub_item
                    iv_override_existing_action   = 'X' ).
            CATCH cx_fpm_floorplan.    " Floorplan exceptions
          ENDTRY.
        ENDLOOP.
      ENDIF.
    ENDLOOP.
  ENDIF.
*Set Action usage for button choice
*OIF
*--------------------------------------------------------------------*
  IF NOT lt_ch_button_oif IS INITIAL.
    SORT lt_ch_button_oif BY ch_element_id.
    LOOP AT lt_ch_button_oif INTO ls_change_buttons.
      IF lv_last_element_id <> ls_change_buttons-ch_element_id
        AND lv_last_element_id IS NOT INITIAL.
        IF NOT lt_menu_act_itm_oif IS INITIAL.
          LOOP AT lt_buttons INTO ls_buttons WHERE ch_element_id = lv_last_element_id.
            READ TABLE lt_menu_act_itm_oif WITH KEY on_action = ls_buttons-on_action
              TRANSPORTING NO FIELDS.
            IF sy-subrc NE 0.
              MOVE-CORRESPONDING ls_buttons TO ls_menu_act_itm_oif.
              ls_menu_act_itm_oif-visible = ls_buttons-visibility.
              INSERT ls_menu_act_itm_oif INTO TABLE lt_menu_act_itm_oif.
            ENDIF.
          ENDLOOP.
          READ TABLE lt_menu_act_itm_oif WITH KEY enabled = abap_true
                                              TRANSPORTING NO FIELDS.
          IF sy-subrc EQ 0.
            lv_oif_enabled = abap_true.
          ELSE.
            lv_oif_enabled = abap_false.
          ENDIF.
          READ TABLE lt_menu_act_itm_oif WITH KEY visible = sc_action_visible
                                              TRANSPORTING NO FIELDS.
          IF sy-subrc EQ 0.
            lv_oif_visible = sc_action_visible.
          ELSE.
            lv_oif_visible = sc_action_invisible.
          ENDIF.
          lo_cnr_oif->define_button_choice(
            EXPORTING
              iv_enabled                = lv_oif_enabled
              iv_visibility             = lv_oif_visible
              iv_function               = ls_change_buttons-function
              iv_element_id             = ls_change_buttons-element_id
              it_menu_action_items      = lt_menu_act_itm_oif ).
          lv_last_element_id = ls_change_buttons-ch_element_id.
          CLEAR: lt_menu_act_itm_oif, lv_oif_enabled, lv_oif_visible.
        ENDIF.
      ENDIF.
      CLEAR ls_menu_act_itm_oif.
      MOVE-CORRESPONDING ls_change_buttons TO ls_menu_act_itm_oif.
      ls_menu_act_itm_oif-visible = ls_change_buttons-visibility.
      INSERT ls_menu_act_itm_oif INTO TABLE lt_menu_act_itm_oif.
* ENDLOOP.
    IF NOT lt_menu_act_itm_oif IS INITIAL.
      lv_last_element_id = ls_change_buttons-ch_element_id.
      LOOP AT lt_buttons INTO ls_buttons WHERE ch_element_id = lv_last_element_id.
        READ TABLE lt_menu_act_itm_oif WITH KEY on_action = ls_buttons-on_action
          TRANSPORTING NO FIELDS.
        IF sy-subrc NE 0.
          MOVE-CORRESPONDING ls_buttons TO ls_menu_act_itm_oif.
          ls_menu_act_itm_oif-visible = ls_buttons-visibility.
          INSERT ls_menu_act_itm_oif INTO TABLE lt_menu_act_itm_oif.
        ENDIF.
      ENDLOOP.
      READ TABLE lt_menu_act_itm_oif WITH KEY enabled = abap_true
                                           TRANSPORTING NO FIELDS.
      IF sy-subrc EQ 0.
        lv_oif_enabled = abap_true.
      ELSE.
        lv_oif_enabled = abap_false.
      ENDIF.
      READ TABLE lt_menu_act_itm_oif WITH KEY visible = sc_action_visible
                                          TRANSPORTING NO FIELDS.
      IF sy-subrc EQ 0.
        lv_oif_visible = sc_action_visible.
      ELSE.
        lv_oif_visible = sc_action_invisible.
      ENDIF.
      lo_cnr_oif->define_button_choice(
        EXPORTING
          iv_enabled                = lv_oif_enabled
          iv_visibility             = lv_oif_visible
          iv_function               = ls_change_buttons-function
          iv_element_id             = ls_change_buttons-ch_element_id
          it_menu_action_items      = lt_menu_act_itm_oif ).
      CLEAR: lt_menu_act_itm_oif, lv_oif_enabled, lv_oif_visible.
    ENDIF.
    ENDLOOP.
*
  ENDIF.
*GAF
*--------------------------------------------------------------------*
  IF NOT lt_ch_button_gaf IS INITIAL.
    SORT lt_ch_button_gaf BY ch_element_id.
    LOOP AT lt_ch_button_oif INTO ls_change_buttons.
      IF lv_last_element_id <> ls_change_buttons-ch_element_id AND
         lv_last_element_id IS NOT INITIAL.
        IF NOT lt_menu_act_itm_gaf IS INITIAL.
          LOOP AT lt_buttons INTO ls_buttons WHERE ch_element_id = lv_last_element_id.
            READ TABLE lt_menu_act_itm_gaf WITH KEY on_action = ls_buttons-on_action
              TRANSPORTING NO FIELDS.
            IF sy-subrc NE 0.
              MOVE-CORRESPONDING ls_buttons TO ls_menu_act_itm_gaf.
              ls_menu_act_itm_gaf-visible = ls_buttons-visibility.
              INSERT ls_menu_act_itm_gaf INTO TABLE lt_menu_act_itm_gaf.
            ENDIF.
          ENDLOOP.
          READ TABLE lt_menu_act_itm_gaf WITH KEY enabled = abap_true
                                                TRANSPORTING NO FIELDS.
          IF sy-subrc EQ 0.
            lv_gaf_enabled = abap_true.
          ELSE.
            lv_gaf_enabled = abap_false.
          ENDIF.
          READ TABLE lt_menu_act_itm_gaf WITH KEY visible = sc_action_visible
                                          TRANSPORTING NO FIELDS.
          IF sy-subrc EQ 0.
            lv_gaf_visible = sc_action_visible.
          ELSE.
            lv_gaf_visible = sc_action_invisible.
          ENDIF.
          lo_cnr_gaf->define_button_choice(
            EXPORTING
              iv_enabled                = lv_gaf_enabled
              iv_visibility             = lv_gaf_visible
              iv_function               = ls_change_buttons-function
              iv_element_id             = ls_change_buttons-element_id
              it_menu_action_items      = lt_menu_act_itm_gaf ).
          lv_last_element_id = ls_change_buttons-ch_element_id.
          CLEAR: lt_menu_act_itm_gaf, lv_gaf_enabled, lv_gaf_visible.
        ENDIF.
      ENDIF.
      CLEAR ls_menu_act_itm_gaf.
      MOVE-CORRESPONDING ls_change_buttons TO ls_menu_act_itm_gaf.
      ls_menu_act_itm_gaf-visible = ls_change_buttons-visibility.
      INSERT ls_menu_act_itm_gaf INTO TABLE lt_menu_act_itm_gaf.
    ENDLOOP.
    IF NOT lt_menu_act_itm_gaf IS INITIAL.
      lv_last_element_id = ls_change_buttons-ch_element_id.
      LOOP AT lt_buttons INTO ls_buttons WHERE ch_element_id = lv_last_element_id.
        READ TABLE lt_menu_act_itm_gaf WITH KEY on_action = ls_buttons-on_action
          TRANSPORTING NO FIELDS.
        IF sy-subrc NE 0.
          MOVE-CORRESPONDING ls_buttons TO ls_menu_act_itm_gaf.
          ls_menu_act_itm_gaf-visible = ls_buttons-visibility.
          INSERT ls_menu_act_itm_gaf INTO TABLE lt_menu_act_itm_gaf.
        ENDIF.
      ENDLOOP.
      READ TABLE lt_menu_act_itm_gaf WITH KEY enabled = abap_true
       TRANSPORTING NO FIELDS.
      IF sy-subrc EQ 0.
        lv_gaf_enabled = abap_true.
      ELSE.
        lv_gaf_enabled = abap_false.
      ENDIF.
      READ TABLE lt_menu_act_itm_gaf WITH KEY visible = sc_action_visible
                                      TRANSPORTING NO FIELDS.
      IF sy-subrc EQ 0.
        lv_gaf_visible = sc_action_visible.
      ELSE.
        lv_gaf_visible = sc_action_invisible.
      ENDIF.
      lo_cnr_gaf->define_button_choice(
        EXPORTING
          iv_enabled                = lv_gaf_enabled
          iv_visibility             = lv_gaf_visible
          iv_function               = ls_change_buttons-function
          iv_element_id             = ls_change_buttons-element_id
          it_menu_action_items      = lt_menu_act_itm_gaf ).
      CLEAR: lt_menu_act_itm_gaf, lv_gaf_enabled.
    ENDIF.
  ENDIF.
ENDMETHOD.

搜索帮助

下拉列表

  METHOD if_fpm_guibb_search~get_definition.
    DATA: ls_field_descr  TYPE fpmgb_s_searchfield_descr,
          lt_fixed_values TYPE fpmgb_t_namevalue,
          ls_fixed_values TYPE fpmgb_s_namevalue,
          lt_comp_tab     TYPE abap_component_tab.

    IF mv_wd_configid = 'ZRRE_WDAC_PLAN_PERYEAR_SUMMARY'.
      eo_field_catalog_attr ?= cl_abap_structdescr=>describe_by_name( 'ZRRE_S_PLAN_SUM_S' ).
    ELSE.
      eo_field_catalog_attr ?= cl_abap_structdescr=>describe_by_name( 'ZRRE_S_PERYEAR_HEAD_S' ).
    ENDIF.
*    eo_field_catalog_attr ?= cl_abap_structdescr=>describe_by_name( 'ZRRE_S_PERYEAR_HEAD_S' ).
    " 设置字段属性及事件
    lt_comp_tab = eo_field_catalog_attr->get_components( ).

    LOOP AT  eo_field_catalog_attr->components INTO DATA(ls_component).
      CLEAR ls_field_descr.
      ls_field_descr-name          = ls_component-name.
      ls_field_descr-null_as_blank = abap_true.

      CASE ls_component-name.
        WHEN 'PLVER' OR 'PLSTA' OR 'PLTYP'.

          ls_field_descr-is_of_type = 'EN'."下拉列表
*          ls_field_descr-value_suggest = abap_true.
*          READ TABLE et_field_description_attr ASSIGNING FIELD-SYMBOL(<fs_field_des>) WITH KEY name = ls_component-name.
*          <fs_field_des>-ddic_shlp_name = ' ZCO_SH_PCITY_NAME '.
*          <fs_field_des>-mandatory = abap_true.


*          SELECT fin_type_code AS name,
*                 pay_mode AS value
*            INTO TABLE @ls_field_descr-enumeration
*            FROM zttr2101.
*          ls_field_descr-is_of_type    = 'EN'.
*          ls_field_descr-value_suggest = abap_true.
        WHEN 'ZMONTH'.
          DO 12 TIMES.
            ls_fixed_values-name = |{ sy-index }月|.
            ls_fixed_values-value = CONV num2( sy-index ).
            APPEND ls_fixed_values TO ls_field_descr-enumeration.
          ENDDO.
          APPEND INITIAL LINE TO lt_fixed_values.

          ls_field_descr-is_of_type = 'EN'."下拉列表
          ls_field_descr-value_suggest = abap_true.
        WHEN ''.

        WHEN OTHERS.
      ENDCASE.
      APPEND ls_field_descr TO et_field_description_attr.
      CLEAR ls_field_descr.
    ENDLOOP.

  ENDMETHOD.

自定义F4

​ 下拉列表说明中ls_field_descr-is_of_type = 'EN'.为空则为简单F4。复杂自定义F4可以使用下面的方法实现,这里可以实现联合搜索帮助(如:省市县等)

抬头信息页面

IF_FPM_GUIBB_OVS~HANDLE_PHASE_0

  METHOD if_fpm_guibb_ovs~handle_phase_0.

    DATA: ls_header_text TYPE string.
    DATA: ls_colunm_text TYPE wdr_name_value.
    DATA: lt_colunm_text TYPE wdr_name_value_list.
*&---------------------------------------------&*
*&   &1: field name                            &*
*&   &2: field value                           &*
*&---------------------------------------------&*
    DEFINE  add_col.
      ls_colunm_text-name = &1.
      ls_colunm_text-value = &2.
      APPEND ls_colunm_text TO lt_colunm_text.
      CLEAR ls_colunm_text.

    END-OF-DEFINITION.

    CASE iv_field_name.
      WHEN 'CONTRACTNO'."
        ls_header_text = text-001.
        add_col: 'CONNO' text-002,
                 'CONNM' text-003,
                 'CONEX'  text-004.
        CALL METHOD io_ovs_callback->set_configuration
          EXPORTING
            group_header       = ls_header_text
            column_texts       = lt_colunm_text
            col_count          = 2
            row_count          = 20.
      WHEN ''."Please add it yourself
      WHEN OTHERS.
    ENDCASE.
  ENDMETHOD.

IF_FPM_GUIBB_OVS~HANDLE_PHASE_1

"全局变量
types:
   BEGIN OF ts_contno,
       conno   TYPE /rer/contno,
       connm TYPE /rer/cont_name,
       conex      TYPE /rer/acont_no,
     END OF ts_contno .
method IF_FPM_GUIBB_OVS~HANDLE_PHASE_1.
  DATA: ls_contno TYPE ts_contno.

  CASE iv_field_name.
    WHEN 'CONTRACTNO'.
      io_ovs_callback->context_element->get_attribute(
            EXPORTING
            name  =  io_ovs_callback->context_attribute
            IMPORTING
            value =  ls_contno
            ).
      io_ovs_callback->set_input_structure( EXPORTING  input = ls_contno ).
  ENDCASE.
endmethod.

IF_FPM_GUIBB_OVS~HANDLE_PHASE_2

METHOD if_fpm_guibb_ovs~handle_phase_2.

  DATA: lt_contno TYPE tt_contno,
        ls_contno TYPE ts_contno,
        lr_root   TYPE REF TO data,
        ls_root   TYPE /rer/s_revision_root.

  DATA: lt_dd07t TYPE TABLE OF dd07t,
        ls_dd07t TYPE dd07t.

  DATA: lt_range_conno TYPE RANGE OF /rer/d_bo_conth-conno,
        ls_range_conno LIKE LINE OF lt_range_conno,
        lt_range_connm TYPE RANGE OF /rer/d_cont_root-contractname,
        ls_range_connm LIKE LINE OF lt_range_connm,
        lt_range_conex TYPE RANGE OF /rer/d_bo_conth-conex,
        ls_range_conex LIKE LINE OF lt_range_conex.

  FIELD-SYMBOLS: <fs_query_contno> TYPE ts_contno,
                 <fs_root>         TYPE any.

  CHECK mo_fpm IS NOT INITIAL.

  CREATE DATA lr_root TYPE /rer/s_revision_root.

  MOVE-CORRESPONDING /rer/cl_rev_fd_guibb_form=>ss_revision TO ls_root.

  CASE iv_field_name.
    WHEN 'CONTRACTNO'.
      ASSIGN io_ovs_callback->query_parameters->* TO <fs_query_contno>.

      IF <fs_query_contno>-conno IS NOT INITIAL.
        ls_range_conno-sign = /rer/if_constants=>sc_sign-including.
        ls_range_conno-option = /rer/if_constants=>sc_option-equal.
        ls_range_conno-low = <fs_query_contno>-conno.
        APPEND ls_range_conno TO lt_range_conno.
      ENDIF.

      IF <fs_query_contno>-conex IS NOT INITIAL.
        ls_range_conex-sign = /rer/if_constants=>sc_sign-including.
        ls_range_conex-option = /rer/if_constants=>sc_option-equal.
        ls_range_conex-low = <fs_query_contno>-conex.
        APPEND ls_range_conex TO lt_range_conex.
      ENDIF.

      IF <fs_query_contno>-connm IS NOT INITIAL.
        ls_range_connm-sign = /rer/if_constants=>sc_sign-including.
        ls_range_connm-option = /rer/if_constants=>sc_option-contains_pattern.
        ls_range_connm-low = <fs_query_contno>-connm.
        APPEND ls_range_connm TO lt_range_connm.
      ENDIF.

      SELECT conno connm conex
        INTO CORRESPONDING FIELDS OF TABLE lt_contno
        FROM /rer/d_bo_conth
        WHERE contcate = /rer/if_ccm_constants=>gc_contcate-main
          AND conno IN lt_range_conno
          AND conex IN lt_range_conex
          AND connm IN lt_range_connm
          AND prjid = ls_root-pspid
          AND prjph = ls_root-proj_ph
          AND appstatus = '40'
          AND constatus <> '05' "Exclude settled contracts
          AND constatus <> '06'
          AND delflag = abap_false.                "#EC CI_SUBRC"#EC CI_SUBRC

      SORT lt_contno BY conno DESCENDING.

      CALL METHOD io_ovs_callback->set_output_table
        EXPORTING
          output = lt_contno.
    WHEN OTHERS.

  ENDCASE.
ENDMETHOD.

IF_FPM_GUIBB_OVS~HANDLE_PHASE_3

method IF_FPM_GUIBB_OVS~HANDLE_PHASE_3.

  DATA: lv_name TYPE string.
  FIELD-SYMBOLS: <fs_selection> TYPE ts_contno.

  lv_name = iv_field_name.
  CASE iv_field_name.
    WHEN 'CONTRACTNO'.
      ASSIGN io_ovs_callback->selection->* TO <fs_selection> .
      IF <fs_selection> IS ASSIGNED.

        CALL METHOD io_ovs_callback->context_element->set_attribute(
            name  = lv_name
            value = <fs_selection>-conno ).

        CREATE OBJECT eo_fpm_event
          EXPORTING
            iv_event_id = 'FPM_GUIBB_LIST_CELL_ACTION'.
      ENDIF.
    WHEN ''."Please add it yourself
  ENDCASE.
endmethod.

弹出消息

(一)

ls_bapiret2         TYPE bapiret2,

MESSAGE s009(/rer/co).
ls_bapiret2-number = sy-msgno.
ls_bapiret2-type = sy-msgty.
ls_bapiret2-id = sy-msgid.
CALL METHOD mo_fpm->mo_message_manager->report_bapiret2_message
        EXPORTING
          is_bapiret2  = ls_bapiret2
          io_component = mo_fpm->mo_message_manager.

(二)

lt_message          TYPE        /bobf/t_frw_message_k,
ls_message          TYPE        /bobf/s_frw_message_k,
lo_message          TYPE REF TO /bobf/if_frw_message,
	CALL METHOD lo_tra_mgr->save
       IMPORTING
         eo_message = lo_message.
    IF lo_message IS NOT INITIAL.
      lo_message->get_messages( IMPORTING et_message = lt_message ).
    ENDIF.


	LOOP AT lt_message INTO ls_message.
        mo_fpm->mo_message_manager->report_object_message(
          EXPORTING
           ir_message_object = ls_message-message
           io_component = mo_fpm->mo_message_manager
        ).
    ENDLOOP.

(三)

MESSAGE e035(zrre_ccm) INTO lv_msg WITH ls_msg-msg_text.
CALL METHOD mo_fpm->mo_message_manager->report_t100_message
  EXPORTING
    iv_msgid       = sy-msgid
    iv_msgno       = sy-msgno
    iv_parameter_1 = sy-msgv1
    io_component   = me.
cv_result = 'FAILED'.

(四)

CALL METHOD mo_fpm->mo_message_manager->report_message
       EXPORTING
        iv_message_text = '非编辑模式,不允许导入数据!'
        io_component  = me
        iv_severity   = if_fpm_message_manager=>GC_SEVERITY_ERROR.

控制列表字段是否可输入

  "IF_FPM_GUIBB_LIST~GET_DATA中调用
  method UPDATE_FIELD_STATUS.
    FIELD-SYMBOLS: <fv_field> TYPE any,
                   <fv_value> TYPE any,
                   <ls_data> TYPE ANY,
                   <lt_data> TYPE ANY TABLE.


*    MOVE-CORRESPONDING cs_data TO ls_data.
    ASSIGN ct_data to <lt_data>.
*    READ TABLE <lt_data> ASSIGNING FIELD-SYMBOL(<ls_data>) INDEX 1.
*    READ TABLE mt_field_description ASSIGNING <fs_field_desc> WITH KEY name = <fs_field>-name.
    LOOP AT ct_field_usage ASSIGNING FIELD-SYMBOL(<fs_field>).
      CASE <fs_field>-name .
        WHEN 'JHTEXT'.
          READ TABLE mt_field_description ASSIGNING FIELD-SYMBOL(<fs_field_desc>) WITH KEY name = <fs_field>-name.
          ASSIGN COMPONENT 'READ_ONLY_REF' OF STRUCTURE <fs_field_desc> TO <fv_field>.
*          READ TABLE mt_field_description ASSIGNING <fs_field_desc> WITH KEY name = <fv_field>.
*          ASSIGN COMPONENT 'READ_ONLY' OF STRUCTURE <fs_field_desc> TO <fv_value>.

          LOOP AT <lt_data> ASSIGNING  <ls_data>.
            ASSIGN COMPONENT <fv_field> OF STRUCTURE <ls_data> TO <fv_value>.
            <fv_value> = abap_true.
          ENDLOOP.

*          ASSIGN COMPONENT <fv_field> OF STRUCTURE ls_data TO <fv_value>.

        WHEN OTHERS.
*          READ TABLE mt_field_description ASSIGNING <fs_field_desc> WITH KEY name = <fs_field>-name.

      ENDCASE.
    ENDLOOP.

	"ev_field_usage_changed = abap_true.
  endmethod.
  
  

控制表单字段读写状态

METHOD if_fpm_guibb_form~get_definition.
    DATA: lt_fixed_value TYPE wdr_context_attr_value_list,
          ls_fixed_value TYPE wdr_context_attr_value.

    CALL METHOD super->if_fpm_guibb_form~get_definition
      IMPORTING
        eo_field_catalog         = eo_field_catalog
        et_field_description     = et_field_description
        et_action_definition     = et_action_definition
        et_special_groups        = et_special_groups
        et_dnd_definition        = et_dnd_definition
        es_options               = es_options
        es_message               = es_message
        ev_additional_error_info = ev_additional_error_info.

    DATA(lv_year) = 2019.

    LOOP AT  et_field_description ASSIGNING FIELD-SYMBOL(<fs_desc>).
      CASE <fs_desc>-name.
        WHEN 'RYEAR'.
          DO 12 TIMES.
            lv_year = 1 + lv_year.
            ls_fixed_value-text = |{ lv_year }年|.
            ls_fixed_value-value = CONV num4( lv_year ).
            APPEND ls_fixed_value TO lt_fixed_value.
          ENDDO.
*          IF mv_change_mode  = 'R'."只读模式
            <fs_desc>-read_only = abap_true.
*          ENDIF.

          <fs_desc>-fixed_values = lt_fixed_value.
          CLEAR lt_fixed_value.
        WHEN 'PLVER'.
*          IF mv_change_mode  = 'R'."只读模式
            <fs_desc>-read_only = abap_true.
*          ENDIF.
        WHEN OTHERS.

      ENDCASE.
    ENDLOOP.
  ENDMETHOD.

弹出确认框

确认框取消后不会进入process_event,只有确认才会进,所以后续操作不能写在get_data中

 method IF_FPM_GUIBB_LIST_EXT~NEEDS_CONFIRMATION.
   DATA :lo_confirm TYPE REF TO cl_fpm_confirmation_request.
   DATA: lt_confirmation_text TYPE string_table.
"弹出数据已更改的警告框
"eo_confirmation_request = cl_fpm_confirmation_request=>go_data_loss.
   CASE io_event->mv_event_id.
     WHEN 'BTN_CONFIRM_BATCH'.
       APPEND '您确定要批量确认选中的年度计划?' TO  lt_confirmation_text.

     WHEN 'BTN_XD'.
       APPEND '您确定要下达选中的年度计划?' TO  lt_confirmation_text.

     WHEN 'BTN_BACK'.
       APPEND '您确定要退回选中的年度计划?' TO  lt_confirmation_text.
   ENDCASE.
   IF lt_confirmation_text IS NOT INITIAL.
     CREATE OBJECT lo_confirm
         EXPORTING
           it_confirmation_text = lt_confirmation_text.
     eo_confirmation_request = lo_confirm.
   ENDIF.

 endmethod.

刷新页面

*        mo_fpm->raise_event_by_id(
*          EXPORTING
*            iv_event_id   = 'FPM_REFRESH'                 " This defines the ID of the FPM Event
*        ).

mo_fpm

CALL TRANSFORMATION id SOURCE structure = ls_form
                              RESULT XML lv_xstr.
DATA(lv_base64) = cl_http_utility=>encode_x_base64( unencoded = lv_xstr ).
CLEAR: ls_app_param.
ls_app_param-key = 'FORM'.
ls_app_param-value = lv_base64.
APPEND ls_app_param TO lt_app_params.
              
mo_fpm ?= cl_fpm_factory=>get_instance( ).
mo_fpm->mo_app_parameter->get_value(
          EXPORTING
            iv_key   = 'CREATE_NEW'
          IMPORTING
            ev_value = ls_form