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: 

New Line in a xls attachment

Former Member
0 Kudos

Hi guys, I'm using ecc 6.0 here

Can't break line in my xls file attached to e-mail

Already tried cl_abap_char_utilities=>cr_lf and cl_abap_char_utilities=>newline and other, not even tab is working properly...

here is my test program:

----


  • Report : ZBETO

  • Author : D038062

----


REPORT zbeto.

  • This table requires information about how the data in the

  • tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are

  • to be distributed to the documents and its attachments.

DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.

  • This table must contain the summarized data dependent on each object

*type.

  • SAPscript objects store information here about forms and styles,

  • for example. Excel list viewer objects store the number of rows and

*columns

  • amongst other things and PC objects store their original file name.

DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.

*CREATION OF INTERNAL TABLE

DATA : BEGIN OF itobjbin OCCURS 10 ,

vbeln TYPE vbrp-vbeln,

matnr TYPE vbrp-matnr,

werks TYPE vbrp-werks,

fktyp LIKE vbrk-fktyp,

END OF itobjbin .

  • This table must contain the summarized content of the objects

*identified as binary objects.

*DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: objbin TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

DATA: wa_itobjbin LIKE itobjbin .

  • This table must contain the summarized content of the objects

*identified as ASCII objects.

DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.

  • This table must contain the document recipients.

DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.

  • This structure must contain the attributes of the document to be sent.

DATA: doc_chng LIKE sodocchgi1.

DATA: tab_lines LIKE sy-tabix.

DATA : v_fktyp LIKE vbrk-fktyp.

  • Creating the document to be sent

doc_chng-obj_name = 'OFFER'. " input contains the attributes of the

*document to be sent

doc_chng-obj_descr = 'EMAIL WITH EXCEL DOWNLOAD 2'. "input contains

*title/subject of the document

*BODY OF THE MAIL

objtxt = 'Hi'.

APPEND objtxt .

objtxt = 'Test for excel download'.

APPEND objtxt.

objtxt = sy-datum.

APPEND objtxt.

objtxt = sy-uzeit.

APPEND objtxt.

objtxt = 'Below is the attachment with Billing Document Details'.

APPEND objtxt.

objtxt = 'Regards'.

APPEND objtxt.

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

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

  • Creating 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.

  • Creating the document attachment

  • (Assume the data in OBJBIN are given in BMP format)

SELECT vbeln matnr werks

FROM vbrp INTO TABLE itobjbin

UP TO 10 ROWS

WHERE werks GE '1000'.

LOOP AT itobjbin.

SELECT SINGLE fktyp INTO v_fktyp FROM vbrk WHERE vbeln = itobjbin-vbeln.

MOVE v_fktyp TO itobjbin-fktyp.

MODIFY itobjbin.

ENDLOOP.

PERFORM build_xls_data_table .

DESCRIBE TABLE objbin LINES tab_lines.

objhead = 'ABC.XLS'. APPEND objhead.

  • Creating 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 = 'XLS'.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = 'XLS'.

objpack-doc_size = tab_lines * 255.

APPEND objpack.

  • Entering names in the distribution list

*reclist-receiver = 'dev02'.

CLEAR reclist.

REFRESH reclist.

  • Completing the recipient list

  • target recipent

CLEAR reclist.

reclist-receiver = 'my@mail.com'.

reclist-express = 'X'.

reclist-rec_type = 'U'.

APPEND reclist.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

commit_work = 'X'

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.

CASE sy-subrc.

WHEN 0.

WRITE: / 'Result of the send process:'.

LOOP AT reclist.

WRITE: / reclist-receiver(48), ':'.

IF reclist-retrn_code = 0.

WRITE 'sent successfully'.

ELSE.

WRITE 'not sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'no authorization to send to the specified number of',

'recipients!'.

WHEN 2.

WRITE: / 'document could not be sent to any of the recipients!'.

WHEN 4.

WRITE: / 'no authorization to send !'.

WHEN OTHERS.

WRITE: / 'error occurred during sending !'.

ENDCASE.

&----


*& Form build_xls_data_table

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_xls_data_table .

  • DATA: CON_CRET(2) TYPE x VALUE '0D', "Line feed OK for non Unicode

  • CON_TAB(2) TYPE x VALUE '09'. "OK for non Unicode

DATA: con_cret LIKE cl_abap_char_utilities=>cr_lf.

DATA: con_tab LIKE cl_abap_char_utilities=>horizontal_tab.

CONCATENATE 'First Col' 'Material Number' 'Plant'

'Billing category' ' ' INTO objbin SEPARATED BY con_tab.

CONCATENATE con_cret objbin INTO objbin.

APPEND objbin.

LOOP AT itobjbin .

CONCATENATE itobjbin-vbeln itobjbin-matnr itobjbin-werks itobjbin-fktyp

INTO objbin SEPARATED BY con_tab.

  • INTO objbin SEPARATED BY TAB.

CONCATENATE objbin con_cret INTO objbin.

APPEND objbin.

ENDLOOP.

ENDFORM. "build_xls_data_table

-


where is the error? first time using cl_abap_char_utilities...

thanks

Roberto

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi

class CL_ABAP_CHAR_UTILITIES definition load.

add this in ur program!!!

*****reward if helpful

regards,

madhu

4 REPLIES 4

Former Member
0 Kudos

hi

class CL_ABAP_CHAR_UTILITIES definition load.

add this in ur program!!!

*****reward if helpful

regards,

madhu

0 Kudos

didnt work, any other error?

----


  • Report : ZBETO

  • Author : D038062

----


REPORT zbeto.

  • This table requires information about how the data in the

  • tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are

  • to be distributed to the documents and its attachments.

DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.

  • This table must contain the summarized data dependent on each object

*type.

  • SAPscript objects store information here about forms and styles,

  • for example. Excel list viewer objects store the number of rows and

*columns

  • amongst other things and PC objects store their original file name.

DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.

*CREATION OF INTERNAL TABLE

DATA : BEGIN OF itobjbin OCCURS 10 ,

vbeln TYPE vbrp-vbeln,

matnr TYPE vbrp-matnr,

werks TYPE vbrp-werks,

fktyp LIKE vbrk-fktyp,

END OF itobjbin .

  • This table must contain the summarized content of the objects

*identified as binary objects.

*DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: objbin TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

DATA: wa_itobjbin LIKE itobjbin .

  • This table must contain the summarized content of the objects

*identified as ASCII objects.

DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.

  • This table must contain the document recipients.

DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.

  • This structure must contain the attributes of the document to be sent.

DATA: doc_chng LIKE sodocchgi1.

DATA: tab_lines LIKE sy-tabix.

DATA : v_fktyp LIKE vbrk-fktyp.

CLASS cl_abap_char_utilities DEFINITION LOAD.

  • Creating the document to be sent

doc_chng-obj_name = 'OFFER'. " input contains the attributes of the

*document to be sent

doc_chng-obj_descr = 'EMAIL WITH EXCEL DOWNLOAD 2'. "input contains

*title/subject of the document

*BODY OF THE MAIL

objtxt = 'Hi'.

APPEND objtxt .

objtxt = 'Test for excel download'.

APPEND objtxt.

objtxt = sy-datum.

APPEND objtxt.

objtxt = sy-uzeit.

APPEND objtxt.

objtxt = 'Below is the attachment with Billing Document Details'.

APPEND objtxt.

objtxt = 'Regards'.

APPEND objtxt.

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

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

  • Creating 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.

  • Creating the document attachment

  • (Assume the data in OBJBIN are given in BMP format)

SELECT vbeln matnr werks

FROM vbrp INTO TABLE itobjbin

UP TO 10 ROWS

WHERE werks GE '1000'.

LOOP AT itobjbin.

SELECT SINGLE fktyp INTO v_fktyp FROM vbrk WHERE vbeln = itobjbin-vbeln.

MOVE v_fktyp TO itobjbin-fktyp.

MODIFY itobjbin.

ENDLOOP.

PERFORM build_xls_data_table .

DESCRIBE TABLE objbin LINES tab_lines.

objhead = 'ABC.XLS'. APPEND objhead.

  • Creating 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 = 'XLS'.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = 'XLS'.

objpack-doc_size = tab_lines * 255.

APPEND objpack.

  • Entering names in the distribution list

*reclist-receiver = 'dev02'.

CLEAR reclist.

REFRESH reclist.

  • Completing the recipient list

  • target recipent

CLEAR reclist.

reclist-receiver = 'myemail@email.com'.

reclist-express = 'X'.

reclist-rec_type = 'U'.

APPEND reclist.

*CLEAR reclist.

*reclist-receiver = 'dev02'.

*reclist-rec_type = 'b'.

*APPEND reclist.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

commit_work = 'X'

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.

CASE sy-subrc.

WHEN 0.

WRITE: / 'Result of the send process:'.

LOOP AT reclist.

WRITE: / reclist-receiver(48), ':'.

IF reclist-retrn_code = 0.

WRITE 'sent successfully'.

ELSE.

WRITE 'not sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'no authorization to send to the specified number of',

'recipients!'.

WHEN 2.

WRITE: / 'document could not be sent to any of the recipients!'.

WHEN 4.

WRITE: / 'no authorization to send !'.

WHEN OTHERS.

WRITE: / 'error occurred during sending !'.

ENDCASE.

&----


*& Form build_xls_data_table

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_xls_data_table .

  • DATA: CON_CRET(2) TYPE x VALUE '0D', "Line feed OK for non Unicode

  • CON_TAB(2) TYPE x VALUE '09'. "OK for non Unicode

CLASS cl_abap_char_utilities DEFINITION LOAD.

DATA: con_cret LIKE cl_abap_char_utilities=>cr_lf."OK for non Unicode

DATA:con_tab LIKE cl_abap_char_utilities=>newline.

CONCATENATE 'First Col' 'Material Number' 'Plant'

'Billing category' ' ' INTO objbin SEPARATED BY con_tab.

CONCATENATE con_cret objbin INTO objbin.

APPEND objbin.

LOOP AT itobjbin .

CONCATENATE itobjbin-vbeln itobjbin-matnr itobjbin-werks itobjbin-fktyp

INTO objbin SEPARATED BY con_tab.

  • INTO objbin SEPARATED BY TAB.

CONCATENATE objbin con_cret INTO objbin.

APPEND objbin.

ENDLOOP.

ENDFORM. "build_xls_data_table

0 Kudos

hi

do this way:

constants:c_tab type c value cl_abap_char_utilities=>horizontal_tab.

or

concatenate itab-fld1 itab-fld2 into str

separated by cl_abap_char_utilities=>horizontal_tab.

in ur code:

DATA: con_cret type c value cl_abap_char_utilities=>cr_lf."OK for non Unicode

DATA:con_tab type c value cl_abap_char_utilities=>newline.

**reward if helpful

regards,

madhu

0 Kudos

thank you Madhu!