08-06-2010 12:35 AM
I have amount balance say amt_bal coming from ftp server file and I have developed function module to derive Posting_type_key based on the amount balance (amt_bal).
Sometimes i_amt_bal value contians alphabets as 'T234567'.
In that case, my code isfailing/dumping
I coded the Function module with
IMPORTparameter as
I_AMT_BAL TYPE CHAR16.
EXPORT paramater as
POST_TYPE TYPE CHAR02.
Source code is below
*"----
""Local Interface:
*" IMPORTING
*" VALUE(I_AMT_BAL) TYPE CHAR16
*" EXPORTING
*" VALUE(POST_TYPE) TYPE CHAR_02
*"----
IF i_amt_bal < 0. ( here it is failing if the amt_bal contians 'T234567' )
post_type = '40'.
ELSE.
post_type= '50'.
ENDIF.
=======================
How to make sure the i_amt_val's value is only numericals and if and only if numerical then pass posting type code?
08-06-2010 2:34 AM
What's so complicated about it ?
Define the IMPORTing param I_AMT_BAL as some currency type (viz., DMBTR, WRBTR etc). Is there any specific reason you've defined it as CHAR16 ?
BR,
Suhas
08-06-2010 2:34 AM
What's so complicated about it ?
Define the IMPORTing param I_AMT_BAL as some currency type (viz., DMBTR, WRBTR etc). Is there any specific reason you've defined it as CHAR16 ?
BR,
Suhas
08-06-2010 7:05 PM
Even If I declare i_amt_bal as NETWR the value comes as 'T234567'.
So, can I check that the i_amt_bal contains only number of 0 yo 9...?
Why because, If i_amt_bal contains other than number, then I won't check Lessthan (<) or greater than (>) check.
THANKS,
08-06-2010 7:22 PM
Hi ,
Use the below statement to solve this problem . I have tried and it is working for me.
Replace all occurrences of 'T' in v_amt_bal with '0' .
Regards,
Prabakaran.S
08-13-2010 5:43 AM
Thanks.
I mean the value may come with alphabets mix (like T36YH789 )incase the file sent with wrong values , that's why how can I check the i_amt_bal shud contain only numbers and comma and full stop.
My intension of asking is
IF i_amt_bal contain only numbers and comma and full stop, then, I will proceed
other wise I will error message
Can anybody help me?
08-13-2010 7:10 AM
Hi Sam,
Write your whole code in the following IF statement
IF I_AMT_BAL CA '0123456789' AND I_AMT_BAL IS NOT INITIAL.
. . .
< your code >
. . .
ELSE.
< error message >
ENDIF.
Regards,
Ateet
08-13-2010 7:17 AM
Hi Sam,
you can assign the input string parameter to a type-P variable, and catch whether there's a conversion exception.
Please try the following code:
data: l_amt_bal_as_amount type dmbtr.
catch system-exceptions convt_no_number = 1.
l_amt_bal_as_amount = i_amt_bal.
endcatch.
if sy-subrc <> 0.
write: / 'Error while converting amount string to number'.
else.
if l_amt_bal_as_amount < 0.
post_type = '40'.
else.
post_type = '50'.
endif.
endif.
I hope this helps. Kind regards,
Alvaro
08-13-2010 7:30 AM
My requirement is to check
i_amt_bal MUST contain only numbers and comma and full stop.
YOUR below synstax will also pass if the I_AMT_BAL has a value of 'T678YR906'.
IF I_AMT_BAL CA '0123456789' AND I_AMT_BAL IS NOT INITIAL.
I dont' want that. I want to make sure the amount value should contains only numbers and comma and full stop, to proceed further.
08-13-2010 8:01 AM
Hi Sam,
Try with
IF I_AMT_BAL CO '0123456789.,' AND I_AMT_BAL IS NOT INITIAL.
It shall work.
Contains Only: True, if operand1 only contains characters from operand2.
Regards,
Selva K.
08-13-2010 8:10 AM
Hi Sam,
Go through this link
http://help.sap.com/saphelp_sm40/helpdata/en/fc/eb3516358411d1829f0000e829fbfe/content.htm
It will help you with comaprison strings.
Regards,
Ateet