Dynamic Table 구성

참고소스 1.

[#M_더보기|접기|

  DATAgo_dref TYPE REF TO data.

  
DATAgo_dy_line TYPE REF TO data.

  
FIELD-SYMBOLS<gt_table> TYPE STANDARD TABLE,

                 <gs_table> 
TYPE ANY.



  
IF g_zpmty ‘1’” 업적.

    
CREATE DATA go_dref TYPE STANDARD TABLE OF zhrt2101.



  
ELSEIF g_zpmty ‘2’” 역량.

    
CREATE DATA go_dref TYPE STANDARD TABLE OF zhrt2108.

  
ENDIF.



  
ASSIGN go_dref->TO <gt_table>.



  
CREATE DATA go_dy_line LIKE LINE OF <gt_table>.

  
ASSIGN go_dy_line->TO <gs_table>.

_M#]

 

 

참고소스 2.

[#M_더보기|접기|

* Data 선언

  FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE
                 <dyn_wa>,
                 <dyn_field>.
  DATA: lo_dy_table TYPE REF TO data,
        lo_dy_line  TYPE REF TO data,
        xfc TYPE lvc_s_fcat,
        ifc TYPE lvc_t_fcat.
  DATA: idetails TYPE abap_compdescr_tab,
        xdetails TYPE abap_compdescr.
  DATA: ref_table_des TYPE REF TO cl_abap_structdescr.

 DATA: lv_field(100).
 DATA: lv_where(100).
 DATA: lv_f_langu TYPE dd03l-fieldname

 

* 테이블 구조 가져오기

      CLEAR: idetails, idetails[], ifc, ifc[].
      ref_table_des ?=
          cl_abap_typedescr=>describe_by_name( lt_3150-tablename ).
      idetails[] = ref_table_des->components[].
      LOOP AT idetails INTO xdetails.
        CLEAR xfc.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-inttype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        APPEND xfc TO ifc.
      ENDLOOP.

 

* 다이나믹 인터널 테이블 생성, FS에 할당.

      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = ifc
        IMPORTING
          ep_table        = lo_dy_table.
      ASSIGN lo_dy_table->* TO <dyn_table>.

 

* Workarea 생성 및 FS 할당

      CREATE DATA lo_dy_line LIKE LINE OF <dyn_table>.
      ASSIGN lo_dy_line->* TO <dyn_w

 

      LOOP AT <dyn_table> INTO <dyn_wa>.

        ASSIGN COMPONENT 1 OF STRUCTURE <dyn_wa> TO <dyn_field>.

        CHECK lt_0080-code = <dyn_field>.

        ASSIGN COMPONENT 2 OF STRUCTURE <dyn_wa> TO <dyn_field>.

        lt_0080-code_text = <dyn_field>.
        lt_0080-langu = sy-langu.
      ENDLOOP

 

_M#]

 

참고 사이트 : http://goo.gl/aw0Vis

 

 

 

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments