메뉴 건너뛰기

SAP 한국 커뮤니티

REPORT ZRTTS_02

sapjoy 2009.12.24 12:05 조회 수 : 2586

* 출처 http://sdn.sap.com   Rich Heilman


REPORT  ZRTTS_02.


type-pools : abap.

field-symbols: <dyn_table> type standard table,
               <dyn_wa>,
               <dyn_field>.

data: dy_table type ref to data,
      dy_line  type ref to data,
      xfc type lvc_s_fcat,
      ifc type lvc_t_fcat.

selection-screen begin of block b1 with frame.
parameters: p_table(30type c default 'T001'.
selection-screen end of block b1.

start-of-selection.

  perform get_structure.
  perform create_dynamic_itab.
  perform get_data.
  perform write_out.


form get_structure.

data : idetails type abap_compdescr_tab,
       xdetails type abap_compdescr.

data : ref_table_des type ref to cl_abap_structdescr.

* Get the structure of the table.
  ref_table_des ?=
      cl_abap_typedescr=>describe_by_name( p_table ).
  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.

endform.

form create_dynamic_itab.

* Create dynamic internal table and assign to FS
  call method cl_alv_table_create=>create_dynamic_table
               exporting
                  it_fieldcatalog = ifc
               importing
                  ep_table        = dy_table.

  assign dy_table->* to <dyn_table>.

* Create dynamic work area and assign to FS
  create data dy_line like line of <dyn_table>.
  assign dy_line->* to <dyn_wa>.

endform.



form get_data.

* Select Data from table.
  select * into table <dyn_table>
             from (p_table).

endform.

form write_out.
 loop at <dyn_table> into <dyn_wa>.
    do.
      assign component  sy-index
         of structure <dyn_wa> to <dyn_field>.
      if sy-subrc <> 0.
        exit.
      endif.
      if sy-index = 1.
        write:/ <dyn_field>.
      else.
        write: <dyn_field>.
      endif.
    enddo.
  endloop.
 endform.

번호 제목 글쓴이 날짜 조회 수
550 REPORT Z18_002 sapjoy 2007.03.05 3082
549 REPORT z18_003 sapjoy 2007.03.05 3281
548 REPORT z18_004 [1] sapjoy 2007.03.05 2348
547 REPORT z18_005 sapjoy 2007.03.06 2157
546 REPORT z18_006 sapjoy 2007.03.06 2423
545 REPORT z18_007 sapjoy 2007.03.07 2206
544 REPORT z18_008 sapjoy 2007.03.07 2359
543 REPORT z18_011 [1] sapjoy 2007.03.07 2326
542 REPORT Z15_045 sapjoy 2007.03.08 2388
541 REPORT z18_012 [1] sapjoy 2007.03.09 2404
540 REPORT z18_013 [1] sapjoy 2007.03.09 2585
539 REPORT z18_014 sapjoy 2007.03.09 2843
538 REPORT z18_017 sapjoy 2007.03.11 2672
537 REPORT z18_018 [4] sapjoy 2007.03.11 2462
536 REPORT z18_019 sapjoy 2007.03.12 2473
535 REPORT z18_035 sapjoy 2007.03.13 2450
534 REPORT z18_036 sapjoy 2007.03.13 2631
533 REPORT z18_022 sapjoy 2007.03.16 2464
532 REPORT z18_025 sapjoy 2007.03.16 2598
531 REPORT z19_001 sapjoy 2007.03.22 2551