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: 

How to convert the character value to currency/numeric

Former Member
0 Kudos

Hi,

See the sample code here

data: v_qtr_field(7).

data: w_low_limit like glt0-kslvt,

w_amount like glt0-hslvt.

w_low_limit = 02.

w_max_period = 3.

concatenate 'HSL' w_low_limit into v_qtr_field.

*comment

*I am looking for a field formation thru above code like in GLT0 table like HSL02,HSL03 *etc based on the value user entered in the selection *screen

DO w_max_period TIMES

VARYING w_amount FROM v_qtr_field NEXT v_qtr_field + 1.

t_trans_values-dmbe2 = t_trans_values-dmbe2 + w_amount.

ENDDO.

I am facing problem in the Do loop as it wont allows multiple data types. can you suggest me how to convert the v_qtr_field whose data type is character to currency?

5 REPLIES 5

Former Member
0 Kudos

Hi,

Please check this code .

PERFORM write_currency

              USING buf_anla-urwrt t_dates-waers t_txw_anla-urwrt.

*---------------------------------------------------------------------*

*       FORM WRITE_CURRENCY                                           *

*---------------------------------------------------------------------*

*       convert currency amount to string                             *

*       - use decimal point                                           *

*       - remove separator characters                                 *

*---------------------------------------------------------------------*

*  -->  P_AMOUNT                                                      *

*  -->  P_CURRENCY_UNIT                                               *

*  -->  P_STRING                                                      *

*---------------------------------------------------------------------*

FORM WRITE_CURRENCY

     USING P_AMOUNT        TYPE P

           P_CURRENCY_UNIT LIKE TCURC-WAERS

           P_STRING        TYPE C.

 

  DATA: DEC2POINT(2) TYPE C VALUE ',.'.

 

 

* convert separator to decimal point

  WRITE P_AMOUNT TO P_STRING CURRENCY P_CURRENCY_UNIT

        NO-GROUPING

        NO-SIGN

        LEFT-JUSTIFIED.

  TRANSLATE P_STRING USING DEC2POINT.

 

* put minus sign before number

  IF p_amount < 0.

    SHIFT P_STRING RIGHT.

    P_STRING(1) = '-'.

  ENDIF.

 

ENDFORM.

<i>Hope This Info Helps YOU.</i>

Regards,

Lakshmi

former_member188685
Active Contributor
0 Kudos

Hi,

use this FM HRCM_STRING_TO_AMOUNT_CONVERT

pass the string , thousand separator,decimal separator, if it is currecy pass currecy key WAERS.

Regards

vijay

rahulkavuri
Active Contributor
0 Kudos

USE THE FM PSSV_TEXT_INTO_FIELD_CURRENCY

Former Member
0 Kudos

Hii

Use command PACK and UNPACK

DATA: c LIKE bseg-dmbtr ,

n(13) TYPE n VALUE '1234.56'.

WRITE n TO c.

Regards

Naresh

andreas_mann3
Active Contributor
0 Kudos

hi,

try this code - it works:

DATA: v_qtr_field(7).
DATA: v_qtr_field2(7).
DATA: w_low_limit LIKE bkpf-monat,
      w_low_next  LIKE bkpf-monat,
      t_trans_values-dmbe2 LIKE glt0-hslvt,
w_amount LIKE glt0-hslvt,
w_max_period.

w_low_limit = 02.
w_max_period = 3.
CONCATENATE 'HSL' w_low_limit INTO v_qtr_field.
w_low_next = w_low_limit + 1.
CONCATENATE 'HSL' w_low_next INTO v_qtr_field2.

DO w_max_period TIMES
VARYING w_amount FROM v_qtr_field NEXT v_qtr_field2.
  t_trans_values-dmbe2 = t_trans_values-dmbe2 + w_amount.
ENDDO.

A.