Former Member

### Problem in Total displaying and calculating in terms of words

Hi All,

Pl help me out in the following scenario. I have been trying this since 5 days but could not know how to find the solution.

I have a check form and in tha ti need to display the amount in words but in terms of digit format. Say for ex., we have a number in the total field as 234567

In the check, it will be like

hundredthousand tenthousand thousand hundred tens units cents

The digits shud be displayed in their respective columns...

Now, for this, i have created separate windows like for displaying the digits in units, i have created window called win_units, like that i created 6 windows for displaying all the 6 digits.

In those window, i am writing code as follows:(say for units window)

DEFINE &L_WAERS& = 'USD'

DEFINE &L_SPRAS& = 'EN'

PERFORM SET_unit_SPELL IN PROGRAM prog name

USING &REGUH-RWBTR&

USING &L_WAERS&

USING &L_SPRAS&

USING &HLP_FILLER&

CHANGING &H_SPELLW&

CHANGING &H_SPELLD&

ENDPERFORM

im displaying the value as: &H_SPELLW&

In the progra, in the routine im writing the code as follows:

FORM set_un_spell TABLES input_fields STRUCTURE itcsy

output_fields STRUCTURE itcsy.

DATA: rwbtr(18) TYPE c,

snett LIKE regud-snett,

waers LIKE t001-waers,

spras LIKE sy-langu,

fill(1) TYPE c.

DATA: l_val TYPE regud-snett,

l_ch_val TYPE spell-word.

rwbtr = input_fields-value.

IF rwbtr NE 'XXXXXXXXXXXXXX.XXX'.

TRANSLATE rwbtr USING ', '.

TRANSLATE rwbtr USING '. '.

CONDENSE rwbtr NO-GAPS.

PACK rwbtr TO snett.

waers = input_fields-value.

spras = input_fields-value.

fill = input_fields-value.

• Units

l_val = snett MOD 10.

PERFORM spell_amt USING l_val l_ch_val spras waers fill.

CONDENSE l_ch_val.

output_fields-value = l_ch_val.

MODIFY output_fields INDEX 1.

CLEAR l_ch_val.

ENDIF.

ENDFORM. "set_un_spell

the spell amt routineis as follows:

FORM spell_amt USING l_val TYPE regud-snett

l_ch_val TYPE spell-word

spras TYPE sylangu

waers TYPE sywaers

fill TYPE c.

DATA: h_spell LIKE spell.

CALL FUNCTION 'SPELL_AMOUNT'

EXPORTING

language = spras

currency = waers

amount = l_val

filler = fill

IMPORTING

in_words = h_spell

EXCEPTIONS

not_found = 1

too_large = 2.

l_ch_val = h_spell-word.

ENDFORM. "spell_amt

Nowm, when im executing the program, when there is an amount field called 12.00, it is displaying "TWELVE" in all the windows..i am not able to understand wehre the problem is...

can any one please suggest me whether my code is correct. if not, pl suggest me the rite code... i m going mad by executing th same thing hundred times...

pl suggest me the rite way to solve the problem.

Regards,

\

Priya

10|10000 characters needed characters exceeded

• Nov 25, 2007 at 06:20 AM

You are making some mistakes while passing the value to the FM SPELL_AMOUNT. You need to pass each and every word to the FM to get its value as a digit.

Try this piece of code. This code returns you the values in the table ITAB for each and every digit from RIGHT to LEFT.

```REPORT  ztest_np_123.

DATA: l_value TYPE bseg-dmbtr.

l_value = '234567.89'.

DATA: c_value(20),
l_off TYPE i,
l_len TYPE i,
l_char TYPE c,
l_val_1 TYPE bseg-dmbtr,
l_spell LIKE spell.

DATA: BEGIN OF itab OCCURS 0,
value(20),
END   OF itab.

c_value = l_value.
TRANSLATE c_value USING '. '.
CONDENSE c_value NO-GAPS.
l_len = STRLEN( c_value ).

DO.

l_len = l_len - 1.

l_char = c_value+l_len(1).
l_val_1 = l_char.

CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
amount    = l_val_1
currency  = 'USD '
language  = sy-langu
IMPORTING
in_words  = l_spell
EXCEPTIONS
not_found = 1
too_large = 2
OTHERS    = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

itab-value = l_spell-word.
APPEND itab.
CLEAR itab.

IF l_len = 0..
EXIT.
ENDIF.

ENDDO.```

Now, to get the values from the ITAB for each digits you need to have as many variables for each digits to get back into your SAPScript.

```PERFORM SET_unit_SPELL IN PROGRAM prog name
USING &REGUH-RWBTR&
USING &L_WAERS&
USING &L_SPRAS&
USING &HLP_FILLER&
CHANGING &H_02&
CHANGING &H_01&
CHANGING &H_1&
CHANGING &H_10&
CHANGING &H_100&
CHANGING &H_1K&
CHANGING &H_10K&
ENDPERFORM```

From the above code you have to read each and every line and assign it to its respective variable.

Say,

```READ TABLE ITAB INDEX 1.
H_02 = ITAB-VALUE.
H_01 = ITAB-VALUE.
H_1 = ITAB-VALUE.
H_10 = ITAB-VALUE.```

And so on..

Hope you got the logic ðŸ˜Š

Regards,

Naimesh Patel

10|10000 characters needed characters exceeded
• Former Member

HiNaimesh,

Thanks a lot. I will try out the logic tomorrow.

Regards,

Priya

• Former Member
Dec 02, 2007 at 12:22 PM

done