GetBatchNumber

Define next Batch Number

Example: Manual receipt, Goods Receipt Po and so on

 

Define new Batch Number in variable e_DistNumber. If this is not defined, the system use the settings in congifuration wizzard

 

Variable

Read

Write

Description

e_ItemCode

x


Calculation methode Id

e_DistNumber

 

x

Define new Batch Number

if the batch number not defined, the system use standard counting

 

 

beasscript-logo-small

 

Example 1

// DistNumber = today (yyyy/mm/dd) + "-" + new counter for every day
// Example: 20200501-0001, 20200501-0002, 20200501-0003 ...
function GetBatchNumber
select coalesce(max(substring("DistNumber",10,4)),0) into myCounter from "OBTN" where left("DistNumber",9) = '<today,yyyymmdd>-'
setvar=myCounter=%numadd(myCounter,1)
setvar=myCounter=000<myCounter,#0>
setvar=e_DistNumber=<today,yyyymmdd>-<myCounter,right 4>
end function 

 

Example 2

// Use B05C as Prefix + own Counter with 5 digits
// All items with MaterialGroup = "ZPT" has own counter
function GetBatchNumber
// define instance from beas Service Layer
instance bsl boy_b
// Read Material Group from item
boy_b.get=Item(<e_itemcode,bsl>)/MaterialGroupId/$value
// if Material Group is ZPT then read Counter G otherwise C
if <boy_b.ret_value> = "ZPT" then
  setvar=boy_counter=G
else
  setvar=boy_counter=C
end if
// new serial Number is B05C + Counter with 5 digits
setvar=boy_counter=00000<system.counter.boy_counter_[boy_counter]>
setvar=e_DistNumber=B05C<boy_counter,right 5>
return success
end function

 

Example 3:

if material group = 20, then ask for the serial number manually

function GetSerialNumber
instance bsl boy_b
// Read Material Group from item
boy_b.get=Item(<e_itemcode,bsl>)/MaterialGroupId/$value
// if Material Group is ZPT then read Counter G otherwise C
if <boy_b.ret_value> = "20" then
  input=SerialNumber=e_DistNumber=<e_DistNumber>
  return true
end if
 
// for all other use a item based counter
select coalesce(max(substring("DistNumber",10,4)),0) into myCounter from "OBTN" where left("DistNumber",9) = '<today,yyyymmdd>-'
setvar=myCounter=%numadd(myCounter,1)
setvar=myCounter=000<myCounter,#0>
setvar=e_DistNumber=<today,yyyymmdd>-<myCounter,right 4>
end function

 

Example 4

In this example we create a serial number per work order with follow structure:

work order (8 letters) + "-" + counter per work order (4 letters)

For this we need an counter per work order. In this example we're using UDF4 from the work order

 

// ******* Event GetSerialNumber ********
// Created 2021/08/24 by Martin Heigl
function GetSerialNumber 
// Get UDF4 from work order
instance bsl b
b.get=Workorder(<e_DocEntry>)/UDF4/$value
setvar=ls_counter=%numadd(b.ret_value,1)
// save new counter back (using SQL, because BSL current not available
sql=update "BEAS_FTHAUPT" set "UDF4"='<ls_counter,#0>'
// create new serial number
setvar=e_DocEntry=000000<e_DocEntry>
setvar=e_Counter=000000<ls_counter,#0>
setvar=e_DistNumber=<e_DocEntry,right 8>-<e_Counter,right 4>
end function

 

help-hinweis Example Notes