REPORT YZTEST_DYN_ITAB2.
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(30) TYPE C DEFAULT 'T002'.
SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
PERFORM GET_STRUCTURE.
PERFORM CREATE_DYNAMIC_ITAB.
**********creates a dyanamic internal table**********
PERFORM GET_DATA.
PERFORM WRITE_OUT.
*&---------------------------------------------------------------------*
*& Form get_structure
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_STRUCTURE.
*//////////////////////////////////////////////////
* 아래부분에서 값을 배수로 가져옴
*/////////////////////////////////////////////////
DATA : IDETAILS TYPE ABAP_COMPDESCR_TAB,
XDETAILS TYPE ABAP_COMPDESCR.
DATA : REF_TABLE_DES TYPE REF TO CL_ABAP_STRUCTDESCR.
DATA : SPTXT(20) TYPE C.
* 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. "get_structure
*&---------------------------------------------------------------------*
*& Form create_dynamic_itab
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
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. "create_dynamic_itab
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_DATA.
* select data from table.
SELECT * INTO TABLE <DYN_TABLE>
FROM (P_TABLE) UP TO 100 ROWS.
ENDFORM. "get_data
*&---------------------------------------------------------------------*
*& Form write_out
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM WRITE_OUT .
* WRITE out data from table.
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. " write_out
전체 소스입니다. 문제가 되는 부분은 GET_STRUCTURE form 부분인데요.
값이 이상하게 나와서 디버깅 해본결과 값을 두배로 튀겨 나옵니다.
테이블의 길이는 1인데 가져오는것은 2 로 가져 옵니다. 왜 이러는 건가요?
또, 어떤 방법으로 해결할수 있는지요.
고수님들의 의견 부탁드립니다.
오래 되어 이미 아시겠지만,
Unicode 문제로 보입니다.
제가 테스트 해보니 error 메시지도 그렇고요.
길이를 1/2 하니 되더군요.
old: XFC-INTLEN = XDETAILS-LENGTH.
new: if uni-code시스템이면,
XFC-INTLEN = XDETAILS-LENGTH/ 2.
endif.