Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

sending excel as email attachment

Hi All,

I am getting truncated with the header only upto 255 char length , and the field contents are ok more than 255 length it s taking.

I am using it_attach type standard table of solisti1 with header line.

the report code is given below

*&----


*

**& Report ZPBILL_INT1 **

**& **

*&----


*

**& **

**& **

*&----


*

REPORT zpbill_int1 .

*Declaration of type-pools.

TYPE-POOLS slis.

*----


*

    • D A T A **

*----


*

TABLES: zbill_inphdr,

zbill_inpdtl.

TYPES: BEGIN OF t_zbill_ipdtl,

cusnr TYPE zbill_inpdtl-cusnr,

svsnr TYPE zbill_inpdtl-svsnr,

revnr TYPE zbill_inpdtl-revnr,

sysnr TYPE zbill_inpdtl-sysnr,

sdate TYPE zbill_inpdtl-sdate,

filnm TYPE zbill_inpdtl-filnm,

zlsch TYPE zbill_inpdtl-zlsch,

clrfe TYPE zbill_inpdtl-clrfe,

revds TYPE zbill_inpdtl-revds,

prind TYPE zbill_inpdtl-prind,

svsds TYPE zbill_inpdtl-svsds,

quant TYPE zbill_inpdtl-quant,

adate TYPE zbill_inpdtl-adate,

trdat TYPE zbill_inpdtl-trdat,

mdate TYPE zbill_inpdtl-mdate,

    • trdval type zbill_inpdtl-trdval,*

exrate TYPE zbill_inpdtl-exrate,

birate TYPE zbill_inpdtl-birate,

cusds1 TYPE zbill_inpdtl-cusds1,

cusds2 TYPE zbill_inpdtl-cusds2,

cusstr TYPE zbill_inpdtl-cusstr,

cuspc TYPE zbill_inpdtl-cuspc,

cuscity TYPE zbill_inpdtl-cuscity,

cusctry TYPE zbill_inpdtl-cusctry ,

rect TYPE zbill_inpdtl-rect,

invno TYPE zbill_inpdtl-invno,

ldate TYPE zbill_inpdtl-ldate,

conty TYPE zbill_inpdtl-conty,

edate TYPE zbill_inpdtl-edate,

custa TYPE zbill_inpdtl-custa,

currc TYPE zbill_inpdtl-currc,

warrt TYPE zbill_inpdtl-warrt,

indrp TYPE zbill_inpdtl-indrp,

textc TYPE zbill_inpdtl-textc,

gstr TYPE zbill_inpdtl-gstr,

clrds TYPE zbill_inpdtl-clrds,

commty TYPE zbill_inpdtl-commty,

commyr TYPE zbill_inpdtl-commyr,

commmt TYPE zbill_inpdtl-commmt,

commop TYPE zbill_inpdtl-commop,

eposdoc TYPE zbill_inpdtl-eposdoc,

custp TYPE zbill_inpdtl-custp,

END OF t_zbill_ipdtl.

DATA: it_zbill TYPE STANDARD TABLE OF t_zbill_ipdtl

INITIAL SIZE 0.

    • ALV Data declaration.*

DATA : v_repid LIKE sy-repid.

    • ALV Function Module Variables*

DATA: gs_layout TYPE slis_layout_alv,

g_exit_caused_by_caller,

gs_exit_caused_by_user TYPE slis_exit_by_user.

DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,

gs_print TYPE slis_print_alv,

gt_events TYPE slis_t_event,

gt_list_top_of_page TYPE slis_t_listheader,

g_status_set TYPE slis_formname VALUE 'PF_STATUS_SET',

g_user_command TYPE slis_formname VALUE 'USER_COMMAND',

g_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE',

g_top_of_list TYPE slis_formname VALUE 'TOP_OF_LIST',

g_end_of_list TYPE slis_formname VALUE 'END_OF_LIST',

g_variant LIKE disvariant,

g_save(1) TYPE c,

g_tabname_header TYPE slis_tabname,

g_tabname_item TYPE slis_tabname,

g_exit(1) TYPE c,

gx_variant LIKE disvariant.

DATA : gr_layout_bck TYPE slis_layout_alv.

DATA : wa_zbill TYPE t_zbill_ipdtl.

*Email related declarations

DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

*DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

*WITH HEADER LINE.

DATA: it_attach TYPE STANDARD TABLE OF SOMLRECI1 INITIAL SIZE 0

WITH HEADER LINE.

DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,

t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

*t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,

t_attachment LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,

w_cnt TYPE i,

w_sent_all(1) TYPE c,

w_doc_data LIKE sodocchgi1,

gd_error TYPE sy-subrc,

gd_reciever TYPE sy-subrc.

*DATA IT_HEADER TYPE STANDARD TABLE OF SOLIX INITIAL SIZE 0 WITH

*HEADER LINE.

*data : begin of it_header occurs 0,

    • header(1023) type C,*

***

    • end of it_header.*

*----


*

    • S E L E C T I O N S **

*----


*

SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE text-b01.

SELECT-OPTIONS: s_cusnr FOR zbill_inpdtl-cusnr,

s_svsnr FOR zbill_inpdtl-svsnr,

s_revnr FOR zbill_inpdtl-revnr,

s_sysnr FOR zbill_inpdtl-sysnr,

s_sdate FOR zbill_inpdtl-sdate,

s_filnm FOR zbill_inpdtl-filnm,

s_prind for zbill_inpdtl-prind.

PARAMETERS: p_test AS CHECKBOX,

p_email AS CHECKBOX.

SELECTION-SCREEN END OF BLOCK b01.

*PARAMETERS: p_email TYPE somlreci1-receiver

*----


*

    • Initialization **

*----


*

INITIALIZATION.

v_repid = sy-repid.

*----


*

    • start-of-selection **

*----


*

START-OF-SELECTION.

PERFORM data_retrieval.

IF p_test = '' AND P_EMAIL = ''.

MESSAGE S038(ZMBILLING).

ELSEIF P_TEST = 'X'.

    • display the data in the form of ALV*

PERFORM display_data.

ELSEIF P_EMAIL = 'X'.

*Populate table with detaisl to be entered into .xls file

PERFORM build_xls_data_table.

*Populate message body text

PERFORM populate_email_message_body.

***

*Send file by email as .xls speadsheet

PERFORM send_file_as_email_attachment

TABLES it_message it_attach USING p_email

'Billing Details list'

'XLS'

'filename'

' '

' '

' '

CHANGING gd_error

gd_reciever.

***

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

PERFORM initiate_mail_execute_program.

ENDIF.

*&----


*

*& Form data_retrieval

*&----


*

    • text*

*----


*

FORM data_retrieval.

SELECT revnr sysnr sdate filnm cusnr

svsnr zlsch clrfe revds prind svsds

quant adate trdat mdate exrate

birate cusds1 cusds2 cusstr

cuspc cuscity cusctry rect

invno ldate conty edate custa

currc warrt indrp textc

gstr clrds commty commyr commmt

commop eposdoc custp

INTO CORRESPONDING FIELDS OF TABLE it_zbill FROM zbill_inpdtl

WHERE cusnr IN s_cusnr

AND svsnr IN s_svsnr

AND revnr IN s_revnr

AND sysnr IN s_sysnr

AND sdate IN s_sdate

AND filnm IN s_filnm

and prind in s_prind.

ENDFORM. " DATA_RETRIEVAL

**&----


*

**& Form build_xls_data_table

**&----


*

      • text*

**----


*

FORM build_xls_data_table.

DATA: ld_store(50) TYPE c. "Leading zeros

DATA: wa_zbill-quant(20),

wa_zbill-custa(20),

wa_zbill-gstr(20).

***

    • wa_zbill-mxamt(20).*

*If you have Unicode check active in program attributes thnen you will

*need to declare constants as follows

CLASS cl_abap_char_utilities DEFINITION LOAD.

CONSTANTS:

con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.

CONCATENATE 'Customer code' 'Service Number' 'Revenue Type' 'Source

System Code' 'Date Source' 'File Name' 'Payment Code' 'Single Char Flag'

'Revenue Description' 'Processing Indicator' 'Service Description'

'Order Quantity' 'Date of Adustment' 'Trade Date' 'Mos Date'

'ExchangeRate' 'Billing Rate' 'Customer Name1' 'Customer name2'

'Customer adress' 'Customer postalcode' 'Customer city'

'Customer country' 'Billing amt without GST' 'GST Payable'

'Receipt number' 'Invoice Number' 'Listing Period'

'Contract Type' 'Entry date' 'Custody Code' 'Currency Code'

'Name of Warrant' 'Rights issue' 'No Of copies'

'GST Rate' 'Clearing Fee' 'Commodity type'

'Commodity year' 'Commodity month' 'Commodity Option Tpye'

'Quantity Transacted' 'Amendment Quantity' 'EPOS DOC type'

'Customer Type'

INTO IT_ATTACH SEPARATED BY con_tab.

CONCATENATE con_cret IT_ATTACH INTO IT_ATTACH.

*CONCATENATE con_cret it_attach INTO it_attach.

APPEND it_attach.

LOOP AT it_zbill INTO wa_zbill.

CONCATENATE wa_zbill-cusnr wa_zbill-svsnr wa_zbill-revnr

wa_zbill-sysnr wa_zbill-sdate wa_zbill-filnm wa_zbill-zlsch

wa_zbill-clrfe wa_zbill-revds wa_zbill-prind wa_zbill-svsds

wa_zbill-quant wa_zbill-adate wa_zbill-trdat wa_zbill-mdate

wa_zbill-exrate wa_zbill-birate wa_zbill-cusds1 wa_zbill-cusds2

wa_zbill-cusstr wa_zbill-cuspc wa_zbill-cuscity wa_zbill-cusctry

wa_zbill-rect wa_zbill-invno wa_zbill-ldate wa_zbill-conty

wa_zbill-edate wa_zbill-custa wa_zbill-currc wa_zbill-warrt

wa_zbill-indrp wa_zbill-textc wa_zbill-gstr wa_zbill-clrds

wa_zbill-commty wa_zbill-commyr wa_zbill-commmt wa_zbill-commop

wa_zbill-eposdoc wa_zbill-custp

INTO it_attach SEPARATED BY con_tab.

CONCATENATE con_cret it_attach INTO it_attach.

    • it_header = it_attach .*

*append it_header.

APPEND it_attach.

***

ENDLOOP.

ENDFORM. " BUILD_XLS_DATA_TABLE

***

**&----


***& Form SEND_FILE_AS_EMAIL_ATTACHMENT

**&----


FORM send_file_as_email_attachment TABLES pit_message

pit_attach

USING p_email

p_mtitle

p_format

p_filename

p_attdescription

p_sender_address

p_sender_addres_type

CHANGING p_error

p_reciever.

DATA: ld_error TYPE sy-subrc,

ld_reciever TYPE sy-subrc,

ld_mtitle LIKE sodocchgi1-obj_descr,

ld_email LIKE somlreci1-receiver,

ld_format TYPE so_obj_tp ,

ld_attdescription TYPE so_obj_nam ,

ld_attfilename TYPE so_obj_des ,

ld_sender_address LIKE soextreci1-receiver,

ld_sender_address_type LIKE soextreci1-adr_typ,

ld_receiver LIKE sy-subrc.

ld_email = p_email.

ld_mtitle = p_mtitle.

ld_format = p_format.

ld_attdescription = p_attdescription.

ld_attfilename = p_filename.

ld_sender_address = p_sender_address.

ld_sender_address_type = p_sender_addres_type.

*ld_sender_address = SY-UNAME.

    • ld_sender_address_type = 'SMTP'.*

***

*fill the document data.

w_doc_data-doc_size = 1.

*populate the subject/generic message attributes

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle .

w_doc_data-sensitivty = 'F'.

*Fill the document data and get size of attachment

CLEAR w_doc_data.

READ TABLE it_attach INDEX w_cnt.

w_doc_data-doc_size =

*( w_cnt - 1 ) * 255 + STRLEN( it_attach ).*

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle.

w_doc_data-OBJ_NAME = ld_attfilename.

w_doc_data-sensitivty = 'F'.

CLEAR t_attachment.

REFRESH t_attachment.

t_attachment = it_attach.

t_attachment[] = it_attach[] .

    • t_attachment = it_header.*

    • t_attachment[] = it_header[] .*

*Describe the body of the message

CLEAR t_packing_list.

REFRESH t_packing_list.

t_packing_list-transf_bin = space.

t_packing_list-head_start = 1.

t_packing_list-head_num = 0.

t_packing_list-body_start = 1.

DESCRIBE TABLE it_message LINES t_packing_list-body_num.

t_packing_list-doc_type = 'RAW'.

APPEND t_packing_list.

*CREATE attachment notification

t_packing_list-transf_bin = 'X'.

t_packing_list-head_start = 1.

t_packing_list-head_num = 1.

t_packing_list-body_start = 1.

DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.

t_packing_list-doc_type = ld_format.

t_packing_list-obj_descr = ld_attdescription.

t_packing_list-obj_name = ld_attfilename.

*t_packing_list-doc_size = t_packing_list-body_num * 255.*

APPEND t_packing_list.

*Add the recipients email address

CLEAR t_receivers.

REFRESH t_receivers.

    • t_receivers-receiver = ld_email.*

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = w_doc_data

put_in_outbox = 'X'

sender_address = ld_sender_address

sender_address_type = ld_sender_address_type

commit_work = 'X'

IMPORTING

sent_to_all = w_sent_all

TABLES

packing_list = t_packing_list

contents_bin = t_attachment

contents_txt = it_message

receivers = t_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.

***

*Populate zerror return code

ld_error = sy-subrc.

*Populate zreceiver return code

LOOP AT t_receivers.

ld_receiver = t_receivers-retrn_code.

ENDLOOP.

ENDFORM. "build_xls_data_table

*

regards

subba

Tags:
Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question