TABLES: mseg,mkpf.
DATA: sla TYPE slis_layout_alv ,
ivariant LIKE disvariant,
i_repid LIKE sy-repid ,
i_excluding TYPE slis_t_extab.
werks LIKE mseg-werks ,
matnr LIKE mseg-matnr ,
lgort LIKE mseg-lgort ,
bwart LIKE mseg-bwart ,
menge LIKE mseg-menge ,
END OF ty_sum.
DATA : itab TYPE STANDARD TABLE OF ty_sum WITH HEADER LINE .
DATA : hs_sum TYPE HASHED TABLE OF ty_sum
WITH UNIQUE KEY werks matnr lgort bwart WITH HEADER LINE .
DATA : itab_sum TYPE STANDARD TABLE OF ty_sum WITH HEADER LINE .
werks LIKE mseg-werks ,
matnr LIKE mseg-matnr ,
lgort LIKE mseg-lgort ,
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 ,
END OF itab_out.
bwart LIKE mseg-bwart ,
END OF ty_bwart.
DATA : hs_bwart TYPE HASHED TABLE OF ty_bwart
WITH UNIQUE KEY bwart WITH HEADER LINE .
DATA : itab_bwart TYPE STANDARD TABLE OF ty_bwart WITH HEADER LINE .
<f_fs2>.
DATA: max_count TYPE i .
s_budat FOR mkpf-budat .
PARAMETERS: p_sum AS CHECKBOX .
PERFORM getdata.
PERFORM fixdata.
IF p_sum = ‘X’.
PERFORM outdata.
ELSE.
PERFORM outdata2.
ENDIF.
*& Form GETDATA
*&———————————————————————*
FORM getdata.
SELECT werks matnr lgort bwart menge INTO TABLE itab
FROM mkpf INNER JOIN mseg ON mkpf~mblnr = mseg~mblnr AND
mkpf~mjahr = mseg~mjahr
WHERE mkpf~mblnr IN s_mblnr AND
mkpf~budat IN s_budat .
ENDFORM. ” GETDATA
*& Form FIXDATA
*&———————————————————————*
FORM fixdata.
DATA: index LIKE sy-tabix .
hs_sum = itab.
COLLECT hs_sum.
COLLECT hs_bwart.
ENDLOOP.
itab_bwart[] = hs_bwart[].
itab_sum[] = hs_sum[].
itab_out-werks = itab_sum-werks .
itab_out-matnr = itab_sum-matnr .
itab_out-lgort = itab_sum-lgort .
READ TABLE itab_bwart WITH KEY bwart = itab_sum-bwart .
index = sy-tabix + 3.
ASSIGN COMPONENT index OF STRUCTURE itab_out TO <f_fs1>.
<f_fs1> = itab_sum-menge.
itab_out-line_sum = itab_sum-menge.
COLLECT itab_out.
CLEAR itab_out.
ENDLOOP.
ENDFORM. ” FIXDATA
*& Form outdata
*&———————————————————————*
FORM outdata.
PERFORM fieldcat_init .
sla-colwidth_optimize = ‘X’.
sla-zebra = ‘X’.
i_repid = sy-repid.
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_sum
EXCEPTIONS
program_error = 1
OTHERS = 2.
*———————————————————————*
* FORM fieldcat_init *
*———————————————————————*
FORM fieldcat_init .
PERFORM frm_catlg_set USING: ‘WERKS’ ‘WERKS’ ‘X’ ,
‘MATNR’ ‘MATNR’ ‘X’ ,
‘LGORT’ ‘LGORT’ ‘X’ ,
‘BWART’ ‘BWART’ ‘X’ ,
‘MENGE’ ‘MENGE’ ” .
ENDFORM. “fieldcat_init
* FORM frm_catlg_set *
*———————————————————————*
FORM frm_catlg_set USING p_field
p_text
p_key.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
ls_fieldcat-seltext_l = p_text.
ls_fieldcat-key = p_key.
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.
READ TABLE itab INDEX rs_selfield-tabindex.
CASE r_ucomm.
WHEN ‘&IC1’. “双击
LEAVE PROGRAM.
ENDCASE.
rs_selfield-refresh = ‘X’. “自动刷新
ENDFORM. “user_com
* FORM outdata2 *
*———————————————————————*
FORM outdata2.
PERFORM fieldcat_init2 .
sla-zebra = ‘X’.
i_repid = sy-repid.
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 *
*———————————————————————*
FORM fieldcat_init2 .
DATA: c(2) TYPE n ,
txt(20) TYPE c .
‘MATNR’ ‘MATNR’ ‘X’ ,
‘LGORT’ ‘LGORT’ ‘X’ .
LOOP AT hs_bwart .
c = c + 1.
CONCATENATE ‘MENGE’ c INTO txt.
PERFORM frm_catlg_set USING: txt hs_bwart-bwart ” .
ENDLOOP.
PERFORM frm_catlg_set USING: ‘LINE_SUM’ ‘SUM’ ” .
ENDFORM. “fieldcat_init
TABLES: mseg,mkpf.
DATA: sla TYPE slis_layout_alv ,
ivariant LIKE disvariant,
i_repid LIKE sy-repid ,
i_excluding TYPE slis_t_extab.
werks LIKE mseg-werks ,
matnr LIKE mseg-matnr ,
lgort LIKE mseg-lgort ,
bwart LIKE mseg-bwart ,
menge LIKE mseg-menge ,
END OF ty_sum.
DATA : itab TYPE STANDARD TABLE OF ty_sum WITH HEADER LINE .
DATA : hs_sum TYPE HASHED TABLE OF ty_sum
WITH UNIQUE KEY werks matnr lgort bwart WITH HEADER LINE .
DATA : itab_sum TYPE STANDARD TABLE OF ty_sum WITH HEADER LINE .
bwart LIKE mseg-bwart ,
END OF ty_bwart.
DATA : hs_bwart TYPE HASHED TABLE OF ty_bwart
WITH UNIQUE KEY bwart WITH HEADER LINE .
DATA : itab_bwart TYPE STANDARD TABLE OF ty_bwart WITH HEADER LINE .
<f_out> TYPE STANDARD TABLE ,
<f_out_wa> .
DATA: max_count TYPE i ,
dy_out TYPE REF TO data ,
dy_out_wa TYPE REF TO data,
xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat.
DATA: c(2) TYPE n ,
txt(20) TYPE c .
SELECT-OPTIONS: s_mblnr FOR mseg-mblnr ,
s_budat FOR mkpf-budat .
PARAMETERS: p_sum AS CHECKBOX .
PERFORM getdata.
PERFORM fixdata.
IF p_sum = ‘X’.
PERFORM outdata.
ELSE.
PERFORM outdata2.
ENDIF.
*& Form GETDATA
*&———————————————————————*
FORM getdata.
SELECT werks matnr lgort bwart menge INTO TABLE itab
FROM mkpf INNER JOIN mseg ON mkpf~mblnr = mseg~mblnr AND
mkpf~mjahr = mseg~mjahr
WHERE mkpf~mblnr IN s_mblnr AND
mkpf~budat IN s_budat .
ENDFORM. ” GETDATA
*& Form FIXDATA
*&———————————————————————*
FORM fixdata.
DATA: index LIKE sy-tabix .
hs_sum = itab.
COLLECT hs_sum.
COLLECT hs_bwart.
ENDLOOP.
itab_bwart[] = hs_bwart[].
itab_sum[] = hs_sum[].
ASSIGN COMPONENT ‘WERKS’ OF STRUCTURE <f_out_wa> TO <f_fs1>.
<f_fs1> = itab_sum-werks.
ASSIGN COMPONENT ‘MATNR’ OF STRUCTURE <f_out_wa> TO <f_fs1>.
<f_fs1> = itab_sum-matnr.
ASSIGN COMPONENT ‘LGORT’ OF STRUCTURE <f_out_wa> TO <f_fs1>.
<f_fs1> = itab_sum-lgort.
index = sy-tabix + 3.
ASSIGN COMPONENT index OF STRUCTURE <f_out_wa> TO <f_fs1>.
<f_fs1> = itab_sum-menge.
<f_fs1> = itab_sum-menge.
CLEAR <f_out_wa>.
ENDLOOP.
ENDFORM. ” FIXDATA
*& Form outdata
*&———————————————————————*
FORM outdata.
PERFORM fieldcat_init .
sla-colwidth_optimize = ‘X’.
sla-zebra = ‘X’.
i_repid = sy-repid.
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_sum
EXCEPTIONS
program_error = 1
OTHERS = 2.
*———————————————————————*
* FORM fieldcat_init *
*———————————————————————*
FORM fieldcat_init .
PERFORM frm_catlg_set USING: ‘WERKS’ ‘WERKS’ ‘X’ ,
‘MATNR’ ‘MATNR’ ‘X’ ,
‘LGORT’ ‘LGORT’ ‘X’ ,
‘BWART’ ‘BWART’ ” ,
‘MENGE’ ‘MENGE’ ” .
ENDFORM. “fieldcat_init
* FORM frm_catlg_set *
*———————————————————————*
FORM frm_catlg_set USING p_field
p_text
p_key.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
ls_fieldcat-seltext_l = p_text.
ls_fieldcat-key = p_key.
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.
* READ TABLE 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 outdata2.
PERFORM fieldcat_init2 .
sla-zebra = ‘X’.
i_repid = sy-repid.
EXPORTING
i_callback_program = i_repid
it_fieldcat = gd_fieldcat[]
i_save = ‘A’
is_variant = ivariant
is_layout = sla
it_excluding = i_excluding
TABLES
t_outtab = <f_out>
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. ” outdata
* FORM fieldcat_init2 *
*———————————————————————*
FORM fieldcat_init2 .
CLEAR c .
PERFORM frm_catlg_set USING: ‘WERKS’ ‘WERKS’ ‘X’ ,
‘MATNR’ ‘MATNR’ ‘X’ ,
‘LGORT’ ‘LGORT’ ‘X’ .
LOOP AT hs_bwart .
c = c + 1.
CONCATENATE ‘MENGE’ c INTO txt.
PERFORM frm_catlg_set USING: txt hs_bwart-bwart ” .
ENDLOOP.
PERFORM frm_catlg_set USING: ‘LINE_SUM’ ‘SUM’ ” .
ENDFORM. “fieldcat_init
* FORM creat_itab_out *
*———————————————————————*
FORM creat_itab_out.
PERFORM build_itab_stru USING: ‘WERKS’ ‘MSEG’ ‘WERKS’ ,
‘MATNR’ ‘MSEG’ ‘MATNR’ ,
‘LGORT’ ‘MSEG’ ‘LGORT’ .
c = c + 1.
CONCATENATE ‘MENGE’ c INTO txt.
PERFORM build_itab_stru USING: txt ‘MSEG’ ‘MENGE’ .
ENDLOOP.
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_out.
ASSIGN dy_out->* TO <f_out>.
CREATE DATA dy_out_wa LIKE LINE OF <f_out>.
ASSIGN dy_out_wa->* TO <f_out_wa>.
ENDFORM.
* FORM build_itab_stru *
*———————————————————————*
FORM build_itab_stru USING fdname ref_t ref_f.
xfc-fieldname = fdname .
xfc-ref_table = ref_t.
xfc-ref_field = ref_f.
APPEND xfc TO ifc.
ENDFORM.
转载于:https://www.cnblogs.com/johnson_yao/archive/2011/09/09/2172238.html
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/110556.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...