首页 > 其他分享 >ALV删除和追加行

ALV删除和追加行

时间:2023-09-18 11:33:05浏览次数:40  
标签:删除 pt cl alv grid 追加 ALV exclude ls

program bcalv_edit_04.
*-----------------------------------------------------------------------
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&data: ok_code like sy-ucomm,
      save_ok like sy-ucomm,
      g_container type scrfname value 'BCALV_GRID_DEMO_0100_CONT1',
      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,
      gs_layout type lvc_s_layo,
      g_max type i value 100,
      gs_spfli type spfli,     "#EC NEEDED
      g_success type c.*local class to handle semantic checks
class lcl_event_receiver definition deferred.data: g_verifier type ref to lcl_event_receiver.
data: begin of gt_outtab occurs 0.     "with header line
        include structure sflight.
data: celltab type lvc_t_styl.
data: end of gt_outtab.data: g_carrid like sflight-carrid,
      g_connid like sflight-connid.*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_event_receiver definition.*.............
  public section.
    types: begin of sflight_key.
    types:   carrid type s_carr_id.
    types:   connid type s_conn_id.
    types:   fldate type s_date.
    types: end of sflight_key.    types: sflight_keys type standard table of sflight_key,
           sflight_table type standard table of sflight.    methods:
      handle_data_changed
         for event data_changed of cl_gui_alv_grid
             importing er_data_changed.    methods:
      get_inserted_rows
           exporting
              inserted_rows type sflight_keys.    methods:
      get_deleted_rows
          exporting
              deleted_rows type sflight_table.    methods:
       refresh_delta_tables.    methods: set_table_is_initial.
    methods: set_table_is_not_initial.
    methods: table_is_initial
                returning value(initial) type char01.*..............
  private section.
* ?.Define internal tables to remember inserted and deleted lines,
*    thus the delta between input made after the last saving.    data: inserted_rows type sflight_keys,
          deleted_rows type standard table of sflight.* This flag is set if any error occured in one of the
* following methods:
    data: error_in_data type c.* This flag signals that no records were read for the flight
* table initially:
    data: initial_table type c.
** Methods to modularize event handler method HANDLE_DATA_CHANGED:
*
    methods:
      check_double_entries
         importing
            pr_data_changed type ref to cl_alv_changed_data_protocol.    methods:
      update_delta_tables
         importing
            pr_data_changed type ref to cl_alv_changed_data_protocol.    methods:
      perform_semantic_checks
         importing
            pr_data_changed type ref to cl_alv_changed_data_protocol.    methods:
      get_cell_values
           importing
             row_id          type int4
             pr_data_changed type ref to cl_alv_changed_data_protocol
           exporting
             key             type sflight_key. 
endclass.
**---------------------------------------------------------
class lcl_event_receiver implementation.
  method handle_data_changed.
*
    data: ls_good type lvc_s_modi,
          l_price type s_price,
          ls_new type lvc_s_moce.    error_in_data = space.
* check if there exist double entries
    call method check_double_entries( er_data_changed ).* remember new or deleted lines for saving
    call method update_delta_tables( er_data_changed ).* check mt_good_cells semantically
    call method perform_semantic_checks( er_data_changed ).    if error_in_data = 'X'.
      call method er_data_changed->display_protocol.
    endif.  endmethod.
*-----------------------------------------------------------------------
  method check_double_entries.
    data: lt_good_cells type lvc_t_modi,
          ls_good type lvc_s_modi,
          ls_key type sflight_key,
          ls_sflight type sflight,
          l_flightdate like gt_outtab-fldate,
          l_del_row type lvc_s_moce,
          ls_outtab like line of gt_outtab,
          l_reentered type c. 
* ?.Check if there exist already other records with equal key fields.
*.............................................
* Check if the user has entered two new lines where the key fields
* are equal.
*.............................................
* Since CARRID and CONNID are read only, the check is restrained
* to field FLDATE.
*
* Algorithm: Copy all entries in MT_GOOD_CELLS to a dummy table.
*            During the copying procedure check if there exists
*            already a line with the same Flight date.
*
    loop at pr_data_changed->mt_good_cells into ls_good.
      case ls_good-fieldname.
        when 'FLDATE'.          call method pr_data_changed->get_cell_value
                      exporting
                            i_row_id = ls_good-row_id
                            i_fieldname = ls_good-fieldname
                      importing e_value = l_flightdate.          read table lt_good_cells with key
                            value = l_flightdate
                            transporting no fields.
          if sy-subrc = 0.
* There exists already a line with the same flight date!
            call method pr_data_changed->add_protocol_entry
                         exporting
              i_msgid = '0K' i_msgno = '000'  i_msgty = 'E'
              i_msgv1 = text-m01
              i_fieldname = ls_good-fieldname
              i_row_id = ls_good-row_id.            error_in_data = 'X'.
          else.
            ls_good-value = l_flightdate.
            append ls_good to lt_good_cells.
          endif.
      endcase.    endloop.
*.........................
* Check if any new entries already exist in gt_outtab.
* At this point, lt_good_cells contains only lines with
* FIELDNAME = 'FLDATE'.
*........................
    loop at lt_good_cells into ls_good.
      l_flightdate = ls_good-value.      "flightdate, see above
      read table gt_outtab with key
                    carrid = g_carrid
                    connid = g_connid
                    fldate = l_flightdate
                    transporting no fields.      if sy-subrc = 0.
* Check if this entry was deleted before, i.e. it is in the table
* of deleted rows. If so, the entry does not exist twice. The user
* has deleted a line and then reentered it.
        l_reentered = space.
        loop at pr_data_changed->mt_deleted_rows into l_del_row.
          read table gt_outtab into ls_outtab index l_del_row-row_id.
          if sy-subrc ne 0.
            message i000(0k) with text-e01."Fehler beim L鰏chen
          elseif
                    ls_outtab-carrid eq g_carrid
                and ls_outtab-connid eq g_connid
                and ls_outtab-fldate eq ls_good-value.
            l_reentered = 'X'.
          endif.
        endloop.        if l_reentered ne 'X'.
          call method pr_data_changed->add_protocol_entry
                         exporting
              i_msgid = '0K' i_msgno = '000'  i_msgty = 'E'
              i_msgv1 = text-m01
              i_fieldname = ls_good-fieldname
              i_row_id = ls_good-row_id.          error_in_data = 'X'.
        endif.
      endif.
    endloop.* In this demo report you may prevent the selection
* of data by setting parameter 'p_ds'.
* If this is done, the next check is required:
    if me->table_is_initial( ) eq 'X'.
      call method get_cell_values
           exporting row_id          = 1
                     pr_data_changed = pr_data_changed
           importing key             = ls_key.      select single * from sflight into ls_sflight
                where carrid = ls_key-carrid
                  and connid = ls_key-connid
                  and fldate = ls_key-fldate.      if sy-subrc = 0.
        call method pr_data_changed->add_protocol_entry
                       exporting
            i_msgid = '0K' i_msgno = '000'  i_msgty = 'E'
            i_msgv1 = text-m01
            i_fieldname = 'FLDATE'
            i_row_id = 1.        error_in_data = 'X'.
      endif.
* flag initial_table is reset in method 'update_delta_tables'
    endif.  endmethod.
*-------------------------------------------------------
  method update_delta_tables.
    data: l_ins_row type lvc_s_moce,
          l_del_row type lvc_s_moce,
          ls_key type sflight_key,
          ls_sflight type sflight,
          ls_outtab like line of gt_outtab.* ?.Use protocol attributes MT_DELETED_ROWS and MT_INSERTED_ROWS
*    to remember which lines where deleted or inserted. Save this
*    information in your internal tables.*..........
* deleted rows
*.............
    loop at pr_data_changed->mt_deleted_rows into l_del_row.
      read table gt_outtab into ls_outtab index l_del_row-row_id.
      if sy-subrc ne 0.
        message i000(0k) with text-e01."Fehler beim L鰏chen
      else.
        move-corresponding ls_outtab to ls_sflight.
* It should no be possible that the same line is deleted twice,
* so we just add the new key line to 'deleted_rows'.
        append ls_sflight to deleted_rows.
* If this line was inserted just before it is deleted:
        delete me->inserted_rows
             where carrid = ls_outtab-carrid
             and   connid = ls_outtab-connid
             and   fldate = ls_outtab-fldate.
      endif.
    endloop.*..........
* inserted rows
* At this point ALV has not added new lines
* to gt_outtab, so you can not access their values
* by reading gt_outtab.
* Table MT_GOOD_CELLS holds new values that can be
* referenced using the ROW_ID.
*..........
    if me->table_is_initial( ) eq 'X'.
* No flights were selected initially. This is the first new line.
      call method get_cell_values
            exporting row_id          = 1
                      pr_data_changed = pr_data_changed
            importing key             = ls_key.      append ls_key to inserted_rows.
      call method me->set_table_is_not_initial.
    endif.    loop at pr_data_changed->mt_inserted_rows into l_ins_row.
      call method get_cell_values
              exporting row_id          = l_ins_row-row_id
                        pr_data_changed = pr_data_changed
              importing key             = ls_key.
*      READ TABLE gt_outtab INTO ls_outtab INDEX l_ins_row-row_id.* Just insert the new row regardless if the input is wrong
      append ls_key to inserted_rows.
    endloop.  endmethod.
*---------------------------------------------------------
  method get_cell_values.
* get values of key cells of row ROW_ID* CARRIER
    call method pr_data_changed->get_cell_value
          exporting
                 i_row_id    = row_id
                 i_fieldname = 'CARRID'
               importing
                 e_value = key-carrid.    if sy-subrc ne 0.
      message i000(0k) with text-e02.  "Fehler beim Einf黦en
    endif.
* CONNID
    call method pr_data_changed->get_cell_value
          exporting
                 i_row_id    = row_id
                 i_fieldname = 'CONNID'
               importing
                 e_value = key-connid.    if sy-subrc ne 0.
      message i000(0k) with text-e02.  "Fehler beim Einf黦en
    endif.* FLDATE
    call method pr_data_changed->get_cell_value
          exporting
                 i_row_id    = row_id
                 i_fieldname = 'FLDATE'
               importing
                 e_value = key-fldate.    if sy-subrc ne 0.
      message i000(0k) with text-e02.  "Fehler beim Einf黦en
    endif. 
  endmethod.
*---------------------------------------------------------
  method perform_semantic_checks.
    data: ls_good type lvc_s_modi,
          l_planetype type s_planetye,
          l_seatsmax type s_seatsmax.    loop at pr_data_changed->mt_good_cells into ls_good.
      case ls_good-fieldname.
        when 'PLANETYPE'.
          call method pr_data_changed->get_cell_value
             exporting
               i_row_id = ls_good-row_id
               i_fieldname = ls_good-fieldname
             importing
               e_value = l_planetype.          select single seatsmax from saplane into l_seatsmax
                        where planetype = l_planetype.          if sy-subrc ne 0.
            call method pr_data_changed->add_protocol_entry
                            exporting
                 i_msgid = '0K' i_msgno = '000'  i_msgty = 'E'
                 i_msgv1 = text-m02
                 i_fieldname = ls_good-fieldname
                 i_row_id = ls_good-row_id.            error_in_data = 'X'.
          else.            call method pr_data_changed->modify_cell
              exporting i_row_id    = ls_good-row_id
                        i_fieldname = 'SEATSMAX'
                        i_value     = l_seatsmax.
          endif.
      endcase.
    endloop.
  endmethod.*------------------------------------------------------
  method get_inserted_rows.
    inserted_rows = me->inserted_rows.
  endmethod.
*------------------------------------------------------  method get_deleted_rows.
    deleted_rows = me->deleted_rows.
  endmethod.
*------------------------------------------------------
  method refresh_delta_tables.
    clear me->inserted_rows[].
    clear me->deleted_rows[].
  endmethod.
*------------------------------------------------------
  method set_table_is_initial.
    initial_table = 'X'.
  endmethod.
*------------------------------------------------------
  method set_table_is_not_initial.
    initial_table = space.
  endmethod.
*------------------------------------------------------
  method table_is_initial.
    if initial_table = 'X'.
      initial = 'X'.
    else.
      initial = space.
    endif.
  endmethod.endclass.
**************************************************************
 
****************************************************************
***************************************************************
* Selection Screen
*-------------------------------------------
tables sflight.parameters: p_ds type c as checkbox.   "delete selection
select-options s_carrid for sflight-carrid
                            no intervals no-extension default 'LH'.
select-options s_connid for sflight-connid
                           no intervals no-extension default '0400'.*---------------------------------------------------------------------*
*       MAIN                                                          *
*---------------------------------------------------------------------*
start-of-selection.  g_carrid = s_carrid-low.
  g_connid = s_connid-low.* first check airline and connection
  select single * from spfli into gs_spfli
                     where carrid = g_carrid
                     and connid = g_connid.  if sy-subrc ne 0.
    call function 'POPUP_TO_INFORM'
         exporting
              titel = text-i01
              txt1  = text-i02
              txt2  = text-i03
              txt3  = text-i04
              txt4  = text-i05.
  else.
* ?.Lock your database table according to CARRID and CONNID
    perform lock_sflight changing g_success.
    if g_success eq 'X'.
      call screen 100.
    else.
      message i000(0k) with text-i10.
    endif.
  endif.*---------------------------------------------------------------------*
*       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.
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
module pai input.
  save_ok = ok_code.
  clear ok_code.
  case save_ok.
    when 'SAVE'.
      perform save_data.
    when 'BACK'.
* ?0.Unlock your database table.
      perform unlock_sflight.
      leave to screen 0.
    when 'EXIT'.
      perform exit_program.
    when others.
*     do nothing
  endcase.
endmodule.
*---------------------------------------------------------------------*
*       FORM EXIT_PROGRAM                                             *
*---------------------------------------------------------------------*
form exit_program.
  leave program.
endform.
*&---------------------------------------------------------------------*
*&      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 = 'SFLIGHT'
       changing
            ct_fieldcat      = pt_fieldcat.  loop at pt_fieldcat into ls_fcat.
    if    ls_fcat-fieldname eq 'PRICE'
       or ls_fcat-fieldname eq 'PLANETYPE'
       or ls_fcat-fieldname eq 'FLDATE'.* ?.Set status of columns FLDATA, PRICE and PLANETYPE to editable.
*    Since all cells are set to non-editable (see step 3) the cells
*    of this columns will only be editable for new lines.      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 = 'CARRID'
       or ls_fcat-fieldname = 'CONNID'
       or ls_fcat-fieldname = 'CURRENCY'.* ?.Use field AUTO_VALUE of the fieldcatalog to preset values when new
*    lines are added.      ls_fcat-auto_value = 'X'.
      ls_fcat-checktable = '!'.   "do not check foreign key relations      modify pt_fieldcat from ls_fcat.
    endif.  endloop.
endform.
*&---------------------------------------------------------------------*
*&      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 like gt_outtab[]
                                  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.* Create Objekt to verify input values.
* (This object is already needed in form SELECT_DATA).
  create object g_verifier.
  set handler g_verifier->handle_data_changed for g_grid.  perform select_data changing pt_outtab[].
* Build fieldcat and set columns PLANETYPE and SEATSOCC
* edit enabled.
  perform build_fieldcat changing pt_fieldcat.
  perform exclude_tb_functions changing lt_exclude.  gs_layout-stylefname = 'CELLTAB'.
*  gs_layout-no_toolbar = 'X'.  call method g_grid->set_table_for_first_display
       exporting it_toolbar_excluding  = lt_exclude
                 is_layout             = gs_layout
       changing  it_fieldcatalog       = pt_fieldcat
                 it_outtab             = pt_outtab[].* 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  select_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_OUTTAB  text
*----------------------------------------------------------------------*
form select_data changing pt_outtab like gt_outtab[].
  data: lt_sflight type table of sflight,
        ls_sflight type sflight,
        ls_outtab like line of gt_outtab,
        l_index type i,
        ls_spfli type spfli,                                "#EC NEEDED
        lt_celltab type lvc_t_styl. 
* Check parameter 'p_ds'=>optionally select no data
  if p_ds is initial.
* Select data from sflight
    select * from sflight into table lt_sflight up to g_max rows
                     where carrid = g_carrid
                       and connid = g_connid.
  endif.  if sy-subrc ne 0 or not p_ds is initial.
* no flights were found!
* We provide some default values for the first line that is entered:
    ls_outtab-carrid = g_carrid.
    ls_outtab-connid = g_connid.
    case g_carrid.
      when 'LH'.
        ls_outtab-currency = 'DEM'.
      when others.
        ls_outtab-currency = 'US'.
    endcase.
    ls_outtab-seatsocc = 0.
    ls_outtab-paymentsum = 0.* set fields FLDATE, PRICE and PLANETYPE to editable
    perform fill_celltab using 'RW'
                         changing lt_celltab.
    insert lines of lt_celltab into table ls_outtab-celltab.
    append ls_outtab to pt_outtab.* Tell Verify-Objekt that the table was initial
    call method g_verifier->set_table_is_initial.
  else.
    call method g_verifier->set_table_is_not_initial.
* move corresponding fields from lt_sflight to gt_outtab
    loop at lt_sflight into ls_sflight.
      move-corresponding ls_sflight to ls_outtab.
      append ls_outtab to pt_outtab.
    endloop.* ?.Set all cells of the table non-editable by using the style table.
    loop at pt_outtab into ls_outtab.
      l_index = sy-tabix.
      refresh lt_celltab.
      perform fill_celltab using 'RO'
                        changing lt_celltab.
* Copy your celltab to the celltab of the current row of gt_outtab.
      insert lines of lt_celltab into table ls_outtab-celltab.
      modify pt_outtab from ls_outtab index l_index.
    endloop.
  endif.endform.                               " select_data
*----------------------------------------------------------------
form fill_celltab using value(p_mode)
                  changing pt_celltab type lvc_t_styl.
  data: ls_celltab type lvc_s_styl,
        l_mode type raw4.
* This forms sets the style of columns 'PRICE', FLDATE and PLANETYPE
* editable  if p_mode eq 'RW'.
    l_mode = cl_gui_alv_grid=>mc_style_enabled.
  else.                                "p_mode eq 'RO'
    l_mode = cl_gui_alv_grid=>mc_style_disabled.
  endif.  ls_celltab-fieldname = 'FLDATE'.
  ls_celltab-style = l_mode.
  insert ls_celltab into table pt_celltab.
  ls_celltab-fieldname = 'PRICE'.
  ls_celltab-style = l_mode.
  insert ls_celltab into table pt_celltab.
  ls_celltab-fieldname = 'PLANETYPE'.
  ls_celltab-style = l_mode.
  insert ls_celltab into table pt_celltab.endform.                               " FILL_CELLTAB
*---------------------------------------------
form exclude_tb_functions changing pt_exclude type ui_functions.
*
  data ls_exclude type ui_func.  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_undo.
  append ls_exclude to pt_exclude.
  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_AUF.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_AVERAGE.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_BACK_CLASSIC.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_CALL_ABC.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_CALL_CHAIN.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_CALL_CRBATCH.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_CALL_CRWEB.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_CALL_LINEITEMS.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_CALL_MASTER_DATA.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_CALL_MORE.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_CALL_REPORT.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_CALL_XINT.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_CALL_XXL.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_COL_INVISIBLE.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_COL_OPTIMIZE.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_COUNT.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_CURRENT_VARIANT.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_DATA_SAVE.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_DELETE_FILTER.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_DESELECT_ALL.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_DETAIL.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_EXPCRDATA.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_EXPCRDESIG.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_EXPCRTEMPL.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_EXPMDB.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_EXTEND.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_F4.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_FILTER.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_FIND.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_FIX_COLUMNS.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_GRAPH.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_HELP.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_HTML.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_INFO.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_LOAD_VARIANT.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_COPY.
  append ls_exclude to pt_exclude.   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_CUT.
  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.   ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_PASTE.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_PASTE_NEW_ROW.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_UNDO.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_MAINTAIN_VARIANT.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_MAXIMUM.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_MINIMUM.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_PC_FILE.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_PRINT.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_PRINT_BACK.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_PRINT_PREV.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_REFRESH.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_REPREP.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_SAVE_VARIANT.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_SELECT_ALL.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_SEND.
  append ls_exclude to pt_exclude.   ls_exclude = cl_gui_alv_grid=>MC_FC_SEPARATOR.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_SORT.
  append ls_exclude to pt_exclude.ls_exclude = cl_gui_alv_grid=>MC_FC_SORT_ASC.
  append ls_exclude to pt_exclude.ls_exclude = cl_gui_alv_grid=>MC_FC_SORT_DSC.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_SUBTOT.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_SUM.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_TO_OFFICE.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_TO_REP_TREE.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_UNFIX_COLUMNS.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_URL_COPY_TO_CLIPBOARD.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_VARIANT_ADMIN.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_VIEWS.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_VIEW_CRYSTAL.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_VIEW_EXCEL.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_VIEW_GRID.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_VIEW_LOTUS.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_FC_WORD_PROCESSOR.
  append ls_exclude to pt_exclude.  ls_exclude = cl_gui_alv_grid=>MC_MB_EXPORT.
  append ls_exclude to pt_exclude.  endform.                               " EXCLUDE_TB_FUNCTIONS
*-------------------------------------
form save_data.
  data: l_valid type c.
* ?.Check if any errors exist in protocol by using method
*    CHECK_CHANGED_DATA of your ALV Grid instance.* The method CHECK_CHANGED_DATA checks all new cells syntactically,
* raises event DATA_CHANGED and looks then for any entries
* in the error protocol. If any exist the parameter e_valid
* is initial ('X' in the other case).
*
  call method g_grid->check_changed_data
               importing e_valid = l_valid.  if l_valid is initial.
    call function 'POPUP_TO_INFORM'
         exporting
              titel = text-i06
              txt1  = text-i07
              txt2  = text-i08
              txt3  = text-i09.  else.
    perform update_database.
    message s000(0k) with text-s01.
  endif.
endform.
*------------------------------------------
form update_database.
  data: lt_del_rows type table of sflight,
        lt_ins_keys type g_verifier->sflight_keys,
        l_ins_key type g_verifier->sflight_key,
        ls_sflight type sflight,
        ls_outtab like line of gt_outtab,
        lt_instab type table of sflight.* ?.When all values are valid, use your internal tables
*    to update your table on the database.*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* IMPORTANT: This method has been disabled, as the program logic
* was erroneous: if a user doubled a line (insert with copied values)
* the data is not accepted by alv, so the line inserted in the table
* had initial values. If he then deleted the line, the deleted line
* also had initial values. On the other hand, the line stored as
* inserted was the line with the original, copied values. So the
* data base was updated with hte copied values which lead to a
* short dump.
*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!* First delete lines in data base according to the
* keys you remembered within 'g_verifier'.
* Imagine a user deleted a row and then entered one with
* the same key fields like the deleted ones.
* Then both tables (deleted_rows, inserted_rows) have got
* an entry of this row.
* So if you first inserted the new rows in the data base
* and then deleted rows according to 'deleted_rows'
* The reentered rows would be lost.
*
* 1.Delete Lines:
*  call method g_verifier->get_deleted_rows
*          importing deleted_rows = lt_del_rows.
*
*  delete sflight from table lt_del_rows.
*
** 2.Insert Lines:
*  call method g_verifier->get_inserted_rows
*          importing inserted_rows = lt_ins_keys.
*
*  loop at lt_ins_keys into l_ins_key.
*    read table gt_outtab into ls_outtab
*     with key carrid = l_ins_key-carrid
*              connid = l_ins_key-connid
*              fldate = l_ins_key-fldate.
*    if sy-subrc eq 0.
*      move-corresponding ls_outtab to ls_sflight.
*      append ls_sflight to lt_instab.
*    endif.
*  endloop.
*
*  insert sflight from table lt_instab.
*
** ?.Refresh your internal tables.
*
*  call method g_verifier->refresh_delta_tables.endform.
*--------------------------------------------------------
form lock_sflight changing p_success type c.  p_success = space.
  call function 'ENQUEUE_ESFLIGHT'
       exporting
            carrid         = g_carrid
            connid         = g_connid
            _scope         = '3'
       exceptions
            foreign_lock   = 1
            system_failure = 2
            others         = 3.  if sy-subrc ne 0.
    p_success = space.
  else.
    p_success = 'X'.
  endif.endform.
*--------------------------------------------------------form unlock_sflight.
  call function 'DEQUEUE_ESFLIGHT'
       exporting
            carrid = g_carrid
            connid = g_connid
            _scope = '3'.endform.

 

屏幕100 的 逻辑流:

 

PROCESS BEFORE OUTPUT.
  MODULE PBO.
*
PROCESS AFTER INPUT.
  MODULE PAI.

屏幕100 中:

 

加一个 : container

BCALV_GRID_DEMO_0100_CONT1

标签:删除,pt,cl,alv,grid,追加,ALV,exclude,ls
From: https://blog.51cto.com/u_8215601/7508682

相关文章

  • 怎样在触发器中删除刚刚录入但是不合法的记录?
    建立一个临时表:CREATEGLOBALTEMPORARYTABLEnorthsnow_tmp(northsnow_idvarchar2(20))ONCOMMITDELETEROWS;在业务表上创建一个行级触发器:createorreplacetriggertrg_northsnowafterinsertontb_northsnowforeachrow......
  • TienChin 渠道管理-删除渠道
    更改一下菜单权限,将删除渠道的delete改为remove:ChannelController.java@PreAuthorize("hasPermission('tienchin:channel:remove')")@Log(title="渠道管理",businessType=BusinessType.DELETE)@DeleteMapping("/{channelIds}")AjaxResult......
  • 2020-2-3-coding删除迭代
    layout:posttitle:coding删除迭代categories:coding-posttag:codingapicoding删除迭代接口URLhttps://<team-name>.coding.net/api/project/<project-id>/iterations/<iterations_id>请求方式DELETE请求header参数:cookie:eid成功返回参数参数示例值参数描......
  • pandas实现读取excel并删除第一条内容再保存
    想要实现的是,获取excel的第一条信息之后,把原excel的信息保存。再读取,再保存,这样,每次读取到的信息都是新的信息。工作需要大量的输入证件号查询信息,这样就避免了手动输入。importnumpyasnpimportpandasaspdimportopenpyxlimporttimelianxi=pd.read_excel('./练习.xl......
  • 【LeetCode】删除数对后的最小数组长度
    题目给你一个下标从0开始的非递减整数数组nums。你可以执行以下操作任意次:选择两个下标i和j,满足i<j且nums[i]<nums[j]。将nums中下标在i和j处的元素删除。剩余元素按照原来的顺序组成新的数组,下标也重新从0开始编号。请你返回一个整数,表示执行......
  • openGauss学习笔记-71 openGauss 数据库管理-创建和管理普通表-删除表中数据
    openGauss学习笔记-71openGauss数据库管理-创建和管理普通表-删除表中数据在使用表的过程中,可能会需要删除已过期的数据,删除数据必须从表中整行的删除。SQL不能直接访问独立的行,只能通过声明被删除行匹配的条件进行。如果表中有一个主键,用户可以指定准确的行。用户可以删除匹配......
  • 删除重复纪录
    删除重复纪录 学习sql有一段时间了,发现在我建了一个用来测试的表(没有建索引)中出现了许多的重复记录。后来总结了一些删除重复记录的方法,在Oracle中,可以通过唯一rowid实现删除重复记录;还可以建临时表来实现...这个只提到其中的几种简单实用的方法,希望可以和大家分享(以表employee为......
  • 50-集合-特点-创建和删除-交集并集差集运算
          ......
  • 45-字典-元素的添加-修改-删除
           ......
  • 35-列表-元素删除的3种方式-删除本质是数组元素拷贝
        删除和增加本质就是数组元素拷贝       ......