Posted: Mon Feb 25, 2008 2:06 pm Post subject: Report from note 190669 for sending lists via SAPconnect
Code:
*&---------------------------------------------------------------------*
*& Report SENDLIST
*&
*&---------------------------------------------------------------------*
*& Sample report from note 190669 for sending lists via SAPconnect
*& for releases as of 6.10:
*&
*& 1. Use so_document_send_api1 instead of
*& so_new_document_att_send_api1 (same interface)
*& Better yet, use the BCS interface. See below and note 190669
*& 2. Cast recipient structures into receiver-receiver field
*& using a field-symbol
*& 3. Set a commit work statement after the sending
*& or set parameter commit_work at the send module
*& 4. Give binary data of type x not type c to send module, i.e.
*& use structure solix instead of soli and give it to tables
*& parameter contents_hex instead of contents_bin
*& Do this by filling contents_hex directly from the module
*& table_compress. In case of reading the data from spool, convert
*& to solix using so_solitab_to_solixtab
*& 5. Don't calculate document size. It is done internally
*&
*& Recommendation:
*& Switch to the new BCS interface instead of calling the API1
*& Function module. See Report sendlist_bcs (also within note 190669)
*& for this
*&
*&---------------------------------------------------------------------*
report sendlist line-size 46 no standard page heading message-id so.
selection-screen begin of block mode with frame title title.
parameters: submit radiobutton group mode default 'X'.
parameters: write radiobutton group mode .
parameters: spool radiobutton group mode.
selection-screen end of block mode.
selection-screen begin of block type with frame title adrtp.
parameters: int type c as checkbox default 'X',
fax type c as checkbox,
rml type c as checkbox,
user type c as checkbox.
selection-screen end of block type.
* global data
data g_list_content type solix_tab.
data g_text_content type soli_tab.
*04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)*
* Form routines *
*04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)04:24 26 abr 2007 (PDT)*
*&---------------------------------------------------------------------*
*& Form create_list_content
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
form create_list_content changing list_content type solix_tab.
* 1st possibility - use "submit <report> exporting list to memory"</
''* this is the recommended way''
if submit = 'X'.
perform use_submit changing list_content.
endif.
''* 2nd possibility - create a new list within this report.''
if write = 'X'.
perform write_a_list changing list_content.
endif.
''* 3rd possibility - get list from spool''
if spool = 'X'.
perform get_list_from_spool changing list_content.
endif.
'''endform.''"create_list_content'''''
''*&---------------------------------------------------------------------*''
''*& Form create_text_content''
''*&---------------------------------------------------------------------*''
''*''
''*----------------------------------------------------------------------*''
'''form create_text_content changing text_content type soli_tab.'''
append 'This is the first line' to text_content.
append 'This is the second line' to text_content.
''* convert the content from RAW to TXT''
CALL FUNCTION '[[SO_RAW_TO_RTF]]'
TABLES
objcont_old = text_content
objcont_new = text_content
EXCEPTIONS
others = 0.
'''endform.''"create_text_content'''''
''*&---------------------------------------------------------------------*''
''*& Form SEND''
''*&---------------------------------------------------------------------*''
''* Create the list-document and send it via FAX, Mail and RML''
''*----------------------------------------------------------------------*''
'''form send using text_content type soli_tab'''
list_content type solix_tab.
''* structures and internal tables for the send data''
data document_data type sodocchgi1.
data packing_list type table of sopcklsti1.
data receivers type table of somlreci1.
data contents_txt type soli_tab.
data contents_hex type solix_tab.
data packlist_wa type sopcklsti1.
data receiver_wa type somlreci1.
data packlist_counter type i.
data sent_to_all type sonv-flag.
''*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*''
''* main document''
''*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*''
''* document data contains information for the whole message''
document_data-obj_descr = 'ABAPlist'.
''* some text for the main document''
append 'Hi,' to contents_txt.
append 'attached you will find the list.' to contents_txt.
packlist_counter = 1.
perform create_packlist_entry using contents_txt
'RAW'
changing packlist_wa
packlist_counter.
append packlist_wa to packing_list.
''*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''
''* add a text attachment of type TXT''
''*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''
perform create_packlist_entry using text_content
'TXT'
changing packlist_wa
packlist_counter.
append packlist_wa to packing_list.
append lines of text_content to contents_txt.
''*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''
''* add the list attachment of type ALI''
''*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''
packlist_counter = 1.''"because we will fill the hex table now''
perform create_packlist_entry using list_content
'ALI'
changing packlist_wa
packlist_counter.
append packlist_wa to packing_list.
append lines of list_content to contents_hex.
''*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''
''* fill recipients tables''
''*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''
if fax = 'X'.
perform create_fax_recipient changing receiver_wa.
append receiver_wa to receivers.
endif.
if int = 'X'.
perform create_int_recipient changing receiver_wa.
append receiver_wa to receivers.
endif.
if rml = 'X'.
perform create_rml_recipient changing receiver_wa.
append receiver_wa to receivers.
endif.
if user = 'X'.
receiver_wa-receiver = 'MYUSER'.
receiver_wa-rec_type = 'B'.
append receiver_wa to receivers.
endif.
''*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''
''* Send the document by calling the API1''
''* as of 6.10 either the flag 'commit_work' has to be set''
''* or a commit work statement has to be set somewhere after the call''
''* Sending won't work without this!''
''*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''
CALL FUNCTION '[[SO_DOCUMENT_SEND_API1]]'
EXPORTING
document_data = document_data
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = sent_to_all
TABLES
packing_list = packing_list
contents_txt = contents_txt
contents_hex = contents_hex
receivers = receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
others = 8.
case sy-subrc.
when 0.
if sent_to_all is initial.
read table receivers index 1 into receiver_wa.
message i865 with receiver_wa-retrn_code.
else.
message s022.
endif.
when 1.
message i552.
when 2.
message i023 with document_data-obj_descr.
when 4.
message i471.
when others.
message i619.
endcase.
'''endform.''" SEND'''''
''*&---------------------------------------------------------------------*''
''*& Form USE_SUBMIT''
''*&---------------------------------------------------------------------*''
<nowiki>* Use "submit <report> exporting list to memory"
*----------------------------------------------------------------------*
form use_submit changing contents_hex type solix_tab.
data listobject type table of abaplist.
* get the list object by calling the list in another report
* F1 on submit gives more information
submit balvsd03 exporting list to memory and return.
* import the list from memory and store it in table listobject
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = listobject
EXCEPTIONS
not_found = 1
others = 2.
if sy-subrc <> 0.
message e105 with 'LIST_FROM_MEMORY'.
endif.
* free memory
CALL FUNCTION 'LIST_FREE_MEMORY'
TABLES
listobject = listobject
EXCEPTIONS
others = 1.
if sy-subrc <> 0.
message e105 with 'LIST_FREE_MEMORY'.
endif.
* it's always necessary to compress the table.
* SAPconnect will decompress it
CALL FUNCTION 'TABLE_COMPRESS'
TABLES
in = listobject
out = contents_hex
EXCEPTIONS
compress_error = 1
others = 2.
if sy-subrc <> 0.
message e105 with 'TABLE_COMPRESS'.
endif.
endform." USE_SUBMIT
*&---------------------------------------------------------------------*
*& Form WRITE_A_LIST
*&---------------------------------------------------------------------*
* Create a new list within this report.
*----------------------------------------------------------------------*
form write_a_list changing contents_hex type solix_tab.
data listobject type table of abaplist.
perform write_list.
* Save the list and store table listobject
CALL FUNCTION 'SAVE_LIST'
EXPORTING
list_index = sy-lsind
TABLES
listobject = listobject
EXCEPTIONS
list_index_invalid = 1.
if sy-subrc = 1.
message e105 with 'SAVE_LIST'.
endif.
* It's always necessary to compress the table
* SAPconnect will decompress it
CALL FUNCTION 'TABLE_COMPRESS'
TABLES
in = listobject
out = contents_hex
EXCEPTIONS
compress_error = 1
others = 2.
if sy-subrc <> 0.
message e105 with 'TABLE_COMPRESS'.
endif.
endform." WRITE_A_LIST
*&---------------------------------------------------------------------*
*& Form GET_LIST_FROM_SPOOL
*&---------------------------------------------------------------------*
* Get list from spool
*----------------------------------------------------------------------*
form get_list_from_spool changing contents_hex type solix_tab.
data spool_number type rspoid.
data contents_bin type soli_tab.
data print_parameters type pri_params.
data valid type c.
* write a list into spool
CALL FUNCTION 'GET_PRINT_PARAMETERS'
IMPORTING
out_parameters = print_parameters
valid = valid
EXCEPTIONS
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
others = 4.
if sy-subrc <> 0.
message e105 with 'GET_PRINT_PARAMETERS'.
elseif valid is initial.
return.
endif.
new-page print on parameters print_parameters no dialog.
perform write_list.
new-page print off.
spool_number = sy-spono.
* you can also send OTF documents from spool with this function
* module. The importing parameter real_type gives you the doc type
* that you have to give to the send interface. The parameter is not
* used here
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
EXPORTING
rqident = spool_number
TABLES
buffer = contents_bin
EXCEPTIONS
no_such_job = 1
job_contains_no_data = 2
selection_empty = 3
no_permission = 4
can_not_access = 5
read_error = 6
type_no_match = 7
others = 8.
if sy-subrc <> 0.
message e105 with 'RSPO_RETURN_SPOOLJOB'.
endif.
* convert to hex table
CALL FUNCTION 'SO_SOLITAB_TO_SOLIXTAB'
EXPORTING
ip_solitab = contents_bin
IMPORTING
ep_solixtab = contents_hex.
endform." GET_LIST_FROM_SPOOL
*&---------------------------------------------------------------------*
*& Form WRITE_LIST
*&---------------------------------------------------------------------*
* Write a list of SAPconnect conversion rules
*----------------------------------------------------------------------*
form write_list.
data lt_scarr type table of scarr.
data carr type scarr.
select * from scarr into table lt_scarr.
format color = 1.
uline at /1(46).
write: / sy-vline,
'CARRID', 10 sy-vline,
'CARRNAME', 35 sy-vline,
'CURRCODE', 46 sy-vline.
format color = 2.
uline at /1(46).
loop at lt_scarr into carr.
write: / sy-vline,
carr-carrid, 10 sy-vline,
carr-carrname, 35 sy-vline,
carr-currcode, 46 sy-vline.
endloop.
uline at /1(46).
new-line.
endform." WRITE_LIST
*&---------------------------------------------------------------------*
*& Form create_packlist_entry
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form create_packlist_entry using contents type standard table
format type so_obj_tp
changing packlist_wa type sopcklsti1
packlist_counter type i.
data tab_lines type i.
clear packlist_wa.
* get the table length of the attachment
describe table contents lines tab_lines.
* set binary flag for binary content to mark that this packlist entry
* is meant for table contents_hex and not for contents_bin
if format = 'ALI'.
packlist_wa-transf_bin = 'X'.
endif.
* attchment's description and format
concatenate format 'Document' into
packlist_wa-obj_descr separated by space.
packlist_wa-doc_type = format.
* describe start and length in contents_txt or contents_hex
* which table is meant is decided by the transf_bin flag set above
packlist_wa-body_start = packlist_counter.
packlist_wa-body_num = tab_lines.
* increase counter to have the starting line for the next attachment
packlist_counter = packlist_counter + tab_lines.
endform." create_packlist_entry
*&---------------------------------------------------------------------*
*& Form create_int_recipient
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form create_int_recipient changing receiver type somlreci1.
field-symbols <receiver> type c.
data recipient_int type sadrud.
clear receiver.
* fill address type specific recipient structure
recipient_int-address = '[email protected]'.
* cast structure to generic receiver field
assign recipient_int to <receiver> casting.
receiver-receiver = <receiver>.
* set address type for INT
receiver-rec_type = 'U'.
endform."create_int_recipient
*&---------------------------------------------------------------------*
*& Form create_fax_recipient
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form create_fax_recipient changing receiver type somlreci1.
field-symbols <receiver> type c.
data recipient_fax type sadrfd.
data name type soud3.
clear receiver.
name-sapnam = sy-uname.
CALL FUNCTION 'SO_NAME_CONVERT'
EXPORTING
name_in = name
IMPORTING
name_out = name
EXCEPTIONS
others = 1.
if sy-subrc <> 0.
name-adrname = sy-uname.
endif.
* fill address type specific recipient structure
recipient_fax-rec_fax = '9999'.
recipient_fax-rec_state = 'DE'.
recipient_fax-rec_title = 'Mr.'.
recipient_fax-rec_name1 = 'John Doe'.
recipient_fax-send_nam = name-adrname.
recipient_fax-send_cover = 'X'.
* cast structure to generic receiver field
assign recipient_fax to <receiver> casting.
receiver-receiver = <receiver>.
* set address type for FAX
receiver-rec_type = 'F'.
endform."create_fax_recipient
*&---------------------------------------------------------------------*
*& Form create_rml_recipient
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form create_rml_recipient changing receiver type somlreci1.
field-symbols <receiver> type c.
data recipient_rml type sadr7d.
clear receiver.
* fill address type specific recipient structure
recipient_rml-sdest = 'C11'.
recipient_rml-umand = '001'.
recipient_rml-uname = 'MYUSER'.
* cast structure to generic receiver field
assign recipient_rml to <receiver> casting.
receiver-receiver = <receiver>.
* set address type for RML
receiver-rec_type = 'R'.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.