Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Save Image @SAPoffice

stefan_heitzer
Participant
0 Likes
2,100

Hi everybody,

I'm trying to develop an application which runs on a mobile device. There you should be able to make a picture with the camera and save it in the SAPoffice. There should also be a link generated between the image and the SAP object. What I did so far was the following:

I implemented a function which is able to make a picture. This picture is going to be transformed into a BASE64 string. Afterwards I send this data to the SAP System. I create a SAP Object and now I want to store the image. First of all I created a XSTRING out of the BASE64 string then I converted the XSTRING into BINARY. And now I'm callling the FM 'SO_DOCUMENT_INSERT_API' but here I get an error. The coding looks like the following:


DATA:
         lf_folder TYPE soodk,
         lf_folderid TYPE soobjinfi1-object_id,
         lf_size TYPE i,
         lt_content TYPE TABLE OF solisti1,
         ls_document_data TYPE sodocchgi1,
         lf_doctype TYPE soodk-objtp,
         lf_docinfo TYPE sofolenti1,
         lt_words TYPE TABLE OF string,
         lf_token TYPE string,
         lf_att_key TYPE swotobjid-objkey,
         lf_picture TYPE xstring.
  

f_folder = 'FOL28000000000004'. "Just named it like this for test purposes
lf_folderid = lf_folder.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
     EXPORTING
         text   = is_meldung-pic1
     IMPORTING
         buffer = lf_picture.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
     EXPORTING
         buffer          = lf_picture
         append_to_table = 'X'
     IMPORTING
         output_length   = lf_size
     TABLES
         binary_tab      = lt_content.

ls_document_data-obj_name = 'ATTACHMENT'.
CONCATENATE 'image' af_qmnum INTO ls_document_data-obj_descr.
ls_document_data-obj_langu = sy-langu.
ls_document_data-doc_size = lf_size.
ls_document_data-no_change = 'X'.
lf_doctype = 'jpg'.

CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
     EXPORTING
         folder_id                  = lf_folderid
         document_data              = ls_document_data
         document_type              = lf_doctype
     IMPORTING
         document_info              = lf_docinfo
     TABLES
         object_content             = lt_content
         contents_hex               = lt_content
     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 <> 0.
     ENDIF.

The exception that I get is 'CX_SY_DYN_CALL_ILLEGAL_TYPE'. I really hope someone can help me solving this problem... so looking forward to your answers.

Greetings

Stef

1 ACCEPTED SOLUTION
Read only

stefan_heitzer
Participant
0 Likes
1,800

Hi everybody,

here is the link to the blog post! hope you enjoy! Greetings

Stef

Hi everybody,

I'm trying to develop an application which runs on a mobile device. There you should be able to make a picture with the camera and save it in the SAPoffice. There should also be a link generated between the image and the SAP object. What I did so far was the following:

I implemented a function which is able to make a picture. This picture is going to be transformed into a BASE64 string. Afterwards I send this data to the SAP System. I create a SAP Object and now I want to store the image. First of all I created a XSTRING out of the BASE64 string then I converted the XSTRING into BINARY. And now I'm callling the FM 'SO_DOCUMENT_INSERT_API' but here I get an error. The coding looks like the following:


DATA:
         lf_folder TYPE soodk,
         lf_folderid TYPE soobjinfi1-object_id,
         lf_size TYPE i,
         lt_content TYPE TABLE OF solisti1,
         ls_document_data TYPE sodocchgi1,
         lf_doctype TYPE soodk-objtp,
         lf_docinfo TYPE sofolenti1,
         lt_words TYPE TABLE OF string,
         lf_token TYPE string,
         lf_att_key TYPE swotobjid-objkey,
         lf_picture TYPE xstring.
  

f_folder = 'FOL28000000000004'. "Just named it like this for test purposes
lf_folderid = lf_folder.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
     EXPORTING
         text   = is_meldung-pic1
     IMPORTING
         buffer = lf_picture.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
     EXPORTING
         buffer          = lf_picture
         append_to_table = 'X'
     IMPORTING
         output_length   = lf_size
     TABLES
         binary_tab      = lt_content.

ls_document_data-obj_name = 'ATTACHMENT'.
CONCATENATE 'image' af_qmnum INTO ls_document_data-obj_descr.
ls_document_data-obj_langu = sy-langu.
ls_document_data-doc_size = lf_size.
ls_document_data-no_change = 'X'.
lf_doctype = 'jpg'.

CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
     EXPORTING
         folder_id                  = lf_folderid
         document_data              = ls_document_data
         document_type              = lf_doctype
     IMPORTING
         document_info              = lf_docinfo
     TABLES
         object_content             = lt_content
         contents_hex               = lt_content
     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 <> 0.
     ENDIF.

The exception that I get is 'CX_SY_DYN_CALL_ILLEGAL_TYPE'. I really hope someone can help me solving this problem... so looking forward to your answers.

Greetings

Stef

11 REPLIES 11
Read only

Former Member
0 Likes
1,800

Hi Stef,

Please use 'SOLIX_TAB' for passing in CONTENTS_HEX parameter.

This is the issue. You are using LT_CONTENT for both OBJECT_CONTENT and CONTENTS_HEX.

Please change the TYPE and try.

-Sowmya

Read only

0 Likes
1,800

Hi Sowmya,

thanks for your quick reply. I leaved the "CONTENTS_HEX" away and it works. I now get back a document-info which contains a document-id. Am I now able to view the created attachment anywhere? I mean I stored it in a folder. Looking forward to your answer.

Greetings

Stef

Read only

stefan_heitzer
Participant
0 Likes
1,800

Ok hi again,

I made it to run the "SO_DOCUMENT_INSERT_API1" and also get back a document-info including a document-id. The next step is normally to build up a linking between the created attachment and the SAP object, isn't it? The coding for this looks like the following:


lo_object_a-instid = af_qmnum.
lo_object_a-typeid = 'BUS7051'.
lo_object_a-catid = 'BO'.

lo_object_b-instid = lf_att_key.
lo_object_b-typeid = 'MESSAGE'.
lo_object_b-catid = 'BO'.

TRY.
     CALL METHOD cl_binary_relation=>create_link
         EXPORTING
           is_object_a = lo_object_a
           is_object_b = lo_object_b
           ip_reltype  = 'ATTA'.

ENDTRY.

IF sy-subrc = 0.
       COMMIT WORK AND WAIT.
ENDIF.

sy-subrc is actually 0 --> the creating must be successfully but ... where is the attachment now? When I click on the qmnum I don't see any attachments. Is it possible to have look into the folder where the attachment should be? Looking forward to your answers!

Greetings

Stef

Read only

0 Likes
1,800

Hi Stef,

Please check in the tcode 'SBWP'.

-Sowmya

Read only

0 Likes
1,800

Hi Sowmya,

well. In the Business Workplace is no content at all. Even if I create manually for a special notification (iw29) an attachment, I'm not able to find it. Are there special settings which have to be made?

Greetings.

Read only

stefan_heitzer
Participant
0 Likes
1,800

Hi everybody,

good news. I can finally store my image and can also see it as an attachment for the notification. The problem I also had to deal with was the choise of the right business object (in my case BUS2038). But at first a logical question.

Are these the right things I have to do?

I get as a String the Base64 encoded image. With this String I call the following FM:


CALL FUNCTION 'SSFC_BASE64_DECODE'
      EXPORTING
        b64data = lf_base64_picture
      IMPORTING
        bindata = lf_xstring_picture.

Afterwards I call the following FM:


CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
       EXPORTING
         buffer          = lf_xstring_picture
         append_to_table = 'X'
       IMPORTING
         output_length   = lf_size
       TABLES
         binary_tab      = lt_content.

And then only:


CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
       EXPORTING
         folder_id      = lf_folderid
         document_data  = ls_document_data
         document_type  = lf_doctype
       IMPORTING
         document_info  = lf_docinfo
       TABLES
         object_content = lt_content.

I ask you due to the fact that when I doubleclick on the attachment I can open it but don't see the picture --> Message: "The image can not be opened in Windows Photo Viewer, because the file may be corrupt or too large"

I changed the size of the picture to 640x480 but this doesn't changed anything. Do you have any hints?


Greetings

Stef

Read only

0 Likes
1,800

Good to know Stef.

Read only

stefan_heitzer
Participant
0 Likes
1,800

Hi again,

I have still the problem that the image can't be displayed. I checked it right now whether the base64 String is correct and it is. If I enter it at a decoder I receive the correct image which I made before. Maybe there's a problem with transforming it into the xstring??? The FMs which I called are listed above. I really hope somebody is able to help me.

Greetings

Stef

Read only

0 Likes
1,800

hi again,

good news! It finally works! I'm going to write a blog-post which deals with the whole procedure. When it's done I'm going to post it here

Thanks again for all your help.

Greetings

Read only

0 Likes
1,800

That will be great it will be very useful for everyone

Read only

stefan_heitzer
Participant
0 Likes
1,801

Hi everybody,

here is the link to the blog post! hope you enjoy! Greetings

Stef