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: 

Error in excel attachment

Former Member
0 Kudos
44

Hi expert,

What is wrong with this abap program? The excel attachement to the email does not display all materials in the 1st column. Please help, thanks!

REPORT test.

TYPES: BEGIN OF mara_type,

matnr TYPE matnr,

mtart TYPE mtart,

matkl TYPE matkl,

meins TYPE meins,

END OF mara_type.

DATA: itab TYPE TABLE OF mara_type WITH HEADER LINE,

t_attach TYPE STANDARD TABLE OF solisti1,

wa_attach TYPE solisti1.

CONSTANTS: c_cret TYPE abap_char1

VALUE cl_abap_char_utilities=>cr_lf,

c_tab TYPE abap_char1

VALUE cl_abap_char_utilities=>horizontal_tab.

DATA: t_contents TYPE TABLE OF soli,

w_contents TYPE soli,

t_receiver TYPE TABLE OF soos1,

w_receiver TYPE soos1,

w_object_hd_change TYPE sood1,

packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE.

FIELD-SYMBOLS <fs> TYPE ANY.

START-OF-SELECTION.

SELECT matnr mtart matkl meins FROM mara INTO TABLE itab

UP TO 10 ROWS.

LOOP AT itab.

CLEAR wa_attach.

DO.

ASSIGN COMPONENT sy-index OF STRUCTURE itab TO <fs>.

IF sy-subrc <> 0.

EXIT.

ENDIF.

IF sy-index = 1.

wa_attach = <fs>.

ELSE.

CONCATENATE wa_attach c_tab <fs> INTO wa_attach.

ENDIF.

ENDDO.

CONCATENATE wa_attach c_cret INTO wa_attach.

APPEND wa_attach TO t_attach.

ENDLOOP.

        • Build the subject line

CONCATENATE sy-sysid

'Test email'

INTO w_object_hd_change-objdes SEPARATED BY '-'.

DESCRIBE TABLE t_attach.

CLEAR packing_list.

REFRESH packing_list.

packing_list-transf_bin = 'X'.

packing_list-head_start = 0.

packing_list-head_num = 0.

packing_list-body_start = 1.

packing_list-body_num = sy-tfill.

packing_list-objtp = 'XLS'.

packing_list-objnam = 'Object name'.

packing_list-objdes = 'Attachment description'.

packing_list-objlen = sy-tfill * 255.

APPEND packing_list.

        • Build the receivers

CLEAR w_receiver.

w_receiver-recextnam = 'XXXXXXX''. <---- enter your email address here for test

w_receiver-recesc = 'E'.

w_receiver-sndart = 'INT'.

w_receiver-sndpri = '1'.

APPEND w_receiver TO t_receiver.

      • send the email

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

object_hd_change = w_object_hd_change

object_type = 'RAW'

TABLES

objcont = t_contents

receivers = t_receiver

packing_list = packing_list

att_cont = t_attach

EXCEPTIONS

x_error = 1.

COMMIT WORK.

1 REPLY 1

MarcinPciak
Active Contributor
0 Kudos
21

Hi,

The problem lies in the logic right here

IF sy-index = 1.

wa_attach = <fs>.

ELSE.

CONCATENATE wa_attach c_tab <fs> INTO wa_attach.

ENDIF.

ENDDO.

CONCATENATE wa_attach c_cret INTO wa_attach.

APPEND wa_attach TO t_attach.

should be


if sy-index = 1.
  wa_attach = c_cret.  "always before first component is added
else.
  concatenate wa_attach c_tab into wa_attach.  "for the rest concatenate c_tab instead of c_cret
else.
concatenate wa_attach <fs> into wa_attach.
enddo.
APPEND wa_attach TO t_attach.

You just accidentally ommited c_cret in first line. Code above should correct it.

Regards

Marcin