Search code examples
crystal-reports

Getting numbers separate from letters from a field in Crystal Reports SAP when the format changes


I'm sorry if this has already been solved, I cant seem to find anything for my specific issue.

We have job numbers that use the following formats: 011111, 11111A, and 11A111. For all of these, I need to export to a new field that just reads 11111. I know I can use right({table.job},5) for the first, left({table.job},5) for the second, or even val({table.job}) but I can not find anything that works to get just the numbers out of the last format.

I have tried using val({table.job}) but it only gives me the first set before the letter. I have tried using the join function and using left 2 + right 3, but I'm still new to this and I'm not certain that I have been using the correct syntax.

I also tried using an array to find the third character to see if it was a specific letter, but it is not accepting the code, and I scrapped it.

When I typed all of it out, I kept getting the error "The ) is missing" but no words were highlighted and I have double checked the opening and closing parenthesis. I know it might be something simple, but I am stumped. Any ideas?


Solution

  • Here's one possible solution:

    local stringvar JobN := "011A111";
    local stringvar result := "";
    local numbervar i;
    
    For i := 1 to Len(JobN) do
    (IF isnumeric(JobN[i]) Then result := result + JobN[i]) ;
    
    ToText(Val(result),0,"");