Extract a series of numbers from a string


(Chris Simpson) #1

Hi there all,

So a little ABL help needed. I have a character field where I need to extract a set of numbers from. Starting length is unknown but preceding character is ALWAYS a hyphen and the set of numbers are ALWAYS followed by a comma. I wanted to try substring but I don’t know the start length. I thought of index but I do not know how to write what I need.

Thanks in advance,
Chris


(Bruce Ordway) #2

I wonder if you can use Num-entries?
Maybe if you use you original string in a calc field 1st … to get it “prepped” ?

image


(Mark Damen) #3

Not so familiar with ABL, but this should be common to C#, ABL, Excel etc

If you know the length of the -xxxx bit is fixed at say 5 characters, you could then do:

Substring(field, length(field) - 5, 5)


(Simon Hall) #4

Lots of examples in the ABL reference, apologies if I am telling you to suck eggs.

https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/abl-syntax-reference.html

I don’t have an ABL evironment to play with, but if I’m understanding your question possibly this:

DEFINE VARIABLE StrVar AS CHARACTER NO-UNDO.
ASSIGN StrVar = “asm-123456,lkjah”.

SUBSTRING(StrVar ,INDEX(StrVar ,"-"),(INDEX(StrVar ,"-")-INDEX(StrVar ,","))).


(Chris Simpson) #5

I’m trying this but Epicor isn’t liking something in the substring… Unfortunately it doesn’t tell just what it doesn’t like.


(Calvin Krusen) #6

I hope you’re not copying and pasting Simon’s code - because some of the quotes are fancy open and close quotes

image


(Simon Hall) #7

Darn fancy quotes. Ooops! Thanks @ckrusen


(Chris Simpson) #8

No, I was not. Luckily I noticed them ahead of time…


(Calvin Krusen) #9

Did you try making individual variables for each of the parameters of SUBSTRING?


(Chris Simpson) #10

Calvin,

This is what I am trying. sourceQuoteLines is a character parameter the series of characters are written to when copying Quote lines in Epicor. I am firing a BPM upon the Quote.CopyLines business object.

srcQuoteNum = SUBSTRING(sourceQuoteLines, INDEX(sourceQuoteLines, “-”), (INDEX(sourceQuoteLines, “-”)-INDEX(sourceQuoteLines, “,”)), “CHARACTER”).

Validating my code gives me the following error. Unable to understand after – “srcQuoteNum = SUBSTRING”.


(Calvin Krusen) #11

If srcQuoteNum is an integer, you’ll need to convert the result of substring (which is a string) to and int


(Chris Simpson) #12

srcQuoteNum is a character.
It just verified… I added spaces before and after the -.
(INDEX(sourceQuoteLines, “-”) - INDEX(sourceQuoteLines

Epicor is so picky.


(Chris Simpson) #13

Maybe I need a little more help here. I was a little off on what I need to parse. Here’s the contents of the sourceQuoteLines parameter that Epicor builds when copying three quote lines from another quote.

6’28635~7’28635~8’28635

image

I changed the code to this but now it errors again. Should I be using the hexidecimal equivalent instead?
srcQuoteNum = SUBSTRING(sourceQuoteLines, INDEX(sourceQuoteLines, “"), (INDEX(sourceQuoteLines, "”) - INDEX(sourceQuoteLines, “~”)), “CHARACTER”).


(Mark Wonsil) #14

Hello Chris,

Have you considered the Entry function? You pass the delimited and it parses the sting returning an array. You could then use the Entry function again to split the line from the quote.

Mark W.


(Chris Simpson) #15

Mark,

To be honest, no I’ve never used it. Do you have an example by chance? I will look it up also.

Thanks,
Chris


(Chris Simpson) #16

I tried this also but I get “Starting position for SUBSTRING, OVERLAY, etc. must be 1 or greater.” in the error log. I did confirm that is a grave accent by the way.

srcQuoteNum = SUBSTRING(sourceQuoteLines, INDEX(sourceQuoteLines, “char(60)”), (INDEX(sourceQuoteLines, “char(60)”) - INDEX(sourceQuoteLines, “char(7E)”)), “CHARACTER”).


(Mark Wonsil) #17

There are three functions that Epicor uses to parse out delimited strings:

Num-entries(list, separator)
Entry(expression, list, separator)
Lookup(expression, list, separator)

where list is your string and separator is your delimiter. Expression is either a string or integer. In your string:

str = “6’28635~7’28635~8’28635”

num-entries(str, “~”) would return 3. There are three substrings delimited by the “~”.

entry(2, str, “~”) would return “7`28635”

lookup(“8`28635”, str, “~”) would return 3, the third entry.

In this case, you would first split by "~’ and then split those by the “`” grave.

Mark W.


(Chris Simpson) #18

Very informative. Thank you


(Chris Simpson) #19

I am struggling with how to loop through the string entry results and getting each individual quote number and line number. Such as quote 28635 line 6; quote 28635 line 7; quote 28635 line 8. This is because I need to find the part number of that quote/line and then relate it to the part number line of the current quote I am copying lines into.