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: 

ALV - negative sign in the front

Former Member
0 Kudos

hai all,

I am facing a problem in ALV. I have a field which is of type currency. Whenever the number is negative, the sign appears at the last. I need to put the negative sign in front of the number.

<b>eg, 5.00- has to be displayed as -5.00.</b>

Thanks,

kannan

9 REPLIES 9

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Please see this thread. On correction.... the edit mask you be like this.

fc_temp-edit_mask = '-________________'.

not

fc_temp-edit_mask = "-________________".

Also, this will work.

fc_temp-edit_mask = 'V________________'.

This puts the sign in front, but in my test program it is not formatting the decimals places correctly for some reason. For example, if the value is 2.00- it is showing in the ALV grid as -200.

Of course this will not work for you. I'll get back if I figure it out.

Regards,

Rich Heilman

0 Kudos

Thanks for the reply Rich.

But as you told the solution is not effective enough. Hope u come up with a better one.

Thanks,

KANNAN

0 Kudos

Hi Selva Kumar,

Am also facing same problem like, may i know how u resolved the issue.

thanks in advance

0 Kudos

Use this Function Module 'CLOI_PUT_SIGN_IN_FRONT'.

Regards,

Supratik

Former Member
0 Kudos

HI,

USe Function Module <b>CLOI_PUT_SIGN_IN_FRONT</b>, may be this works in your case.

Regards

Sudheer

0 Kudos

If you don't mind converting the currency field to a character field, then you can use the previously mentioned funtion module. Check out this same program, pay close attention to the field catalog for "Price", you must do the field catalog like so in order to get this to work. The totaling functionality will still work if you do it like this. The field in the internal table must be of TYPE c.



report zrich_0004
       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,
<b>      STPRS(15) type c,</b>
      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' .

<b>call function 'CLOI_PUT_SIGN_IN_FRONT'
  changing
    value         = imara-stprs.
          .</b>
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.


<b>  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.</b>

endform.


REgards,

Rich Heilman

0 Kudos

Hi,

While using the above solutions please ensure that the Check Box for Fixed Point Arithmetic is checked in the attributes of your program.

Rich, it maybe why your program displays such values.

Hope it helps

0 Kudos

Hi Supratik,

Thanks for replay

It is not working for currency field, showing  error like unexpected function module.

Thank you.

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

Create your own conversion exit function an put in the ALV catalog.

See here:

scroll down to my response.

Regards.