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: 

Internal Table to xls Attachment cl bcs?

Former Member
0 Kudos

Hy folks i'm facing an issue while converting an internal table to excel using cl_bcs (to send as attachment.

After the first row, the first column wouldn't be fill again.

i can't figure out why.

this is my piece of code.

LOOP AT lt_kdmat INTO ls_kdmat.

DO.

ASSIGN COMPONENT sy-index OF STRUCTURE ls_kdmat TO <lv_field>.

IF sy-subrc EQ 0.

IF lv_string IS INITIAL.

WRITE <lv_field> TO lv_string_field.

lv_string = lv_string_field.

ELSE.

WRITE <lv_field> TO lv_string_field.

CONCATENATE lv_string gc_tab lv_string_field INTO lv_string.

ENDIF.

ELSE.

CONCATENATE lv_string gc_crlf INTO lv_string.

EXIT.

ENDIF.

ENDDO.

ENDLOOP.

TRY.

CALL METHOD cl_bcs_convert=>string_to_solix

EXPORTING

iv_string = lv_string

* iv_codepage = '4103'

* iv_add_bom =

IMPORTING

et_solix = gt_binary_data

ev_size = gw_doc_len. 

CATCH cx_bcs .

MESSAGE 'Error when transfering document contents' TYPE 'E'.

ENDTRY.

What do i miss?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Is it possible that first column has data but it is not visible because of too many leading spaces?

It would be helpful to see 2 lines of internal table and 2 lines of output file when opened in Notepad.

4 REPLIES 4

Former Member
0 Kudos

Is it possible that first column has data but it is not visible because of too many leading spaces?

It would be helpful to see 2 lines of internal table and 2 lines of output file when opened in Notepad.

0 Kudos

no it's not possible, because the first column has the mandt, please found in attachment the txt file

0 Kudos

Every line except first one is starting with tab character. This needs to be taken care of.

Basically, for first field of every line, you need to ensure that only value is concatenated, not the tab character.

Try changing the IF block after ASSIGN statement to this.

  1. ASSIGN COMPONENT sy-index OF STRUCTURE ls_kdmat TO <lv_field>.
  2. IF sy-subrc EQ 0.
  3.   IF lv_string IS INITIAL.
  4.     WRITE <lv_field> TO lv_string_field.
  5.     lv_string = lv_string_field.
  6. *  ELSE.
  7.   ELSEIF sy-index EQ 1.
  8.     WRITE <lv_field> TO lv_string_field.
  9.     CONCATENATE lv_string lv_string_field INTO lv_string.
  10.   ELSE.
  11.     WRITE <lv_field> TO lv_string_field.
  12.     CONCATENATE lv_string gc_tab lv_string_field INTO lv_string.
  13.   ENDIF.
  14. ELSE.
  15.   CONCATENATE lv_string gc_crlf INTO lv_string.
  16.   EXIT.
  17. ENDIF.

/.

0 Kudos

thanx work perfectly