*&---------------------------------------------------------------------*
*& Report Z_TEST_COL_TO_ROW_02
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_TEST_COL_TO_ROW_02.
TABLES: VTTP,LIPS,LIKP,KNA1 ,VTTK.
DATA: gs_fcat TYPE lvc_s_fcat,
gt_fcat TYPE lvc_t_fcat,
gs_layo TYPE lvc_s_layo,
gs_grid TYPE lvc_s_glay.
DATA: gt_event TYPE slis_t_event WITH HEADER LINE,
gt_event_exit TYPE slis_t_event_exit WITH HEADER LINE.
DATA: ref_grid TYPE REF TO cl_gui_alv_grid .
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 ,"单位
01 TYPE i ,
02 TYPE i ,
03 TYPE i ,
04 TYPE i ,
05 TYPE i ,
06 TYPE i ,
07 TYPE i ,
08 TYPE i ,
09 TYPE i ,
10 TYPE i ,
11 TYPE i ,
12 TYPE i ,
13 TYPE i ,
14 TYPE i ,
15 TYPE i ,
16 TYPE i ,
17 TYPE i ,
18 TYPE i ,
19 TYPE i ,
20 TYPE i ,
21 TYPE i ,
22 TYPE i ,
23 TYPE i ,
24 TYPE i ,
25 TYPE i ,
26 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>
.
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.
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 USING p_field p_text p_key p_edit p_no_out .
gs_fcat
-fieldname = p_field.
gs_fcat
-reptext = p_text.
gs_fcat
-key = p_key.
gs_fcat
-edit = p_edit.
gs_fcat
-no_out = p_no_out.
IF p_field = 'LINE_SUM'.
gs_fcat
-emphasize = 'C700'.
ENDIF.
APPEND gs_fcat TO gt_fcat .
CLEAR gs_fcat .
ENDFORM. "frm_catlg_set
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 '' 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' '毛重' '' '' '' .
gs_layo
-zebra = 'X'.
ENDFORM. "fieldcat_init
FORM outdata.
PERFORM fieldcat_init .
PERFORM show_alv TABLES gt_fcat itab_out[]
USING gs_layo.
ENDFORM. " outdata
FORM show_alv TABLES pt_fcat
pt_tab
USING ps_layout.
gs_grid
-edt_cll_cb = 'X'."当屏幕失去焦点时,自动刷新
gt_event
-name = 'CALLER_EXIT'. "slis_ev_caller_exit_at_start事件
gt_event
-FORM = 'FM_BUTTON'.
APPEND gt_event .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program
= sy-repid
i_callback_user_command
= 'USER_COMMAND'
i_grid_settings
= gs_grid
i_callback_pf_status_set
= 'SET_PF_STATUS'
is_layout_lvc
= gs_layo
it_fieldcat_lvc
= pt_fcat[]
it_events
= gt_event[]
i_save
= 'X'
* it_event_exit = gt_event_exit[]
TABLES
t_outtab
= pt_tab
EXCEPTIONS
PROGRAM_ERROR
= 1
OTHERS = 2
.
ENDFORM. "csalv_set_fcat
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield
TYPE slis_selfield.
CASE r_ucomm.
WHEN '&DATA_SAVE'.
WHEN '&PRINT' OR '&PRT'.
"PERFORM PRINT.
WHEN OTHERS.
LEAVE TO SCREEN 0.
ENDCASE.
ENDFORM. "user_command
*&---------------------------------------------------------------------*
*& Form SET_PF_STATUS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM set_pf_status USING rt_extab TYPE slis_t_extab..
SET PF-STATUS 'STANDARD'.
ENDFORM. "SET_PF_STATUS
*&---------------------------------------------------------------------*
*& Form fm_button
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->E_GRID text
*----------------------------------------------------------------------*
FORM fm_button USING e_grid TYPE slis_data_caller_exit.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
* EXPORTING
* IR_SALV_FULLSCREEN_ADAPTER =
IMPORTING
* ET_EXCLUDING =
* E_REPID =
* E_CALLBACK_PROGRAM =
* E_CALLBACK_ROUTINE =
e_grid
= ref_grid
* ET_FIELDCAT_LVC =
* ER_TRACE =
* E_FLG_NO_HTML =
* ES_LAYOUT_KKBLO =
* ES_SEL_HIDE =
* ET_EVENT_EXIT =
* ER_FORM_TOL =
* ER_FORM_EOL =
.
* CALL METHOD ref_grid->check_changed_data.
* 设置enter事件
CALL METHOD ref_grid->register_edit_event
EXPORTING
i_event_id
= cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
error
= 1
OTHERS = 2.
"CREATE OBJECT gt_event_receiver.
"SET HANDLER gt_event_receiver->handle_modify FOR ref_grid.
ENDFORM. "FM_BUTTON