Skip to Content

Calculate number of Commas

hi,

i need to calculate the number of commas in a string variable. is there any standard function for it?

regards,

ags.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 23, 2008 at 10:32 AM

    Loop though the string character by character and every time the character is a comma add one to a counter.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 23, 2008 at 10:34 AM

    Hi

    Use syntax

    FIND ALL OCCURRENCES OF 'your pattern'.

    Example -

    data : var(100),

    cnt type i.

    var = 'faasdsa,fdasfdas,asdfads,'.

    DATA: result_tab TYPE match_result_tab.

    FIND ALL OCCURRENCES OF `,`

    IN var

    RESULTS result_tab.

    describe table result_tab lines cnt.

    write : cnt.

    Regards

    Nimesh S. Patel

    Edited by: Nimesh Patel on Dec 23, 2008 11:42 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 23, 2008 at 10:37 AM

    hi,

    Data ur_string type string.

    Data cnt type i.

    FIND ',' IN ur_string MATCH COUNT cnt.

    variable Cnt will be having number of commas in the string.

    Regards,

    Rohit

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 23, 2008 at 10:41 AM

    hi,

    try this code...

    DATA : V_CHAR(25) VALUE 'abbbbbbabjjjaa',

    CNT TYPE I.

    REPLACE ALL OCCURRENCES OF 'a' IN V_CHAR WITH 'l': REPLACEMENT COUNT CNT

    .

    WRITE CNT.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 23, 2008 at 10:42 AM

    Hi,

    To get the total number of commas, you need to build the logic......

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 23, 2008 at 10:55 AM

    Hi,

    This snipet will give you the number of commas:

    DATA w_str TYPE string VALUE 'This,is,to,find,number,of,commas'.
    DATA: w_cnt TYPE i.
    
    
    REPLACE ALL OCCURRENCES OF ',' IN  w_str
    WITH ',': REPLACEMENT COUNT w_cnt.
    
    WRITE: / w_str,
                / w_cnt.

    Regards,

    Manoj Kumar P

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 23, 2008 at 10:58 AM

    You can try this code

    data : itext type string value 'abc,def,ghi,klm,,,,gdgd'.
    DATA result_tab TYPE match_result_tab.
    
    data : count type i.
    
    *search
    
    FIND ALL OCCURRENCES OF REGEX ','
         IN itext
         RESULTS result_tab.
    describe table result_tab lines count.
    write : / count.

    Regards

    Shiba Prasad Dutta

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.