When I test a subroutine that included in SAPScript,a runtime error occured.Below is the error message.
Unable to interpret "XXXXXXXXXXX.XX " as a number.
An exception occurred. This exception is dealt with in more detail below. The exception, which is assigned to the class 'CX_SY_CONVERSION_NO_NUMBER', was neither
caught nor passed along using a RAISING clause, in the procedure "Z_CALCULATE_GROSS" "(FORM)".
Since the caller of the procedure could not have expected this exception to occur, the running program was terminated.
The reason for the exception is:
The program attempted to interpret the value "XXXXXXXXXXX.XX " as a number, but
since the value contravenes the rules for correct number formats,
this was not possible.
<b>The related source code is :</b>
000170 FORM Z_CALCULATE_GROSS TABLES IN_TAB STRUCTURE ITCSY
000180 OUT_TAB STRUCTURE ITCSY.
000200 DATA: NET_VALUE LIKE EKPO-NETPR, " TYPE C,
000210 GROSS TYPE P DECIMALS 2. "LIKE EKPO-NETPR.
000230 READ TABLE IN_TAB WITH KEY 'EKPO-NETPR'.
<b>-----> NET_VALUE = IN_TAB-VALUE.</b>
It seems that the data type of NET_VALUE can not be assigned a type CHAR data source.But the data source IN_TAB-VALUE actually is a CHAR type.
How should I solve this problem ?
The problem is you are assigning a char field to a currency field.
DATA: NET_VALUE LIKE EKPO-NETPR,
its a currency field with length 11 and decimal place 2.
you can ceck the netpr filed from ekpo table in se11.
So the filed value filed in IN_TAB table should be like ekpo-netpr.
if this solves your query please reward points
the internal tables that transfer date from sapscript to form save the data in char format, so before moving your value to variable you should check the type of that variable because a dump could occur.
Now in IN_TAB-VALUE you have a amount and it's char type and output form. If you have 101060.34 in IN_TAB-VALUE you'll have: 101.060,34. The system can't interpret the value as number when you try to transfer in NET_VALUE.
So you convert your value before moving it to NET_VALUE.
REPLACE '.' WITH SPACE INTO IN_TAB-VALUE.
IF SY-SUBRC <> 0. EXIT.
CONDENSE IN_TAB-VALUE NO-GAPS.
REPLACE ',' WITH '.' INTO IN_TAB-VALUE.
Now you can move IN_TAB-VALUE to NET_VALUE.
Message was edited by: max bianchi
Also, a good way of exception handling like in this case, would be to catch catchable runtime errors like this one and handle exceptions to your requirements:
CATCH SYSTEM-EXCEPTIONS CONVT_NO_NUMBER = 5. DO. ...... ...... ENDDO. ENDCATCH. IF SY-SUBRC = 5. "handle your exceptions here ENDIF.