Application Development and Automation 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: 
Read only

Reg: .CSV file

Former Member
0 Likes
451

Hi sapers,

I need to convert the ITAB data to .csv file. Here my problem is:

<b>As the ITAB contains a CURR field</b>

my piece of code is

DATA : i_csv TYPE truxs_t_text_data. " INTERNAL TABLE WITH COMMA.

data com type c value ','.

CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'

EXPORTING

i_field_seperator = COM

  • I_LINE_HEADER =

i_filename = p_file

  • I_APPL_KEEP = ' '

TABLES

i_tab_sap_data = inetbrtot

CHANGING

i_tab_converted_data = i_csv

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = v_pfile

FILETYPE = 'ASC'

  • WRITE_FIELD_SEPARATOR = 'X'

TABLES

data_tab = i_csv

fieldnames = infieldnames.

after executing my result is.

369;9.900 00-

258;1.000 00-

358264;13.161 36

and so on.....

but not the desired one , the correct one is

369;9900.00-

258;1000.00-

358264;13161.36

as the itab contains one CURR field m getting worst result.

plz help me out.

regards,

sri

2 REPLIES 2
Read only

Former Member
0 Likes
379

Hi

Try the method shown below.This is an example program without using the function module you mentionmed above.Try this.

FORM csv_conv.

TYPE-POOLS:truxs.

DATA: BEGIN OF itab OCCURS 0,

vbeln LIKE vbap-vbeln,

posnr LIKE vbap-posnr,

END OF itab.

DATA: itab1 TYPE truxs_t_text_data WITH HEADER LINE.

DATA:wa_bal1 TYPE t_bal.

DATA:flgact.

DATA : v_line(256) TYPE c.

DATA : fname(500) TYPE c.

DATA : sdate(8),scol(6).

DATA : var_tot TYPE kslxx9.

scol = p_date+0(6).

sdate = p_date+0(8).

var_tot = 0.

LOOP AT it_bal INTO wa_bal.

DATA : sdbt(20),scrdt(20),oth(20).

DATA : var_msg(50).

var_match = wa_bal-glacc+0(1).

IF NOT var_match = '9'.

  • IF wa_ret_day1-tot_cr = 0 AND wa_ret_day1-tot_dr = 0.

IF wa_bal-other = 0 .

ELSE.

  • SDBT = wa_ret_day1-tot_dr.

  • OTH = wa_ret_day1-OTHER.

  • IF wa_ret_day1-tot_cr < 0.

  • SCRDT = -1 * wa_ret_day1-tot_cr.

  • ELSE.

  • SCRDT = wa_ret_day1-tot_cr.

  • ENDIF.

*************************************************ME******************************

flgact = 'N'.

IF wa_bal-glacc = 'E4N3859999'.

READ TABLE it_bal INTO wa_bal1 WITH KEY glacc = 'L2N3309999'.

c = wa_bal-other.

c1 = wa_bal1-other.

c2 = c + c1.

IF c2 = 0.

flgact = 'Y'.

delete it_ret_res where glacc = 'E4N3859999'.

*CONTINUE.

ENDIF.

ELSEIF wa_bal-glacc = 'L2N3309999'.

READ TABLE it_bal INTO wa_bal1 WITH KEY glacc = 'E4N3859999'.

c = wa_bal-other.

c1 = wa_bal1-other.

c2 = c + c1.

IF c2 = 0.

flgact = 'Y'.

*CONTINUE.

delete it_ret_res where glacc = 'L2N3309999'.

ENDIF.

ENDIF.

IF flgact = 'N'.

**********************************************************MED*****************

IF wa_bal-other < 0.

scrdt = -1 * wa_bal-other.

sdbt = 0.

ELSE.

sdbt = wa_bal-other.

scrdt = 0.

ENDIF.

CLEAR v_line.

var_tot = var_tot + wa_bal-other.

CONCATENATE sdate ',' scol ',' space ','

wa_bal-glacc ',' sdbt ',' scrdt ',' space ','

space INTO

v_line.

APPEND v_line TO itab1.

*******************************************med****************

ENDIF.

*******************************************med****************

ENDIF.

ENDIF.

CLEAR wa_bal.

ENDLOOP.

*This for GUI download not needed for server (below)

*Please change the path accordingly

DATA :fpath TYPE string.

IF p_local = 'X'.

CONCATENATE p_lpath '\IRL01_B_' sdate '.CSV' INTO fname.

fpath = fname.

IF var_tot = 0.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = fpath

TABLES

data_tab = itab1

EXCEPTIONS

OTHERS = 1.

ELSE.

IF g_tblupdate = 'Y'.

DELETE zirl01_day_bal2 FROM TABLE it_ret_day1 .

ENDIF.

var_msg = var_tot.

CONCATENATE 'TotalDr./ Cr. not balacing check the source ' var_msg INTO var_msg.

log_line = var_msg.

APPEND log_line TO itab_log.

PERFORM log_writing.

MESSAGE e398(00) WITH var_msg.

ENDIF.

ENDIF.

*This for GUI download not needed for server (above)

*Please change the path accordingly for balance file

*if p_server = 'X'.

CONCATENATE p_spath '\IRL01_B_' sdate '.CSV' INTO fname.

fpath = fname.

DATA: e_file LIKE rlgrap-filename .

e_file = fname.

IF var_tot = 0.

OPEN DATASET e_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc <> 0.

CONCATENATE 'No access for the directory or may not exist' ' ' INTO var_msg .

log_line = var_msg.

APPEND log_line TO itab_log.

PERFORM log_writing.

MESSAGE e398(00) WITH var_msg.

ENDIF.

LOOP AT itab1.

TRANSFER itab1 TO e_file.

ENDLOOP.

CLOSE DATASET e_file.

ELSE.

IF g_tblupdate = 'Y'.

DELETE zirl01_day_bal2 FROM TABLE it_ret_day1 .

ENDIF.

var_msg = var_tot.

CONCATENATE 'TotalDr./ Cr. not balacing check the source ' var_msg INTO var_msg.

log_line = var_msg.

APPEND log_line TO itab_log.

PERFORM log_writing.

MESSAGE e398(00) WITH var_msg.

ENDIF.

*endif.

ENDFORM. "CSV_CONV

Reward All Helpfull Answers..........

Read only

0 Likes
379

Thanks for your immediate reply, I tried in a different manner, its working.

regards,

sri...