REPORT ZRTTS_01 .
TYPE-POOLS abap.
TYPES : BEGIN OF ty_kind, " 종류 코드
kind TYPE c LENGTH 4, " 코드
text TYPE c LENGTH 20, " 내역
END OF ty_kind.
DATA : gs_kind TYPE ty_kind,
gt_kind TYPE SORTED TABLE OF ty_kind WITH UNIQUE KEY kind.
DATA : BEGIN OF gs_snak,
kind TYPE c LENGTH 4, " 종류
quantity TYPE menge_d, " 수량
meins TYPE meins, " 단위
END OF gs_snak,
gt_snak LIKE TABLE OF gs_snak,
g_meins TYPE meins. " 단위
DATA : components TYPE TABLE OF rstrucinfo, " Component lists
method_name TYPE string, " Method name
g_leng TYPE i, " Length
g_decs TYPE i. " Decimal points
DATA: struct_type TYPE REF TO cl_abap_structdescr, " Structure handler
table_type TYPE REF TO cl_abap_tabledescr, " table handler
comp_tab TYPE cl_abap_structdescr=>component_table, " Component table
comp LIKE LINE OF comp_tab, " Component line
table TYPE REF TO data, " Reference data
line TYPE REF TO data. " Reference data
DATA ls_comp TYPE rstrucinfo. "Temporary : components
FIELD-SYMBOLS : <fs_comp> TYPE rstrucinfo, " Components list
<fs_field> TYPE ANY, " Temporary : field
<fs_line> TYPE ANY, " Temporary : structure
<fs_table> TYPE table. " Temporary : Table
* Macro : append itab
DEFINE app.
clear gs_snak.
gs_snak-kind = &1.
gs_snak-quantity = &2.
gs_snak-meins = 'EA'.
append gs_snak to gt_snak.
END-OF-DEFINITION.
DEFINE app_code.
gs_kind = &1.
insert gs_kind into table gt_kind.
END-OF-DEFINITION.
* MAKE CODE
app_code : 'AAAA삼양라면',
'BBBB짜파게티',
'CCCC너구리',
'DDDD간짜장',
'EEEE비빔면'.
* Make data => AAAA 12
* BBBB 25
* CCCC 31
* EEEE 15
app : 'AAAA' 12,
'BBBB' 25,
'CCCC' 31,
'EEEE' 15.
* 위 데이터를 => AAAA BBBB CCCC EEEE
* 12 25 31 15
* 로 구조를 생성하여 이동함.
* GS_SNAK 에 대한 component lists
PERFORM get_component USING 'GS_SNAK'
CHANGING components.
* 필드이름은 kind로 필드속성을 quantity로 설정
CLEAR : comp, comp_tab.
LOOP AT gt_snak INTO gs_snak.
" 단위
READ TABLE comp_tab TRANSPORTING NO FIELDS
WITH KEY name = 'MEINS'.
IF sy-subrc IS NOT INITIAL.
READ TABLE components ASSIGNING <fs_comp>
WITH KEY compname = 'MEINS'.
IF sy-subrc IS INITIAL.
" component set
PERFORM set_comp USING <fs_comp>
CHANGING comp_tab.
ENDIF.
ENDIF.
" 수량
READ TABLE components ASSIGNING <fs_comp>
WITH KEY compname = 'QUANTITY'.
IF sy-subrc IS INITIAL.
" 필드이름은 KIND로 함
ls_comp = <fs_comp>.
ls_comp-compname = gs_snak-kind.
" component set
PERFORM set_comp USING ls_comp
CHANGING comp_tab.
ENDIF.
ENDLOOP.
* 위에 추가된 필드로 구조생성
struct_type = cl_abap_structdescr=>create( comp_tab ).
*table_type = cl_abap_tabledescr=>create( comp_tab ).
* Data object 생성
CREATE DATA line TYPE HANDLE struct_type.
* Assign
ASSIGN : line->* TO <fs_line>.
* 생성된 테이블에 데이터 Assign
LOOP AT gt_snak INTO gs_snak.
" 원본출력
AT FIRST.
WRITE :/(10) '종류',
(10) '수량',
(10) '단위'.
ENDAT.
READ TABLE gt_kind INTO gs_kind WITH KEY kind = gs_snak-kind.
WRITE : /(10) gs_kind-text CENTERED,
(10) gs_snak-quantity CENTERED,
(10) gs_snak-meins CENTERED.
ENDLOOP.
SKIP 2.
WRITE : /(10) '종류'.
LOOP AT gt_snak INTO gs_snak.
" 단위
ASSIGN COMPONENT 'MEINS'
OF STRUCTURE <fs_line>
TO <fs_field>.
IF sy-subrc IS INITIAL.
<fs_field> = gs_snak-meins.
ENDIF.
" 수량
ASSIGN COMPONENT gs_snak-kind
OF STRUCTURE <fs_line>
TO <fs_field>.
CHECK sy-subrc IS INITIAL.
READ TABLE gt_kind INTO gs_kind WITH KEY kind = gs_snak-kind.
WRITE (10) gs_kind-text CENTERED. " Head write
<fs_field> = gs_snak-quantity.
ENDLOOP.
* Body write
WRITE : /(10) '수량'.
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE <fs_line>
TO <fs_field>.
IF sy-subrc IS NOT INITIAL. EXIT. ENDIF.
CASE sy-index.
WHEN 1. " 단위
g_meins = <fs_field>.
WHEN OTHERS.
WRITE (10) <fs_field> UNIT g_meins CENTERED.
ENDCASE.
ENDDO.
*&-------------------------------------------------------------*
*& Form GET_COMPONENT
*&-------------------------------------------------------------*
FORM get_component USING tabname TYPE any
CHANGING ct_comp TYPE table.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-repid
fieldname = tabname
TABLES
components = ct_comp.
ENDFORM. " GET_COMPONENT
*&---------------------------------------------------------------------*
*& Form SET_COMP
*&---------------------------------------------------------------------*
FORM set_comp USING us_comp TYPE rstrucinfo
CHANGING ct_comp TYPE cl_abap_structdescr=>component_table.
DATA ls_comp LIKE LINE OF comp_tab.
ls_comp-name = us_comp-compname. " Component name
CONCATENATE 'GET_' us_comp-type INTO method_name. " Method name
g_leng = us_comp-olen.
g_decs = us_comp-decs .
" Define type
CASE <fs_comp>-type.
WHEN 'C' OR 'N' OR 'X'. " => 메쏘드 : GET_C, GET_N, GET_X
" C, N, X 는 문자열 길이를 지정함
CALL METHOD cl_abap_elemdescr=>(method_name)
EXPORTING
p_length = g_leng
RECEIVING
p_result = ls_comp-type.
WHEN 'P'. " => 메쏘드 : GET_P
" P 는 길이와 소수점을 지정함( 길이는 1 ~ 16, 소수점은 1 ~ 14 )
CALL METHOD cl_abap_elemdescr=>(method_name)
EXPORTING
p_length = 16 " Max length 가 16 임
p_decimals = g_decs
RECEIVING
p_result = ls_comp-type.
WHEN OTHERS. " => 메쏘드 : GET_I, GET_F, GET_D, GET_T
" 기타 유형은 default 임( i, f, etc...)
CALL METHOD cl_abap_elemdescr=>(method_name)
RECEIVING
p_result = ls_comp-type.
ENDCASE.
APPEND ls_comp TO ct_comp.
ENDFORM. " SET_COMP
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
371 | report zsalv_021 . | sapjoy | 2010.08.20 | 2293 |
370 | report zsalv_020 . | sapjoy | 2010.08.20 | 2381 |
369 | report zsalv_019 . | sapjoy | 2010.08.20 | 2272 |
368 | report zsalv_018 . | sapjoy | 2010.08.20 | 2327 |
367 | report zsalv_017 . | sapjoy | 2010.08.20 | 2270 |
366 | report zsalv_015 | sapjoy | 2010.08.20 | 2280 |
365 | report zsalv_014 | sapjoy | 2010.08.20 | 2299 |
364 | report zsalv_013 | sapjoy | 2010.08.20 | 2361 |
363 | report zsalv_012 | sapjoy | 2010.08.20 | 2271 |
362 | report zsalv_011 | sapjoy | 2010.08.20 | 2331 |
361 | report zsalv_010 | sapjoy | 2010.08.20 | 2294 |
360 | report zsalv_004 | sapjoy | 2010.08.20 | 3078 |
359 | report zsalv_003 | sapjoy | 2010.08.20 | 2336 |
358 | report zsalv_002 [1] | sapjoy | 2010.08.20 | 2476 |
357 | report zsalv_001 | sapjoy | 2010.08.20 | 2442 |
356 | zsalv_edit [1] | sapjoy | 2010.08.20 | 3235 |
355 | REPORT ZRTTS_02 | sapjoy | 2009.12.24 | 2586 |
» | REPORT ZRTTS_01 . | sapjoy | 2009.12.24 | 2670 |
353 | Z16_005TOP | sapjoy | 2009.09.22 | 2549 |
352 | Z16_005 | sapjoy | 2009.09.22 | 2579 |