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: 

Regarding sending Email as attachment

Former Member
0 Kudos

Hi guys.

One unique issue.

I meed to send a file as an attachment to one perticular address. Got to knowt that some function module like So_attmail would work. But that sends the content as body of the mail. But i want the file to be sent as attachment. Could someone help me this plz.

If possible also let me know what are the parameters that i need to pass in short.

Thanks in advance.

Abhi.

9 REPLIES 9

Former Member
0 Kudos

Hai

Go through the following Code

DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: TAB_LINES LIKE SY-TABIX.

DATA L_NUM(3).

  • Creation of the document to be sent

  • File Name

DOC_CHNG-OBJ_NAME = 'SENDFILE'.

  • Mail Subject

DOC_CHNG-OBJ_DESCR = 'Delivered Mail'.

  • Mail Contents

OBJTXT = 'Object text'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

  • Creation of the entry for the compressed document

CLEAR OBJPACK-TRANSF_BIN.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'RAW'.

APPEND OBJPACK.

  • Creation of the document attachment

LOOP AT ITAB_DATA.

CONCATENATE ITAB_DATA-PRODUCTOR

ITAB_DATA-VBELN

ITAB_DATA-POSNR

ITAB_DATA-MATNR INTO OBJBIN.

APPEND OBJBIN.

ENDLOOP.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

OBJHEAD = 'ORDERS'.

APPEND OBJHEAD.

    • Creation of the entry for the compressed attachment

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 1.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'TXT'.

OBJPACK-OBJ_NAME = 'WEBSITE'.

OBJPACK-OBJ_DESCR = 'ORDERS.TXT'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK.

  • Completing the recipient list

  • target recipent

clear RECLIST.

RECLIST-RECEIVER = 'test@here.com'.

RECLIST-EXPRESS = 'X'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

  • copy recipents

clear RECLIST.

RECLIST-RECEIVER = 'secondtest@here.com'.

RECLIST-EXPRESS = 'X'.

RECLIST-REC_TYPE = 'U'.

RECLIST-COPY = 'X'.

APPEND RECLIST.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_CHNG

TABLES

PACKING_LIST = OBJPACK

OBJECT_HEADER = OBJHEAD

CONTENTS_BIN = OBJBIN

CONTENTS_TXT = OBJTXT

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

Thanks & Regards

Sreenivasulu P

Former Member
0 Kudos

Hi Abhi,

Refer this thread

This is the FM to send attachment in mail : 'SO_NEW_DOCUMENT_ATT_SEND_API1'

Rgds,

Prakashsingh

former_member181962
Active Contributor
0 Kudos

Refer these links:

http://www.sap-img.com/abap/sending-email-with-attachment.htm

You can search the forum for the same.

You would find loads of them.

Regards,

Ravi

former_member188685
Active Contributor
0 Kudos

Hi,

Check this

http://www.sapdevelopment.co.uk/reporting/email/emailhome.htm

here you can see sample programs...

Regards

vijay

Former Member
0 Kudos

Hi abhi,

1. There is some trick involved

in the binary files.

2. I have made a program (and it works fantastic)

ONLY 6 LINES FOR EMAILING

BELIEVE ME

ITS A FANTASTIC PROGRAM.

IT WILL WORK LIKE OUTLOOK EXPRESS !

3. The user is provided with

a) file name

b) email address to send mail

and it sends ANY FILE (.xls,.pdf .xyz..)

Instantaneously !

-


4. Make two things first :

1. Include with the name : ZAMI_INCLFOR_MAIL

2. Report with the name : ZAM_TEMP147 (any name will do)

3. Activate both and execute (2)

4. After providing filename, email adress

5. Code for Include :

*----


  • 10.08.2005 Amit M - Created

  • Include For Mail (First Req F16)

  • Modification Log

*

*

*

*

*

*

*

*----


*----


  • Data

*----


DATA: docdata LIKE sodocchgi1,

objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,

objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,

objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objhex LIKE solix OCCURS 10 WITH HEADER LINE,

reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.

DATA: tab_lines TYPE i,

doc_size TYPE i,

att_type LIKE soodk-objtp.

DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.

*----


  • FORM

*----


FORM ml_customize USING objname objdesc.

*----


Clear Variables

CLEAR docdata.

REFRESH objpack.

CLEAR objpack.

REFRESH objhead.

REFRESH objtxt.

CLEAR objtxt.

REFRESH objbin.

CLEAR objbin.

REFRESH objhex.

CLEAR objhex.

REFRESH reclist.

CLEAR reclist.

REFRESH listobject.

CLEAR listobject.

CLEAR tab_lines.

CLEAR doc_size.

CLEAR att_type.

*----


Set Variables

docdata-obj_name = objname.

docdata-obj_descr = objdesc.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_addrecp USING preceiver prec_type.

CLEAR reclist.

reclist-receiver = preceiver.

reclist-rec_type = prec_type.

APPEND reclist.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_addtxt USING ptxt.

CLEAR objtxt.

objtxt = ptxt.

APPEND objtxt.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_prepare USING bypassmemory whatatt_type whatname.

IF bypassmemory = ''.

*----


Fetch List From Memory

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

listobject = listobject

EXCEPTIONS

OTHERS = 1.

IF sy-subrc <> 0.

MESSAGE ID '61' TYPE 'E' NUMBER '731'

WITH 'LIST_FROM_MEMORY'.

ENDIF.

CALL FUNCTION 'TABLE_COMPRESS'

  • IMPORTING

  • COMPRESSED_SIZE =

TABLES

in = listobject

out = objbin

EXCEPTIONS

OTHERS = 1

.

IF sy-subrc <> 0.

MESSAGE ID '61' TYPE 'E' NUMBER '731'

WITH 'TABLE_COMPRESS'.

ENDIF.

ENDIF.

  • -----------

  • Header Data

  • Already Done Thru FM

  • -----------

  • -----------

  • Main Text

  • Already Done Thru FM

  • -----------

  • -----------

  • Packing Info For Text Data

  • -----------

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'TXT'.

APPEND objpack.

  • -----------

  • Packing Info Attachment

  • -----------

att_type = whatatt_type..

DESCRIBE TABLE objbin LINES tab_lines.

READ TABLE objbin INDEX tab_lines.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = att_type.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = whatname.

APPEND objpack.

  • -----------

  • Receiver List

  • Already done thru fm

  • -----------

ENDFORM. "ml_prepare

*----


  • FORM

*----


FORM ml_dosend.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = docdata

put_in_outbox = 'X'

commit_work = 'X' "used from rel. 6.10

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

  • CONTENTS_HEX = objhex

  • OBJECT_PARA =

  • object_parb =

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8

.

IF sy-subrc <> 0.

MESSAGE ID 'SO' TYPE 'S' NUMBER '023'

WITH docdata-obj_name.

ENDIF.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_spooltopdf USING whatspoolid.

DATA : pdf LIKE tline OCCURS 0 WITH HEADER LINE.

*----


Call Function

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = whatspoolid

TABLES

pdf = pdf

EXCEPTIONS

err_no_otf_spooljob = 1

OTHERS = 12.

*----


Convert

PERFORM doconv TABLES pdf objbin.

ENDFORM. "ml_spooltopdf

*----


  • FORM

*----


FORM doconv TABLES

mypdf STRUCTURE tline

outbin STRUCTURE solisti1.

*----


Data

DATA : pos TYPE i.

DATA : len TYPE i.

*----


Loop And Put Data

LOOP AT mypdf.

pos = 255 - len.

IF pos > 134. "length of pdf_table

pos = 134.

ENDIF.

outbin+len = mypdf(pos).

len = len + pos.

IF len = 255. "length of out (contents_bin)

APPEND outbin.

CLEAR: outbin, len.

IF pos < 134.

outbin = mypdf+pos.

len = 134 - pos.

ENDIF.

ENDIF.

ENDLOOP.

IF len > 0.

APPEND outbin.

ENDIF.

ENDFORM. "doconv

*----


CODE FOR PROGRAM

5.

REPORT zam_temp147 .

INCLUDE zami_inclfor_mail.

*----


  • DATA

*----


DATA : itab LIKE tline OCCURS 0 WITH HEADER LINE.

DATA : file_name TYPE string.

data : path like PCFILE-PATH.

data : extension(5) type c.

data : name(100) type c.

*----


  • SELECTION SCREEN

*----


PARAMETERS : receiver TYPE somlreci1-receiver lower case.

PARAMETERS : p_file LIKE rlgrap-filename

OBLIGATORY.

*----


  • AT SELECTION SCREEN

*----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CLEAR p_file.

CALL FUNCTION 'F4_FILENAME'

IMPORTING

file_name = p_file.

*----


  • START-OF-SELECTION

*----


START-OF-SELECTION.

PERFORM ml_customize USING 'Tst' 'Testing'.

PERFORM ml_addrecp USING receiver 'U'.

PERFORM upl.

PERFORM doconv TABLES itab objbin.

PERFORM ml_prepare USING 'X' extension name.

PERFORM ml_dosend.

*----


SUBMIT rsconn01

WITH mode EQ 'INT'

AND RETURN.

*----


  • FORM

*----


FORM upl.

file_name = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = file_name

filetype = 'BIN'

TABLES

data_tab = itab

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17.

path = file_name.

CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'

EXPORTING

complete_filename = path

  • CHECK_DOS_FORMAT =

IMPORTING

  • DRIVE =

EXTENSION = extension

NAME = name

  • NAME_WITH_EXT =

  • PATH =

EXCEPTIONS

INVALID_DRIVE = 1

INVALID_EXTENSION = 2

INVALID_NAME = 3

INVALID_PATH = 4

OTHERS = 5

.

ENDFORM. "upl

*----


regards,

amit m.

Former Member
0 Kudos

Hi,

REPORT zsendemail .

PARAMETERS: psubject(40) type c default 'Hello',

p_email(40) type c default 'test@sapdev.co.uk' .

data: it_packing_list like sopcklsti1 occurs 0 with header line,

it_contents like solisti1 occurs 0 with header line,

it_receivers like somlreci1 occurs 0 with header line,

it_attachment like solisti1 occurs 0 with header line,

gd_cnt type i,

gd_sent_all(1) type c,

gd_doc_data like sodocchgi1,

gd_error type sy-subrc.

data: it_message type standard table of SOLISTI1 initial size 0

with header line.

***********************************************************************

*START-OF-SELECTION.

START-OF-SELECTION.

Perform populate_message_table.

*Send email message, although is not sent from SAP until mail send

*program has been executed(rsconn01)

PERFORM send_email_message.

*Instructs mail send program for SAPCONNECT to send email(rsconn01)

perform initiate_mail_execute_program.

&----


*& Form POPULATE_MESSAGE_TABLE

&----


  • Adds text to email text table

----


form populate_message_table.

Append 'Email line 1' to it_message.

Append 'Email line 2' to it_message.

Append 'Email line 3' to it_message.

Append 'Email line 4' to it_message.

endform. " POPULATE_MESSAGE_TABLE

&----


*& Form SEND_EMAIL_MESSAGE

&----


  • Send email message

----


form send_email_message.

  • Fill the document data.

gd_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

gd_doc_data-obj_langu = sy-langu.

gd_doc_data-obj_name = 'SAPRPT'.

gd_doc_data-obj_descr = psubject.

gd_doc_data-sensitivty = 'F'.

  • Describe the body of the message

clear it_packing_list.

refresh it_packing_list.

it_packing_list-transf_bin = space.

it_packing_list-head_start = 1.

it_packing_list-head_num = 0.

it_packing_list-body_start = 1.

describe table it_message lines it_packing_list-body_num.

it_packing_list-doc_type = 'RAW'.

append it_packing_list.

  • Add the recipients email address

clear it_receivers.

refresh it_receivers.

it_receivers-receiver = p_email.

it_receivers-rec_type = 'U'.

it_receivers-com_type = 'INT'.

it_receivers-notif_del = 'X'.

it_receivers-notif_ndel = 'X'.

append it_receivers.

  • Call the FM to post the message to SAPMAIL

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = gd_doc_data

put_in_outbox = 'X'

importing

sent_to_all = gd_sent_all

tables

packing_list = it_packing_list

contents_txt = it_message

receivers = it_receivers

exceptions

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

others = 8.

  • Store function module return code

gd_error = sy-subrc.

  • Get it_receivers return code

loop at it_receivers.

endloop.

endform. " SEND_EMAIL_MESSAGE

&----


*& Form INITIATE_MAIL_EXECUTE_PROGRAM

&----


  • Instructs mail send program for SAPCONNECT to send email.

----


form initiate_mail_execute_program.

wait up to 2 seconds.

if gd_error eq 0.

submit rsconn01 with mode = 'INT'

with output = 'X'

and return.

endif.

endform. " INITIATE_MAIL_EXECUTE_PROGRAM

- Selvapandian Arunachalam

Former Member
0 Kudos

Hi Abhi,

Have a look at this example:

http://www.sap-img.com/abap/sending-email-with-attachment.htm

http://www.sap-img.com/abap/sending-mail-with-attachment-report-in-background.htm

http://www.sap-img.com/fu016.htm

1. We can send files with attachment.

However, There is some trick involved

in the binary files.

2. I have made a program (and it works fantastic)

ONLY 6 LINES FOR EMAILING

BELIEVE ME

ITS A FANTASTIC PROGRAM.

IT WILL WORK LIKE OUTLOOK EXPRESS !

3. The user is provided with

a) file name

b) email address to send mail

and it sends ANY FILE (.xls,.pdf .xyz..)

Instantaneously !

-


4. Make two things first :

1. Include with the name : ZAMI_INCLFOR_MAIL

2. Report with the name : ZAM_TEMP147 (any name will do)

3. Activate both and execute (2)

4. After providing filename, email adress

5. Code for Include :

*----


  • 10.08.2005 Amit M - Created

  • Include For Mail (First Req F16)

  • Modification Log

*

*

*

*

*

*

*

*----


*----


  • Data

*----


DATA: docdata LIKE sodocchgi1,

objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,

objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,

objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objhex LIKE solix OCCURS 10 WITH HEADER LINE,

reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.

DATA: tab_lines TYPE i,

doc_size TYPE i,

att_type LIKE soodk-objtp.

DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.

*----


  • FORM

*----


FORM ml_customize USING objname objdesc.

*----


Clear Variables

CLEAR docdata.

REFRESH objpack.

CLEAR objpack.

REFRESH objhead.

REFRESH objtxt.

CLEAR objtxt.

REFRESH objbin.

CLEAR objbin.

REFRESH objhex.

CLEAR objhex.

REFRESH reclist.

CLEAR reclist.

REFRESH listobject.

CLEAR listobject.

CLEAR tab_lines.

CLEAR doc_size.

CLEAR att_type.

*----


Set Variables

docdata-obj_name = objname.

docdata-obj_descr = objdesc.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_addrecp USING preceiver prec_type.

CLEAR reclist.

reclist-receiver = preceiver.

reclist-rec_type = prec_type.

APPEND reclist.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_addtxt USING ptxt.

CLEAR objtxt.

objtxt = ptxt.

APPEND objtxt.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_prepare USING bypassmemory whatatt_type whatname.

IF bypassmemory = ''.

*----


Fetch List From Memory

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

listobject = listobject

EXCEPTIONS

OTHERS = 1.

IF sy-subrc <> 0.

MESSAGE ID '61' TYPE 'E' NUMBER '731'

WITH 'LIST_FROM_MEMORY'.

ENDIF.

CALL FUNCTION 'TABLE_COMPRESS'

  • IMPORTING

  • COMPRESSED_SIZE =

TABLES

in = listobject

out = objbin

EXCEPTIONS

OTHERS = 1

.

IF sy-subrc <> 0.

MESSAGE ID '61' TYPE 'E' NUMBER '731'

WITH 'TABLE_COMPRESS'.

ENDIF.

ENDIF.

  • -----------

  • Header Data

  • Already Done Thru FM

  • -----------

  • -----------

  • Main Text

  • Already Done Thru FM

  • -----------

  • -----------

  • Packing Info For Text Data

  • -----------

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'TXT'.

APPEND objpack.

  • -----------

  • Packing Info Attachment

  • -----------

att_type = whatatt_type..

DESCRIBE TABLE objbin LINES tab_lines.

READ TABLE objbin INDEX tab_lines.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = att_type.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = whatname.

APPEND objpack.

  • -----------

  • Receiver List

  • Already done thru fm

  • -----------

ENDFORM. "ml_prepare

*----


  • FORM

*----


FORM ml_dosend.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = docdata

put_in_outbox = 'X'

commit_work = 'X' "used from rel. 6.10

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

  • CONTENTS_HEX = objhex

  • OBJECT_PARA =

  • object_parb =

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8

.

IF sy-subrc <> 0.

MESSAGE ID 'SO' TYPE 'S' NUMBER '023'

WITH docdata-obj_name.

ENDIF.

ENDFORM. "ml_customize

*----


  • FORM

*----


FORM ml_spooltopdf USING whatspoolid.

DATA : pdf LIKE tline OCCURS 0 WITH HEADER LINE.

*----


Call Function

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = whatspoolid

TABLES

pdf = pdf

EXCEPTIONS

err_no_otf_spooljob = 1

OTHERS = 12.

*----


Convert

PERFORM doconv TABLES pdf objbin.

ENDFORM. "ml_spooltopdf

*----


  • FORM

*----


FORM doconv TABLES

mypdf STRUCTURE tline

outbin STRUCTURE solisti1.

*----


Data

DATA : pos TYPE i.

DATA : len TYPE i.

*----


Loop And Put Data

LOOP AT mypdf.

pos = 255 - len.

IF pos > 134. "length of pdf_table

pos = 134.

ENDIF.

outbin+len = mypdf(pos).

len = len + pos.

IF len = 255. "length of out (contents_bin)

APPEND outbin.

CLEAR: outbin, len.

IF pos < 134.

outbin = mypdf+pos.

len = 134 - pos.

ENDIF.

ENDIF.

ENDLOOP.

IF len > 0.

APPEND outbin.

ENDIF.

ENDFORM. "doconv

*----


CODE FOR PROGRAM

5.

REPORT zam_temp147 .

INCLUDE zami_inclfor_mail.

*----


  • DATA

*----


DATA : itab LIKE tline OCCURS 0 WITH HEADER LINE.

DATA : file_name TYPE string.

data : path like PCFILE-PATH.

data : extension(5) type c.

data : name(100) type c.

*----


  • SELECTION SCREEN

*----


PARAMETERS : receiver TYPE somlreci1-receiver lower case.

PARAMETERS : p_file LIKE rlgrap-filename

OBLIGATORY.

*----


  • AT SELECTION SCREEN

*----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CLEAR p_file.

CALL FUNCTION 'F4_FILENAME'

IMPORTING

file_name = p_file.

*----


  • START-OF-SELECTION

*----


START-OF-SELECTION.

PERFORM ml_customize USING 'Tst' 'Testing'.

PERFORM ml_addrecp USING receiver 'U'.

PERFORM upl.

PERFORM doconv TABLES itab objbin.

PERFORM ml_prepare USING 'X' extension name.

PERFORM ml_dosend.

*----


SUBMIT rsconn01

WITH mode EQ 'INT'

AND RETURN.

*----


  • FORM

*----


FORM upl.

file_name = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = file_name

filetype = 'BIN'

TABLES

data_tab = itab

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17.

path = file_name.

CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'

EXPORTING

complete_filename = path

  • CHECK_DOS_FORMAT =

IMPORTING

  • DRIVE =

EXTENSION = extension

NAME = name

  • NAME_WITH_EXT =

  • PATH =

EXCEPTIONS

INVALID_DRIVE = 1

INVALID_EXTENSION = 2

INVALID_NAME = 3

INVALID_PATH = 4

OTHERS = 5

.

ENDFORM. "upl

*----


<b>PS : Reward points if helpful</b>

Thanks,

Ramya.

Manohar2u
Active Contributor
0 Kudos

Refer to this link.

Regds

Manohar

Former Member
0 Kudos

HI

GOOD

CHECK WITH THIS REPORT

report y_cr17_mail.

data method1 like sy-ucomm.

data g_user like soudnamei1.

data g_user_data like soudatai1.

data g_owner like soud-usrnam.

data g_receipients like soos1 occurs 0 with header line.

data g_document like sood4 .

data g_header like sood2.

data g_folmam like sofm2.

data g_objcnt like soli occurs 0 with header line.

data g_objhead like soli occurs 0 with header line.

data g_objpara like selc occurs 0 with header line.

data g_objparb like soop1 occurs 0 with header line.

data g_attachments like sood5 occurs 0 with header line.

data g_references like soxrl occurs 0 with header line.

data g_authority like sofa-usracc.

data g_ref_document like sood4.

data g_new_parent like soodk.

data: begin of g_files occurs 10 ,

text(4096) type c,

end of g_files.

data : fold_number(12) type c,

fold_yr(2) type c,

fold_type(3) type c.

parameters ws_file(4096) type c default 'c:\debugger.txt'.

  • Can me any file fromyour pc ....either xls or word or ppt etc ...

g_user-sapname = sy-uname.

call function 'SO_USER_READ_API1'

exporting

user = g_user

  • PREPARE_FOR_FOLDER_ACCESS = ' '

importing

user_data = g_user_data

  • EXCEPTIONS

  • USER_NOT_EXIST = 1

  • PARAMETER_ERROR = 2

  • X_ERROR = 3

  • OTHERS = 4

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

fold_type = g_user_data-outboxfol+0(3).

fold_yr = g_user_data-outboxfol+3(2).

fold_number = g_user_data-outboxfol+5(12).

clear g_files.

refresh : g_objcnt,

g_objhead,

g_objpara,

g_objparb,

g_receipients,

g_attachments,

g_references,

g_files.

method1 = 'SAVE'.

g_document-foltp = fold_type.

g_document-folyr = fold_yr.

g_document-folno = fold_number.

g_document-objtp = g_user_data-object_typ.

*g_document-OBJYR = '27'.

*g_document-OBJNO = '000000002365'.

*g_document-OBJNAM = 'MESSAGE'.

g_document-objdes = 'sap-img.com testing by program'.

g_document-folrg = 'O'.

*g_document-okcode = 'CHNG'.

g_document-objlen = '0'.

g_document-file_ext = 'TXT'.

g_header-objdes = 'sap-img.com testing by program'.

g_header-file_ext = 'TXT'.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = sy-uname

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header

  • FOLMEM_DATA =

  • RECEIVE_DATA =

.

  • File from the pc to send...

method1 = 'ATTCREATEFROMPC'.

g_files-text = ws_file.

append g_files.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = g_owner

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header

.

method1 = 'SEND'.

g_receipients-recnam = 'MK085'.

g_receipients-recesc = 'B'.

g_receipients-sndex = 'X'.

append g_receipients.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = g_owner

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header.

*-- End of Program

THANKS

MRUTYUN