cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to get the position of a charcter from a string ?

Former Member
0 Kudos

Hi !

Is it possible to get the position of a charcter from a string ?

Example:

@VAR contains the following text "ABCDEFGHIJKLM"

I'am seaching for FGH, it start on pos. 6 en ends on pos 8.

How can I get these numbers 6 and 8 ?

So, I can use them in the MID(text,start,len) function.

Thanks!

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Tobias,

It is correct, wildcards DON'T work in the pattern of the REPLACE function !!!

We have tried several combinations with all kind of functions like REPLACE, TRIM etc.

It can not (yet) be done.

We have solved the problem by changing our webservice.

It now provides the data in the @Spec variable, in fixed length.

So the final expression sounds like :

TRIM(IF(BEGINS(@specification,'MOTORTYPE'),MID(@specification,10,10),IF(BEGINS(MID(@specification,100,100),'MOTORTYPE'),MID(@specification,110,10),@ENGID)))

Kind regards,

Erwin

Former Member
0 Kudos

Thanks for the answer.

Maybe a new function would be nice for the next version of VC ?

Former Member
0 Kudos

Hi,

one additional question: is it correct, that wildcards don't work in the pattern of the REPLACE function? I tried it, but with no success. It would be really helpful, if patterns would work in the same way like in the LIKE function. Or even better if they would be able to deal with regular expressions. Does anybody know if this is planned for future versions of VC?

Regards,

Tobias

Former Member
0 Kudos

Hi Sooraj,

I'll explain more in detail:

From a web-service I get a variable called @Spec.

This variable contains the following:

"MOTORTYPE[CR]D-QW1234[LF]PART[CR]1234-FRD-X[LF]"

or

"MOTORTYPE[CR]ABC[LF]PART[CR]E-435[LF]"

I need the values behind MOTORTYPE[CR] and behind PART[CR]

But you’ll see that the positions of these values are different each time.

If there is a way to get the (start) position of "MOTORTYPE[CR]" or "PART[CR]" and the (end) position of the first "[LF]" behind that,

then I could use the MID() function to get the correct values.

The values will be displayed in a table view (between other fields).

An ABAP-call/function won’t work . . . how should I invoke this within a table column/field object ? (system action ?)

Former Member
0 Kudos

Hi,

I am not able to find a direct function for your method. But there is a roundabout way.

Use REPLACE(text,pattern,repstr), to replace the string till the end of MOTORTYPE[CR] with whitespaces. (May be you can give a wildcard pattern for this). Use some logic to replace the text at then end too. (May be you can use some hidden expression box to store intermediate values)

Then Use TRIM to remove the whitespaces and use LEFT(text,len) to get the required characters..

I know its a very difficult thing to achieve. But if your requirement is urgent, just give a try.

Regards,

Sooraj

Former Member
0 Kudos

> Example:

> @VAR contains the following text "ABCDEFGHIJKLM"

> I'am seaching for FGH,

> So, I can use them in the MID(text,start,len)

> function.

Hi,

The requirement seems ambiguous

If you know the return text from MID function (ie FGH), then why you want to find its start position. . Please clarify.

If the requirement is just to find out whether the string @VAR contains the substring "FGH", you can use CONTAINS(@VAR,"FGH") or LIKE(@VAR,"FGH") if you are searching for wildcard characters.

Regards,

Sooraj

Former Member
0 Kudos

Hi Erwin,

you can find a description of the available functions under:

http://help.sap.com/saphelp_nw04s/helpdata/en/40/a228173435437394f54c56de571ca4/frameset.htm

If it is not possible you write your own ABAP RFC, this is quite easy.

Best Regards,

Marcel