The objective behind this article is to give the user an introduction to eCATT – Test Data Container. In this article we will understand the following: • Concept of Test Data Container • Variants • Creating a demo test container.
eCATT Part 7 – Test Data Container
Dynamic Creation of Report
In this document I am going to show how to create dynamic reports in ABAP from another report and how to call those dynamic report.
First create a report with some name say ZDYNAMIC_REPORT_GEN.
Write the following code in this report.
1. First create and internal table that holds the statements that to be added into dynamic report.
DATA: lt_code TYPE TABLE OF rssource-line.
2. Now append the lines that you want to insert into report in lt_code internal table:
> Append the first line that reach report contains.
APPEND 'REPORT ZDYNAMIC_REPORT.' TO lt_code.
> Create an input parameters
APPEND 'PARAMETERS: lv_name TYPE string.' TO lt_code.
> Now display the name in output.
APPEND 'WRITE: /''Your name is : '', lv_name.' TO lt_code.
> Now insert the internal table containing lines of codes into dynamic report created through this program.
INSERT REPORT 'ZDYNAMIC_REPORT' FROM lt_code.
> Now the report is ready for execution, so call the report for execution using the dynamic report name
SUBMIT zdynamic_report VIA SELECTION-SCREEN AND RETURN.
3. Thats it. Now execute the report ZDYNAMIC_REPORT_GEN, it asks for the name, enter some name and execute. Your name will be printed in the output screen.
This is how we can create dynamic reports. It is possible to write any set of code using dynamic report.
Formatting Date, Times and Timestamps
At this stage this is just a list of links on SDN I have found in my searching for formatting dates, times and timestamps
http://wiki.sdn.sap.com/wiki/display/ABAP/Date+formatting+Using+CL_ABAP_DATFM
http://scn.sap.com/thread/3271020
http://scn.sap.com/thread/744799
I have a bigger purpose here and in good time all will be revealed. <turns round on large leather chair stroking white kitten while laughing a big eeeevil laugh.>
BWAHAHAHAHAHAHAAAAAAA
The GOS (Generic Object Services) class that does all the work
Linked From Document: http://scn.sap.com/docs/DOC-41921
The first thing I did is create a class that can handle any type of activity with GOS, such as listing, uploading, downloading, and deleting of attachments. The class is generic enough to handle the subtle differences required when called from GUI, WebDynpro, or ITS applications. Below you will see the class attributes and all the methods of the class.
CLASS ATTRIBUTES
GOS_GET_FILE_LIST
This method gets a listing of all the attachment details for a specific object type and key
method gos_get_file_list.
types: begin of ts_key,
foltp type so_fol_tp,
folyr type so_fol_yr,
folno type so_fol_no,
objtp type so_obj_tp,
objyr type so_obj_yr,
objno type so_obj_no,
forwarder type so_usr_nam,
end of ts_key,
begin of ts_attachment,
foltp type so_fol_tp,
folyr type so_fol_yr,
folno type so_fol_no,
objtp type so_obj_tp,
objyr type so_obj_yr,
objno type so_obj_no,
brelguid type oblguid32,
roletype type oblroltype,
end of ts_attachment,
tt_attachment type table of ts_attachment.
data: ta_srgbtbrel type standard table of srgbtbrel,
wa_srgbtbrel type srgbtbrel,
lta_sood type standard table of sood,
lwa_sood type sood, ltp_pathin(1000) type c,
ltp_filename type string,
ltp_sortfield type char30,
lta_objcont type soli_tab,
lta_attachments type tt_attachment,
lwa_attachments like line of lta_attachments,
lo_boritem type ref to cl_sobl_bor_item,
lo_al_item type ref to cl_gos_al_item,
li_link type ref to if_browser_link,
ls_option type obl_s_relt,
lt_options type obl_t_relt,
ls_key type ts_key,
ls_attachment type ts_attachment,
lt_attachment type tt_attachment,
lt_links type obl_t_link,
ls_link type obl_s_link,
lp_linkid type blnk_inst,
gs_lpor type sibflporb,
ls_message type bapiret2.
if not is_lporb-typeid is initial and not is_lporb-instid is initial.
select * from srgbtbrel into table ta_srgbtbrel
where instid_a eq is_lporb-instid
and typeid_a eq is_lporb-typeid
and catid_a eq 'BO'.
if sy-subrc eq 0.
sort ta_srgbtbrel by instid_a typeid_a catid_a.
delete adjacent duplicates from ta_srgbtbrel comparing instid_a typeid_a catid_a.
loop at ta_srgbtbrel into wa_srgbtbrel.
clear: lt_attachment[], lta_attachments[].
gs_lpor-instid = wa_srgbtbrel-instid_a.
gs_lpor-typeid = wa_srgbtbrel-typeid_a.
gs_lpor-catid = wa_srgbtbrel-catid_a.
ls_option-sign = 'I'.
ls_option-option = 'EQ'.
ls_option-low = 'ATTA'.
append ls_option to lt_options.
ls_option-low = 'NOTE'.
append ls_option to lt_options.
ls_option-low = 'URL'.
append ls_option to lt_options.
try.
call method cl_binary_relation=>read_links_of_binrels
exporting
is_object = gs_lpor
it_relation_options = lt_options
ip_role = 'GOSAPPLOBJ'
importing
et_links = lt_links.
loop at lt_links into ls_link.
case ls_link-typeid_b .
when 'MESSAGE'.
ls_key = ls_link-instid_b.
move-corresponding ls_key to ls_attachment.
ls_attachment-roletype = ls_link-roletype_b.
if ls_link-brelguid is initial.
ls_attachment-brelguid = ls_link-relguidold.
else.
ls_attachment-brelguid = ls_link-brelguid.
endif.
append ls_attachment to lt_attachment.
when others.
continue.
endcase.
endloop.
catch cx_obl_parameter_error .
catch cx_obl_internal_error .
catch cx_obl_model_error .
catch cx_root.
endtry.
endloop.
lta_attachments[] = lt_attachment[].
check lines( lta_attachments ) > 0.
select * from sood into table lta_sood
for all entries in lta_attachments
where
objtp = lta_attachments-objtp and
objyr = lta_attachments-objyr and
objno = lta_attachments-objno.
if sy-subrc eq 0.
t_attachments[] = lta_sood.
endif.
data rcode type i.
data objhead_tab type table of soli.
data objcont_tab type table of soli.
data objpara_tab type table of selc.
data objparb_tab type table of soop1.
data sood_key type soodk.
data hex_mode type sonv-flag.
field-symbols <fs> type line of z_tt_sood.
loop at t_attachments assigning <fs>.
if not ( <fs>-objtp is initial or <fs>-objyr is initial or <fs>-objno is initial ).
concatenate <fs>-objtp <fs>-objyr <fs>-objno into sood_key.
perform socx_select in program sapfsso0
tables objhead_tab objcont_tab
objpara_tab objparb_tab
using sood_key
hex_mode
rcode.
if rcode eq 0.
data moff type i.
data l_param_search type soli-line.
data l_param_head type soli-line.
data value type soli-line.
data wa_objhead_tab like line of objhead_tab.
data lt_url_tab type table of so_url.
data ld_url_tab_size type sytabix.
l_param_search = '&SO_FILENAME'.
translate l_param_search to upper case.
loop at objhead_tab into wa_objhead_tab.
clear moff.
find '=' in wa_objhead_tab-line match offset moff.
check sy-subrc = 0.
l_param_head = wa_objhead_tab-line(moff).
translate l_param_head to upper case.
if l_param_head = l_param_search.
add 1 to moff.
value = wa_objhead_tab-line+moff.
if not ( value is initial ).
split value at '.' into table lt_url_tab.
describe table lt_url_tab lines ld_url_tab_size.
if ld_url_tab_size gt 1.
read table lt_url_tab index ld_url_tab_size into <fs>-acnam.
endif.
endif.
endif.
endloop.
endif.
endif.
endloop.
else.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into ls_message-message.
ls_message-type = sy-msgty.
ls_message-id = sy-msgid.
ls_message-number = sy-msgno.
ls_message-message_v1 = sy-msgv1.
ls_message-message_v2 = sy-msgv2.
ls_message-message_v3 = sy-msgv3.
ls_message-message_v4 = sy-msgv4.
append ls_message to rt_messages.
return.
endif.
else.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into ls_message-message.
ls_message-type = sy-msgty.
ls_message-id = sy-msgid.
ls_message-number = sy-msgno.
ls_message-message_v1 = sy-msgv1.
ls_message-message_v2 = sy-msgv2.
ls_message-message_v3 = sy-msgv3.
ls_message-message_v4 = sy-msgv4.
append ls_message to rt_messages.
return.
endif.
endmethod.
GOS_DOWNLOAD_FILE_TO_GUI
This method is used by SAP GUI applications to download the selected attachment to the workstation
method gos_download_file_to_gui.
data: ex type ref to cx_root,
text type string,
ltp_sortfield type char30,
lta_objcont type soli_tab,
ltp_pathfile(1000) type c,
ltp_filename type string,
ltp_binfilesize type so_doc_len,
ls_message type bapiret2.
try .
concatenate attachment-objtp attachment-objyr attachment-objno into ltp_sortfield.
import objcont_tab to lta_objcont from database soc3(dt) id ltp_sortfield.
if sy-subrc = 0.
if not attachment-acnam is initial.
concatenate file_path '\' attachment-objdes '.' attachment-acnam into ltp_pathfile.
else.
concatenate file_path '\' attachment-objdes '.' attachment-file_ext into ltp_pathfile.
endif.
replace '\\' with '\' into ltp_pathfile+2.
translate ltp_pathfile using '/ '.
ltp_binfilesize = attachment-objlen.
call function 'SO_OBJECT_DOWNLOAD'
exporting
bin_filesize = ltp_binfilesize
filetype = 'BIN'
path_and_file = ltp_pathfile
extct = attachment-extct
no_dialog = 'X'
importing
act_filename = ltp_filename
tables
objcont = lta_objcont
exceptions
file_write_error = 1
invalid_type = 2
x_error = 3
kpro_error = 4
others = 5.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into ls_message-message.
ls_message-type = sy-msgty.
ls_message-id = sy-msgid.
ls_message-number = sy-msgno.
ls_message-message_v1 = sy-msgv1.
ls_message-message_v2 = sy-msgv2.
ls_message-message_v3 = sy-msgv3.
ls_message-message_v4 = sy-msgv4.
append ls_message to rt_messages.
return.
endif.
else.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into ls_message-message.
ls_message-type = sy-msgty.
ls_message-id = sy-msgid.
ls_message-number = sy-msgno.
ls_message-message_v1 = sy-msgv1.
ls_message-message_v2 = sy-msgv2.
ls_message-message_v3 = sy-msgv3.
ls_message-message_v4 = sy-msgv4.
append ls_message to rt_messages.
return.
endif.
catch cx_root into ex.
text = ex->get_text( ).
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into ls_message-message.
ls_message-type = sy-msgty.
ls_message-id = sy-msgid.
ls_message-number = sy-msgno.
ls_message-message_v1 = sy-msgv1.
ls_message-message_v2 = sy-msgv2.
ls_message-message_v3 = sy-msgv3.
ls_message-message_v4 = sy-msgv4.
append ls_message to rt_messages.
return.
endtry.
endmethod.
GOS_GET_FILE_XSTRING
This method is used to download attached files when using ABAP WebDynpro Applications
method gos_get_file_xstring.
data: ex type ref to cx_root,
text type string,
l_folder_id type soodk,
l_object_id type soodk,
document_id type sofmk,
lo_root type ref to cx_root,
ls_fol_id type soodk,
lwa_document_data type sofolenti1,
document_content type standard table of soli,
lwa_object_header type standard table of solisti1,
l_subrc type int4,
l_objkey type soodk,
lt_data type standard table of solisti1,
lt_xdata type solix_tab,
ls_xdata type solix,
ls_data type solisti1,
l_data type string,
l_xdata type xstring,
l_xdata_line type xstring,
l_filename type string,
l_mimetype type string,
l_document_id type sofolenti1-doc_id,
l_document_data type sofolenti1,
lt_header type soli_tab,
lv_filename type string,
lo_header type ref to cl_bcs_objhead,
file type string, dot_offset type i,
extension type mimetypes-extension,
mimetype type mimetypes-type,
lv_message type bapiret2.
try.
call function 'SO_FOLDER_ROOT_ID_GET'
exporting
region = folder_region
importing
folder_id = ls_fol_id
exceptions
others = 1.
if sy-subrc eq 0.
l_folder_id-objtp = ls_fol_id-objtp.
l_folder_id-objyr = ls_fol_id-objyr.
l_folder_id-objno = ls_fol_id-objno.
l_object_id-objtp = doctp.
l_object_id-objyr = docyr.
l_object_id-objno = docno.
call function 'SO_OBJECT_READ'
exporting
folder_id = l_folder_id
object_id = l_object_id
tables
objcont = document_content
exceptions
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
folder_no_authorization = 5
object_not_exist = 6
object_no_authorization = 7
operation_no_authorization = 8
owner_not_exist = 9
parameter_error = 10
substitute_not_active = 11
substitute_not_defined = 12
system_failure = 13
x_error = 14
others = 15.
if sy-subrc eq 0.
document_id-foltp = l_folder_id-objtp.
document_id-folyr = l_folder_id-objyr.
document_id-folno = l_folder_id-objno.
document_id-doctp = l_object_id-objtp.
document_id-docyr = l_object_id-objyr.
document_id-docno = l_object_id-objno.
l_document_id = document_id.
call function 'SO_DOCUMENT_READ_API1'
exporting
document_id = l_document_id
importing
document_data = l_document_data
tables
object_header = lt_header
object_content = lt_data
contents_hex = lt_xdata
exceptions
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
others = 4.
if sy-subrc <> 0.
l_subrc = sy-subrc.
lv_message-type = 'E'.
if sy-msgid is not initial and sy-msgno is not initial.
lv_message-id = sy-msgid.
lv_message-number = sy-msgno.
lv_message-message_v1 = sy-msgv1.
lv_message-message_v2 = sy-msgv2.
lv_message-message_v3 = sy-msgv3.
lv_message-message_v4 = sy-msgv4.
elseif l_subrc = 2.
lv_message-id = 'SO'.
lv_message-number = '055'.
lv_message-message_v1 = l_document_id.
else.
lv_message-id = 'SO'.
lv_message-number = '006'.
lv_message-message_v1 = l_document_id.
endif.
append lv_message to rt_messages.
return.
endif.
lo_header = cl_bcs_objhead=>create( lt_header ).
lv_filename = lo_header->get_filename( ).
o_file_name = lv_filename.
file = o_file_name.
find first occurrence of regex '\.[^\.]+$' in file match offset dot_offset.
add 1 to dot_offset.
extension = file+dot_offset.
call function 'SDOK_MIMETYPE_GET'
exporting
extension = extension
importing
mimetype = o_mimetype.
data conv_out type ref to cl_abap_conv_out_ce.
if lt_xdata is not initial.
data l_counter type i.
l_counter = l_document_data-doc_size.
loop at lt_xdata into ls_xdata.
if l_counter > 255.
concatenate l_xdata ls_xdata-line into l_xdata in byte mode.
else.
concatenate l_xdata ls_xdata-line+0(l_counter) into l_xdata in byte mode.
endif.
l_counter = l_counter - 255.
endloop.
o_content_hex = l_xdata.
else.
loop at lt_data into ls_data.
if doctp = 'URL' and strlen( ls_data-line ) >= 5.
concatenate l_data ls_data-line+5 into l_data.
endif.
if doctp = 'RAW'.
concatenate l_data ls_data-line into l_data.
endif.
endloop.
if doctp = 'RAW' or doctp = 'URL'.
o_content = l_data.
return.
endif.
conv_out = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' ).
conv_out->convert( exporting data = l_data importing buffer = o_content_hex ).
endif.
endif.
endif.
catch cx_root into ex.
lv_message-id = sy-msgid.
lv_message-number = sy-msgno.
lv_message-message_v1 = sy-msgv1.
lv_message-message_v2 = sy-msgv2.
lv_message-message_v3 = sy-msgv3.
lv_message-message_v4 = sy-msgv4.
append lv_message to rt_messages.
endtry.
endmethod.
GOS_GET_FILE_SOLITAB
This method is used to download attached files when using ITS Applications
data: ex type ref to cx_root,
text type string,
l_folder_id type soodk,
l_object_id type soodk,
document_id type sofmk,
lo_root type ref to cx_root,
ls_fol_id type soodk,
lwa_document_data type sofolenti1,
document_content type standard table of soli,
lwa_object_header type standard table of solisti1,
l_subrc type int4,
l_objkey type soodk,
lt_data type standard table of solisti1,
lt_xdata type solix_tab,
ls_xdata type solix,
ls_data type solisti1,
l_data type string,
l_xdata type xstring,
l_xdata_line type xstring,
l_filename type string,
l_mimetype type string,
l_document_id type sofolenti1-doc_id,
l_document_data type sofolenti1,
lt_header type soli_tab,
lv_filename type string,
lo_header type ref to cl_bcs_objhead,
file type string, dot_offset type i,
extension type mimetypes-extension,
mimetype type mimetypes-type,
lv_message type bapiret2.
try.
call function 'SO_FOLDER_ROOT_ID_GET'
exporting
region = folder_region
importing
folder_id = ls_fol_id
exceptions
others = 1.
if sy-subrc eq 0.
l_folder_id-objtp = ls_fol_id-objtp.
l_folder_id-objyr = ls_fol_id-objyr.
l_folder_id-objno = ls_fol_id-objno.
l_object_id-objtp = doctp.
l_object_id-objyr = docyr.
l_object_id-objno = docno.
call function 'SO_OBJECT_READ'
exporting
folder_id = l_folder_id
object_id = l_object_id
tables
objcont = document_content
exceptions
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
folder_no_authorization = 5
object_not_exist = 6
object_no_authorization = 7
operation_no_authorization = 8
owner_not_exist = 9
parameter_error = 10
substitute_not_active = 11
substitute_not_defined = 12
system_failure = 13
x_error = 14
others = 15.
if sy-subrc eq 0.
document_id-foltp = l_folder_id-objtp.
document_id-folyr = l_folder_id-objyr.
document_id-folno = l_folder_id-objno.
document_id-doctp = l_object_id-objtp.
document_id-docyr = l_object_id-objyr.
document_id-docno = l_object_id-objno.
l_document_id = document_id.
call function 'SO_DOCUMENT_READ_API1'
exporting
document_id = l_document_id
importing
document_data = l_document_data
tables
object_header = lt_header
object_content = lt_data
contents_hex = lt_xdata
exceptions
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
others = 4.
move l_document_data-doc_size to o_filelength.
if sy-subrc <> 0.
l_subrc = sy-subrc.
lv_message-type = 'E'.
if sy-msgid is not initial and sy-msgno is not initial.
lv_message-id = sy-msgid.
lv_message-number = sy-msgno.
lv_message-message_v1 = sy-msgv1.
lv_message-message_v2 = sy-msgv2.
lv_message-message_v3 = sy-msgv3.
lv_message-message_v4 = sy-msgv4.
elseif l_subrc = 2.
lv_message-id = 'SO'.
lv_message-number = '055'.
lv_message-message_v1 = l_document_id.
else.
lv_message-id = 'SO'.
lv_message-number = '006'.
lv_message-message_v1 = l_document_id.
endif.
append lv_message to rt_messages.
return.
endif.
lo_header = cl_bcs_objhead=>create( lt_header ).
lv_filename = lo_header->get_filename( ).
o_file_name = lv_filename.
file = o_file_name.
find first occurrence of regex '\.[^\.]+$' in file match offset dot_offset.
add 1 to dot_offset.
extension = file+dot_offset.
call function 'SDOK_MIMETYPE_GET'
exporting
extension = extension
importing
mimetype = o_mimetype.
data conv_out type ref to cl_abap_conv_out_ce.
if lt_data is not initial.
o_content_solitab[] = lt_data[].
endif.
endif.
endif.
catch cx_root into ex.
lv_message-id = sy-msgid.
lv_message-number = sy-msgno.
lv_message-message_v1 = sy-msgv1.
lv_message-message_v2 = sy-msgv2.
lv_message-message_v3 = sy-msgv3.
lv_message-message_v4 = sy-msgv4.
append lv_message to rt_messages.
endtry.
endmethod.
GOS_ATTACH_FILE_XSTRING
This method is used attach files when using ABAP WebDynpro Applications
method gos_attach_file_xstring.
data: ls_message type bapiret2,
filename type string,
filefullname type string,
mime_type type string,
size type i,
offset type i,
offset_old type i,
temp_len type i,
objname type string,
l_obj_type type so_obj_tp,
hex_null type x length 1 value '20',
l_document_title type so_text255,
file_ext type string,
lt_objcont type standard table of solisti1 initial size 6,
objcont like line of lt_objcont,
lt_ls_doc_change type standard table of sodocchgi1,
ls_doc_change like line of lt_ls_doc_change,
lt_data type soli_tab,
ls_data type soli,
lt_xdata type solix_tab,
ls_xdata type solix,
l_folder_id type sofdk,
ls_object_id type soodk,
l_object_id_fol type so_obj_id,
l_object_id type so_obj_id,
l_object_hd_change type sood1,
l_tab_size type int4,
l_retype type breltyp-reltype,
lt_urltab type standard table of sood-objdes.
call function 'SO_FOLDER_ROOT_ID_GET'
exporting
region = 'B'
importing
folder_id = l_folder_id.
if iv_objtp = gc_type_file.
size = xstrlen( iv_content_hex ).
call method split_path
exporting
iv_path = iv_name
importing
ev_filename = filename.
call method split_file_extension
exporting
iv_filename_with_ext = filename
importing
ev_filename = objname
ev_extension = file_ext.
ls_doc_change-obj_name = objname.
ls_doc_change-obj_descr = objname.
ls_doc_change-obj_langu = sy-langu.
ls_doc_change-sensitivty = 'F'.
ls_doc_change-doc_size = size.
offset = 0.
while offset <= size.
offset_old = offset.
offset = offset + 255.
if offset > size.
temp_len = xstrlen( iv_content_hex+offset_old ).
clear ls_xdata-line with hex_null in byte mode.
ls_xdata-line = iv_content_hex+offset_old(temp_len).
else.
ls_xdata-line = iv_content_hex+offset_old(255).
endif.
append ls_xdata to lt_xdata.
endwhile.
l_retype = 'ATTA'.
l_obj_type = 'EXT'.
l_object_hd_change-objnam = ls_doc_change-obj_name.
l_object_hd_change-objdes = ls_doc_change-obj_descr.
l_object_hd_change-objsns = ls_doc_change-sensitivty.
l_object_hd_change-objla = ls_doc_change-obj_langu.
l_object_hd_change-objlen = ls_doc_change-doc_size.
l_object_hd_change-file_ext = file_ext.
data lt_obj_header type standard table of solisti1.
data ls_header type solisti1.
concatenate '&SO_FILENAME=' filename into ls_header.
append ls_header to lt_obj_header.
clear ls_header.
ls_header = '&SO_FORMAT=BIN'.
append ls_header to lt_obj_header.
* change hex data to text data
call function 'SO_SOLIXTAB_TO_SOLITAB'
exporting
ip_solixtab = lt_xdata
importing
ep_solitab = lt_data.
else.
size = strlen( iv_content ).
objname = iv_name.
ls_doc_change-obj_descr = objname.
ls_doc_change-sensitivty = 'O'.
ls_doc_change-obj_langu = sy-langu.
offset = 0.
if iv_objtp = gc_type_note.
l_retype = 'NOTE'.
l_obj_type = 'RAW'.
l_object_hd_change-file_ext = 'TXT'.
while offset <= size.
offset_old = offset.
offset = offset + 255.
if offset > size.
temp_len = strlen( iv_content+offset_old ).
clear ls_data-line.
ls_data-line = iv_content+offset_old(temp_len).
else.
ls_data-line = iv_content+offset_old(255).
endif.
append ls_data to lt_data.
endwhile.
if objname is initial.
read table lt_data index 1 into l_document_title.
while l_document_title+49 <> ' '.
shift l_document_title right.
endwhile.
shift l_document_title left deleting leading ' '.
ls_doc_change-obj_descr = l_document_title.
endif.
else.
* it's url (not note)
l_retype = 'URL'.
l_obj_type = 'URL'.
if objname is initial.
split iv_content at '/' into table lt_urltab.
describe table lt_urltab lines l_tab_size.
read table lt_urltab index l_tab_size into ls_doc_change-obj_descr.
endif.
while offset <= size.
offset_old = offset.
offset = offset + 250.
if offset > size.
temp_len = strlen( iv_content+offset_old ).
clear ls_data-line.
ls_data-line = iv_content+offset_old(temp_len).
else.
ls_data-line = iv_content+offset_old(250).
endif.
concatenate '&KEY&' ls_data-line into ls_data-line.
append ls_data to lt_data.
endwhile.
endif.
ls_doc_change-doc_size = size.
l_object_hd_change-objdes = ls_doc_change-obj_descr.
l_object_hd_change-objsns = ls_doc_change-sensitivty.
l_object_hd_change-objla = ls_doc_change-obj_langu.
l_object_hd_change-objlen = ls_doc_change-doc_size.
endif.
* save object
call function 'SO_OBJECT_INSERT'
exporting
folder_id = l_folder_id
object_hd_change = l_object_hd_change
object_type = l_obj_type
importing
object_id = ls_object_id
tables
objcont = lt_data
objhead = lt_obj_header
exceptions
component_not_available = 01
folder_not_exist = 06
folder_no_authorization = 05
object_type_not_exist = 17
operation_no_authorization = 21
parameter_error = 23
others = 1000.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into ls_message-message.
ls_message-type = sy-msgty.
ls_message-id = sy-msgid.
ls_message-number = sy-msgno.
ls_message-message_v1 = sy-msgv1.
ls_message-message_v2 = sy-msgv2.
ls_message-message_v3 = sy-msgv3.
ls_message-message_v4 = sy-msgv4.
append ls_message to rt_messages.
return.
endif.
* create relation
data l_obj_rolea type borident.
data l_obj_roleb type borident.
l_obj_rolea-objkey = is_lporb-instid.
l_obj_rolea-objtype = is_lporb-typeid.
l_obj_rolea-logsys = is_lporb-catid.
l_object_id_fol = l_folder_id.
l_object_id = ls_object_id.
concatenate l_object_id_fol l_object_id into l_obj_roleb-objkey respecting blanks.
l_obj_roleb-objtype = 'MESSAGE'.
clear l_obj_roleb-logsys.
call function 'BINARY_RELATION_CREATE'
exporting
obj_rolea = l_obj_rolea
obj_roleb = l_obj_roleb
relationtype = l_retype
exceptions
others = 1.
if sy-subrc = 0.
commit work and wait.
else.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into ls_message-message.
ls_message-type = sy-msgty.
ls_message-id = sy-msgid.
ls_message-number = sy-msgno.
ls_message-message_v1 = sy-msgv1.
ls_message-message_v2 = sy-msgv2.
ls_message-message_v3 = sy-msgv3.
ls_message-message_v4 = sy-msgv4.
append ls_message to rt_messages.
return.
endif.
endmethod.
GOS_ATTACH_FILE_SOLITAB
This method is used attach files when using ITS Applications
method gos_attach_file_solitab.
data: ls_message type bapiret2,
filename type string,
filefullname type string,
mime_type type string,
size type i,
offset type i,
offset_old type i,
temp_len type i,
objname type string,
l_obj_type type so_obj_tp,
hex_null type x length 1 value '20',
l_document_title type so_text255,
file_ext type string,
lt_objcont type standard table of solisti1 initial size 6,
objcont like line of lt_objcont,
lt_ls_doc_change type standard table of sodocchgi1,
ls_doc_change like line of lt_ls_doc_change,
lt_data type soli_tab,
ls_data type soli,
lt_xdata type solix_tab,
ls_xdata type solix,
l_folder_id type sofdk,
ls_object_id type soodk,
l_object_id_fol type so_obj_id,
l_object_id type so_obj_id,
l_object_hd_change type sood1,
l_tab_size type int4,
l_retype type breltyp-reltype,
lt_urltab type standard table of sood-objdes.
call function 'SO_FOLDER_ROOT_ID_GET'
exporting
region = 'B'
importing
folder_id = l_folder_id.
if iv_objtp = gc_type_file.
size = iv_filelength.
call method split_path
exporting
iv_path = iv_name
importing
ev_filename = filename.
call method split_file_extension
exporting
iv_filename_with_ext = filename
importing
ev_filename = objname
ev_extension = file_ext.
ls_doc_change-obj_name = objname.
ls_doc_change-obj_descr = objname.
ls_doc_change-obj_langu = sy-langu.
ls_doc_change-sensitivty = 'F'.
ls_doc_change-doc_size = size.
l_retype = 'ATTA'.
l_obj_type = 'EXT'.
l_object_hd_change-objnam = ls_doc_change-obj_name.
l_object_hd_change-objdes = ls_doc_change-obj_descr.
l_object_hd_change-objsns = ls_doc_change-sensitivty.
l_object_hd_change-objla = ls_doc_change-obj_langu.
l_object_hd_change-objlen = ls_doc_change-doc_size.
l_object_hd_change-file_ext = file_ext.
data lt_obj_header type standard table of solisti1.
data ls_header type solisti1.
concatenate '&SO_FILENAME=' filename into ls_header.
append ls_header to lt_obj_header.
clear ls_header.
ls_header = '&SO_FORMAT=BIN'.
append ls_header to lt_obj_header.
lt_data[] = iv_content_solitab[].
else.
size = strlen( iv_content ).
objname = iv_name.
ls_doc_change-obj_descr = objname.
ls_doc_change-sensitivty = 'O'.
ls_doc_change-obj_langu = sy-langu.
offset = 0.
if iv_objtp = gc_type_note.
l_retype = 'NOTE'.
l_obj_type = 'RAW'.
l_object_hd_change-file_ext = 'TXT'.
while offset <= size.
offset_old = offset.
offset = offset + 255.
if offset > size.
temp_len = strlen( iv_content+offset_old ).
clear ls_data-line.
ls_data-line = iv_content+offset_old(temp_len).
else.
ls_data-line = iv_content+offset_old(255).
endif.
append ls_data to lt_data.
endwhile.
if objname is initial.
read table lt_data index 1 into l_document_title.
while l_document_title+49 <> ' '.
shift l_document_title right.
endwhile.
shift l_document_title left deleting leading ' '.
ls_doc_change-obj_descr = l_document_title.
endif.
else.
* it's url (not note)
l_retype = 'URL'.
l_obj_type = 'URL'.
if objname is initial.
split iv_content at '/' into table lt_urltab.
describe table lt_urltab lines l_tab_size.
read table lt_urltab index l_tab_size into ls_doc_change-obj_descr.
endif.
while offset <= size.
offset_old = offset.
offset = offset + 250.
if offset > size.
temp_len = strlen( iv_content+offset_old ).
clear ls_data-line.
ls_data-line = iv_content+offset_old(temp_len).
else.
ls_data-line = iv_content+offset_old(250).
endif.
concatenate '&KEY&' ls_data-line into ls_data-line.
append ls_data to lt_data.
endwhile.
endif.
ls_doc_change-doc_size = size.
l_object_hd_change-objdes = ls_doc_change-obj_descr.
l_object_hd_change-objsns = ls_doc_change-sensitivty.
l_object_hd_change-objla = ls_doc_change-obj_langu.
l_object_hd_change-objlen = ls_doc_change-doc_size.
endif.
* save object
call function 'SO_OBJECT_INSERT'
exporting
folder_id = l_folder_id
object_hd_change = l_object_hd_change
object_type = l_obj_type
importing
object_id = ls_object_id
tables
objcont = lt_data
objhead = lt_obj_header
exceptions
component_not_available = 01
folder_not_exist = 06
folder_no_authorization = 05
object_type_not_exist = 17
operation_no_authorization = 21
parameter_error = 23
others = 1000.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into ls_message-message.
ls_message-type = sy-msgty.
ls_message-id = sy-msgid.
ls_message-number = sy-msgno.
ls_message-message_v1 = sy-msgv1.
ls_message-message_v2 = sy-msgv2.
ls_message-message_v3 = sy-msgv3.
ls_message-message_v4 = sy-msgv4.
append ls_message to rt_messages.
return.
endif.
* create relation
data l_obj_rolea type borident.
data l_obj_roleb type borident.
l_obj_rolea-objkey = is_lporb-instid.
l_obj_rolea-objtype = is_lporb-typeid.
l_obj_rolea-logsys = is_lporb-catid.
l_object_id_fol = l_folder_id.
l_object_id = ls_object_id.
concatenate l_object_id_fol l_object_id into l_obj_roleb-objkey respecting blanks.
l_obj_roleb-objtype = 'MESSAGE'.
clear l_obj_roleb-logsys.
call function 'BINARY_RELATION_CREATE'
exporting
obj_rolea = l_obj_rolea
obj_roleb = l_obj_roleb
relationtype = l_retype
exceptions
others = 1.
if sy-subrc = 0.
commit work and wait.
else.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into ls_message-message.
ls_message-type = sy-msgty.
ls_message-id = sy-msgid.
ls_message-number = sy-msgno.
ls_message-message_v1 = sy-msgv1.
ls_message-message_v2 = sy-msgv2.
ls_message-message_v3 = sy-msgv3.
ls_message-message_v4 = sy-msgv4.
append ls_message to rt_messages.
return.
endif.
endmethod.
GOS_EMAIL_ATTACHED_FILE
This method is used email attachments
method gos_email_attached_file.
data: ex type ref to cx_root,
text type string,
l_folder_id type soodk,
l_object_id type soodk,
document_id type sofmk,
lo_root type ref to cx_root,
ls_fol_id type soodk,
l_document_id type so_entryid,
lwa_document_data type sofolenti1,
document_content type standard table of soli,
lwa_object_header type standard table of solisti1,
lwa_object_content type standard table of solisti1,
lwa_object_content_1 type standard table of solisti1,
lwa_contents_hex type standard table of solix,
lt_plist type standard table of sopcklsti1,
wa_lt_plist type sopcklsti1,
wa_lwa_object_content_1 type solisti1,
mailto type ad_smtpadr,
document_content_solix type solix_tab,
wa_object_header like line of lwa_object_header,
send_request type ref to cl_bcs,
sent_to_all type os_boolean,
document type ref to cl_document_bcs,
doc_size type so_obj_len,
recipient type ref to if_recipient_bcs,
bcs_exception type ref to cx_bcs,
ttext type bcsy_text,
wa_t_receivers like line of t_receivers,
moff type i,
lt_url_tab type table of so_url,
ld_url_tab_size type sytabix,
fil_nm(50) type c,
file_ext(3) type c,
fil_nm_txt type so_obj_des,
ls_message type bapiret2.
try .
call function 'SO_FOLDER_ROOT_ID_GET'
exporting
region = folder_region
importing
folder_id = ls_fol_id
exceptions
others = 1.
if sy-subrc eq 0.
l_folder_id-objtp = ls_fol_id-objtp.
l_folder_id-objyr = ls_fol_id-objyr.
l_folder_id-objno = ls_fol_id-objno.
l_object_id-objtp = doctp.
l_object_id-objyr = docyr.
l_object_id-objno = docno.
call function 'SO_OBJECT_READ'
exporting
folder_id = l_folder_id
object_id = l_object_id
tables
objcont = document_content
exceptions
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
folder_no_authorization = 5
object_not_exist = 6
object_no_authorization = 7
operation_no_authorization = 8
owner_not_exist = 9
parameter_error = 10
substitute_not_active = 11
substitute_not_defined = 12
system_failure = 13
x_error = 14
others = 15.
if sy-subrc eq 0.
document_id-foltp = l_folder_id-objtp.
document_id-folyr = l_folder_id-objyr.
document_id-folno = l_folder_id-objno.
document_id-doctp = l_object_id-objtp.
document_id-docyr = l_object_id-objyr.
document_id-docno = l_object_id-objno.
l_document_id = document_id.
call function 'SO_DOCUMENT_READ_API1'
exporting
document_id = l_document_id
importing
document_data = lwa_document_data
tables
object_header = lwa_object_header
object_content = lwa_object_content_1
contents_hex = lwa_contents_hex
exceptions
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
others = 4.
if sy-subrc eq 0.
clear: send_request, document, recipient, sent_to_all, fil_nm_txt.
try.
read table t_receivers into wa_t_receivers index 1.
mailto = wa_t_receivers-receiver.
send_request = cl_bcs=>create_persistent( ).
read table lwa_object_header into wa_object_header index 1.
if sy-subrc eq 0.
find '=' in wa_object_header-line match offset moff.
add 1 to moff.
fil_nm = wa_object_header-line+moff.
split fil_nm at '.' into table lt_url_tab.
describe table lt_url_tab lines ld_url_tab_size.
if ld_url_tab_size gt 1.
read table lt_url_tab index ld_url_tab_size into file_ext.
else.
clear file_ext.
endif.
endif.
fil_nm_txt = fil_nm.
if fil_nm_txt is initial.
fil_nm_txt = 'Requested File is Attached'.
endif.
append 'The file you requested file is attached.' to ttext.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = ttext
i_subject = fil_nm_txt ).
call method document->add_attachment
exporting
i_attachment_type = file_ext
i_attachment_subject = fil_nm
i_att_content_hex = lwa_contents_hex
i_attachment_header = lwa_object_header
i_attachment_size = lwa_document_data-doc_size.
send_request->set_document( document ).
recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
send_request->add_recipient( recipient ).
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
catch cx_bcs into bcs_exception.
message i865(so) with bcs_exception->error_type.
endtry.
if sy-subrc eq 0.
if send_now eq 'X'.
submit rsconn01 with mode = 'INT' and return.
endif.
else.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into ls_message-message.
ls_message-type = sy-msgty.
ls_message-id = sy-msgid.
ls_message-number = sy-msgno.
ls_message-message_v1 = sy-msgv1.
ls_message-message_v2 = sy-msgv2.
ls_message-message_v3 = sy-msgv3.
ls_message-message_v4 = sy-msgv4.
append ls_message to rt_messages.
return.
endif.
commit work.
else.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into ls_message-message.
ls_message-type = sy-msgty.
ls_message-id = sy-msgid.
ls_message-number = sy-msgno.
ls_message-message_v1 = sy-msgv1.
ls_message-message_v2 = sy-msgv2.
ls_message-message_v3 = sy-msgv3.
ls_message-message_v4 = sy-msgv4.
append ls_message to rt_messages.
return.
endif.
else.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into ls_message-message.
ls_message-type = sy-msgty.
ls_message-id = sy-msgid.
ls_message-number = sy-msgno.
ls_message-message_v1 = sy-msgv1.
ls_message-message_v2 = sy-msgv2.
ls_message-message_v3 = sy-msgv3.
ls_message-message_v4 = sy-msgv4.
append ls_message to rt_messages.
return.
endif.
else.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into ls_message-message.
ls_message-type = sy-msgty.
ls_message-id = sy-msgid.
ls_message-number = sy-msgno.
ls_message-message_v1 = sy-msgv1.
ls_message-message_v2 = sy-msgv2.
ls_message-message_v3 = sy-msgv3.
ls_message-message_v4 = sy-msgv4.
append ls_message to rt_messages.
return.
endif.
catch cx_root into ex.
text = ex->get_text( ).
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into ls_message-message.
ls_message-type = sy-msgty.
ls_message-id = sy-msgid.
ls_message-number = sy-msgno.
ls_message-message_v1 = sy-msgv1.
ls_message-message_v2 = sy-msgv2.
ls_message-message_v3 = sy-msgv3.
ls_message-message_v4 = sy-msgv4.
append ls_message to rt_messages.
return.
endtry.
endmethod.
GOS_DELETE_FILE
This method is used delete attachments
method gos_delete_file.
data: ex type ref to cx_root,
text type string,
l_folder_id type soodk,
l_object_id type soodk,
document_id type sofmk,
lo_root type ref to cx_root,
ls_fol_id type soodk,
lwa_document_data type sofolenti1,
document_content type standard table of soli,
lwa_object_header type standard table of solisti1,
l_document_id type swo_typeid,
l_document_data type sofolenti1,
lt_header type soli_tab,
lv_message type bapiret2,
lo_docsrv type ref to cl_gos_document_service.
try.
call function 'SO_FOLDER_ROOT_ID_GET'
exporting
region = folder_region
importing
folder_id = ls_fol_id
exceptions
others = 1.
if sy-subrc eq 0.
l_folder_id-objtp = ls_fol_id-objtp.
l_folder_id-objyr = ls_fol_id-objyr.
l_folder_id-objno = ls_fol_id-objno.
l_object_id-objtp = doctp.
l_object_id-objyr = docyr.
l_object_id-objno = docno.
call function 'SO_OBJECT_READ'
exporting
folder_id = l_folder_id
object_id = l_object_id
tables
objcont = document_content
exceptions
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
folder_no_authorization = 5
object_not_exist = 6
object_no_authorization = 7
operation_no_authorization = 8
owner_not_exist = 9
parameter_error = 10
substitute_not_active = 11
substitute_not_defined = 12
system_failure = 13
x_error = 14
others = 15.
if sy-subrc eq 0.
document_id-foltp = l_folder_id-objtp.
document_id-folyr = l_folder_id-objyr.
document_id-folno = l_folder_id-objno.
document_id-doctp = l_object_id-objtp.
document_id-docyr = l_object_id-objyr.
document_id-docno = l_object_id-objno.
l_document_id = document_id.
create object lo_docsrv.
case doctp.
when gc_type_file.
call method lo_docsrv->delete_attachment
exporting
is_lporb = is_lporb
ip_attachment = l_document_id.
when gc_type_note.
call method lo_docsrv->delete_note
exporting
is_lporb = is_lporb
ip_note = l_document_id.
when gc_type_url.
call method lo_docsrv->delete_url
exporting
is_lporb = is_lporb
ip_url = l_document_id.
endcase.
if sy-subrc = 0.
commit work and wait.
else.
lv_message-id = sy-msgid.
lv_message-number = sy-msgno.
lv_message-message_v1 = sy-msgv1.
lv_message-message_v2 = sy-msgv2.
lv_message-message_v3 = sy-msgv3.
lv_message-message_v4 = sy-msgv4.
append lv_message to rt_messages.
return.
endif.
endif.
endif.
catch cx_root into ex.
lv_message-id = sy-msgid.
lv_message-number = sy-msgno.
lv_message-message_v1 = sy-msgv1.
lv_message-message_v2 = sy-msgv2.
lv_message-message_v3 = sy-msgv3.
lv_message-message_v4 = sy-msgv4.
append lv_message to rt_messages.
endtry.
endmethod.
Using the GOS (Generic Object Services) Class within classic GUI programs
Linked From Document: http://scn.sap.com/docs/DOC-41921
This first example demonstrates how to use the GOS class from within regular SAP GUI applications such as report programs.
Listing Attachments
report zget_file_list_using_class.
data: lta_sood type standard table of sood, lwa_sood type sood.
data: str_write type string.
data: ls_lporb type sibflporb.
*Specify Business Object Type and Key (BUS1065 = Employees)
parameters: p_key type swo_typeid obligatory default '00000111',
p_type type swo_objtyp obligatory default 'BUS1065'.
start-of-selection.
data: lt_bapirettab type bapirettab.
ls_lporb-typeid = p_type.
ls_lporb-instid = p_key.
call method zcl_oh_my_gos_new=>gos_get_file_list
exporting
is_lporb = ls_lporb
importing
t_attachments = lta_sood
rt_messages = lt_bapirettab.
if lt_bapirettab[] is initial.
data dec_kb type p.
loop at lta_sood into lwa_sood.
dec_kb = lwa_sood-objlen / 1024.
if dec_kb < 1.
dec_kb = 1.
endif.
write: / lwa_sood-objdes, dec_kb, 'KB', ' ', lwa_sood-acnam.
endloop.
endif.
Uploading Attachments
report zfile_upload_using_class.
*Specify Business Object Type and Key (BUS1065 = Employees))
parameters: p_key type swo_typeid obligatory default '00000111',
p_type type swo_objtyp obligatory default 'BUS1065',
p_file type rlgrap-filename obligatory.
at selection-screen on value-request for p_file.
call function 'F4_FILENAME'
exporting
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
importing
file_name = p_file.
start-of-selection.
data: g_filename type string.
data: g_attsize type wsrm_error-wsrm_direction.
data: it_content like standard table of soli.
data: ta_srgbtbrel type standard table of srgbtbrel, wa_srgbtbrel type srgbtbrel.
data: lta_sood type standard table of sood, lwa_sood type sood.
data: dec_kb type p.
data: ls_lporb type sibflporb.
data: lv_objtyp type so_obj_tp.
data: lt_bapirettab type bapirettab.
lv_objtyp = 'EXT'.
ls_lporb-instid = p_key.
ls_lporb-typeid = p_type.
move p_file to g_filename.
call function 'GUI_UPLOAD'
exporting
filename = g_filename
filetype = 'BIN'
importing
filelength = g_attsize
tables
data_tab = it_content.
if sy-subrc eq 0.
call method zcl_oh_my_gos_new=>gos_attach_file_solitab
exporting
iv_name = g_filename
iv_content_solitab = it_content
is_lporb = ls_lporb
iv_objtp = lv_objtyp
iv_filelength = g_attsize
receiving
rt_messages = lt_bapirettab.
endif.
call method zcl_oh_my_gos_new=>gos_get_file_list
exporting
is_lporb = ls_lporb
importing
t_attachments = lta_sood
rt_messages = lt_bapirettab.
if lt_bapirettab[] is initial.
write: /.
loop at lta_sood into lwa_sood.
dec_kb = lwa_sood-objlen / 1024.
if dec_kb < 1.
dec_kb = 1.
endif.
write: / lwa_sood-objdes, dec_kb, 'KB', ' ', lwa_sood-acnam.
endloop.
endif.
Downloading Attachments
report zfile_download_using_class.
data: ta_srgbtbrel type standard table of srgbtbrel, wa_srgbtbrel type srgbtbrel.
data: lta_sood type standard table of sood, lwa_sood type sood.
data: dec_kb type p.
data: ls_lporb type sibflporb.
data: lt_bapirettab type bapirettab.
*Specify Business Object Type and Key (BUS1065 = Employees)
parameters: p_key type swo_typeid obligatory default '00000111',
p_type type swo_objtyp obligatory default 'BUS1065'.
start-of-selection.
ls_lporb-typeid = p_type.
ls_lporb-instid = p_key.
call method zcl_oh_my_gos_new=>gos_get_file_list
exporting
is_lporb = ls_lporb
importing
t_attachments = lta_sood
rt_messages = lt_bapirettab.
if lt_bapirettab[] is initial.
loop at lta_sood into lwa_sood.
call method zcl_oh_my_gos_new=>gos_download_file_to_gui
exporting
file_path = 'C:\TEMP\TTT'
attachment = lwa_sood
importing
rt_messages = lt_bapirettab.
if lt_bapirettab[] is initial.
dec_kb = lwa_sood-objlen / 1024.
if dec_kb < 1.
dec_kb = 1.
endif.
write: / lwa_sood-objdes, dec_kb, 'KB', ' ', lwa_sood-acnam.
endif.
endloop.
endif.
Emailing Attachments
report zfile_email_using_class.
data: ta_srgbtbrel type standard table of srgbtbrel, wa_srgbtbrel type srgbtbrel.
data: lta_sood type standard table of sood, lwa_sood type sood.
data: t_receivers type somlreci1 occurs 0 with header line.
*Specify Business Object Type and Key (BUS1065 = Employees)
parameters: p_key type swo_typeid obligatory default '00000111',
p_type type swo_objtyp obligatory default 'BUS1065',
p_recevr type so_recname obligatory default 'elvis@presley.com'.
start-of-selection.
data: t_st_return type zvnt_st_return.
data: ls_lporb type sibflporb.
data: lt_bapirettab type bapirettab.
ls_lporb-typeid = p_type.
ls_lporb-instid = p_key.
call method zcl_oh_my_gos_new=>gos_get_file_list
exporting
is_lporb = ls_lporb
importing
t_attachments = lta_sood
rt_messages = lt_bapirettab.
if lt_bapirettab[] is initial.
data dec_kb type p.
loop at lta_sood into lwa_sood.
dec_kb = lwa_sood-objlen / 1024.
if dec_kb < 1.
dec_kb = 1.
endif.
write: / lwa_sood-objdes, dec_kb, 'KB', ' ', lwa_sood-acnam.
clear t_receivers.
t_receivers-receiver = p_recevr.
t_receivers-rec_type = 'U'.
append t_receivers.
call method zcl_oh_my_gos_new=>gos_email_attached_file
exporting
folder_region = 'B'
doctp = lwa_sood-objtp
docyr = lwa_sood-objyr
docno = lwa_sood-objno
t_receivers = t_receivers[]
importing
rt_messages = lt_bapirettab.
if lt_bapirettab[] is initial.
write: '(Attachment Has Been Sent)'.
endif.
endloop.
endif.
Using the GOS (Generic Object Services) Class within ITS programs
Linked From Document: http://scn.sap.com/docs/DOC-41921
This last example demonstrates how to use the GOS class from within ITS applications.
Basic Setup
Create a program with one screen and a transaction.
Insert this code into the top include:
include avwrtcxm.
data: objtype type swo_objtyp.
data: objkey type swo_typeid.
data: g_dwnl_objtp like sood-objtp.
data: g_dwnl_objyr like sood-objyr.
data: g_dwnl_objno like sood-objno.
data: okcode like sy-ucomm.
data: save_ok_code like sy-ucomm.
data: dec_kb type p.
data: g_counter like sy-index.
data: g_lines like sy-tabix.
data: filelength type i.
data: it_content like standard table of soli.
data: mime_info like savwmpmime occurs 0 with header line.
data: lta_sood type standard table of sood.
data: lwa_sood type sood.
data: ls_lporb type sibflporb.
data: lt_bapirettab type bapirettab.
data: lv_objtyp type so_obj_tp.
data: l_file_name_with_path type avwctxcont.
data: mimetype type w3conttype.
data: g_filename type string.
data: g_download_content type soli_tab.
data: size type i.
data: t_receivers type somlreci1 occurs 0 with header line.
Screen 0100 Attributes:
Listing Attachments
module status_0100 output.
objtype = 'BUS1065'.
objkey = '00000111'.
ls_lporb-typeid = objtype.
ls_lporb-instid = objkey.
call method zcl_oh_my_gos_new=>gos_get_file_list
exporting
is_lporb = ls_lporb
importing
t_attachments = lta_sood
rt_messages = lt_bapirettab.
if lt_bapirettab[] is initial.
g_counter = 1.
describe table lta_sood lines g_lines.
field-set 'TOTAL_ATTACHMENTS' g_counter g_lines.
field-transport.
g_counter = 1.
loop at lta_sood into lwa_sood.
dec_kb = lwa_sood-objlen / 1024.
if dec_kb < 1.
dec_kb = 1.
endif.
field-set 'ATTACHMENTS_COL1' g_counter lwa_sood-objdes.
field-set 'ATTACHMENTS_COL2' g_counter dec_kb.
if lwa_sood-acnam <> ''.
field-set 'ATTACHMENTS_COL3' g_counter lwa_sood-acnam.
else.
field-set 'ATTACHMENTS_COL3' g_counter lwa_sood-file_ext.
endif.
field-set 'ATTACHMENTS_objtp' g_counter lwa_sood-objtp.
field-set 'ATTACHMENTS_objyr' g_counter lwa_sood-objyr.
field-set 'ATTACHMENTS_objno' g_counter lwa_sood-objno.
g_counter = g_counter + 1.
endloop.
field-transport.
endif.
endmodule. " STATUS_0100 OUTPUT
Uploading Attachments, Downloading Attachments, Emailing Attachments
module user_command_0100 input.
save_ok_code = sy-ucomm.
lv_objtyp = 'EXT'.
ls_lporb-typeid = objtype.
ls_lporb-instid = objkey.
case save_ok_code.
when 'FIUP'.
clear mime_info.
mime-info mime_info.
loop at mime_info.
mime-upload sy-tabix it_content filelength.
endloop.
move mime_info-contfname to l_file_name_with_path.
move mime_info-contfname to g_filename.
call method zcl_oh_my_gos_new=>gos_attach_file_solitab
exporting
iv_name = g_filename
iv_content_solitab = it_content
is_lporb = ls_lporb
iv_objtp = lv_objtyp
iv_filelength = filelength
receiving
rt_messages = lt_bapirettab.
if lt_bapirettab[] is initial.
leave to transaction 'ZGOS_NEW'.
endif.
when 'DOWN'.
"note: This code should really be put in the PBO of a new screen since the mime-download
"is the only processing completed.
if not ( g_dwnl_objtp is initial ) and
not ( g_dwnl_objyr is initial ) and
not ( g_dwnl_objno is initial ).
call method zcl_oh_my_gos_new=>gos_get_file_solitab
exporting
folder_region = 'B'
doctp = g_dwnl_objtp
docyr = g_dwnl_objyr
docno = g_dwnl_objno
importing
o_content_solitab = g_download_content
o_mimetype = mimetype
o_filelength = size
rt_messages = lt_bapirettab.
if lt_bapirettab[] is initial.
mime-download g_download_content size mimetype.
endif.
endif.
when 'EMAIL'.
if not ( g_dwnl_objtp is initial ) and
not ( g_dwnl_objyr is initial ) and
not ( g_dwnl_objno is initial ).
clear t_receivers.
t_receivers-receiver = 'elvis@presley.com'.
t_receivers-rec_type = 'U'.
append t_receivers.
call method zcl_oh_my_gos_new=>gos_email_attached_file
exporting
folder_region = 'B'
doctp = g_dwnl_objtp
docyr = g_dwnl_objyr
docno = g_dwnl_objno
t_receivers = t_receivers[]
importing
rt_messages = lt_bapirettab.
endif.
endcase.
endmodule. " USER_COMMAND_0100 INPUT
ITS HTML
<html>
<head>
<title>`~windowtitle`</title>
</head>
<body>
`~messageline`
<!--BEGIN UPLOAD FILE PROCESSING-->
<form method="post" enctype="multipart/form-data" action="`WGateURL()`">
<p><CENTER><INPUT TYPE="FILE" size="50" NAME="LOCALFILE1"></CENTER></p>
<p><CENTER><INPUT TYPE="SUBMIT" NAME="~OkCode(FIUP)" VALUE="Upload File"></CENTER></p>
</form>
<!--END UPLOAD FILE PROCESSING-->
<!--BEGIN DOWNLOAD FILE PROCESSING-->
`if (TOTAL_ATTACHMENTS > 0)`
<CENTER>
<TABLE border=1>
<TH colspan=3>
<font face="arial, helvetica" class="style5" size="2">Attached Documents</font>
</TH>
<TR><TD></TD></TR>
`end`
`repeat with j from 1 to TOTAL_ATTACHMENTS`
<FORM NAME="`ATTACHMENTS_DOWN_objno[j]`"
ACTION = "`wgateURL(~OKCode="DOWN")`&g_dwnl_objtp=`ATTACHMENTS_objtp[j]`&g_dwnl_objyr=`ATTACHMENTS_objyr[j]`&g_dwnl_objno=`ATTACHMENTS_objno[j]`"
METHOD="post">
<TR>
<TD>
<font face="arial, helvetica" class="style5" size="2">
<INPUT TYPE="submit" name="" value="Download File">
</font>
</TD>
<TD>
<font face="arial, helvetica" class="style5" size="2">
`ATTACHMENTS_COL1[j]` (`ATTACHMENTS_COL2[j]`KB )
</font>
</TD>
<TD align=center>
<font face="arial, helvetica" class="style5" size="2">
  `ATTACHMENTS_COL3[j]`  
</font>
</TD>
</TR>
</FORM>
`end`
`if (TOTAL_ATTACHMENTS > 0)`
</TABLE>
</CENTER>
`end`
<!--END DOWNLOAD FILE PROCESSING-->
<p><p>
<!--BEGIN EMAIL FILE PROCESSING-->
`if (TOTAL_ATTACHMENTS > 0)`
<CENTER>
<TABLE border=1>
<TH colspan=3>
<font face="arial, helvetica" class="style5" size="2">Attached Documents</font>
</TH>
<TR><TD></TD></TR>
`end`
`repeat with j from 1 to TOTAL_ATTACHMENTS`
<FORM NAME="`ATTACHMENTS_EMAIL_objno[j]`"
ACTION = "`wgateURL(~OKCode="EMAIL")`&g_dwnl_objtp=`ATTACHMENTS_objtp[j]`&g_dwnl_objyr=`ATTACHMENTS_objyr[j]`&g_dwnl_objno=`ATTACHMENTS_objno[j]`"
METHOD="post">
<TR>
<TD>
<font face="arial, helvetica" class="style5" size="2">
<INPUT TYPE="submit" name="" value="Email File">
</font>
</TD>
<TD>
<font face="arial, helvetica" class="style5" size="2">
`ATTACHMENTS_COL1[j]` (`ATTACHMENTS_COL2[j]`KB )
</font>
</TD>
<TD align=center>
<font face="arial, helvetica" class="style5" size="2">
  `ATTACHMENTS_COL3[j]`  
</font>
</TD>
</TR>
</FORM>
`end`
`if (TOTAL_ATTACHMENTS > 0)`
</TABLE>
</CENTER>
`end`
<!--END EMAIL FILE PROCESSING-->
</body>
</html>
RESULT
Everything GOS (Generic Object Services)
I've discussed GOS in prior documents. But never have I put together a complete GOS document that demonstrates how to create a generic GOS class that can be used in regular SAP GUI programs, ABAP Web DynPro applications, and even ITS (Internet Transaction Server) based applications. This document discusses how to use GOS functionality (Upload, Download, List, Delete) in all those environments. Don't ask me why I chose to put a sample together for ITS applications. I just figured there may be an interest in still developing applications using ITS since it's still available and it's a lot of fun.
There a many parts to this document, but it is broken down logically to allow you to go directly to the part you are most interested in.
The class that does all the work (http://scn.sap.com/docs/DOC-41922)
CLASS ATTRIBUTES
GOS_GET_FILE_LIST
GOS_DOWNLOAD_FILE_TO_GUI
GOS_GET_FILE_XSTRING
GOS_GET_FILE_SOLITAB
GOS_ATTACH_FILE_XSTRING
GOS_ATTACH_FILE_SOLITAB
GOS_EMAIL_ATTACHED_FILE
GOS_DELETE_FILE
Using the GOS Class within classic GUI programs (http://scn.sap.com/docs/DOC-41923)
Listing Attachments
Uploading Attachments
Downloading Attachments
Emailing Attachments
Using the GOS Class within ABAP WebDynpro applications (http://scn.sap.com/docs/DOC-41925)
Basic Setup
Listing Attachments
Uploading Attachments, Downloading Attachments, Deleting Attachments
RESULT
Using the GOS Class within ITS programs (http://scn.sap.com/docs/DOC-41924)
Basic Setup
Top Include
Screen 0100 Attributes
Listing Attachments
Uploading Attachments, Downloading Attachments, Emailing Attachments
ITS HTML
RESULT
Source code for Dynamic Report from flat file
Below set of code was used to execute the report prom from flat file.
*&---------------------------------------------------------------------*
*& Report Z_DYNAMIC_REPORT
*&---------------------------------------------------------------------*
* Execute ABAP report from a PC file(.txt)Therefor allowing any *
* abap code to be executed on any clientwhich contains this program *
*&---------------------------------------------------------------------*
REPORT z_dynamic_report.
TABLES rlgrap.
*selection screen creation
PARAMETER: p_file(200) TYPE c,
p_temp(30) TYPE c DEFAULT 'Z_REPORT_FOR_CODE'.
*data declaration
DATA: it_tab TYPE filetable,
gd_subrc TYPE i,
answer TYPE c.
TYPES: BEGIN OF t_abapcode,
row(72) TYPE c,
END OF t_abapcode.
DATA: it_abapcode TYPE STANDARD TABLE OF t_abapcode INITIAL SIZE 0,
it_store TYPE STANDARD TABLE OF t_abapcode INITIAL SIZE 0.
DATA: filename TYPE string.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*Selecting a File, plus inserting default file extension
REFRESH: it_tab.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Select File'
default_filename = '*.txt'
multiselection = ' '
CHANGING
file_table = it_tab
rc = gd_subrc.
START-OF-SELECTION.
filename = p_file.
*upload file from PC
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
TABLES
data_tab = it_abapcode
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc EQ 0.
* Check if report name being used fro temorary code already exists as
* any code will be over written and lost
READ REPORT p_temp INTO it_store.
IF sy-subrc NE 0.
* Please note any existing code in the program will be lost!!!!
INSERT REPORT p_temp FROM it_abapcode.
SUBMIT (p_temp) AND RETURN.
DELETE REPORT p_temp.
ELSE.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
text_question = 'Report used to store temporary code already exists!!! Do you want to overwrite it?'
IMPORTING
answer = answer.
IF sy-subrc EQ 0.
IF answer EQ '1'. "yes
* Please note any existing code in the program will be lost!!!!
INSERT REPORT p_temp FROM it_abapcode.
SUBMIT (p_temp) AND RETURN.
DELETE REPORT p_temp.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
kindly provide your valuable comments,
How to Create a Custom Print program with Smartforms for Payment Instruments(like Cheque,Payorder e.t.c) in SAP FI(Financials)(Transactions = F-58,FBZ5,FBZP)?
How to Create a Custom Print program with Smartforms for Payment Instruments(like Cheque,Payorder e.t.c) in SAP FI(Financials)(Transactions = F-58,FBZ5,FBZP)?
There are various payment instruments available in SAP FI,each of which is denoted technically in sap by the term 'Payment method'. Some of these instruments include 'Cheque Payment','Cash Payment','Payment Order','Bank Transfer PLS','Bank Transfer Current' e.t.c. Cheque and Payorder are the most commonly used instruments. Of course the FI consultant can create custom payment methods and map them to a country,by going to the following menu path in IMG(Customizing):
Financial Accounting(New) > Accounts Receivable and Accounts Payable > Business Transactions > Incoming Payments > Automatic Incoming Payments > Payment Method/Bank Selection for Payment Program > Set Up Payment Methods per Country for Payment Transactions
The name of the Standard Print Program for these Payment Instruments is 'RFFOUS_C'. If you look closely at this program,you will find an include named 'RFFORI01',this include program will contain SAP Scrip statements such as 'OPEN_FORM','WRITE_FORM' and 'CLOSE_FORM' e.t.c.,which can easily be opened in SAP Script Form transaction of 'SE71'. For example the default SAP Script attached to a cheque Payment instrument is 'F110_PRENUM_CHCK'. The standard print program 'RFFOUS_S' already contains pre-populated Payment instrument data in the form of structures,that can be added to a custom structure or internal table and passed to a smartform or an SAP Script.
Standard Structures pre-populated with data in the Standard Print Program:
The standard Structures that will be helpful for passing in data,include the following:
(01)REGUH(Settlement data from payment program):
This structure includes information related to the payment instrument such as:
(A)Vendor or Payee Number(reguh-empfg+1(10),reguh-lifnr)
(B)Vendor or Payee Name(reguh-znme1,reguh-znme2)
(C)Cheque Date(reguh-laufd)
(D)Cheque Amount in Number(reguh-rbetr)[Note: you can use the function module 'SPELL_AMOUNT' for converting the given cheque amount into words]
(E)Bank Document Number(reguh-belnr)
(F)Bank Document Date(reguh-laufd)
(G)Vendor or Payee Address Line(reguh-stras)
(H)Vendor or Payee City(reguh-ort01)
(02)REGUD(Form print transfer data):
This structure includes information related to the payment instrument such as:
(A)Cheque Number(reguh-chect)[This is basically is the lot number for the payment instrument which is defined as a series by the FI functional Consultant]
(03)PAYR(Payment Medium File):
This structure includes fields such as:
(A)short key for House Bank(payr-HBKID)(This can be used for determining the Payment Instrument being currently used)
(B)Cheque number(payr-CHECT)
(C)Currency key(payr-WAERS)
(D)Print User(payr-PRIUS)
(E)Bank number of the payee's bank(payr-ZBNKL)
(F)Name of the payee(payr-ZNME1)
(G)Title of the payee(payr-ZANRE)
(H)Fiscal Year(payr-GJAHR)
(I)Paying company code(payr-ZBUKR)
[Note]: To see all the fields in these structures,you can enter them in the Data Dictionary Transaction(SE11),to see a list of all the fields.
> The Print Program for these Payment instruments can be invoked in 2 ways:
(01)By posting a document for the given payment methods,you will be prompted to print that,using the Transaction 'F-58'(Payment with Printout:Header Data).
(02)By printing documents that have already been printed using the transaction 'FBZ5'(Print Form for Payment Document).
Procedure for attaching the Smartform in place of the standard Print Program(RFFOUS_C):
In order to attach the smartform,you need to create a replica of the Standard Print Program(RFFOUS_C) in customer namespace e.g: 'ZRFFOUS_C'.Next you will need to attach this replica in place of the standard program,by going to the Transaction 'FBZP'(Maintain Payment Program) and then click the 'Pmnt methods in country' button,in the position button enter in the 'country code',in our case it is PK(Pakistan) and the 'payment method' lets say 'C'(Cheque payment) Just Double click the payment method for which you want to attach the program. Now in the 'Payment medium' section,copy the name of your custom replica program within the 'Payment medium program' input field,just below the 'Use classic payment medium programs(RFFO)*' radio button and then click the save button to save this. This attaches your custom print program instead of the standard print program.
You can attach the same custom replica program on all payment methods and use conditional constructs to launch the relevant smarforms for each of the payment instruments. you can use a field such as 'short key for House Bank'(reguh-HBKID) to select whether the Payment method is 'NBPC'(custom created for the NBP project) cheque or Payorder 'NBPP'((custom created for the NBP project)) [OR] you can use the 'Payment Method for This Payment' field(reguh-RZAWE) to check for the payment method 'C'(For Cheque) and 'E'(For Payorder).
Figure 01(A) : Attaching Print Program in FBZP 'paymnt methods in country' |
---|
![]() |
Figure 01(B) : Position button country code to seek out payment methods |
---|
![]() |
Figure 01(C) : Select the Payment Method Row and click details button in ApplicationToolbar |
---|
![]() |
Figure 01(D) : Attaching Print Program in FBZP and Click Save button to assign |
---|
![]() |
Sample Source Code:
IF reguh-RZAWE EQ 'C'."A - Load Smartform for a Cheque [Payment Method = C(Cheque)]
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZFJ_FI_VENDOR_CHEQUE'
IMPORTING
fm_name = fname.
CALL FUNCTION fname
EXPORTING
header_data = header_data"Header Data
TABLES
item_data = item_data."Item Data
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
elseIF reguh-RZAWE EQ 'E'."B - Load Smartform for a Payorder [Payment Method = E(Payorder)]
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZFJ_FI_VENDOR_PAYORDER'
IMPORTING
fm_name = fname.
CALL FUNCTION fname
EXPORTING
header_data = header_data
TABLES
item_data = item_data.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
Testing the Final Cheque or Payorder:
In order to test the newly attached replica of Payment Instrument Print program,you have the following 2 ways:
(A) At the Time of posting the document at runtime using transaction F-58:
> When you post a document via the F-58 transaction,you will be prompted to print the payment instrument then and there. In case you have skipped that step,you can use the second method to print it.
(B)Using the Transaction FBZ5 for printing Payment Instruments based on already posted documents,incase the user did not print them while posting them:
> You can print Already posted documents in Transaction FBZ5(Print form for Payment Document). You need to provide in details such as document number,company code,Fiscal year,payment method e.t.c. Just make sure that you have checked the 'Print Immediately' checkbox. Now go the following menu path:
Check > Print > Old Check
This will trigger you custom program and select the smartform based on the selection provided in the Payment Method field. You can even set a breakpoint in your custom program to check whether its working or not. You can then print the payment instrument like cheque or payorder,or seek out a Print Preview of the smartform.
Figure 02(A) : Checking Vendor Cheque(FBZ5) |
---|
![]() |
Figure 02(B) : Checking Vendor Payorder(FBZ5) |
---|
![]() |
Figure 03(A) : Final Cheque Smartform Output |
---|
![]() |
Figure 03(A) : Final Payorder Smartform Output |
---|
![]() |
[Tip]:You can seek out all documents already posted by looking into a Transparent table named 'PAYR' (Payment Medium File). Its also populated as a structure when the Standard Print program or your custom replica of it is invoked. Details from this table can be used for printing these payment instruments in the FBZ5 Transaction.
> In case the data is not fetched from the Standard Structures,you will need to write alternate code for fetching it for example vendor details can be fetched from the Vendor Master data table named 'LFA1'(Vendor Master) or from Customer Master data based in the table named 'KNA1'(Customer Master).
Legal
Fahad Javed's Copyrights
All Screen Shots taken,Fahad Javed's Logo are copyrights © 2010-2013 Fahad Javed. All Rights Reserved.
All the material written is a labour of hardwork carried out by the author. Kindly don't copy this material for commercial purposes. If a link is provided do provide the accredition to the author as follows:'© 2010-2013 Fahad Javed. All rights reserved.'.
All the terms used are copyrights of SAP AG © 2013 SAP AG. All rights reserved. See the section 'SAP - Copyrights and Trademarks' for further details.
SAP - Copyrights and Trademarks
© 2013 SAP AG. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.
Microsoft, Windows, Excel, Outlook, PowerPoint, Silverlight, and Visual Studio are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, z10, z/VM, z/OS, OS/390, zEnterprise, PowerVM, Power Architecture, Power Systems, POWER7, POWER6+, POWER6, POWER, PowerHA, pureScale, PowerPC, BladeCenter, System Storage, Storwize, XIV, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, AIX, Intelligent Miner, WebSphere, Tivoli, Informix, and Smarter Planet are trademarks or registered trademarks of IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the United States and other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are trademarks or registered trademarks of Adobe Systems Incorporated in the United States and other countries.
Oracle and Java are registered trademarks of Oracle and its affiliates.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems Inc.
HTML, XML, XHTML, and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology.
Apple, App Store, iBooks, iPad, iPhone, iPhoto, iPod, iTunes, Multi-Touch, Objective-C, Retina, Safari, Siri, and Xcode are trademarks or registered trademarks of Apple Inc.
IOS is a registered trademark of Cisco Systems Inc.
RIM, BlackBerry, BBM, BlackBerry Curve, BlackBerry Bold, BlackBerry Pearl, BlackBerry Torch, BlackBerry Storm, BlackBerry Storm2, BlackBerry PlayBook, and BlackBerry App World are trademarks or registered trademarks of Research in Motion Limited.
Google App Engine, Google Apps, Google Checkout, Google Data API, Google Maps, Google Mobile Ads, Google Mobile Updater, Google Mobile, Google Store, Google Sync, Google Updater, Google Voice, Google Mail, Gmail, YouTube, Dalvik and Android are trademarks or registered trademarks of Google Inc.
INTERMEC is a registered trademark of Intermec Technologies Corporation.
Wi-Fi is a registered trademark of Wi-Fi Alliance.
Bluetooth is a registered trademark of Bluetooth SIG Inc.
Motorola is a registered trademark of Motorola Trademark Holdings LLC.
Computop is a registered trademark of Computop Wirtschaftsinformatik GmbH.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP BusinessObjects Explorer, StreamWork, SAP HANA, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries.
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects Software Ltd. Business Objects is an SAP company.
Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere, and other Sybase products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Sybase Inc. Sybase is an SAP company.
Crossgate, m@gic EDDY, B2B 360°, and B2B 360° Services are registered trademarks of Crossgate AG in Germany and other countries. Crossgate is an SAP company.
All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.
These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
LSMW for Vendor Master
The objective of this document is to help consultants understand how Vendor Master data can be uploaded by LSMW using direct input method.
Mass Change of Specific Condition Type Value in Purchase Orders
SAP ECC 6.0. For more information, visit the ABAP homepage.
Summary
This article describes the procedure to change a specific condition type value in Purchase Orders.
Author:
Company:
- Business Requirement
- Transactions
- Module
- Functionality
- Step by Step Procedure
3. Module
Material Management (MM)
BAPI_PO_CHANGE - Function module BAPI_PO_CHANGE enables you to change purchase orders. The Change method uses the technology behind the online transaction ME22N.
5. Step by step procedure
I. Get the required data from tables KONV, EKKO and EKPO based on required Condition Type (Eg: ZXYZ) into an internal table.
DELETE i_pocond WHERE cond_type NE 'ZXYZ'.
VII. If there are no error messages in i_return table then call function module BAPI_TRANSACTION_COMMIT
to update the changes to Database tables.
VIII.Now All the POs which are in internal table will be updated with new value for condition type ZXYZ.
Thanks & Regards,
Shravan Kumar N
Function Module to archiving file in Application server
This Function Module is mainly used in Interface type of objects.
One specific selection screen frame must be added to feed the function module call for each file read (with file name and repository for archiving).
Function module ZFILE_ARCHIVE is created for that purpose.
Local Interface:
IMPORTING
VALUE(I_SFILE) TYPE LOCALFILE (Source Filepath)
VALUE(I_DPATH) TYPE LOCALFILE (Destination Filepath)
VALUE(I_FILENAME) TYPE LOCALFILE (Filename)
EXCEPTIONS
ERROR_OPENING_SOURCE_FILE
ERROR_OPENING_TARGET_FILE
In the source code write the below code:
* Variables
DATA : lv_data TYPE string,
lv_len TYPE char02,
lv_archvive TYPE localfile.
lv_len = strlen( i_filename ).
lv_len = lv_len - 4.
* Filename has extension or not
IF i_filename+lv_len(1) EQ '.'.
lv_archvive = i_dpath.
ELSE.
CONCATENATE i_dpath " Destination path
i_filename " File name without extension
sy-datum " Sys date
sy-uzeit " Sys time
INTO lv_archvive.
ENDIF.
OPEN DATASET i_sfile IN LEGACY TEXT MODE FOR INPUT IGNORING CONVERSION ERRORS.
IF sy-subrc NE 0.
RAISE error_opening_source_file.
ENDIF.
OPEN DATASET lv_archvive IN LEGACY TEXT MODE FOR APPENDING IGNORING CONVERSION ERRORS.
IF sy-subrc NE 0.
RAISE error_opening_target_file.
ENDIF.
* copy the file from source to destination
DO.
READ DATASET i_sfile INTO lv_data.
IF sy-subrc EQ 0.
TRANSFER lv_data TO lv_archvive.
CLEAR lv_data.
ELSE.
EXIT.
ENDIF.
ENDDO.
* Delete the source file after copy
DELETE DATASET i_sfile.
* Close all open dataset
CLOSE DATASET: i_sfile,
lv_archvive.
CLEAR : lv_data.
Eg:
Selection Screen
Logical Path for Source File is the path from where the file is retrieved from Application Server.
Logical Path for archieve file is the path to where the file is archieved to the Application Server using the Function Module 'ZFILE_ARCHIVE'.
Dynamic call to a functional method (that has no import elements)
I was in the need to make a dynamic call from within an ABAP class method to a functional method, which isn't known at compile time. The class can be subtyped, and from anywhere down the class hierarchy, this generic method should return the value of any functional method.
The short-cut statement would be great to use ..l like this:
ev_value = me->(lv_dynamic_method_name)( ).
but the ABAP compiler only allows to use dynamic calls with the full statement
CALL METHOD (lv_dynamic_method_name) RECEIVING rv_value = ev_value.
But in difference to the first short-cut solution, you have to know the name of the receiving parameter (likewise with a naming convention) or retrieve it somehow. As I disliked to create a development rule to name all returning parameter RV_VALUE, I was bound to use the runtime type description.
And here is the template to make such a dynamic call, without knowing the actual parameter name of the receiving element.
method GET_RECEIVING_PARAMETER.
"Get the class description of myself
DATA: lo_typeDescription TYPE REF TO CL_ABAP_TYPEDESCR.
lo_typeDescription = CL_ABAP_TYPEDESCR=>DESCRIBE_BY_OBJECT_REF( me ).
CHECK lo_typeDescription->type_kind = CL_ABAP_TYPEDESCR=>typekind_class.
"Only ABAP OO Classes are allowed
DATA: lo_classDescription TYPE REF TO CL_ABAP_CLASSDESCR.
lo_classDescription ?= lo_typeDescription.
FIELD-SYMBOLS: <ls_method_definition> TYPE abap_methdescr.
READ TABLE lo_classDescription->methods ASSIGNING <ls_method_definition>
WITH KEY name = iv_methodName.
CHECK sy-subrc = 0. "Yes, we really need the method to be
"existing to deliver the receiving type
"Retrieve the name of the receiving parameter
FIELD-SYMBOLS: <ls_receiving_parameter> TYPE LINE OF abap_parmdescr_tab.
READ TABLE <ls_method_definition>-parameters ASSIGNING <ls_receiving_parameter>
WITH KEY parm_kind = CL_ABAP_CLASSDESCR=>RECEIVING.
CHECK sy-subrc = 0.
ls_receiving_parameter-name = <ls_receiving_parameter>-name.
ls_receiving_parameter-kind = <ls_receiving_parameter>-parm_kind.
"To-Be assigned by caller: structure field VALUE filled with a type ref to data,
"by using the statements:
" GET REFERENCE OF <your-variable-name> INTO ls_receiving_parameter-value.
" APPEND ls_receiving_parameter TO lt_parameter_table.
" CALL METHOD (lv_method_name) PARAMETER TABLE lt_parameter_table.
"
" After that call you can find the result in the variable, that you've used with
" the GET REFERENCE statement.
endmethod.
And the dynamic call is simply something like this:
DATA: lt_parameter_table TYPE ABAP_PARMBIND_TAB,
ls_receiving_parameter TYPE LINE OF ABAP_PARMBIND_TAB.
ls_receiving_parameter = me->get_receiving_parameter( lv_methodname ).
IF ls_receiving_parameter IS INITIAL.
"We have a problem, so we leave the returned value blank now
EXIT.
ENDIF.
GET REFERENCE OF ev_value INTO ls_receiving_parameter-value.
INSERT ls_receiving_parameter INTO TABLE lt_parameter_table.
CALL METHOD (lv_methodname) PARAMETER-TABLE lt_parameter_table.
Take care
Florin Wach
Systems-Integration
SAP Business Workflow Senior-Expert
Sending Mail using Oo
You can use the function SO_NEW_DOCUMENT_SEND_API1 to send an email from SAP, but you could also use Oo.
Example of simple HTML mail with Oo.
Data declaration
DATA : obj_mime_helper TYPE REF TO cl_gbt_multirelated_service ,
obj_bcs TYPE REF TO cl_bcs ,
obj_doc_bcs TYPE REF TO cl_document_bcs ,
obj_recipient TYPE REF TO if_recipient_bcs ,
w_status TYPE bcs_rqst ,
is_soli TYPE soli ,
it_soli TYPE TABLE OF soli .
Creation of the mail
* Create the main object of the mail.
CREATE OBJECT obj_mime_helper.
* Create the mail content.
MOVE '<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">' TO is_soli-line.
APPEND is_soli TO it_soli.
MOVE '<HTML>' TO is_soli-line.
APPEND is_soli TO it_soli.
MOVE '<BODY>' TO is_soli-line.
APPEND is_soli TO it_soli.
MOVE '<P>Hello world !</P>' TO is_soli-line.
APPEND is_soli TO it_soli.
MOVE '</BODY>' TO is_soli-line.
APPEND is_soli TO it_soli.
MOVE '</HTML>' TO is_soli-line.
APPEND is_soli TO it_soli.
* Set the HTML body of the mail
CALL METHOD obj_mime_helper->set_main_html
EXPORTING
content = it_soli
filename = ''
description = 'Hello world'.
* Set the subject of the mail.
obj_doc_bcs = cl_document_bcs=>create_from_multirelated(
i_subject = 'Mail example'
i_importance = '9' " 1 / 5 / 9
i_multirel_service = obj_mime_helper ).
obj_bcs = cl_bcs=>create_persistent( ).
obj_bcs->set_document(
i_document = obj_doc_bcs ).
* Set the email address
obj_recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = 'toto@titi.com' ).
obj_bcs->add_recipient(
i_recipient = obj_recipient ).
* Change the status.
MOVE 'N' TO w_status.
CALL METHOD obj_bcs->set_status_attributes
EXPORTING
i_requested_status = w_status.
* Send the mail.
obj_bcs->send( ).
* Commit Work.
IF sy-subrc EQ space.
COMMIT WORK AND WAIT.
ELSE.
ROLLBACK WORK.
ENDIF.
Result
Go in transaction SOST to see the mail :
The sender is the user who ran the program.
Example of mail with a simple attachment
Data declaration (add)
w_attach_type TYPE so_obj_tp ,
w_attach_subject TYPE so_obj_des ,
w_attach_length TYPE sood-objlen ,
w_rc TYPE i ,
w_filename TYPE string ,
w_length TYPE i ,
is_file TYPE file_table ,
it_file TYPE filetable ,
it_file_content TYPE TABLE OF solix.
Open the file
* Get the filename of the input file.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
CHANGING
file_table = it_file
rc = w_rc
EXCEPTIONS
OTHERS = 5.
CHECK sy-subrc EQ space AND
NOT it_file[] IS INITIAL.
* Get the first line (single selection)
READ TABLE it_file
INTO is_file
INDEX 1.
CHECK sy-subrc EQ space.
MOVE is_file-filename TO w_filename.
* Read the file and put it in the internal table
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = w_filename
filetype = 'BIN'
IMPORTING
filelength = w_length
CHANGING
data_tab = it_file_content
EXCEPTIONS
OTHERS = 19.
it's really an easy example, there is no need to convert the file content.
Insert the attachment in the mail
MOVE : 'PDF' TO w_attach_type ,
w_filename TO w_attach_subject ,
w_length TO w_attach_length .
CALL METHOD obj_doc_bcs->add_attachment
EXPORTING
i_attachment_type = w_attach_type
i_attachment_subject = w_attach_subject
i_attachment_size = w_attach_length
i_att_content_hex = it_file_content.
For this example, I force the attachment type to PDF, but it could be anything.
Used the method ADD_ATTACHMENT after the creation of the object OBJ_DOC_BCS or you will have a dump.
Result
The mail didn't change, but there is a new tab in the message detail : Attachments
I have keep the full location of the filename, but you could keep only the filename.
Modify the sender
It's something useful to change the sender of an email. For example, when you send the mail to a customer and you didn't want he replies to you but to a generic mail box like customer-suport@mycompany.com
Data declaration (add)
obj_sender TYPE REF TO if_sender_bcs .
PARAMETERS : p_sender TYPE ad_smtpadr.
Modify the sender in the OBJ_BCS
* Modify the sender
obj_sender = cl_cam_address_bcs=>create_internet_address(
i_address_string = p_sender ).
obj_bcs->set_sender( i_sender = obj_sender ).
Result
In my example you could choose the email address of the sender.
In the RFC of the SMTP is not really allowed to send a mail from a domain different of the mail address. That means, my SMTP server must refused to send a mail from @sap.com because I'm not owner of this domain. You could have a message like : "SMTP relaying denied"
(next step, Mail of a Smartforms)
Fred
Download Complete Spool Including Long Text And Special Characters
Overview
Text spool can be viewing using transaction SP01.
Spool can be seen on following display modes:
- Graphical
- Raw
- Hex
If spool has lines longer than 255 characters and contains accented characters like chèque, none of above modes allow user to download spool to local text file without loss of information. A program was written to overcome this.
Technical Details
Graphical display mode shows accented characters, but it truncates lines longer than 255 characters.
Raw display mode shows long lines without truncation, but it shows # instead of accented characters.
Hex display mode shows 3 times the lines in Raw mode. In every 3 line set, 1st line is similar to Raw mode text and 2nd and 3rd lines show hex equivalent code.
Program essentially reads the Hex mode spool stored in local text file, converts hex codes and generates local spool file.
Input file: C:\input.txt should have Hex mode spool contents downloaded using Download button or Menu System > List > Save > Local file.
Output file: C:\output.txt file would have desired spool content once program is run.
Logic
Assuming spool has only one word CHEÈQUE, spool content in Hex mode would be something like this:
|CHE#QUE
2|444C554
0|3858155
Hex code for È is C8. In the above example, the hex code is placed in same column as original character, but in lines 2nd and 3rd. This is the reason why characters below È are C and 8.
Program will read the data and store lines starting with 2| (first half of hex code) and 0| (second half of hex code) in separate internal tables.
The internal tables would then be merged to form hex code written left to right. For above data, merged hex code would be 434845C8515545.
The merged internal table would be converted from hex to string using function module.
Converted text would be download to C:\output.txt.
Code Snippet
TYPES:
tty_string TYPE TABLE OF string,
BEGIN OF ty_pair,
first TYPE string,
second TYPE string,
END OF ty_pair,
tty_pair TYPE TABLE OF ty_pair.
DATA: gv_path TYPE string,
gt_input TYPE TABLE OF string.
gv_path = 'c:\input.txt'.
PERFORM read_local_file USING gv_path CHANGING gt_input[].
DATA: gv_identifier1 TYPE string,
gv_identifier2 TYPE string,
gt_pair TYPE TABLE OF ty_pair.
gv_identifier1 = '2|'.
gv_identifier2 = '0|'.
PERFORM extract_hex_pairs USING gt_input[] gv_identifier1 gv_identifier2 CHANGING gt_pair[].
DATA gt_merged TYPE TABLE OF string.
PERFORM hex_merge USING gt_pair CHANGING gt_merged.
DATA gt_output TYPE TABLE OF string.
PERFORM hex_to_string USING gt_merged CHANGING gt_output.
gv_path = 'c:\output.txt'.
PERFORM write_local_file USING gv_path gt_output.
*&---------------------------------------------------------------------*
*& Form READ_LOCAL_FILE
*&---------------------------------------------------------------------*
FORM read_local_file USING pv_path TYPE string
CHANGING ct_data TYPE tty_string.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = pv_path
TABLES
data_tab = ct_data
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
ENDFORM. " READ_LOCAL_FILE
*&---------------------------------------------------------------------*
*& Form EXTRACT_HEX_PAIRS
*&---------------------------------------------------------------------*
FORM extract_hex_pairs USING pt_input TYPE tty_string
pv_identifier1 TYPE string
pv_identifier2 TYPE string
CHANGING ct_pair TYPE tty_pair.
DATA: lv_input TYPE string,
lv_offset TYPE i,
ls_pair TYPE ty_pair,
lv_length TYPE i,
lv_dummy TYPE c LENGTH 9999.
lv_length = STRLEN( pv_identifier1 ).
LOOP AT pt_input INTO lv_input.
FIND FIRST OCCURRENCE OF pv_identifier1 IN lv_input MATCH OFFSET lv_offset.
IF sy-subrc EQ 0.
lv_dummy = lv_input.
ls_pair-first = lv_input+lv_length.
ENDIF.
FIND FIRST OCCURRENCE OF pv_identifier2 IN lv_input MATCH OFFSET lv_offset.
IF sy-subrc EQ 0.
lv_dummy = lv_input.
ls_pair-second = lv_dummy+lv_length.
APPEND ls_pair TO ct_pair.
CLEAR: ls_pair.
ENDIF.
ENDLOOP.
ENDFORM. " EXTRACT_HEX_PAIRS
*&---------------------------------------------------------------------*
*& Form HEX_MERGE
*&---------------------------------------------------------------------*
FORM hex_merge USING pt_pair TYPE tty_pair
CHANGING ct_merged TYPE tty_string.
DATA: ls_pair TYPE ty_pair,
lv_merged TYPE string,
lv_offset TYPE i,
lv_length TYPE i.
LOOP AT pt_pair INTO ls_pair.
lv_length = STRLEN( ls_pair-first ).
lv_offset = 0.
DO lv_length TIMES.
CONCATENATE lv_merged
ls_pair-first+lv_offset(1)
ls_pair-second+lv_offset(1)
INTO lv_merged.
lv_offset = lv_offset + 1.
ENDDO.
APPEND lv_merged TO ct_merged.
CLEAR lv_merged.
ENDLOOP.
ENDFORM. " HEX_MERGE
*&---------------------------------------------------------------------*
*& Form HEX_TO_STRING
*&---------------------------------------------------------------------*
FORM hex_to_string USING pt_input TYPE tty_string
CHANGING ct_output TYPE tty_string.
DATA: lv_input TYPE xstring,
lv_output TYPE string.
LOOP AT pt_input INTO lv_input.
CALL FUNCTION 'LXE_COMMON_XSTRING_TO_STRING'
EXPORTING
in_xstring = lv_input
in_codepage = '1100'
IMPORTING
ex_string = lv_output
EXCEPTIONS
error = 1
OTHERS = 2.
APPEND lv_output TO ct_output.
CLEAR lv_output.
ENDLOOP.
ENDFORM. " HEX_TO_STRING
*&---------------------------------------------------------------------*
*& Form WRITE_LOCAL_FILE
*&---------------------------------------------------------------------*
FORM write_local_file USING pv_path
pt_input TYPE tty_string.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = pv_path
TABLES
data_tab = pt_input
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.
ENDFORM. " WRITE_LOCAL_FILE
EHS: Adding search in CG02
With standard SAP, specification can be searched for only
one material. Using this document, specifications can be searched for
multiple materials.
Create FM ZEHS_OCC_SUB_FIND_BY_MAT_PARA with code in attached
the FM_PARA. This FM will be called to enter different materials(Selection )
Create FM ZEHS_OCC_SUB_FIND_BY_MAT with code in attached the
FM document. This FM to get materials for the selection
Create FM ZEHS_OCC_SUB_FIND_BY_MAT_CMD with code in attached
the FM_CMD. This FM to display the search results
EHS->Basic data->Basic settings->user exits->create below entry
After above steps, CG02 shows with above extended functionality
Using dirty assigns in practice - using calling variables for indirect wagetype evaluation
In standard, SAP provides several BAdIs and user exits to enhance applications or include custom logic flows into standard reports and dynpros. Most of the time these enhancing possibilities are sufficient, but there might come a time when a BAdI or user exit should be used, but the method’s or form’s signature isn't sufficient. One might use variables, present in the calling routine but not passed inside the current method.
To overcome this issue, there is a way called “dirty assign” that can be used. From within any abap program, class method or form, it is possible to get access to the variables of the calling routine.
The main thing about a dirty assign is using a field symbol and assigning this to a variable of the calling routine. I once had to implement a custom function for indirect evaluation of wage types in infotype 8 in HCM. SAP provides a BAdI where customer specific evaluation methods can be defined. The evaluation I had to do was based on the current activity rate of the employee, entered on the screen. As this value isn't yet saved and the value isn't passed to my BAdI’s method, I had to use a dirty assign to fetch the entered values on the dynpro.
Looking at the code in my method now, I first hat to declare a field symbol:
FIELD-SYMBOLS: <ptr> TYPE prelp.
After looking through the code of infotyp 8, I realized that the values entered on the dynpro are present in the variable cprel at PAI time, which is a copy of the infotype’s structure, filled with data.
Using an assign on the field symbol, assigning the value of the CPREL field from the calling routine gave me all I needed:
ASSIGN ('(MP000800)CPREL') TO <ptr>.
The value in brackets (here MP000800) is the name of the calling program, the variable is in, followed by CPREL, the name of the needed variable. I now had the CPREL data in my field symbol and could build my evaluation routine based on the values entered on the dynpro.
This method can almost be used in any custom code, one only have to find the name of the calling routine and the variable that should be used. Debugging is here a great help, also for evaluating if the dirty assign works correctly and gives the needed values.
As this is applicable to variables, also whole tables can be "fetched". For that, the working area has to be defined first, the field symbol has to be of type "ANY TABLE". Say we have a table called it_0008 inside MP000800, the dirty assign for that table would look like the following:
DATA: wa_0008 TYPE PA0008.
FIELD-SYMBOLS: <ptr_table> TYPE AND TABLE.
ASSIGN ('(MP000800)IT_0008[]') TO <ptr_table>.
After that assign, we have the internal table it_0008 of MP000800 in our field-symbol and can loop over it:
LOOP AT <ptr_table> INTO wa_0008.
ENDLOOP.
VF01 invoice to mail to multiple recipients
These are the requirements that I was given:
- You may not use distribution lists, neither internal nor external. This requirement extends from not wanting common users to have access to these functions. How ever the user defines the multiple email addresses, then must be able to do so without significantly extending their roles. A Z table and interface screens are acceptable but not preferred. We would prefer to take advantage of the existing Vender Master address functionality.
- If the email addresses are in SAP already (Vendor addresses already allow multiple email addresses to be entered, however only one can be printed in standard functionality), why do we have to have new configuration to have access to them?
- Emails must be monitored through through standard SAP functionality, such as SOST or similar functions and therefore must be issued through SCOT configuration.
- Less is more. The less effort this takes, the better.
Knowns about our system (the preconditions for certainty that the described process will work):
- SAP Version - ECC6 Support Stack 22
- Also still working after Loading EHP6 on top of ECC6
- IBM i-series DB2 Database
- Invoices are created through a SmartForm
- We have used note 718017 to get the invoice number into the Subject line of our invoice
Observations:
- In the customer master, multiple emails addresses may be recorded for a single customer.
- Only one can be the default address. This one is the only address that un-augmented SAP allows the invoice to be sent to.
- As addresses are no longer needed, they can be marked for deletion. All others are available for use but not currently used.
- These characteristics are easily found in table ADR6.
- In debugging, we see that the following portion of the call stack is accessed:
SAPLSBCOMSUT FUNCTION SBCOMS_SEND_REQUEST_CREATE
SAPLSOA2 FUNCTION SO_OBJECT_SEND
SAPLSTXBW FUNCTION SSFCONVERT_OTF_AND_MAIL
SAPLSTXBC FORM OTF_MAIL
SAPLSTXBC FORM OTF_RESOLVE
SAPLSTXBC FORM OTF_FINISH
SAPLSTXBC FUNCTION SSFCOMP_CLOSE
/1BCDWB/SAPLSF00000001 FUNCTION /1BCDWB/SF00000001
RLB_INVOICE FORM PROCESSING
RLB_INVOICE FORM ENTRY
RSNAST00 FORM PROGRAMM_AUFRUFEN
- receivers is built in SBCOMS_SEND_REQUEST_CREATE
- By nature it contains only the default address
Solving the problem:
- Place an implicit enhancement at the beginning of FM sbcoms_send_request_create.
- In this read the email title from objhead where objhead-line(12) = 'TDTITLE=Inv:'.
- objhead-line+13(9) is the invoice number in our case
- In VBRK, the invoice number is connected to the Customer number
- In KNA1, the customer number is connected to the address number
- The sought addresses are in ADR6 and can therefore be appended to receivers
Things that you might want to think about further:
- In another exit, you might export the address number, then import it in this exit. The method I'm using is pretty hokey...
I will be glad to talk further to anyone about this solution.
Neal Wilhite
SAP Calendar Master – Delete Holiday Assignment
SAP Calendar Master – Delete Holiday Assignment
Some theory about basic SAP Calendar Master before I formulate the issue / problem statement
SAP calendar master consists of three separate sub-objects which are inter-linked to each other: Public Holidays, Holiday Calendar and Factory Calendar
Public holidays :Public holidays can be defined and be combined into holiday calendars. Public holidays describe the statutory holidays for a particular country or region within a country.
Types of Public holidays:
- Fixed date
- Fixed day of week from a specific date
- Specific number of days before or after Easter (Sunday)
- Easter Sunday
- Moveable holiday (with individual specification of dates during each specified year).
For holidays with fixed date (such as Christmas) and moveable holidays it is possible to specify simple rules guaranteeing the holiday if it falls on certain days of the week (Thu, Fri, Sun, Sat/Sun). For instance, Christmas day public holiday may be moved to the next working day if it falls on a Saturday or Sunday.
Holiday calendar : Holiday calendar is assigned to each factory calendar.
Factory calendar :Factory calendar contain company specific dates such as alternate working Saturdays and holidays.
Issue / Problem Statement: Apparently for some reason there was a data issue and May 30 was set as a holiday and needed to be corrected.
As per standard SAP recommendation, it should be done in the DEV environment and then transported to the various systems in the landscape before finally reaching to PROD environment to ensure none of the interfaces are impacted by this change.
I was trying to read some literature on SCAL but didn't get enough inputs so I decided to pen this down with snapshots.
Step 1 : Go to SE93 and enter T-Code SCA5_U.
Step 2: Execute the T-code from SE93 only (Cannot be executed directly using the command bar)
Step 3: Select the desired holiday calendar to edit and Click Change button.
Step 4: Select the desired holiday to delete and Click Delete Assignment button and you are all set.
Final Step: Save all the changes and transport it (always the best and the safest way).
Sending Mail using Oo (2) - Smartforms
Creation of a simple Smartform
Import of a logo
Transaction SE78
Double-click on the line BMAP
Enter a name for your logo, select the color BitMap Image and press the Import button.
Enter the file name, and press Enter.
Smartform creation
Transaction SmartForms
Enter a name and press the button Create
Select the Main Window, click on the right button, select Create --> Graphic
Enter the graphic name, the object and the ID (GRAPHICS / BMAP), select the Color BitMap Image
Select the main window, click on the right button, select Create --> Text
Enter a text ..
Press the Activate icon.
Now we could test our Smartform, press the Test button (F8).
SAP launch the SE37 transaction (Function module) with the function generated by the Smartforms.
Press again the test button (F8)
Press now execute (F8)
Choose a printer and press the button Print Preview
It works !
Creation of a simple calling program for the Smartform.
DATA : w_formname TYPE tdsfname ,
w_funcname TYPE tdsfname ,
is_control_param TYPE ssfctrlop ,
is_params TYPE pri_params.
START-OF-SELECTION.
* My Smartforms.
MOVE 'ZMY_SMARTFORMS' TO w_formname.
* Get the function module name corresponding of the Smartform.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = w_formname
IMPORTING
fm_name = w_funcname
EXCEPTIONS
OTHERS = 3.
CHECK sy-subrc EQ space.
* Set the parameters of the forms.
MOVE : 'X' TO is_control_param-no_dialog ,
'X' TO is_control_param-preview ,
' ' TO is_control_param-getotf ,
sy-langu TO is_control_param-langu .
CALL FUNCTION w_funcname
EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
control_parameters = is_control_param
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
* output_options =
USER_SETTINGS = ' '
* IMPORTING
* DOCUMENT_OUTPUT_INFO =
* JOB_OUTPUT_INFO =
* JOB_OUTPUT_OPTIONS =
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
END-OF-SELECTION.
With this code you could print or preview the form.
Send the Smartform by email
* Need for the macro to build Mail_Appl_Obj.
INCLUDE <cntn01>.
DATA : w_formname TYPE tdsfname ,
w_funcname TYPE tdsfname ,
w_borkey TYPE swo_typeid ,
w_year TYPE so_doc_yr ,
w_number TYPE so_doc_no ,
is_control_param TYPE ssfctrlop ,
is_params TYPE pri_params ,
is_recipient TYPE swotobjid ,
is_sender TYPE swotobjid ,
is_mailobj TYPE swotobjid ,
is_folder TYPE swc_object ,
is_sofmk TYPE sofmk .
START-OF-SELECTION.
* My Smartforms.
MOVE 'ZMY_SMARTFORMS' TO w_formname.
* Get the function module name corresponding of the Smartform.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = w_formname
IMPORTING
fm_name = w_funcname
EXCEPTIONS
OTHERS = 3.
CHECK sy-subrc EQ space.
* Set the parameters of the forms.
MOVE : 'X' TO is_control_param-no_dialog ,
' ' TO is_control_param-preview ,
' ' TO is_control_param-getotf ,
sy-langu TO is_control_param-langu ,
'MAIL' TO is_control_param-device.
* Create the Recipient.
CALL FUNCTION 'CREATE_RECIPIENT_OBJ_PPF'
EXPORTING
ip_mailaddr = 'frederic.girod@everywhere.com'
IMPORTING
ep_recipient_id = is_recipient
EXCEPTIONS
invalid_recipient = 1
OTHERS = 2.
* Create the Sender
CALL FUNCTION 'CREATE_SENDER_OBJECT_PPF'
EXPORTING
ip_sender = sy-uname
IMPORTING
ep_sender_id = is_sender
EXCEPTIONS
invalid_sender = 1
OTHERS = 2.
* Create the Mail Obj.
SELECT SINGLE inbyr inbno
INTO (w_year, w_number)
FROM soud
WHERE sapnam EQ sy-uname.
CHECK sy-subrc EQ space.
MOVE : 'FOL' TO is_sofmk-doctp ,
w_number TO is_sofmk-docyr ,
w_year TO is_sofmk-docno .
MOVE is_sofmk TO w_borkey.
swc_create_object is_folder 'SOFMFOL' w_borkey.
swc_object_to_persistent is_folder is_mailobj.
CALL FUNCTION w_funcname
EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
control_parameters = is_control_param
mail_appl_obj = is_mailobj
mail_recipient = is_recipient
mail_sender = is_sender
* output_options =
user_settings = ' '
* IMPORTING
* DOCUMENT_OUTPUT_INFO =
* JOB_OUTPUT_INFO =
* JOB_OUTPUT_OPTIONS =
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc EQ space.
COMMIT WORK AND WAIT.
ENDIF.
END-OF-SELECTION.
If you haven't entry in the SOUD table you could add-it dynamically with the function SO_USER_AUTOMATIC_INSERT.
If you use an entry of the NAST table (configuration with the NACE transaction ..), instead of creating manually the MAIL_APPL_OBJ, MAIL_RECIPIENT, MAIL_SENDER, you only have to use the function WFMC_PREPARE_SMART_FORM.
Result
In the SOST transaction :
And the mail :
The attachment :
Each time I show that to my users, they didn't want to use that for external mails.
Send the Smartform inside the email.
Code
DATA : w_formname TYPE tdsfname ,
w_funcname TYPE tdsfname ,
w_status TYPE bcs_rqst ,
w_html_xtxt TYPE xstring ,
w_html_txt TYPE string ,
w_html_len TYPE i ,
w_gr_xtxt TYPE xstring ,
w_offset TYPE i ,
w_len TYPE i ,
w_diff TYPE i ,
w_file TYPE string ,
w_content_type TYPE w3conttype ,
w_obj_len TYPE so_obj_len ,
w_content_id TYPE string ,
w_title TYPE so_obj_des ,
w_docno TYPE so_obj_no ,
is_control_param TYPE ssfctrlop ,
is_composer_param TYPE ssfcompop ,
is_soli TYPE soli ,
is_job_info TYPE ssfcrescl ,
is_xfsparam TYPE ssfxsfp ,
is_html_raw LIKE LINE OF is_job_info-xmloutput-trfresult-content ,
is_graphic TYPE ssf_xsf_gr ,
is_gr_raw TYPE bapiconten ,
is_solix TYPE solix ,
it_soli TYPE TABLE OF soli ,
it_graphics TYPE tsf_xsf_gr ,
it_solix TYPE solix_tab ,
obj_mime_helper TYPE REF TO cl_gbt_multirelated_service ,
obj_bcs TYPE REF TO cl_bcs ,
obj_doc_bcs TYPE REF TO cl_document_bcs ,
obj_recipient TYPE REF TO if_recipient_bcs .
START-OF-SELECTION.
* My Smartforms.
MOVE 'ZMY_SMARTFORMS' TO w_formname.
* Get the function module name corresponding of the Smartform.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = w_formname
IMPORTING
fm_name = w_funcname
EXCEPTIONS
OTHERS = 3.
CHECK sy-subrc EQ space.
* Set the parameters of the forms.
MOVE : 'X' TO is_control_param-no_dialog ,
' ' TO is_control_param-preview ,
'X' TO is_control_param-getotf ,
sy-langu TO is_control_param-langu ,
'PRINTER' TO is_control_param-device ,
'X' TO is_composer_param-tdnoprint ,
'X' TO is_composer_param-tdnoprev ,
'X' TO is_composer_param-tdfinal ,
'X' TO is_composer_param-xdfcmode ,
' ' TO is_composer_param-xdf ,
'X' TO is_composer_param-xsfcmode ,
'X' TO is_composer_param-xsf ,
' ' TO is_composer_param-xsfoutdev ,
'A' TO is_composer_param-xsfoutmode ,
'X' TO is_composer_param-xsfformat ,
'My Mail' TO is_composer_param-tdtitle.
* For the Graphics
MOVE : 'GRAPHICS' TO is_xfsparam-name ,
'EXTRACT' TO is_xfsparam-value.
APPEND is_xfsparam TO is_composer_param-xsfpars.
MOVE : 'GRAPHICS-DIRECTORY' TO is_xfsparam-name ,
'MyDirY TO is_xfsparam-value.
APPEND is_xfsparam TO is_composer_param-xsfpars.
MOVE : 'CONTENT-ID' TO is_xfsparam-name ,
'ENABLE' TO is_xfsparam-value.
APPEND is_xfsparam TO is_composer_param-xsfpars.
* Call the Smartforms
CALL FUNCTION w_funcname
EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
control_parameters = is_control_param
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
output_options = is_composer_param
user_settings = ' '
IMPORTING
* DOCUMENT_OUTPUT_INFO =
job_output_info = is_job_info
* JOB_OUTPUT_OPTIONS =
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
* Conversion du HTML Hex en Text.
LOOP AT is_job_info-xmloutput-trfresult-content
INTO is_html_raw.
CONCATENATE w_html_xtxt
is_html_raw
INTO w_html_xtxt
IN BYTE MODE.
ENDLOOP.
w_html_xtxt = w_html_xtxt(is_job_info-xmloutput-trfresult-length).
CALL FUNCTION 'SCP_TRANSLATE_CHARS'
EXPORTING
inbuff = w_html_xtxt
incode = '4110'
outcode = '0000'
csubst = 'X'
substc_space = 'X'
IMPORTING
outbuff = w_html_txt
outused = w_html_len
EXCEPTIONS
OTHERS = 5.
REPLACE ALL OCCURRENCES OF 'utf-8' IN w_html_txt WITH 'latin1'.
w_html_len = strlen( w_html_txt ).
* Creation objet pour mail.
CREATE OBJECT obj_mime_helper.
* Récupère les graphiques.
it_graphics = is_job_info-xmloutput-xsfgr[].
LOOP AT it_graphics
INTO is_graphic.
CLEAR w_gr_xtxt.
LOOP AT is_graphic-content
INTO is_gr_raw.
CONCATENATE w_gr_xtxt
is_gr_raw-line
INTO w_gr_xtxt
IN BYTE MODE.
ENDLOOP.
w_gr_xtxt = w_gr_xtxt(is_graphic-length).
w_offset = 0.
w_len = 255.
CLEAR it_solix[].
WHILE w_offset < is_graphic-length.
w_diff = is_graphic-length - w_offset.
IF w_diff > w_len.
is_solix-line = w_gr_xtxt+w_offset(w_len).
ELSE.
is_solix-line = w_gr_xtxt+w_offset(w_diff).
ENDIF.
APPEND is_solix TO it_solix.
ADD w_len TO w_offset.
ENDWHILE.
CONCATENATE 'MyDir'
is_graphic-graphics
'.bmp'
INTO w_file.
CONCATENATE 'MyDir'
is_graphic-graphics
'.bmp'
INTO w_content_id.
w_content_type = is_graphic-httptype.
w_obj_len = is_graphic-length.
CALL METHOD obj_mime_helper->add_binary_part
EXPORTING
content = it_solix
filename = w_file
extension = 'BMP'
description = 'Graphic in BMP format'
content_type = w_content_type
length = w_obj_len
content_id = w_content_id.
ENDLOOP.
w_offset = 0.
w_len = 255.
WHILE w_offset < w_html_len.
w_diff = w_html_len - w_offset.
IF w_diff > w_len.
is_soli-line = w_html_txt+w_offset(w_len).
ELSE.
is_soli-line = w_html_txt+w_offset(w_diff).
ENDIF.
APPEND is_soli TO it_soli.
ADD w_len TO w_offset.
ENDWHILE.
* Ajoute le corps.
CALL METHOD obj_mime_helper->set_main_html
EXPORTING
content = it_soli
filename = ''
description = 'My mail'.
* Ajoute le titre
MOVE is_composer_param-tdtitle TO w_title.
obj_doc_bcs = cl_document_bcs=>create_from_multirelated(
i_subject = w_title
i_importance = '9' " 1 / 5 / 9
i_multirel_service = obj_mime_helper ).
CALL METHOD obj_doc_bcs->get_docno
RECEIVING
result = w_docno.
obj_bcs = cl_bcs=>create_persistent( ).
obj_bcs->set_document( i_document = obj_doc_bcs ).
* add the email address.
obj_recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = 'frederic.girod@everywhere.com' ).
obj_bcs->add_recipient( i_recipient = obj_recipient ).
* Statut change
MOVE 'N' TO w_status.
CALL METHOD obj_bcs->set_status_attributes
EXPORTING
i_requested_status = w_status.
* Send the mail.
obj_bcs->send( ).
* Commit Work.
IF sy-subrc EQ space.
COMMIT WORK AND WAIT.
ELSE.
ROLLBACK WORK.
ENDIF.
END-OF-SELECTION.
The code is little more complex.
First, we need to execute the Smartform, but without printing it. We asked SAP to create XDF and XSF, the result was store in the JOB_OUTPUT_INFO.
The form is in Hex format, we used the function SCP_TRANSLATE_CHARS to convert to a text format.
We need also to include the logo in the mail, but not as attachment, so we used the ADD_BINARY_PART method instead of ADD_ATTACHMENT.
Result
Send the Smartform in PDF attachment with a text message.
Create a new Smartform
I need a simple Smartform to put-it in the text message of the email.
The code need to be organized ...
The data :
TYPES : tt_docs TYPE TABLE OF docs.
DATA : w_formname TYPE tdsfname ,
w_funcname TYPE tdsfname ,
w_status TYPE bcs_rqst ,
w_html_xtxt TYPE xstring ,
w_html_txt TYPE string ,
w_html_len TYPE i ,
w_gr_xtxt TYPE xstring ,
w_offset TYPE i ,
w_len TYPE i ,
w_diff TYPE i ,
w_file TYPE string ,
w_content_type TYPE w3conttype ,
w_obj_len TYPE so_obj_len ,
w_content_id TYPE so_obj_des ,
w_content_id2 TYPE string ,
w_title TYPE so_obj_des ,
w_docno TYPE so_obj_no ,
w_doc_size TYPE i ,
w_xtxt TYPE xstring ,
is_control_param TYPE ssfctrlop ,
is_composer_param TYPE ssfcompop ,
is_soli TYPE soli ,
is_job_info TYPE ssfcrescl ,
is_xfsparam TYPE ssfxsfp ,
is_html_raw LIKE LINE OF is_job_info-xmloutput-trfresult-content ,
is_graphic TYPE ssf_xsf_gr ,
is_gr_raw TYPE bapiconten ,
is_solix TYPE solix ,
is_tline TYPE tline ,
it_soli TYPE TABLE OF soli ,
it_graphics TYPE tsf_xsf_gr ,
it_solix TYPE solix_tab ,
it_docs TYPE tt_docs ,
it_tline TYPE tline_tab ,
obj_mime_helper TYPE REF TO cl_gbt_multirelated_service ,
obj_bcs TYPE REF TO cl_bcs ,
obj_doc_bcs TYPE REF TO cl_document_bcs ,
obj_recipient TYPE REF TO if_recipient_bcs ,
obj_conv TYPE REF TO cl_abap_conv_obj.
First part, create the mail with the text message :
START-OF-SELECTION.
*---------------------------------------------------------------------*
* Create the text message *
*---------------------------------------------------------------------*
* My Smartforms.
MOVE 'ZMY_SMARTFORMS_002' TO w_formname.
* Get the function module name corresponding of the Smartform.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = w_formname
IMPORTING
fm_name = w_funcname
EXCEPTIONS
OTHERS = 3.
CHECK sy-subrc EQ space.
* Set the parameters of the forms.
MOVE : 'X' TO is_control_param-no_dialog ,
' ' TO is_control_param-preview ,
'X' TO is_control_param-getotf ,
sy-langu TO is_control_param-langu ,
'PRINTER' TO is_control_param-device ,
'X' TO is_composer_param-tdnoprint ,
'X' TO is_composer_param-tdnoprev ,
'X' TO is_composer_param-tdfinal ,
'X' TO is_composer_param-xdfcmode ,
' ' TO is_composer_param-xdf ,
'X' TO is_composer_param-xsfcmode ,
'X' TO is_composer_param-xsf ,
' ' TO is_composer_param-xsfoutdev ,
'A' TO is_composer_param-xsfoutmode ,
'X' TO is_composer_param-xsfformat ,
'My Mail' TO is_composer_param-tdtitle.
* For the Graphics
MOVE : 'GRAPHICS' TO is_xfsparam-name ,
'EXTRACT' TO is_xfsparam-value.
APPEND is_xfsparam TO is_composer_param-xsfpars.
MOVE : 'GRAPHICS-DIRECTORY' TO is_xfsparam-name ,
'MyDirY TO is_xfsparam-value.
APPEND is_xfsparam TO is_composer_param-xsfpars.
MOVE : 'CONTENT-ID' TO is_xfsparam-name ,
'ENABLE' TO is_xfsparam-value.
APPEND is_xfsparam TO is_composer_param-xsfpars.
* Call the Smartforms
CALL FUNCTION w_funcname
EXPORTING
control_parameters = is_control_param
output_options = is_composer_param
user_settings = ' '
IMPORTING
job_output_info = is_job_info
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
* Conversion du HTML Hex en Text.
LOOP AT is_job_info-xmloutput-trfresult-content
INTO is_html_raw.
CONCATENATE w_html_xtxt
is_html_raw
INTO w_html_xtxt
IN BYTE MODE.
ENDLOOP.
w_html_xtxt = w_html_xtxt(is_job_info-xmloutput-trfresult-length).
CALL FUNCTION 'SCP_TRANSLATE_CHARS'
EXPORTING
inbuff = w_html_xtxt
incode = '4110'
outcode = '0000'
csubst = 'X'
substc_space = 'X'
IMPORTING
outbuff = w_html_txt
outused = w_html_len
EXCEPTIONS
OTHERS = 5.
REPLACE ALL OCCURRENCES OF 'utf-8' IN w_html_txt WITH 'latin1'.
w_html_len = strlen( w_html_txt ).
* Creation objet pour mail.
CREATE OBJECT obj_mime_helper.
* Récupère les graphiques.
it_graphics = is_job_info-xmloutput-xsfgr[].
LOOP AT it_graphics
INTO is_graphic.
CLEAR w_gr_xtxt.
LOOP AT is_graphic-content
INTO is_gr_raw.
CONCATENATE w_gr_xtxt
is_gr_raw-line
INTO w_gr_xtxt
IN BYTE MODE.
ENDLOOP.
w_gr_xtxt = w_gr_xtxt(is_graphic-length).
w_offset = 0.
w_len = 255.
CLEAR it_solix[].
WHILE w_offset < is_graphic-length.
w_diff = is_graphic-length - w_offset.
IF w_diff > w_len.
is_solix-line = w_gr_xtxt+w_offset(w_len).
ELSE.
is_solix-line = w_gr_xtxt+w_offset(w_diff).
ENDIF.
APPEND is_solix TO it_solix.
ADD w_len TO w_offset.
ENDWHILE.
CONCATENATE 'MyDir'
is_graphic-graphics
'.bmp'
INTO w_file.
CONCATENATE 'MyDir'
is_graphic-graphics
'.bmp'
INTO w_content_id.
w_content_type = is_graphic-httptype.
w_obj_len = is_graphic-length.
CALL METHOD obj_mime_helper->add_binary_part
EXPORTING
content = it_solix
filename = w_file
extension = 'BMP'
description = 'Graphic in BMP format'
content_type = w_content_type
length = w_obj_len
content_id = w_content_id2.
ENDLOOP.
w_offset = 0.
w_len = 255.
WHILE w_offset < w_html_len.
w_diff = w_html_len - w_offset.
IF w_diff > w_len.
is_soli-line = w_html_txt+w_offset(w_len).
ELSE.
is_soli-line = w_html_txt+w_offset(w_diff).
ENDIF.
APPEND is_soli TO it_soli.
ADD w_len TO w_offset.
ENDWHILE.
* Ajoute le corps.
CALL METHOD obj_mime_helper->set_main_html
EXPORTING
content = it_soli
filename = ''
description = 'My mail'.
* Ajoute le titre
MOVE is_composer_param-tdtitle TO w_title.
obj_doc_bcs = cl_document_bcs=>create_from_multirelated(
i_subject = w_title
i_importance = '9' " 1 / 5 / 9
i_multirel_service = obj_mime_helper ).
CALL METHOD obj_doc_bcs->get_docno
RECEIVING
result = w_docno.
obj_bcs = cl_bcs=>create_persistent( ).
obj_bcs->set_document( i_document = obj_doc_bcs ).
Second part, create the PDF and add in attachment of the mail.
*---------------------------------------------------------------------*
* Create the attachment. *
*---------------------------------------------------------------------*
* My Smartforms.
MOVE 'ZMY_SMARTFORMS' TO w_formname.
* Get the function module name corresponding of the Smartform.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = w_formname
IMPORTING
fm_name = w_funcname
EXCEPTIONS
OTHERS = 3.
CHECK sy-subrc EQ space.
* Set the parameters of the forms.
CLEAR : is_control_param, is_composer_param.
MOVE : 'X' TO is_control_param-no_dialog ,
' ' TO is_control_param-preview ,
'X' TO is_control_param-getotf ,
sy-langu TO is_control_param-langu ,
'PRINTER' TO is_control_param-device ,
'X' TO is_composer_param-tdnoprint ,
'X' TO is_composer_param-tdnoprev ,
'X' TO is_composer_param-tdfinal.
* Call the Smartforms
CALL FUNCTION w_funcname
EXPORTING
control_parameters = is_control_param
output_options = is_composer_param
user_settings = ' '
IMPORTING
job_output_info = is_job_info
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
break fgi.
* Convert the OTF to PDF.
CALL FUNCTION 'CONVERT_OTF_2_PDF'
IMPORTING
bin_filesize = w_doc_size
TABLES
otf = is_job_info-otfdata
doctab_archive = it_docs
lines = it_tline
EXCEPTIONS
OTHERS = 3.
CLEAR w_gr_xtxt.
CREATE OBJECT obj_conv.
* Change the output format.
LOOP AT it_tline
INTO is_tline.
CALL METHOD obj_conv->convert
EXPORTING
inbuff = is_tline
outbufflg = 2500
IMPORTING
outbuff = w_xtxt.
CONCATENATE w_gr_xtxt
w_xtxt
INTO w_gr_xtxt
IN BYTE MODE.
ENDLOOP.
w_gr_xtxt = w_gr_xtxt(w_doc_size).
w_offset = 0.
w_len = 255.
CLEAR it_solix[].
WHILE w_offset < w_doc_size.
w_diff = w_doc_size - w_offset.
IF w_diff > w_len.
is_solix-line = w_gr_xtxt+w_offset(w_len).
ELSE.
is_solix-line = w_gr_xtxt+w_offset(w_diff).
ENDIF.
APPEND is_solix TO it_solix.
ADD w_len TO w_offset.
ENDWHILE.
MOVE : 'Attachment' TO w_title ,
'Attachment.pdf' TO w_content_id.
w_content_type = ' '.
w_obj_len = w_doc_size.
* Add as attachment the PDF
CALL METHOD obj_doc_bcs->add_attachment
EXPORTING
i_attachment_type = 'PDF'
i_attachment_subject = w_content_id
i_attachment_size = w_obj_len
i_att_content_hex = it_solix.
And finaly send the mail.
* add the email address.
obj_recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = 'frederic.girod@sap.com' ).
obj_bcs->add_recipient( i_recipient = obj_recipient ).
* Statut change
MOVE 'N' TO w_status.
CALL METHOD obj_bcs->set_status_attributes
EXPORTING
i_requested_status = w_status.
* Send the mail.
obj_bcs->send( ).
* Commit Work.
IF sy-subrc EQ space.
COMMIT WORK AND WAIT.
ELSE.
ROLLBACK WORK.
ENDIF.
END-OF-SELECTION.
It's a little bit long, but the result is better for the end user.
Result
(next step : result of a report ..)
Fred