zoukankan      html  css  js  c++  java
  • ALV Grid Demo

    引用:翱翔云天

    前段时间写了一个alv grid demo程序,还没有完成,后来由于自己开始写alv generator,所以就把这个程序放下,那天老根同志问我要源代码,才发现由于工作转换的原因找不到了,后来委托以前的同事,终于把它弄出来,现在在这里发布,有兴趣的人可以看看.

    注意,这个程序并没有完成全部demo的功能,但是对一些control的使用还是有些帮助的.

    report zbobo_alv_grid_demo .
    
    types: begin of rt_tab,
            excp(1) type c,
            ebeln type ebeln,
            ebelp type ebelp,
            matnr type matnr,
            bukrs type bukrs,
            menge type bstmg,
            meins type bstme,
            rowc(4) type c,
            cc type lvc_t_scol,
            detailinit type c,
          end of rt_tab.
    
    class cl_gui_custom_container definition load.
    
    class zalv_grid definition deferred.
    
    define set_button.
      call method ref_colu->item_set_disabled
        exporting
          node_key          = &1
          item_name         = 'C3'
          disabled          = &2 .
    end-of-definition.
    
    define set_text.
      if &1 is initial.
        ls = 'Off'.
      else.
        ls = 'On'.
      endif.
      if &3 is initial.
        ls = 'Change'.
      endif.
    
      call method set_text
        exporting:
          n = &2 i = 'C2' t = &1 f = &3,
          n = &2 i = 'C3' t = ls f = &3.
    end-of-definition.
    
    define add_item_detail.
      call method add_item_detail
        exporting node_key  = &1
                  item_name = 'C1'
                  class     = 2
                  text      = &4.
      call method add_item_detail
        exporting node_key  = &1
                  item_name = 'C2'
                  class     = 2
                  text      = 'init'.
      call method add_item_detail
        exporting node_key  = &1
                  item_name = 'C3'
                  class     = &2
                  text      = &3.
    end-of-definition.
    
    define refresh_display.
      concatenate 'LAYOUT-' &1 into ls.
      assign (ls) to <fs>.
      if n = &1.
        <fs> = c.
        call method ref_alv->set_frontend_layout
          exporting
            is_layout = layout.
        call method ref_alv->refresh_table_display.
      endif.
    end-of-definition.
    
    define set_when.
      when &1.
        method = 'LAY_CHECKBOX'.
        if not checked is initial.
          call method set_text
            exporting n = &1 i = 'C3' t = 'On' f = 'X'.
          call method me->(method)
            exporting n = &1 i = 'C3' c = checked.
        else.
          call method set_text
            exporting n = &1 i = 'C3' t = 'Off' f = 'X'.
          call method me->(method)
            exporting n = &1 i = 'C3' c = checked.
        endif.
    end-of-definition.
    
    define set_checkbox.
      concatenate 'LAYOUT-' &1 into ls.
      assign ls to <fs>.
      if n = &1.
        refresh_display <fs>.
      endif.
    end-of-definition.
    
    define set_node_when.
      when &1.
        flag = &1.
        length = &2.
    
        call screen 9100 starting at 30 3
                         ending at 74 13.
        if flag = 'Y'.
          concatenate 'LAYOUT-' &1 into ls.
          assign (ls) to <fs>.
          read table is into s index 1.
          <fs> = s.
          call method ref_alv->set_frontend_layout
            exporting
              is_layout = layout.
          call method ref_alv->refresh_table_display .
        endif.
    end-of-definition.
    
    define set_flag_when.
      when &1.
        if text is initial.
          create object text
            exporting
              MAX_NUMBER_CHARS       = length
              parent                 = con  .
          call method text->set_statusbar_mode
            EXPORTING
              STATUSBAR_MODE         = 0.
          call method text->set_toolbar_mode
            EXPORTING
              TOOLBAR_MODE           = 0.
        else.
          call method text->free.
          create object text
            exporting
              MAX_NUMBER_CHARS       = length
              parent                 = con  .
          call method text->set_statusbar_mode
            EXPORTING
              STATUSBAR_MODE         = 0.
          call method text->set_toolbar_mode
            EXPORTING
              TOOLBAR_MODE           = 0.
        endif.
    end-of-definition.
    
    data: con type ref to cl_gui_custom_container.
    data: text type ref to cl_gui_textedit.
    data: s(255) type c.
    data: is like standard table of s.
    data: modif type i.
    data: flag(20) type c,
          length type i.
    
    *---------------------------------------------------------------------*
    *       CLASS zcl_init_screen DEFINITION
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    class zcl_init_screen definition.
      public section.
        data:
          sp_h type ref to cl_gui_splitter_container.
        methods:
          constructor,
          free,
          get_alv_con
            returning value(c_alv) type ref to cl_gui_container,
          get_tree_con
            returning value(c_tree) type ref to cl_gui_container.
    endclass.
    
    *---------------------------------------------------------------------*
    *       CLASS zcl_init_screen IMPLEMENTATION
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    class zcl_init_screen implementation.
      method constructor.
        create object sp_h
          exporting
            parent  = cl_gui_custom_container=>screen0
            rows    = 1
            columns = 2
          exceptions
            cntl_error        = 1
            cntl_system_error = 2
            others            = 3
            .
    
        call method sp_h->set_row_sash
          exporting
            id                = 1
            type              = sp_h->type_movable
            value             = 0.
      endmethod.
      method get_alv_con.
        c_alv = sp_h->get_container( row = 1 column = 2 ).
      endmethod.
      method get_tree_con.
        c_tree = sp_h->get_container( row = 1 column = 1 ).
      endmethod.
      method free.
        call method sp_h->free.
      endmethod.
    endclass.
    
    *---------------------------------------------------------------------*
    *       CLASS zcl_event DEFINITION
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    class zcl_event definition.
      public section.
        data:
          event type cntl_simple_event,
          events type cntl_simple_events.
    
        data:
          layout type lvc_s_layo.
        methods:
          constructor
            importing alv type ref to object
                      tree type ref to object,
          colu_button_click for event button_click
            of cl_gui_column_tree
            importing node_key item_name sender,
          colu_checkbox_change for event checkbox_change
            of cl_gui_column_tree
            importing node_key item_name checked,
          alv_HOTSPOT_CLICK for event HOTSPOT_CLICK
            of cl_gui_alv_grid
            importing E_ROW_ID E_COLUMN_ID ES_ROW_NO,
          add_colu_events,
          add_alv_events,
          set_handler.
      private section.
        data:
          ref_alv type ref to cl_gui_alv_grid,
          ref_tree type ref to cl_gui_column_tree,
          ref_colu type ref to cl_gui_column_tree.
        methods:
          set_text
            importing n type any i type any t type any f type c,
          lay_checkbox
            importing n type any optional
                      i type any optional
                      c type c optional.
    endclass.
    *---------------------------------------------------------------------*
    *       CLASS zcl_event IMPLEMENTATION
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    class zcl_event implementation.
      method constructor.
        if not alv is initial.
          ref_alv ?= alv.
        endif.
        if not tree is initial.
          ref_tree ?= tree.
        endif.
      endmethod.
      method alv_HOTSPOT_CLICK.
        break-point.
      endmethod.
      method colu_button_click.
        data: ls(30) type c.
        data: ltab type rt_tab.
        field-symbols: <fs> type any.
        case node_key.
          when 'F'.
            if item_name = 'C2'.
            elseif item_name = 'C3'.
            endif.
          when 'L'.
            if item_name = 'C2'.
              call method ref_alv->get_frontend_layout
                importing
                  es_layout = layout.
    
              set_text:
                layout-cwidth_opt 'CWIDTH_OPT' 'X',
                layout-smalltitle 'SMALLTITLE' 'X',
                layout-grid_title 'GRID_TITLE' ' ',
                layout-no_headers 'NO_HEADERS' 'X',
                layout-no_hgridln 'NO_HGRIDLN' 'X',
                layout-no_merging 'NO_MERGING' 'X',
                layout-no_rowmark 'NO_ROWMARK' 'X',
                layout-no_toolbar 'NO_TOOLBAR' 'X',
                layout-no_vgridln 'NO_VGRIDLN' 'X',
                layout-sel_mode 'SEL_MODE' ' ',
                layout-excp_conds 'EXCP_CONDS' 'X',
                layout-excp_fname 'EXCP_FNAME' ' ',
                layout-excp_led 'EXCP_LED' 'X',
                layout-excp_rolln 'EXCP_ROLLN' ' ',
                layout-ctab_fname 'CTAB_FNAME' ' ',
                layout-info_fname 'INFO_FNAME' ' ',
                layout-zebra 'ZEBRA' 'X',
                layout-no_totarr 'NO_TOTARR' 'X',
                layout-no_totexp 'NO_TOTEXP' 'X',
                layout-no_totline 'NO_TOTLINE' 'X',
                layout-numc_total 'NUMC_TOTAL' 'X',
                layout-totals_bef 'TOTALS_BEF' 'X',
                layout-detailinit 'DETAILINIT' 'X',
                layout-detailtitl 'DETAILTITL' ' ',
                layout-keyhot 'KEYHOT' 'X',
                layout-sgl_clk_hd 'SGL_CLK_HD' 'X',
                layout-stylefname 'STYLEFNAME' ' '.
                ref_colu = ref_tree.
                set_button: 'GRID_TITLE' ' ',
                            'SEL_MODE' ' ',
                            'EXCP_FNAME' ' ',
                            'EXCP_ROLLN' ' ',
                            'CTAB_FNAME' ' ',
                            'INFO_FNAME' ' ',
                            'DETAILTITL' ' ',
                            'S_DRAGDROP' ' ',
                            'STYLEFNAME' ' '.
    *          call method ref_tree->item_set_text
    *            exporting
    *              node_key          = 'S_DRAGDROP'
    *              item_name         = 'C2'
    *              text              = layout-S_DRAGDROP   .
    
            elseif item_name = 'C3'.
            endif.
          set_node_when: 'GRID_TITLE' 70,
                         'SEL_MODE' 1,
                         'EXCP_FNAME' 30,
                         'EXCP_ROLLN' 30,
                         'INFO_FNAME' 30,
                         'CTAB_FNAME' 30,
                         'DETAILTITL' 30.
        endcase.
      endmethod.
      method colu_checkbox_change.
        data: method(20) type c.
        case node_key.
          set_when: 'CWIDTH_OPT',
                    'SMALLTITLE',
                    'NO_HEADERS',
                    'NO_HGRIDLN',
                    'NO_MERGING',
                    'NO_ROWMARK',
                    'NO_TOOLBAR',
                    'NO_VGRIDLN',
                    'EXCP_CONDS',
                    'EXCP_LED',
                    'ZEBRA',
                    'NO_TOTARR',
                    'NO_TOTEXP',
                    'NO_TOTLINE',
                    'NUMC_TOTAL',
                    'TOTALS_BEF',
                    'KEYHOT',
                    'SGL_CLK_HD',
                    'DETAILINIT'.
        endcase.
      endmethod.
      method lay_checkbox.
        data: ls(30) type c.
        field-symbols <fs> type any.
    
        refresh_display:
          'CWIDTH_OPT',
          'SMALLTITLE',
          'NO_HEADERS',
          'NO_HGRIDLN',
          'NO_MERGING',
          'NO_ROWMARK',
          'NO_TOOLBAR',
          'NO_VGRIDLN',
          'EXCP_CONDS',
          'EXCP_LED',
          'ZEBRA',
          'NO_TOTARR',
          'NO_TOTEXP',
          'NO_TOTLINE',
          'NUMC_TOTAL',
          'DETAILINIT',
          'TOTALS_BEF',
          'KEYHOT',
          'SGL_CLK_HD',
          'DETAILINIT'.
      endmethod.
      method set_text.
        call method ref_tree->item_set_text
          exporting
            node_key          = n
            item_name         = i
            text              = t   .
        check i = 'C3' and f = 'X'.
        call method ref_tree->item_set_editable
          exporting
            node_key          = n
            item_name         = i
            editable          = 'X'.
      endmethod.
      method add_alv_events.
    *    clear:event,events.
    *    event-eventid = CL_GUI_ALV_GRID=>eventid_link_click.
    *    event-appl_event = 'X'.                                   "
    *    append event to events.
      endmethod.
      method add_colu_events.
        clear:event,events.
        event-eventid = cl_gui_column_tree=>eventid_link_click.
        event-appl_event = 'X'.                                   "
        append event to events.
    
        event-eventid = cl_gui_column_tree=>eventid_button_click.
        event-appl_event = 'X'.
        append event to events.
    
        event-eventid = cl_gui_column_tree=>eventid_checkbox_change.
        event-appl_event = 'X'.
        append event to events.
      endmethod.
      method set_handler.
        set handler me->colu_button_click for ref_tree.
        set handler me->colu_checkbox_change for ref_tree.
      endmethod.
    endclass.
    
    *---------------------------------------------------------------------*
    *       CLASS zcl_tree DEFINITION
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    class zcl_tree definition.
      public section.
        data:
          l_node_t type treev_ntab,
          l_item_t type standard table of mtreeitm with default key,
          con type ref to cl_gui_container,
          ref_colu type ref to cl_gui_column_tree.
        methods:
          constructor
            importing ref_init type ref to zcl_init_screen,
          add_data,
          show_data,
          free.
      private section.
        methods:
          add_node,
          add_item,
          add_node_detail
            importing node_key  type tv_nodekey
                      relatkey  type tv_nodekey optional
                      relatship type int4 optional
                      isfolder  type as4flag optional,
          add_item_detail
            importing node_key  type tv_nodekey
                      item_name type tv_itmname
                      class     type int4 optional
                      text      type scrpcha72
                      t_image   type tv_image optional
                      editable  type as4flag optional.
    endclass.
    *---------------------------------------------------------------------*
    *       CLASS zcl_tree IMPLEMENTATION
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    class zcl_tree implementation.
      method constructor.
        data: hierarchy_header type treev_hhdr.
    
        call method ref_init->get_tree_con
          receiving c_tree = con.
    
        hierarchy_header-heading = text-001.
        hierarchy_header-width = 30.
    
        create object ref_colu
          exporting
            parent                      = con
            node_selection_mode         = 0
            item_selection              = 'X'
            hierarchy_column_name       = 'C1'
            hierarchy_header            = hierarchy_header
          exceptions
            lifetime_error              = 1
            cntl_system_error           = 2
            create_error                = 3
            illegal_node_selection_mode = 4
            failed                      = 5
            illegal_column_name         = 6
            others                      = 7
            .
        if sy-subrc <> 0.
    *     Processing error
        endif.
    *   Add data to tree
        call method add_data.
    *   Display tree data
        call method show_data.
      endmethod.
      method add_data.
        data: node type treev_node,
              item type mtreeitm.
    *   Add columns to tree
        call method ref_colu->add_column
          exporting
            name = 'C2'
            width = 20
            header_text = 'Document'.
        call method ref_colu->add_column
          exporting
            name = 'C3'
            width = 21
            header_text = 'Value'.
    *   Add node data to tree
        call method add_node.
    *   Add item data to tree
        call method add_item.
      endmethod.
      method add_node.
    *   For field catelog
        call method add_node_detail
          exporting node_key = 'F'
                    isfolder = 'X'.
        call method add_node_detail
          exporting node_key = 'FIELDNAME'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'REF_FIELD'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'REF_TABLE'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'CHECKBOX'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'COL_POS'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'DO_SUM'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'EMPHASIZE'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'HOTSPOT'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'HREF_HNDL'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'KEY'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'LOWERCASE'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'NO_OUT'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'NO_MERG'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'NO_SUM'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'OUTPUTLEN'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'STYLE'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'TECH'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'DECIMALS_O'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'DECMFIELD'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'EDIT_MASK'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'ICON'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'JUST'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'LZERO'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'NO_SIGN'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'NO_ZERO'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'COLDDICTXT'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'COLTEXT'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'REPTEXT'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'SCRTEXT_L'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'SCRTEXT_M'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'SCRTEXT_S'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'SELDDICTXT'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'SELTEXT'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'TIPDDICTXT'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'TOOLTIP'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'INTTYPE'
                    relatkey = 'F'.
        call method add_node_detail
          exporting node_key = 'SP_GROUP'
                    relatkey = 'F'.
    
    *   For alv layout
        call method add_node_detail
          exporting node_key = 'L'
                    isfolder = 'X'.
        call method add_node_detail
          exporting node_key = 'CWIDTH_OPT'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'SMALLTITLE'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'GRID_TITLE'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'NO_HEADERS'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'NO_HGRIDLN'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'NO_MERGING'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'NO_ROWMARK'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'NO_TOOLBAR'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'NO_VGRIDLN'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'SEL_MODE'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'EXCP_CONDS'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'EXCP_FNAME'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'EXCP_LED'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'EXCP_ROLLN'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'CTAB_FNAME'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'INFO_FNAME'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'ZEBRA'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'NO_TOTARR'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'NO_TOTEXP'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'NO_TOTLINE'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'NUMC_TOTAL'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'TOTALS_BEF'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'DETAILINIT'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'DETAILTITL'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'S_DRAGDROP'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'KEYHOT'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'SGL_CLK_HD'
                    relatkey = 'L'.
        call method add_node_detail
          exporting node_key = 'STYLEFNAME'
                    relatkey = 'L'.
    *   For alv variant
        call method add_node_detail
          exporting node_key = 'V'
                    isfolder = 'X'.
    *   For alv filter
        call method add_node_detail
          exporting node_key = 'FI'
                    isfolder = 'X'.
        call method add_node_detail
          exporting node_key = 'STR1'
                    relatkey = 'FI'
                    isfolder = 'X'.
        call method add_node_detail
          exporting node_key = 'FIELDNAME2'
                    relatkey = 'STR1'.
        call method add_node_detail
          exporting node_key = 'SIGN'
                    relatkey = 'STR1'.
        call method add_node_detail
          exporting node_key = 'OPTION'
                    relatkey = 'STR1'.
        call method add_node_detail
          exporting node_key = 'LOW'
                    relatkey = 'STR1'.
        call method add_node_detail
          exporting node_key = 'HIGH'
                    relatkey = 'STR1'.
    *   For alv sorts
        call method add_node_detail
          exporting node_key = 'S'
                    isfolder = 'X'.
        call method add_node_detail
          exporting node_key = 'STR'
                    relatkey = 'S'
                    isfolder = 'X'.
        call method add_node_detail
          exporting node_key = 'SPOS'
                    relatkey = 'STR'.
        call method add_node_detail
          exporting node_key = 'FIELDNAME1'
                    relatkey = 'STR'.
        call method add_node_detail
          exporting node_key = 'UP'
                    relatkey = 'STR'.
        call method add_node_detail
          exporting node_key = 'DOWN'
                    relatkey = 'STR'.
      endmethod.
      method add_item.
        call method add_item_detail
          exporting node_key  = 'F'
                    item_name = 'C1'
                    class     = 2
                    text      = text-i01.
        call method add_item_detail
          exporting node_key  = 'F'
                    item_name = 'C3'
                    class     = 4
                    text      = text-c01.
        call method add_item_detail
          exporting node_key  = 'F'
                    item_name = 'C2'
                    class     = 4
                    text      = text-c05.
        call method add_item_detail
          exporting node_key  = 'FIELDNAME'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f01.
        call method add_item_detail
          exporting node_key  = 'FIELDNAME'
                    item_name = 'C2'
                    class     = 2
                    text      = text-c02.
        call method add_item_detail
          exporting node_key  = 'REF_FIELD'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f02.
        call method add_item_detail
          exporting node_key  = 'REF_FIELD'
                    item_name = 'C2'
                    class     = 2
                    text      = text-c02.
        call method add_item_detail
          exporting node_key  = 'REF_TABLE'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f03.
        call method add_item_detail
          exporting node_key  = 'REF_TABLE'
                    item_name = 'C2'
                    class     = 2
                    text      = text-c02.
        call method add_item_detail
          exporting node_key  = 'CHECKBOX'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f04.
        call method add_item_detail
          exporting node_key  = 'CHECKBOX'
                    item_name = 'C2'
                    class     = 3
                    editable  = 'X'
                    text      = text-c03.
        call method add_item_detail
          exporting node_key  = 'COL_POS'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f05.
        call method add_item_detail
          exporting node_key  = 'DO_SUM'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f06.
        call method add_item_detail
          exporting node_key  = 'EMPHASIZE'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f07.
        call method add_item_detail
          exporting node_key  = 'HOTSPOT'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f08.
        call method add_item_detail
          exporting node_key  = 'HREF_HNDL'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f09.
        call method add_item_detail
          exporting node_key  = 'KEY'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f10.
        call method add_item_detail
          exporting node_key  = 'LOWERCASE'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f11.
        call method add_item_detail
          exporting node_key  = 'NO_OUT'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f12.
        call method add_item_detail
          exporting node_key  = 'NO_MERGING'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f13.
        call method add_item_detail
          exporting node_key  = 'NO_SUM'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f14.
        call method add_item_detail
          exporting node_key  = 'OUTPUTLEN'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f15.
        call method add_item_detail
          exporting node_key  = 'STYLE'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f16.
        call method add_item_detail
          exporting node_key  = 'TECH'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f17.
        call method add_item_detail
          exporting node_key  = 'DECIMALS_O'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f18.
        call method add_item_detail
          exporting node_key  = 'DECMFIELD'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f19.
        call method add_item_detail
          exporting node_key  = 'EDIT_MASK'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f20.
        call method add_item_detail
          exporting node_key  = 'ICON'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f21.
        call method add_item_detail
          exporting node_key  = 'JUST'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f22.
        call method add_item_detail
          exporting node_key  = 'LZERO'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f23.
        call method add_item_detail
          exporting node_key  = 'NO_SIGN'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f24.
        call method add_item_detail
          exporting node_key  = 'NO_ZERO'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f25.
        call method add_item_detail
          exporting node_key  = 'COLDDICTXT'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f26.
        call method add_item_detail
          exporting node_key  = 'COLTEXT'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f27.
        call method add_item_detail
          exporting node_key  = 'REPTEXT'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f28.
        call method add_item_detail
          exporting node_key  = 'SCRTEXT_L'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f29.
        call method add_item_detail
          exporting node_key  = 'SCRTEXT_M'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f30.
        call method add_item_detail
          exporting node_key  = 'SCRTEXT_S'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f31.
        call method add_item_detail
          exporting node_key  = 'SELDDICTXT'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f32.
        call method add_item_detail
          exporting node_key  = 'SELTEXT'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f33.
        call method add_item_detail
          exporting node_key  = 'TIPDDICTXT'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f34.
        call method add_item_detail
          exporting node_key  = 'TOOLTIP'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f35.
        call method add_item_detail
          exporting node_key  = 'INTTYPE'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f36.
        call method add_item_detail
          exporting node_key  = 'SP_GROUP'
                    item_name = 'C1'
                    class     = 2
                    text      = text-f37.
        call method add_item_detail
          exporting node_key  = 'L'
                    item_name = 'C1'
                    class     = 2
                    text      = text-i02.
    

    call method add_item_detail
          exporting node_key  = 'L'
                    item_name = 'C3'
                    class     = 4
                    text      = text-c01.
        call method add_item_detail
          exporting node_key  = 'L'
                    item_name = 'C2'
                    class     = 4
                    text      = text-c05.
        call method add_item_detail
          exporting node_key  = 'NO_MERG'
                    item_name = 'C1'
                    class     = 2
                    text      = text-l06.
        call method add_item_detail
          exporting node_key  = 'NO_MERGING'
                    item_name = 'C2'
                    class     = 2
                    text      = 'init'.
        call method add_item_detail
          exporting node_key  = 'NO_MERGING'
                    item_name = 'C3'
                    class     = 3
                    text      = 'init'.
        add_item_detail:
          'CWIDTH_OPT' '3' 'init' text-l01,
          'SMALLTITLE' '3' 'init' text-l02,
          'GRID_TITLE' '4' 'Change' text-l03,
          'NO_HEADERS' '3' 'init' text-l04,
          'NO_HGRIDLN' '3' 'init' text-l05,
          'NO_ROWMARK' '3' 'init' text-l07,
          'NO_TOOLBAR' '3' 'init' text-l08,
          'NO_VGRIDLN' '3' 'init' text-l09,
          'SEL_MODE' '4' 'Change' text-l10,
          'EXCP_CONDS' '3' 'init' text-l11,
          'EXCP_FNAME' '4' 'Change' text-l12,
          'EXCP_LED' '3' 'init' text-l13,
          'EXCP_ROLLN' '4' 'Change' text-l14,
          'CTAB_FNAME' '4' 'Change' text-l15,
          'INFO_FNAME' '4' 'Change' text-l16,
          'ZEBRA' '3' 'init' text-l17,
          'NO_TOTARR' '3' 'init' text-l18,
          'NO_TOTEXP' '3' 'init' text-l19,
          'NO_TOTLINE' '3' 'init' text-l20,
          'NUMC_TOTAL' '3' 'init' text-l21,
          'TOTALS_BEF' '3' 'init' text-l22,
          'DETAILINIT' '3' 'init' text-l23,
          'DETAILTITL' '4' 'Change' text-l24,
          'S_DRAGDROP' '4' 'Change' text-l25,
          'KEYHOT' '3' 'init' text-l26,
          'SGL_CLK_HD' '3' 'init' text-l27,
          'STYLEFNAME' '4' 'Change' text-l28.
    
        call method add_item_detail
          exporting node_key  = 'V'
                    item_name = 'C1'
                    class     = 2
                    text      = text-i03.
        call method add_item_detail
          exporting node_key  = 'V'
                    item_name = 'C3'
                    class     = 4
                    text      = text-c01.
        call method add_item_detail
          exporting node_key  = 'V'
                    item_name = 'C2'
                    class     = 4
                    text      = text-c05.
    
        call method add_item_detail
          exporting node_key  = 'FI'
                    item_name = 'C1'
                    class     = 2
                    text      = text-i04.
        call method add_item_detail
          exporting node_key  = 'FIELDNAME2'
                    item_name = 'C1'
                    class     = 2
                    text      = 'FIELDNAME'.
        call method add_item_detail
          exporting node_key  = 'FIELDNAME2'
                    item_name = 'C2'
                    class     = 2
                    text      = 'Field name for filter'.
        call method add_item_detail
          exporting node_key  = 'SIGN'
                    item_name = 'C1'
                    class     = 2
                    text      = 'SIGN'.
        call method add_item_detail
          exporting node_key  = 'SIGN'
                    item_name = 'C2'
                    class     = 2
                    text      = '''E'',''I'''.
        call method add_item_detail
          exporting node_key  = 'OPTION'
                    item_name = 'C1'
                    class     = 2
                    text      = 'OPTION'.
        call method add_item_detail
          exporting node_key  = 'OPTION'
                    item_name = 'C2'
                    class     = 2
                    text      = '''BT'',''EQ'''.
        call method add_item_detail
          exporting node_key  = 'LOW'
                    item_name = 'C1'
                    class     = 2
                    text      = 'LOW'.
        call method add_item_detail
          exporting node_key  = 'LOW'
                    item_name = 'C2'
                    class     = 2
                    text      = 'Text (80 characters)'.
        call method add_item_detail
          exporting node_key  = 'HIGH'
                    item_name = 'C1'
                    class     = 2
                    text      = 'HIGH'  .
        call method add_item_detail
          exporting node_key  = 'HIGH'
                    item_name = 'C2'
                    class     = 2
                    text      = 'Text (80 characters)'  .
    
        call method add_item_detail
          exporting node_key  = 'S'
                    item_name = 'C1'
                    class     = 2
                    text      = text-i05.
        call method add_item_detail
          exporting node_key  = 'S'
                    item_name = 'C2'
                    class     = 2
                    text      = 'LVC_S_SORT'.
        call method add_item_detail
          exporting node_key  = 'FI'
                    item_name = 'C2'
                    class     = 2
                    text      = 'LVC_S_FILT'.
        call method add_item_detail
          exporting node_key  = 'STR'
                    item_name = 'C1'
                    class     = 2
                    text      = 'Structure'.
        call method add_item_detail
          exporting node_key  = 'STR1'
                    item_name = 'C1'
                    class     = 2
                    text      = 'Structure'.
        call method add_item_detail
          exporting node_key  = 'SPOS'
                    item_name = 'C1'
                    class     = 2
                    text      = text-d01.
        call method add_item_detail
          exporting node_key  = 'SPOS'
                    item_name = 'C2'
                    class     = 2
                    text      = 'Sort sequence'.
        call method add_item_detail
          exporting node_key  = 'FIELDNAME1'
                    item_name = 'C1'
                    class     = 2
                    text      = text-d02.
        call method add_item_detail
          exporting node_key  = 'FIELDNAME1'
                    item_name = 'C2'
                    class     = 2
                    text      = 'Sorted field name'.
        call method add_item_detail
          exporting node_key  = 'UP'
                    item_name = 'C1'
                    class     = 2
                    text      = text-d03.
        call method add_item_detail
          exporting node_key  = 'UP'
                    item_name = 'C2'
                    class     = 2
                    text      = 'Asscending is ''X'''.
        call method add_item_detail
          exporting node_key  = 'DOWN'
                    item_name = 'C1'
                    class     = 2
                    text      = text-d04.
        call method add_item_detail
          exporting node_key  = 'DOWN'
                    item_name = 'C2'
                    class     = 2
                    text      = 'Asscending is ''X'''.
        call method add_item_detail
          exporting node_key  = 'STR'
                    item_name = 'C2'
                    class     = 2
                    text      = 'Field description'.
        call method add_item_detail
          exporting node_key  = 'STR1'
                    item_name = 'C2'
                    class     = 2
                    text      = 'Field description'.
    
      endmethod.
      method add_node_detail.
        data: node type treev_node.
        node-node_key = node_key.
        node-relatkey = relatkey.
        node-relatship = relatship.
        node-isfolder = isfolder.
        append node to l_node_t.
      endmethod.
      method add_item_detail.
        data:item type mtreeitm.
        item-node_key = node_key.
        item-item_name = item_name.
        item-class = class.
        item-text = text.
        item-t_image = t_image.
        item-editable = editable.
        append item to l_item_t.
      endmethod.
      method show_data.
        call method ref_colu->add_nodes_and_items
          exporting
            node_table = l_node_t
            item_table = l_item_t
            item_table_structure_name = 'MTREEITM'.
        set_button: 'GRID_TITLE' 'X',
                    'SEL_MODE' 'X',
                    'EXCP_FNAME' 'X',
                    'EXCP_ROLLN' 'X',
                    'CTAB_FNAME' 'X',
                    'INFO_FNAME' 'X',
                    'DETAILTITL' 'X',
                    'S_DRAGDROP' 'X',
                    'STYLEFNAME' 'X'.
      endmethod.
      method free.
      endmethod.
    endclass.
    
    *---------------------------------------------------------------------*
    *       CLASS zalv_grid DEFINITION
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    class zalv_grid definition inheriting from cl_gui_alv_grid.
      public section.
        methods:
          constructor
            importing par type ref to cl_gui_container.
    endclass.
    *---------------------------------------------------------------------*
    *       CLASS zalv_grid IMPLEMENTATION
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    class zalv_grid implementation.
      method constructor.
        call method super->constructor
          exporting i_parent = par.
      endmethod.
    endclass.
    *---------------------------------------------------------------------*
    *       CLASS zcl_alv DEFINITION
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    class zcl_alv definition.
      public section.
        data: it_tab type standard table of rt_tab,
              st_tab type rt_tab.
        data:
          con type ref to cl_gui_container,
          ref_alv type ref to zalv_grid.
    
        data:
          it_fieldcat type lvc_t_fcat,
          fieldcat type lvc_s_fcat,
          layout type lvc_s_layo.
    
        methods:
          constructor importing
            ref_init type ref to zcl_init_screen,
          refresh_data.
      private section.
        methods:
          init_fieldcat,
          init_layout,
          get_variant,
          build_sort,
          build_filter,
          add_data,
          show_data.
    endclass.
    *---------------------------------------------------------------------*
    *       CLASS zcl_alv IMPLEMENTATION
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    class zcl_alv implementation.
      method constructor.
        call method ref_init->get_alv_con
          receiving c_alv = con.
        create object ref_alv
          exporting par = con.
        call method init_fieldcat.
        call method init_layout.
        call method get_variant.
        call method build_sort.
        call method build_filter.
        call method add_data.
        call method show_data.
      endmethod.
      method init_fieldcat.
        clear: fieldcat.
        fieldcat-col_pos = '1'.
        fieldcat-fieldname = 'EXCP'.
        fieldcat-key = 'X'.
        fieldcat-COLTEXT = 'Exceptions'.
        append fieldcat to it_fieldcat.
        clear: fieldcat.
        fieldcat-col_pos = '2'.
        fieldcat-fieldname = 'EBELN'.
        fieldcat-ref_field = 'EBELN'.
        fieldcat-ref_table = 'EKPO'.
        fieldcat-key = 'X'.
        append fieldcat to it_fieldcat.
        clear: fieldcat.
        fieldcat-col_pos = '3'.
        fieldcat-fieldname = 'EBELP'.
        fieldcat-ref_field = 'EBELP'.
        fieldcat-ref_table = 'EKPO'.
        append fieldcat to it_fieldcat.
        clear: fieldcat.
        fieldcat-col_pos = '4'.
        fieldcat-fieldname = 'MATNR'.
        fieldcat-ref_field = 'MATNR'.
        fieldcat-ref_table = 'EKPO'.
        append fieldcat to it_fieldcat.
        clear: fieldcat.
        fieldcat-col_pos = '5'.
        fieldcat-fieldname = 'BUKRS'.
        fieldcat-ref_field = 'BUKRS'.
        fieldcat-ref_table = 'EKPO'.
        append fieldcat to it_fieldcat.
        clear: fieldcat.
        fieldcat-col_pos = '6'.
        fieldcat-fieldname = 'MENGE'.
        fieldcat-ref_field = 'MENGE'.
        fieldcat-ref_table = 'EKPO'.
        append fieldcat to it_fieldcat.
        clear: fieldcat.
        fieldcat-col_pos = '7'.
        fieldcat-fieldname = 'MEINS'.
        fieldcat-ref_field = 'MEINS'.
        fieldcat-ref_table = 'EKPO'.
        append fieldcat to it_fieldcat.
      endmethod.
      method init_layout.
        layout-grid_title = 'test'.
      endmethod.
      method get_variant.
      endmethod.
      method build_sort.
      endmethod.
      method build_filter.
      endmethod.
      method add_data.
        data: ls type lvc_s_scol.
        clear sy-tabix.
        select ebeln ebelp matnr bukrs menge meins
          from ekpo
          into (st_tab-ebeln, st_tab-ebelp, st_tab-matnr,
          st_tab-bukrs, st_tab-menge, st_tab-meins).
          if sy-tabix > 200.
            exit.
          endif.
          append st_tab to it_tab.
        endselect.
        sort it_tab by ebeln.
        loop at it_tab into st_tab.
    *     For coloring a row
          st_tab-excp = sy-tabix mod 3 + 1.
          st_tab-rowc+0(1) = 'C'.
          st_tab-rowc+1(1) = sy-tabix mod 7 + 1.
          st_tab-rowc+2(2) = '10'.
    *     For coloring a cell
          if sy-tabix = 2.
            ls-fname = 'MENGE'.
            ls-color-col = '6'.
            ls-color-int = '1'.
            append ls to st_tab-cc.
          endif.
    *     For coloring all column
          ls-fname = 'MATNR'.
          ls-color-col = '7'.
          ls-color-int = '1'.
          append ls to st_tab-cc.
          modify it_tab from st_tab.
        endloop.
      endmethod.
      method show_data.
        call method ref_alv->set_table_for_first_display
          exporting
    *        I_BYPASSING_BUFFER            =
    *        I_BUFFER_ACTIVE               =
    *        I_CONSISTENCY_CHECK           =
    *        I_STRUCTURE_NAME              =
    *        IS_VARIANT                    =
    *        I_SAVE                        =
    *        I_DEFAULT                     = 'X'
            is_layout                     = layout
    *        IS_PRINT                      =
    *        IT_SPECIAL_GROUPS             =
    *        IT_TOOLBAR_EXCLUDING          =
    *        IT_HYPERLINK                  =
    *        IT_ALV_GRAPHICS               =
    *        IT_EXCEPT_QINFO               =
          changing
            it_outtab                     = it_tab
            it_fieldcatalog               = it_fieldcat
    *        IT_SORT                       =
    *        IT_FILTER                     =
    *      EXCEPTIONS
    *        INVALID_PARAMETER_COMBINATION = 1
    *        PROGRAM_ERROR                 = 2
    *        TOO_MANY_LINES                = 3
    *        others                        = 4
                .
        if sy-subrc <> 0.
    *     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        endif.
    
      endmethod.
      method refresh_data.
      endmethod.
    endclass.
    
    *---------------------------------------------------------------------*
    *       CLASS zcl_excute DEFINITION
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    class zcl_excute definition.
      public section.
        data:
          ref_screen type ref to zcl_init_screen,
          ref_tree type ref to zcl_tree,
          ref_alv type ref to zcl_alv,
          ref_event type ref to zcl_event.
        methods:
          constructor.
    endclass.
    *---------------------------------------------------------------------*
    *       CLASS zcl_excute IMPLEMENTATION
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    class zcl_excute implementation.
      method constructor.
        create object ref_screen.
        create object ref_tree
          exporting ref_init = ref_screen.
        create object ref_alv
          exporting ref_init = ref_screen.
        create object ref_event
          exporting alv = ref_alv->ref_alv
                    tree = ref_tree->ref_colu.
        call method ref_event->add_colu_events.
    
        call method ref_tree->ref_colu->set_registered_events
          exporting
            events = ref_event->events
          exceptions
            cntl_error                = 1
            cntl_system_error         = 2
            illegal_event_combination = 3.
        call method ref_event->set_handler.
      endmethod.
    endclass.
    
    data:
      ok_code like sy-ucomm,
      ref_excute type ref to zcl_excute.
    
    start-of-selection.
    
      call screen 9000.
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_9000  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    module status_9000 output.
      set pf-status 'ST9000'.
      set titlebar 'ALV'.
      if ref_excute is initial.
        create object ref_excute.
      endif.
    endmodule.                 " STATUS_9000  OUTPUT
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_9000  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    module user_command_9000 input.
      case ok_code.
        when 'BACK'.
          leave program.
      endcase.
    endmodule.                 " USER_COMMAND_9000  INPUT
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_9100  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    module USER_COMMAND_9100 input.
      case ok_code.
        when 'CONF'.
          clear: s, is.
          call method text->get_text_as_stream
            IMPORTING
              TEXT                   = is
              IS_MODIFIED            = modif.
          if modif <> 0.
            flag = 'Y'.
          else.
            flag = 'N'.
          endif.
          leave to screen 0.
        when 'CANC'.
          flag = 'N'.
          leave to screen 0.
      endcase.
    endmodule.                 " USER_COMMAND_9100  INPUT
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_9100  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    module STATUS_9100 output.
      if con is initial.
        create object con
          exporting
            container_name              = 'CON'.
      endif.
      case flag.
        set_flag_when 'GRID_TITLE'.
        set_flag_when 'SEL_MODE'.
        set_flag_when 'EXCP_FNAME'.
        set_flag_when 'EXCP_ROLLN'.
        set_flag_when 'INFO_FNAME'.
        set_flag_when 'CTAB_FNAME'.
        set_flag_when 'DETAILTITL'.
      endcase.
    endmodule.                 " STATUS_9100  OUTPUT
    

    屏幕属性

    9000

    PROCESS BEFORE OUTPUT.

    MODULE STATUS_9000.

    *

    PROCESS AFTER INPUT.

    MODULE USER_COMMAND_9000.

    9100

     

    PROCESS BEFORE OUTPUT.

    MODULE STATUS_9100.

    *

    PROCESS AFTER INPUT.

    MODULE USER_COMMAND_9100.

    Status:

  • 相关阅读:
    AJAX 基础知识
    jQuery知识点总结
    css基础应用总结
    javascript 总结
    找回密码-博客园
    centerOS 7 安装MySql
    java leetcode TreeNode类、ListNode类的实现
    iOS StatusBar状态栏文字颜色更改
    使用Jmeter压力测试工具测试
    安装node.js
  • 原文地址:https://www.cnblogs.com/wequst/p/1513265.html
Copyright © 2011-2022 走看看