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

Negative sign on the wrong side when export data to csv

Former Member
0 Likes
4,737

Hi,

I have an internal table with some character and numeric (integer, currency) fields and I need to export that data to a csv file.

I have used the function "CONVERT_SAP_TO_CSV" to geht my csv data. Before that I have converted the numeric fields by WRITE TO to character.

In my csv file, I get the negative sign on the right side, so I can´t calculate anything in excel than.

In the debugger, the negativ sign is always on the right side, but in the csv it need to be on the left side.

Can anybody help me, how to get it to the left in my csv?

Thank You!

Cheers Arne

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,299

You can use the function module

CLOI_PUT_SIGN_IN_FRONT.

Regards,

Ravi

Hi,

I have an internal table with some character and numeric (integer, currency) fields and I need to export that data to a csv file.

I have used the function "CONVERT_SAP_TO_CSV" to geht my csv data. Before that I have converted the numeric fields by WRITE TO to character.

In my csv file, I get the negative sign on the right side, so I can´t calculate anything in excel than.

In the debugger, the negativ sign is always on the right side, but in the csv it need to be on the left side.

Can anybody help me, how to get it to the left in my csv?

Thank You!

Cheers Arne

6 REPLIES 6
Read only

Former Member
0 Likes
2,300

You can use the function module

CLOI_PUT_SIGN_IN_FRONT.

Regards,

Ravi

Read only

Former Member
0 Likes
2,299

Hi,

Try using FM CLOI_PUT_SIGN_IN_FRONT.

Sreedhar

Read only

rahulkavuri
Active Contributor
0 Likes
2,299

CLOI_PUT_SIGN_IN_FRONT.

Use tha above FM


CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
  CHANGING
    VALUE         = netvalue
          .

Read only

Former Member
0 Likes
2,299

Hi,

This is happening because u have converted the numeric fields to character. And the character fields will be written in CSV file as it is.

Try by not converting the numeric values to char.

Rgds,

Prakashsingh

Read only

Former Member
0 Likes
2,299

hii

chk this code

<b>

report z_sign
       no standard page heading.

 

type-pools slis.

 

data: fieldcat type slis_t_fieldcat_alv.

 

data: begin of imara occurs 0,

      matnr type mara-matnr,

      maktx type makt-maktx,

      STPRS(15) type c,

      end of imara.

 

* Selection Screen

selection-screen begin of block b1 with frame title text-001 .

select-options: s_matnr for imara-matnr .

selection-screen end of block b1.

 

start-of-selection.

 

  perform get_data.

  perform write_report.

 

 

************************************************************************

*  Get_Data

************************************************************************

form get_data.

 

  select  mara~matnr makt~maktx

            into corresponding fields of table imara

              from mara

               inner join makt

                 on mara~matnr = makt~matnr

                    where mara~matnr in s_matnr

                      and makt~spras = sy-langu.

 

loop at imara.

imara-stprs = '-15.23' .

 

call function 'CLOI_PUT_SIGN_IN_FRONT'

  changing

    value         = imara-stprs.

          .

modify imara.

endloop.

 

endform.

 

************************************************************************

*  WRITE_REPORT

************************************************************************

form write_report.

 

  perform build_field_catalog.

 

* CALL ABAP LIST VIEWER (ALV)

  call function 'REUSE_ALV_GRID_DISPLAY'

       exporting

            it_fieldcat = fieldcat

       tables

            t_outtab    = imara.

 

endform.

 

************************************************************************

* BUILD_FIELD_CATALOG

************************************************************************

form build_field_catalog.

 

  data: fc_tmp type slis_t_fieldcat_alv with header line.

  clear: fieldcat. refresh: fieldcat.

 

  clear: fc_tmp.

  fc_tmp-reptext_ddic    = 'Material Number'.

  fc_tmp-fieldname  = 'MATNR'.

  fc_tmp-tabname   = 'IMARA'.

  fc_tmp-outputlen  = '18'.

  fc_tmp-col_pos    = 2.

  append fc_tmp to fieldcat.

 

 

  clear: fc_tmp.

  fc_tmp-reptext_ddic    = 'Material'.

  fc_tmp-fieldname  = 'MAKTX'.

  fc_tmp-tabname   = 'IMARA'.

  fc_tmp-outputlen  = '40'.

  fc_tmp-col_pos    = 3.

  append fc_tmp to fieldcat.

 

 

  clear: fc_tmp.

  fc_tmp-reptext_ddic    = 'Price'.

  fc_tmp-fieldname  = 'STPRS'.

  fc_tmp-tabname   = 'IMARA'.

  fc_tmp-datatype  = 'CURR'.

  fc_tmp-just       = 'R'.

  fc_tmp-outputlen  = '15'.

  fc_tmp-decimals_out   = '2'.

  fc_tmp-col_pos    = 4.

  fc_tmp-do_sum     = 'X'.

  append fc_tmp to fieldcat.

 

endform.

</b>

Otherwise

with simple logic

data : char(20).

data : val type i.

if val < 0.

write val to char.

concatenate '-' char into char .

condense char no-gaps.

endif.

write : / char.

Regards

Naresh

Read only

0 Likes
2,299

check this function module..

CLOI_PUT_SIGN_IN_FRONT will move the negative sign from the left hand side of a number, to the right hand side of the number. Note that The result will be left justified (like all character fields), not right justifed as numbers normally are.

chck this example..

data: a1 type i value 56 ,

a2 type i value 60,

res type i.

res = a1 - a2.

data: res1(10).

res1 = res.

CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'

CHANGING

VALUE = res1

.

write res1.