Skip to Content
0
Former Member
Jan 16, 2007 at 01:08 PM

send fax

23 Views

I have written the following code to send a fax.

But finally SUBRC is setting to 0 and raising an exception.

Are there any basis settings required for this?

DATA:

*for the htmlb event handling

  • evt type ref to if_htmlb_data,

*mail elements

bodyTable type table of char255, "body

receiver type somlreci1, "reciver

receivers type TABLE OF somlreci1, "table containing the reciver

senderAddr TYPE sender, "sender

document_data type SODOCCHGI1, "header informations

packing_list type table of SOPCKLSTI1,"document content description

sent_to_all type boolean,

*help variables

len type int4,

base type int4,

line type char255,

BODY TYPE STRING,

statust(255).

body = 'This is a test fax'.

  • first we need to split the string into an internal table

  • with line length of 255

len = strlen( body ) / 256.

if len gt 0.

do len times.

base = ( sy-index - 1 ) * 256.

if sy-index = len.

line = body+base.

else.

line = body+base(256).

endif.

APPEND line to bodyTable.

enddo.

ELSE. "one line length.

append body to bodyTable.

endif.

  • The text is now in the table bodytable.

  • if typeSelector eq 'INT'. "MAIL RECIPIENT

  • receiver-receiver = recipient.

  • receiver-rec_type = 'U'.

  • APPEND receiver to receivers.

  • move sender to senderAddr.

  • endif.

  • if typeSelector eq 'FAX'. "FAX RECIPIENT

field-symbols <receiver> type c.

data recipient_fax type sadrfd.

recipient_fax-rec_fax = '02066425476'.

recipient_fax-rec_state = '91'.

TRANSLATE recipient_fax-rec_state to UPPER CASE.

recipient_fax-send_cover = 'X'.

assign recipient_fax to <receiver> casting.

receiver-receiver = <receiver>.

receiver-rec_type = 'F'.

APPEND receiver to receivers.

*In case of fax the sender also needs to be adjusted.(country code)

  • field-symbols <sender> type c.

  • data sender_fax type sadrfd.

  • sender_fax-rec_fax = sender+2.

  • sender_fax-rec_state = sender+0(2).

  • TRANSLATE sender_fax-rec_state to UPPER CASE.

  • assign sender_fax to <sender> casting.

  • senderAddr = <sender>.

  • endif.

  • Fill the document data /subject/

document_data-obj_descr = 'Order Acknowledgement'.

  • Fill packing list

data: p_item type SOPCKLSTI1.

describe table bodyTable lines len. " the length of the document

p_item-doc_type = 'RAW'. " text document

p_item-transf_bin = ' '. " non binary

p_item-obj_descr = 'Order Acknowledgement'."subject.

p_item-body_start = 1. " first (and only) object

p_item-body_num = len. " set the length.

APPEND p_item to packing_list.

**send the document

call function 'SO_DOCUMENT_SEND_API1'

exporting

document_data = document_data

put_in_outbox = ' '

commit_work = 'X'

  • sender_address = senderAddr

sender_address_type = 'FAX' "typeSelector

importing

sent_to_all = sent_to_all

tables

packing_list = packing_list

contents_txt = bodyTable

  • 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. "Error handling

when '0'.

statusT = 'Document is sent.'.

when others.

statusT = 'Error during the operation'.

endcase.

write: / statust.