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

Split last string

Former Member
0 Likes
1,149

Hi all,

I have some strings like these:

1. AAA-BBB-CC-DDDD-ZZZ

2. AA-BBBB-C-DDD-ZZZZ

3. A-BB-ZZZ

4. AA-ZZZZZZ

......

I have to split string and get the last string(Z..) that after the last '-'.

Best regards,

Munur

1 ACCEPTED SOLUTION
Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
1,018

Hi,

Refer code:-


DATA : itab TYPE TABLE OF string,
       wa LIKE LINE OF itab,
       v_lines TYPE i.

PARAMETERS : p_string TYPE string.

START-OF-SELECTION.

  SPLIT p_string AT '-' INTO TABLE itab.
  DESCRIBE TABLE itab
  LINES v_lines.

  READ TABLE itab INTO wa INDEX v_lines. "<--you get the desired string

Hope this helps you.

Regards,

Tarun

5 REPLIES 5
Read only

Former Member
0 Likes
1,018

Search for function module in SE37, fm realted with string operation.

Read only

prasenjit_sharma
Active Contributor
0 Likes
1,018

Hi,

Try this:

1. split the string into table at '-'.

2. describe table to get the no of records

3. read table index sy-tfill.

Regards

Prasenjit

Read only

0 Likes
1,018

As Prasenjit says something like this will do it.

  DATA: lt_string TYPE TABLE OF string,
        lr_last TYPE REF TO string,
        lv_lines TYPE i.

  SPLIT 'AAA-BBB-CC-DDDD-ZZZ' AT `-` INTO TABLE lt_string.

  lv_lines = LINES( lt_string ).
  READ TABLE lt_string REFERENCE INTO lr_last INDEX lv_lines.

  WRITE: /, lr_last->*.

Cheers

Graham Robbo

Read only

Former Member
0 Likes
1,018

Save Our Environment. Save Yourself.

Hi Munur,

You can use the function module STRING_SPLIT by using the delimiter as '-'. This will meet your requirement.

- I'm not an environmentalist. I'm an Earth warrior.

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
1,019

Hi,

Refer code:-


DATA : itab TYPE TABLE OF string,
       wa LIKE LINE OF itab,
       v_lines TYPE i.

PARAMETERS : p_string TYPE string.

START-OF-SELECTION.

  SPLIT p_string AT '-' INTO TABLE itab.
  DESCRIBE TABLE itab
  LINES v_lines.

  READ TABLE itab INTO wa INDEX v_lines. "<--you get the desired string

Hope this helps you.

Regards,

Tarun