Você está na página 1de 6

report Z_SCR_WORD_UPLOAD line-size 141

no standard page heading message-id td.


* V2.1
data: dummy(80),
f_ext(4).
parameters: Path like dummy default 'C:\Word2007template.dotm' lower case,
ext like f_ext default 'dotm' lower case.
data: bds_instance type ref to cl_bds_document_set,
bds_classname type sbdst_classname value
'SAPSCRIPTWORDINTEGRATION',
bds_classtype type sbdst_classtype value 'OT',
bds_objectkey type sbdst_object_key value 'WORDTEMPLATE',
doc_id_700
type sbdst_doc_id
value
'BDS_LOC2 A83FD83F732D5D1EE10000000A1550A7',
doc_id_640
type sbdst_doc_id
value
'BDS_LOC2 B91FC640B91E325CE10000000A1551F7',
doc_id_620
type sbdst_doc_id
value
'BDS_LOC2 40C0B062D5C34C4CE10000000A1145AB',
bds_classname_7
type sbdst_classname value
'SAPSCRIPTWORDINTEGRATION2',
doc_id_7
type sbdst_doc_id
value
'BDS_LOC2 473BA296286672C0E10000000A1146E7',
l_doc_id
type sbdst_doc_id,
l_doc_ver_no type sbdst_doc_ver_no,
l_doc_var_id type sbdst_doc_var_id,
l_files_line type bapifiles,
l_files
type table of bapifiles,
filename
like
dir
type
file
type
rel_i
type
rel(4),
extt(1),
rc like sy-subrc.

rlgrap-filename,
string,
string,
i,

data: true type tdbool value 'X',


false type tdbool value space,
cancel.
filename = path.
* Check extension dot|dotm
if not ( ext eq 'dotm' or ext eq 'dot' ).
perform bd_textbox_err(rstxpdft) using 80
'Wrong file extension'(003).
exit.
endif.
perform check_data.
perform upload_file changing filename
ext
dir
file
cancel.

if cancel eq true.
exit.
endif.
perform init_file_line using dir
file.
perform init.
perform upload changing rc.
if rc = 1.
perform bd_textbox_err(rstxpdft) using 80
'Error in Upload'(003).
else.
perform bd_textbox_msg(rstxpdft) using 80
'The upload of Wordtemplate is done'(001).
endif.
form init.
* init for 2003 Upload
* release
rel = sy-saprl.
rel_i = rel(2).
if

rel_i
l_doc_id =
elseif rel_i
l_doc_id =
elseif rel_i
l_doc_id =
else.
exit.
endif.

ge 70.
doc_id_700.
eq 64.
doc_id_640.
eq 62.
doc_id_620.

endform.
form init_file_line using dir type string
file type string.
* BDS file line
data: file_up type string.
clear l_files_line.
file_up = file.
translate file_up to upper case.
clear l_files_line.
* l_files_line-comp_id = 'WORDTEMPLATE.DOT'.
l_files_line-comp_id = 'Word2007template.dotm'.
l_files_line-directory = dir.
l_files_line-filename = file_up.
l_files_line-mimetype = 'APPLICATION/MSWORD'.
clear l_files[].
append l_files_line to l_files[].
endform.
form check_data.
if rel_i ge 70.
perform delete_rel using 62.
perform delete_rel using 64.
elseif rel_i eq 64.

perform delete_rel
perform delete_rel
elseif rel_i eq 62.
perform delete_rel
perform delete_rel
else.
exit.
endif.
endform.

using 62.
using 70.
using 64.
using 70.

form delete_rel using p_rel type i.


data: signature_line type bapisignat,
signature
type table of bapisignat,
pp_cancel
value 'A',
pp_replace_all
value 'R',
pp_enter
value 'E',
pp_yes
value 'J',
pp_no
value 'N',
pp_leave.
if

p_rel eq 62.
move: doc_id_620 to signature_line-doc_id.
elseif p_rel eq 64.
move: doc_id_640 to signature_line-doc_id.
elseif p_rel eq 70.
move: doc_id_700 to signature_line-doc_id.
else.
exit.
endif.
append signature_line to signature[].
call function 'BDS_BUSINESSDOCUMENT_GET_INFO'
exporting
classname
= bds_classname
classtype
= bds_classtype
object_key
= bds_objectkey
tables
signature
= signature
exceptions
nothing_found
= 1
parameter_error
= 2
not_allowed
= 3
error_kpro
= 4
internal_error
= 5
not_authorized
= 6
others
= 9.
if sy-subrc eq 0.
call function 'POPUP_TO_CONFIRM_STEP'
exporting
titel
= 'Template delete'
textline1
=
'The system contains Wordtemplate.dot from old Basis release.'
textline2
= 'Do you want to delete this Object?'
defaultoption = pp_no
importing
answer
= pp_leave.
if pp_leave = pp_yes.

call function 'BDS_BUSINESSDOCUMENT_DELETE'


exporting
classname
= bds_classname
classtype
= bds_classtype
object_key
= bds_objectkey
tables
signature
= signature
exceptions
nothing_found
= 1
parameter_error
= 2
not_allowed
= 3
error_kpro
= 4
internal_error
= 5
not_authorized
= 6
others
= 7.
endif.
* To do: Transport create on case of Yes answer.
endif.
endform.
form upload changing rc like sy-subrc.
data: l_bds_classname type sbdst_classname.
if ext eq 'dotm'.
l_bds_classname = bds_classname_7.
l_doc_id
= doc_id_7.
else.
l_bds_classname = bds_classname.
endif.
call function 'BDS_BUSINESSDOCUMENT_UPD_F'
exporting
classname
= l_bds_classname
classtype
= bds_classtype
object_key
= bds_objectkey
doc_id
= l_doc_id
doc_ver_no
= l_doc_ver_no
doc_var_id
= l_doc_var_id
tables
files
= l_files
exceptions
nothing_found
= 1
parameter_error
= 2
not_allowed
= 3
error_kpro
= 4
internal_error
= 5
not_authorized
= 6
others
= 7.
rc = sy-subrc.
endform.
form upload_file changing
p_filename
p_ext

like rlgrap-filename
like ext

p_dir
p_file
p_cancel
data: name
filetable
filter
rc
uact
result
l_res
l_str
l_res2
l_find
l_name

type
type
type
type
type
type
type
type
type
like
type

type string
type string
type c.

string,
filetable,
string,
i,
i,
tdbool,
i,
i,
i,
sy-subrc,
string.

* condense filename no-gaps.


name
= p_filename.
clear p_cancel.
clear p_dir.
clear p_file.
if p_ext eq 'dotm'.
filter = '(Word2007template.dotm)|Word2007template.dotm|'.
else.
filter = '(Wordtemplate.dot)|Wordtemplate.dot|'.
" '(*.*)|*.*|)'.
endif.
while result eq false.
" Search the file
call method cl_gui_frontend_services=>file_exist
exporting file
= name
receiving result
= result
exceptions cntl_error
= 1
error_no_gui
= 2
wrong_parameter = 3
others
= 5.
if result eq true.
exit.
endif.

call method cl_gui_frontend_services=>file_open_dialog


exporting window_title
= 'Template Upload'
default_filename = name
file_filter
= filter
changing file_table
= filetable
rc
= rc
user_action
= uact
exceptions file_open_dialog_failed = 1
cntl_error
= 2
error_no_gui
= 3.
check sy-subrc = 0.
if rc < 0 or uact eq 9.
p_cancel = true.
exit.
endif.
read table filetable index 1 into name.
check sy-subrc = 0.
endwhile.
if p_cancel ne 'X'.

l_name = name.
l_str = strlen( name ).
while l_find eq 0 and
l_res2 lt l_str.
l_name = l_name+l_res.
find '\' in l_name match offset l_res.
l_find = sy-subrc.
if l_find eq 0.
l_res = l_res + 1.
l_res2 = l_res2 + l_res.
endif.
endwhile.
if l_res2 eq 0.
p_cancel = 'X'.
exit.
endif.
p_file = name+l_res2.
p_dir = name(l_res2).
p_filename = name.
else.
exit.
endif.
endform.

Você também pode gostar