Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Split a string

Former Member
0 Kudos

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

10 REPLIES 10

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

0 Kudos

Hi

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.

0 Kudos
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?

Former Member
0 Kudos

Hi,

Check the function module: STRING_SPLIT_AT_POSITION

Regards,

Bhaskar

0 Kudos

Dear Mona

Please let me know the correct string what you want to split

because what you mentioned text is not possible to post as string

your requirement is clear and it can be happen

please give us correct string and if you like describe us why you doing such a thing.

Regards

Nelson From Sri Lanka

0 Kudos

hi Nelson,

This is the string which i need to append and its taking as a sting no poblem in that.

Former Member
0 Kudos

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 .......

Former Member
0 Kudos

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

Former Member
0 Kudos

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.