This commit is contained in:
danrega
2024-12-09 13:20:24 +01:00
parent 85b51a94ce
commit 183580cb04
7 changed files with 473 additions and 39 deletions

View File

@@ -1490,7 +1490,7 @@ ENDDO.
- Two flavors for iterations using [`FOR`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfor.htm):
- [Conditional iterations](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfor_conditional.htm)
(including the ABAP words `UNTIL` and `WHILE` which
have the semantics of ABAP statements
have the semantics of the ABAP statements
[`DO`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapdo.htm)
and
[`WHILE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapwhile.htm))
@@ -1660,23 +1660,28 @@ ENDLOOP.
"The objective of the following example is to extract the content of the segments that
"are positioned within /.../ in a URL. The segments are stored in an internal table.
DATA(url) = `https://help.sap.com/docs/abap-cloud/abap-concepts/controlled-sap-luw/`.
FIND ALL OCCURRENCES OF PCRE `(?<=/)([^/]+)(?=/)` IN url RESULTS DATA(res).
FIND ALL OCCURRENCES OF PCRE `(?<=\/)([^\/]+)(?=\/)` IN url RESULTS DATA(res).
"Details on the regular expression:
"- Positive lookbehind (?<=/) that determines that the content is preceded by `/`
"- Positive lookahead (?=/) that determines that the content is followed by `/
"- ([^/]+) in between determines that any sequence of characters that are not `/` are matched
"- Positive lookbehind (?<=\/) that determines that the content is preceded by `/`
"- Positive lookahead (?=\/) that determines that the content is followed by `/
"- ([^\/]+) in between determines that any sequence of characters that are not `/` are matched
"- The match is put in parentheses to store the submatch
"The RESULTS addition stores findings in an internal table of type match_result_tab.
"Submatches (i.e. length and offset values of the submatches) are stored in internal
"tables themselves. Therefore, the example uses nested loops and the substring function
"to retrieve the strings.
LOOP AT res INTO DATA(finding).
LOOP AT finding-submatches INTO DATA(sub).
DATA(url_part) = substring( val = url off = sub-offset len = sub-length ).
APPEND url_part TO url_parts.
ENDLOOP.
ENDLOOP.
"The following statement uses nested iteration expressions with FOR instead of nested
"LOOP statements.
DATA(url_parts_for_loop) = VALUE string_table( FOR wa1 IN res
FOR wa2 IN wa1-submatches
( substring( val = url off = wa2-offset len = wa2-length ) ) ).
( substring( val = url off = wa2-offset len = wa2-length ) ) ).
ASSERT url_parts = url_parts_for_loop.
*Content:
*help.sap.com
*docs