Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Find First Occurrence ']'

0 Kudos
1,966

Hello Experts!

Kinda new to SAP. Please help me how to find the first occurrence. The goal here is to separate two values when it detects ']' then display the first value. For example with a data 123456]0879. Only the 123456 should be displayed. I was supposed to use SPLIT but it won't work if SPLIT sscc1 INTO s_sscc1 since it requires 2 or more fields to be specified.

Current code(still not sure about this one):

DATA: s_sscc1 TYPE string.

IF sscc1 CA ']'.
*find first occurrence code*
ENDIF.
sscc1 = s_sscc1.
4 REPLIES 4

Richa-Katiyar
Explorer
0 Kudos
1,873

Please try with below code.

SPLIT sscc1 AT ']' INTO: str1 str2. WRITE 😕 str1. 

0 Kudos
1,873

Hi Richa,

That was my code before but I was told not to use SPLIT since str2 is not necessary. They want me to use FIND first occurrence. Thank you!

Sandra_Rossi
Active Contributor
1,873

ABAP function:

substring_before

venkateswaran_k
Active Contributor
0 Kudos
1,873

Hi

Please try this code.

DATA: s_sscc1 TYPE String,
      lv_var  TYPE I.
 
s_sscc1 = 'AAAA[BBBBB][CCC]'.
 
FIND '[' IN s_sscc1 MATCH OFFSET V_OFF MATCH LENGTH lv_var.
IF SY-SUBRC = 0.
  write v_off.
  write lv_var.
  WRITE s_sscc1+0(v_off).
Endif.

Regards,

Venkat