Application Development and Automation 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: 
Read only

proble in spliting

Former Member
0 Likes
1,687

Hello All ,

I have problem with spiting i want to split the below message into table and i have tried

with the following command without success

Hello Dan,##My mobile doesn't work#Please assist ##Best regards #joy

SPLIT ls_create_message-text AT '#' INTO TABLE lt_text.

I want that the first line in lt_text will be hello dan

that to emty lines since i have two ##

etc

what i miss here since i getting all the sentence in lt_text ?

Best regards,

Joy


1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
1,594

Hi Joy,

as Shambu tried to explain.

Whenever you see a #  character in ABAP, very probably this is no # put just a character which can not be displayed or printed, mostly a control, character like tab, linefeed and others.

In debugger, you can switch to hey mode and see the hex representation of the character.

Class CL_ABAP_CHAR_UTILITIES has the attributes

BACKSPACE

BYTE_ORDER_MARK_BIG Unicode - Big Endian

BYTE_ORDER_MARK_LITTLE Unicode - Little Endian

BYTE_ORDER_MARK_UTF8

CHARSIZE

CR_LF

ENDIAN

FORM_FEED

HORIZONTAL_TAB

MAXCHAR

MINCHAR

NEWLINE

VERTICAL_TAB

So first try to split at CL_ABAP_CHAR_UTILITIES=>NEWLINE or CL_ABAP_CHAR_UTILITIES=>CR_LF to get the lines of the message, then if needed split at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB to get tab-delimited elements.

What I see from your line "Hello Dan,##My mobile doesn't work#Please assist ##Best regards #joy", I assume

SPLIT ls_create_message-text AT CL_ABAP_CHAR_UTILITIES=>NEWLINE INTO TABLE lt_text.

will do it.

Regards

Clemens

8 REPLIES 8
Read only

former_member282968
Contributor
0 Likes
1,594

Hi Joy,

Please check the below code its going to work:

DATA:LV_STRING TYPE STRING,
           LT_STRING TYPE TABLE OF STRING.

LV_STRING = 'Hello Dan,##My mobile doesnt work.#Please assist. ##Best regards, #Joy'.

SPLIT LV_STRING AT '#' INTO TABLE LT_STRING.

LOOP AT LT_STRING INTO LV_STRING.
  IF LV_STRING IS INITIAL.
    SKIP.
  ENDIF.
  WRITE:/ LV_STRING.
ENDLOOP.

With regards,

Read only

0 Likes
1,594

Hi

Use REPLACE or TRANSALATE - Command to translate the ## into # in the text.

Then process that text line

Regards,

Venkat

Read only

laurent_fournier2
Contributor
0 Likes
1,594

Hello,

Why don't you try to add a space between ## ?

ie : Hello Dan,# #My mobile doesn't work#Please assist # #Best regards #joy

Regards.

Read only

Former Member
0 Likes
1,594

By # if you mean TAB, the split using CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

Data: htab TYPE c VALUE cl_abap_char_utilities=>HORIZONTAL_TAB.

SPLIT ls_create_message-text AT htab INTO TABLE lt_text.

Thanks,

Shambu

Read only

Former Member
0 Likes
1,594

Hi Joy,

Try This..

DATA : STR(50) TYPE C VALUE 'R#P#S'.

data : chr(1) type c value '#'.

split STR at chr into table name.

Pass '#' symble to a veriable and then pass that veriable into SPLIT statement.

You will get the desired output.

Regards,

Ravi Singh

Read only

Clemenss
Active Contributor
1,595

Hi Joy,

as Shambu tried to explain.

Whenever you see a #  character in ABAP, very probably this is no # put just a character which can not be displayed or printed, mostly a control, character like tab, linefeed and others.

In debugger, you can switch to hey mode and see the hex representation of the character.

Class CL_ABAP_CHAR_UTILITIES has the attributes

BACKSPACE

BYTE_ORDER_MARK_BIG Unicode - Big Endian

BYTE_ORDER_MARK_LITTLE Unicode - Little Endian

BYTE_ORDER_MARK_UTF8

CHARSIZE

CR_LF

ENDIAN

FORM_FEED

HORIZONTAL_TAB

MAXCHAR

MINCHAR

NEWLINE

VERTICAL_TAB

So first try to split at CL_ABAP_CHAR_UTILITIES=>NEWLINE or CL_ABAP_CHAR_UTILITIES=>CR_LF to get the lines of the message, then if needed split at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB to get tab-delimited elements.

What I see from your line "Hello Dan,##My mobile doesn't work#Please assist ##Best regards #joy", I assume

SPLIT ls_create_message-text AT CL_ABAP_CHAR_UTILITIES=>NEWLINE INTO TABLE lt_text.

will do it.

Regards

Clemens

Read only

Former Member
0 Likes
1,594

Hi Joy,

*-- Declarations

    

   DATA : convt TYPE REF TO cl_abap_conv_in_ce,

    DATA : t_data TYPE STANDARD TABLE OF string,
                lv_string TYPE string.

*--Split srting into internal table

lv_string =  'Hello Dan##My mobile doesnt work#Please assist ##Best regards#Joy'.


   SPLIT lv_string AT cl_abap_char_utilities=>
HORIZONTAL_TAB INTO TABLE t_data.

This may help you .

Thanks & Regards,

Suresh M

Read only

Former Member
0 Likes
1,594

Hi Joy

I've tried Suresh's code above to no avail, but by doing the following:

SPLIT lv_string AT '#' INTO TABLE t_data.

Then the results are as follows:

(

Hello Dan

My mobile doesnt work

Please assist

Best regards

Joy

)

I'm guessing this is your required result...
Maybe just check the Type of your lt_text declaration, is it a "type standard table of string"?

Regards

Vic