ALV List: Edit Line Text

Salah satu kelebihan ALV adalah kemampuan untuk mengedit line text. Untuk membuat kolom menjadi editable, hanya dengan men-set fieldcatalog-input menjadi ‘X’ :

form f_buildcats.
form f_buildcats.
  perform f_fieldcats using 'T_DATA' :
*FieldName   RefTable RefFieldNam Text Len sum CurFld spot Hide UOM Input Key.
  'CARRID'     'SPFLI'  'CARRID'  ''  ''  ''  ''  'X' ''  ''  ''  'X',
  'CONNID'    'SPFLI'  'CONNID'  ''  ''  'X' ''  'X' ''  ''  ''  '',
  'CITYFROM' 'SPFLI' 'CITYFROM'  ''  ''  ''  ''  'X' ''  ''  'X' '',
  'CITYTO'    'SPFLI'  'CITYTO'  ''  ''  ''  ''  'X' ''  '' 'X' ''.
endform.                    "f_buildcats

Pada potongan syntax di atas, field Cityfrom dan Cityto di set ‘X’ pada field input dari fieldcats, sehingga saat program dieksekusi, hanya kedua field itu saja yang bisa di-edit.

Input Screen

Output Screen

Source Code

*&---------------------------------------------------------------------*
*& Report  YDOK_TEST1
*&---------------------------------------------------------------------*

report  ydok_test1.
*-----------------------------------------------------------------------
* Global data include
*-----------------------------------------------------------------------
type-pools: slis.
data : t_fieldcat         type slis_t_fieldcat_alv,
       d_layout           type slis_layout_alv,
       t_sort             type slis_t_sortinfo_alv with header line,
       t_events           type slis_t_event with header line,
       t_list_top_of_page type slis_t_listheader with header line.

tables : spfli.

* INTERNAL TABLE FOR STORING NAMES IN SELECTION LIST
data: begin of t_data occurs 0.
        include structure spfli.
data: end of t_data.

data : t_data1 like t_data occurs 0 with header line,
       d_flag(1).

*START THE SELECTION SCREEN BLOCK
selection-screen begin of block ss1 with frame.
select-options: s_carrid for spfli-carrid.
selection-screen end of block ss1.

*-----------------------------------------------------------------------
* Events
*-----------------------------------------------------------------------
start-of-selection.
  perform f_get_data.
  perform f_write_data.

*&---------------------------------------------------------------------*
*&      Form  f_get_data
*&---------------------------------------------------------------------*
form f_get_data.
  select *
    into corresponding fields of table t_data
    from spfli
    where carrid in s_carrid.

  if sy-subrc ne 0.
    message id 'AQ' type 'I' number '260'.
  endif.
endform.                    "f_get_data

*&---------------------------------------------------------------------*
*&      Form  f_write_data
*&---------------------------------------------------------------------*
form f_write_data.
  perform f_buildcats.
  perform f_layout.
  perform f_sortfield.
  perform f_build_event.
  perform f_alv_display tables t_data.
endform.                    "f_write_data

*&---------------------------------------------------------------------*
*&      Form  f_buildcats
*&---------------------------------------------------------------------*
* alv list :
* untuk membuat line text editable, set field itab yg ingin diubah-ubah
* datanya --> set input = 'X'
*----------------------------------------------------------------------*
form f_buildcats.
  clear t_fieldcat[]. refresh t_fieldcat.
  perform f_fieldcats using 'T_DATA' :
* FieldName RefTable RefFieldName Text Len sum CurrFld spot Hide UOM Input Key.
  'CARRID'    'SPFLI'     'CARRID'        ''     ''    ''     ''
'X'     ''     ''    ''    'X',
  'CONNID'    'SPFLI'     'CONNID'       ''     ''    'X'   ''
'X'     ''     ''    ''    '',
  'CITYFROM'  'SPFLI'     'CITYFROM'  ''     ''    ''     ''
'X'     ''     ''    'X'  '',
  'CITYTO'    'SPFLI'     'CITYTO'       ''     ''    ''     ''
 'X'     ''     ''    'X'  ''.

endform.                    "f_buildcats

*&---------------------------------------------------------------------*
*&      Form  F_FIELDCATS
*&---------------------------------------------------------------------*
form f_fieldcats using fu_tabname     "Itab Name
                       fu_fname       "Field Itab
                       fu_reftb       "Reff.Table for fu_fname
                       fu_reffname    "Reff.Field for fu_reftb
                       fu_text        "Text will Display
                       fu_len         "Length Text
                       fu_sum         "Sum for currency
                       fu_curr        "Currency field at Itab
                       fu_spot        "X = Spot
                       fu_out         "X = Hide
                       fu_uom         "UoM Field at Itab
                       fu_input       "Inputing Field
                       fu_key.        "Field Key

  data : lt_fieldcat type slis_fieldcat_alv.
  lt_fieldcat-tabname        = fu_tabname.
  lt_fieldcat-fieldname      = fu_fname.
  lt_fieldcat-ref_tabname    = fu_reftb.
  lt_fieldcat-ref_fieldname  = fu_reffname.
  lt_fieldcat-seltext_l      = lt_fieldcat-seltext_m =
  lt_fieldcat-seltext_s      = fu_text.
  lt_fieldcat-reptext_ddic   = fu_text.
  lt_fieldcat-outputlen      = fu_len.
  lt_fieldcat-do_sum         = fu_sum.
  lt_fieldcat-cfieldname     = fu_curr.
  lt_fieldcat-hotspot        = fu_spot.
  lt_fieldcat-no_out         = fu_out.
  lt_fieldcat-qfieldname     = fu_uom.
  lt_fieldcat-input          = fu_input.
  lt_fieldcat-edit           = fu_input.
  lt_fieldcat-key            = fu_key.

  append lt_fieldcat to t_fieldcat.
  clear: lt_fieldcat.
endform.                    " F_FIELDCATS

*&---------------------------------------------------------------------*
*&      Form  f_layout
*&---------------------------------------------------------------------*
form f_layout.
  clear d_layout.
  d_layout-colwidth_optimize = 'X'.
  d_layout-f2code            = '&ETA'.
  d_layout-zebra             = 'X'.
  d_layout-hotspot_fieldname = 'X'.
  d_layout-detail_popup      = 'X'.
endform.                    "f_layout

*&---------------------------------------------------------------------*
*&      Form  f_sortfield
*&---------------------------------------------------------------------*
form f_sortfield.
  t_sort-fieldname  = 'CARRID'.
  t_sort-tabname    = 'T_DATA'.
  t_sort-up         = 'X' .
  append t_sort.
endform.                    "f_sortfield

*&---------------------------------------------------------------------*
*&      Form  f_build_event
*&---------------------------------------------------------------------*
form f_build_event.
  clear t_events[]. refresh t_events.
  t_events-name = slis_ev_top_of_page.
  t_events-form = 'F_TOP_OF_PAGE'.
  append t_events.
endform.                    " F_BUILD_EVENT

*&---------------------------------------------------------------------*
*&      Form  f_top_of_page
*&---------------------------------------------------------------------*
form f_top_of_page.
  data : ld_line(4).
  clear t_list_top_of_page[]. refresh t_list_top_of_page.

  t_list_top_of_page-typ  = 'H'.
  t_list_top_of_page-info = 'ALV : Editing Line Text'.
  append t_list_top_of_page.

  call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
      it_list_commentary = t_list_top_of_page[].

endform.                    "f_top_of_page

*&---------------------------------------------------------------------*
*&      Form  alv_display
*&---------------------------------------------------------------------*
form f_alv_display tables ft_data.
  data ld_repid  like sy-repid.

  ld_repid = sy-repid.

  call function 'REUSE_ALV_LIST_DISPLAY'
    exporting
      i_callback_program = sy-repid
      is_layout          = d_layout
      it_fieldcat        = t_fieldcat[]
      it_sort            = t_sort[]
      i_default          = 'X'
      i_save             = 'A'
      it_events          = t_events[]
    tables
      t_outtab           = ft_data[]
    exceptions
      program_error      = 1
      others             = 2.
endform.                    "alv_display
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s