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: 

characters before decimal point

Former Member
0 Kudos
2,480

Hi,

i want to read the characters before decimal point i.e if i have number as 11111111.011

i want to read the all 1's before decimal point and write an condition as

if the number of characters before point exceeds 11 char than display some mesage.

please help.

Gayatri

1 ACCEPTED SOLUTION

Mohamed_Mukhtar
Active Contributor
0 Kudos
432

hi,

DATA : wa_dec TYPE p DECIMALS 3 VALUE '11111111.011',
       wa_p1 TYPE string,
       wa_p2 TYPE string,
       wa_dec1(20),
       len TYPE i.

wa_dec1 = wa_dec.


SPLIT wa_dec1 AT '.' INTO wa_p1
                         wa_p2.
CONDENSE wa_p1.
len = STRLEN( wa_p1 ).
" len = number of characters before decimal
if len > 11.
" do ur work here
endif.
BREAK-POINT.

Thanks & Regards

12 REPLIES 12

Mohamed_Mukhtar
Active Contributor
0 Kudos
433

hi,

DATA : wa_dec TYPE p DECIMALS 3 VALUE '11111111.011',
       wa_p1 TYPE string,
       wa_p2 TYPE string,
       wa_dec1(20),
       len TYPE i.

wa_dec1 = wa_dec.


SPLIT wa_dec1 AT '.' INTO wa_p1
                         wa_p2.
CONDENSE wa_p1.
len = STRLEN( wa_p1 ).
" len = number of characters before decimal
if len > 11.
" do ur work here
endif.
BREAK-POINT.

Thanks & Regards

0 Kudos
432

hi,

how can i find out that the user entered value has point in it.

0 Kudos
432

Hi ,

can u be more precise on ur requirement .??

0 Kudos
432

data: lv_dec type p decimals 2.

first split the number into two

split <number> at '.' into lv_char1 lv_char2.

0 Kudos
432

Simple

data: v_str type string value '111.11'.

if v_str CA '.'.
  write:/ 'Dot at', sy-fdpos.
endif.

0 Kudos
432

hi,

i meant if user can enter any value for example 1111111111 or 1

0 Kudos
432

in that case also the above code samples will work.

but in that case u will not get anything in var3 ( i.e the part after decimal).

anuj_srivastava
Active Participant
0 Kudos
432

Hi gayatri ,

u can draft ur logic as below..

var1 = 1111111.101

Split var1 at '.' into var2 var3.

var4 = strlen ( var2).

if var4 > 11.

do something..

else.

do something.

endif.

Hope this solves ur problem

Regards,

Anuj

Former Member
0 Kudos
432

Hi,

If the input is a packed decimal number, then you can move the contents into a numeric field variable. then you can use a if statement saying ' > 99999999999'.

murat_kaya
Participant
0 Kudos
432

Hi Gayatri,

you can use as below;

l_integer = TRUNC( l_decimal ).

l_integer gets the value before decimal point.

regards,

Murat Kaya

Former Member
0 Kudos
432

Hi Gayatri,

Try below code for your requirement.

Data: v_data type c.

If value entered by user = p_value.

V_data = p_value.

Data: v_data1 type c,

V_data2 typec,

Len type i.

If v_data CA u2018.u2019.

Split v_data at u2018.u2019 Into v_data1

V_data2.

Else.

V_data1 = v_data.

Endif.

Condense v_data1.

Len = strlen (v_data1).

If len> 11.

Message.

Endif.

Hope this will help you.

Regards,

Deepa Kulkarni

Former Member
0 Kudos
432

Hi Gayatri,

Use the following code:

DATA: v_num TYPE p DECIMALS 3 VALUE '11111111.011',

v_len TYPE i,

v_var(15) TYPE c,

v_var1(15) TYPE c,

v_var2(15) TYPE c.

v_var = v_num.

IF v_var CA '.'.

SPLIT v_var AT '.' INTO v_var1 v_var2.

SHIFT v_var1 LEFT DELETING LEADING ' '.

v_len = STRLEN( v_var1 ).

IF v_len > 11.

MESSAGE 'error message' TYPE 'E'.

ENDIF.

ELSE.

SHIFT v_var LEFT DELETING LEADING ' '.

v_len = STRLEN( v_var ).

IF v_len > 11.

MESSAGE 'error message' TYPE 'E'.

ENDIF.

ENDIF.

Revert back in case of any doubt.

Regards,

Nitin.