SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Является ли строка числом



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP
View previous topic :: View next topic  
Author Message
A_Smith
Участник
Участник



Joined: 28 Nov 2007
Posts: 30

PostPosted: Thu Jun 26, 2008 8:45 am    Post subject: Является ли строка числом Reply with quote

Доброго вам времени суток...знаю глупый вопрос, но все же...как проверить, является ли строка числом?
Back to top
View user's profile Send private message
vga
Мастер
Мастер


Age: 200
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Thu Jun 26, 2008 8:56 am    Post subject: Reply with quote

Code:
IF str CO '1234567890. '.
 WRITE: / 'ЙА ЧИСЛО'.
ENDIF.
Back to top
View user's profile Send private message Blog Visit poster's website
Loyso
Участник
Участник



Joined: 19 Nov 2007
Posts: 37

PostPosted: Mon Jun 30, 2008 12:56 pm    Post subject: Reply with quote

vga wrote:
Code:
IF str CO '1234567890. '.
 WRITE: / 'ЙА ЧИСЛО'.
ENDIF.


Есть мнение, что строка '.... .. ...' не является числом....... тем не менее, программа напишет "ЙА ЧИСЛО".

тем не менее можно попробовать вот так:

Code:

form conv_char_to_curr using value(l_char)  type any
                             l_typename     type any
                    changing l_curr         type any.

  data: li_input_util type ref to cl_fobu_input_util.

  create object li_input_util
    exporting
      typename = l_typename.

  condense l_char no-gaps.

  call method li_input_util->input_convert_with_check
    exporting
      field_value_ext = l_char
    importing
      field_value_int = l_curr
    exceptions
      illegal_value   = 1
      others          = 2.

endform.                    "conv_char_to_curr

Back to top
View user's profile Send private message Blog
Timer
Участник
Участник



Joined: 21 Jul 2008
Posts: 6

PostPosted: Tue Jul 29, 2008 12:33 pm    Post subject: Reply with quote

Привет. Хотя уже прошёл месяц, я всё же добавлю ещё одно решение.
Для проверки можно использовать регулярные выражения (как сказано в разделе "Регулярные выражения" транзакции AbapDocu, "As of release 7.0, ABAP supports extended regular expressions in accordance with POSIX standard 1003.2").
Например, так:
Code:

Parameters: p_input type string default '-123.45' obligatory.

DATA: regex   TYPE REF TO cl_abap_regex,
      matcher TYPE REF TO cl_abap_matcher,
      match   TYPE c LENGTH 1.

CREATE OBJECT regex EXPORTING pattern     = '-?\d+([\.,]\d+)?'
                              ignore_case = 'X' .

matcher = regex->create_matcher( text = p_input ).

match = matcher->match( ).

If p_input CN '0123456789-.,'.
  Write 'Явно не число в десятичной СС - содержит не только цифры 0-9, минус, точку, запятую.'.
Elseif match = ' '.
  Write 'Не число, не совпадает с регулярным выражением ''-?\d+([\.,]\d+)?'''.
Else.
  Write 'Число - совпадает с регулярным выражением ''-?\d+([\.,]\d+)?'''.
Endif.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.