Application Development and Automation 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: 
Read only

How to get pattern from the string?

Former Member
0 Likes
1,423

Friends,

I have 3 strings variables.

Name1,Name2 and Name 3.

I want to search following terms in above variables.

'T1' 'TURC1' 'TURC 1' and 'TURC 1X' " X=any character

'T2' 'TURC1' 'TURC 2' and 'TURC 2X' " X=any character

'T3' 'TURC1' 'TURC 3' and 'TURC 3X' " X=any character

'T4' 'TURC1' 'TURC 4' and 'TURC 4X' " X=any character

If T1 found, then v_res = 1.

If TURC1 found, then v_res = 1.

If TURC 1 found, then v_res = 1.

If TURC1X found, then v_res = 1X.

......

......

Same for 2 3 and 4.

So, How can I do this?

1 ACCEPTED SOLUTION
Read only

former_member585060
Active Contributor
0 Likes
1,165

Hi,

Name1,Name2 and Name 3.

I want to search following terms in above variables.

FIND 'T1' IN Name1.
IF sy-subrc = 0
v_res = 1.
ELSE.

FIND 'TURC1' IN Name1.
IF sy-subrc = 0
v_res = 1.
ENDIF.
ENDIF.

" Try giving multiple value in FIND statement, check wether it work or not so that u can find all the 1st in single statement.
" Do same for remaining strings

Regards

Bala Krishna

9 REPLIES 9
Read only

Former Member
0 Likes
1,165

Hi,

try this.

search string for 'T1' abbrieviated.

Search 'TURC1' for 'T1' abbrieviated.

if sy-subrc eq 0.

write : 'Found'.

endif.

Do the same for all strings

Read only

Former Member
0 Likes
1,165

HI,

try this way..

IF 'T1 TURC1 TURC 1 TURC 1X' CS 'T1'

v_res = 1.

ENDIF.

Do same for the others

Read only

former_member585060
Active Contributor
0 Likes
1,166

Hi,

Name1,Name2 and Name 3.

I want to search following terms in above variables.

FIND 'T1' IN Name1.
IF sy-subrc = 0
v_res = 1.
ELSE.

FIND 'TURC1' IN Name1.
IF sy-subrc = 0
v_res = 1.
ENDIF.
ENDIF.

" Try giving multiple value in FIND statement, check wether it work or not so that u can find all the 1st in single statement.
" Do same for remaining strings

Regards

Bala Krishna

Read only

former_member222860
Active Contributor
0 Likes
1,165

Check this logic:

data: v_str type string,
      v_res(2) type c.

v_str = 'T1 TURC1 TURC 1 TURC 1X'.

if v_str CA 'T1' OR v_str CA 'TCUR1' OR v_str CA 'TURC 1'.
  v_res = 1.
endif.

if v_str CA 'TURC 1X'.
  v_res = '1x'.
endif.

write:/ v_res.

Mahesh

Read only

awin_prabhu
Active Contributor
0 Likes
1,165

Hi,

Use below logic for 'T1'. For 'T2' and 'T3' change all '1' in below code to '2' and '3' respectively.

DATA: str TYPE string VALUE 'TURC 1'

v TYPE string,

ch TYPE string,

l TYPE i.

IF str CO 'T1'.

v = 1.

ELSE.

IF str CO 'TURC1'.

v = 1.

ELSE.

IF str CO 'TURC 1'.

v = 1.

ELSE.

IF str CS 'TURC1'.

l = STRLEN( str ).

l = l - 1.

MOVE str+l(1) TO ch.

CONCATENATE '1' ch INTO v.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

Thanks.

Read only

Former Member
0 Likes
1,165

Hi,

Try to check the Contains String "CS" command.

Note that this command is case-sensitive.

Read only

Former Member
0 Likes
1,165

Hi,

you need to String options like below.

CA --> contains any

CO --> contains only

CP --> contain patterns

CN

and for your requirement u can use CA and CP.

thanks ,

kat

Read only

awin_prabhu
Active Contributor
0 Likes
1,165

Hi

Change in my code.

First check 'name1' variable with below code.

For checking 'name2' 'name3' replace all 'name1' in below code to 'name2' and 'name3'.

DATA: name1 TYPE string VALUE 'TURC1y',

v TYPE string,

ch TYPE string,

l TYPE i,

h type i.

*For checking 'name1' variable.

IF name1 CO 'T1' OR name1 CO 'T2' OR name1 CO 'T3' OR name1 CO 'T4'.

v = 1.

ELSE.

IF name1 CO 'TURC1' OR name1 CO 'TURC2' OR name1 CO 'TURC3' OR name1 CO 'TURC4'.

v = 1.

ELSE.

IF name1 CO 'TURC 1' OR name1 CO 'TURC 2' OR name1 CO 'TURC 3' OR name1 CO 'TURC 4'.

v = 1.

ELSE.

IF name1 CS 'TURC1' OR name1 CS 'TURC2' OR name1 CS 'TURC3' OR name1 CS 'TURC4'.

l = STRLEN( name1 ).

l = l - 1.

MOVE name1+l(1) TO ch.

CONCATENATE '1' ch INTO v.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

Might solve ur problem

Read only

former_member585060
Active Contributor
0 Likes
1,165

Hi,

Try below code

Do for remaining same Strings

DATA : name1 TYPE string,
       name11 TYPE string,
       name2 TYPE string,
       name3 TYPE string.
DATA : v_res(2) TYPE n,
       w_fdpos TYPE sy-fdpos,
       str TYPE i,
       ch TYPE c.


name1 = 'ABCT1XRYTURC1JJTURC 1LLTURC 1A'.

str = STRLEN( name1 ).

FIND 'T1' IN name1.

IF sy-subrc = 0.
  v_res = 1.

  FIND 'TURC1' IN name1.

  IF sy-subrc = 0.
    v_res = 1.
    SEARCH name1 FOR 'TURC 1'.

    IF sy-subrc = 0.
      v_res = 1.
      w_fdpos = syst-fdpos.
      w_fdpos = w_fdpos + 6.
      str = str - w_fdpos.
      name11 = name1+w_fdpos(str).

      SEARCH name11 FOR 'TURC 1'.

      IF sy-subrc = 0.
        CLEAR w_fdpos.
        w_fdpos = sy-fdpos.
        w_fdpos = w_fdpos + 6.
        ch = name11+w_fdpos(1).

        CONCATENATE '1' ch INTO v_res.

      ENDIF.
    ENDIF.
  ENDIF.
ENDIF.

FIND 'T2' IN name1.

IF sy-subrc = 0.
  v_res = 1.
  FIND 'TURC2' IN name1.

  IF sy-subrc = 0.
    v_res = 1.
    SEARCH name1 FOR 'TURC 2'.

    IF sy-subrc = 0.
      v_res = 1.
      w_fdpos = syst-fdpos.
      w_fdpos = w_fdpos + 6.
      str = str - w_fdpos.
      name11 = name1+w_fdpos(str).

      SEARCH name11 FOR 'TURC 2'.

      IF sy-subrc = 0.
        CLEAR w_fdpos.
        w_fdpos = sy-fdpos.
        w_fdpos = w_fdpos + 6.
        ch = name11+w_fdpos(1).

        CONCATENATE '1' ch INTO v_res.

      ENDIF.
    ENDIF.
  ENDIF.
ENDIF.

FIND 'T3' IN name1.

IF sy-subrc = 0.
  v_res = 1.
  FIND 'TURC3' IN name1.

  IF sy-subrc = 0.
    v_res = 1.
    SEARCH name1 FOR 'TURC 3'.

    IF sy-subrc = 0.
      v_res = 1.
      w_fdpos = syst-fdpos.
      w_fdpos = w_fdpos + 6.
      str = str - w_fdpos.
      name11 = name1+w_fdpos(str).

      SEARCH name11 FOR 'TURC 3'.

      IF sy-subrc = 0.
        CLEAR w_fdpos.
        w_fdpos = sy-fdpos.
        w_fdpos = w_fdpos + 6.
        ch = name11+w_fdpos(1).

        CONCATENATE '1' ch INTO v_res.

      ENDIF.
    ENDIF.
  ENDIF.
ENDIF.

FIND 'T4' IN name1.

IF sy-subrc = 0.
  v_res = 1.
  FIND 'TURC4' IN name1.

  IF sy-subrc = 0.
    v_res = 1.
    SEARCH name1 FOR 'TURC 4'.

    IF sy-subrc = 0.
      v_res = 1.

      w_fdpos = syst-fdpos.
      w_fdpos = w_fdpos + 6.
      str = str - w_fdpos.
      name11 = name1+w_fdpos(str).

      SEARCH name11 FOR 'TURC 4'.

      IF sy-subrc = 0.
        CLEAR w_fdpos.
        w_fdpos = sy-fdpos.
        w_fdpos = w_fdpos + 6.
        ch = name11+w_fdpos(1).

        CONCATENATE '1' ch INTO v_res.

      ENDIF.
    ENDIF.
  ENDIF.
ENDIF.

Regards

Bala Krishna