IT干货网

ABAP-上载PDF转OTF

sanshao 2022年03月09日 SAP 150 0
  1 *&---------------------------------------------------------------------* 
  2 *& Report ZRICO_25 
  3 *&---------------------------------------------------------------------* 
  4 *& 
  5 *&---------------------------------------------------------------------* 
  6  
  7 report ztest_pdf2spool. 
  8  
  9 include fp_utilities. "#EC INCL_OK 
 10  
 11 data gv_cust_id type s_customer. 
 12 data: content type fpcontent. 
 13 data gs_outputparams type sfpoutputparams. 
 14 data: total_pages type fppagecount. 
 15  
 16 parameters: fpages type i modif id upl. 
 17  
 18 initialization. 
 19  
 20 start-of-selection. 
 21  
 22  
 23 perform upload_data. 
 24  
 25 perform set_outpars. 
 26 perform send_pdf_to_spool. 
 27  
 28 form send_pdf_to_spool. 
 29  
 30 data: size type i. 
 31 data: total_size type i. 
 32 data: spoolid type rspoid. 
 33 data: copies type rspocopies. 
 34 data: lifetime. 
 35  
 36 size = xstrlen( content ). 
 37 add size to total_size. 
 38  
 39 copies = gs_outputparams-copies. 
 40 lifetime = gs_outputparams-lifetime. 
 41  
 42 call function 'ADS_CREATE_PDF_SPOOLJOB' 
 43 exporting 
 44 dest = gs_outputparams-dest 
 45 pages = total_pages 
 46 pdf_data = content 
 47 name = gs_outputparams-dataset 
 48 suffix1 = gs_outputparams-suffix1 
 49 suffix2 = gs_outputparams-suffix2 
 50 copies = copies 
 51 immediate_print = gs_outputparams-reqimm 
 52 auto_delete = gs_outputparams-reqdel 
 53 titleline = gs_outputparams-covtitle 
 54 receiver = gs_outputparams-receiver 
 55 division = gs_outputparams-division 
 56 authority = gs_outputparams-authority 
 57 lifetime = lifetime 
 58 importing 
 59 spoolid = spoolid 
 60 exceptions 
 61 no_data = 1 
 62 not_pdf = 2 
 63 wrong_devtype = 3 
 64 operation_failed = 4 
 65 cannot_write_file = 5 
 66 device_missing = 6 
 67 no_such_device = 7 
 68 others = 8. 
 69 if sy-subrc <> 0. 
 70 message id sy-msgid type sy-msgty number sy-msgno 
 71 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
 72 endif. 
 73  
 74 message s060(ssfcomposer) with spoolid. 
 75  
 76  
 77 endform. " SEND_PDF_To_SPOOL 
 78  
 79  
 80 form upload_data. 
 81  
 82 include fp_spool_constants. 
 83  
 84 data: name type string, 
 85 filetype type char10, 
 86 filetable type filetable, 
 87 rc type i, 
 88 guiobj type ref to cl_gui_frontend_services, 
 89 uact type i. 
 90 data: datatab type table of ssfdata. 
 91 data: extension type string. 
 92 data: bin_filesize type i. 
 93 data: buffer type xstring. 
 94  
 95 extension = c_file_ext_pdf. 
 96 filetype = 'BIN'. 
 97 concatenate '*' extension into name. 
 98 create object guiobj. 
 99  
100 call method guiobj->file_open_dialog 
101 exporting 
102 default_filename = name 
103 changing 
104 file_table = filetable 
105 rc = rc 
106 user_action = uact 
107 exceptions 
108 file_open_dialog_failed = 1 
109 cntl_error = 2 
110 error_no_gui = 3. 
111 if uact = guiobj->action_cancel. 
112 leave program. 
113 endif. 
114  
115 read table filetable index 1 into name. 
116 check sy-subrc = 0. 
117  
118 call function 'GUI_UPLOAD' 
119 exporting 
120 filename = name 
121 filetype = filetype 
122 importing 
123 filelength = bin_filesize 
124 tables 
125 data_tab = datatab 
126 exceptions 
127 file_open_error = 1 
128 file_read_error = 2 
129 invalid_type = 3 
130 no_batch = 4 
131 others = 5. 
132 if sy-subrc <> 0. 
133 message id sy-msgid type sy-msgty number sy-msgno 
134 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
135 leave program. 
136 endif. "#EC * 
137  
138 call function 'SCMS_BINARY_TO_XSTRING' 
139 exporting 
140 input_length = bin_filesize 
141 importing 
142 buffer = buffer 
143 tables 
144 binary_tab = datatab 
145 exceptions 
146 failed = 1 
147 others = 2. 
148 if sy-subrc <> 0. 
149 message id sy-msgid type sy-msgty number sy-msgno 
150 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
151 leave program. 
152 endif. 
153  
154 content = buffer. 
155 total_pages = fpages. 
156  
157 endform. 
158  
159 form set_outpars . 
160  
161 data: ls_outpars type sfpoutpar. 
162  
163 call function 'FPCOMP_SHOW_DIALOG' 
164 changing 
165 ie_outpar = ls_outpars 
166 exceptions 
167 cancel = 1 
168 usage_error = 2 
169 system_error = 3 
170 internal_error = 4 
171 others = 5. 
172 if sy-subrc <> 0. 
173 message id sy-msgid type 'S' number sy-msgno 
174 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
175 leave program. 
176 else. 
177 move-corresponding ls_outpars to gs_outputparams. 
178 endif. 
179  
180 endform.
View Code

1.上载PDF

2.通过函数GUI_UPLOAD获取filelength / data_tab

3.通过函数SCMS_BINARY_TO_XSTRING获取buffer

4.通过函数FPCOMP_SHOW_DIALOG获取ie_outpar

5.通过函数ADS_CREATE_PDF_SPOOLJOB获取spoolid


评论关闭
IT干货网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

ABAP-HTML-MAIL