cancel
Showing results for 
Search instead for 
Did you mean: 

Upload file in Web Dynpro and add to Workflow container as SOFM object

Former Member
0 Kudos

Hi!

I have a Web Dynpro for ABAP application that should send attachments of uploaded files to a workflow container. I have already managed to do this, and it works fine for TXT files, but when I try to attach a WORD (.DOC) file the file looks corrput when I open it from the SAP inbox.

When uploading files in Web Dynpro it is as an XSTRING. I have tried out the following alternatives regarding convertion of the XSTRING before it is inserted in the SOFM object:

1) Convert from XSTRING to STRING using codepage 4110.

Then it is split into a string table of 255 chars

2) Convert from XSTRING to STRING using codepage 4102

Then it is split into a string table of 255 chars

3) Convert from XSTRING to BINARY format

I use function module 'SWL_SOFM_CREATE_WITH_TABLE'

and then swf_create_object lr_sofm 'SOFM' ls_sofm_key.

before I call some macros to fill the container.

Anyone else who have tried to do this with success? I'm greatful for any help.

Regards, Tine

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi!

Thanks I will try this out very soon!

regards, Tine

Former Member
0 Kudos

Hi,

I had the same problem in the last days and finally I got a quite simple solution:

I had a look at the FM SWL_SOFM_CREATE_WITH_TABLE an noticed that it calls another FM (SO_DOCUMENT_INSERT_API1) which has a tables parameter for HEX data and is actually able to create a SOFM object from HEX data.

I simply copied SWL_SOFM_CREATE_WITH_TABLE as a customer FM and applied a few changes to make it accept HEX data:

First I added a new table parameter in the interface which gets the HEX data from the calling application (uploaded data using BIN format):

OBJECT_CONTENT_HEX LIKE SOLIX

Here is the code of the FM (I marked all additional and changed lines with a comment):


function z_test_sofm_create_with_table .
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(NOTE_TITLE) LIKE  SODOCCHGI1-OBJ_DESCR OPTIONAL
*"     VALUE(DOCUMENT_TYPE) LIKE  SOODK-OBJTP DEFAULT SPACE
*"  EXPORTING
*"     VALUE(SOFM_KEY) LIKE  SWOTOBJID-OBJKEY
*"  TABLES
*"      NOTE_TEXT STRUCTURE  SOLISTI1 OPTIONAL
*"      OBJECT_CONTENT_HEX STRUCTURE  SOLIX OPTIONAL
*"  EXCEPTIONS
*"      ERROR_SOFM_CREATION
*"----------------------------------------------------------------------
  data: region like sofd-folrg.
  data: folder_id like soodk.
  data: l_folder_id like soobjinfi1-object_id.
  data: document_data like sodocchgi1.
  data: document_info like sofolenti1.
  data: object_content like solisti1 occurs 0 with header line.
  data: lines like sy-tabix.




*- set default
  if document_type is initial.
    document_type = 'RAW'.
  endif.

*- create office object
*-- get dark folder
  region = 'B'.
  call function 'SO_FOLDER_ROOT_ID_GET'
    exporting
      region                = region
    importing
      folder_id             = folder_id
    exceptions
      communication_failure = 1
      owner_not_exist       = 2
      system_failure        = 3
      x_error               = 4
      others                = 5.
  if sy-subrc ne 0.
    message e696(wl)                       "<== Add message class
            raising error_sofm_creation.
  endif.

*- get description
  if note_title is initial.
    read table note_text index 1.
    note_title = note_text.
  endif.

*-- create office document
  document_data-obj_name = 'ATTACHMENT'.
  document_data-obj_descr = note_title.
  document_data-obj_langu = sy-langu.
  object_content[] = note_text[].
  describe table object_content lines lines.
  document_data-doc_size = ( lines - 1 ) * 255 + strlen( object_content ).

  if object_content[] is initial.                     "<== insert
    describe table object_content_hex lines lines.    "<== insert
    document_data-doc_size = lines * 255.             "<== insert
  endif.                                              "<== insert


  l_folder_id = folder_id.
  call function 'SO_DOCUMENT_INSERT_API1'
    exporting
      folder_id                  = l_folder_id
      document_data              = document_data
      document_type              = document_type
    importing
      document_info              = document_info
    tables
      object_content             = object_content
      contents_hex               = object_content_hex   " <== Insert line
    exceptions
      folder_not_exist           = 1
      document_type_not_exist    = 2
      operation_no_authorization = 3
      parameter_error            = 4
      x_error                    = 5
      enqueue_error              = 6
      others                     = 7.

  if sy-subrc ne 0.
    message e696(wl)                              "<== Add message class
            raising error_sofm_creation.
  endif.

*- set export parameter
  sofm_key = document_info-doc_id.

endfunction.

The returned SOFM key I added to a container element. The element refers to event parameter of type OBJ_RECORD in my ABAP OO Class

Using this function I was able to raise an event by using Method cl_swf_evt_event=>raise

that invoked a workitem containing an Excel-File i had uploaded as binary file and passed to the FM z_test_sofm_create_with_table as document type 'XLS'.

In the woritem preview when clicking on the attachment the file was opened directly in Excel.

Actually the new lines for calculation the file size is not yet quite correct. At first glance it does not seem to cause any trouble, but I will stll check that. In FM SO_OBJECT_INSERT the size is again checked and calculated if initial, so leaving size initial might also be an option.

I hope this helps anyone having a similar issue.

Greetings,

Michael Gulitz