-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path4.Dynamic Texts Export
433 lines (322 loc) · 14 KB
/
4.Dynamic Texts Export
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
************************************************************************
* Program name: Z_DYNAMIC_TEXTS_EXPORT
* Description : Download Texts to XLSX File
*
* Created by: George Drakos
*
************************************************************************
REPORT z_dynamic_texts_export.
*&---------------------------------------------------------------------*
*& GLOBAL DATA DEFINITION
*&---------------------------------------------------------------------*
TABLES:stxh,sscrfields.
CLASS: lcx_texts DEFINITION DEFERRED,
lcl_texts DEFINITION DEFERRED,
lcl_utilities DEFINITION DEFERRED,
lcl_sel_screen DEFINITION DEFERRED.
*&---------------------------------------------------------------------*
*& Class LCX_TEXTS DEFINITION
*&---------------------------------------------------------------------*
CLASS lcx_texts DEFINITION INHERITING FROM cx_static_check.
PUBLIC SECTION.
METHODS:
constructor IMPORTING text TYPE string,
get_text REDEFINITION.
PRIVATE SECTION.
DATA local_text TYPE string.
ENDCLASS.
*&---------------------------------------------------------------------*
*& Class LCL_TEXTS DEFINITION
*&---------------------------------------------------------------------*
CLASS lcl_texts DEFINITION CREATE PUBLIC.
PUBLIC SECTION.
METHODS:
get_data IMPORTING so_object TYPE STANDARD TABLE
so_tdname TYPE STANDARD TABLE
so_tdid TYPE STANDARD TABLE
so_spras TYPE STANDARD TABLE
RAISING lcx_texts,
download_texts IMPORTING im_filename TYPE file_table-filename
im_field_labels_as_header TYPE abap_bool DEFAULT space
RAISING lcx_texts.
PRIVATE SECTION.
TYPES:
BEGIN OF t_texts,
tdobject TYPE tdobject,
tdname TYPE tdobname,
tdid TYPE tdid,
tdspras TYPE spras,
tdtxtlines TYPE tdtxtlines,
text TYPE string,
END OF t_texts,
tt_texts TYPE STANDARD TABLE OF t_texts WITH DEFAULT KEY INITIAL SIZE 0.
DATA:lt_texts TYPE tt_texts.
METHODS:
populate_texts.
ENDCLASS.
*&---------------------------------------------------------------------*
*& Class LCL_UTILITIES DEFINITION
*&---------------------------------------------------------------------*
CLASS lcl_utilities DEFINITION.
PUBLIC SECTION.
CLASS-METHODS get_export_filepath CHANGING ch_filepath TYPE file_table-filename.
ENDCLASS.
*----------------------------------------------------------------------*
* CLASS lcl_sel_screen DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_sel_screen DEFINITION FINAL CREATE PRIVATE.
PUBLIC SECTION.
CLASS-METHODS get_instance RETURNING VALUE(re_instance) TYPE REF TO lcl_sel_screen.
METHODS:
screen_initialization,
screen_pbo,
screen_pai IMPORTING im_system_command TYPE syst-ucomm.
PRIVATE SECTION.
CLASS-DATA lo_instance TYPE REF TO lcl_sel_screen.
ENDCLASS.
*&---------------------------------------------------------------------*
*& SELECTION SCREEN DESIGN
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b0 WITH FRAME TITLE title0.
PARAMETERS p_file TYPE file_table-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b0.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE title1.
SELECT-OPTIONS: s_obj FOR stxh-tdobject OBLIGATORY DEFAULT 'TEXT',
s_tdname FOR stxh-tdname OBLIGATORY DEFAULT 'SAPSCRIPT-TEST_01',
s_tdid FOR stxh-tdid OBLIGATORY DEFAULT 'ST',
s_spras FOR stxh-tdspras OBLIGATORY DEFAULT syst-langu.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE title2.
PARAMETERS c_header AS CHECKBOX DEFAULT abap_true.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN END OF BLOCK b1.
*&---------------------------------------------------------------------*
*& INITIALIZATION OF SELECTION SCREEN ELEMENTS
*&---------------------------------------------------------------------*
INITIALIZATION.
lcl_sel_screen=>get_instance( )->screen_initialization( ).
*&---------------------------------------------------------------------*
*& AT SELECTION SCREEN MODIFICATION (PBO)
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
lcl_sel_screen=>get_instance( )->screen_pbo( ).
*&---------------------------------------------------------------------*
*& AT SELECTION SCREEN ON VALUE REQUESTS (F4)
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
lcl_utilities=>get_export_filepath( CHANGING ch_filepath = p_file ).
*&---------------------------------------------------------------------*
*& AT SELECTION SCREEN Actions(PAI)
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
lcl_sel_screen=>get_instance( )->screen_pai( sscrfields-ucomm ).
*&---------------------------------------------------------------------*
*& EXECUTABLE CODE
*&---------------------------------------------------------------------*
START-OF-SELECTION.
TRY.
DATA(lo_texts) = NEW lcl_texts( ).
lo_texts->get_data( so_object = s_obj[]
so_spras = s_spras[]
so_tdid = s_tdid[]
so_tdname = s_tdname[] ).
lo_texts->download_texts( im_filename = p_file
im_field_labels_as_header = c_header ).
CATCH lcx_texts INTO DATA(lo_exception).
MESSAGE lo_exception->get_text( ) TYPE cl_cms_common=>con_msg_typ_i DISPLAY LIKE cl_cms_common=>con_msg_typ_e.
ENDTRY.
END-OF-SELECTION.
*----------------------------------------------------------------------*
* CLASS lcl_sel_screen IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_sel_screen IMPLEMENTATION.
METHOD get_instance.
IF lo_instance IS NOT BOUND.
lo_instance = NEW #( ).
ENDIF.
re_instance = lo_instance.
ENDMETHOD.
METHOD screen_initialization.
title0 = 'Export Filepath'.
title1 = 'Texts Selection'.
title2 = 'Properties'.
syst-title = 'Texts Export'.
%_p_file_%_app_%-text = icon_xls && 'Excel Filepath'.
%_s_obj_%_app_%-text = icon_object_list && 'Text Object'.
%_s_tdname_%_app_%-text = icon_text_field && 'Text Name'.
%_s_tdid_%_app_%-text = icon_text_ina && 'Text ID'.
%_s_spras_%_app_%-text = icon_eu && 'Language'.
%_c_header_%_app_%-text = 'Field Labels as Excel Header'.
ENDMETHOD.
METHOD screen_pbo.
LOOP AT SCREEN INTO DATA(ls_screen).
MODIFY SCREEN FROM ls_screen.
ENDLOOP.
ENDMETHOD.
METHOD screen_pai.
CASE im_system_command.
WHEN /pmg/if_ge_sel_constants=>gc_policy_free_sel.
WHEN cl_wsti_calc_const=>c_execute.
ENDCASE.
ENDMETHOD.
ENDCLASS.
*&---------------------------------------------------------------------*
*& Class LCL_UTILITIES IMPLEMENTATION
*&---------------------------------------------------------------------*
CLASS lcl_utilities IMPLEMENTATION.
METHOD get_export_filepath.
DATA filename TYPE string.
DATA path TYPE string.
DATA fullpath TYPE string.
DATA user_action TYPE i.
cl_gui_frontend_services=>file_save_dialog(
EXPORTING
window_title = 'File System of Presentation Server'
default_extension = cl_gui_frontend_services=>filetype_excel
prompt_on_overwrite = abap_true
default_file_name = 'Exported_Texts.XLSX'
file_filter = 'All Files(*.*)|*.*|' && 'Excel Files (*.xlsx)|*.xlsx|' && 'Excel Files (*.xls)|*.xls|'
CHANGING
filename = filename
path = path
fullpath = fullpath
user_action = user_action
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
invalid_default_file_name = 4
OTHERS = 5 ).
ch_filepath = COND #( WHEN syst-subrc IS INITIAL AND user_action EQ cl_gui_frontend_services=>action_ok THEN fullpath ).
ENDMETHOD.
ENDCLASS.
*&---------------------------------------------------------------------*
*& Class LCL_TEXTS IMPLEMENTATION
*&---------------------------------------------------------------------*
CLASS lcl_texts IMPLEMENTATION.
METHOD get_data.
CLEAR me->lt_texts.
SELECT FROM stxh
FIELDS stxh~tdobject, stxh~tdname, stxh~tdid, stxh~tdspras, stxh~tdtxtlines
WHERE tdobject IN @so_object
AND tdname IN @so_tdname
AND tdid IN @so_tdid
AND tdspras IN @so_spras
INTO CORRESPONDING FIELDS OF TABLE @me->lt_texts.
IF syst-subrc IS NOT INITIAL OR lt_texts IS INITIAL.
RAISE EXCEPTION TYPE lcx_texts EXPORTING text = 'No Texts Found for the Specified Criteria'.
ENDIF.
me->populate_texts( ).
ENDMETHOD.
METHOD populate_texts.
DATA lt_text_table TYPE text_lh.
DATA lt_error_table TYPE text_lh.
LOOP AT me->lt_texts ASSIGNING FIELD-SYMBOL(<fs_line>).
CALL FUNCTION 'READ_MULTIPLE_TEXTS'
EXPORTING
client = syst-mandt
name = <fs_line>-tdname
object = <fs_line>-tdobject
id = <fs_line>-tdid
language = <fs_line>-tdspras
IMPORTING
text_table = lt_text_table
error_table = lt_error_table
EXCEPTIONS
wrong_access_to_archive = 1
error_message = 2
OTHERS = 3.
IF syst-subrc IS INITIAL AND lt_text_table IS NOT INITIAL.
DATA(lt_text) = VALUE #( lt_text_table[ 1 ]-lines OPTIONAL ).
CALL FUNCTION 'IDMX_DI_TLINE_INTO_STRING'
EXPORTING
it_tline = lt_text
IMPORTING
ev_text_string = <fs_line>-text
EXCEPTIONS
error_message = 1
OTHERS = 2.
ENDIF.
CLEAR:lt_text,lt_text_table,lt_error_table.
ENDLOOP.
ENDMETHOD.
METHOD download_texts.
TRY.
cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lo_salv) CHANGING t_table = me->lt_texts ).
DATA(lt_fieldcatalog) = cl_salv_controller_metadata=>get_lvc_fieldcatalog( r_columns = lo_salv->get_columns( ) r_aggregations = lo_salv->get_aggregations( ) ).
CATCH cx_salv_msg INTO DATA(lo_exception).
EXIT.
ENDTRY.
IF im_field_labels_as_header EQ abap_true.
LOOP AT lt_fieldcatalog ASSIGNING FIELD-SYMBOL(<fs_line>).
<fs_line>-fix_column = abap_true.
IF <fs_line>-fieldname EQ 'TEXT'.
<fs_line>-coltext = 'Text String'.
ENDIF.
ENDLOOP.
ENDIF.
"Get XSTRING
cl_salv_bs_tt_util=>if_salv_bs_tt_util~transform( EXPORTING xml_type = if_salv_bs_xml=>c_type_xlsx
xml_version = cl_salv_bs_a_xml_base=>get_version( )
r_result_data = cl_salv_ex_util=>factory_result_data_table( r_data = REF #( me->lt_texts )
t_fieldcatalog = lt_fieldcatalog )
xml_flavour = if_salv_bs_c_tt=>c_tt_xml_flavour_export
gui_type = if_salv_bs_xml=>c_gui_type_gui
IMPORTING xml = DATA(lv_xstring) ).
CHECK lv_xstring IS NOT INITIAL.
"XString to SOLIX
cl_scp_change_db=>xstr_to_xtab( EXPORTING im_xstring = lv_xstring
IMPORTING ex_xtab = DATA(lt_binary_content)
ex_size = DATA(lv_bin_size) ).
CHECK lt_binary_content IS NOT INITIAL.
cl_gui_frontend_services=>gui_download(
EXPORTING
bin_filesize = lv_bin_size
filename = |{ im_filename }|
filetype = 'BIN'
confirm_overwrite = abap_true
IMPORTING
filelength = DATA(lv_bytestransferred)
CHANGING
data_tab = lt_binary_content
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
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24 ).
IF syst-subrc IS NOT INITIAL.
RAISE EXCEPTION TYPE lcx_texts EXPORTING text = 'Error Downloading Texts'.
ENDIF.
ENDMETHOD.
ENDCLASS.
*&---------------------------------------------------------------------*
*& Class LCX_TEXTS IMPLEMENTATION
*&---------------------------------------------------------------------*
CLASS lcx_texts IMPLEMENTATION.
METHOD constructor.
super->constructor( textid = CONV #( text ) ).
local_text = text.
ENDMETHOD.
METHOD get_text.
result = me->local_text.
ENDMETHOD.
ENDCLASS.