Help with ABL in a BPM

I am trying to write a code for taking an number entered in a Data Form and compare it to the part table to see if the number already exists. If it does I want to add 1 to it and test it again until it gets to a part number that doesn’t exist yet, and then assign the new part number to the CallContextBOMData.Character01 field for use later. I have been reading all the documentation and examples I can find and am a bit stuck. I have never written anything like this in ABL. What I have cobbled together so far is below. Am I on the right track? I have bolded the 2 parts where I am not sure what I need to do. Any ideas, help or places to find some help are appreciated :blush:

Thanks,
Melissa

Define Variable iCount AS Integer No-Undo Initial 1.
Define Variable NewPartNumber AS Integer
Outerloop:
FOR each NEWPARTFIELD:
If ttCallContextBPMData.Character01 = Part.PartNum Then NewPartNumber = (ttCallContextBPMData.Character01+iCount)
Innerloop:
REPEAT WHILE NewPartNumber = Part.PartNum :
(Not sure what I need here to make it do this step) NewPartNumber = (NewPartNumber + 1)
(Don’t know what I need here about stopping the Repeat)
Then assign NewPartNumber = ttCallContextBPMData.Character01.
END.

If the numbers are sequential you are much better off just getting the “MAX” number and adding one to it. Or am I misunderstanding what you are trying to do?

FOR EACH Part:
         ACCUMULATE INTEGER(Part.PartNum) (MAXIMUM).
END. 
Assign ttCallContextBPMData.Character01 = ACCUM MAXIMUM INTEGER(Part.PartNum) +1.
1 Like

Thanks. I’m not sure that works because our numbers are semi-intelligent. The first 2 digits are indicative of the type of part. So they will be starting at a different part number every entry… IE 700000 (ply Kits) 500000 (core assemblies) and the check needs to start at those numbers.

Thanks
Melissa

You can add a where statement where PartNum > YourCurrentSmartNumber