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

RFC call of BAPI_DOCUMENT_CREATE2

Former Member
0 Likes
1,499

Hi all,

I'm trying to attach a photo to PM notification (tcode iw22). I use FM BAPI_DOCUMENT_CREATE2 to upload a photo from local disc C.

Here is my code:

ls_drad-objecttype = 'PMQMEL'.
ls_drad-objectkey = I_MESSAGENUMBER.
APPEND ls_drad TO lt_drad.

ls_doc_data-documenttype = 'MS1'.
ls_doc_data-documentnumber = '*'.
ls_doc_data-description = 'Photo description'.


LOOP AT t_files ASSIGNING <fs_file>.

     ls_files-documenttype = 'MS1'.
     ls_files-storagecategory = 'DMS_C1_ST'.
     ls_files-docfile = <fs_file>-filepath.
     ls_files-wsapplication = <fs_file>-wsapplication.
     ls_files-description = <fs_file>-description.
     ls_files-SOURCEDATACARRIER = 'DEFAULT'.
     APPEND ls_files TO lt_files.
ENDLOOP.

   CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
       EXPORTING
         documentdata               = ls_doc_data
      IMPORTING
        documentnumber             = docnum
        return                     = ret
      TABLES
        objectlinks                = lt_drad
        documentfiles              = lt_files
               .

     IF sy-subrc EQ 0.
       CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
     ENDIF.

It works fine when I execute this code, my photos are succesfully attached.

The problem appears when I try to execute my code by RFC. I got the following dump message:


CALL_FUNCTION_SEND_ERROR

Short text

    " " (I/O error)

What happened?

    "connection closed (no data)"

An error occurred when executing a Remote Function Call.

SY-MSGTY I

SY-MSGID 26

SY-MSGNO 253

SY-MSGV1 C:\Photos\photo1.jpg

It means "Error while checking and storing C:\Photos\photo1.jpg".

I guess this happens because the system can`t find the path C:\xxx while in RFC mode, but I`m not sure.

So my question is how to attach JPG files to PM notification by RFC?

Any help`s appreciated,

Thanks!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,178

Hi Anton,

For FM BAPI_DOCUMENT_CREATE2 ,

pass hostname(From where you are calling(front end computer name) ) to parameter HOSTNAME.

Regards,

Ravi.

Hi all,

I'm trying to attach a photo to PM notification (tcode iw22). I use FM BAPI_DOCUMENT_CREATE2 to upload a photo from local disc C.

Here is my code:

ls_drad-objecttype = 'PMQMEL'.
ls_drad-objectkey = I_MESSAGENUMBER.
APPEND ls_drad TO lt_drad.

ls_doc_data-documenttype = 'MS1'.
ls_doc_data-documentnumber = '*'.
ls_doc_data-description = 'Photo description'.


LOOP AT t_files ASSIGNING <fs_file>.

     ls_files-documenttype = 'MS1'.
     ls_files-storagecategory = 'DMS_C1_ST'.
     ls_files-docfile = <fs_file>-filepath.
     ls_files-wsapplication = <fs_file>-wsapplication.
     ls_files-description = <fs_file>-description.
     ls_files-SOURCEDATACARRIER = 'DEFAULT'.
     APPEND ls_files TO lt_files.
ENDLOOP.

   CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
       EXPORTING
         documentdata               = ls_doc_data
      IMPORTING
        documentnumber             = docnum
        return                     = ret
      TABLES
        objectlinks                = lt_drad
        documentfiles              = lt_files
               .

     IF sy-subrc EQ 0.
       CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
     ENDIF.

It works fine when I execute this code, my photos are succesfully attached.

The problem appears when I try to execute my code by RFC. I got the following dump message:


CALL_FUNCTION_SEND_ERROR

Short text

    " " (I/O error)

What happened?

    "connection closed (no data)"

An error occurred when executing a Remote Function Call.

SY-MSGTY I

SY-MSGID 26

SY-MSGNO 253

SY-MSGV1 C:\Photos\photo1.jpg

It means "Error while checking and storing C:\Photos\photo1.jpg".

I guess this happens because the system can`t find the path C:\xxx while in RFC mode, but I`m not sure.

So my question is how to attach JPG files to PM notification by RFC?

Any help`s appreciated,

Thanks!

3 REPLIES 3
Read only

Former Member
0 Likes
1,179

Hi Anton,

For FM BAPI_DOCUMENT_CREATE2 ,

pass hostname(From where you are calling(front end computer name) ) to parameter HOSTNAME.

Regards,

Ravi.

Read only

0 Likes
1,178

Hi Ravi,

thanks for your answer!

I added the HOSTNAME, PF_FTP_DEST and PF_HTTP_DEST parameters. It is still not working but in SLG1 I can see the following error:

RFC server sapftp cannot be started - 1: The valid RFC handle 1 refers to an invalid memory

I checked SM59 and found SAPFTP, SAPHTTP, SAPHTTPA (all connections succesfully tested), but no SAPFTPA at all.

I also checked OACT, there DMS_C1_ST is linked to H3 repository. In OAC0 I see that H3 repository storage type is "SAP system database" and not a content server.

It seems I have to configure the whole mechanism but I dont know how.

Best wishes,

Anton.

Read only

1,178

The problem is solved.

To attach a file in background you should first upload it to application server. That is, the server can't find the path like "C:\myFiles\...". You should pass the path like "/path/to/file" instead. That path is realtive to appserver root.

To upload the file to appserver I use the following code:

TYPES: begin of ty_bindata,

               line type raw,

             end of ty_bindata.

DATA: t_bindata TYPE TABLE OF ty_bindata OCCURS 0.

field-symbols: <x> type any.

CONSTANTS: c_path_name TYPE localfile VALUE '/tmp/'.

" *******

" here the t_bindata is being filled by hex values

" ...

" *******

CONCATENATE c_path_name
                   lv_filename  " my file name
                   INTO w_file_name.

CONDENSE w_file_name  NO-GAPS.

OPEN DATASET w_file_name FOR OUTPUT
                                IN BINARY MODE
                                MESSAGE w_msg.
     IF sy-subrc <> 0.
       " message handling
     ENDIF.

     loop at t_bindata ASSIGNING <fs_bindata>.
       ASSIGN <fs_bindata>-line to <x> TYPE 'X'.
       TRANSFER <x> to w_file_name.
     endloop.

     CLOSE DATASET w_file_name.

After the file is uploaded you can attach it to everywhere you want:

      ls_files-documenttype = 'MS1'.
     ls_files-storagecategory = 'DMS_C1_ST'.
     ls_files-docfile = w_file_name.           " filename contains the path to file on the appserver
     ls_files-wsapplication = <fs_file>-wsapplication.
     ls_files-description = <fs_file>-description.
     ls_files-sourcedatacarrier = 'DEFAULT'.
     APPEND ls_files TO lt_files.

CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
     EXPORTING
       documentdata   = ls_doc_data
       pf_ftp_dest    = 'SAPFTPA'
       pf_http_dest   = 'SAPHTTPA'
     IMPORTING
       documentnumber = docnum
       return         = ret
     TABLES
       objectlinks    = lt_drad
       documentfiles  = lt_files.