‎2008 Dec 19 3:25 AM
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,
‎2008 Dec 19 3:31 AM
‎2008 Dec 19 4:21 AM
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
‎2008 Dec 19 4:23 AM
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
‎2008 Dec 19 4:41 AM
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.
‎2008 Dec 19 6:12 AM
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.
‎2008 Dec 22 11:39 AM
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
‎2008 Dec 19 5:38 AM
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
‎2008 Dec 22 12:01 PM
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,