Application Development 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: 

Attach a document to VA02 - Background

Former Member
0 Kudos

Hello !

I really need your help. I have a scenario where I have to attach a PDF document to VA02.

I managed to make it work in dialog mode, but in my scenario I have to make it work in background.

The file will come to SAP via RFC in a lraw field. Then I have to get this file and attach it to VA02.

This is the guide I used to make it work in dialog mode.

Thanks ! If you need any more information, please let me know.

Obs.: My problem is running in background. Any option is welcome. Save the file to a unix folder and upload, or read it straight from the table and attach, etc...

Thales Schmidt

1 ACCEPTED SOLUTION

roberto_vacca2
Active Contributor

Hi.

You can try this:

Use SO_SOLIXTAB_TO_SOLITAB to convert your RAW data do SOLITAB.

Use FM SO_CONVERT_CONTENTS_BIN to convert your binary data

Use FM SO_FOLDER_ROOT_ID_GET to get your folder root data

Compile your objdata like this:

ls_obj_data-objsns = 'O'.

ls_obj_data-objla = sy-langu.

ls_obj_data-objdes = p_desc.

lv_offset = STRLEN( p_file ) - 3.

ls_obj_data-file_ext = p_file+lv_offset(3).

ls_obj_data-objlen = LINES( it_content ) * 255.




Call FM SO_OBJECT_INSERT  to feed your object attachment.


With folder data from SD_FOLDER_ROOT_ID_GET, call BINARY_RELATION_CREATE_COMMIT to generate link between attachment and document


You should get your goal.


Hope to help

Bye

4 REPLIES 4

roberto_vacca2
Active Contributor

Hi.

You can try this:

Use SO_SOLIXTAB_TO_SOLITAB to convert your RAW data do SOLITAB.

Use FM SO_CONVERT_CONTENTS_BIN to convert your binary data

Use FM SO_FOLDER_ROOT_ID_GET to get your folder root data

Compile your objdata like this:

ls_obj_data-objsns = 'O'.

ls_obj_data-objla = sy-langu.

ls_obj_data-objdes = p_desc.

lv_offset = STRLEN( p_file ) - 3.

ls_obj_data-file_ext = p_file+lv_offset(3).

ls_obj_data-objlen = LINES( it_content ) * 255.




Call FM SO_OBJECT_INSERT  to feed your object attachment.


With folder data from SD_FOLDER_ROOT_ID_GET, call BINARY_RELATION_CREATE_COMMIT to generate link between attachment and document


You should get your goal.


Hope to help

Bye

0 Kudos

Old post, but just for anyone looking at this going forward, the object length is calculated incorrectly and you might get corrupt files this way. When you calculate the length don't just take the number of lines * 255 as the last line might not (and most likely won't) have a length of 255. So use :

ls_obj_data-objlen    = ( lines( it_content ) - 1 ) * 255 + strlen( it_content[ lines( it_content ) ]-line ).

Former Member
0 Kudos

Hi Thales,

When you say file will come to SAP via RFC in a lraw field, what exactly do you mean? Iraw field contains file data or file path? if it contains file data, then is there any field that contains file path as well?

You simply have to follow three steps

1) Identify physical location of file on SAP application server.

2) Convert it to the format that can uploaded as an attachment.

3) Call 'SO_DOCUMENT_REPOSITORY_MANAGER' as mentioned in the above link.

If physical location of file could not be identified in the program & if you only have data, then you can simply create a file from the data and save it at a particular location on application server. Then you can pickup same file from application server and load it using same FM. Does that make sense?

Thanks & Regards,

Tejas Asodekar

Former Member
0 Kudos

Thanks ! It's solved !