2009 Jul 28 7:34 AM
Hi Gurus,
Before posting this thread, i serached SDN and i could not find proper answer for my requirement.
My Question is , i have a text filed which will contain a numeric value. say .5 . the desired output should be 0050.
means , it should remove the decimals from text and result output shuold contain 4 characters. (It should consider 2 numbers before decimal and 2 numbers after decimal)
any suggestions pls..
Thanks
Meher
Hi Gurus,
Before posting this thread, i serached SDN and i could not find proper answer for my requirement.
My Question is , i have a text filed which will contain a numeric value. say .5 . the desired output should be 0050.
means , it should remove the decimals from text and result output shuold contain 4 characters. (It should consider 2 numbers before decimal and 2 numbers after decimal)
any suggestions pls..
Thanks
Meher
2009 Jul 28 7:37 AM
Hi ,
first of all use translate statement
use this statement for replacing . by space ,
translate p_field by '. space'.
then . will be removed then use condence p_field with no gaps.
PLease let me know if you still have any issues on this.
Thanks and regards,
Rajeshwar.
2009 Jul 28 7:42 AM
Thanks Rajeswar,
I did it, but still this logic is not working for some cases like...one which i mentioned in my question.
Let me explain bit clear..
if the text contains .5 (point 5), result should be 0050. means it should take 2 numbers before decimal place and 2 numbers after decimal.
the suggested logic will not work in this case.
Please clarify me..
Thanks
Meher
2009 Jul 28 7:38 AM
See this code:
v_number = '.5'.
v_whole = trunc( v_number ).
v_deci = frac( v_number ).
concatenate v_whole v_deci into v_newnum.
you may need to put the whole and deci into a character variable; just adjust accordingly...
v_whole and v_deci are type N of length 2
hope this helps
Edited by: Chris C. on Jul 28, 2009 8:39 AM
2009 Jul 28 7:46 AM
Hi Rakesh,
Try this way. Its very simple.
Thanks
Venkat.Odata: v_char(2) type c value '.5'.
data: v_num(4) type n.
v_num = v_char * 100.
write v_num.
2009 Jul 28 7:57 AM
Thanks Venkat.
Problem solved. Thank you very much all for your valuable suggestions..
2009 Jul 28 7:46 AM
Can you try in this way:
DATA: INPUT(4) type c value '1.5',
var1(2) type N,
output type string,
fst type string,
sec type string.
split input at '.' into fst sec.
var1 = fst.
fst = var1.
var1 = sec.
sec = var1.
concatenate fst sec into output.
write output.
2009 Jul 28 7:51 AM
Hi ,
then in this case first find the string length using STRLEN statement and then use if condition.
P_val = STRLRN(p_field) .
if p_val = 2.
translate p_val ' . '.
condence no gaps.
then use
concatenate '00' p_val 'oo' into p_val.
elseif = 3.
endif.
Please let me know if you still have any issues on this.
Thanks and regards,
Rajeshwar.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |