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

sap mail attachment download using abap program

Former Member
0 Likes
1,777

Hi All,

I need to download sap mail attachement using abap program to application server i.e as soon as I received any sap mail in my workplace I need to download the attachment to application server , please suggest any FM or how to do the same.

thanks

bobby

Hi All,

I need to download sap mail attachement using abap program to application server i.e as soon as I received any sap mail in my workplace I need to download the attachment to application server , please suggest any FM or how to do the same.

thanks

bobby

2 REPLIES 2
Read only

vinod_vemuru2
Active Contributor
0 Likes
744

Hi,

Check out the FMs SO_ATTACHMENT_READ and SO_OBJECT_READ. Place break point in these FMs and go to SBWP, open the attachment and see how the input parameters are handled. You can check other FMs of the FG and SOobj FMs.

Thanks,

Vinod.

Read only

0 Likes
744

Hi Vinod,

Thanks for your input ,

I have written the following code for reading the mail attachment , but now I have to problem ofputting the attachment on application server in a folder.

&----


*& Report ZTESTPK

*&

&----


*&

*&

&----


REPORT ztestpk.

  • Data declaration for SO_USER_READ_API1

DATA: BEGIN OF user_data OCCURS 0.

INCLUDE STRUCTURE soudatai1.

DATA: END OF user_data.

DATA: username TYPE soudnamei1.

  • Data Declaration for SO_FOLDER_READ_API1

DATA: BEGIN OF mail_content OCCURS 0.

INCLUDE STRUCTURE sofolenti1.

DATA: END OF mail_content.

  • Data Declaration for SO_OBJECT_READ + SO_OBJECT_DELETE

DATA: BEGIN OF i_folder_id OCCURS 0.

INCLUDE STRUCTURE soodk.

DATA: END OF i_folder_id.

DATA: username2 LIKE soud-usrnam.

DATA: BEGIN OF i_object_id OCCURS 0.

INCLUDE STRUCTURE soodk.

DATA: END OF i_object_id.

DATA: BEGIN OF object_contents OCCURS 0.

INCLUDE STRUCTURE soli.

DATA: END OF object_contents.

DATA: BEGIN OF object_header OCCURS 0.

INCLUDE STRUCTURE sood2.

DATA: END OF object_header.

DATA: BEGIN OF i_att_list OCCURS 0.

INCLUDE STRUCTURE sood5.

DATA: END OF i_att_list.

DATA: BEGIN OF i_filter OCCURS 0.

INCLUDE STRUCTURE sofor.

DATA: END OF i_filter.

DATA: BEGIN OF i_attachment OCCURS 0.

INCLUDE STRUCTURE soodk.

DATA: END OF i_attachment.

DATA: wa_hd_display LIKE sood2,

wa_rc_display LIKE soos6,

wa_fl_display LIKE sofm2.

DATA: wa_hd_change LIKE sood1,

wa_fl_change LIKE sofm1.

DATA: i_objcont LIKE soli OCCURS 0 WITH HEADER LINE,

i_objhead LIKE soli OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.

PERFORM find_user.

PERFORM find_inbox.

*----


  • FORM FIND_USER

*----


FORM find_user.

  • Set current username

username-sapname = sy-uname.

username2 = sy-uname.

  • Find user ID

CALL FUNCTION 'SO_USER_READ_API1'

EXPORTING

user = username

IMPORTING

user_data = user_data.

ENDFORM. "FIND_USER

*----


  • FORM FIND_INBOX

*----


  • Find ID of current users inbox

*----


FORM: find_inbox.

  • Find folder ID

CALL FUNCTION 'SO_FOLDER_READ_API1'

EXPORTING

folder_id = user_data-inboxfol

TABLES

folder_content = mail_content.

  • Set folder id details

i_folder_id-objtp = mail_content-doc_id(3).

i_folder_id-objyr = mail_content-doc_id+3(2).

i_folder_id-objno = mail_content-doc_id+5(12).

  • Set object id details

i_object_id-objtp = mail_content-object_id(3).

i_object_id-objyr = mail_content-object_id+3(2).

i_object_id-objno = mail_content-object_id+5(12).

  • Read mail details using object

CALL FUNCTION 'SO_OBJECT_READ'

EXPORTING

folder_id = i_folder_id

object_id = i_object_id

owner = username2

IMPORTING

object_hd_display = object_header

TABLES

objcont = object_contents.

  • read list of attachments

CALL FUNCTION 'SO_ATTACHMENT_LIST_READ'

EXPORTING

object_id = i_object_id

TABLES

OBJECTS = i_att_list

EXCEPTIONS

system_failure = 1

communication_failure = 2

OTHERS = 3.

i_filter-nocont = 'X'.

i_filter-sndi = 'X'.

APPEND i_filter.

READ TABLE i_filter INDEX 1.

LOOP AT i_att_list.

i_attachment-objtp = i_att_list-objtp.

i_attachment-objyr = i_att_list-objyr.

i_attachment-objno = i_att_list-objno.

APPEND i_attachment.

READ TABLE i_attachment INDEX 1.

CALL FUNCTION 'SO_ATTACHMENT_READ'

EXPORTING

filter = i_filter

object_id = i_object_id

attach_id = i_attachment

owner = sy-uname

IMPORTING

object_hd_display = wa_hd_display

object_rc_display = wa_rc_display

object_fl_display = wa_fl_display

TABLES

objcont = i_objcont

objhead = i_objhead

EXCEPTIONS

active_user_not_exist = 1

object_not_exist = 2

operation_no_authorization = 3

owner_not_exist = 4

parameter_error = 5

substitute_not_active = 6

substitute_not_defined = 7

x_error = 8

communication_failure = 9

system_failure = 10

OTHERS = 11.

ENDLOOP.

ENDFORM. "find_inbox.

Thanks

Bobby

Edited by: Bobby G on Apr 30, 2010 2:33 PM