cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding Autogeneration of Business Partner Code.

Former Member
0 Kudos

Dear All,

I have a unique requirement. My client wants autogeneration of Business Partner Code in the Business Partner Master.

Please guide me in regard to this.

Regards

Hitesh Parsawala

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member204969
Active Contributor
0 Kudos

Generating business partner code try this code. It generates 6 digit codes, for more you can modify it accordingly.

Select $[OCRD.CardType] 
+isnull(right(str(max(substring(c.CardCode,2,10))+1000000001),5),'00001') 
  From OCRD c 
Where c.CardCode like $[OCRD.CardType]+'[0-9][0-9][0-9][0-9][0-9]'

Former Member
0 Kudos

We normally have customer code generated as 'C00001' then 'C00002' etc and Supplier or vendors as 'S00001' and 'S00002' etc. This requires the FMS on the BP Code to be a little more complicated but not over the top.

DECLARE @MAXC as integer

SET @MAXC=isnull((SELECT CAST(MAX(RIGHT(OCRD.CardCode,5))+1 AS INTEGER)

FROM OCRD

WHERE OCRD.CardType<>'S' AND Len(OCRD.CardCode)=6 AND OCRD.CardCode like 'C%'),1)

DECLARE @MAXS as integer

SET @MAXS=isnull((SELECT CAST(MAX(RIGHT(OCRD.CardCode,5))+1 AS INTEGER)

FROM OCRD

WHERE OCRD.CardType='S' AND Len(OCRD.CardCode)=6 AND OCRD.CardCode like 'S%'),1)

--This will give you the next number then

SELECT CASE

WHEN $[OCRD.CardType]='C' THEN (SELECT DISTINCT CASE

WHEN LEN(@MAXC)=5 THEN (SELECT 'C' + CAST(@MAXC AS varchar) )

WHEN LEN(@MAXC)=4 THEN (SELECT 'C' + '0' + CAST(@MAXC AS varchar))

WHEN LEN(@MAXC)=3 THEN (SELECT 'C' + '00' + CAST(@MAXC AS varchar))

WHEN LEN(@MAXC)=2 THEN (SELECT 'C' + '000' + CAST(@MAXC AS varchar))

WHEN LEN(@MAXC)=1 THEN (SELECT 'C' + '0000' + CAST(@MAXC AS varchar))

END FROM OCRD )

WHEN $[OCRD.CardType]='L' THEN (SELECT DISTINCT CASE

WHEN LEN(@MAXC)=5 THEN (SELECT 'C' + CAST(@MAXC AS varchar) )

WHEN LEN(@MAXC)=4 THEN (SELECT 'C' + '0' + CAST(@MAXC AS varchar))

WHEN LEN(@MAXC)=3 THEN (SELECT 'C' + '00' + CAST(@MAXC AS varchar))

WHEN LEN(@MAXC)=2 THEN (SELECT 'C' + '000' + CAST(@MAXC AS varchar))

WHEN LEN(@MAXC)=1 THEN (SELECT 'C' + '0000' + CAST(@MAXC AS varchar))

END FROM OCRD )

WHEN $[OCRD.CardType]='S' THEN (SELECT DISTINCT CASE

WHEN LEN(@MAXC)=5 THEN (SELECT 'S' + CAST(@MAXS AS varchar) )

WHEN LEN(@MAXC)=4 THEN (SELECT 'S' + '0' + CAST(@MAXS AS varchar))

WHEN LEN(@MAXC)=3 THEN (SELECT 'S' + '00' + CAST(@MAXS AS varchar))

WHEN LEN(@MAXC)=2 THEN (SELECT 'S' + '000' + CAST(@MAXS AS varchar))

WHEN LEN(@MAXC)=1 THEN (SELECT 'S' + '0000' + CAST(@MAXS AS varchar))

END FROM OCRD)

END

Try Shift-F2 on the BP code with this FMS

former_member184708
Participant
0 Kudos

Hi there

We have a very small Add On Module that we developed which automatically generates the next Supplier, Customer or Lead Code when the "Add" button is hit. You can configure your codes to your requirements and the Add On will allow for this with good flexibility

Its nice and concise and easy.

Rgds

Marilyn

Former Member
0 Kudos

I have attempted to make this work in every mode I could think of is there more detailed information on how I would make the auto-increment work>

I am currently on SAP B1 2005 A SP01 PL 29

DECLARE @MAXC as integer

SET @MAXC=isnull((SELECT CAST(MAX(RIGHT(CardCode,5))+1 AS INTEGER)

FROM OCRD

WHERE CardType <> 'S' AND Len(CardCode) = 6 AND CardCode like 'C%' or CardCode like 'L%'),1)

DECLARE @MAXS as integer

SET @MAXS=isnull((SELECT CAST(MAX(RIGHT(CardCode,5))+1 AS INTEGER)

FROM OCRD

WHERE CardType = 'S' AND Len(CardCode) = 6 AND CardCode like 'S%'),1)

--This will give you the next number then

SELECT CardType = CASE

WHEN 'C' THEN (SELECT DISTINCT CASE

WHEN LEN(@MAXC)=5 THEN (SELECT 'C' + CAST(@MAXC AS varchar))

WHEN LEN(@MAXC)=4 THEN (SELECT 'C' + '0' + CAST(@MAXC AS varchar))

WHEN LEN(@MAXC)=3 THEN (SELECT 'C' + '00' + CAST(@MAXC AS varchar))

WHEN LEN(@MAXC)=2 THEN (SELECT 'C' + '000' + CAST(@MAXC AS varchar))

WHEN LEN(@MAXC)=1 THEN (SELECT 'C' + '0000' + CAST(@MAXC AS varchar))

END FROM OCRD)

WHEN 'L' THEN (SELECT DISTINCT CASE

WHEN LEN(@MAXC)=5 THEN (SELECT 'L' + CAST(@MAXC AS varchar))

WHEN LEN(@MAXC)=4 THEN (SELECT 'L' + '0' + CAST(@MAXC AS varchar))

WHEN LEN(@MAXC)=3 THEN (SELECT 'L' + '00' + CAST(@MAXC AS varchar))

WHEN LEN(@MAXC)=2 THEN (SELECT 'L' + '000' + CAST(@MAXC AS varchar))

WHEN LEN(@MAXC)=1 THEN (SELECT 'L' + '0000' + CAST(@MAXC AS varchar))

END FROM OCRD)

WHEN 'S' THEN (SELECT DISTINCT CASE

WHEN LEN(@MAXC)=5 THEN (SELECT 'V' + CAST(@MAXS AS varchar))

WHEN LEN(@MAXC)=4 THEN (SELECT 'V' + '0' + CAST(@MAXS AS varchar))

WHEN LEN(@MAXC)=3 THEN (SELECT 'V' + '00' + CAST(@MAXS AS varchar))

WHEN LEN(@MAXC)=2 THEN (SELECT 'V' + '000' + CAST(@MAXS AS varchar))

WHEN LEN(@MAXC)=1 THEN (SELECT 'V' + '0000' + CAST(@MAXS AS varchar))

END FROM OCRD)

END

I receive SAP error (8180)

Hope someone can help... Thanks in advance

Edited by: Craig Spehar on Mar 6, 2009 2:47 PM

Former Member
0 Kudos

the B1Up has a function for this along with a lot of other little gems

Former Member
0 Kudos

Hi Hitesh,

you could solve your issue by using a FMS. Create a query like



SELECT MAX(T1.CardCode)+1 FROM OCRD T1

Insert this query in your CardCode field.

Otherwise you find here a description by SAP.

Regards Steffen