2013 Nov 22 12:41 PM
Hi,
Please help me in splitting a string which contains url.
Here the problem is user can give any text as per his wish,so only url should be displayed in next line of the workflow inbox.
My code is like this.
lv_name = quote_no.
CALL FUNCTION 'READ_TEXT'
EXPORTING
* CLIENT = SY-MANDT
id = 'Z006' "'0001'
language = sy-langu
name = lv_name
object = 'VBBK'
TABLES
lines = lt_http_link
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF lt_http_link[] IS INITIAL.
*Raise error cos document link shud exist
MESSAGE e001 INTO dummy.
zmac_exception message.
ELSE.
LOOP AT lt_http_link INTO ls_http_link.
CONCATENATE lv_link ls_http_link-tdline INTO lv_link.
ENDLOOP.
CONDENSE lv_link.
IF lv_link CS 'HTTP' OR lv_link CS 'http'.
*Ok
ELSE.
MESSAGE e009 INTO dummy.
zmac_exception message.
ENDIF.
**Append blank line
* APPEND ls_body TO t_body.
* ls_body-line = text-006.
* APPEND ls_body TO t_body.
*
**Append Link
* ls_body-line = lv_link.
* APPEND ls_body TO t_body.
* CLEAR: ls_body.
ENDIF.
2013 Nov 22 12:47 PM
Hi Sandeep,
it's a good beginning, you just have to know the size of the text, make a loop (with a DO x times) and search for the next character = ' '. (space)
I will convert to uppercase and check only if begin contain 'HTTP'
regards
Fred
2013 Nov 22 1:16 PM
Hi Sandeep Reddy,
Please check this code it might be helpful for you.
DATA : lv_found_line TYPE i.
DATA : lt_text TYPE TABLE OF string,
wa_text LIKE LINE OF lt_text.
DATA : lv_string TYPE string.
APPEND 'RAGHUNADH' TO lt_text.
APPEND 'HTTP' TO lt_text.
APPEND 'COM' to lt_text.
APPEND 'KODALI' TO lt_text.
FIND 'HTTP' IN TABLE lt_text MATCH LINE lv_found_line.
IF sy-subrc IS INITIAL.
READ TABLE lt_text INTO wa_text INDEX lv_found_line.
IF sy-subrc IS INITIAL.
IF wa_text CA 'HTTP' OR wa_text CA 'http'.
lv_pos = sy-fdpos.
ENDIF.
if wa_text CA 'COM' or wa_text CA 'com'.
lv_endpos = sy-fdpos.
endif.
ENDIF.
ENDIF.
Now we got Starting and end Position for the LINK
Thanks & Regards,
Raghunadh Kodali.
2013 Nov 22 1:30 PM
Hi,
how did you know is url ending by a COM ? maybe less than 1% ending with a .com
(look the url of this thread ..)
Fred
2013 Nov 22 2:01 PM
Regex can be used.
In below sample, code first tries to find http://abc.def.ghi type of URL.
If not found, code tries to find http://abc.def type of URL.
Both http and https are supported by the pattern.
DATA: lv_string1 TYPE string
VALUE 'something about http://www.test.in/rest/of/the/url regards',
lv_string2 TYPE string
VALUE 'something about https://test.in/rest/of/the/url regards',
lv_result TYPE string.
TRANSLATE lv_string1 TO UPPER CASE.
FIND REGEX '(HTTPS?://\w+\.\w+\.\w+\S+)' IN lv_string1 SUBMATCHES lv_result.
IF sy-subrc <> 0.
FIND REGEX '(HTTPS?://\w+\.\w+\S+)' IN lv_string1 SUBMATCHES lv_result.
ENDIF.
WRITE:/ sy-subrc, lv_result.
TRANSLATE lv_string2 TO UPPER CASE.
FIND REGEX '(HTTPS?://\w+\.\w+\.\w+\S+)' IN lv_string2 SUBMATCHES lv_result.
IF sy-subrc <> 0.
FIND REGEX '(HTTPS?://\w+\.\w+\S+)' IN lv_string2 SUBMATCHES lv_result.
ENDIF.
WRITE:/ sy-subrc, lv_result.