2013 Sep 12 9:34 PM
Hi All,
I need to convert FLTP to decimal. I have done some research and tried different ways with NO success. This is in SRM system.
1. The Class CL_ABAP_DECFLOAT does help, but not available in SRM.
2. The FM's like QSS0_FLTP_TO_CHAR_CONVERSION etc, which are available in ECC but not available in SRM.
3. I tried the below logic
Move the FLTP value to Packed field.
The problem with the 3rd approach, it works in Report but doesn't work in Method. I tried to write a FM and pass this value to do the conversion in there and pass the value back to method. But even that doesn't work, although the FM works independently.
Question: why is FLTP to Packed works in FM/Report and not in Method of a class? What is the alternative approach?
Appreciate your help.
Thanks,
Gopi
Hi All,
I need to convert FLTP to decimal. I have done some research and tried different ways with NO success. This is in SRM system.
1. The Class CL_ABAP_DECFLOAT does help, but not available in SRM.
2. The FM's like QSS0_FLTP_TO_CHAR_CONVERSION etc, which are available in ECC but not available in SRM.
3. I tried the below logic
Move the FLTP value to Packed field.
The problem with the 3rd approach, it works in Report but doesn't work in Method. I tried to write a FM and pass this value to do the conversion in there and pass the value back to method. But even that doesn't work, although the FM works independently.
Question: why is FLTP to Packed works in FM/Report and not in Method of a class? What is the alternative approach?
Appreciate your help.
Thanks,
Gopi
2013 Sep 12 9:51 PM
Hi Gopi,
Why don't you just copy the class (or just the required method of) CL_ABAP_DECFLOAT to a ZCL_ABAP_DECFLOAT in the SRM system and use this? There are import/export reports you can use for this : http://scn.sap.com/docs/DOC-10143. Just rename the class before you import it.
The reason that it works in FM/Report and not in class method is that in a class ABAP OO is enforced and the ABAP syntax is more restrictive. Obsolete statements are not allowed and typing and moving data also is more limited.
Regards,
Freek
2013 Sep 13 4:37 PM
Hi Cavens,
Yes, you are correct. We can copy the class/method. I was trying to avoid copying and if there is an alternate solution.
Still I am not clear as why a FM doesn't work when called from a method, but works independently?
Thanks,
Gopi
2013 Sep 13 7:46 PM
Hi Gopi,
At this Wiki, you can find some of the restrictions of ABAP OO. This is quite interesting literature :
http://wiki.scn.sap.com/wiki/display/ABAP/ECC5.0+And+Above
Concerning your FM : if you call the FM from the method and you debug it, does the conversion work in the FM if you debug it? If it does, what is the type of the parameter that you return the value in? If the conversion works in the function and you return it to a decimal in the method, I do not see where it goes wrong.
If you show the code of the method (with parameters) and the function, I can test it myself.
Regards,
Freek
2013 Sep 14 5:53 AM
Thanks Cavens. The FM runs perfectly when tested independently or from a report. But when I call this FM in method and pass the value 1.2050000000000001E+01 it doesn't convert properly.
Results:
When tested independently is 12.0500000000000....
From method it converts to .120500000000... .
I check the value in debug mode and it does diff depending from where its called. The data type is fltp, but don't exactly remember .
Going back to u r previous and of copy the ECC class, even that didn,t work as one method has the statement Kernal ..... Not sure what this does? I checked the documentation and saw that its for internal use only.
Thanks
2013 Sep 14 10:35 AM
HI Gopi,
If the problem with the kernel call is in a method that you don't need, you can just leave it out of the class. if not, then you won't be able to use it.
With the function : is the value in the import parameter the same when you call it directly or when you call it from the method. By this I mean : if you debug, is the value the same before you do the conversion? Is it the result of the conversion that different?
Can you provide the function code, the types used in the method and the exact value passed to it? Then I can test it myself.
Regards,
Freek
2013 Sep 13 6:41 AM
Hi Gopi,
The ROUND FM should be able to help you.
Pass the float to it and get the output in char now move this to your packed decimal.
Regards
2013 Sep 13 4:33 PM
Hi Shah,
How can I use ROUND FM when the input is 1.2050000000000001E+01 ?
Thanks,
2013 Sep 14 6:29 AM
Hi Gopi,
You can try like this
DATA : output TYPE p LENGTH 16 DECIMALS 2,
input TYPE p LENGTH 16 DECIMALS 14.
DATA: var TYPE string,
a TYPE string,
b TYPE string.
var = '1.2050000000000001E+01'.
SPLIT var AT 'E' INTO a b.
input = a.
CALL FUNCTION 'ROUND'
EXPORTING
decimals = 2
input = input
sign = '+'
IMPORTING
output = output
* EXCEPTIONS
* INPUT_INVALID = 1
* OVERFLOW = 2
* TYPE_INVALID = 3
* OTHERS = 4
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
WRITE : / output.
2013 Sep 15 6:22 PM
Hi Ramesh,
Thanks for the reply.
I don't think round fm will work, as what if the value has E+02 as the exponential? Round doesn't seem to consider the exponential values.
Will give it a try though.
2013 Sep 16 3:44 AM
2013 Sep 16 2:04 PM
Thanks Ramesh. But that is not what I am looking.
The value '1.2050000000000001E+01' should be 12.050000000000001.
Thanks,