‎2006 Mar 07 10:49 AM
Hi,
Given a string of character values, I get the values comprising of character values and also floating point values. eg 25.75 . The problem is the decimal value is not deciphered as a decimal but instead a character value. Could you please give me the name of the function module that would recognise the floating point value..
Thanks in advance....
‎2006 Mar 07 10:52 AM
Hi sanjay,
1. Declare another variable
data : num type p decimals 2.
2. then just assign
num = mystring.
3. then use num in all your calculations.
4. eg (just copy paste in new program)
report abc.
data : mynum type p decimals 2.
data : mystr(15) type c.
mystr = '25.65'.
mynum = mystr.
mynum = mynum + 1.
write mynum.
regards,
amit m.
Message was edited by: Amit Mittal
‎2006 Mar 07 10:54 AM
‎2006 Mar 07 10:55 AM
declare a variable type p
and assign this vaue to that.
type casting will be done.
‎2006 Mar 07 10:56 AM
Hi Sanjay,
Would you please be a little more specific about your requirement?
Still, from what I understand you want to convert the values stored ina character variable to a numeric value complete with the decimal places.
You can do so as follows:
DATA: WA_TMP TYPE P DECIMALS 2,
WA_TXT(10) VALUE '24.54'.
WA_TMP = WA_TXT.
WRITE: WA_TMP.This way you will be able to preserve the numbers after the decimal as well.
Hope this helps,
Regards,
Madhur
NB: Please award points if found helpful.
‎2006 Mar 07 11:15 AM
Hi Madhur,
eq 1) field xyz = 20.30.
2) field xyz = 'SAM_TEST' .
Thus xyz can have packed number or character value. If it is a packed number I can assign directly to any packed variable, However if it is 'SAM_TEST' value then i would have to search through another table and retrieve value for that string.
My problem is to find if xyz contains P value or character string.
Thanks in Adv
‎2006 Mar 07 11:20 AM
Hi again,
1. we can check like this.
2.
REPORT abc.
PARAMETERS : mystr(15) TYPE c.
start-of-selection.
IF mystr CO '1234567890. '.
WRITE 😕 'OK'.
else.
WRITE 😕 'incorrect value'.
ENDIF.
regards,
amit m.
‎2006 Mar 07 11:21 AM
Hi,
Maey be you can write code like below.
if field CO '0123456789.'.(Need to check . can be put in '')
it is charatcter
else.
it is a number
endif.
Message was edited by: Ramakrishna Prasad
‎2006 Mar 07 11:46 AM
Hi Sanjay,
You will have to parse the character variable character by character to determine if it contains any character field.
This can easily be achieved by the following code.
REPORT ZTMP.
DATA: WA_TMP TYPE P DECIMALS 2,
WA_TXT(10) VALUE '35.56',
WA_LTH TYPE I,
WA_INDEX TYPE I VALUE 0,
WA_INDC(1) VALUE ' '.
CONDENSE WA_TXT.
WA_LTH = STRLEN( WA_TXT ).
DO WA_LTH TIMES.
IF WA_TXT+WA_INDEX(1) CO '0123456789.'.
WA_INDC = 'X'.
ELSE.
WA_INDC = ' '.
EXIT.
ENDIF.
WA_INDEX = WA_INDEX + 1.
ENDDO.
IF WA_INDC EQ ' '.
WRITE: 'VARIABLE CONTAINS A STRING.'.
ELSE.
WRITE: 'VARIABLE CONTAINS A PACKED DECIMAL.'.
ENDIF.Using CO directly will not work.
Regards,
Madhur
CORRECTION ***************
Sorry Sanjay,
I made a mistake here. Using CO directly will work if we include a SPACE " " character in our CO criteria. This would be as follows:
REPORT ZTMP .
DATA: WA_TMP TYPE P DECIMALS 2,
WA_TXT(10) VALUE '35.57',
WA_LTH TYPE I,
WA_INDEX TYPE I VALUE 0,
WA_INDC(1) VALUE ' '.
CONDENSE WA_TXT.
IF WA_TXT CO '0123456789. '. "This contains a space char.
WRITE: 'VARIABLE CONTAINS A PACKED DECIMAL.'.
ELSE.
WRITE: 'VARIABLE CONTAINS A STRING.'.
ENDIF.Message was edited by: Madhur Chopra
Message was edited by: Madhur Chopra
‎2006 Mar 07 11:50 AM
Hi again,
To remind.
1. IF mystr CO '1234567890. '.
there is a SPACE after the . (DOT)
2. If we do not give space,
it won't work.
3. its like this.
IF mystr CO '1234567890.@'.
where @ = SPACE
regards,
amit m.
‎2006 Mar 07 11:52 AM
hi ,
you can just use.
data : typ(1).
describe field xyz type typ.
typ contains C if character and P if it is packed.
regards
satesh
‎2006 Mar 07 11:58 AM
Hi Amit,
Yes, I just realised out that SPACE was necessary for this to work since its a character field defined with the specified length. If this length is not completely filled up, it will contains spaces and hence not work.
I made the necessary corrections to my post.
Thanks!
Regards,
Madhur
‎2006 Mar 07 12:13 PM
Hi Satesh,
Sanjay's requirement is to know the content of the variable. His variable XYZ is of type C, and can contain either a string or a decimal number. In case its a Decimal No. he wants to move it into another variable of type Packed Decimal.
Regards,
Madhur
‎2006 Mar 07 12:31 PM
hi madhur,
then i think this will do..
parameters : c(10) type c.
data : c1(10) , p type p decimals 2.
<b> if c ca sy-abcde.</b>
c1 = c.
write : c1.
else.
p = c.
write : p.
endif.regards
satesh
‎2006 Mar 07 12:44 PM
hi again,
1. did your problem get solved ?
2. As per the forum etiquette,
u may pls award points
to helpful answers by clicking the STAR
on the left of that reply.
regards,
amit m.
regards,
amit m.