Floorplan Manager Codebeispiele (ABAP)

Aus MattWiki

Dieser Artikel zeigt beispielhafte Listings für verschiedene Methoden, die im Floorplan Manager benötigt werden.

Grundlegende Informationen sowie weitere Quellen finden sich in Floorplan Manager (ABAP)

IF_FPM_GUIBB_FORM

GET_DEFINITION - Grundform

Signatur der Methode:

EO_FIELD_CATALOG - Enthält Feldkatalog in Form eines Strukturtyps, der alle Komponenten umfasst, die als Felder im Formular verwendet werden können
ET_FIELD_DESCRIPTION - Liste mit Feldbeschreibungen und beschreibenden Informationen zu den einzelnen Feldern
ET_ACTION_DEFINITION - Liste mit möglichen Aktionen

Beispielhafte Befüllung der Description-Tabelle für Form-GUIBB mit dem Ziel, Warnungen im FLUID-Designer zu vermeiden:

  METHOD if_fpm_guibb_form~get_definition.

    DATA: ...

    CLEAR:...
 
    ...
    ...
    ...

    " Definition of field catalog
    eo_field_catalog ?= cl_abap_structdescr=>describe_by_name( p_name = 'Z_S_SELECTION' ).


    " Build list of field descriptions for FPM containing mostly only field names
    " in order to prevent warnings in FPM designer
    APPEND VALUE fpmgb_s_formfield_descr( name = 'FISCYEAR' ) TO et_field_description.
    APPEND VALUE fpmgb_s_formfield_descr( name = 'ZDOMUSER' ) TO et_field_description.
    APPEND VALUE fpmgb_s_formfield_descr( name = 'ZDOMUSERNAME' ) TO et_field_description.
  ENDMETHOD.

GET_DEFINITION mit Listen-Feld

  METHOD if_fpm_guibb_form~get_definition.

    DATA: lt_year_list  TYPE TABLE OF wdr_context_attr_value,
          ls_year_list  TYPE wdr_context_attr_value,
          ls_field_desc TYPE fpmgb_s_formfield_descr,
          lv_year       TYPE /bi0/oifiscyear.

    CLEAR: et_action_definition, et_special_groups, et_dnd_definition, es_options, es_message,
      ev_additional_error_info.

    " Definition of field catalog
    eo_field_catalog ?= cl_abap_structdescr=>describe_by_name( p_name = 'Z_S_CAR_SEL' ).

    lv_year = sy-datum(4).
    ls_year_list-text = lv_year.
    ls_year_list-value = lv_year.
    APPEND ls_year_list TO lt_year_list.

    lv_year = lv_year + 1.
    ls_year_list-text = lv_year.
    ls_year_list-value = lv_year.
    APPEND ls_year_list TO lt_year_list.

    " Definition of available fields
    " Fiscal year dropdown for actual and next year
    CLEAR ls_field_desc.
    ls_field_desc-name = 'FISCYEAR'.
    ls_field_desc-is_nullable = abap_false.
    ls_field_desc-fixed_values = lt_year_list.
    ls_field_desc-default_display_type = 'DD'.
    APPEND ls_field_desc TO et_field_description.

  ENDMETHOD.

GET_DEFINITON - Mit Action-Buttons, Textkonstanten und Symbolen

  METHOD if_fpm_guibb_form~get_definition.

    DATA: ls_action_def TYPE LINE OF fpmgb_t_actiondef.

    CLEAR: et_field_description, et_special_groups, et_dnd_definition,
      es_options, es_message, ev_additional_error_info.

    " Definition of field catalog
    eo_field_catalog ?= cl_abap_structdescr=>describe_by_name( p_name = 'Z_S_CAR_TRA' ).

    " Define properties of transfer button
    ls_action_def-id = GC_EVENT_BUTTON_TRANSFER.
    ls_action_def-text = TEXT-001.
    ls_action_def-tooltip = TEXT-001.
    ls_action_def-imagesrc = 'ICON_SYSTEM_SAVE'.
    ls_action_def-enabled = abap_true.
    APPEND ls_action_def TO et_action_definition.

  ENDMETHOD.


PROCESS_EVENT

  METHOD if_fpm_guibb_form~process_event.

    CLEAR: ev_result, et_messages.

    CASE io_event->mv_event_id.

        " Click on transfer data button
      WHEN gc_event_button_transfer.
 
 

      WHEN OTHERS.
        "Unbekanntes Event
    ENDCASE.

  ENDMETHOD.

IF_FPM_GUIBB_LIST

GET_DEFINITION - Mit Button und Read-Only-Spalten

  method IF_FPM_GUIBB_LIST~GET_DEFINITION.

    DATA: lt_field_cat   TYPE ztt_list,
          ls_field_descr TYPE LINE OF fpmgb_t_listfield_descr,
          ls_action_def  type line of fpmgb_t_actiondef.

    eo_field_catalog ?= cl_abap_tabledescr=>describe_by_data( lt_field_cat ).

    ls_field_descr-name = 'LFDNR'.
    ls_field_descr-read_only = abap_true.
    ls_field_descr-condense = 'X'.
    APPEND ls_field_descr TO et_field_description.

    ls_action_def-id = 'SAVEBUTTON'.
    ls_action_def-text = text-001.
    ls_action_def-tooltip = text-001.
    ls_action_def-imagesrc = 'ICON_SYSTEM_SAVE'.
    ls_action_def-enabled = abap_true.
    APPEND ls_action_def TO et_action_definition.
  endmethod.


GET_DEFINITION - Custom-Spaltenüberschriften

Zusätzlich: Felder mit individuellen Spaltenüberschriften sowie Editierbarkeit-Kennzeichen und Darstellung als Checkbox.

  METHOD if_fpm_guibb_list~get_definition.

    DATA: ...

    CLEAR:...
 
    ...
    ...
    ...

    " Definition of field catalog
    eo_field_catalog ?= cl_abap_structdescr=>describe_by_name( p_name = 'Z_TT_LIST' ).


    " Build list of field descriptions for FPM containing mostly only field names
    " in order to prevent warnings in FPM designer

    APPEND VALUE fpmgb_s_listfield_descr( name = 'ROW' technical_field = abap_true ) TO et_field_description.
    APPEND VALUE fpmgb_s_listfield_descr( name = 'ZKSTL_K' ) TO et_field_description.
    APPEND VALUE fpmgb_s_listfield_descr( name = 'ZKSTL_T' ) TO et_field_description.
    APPEND VALUE fpmgb_s_listfield_descr( name = 'ZKRS_K' ) TO et_field_description.
    APPEND VALUE fpmgb_s_listfield_descr( name = 'ZKRS_T' ) TO et_field_description.
    APPEND VALUE fpmgb_s_listfield_descr( name = 'ZBEM' ) TO et_field_description.
    APPEND VALUE fpmgb_s_listfield_descr( name = 'APPROVED' header_label = TEXT-001 ) TO et_field_description.
    APPEND VALUE fpmgb_s_listfield_descr( name = 'REJECTED' header_label = TEXT-002 ) TO et_field_description.
  ENDMETHOD.

FLUSH - Mit Verarbeitung von Change-Log

Nachfolgendes Listing führt Aktionen abhängig von Change-Log aus. Laut SAP sollen Änderungen der Daten aber nicht im Flush statt finden, sondern im Get_Data. Vermutlich ist dieses Listing daher nicht mustergültig, sondern müsste die zu ändernden Daten abhängig von den Eingaben aus dem Change-Log im Flush an das Get_Data übergeben, und dort verarbeiten.

METHOD if_fpm_guibb_list~flush.

    DATA: lr_new_val TYPE REF TO data,
          lv_carnr   TYPE /bic/oicarnr.

    FIELD-SYMBOLS: <lt_data>       TYPE z_tt_car_list,
                   <ls_list>       LIKE LINE OF mt_list,
                   <ls_change_log> LIKE LINE OF it_change_log,
                   <ls_new_val>    TYPE boolean.


    IF lines( it_change_log ) > 0.
      ASSIGN it_data->* TO <lt_data>.
      mt_list = <lt_data>.

      LOOP AT it_change_log ASSIGNING <ls_change_log>.

        " Find out which value was changed on the UI
        CASE <ls_change_log>-name.

          " Perform actions needed when
          " approved checkbox was clicked
          WHEN 'APPROVED'.
            CREATE DATA lr_new_val TYPE boolean.
            lr_new_val = <ls_change_log>-new_value.
            ASSIGN lr_new_val->* TO <ls_new_val>.

            READ TABLE mt_list ASSIGNING <ls_list> INDEX <ls_change_log>-line_index.
            IF sy-subrc = 0.
              lv_carnr = <ls_list>-carnr_k.

              IF <ls_new_val> = abap_true.
                LOOP AT mt_list ASSIGNING <ls_list> WHERE carnr_k = lv_carnr.
                  <ls_list>-approved = abap_true.
                  <ls_list>-rejected = abap_false.
                  <ls_list>-tl = MC_ICONS-green.
                ENDLOOP.
              ELSE.
                LOOP AT mt_list ASSIGNING <ls_list> WHERE carnr_k = lv_carnr.
                  <ls_list>-approved = abap_false.
                  <ls_list>-tl = MC_ICONS-yellow.
                ENDLOOP.
              ENDIF.

              me->mv_data_changed = abap_true.
            ENDIF.


          " Perform actions needed when
          " rejected checkbox was clicked
          WHEN 'REJECTED'.
            CREATE DATA lr_new_val TYPE boolean.
            lr_new_val = <ls_change_log>-new_value.
            ASSIGN lr_new_val->* TO <ls_new_val>.

            READ TABLE mt_list ASSIGNING <ls_list> INDEX <ls_change_log>-line_index.
            IF sy-subrc = 0.
              lv_carnr = <ls_list>-carnr_k.

              IF <ls_new_val> = abap_true.
                LOOP AT mt_list ASSIGNING <ls_list> WHERE carnr_k = lv_carnr.
                  <ls_list>-approved = abap_false.
                  <ls_list>-rejected = abap_true.
                  <ls_list>-tl = MC_ICONS-red.
                ENDLOOP.
              else.
                LOOP AT mt_list ASSIGNING <ls_list> WHERE carnr_k = lv_carnr.
                  <ls_list>-rejected = abap_false.
                  <ls_list>-tl = MC_ICONS-yellow.

                  " If the Car Nr. is approved right now this means
                  " that the Car Nr. was already approved.
                  " In this case the if the new value of the rejected field is false now
                  " it was true before. Therefore an already approved Car Nr.
                  " was rejected and un-rejected again and therefore needs to be
                  " shown as approved again.
                  IF <ls_list>-carst = z_if_constants=>sc_car_status-approved.
                    <ls_list>-approved = abap_true.
                    <ls_list>-tl = MC_ICONS-green.
                  ENDIF.
                ENDLOOP.
              ENDIF.
              me->mv_data_changed = abap_true.
            ENDIF.

          WHEN OTHERS.
            " No implementation

        ENDCASE.
      ENDLOOP.


    ENDIF.


  ENDMETHOD.