*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form OUTPUT_DATA .
data: FM_NAME type RS38L_FNAM.
data: HEADERNAME(18) type C.
data: ITEMSNAME(18) type C.
data: ITABENAME(18) type C.
data:L_FORMNAME type TDSFNAME.
data:L_VBELN like VBRP-VBELN.
data:NUM(3) type N.
data:L_TEXT(15) type C.
L_FORMNAME = 'ZMM0009'.
" 在句柄中加上服务器当前时间作为句柄名称,防止多人同时使用该程序,导致句柄名称相同
concatenate 'ZSPMMF1002HD' SY-UZEIT into HEADERNAME .
concatenate 'ZSPMMF1002IT' SY-UZEIT into ITEMSNAME.
concatenate 'ZSPMMF1002IE' SY-UZEIT into ITABENAME.
SAVEBUFFER ITABH1[] HEADERNAME. "ig_output_h是保存输出表单表头数据的内表
SAVEBUFFER ITABD[] ITEMSNAME. "ig_output_d是保存输出数据明细的内表,与表头数据有关联字段
SAVEBUFFER ITABE[] ITABENAME. "ig_output_d是保存输出数据明细的内表,与表头数据有关联字段
concatenate SY-DATUM+0(4) '年' SY-DATUM+4(2) '月' SY-DATUM+6(2) '日' into L_TEXT.
call function 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = L_FORMNAME
VARIANT = ' '
DIRECT_CALL = ' '
IMPORTING
FM_NAME = FM_NAME
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
others = 3.
if SY-SUBRC <> 0.
write: / 'ERROR 1'.
endif.
call function FM_NAME
EXPORTING
PTR_HEADER = HEADERNAME
PTR_ITEMS = ITEMSNAME
PTR_ITABE = ITABENAME
L_TEXT = L_TEXT
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
others = 5.
if SY-SUBRC <> 0.
message id SY-MSGID type SY-MSGTY number SY-MSGNO
with SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " OUTPUT_DATA
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form BUILD_FIELDCATALOG .
* Macro definition
define M_FIELDCAT1.
FIELDCATALOG1-FIELDNAME = &1.
FIELDCATALOG1-SELTEXT_M = &2.
FIELDCATALOG1-OUTPUTLEN = &3.
FIELDCATALOG1-EMPHASIZE = &4.
FIELDCATALOG1-KEY = &5.
FIELDCATALOG1-EDIT = &6.
FIELDCATALOG1-CHECKBOX = &7.
FIELDCATALOG1-COL_POS = &8.
FIELDCATALOG1-NO_ZERO = &9.
APPEND FIELDCATALOG1.
end-of-definition.
M_FIELDCAT1 'SEL' '选择' '4' '' 'X' 'X' 'X' '0' ''.
M_FIELDCAT1 'EBELN' '订单编号' '' '' '' '' '' '1' ''.
M_FIELDCAT1 'AEDAT' '订单日期' '' '' '' '' '' '2' ''.
M_FIELDCAT1 'LIFNR' '供应商' '' '' '' '' '' '3' ''.
M_FIELDCAT1 'EKGRP' '采购组' '' '' '' '' '' '4' ''.
M_FIELDCAT1 'MWSKZ' '税率' '' '' '' '' '' '5' ''.
M_FIELDCAT1 'EBELP' '项次' '' '' '' '' '' '6' ''.
M_FIELDCAT1 'MATNR' '物料编码' '' '' 'X' '' '' '7' 'X'.
M_FIELDCAT1 'MAKTX' '物料描述' '' '' '' '' '' '8' ''.
M_FIELDCAT1 'ATWRT2' '图号' '' '' '' '' '' '9' ''.
M_FIELDCAT1 'ATWRT5' '制造商' '' '' '' '' '' '10' ''.
M_FIELDCAT1 'ATWRT6' '备注' '' '' '' '' '' '11' ''.
M_FIELDCAT1 'MEINS' '单位' '' '' '' '' '' '12' ''.
M_FIELDCAT1 'MENGE' '数量' '' '' '' '' '' '13' ''.
M_FIELDCAT1 'NETALL' '含税单价' '' '' '' '' '' '14' ''.
M_FIELDCAT1 'BRTWR' '含税总价' '' '' 'X' '' '' '15' ''.
M_FIELDCAT1 'KBETR' '运费' '' '' 'X' '' '' '16' ''.
M_FIELDCAT1 'KWERT1' '海关费' '' '' 'X' '' '' '17' ''.
M_FIELDCAT1 'EINDT' '计划到货日期' '' '' '' '' '' '18' ''.
M_FIELDCAT1 'TEXT' '说明' '4' '' '' '' '' '19' ''.
M_FIELDCAT1 'ZSABE' '供方联系人' '' '' '' '' '' '20' ''.
M_FIELDCAT1 'TLFXS' '供方传真' '' '' '' '' '' '21' ''.
M_FIELDCAT1 'TLFNS' '供方电话' '' '' '' '' '' '21' ''.
endform. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form BUILD_LAYOUT .
GD_LAYOUT-NO_INPUT = 'X'.
GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GD_LAYOUT-TOTALS_TEXT = 'Totals'(201).
endform. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form DISPLAY_ALV_REPORT.
GD_REPID = SY-REPID.
SORT ITABH0 BY EBELP.
call function 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = GD_REPID
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_HTML_TOP_OF_PAGE = 'ALV_TOP_OF_PAGE'
IS_LAYOUT = GD_LAYOUT
IT_FIELDCAT = FIELDCATALOG1[]
I_SAVE = 'X'
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
TABLES
T_OUTTAB = ITABH0
EXCEPTIONS
PROGRAM_ERROR = 1
others = 2.
if SY-SUBRC <> 0.
message id SY-MSGID type SY-MSGTY number SY-MSGNO
with SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form ALV_TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->CL_DD text
*----------------------------------------------------------------------*
form ALV_TOP_OF_PAGE using CL_DD type ref to CL_DD_DOCUMENT.
*form alv_top_of_page using cl_dd type ref to cl_dd_document.
data: M_P type I.
data: M_BUFF type STRING,
M_BUFF1 type STRING,
M_BUFF2 type STRING.
data:L_ARBPL like CRHD-ARBPL,
L_KTEXT like CRTX-KTEXT.
M_BUFF = '<html>'.
call method CL_DD->HTML_INSERT
EXPORTING
CONTENTS = M_BUFF
CHANGING
POSITION = M_P.
M_BUFF = '<p align="center"><span style="font-family: 黑体"><font size="6">采购订单</font></span><P>'.
M_BUFF1 = '<p align="center"><span style="font-family: 黑体"><font size="4">版本号:2.0</font></span><P>'.
call method CL_DD->HTML_INSERT
EXPORTING
CONTENTS = M_BUFF
CHANGING
POSITION = M_P.
call method CL_DD->HTML_INSERT
EXPORTING
CONTENTS = M_BUFF1
CHANGING
POSITION = M_P.
endform. " form_alvheader
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->I_UCOMM text
* -->IS_SELFIELD text
*----------------------------------------------------------------------*
form USER_COMMAND using I_UCOMM like SY-UCOMM
IS_SELFIELD type SLIS_SELFIELD.
data:NUM(3) type I,
L_TCODE like SY-TCODE,
L_BELNR like BSEG-BELNR,
L_EBELN LIKE EKPO-EBELN,
l_aedat like ekKo-aedat,
L_EBELP LIKE EKPO-EBELP,
l_matnr like ekpo-matnr.
data: LO_GUID type ref to CL_GUI_ALV_GRID. "#EC CALLED
case I_UCOMM.
when '&IC1'. " Pick
read table ITABH index IS_SELFIELD-TABINDEX.
if SY-SUBRC eq 0.
call transaction 'CO03' and skip first screen.
endif.
when 'S_ALL'.
LOOP AT ITABH0.
ITABH0-SEL = 'X'.
MODIFY ITABH0.
ENDLOOP.
perform DISPLAY_ALV_REPORT.
WHEN 'ES_ALL'.
LOOP AT ITABH0.
ITABH0-SEL = ''.
MODIFY ITABH0.
ENDLOOP.
perform DISPLAY_ALV_REPORT.
when 'PRINT'.
call function 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = LO_GUID.
call method LO_GUID->CHECK_CHANGED_DATA.
loop at ITABH0 where SEL = 'X'.
itabh1-werks = itabH0-werks.
itabh1-ebeln = itabH0-ebeln.
itabh1-eknam = itabH0-eknam.
itabh1-aedat = itabH0-aedat.
itabh1-mwskz1 = itabH0-mwskz1.
itabh1-tel_number = itabH0-tel_number.
itabh1-telfx = itabH0-telfx.
itabh1-lifnr = itabH0-lifnr.
itabh1-name_text = itabh0-name_text.
itabh1-username = itabh0-username.
itabh1-textA = itabh0-textA.
itabh1-zsabe = itabh0-zsabe.
itabh1-tlfxs = itabh0-tlfxs.
itabh1-tlfns = itabh0-tlfns.
* ITABH1-BRTWR = ITABH0-BRTWR.
itabh1-EKGRP = itabh0-EKGRP.
itabh1-kbetr2 = itabh0-kbetr2.
itabh1-kbetr3 = itabh0-kbetr3.
* itabh1-KWERT2 = itabh0-KWERT2.
collect itabh1.
if SY-SUBRC <> 0.
*没有任何选择
message '请选择您所需要的记录!' type 'E'.
endif.
clear ITABH0-SEL.
modify ITABH0.
endloop.
loop at itabh1.
loop at itabh0
where
EBELN = ITABH1-EBELN.
* AND aedat = itabh1-aedat and lifnr = itabh1-lifnr.
call function 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
INPUT = ITABH0-MEINS
LANGUAGE = SY-LANGU
IMPORTING
OUTPUT = ITABH0-MEINS.
itabd-EBELP = itabH0-ebelp.
itabd-matnr = itabH0-matnr.
itabd-MAKTX = itabH0-maktx.
itabd-ATWRT1 = itabH0-ATWRT1.
itabd-ATWRT2 = itabH0-ATWRT2.
itabd-ATWRT3 = itabH0-ATWRT3.
itabd-ATWRT4 = itabH0-ATWRT4.
itabd-ATWRT5 = itabH0-ATWRT5.
itabd-ATWRT6 = itabH0-ATWRT6.
itabd-MEINS = itabH0-meins.
itabd-MENGE = itabH0-menge.
itabd-netall = itabh0-netall.
itabd-brtwr = itabh0-brtwr.
ITABD-EINDT = ITABH0-EINDT.
ITABD-BRTWR = ITABH0-BRTWR.
itabd-ebeln = itabh0-ebeln.
ITABD-KZWI1 = ITABH0-KZWI1.
COLLECT ITABD.
ENDLOOP.
ENDLOOP.
delete ADJACENT DUPLICATES FROM itabd.
sort itabd by ebeln.
loop at ITABD.
if L_ebeln is initial.
L_ebeln = ITABD-ebeln.
NUM = NUM + 1.
elseif L_ebeln <> ITABD-ebeln.
clear NUM.
NUM = NUM + 1.
L_ebeln = ITABD-ebeln.
elseif L_ebeln = ITABD-ebeln.
NUM = NUM + 1.
L_ebeln = ITABD-ebeln.
endif.
itabd-index = num.
modify ITABD.
endloop.
DELETE ITABE WHERE KBETR1 = 0 AND KBETR = 0.
DELETE ITABE WHERE KBETR1 = 0 AND KBETR = 0.
perform OUTPUT_DATA.
clear:ITABD,ITABH1,ITABE.
free:ITABD,ITABH1,ITABE.
when 'DELETE'.
call function 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = LO_GUID.
call method LO_GUID->CHECK_CHANGED_DATA.
delete ITABH0 where SEL = 'X'.
clear ITABH0-SEL.
perform DISPLAY_ALV_REPORT.
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_FULLSCREEN' excluding RT_EXTAB.
endform. "set_pf_status
转载于:https://blog.51cto.com/itlingm/562109