动态代码

来源:互联网 发布:pgp加密软件下载 编辑:程序博客网 时间:2024/04/30 14:57
*&---------------------------------------------------------------------
*&      Form  ANALYSE_FIELDCAT_NEW
*&---------------------------------------------------------------------

form analyse_fieldcat_new
        using
          it_data             type table
          is_layout           type lvc_s_layo
          it_fieldcat         type lvc_t_fcat
        changing
          ct_fieldcat_local   type lvc_t_fcat_local
          cs_layout_local     type lvc_s_layl.

  data:
     l_struc_descr   type ref to cl_abap_structdescr,
     begin of lt_components occurs 40,
       name          type abap_compdescr-name,
       component     type sy-tabix,
     end of lt_components,
     ls_fieldcat_local type lvc_s_fcat_local.

  data: lr_alv type ref to cl_gui_alv_grid.

  data: l_tabix type i.

  field-symbols:
    <ls_component>   type abap_compdescr,
    <l_workarea>     type any,
    <l_field>        type any,
    <ls_fieldcat>    type lvc_s_fcat.


***********************************************************************
* find out the component numbers and names
***********************************************************************
  assign local copy of initial line of it_data to <l_workarea>.
  l_struc_descr ?= cl_abap_typedescr=>describe_by_data( <l_workarea> ).
  loop at l_struc_descr->components assigning <ls_component>.
    lt_components-component = sy-tabix.
    lt_components-name      = <ls_component>-name.
    append lt_components.
  endloop.
  sort lt_components by name.


***********************************************************************
* prepare local layout structure
***********************************************************************
  clear cs_layout_local.
* find component number for ctab_fname
  read table lt_components with key name = is_layout-ctab_fname
                           binary search.
  if sy-subrc = 0.
    cs_layout_local-indx_ctab = lt_components-component.
  endif.
* find component number for info_fname
  read table lt_components
             with key name = is_layout-info_fname
             binary search.
  if sy-subrc = 0.
    cs_layout_local-indx_info = lt_components-component.
  endif.
* find component number for stylefname
  read table lt_components with key name = is_layout-stylefname
                           binary search.
  if sy-subrc = 0.
    cs_layout_local-indx_style = lt_components-component.
  endif.
* find component number for excp_fname
  read table lt_components with key name = is_layout-excp_fname
                           binary search.
  if sy-subrc = 0.
    cs_layout_local-indx_excp = lt_components-component.
  endif.
* find component number for s_dragdrop_fieldname
  read table lt_components
             with key name = is_layout-s_dragdrop-fieldname
             binary search.
  if sy-subrc = 0.
    cs_layout_local-indx_drnd = lt_components-component.
  endif.


***********************************************************************
* prepare local field catalog
***********************************************************************
  loop at it_fieldcat assigning <ls_fieldcat> where no_out ne 'X'
                                                and tech   ne 'X'.

    add 1 to l_tabix.

*   find component number for fieldname
    check <ls_fieldcat>-fieldname ne '&&$$&&'.
    read table lt_components with key name = <ls_fieldcat>-fieldname
                             binary search.
    if sy-subrc = 0.
      <ls_fieldcat>-indx_field = lt_components-component.
    endif.

*   find component number for cfieldname
    if not <ls_fieldcat>-cfieldname is initial.
      read table lt_components with key name = <ls_fieldcat>-cfieldname
                               binary search.
      if sy-subrc = 0.
        <ls_fieldcat>-indx_cfiel = lt_components-component.
      endif.
    endif.

*   find component number for qfieldname
    if not <ls_fieldcat>-qfieldname is initial.
      read table lt_components with key name = <ls_fieldcat>-qfieldname
                               binary search.
      if sy-subrc = 0.
        <ls_fieldcat>-indx_qfiel = lt_components-component.
      endif.
    endif.

*   find component number for ifieldname
    if not <ls_fieldcat>-ifieldname is initial.
      read table lt_components with key name = <ls_fieldcat>-ifieldname
                               binary search.
      if sy-subrc = 0.
        <ls_fieldcat>-indx_ifiel = lt_components-component.
      endif.
    endif.

*   find component number for roundfield
    if not <ls_fieldcat>-roundfield is initial.
      read table lt_components with key name = <ls_fieldcat>-roundfield
                               binary search.
      if sy-subrc = 0.
        <ls_fieldcat>-indx_round = lt_components-component.
      endif.
    endif.

*   find component number for decmlfield
    if not <ls_fieldcat>-decmlfield is initial.
      read table lt_components with key name = <ls_fieldcat>-decmlfield
                               binary search.
      if sy-subrc = 0.
        <ls_fieldcat>-indx_decml = lt_components-component.
      endif.
    endif.

*   is a complex style to be derived ?
    if not is_layout-ctab_fname is initial or
       not is_layout-stylefname is initial or
       not <ls_fieldcat>-web_field is initial or
       not <ls_fieldcat>-drdn_field is initial or
       <ls_fieldcat>-hotspot  = 'V'        or
       <ls_fieldcat>-checkbox = 'X'        or
       <ls_fieldcat>-checkbox = 'R'.
      <ls_fieldcat>-get_style = 'X'.
    endif.

    <ls_fieldcat>-col_pos = l_tabix.

*   append to result table
    append <ls_fieldcat> to ct_fieldcat_local.
  endloop.
  if g_gui_type = 3.
    read table it_fieldcat into ls_fieldcat_local with key
         ref_field = '&&$$&&'.
    if sy-subrc = 0.
      read table it_fieldcat into ls_fieldcat_local
                 with key fieldname = 'ROW_ID'.
      if sy-subrc = 0.
        ls_fieldcat_local-no_out = space.
        append ls_fieldcat_local to ct_fieldcat_local.
      endif.
      read table it_fieldcat into ls_fieldcat_local
                 with key fieldname = 'COL_ID'.
      if sy-subrc = 0.
        ls_fieldcat_local-no_out = space.
        append ls_fieldcat_local to ct_fieldcat_local.
      endif.
      read table it_fieldcat into ls_fieldcat_local
                 with key fieldname = '&&$$&&'.
      if sy-subrc ne 0message x000(0k). endif.
      if sy-subrc = 0.
        read table it_data index 1 assigning <l_workarea>.
        if sy-subrc = 0.
          assign component ls_fieldcat_local-fieldname of structure
          <l_workarea> to <l_field>.
          if sy-subrc ne 0message x000(0k). endif.

          call function 'LVC_LOG_HANDLE_GET'
            exporting
              i_log = <l_field>
            importing
              e_alv = lr_alv.

          call method g_alv->set_error_log
            exporting
              ir_alv = lr_alv.
        endif.
      endif.
    endif.
  endif.

endform.                                                    "
*&---------------------------------------------------------------------
*&      Form  lvc_table_for_display_prepare
*&---------------------------------------------------------------------
form lvc_table_for_display_prepare
                             tables rt_data
                                    rt_collect00
                                    rt_collect01
                                    rt_collect02
                                    rt_collect03
                                    rt_collect04
                                    rt_collect05
                                    rt_collect06
                                    rt_collect07
                                    rt_collect08
                                    rt_collect09
                             using  r_grid type ref to
                                               cl_gui_alv_grid
                                    rt_filter_index type lvc_t_fidx
                                    rt_filter       type lvc_t_filt
                                    rt_fieldcat type lvc_t_fcat
                                    rt_sort     type lvc_t_sort
                                    rt_grouplevels type lvc_t_grpl
                                    rs_total_options type lvc_s_toto
                                    rs_layout   type lvc_s_layo
                                    rt_lvc_data type lvc_t_data
                                    rt_lvc_info type lvc_t_info
                                    rt_poid type lvc_t_poid
                                    rt_idpo type lvc_t_idpo
                                    rt_roid type lvc_t_roid
                                    ct_fielcat_local type lvc_t_fcat
                                    cs_layout_local  type lvc_s_layl
                                    ct_start_index   type lvc_t_stin.


* Check completion of fieldcat
  read table rt_fieldcat with key tech_comp = space
       transporting no fields.

  if sy-subrc = 0.
    message a000(0k) with 'IN: LVC_TABLE_FOR_DISPLAY'
                          'ERROR: FIELDCAT_NOT_COMPLETE'
                     raising fieldcat_not_complete.
  endif.

* Get info-table
  perform info_table_get using rt_fieldcat
                               rt_sort
                               rt_filter
                               rs_total_options
                               rs_layout
                      changing rt_lvc_info.

* Get data-table
  perform data_table_prepare
                         tables rt_data
                                rt_collect00
                                rt_collect01
                                rt_collect02
                                rt_collect03
                                rt_collect04
                                rt_collect05
                                rt_collect06
                                rt_collect07
                                rt_collect08
                                rt_collect09
                          using r_grid
                                rt_fieldcat
                                rt_grouplevels
                                rs_total_options
                                rs_layout
                                rt_filter_index
                                rt_lvc_data
                                rt_idpo
                                rt_poid
                                rt_roid
                                ct_fielcat_local
                                cs_layout_local
                                ct_start_index.

endform.                               " LVC_SET_TABLE_FOR_DISPLAY
"

*---------------------------------------------------------------------*
*       FORM DATA_TABLE_PREPARE                                   *
*---------------------------------------------------------------------*
form data_table_prepare
       tables
         rt_data
         rt_collect00
         rt_collect01
         rt_collect02
         rt_collect03
         rt_collect04
         rt_collect05
         rt_collect06
         rt_collect07
         rt_collect08
         rt_collect09
       using
         r_grid                type ref to cl_gui_alv_grid
         rt_fieldcat           type lvc_t_fcat
         rt_grouplevels        type lvc_t_grpl
         rs_total_options      type lvc_s_toto
         rs_layout             type lvc_s_layo
         rt_filter_index       type lvc_t_fidx
         rt_lvc_data           type lvc_t_data
         rt_idpo               type lvc_t_idpo
         rt_poid               type lvc_t_poid
         rt_roid               type lvc_t_roid
         ct_fieldcat_local     type lvc_t_fcat
         cs_layout_local       type lvc_s_layl
         ct_start_index        type lvc_t_stin.

  field-symbols:
    <field>                    type any,
    <lt_dragdrop>              type lvc_t_drdr,
    <ls_lvc_data>              type lvc_s_data.

  field-symbols: <fs_component> type any.

  data: lr_type_descr  type ref to cl_abap_typedescr,
        lr_table_descr type ref to cl_abap_tabledescr,
        lr_struc_descr type ref to cl_abap_structdescr,
        lt_components  type abap_compdescr_tab,
        l_struc_lvc    type char1,
        lt_slis_coltab type slis_t_specialcol_alv,
        lt_coltab      type lvc_t_scol,
        ls_color       type lvc_s_scol,
        ls_slis_color  type slis_specialcol_alv.

  data:
    l_grouptabix               type sy-tabix,
    ls_grouplevels             type lvc_s_grpl,
    ls_groups_static           type lvc_s_grpl,
    lt_groups_check            type lvc_t_grpl,
    ls_dummy                   type lvc_s_colo,
    lflg_suppress_item(1)      type c,
    l_row_counter              type sy-tabix,
    l_row_id                   type i,
    ls_dragdrop                type lvc_s_drdr,
    l_color(4)                 type c,
    ls_row                     type lvc_s_row,
    l_style                    type lvc_s_data-style,       "#EC NEEDED
    l_style_color              type lvc_s_data-style,
    ls_layout                  type lvc_s_layo,
    l_counter                  type sy-tabix,
    ls_start_index             type lvc_s_stin,
    l_columns                  type i,
    l_lines                    type i,
    ls_lvc_columns             type lvc_s_data,
    lt_lvc_columns             type lvc_t_data,
    l_no_filter(1)             type c,
    lt_dragdrop                type lvc_t_drdr,
    lt_style                   type lvc_t_styl.

***********************************************************************
* initialze return parameters
***********************************************************************
  clear rt_idpo.
  clear rt_poid.
  clear rt_roid.

***********************************************************************
* analyse field catalog and layout structure
***********************************************************************
  sort rt_fieldcat stable by col_pos.
  perform analyse_fieldcat_new
            using
              rt_data[]
              rs_layout
              rt_fieldcat
            changing
              ct_fieldcat_local
              cs_layout_local.

***********************************************************************
* create dummy table with all cells for one line
***********************************************************************
  clear ls_lvc_columns.
* one entry for col_pos = -1
  append ls_lvc_columns to lt_lvc_columns.
* directly point to this entry already here
  read table lt_lvc_columns assigning <ls_lvc_data> index 1.
* one entry for the exception icon
  if not rs_layout-excp_fname is initial.
    append ls_lvc_columns to lt_lvc_columns.
  endif.
* and the real columns
  describe table ct_fieldcat_local lines l_columns.
  do l_columns times.
    append ls_lvc_columns to lt_lvc_columns.
  enddo.


***********************************************************************
* create initial table with start positions in rt_lvc_data for each row
***********************************************************************
  describe table rt_data lines l_lines.
  clear ls_start_index.
* a not yet defined index is identified by -1
  ls_start_index-start_indx = -1.
  do l_lines times.
    append ls_start_index to ct_start_index.
  enddo.


***********************************************************************
* prepare group level tables
***********************************************************************
* Totals should be given out behind the related items
  if rs_layout-totals_bef is initial.
    sort rt_grouplevels by index_to ascending
                           index_from descending
                           level    descending.
* Totals should be given out before the related items
  else.
    sort rt_grouplevels by index_from ascending
                           index_to descending
                           level    ascending.
  endif.

***********************************************************************
* carry out global assigns for some subroutines
***********************************************************************
  assign rt_data[]       to <gt_table>.
  assign rt_filter_index to <gt_filter>.

***********************************************************************
* color
***********************************************************************
  if not rs_layout-ctab_fname is initial.
    assign component rs_layout-ctab_fname
           of structure rt_data to <fs_component>.
    if sy-subrc eq 0.
      lr_type_descr =
              cl_abap_typedescr=>describe_by_data( <fs_component> ).
      case lr_type_descr->type_kind.
        when cl_abap_typedescr=>typekind_table.
*...cast to class tabledescr.
          lr_table_descr ?= lr_type_descr.
          lr_struc_descr ?= lr_table_descr->get_table_line_type( ).
        when cl_abap_typedescr=>typekind_struct1 or
             cl_abap_typedescr=>typekind_struct2.
*...cast to class structdescr.
          lr_struc_descr ?= lr_type_descr.
      endcase.

      lt_components = lr_struc_descr->components.

      read table lt_components with key name = 'FNAME'
                 transporting no fields.
      if sy-subrc eq 0.
*... color is in lvc structure
        l_struc_lvc = 'X'.
      else.
*... color is in slis structure
        l_struc_lvc = space.
      endif.
    endif.
  endif.
*... default Zuweisung
  assign lt_coltab to <coltab>.

  if not rs_layout-stylefname is initial.
    assign component rs_layout-stylefname
           of structure rt_data to <gt_style>.
    if sy-subrc ne 0.
      assign lt_style to <gt_style>.
    endif.
  else.
    assign lt_style to <gt_style>.
  endif.

***********************************************************************
* prepare group levels
***********************************************************************
  lt_groups_check = rt_grouplevels.
  if rs_layout-totals_bef is initial.
    sort lt_groups_check by index_from index_to descending
                                       level ascending      .
  else.
    if rs_total_options-totals_out = 'X'.
      clear ls_grouplevels.
      l_grouptabix = 1.
*     Displaying the totalline before the related items
      if rs_layout-no_totline is initial.
        perform total_out_new tables rt_collect00
                                 rt_lvc_data
                          using  r_grid
                                 rt_fieldcat
                                 ct_fieldcat_local
                                 rt_poid
                                 rt_idpo
                                 rt_roid
                                 rs_layout
                                 ls_grouplevels
                                 rs_total_options
                                 l_row_counter
                                 l_grouptabix
                                 'T'.
      endif.
    endif.
  endif.

***********************************************************************
* is there a filter index defined ?
***********************************************************************
  if rt_filter_index[] is initial.
    l_no_filter = 'X'.
  else.
    l_no_filter = ' '.
  endif.

***********************************************************************
* Display the item lines
***********************************************************************
  loop at rt_data assigning <gs_table>.

*   Increase the index counter which is the id of an item line
    l_row_id      = sy-tabix.

*   Check whether the line has been filtered out
    if l_no_filter is initial.
      read table rt_filter_index from l_row_id transporting no fields.
      check sy-subrc ne 0.
    endif.

***********************************************************************
*   point to some important fields in this workarea
***********************************************************************
*... point to color table of this line
    if not rs_layout-ctab_fname is initial.
      clear lt_coltab.
      if l_struc_lvc eq space.
*... column contains color in slis structure
        if not cs_layout_local-indx_ctab is initial.
          assign component cs_layout_local-indx_ctab
                           of structure <gs_table> to <slis_coltab>.
          if sy-subrc ne 0.
            assign lt_slis_coltab to <slis_coltab>.
          endif.
        else.
          assign component rs_layout-ctab_fname
                           of structure <gs_table> to <slis_coltab>.
          if sy-subrc ne 0.
            assign lt_slis_coltab to <slis_coltab>.
          endif.
        endif.
        loop at <slis_coltab> into ls_slis_color.
          move-corresponding ls_slis_color to ls_color.
          ls_color-fname = ls_slis_color-fieldname.
          append ls_color to lt_coltab.
        endloop.
        assign lt_coltab to <coltab>.
      else.
*... column contains color in lvc structure
        if not cs_layout_local-indx_ctab is initial.
          assign component cs_layout_local-indx_ctab
                           of structure <gs_table> to <coltab>.
          if sy-subrc ne 0.
            assign lt_coltab to <coltab>.
          endif.
        else.
          assign component rs_layout-ctab_fname
                           of structure <gs_table> to <coltab>.
          if sy-subrc ne 0.
            assign lt_coltab to <coltab>.
          endif.
        endif.
      endif.
    endif.

*   point to info field of this line
    if not rs_layout-info_fname is initial.
      if not cs_layout_local-indx_info is initial.
        assign component cs_layout_local-indx_info
                         of structure <gs_table> to <field>.
      else.
        assign component rs_layout-info_fname
                         of structure <gs_table> to <field>.
        if sy-subrc ne 0.
          assign ls_layout-info_fname to <field>.
        endif.
      endif.
    endif.

*   point to style table of this line
    if not rs_layout-stylefname is initial.
      if not cs_layout_local-indx_style is initial.
        assign component cs_layout_local-indx_style
                         of structure <gs_table> to <gt_style>.
      else.
        assign component rs_layout-stylefname
                         of structure <gs_table> to <gt_style>.
        if sy-subrc ne 0.
          assign lt_style to <gt_style>.
        endif.
      endif.
    endif.

*   point to dragdropid-table of this line
    if not rs_layout-s_dragdrop-fieldname is initial.
      if not cs_layout_local-indx_drnd is initial.
        assign component cs_layout_local-indx_drnd
                         of structure <gs_table> to <lt_dragdrop>.
      else.
        assign component rs_layout-s_dragdrop-fieldname
                         of structure <gs_table> to <lt_dragdrop>.
        if sy-subrc ne 0.
          assign lt_dragdrop to <lt_dragdrop>.
        endif.
      endif.
      gt_dragdrop[] = <lt_dragdrop>.
    endif.


***********************************************************************
*   add totals if necessary
***********************************************************************
*   Compare the actual row with the index table of the totals
    if rs_total_options-totals_out = 'X' or
       rs_total_options-subtot_out = 'X'.
      if ls_groups_static is initial or
         l_row_id > ls_groups_static-index_to.
        read table lt_groups_check into ls_groups_static
               with key
                    index_from = l_row_id
                    level      = rs_total_options-max_level
                    subtot     = 'X'
               binary search.
      endif.
      if ls_groups_static-compress = 'X' and
                g_view ne cl_gui_alv_grid=>mc_fc_view_excel.
        lflg_suppress_item = 'X'.
      else.
        clear lflg_suppress_item.
      endif.
    endif.
*   Display subtotals before the items
    if not rs_layout-totals_bef is initial.
      if rs_total_options-subtot_out = 'X'.
        read table rt_grouplevels into ls_grouplevels
                                  with key index_from = l_row_id
                                       binary search.
        if sy-subrc = 0.
          perform subtotals_out_before_new tables rt_collect01
                                         rt_collect02
                                         rt_collect03
                                         rt_collect04
                                         rt_collect05
                                         rt_collect06
                                         rt_collect07
                                         rt_collect08
                                         rt_collect09
                                         rt_lvc_data
                                  using  r_grid
                                         rt_fieldcat
                                         ct_fieldcat_local
                                         rt_poid
                                         rt_idpo
                                         rt_roid
                                         rs_layout
                                         rt_grouplevels
                                         ls_grouplevels
                                         rs_total_options
                                         l_row_id
                                         l_row_counter.
        endif.
      endif.
    endif.


***********************************************************************
*   now start the output of a table line (if not suppressed)
***********************************************************************
    if lflg_suppress_item is initial.
*     Number of the displayed line (NOT the index in the internal table)
      l_row_counter = l_row_counter + 1.


***********************************************************************
*     Add the line info cell into data table
***********************************************************************
*     basic data
      clear <ls_lvc_data>.
      <ls_lvc_data>-col_pos = -1.
      <ls_lvc_data>-row_pos = l_row_counter.
      <ls_lvc_data>-row_id  = l_row_id.
*     Line info: the row identification is put into the value field
      ls_row-index = l_row_id.
      ls_row-rowtype = ' '.
      <ls_lvc_data>-value = ls_row.
*     style in case of zebra line coloring
      if rs_layout-zebra = 'X'.
        l_counter = 1 - l_counter.
        if l_counter is initial.
          <ls_lvc_data>-style4 = <ls_lvc_data>-style4 +
                                  alv_style4_zebra_row.
        endif.
      endif.
*     complex style definition
      if not rs_layout-stylefname is initial.
        read table <gt_style> into gs_style
                   with key fieldname = space.
        if sy-subrc = 0.
          <ls_lvc_data>-style  = <ls_lvc_data>-style  + gs_style-style.
          <ls_lvc_data>-style2 = <ls_lvc_data>-style2 + gs_style-style2.
          <ls_lvc_data>-style3 = <ls_lvc_data>-style3 + gs_style-style3.
          <ls_lvc_data>-style4 = <ls_lvc_data>-style4 + gs_style-style4.
          <ls_lvc_data>-maxlen = gs_style-maxlen.
        endif.
      endif.
*     derive style of this line
      clear l_style_color.
      if not rs_layout-info_fname is initial.
        l_color = <field>.
        if l_color(1) = 'C'.
          clear l_style.
          perform style_for_listcolor     using l_color+1(3)
                                          l_style_color
                                          ls_dummy.
          <ls_lvc_data>-style = <ls_lvc_data>-style + l_style_color.
        endif.
      endif.
*     get dragdrop data
      if not rs_layout-s_dragdrop-row_ddid is initial.
        <ls_lvc_data>-dragdropid = rs_layout-s_dragdrop-row_ddid.
      endif.
      if not rs_layout-s_dragdrop-fieldname is initial.
        read table gt_dragdrop into ls_dragdrop
                               with key fieldname = space
                               binary search.
        if sy-subrc = 0.
          <ls_lvc_data>-dragdropid = ls_dragdrop-dragdropid.
        endif.
      endif.


***********************************************************************
*     fill table roid
***********************************************************************
      gs_roid-row_id = l_row_id.
      clear gs_roid-sub_row_id.
      append gs_roid to rt_roid.


***********************************************************************
*     store starting index data
***********************************************************************
      describe table rt_lvc_data lines ls_start_index-start_indx.
      ls_start_index-filled  = space.
      ls_start_index-counter = l_counter.
      ls_start_index-row_id  = l_row_id.
      ls_start_index-row_pos = l_row_counter.
      modify ct_start_index from ls_start_index index l_row_id.


***********************************************************************
*     now fill all columns of this line with empty data
***********************************************************************
      append lines of lt_lvc_columns to rt_lvc_data.


************************************************************************
*     end of code for a not suppressed line:
***********************************************************************
    endif.


***********************************************************************
*   output of sum
***********************************************************************
    if rs_layout-totals_bef is initial.
      read table rt_grouplevels into ls_grouplevels
                                with key index_to = l_row_id
*                                    SUBTOT = 'X'
                                                  binary search.

      if sy-subrc = 0.
        perform subtotals_out_behind_new tables rt_collect01
                                       rt_collect02
                                       rt_collect03
                                       rt_collect04
                                       rt_collect05
                                       rt_collect06
                                       rt_collect07
                                       rt_collect08
                                       rt_collect09
                                       rt_lvc_data
                                using  r_grid
                                       rt_fieldcat
                                       ct_fieldcat_local
                                       rt_poid
                                       rt_idpo
                                       rt_roid
                                       rs_layout
                                       rt_grouplevels
                                       ls_grouplevels
                                       rs_total_options
                                       l_row_id
                                       l_row_counter.
      endif.
    endif.

***********************************************************************
*   and of loop at the data table:
***********************************************************************
  endloop.


***********************************************************************
* output of last sum if necessary
***********************************************************************
  if rs_layout-totals_bef is initial.
    clear ls_grouplevels.
    describe table rt_grouplevels lines l_grouptabix.
    if rs_layout-no_totline is initial.
      perform total_out_new tables rt_collect00
                               rt_lvc_data
                        using  r_grid
                               rt_fieldcat
                               ct_fieldcat_local
                               rt_poid
                               rt_idpo
                               rt_roid
                               rs_layout
                               ls_grouplevels
                               rs_total_options
                               l_row_counter
                               l_grouptabix
                               'T'.
    endif.
  endif.

endform.                                                "
*---------------------------------------------------------------------*
*       FORM DATA_TABLE_FILL
*---------------------------------------------------------------------*
form data_table_fill
       tables
         rt_data
       using
         i_start_index         type i
         i_end_index           type i
         rs_layout             type lvc_s_layo
         ct_lvc_data           type lvc_t_data
         ct_fieldcat_local     type lvc_t_fcat
         cs_layout_local       type lvc_s_layl
         ct_start_index        type lvc_t_stin
         rt_except_qinfo       type lvc_t_qinf
         ir_salv_adapter       type ref to if_salv_adapter.

  field-symbols:
    <ls_fieldcat>              type lvc_s_fcat,
    <field>                    type any,
    <lt_dragdrop>              type lvc_t_drdr,
    <ls_start_index>           type lvc_s_stin,
    <ls_lvc_data>              type lvc_s_data,
    <l_excp_fname>             type any.

  field-symbols: <fs_component> type any.

  data: lr_type_descr  type ref to cl_abap_typedescr,
        lr_table_descr type ref to cl_abap_tabledescr,
        lr_struc_descr type ref to cl_abap_structdescr,
        lt_components  type abap_compdescr_tab,
        l_struc_lvc    type char1,
        lt_slis_coltab type slis_t_specialcol_alv,
        lt_coltab      type lvc_t_scol,
        ls_color       type lvc_s_scol,
        ls_slis_color  type slis_specialcol_alv.

  data:
    l_style_color              type lvc_s_data-style,
    ls_layout                  type lvc_s_layo,
    ls_fcat                    type lvc_s_fcat,
    l_data_start               type i,
    l_data_end                 type i,
    l_lvc_index                type i,
    lt_dragdrop                type lvc_t_drdr,
    lt_style                   type lvc_t_styl,
    l_index                    type i,
    l_end_index                type i,
    l_row_id                   type i.

  data: ls_except_qinfo type lvc_s_qinf,
        l_add_stdinf type icon-internal.

  data: l_accessibility_mode type char1.

*>>> new API
  field-symbols: <lt_celltype>  type salv_t_int4_column,
                 <lt_hyperlink> type salv_t_int4_column,
                 <lt_dropdown>  type salv_t_int4_column.

  data: lr_display         type ref to if_salv_display_adapter,
        lr_columns         type ref to cl_salv_columns_list,

        l_celltype_column  type lvc_fname,
        lt_celltype        type salv_t_int4_column,
        ls_celltype        type salv_s_int4_column,
        l_no_celltype      type sap_bool,

        l_hyperlink_column type lvc_fname,
        lt_hyperlink       type salv_t_int4_column,
        ls_hyperlink       type salv_s_int4_column,
        l_no_hyperlink     type sap_bool,                   "#EC NEEDED

        l_dropdown_column  type lvc_fname,
        lt_dropdown        type salv_t_int4_column,
        ls_dropdown        type salv_s_int4_column,
        l_no_dropdown      type sap_bool.                   "#EC NEEDED

  if ir_salv_adapter is bound.
    try.
        lr_display ?= ir_salv_adapter.

        lr_columns ?= lr_display->get_columns( ).

        l_celltype_column  = lr_columns->get_cell_type_column( ).
        l_hyperlink_column = lr_columns->get_hyperlink_entry_column( ).
        l_dropdown_column  = lr_columns->get_dropdown_entry_column( ).

      catch cx_sy_assign_cast_illegal_cast.             "#EC NO_HANDLER
    endtry.
  endif.
*<<< new API

  call function 'GET_ACCESSIBILITY_MODE'
    importing
      accessibility     = l_accessibility_mode
    exceptions
      its_not_available = 0
      others            = 0.

**********************************************************************
* derive start index
**********************************************************************
  l_data_start = 1.
  l_index      = i_start_index.
  l_end_index  = i_end_index.
  do.
    if l_index <= 0 or l_end_index <= 0.
      exit.
    endif.
    read table ct_lvc_data assigning <ls_lvc_data> index l_index.
    if <ls_lvc_data>-col_pos = -1 and <ls_lvc_data>-row_id > 0.
      l_data_start = <ls_lvc_data>-row_id.
      exit.
    endif.
    l_index = l_index - 1.
  enddo.


**********************************************************************
* derive end index
**********************************************************************
  describe table rt_data lines l_data_end.
  l_index = i_end_index.
  do.
    if l_index <= 0.
      exit.
    endif.
    read table ct_lvc_data assigning <ls_lvc_data> index l_index.
    if <ls_lvc_data>-col_pos = -1 and <ls_lvc_data>-row_id > 0.
      l_data_end = <ls_lvc_data>-row_id.
      exit.
    endif.
    l_index = l_index - 1.
  enddo.


**********************************************************************
* fill data of this package
**********************************************************************
  loop at ct_start_index assigning <ls_start_index>
                    from l_data_start
                      to l_data_end
                   where filled is initial
                     and not start_indx = -1.
    l_row_id = sy-tabix.

*   set flag that this line was already filled
    <ls_start_index>-filled = 'X'.

*   point to line in the real data table
    read table rt_data assigning <gs_table> index l_row_id .

*   callback for merging
    if not g_exit is initial.
      perform (g_routine)
                          in program (g_callback)
                               using l_row_id
                                     g_stop_merge.
    endif.


**********************************************************************
*   point to several fields in the workarea
**********************************************************************
*... point to color table of this line
***********************************************************************
* color
***********************************************************************
    if not rs_layout-ctab_fname is initial.
      assign component rs_layout-ctab_fname
             of structure rt_data to <fs_component>.
      if sy-subrc eq 0.
        lr_type_descr =
                cl_abap_typedescr=>describe_by_data( <fs_component> ).
        case lr_type_descr->type_kind.
          when cl_abap_typedescr=>typekind_table.
*...cast to class tabledescr.
            lr_table_descr ?= lr_type_descr.
            lr_struc_descr ?= lr_table_descr->get_table_line_type( ).
          when cl_abap_typedescr=>typekind_struct1 or
               cl_abap_typedescr=>typekind_struct2.
*...cast to class structdescr.
            lr_struc_descr ?= lr_type_descr.
        endcase.

        lt_components = lr_struc_descr->components.

        read table lt_components with key name = 'FNAME'
                   transporting no fields.
        if sy-subrc eq 0.
*... color is in lvc structure
          l_struc_lvc = 'X'.
        else.
*... color is in slis structure
          l_struc_lvc = space.
        endif.
      endif.

      clear lt_coltab.
      if l_struc_lvc eq space.
*... column contains color in slis structure
        if not cs_layout_local-indx_ctab is initial.
          assign component cs_layout_local-indx_ctab
                           of structure <gs_table> to <slis_coltab>.
          if sy-subrc ne 0.
            assign lt_slis_coltab to <slis_coltab>.
          endif.
        else.
          assign component rs_layout-ctab_fname
                           of structure <gs_table> to <slis_coltab>.
          if sy-subrc ne 0.
            assign lt_slis_coltab to <slis_coltab>.
          endif.
        endif.
        loop at <slis_coltab> into ls_slis_color.
          move-corresponding ls_slis_color to ls_color.
          ls_color-fname = ls_slis_color-fieldname.
          append ls_color to lt_coltab.
        endloop.
        assign lt_coltab to <coltab>.
      else.
*... column contains color in lvc structure
        if not cs_layout_local-indx_ctab is initial.
          assign component cs_layout_local-indx_ctab
                           of structure <gs_table> to <coltab>.
          if sy-subrc ne 0.
            assign lt_coltab to <coltab>.
          endif.
        else.
          assign component rs_layout-ctab_fname
                           of structure <gs_table> to <coltab>.
          if sy-subrc ne 0.
            assign lt_coltab to <coltab>.
          endif.
        endif.
      endif.
    else.
*... default Zuweisung
      assign lt_coltab to <coltab>.
    endif.

*   point to info field of this line
    if not rs_layout-info_fname is initial.
      if not cs_layout_local-indx_info is initial.
        assign component cs_layout_local-indx_info
                         of structure <gs_table> to <field>.
      else.
        assign component rs_layout-info_fname
                         of structure <gs_table> to <field>.
        if sy-subrc ne 0.
          assign ls_layout-info_fname to <field>.
        endif.
      endif.
    endif.

*   point to style table of this line
    if not rs_layout-stylefname is initial.
      if not cs_layout_local-indx_style is initial.
        assign component cs_layout_local-indx_style
                         of structure <gs_table> to <gt_style>.
      else.
        assign component rs_layout-stylefname
                         of structure <gs_table> to <gt_style>.
        if sy-subrc ne 0.
          assign lt_style to <gt_style>.
        endif.
      endif.
    endif.

*   point to dragdropid-table of this line
    if not rs_layout-s_dragdrop-fieldname is initial.
      if not cs_layout_local-indx_drnd is initial.
        assign component cs_layout_local-indx_drnd
                         of structure <gs_table> to <lt_dragdrop>.
      else.
        assign component rs_layout-s_dragdrop-fieldname
                         of structure <gs_table> to <lt_dragdrop>.
        if sy-subrc ne 0.
          assign lt_dragdrop to <lt_dragdrop>.
        endif.
      endif.
      gt_dragdrop[] = <lt_dragdrop>.
    endif.

*   point to excp_fname of this line
    if not rs_layout-excp_fname is initial.
      if not cs_layout_local-indx_excp is initial.
        assign component cs_layout_local-indx_excp
                         of structure <gs_table> to <l_excp_fname>.
      else.
        assign component rs_layout-excp_fname
                         of structure <gs_table> to <l_excp_fname>.
        if sy-subrc ne 0.
          assign ls_layout-excp_fname to <l_excp_fname>.
        endif.
      endif.
    endif.


***********************************************************************
*   initialize gs_lvc_data
***********************************************************************
    clear gs_lvc_data.
    gs_lvc_data-row_pos = <ls_start_index>-row_pos.
    gs_lvc_data-row_id  = <ls_start_index>-row_id.
    l_lvc_index         = <ls_start_index>-start_indx + 1.


***********************************************************************
*    fill exception cell if necessary
***********************************************************************
    if not rs_layout-excp_fname is initial.
      data: excp type char10.
      move <l_excp_fname> to excp.
      condense excp.
      case rs_layout-excp_group.
        when '1' or '0' or space.
*         Exception von der Gruppe "LIGHT"/"LED"
*          case <l_excp_fname>+0(1).
          case excp+0(1).
            when '0'.
              if rs_layout-excp_led eq 'X'.
                gs_lvc_data-value = icon_led_inactive.
              else.
                gs_lvc_data-value = icon_light_out.
              endif.
            when '1'.
              if rs_layout-excp_led eq 'X'.
                gs_lvc_data-value = icon_led_red.
              else.
                gs_lvc_data-value = icon_red_light.
              endif.
            when '2'.
              if rs_layout-excp_led eq 'X'.
                gs_lvc_data-value = icon_led_yellow.
              else.
                gs_lvc_data-value = icon_yellow_light.
              endif.
            when '3'.
              if rs_layout-excp_led eq 'X'.
                gs_lvc_data-value = icon_led_green.
              else.
                gs_lvc_data-value = icon_green_light.
              endif.
          endcase.
        when '2'.
*         Exception von der Gruppe "LED"
*          case <l_excp_fname>+0(1).
          case excp+0(1).
            when '0'.
              gs_lvc_data-value = icon_led_inactive.
            when '1'.
              gs_lvc_data-value = icon_led_red.
            when '2'.
              gs_lvc_data-value = icon_led_yellow.
            when '3'.
              gs_lvc_data-value = icon_led_green.
          endcase.
        when '3'.
*         Exception von der Gruppe "STATUS"
*          case <l_excp_fname>+0(1).
          case excp+0(1).
            when '0'.
              gs_lvc_data-value = icon_no_status.
            when '1'.
              gs_lvc_data-value = icon_status_critical.
            when '2'.
              gs_lvc_data-value = icon_status_alert.
            when '3'.
              gs_lvc_data-value = icon_status_ok.
            when '4'.
              gs_lvc_data-value = icon_status_best.
          endcase.
        when '4'.
*         Exception von der Gruppe "TREND"
*          case <l_excp_fname>+0(1).
          case excp+0(1).
            when '1'.
              gs_lvc_data-value = icon_trend_down.
            when '2'.
              gs_lvc_data-value = icon_trend_unchanged.
            when '3'.
              gs_lvc_data-value = icon_trend_up.
            when '4'.
              gs_lvc_data-value = icon_trend_decreasing.
            when '5'.
              gs_lvc_data-value = icon_trend_rising.
          endcase.
        when '5'.
*         Exception von der Gruppe "MESSAGE"
*          case <l_excp_fname>+0(1).
          case excp+0(1).
            when '1'.
              gs_lvc_data-value = icon_message_error_small.
            when '2'.
              gs_lvc_data-value = icon_message_warning_small.
            when '3'.
              gs_lvc_data-value = icon_message_information_small.
            when '4'.
              gs_lvc_data-value = icon_message_critical_small.
            when '5'.
              gs_lvc_data-value = icon_message_question_small.
          endcase.
        when '6'.
*         Exception von der Gruppe "ALERT/WARNING/HINT"
*          case <l_excp_fname>+0(1).
          case excp+0(1).
            when '1'.
              gs_lvc_data-value = icon_alert.
            when '2'.
              gs_lvc_data-value = icon_warning.
            when '3'.
              gs_lvc_data-value = icon_hint.
          endcase.
        when '7'.
*         Exception von der Gruppe "FAILURE/INCOMPLETE/CHECKED"
*          case <l_excp_fname>+0(1).
          case excp+0(1).
            when '1'.
              gs_lvc_data-value = icon_failure.
            when '2'.
              gs_lvc_data-value = icon_incomplete.
            when '3'.
              gs_lvc_data-value = icon_checked.
          endcase.
      endcase.

      if l_accessibility_mode eq 'X' or
         not rt_except_qinfo is initial.
*Quickinfo for Exception
        clear ls_except_qinfo.
        read table rt_except_qinfo into ls_except_qinfo
             with key value = <l_excp_fname>
                      type = cl_salv_tooltip=>c_type_exception.
        if sy-subrc ne 0.
          read table rt_except_qinfo into ls_except_qinfo
               with key value = <l_excp_fname>.
          if sy-subrc = 0.
            clear l_add_stdinf.
          else.
            l_add_stdinf = 'X'.
          endif.
        endif.
        call function 'ICON_CREATE'
          exporting
            name                        = gs_lvc_data-value
*         TEXT                        = ' '
            info                        = ls_except_qinfo-text
            add_stdinf                  = l_add_stdinf
          importing
            result                      = gs_lvc_data-value
          exceptions
            icon_not_found              = 0
            outputfield_too_short       = 0
            others                      = 0.
      endif.

*     derive style of this exception cell
      if g_gui_type ne 1.
        gs_lvc_data-style = alv_style_color_normal +
                            alv_style_align_center_top.
      endif.
*     put result into table
      add 1 to gs_lvc_data-col_pos.
      add 1 to l_lvc_index.
      modify ct_lvc_data from gs_lvc_data index l_lvc_index.
    endif.


***********************************************************************
*   now fill all columns of this line
***********************************************************************
    loop at ct_fieldcat_local assigning <ls_fieldcat>.

      clear: gs_lvc_data-href_hndl,
             gs_lvc_data-drdn_hndl,
             gs_lvc_data-style,
             gs_lvc_data-style2,
             gs_lvc_data-style3,
             gs_lvc_data-style4,
             gs_lvc_data-maxlen.

*     point to field in workarea
      if not <ls_fieldcat>-indx_field is initial.
        assign component <ls_fieldcat>-indx_field
            of structure <gs_table> to <g_field>.
      else.
        assign component <ls_fieldcat>-fieldname
            of structure <gs_table> to <g_field>.
        if sy-subrc ne 0.
          assign ls_fcat-fieldname to <g_field>.
        endif.
      endif.

*     carry out WRITE statement to fill value of this cell
      macro_cell_data_get
*           USING
              <ls_fieldcat>
              <gs_table>
              <g_field>
*           CHANGING
              gs_lvc_data-value.

*>>> new API
      if ir_salv_adapter is bound.
        clear gs_lvc_data-style.

* color
        if g_gui_type ne 1.
          if <ls_fieldcat>-key = 'X'.
            gs_lvc_data-style = alv_style_color_int_key.
          elseif l_style_color is initial
                and ( <ls_fieldcat>-emphasize is initial or
                      <ls_fieldcat>-emphasize = '$' ).
            if <ls_start_index>-counter is initial.
              gs_lvc_data-style = alv_style_color_normal.
            else.
              gs_lvc_data-style = alv_style_color_int_normal.
            endif.
          endif.
        endif.

*       is there a complex color table defined ?
        if not rs_layout-ctab_fname is initial.
          clear g_style_color.
          perform field_color_complex using <coltab>
                                            <ls_fieldcat>
                                            g_style_color.
          if not g_style_color is initial.
            gs_lvc_data-style = g_style_color.
          endif.
        endif.

        clear l_no_celltype.
        assign component l_celltype_column of structure <gs_table> to <lt_celltype>.
        if sy-subrc ne 0.
          assign lt_celltype to <lt_celltype>.
        endif.
        read table <lt_celltype> into ls_celltype
          with key columnname = <ls_fieldcat>-fieldname.
        if sy-subrc ne 0.
          read table <lt_celltype> into ls_celltype
            with key columnname = space.
          if sy-subrc ne 0.
            l_no_celltype = 'X'.
          endif.
        endif.

        clear l_no_hyperlink.
        assign component l_hyperlink_column of structure <gs_table> to <lt_hyperlink>.
        if sy-subrc ne 0.
          assign lt_hyperlink to <lt_hyperlink>.
        endif.
        read table <lt_hyperlink> into ls_hyperlink
          with key columnname = <ls_fieldcat>-fieldname.
        if sy-subrc ne 0.
          read table <lt_hyperlink> into ls_hyperlink
            with key columnname = space.
          if sy-subrc ne 0.
            l_no_hyperlink = 'X'.
          endif.
        endif.

        clear l_no_dropdown.
        assign component l_dropdown_column of structure <gs_table> to <lt_dropdown>.
        if sy-subrc ne 0.
          assign lt_dropdown to <lt_dropdown>.
        endif.
        read table <lt_dropdown> into ls_dropdown
          with key columnname = <ls_fieldcat>-fieldname.
        if sy-subrc ne 0.
          read table <lt_dropdown> into ls_dropdown
            with key columnname = space.
          if sy-subrc ne 0.
            l_no_dropdown = 'X'.
          endif.
        endif.

        read table <lt_hyperlink> into ls_hyperlink
          with key columnname = <ls_fieldcat>-fieldname.
        if sy-subrc eq 0.
          gs_lvc_data-href_hndl = ls_hyperlink-value.
        else.
          clear gs_lvc_data-href_hndl.
        endif.

        gs_lvc_data-drdn_hndl = <ls_fieldcat>-drdn_hndl.
        read table <lt_dropdown> into ls_dropdown
          with key columnname = <ls_fieldcat>-fieldname.
        if sy-subrc eq 0.
          gs_lvc_data-drdn_hndl = ls_dropdown-value.
        endif.
        if gs_lvc_data-drdn_hndl is not initial.
          add alv_style_f4_no to gs_lvc_data-style.
        endif.

        if l_no_celltype eq space.
          case ls_celltype-value.
            when if_salv_c_cell_type=>button.
              add alv_style_button to gs_lvc_data-style.

            when others.
              add alv_style_button_no to gs_lvc_data-style.
              clear gs_lvc_data-href_hndl.
              clear gs_lvc_data-drdn_hndl.
          endcase.
        endif.

        if <ls_fieldcat>-hotspot eq 'X'.
          if l_no_celltype eq space and
             ls_celltype-value ne if_salv_c_cell_type=>hotspot.
            add alv_style_single_clk_event_no to gs_lvc_data-style.
          else.
            add alv_style_single_clk_event to gs_lvc_data-style.
          endif.
        else.
          if l_no_celltype eq space and
             ls_celltype-value eq if_salv_c_cell_type=>hotspot.
            add alv_style_single_clk_event to gs_lvc_data-style.
          else.
            add alv_style_single_clk_event_no to gs_lvc_data-style.
          endif.
        endif.

        if <ls_fieldcat>-checkbox eq 'X'.
          if l_no_celltype eq space and
             ls_celltype-value ne if_salv_c_cell_type=>checkbox.
            add alv_style_checkbox_no to gs_lvc_data-style.
            add alv_style_f4_no to gs_lvc_data-style.
          else.
            if <g_field> = 'X'.
              add alv_style_checkbox_checked to gs_lvc_data-style.
            else.
              add alv_style_checkbox_not_checked to gs_lvc_data-style.
            endif.
          endif.
        else.
          if l_no_celltype eq space and
             ls_celltype-value eq if_salv_c_cell_type=>checkbox.
            if <g_field> = 'X'.
              add alv_style_checkbox_checked to gs_lvc_data-style.
            else.
              add alv_style_checkbox_not_checked to gs_lvc_data-style.
            endif.
          endif.
        endif.
      endif.
*<<< new API

      if <ls_fieldcat>-icon eq 'X'.
        clear ls_except_qinfo.
        read table rt_except_qinfo into ls_except_qinfo
               with key type = cl_salv_tooltip=>c_type_icon
                        value     = gs_lvc_data-value.

        if sy-subrc ne 0.
          read table rt_except_qinfo into ls_except_qinfo
             with key fieldname = <ls_fieldcat>-fieldname
                      value     = gs_lvc_data-value.
        endif.

        if sy-subrc eq 0 or l_accessibility_mode eq 'X'.
          if sy-subrc eq 0.
            clear l_add_stdinf.
          else.
            l_add_stdinf = 'X'.
          endif.
          call function 'ICON_CREATE'
            exporting
              name                        = gs_lvc_data-value
*         TEXT                        = ' '
              info                        = ls_except_qinfo-text
              add_stdinf                  = l_add_stdinf
            importing
              result                      = gs_lvc_data-value
            exceptions
              icon_not_found              = 0
              outputfield_too_short       = 0
              others                      = 0.
        endif.
      endif.

*>>> new API
      if ir_salv_adapter is not bound.
*<<< new API
*     is dragdropid to be derived ?
        if not rs_layout-s_dragdrop-fieldname is initial.
          read table gt_dragdrop into gs_dragdrop
                     with key fieldname =  <ls_fieldcat>-fieldname
                     binary search.
          if sy-subrc = 0.
            gs_lvc_data-dragdropid = gs_dragdrop-dragdropid.
          else.
            clear gs_lvc_data-dragdropid.
          endif.
        endif.


***********************************************************************
*     derive style in simple case
***********************************************************************
        if <ls_fieldcat>-get_style is initial.

          if g_stop_merge = 'X'.
            gs_lvc_data-style4 =
                            gs_lvc_data-style4 + alv_style4_stop_merge.
          endif.

        else.


***********************************************************************
*     derive complex style definition if necessary
***********************************************************************
          clear gs_lvc_data-style.
*       get style for columns etc.
          if g_gui_type ne 1.
            if <ls_fieldcat>-key = 'X'.
              gs_lvc_data-style = alv_style_color_int_key.
            elseif l_style_color is initial
                  and ( <ls_fieldcat>-emphasize is initial or
                        <ls_fieldcat>-emphasize = '$' ).
              if <ls_start_index>-counter is initial.
                gs_lvc_data-style = alv_style_color_normal.
              else.
                gs_lvc_data-style = alv_style_color_int_normal.
              endif.
            endif.
          endif.
*       point to web field
          if not <ls_fieldcat>-web_field is initial.
            assign component <ls_fieldcat>-web_field
                   of structure <gs_table> to <g_href>.
            if sy-subrc ne 0.
              assign ls_fcat-web_field to <g_href>.
            endif.
            gs_lvc_data-href_hndl = <g_href>.
          else.
            clear gs_lvc_data-href_hndl.
          endif.
*       point to drag&drop field
          if not <ls_fieldcat>-drdn_field is initial.
            assign component <ls_fieldcat>-drdn_field
                   of structure <gs_table> to <g_href>.
            if sy-subrc ne 0.
              assign ls_fcat-drdn_field to <g_href>.
            endif.
            gs_lvc_data-drdn_hndl = <g_href>.
          else.
            clear gs_lvc_data-drdn_hndl.
          endif.
*       is there a complex color table defined ?
          if not rs_layout-ctab_fname is initial.
            clear g_style_color.
            perform field_color_complex using <coltab>
                                              <ls_fieldcat>
                                              g_style_color.
            if not g_style_color is initial.
              gs_lvc_data-style = g_style_color.
            endif.
          endif.
*       is a complex style defined ?
          if not rs_layout-stylefname is initial.
            read table <gt_style> into gs_style
                       with key fieldname = <ls_fieldcat>-fieldname.
            if sy-subrc = 0.
              gs_lvc_data-style  = gs_lvc_data-style  + gs_style-style.
              gs_lvc_data-style2 = gs_lvc_data-style2 + gs_style-style2.
              gs_lvc_data-style3 = gs_lvc_data-style3 + gs_style-style3.
              gs_lvc_data-style4 = gs_lvc_data-style4 + gs_style-style4.
              gs_lvc_data-maxlen = gs_style-maxlen.
            endif.
          endif.
*       deactivate hotspot when field is initial
          if <ls_fieldcat>-hotspot = 'V' and
                        gs_lvc_data-value is initial.
            add alv_style_single_clk_event_no to gs_lvc_data-style.
          endif.
*       set sytle for a checkbox/radiobutton
          if <ls_fieldcat>-checkbox = 'X'.
            if <g_field> ca '01'.
              add alv_style_enabled to gs_lvc_data-style.
            else.
*           add alv_style_disabled to gs_lvc_data-style.
            endif.
            if <g_field> = 'X' or <g_field> = '1'.
              add alv_style_checkbox_checked to gs_lvc_data-style.
            elseif <g_field> = space or <g_field> = '0'.
              add alv_style_checkbox_not_checked to gs_lvc_data-style.
            elseif <g_field> = '-'.
              add alv_style_checkbox_no to gs_lvc_data-style.
            endif.
          elseif <ls_fieldcat>-checkbox = 'R'.
            if <g_field> ca '01'.
              add alv_style_enabled to gs_lvc_data-style.
            else.
              add alv_style_disabled to gs_lvc_data-style.
            endif.
            if <g_field> = 'X' or <g_field> = '1'.
              add alv_style_radio_checked to gs_lvc_data-style.
            elseif <g_field> = space or <g_field> = '0'.
              add alv_style_radio_not_checked to gs_lvc_data-style.
            elseif <g_field> = '-'.
              add alv_style_radio_no to gs_lvc_data-style.
            endif.
          endif.

        endif"if <ls_fieldcat>-get_style is initial
*>>> new API
      endif.
*<<< new API

***********************************************************************
*     put result into table
***********************************************************************
      add 1 to gs_lvc_data-col_pos.
      add 1 to l_lvc_index.
      modify ct_lvc_data from gs_lvc_data index l_lvc_index.


    endloop.

  endloop.


endform.                    "data_table_fill

*&---------------------------------------------------------------------*
*&      Form  data_table_determine
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form data_table_determine tables it_data
                                 it_collect00
                                 it_collect01
                                 it_collect02
                                 it_collect03
                                 it_collect04
                                 it_collect05
                                 it_collect06
                                 it_collect07
                                 it_collect08
                                 it_collect09
                           using is_layo        type lvc_s_layo
                                 value(it_fcat) type lvc_t_fcat
                                 it_fidx        type lvc_t_fidx
                                 is_toto        type lvc_s_toto
                        changing cs_layo_local  type lvc_s_layl
                                 ct_fcat_local  type lvc_t_fcat
                                 ct_grpl        type lvc_t_grpl
                                 ct_roid        type lvc_t_roid
                                 ct_poid        type lvc_t_poid
                                 ct_stin        type lvc_t_stin
                                 c_columns      type i
                                 c_lines        type i.

***********************************************************************
* analyse field catalog and layout structure
***********************************************************************
  clear: ct_fcat_local, cs_layo_local.
  sort it_fcat stable by col_pos.
  perform analyse_fieldcat_new
            using
              it_data[]
              is_layo
              it_fcat
            changing
              ct_fcat_local
              cs_layo_local.

***********************************************************************
* determine columns per line
***********************************************************************
  describe table ct_fcat_local lines c_columns.
  add 1 to c_columns. "col_pos = -1
  if not is_layo-excp_fname is initial.
    add 1 to c_columns.
  endif.

***********************************************************************
* determine if filter exists
***********************************************************************
  data: l_filter type boolean.
  if not it_fidx is initial.
    l_filter = 'X'.
  endif.

***********************************************************************
* prepare group level tables
***********************************************************************
  if is_layo-totals_bef is initial.
*... Totals should be given out behind the related items
    sort ct_grpl by index_to   ascending
                    index_from descending
                    level      descending.
  else.
*... Totals should be given out before the related items
    sort ct_grpl by index_from ascending
                    index_to   descending
                    level      ascending.
  endif.

  data: lt_groups type lvc_t_grpl,
        ls_groups type lvc_s_grpl.

  lt_groups = ct_grpl.
  if is_layo-totals_bef is initial.
    sort lt_groups by index_from ascending
                      index_to   descending
                      level      ascending      .
  endif.

***********************************************************************
* DATA TABLE
***********************************************************************
  data: l_row_counter   type i,
        l_lin           type i,
        ls_roid         type lvc_s_roid,
        ls_stin         type lvc_s_stin,
        ls_grpl         type lvc_s_grpl,
        l_grpl_idx      type i.

  clear: ct_roid, ct_poid, ct_stin.

***********************************************************************
* Total before line items
***********************************************************************
  if not is_layo-totals_bef is initial.
    if is_toto-totals_out eq 'X'.
      if is_layo-no_totline is initial.
        perform total tables it_collect00
                       using is_toto
                             ls_grpl
                             ct_fcat_local
                             1
                             c_columns
                             'T'
                    changing l_row_counter
                             ct_roid
                             ct_poid
                             ct_stin.
      endif.
    endif.
  endif.

***********************************************************************
* Go through the item lines
***********************************************************************
  data: l_row_id        type sytabix,
        l_suppress_item type boolean,
        l_counter       type i.

  loop at it_data assigning <gs_table>.
    l_row_id = sy-tabix.

*   if this line has been filtered then continue since the data
*   is not allowed to be displayed
    if l_filter eq 'X'.
      read table it_fidx from l_row_id transporting no fields.
      if sy-subrc eq 0.
        continue.
      endif.
    endif.

*   if the subtotal for this line item has been compressed then
*   the line is not alloed to appear
*   the flag l_suppress_item is set and in this case the line
*   item is not filled for display
    if is_toto-totals_out = 'X' or
       is_toto-subtot_out = 'X'.
      if ls_groups is initial or l_row_id gt ls_groups-index_to.
        read table lt_groups into ls_groups
          with key index_from = l_row_id
                   level      = is_toto-max_level
                   subtot     = 'X'
          binary search.
      endif.
      if ls_groups-compress eq 'X' and
         g_view ne cl_gui_alv_grid=>mc_fc_view_excel.
        l_suppress_item = 'X'.
      else.
        clear l_suppress_item.
      endif.
    endif.

***********************************************************************
* Subtotal before related line items
***********************************************************************
    if not is_layo-totals_bef is initial.
      if is_toto-subtot_out eq 'X'.
        perform subtotals tables it_collect01
                                 it_collect02
                                 it_collect03
                                 it_collect04
                                 it_collect05
                                 it_collect06
                                 it_collect07
                                 it_collect08
                                 it_collect09
                           using ct_grpl
                                 is_toto
                                 ct_fcat_local
                                 c_columns
                                 l_row_id
                                 'X'
                        changing l_row_counter
                                 ct_roid
                                 ct_poid
                                 ct_stin.
      endif.
    endif.

*   if the line item has not been suppressed by a collapsed subotal
*   then it can be entered for display
    if l_suppress_item is initial.
      add 1 to l_row_counter.

*... fill table roid
      ls_roid-row_id = l_row_id.
      clear ls_roid-sub_row_id.
      append ls_roid to ct_roid.

*... fill table stin
      if is_layo-zebra eq 'X'.
        l_counter = 1 - l_counter.
      endif.

      describe table ct_stin lines l_lin.
      ls_stin-start_indx = ( l_lin * c_columns ) + 1.
      ls_stin-row_id  = l_row_id.
      ls_stin-row_pos = l_row_counter.
      ls_stin-counter = l_counter.
      append ls_stin to ct_stin.
    endif.

***********************************************************************
* Subtotal after related line items
***********************************************************************
    if is_layo-totals_bef is initial.
      if is_toto-subtot_out eq 'X'.
        perform subtotals tables it_collect01
                                 it_collect02
                                 it_collect03
                                 it_collect04
                                 it_collect05
                                 it_collect06
                                 it_collect07
                                 it_collect08
                                 it_collect09
                           using ct_grpl
                                 is_toto
                                 ct_fcat_local
                                 c_columns
                                 l_row_id
                                 space
                        changing l_row_counter
                                 ct_roid
                                 ct_poid
                                 ct_stin.
      endif.
    endif.
  endloop.

***********************************************************************
* Total after line items
***********************************************************************
  if is_layo-totals_bef is initial.
    if is_toto-totals_out eq 'X'.
      if is_layo-no_totline is initial.
        describe table ct_grpl lines l_grpl_idx.
        perform total tables it_collect00
                       using is_toto
                             ls_grpl
                             ct_fcat_local
                             l_grpl_idx
                             c_columns
                             'T'
                    changing l_row_counter
                             ct_roid
                             ct_poid
                             ct_stin.
      endif.
    endif.
  endif.

* determine how many lines the table ct_data actually has
* by multiplying the line items with the amount of columns
  describe table ct_stin lines l_lin.
  c_lines = l_lin * c_columns.

endform.                    " data_table_determine

*&---------------------------------------------------------------------*
*&      Form  total
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form total tables it_collect
            using is_toto           type lvc_s_toto
                  value(is_grpl)    type lvc_s_grpl
                  it_fcat           type lvc_t_fcat
                  value(i_grpl_idx) type i
                  i_columns         type i
                  i_type            type char1
         changing c_row_counter     type i
                  ct_roid           type lvc_t_roid
                  ct_poid           type lvc_t_poid
                  ct_stin           type lvc_t_stin.

  data: l_lin           type i,
        ls_level        type lvc_s_sort,
        ls_roid         type lvc_s_roid,
        ls_poid         type lvc_s_roro,
        ls_stin         type lvc_s_stin,
        ls_row          type lvc_s_row,
        l_level(2)      type n,
        l_subs_n(10)    type n,
        l_subs          type i.

* if this is a total line then there is no grouplevel information
* for this line, since grouplevel information is only given for
* subtotals. In this case the grouplevel index is also initial
  if i_type eq 'T'.
    clear is_grpl.
    clear i_grpl_idx.
  endif.

* if a subtotal line holds more then one line (this is the case if
* more then one currency exists) then there is a range from where
* the subtotal starts and ends in the collect table.
* If the subotal line consists of only one line then the start and
* end range are identical.
* If the line is a total line then the range will be empty. In this
* case the range begins with 1 and ends at the end of the table
  if is_grpl-cindx_from is initial and
     is_grpl-cindx_to   is initial.
    describe table it_collect lines l_lin.
    is_grpl-cindx_from = 1.
    is_grpl-cindx_to   = l_lin.
  endif.

*... fill initial row information
* _ _ __ __ _ __________
* [1]   first character reserved for type (T)(S)(A)
* [2]   second character reserved for information if the item is a
*       following line item of the subtotal (F)
* [3,4] 3rd and fourth character is reserved for the level (??)
* [5,6] 5th and 6th character are reserved for grouplevel level (??)
* [7]   7th character is reserved for collapsed information (X)
* [8-17] the rest holds the sub_row_id of this subtotal
  ls_row-rowtype = i_type. "(T)otal (S)ubtotal (A)invisible subtotal
  describe table is_toto-t_levels lines l_level.
  add 1 to l_level.
  if i_type eq 'T'.
    ls_row-rowtype+2 = l_level.
  else.
    read table is_toto-t_levels into ls_level
      with key level = is_grpl-level.
    l_level = l_level - sy-tabix.
    ls_row-rowtype+2 = l_level.
  endif.
  l_level = is_grpl-level.
  ls_row-rowtype+4 = l_level.
  ls_row-index = i_grpl_idx.
  if ls_level-no_out eq 'X'.
    ls_row-rowtype(1) = 'A'.
  endif.
  if is_grpl-compress eq 'X'.
    ls_row-rowtype+6(1) = 'X'.
  endif.

  loop at it_collect from is_grpl-cindx_from
                     to   is_grpl-cindx_to.
    add 1 to c_row_counter.

*... fill row information
    add 1 to l_subs.
    l_subs_n = l_subs.
    ls_row-rowtype+7(10) = l_subs_n.
    if l_subs gt 1.
      ls_row-rowtype+1(1) = 'F'.
    endif.

*... fill table roid
    if ls_row-rowtype is initial.
      ls_roid-row_id = ls_row-index.
      clear ls_roid-sub_row_id.
    else.
      if i_type eq 'T'.
        ls_roid-row_id = 0.
      else.
        ls_roid-row_id = ls_row-index * -1.
      endif.
      ls_roid-sub_row_id = ls_row-rowtype+7(10).
    endif.
    append ls_roid to ct_roid.

*... fill table poid
    ls_poid-row_id     = ls_roid-row_id.
    ls_poid-sub_row_id = ls_roid-sub_row_id.
    ls_poid-rowtype    = ls_row-rowtype.
    ls_poid-index      = ls_row-index.
    if ls_poid-rowtype(1eq 'A'.
      read table it_fcat with key col_pos = 1
                                  do_sum  = 'X'
                                  no_out  = space
                         transporting no fields.
      if sy-subrc eq 0.
        ls_poid-rowtype(1) = 'S'.
      endif.
    endif.
    insert ls_poid into table ct_poid.

*... fill table stin
    describe table ct_stin lines l_lin.
    ls_stin-start_indx = ( l_lin * i_columns ) + 1.
    ls_stin-row_id  = 0.
    ls_stin-row_pos = c_row_counter.
    ls_stin-counter = ls_poid-row_id.
    append ls_stin to ct_stin.
  endloop.

endform.                    " total

*&---------------------------------------------------------------------*
*&      Form  subtotals
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form subtotals tables it_collect01
                      it_collect02
                      it_collect03
                      it_collect04
                      it_collect05
                      it_collect06
                      it_collect07
                      it_collect08
                      it_collect09
                using it_grpl   type lvc_t_grpl
                      is_toto   type lvc_s_toto
                      it_fcat   type lvc_t_fcat
                      i_columns type i
                      i_row_id  type i
                      i_before  type boolean
             changing c_row_counter    type i
                      ct_roid          type lvc_t_roid
                      ct_poid          type lvc_t_poid
                      ct_stin          type lvc_t_stin.     "#EC *

  field-symbols: <lt_table> type table.

  data: ls_grpl    type lvc_s_grpl,
        l_grpl_idx type i.

  data: l_level(2)    type n,
        l_tabname(30type c.

  if i_before is initial.
    read table it_grpl into ls_grpl
      with key index_to = i_row_id
      binary search.
  else.
    read table it_grpl into ls_grpl
      with key index_from = i_row_id
      binary search.
  endif.

  check sy-subrc eq 0.

  l_grpl_idx = sy-tabix.

  do.
    if ls_grpl-subtot eq 'X' and
      ( ( ls_grpl-hide_level is initial and ls_grpl-compressed is initial ) or
         ( g_view = cl_gui_alv_grid=>mc_fc_view_excel )
        ) and ls_grpl-cindx_from ne 0.
      l_level = ls_grpl-level.
      concatenate 'IT_COLLECT' l_level '[]' into l_tabname.
      assign (l_tabname) to <lt_table>.

      perform total tables <lt_table>
                     using is_toto
                           ls_grpl
                           it_fcat
                           l_grpl_idx
                           i_columns
                           'S'
                  changing c_row_counter
                           ct_roid
                           ct_poid
                           ct_stin.
    endif.

    add 1 to l_grpl_idx.
    clear ls_grpl.
    read table it_grpl into ls_grpl index l_grpl_idx.
    if i_before is initial.
      if ls_grpl-index_to ne i_row_id or sy-subrc ne 0.
        exit.
      endif.
    else.
      if ls_grpl-index_from ne i_row_id or sy-subrc ne 0.
        exit.
      endif.
    endif.
  enddo.

endform.                    " subtotals

*&---------------------------------------------------------------------*
*&      Form  fill_data_table
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form fill_data_table tables it_data
                            it_collect00
                            it_collect01
                            it_collect02
                            it_collect03
                            it_collect04
                            it_collect05
                            it_collect06
                            it_collect07
                            it_collect08
                            it_collect09
                      using i_start         type i
                            i_end           type i
                            i_delete_entries_not_in_range type abap_bool
                            it_roid         type lvc_t_roid
                            it_poid         type lvc_t_poid
                            is_layo         type lvc_s_layo
                            is_layo_local   type lvc_s_layl
                            is_toto         type lvc_s_toto
                            it_qinf         type lvc_t_qinf
                            it_fcat         type lvc_t_fcat
                            it_fcat_local   type lvc_t_fcat
                            it_fidx         type lvc_t_fidx
                            it_grpl         type lvc_t_grpl
                            ir_salv_adapter type ref to if_salv_adapter
                   changing ct_stin                type lvc_t_stin
                            ct_lvc_data            type lvc_t_data."#EC *

  field-symbols: <lt_data> type table,
                 <ls_data> type any,
                 <ls_stin> type lvc_s_stin.

  field-symbols: <ls_data_itab> type any,
                 <l_unit>       type any,
                 <l_unit_itab>  type any.

  data: l_start          type i,
        l_end            type i,
        ls_stin          type lvc_s_stin,
        ls_lvc_data      type lvc_s_data,
        ls_row           type lvc_s_row,
        ls_grpl          type lvc_s_grpl,
        l_cindx          type i,
        ls_roid          type lvc_s_roid,
        ls_poid          type lvc_s_roro,
        ls_level         type lvc_s_sort,
        l_table_name(20type c,
        l_invisible      type boolean,
        ls_subtot_info   type lvc_s_stxt,
        l_subtottxt      type lvc_distxt,
        l_value          type lvc_value,
        lr_data          type ref to data.

  data: l_from    type i,
        l_to      type i,
        l_packed  type p decimals 2,
        l_entries type i.

  field-symbols: <lt_style>      type lvc_t_styl,
                 <lt_color_lvc>  type lvc_t_scol,
                 <lt_color_slis> type slis_t_specialcol_alv,
                 <lt_color>      type any,
                 <l_info_fname>  type any,
                 <l_excp_fname>  type any,
                 <lt_dragdrop>   type lvc_t_drdr,
                 <ls_fcat>       type lvc_s_fcat,
                 <l_field_value> type any,
                 <l_web_field>   type any,
                 <l_drdn_field>  type any.

  data: lt_style        type lvc_t_styl,
        ls_style        type lvc_s_styl,
        lt_color_lvc    type lvc_t_scol,
        ls_color_lvc    type lvc_s_scol,
        lt_color_slis   type slis_t_specialcol_alv,         "#EC NEEDED
        ls_color_slis   type slis_specialcol_alv,
        l_color_slis    type boolean,
        l_color(4)      type c,
        ls_dummy        type lvc_s_colo,
        l_style         type lvc_istyle,                    "#EC NEEDED
        l_style_color   type lvc_istyle,
        lr_table_descr  type ref to cl_abap_tabledescr,
        l_info_fname(4type c,
        l_excp_fname    type c,
        lt_dragdrop     type lvc_t_drdr,
        ls_dragdrop     type lvc_s_drdr,
        l_acc           type char1,
        ls_qinf         type lvc_s_qinf,
        l_add_stdinf    type icon-internal.

*>>> new API
  field-symbols: <lt_celltype>  type salv_t_int4_column,
                 <lt_hyperlink> type salv_t_int4_column,
                 <lt_dropdown>  type salv_t_int4_column.

  data: lr_display         type ref to if_salv_display_adapter,
        lr_columns         type ref to cl_salv_columns_list,

        l_celltype_column  type lvc_fname,
        lt_celltype        type salv_t_int4_column,
        ls_celltype        type salv_s_int4_column,
        l_no_celltype      type sap_bool,

        l_hyperlink_column type lvc_fname,
        lt_hyperlink       type salv_t_int4_column,
        ls_hyperlink       type salv_s_int4_column,
        l_no_hyperlink     type sap_bool,                   "#EC NEEDED

        l_dropdown_column  type lvc_fname,
        lt_dropdown        type salv_t_int4_column,
        ls_dropdown        type salv_s_int4_column,
        l_no_dropdown      type sap_bool.                   "#EC NEEDED

  if ir_salv_adapter is bound.
    try.
        lr_display ?= ir_salv_adapter.

        lr_columns ?= lr_display->get_columns( ).

        l_celltype_column  = lr_columns->get_cell_type_column( ).
        l_hyperlink_column = lr_columns->get_hyperlink_entry_column( ).
        l_dropdown_column  = lr_columns->get_dropdown_entry_column( ).

      catch cx_sy_assign_cast_illegal_cast.             "#EC NO_HANDLER
    endtry.
  endif.
*<<< new API

  call function 'GET_ACCESSIBILITY_MODE'
    importing
      accessibility     = l_acc
    exceptions
      its_not_available = 0
      others            = 0.

*... PERFORMANCE:
*    (1) data is requested by frontend:
*      when data is requested by the frontend then requested cells have not yet been sent
*      to the frontend.
*      CT_LVC_DATA is only allowed to contain requested cells -> MT_DATA could contain rendered
*      entries for other cells which have to be deleted. This is OK for the frontend, since the
*      frontend collects the information and therefore does not request this information any more.
*         ==> clear ct_lvc_data
*         ==> clear the attribute FILLED for all entries in CT_STIN. The attribute FILLED
*             will then be set to true once all cells of a line have been rendered
*      However the search functionality could already have rendered this area or at least part of
*      this area. The rendered information should therefore be used.
*         ==> clear CT_LVC_DATA where row not in requested area
*         !!! cells of a row in requested range could already have been rendered
*             the attribute FILLED of CT_STIN is ABAP_FALSE since not all cells were rendered.
*             Entries exist in CT_LVC_DATA which have to be removed.
*             ==> clear CT_LVC_DATA where row_pos in CT_STIN where FILLED eq ABAP_FALSE
*         ==> clear attribute FILLED in CT_STIN for rows which are not within requested range.
*             do not clear attribute FILLED in CT_STIN for rows which are in requested range,
*             in order to avoid rendering of already rendered rows
*    (2) data is requested by backend (e.g. search) !!!!!! Not yet implemented
*      ct_lvc_data should not be cleared, since the search can be performed more than once and
*      entries sent to frontend which have already been rendered can be used.
*         ==> do not clear CT_LVC_DATA
*         !!! cells of a row in requested range could already have been rendered
*             the attribute FILLED of CT_STIN is ABAP_FALSE since not all cells were rendered
*             Entries exist in CT_LVC_DATA which have to be removed.
*             ==> clear CT_LVC_DATA where row_pos in CT_STIN where FILLED eq ABAP_FALSE
*         ==> do not clear attribute FILLED in CT_STIN, in order to avoid rendering of already
*             rendered rows

  ranges:
    lt_delete_row for lvc_s_stin-row_pos.

*... derive start
*... ... find the row that holds the first requested cell
  loop at ct_stin assigning <ls_stin>
    where start_indx le i_start.
    l_start = sy-tabix.
  endloop.                       "Y6DK065306
  if sy-subrc eq 0.
    if <ls_stin>-filled eq abap_false.
      lt_delete_row-low    = <ls_stin>-row_pos.
      lt_delete_row-sign   = 'I'.
      lt_delete_row-option = 'EQ'.
      insert lt_delete_row into table lt_delete_row.
    endif.
  endif.

*... derive end
*... ... find the row that holds the last requested cell
  loop at ct_stin assigning <ls_stin> from l_start
    where start_indx le i_end.              "Y6DK065306
    l_end = sy-tabix.
*<<<Y6DK070916 neccessary, if rows are not filled totally
    if <ls_stin>-filled eq abap_false.
      lt_delete_row-low    = <ls_stin>-row_pos.
      lt_delete_row-sign   = 'I'.
      lt_delete_row-option = 'EQ'.
      insert lt_delete_row into table lt_delete_row.
    endif.
*>>>Y6DK070916
  endloop.
  if sy-subrc ne 0.                         "Y6DK065306
    l_end = l_start.
  endif.

*... delete entries in range
  if i_delete_entries_not_in_range eq abap_true.
    if lines( lt_delete_row ) gt 0.
      delete ct_lvc_data
        where row_pos lt l_start
           or row_pos gt l_end
           or row_pos in lt_delete_row.
    else.
      delete ct_lvc_data
        where row_pos lt l_start
           or row_pos gt l_end.
    endif.

    modify ct_stin from ls_stin transporting filled
      where row_pos lt l_start
         or row_pos gt l_end.
  else.
    if lines( lt_delete_row ) gt 0.
      delete ct_lvc_data where row_pos in lt_delete_row.
    endif.
  endif.

* initialize
  assign lt_style to <lt_style>.
  assign lt_color_lvc to <lt_color>.
  assign lt_dragdrop to <lt_dragdrop>.

* start filling the data table
  loop at ct_stin assigning <ls_stin> from l_start to l_end where filled ne abap_true.
    <ls_stin>-filled = 'X'.

    clear ls_lvc_data.

    if <ls_stin>-row_id is initial.
***********************************************************************
* SUBTOTAL OR TOTAL LINE
***********************************************************************
      clear: lt_color_lvc, lt_color_slis.

*     the information regarding the line item of the subtotal line
*     ( if the subtotal has more than one line due to different currencies )
*     is held int the table it_roid. The field sub_row_id identifies the
*     line item
      read table it_roid into ls_roid index <ls_stin>-row_pos.
      if sy-subrc ne 0.
        clear ls_roid.
      endif.

*     <ls_stin>-counter holds it_poid-row_id
*     it_poid can have more than one item with this row_id if
*     the subtotal contains of more than one line.
*     ls_roid-sub_row_id delivers the line item number with which
*     the correct it_poid can be read
      read table it_poid into ls_poid
        with key row_id     = <ls_stin>-counter
                 sub_row_id = ls_roid-sub_row_id.
      if sy-subrc ne 0.
        clear ls_poid.
      endif.
      ls_row-rowtype = ls_poid-rowtype.
      ls_row-index   = ls_poid-index.

*     the index for the corresponding grouplevel table can be determined
*     with ls_poid-index
*     If ls_poid-index is initial then this line is a total line
*     otherwise it is a subtotal line
*     If it is a total line then ls_grpl has to be initial
      read table it_grpl into ls_grpl index ls_poid-index.
      if sy-subrc ne 0.
        clear ls_grpl.
      endif.

*     with help of ls_grpl the collect table holding the information
*     for this line can be determined.
      concatenate 'IT_COLLECT' ls_grpl-collect '[]' into l_table_name.
      assign (l_table_name) to <lt_data>.

*     ls_grpl also delivers the range in which the data requested for
*     this grouplevel is held
*     if ls_grpl is initial then this is a total line and no range is
*     given. In this case the range is from 1 until the end of the table
      if ls_grpl-cindx_from is initial.
        ls_grpl-cindx_from = 1.
      endif.
      if ls_grpl-cindx_to is initial.
        describe table <lt_data> lines ls_grpl-cindx_to.
      endif.

*     the item in this range which is to be read can be determined with
*     help of the ls_roid-sub_row_id. The subtotal line is the upper
*     range + the line item - 1
      l_cindx = ls_grpl-cindx_from + ls_roid-sub_row_id - 1.
      read table <lt_data> assigning <ls_data> index l_cindx.
      if sy-subrc eq 0.
************************************
* Column -1
************************************
        ls_lvc_data-col_pos = -1.
        ls_lvc_data-row_pos = <ls_stin>-row_pos.
        ls_lvc_data-row_id  = ls_poid-row_id.
        add 1 to ls_lvc_data-sub_row_id.
        ls_lvc_data-value   = ls_row.
        ls_lvc_data-style   = ls_lvc_data-style + alv_style_disabled.
        append ls_lvc_data to ct_lvc_data.
        add 1 to ls_lvc_data-col_pos.

************************************
* Column Exception
************************************
        if not is_layo-excp_fname is initial.
          assign component is_layo-excp_fname
                           of structure <ls_data> to <l_field_value>.
          if sy-subrc ne 0.
            message x000(0k).
          endif.

          add 1 to ls_lvc_data-col_pos.

          ls_lvc_data-value = space.

*   No exception in splitted total lines
          if ls_row-rowtype+1(1ne 'F'.
            case is_layo-excp_group.
              when '1' or '0' or space.
*         Exception von der Gruppe "LIGHT"/"LED"
                case <l_field_value>+0(1).
                  when '0'.
                    if is_layo-excp_led eq 'X'.
                      ls_lvc_data-value = icon_led_inactive.
                    else.
                      ls_lvc_data-value = icon_light_out.
                    endif.
                  when '1'.
                    if is_layo-excp_led eq 'X'.
                      ls_lvc_data-value = icon_led_red.
                    else.
                      ls_lvc_data-value = icon_red_light.
                    endif.
                  when '2'.
                    if is_layo-excp_led eq 'X'.
                      ls_lvc_data-value = icon_led_yellow.
                    else.
                      ls_lvc_data-value = icon_yellow_light.
                    endif.
                  when '3'.
                    if is_layo-excp_led eq 'X'.
                      ls_lvc_data-value = icon_led_green.
                    else.
                      ls_lvc_data-value = icon_green_light.
                    endif.
                endcase.
              when '2'.
*         Exception von der Gruppe "LED"
                case <l_field_value>+0(1).
                  when '0'.
                    ls_lvc_data-value = icon_led_inactive.
                  when '1'.
                    ls_lvc_data-value = icon_led_red.
                  when '2'.
                    ls_lvc_data-value = icon_led_yellow.
                  when '3'.
                    ls_lvc_data-value = icon_led_green.
                endcase.
              when '3'.
*         Exception von der Gruppe "STATUS"
                case <l_field_value>+0(1).
                  when '0'.
                    ls_lvc_data-value = icon_no_status.
                  when '1'.
                    ls_lvc_data-value = icon_status_critical.
                  when '2'.
                    ls_lvc_data-value = icon_status_alert.
                  when '3'.
                    ls_lvc_data-value = icon_status_ok.
                  when '4'.
                    ls_lvc_data-value = icon_status_best.
                endcase.
              when '4'.
*         Exception von der Gruppe "TREND"
                case <l_field_value>+0(1).
                  when '1'.
                    ls_lvc_data-value = icon_trend_down.
                  when '2'.
                    ls_lvc_data-value = icon_trend_unchanged.
                  when '3'.
                    ls_lvc_data-value = icon_trend_up.
                  when '4'.
                    ls_lvc_data-value = icon_trend_decreasing.
                  when '5'.
                    ls_lvc_data-value = icon_trend_rising.
                endcase.
              when '5'.
*         Exception von der Gruppe "MESSAGE"
                case <l_field_value>+0(1).
                  when '1'.
                    ls_lvc_data-value = icon_message_error_small.
                  when '2'.
                    ls_lvc_data-value = icon_message_warning_small.
                  when '3'.
                    ls_lvc_data-value = icon_message_information_small.
                  when '4'.
                    ls_lvc_data-value = icon_message_critical_small.
                  when '5'.
                    ls_lvc_data-value = icon_message_question_small.
                endcase.
              when '6'.
*         Exception von der Gruppe "ALERT/WARNING/HINT"
                case <l_field_value>+0(1).
                  when '1'.
                    ls_lvc_data-value = icon_alert.
                  when '2'.
                    ls_lvc_data-value = icon_warning.
                  when '3'.
                    ls_lvc_data-value = icon_hint.
                endcase.
              when '7'.
*         Exception von der Gruppe "FAILURE/INCOMPLETE/CHECKED"
                case <l_field_value>+0(1).
                  when '1'.
                    ls_lvc_data-value = icon_failure.
                  when '2'.
                    ls_lvc_data-value = icon_incomplete.
                  when '3'.
                    ls_lvc_data-value = icon_checked.
                endcase.
            endcase.

            if l_acc eq 'X' or
               not it_qinf is initial.
*Quickinfo for Exception
              clear ls_qinf.
              read table it_qinf into ls_qinf
                   with key type = cl_salv_tooltip=>c_type_exception
                            value = <l_field_value>. "<l_excp_fname> ist nicht gefüllt
              if sy-subrc ne 0.
                read table it_qinf into ls_qinf
                     with key fieldname = is_layo-excp_fname
                              value     = <l_field_value>.
                if sy-subrc = 0.
                  clear l_add_stdinf.
                else.
                  l_add_stdinf = 'X'.
                endif.
              endif.

              call function 'ICON_CREATE'
                exporting
                  name                        = ls_lvc_data-value
*                 TEXT                        = ' '
                  info                        = ls_qinf-text
                  add_stdinf                  = l_add_stdinf
                importing
                  result                      = ls_lvc_data-value
                exceptions
                  icon_not_found              = 0
                  outputfield_too_short       = 0
                  others                      = 0.
            endif.
          endif.

          ls_lvc_data-style = alv_style_align_center_top.

          if g_gui_type ne 1 or g_view eq cl_gui_alv_grid=>mc_fc_view_excel.
            l_style_color = alv_style_color_normal.
            ls_lvc_data-style = ls_lvc_data-style + l_style_color.
          endif.

          append ls_lvc_data to ct_lvc_data.
        endif.

************************************
* Hidden Subtotal Columns
************************************
        ls_lvc_data-value = space.
        clear ls_lvc_data-style.
        if ls_row-rowtype(1eq 'A' and not ls_row-rowtype+1(1eq 'F'.
          read table is_toto-t_levels into ls_level
            with key level = ls_grpl-level.
          if sy-subrc ne 0.
            clear ls_level.
          endif.
          read table it_fcat assigning <ls_fcat>
            with key fieldname = ls_level-fieldname.
          if sy-subrc eq 0.
            ls_subtot_info-criteria = ls_level-fieldname.
            get reference of <ls_data> into lr_data.
            l_invisible = 'X'.

            add 1 to ls_lvc_data-col_pos.

            if <ls_fcat>-icon eq space.
              ls_lvc_data-value = <ls_fcat>-seltext.
            endif.
            ls_subtot_info-keyword = <ls_fcat>-seltext.
            assign component <ls_fcat>-fieldname
                             of structure <ls_data> to <l_field_value>.
            if sy-subrc ne 0.
              message x000(0k).
            endif.

            macro_cell_data_get
              <ls_fcat>
              <lt_data>
              <l_field_value>
              l_value.

            concatenate ls_lvc_data-value l_value
                        into ls_lvc_data-value separated by space.

            if g_gui_type ne 1 or g_view eq cl_gui_alv_grid=>mc_fc_view_excel.
              l_style_color = alv_style_color_total.
              ls_lvc_data-style = l_style_color +
                                  alv_style_font_bold + alv_style_align_left_top.
              clear l_style_color.
            endif.
          endif.

          if not <ls_fcat>-txt_field is initial.
            read table it_fcat assigning <ls_fcat>
              with key fieldname = <ls_fcat>-txt_field.
            if sy-subrc eq 0 and <ls_fcat>-no_out eq 'X'.
              assign component <ls_fcat>-fieldname
                               of structure <ls_data> to <l_field_value>.
              if sy-subrc ne 0.
                message x000(0k).
              endif.

              macro_cell_data_get
                <ls_fcat>
                <ls_data>
                <l_field_value>
                l_value.

              ls_subtot_info-crit_text = l_value.
              concatenate ls_lvc_data-value l_value into ls_lvc_data-value
                          separated by space.

              if g_gui_type ne 1 or g_view eq cl_gui_alv_grid=>mc_fc_view_excel.
                l_style_color = alv_style_color_total.
                ls_lvc_data-style = l_style_color +
                                    alv_style_font_bold + alv_style_align_left_top.
                clear l_style_color.
              endif.
            endif.
          endif.

          l_subtottxt = ls_lvc_data-value.
          call method g_alv->list_processing_events
            exporting
              i_event_name      = 'SUBTOTAL_TEXT'
              is_subtottxt_info = ls_subtot_info
              ip_subtot_line    = lr_data
            changing
              c_subtottxt       = l_subtottxt.
          ls_lvc_data-value = l_subtottxt.

          append ls_lvc_data to ct_lvc_data.
        endif.

************************************
* Column per Fieldcat Entry
************************************
        ls_lvc_data-value = space.
        clear ls_lvc_data-style.
        loop at it_fcat_local assigning <ls_fcat>
                where tech ne 'X' and no_out ne 'X'.
          if l_invisible eq 'X'.
            clear l_invisible.
            if <ls_fcat>-do_sum is initial.
              continue.
            else.
              clear ls_lvc_data-col_pos.
            endif.
          endif.

          add 1 to ls_lvc_data-col_pos.

          assign component <ls_fcat>-fieldname
                           of structure <ls_data> to <l_field_value>.
          if sy-subrc ne 0.
            message x000(0k).
          endif.

*... work on average
          if <ls_fcat>-do_sum eq 'C'.
*           Initialize average result and entries
            <l_field_value> = 0.
            clear l_entries.

*           retrive unit from fieldcatalog
            assign space to <l_unit>.
            if not <ls_fcat>-cfieldname is initial.
              assign component <ls_fcat>-cfieldname
                     of structure <ls_data> to <l_unit>.
            endif.
            if not <ls_fcat>-qfieldname is initial.
              assign component <ls_fcat>-qfieldname
                     of structure <ls_data> to <l_unit>.
            endif.

            l_from = ls_grpl-index_from.
            l_to   = ls_grpl-index_to.
            if ls_grpl-index_from is initial and
               ls_grpl-index_to   is initial.
              l_from = 0.
              l_to   = '999999999'.
            endif.

            field-symbols:
              <l_data_table_value> type any.

            loop at it_data assigning <ls_data_itab>
                    from l_from
                    to   l_to.
*             retrieve unit from data table
*             assert unit of fieldcatalog is identical to data table unit
              assign space to <l_unit_itab>.
              if not <ls_fcat>-cfieldname is initial.
                assign component <ls_fcat>-cfieldname
                       of structure <ls_data_itab> to <l_unit_itab>.
              endif.
              if not <ls_fcat>-qfieldname is initial.
                assign component <ls_fcat>-qfieldname
                       of structure <ls_data_itab> to <l_unit_itab>.
              endif.

              check <l_unit_itab> eq <l_unit>.

*             assert that entry is not filtered away
              read table it_fidx with key table_line = sy-tabix
                transporting no fields.
              check sy-subrc ne 0.

*             sum up entries
              add 1 to l_entries.
*             sum up values
              assign component <ls_fcat>-fieldname
                of structure <ls_data_itab> to <l_data_table_value>.
              if sy-subrc ne 0.
                message x000(0k).
              endif.
              <l_field_value> = <l_field_value> + <l_data_table_value>.
            endloop.

            if l_entries is not initial.
*           average should be displayed in the correct output type of field
*           and not in a predefined packed field which does not match to
*           output field over which the average is to be performed
              <l_field_value> = <l_field_value> / l_entries.
            endif.
          endif.

          macro_cell_data_get
            <ls_fcat>
            <ls_data>
            <l_field_value>
            ls_lvc_data-value.
*         hotspot when field is initial
          if <ls_fcat>-hotspot eq 'V' and ls_lvc_data-value is initial.
            add alv_style_single_clk_event_no to ls_lvc_data-style.
          endif.
*         style field
          if not is_layo-stylefname is initial.
            assign component is_layo-stylefname of structure <ls_data> to <lt_style>.
            if sy-subrc eq 0.
              clear <lt_style>.
              read table <lt_style> into ls_style
                         with key fieldname = <ls_fcat>-fieldname.
              if sy-subrc eq 0.
                if ls_row-rowtype(1ca 'AST'.
                  ls_lvc_data-style = ls_lvc_data-style + alv_style_disabled.
                else.
                  ls_lvc_data-style = ls_lvc_data-style + ls_style-style.
                endif.
                ls_lvc_data-maxlen = ls_style-maxlen.
              endif.
            endif.
          endif.
*         color table
          if not ls_row-rowtype(1ca 'AST'.
            if not is_layo-ctab_fname is initial.
              clear l_style_color.
              perform field_color_complex using <lt_color>
                                                <ls_fcat>
                                                l_style_color.
              ls_lvc_data-style = ls_lvc_data-style + l_style_color.
            endif.
          endif.
*         DragAndDrop
          if not is_layo-s_dragdrop-fieldname is initial.
            assign component is_layo-s_dragdrop-fieldname
                             of structure <lt_data> to <lt_dragdrop>.
            if not <lt_dragdrop> is initial.
              if sy-subrc eq 0.
                read table <lt_dragdrop> into ls_dragdrop
                  with key fieldname =  <ls_fcat>-fieldname
                  binary search.
                if sy-subrc eq 0.
                  ls_lvc_data-dragdropid = ls_dragdrop-dragdropid.
                endif.
              endif.
            endif.
          endif.
*         special fields
          if <ls_fcat>-key eq 'X' and not
             ls_row-rowtype(1ca 'ATS' and
             l_style_color is initial.
            if g_gui_type ne 1 or g_view eq cl_gui_alv_grid=>mc_fc_view_excel.
              l_style_color = alv_style_color_int_key.
              ls_lvc_data-style = ls_lvc_data-style + l_style_color.
            endif.
          elseif ls_row-rowtype(1eq 'T' or ls_row-rowtype(1eq 'S' or
                 ls_row-rowtype(1eq 'A'.
            data:
              l_zsum type abap_bool value abap_false.       "Y6DK072580

            if ls_row-rowtype(1ne 'T' and <ls_fcat>-no_sum eq abap_true.
              read table is_toto-t_levels into ls_level
                with key level = ls_grpl-level.
              if sy-subrc eq 0.
                if ls_level-fieldname eq <ls_fcat>-fieldname.
                  l_zsum = abap_true.
                endif.
              endif.
            endif.
            if l_zsum eq abap_true.
              clear l_zsum.                                 "Y6DK072580
            else.
              if <ls_fcat>-inttype ca 'PIF' or <ls_fcat>-inttype ca 'bsX'.
              if <ls_fcat>-do_sum is initial.
                clear ls_lvc_data-value.
              elseif ls_row-rowtype+1(1eq 'F'.
                if <ls_fcat>-cfieldname is initial and
                   <ls_fcat>-qfieldname is initial.
                  clear ls_lvc_data-value.
                endif.
              endif.
            elseif <ls_fcat>-inttype ca 'NDT' or
                  ( not <ls_fcat>-convexit is initial and
                    <ls_fcat>-no_convext is initial ).
              if <l_field_value> is initial.
                clear ls_lvc_data-value.
                endif.
              endif.
            endif.
            case ls_row-rowtype(1).
              when 'T'.
                if g_gui_type ne 1 or g_view eq cl_gui_alv_grid=>mc_fc_view_excel.
                  l_style_color = alv_style_color_int_total.
                  ls_lvc_data-style = l_style_color + alv_style_font_bold.
                endif.
              when 'S' or 'A'.
                if g_gui_type ne 1 or g_view eq cl_gui_alv_grid=>mc_fc_view_excel.
                  l_style_color = alv_style_color_total.
                  ls_lvc_data-style = l_style_color + alv_style_font_bold.
                endif.
            endcase.
          elseif l_style_color is initial and
                 ( <ls_fcat>-emphasize is initial or <ls_fcat>-emphasize eq '$' ).
            if g_gui_type ne 1 or g_view eq cl_gui_alv_grid=>mc_fc_view_excel.
*              if l_counter is initial.
              l_style_color = alv_style_color_normal.
*              else.
*                l_style_color = alv_style_color_int_normal.
*              endif.
              ls_lvc_data-style = ls_lvc_data-style + l_style_color.
            endif.
          endif.

          append ls_lvc_data to ct_lvc_data.
        endloop.
      endif.

    else.
***********************************************************************
* ENTRY IN THE DATA TABLE
***********************************************************************
      read table it_data assigning <ls_data> index <ls_stin>-row_id.
      if sy-subrc ne 0.
        continue.
      endif.

************************************
* Callback for merging
************************************
      if not g_exit is initial.
        perform (g_routine) in program (g_callback)
                                 using <ls_stin>-row_id
                                       g_stop_merge.
      endif.

************************************
* Pointers
************************************
*... COLOR
      if not is_layo-ctab_fname is initial.
        if not is_layo_local-indx_ctab is initial.
          assign component is_layo_local-indx_ctab
                           of structure <ls_data> to <lt_color>.
        else.
          assign component is_layo-ctab_fname
                 of structure <ls_data> to <lt_color>.
        endif.
        if sy-subrc ne 0.
          assign lt_color_lvc to <lt_color>.
        endif.
        lr_table_descr ?= cl_abap_typedescr=>describe_by_name( 'LVC_T_SCOL' ).
        if lr_table_descr->applies_to_data( <lt_color> ) eq 'X'.
          l_color_slis = space.
          assign <lt_color> to <lt_color_lvc>.
        else.
          l_color_slis = 'X'.
          assign <lt_color> to <lt_color_slis>.
        endif.
      endif.
*... INFO Field
      if not is_layo-info_fname is initial.
        if not is_layo_local-indx_info is initial.
          assign component is_layo_local-indx_info
                           of structure <ls_data> to <l_info_fname>.
        else.
          assign component is_layo-info_fname
                           of structure <ls_data> to <l_info_fname>.
        endif.
        if sy-subrc ne 0.
          assign l_info_fname to <l_info_fname>.
        endif.
      endif.
*... Exception Field
      if not is_layo-excp_fname is initial.
        if not is_layo_local-indx_excp is initial.
          assign component is_layo_local-indx_excp
                           of structure <ls_data> to <l_excp_fname>.
        else.
          assign component is_layo-excp_fname
                           of structure <ls_data> to <l_excp_fname>.
        endif.
        if sy-subrc ne 0.
          assign l_excp_fname to <l_excp_fname>.
        endif.
      endif.
*... STYLE
      if not is_layo-stylefname is initial.
        if not is_layo_local-indx_style is initial.
          assign component is_layo_local-indx_style
                           of structure <ls_data> to <lt_style>.
        else.
          assign component is_layo-stylefname
                           of structure <ls_data> to <lt_style>.
        endif.
        if sy-subrc ne 0.
          assign lt_style to <lt_style>.
        endif.
      endif.
*... DragAndDrop
      if not is_layo-s_dragdrop-fieldname is initial.
        if not is_layo_local-indx_drnd is initial.
          assign component is_layo_local-indx_drnd
                           of structure <ls_data> to <lt_dragdrop>.
        else.
          assign component is_layo-s_dragdrop-fieldname
                           of structure <ls_data> to <lt_dragdrop>.
        endif.
        if sy-subrc ne 0.
          assign lt_dragdrop to <lt_dragdrop>.
        endif.
      endif.

************************************
* Column -1
************************************
      ls_lvc_data-col_pos = -1.
      ls_lvc_data-row_pos = <ls_stin>-row_pos.
      ls_lvc_data-row_id  = <ls_stin>-row_id.
      ls_row-index = <ls_stin>-row_id.
      clear ls_row-rowtype.
      ls_lvc_data-value = ls_row.

*...  zebra
      if is_layo-zebra eq 'X'.
        if <ls_stin>-counter is initial.
          ls_lvc_data-style4 = ls_lvc_data-style4 + alv_style4_zebra_row.
        endif.
      endif.
*...  style fieldname
      if not is_layo-stylefname is initial.
        read table <lt_style> into ls_style
          with key fieldname = space.
        if sy-subrc eq 0.
          ls_lvc_data-style  = ls_lvc_data-style  + ls_style-style.
          ls_lvc_data-style2 = ls_lvc_data-style2 + ls_style-style2.
          ls_lvc_data-style3 = ls_lvc_data-style3 + ls_style-style3.
          ls_lvc_data-style4 = ls_lvc_data-style4 + ls_style-style4.
          ls_lvc_data-maxlen = ls_style-maxlen.
        endif.
      endif.
*...  info fieldname
      if not is_layo-info_fname is initial.
        l_color = <l_info_fname>.
        if l_color(1) = 'C'.
          clear: l_style, l_style_color.
          perform style_for_listcolor using l_color+1(3)
                                            l_style_color
                                            ls_dummy.
          ls_lvc_data-style = ls_lvc_data-style + l_style_color.
        endif.
      endif.
*...  DragAndDrop
      if not is_layo-s_dragdrop-row_ddid is initial.
        ls_lvc_data-dragdropid = is_layo-s_dragdrop-row_ddid.
      endif.
      if not is_layo-s_dragdrop-fieldname is initial.
        read table <lt_dragdrop> into ls_dragdrop
          with key fieldname = space
          binary search.
        if sy-subrc eq 0.
          ls_lvc_data-dragdropid = ls_dragdrop-dragdropid.
        else.
          clear ls_lvc_data-dragdropid.
        endif.
      endif.

      append ls_lvc_data to ct_lvc_data.
      add 1 to ls_lvc_data-col_pos.

************************************
* Column Exception
************************************
      if not is_layo-excp_fname is initial.
        data: excp type char10.
        move <l_excp_fname> to excp.
        condense excp.
        add 1 to ls_lvc_data-col_pos.

        case is_layo-excp_group.
          when '1' or '0' or space.
*         Exception von der Gruppe "LIGHT"/"LED"
*          case <l_excp_fname>+0(1).
            case excp+0(1).
              when '0' or space.
                if is_layo-excp_led eq 'X'.
                  ls_lvc_data-value = icon_led_inactive.
                else.
                  ls_lvc_data-value = icon_light_out.
                endif.
              when '1'.
                if is_layo-excp_led eq 'X'.
                  ls_lvc_data-value = icon_led_red.
                else.
                  ls_lvc_data-value = icon_red_light.
                endif.
              when '2'.
                if is_layo-excp_led eq 'X'.
                  ls_lvc_data-value = icon_led_yellow.
                else.
                  ls_lvc_data-value = icon_yellow_light.
                endif.
              when '3'.
                if is_layo-excp_led eq 'X'.
                  ls_lvc_data-value = icon_led_green.
                else.
                  ls_lvc_data-value = icon_green_light.
                endif.
            endcase.
          when '2'.
*         Exception von der Gruppe "LED"
*          case <l_excp_fname>+0(1).
            case excp+0(1).
              when '0' or space.
                ls_lvc_data-value = icon_led_inactive.
              when '1'.
                ls_lvc_data-value = icon_led_red.
              when '2'.
                ls_lvc_data-value = icon_led_yellow.
              when '3'.
                ls_lvc_data-value = icon_led_green.
            endcase.
          when '3'.
*         Exception von der Gruppe "STATUS"
*          case <l_excp_fname>+0(1).
            case excp+0(1).
              when '0' or space.
                ls_lvc_data-value = icon_no_status.
              when '1'.
                ls_lvc_data-value = icon_status_critical.
              when '2'.
                ls_lvc_data-value = icon_status_alert.
              when '3'.
                ls_lvc_data-value = icon_status_ok.
              when '4'.
                ls_lvc_data-value = icon_status_best.
            endcase.
          when '4'.
*         Exception von der Gruppe "TREND"
*          case <l_excp_fname>+0(1).
            case excp+0(1).
              when '1'.
                ls_lvc_data-value = icon_trend_down.
              when '2'.
                ls_lvc_data-value = icon_trend_unchanged.
              when '3'.
                ls_lvc_data-value = icon_trend_up.
              when '4'.
                ls_lvc_data-value = icon_trend_decreasing.
              when '5'.
                ls_lvc_data-value = icon_trend_rising.
            endcase.
          when '5'.
*         Exception von der Gruppe "MESSAGE"
*          case <l_excp_fname>+0(1).
            case excp+0(1).
              when '1'.
                ls_lvc_data-value = icon_message_error_small.
              when '2'.
                ls_lvc_data-value = icon_message_warning_small.
              when '3'.
                ls_lvc_data-value = icon_message_information_small.
              when '4'.
                ls_lvc_data-value = icon_message_critical_small.
              when '5'.
                ls_lvc_data-value = icon_message_question_small.
            endcase.
          when '6'.
*         Exception von der Gruppe "ALERT/WARNING/HINT"
*          case <l_excp_fname>+0(1).
            case excp+0(1).
              when '1'.
                ls_lvc_data-value = icon_alert.
              when '2'.
                ls_lvc_data-value = icon_warning.
              when '3'.
                ls_lvc_data-value = icon_hint.
            endcase.
          when '7'.
*         Exception von der Gruppe "FAILURE/INCOMPLETE/CHECKED"
*          case <l_excp_fname>+0(1).
            case excp+0(1).
              when '1'.
                ls_lvc_data-value = icon_failure.
              when '2'.
                ls_lvc_data-value = icon_incomplete.
              when '3'.
                ls_lvc_data-value = icon_checked.
            endcase.
        endcase.

        if l_acc eq 'X' or
           not it_qinf is initial.
*Quickinfo for Exception
          clear ls_qinf.
          read table it_qinf into ls_qinf
               with key type = cl_salv_tooltip=>c_type_exception
                        value = <l_excp_fname>.
          if sy-subrc ne 0.
            read table it_qinf into ls_qinf
                 with key fieldname = is_layo-excp_fname
                          value     = <l_excp_fname>.
            if sy-subrc = 0.
              clear l_add_stdinf.
            else.
              l_add_stdinf = 'X'.
            endif.
          endif.
          call function 'ICON_CREATE'
            exporting
              name                        = ls_lvc_data-value
*         TEXT                        = ' '
              info                        = ls_qinf-text
              add_stdinf                  = l_add_stdinf
            importing
              result                      = ls_lvc_data-value
            exceptions
              icon_not_found              = 0
              outputfield_too_short       = 0
              others                      = 0.
        endif.

        if g_gui_type ne 1.
          ls_lvc_data-style = alv_style_color_normal +
                              alv_style_align_center_top.
        endif.

        append ls_lvc_data to ct_lvc_data.
      endif.

************************************
* Column per Fieldcat Entry
************************************
      loop at it_fcat_local assigning <ls_fcat>.
        clear: ls_lvc_data-href_hndl,
               ls_lvc_data-drdn_hndl,
               ls_lvc_data-style,
               ls_lvc_data-style2,
               ls_lvc_data-style3,
               ls_lvc_data-style4,
               ls_lvc_data-maxlen.

        clear: lt_color_lvc, lt_color_slis.

        add 1 to ls_lvc_data-col_pos.

        if not <ls_fcat>-indx_field is initial.
          assign component <ls_fcat>-indx_field
                           of structure <ls_data> to <l_field_value>.
        else.
          assign component <ls_fcat>-fieldname
                           of structure <ls_data> to <l_field_value>.
        endif.

        macro_cell_data_get
          <ls_fcat>
          <ls_data>
          <l_field_value>
          ls_lvc_data-value.

*>>> new API
        if ir_salv_adapter is bound.
          clear ls_lvc_data-style.

* color
          if g_gui_type ne 1.
            if <ls_fcat>-key eq abap_true.
              ls_lvc_data-style = alv_style_color_int_key.
            elseif l_style_color is initial
                  and ( <ls_fcat>-emphasize is initial or
                        <ls_fcat>-emphasize = '$' ).
              if <ls_stin>-counter is initial.
                ls_lvc_data-style = alv_style_color_normal.
              else.
                ls_lvc_data-style = alv_style_color_int_normal.
              endif.
            endif.
          endif.

*       is there a complex color table defined ?
          if not is_layo-ctab_fname is initial.
            clear l_style_color.
            if l_color_slis eq abap_true.
              clear lt_color_lvc.
              loop at <lt_color_slis> into ls_color_slis.
                move-corresponding ls_color_slis to ls_color_lvc.
                ls_color_lvc-fname = ls_color_slis-fieldname.
                append ls_color_lvc to lt_color_lvc.
              endloop.
              assign lt_color_lvc to <lt_color_lvc>.
            endif.
            perform field_color_complex using <lt_color_lvc>
                                              <ls_fcat>
                                              l_style_color.
            if not l_style_color is initial.
              ls_lvc_data-style = l_style_color.
            endif.
          endif.

          clear l_no_celltype.
          clear ls_celltype.
          assign component l_celltype_column of structure <ls_data> to <lt_celltype>.
          if sy-subrc ne 0.
            assign lt_celltype to <lt_celltype>.
          endif.
          read table <lt_celltype> into ls_celltype
            with key columnname = <ls_fcat>-fieldname.
          if sy-subrc ne 0.
            read table <lt_celltype> into ls_celltype
              with key columnname = space.
            if sy-subrc ne 0.
              l_no_celltype = abap_true.
            endif.
          endif.

          clear l_no_hyperlink.
          assign component l_hyperlink_column of structure <ls_data> to <lt_hyperlink>.
          if sy-subrc ne 0.
            assign lt_hyperlink to <lt_hyperlink>.
          endif.
          read table <lt_hyperlink> into ls_hyperlink
            with key columnname = <ls_fcat>-fieldname.
          if sy-subrc ne 0.
            read table <lt_hyperlink> into ls_hyperlink
              with key columnname = space.
            if sy-subrc ne 0.
              l_no_hyperlink = abap_true.
            endif.
          endif.
          if l_no_celltype eq abap_false and
             ls_celltype-value ne if_salv_c_cell_type=>link.
            l_no_hyperlink = abap_true.
          endif.

          clear ls_lvc_data-href_hndl.
          ls_lvc_data-href_hndl = <ls_fcat>-href_hndl.
          if l_no_hyperlink eq abap_false.
            ls_lvc_data-href_hndl = ls_hyperlink-value.
          else.
            clear ls_lvc_data-href_hndl.
          endif.

          clear l_no_dropdown.
          assign component l_dropdown_column of structure <ls_data> to <lt_dropdown>.
          if sy-subrc ne 0.
            assign lt_dropdown to <lt_dropdown>.
          endif.
          read table <lt_dropdown> into ls_dropdown
            with key columnname = <ls_fcat>-fieldname.
          if sy-subrc ne 0.
            read table <lt_dropdown> into ls_dropdown
              with key columnname = space.
            if sy-subrc ne 0.
              l_no_dropdown = abap_true.
            endif.
          endif.
          if l_no_celltype eq abap_false and
             ls_celltype-value ne if_salv_c_cell_type=>dropdown.
            l_no_dropdown = abap_true.
          endif.

          clear ls_lvc_data-drdn_hndl.
          ls_lvc_data-drdn_hndl = <ls_fcat>-drdn_hndl.
          if l_no_dropdown eq abap_false.
            ls_lvc_data-drdn_hndl = ls_dropdown-value.
          else.
            clear ls_lvc_data-drdn_hndl.
          endif.
          if ls_lvc_data-drdn_hndl is not initial.
            add alv_style_f4_no to ls_lvc_data-style.
          endif.

          if l_no_celltype eq space and
             ls_celltype-value eq if_salv_c_cell_type=>button.
            add alv_style_button to ls_lvc_data-style.
          endif.
          if l_no_celltype eq space and
             ls_celltype-value ne if_salv_c_cell_type=>button and
             <ls_fcat>-style o cl_gui_alv_grid=>mc_style_button.
            add alv_style_button_no to ls_lvc_data-style.
          endif.

* if the column is hotspot_checkbox it might be overwritten

          if <ls_fcat>-hotspot eq abap_true
*              and ( l_no_celltype ne SPACE or ( l_no_celltype eq space and
*               ls_celltype-value ne if_salv_c_cell_type=>checkbox ) ) )
             or ( l_no_celltype eq space and
               ls_celltype-value eq if_salv_c_cell_type=>hotspot )
             or ( l_no_celltype eq space and
               ls_celltype-value eq if_salv_c_cell_type=>checkbox_hotspot )."Y6DK034262

            if l_no_celltype eq space and (
               ls_celltype-value ne if_salv_c_cell_type=>hotspot
               and ls_celltype-value ne if_salv_c_cell_type=>checkbox_hotspot )."Y6DK034262
              add alv_style_single_clk_event_no to ls_lvc_data-style.
            else.
              add alv_style_single_clk_event to ls_lvc_data-style.
            endif.
          endif.

          if <ls_fcat>-checkbox eq abap_true or
             ( l_no_celltype eq space and
               ls_celltype-value eq if_salv_c_cell_type=>checkbox ).
            if l_no_celltype eq space and (
               ls_celltype-value ne if_salv_c_cell_type=>checkbox
               and ls_celltype-value ne if_salv_c_cell_type=>checkbox_hotspot )."Y6DK034262
              add alv_style_checkbox_no to ls_lvc_data-style.
              add alv_style_f4_no to ls_lvc_data-style.
            else.
              if <l_field_value> eq abap_true.
                add alv_style_checkbox_checked to ls_lvc_data-style.
              else.
                add alv_style_checkbox_not_checked to ls_lvc_data-style.
              endif.
            endif.
          endif.
        endif.
*<<< new API

        if <ls_fcat>-icon eq abap_true.
          clear ls_qinf.
          read table it_qinf into ls_qinf
            with key fieldname = <ls_fcat>-fieldname
                     value     = ls_lvc_data-value.
          if sy-subrc ne 0.   ">>>>>>>>>>>>>>>Y7AK007927
            read table it_qinf into ls_qinf
              with key value = ls_lvc_data-value.
          endif.   "<<<<<<<<<<<<<<<<<Y7AK007927
          if sy-subrc eq 0 or l_acc eq abap_true.
            if sy-subrc eq 0.
              clear l_add_stdinf.
            else.
              l_add_stdinf = abap_true.
            endif.
            call function 'ICON_CREATE'
              exporting
                name                        = ls_lvc_data-value
*         TEXT                        = ' '
                info                        = ls_qinf-text
                add_stdinf                  = l_add_stdinf
              importing
                result                      = ls_lvc_data-value
              exceptions
                icon_not_found              = 0
                outputfield_too_short       = 0
                others                      = 0.
          endif.
        endif.

*>>> new API
        if ir_salv_adapter is not bound.
*<<< new API
          if not is_layo-s_dragdrop-fieldname is initial.
            read table <lt_dragdrop> into ls_dragdrop
              with key fieldname = <ls_fcat>-fieldname
              binary search.
            if sy-subrc eq 0.
              ls_lvc_data-dragdropid = ls_dragdrop-dragdropid.
            else.
              clear ls_lvc_data-dragdropid.
            endif.
          endif.

          if <ls_fcat>-get_style is initial.
            if g_stop_merge eq abap_true.
              ls_lvc_data-style4 = ls_lvc_data-style4 + alv_style4_stop_merge.
            endif.
          else.
            clear ls_lvc_data-style.
*         special columns
            if g_gui_type ne 1.
              if <ls_fcat>-key eq abap_true.
                ls_lvc_data-style = alv_style_color_int_key.
              elseif l_style_color is initial and
                     ( <ls_fcat>-emphasize is initial or <ls_fcat>-emphasize eq '$' ).
                if <ls_stin>-counter is initial.
                  ls_lvc_data-style = alv_style_color_normal.
                else.
                  ls_lvc_data-style = alv_style_color_int_normal.
                endif.
              endif.
            endif.
*         web field
            if not <ls_fcat>-web_field is initial.
              assign component <ls_fcat>-web_field
                     of structure <ls_data> to <l_web_field>.
              if sy-subrc eq 0.
                ls_lvc_data-href_hndl = <l_web_field>.
              else.
                clear ls_lvc_data-href_hndl.
              endif.
            endif.
*         drag&drop field
            if not <ls_fcat>-drdn_field is initial.
              assign component <ls_fcat>-drdn_field
                     of structure <ls_data> to <l_drdn_field>.
              if sy-subrc eq 0.
                ls_lvc_data-drdn_hndl = <l_drdn_field>.
              else.
                clear ls_lvc_data-drdn_hndl.
              endif.
            endif.
*         color table
            if not is_layo-ctab_fname is initial.
              clear l_style_color.
              if l_color_slis eq abap_true.
                clear lt_color_lvc.
                loop at <lt_color_slis> into ls_color_slis.
                  move-corresponding ls_color_slis to ls_color_lvc.
                  ls_color_lvc-fname = ls_color_slis-fieldname.
                  append ls_color_lvc to lt_color_lvc.
                endloop.
                assign lt_color_lvc to <lt_color_lvc>.
              endif.
              perform field_color_complex using <lt_color_lvc>
                                                <ls_fcat>
                                                l_style_color.
              if not l_style_color is initial.
                ls_lvc_data-style = l_style_color.
              endif.
            endif.
*         style field
            if not is_layo-stylefname is initial.
              read table <lt_style> into ls_style
                with key fieldname = <ls_fcat>-fieldname.
              if sy-subrc eq 0.
                ls_lvc_data-style  = ls_lvc_data-style  + ls_style-style.
                ls_lvc_data-style2 = ls_lvc_data-style2 + ls_style-style2.
                ls_lvc_data-style3 = ls_lvc_data-style3 + ls_style-style3.
                ls_lvc_data-style4 = ls_lvc_data-style4 + ls_style-style4.
                ls_lvc_data-maxlen = ls_style-maxlen.
              endif.
            endif.
*         hotspot when field is initial
            if <ls_fcat>-hotspot eq 'V' and ls_lvc_data-value is initial.
              add alv_style_single_clk_event_no to ls_lvc_data-style.
            endif.
*         checkbox
            if <ls_fcat>-checkbox eq abap_true.
              if <l_field_value> ca '01'.
                add alv_style_enabled to ls_lvc_data-style.
              else.
*             add alv_style_disabled to gs_lvc_data-style.
              endif.
              if <l_field_value> eq abap_true or <l_field_value> eq '1'.
                add alv_style_checkbox_checked to ls_lvc_data-style.
              elseif <l_field_value> eq space or <l_field_value> eq '0'.
                add alv_style_checkbox_not_checked to ls_lvc_data-style.
              elseif <l_field_value> eq '-'.
                add alv_style_checkbox_no to ls_lvc_data-style.
              endif.
*         RadioButton
            elseif <ls_fcat>-checkbox eq 'R'.
              if <l_field_value> ca '01'.
                add alv_style_enabled to ls_lvc_data-style.
              else.
                add alv_style_disabled to ls_lvc_data-style.
              endif.
              if <l_field_value> eq abap_true or <l_field_value> eq '1'.
                add alv_style_radio_checked to ls_lvc_data-style.
              elseif <l_field_value> eq space or <l_field_value> eq '0'.
                add alv_style_radio_not_checked to ls_lvc_data-style.
              elseif <l_field_value> eq '-'.
                add alv_style_radio_no to ls_lvc_data-style.
              endif.
            endif.
          endif.
*>>> new API
        endif.
*<<< new API

        append ls_lvc_data to ct_lvc_data.
      endloop.
    endif.
  endloop.

  sort ct_lvc_data by row_pos col_pos.

* the data table has to now be corrected by too many upper cells
* which might have been built and too many lower cells
  if i_delete_entries_not_in_range eq abap_true.
    check not ct_lvc_data is initial.

    data: l_index type i,
          l_lines type i.

    if l_start le 0.
      l_start = 1.
    endif.
    read table ct_stin assigning <ls_stin> index l_start.
    if <ls_stin>-start_indx ne i_start.
      <ls_stin>-filled = space.
      l_index = i_start - <ls_stin>-start_indx.
      if l_index gt 0.
        delete ct_lvc_data to l_index.
      endif.
    endif.

    describe table ct_lvc_data lines l_lines.
    l_index = i_end - i_start + 1.
    if l_index ne l_lines.
      read table ct_stin assigning <ls_stin> index l_end.
      if sy-subrc eq 0.
        <ls_stin>-filled = space.
      endif.
      add 1 to l_index.
      if l_index le l_lines.
        delete ct_lvc_data from l_index.
      endif.
    endif.
  endif.

endform.                    " fill_data_table