cancel
Showing results for 
Search instead for 
Did you mean: 

converting '.xls' file to '.txt' in BDC Session method

Former Member
0 Kudos

Hi gurus,

Happy DIWALIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII------',','

Please help me in converting '.xls' file to '.txt' in BDC Session method. Is there is any method or function module for this conversion. Please help me with coding.

Thanks and regards,

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

File->save as -> Save as type ( text tab delimted.txt) ->Click on yes .

Now open .txt file -> here data will be tab delimted.

genrally i use tab delimted file to upload the data.

Even if you want to programtically then get the data from xls file to Internal table,now use concatenate with comma ,now download it.

Check the below program :

Upload xls file and you can see .txt file ( with comma delimted)

Input ( XLS file )

aaa 1245 2344 233 qwww

233 2222 qwww www www

Output ( .txt file with comma delimted)

aaa,1245,2344,233,qwww

233,2222,qwww,www,www

REPORT ZFII_MISSING_FILE_UPLOAD no standard page heading.

data : begin of i_text occurs 0,

text(1024) type c,

end of i_text.

  • Internal table for File data

data : begin of i_data occurs 0,

field1(10) type c,

field2(10) type c,

field3(10) type c,

field4(10) type c,

field5(10) type c,

end of i_data.

data : begin of i_download occurs 0,

text(1024) type c,

end of i_download.

data : v_lines type sy-index.

data : g_repid like sy-repid.

data v_file type string.

data: itab like alsmex_tabline occurs 0 with header line.

data : g_line like sy-index,

g_line1 like sy-index,

$v_start_col type i value '1',

$v_start_row type i value '1',

$v_end_col type i value '256',

$v_end_row type i value '65536',

gd_currentrow type i.

selection-screen : begin of block blk with frame title text.

parameters : p_file like rlgrap-filename obligatory.

selection-screen : end of block blk.

initialization.

g_repid = sy-repid.

at selection-screen on value-request for p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = g_repid

IMPORTING

FILE_NAME = p_file.

start-of-selection.

  • Uploading the data into Internal Table

perform upload_data.

  • download the file into comma delimted file.

perform download_data.

.

&----


*& Form upload_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM upload_data.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = p_file

I_BEGIN_COL = $v_start_col

I_BEGIN_ROW = $v_start_row

I_END_COL = $v_end_col

I_END_ROW = $v_end_row

TABLES

INTERN = itab

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

write:/10 'File '.

ENDIF.

if sy-subrc eq 0.

read table itab index 1.

gd_currentrow = itab-row.

loop at itab.

if itab-row ne gd_currentrow.

append i_data.

clear i_data.

gd_currentrow = itab-row.

endif.

case itab-col.

when '0001'.

  • first Field

i_data-field1 = itab-value.

  • second field

when '0002'.

i_data-field2 = itab-value.

  • Third field

when '0003'.

i_data-field3 = itab-value.

  • fourth field

when '0004'.

i_data-field4 = itab-value.

  • fifth field

when '0005'.

i_data-field5 = itab-value.

endcase.

endloop.

endif.

append i_data.

ENDFORM. " upload_data

&----


*& Form download_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM download_data.

loop at i_data.

concatenate i_data-field1 ',' i_data-field2 ',' i_data-field3 ','

i_data-field4 ',' i_data-field5 into i_download-text.

append i_download.

clear : i_download,

i_data.

endloop.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME =

'C:\Documents and Settings\smaramreddy\Desktop\fff.txt'

FILETYPE = 'ASC'

  • APPEND = ' '

  • WRITE_FIELD_SEPARATOR = ' '

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = i_download

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " download_data

Regards

Pavan