Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

ItemCode autogeneration

Hey All,

I was wondering if anyone has some working code or ideas to auto generate an item master code record. I have to do this for a client and I am not really sure how this might work.

Former Member
Former Member replied

Curtis,

I create a sql table as follows:

CREATE TABLE [dbo].[AC_TBLIDX](

[TblName] [varchar](10) COLLATE SQL_Latin1_General_CP850_CI_AS NOT NULL,

[Idx] [int] NOT NULL

) ON [PRIMARY]

Then I use a stored procedure to populate the value the first time, increment each successive time and return the updated.

I call this stored procedure thru code so that I can handle any user errors.

In my opinion this works better than a max function on a field within the oitm table.

You can also add extra fields that store a prefix or suffix.

snippet from stored procedure

if exists(select Idx from [dbo].[AC_TBLIDX] where TblName = @Tbl)

begin

update [dbo].[AC_TBLIDX]

set Idx = Idx + 1

where TblName = @Tbl

end

else

begin

insert into [dbo].[AC_TBLIDX] (TblName, Idx)

values (@Tbl, 0)

end

set @return_value = (select Idx from [dbo].[AC_TBLIDX] where TblName = @Tbl)

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question