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

Convert Number

Former Member
0 Likes
944

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.

6 REPLIES 6
Read only

former_member217544
Active Contributor
0 Likes
867

Hi,

Check this thread:

Regards,

Swarna Munukoti

Read only

former_member404244
Active Contributor
0 Likes
867

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

Read only

Former Member
0 Likes
867

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

Read only

0 Likes
867

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

Read only

0 Likes
867

Hi,

My code will always work .In that case we can use.


when '21'.

concatenate '21' 'st' into lv_num.

Regards,

Nagaraj

Read only

former_member194669
Active Contributor
0 Likes
867

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.