zoukankan      html  css  js  c++  java
  • 许多人推荐的sap关于ALV的教程样例(BCALV_EDIT_08)

    program bcalv_edit_08.
    *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    * Purpose:
    * ~~~~~~~~
    * This report implements an ALV Grid Control with an application
    * specific F4 help. The following aspects are dealth with:
    *  o how to replace the standard f4 help
    *     NOTE: This example uses a second ALV Grid Control to
    *           provide an application specific F4 help.
    *           This is probalbly NOT the usual way to
    *           provide such a functionality.
    *           However, the purpose of this report is not to
    *           show you how to implement an F4 help, but to
    *           explain how you pass the selected value to ALV,
    *           how you take values of other cells into account, etc.
    *           For this purpose, it does not matter how the f4 help
    *           is actually implemented.
    *
    *  o how to pass the selected value to the ALV Grid Control
    *  o how to build an f4 help, whose value range depend on
    *    a value of another cell.
    *-----------------------------------------------------------------
    * To check program behavior
    * ~~~~~~~~~~~~~~~~~~~~~~~~~
    * We use table SBOOK with columns CLASS and SMOKER ready for input.
    * The idea of this scenario is that it is only allowed to smoke
    * in the first class (value 'F' of field CLASS).
    * The application specific f4 help can be called for column CLASS:
    * o if the value of column SMOKER in the same row is 'X', only class
    *   'F' can be chosen
    * o if the value of column SMOKER in the same row is ' ', all
    *   classes are allowed ('F','C','Y'). Thus, the f4 help shows all
    *   values.
    * o if the value of column SMOKER in the same row is not valid
    *   (syntactically or semantically), a message is shown and
    *   no f4 help pops up.
    *-----------------------------------------------------------------
    * Essential steps (search for '§')
    * ~~~~~~~~~~~~~~~
    * Note that this report is rather long because the columns CLASS and
    * SMOKER are checked semantically which does not belong to the f4 help
    * implementation. Class lcl_application_dc handles semantic checks.
    * Local class lcl_application_f4 handles event ONF4 to build up
    * the f4 help, to pass the value to the ALV Grid Control and
    * to check whether the value of the SMOKER column is valid.
    *
    * 1. Register event ONF4 at frontend using method
    *    register_f4_for_fields. For this purpose, you pass a table
    *    with all fields, for which you want to implement your own
    *    f4 help.
    *   1b. If the value range in your f4 help depends on other
    *       values of cells that are input enabled, set the
    *       GETBEFORE parameter.
    * 2. Implement an event handler method for event ONF4.
    * 3. Call your own f4 help. To customize your popup check
    *    first if the cell is ready for input (event parameter E_DISPLAY).
    * 4. Check whether the value your f4 help depends on is valid.
    * 5. If not already caught by your own f4 help, check whether
    *    the triggered cell was ready for input by using E_DISPLAY
    *    and if not, exit.
    * 6. After the user selected a value, pass it to the ALV Grid Control:
    *   6a. Define a field symbol of type: LVC_T_MODI and a structure of
    *       type LVC_S_MODI to pass the value later on.
    *   6b. Dereference attribute M_DATA to your field symbol and add
    *       the selected value to the table to which this symbol points to.
    * 7. Inform the ALV Grid Control that an own f4 help has been processed
    *    to suppress the standard f4 help.
    *-----------------------------------------------------------------------
    *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

    data: ok_code like sy-ucomm,
          save_ok like sy-ucomm,
          g_container type scrfname value 'CC1',
          g_grid  type ref to cl_gui_alv_grid,
          g_custom_container type ref to cl_gui_custom_container,
          gt_fieldcat type lvc_t_fcat,
           g_max type i value 100.

    class lcl_application_f4 definition deferred.
    class lcl_application_dc definition deferred.


    data: g_onf4 type ref to lcl_application_f4,
          g_dc type ref to lcl_application_dc.


    data: gt_outtab type table of sbook.

    ****************************************************************
    * LOCAL CLASSES: Definition
    ****************************************************************
    *===============================================================
    * class lcl_application_f4: local class to handle own F4.
    *
    * Definition:
    * ~~~~~~~~~~~
    class lcl_application_f4 definition.

      public section.
        methods:

                 on_f4 for event onf4 of cl_gui_alv_grid
                   importing e_fieldname
                             es_row_no
                             er_event_data
                             et_bad_cells
                             e_display.

        methods: reset.
        methods: show_f4.

      private section.
    **
    * attributes for creating an own F4-Help
    * (using a second ALV Grid Control
    **
        data: f4_alv type ref to cl_gui_alv_grid,
              f4_cont type ref to cl_gui_custom_container.

        types: begin of f4_itab_type.
        types: value type s_class.
        types: descr(20) type c.
        types: end of f4_itab_type.

        data: f4_itab type table of f4_itab_type.
        data: fieldcatalog type lvc_t_fcat.

    **
    * attributes to store event parameters
    * (after the CALL SCREEN command, the event parameters
    * are not accessible)
    **
        types: begin of onf4_event_parameters_type.
        types: c_fieldname     type lvc_fname.
        types: cs_row_no       type lvc_s_roid.
        types: cr_event_data   type ref to cl_alv_event_data.
        types: ct_bad_cells    type lvc_t_modi.
        types: c_display       type char01.
        types: end of onf4_event_parameters_type.

        data: f4_params type onf4_event_parameters_type.


    **
    * Methods to create own F4-Help
    * (This is done using a second ALV Grid Control)
    **
        methods: init_f4.

        methods: build_fieldcatalog.
        methods: fill_f4_itab importing smoker type c.

        methods: on_double_click for event double_click of cl_gui_alv_grid
                        importing es_row_no.

    **
    * Methods to check whether the values which the F4-Help needs
    * are correct
    * (The entries of the F4-Help of field CLASS depend on the value
    * of field SMOKER. If field SMOKER of the same row is syntaktically
    * or semantically not correct, this has to be handled during ONF4.
    **
        methods: smoker_cell_is_bad
                    returning value(r_flag) type i.

    endclass.                    "lcl_application_f4 DEFINITION
    *
    * lcl_application_f4 (Definition)
    *===============================================================
    * class lcl_application_dc: local class to handle event data_changed.
    *
    * Definition:
    * ~~~~~~~~~~~
    class lcl_application_dc definition.

      public section.

        methods: handle_data_changed
                   for event data_changed of cl_gui_alv_grid
                      importing er_data_changed
                                e_onf4 e_onf4_before e_onf4_after.

      private section.

    * This flag is set if any error occured in one of the
    * following methods:
        data: error_in_data type c.

        methods:
         perform_semantic_checks
           importing
             pr_data_changed type ref to cl_alv_changed_data_protocol.

        methods: check_smoker
         importing
            ps_good_smoker type lvc_s_modi
            pr_data_changed type ref to cl_alv_changed_data_protocol.

        methods: check_class
         importing
            ps_good_class type lvc_s_modi
            pr_data_changed type ref to cl_alv_changed_data_protocol.

    endclass.                    "lcl_application_dc DEFINITION
    *
    * lcl_application_dc (Definition)
    *===============================================================


    ****************************************************************
    * LOCAL CLASSES: Implementation
    ****************************************************************
    *===============================================================
    * class lcl_application_f4 (Implementation)
    *
    class lcl_application_f4 implementation.

    *§2. Implement an event handler method for event ONF4.

      method on_f4.

    * Save event parameter as global attributes of this class
    * (maybe solved differently if you use a function module!)
        f4_params-c_fieldname = e_fieldname.
        f4_params-cs_row_no = es_row_no.
        f4_params-cr_event_data = er_event_data.
        f4_params-ct_bad_cells = et_bad_cells.
        f4_params-c_display = e_display.

    *§3. Call your own f4 help. To customize your popup check
    *    first if the cell is ready for input (event parameter E_DISPLAY).
    * (parameter E_DISPLAY is checked later in method on_double_click)

    * (Probably, you would call a function module at this point,
    * pass the needed event parameter and call the popup screen
    * within that function module. This is not done in this example
    * to avoid scattering its code).

        call screen 101 starting at 10 10.

    *§7. Inform the ALV Grid Control that an own f4 help has been processed
    *    to suppress the standard f4 help.

        er_event_data->m_event_handled = 'X'.
      endmethod.                                                "on_f4
    *---------------------------------------------------------------------
      method show_f4.
        data: ls_outtab type sbook.

    * initialize own f4 help if needed
        if f4_cont is initial.
          call method init_f4.
        endif.

    *§4. Check whether the value your f4 help depends on is valid.

    * The possible values of field CLASS depend on
    * the value of field SMOKER of the same row.
    * You have to check that this value is valid:
        if smoker_cell_is_bad( ) eq 1.
          leave screen.
        endif.

    * determine value of column SMOKER and use appropriate f4 table
        read table gt_outtab into ls_outtab index f4_params-cs_row_no-row_id
    .
        call method fill_f4_itab( ls_outtab-smoker ).

    * refresh list of values in f4 help and show it
        call method f4_alv->refresh_table_display.
    * CAUTION: Do not use method REFRESH_TABLE_DISPLAY for
    * your editable ALV Grid instances while handling events
    * DATA_CHANGED or ONf4. You would overwrite intermediate
    * values of your output table on frontend.
    * 'f4_alv' is a non-editable ALV Grid Control for the
    * application specific F4-Help. Therefore, calling
    * REFRESH_TABLE_DISPLAY for this instance has no
    * negative effect.

        call method cl_gui_cfw=>flush.
      endmethod.                                                "show_f4

    *--------------------------------------------------------------------

      method init_f4.
        data: ls_layout type lvc_s_layo.
    * build fieldcatalog entries for f4
        call method build_fieldcatalog.

    * create controls
        create object f4_cont
                  exporting container_name = 'CC_ONF4'.

        create object f4_alv
                  exporting i_parent = f4_cont.

    * hide toolbar
        ls_layout-no_toolbar = 'X'.

        call method f4_alv->set_table_for_first_display
          exporting
            is_layout       = ls_layout
          changing
            it_fieldcatalog = fieldcatalog
            it_outtab       = f4_itab.

    * register event double click on backend
        set handler me->on_double_click for f4_alv.

    * flush since 'ls_layout' is local!
        call method cl_gui_cfw=>flush.

      endmethod.                                                "init_f4
    *-----------------------------------------------------
      method fill_f4_itab.
        data ls_f4_itab type f4_itab_type.

    * Delete all entries in f4_itab to determine
    * offered values dynamically
        clear f4_itab[].
    * create entries depending on SMOKER field
        if smoker is initial.
          ls_f4_itab-value = 'C'.
          ls_f4_itab-descr = text-t03. "Business Class
          append ls_f4_itab to f4_itab.
          ls_f4_itab-value = 'Y'.
          ls_f4_itab-descr = text-t04. "Economie Class
          append ls_f4_itab to f4_itab.
          ls_f4_itab-value = 'F'.
          ls_f4_itab-descr = text-t05. "First Class
          append ls_f4_itab to f4_itab.
        else.
          ls_f4_itab-value = 'F'.
          ls_f4_itab-descr = text-t05. "First Class
          append ls_f4_itab to f4_itab.
        endif.
      endmethod.                    "fill_f4_itab
    *----------------------------------------------------
      method build_fieldcatalog.
        data: ls_fcat type lvc_s_fcat.

        clear ls_fcat.
        ls_fcat-fieldname = 'VALUE'.
        ls_fcat-coltext = text-t02.
        ls_fcat-inttype = 'S_CLASS'.
        ls_fcat-outputlen = 5.
        append ls_fcat to fieldcatalog.
        clear ls_fcat.
        ls_fcat-fieldname = 'DESCR'.
        ls_fcat-coltext = text-t01.
        ls_fcat-inttype = 'C'.
        ls_fcat-outputlen = 20.
        append ls_fcat to fieldcatalog.
      endmethod.                    "build_fieldcatalog
    *-----------------------------------------------------
      method on_double_click.

    *§5. If not already caught by your own f4 help, check whether
    *    the triggered cell was ready for input by using E_DISPLAY
    *    and if not, exit.
        if f4_params-c_display eq 'X'.
          leave screen.
        endif.

    *§6. After the user selected a value, pass it to the ALV Grid Control:

    *§  6a. Define a field symbol of type: LVC_T_MODI and a structure of
    *       type LVC_S_MODI to pass the value later on.
        field-symbols <itab> type lvc_t_modi.
        data: ls_modi type lvc_s_modi,
              ls_f4_itab type f4_itab_type.

    *§  6b. Dereference attribute M_DATA into your field symbol and add
    *       the selected value to the table to which this symbol points to.
        assign f4_params-cr_event_data->m_data->* to <itab>.
        ls_modi-row_id = f4_params-cs_row_no-row_id.
        ls_modi-fieldname = f4_params-c_fieldname.

        read table f4_itab into ls_f4_itab index es_row_no-row_id.

        ls_modi-value = ls_f4_itab-value.
        append ls_modi to <itab>.

        leave screen.
      endmethod.                    "on_double_click
    *-----------------------------------------------------
      method reset.
        field-symbols <itab> type lvc_t_modi.

        assign f4_params-cr_event_data->m_data->* to <itab>.
        clear <itab>[].
      endmethod.                    "reset
    *-----------------------------------------------------
      method smoker_cell_is_bad.
        data: ls_bad_cell type lvc_s_modi. "#EC NEEDED

        r_flag = 0. "no error initially

    * Determine if value of smoker cell of the same
    * row has a bad value. If so, a message pops up
    * instead of our F4 help.
        read table f4_params-ct_bad_cells into ls_bad_cell
            with key fieldname = 'SMOKER'
                     row_id    = f4_params-cs_row_no-row_id.
        if sy-subrc eq 0.
            r_flag = 1.
            message i000(0k) with text-i01 text-i02.
    * NOTE: Although there is a bad value present
    *       the ALV Grid Control shows no error protocol.
    *       However, the bad value is saved in the
    *       protocol and event DATA_CHANGED_FINISHED is
    *       not raised.
        endif.

      endmethod.                    "smoker_cell_is_bad
    *=====================================================


    endclass.                    "lcl_application_f4 IMPLEMENTATION

    *
    * lcl_application_f4 (Implementation)
    *===================================================================

    *===============================================================
    * class lcl_application_dc (Implementation)
    *
    class lcl_application_dc implementation.
      method handle_data_changed.
    *
        error_in_data = space.

    * Distinguish, if DATA_CHANGED was raised because of an
    * own F4-help.
    * Event DATA_CHANGED provides parameter E_ONF4
    * for this purpose.
        if not e_onf4 is initial.
    * Add your special handling here if needed.
    * Event DATA_CHANGED provides parameters E_ONF4_AFTER
    * and E_ONF4_BEFORE to distinguish the context
    * additionally.

    * In general, semantic checks should be the same no matter if
    * they have been entered by hand or using an application
    * specific F4 help. So you probably do not need these parameters.
        else.
          call method perform_semantic_checks( er_data_changed ).
        endif.

        if error_in_data = 'X'.
          call method er_data_changed->display_protocol.
        endif.

      endmethod.                    "handle_data_changed
    *------------------------------------
    * private methods
    *------------------------------------
      method perform_semantic_checks.
    *
    * In this snenario, only values of cells in columns CLASS or SMOKER
    * can be changed. These fields have a value range defined
    * in the ABAP dictionary.
    * Thus, after ALVs syntaktical check, we only need to
    * check if the user tried to enter a smoker seat for
    * a class other than 'F' or vice versa.
    *
        data: ls_good type lvc_s_modi.

        loop at pr_data_changed->mt_good_cells into ls_good.
          case ls_good-fieldname.
            when 'SMOKER'.
              call method check_smoker
                exporting
                  ps_good_smoker  = ls_good
                  pr_data_changed = pr_data_changed.

            when 'CLASS'.
              call method check_class
                exporting
                  ps_good_class   = ls_good
                  pr_data_changed = pr_data_changed.
          endcase.
        endloop.

      endmethod.                    "perform_semantic_checks
    *--------------------------------------
      method check_smoker.
        data: l_smoker type s_smoker,
              l_class  type s_class,
              ls_outtab type sbook,
              ls_good_class type lvc_s_modi. "#EC NEEDED

    * first get value of smoker cell:
        call method pr_data_changed->get_cell_value
          exporting
            i_row_id    = ps_good_smoker-row_id
            i_fieldname = ps_good_smoker-fieldname
          importing
            e_value     = l_smoker.

    * If it's a non smoker there is no problem at all
    * because every value of CLASS shall be possible then.
        if l_smoker is initial.
          exit.
        endif.

    * If not, value of cell CLASS has to be 'F'.
    * First check if the value of field CLASS has been
    * changed/entered newly, too:
        read table pr_data_changed->mt_good_cells into ls_good_class
                            with key row_id    = ps_good_smoker-row_id
                                     fieldname = 'CLASS'.
        if sy-subrc eq 0.
    * get that new value:
          call method pr_data_changed->get_cell_value
            exporting
              i_row_id    = ps_good_smoker-row_id
              i_fieldname = 'CLASS'
            importing
              e_value     = l_class.
        else.
    * get current value
          read table gt_outtab into ls_outtab index ps_good_smoker-row_id.
          l_class = ls_outtab-class.
        endif.

    * Since we have a smoker his class has to be 'F':
        if l_class ne 'F'.
          call method pr_data_changed->add_protocol_entry
            exporting
              i_msgid     = '0K'
              i_msgno     = '000'
              i_msgty     = 'E'
              i_msgv1     = text-m01           "Klasse
              i_msgv2     = l_class
              i_msgv3     = text-m02           "nicht erlaubt für Raucher
              i_fieldname = ps_good_smoker-fieldname
              i_row_id    = ps_good_smoker-row_id.

          error_in_data = 'X'.
        endif.
      endmethod.                    "check_smoker
    *--------------------------------------
      method check_class.
          data: l_smoker type s_smoker,
                l_class  type s_class,
                ls_outtab type sbook,
                ls_good_smoker type lvc_s_modi. "#EC NEEDED

    * first get value of class cell:
        call method pr_data_changed->get_cell_value
          exporting
            i_row_id    = ps_good_class-row_id
            i_fieldname = ps_good_class-fieldname
          importing
            e_value     = l_class.

    * If it's CLASS 'F' there is no problem at all
    * because every value of SMOKER shall be possible then.
        if l_class eq 'F'.
          exit.
        endif.

    * If not, value of cell SMOKER has to be initial.
    * First check if the value of field CLASS has been
    * changed/entered newly, too:
        read table pr_data_changed->mt_good_cells into ls_good_smoker
                            with key row_id    = ps_good_class-row_id
                                     fieldname = 'SMOKER'.
        if sy-subrc eq 0.
    * get that new value:
          call method pr_data_changed->get_cell_value
            exporting
              i_row_id    = ps_good_class-row_id
              i_fieldname = 'SMOKER'
            importing
              e_value     = l_smoker.
        else.
    * get current value
          read table gt_outtab into ls_outtab index ps_good_class-row_id.
          l_smoker = ls_outtab-smoker.
        endif.

    * Since the class is not 'F' it has to be a non smoking person:
        if not l_smoker is initial.
          call method pr_data_changed->add_protocol_entry
            exporting
              i_msgid     = '0K'
              i_msgno     = '000'
              i_msgty     = 'W'
              i_msgv1     = text-m03         "Als Raucher dürfen Sie Klasse
              i_msgv2     = l_class
              i_msgv3     = text-m04         "nicht buchen
              i_fieldname = ps_good_class-fieldname
              i_row_id    = ps_good_class-row_id.

          error_in_data = 'X'.
        endif.

      endmethod.                    "check_class
    *--------------------------------------
    endclass.                    "lcl_application_dc IMPLEMENTATION
    ***********************************************************************

    *---------------------------------------------------------------------*
    *       MAIN                                                          *
    *---------------------------------------------------------------------*
    end-of-selection.
      call screen 100.

    *---------------------------------------------------------------------*
    *       MODULE PBO OUTPUT                                             *
    *---------------------------------------------------------------------*
    module pbo output.
      set pf-status 'MAIN100'.
      set titlebar 'MAIN100'.
      if g_custom_container is initial.
        perform create_and_init_alv changing gt_outtab[]
                                             gt_fieldcat.
      endif.

    endmodule.                    "pbo OUTPUT
    *---------------------------------------------------------------------*
    *       MODULE PAI INPUT                                              *
    *---------------------------------------------------------------------*
    module pai input.
      save_ok = ok_code.
      clear ok_code.
      case save_ok.
        when 'EXIT'.
          perform exit_program.
        when 'SWITCH'.
          perform switch_edit_mode.
        when others.
    *     do nothing
      endcase.
    endmodule.                    "pai INPUT
    *---------------------------------------------------------------------*
    *       FORM EXIT_PROGRAM                                             *
    *---------------------------------------------------------------------*
    form exit_program.
      leave program.
    endform.                    "exit_program
    *&---------------------------------------------------------------------*
    *&      Form  BUILD_FIELDCAT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      <--P_GT_FIELDCAT  text
    *----------------------------------------------------------------------*
    form build_fieldcat changing pt_fieldcat type lvc_t_fcat.

      data ls_fcat type lvc_s_fcat.

      call function 'LVC_FIELDCATALOG_MERGE'
        exporting
          i_structure_name = 'SBOOK'
        changing
          ct_fieldcat      = pt_fieldcat.

      loop at pt_fieldcat into ls_fcat.
    * Exchange smoker field with invoice field - just to
    * make the dependance between SMOKER and CLASS more transparent
    * (Smoking is only allowed in the first class).
        if ls_fcat-fieldname eq 'SMOKER'.
          ls_fcat-col_pos = 11.
          ls_fcat-outputlen = 10.
          ls_fcat-edit = 'X'.
    * Field 'checktable' is set to avoid shortdumps that are caused
    * by inconsistend data in check tables. You may comment this out
    * when the test data of the flight model is consistent in your system.
          ls_fcat-checktable = '!'.        "do not check foreign keys

          modify pt_fieldcat from ls_fcat.

        elseif ls_fcat-fieldname eq 'INVOICE'.
          ls_fcat-col_pos = 7.
          modify pt_fieldcat from ls_fcat.

        elseif    ls_fcat-fieldname eq 'CLASS'.

          ls_fcat-edit = 'X'.
          ls_fcat-outputlen = 5.
          ls_fcat-checktable = '!'.        "do not check foreign keys

          modify pt_fieldcat from ls_fcat.
        endif.
      endloop.

    endform.                    "build_fieldcat
    *&---------------------------------------------------------------------*
    *&      Form  CREATE_AND_INIT_ALV
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      <--P_GT_OUTTAB  text
    *      <--P_GT_FIELDCAT  text
    *      <--P_GS_LAYOUT  text
    *----------------------------------------------------------------------*
    form create_and_init_alv changing pt_outtab type standard table
                                      pt_fieldcat type lvc_t_fcat.

      data: lt_exclude type ui_functions.

      create object g_custom_container
              exporting container_name = g_container.
      create object g_grid
             exporting i_parent = g_custom_container.

      perform build_fieldcat changing pt_fieldcat.

    * Optionally restrict generic functions to 'change only'.
    *   (The user shall not be able to add new lines).
      perform exclude_tb_functions changing lt_exclude.

      perform build_data changing pt_outtab.

      call method g_grid->set_table_for_first_display
        exporting
          it_toolbar_excluding = lt_exclude
        changing
          it_fieldcatalog      = pt_fieldcat
          it_outtab            = pt_outtab[].

    * register f4 for field CLASS
      perform register_events.

    * Set editable cells to ready for input initially
      call method g_grid->set_ready_for_input
        exporting
          i_ready_for_input = 1.

    endform.                               "CREATE_AND_INIT_ALV

    *&---------------------------------------------------------------------*
    *&      Form  EXCLUDE_TB_FUNCTIONS
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      <--P_LT_EXCLUDE  text
    *----------------------------------------------------------------------*
    form exclude_tb_functions changing pt_exclude type ui_functions.
    * Only allow to change data not to create new entries (exclude
    * generic functions).

      data ls_exclude type ui_func.

      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
      append ls_exclude to pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
      append ls_exclude to pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
      append ls_exclude to pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
      append ls_exclude to pt_exclude.
      ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
      append ls_exclude to pt_exclude.

    endform.                               " EXCLUDE_TB_FUNCTIONS
    *&---------------------------------------------------------------------*
    *&      Form  build_data
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    form build_data changing pt_outtab type standard table.
      data: ls_sbook type sbook,
            l_index type i.

      select * from sbook into table gt_outtab up to g_max rows.
      if sy-subrc ne 0.
        perform generate_entries changing pt_outtab.
      endif.

      loop at pt_outtab into ls_sbook.
        l_index = sy-tabix.
        clear ls_sbook-class.
    * Alternate between smoker and non smoker to make
    * it more obvious what this example is about
        l_index = l_index mod 2.
        if l_index eq 1.
          ls_sbook-smoker = 'X'.
        else.
          ls_sbook-smoker = ' '.
        endif.
        modify pt_outtab from ls_sbook.
      endloop.

    endform.                               " build_data

    *&---------------------------------------------------------------------*
    *&      Form  generate_entries
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      <--P_LT_SLFIGHT  text
    *----------------------------------------------------------------------*
    form generate_entries changing pt_sbook type standard table.
      data: ls_sbook type sbook,
            l_month(2) type c,
            l_day(2) type c,
            l_date(8) type c,
     l_prebookid type i.


      ls_sbook-carrid = 'LH'.
      ls_sbook-connid = '0400'.
      ls_sbook-forcurkey = 'DEM'.
      ls_sbook-loccurkey = 'USD'.
      ls_sbook-custtype = 'B'.

      do 110 times.
        l_prebookid = sy-index.

        ls_sbook-forcuram = sy-index * 10.
        ls_sbook-loccuram = ls_sbook-loccuram * 2.
        ls_sbook-customid = sy-index.
        ls_sbook-counter = 18.
        ls_sbook-agencynum = 11.

        l_month = sy-index / 10 + 1.
        do 2 times.
          l_day = 3 + l_month + sy-index * 2.
          l_date+0(4) = '2000'.
          l_date+4(2) = l_month.
          l_date+6(2) = l_day.
          ls_sbook-fldate = l_date.
          subtract 3 from l_day.
          ls_sbook-order_date+0(6) = l_date+0(6).
          ls_sbook-order_date+6(2) = l_day.
          ls_sbook-bookid = l_prebookid * 2 + sy-index.
          if sy-index eq 1.
            ls_sbook-smoker = 'X'.
          else.
            ls_sbook-smoker = space.
          endif.

          ls_sbook-luggweight = l_prebookid * 10.
          if ls_sbook-luggweight ge 1000.
            ls_sbook-wunit = 'G'.
            ls_sbook-class = 'C'.
          else.
            ls_sbook-wunit = 'KG'.
            ls_sbook-class = 'Y'.
          endif.

          if ls_sbook-bookid > 40 and ls_sbook-wunit eq 'KG'.
            ls_sbook-invoice = 'X'.
          endif.
          if ls_sbook-bookid eq 2.
            ls_sbook-cancelled = 'X'.
            ls_sbook-class = 'F'.
          endif.

          append ls_sbook to pt_sbook.
        enddo.
      enddo.
    endform.                               " generate_entries
    *&---------------------------------------------------------------------*
    *&      Form  register_events
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    form register_events.
    *§1. Register event ONF4 at frontend using method
    *    register_f4_for_fields. For this purpose, you pass a table
    *    with all fields, for which you want to implement your own
    *    f4 help.

    * remark: If you want to use an own f4 help for fields where
    *         no standard f4 help exists set field F4AVAILABL for
    *         this field in the fieldcatalog.
      data: lt_f4 type lvc_t_f4 with header line.

      clear lt_f4.
      lt_f4-fieldname = 'CLASS'.
    * If you would like to deregister the field again,
    * pass value SPACE with field 'register'.
      lt_f4-register = 'X'.
    *§  1b. If the value range in your f4 help depends on other
    *       values of cells that are input enabled, set the
    *       GETBEFORE parameter.
    * The consequence is that the ALV Grid Control raises
    * event DATA_CHANGED before the f4 help is called to
    * check values that the f4 help depends on.
      lt_f4-getbefore = 'X'.
    * The next parameter is used to change values after onf4 has
    * been processed. The ALV Grid Control will raise
    * event DATA_CHANGED afterwards, if you set it.
      lt_f4-chngeafter = space.
      insert table lt_f4.

      call method g_grid->register_f4_for_fields
        exporting
          it_f4 = lt_f4[].

    * register events for abap objects (backend)
      create object g_onf4.
      set handler g_onf4->on_f4 for g_grid.

      create object g_dc.
      set handler g_dc->handle_data_changed for g_grid.

    endform.                    " register_events
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_0101  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    module status_0101 output.
      set pf-status 'POPUP'.
      set titlebar 'POPUP'.
      call method g_onf4->show_f4.
    endmodule.                 " STATUS_0101  OUTPUT
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_0101  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    module user_command_0101 input.
      perform user_command.
    endmodule.                 " USER_COMMAND_0101  INPUT
    *&---------------------------------------------------------------------*
    *&      Form  user_command
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    form user_command.

      data: save_ok type sy-ucomm.

      save_ok = ok_code.
      clear ok_code.
      case save_ok.
        when 'CANCEL'.
          call method g_onf4->reset.
          leave screen.
      endcase.

    endform.                    " user_command
    *-------------------------------------------------------------------
    form switch_edit_mode.

      if g_grid->is_ready_for_input( ) eq 0.
    * set edit enabled cells ready for input
        call method g_grid->set_ready_for_input
                         exporting i_ready_for_input = 1.

      else.
    * lock edit enabled cells against input
        call method g_grid->set_ready_for_input
                        exporting i_ready_for_input = 0.
      endif.
    endform.                               " SWITCH_EDIT_MODE
     

  • 相关阅读:
    OutputCache 缓存key的创建 CreateOutputCachedItemKey
    Asp.net Web Api源码调试
    asp.net mvc源码分析DefaultModelBinder 自定义的普通数据类型的绑定和验证
    Asp.net web Api源码分析HttpParameterBinding
    Asp.net web Api源码分析HttpRequestMessage的创建
    asp.net mvc源码分析ActionResult篇 RazorView.RenderView
    Asp.Net MVC 项目预编译 View
    Asp.net Web.config文件读取路径你真的清楚吗?
    asp.net 动态创建TextBox控件 如何加载状态信息
    asp.net mvc源码分析BeginForm方法 和ClientValidationEnabled 属性
  • 原文地址:https://www.cnblogs.com/xiaomaohai/p/6157432.html
Copyright © 2011-2022 走看看