=====================================================
Looking for a way to create a dynamic internal table? In release WAS 620, you can, by using :
CREATE DATA new_line TYPE table of (p_tab).
This syntax was not allowed in earlier releases. The FM Y_CREATE_DYNAMIC_TABLE can help you to achieve this goal.
Code
FUNCTION y_create_dynamic_table.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(I_STRUCT_NAME) TYPE DD02L-TABNAME
*" REFERENCE(I_ALV_CLEAR_KEY) TYPE FLAG OPTIONAL
*" EXPORTING
*" REFERENCE(E_TOTAL_LENGTH) TYPE I
*" TABLES
*" CTBL_ALV_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV OPTIONAL
*" CTBL_DYN_CATALOG STRUCTURE LVC_S_FCAT OPTIONAL
*" CHANGING
*" REFERENCE(DYN_WA) TYPE REF TO DATA
*" REFERENCE(DYN_TABLE) TYPE REF TO DATA
*"----------------------------------------------------------------------
FIELD-SYMBOLS : <tbl_output> TYPE STANDARD TABLE,
<wa_output> TYPE ANY.
DATA: new_line TYPE REF TO data, " dereference <fs>
new_table TYPE REF TO data.
* Dynamic field description of a structure
DATA: ref_descr TYPE REF TO cl_abap_structdescr,
wa_comp TYPE abap_compdescr.
* cl_alv_table_create=>create_dynamic_table METHOD
DATA: it_fieldcat TYPE lvc_t_fcat,
is_fieldcat LIKE LINE OF it_fieldcat.
* REUSE_ALV FM
DATA: ct_fieldcat TYPE slis_t_fieldcat_alv,
wa_fc LIKE LINE OF ct_fieldcat.
** create working area according to selection
CREATE DATA new_line TYPE (i_struct_name).
ASSIGN new_line->* TO <wa_output>.
* create table-> fill catalog
ref_descr ?= cl_abap_typedescr=>describe_by_data( <wa_output> ).
LOOP AT ref_descr->components INTO wa_comp.
MOVE:
wa_comp-name TO is_fieldcat-fieldname,
wa_comp-name TO is_fieldcat-ref_field,
i_struct_name TO is_fieldcat-ref_table.
APPEND is_fieldcat TO it_fieldcat.
ADD wa_comp-length TO e_total_length.
* Catalog for REUSE_ALV_GRID_DISPLAY
MOVE-CORRESPONDING is_fieldcat TO wa_fc.
wa_fc-fieldname = is_fieldcat-fieldname.
wa_fc-fieldname = is_fieldcat-ref_field.
wa_fc-ref_tabname = is_fieldcat-ref_table.
* If the key is cleared, the order of columns are not changed
IF NOT i_alv_clear_key IS INITIAL.
CLEAR wa_fc-key.
ENDIF.
APPEND wa_fc TO ct_fieldcat.
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = new_table.
ASSIGN new_table->* TO <tbl_output>.
* Return
ctbl_alv_fieldcat[] = ct_fieldcat[]. " ALV use
ctbl_dyn_catalog[] = it_fieldcat[]. " create_dynamic_table reuse
* dyn_table[] = <tbl_output>. " generates a dump, <fs> not assigned
* dyn_wa = <wa_output>. " when calling the FM
dyn_table = new_table.
dyn_wa = new_line.
ENDFUNCTION.
In the calling program:
*------------
* F I E L D ? S Y M B O L S
*------------
FIELD-SYMBOLS : <tbl> TYPE STANDARD TABLE,
<wa> TYPE ANY.
*--------------
* D A T A
*--------------
DATA: new_line TYPE REF TO data, " dereference <fs>
new_table TYPE REF TO data.
CALL FUNCTION 'Y_CREATE_DYNAMIC_TABLE'
EXPORTING
i_struct_name = p_tab
i_alv_clear_key = 'X'
TABLES
ctbl_alv_fieldcat = ct_fieldcat
CHANGING
dyn_wa = new_line
dyn_table = new_table.
* Dereference to field symbol
ASSIGN new_table->* TO <tb>.
ASSIGN new_line->* TO <wa>.
댓글 8
-
낙천
2009.04.24 16:36
감사합니다^^ -
[퐈]박
2009.04.28 14:59
좋은 정보 감사합니다.
-
보나
2009.04.29 17:51
dynamic internal table 에 대한 내용이네요 ^^
좋은 자료 감사합니다.
출간될 plus ABAP 에서도 이부분을 한 챕터로 상세히 다루고 있습니다.
-
부자사랑
2009.05.17 18:36
감솨합니다~ -
사랑과평화
2009.06.10 16:30
감사 ^**^ -
윤
2009.06.15 18:24
좋은 소스 완전 감사!! ^^ -
베짱이
2009.07.10 09:34
와우~감사!! -
yang
2010.08.22 20:46
필요했던 정보 감사합니다.
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
984 |
SMOD와 CMOD - 2
[10] ![]() | 정군 | 2009.06.08 | 3772 |
983 |
SMOD와 CMOD - 1
[13] ![]() | 정군 | 2009.06.08 | 13779 |
982 | General SAP Tips [12] | D.Y.Kim | 2009.05.29 | 36120 |
981 | SAP SCRIPT를 PDF로 다이렉트로 저장시키는 로직. [8] | 쿵푸ㅋ | 2009.05.25 | 4163 |
980 |
bdc레코딩및예제
[31] ![]() | BC고 | 2009.05.14 | 5686 |
979 |
SAP_Organizational_structure
[11] ![]() | BC고 | 2009.05.14 | 3181 |
978 |
ABAP 족보
[15] ![]() | 나무 | 2009.05.08 | 3737 |
977 |
ABAP 교육자료
[21] ![]() | 나무 | 2009.05.08 | 5072 |
976 |
Customizing Guide
[3] ![]() | 나무 | 2009.05.08 | 3579 |
975 |
abap 소스
[5] ![]() | 나무 | 2009.05.08 | 3331 |
974 |
1부 효율적인 코딩기법
[7] ![]() | 나무 | 2009.05.08 | 3320 |
973 |
sap 영한 단어집
[19] ![]() | 서키트 | 2009.04.30 | 3226 |
972 |
sap_flex 영문자료
[4] ![]() | 서키트 | 2009.04.30 | 3579 |
971 | 2 byte 글자 자르기 관련 [1] | 정군 | 2009.04.30 | 6348 |
970 |
FV60 BADI screen
[12] ![]() | 정군 | 2009.04.30 | 3593 |
969 |
abap 교육자료입니다.(3)
[10] ![]() | graceKim | 2009.04.29 | 3487 |
968 |
abap 교육자료입니다.(2)
[8] ![]() | graceKim | 2009.04.29 | 3938 |
967 |
abap 교육자료입니다.(1)
[18] ![]() | graceKim | 2009.04.29 | 3334 |
» | 가변 itab 관련 [8] | 정군 | 2009.04.23 | 62390 |
965 |
abap bc dictionary
[10] ![]() | 우째 .. | 2009.04.15 | 3579 |