Get all occurrences of the string between any two specific characters in SAP ABAP

SAP HANASAPSAP Basis

I usually use REGEX in all such cases as it is faster and easily readable and would recommend the same to you.

You can use something similar as the snippet to get your job done.

DATA: lv_para TYPE string.
lv_para = ' You &are like& kite &flying& in a &hurricane&'.
REPLACE ALL OCCURRENCES OF REGEX '&[^&]+&' IN lv_para WITH ''.
WRITE lv_para.

Let me explain the regex for you. It should match the first ‘&’, then you can have any combination with multiple occurrences of ‘&’ and the last occurrence of ‘&’ must be matched.

Published on 14-Dec-2017 10:30:17