Skip to Content

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

Formatted Search to Generate Consecutive Number of Batch

Hello !

I'm trying to create a query to use it in a Formatted Search to generate a consecutive number of Batch.

In the Good Receipt when you define the Batches - Setup in the section Created Batches i want to generate a consecutive number with a formatted search.

This is my query:

/* Start Query */

declare @temp as varchar

declare @pad as varchar

declare @batchnum as varchar

set @batchnum=(select top 1 batchnum from oibt order by itemcode desc)

set @temp=(SELECT

CASE

WHEN (@batchnum LIKE cast($[$3.0.0] as varchar)) THEN (@batchnum + 1)

WHEN (@batchnum NOT LIKE cast($[$3.0.0] as varchar)) THEN ($[$3.0.0] + 1)

END

)

set @pad=(SELECT len(@temp))

SELECT CASE @pad

when '1' then cast('00000' + @temp as varchar)

when '2' then cast('0000' + @temp as varchar)

when '3' then cast('000' + @temp as varchar)

when '4' then cast('00' + @temp as varchar)

when '5' then cast('0' + @temp as varchar)

else

@temp

end

/* End Query */

In this query i try to compare the value of field BatchNum in the Table OIBT, this is for know the last value in the tables if exists, then because in the Batch: Setup windows in SAP you can Add many numbers of Batch that you can, this depends of the items quantity.

So this is my real problem because i need to know the last value inserted in the table and if the user is adding more than one Batch i need to know the number that user is writing.

In this query i trying to use the fiel batchnum and the variable $[$3.0.0] but it doesn't work, i'm not sure if the variable $[$3.0.0] is taking the value that the user typing in the window Batch:Setup

I hope you can help please.

I want to know if exist a way to create this consecutive number in a formatted search or this is a develop that i have to do.

Thanks in advance

Best Regards.

Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question