我目前正在学习在ABAP中编程,并获得了我卡住的练习。我或多或少都可以正常工作,但我很确定还有另一种更好的方法。
练习要求是:
- 从"选择"屏幕中允许用户上传文件。
- 从"选择"屏幕中允许用户选择打印机。
- 当报告运行时,上传文件的内容应发送到要打印的指定打印机。
到目前为止,我到了什么,或多或少有效的是:
*&---------------------------------------------------------------------*
*& Report Z_SELECT_PRINT_JR *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT z_select_print_jr NO STANDARD PAGE HEADING .
DATA: filedata TYPE STANDARD TABLE OF char255,
fileline TYPE char255.
DATA: valid,
params TYPE pri_params.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_file TYPE char255.
PARAMETERS: p_prnt TYPE char30.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM display_file_selection.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_prnt.
PERFORM display_printer_selection.
START-OF-SELECTION.
PERFORM load_file_data.
PERFORM send_to_printer.
*&--------------------------------------------------------------------*
*& Form display_file_selection
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM display_file_selection.
DATA: lv_return TYPE i,
lt_filetable TYPE STANDARD TABLE OF file_table,
ls_filetable TYPE file_table.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'SELECT FILE TO PRINT:'
default_extension = 'txt'
file_filter = 'Text Files (.txt)|*.txt|XML Files (.xml)|*.xml'
initial_directory = 'C:demo'
multiselection = space
CHANGING
file_table = lt_filetable
rc = lv_return
EXCEPTIONS
OTHERS = 1.
IF lv_return NE 0.
READ TABLE lt_filetable INTO ls_filetable INDEX 1.
p_file = ls_filetable-filename.
ENDIF.
ENDFORM. "display_file_selection
*&--------------------------------------------------------------------*
*& Form display_printer_selection
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM display_printer_selection.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
IMPORTING
out_parameters = params
valid = valid
EXCEPTIONS
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
OTHERS = 4.
IF sy-subrc EQ 0.
p_prnt = params-pdest.
ENDIF.
ENDFORM. "display_printer_selection
*&--------------------------------------------------------------------*
*& Form load_file_data
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM load_file_data.
DATA: filename TYPE string,
fileleng TYPE i.
MOVE p_file TO filename.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = filename
IMPORTING
filelength = fileleng
CHANGING
data_tab = filedata.
ENDFORM. "load_file_data
*&--------------------------------------------------------------------*
*& Form send_to_printer
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM send_to_printer.
DATA: lv_line TYPE char255,
ndx TYPE i.
ndx = 1.
NEW-PAGE PRINT ON
PARAMETERS params
NO DIALOG.
DO.
READ TABLE filedata INTO lv_line INDEX ndx.
IF sy-subrc NE 0.
EXIT.
ENDIF.
WRITE: / lv_line.
ndx = ndx + 1.
ENDDO.
NEW-PAGE PRINT OFF.
ENDFORM. "send_to_printer
当我或多或少地说这件事时,基本上我会向打印机输出输出,但是如果有空的线路分隔文本,则在打印过程中不会携带这些文本。我很确定有某种可用的功能模块,但是找到有关SAP和ABAP相关的任何内容的文档非常困难。有人有更好的方法执行此操作吗?
与同事交谈后,他建议我使用以下功能模块:
-
RSPO_SR_OPEN
-
RSPO_SR_TABLE_WRITE
-
RSPO_SR_CLOSE
在这种情况下,我正在使用SAP的Spool Server打开一个线轴请求,然后编写由GUI_UPLOAD
函数填写的表。最后,最后我关闭了阀芯请求。
这允许按预期打印文件,但是没有所有控制字符,并且记得将其按在实际文本文件中的空白行中。