2009 Dec 17 6:34 AM
Hi,
Is there any way or function module to convert the number in this format:
example:
1-> 1st
2 -> 2nd
3-> 3rd
thanks.
Hi,
Is there any way or function module to convert the number in this format:
example:
1-> 1st
2 -> 2nd
3-> 3rd
thanks.
2009 Dec 17 6:40 AM
2009 Dec 17 6:45 AM
Hi,
Not sure of the Function module.. But some other way we can do..Please have a look at the below piece of code.
case number.
when '1'.
concatenate '1' 'st' into lv_num1.
when '2'.
concatenate '2' 'nd' into lv_num2.
endcase.
Regards,
Nagaraj
2009 Dec 17 6:54 AM
Hi Jeromejerome,
Check out below code..
As far as I know there is no FM available for this..
REPORT ZILESH_TEST.
PARAMETERS : P_NUM(3) TYPE C.
DATA : L_OUT(10) TYPE C.
DATA : L_SUFFIX(2) TYPE C.
DATA : L1 TYPE I.
START-OF-SELECTION.
L1 = STRLEN( P_NUM ) - 1.
CASE P_NUM+L1(1).
WHEN '1'.
L_SUFFIX = 'st'.
WHEN '2'.
L_SUFFIX = 'nd'.
WHEN '3'.
L_SUFFIX = 'rd'.
WHEN OTHERS.
L_SUFFIX = 'th'.
ENDCASE.
CONCATENATE P_NUM L_SUFFIX INTO L_OUT.
CONDENSE L_OUT.
WRITE : L_OUT.
Hope it will solve your problem..
Thanks & Regards
ilesh 24x7
ilesh Nandaniya
2009 Dec 17 7:01 AM
Hi Ilesh & Nagraj,
What if the number is 21 for 21 we pronounce it as Twenty first. The above code will not work in that case.
Regards
Abhii
2009 Dec 17 7:06 AM
Hi,
My code will always work .In that case we can use.
when '21'.
concatenate '21' 'st' into lv_num.
Regards,
Nagaraj
2009 Dec 17 7:09 AM
Try something this way
REPORT zaRs.
parameters : v_num type i.
data : v_len type i.
data : v_num1 type i.
data : v_char(20) type c.
start-of-selection.
write : v_num to v_char.
condense v_char no-gaps.
if not v_num is initial.
v_len = strlen( v_char ).
v_len = v_len - 1.
move v_char+v_len(1) to v_num1.
if v_num1 eq 1.
concatenate v_char 'st' into v_char.
condense v_char no-gaps.
write : v_char.
endif.
if v_num1 eq 2.
concatenate v_char 'nd' into v_char.
condense v_char no-gaps.
write : v_char.
endif.
if v_num1 eq 3.
concatenate v_char 'rd' into v_char.
condense v_char no-gaps.
write : v_char.
endif.
endif.
a®
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |