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: 

Matching a string of text with another

Former Member
0 Kudos

Hello Gurus

I have what is hopefully a fun problem for someone to help me solve. I was unable to find the relevant commands in the ABAP dictionary and am not the best at ABAP anyway!

We have field with properties:

/BIC/OZBARCODE

Data Type NUMC

Length 20

In reality the data in this field should be 13 characters long and we are not interested in strings that are not this length.

From the remaining data we want to compare characters 8-12 to another text string, lets call it ABCDE. We are then only interested in those that match.

eg

if there were three values for /BIC/OZBARCODE:

ABCDE

ABCDEXXXXXXXX

XXXXXXXABCDEX

ABCDE - would be deleted as of the wrong length

ABCDEXXXXXXXX - would be deleted as the relevant string does not fall in the right place

XXXXXXXABCDEX - would be kept

......

No need to give me the whole code, I just need the bits that will say:

If length of /BIC/OZBARCODE = 13

and

if characters 8-12 of /BIC/OZBARCODE = ABCDE

Many thanks in advance for any help.

Tom

1 ACCEPTED SOLUTION

nirajgadre
Active Contributor
0 Kudos

Hi,

try this..

1 .check the length of the field /BIC/OZBARCODE using command STRLEN( /BIC/OZBARCODE ) and pass to the variable.

2. check the value of variable is EQ 13 and also check /BIC/OZBARCODE+7(5) = 'ABCDE'.

4 REPLIES 4

nirajgadre
Active Contributor
0 Kudos

Hi,

try this..

1 .check the length of the field /BIC/OZBARCODE using command STRLEN( /BIC/OZBARCODE ) and pass to the variable.

2. check the value of variable is EQ 13 and also check /BIC/OZBARCODE+7(5) = 'ABCDE'.

romanweise
Active Contributor
0 Kudos

Hello Tom,

you basically will need the strlen( ) operator for getting the length of the string and an offset operation to compare the substring.


  DATA: lv_string(20) TYPE c,
        ln_length     TYPE i.

lv_string = 'XXXXXXXABCDEX'.

ln_length = strlen( lv_string ).

IF ln_length NE 13 or
   lv_string+7(5) NE 'ABCDE'.
  " throw the value away
ELSE.
  " keep the value
ENDIF:

The trouble you will face in your setting is that the field is no string but a numeric character. These fields should be right aligned and cannot contain spaces or letters so the length should always be 20. Furthermore they are right alligned and filled with zeros so if zeros are allowed characters from the business view you might not be able to get the length of the string for sure.

Kind Regards

Roman

former_member182670
Contributor
0 Kudos

I'd go with [regex|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/03a52be5-0901-0010-9da4-e9d5f8c5ce1c?quicklink=index&overridelayout=true]

FIND REGEX '^.{7,7}ABCDE.$' IN lv_string

.

0 Kudos

That's great, cheers all.

It was the +7(5) bit that was the missing link for me.

Thanks again.

Tom