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

Urgent : - Some Error in code while sending attachment thru SAP

Former Member
0 Likes
1,582

hiii,

i have posted a problem in the following thread.

at some extent Surpreet is able to solve the problem, but now we r stuck to this that email is coming with attachment but not the exact that i am attching and trying to send the mail.

can any one check this code and rectify if any error is there.



REPORT YBALTEST.

DATA: gd_cnt TYPE i,
gd_sent_all(1) TYPE c,
gd_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc.


DATA: it_message LIKE solisti1 OCCURS 0 WITH HEADER LINE,
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.

* Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0,
row(255).
DATA: END OF it_pdf_output.

START-OF-SELECTION.
perform send_email_message .

*&---------------------------------------------------------------------*
*& Form SEND_EMAIL_MESSAGE
*&---------------------------------------------------------------------*
* Send email message
*----------------------------------------------------------------------*
FORM send_email_message.
DATA: tab_lines LIKE SY-TABIX.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:test.pdf'
filetype = 'BIN'
TABLES
data_tab = it_pdf_output .

* Populate the subject/generic message attributes
concatenate 'Attached is the '
' are waiting for.' into it_message.
append it_message.

DESCRIBE TABLE it_message LINES tab_lines.
READ TABLE it_message INDEX tab_lines.

gd_doc_data-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_message ).
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SENDFILE'.
gd_doc_data-obj_descr = 'Attachement'.
gd_doc_data-sensitivty = 'O'.

describe table it_pdf_output lines tab_lines.
* Describe the body of the message

CLEAR it_packing_list-transf_bin.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
it_packing_list-doc_type = 'RAW'.
it_packing_list-body_num = tab_lines.
APPEND it_packing_list.

describe table it_pdf_output lines tab_lines.

CLEAR it_packing_list.
it_packing_list-transf_bin = 'X'.
it_packing_list-head_start = 1.
it_packing_list-head_num = 1.
it_packing_list-body_start = 1.
it_packing_list-doc_type = 'RAW'.
it_packing_list-body_num = tab_lines.
it_packing_list-doc_size = tab_lines * 255.
it_packing_list-OBJ_DESCR = ' object '.
it_packing_list-obj_name = 'MAIL'.
APPEND it_packing_list.

it_receivers-receiver = '[email protected]'.
it_receivers-rec_type = 'U'.
it_receivers-com_type = 'INT'.
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'
commit_work = 'X'
* IMPORTING
* sent_to_all = gd_sent_all
TABLES
packing_list = it_packing_list
contents_txt = it_message
contents_bin = it_pdf_output
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.
ENDFORM. " SEND_EMAIL_MESSAGE

thanx

abhishek suppal

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,558

It will work even if you dont use OBJBIN . Just comment the following line in your original code -

it_packing_list-obj_name = 'MAIL'.

However it is a good practice to pass compatible / similar parameters to FM.

Cheers

hiii,

i have posted a problem in the following thread.

at some extent Surpreet is able to solve the problem, but now we r stuck to this that email is coming with attachment but not the exact that i am attching and trying to send the mail.

can any one check this code and rectify if any error is there.



REPORT YBALTEST.

DATA: gd_cnt TYPE i,
gd_sent_all(1) TYPE c,
gd_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc.


DATA: it_message LIKE solisti1 OCCURS 0 WITH HEADER LINE,
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.

* Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0,
row(255).
DATA: END OF it_pdf_output.

START-OF-SELECTION.
perform send_email_message .

*&---------------------------------------------------------------------*
*& Form SEND_EMAIL_MESSAGE
*&---------------------------------------------------------------------*
* Send email message
*----------------------------------------------------------------------*
FORM send_email_message.
DATA: tab_lines LIKE SY-TABIX.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:test.pdf'
filetype = 'BIN'
TABLES
data_tab = it_pdf_output .

* Populate the subject/generic message attributes
concatenate 'Attached is the '
' are waiting for.' into it_message.
append it_message.

DESCRIBE TABLE it_message LINES tab_lines.
READ TABLE it_message INDEX tab_lines.

gd_doc_data-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_message ).
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SENDFILE'.
gd_doc_data-obj_descr = 'Attachement'.
gd_doc_data-sensitivty = 'O'.

describe table it_pdf_output lines tab_lines.
* Describe the body of the message

CLEAR it_packing_list-transf_bin.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
it_packing_list-doc_type = 'RAW'.
it_packing_list-body_num = tab_lines.
APPEND it_packing_list.

describe table it_pdf_output lines tab_lines.

CLEAR it_packing_list.
it_packing_list-transf_bin = 'X'.
it_packing_list-head_start = 1.
it_packing_list-head_num = 1.
it_packing_list-body_start = 1.
it_packing_list-doc_type = 'RAW'.
it_packing_list-body_num = tab_lines.
it_packing_list-doc_size = tab_lines * 255.
it_packing_list-OBJ_DESCR = ' object '.
it_packing_list-obj_name = 'MAIL'.
APPEND it_packing_list.

it_receivers-receiver = '[email protected]'.
it_receivers-rec_type = 'U'.
it_receivers-com_type = 'INT'.
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'
commit_work = 'X'
* IMPORTING
* sent_to_all = gd_sent_all
TABLES
packing_list = it_packing_list
contents_txt = it_message
contents_bin = it_pdf_output
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.
ENDFORM. " SEND_EMAIL_MESSAGE

thanx

abhishek suppal

11 REPLIES 11
Read only

Former Member
0 Likes
1,558

hi

one error i left

describe table it_pdf_output lines tab_lines.

  • Describe the body of the message

CLEAR it_packing_list-transf_bin.

it_packing_list-head_start = 1.

it_packing_list-head_num = 0.

it_packing_list-body_start = 1.

it_packing_list-doc_type = 'RAW'.

it_packing_list-body_num = tab_lines.

APPEND it_packing_list.

describe table it_pdf_output lines tab_lines

delete first describe

although it will not remove the error we are facing

regards

Read only

Former Member
0 Likes
1,558

What are you getting as the attachment? Is it just unreadable or some other pdf document?

Read only

0 Likes
1,558

just unreadable

like this

€¥ä™„ã„­ã˜®â”î¢íà¨ãˆ±ãŒ¸ã€ æ¼ æ©¢ã° â¼¼æ¥Œæ•®ç‰¡ç©©æ‘¥ã„ ä°¯ãŒ ã”²ã˜²â¼¶âãˆ±ãœ¸ä”¯ã ã¤·ã´ä¸¯ãˆ â¼¹â”ã¤²ã”¹ã€´ä ¯å¬ ã„ ã˜µâ€·ãˆ¹å´¶ã¸¾æ”æ‘®æ‰¯àµªâ€ â€ â€ â€ â€ à¨ç‰¸æ™¥à¨ãˆ±ãŒ¸ã˜ à´±ã€Šã€°ã€°ã€°ã„°â€¶ã€°ã€°â€°àµ®ã€Šã€°ã€°ãˆ°ã¤¶â€¹ã€°ã€°â€°àµ®ã€Šã€°ã€°ãˆ°ãŒ¸â€·ã€°ã€°â€°àµ®ã€Šã€°ã€°ãŒ°ãœ±â€³ã€°ã€°â€°àµ®ã€Šã€°ã€°ãŒ°ãŒ³â€²ã€°ã€°â€°àµ®ã€Šã€°ã€°ãŒ°ã µâ€°ã€°ã€°â€°àµ®ã€Šã€°ã€°ãŒ°ã„¶â€¸ã€°ã€°â€°àµ®ã€Šã€°ã€°ãŒ°ã€¸â€²ã€°ã€°â€°àµ®ã€Šã€°ã€°ãŒ°ã ¸â€°ã€°ã€°â€°àµ®ã€Šã€°ã€°ã˜°ã”µâ€±ã€°ã€°â€°àµ®ã€Šã€°ã€°ãˆ´ãµâ€¹ã€°ã€°â€°àµ®ã€Šã€°ã€°ãˆ´ãˆ¶â€²ã€°ã€°â€°àµ®ã€Šã€°ã€°ãˆ´ã€·â€³ã€°ã€°â€°àµ®ã€Šã€°ã€°ãˆ´ã˜¸â€¶ã€°ã€°â€°àµ®ã€Šã€°ã€°ãˆ´ãˆ¹â€°ã€°ã€°â€°àµ®ã€Šã€°ã€°ãŒ´ã °â€´ã€°ã€°â€°àµ®ã€Šã€°ã€°ãŒ´ãŒ±â€¸ã€°ã€°â€°àµ®ã€Šã€°ã€°ãŒ´ã³â€µã€°ã€°â€°àµ®ã€Šã€°ã€°ãŒ´ã„µâ€¸ã€°ã€°â€°àµ®

《〰〰㌴㜵′〰〰‰൮《〰〰㌴㐷‸〰〰‰൮《〰〰㌴㐹‵〰〰‰൮《〰〰㐴〱‶〰〰‰൮《〰〰㐴㘱‰〰〰‰൮《〰〰㐴㌳‶〰〰‰൮《〰〰㐴㌴‹〰〰‰൮《〰〰㐴㤴′〰〰‰൮《〰〰㐴㤵‴〰〰‰൮《〰〰㐴㌶‶〰〰‰൮《〰〰㐴㘷‴〰〰‰൮《〰〰㐴ㄸ‸〰〰‰൮《〰〰㔴㈰‴〰〰‰൮《〰〰㔴㔲‰〰〰‰൮《〰〰㔴㠳‶〰〰‰൮《〰〰㔴㐴‰〰〰‰൮《〰〰㔴㜵‷〰〰‰൮《〰〰㔴㌶‱〰〰‰൮《〰〰㔴㠶‵〰〰‰൮《〰〰㔴㌷‹〰〰‰൮《〰〰㔴〹‷〰〰‰൮《〰〰㔴㘹‱〰〰‰൮《〰〰㘴〲‸〰〰‰൮《〰〰㘴㘲′〰〰‰൮《〰〰㘴〵‷〰〰‰൮《〰〰㘴㘵

â€±ã€°ã€°â€°àµ®ã€Šã€°ã€°ã˜´ãŒ·â€¶ã€°ã€°â€°àµ®ã€Šã€°ã€°ã˜´ã¤·â€°ã€°ã€°â€°àµ®ã€Šã€°ã€°ã˜´ã˜¹â€²ã€°ã€°â€°àµ®ã€Šã€°ã€°ãœ´ã„°â€¶ã€°ã€°â€°àµ®ã€Šã€°ã€°ãœ´ãœ°â€°ã€°ã€°â€°àµ®ã€Šã€°ã€°ãœ´ãˆ±â€´ã€°ã€°â€°àµ®ã€Šã€°ã€°ãœ´ã ²â€¸ã€°ã€°â€°àµ®ã€Šã€°ã€°ãœ´ã³â€²ã€°ã€°â€°àµ®ã€Šã€°ã€°ãœ´ãœ´â€¸ã€°ã€°â€°àµ®ã€Šã€°ã€°ãœ´ãŒµâ€²ã€°ã€°â€°àµ®ã€Šã€°ã€°ãœ´ãŒ·â€·ã€°ã€°â€°àµ®ã€Šã€°ã€°ãœ´ã¤·â€±ã€°ã€°â€°àµ®ã€Šã€°ã€°ãœ´ã¸â€µã€°ã€°â€°àµ®ã€Šã€°ã€°ãœ´ã¤¸â€¹ã€°ã€°â€°àµ®ã€Šã€°ã€°ãˆ°ã¤´â€³ã€°ã€°â€°àµ®ã€Šã€°ã€°ã„°ã˜µâ€·ã€°ã€°â€°àµ®çŠæ…²æ±©ç‰¥à¨ã°¼åŒ¯ç©©â¥ãŒ±ã´å€¯æ•²â¶ã¤²ã”¹ãœ²å ¯æ•’å¦æµ´ãˆ ã¤´â¼³æ½’ç‘¯ã„ ã ²â€µâ€°â½’æ¹…ç‰£ç¹â´ãˆ±ã¸ã€ åˆ ä¤¯æ™®â¯ã˜²â€³â€°â½’ä‘‰ã±›ã‰†ã„·ã€µã„±ãˆ²ã†ä•‚ä‘ƒä‰„ãœµä„³äŒ¸ãˆ¹ã„°ãˆ±ä˜±ã°¾ã”°ã¤°äŒ±ã…ãäŒ¹ãœ³äˆ´ä‰ã™‚ä´äŒµãœ·ä‘‚ãä™å´¾ã¸¾à¨ç‘³ç‰¡ç¡´æ•²àµ¦ã€Š

਍┥佅െ ††††††††††††ഠㄊ㐳″‰扯㱪⼼敌杮桴ã ㄲ䌯ㄠ㈳⼷楆瑬牥䘯慬整敄潣敤䤯ㄠ㐴⼲⁌㌱ㄱ伯ㄠ㤲⼵⁓㔹㸶猾牴慥൭#풜鷾姐呭)Ὕ됑盿##Ἵ슂Ⓑꖓ⎇↦⮍憺஌펙#럼봭 ä·ä¦“îŒˆë½‰ìš°Ø‰æ‚©ë¶£èµ¤èŒ¾é™à·å‡‡á®€à§ªê™«é¢ë‘„åª¸ì¯¨ä¶”â£‚î­¡ä”í…†î“®ä“—é¿¦ì½›æ­žáŠé®½î‹™äŠæŸ¾ï‰ä˜šî ‚ã¥ªæ±£ï…¯ç±½é¡ƒç¨•âªˆä»ê‰ç„“ï·–ä¤˜à³®äŸœé§‚ãƒè©ä ƒæ¡¸î„¦â›³îºç©·ë†¿äŠ¹êŒêºž×¥æ­£êŠ½îºŽ#絥쇒뀁劒혣긤㏬䮧䉏㕴箨䔈鲝㟆ꃬ㮁層#å€‹é¡ƒæ­Žå¯¶íž£ä–•à£ªå£ƒä˜â¬ç®²é¼¨í†äœ½é´”ïš·ï‹­éƒ¶ì‹¥çŒ‘ë°‰ë°´â‚‡à¹¸é±¤ä‡é®‹æ®¢é”´ã€Šë±ä•»ï±ªÚ„ì·“ç”›ëŠ¢æ¿ á¼žå·»ë€¸âšë¯‡áµ¢æŠî€â¢®ï¥ì£¦î’ë¡¹ê’¼æ¾ é¢¹å‚‹äªè¨¹è‹ê·Žä‰½ì‘Äâ­¤é»—î²±â­‰æš£ë²¨è™„î‚»å‡¾#辍ﮔ

껆펽㥆⽛䆺㬸睲讀㤓꒜è

regards

Message was edited by: Surpreet Singh Bal

Read only

0 Likes
1,558

yes something like this is getting in the attachment file.

also surpreet i have done something

CLEAR it_packing_list.
  it_packing_list-transf_bin = 'X'.
  it_packing_list-head_start = 1.
  it_packing_list-head_num = 1.
  it_packing_list-body_start = 1.
  it_packing_list-doc_type = 'RAW'.
  it_packing_list-body_num = tab_lines.
  it_packing_list-doc_size = tab_lines * 255.

*  it_packing_list-obj_descr = ' object '.

  it_packing_list-obj_descr = 'test.pdf'.
  it_packing_list-obj_name = 'MAIL'.
  APPEND it_packing_list.

by doing so we can get the exact file name, .

abhishek suppal

Read only

0 Likes
1,558

Does your internet email node allow PDF type documents to be sent? Check in transaction SCOT for the node, if *.pdf is there.

Srinivas

Read only

0 Likes
1,558

yes srinivas its there in scot

and also surpreet i have just check it for txt file it is going well, but for pdf file its something like the above format, may be i thing i have just debug the function GUI_UPLOAD the internal table got all the data in binary format may be we have to see there....

abhishek suppal

Read only

Former Member
0 Likes
1,558

Hi Abhisek

I am pasting the exact code which will work.

REPORT YBALTEST.

DATA: gd_cnt TYPE i,

gd_sent_all(1) TYPE c,

gd_doc_data LIKE sodocchgi1,

gd_error TYPE sy-subrc.

DATA OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.

DATA: it_message LIKE solisti1 OCCURS 0 WITH HEADER LINE,

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.

  • Binary store for PDF

DATA: BEGIN OF it_pdf_output OCCURS 0,

row(255).

DATA: END OF it_pdf_output.

START-OF-SELECTION.

perform send_email_message .

&----


*& Form SEND_EMAIL_MESSAGE

&----


  • Send email message

----


FORM send_email_message.

DATA: tab_lines LIKE SY-TABIX.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'C:\test.pdf'

filetype = 'BIN'

TABLES

data_tab = it_pdf_output .

  • Populate the subject/generic message attributes

concatenate 'Attached is the '

' are waiting for.' into it_message.

append it_message.

DESCRIBE TABLE it_message LINES tab_lines.

READ TABLE it_message INDEX tab_lines.

gd_doc_data-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_message ).

gd_doc_data-obj_langu = sy-langu.

gd_doc_data-obj_name = 'SENDFILE'.

gd_doc_data-obj_descr = 'Attachement'.

gd_doc_data-sensitivty = 'O'.

describe table it_pdf_output lines tab_lines.

  • Describe the body of the message

CLEAR it_packing_list-transf_bin.

it_packing_list-head_start = 1.

it_packing_list-head_num = 0.

it_packing_list-body_start = 1.

it_packing_list-doc_type = 'RAW'.

it_packing_list-body_num = tab_lines.

APPEND it_packing_list.

loop at it_pdf_output.

move it_pdf_output-row to objbin-line.

append objbin.

endloop.

describe table objbin lines tab_lines.

CLEAR it_packing_list.

it_packing_list-transf_bin = 'X'.

it_packing_list-head_start = 1.

it_packing_list-head_num = 1.

it_packing_list-body_start = 1.

it_packing_list-doc_type = 'PDF'.

it_packing_list-body_num = tab_lines.

it_packing_list-doc_size = tab_lines * 255.

it_packing_list-OBJ_DESCR = ' object '.

*it_packing_list-obj_name = 'MAIL'.

APPEND it_packing_list.

it_receivers-receiver = '[email protected]'.

it_receivers-rec_type = 'U'.

it_receivers-com_type = 'INT'.

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'

commit_work = 'X'

  • IMPORTING

  • sent_to_all = gd_sent_all

TABLES

packing_list = it_packing_list

contents_txt = it_message

contents_bin = objbin

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.

ENDFORM. " SEND_EMAIL_MESSAGE

Cheers

Read only

0 Likes
1,558

yes sanjay

you are right i missed to put data in objbin-line

regards

Read only

Former Member
0 Likes
1,559

It will work even if you dont use OBJBIN . Just comment the following line in your original code -

it_packing_list-obj_name = 'MAIL'.

However it is a good practice to pass compatible / similar parameters to FM.

Cheers

Read only

0 Likes
1,558

yes it works,

important point

doc_type = 'PDF'.

regards

thanks sanjay, abhi please close your both threads

Read only

0 Likes
1,558

yes surpreet

doc_type = 'PDF'

is the main thing

and also i have checked it for excel file putting

doc_type = 'XLS'

and for Word file

doc_type = 'DOC'

it works fine....

thanx sanjay and surpreet for ur efforts

ya sure i am going to close both threads and reward the points..

abhishek suppal