Skip to Content
avatar image
Former Member

Split a string

Hi All,

I have a requirement where there is a string suppose

$self.qty = ( ( 3.1429 * dpcc_c * dpcc_c ) / 4 ) * hpcc_c if V_PCC = 'V_PCC_CIRC' , $self.qty = lpcc_r * bpcc_r * hpcc_r * n if v_PCC = 'V_PCC_RECT' , $self.qty = ( lpcc_t * bpcc_t * hpcc_t * n ) + ( h1pcc_t / 2 * ( lpcc_T + l1pcc_t )

In this string i want to divide it according to the ' ' marks so that the both starting and ending codes should be in the same line, and the maximum length of the line is 72 char, so need to divide is first on the basis of ' if no quotes found then split at 72 char.

need to check both the conditions single quotes and length in one line 72 and append in a table like the output in the table sholuld be like this.

$self.qty = ( ( 3.1429 * dpcc_c * dpcc_c ) / 4 ) * hpcc_c if V_PCC =

'V_PCC_CIRC' , $self.qty = lpcc_r * bpcc_r * hpcc_r * n if v_PCC =

'V_PCC_RECT' , $self.qty = ( lpcc_t * bpcc_t * hpcc_t * n )+ ( h1pcc_t

/ 2 * ( lpcc_T + l1pcc_t ).

Please suggest some solution.

Thanks

Mona

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

6 Answers

  • avatar image
    Former Member
    Sep 01, 2008 at 01:12 PM

    Hi,

    Use SPLIT Command.

    Example:

    data:

    w_data(72) type c 'ABAP is easy'.

    Split w_data at ' ' into w_data1 w_data2 w_data3.

    Regards,

    Rama.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 01, 2008 at 01:18 PM

    Hi Mona,

    You can use the SPLIT command to split the text.

    SPLIT dobj AT sep INTO

    { {result1 result2 ...} | {TABLE result_tab} }

    [IN {BYTE|CHARACTER} MODE].

    You can move the split string into the TABLE result tab.

    Anand

    Add comment
    10|10000 characters needed characters exceeded

    • I know to use split command but my problem is i want the quotes along with the string after splitting , but split command removes that and also i need to count 72 characters.

      You said After Split the string quotes are remove.can you not concatenate again only quotes after split?

  • avatar image
    Former Member
    Sep 02, 2008 at 04:30 AM

    Hi,

    Check the function module: STRING_SPLIT_AT_POSITION

    Regards,

    Bhaskar

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 02, 2008 at 04:42 AM

    try this .........

    FIND FIRST OCCURRENCE of ''' in section offset off of string.

    " Search for the forst occurence of ' .

    if off > 72 . " if first occurrence is after 72

    off = 72 . " set the offset to 72

    endif.

    append string(off) to internal_table.

    string = string + off .

    hope it helps ....... 😊

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 02, 2008 at 04:44 AM

    You can use

    FIND ALL OCCURRENCES OF substring IN string RESULTS result_tab.

    This will give offset points of the substring in table result. Loop the table and use the offset to split ur string.

    Regards

    Sathar

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 02, 2008 at 04:50 AM

    One way to get this is to use two nested do loops.

    The outer loop will split the main string at first single quote.

    The inner loop will check lenghth of splitted portion and split it further if lenghth is more than 72.

    regarding the lost single quote, you can pad it with concatenate after splitting.

    Inside the inner loop you can populate a temp internal table. The final internal table can be built using temp internal table at the end of inner do loop. (temp internal table to be refreshed on end of each inner loop)

    please provide proper exit points for both do loops.

    Add comment
    10|10000 characters needed characters exceeded