on 10-06-2008 1:03 PM
Hi All,
Can anyone tell me how do i separate following:
01, Rupesh, Mhatre, "Mhatre, Rupesh", 23.08.2008
as
01
Rupesh
Mhatre
Mhatre, Rupesh
23.08.2008
Thanks in Advance
Regards,
Rupesh
Try this:
DATA: g_text TYPE string,
g_text2 type string.
DATA: it_result_tab TYPE match_result_tab,
wa_result_tab TYPE match_result,
g_start TYPE syindex,
g_end TYPE syindex,
g_length TYPE syindex.
g_text = '01, Rupesh, Mhatre, "Mhatre, Rupesh", 23.08.2008'.
FIND ALL OCCURRENCES OF '"' IN g_text RESULTS it_result_tab.
IF sy-subrc EQ 0.
READ TABLE it_result_tab INDEX 1 INTO wa_result_tab.
IF sy-subrc EQ 0.
g_start = wa_result_tab-offset.
ENDIF.
READ TABLE it_result_tab INDEX 2 INTO wa_result_tab.
IF sy-subrc EQ 0.
g_end = wa_result_tab-offset.
ENDIF.
g_length = g_end - g_start + 1.
g_text2 = g_text+g_start(g_length).
replace g_text2 in g_text with ''.
* Then do the splitting on G_TEXT
ENDIF.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Maen,
Thanks a lot your brilliant solution.
But for SAP R/3 4.7C there is no support for
FIND ALL OCCURRENCES.
Hence, somebody can try this. It gets the offset values of all the ' " ' in a string.
DO len TIMES.
SEARCH g_text(sy-index) FOR ' " '
IN CHARACTER MODE
STARTING AT sy-index.
IF sy-subrc = 0.
off = sy-index - 1.
wa_temp-l_offset = off.
APPEND wa_temp TO l_temp.
CLEAR: off, wa_temp.
ENDIF.
ENDDO.
Once Again Thanks everybody.
& Nothing is impossible in SAP world &
Happy Coding.
Regards,
Rupesh
Hi Rupesh ,
Look into the below code its working as per your requirement.
DATA : STR1 TYPE STRING.
TYPES : BEGIN OF TY_ITAB,
W_S1(100) TYPE C,
END OF TY_ITAB.
DATA : GT_ITAB TYPE TABLE OF TY_ITAB,
GT_JTAB TYPE TABLE OF TY_ITAB,
WA_ITAB TYPE TY_ITAB,
GT_ITAB1 TYPE TABLE OF TY_ITAB,
WA_ITAB1 TYPE TY_ITAB,
WA_ITAB2 TYPE TY_ITAB,
GT_ITAB2 TYPE TABLE OF TY_ITAB.
DATA LEN TYPE I.
WA_ITAB-W_S1 = '01,hyderabad,"vikram,chandu",03.03.1983'.
APPEND WA_ITAB TO GT_JTAB.
WA_ITAB-W_S1 = '01,hyderabad,"mukesh,kumr",03.03.1983,"kumar"'.
APPEND WA_ITAB TO GT_JTAB.
WA_ITAB-W_S1 = '01,hyderabad,"chaitu,hanmantu",03.03.1983'.
APPEND WA_ITAB TO GT_JTAB.
CLEAR WA_ITAB.
LOOP AT GT_JTAB INTO WA_ITAB2.
CLEAR GT_ITAB.
SPLIT WA_ITAB2-W_S1 AT '"' INTO TABLE GT_ITAB.
LOOP AT GT_ITAB INTO WA_ITAB.
CLEAR : GT_ITAB1[],LEN,WA_ITAB1.
LEN = STRLEN( WA_ITAB ) - 1.
IF ( WA_ITAB-W_S1(1) EQ ',' ) OR ( WA_ITAB-W_S1+LEN(1) EQ ',').
SPLIT WA_ITAB-W_S1 AT ',' INTO TABLE GT_ITAB1.
LOOP AT GT_ITAB1 INTO WA_ITAB1.
APPEND WA_ITAB1 TO GT_ITAB2.
ENDLOOP.
ELSE.
WA_ITAB1-W_S1 = WA_ITAB-W_S1.
APPEND WA_ITAB1 TO GT_ITAB2.
ENDIF.
ENDLOOP.
ENDLOOP.
LOOP AT GT_ITAB2 INTO WA_ITAB.
WRITE WA_ITAB-W_S1.
ENDLOOP.
This works for multiple strings,
please provide ur suggestions
regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Mukesh it really worked.
But I had implemented Maen's solution as it suited my requirement.
Also, I would like to thank Maen for the solution. It works very well in ECC 6.0 but my client is having SAP R/3 4.7C version.
Thanks a lot all of you.
Regards,
Rupesh
Edited by: Rupesh Mhatre on Oct 9, 2008 8:39 AM
hi ,
try this ... its working ..
data : str type string ,
com_pos TYPE i,
str_tab type tline_t,
wa_str like LINE OF str_tab.
str = '01, Rupesh, Mhatre, "Mhatre, Rupesh", 23.08.2008'.
while str is NOT INITIAL.
CLEAR com_pos .
if str(1) = ',' .
str = str+1.
ENDIF.
SHIFT str LEFT DELETING LEADING space.
if str(1) = '"' .
str = str+1.
find FIRST OCCURRENCE OF '"' in str MATCH OFFSET com_pos .
else.
find FIRST OCCURRENCE OF ',' in str MATCH OFFSET com_pos .
ENDIF.
if com_pos is INITIAL .
wa_str-tdline = str .
CLEAR str.
else.
wa_str-TDLINE = str(com_pos).
str = str+com_pos.
if str(1) = '"' .
str = str+1.
ENDIF.
ENDIF.
APPEND wa_str to str_tab.
ENDWHILE.
this will work for any case ... means if " value is there in any place also ....
Edited by: ganesh prasad on Oct 8, 2008 11:18 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
split <variable> at ',' into table <internaltable>.
this will work for sure
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Below code is giving the output you expected . Check and let us know.
DATA: n(2) type n,
str1 TYPE string,
str2 TYPE string,
str3 TYPE string,
str4 type string,
date(10) type c,
text type string.
text = '01, Rupesh, Mhatre, "Mhatre, Rupesh", 23.08.2008'.
REPLACE ALL OCCURRENCES OF REGEX '"' IN text WITH ''.
condense text no-gaps.
SPLIT text AT ',' INTO: n str1 str2 str3 str4 date.
concatenate str3 ',' str4 into str3.
write : n , str1, str2, str3, date.
output :
01 Rupesh Mhatre Mhatre,Rupesh 23.08.2008
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This can be done using the Regular expressions. just search in SDN for Regular Expressions usage.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use -
SPLIT string AT ',' INTO TABLE itab.
Regards,
Aparna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
DATA: n(2) type n,
str1 TYPE string,
str2 TYPE string,
str3 TYPE string,
date type datum,
comma type c value ',',
text type string.
text = '01, Rupesh, Mhatre, "Mhatre, Rupesh", 23.08.2008'
SPLIT text AT comma INTO: n str1 str2 str3 date.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try like this,,,
split lv_string at ',' into table <internaltable>.
Hope it will helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Press F1 on statement SPLIT. And all will be explained.
edit:
The only problem will be the splitting of "Mhatre, Rupesh". You don't want that to be split, so you'll have to figure out a solution for that.
Edited by: Maen Anachronos on Oct 6, 2008 2:05 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi , Try this code. It works for me as you asked.
REPORT zjtest_text2.
DATA: chr TYPE char50,
txt1 LIKE chr,
txt2 LIKE chr,
txt3 LIKE chr.
chr = '01, Rupesh, Mhatre, "Mhatre, Rupesh", 23.08.2008'.
CONDENSE chr.
txt1 = chr.
DO.
SPLIT txt1 AT ',' INTO txt1 txt2.
IF txt1 CA '"'.
REPLACE '"' INTO txt1 WITH space.
SPLIT txt2 AT '"' INTO txt3 txt2.
CONCATENATE txt1 ',' txt3 INTO txt1.
CONDENSE txt1.
ENDIF.
shift txt1 left deleting leading space.
WRITE / txt1.
txt1 = txt2.
IF txt2 IS INITIAL.
EXIT.
ENDIF.
ENDDO.
Regards,
Jey
User | Count |
---|---|
102 | |
12 | |
11 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.