Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8644

Re: Function to check if string is a valid number

$
0
0

I know it's an old post, apologies to drag it from the grave, but I recently had a similar problem.
I had to write a Batch Input routine to transfer Configuration data from a Quotes to Contract create with a reference to that quote.

The first test I did dumped because there was a number in scientific notation in there.

 

Not the nicest solution, but as a work-around it did the trick.

 

 

REPORT zev_number_check        NO STANDARD PAGE HEADING LINE-SIZE 255.
DATA: lv_scientific  TYPE qsollwerte.
DATA: value_number   TYPE p DECIMALS 2.
DATA: value_char     TYPE cux_value.
DATA: lr_root        TYPE REF TO cx_root.
DATA: error          TYPE string.
*--------------------------------------------------------------------*
* Selection screen
*--------------------------------------------------------------------*
SELECTION-SCREEN: BEGIN OF BLOCK box1 WITH FRAME TITLE tp_b10.
PARAMETERS: p_valin TYPE cux_value DEFAULT '1.3400000000000000E+00'.
SELECTION-SCREEN: END OF BLOCK box1.
*--------------------------------------------------------------------*
* Initialization
*--------------------------------------------------------------------*
INITIALIZATION.
* Set selection texts (to link texts to selection screen):
* This is done to facilitate (love that word...) the copying of this
* program to other environments without losing all the texts.   tp_b10 = 'Enter value'(b10).
*--------------------------------------------------------------------*
* Select data
*--------------------------------------------------------------------*
START-OF-SELECTION.
END-OF-SELECTION.
*--------------------------------------------------------------------*
* Main Logic
*--------------------------------------------------------------------*
* Check if it's a number (Scientific Notation).   TRY.       MOVE p_valin TO lv_scientific.       MOVE lv_scientific TO value_number.       WRITE: value_number, '(Number)'(m01).     CATCH cx_root INTO lr_root.
* Do nothing, not a number.       error = lr_root->get_text( ).       WRITE /: error.       MOVE p_valin TO value_char.       WRITE /: value_char, '(Not a number)'(m02).   ENDTRY.

Viewing all articles
Browse latest Browse all 8644

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>