ABAP中如何把某一列的数据全部排列到一行上
1个回答
展开全部
用动态内表做行列转换 这是我以前写过个一个demo
REPORT ZTCZ001.
type-pools: slis.
data: BEGIN OF itab OCCURS 0,
date like sy-datum,
col1 type i,
col2 type i,
end of itab.
data: col_name(6) type c.
FIELD-SYMBOLS: <fs_any>.
data: l_index type string.
FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,
<DYN_WA>,
<DYN_FIELD>.
DATA: DY_TABLE TYPE REF TO DATA,
DY_LINE TYPE REF TO DATA,
IT_STRUCTURE TYPE LVC_T_FCAT,
WA_STRUCTURE TYPE LVC_S_FCAT.
do 10 times.
itab-date = sy-datum + sy-index.
itab-col1 = sy-index.
itab-col2 = sy-index * 2.
APPEND itab.
enddo.
do 10 times.
l_index = sy-index.
CLEAR: WA_STRUCTURE.
CONCATENATE 'COL' l_index INTO WA_STRUCTURE-FIELDNAME.
CONDENSE WA_STRUCTURE-FIELDNAME.
WA_STRUCTURE-COL_POS = SY-INDEX.
WA_STRUCTURE-INTTYPE = 'C'.
WA_STRUCTURE-INTLEN = '10'.
APPEND WA_STRUCTURE TO IT_STRUCTURE.
enddo.
CALL METHOD CL_ALV_TABLE_CREATE=>create_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATaLOG = IT_STRUCTURE
IMPORTING
EP_TABLE = DY_TABLE.
ASSIGN DY_TABLE->* TO <DYN_TABLE>.
CREATE DATA DY_LINE LIKE LINE OF <DYN_TABLE>.
ASSIGN DY_LINE->* TO <DYN_WA>.
do 2 times.
l_index = sy-index.
CLEAR: col_name.
CONCATENATE 'COL' l_index INTO col_name.
LOOP AT IT_STRUCTURE INTO WA_STRUCTURE.
ASSIGN COMPONENT WA_STRUCTURE-FIELDNAME OF STRUCTURE <DYN_WA> TO <dyn_field>.
read table itab index WA_STRUCTURE-COL_POS.
ASSIGN COMPONENT col_name OF STRUCTURE ITAB TO <fs_any>.
if sy-subrc = 0.
<DYN_FIELD> = <fs_any>.
endif.
ENDLOOP.
APPEND <dyn_wa> TO <dyn_table>.
enddo.
DESCRIBE table <DYN_TABLE> lines l_index.
WRITE:/ l_index.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询