REPORT Z_TEST_COL_TO_ROW.
TYPE-POOLS: slis.
TABLES: VTTP,LIPS,LIKP,KNA1 ,VTTK.
DATA: gd_fieldcat TYPE slis_t_fieldcat_alv.
DATA: sla TYPE slis_layout_alv ,
ivariant LIKE disvariant,
i_repid LIKE sy-repid ,
i_excluding TYPE slis_t_extab.
TYPES: BEGIN OF TY_ALL,
TKNUM LIKE VTTK-TKNUM,"运单号
VBELN LIKE LIPS-VBELN,"交货单号
TPLST LIKE VTTK-TPLST ,"装运点
NAME1 LIKE KNA1-NAME1 ,"客户
ERDAT LIKE VTTK-ERDAT ,"创建日期
TDLNR LIKE VTTK-TDLNR ,"物流公司
ROUTE LIKE VTTK-ROUTE ,"线路
DISTZ LIKE VTTK-DISTZ ,"里程
ADD01 LIKE VTTK-ADD01 ,"车主
EXTI1 LIKE VTTK-EXTI1 ,"卸货点
ADD02 LIKE VTTK-ADD02 ,"司机
BFART LIKE VTTK-BFART ,"车厢类型
MATNR LIKE LIPS-MATNR,"物料编码
ARKTX LIKE LIPS-ARKTX,"物料描述
BRGEW LIKE LIPS-BRGEW,"货物单项目毛重
LFIMG LIKE LIPS-LFIMG,"单项目数量
VRKME LIKE LIPS-VRKME ,"单位
GEWEI LIKE LIPS-GEWEI,"重量单位
LGORT LIKE LIPS-LGORT,"库存地点
BEIZHU(30) TYPE C,"备注
END OF TY_ALL.
TYPES:BEGIN OF TY_HEADER,
TKNUM LIKE VTTK-TKNUM,"运单号
VBELN LIKE LIPS-VBELN,"交货单号
NAME1 LIKE KNA1-NAME1 ,"客户
TPLST LIKE VTTK-TPLST ,"装运点
ERDAT LIKE VTTK-ERDAT ,"装运日期
TDLNR LIKE VTTK-TDLNR ,"物流公司
ROUTE LIKE VTTK-ROUTE ,"线路
DISTZ LIKE VTTK-DISTZ ,"里程
ADD01 LIKE VTTK-ADD01 ,"车主
EXTI1 LIKE VTTK-EXTI1 ,"卸货点
ADD02 LIKE VTTK-ADD02 ,"司机
BFART LIKE VTTK-BFART ,"车厢类型
TOTAL_BRGEW LIKE LIPS-BRGEW,"一个交货单的总重量
END OF TY_HEADER.
*单据抬头结束
*单据明细开始
TYPES:BEGIN OF TY_ITEMS,
TKNUM LIKE VTTK-TKNUM,"运单号
VBELN LIKE LIPS-VBELN,"交货单号
NAME1 LIKE KNA1-NAME1 ,"客户
MATNR LIKE LIPS-MATNR,"物料编码
ARKTX LIKE LIPS-ARKTX,"物料描述
BRGEW LIKE LIPS-BRGEW,"单项目毛重
GEWEI LIKE LIPS-GEWEI,"重量单位
LFIMG LIKE LIPS-LFIMG,"单项目数量
VRKME LIKE LIPS-VRKME ,"单位
LGORT LIKE LIPS-LGORT,"库存地点
BEIZHU(30) TYPE C,"备注
END OF TY_ITEMS.
*单据明细结束
DATA:WA_ALL TYPE TY_ALL,
GT_ALL TYPE TY_ALL OCCURS 0.
DATA:WA_HEADER TYPE TY_HEADER,
GT_HEADER TYPE TY_HEADER OCCURS 0 .
DATA:WA_ITEMS TYPE TY_ITEMS,
GT_ITEMS TYPE TY_ITEMS OCCURS 0.
DATA: GT_HEADER_SHOW TYPE TY_HEADER OCCURS 0.
DATA: GT_ITEMS_SHOW TYPE TY_ITEMS OCCURS 0.
*定义传入到smartforms的变量开始
DATA:fm_name TYPE rs38l_fnam.
DATA:itemsname(32) TYPE c.
DATA:headername(32) TYPE c.
*定义传入到smartforms的变量结束
*定义存储ALV向smartforms传入数据的内表开始
DATA:GT_HEADER_TEMP TYPE TY_HEADER OCCURS 0.
DATA:GT_ITEMS_TEMP TYPE TY_ITEMS OCCURS 0.
DATA:GT_ALL_TEMP TYPE TY_ALL OCCURS 0.
*定义存储ALV向smartforms传入数据的内表结束
"控制smartforms参数声明开始
DATA :control_parameters TYPE ssfctrlop.
"控制smartforms参数声明结束
TYPES: BEGIN OF ty_sum ,
MATNR LIKE LIPS-MATNR,"物料编码
ARKTX LIKE LIPS-ARKTX,"物料描述
LFIMG LIKE LIPS-LFIMG,"单项目数量
VRKME LIKE LIPS-VRKME ,"单位
NAME1 LIKE KNA1-NAME1 ,"客户
BRGEW LIKE LIPS-BRGEW,"单项目毛重
END OF ty_sum.
DATA : itab TYPE ty_sum OCCURS 0 ."WITH HEADER LINE ."从数据库中取出的数放入的内表
DATA : hs_sum TYPE HASHED TABLE OF ty_sum WITH UNIQUE KEY MATNR ARKTX VRKME NAME1 WITH HEADER LINE .
DATA : itab_sum TYPE STANDARD TABLE OF ty_sum WITH HEADER LINE .
DATA: BEGIN OF itab_out OCCURS 0,"行列转换后的内表
MATNR LIKE LIPS-MATNR,"物料编码
ARKTX LIKE LIPS-ARKTX,"物料描述
VRKME LIKE LIPS-VRKME ,"单位
menge01 TYPE i ,
menge02 TYPE i ,
menge03 TYPE i ,
menge04 TYPE i ,
menge05 TYPE i ,
menge06 TYPE i ,
menge07 TYPE i ,
menge08 TYPE i ,
menge09 TYPE i ,
menge10 TYPE i ,
menge11 TYPE i ,
menge12 TYPE i ,
menge13 TYPE i ,
menge14 TYPE i ,
menge15 TYPE i ,
menge16 TYPE i ,
menge17 TYPE i ,
menge18 TYPE i ,
menge19 TYPE i ,
menge20 TYPE i ,
menge21 TYPE i ,
menge22 TYPE i ,
menge23 TYPE i ,
menge24 TYPE i ,
menge25 TYPE i ,
menge26 TYPE i ,
line_sum TYPE i ,
BRGEW_sum LIKE LIPS-BRGEW,
END OF itab_out.
TYPES: BEGIN OF ty_col ,
NAME1 LIKE KNA1-NAME1 ,"客户
END OF ty_col.
DATA : hs_col TYPE HASHED TABLE OF ty_col WITH UNIQUE KEY NAME1 WITH HEADER LINE .
DATA : itab_col TYPE STANDARD TABLE OF ty_col WITH HEADER LINE .
FIELD-SYMBOLS: <f_fs1> ,
<f_fs2>
.
DATA: max_count TYPE i .
START-OF-SELECTION.
SELECT-OPTIONS: P_ERDAT FOR VTTK-ERDAT ,
P_TKNUM
FOR VTTK-TKNUM ,
P_TDLNR
FOR VTTK-TDLNR ,
P_TPLST
FOR VTTK-TPLST ,
P_ERNAM
FOR VTTK-ERNAM ,
P_ROUTE
FOR VTTK-ROUTE .
START-OF-SELECTION.
PERFORM getdata.
PERFORM fixdata.
PERFORM outdata.
*&---------------------------------------------------------------------*
*& Form GETDATA
*&---------------------------------------------------------------------*
FORM getdata.
SELECT *
FROM VTTK AS VK
INNER
JOIN VTTP AS VP
ON VK~TKNUM = VP~TKNUM
INNER
JOIN LIPS AS L
ON L~VBELN = VP~VBELN
INNER
JOIN LIKP AS LP
ON LP~VBELN = L~VBELN
INNER
JOIN KNA1 AS K
ON K~KUNNR = LP~KUNAG
INTO CORRESPONDING FIELDS OF TABLE GT_ALL
WHERE
VK
~TKNUM IN P_TKNUM AND (
VK
~ERDAT IN P_ERDAT AND
VK
~TDLNR IN P_TDLNR AND
VK
~TPLST IN P_TPLST AND
VK
~ERNAM IN P_ERNAM AND
VK
~ROUTE IN P_ROUTE ) .
SORT GT_ALL ASCENDING BY TKNUM.
MOVE-CORRESPONDING GT_ALL TO GT_HEADER_SHOW.
MOVE-CORRESPONDING GT_ALL TO GT_ITEMS_SHOW.
DELETE ADJACENT DUPLICATES FROM GT_HEADER_SHOW COMPARING TKNUM .
MOVE-CORRESPONDING GT_ALL TO itab.
ENDFORM. " GETDATA
*&---------------------------------------------------------------------*
*& Form FIXDATA
*&---------------------------------------------------------------------*
FORM fixdata.
DATA: index LIKE sy-tabix .
DATA:wa_itab TYPE ty_sum.
LOOP AT itab INTO wa_itab.
hs_sum
= wa_itab.
COLLECT hs_sum.
hs_col
= wa_itab-NAME1 .
COLLECT hs_col.
ENDLOOP.
SORT hs_col.
itab_col[]
= hs_col[].
itab_sum[]
= hs_sum[].
LOOP AT itab_sum.
itab_out
-MATNR = itab_sum-MATNR .
itab_out
-ARKTX = itab_sum-ARKTX .
itab_out
-VRKME = itab_sum-VRKME .
READ TABLE itab_col WITH KEY NAME1 = itab_sum-NAME1 .
index = sy-tabix + 3."3这个数字代表有几列是固定不变的
ASSIGN COMPONENT index OF STRUCTURE itab_out TO <f_fs1>.
<f_fs1>
= itab_sum-LFIMG.
itab_out
-line_sum = itab_sum-LFIMG.
itab_out
-BRGEW_sum = itab_sum-BRGEW.
COLLECT itab_out.
CLEAR itab_out.
ENDLOOP.
ENDFORM. " FIXDATA
*---------------------------------------------------------------------*
* FORM frm_catlg_set *
*---------------------------------------------------------------------*
FORM frm_catlg_set USING p_field p_text p_key.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
ls_fieldcat
-fieldname = p_field.
ls_fieldcat
-seltext_l = p_text.
ls_fieldcat
-key = p_key.
IF p_field = 'LINE_SUM'.
ls_fieldcat
-emphasize = 'C700'.
ENDIF.
APPEND ls_fieldcat TO gd_fieldcat .
CLEAR ls_fieldcat .
ENDFORM. "frm_catlg_set
*&--------------------------------------------------------------------*
*& Form user_command
*&--------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield
TYPE slis_selfield.
DATA:wa_itab TYPE ty_sum.
READ TABLE itab INTO wa_itab INDEX rs_selfield-tabindex.
CASE r_ucomm.
WHEN '&IC1'. "双击
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
rs_selfield
-refresh = 'X'. "自动刷新
ENDFORM. "user_com
*---------------------------------------------------------------------*
* FORM outdata2 *
*---------------------------------------------------------------------*
FORM fieldcat_init .
DATA: c(2) TYPE n ,
txt
(20) TYPE c .
PERFORM frm_catlg_set USING:
'MATNR' '物料编码' 'X' ,
'ARKTX' '物料描述' 'X' ,
'VRKME' '单位' 'X' .
LOOP AT hs_col .
c = c + 1.
CONCATENATE 'MENGE' c INTO txt.
PERFORM frm_catlg_set USING: txt hs_col-NAME1 '' .
ENDLOOP.
PERFORM frm_catlg_set USING: 'LINE_SUM' '数量合计' '' .
PERFORM frm_catlg_set USING: 'BRGEW_sum' '毛重' '' .
ENDFORM. "fieldcat_init
FORM outdata.
PERFORM fieldcat_init .
sla
-colwidth_optimize = 'X'.
sla
-zebra = 'X'.
i_repid
= sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program
= i_repid
it_fieldcat
= gd_fieldcat[]
i_save
= 'A'
is_variant
= ivariant
is_layout
= sla
it_excluding
= i_excluding
i_callback_user_command
= 'USER_COMMAND'
TABLES
t_outtab
= itab_out
EXCEPTIONS
program_error
= 1
OTHERS = 2.
ENDFORM. " outdata
*---------------------------------------------------------------------*
* FORM fieldcat_init2 *
*---------------------------------------------------------------------*