一、user_command 触发按钮
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = go_grid.
go_grid->check_changed_data( ). "当数据有变化时赋值
rs_selfield-refresh = 'X'.
rs_selfield-col_stable = 'X'.
rs_selfield-row_stable = 'X'.
CASE r_ucomm.
WHEN 'PRINT' OR 'PDF'."打印
READ TABLE gt_tab WITH KEY sel = 'X' TRANSPORTING NO FIELDS."不用赋值
IF sy-subrc = 0.
PERFORM frm_get_print USING r_ucomm.
ELSE.
MESSAGE '请选择行进行打印!' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
WHEN '&AL'.
LOOP AT gt_tab ASSIGNING FIELD-SYMBOL(<f_tab>).
<f_tab>-sel = abap_true.
ENDLOOP.
WHEN '&SA'.
LOOP AT gt_tab ASSIGNING <f_tab>.
<f_tab>-sel = abap_false.
ENDLOOP.
ENDCASE.
go_grid->check_changed_data( ).
rs_selfield-refresh = 'X'.
rs_selfield-col_stable = 'X'.
rs_selfield-row_stable = 'X'.
ENDFORM.
二、打印方法
FORM frm_get_print USING r_ucomm TYPE sy-ucomm.
DATA ls_head TYPE zshdh_head.
DATA lt_tab TYPE TABLE OF zsmm0038.
DATA ls_tab TYPE zsmm0038.
DATA lv_formname TYPE tdsfname.
DATA fn_name TYPE rs38l_fnam.
DATA ls_composer_options TYPE ssfcompop.
DATA control TYPE ssfctrlop.
DATA jobout TYPE ssfcresop.
DATA ls_formb TYPE ssfcrescl.
DATA ls_return TYPE ssfcrescl.
DATA ls_job_output_info TYPE ssfcrescl.
DATA lv_success TYPE char1.
CLEAR:gs_item,gt_item,gs_head,lv_success.
lv_formname = 'ZQMF_01'.
ls_composer_options-tddest = 'LP01'.
ls_composer_options-tdiexit = 'X'.
ls_composer_options-tdimmed = 'X'.
ls_composer_options-tddelete = 'X'.
ls_composer_options-tdnoprev = ''.
IF r_ucomm = 'PRINT'. "smartforms 打印才需要SSF_OPRN 和 SSF_CLOSE
control-preview = 'X'.
control-no_dialog = ''.
control-no_open = 'X'.
control-no_close = 'X'.
CALL FUNCTION 'SSF_OPEN'
EXPORTING
user_settings = ''
output_options = ls_composer_options
control_parameters = control
IMPORTING
job_output_options = jobout
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ELSE.
control-getotf = 'X'. "pdf转换一定要这个参数
control-no_dialog = 'X'.
ENDIF.
********************************** Begin获取数据 ************************************
IF gt_tab IS NOT INITIAL.
SELECT a~prueflos, "检验批
b~pspnr ,"wbs
b~post1 "wbs描述
FROM qals AS a
JOIN prps AS b ON b~pspnr = a~ps_psp_pnr
FOR ALL ENTRIES IN @gt_tab
WHERE prueflos = @gt_tab-prueflos
INTO TABLE @DATA(lt_wbs).
SORT lt_wbs BY prueflos.
SELECT DISTINCT a~prueflos,b~bewregel
FROM qals AS a
JOIN qamv AS b ON b~prueflos = a~prueflos
FOR ALL ENTRIES IN @gt_tab
WHERE a~prueflos = @gt_tab-prueflos
INTO TABLE @DATA(lt_bewregel)
.
SORT lt_bewregel BY prueflos.
"1.根据MERKNR去取QAMV-AUSWMENGE1
"2.再根据AUSMENGE1作为表QPAC中AUSWAHLMGE的值去取表QPAC中BEWERTUNG为A的QPAC-CODEGRUPPE和QPAC-CODE
"3.再根据CODEGRUPPE和CODE去表QPCD取KATALOGART为1的KURZTEXT显示出来
"4.若QAMV-AUSMENGE1为空,取QAMV表中的SOLLWERT和MASSEINHSW显示
SELECT a~prueflos
,b~merknr"检验特性
,b~kurztext"检验特性名称
,b~auswmenge1 "代码组/选择集
,b~masseinhsw
,b~sollwert
,t~kurztext AS zqspecific "b~SOLLWERT && b~MASSEINHSW
FROM qals AS a
JOIN qamv AS b ON b~prueflos = a~prueflos
LEFT JOIN qpac AS c ON c~auswahlmge = b~auswmenge1 AND c~bewertung = 'A'
LEFT JOIN qpcd AS d ON d~codegruppe = c~codegruppe AND d~code = c~code AND d~katalogart = '1'
LEFT JOIN qpct AS t ON t~katalogart = d~katalogart AND t~codegruppe = d~codegruppe AND t~code = d~code AND t~sprache = @sy-langu AND t~version = d~version
FOR ALL ENTRIES IN @gt_tab
WHERE a~prueflos = @gt_tab-prueflos
INTO TABLE @DATA(lt_qamv)
.
SORT lt_qamv BY prueflos merknr.
ENDIF.
********************************** End 获取数据 ************************************
LOOP AT gt_tab INTO gs_tab WHERE sel = 'X'.
CLEAR:gs_head,gs_item,gt_item.
MOVE-CORRESPONDING gs_tab TO gs_head.
* 项目名 POST1 评估规则 ZQBEWREGEL
READ TABLE lt_wbs INTO DATA(ls_wbs) WITH KEY prueflos = gs_tab-prueflos BINARY SEARCH.
IF sy-subrc = 0.
gs_head-post1 = ls_wbs-post1.
ENDIF.
READ TABLE lt_bewregel INTO DATA(ls_bewregel) WITH KEY prueflos = gs_tab-prueflos BINARY SEARCH.
IF sy-subrc = 0.
IF ls_bewregel-bewregel = 'A1'.
gs_head-zqbewregel = '手工评估'.
ELSE.
gs_head-zqbewregel = '系统评估'.
ENDIF.
ENDIF.
LOOP AT lt_qamv INTO DATA(ls_qamv) WHERE prueflos = gs_tab-prueflos.
CLEAR: gs_item.
gs_item-merknr = ls_qamv-merknr.
gs_item-zqkurztext = ls_qamv-kurztext.
IF ls_qamv-auswmenge1 IS INITIAL.
gs_item-zqspecific = |{ ls_qamv-sollwert }{ ls_qamv-masseinhsw }|.
ELSE.
gs_item-zqspecific = ls_qamv-zqspecific.
ENDIF.
APPEND gs_item TO gt_item.
ENDLOOP.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = lv_formname
* VARIANT = ' '
* DIRECT_CALL = ' '
IMPORTING
fm_name = fn_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CALL FUNCTION fn_name
EXPORTING
control_parameters = control "pdf转换的getotf
output_options = ls_composer_options
is_head = gs_head
user_settings = 'X'
IMPORTING
job_output_info = ls_job_output_info "pdf转换需要这个表
TABLES
it_tab = gt_item
it_tab2 = gt_item2
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
IF ls_job_output_info IS NOT INITIAL AND r_ucomm = 'PDF'.
DATA lv_xstring TYPE xstring.
DATA lv_xstring2 TYPE i.
DATA lt_lines TYPE TABLE OF tline.
DATA lt_attachment TYPE TABLE OF string.
DATA: lv_file TYPE string, "文件名
lv_path TYPE string, "文件路径
lv_fullpath TYPE string. "文件路径
* 文件下载路径获取
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = '下载'
default_file_name = '空白检验计划表格下载'
file_filter = 'PDF(*.pdf)' ##NO_TEXT
CHANGING
filename = lv_file
path = lv_path
fullpath = lv_fullpath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc <> 0 OR lv_file IS INITIAL.
RETURN.
ELSE.
CONCATENATE lv_fullpath '.pdf' INTO lv_fullpath.
ENDIF.
* smartforms 转换为pdf
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
* max_linewidth = 132 ”注释掉
* ARCHIVE_INDEX = ' '
* copynumber = 0
* ASCII_BIDI_VIS2LOG = ' '
* PDF_DELETE_OTFTAB = ' '
* PDF_USERNAME = ' '
* PDF_PREVIEW = 'X'
use_cascading = 'X' "不打X会导致乱码
* MODIFIED_PARAM_TABLE =
* IMPORTING
* bin_filesize = lv_xstring2
* bin_file = lv_xstring
TABLES
otf = ls_job_output_info-otfdata[]
lines = lt_lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
* 文件下载
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = lv_xstring2
filename = lv_fullpath
* filename = '空白检验计划表'
filetype = 'BIN'
* APPEND = ' '
* WRITE_FIELD_SEPARATOR = ' '
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
no_auth_check = 'X'
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
* SHOW_TRANSFER_STATUS = ABAP_TRUE
* VIRUS_SCAN_PROFILE = '/SCET/GUI_DOWNLOAD'
* IMPORTING
* FILELENGTH =
TABLES
data_tab = lt_lines
* FIELDNAMES =
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc <> 0.
* Implement suitable error handling here
ELSE.
PERFORM frm_refresh_printtime.
ENDIF.
ENDIF.
ENDLOOP.
IF r_ucomm = 'PRINT'.
CALL FUNCTION 'SSF_CLOSE'
IMPORTING
job_output_info = ls_return
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
OTHERS = 4.
IF ls_return-outputdone = 'X'. "按打印预览不会让打印次数增加
PERFORM frm_refresh_printtime.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.