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

ABAP String processing using normal methods

Former Member
0 Likes
1,022

I have a string like this:

A:12345;B:34324;C:443232;

Question 1)

How do I extract B:34324 from the above string?

Note: I can only use methods provided in ABAP programming (BC-ABA) such as split, CO, CA,etc

Question 2)

How do I know how many ';' characters the string contains?

Question 3)

How do I know the position of "B:" in the string?

Please help.

Thanks and best regards,

8 REPLIES 8
Read only

Former Member
0 Likes
946
Read only

Former Member
0 Likes
946

Check this sample code

data : text(100) value 'A:12345;B:34324;C:443232;'.
data : itab(50) occurs 0 with header line.
split text at ';' into table itab.
loop at itab.
if itab ca 'B'.
 write : / itab.
endif.
endloop.

Regards

Shiba Prasad Dutta

Read only

Former Member
0 Likes
946

Hi,

Please find code below for the Question 1:

DATA: v_string TYPE string,

v_one TYPE string,

v_two TYPE string,

v_three TYPE string.

CONSTANTS: c_colon TYPE char1 VALUE ';'.

v_string = 'A:12345;B:34324;C:443232'.

SPLIT v_string AT c_colon INTO v_one v_two v_three.

WRITE:/ v_two.

The variable V_TWO contains 'B:34324'.

Hope this solves your problem.

Regards,

Lavanya

Read only

Former Member
0 Likes
946

Hi,

The same code can be used for the question 2:

DATA : text(100) VALUE 'A:12345;B:34324;C:443232;',

v_count TYPE sytabix.

DATA : itab(50) OCCURS 0 WITH HEADER LINE.

SPLIT text AT ':' INTO TABLE itab.

CLEAR v_count.

LOOP AT itab.

IF itab CA ';'.

v_count = v_count + 1.

ENDIF.

ENDLOOP.

WRITE:/ v_count.

Regards,

Lavanya.

Read only

0 Likes
946

I got this error message when compile:

The addition of OCCURS is no longer supported in the OO context. Use "Table of ... Intial size" instaead.

So what is the actual syntax like? Help me.

Read only

0 Likes
946

Hi,

Please find the correct syntax:

DATA: text(100) VALUE 'A:12345;B:34324;C:443232;',
      v_count TYPE sytabix.

TYPES: BEGIN OF ty_itab,
         text(50),
       END OF ty_itab.

DATA: itab TYPE TABLE OF ty_itab,
      wa_itab TYPE ty_itab.

SPLIT text AT ':' INTO TABLE itab.

CLEAR v_count.
LOOP AT itab INTO wa_itab.
  IF wa_itab-text CA ';'.
    v_count = v_count + 1.
  ENDIF.
ENDLOOP.

WRITE:/ v_count.

Regards,

Lavanya.

Edited by: Lavanya Gourisetty on Dec 22, 2008 12:41 PM

Read only

Former Member
0 Likes
946

Hi,

Question 3)
How do I know the position of "B:" in the string?

Check this

DATA a TYPE string value  'A:12345;B:34324;C:443232'.
DATA c TYPE i.
DATA d TYPE c.
DATA e TYPE i VALUE 0.
DATA f TYPE i VALUE 0.
c = STRLEN( a ).

DO c TIMES.
  d = a+e(1).
  e = e + 1.
  f = f + 1.
  IF d EQ 'B'.
    EXIT.
  ENDIF.
ENDDO.
WRITE f.

Thanks

Read only

Former Member
0 Likes
946

Hi,

Try this

DATA : char03 TYPE string VALUE 'A1234;B5678;C9012;',

char04 TYPE string,

len1 type sy-fdpos.

data char_tab type table of string.

split char03 at ';' into table char_tab.

search char03 for 'B'.

len1 = sy-fdpos. " Position of B

Regards,