ITPub博客

首页 > Linux操作系统 > Linux操作系统 > BCALV_EDIT_07

BCALV_EDIT_07

原创 Linux操作系统 作者:fivezhuo 时间:2009-08-02 23:11:31 0 删除 编辑

program bcalv_edit_07.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
* Purpose:
* ~~~~~~~~
* This example shows how to define dropdown listboxes for
* particular cells of your output table.
*-----------------------------------------------------------------
* To check program behavior
* ~~~~~~~~~~~~~~~~~~~~~~~~~
* Conceive that customers are only allowed to smoke in the
* first class. For this reason, if the customer is a smoker
* only the first class (F) can be chosen in column 'CLASS',
* otherwise all classes.
*-----------------------------------------------------------------
* Essential steps (search for '§')
* ~~~~~~~~~~~~~~~
* 1.Define an extra field in your output table
* 2.Define a dropdown table and pass it to ALV.
* 3.Set your dropdown field editable and assign the fieldname of the
*   corresponding additional field to DRDN_FIELD of the fieldcatalog.
* 4.Set the handle of your additional field of your output
*   table according to the listbox that shall be displayed.
*-----------------------------------------------------------------------
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

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.

*§1.Define an extra field in your output table
*   for each column where you want to use drop down listboxes.
*   (One additional field refers to cells of one column).
data: begin of gt_outtab occurs 0.
        include structure sbook.
data: drop_down_handle type int4.
data: end of gt_outtab.

*---------------------------------------------------------------------*
*       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.
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
module pai input.
  save_ok = ok_code.
  clear ok_code.
  case save_ok.
    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 = '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.
      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'.

*§3.Set your dropdown field editable and assign the fieldname of the
*   corresponding additional field to DRDN_FIELD of the fieldcatalog.
      ls_fcat-edit = 'X'.
      ls_fcat-drdn_field = 'DROP_DOWN_HANDLE'.
      ls_fcat-outputlen = 5.

* 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.
    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 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. set_drdn_table.

  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[].

* 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  set_drdn_table
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form. set_drdn_table.
*§2.Define a dropdown table and pass it to ALV.
*   One listbox is referenced by a handle, e.g., '1'.
*   For each entry that shall appear in this listbox
*   you have to append a line to the dropdown table
*   with handle '1'.
*   This handle can be assigned to several columns
*   of the output table using the field catalog.

  data: lt_dropdown type lvc_t_drop,
        ls_dropdown type lvc_s_drop.

  ls_dropdown-handle = '1'.
  ls_dropdown-value = 'F'.
  append ls_dropdown to lt_dropdown.

  ls_dropdown-handle = '2'.
  ls_dropdown-value = 'F'.
  append ls_dropdown to lt_dropdown.

  ls_dropdown-handle = '2'.
  ls_dropdown-value = 'C'.
  append ls_dropdown to lt_dropdown.

  ls_dropdown-handle = '2'.
  ls_dropdown-value = 'Y'.
  append ls_dropdown to lt_dropdown.

  call method g_grid->set_drop_down_table
              exporting it_drop_down = lt_dropdown.

endform.                               " set_drdn_table
*&---------------------------------------------------------------------*
*&      Form  build_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form. build_data changing pt_outtab type standard table.

  data: lt_sbook type table of sbook,
        ls_sbook type sbook,
        l_index type i,
        ls_outtab like line of gt_outtab.

  select * from sbook into table lt_sbook up to g_max rows.  "#EC CI_NOWHERE
  if sy-subrc ne 0.
    perform. generate_entries changing lt_sbook.
  endif.
*§4.Set the handle of your additional field of your output
*   table according to the listbox that shall be displayed.
  loop at lt_sbook into ls_sbook.
    l_index = sy-tabix.
    move-corresponding ls_sbook to ls_outtab.
    clear ls_outtab-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_outtab-smoker = 'X'.
    else.
       ls_outtab-smoker = ' '.
    endif.
*
    if ls_outtab-smoker eq 'X'.
      ls_outtab-drop_down_handle = '1'.
    else.
      ls_outtab-drop_down_handle = '2'.
    endif.
    append ls_outtab to pt_outtab.
  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

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/14397246/viewspace-611090/,如需转载,请注明出处,否则将追究法律责任。

上一篇: ZFIVE_002 change
下一篇: Pricing
请登录后发表评论 登录
全部评论

注册时间:2009-08-01

  • 博文量
    110
  • 访问量
    46389