Chinaunix首页 | 论坛 | 博客
  • 博客访问: 176921
  • 博文数量: 31
  • 博客积分: 3000
  • 博客等级: 中校
  • 技术积分: 585
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-17 23:11
文章分类

全部博文(31)

文章存档

2011年(1)

2009年(18)

2008年(12)

我的朋友

分类:

2009-01-10 16:25:05

I have posted some articles about dynamic columns in gui alv.

Now I just give a guide to build dynamic Web ALV columns and table

many articles in sdn are shown how to build web alv applications .

based on those articles, I just post some further researchs.

As we all know,the alv wants some structures to build the catelogs.

Wes should build the catelogs as below

Build the dynamic data table

l  Build the catelogs

DATA: is_fieldcat TYPE LVC_S_FCAT.

DATA: gt_fieldcatalog TYPE lvc_t_fcat.

DATA: new_table TYPE REF TO data."out_data table space

DATA: new_line  TYPE REF TO data."out_data line space

DATA: LNAME TYPE STRING.

DATA: LS TYPE I VALUE 30.

DO LS TIMES.

  LNAME = SY-INDEX.

  CONCATENATE 'C' LNAME INTO is_fieldcat-fieldname.

*  is_fieldcat-fieldname = 'GUID'.

  is_fieldcat-ref_field = 'PROCESS_TYPE'..

  is_fieldcat-ref_table = 'CRMD_ORDERADM_H'.

  APPEND is_fieldcat TO gt_fieldcatalog.

ENDDO.

l  Build the data table

CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING

      it_fieldcatalog = gt_fieldcatalog

    IMPORTING

      ep_table        = new_table.

l  Assign the data to table

FIELD-SYMBOLS: TYPE ANY TABLE,

                 TYPE ANY,

               TYPE ANY.

  ASSIGN new_table->* TO .

DO LS TIMES.

  CREATE DATA new_line LIKE LINE OF .

  ASSIGN new_line->* TO .

 DO LS TIMES.

ASSIGN COMPONENT SY-INDEX

            OF STRUCTURE TO .

= SY-INDEX.

ENDDO.

insert into table .

ENDDO.

l  Create dynamic alv columns

data: descr_ref TYPE ref to CL_ABAP_TYPEDESCR.

data: STATIC_ELEMENT_RTTI type ref to CL_ABAP_STRUCTDESCR.

descr_ref = cl_abap_typedescr=>describe_by_data( ).

STATIC_ELEMENT_RTTI ?= descr_ref.

ZCL_WD_ALV_TEST=>CREATE_NODEINFO_FROM_STRUCT(

*    EXPORTING

    PARENT_INFO         = rootnode_info

*    STRUCTURE_NAME      = tablename

    IS_MULTIPLE         = abap_true

*    IS_MANDATORY        = ABAP_FALSE

    NODE_NAME           = 'DTABLE'

    STATIC_ELEMENT_RTTI = STATIC_ELEMENT_RTTI ).

*  RECEIVING

*    NEW_NODE            = dyn_node

    .

 

l  Bind the data to web alv

* get instance of new node

dyn_node = wd_context->get_child_node( name = 'DTABLE' ).

 

dyn_node->bind_table( ).

 

As shown above, we should create ZCL_WD_ALV_TEST=>CREATE_NODEINFO_FROM_STRUCT

method CREATE_NODEINFO_FROM_STRUCT.

*Programmed by Victor.Pan 2009

data: l_sdescr      type ref to cl_abap_structdescr,  "#EC NEEDED

        l_tdescr      type ref to cl_abap_typedescr.

*

  data: subnode_info   type ref to if_wd_context_node_info.

 

* check whether there is a subnode with this name

*  translate structure_name to upper case.                   "#EC NOTEXT

 

  if node_name is initial.

    node_name = structure_name.

  endif.

 

  try.

      subnode_info ?= parent_info->get_child_node( name = node_name ).

    catch CX_WD_CONTEXT.

      clear subnode_info.

  endtry.

 

  if subnode_info is initial.

* create subnode_info

    subnode_info = parent_info->add_new_child_node(

        name                   = node_name

        STATIC_ELEMENT_RTTI = STATIC_ELEMENT_RTTI

*        static_element_type    = structure_name

 

        IS_MANDATORY           = is_mandatory

        IS_MANDATORY_SELECTION = abap_false

        is_multiple            = is_multiple ).

 

  endif.

 

  new_node = subnode_info.

 

endmethod.

 

Then you will get the result below

 

阅读(952) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~