function zo_new_document_send_api1.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(DOCUMENT_DATA) LIKE  SODOCCHGI1 STRUCTURE  SODOCCHGI1
*"     VALUE(DOCUMENT_TYPE) LIKE  SOODK-OBJTP DEFAULT 'RAW'
*"     VALUE(PUT_IN_OUTBOX) LIKE  SONV-FLAG DEFAULT SPACE
*"     VALUE(COMMIT_WORK) LIKE  SONV-FLAG DEFAULT SPACE
*"     VALUE(SENDER) LIKE  SOUD-USRNAM OPTIONAL
*"     VALUE(ORIGINATOR) LIKE  SOOS1-RECEXTNAM OPTIONAL
*"  EXPORTING
*"     VALUE(SENT_TO_ALL) LIKE  SONV-FLAG
*"     VALUE(NEW_OBJECT_ID) LIKE  SOFOLENTI1-OBJECT_ID
*"  TABLES
*"      OBJECT_HEADER STRUCTURE  SOLISTI1 OPTIONAL
*"      OBJECT_CONTENT STRUCTURE  SOLISTI1 OPTIONAL
*"      CONTENTS_HEX STRUCTURE  SOLIX OPTIONAL
*"      OBJECT_PARA STRUCTURE  SOPARAI1 OPTIONAL
*"      OBJECT_PARB STRUCTURE  SOPARBI1 OPTIONAL
*"      RECEIVERS STRUCTURE  SOMLRECI1
*"  EXCEPTIONS
*"      TOO_MANY_RECEIVERS
*"      DOCUMENT_NOT_SENT
*"      DOCUMENT_TYPE_NOT_EXIST
*"      OPERATION_NO_AUTHORIZATION
*"      PARAMETER_ERROR
*"      X_ERROR
*"      ENQUEUE_ERROR
*"----------------------------------------------------------------------

data begin of object_id.
        include structure soodk.
data end of object_id.
data begin of object_hd_change.
        include structure sood1.
data end of object_hd_change.
data begin of object_fl_change.
        include structure sofm1.
data end of object_fl_change.
data begin of rec_table occurs 1.
        include structure soos1.
data end of rec_table.
data rcode like sonv-rcode.
data i like sy-tabix.
data: hex_size like sy-tabix.

data l_hex         type so_tranbin.
data l_file_ext    type sood-file_ext.
data l_file_format type rlgrap-filetype.

* * transfer folder data
  perform transfer_objdat_to_obj using document_data
                                       object_hd_change
                                       object_fl_change.

* note 873845 - use new form
  perform format_prepare_for_insert in program sapfssoa
       using space
             contents_hex[]
    changing object_header[]
             object_content[]
             document_type
             object_hd_change-file_ext
             rcode.
  if rcode = 1.
    message e067 raising parameter_error.
  endif.
* * transfer receiver data
  perform transfer_rec_to_tab tables receivers
                                     rec_table.
* * for old types move size to header
  perform size_to_header tables object_header
                         using  document_type
                                document_data-doc_size.

  call function 'SO_OBJECT_SEND'
       exporting
*           EXTERN_ADDRESS             = ' '
*           FOLDER_ID                  = ' '
*           FORWARDER                  = ' '
            originator                 = originator    "st sept 2008
            originator_type            = 'U'           "st sept 2008

            object_fl_change           = object_fl_change
            object_hd_change           = object_hd_change
*           OBJECT_ID                  = ' '
            object_type                = document_type
            outbox_flag                = put_in_outbox
*           OWNER                      = ' '
*           STORE_FLAG                 = ' '
       importing
            object_id_new              = object_id
            sent_to_all                = sent_to_all
       tables
            objcont                    = object_content
            objhead                    = object_header
            objpara                    = object_para
            objparb                    = object_parb
            receivers                  = rec_table
       exceptions
            object_not_sent            = 15
            object_type_not_exist      = 17
            operation_no_authorization = 21
            parameter_error            = 23
            too_much_receivers         = 73
            others                     = 1000.
  case sy-subrc.
    when ok.
    when object_not_sent.
      perform transfer_tab_to_rec tables rec_table
                                         receivers.
      raise document_not_sent.
    when too_much_receivers.
      raise too_many_receivers.
    when object_type_not_exist.
      raise document_type_not_exist.
    when operation_no_authorization.
      raise operation_no_authorization.
    when parameter_error.
      raise parameter_error.
    when others.
      raise x_error.
  endcase.

  move object_id to new_object_id.
  perform transfer_tab_to_rec tables rec_table
                                     receivers.
  if commit_work = on.
    commit work.
  endif.
endfunction.