SBO存储过程――SBO_SP_TransactionNotification流程控制

在我开发的项目过程中,许多客户和顾问向我提出了许许多多的功能需求。但我在分析研究了这些需求后发现许多的需求我们顾问均可以解决。尤其是流程控制方面的需求。我把这方面的一些粗浅看法整理出来,供大家分享。
一、各种顾问在项目实施过程中出现过的看是需要研发解决的需求
1、如何控制不同的销售人员只能修改自己管理的客户的数据?
2、如何控制不同的销售人员只能录入修改自己的销售订单?
3、如何给sbo的任何单据(我这里强调任何单据,包括销售订单,销售发货单、发票、采购订单、采购收货单、采购发票、财务凭证、库存转储等等)加上自己的逻辑验证控制(例如不填某一个字段不用许sbo添加到数据库)
4、如何在各种单据或主数据添加修改过程中加上自己想要的功能?

以前这些需求一般都是顾问要求研发人员来参与协同工作来解决。我们现在要讨论的就是这些问题统统不再研发,顾问可轻松搞定。当然这要求顾问要具备一些基础知识。
二、顾问要解决这些问题要具备的基础知识
1、sql的知识。我一直认为,一个ERP软件顾问高手对SQL必须的基本素质。他可以让你随心所欲从这个充满金矿的ERP数据海洋里找到你想要的金子。我认为有志于成为ERP软件顾问高手的朋友在此付出一点时间和金钱是绝对值得的!它是打开我们理解ERP软件内核的金钥匙,也是会让我们终生受益的一种技能。无论我们从事的是哪一个ERP系统的顾问工作!
2、SBO对象的概念与规则。
当然,我觉得您在读这篇杂论前要有坚持读下去的意志。尽管这好像是有点枯燥乏味。但这点乏味的知识会给您带来无穷的想象力!
SBO的DI对象,针对顾问通俗点简单点说就像物料主数据、客户主数据、销售订单、采购订单等等这些SBO里的东东。他们在SBO系统里都有一个编号,就像我们都有一个名字一样用于唯一识别。例如物料主数据的编号是:4。具体清单如下:
Member Value
oChartOfAccounts 1
oBusinessPartners 2
oBanks 3
oItems 4
oVatGroups 5
oPriceLists 6
oSpecialPrices 7
oItemProperties 8
oUsers 12
oInvoices 13
oCreditNotes 14
oDeliveryNotes 15
oReturns 16
oOrders 17
oPurchaseInvoices 18
oPurchaseCreditNotes 19
oPurchaseDeliveryNotes 20
oPurchaseReturns 21
oPurchaseOrders 22
oQuotations 23
oIncomingPayments 24
oJournalVouchers 28
oJournalEntries 30
oStockTakings 31
oContacts 33
oCreditCards 36
oCurrencyCodes 37
oPaymentTermsTypes 40
oBankPages 42
oManufacturers 43
oVendorPayments 46
oLandedCostsCodes 48
oShippingTypes 49
oLengthMeasures 50
oWeightMeasures 51
oItemGroups 52
oSalesPersons 53
oCustomsGroups 56
oChecksforPayment 57
oInventoryGenEntry 59
oInventoryGenExit 60
oWarehouses 64
oCommissionGroups 65
oProductTrees 66
oStockTransfer 67
oWorkOrders 68
oCreditPaymentMethods 70
oCreditCardPayments 71
oAlternateCatNum 73
oBudget 77
oBudgetDistribution 78
oMessages 81
oBudgetScenarios 91
oSalesOpportunities 97
oUserDefaultGroups 93
oSalesStages 101
oActivityTypes 103
oActivityLocations 104
oDrafts 112
oDeductionTaxHierarchies 116
oDeductionTaxGroups 117
oAdditionalExpenses 125
oSalesTaxAuthorities 126
oSalesTaxAuthoritiesTypes 127
oSalesTaxCodes 128
oQueryCategories 134
oFactoringIndicators 138
oPaymentsDrafts 140
oAccountSegmentations 142
oAccountSegmentationCategories 143
oWarehouseLocations 144
oForms1099 145
oInventoryCycles 146
oWizardPaymentMethods 147
oBPPriorities 150
oDunningLetters 151
oUserFields 152
oUserTables 153
oPickLists 156
oPaymentRunExport 158
oUserQueries 160
oMaterialRevaluation 162
oCorrectionPurchaseInvoice 163
oCorrectionPurchaseInvoiceReversal 164
oCorrectionInvoice 165
oCorrectionInvoiceReversal 166
oContractTemplates 170
oEmployeesInfo 171
oCustomerEquipmentCards 176
oWithholdingTaxCodes 178
oBillOfExchangeTransactions 182
oKnowledgeBaseSolutions 189
oServiceContracts 190
oServiceCalls 191
oUserKeys 193
oQueue 194
oSalesForecast 198
oTerritories 200
oIndustries 201
oProductionOrders 202
oPackagesTypes 205
oUserObjectsMD 206
oTeams 211
oRelationships 212
oUserPermissionTree 214
oActivityStatus 217
oChooseFromList 218
oFormattedSearches 219
oAttachments2 221
oUserLanguages 223
oMultiLanguageTranslations 224
oDynamicSystemStrings 229
oHouseBankAccounts 231
oBusinessPlaces 247
oLocalEra 250
oSalesTaxInvoice 280
oPurchaseTaxInvoice 281
BoRecordset 300
BoBridge 305
oNotaFiscalUsage 260
oNotaFiscalCFOP 258
oNotaFiscalCST 259
oClosingDateProcedure 261
oBusinessPartnerGroups 10
oBPFiscalRegistryID 278

三、关键的存储过程语法:
大家打开sqlserver的查询分析器,打开SBO的一个公司数据库,查找一个存储过程:SBO_SP_TransactionNotification
它就是让我们得以控制SBO的魅力所在!
ALTER proc SBO_SP_TransactionNotification

@object_type nvarchar(25), -- SBO Object Type
@transaction_type nchar(1), -- [A]dd, [U]pdate, [D]elete, [C]ancel, C[L]ose
@num_of_cols_in_key int,
@list_of_key_cols_tab_del nvarchar(255),
@list_of_cols_val_tab_del nvarchar(255)

AS

begin

-- Return values
declare @error int -- Result (0 for no error)
declare @error_message nvarchar (200) -- Error string to be displayed
select @error = 0
select @error_message = N'Ok'

--------------------------------------------------------------------------------------------------------------------------------

-- ADD YOUR CODE HERE

--------------------------------------------------------------------------------------------------------------------------------

-- Select the return values
select @error, @error_message

end

这个存储过程的作用就是任何一个SBO对象操作完程前都会调用它一次。以便我们加入我们的逻辑控制来实现一些客户的特殊要求。
我们来看一下他的参数:
第一个参数:@object_type 这就是我们上边讨论的SBO对象的编号。每一个对象执行Add, [U]pdate, [D]elete, [C]ancel, C[L]ose操作时都会把操作的对象编号在这个参数中传入,我们只要判断该参数即可实现对不同的对象的不同的控制。我后边会给大家提供一些练习。
第二个参数:@transaction_type nchar(1), -- [A]dd, [U]pdate, [D]elete, [C]ancel, C[L]ose
当在SBO系统中执行了添加操作,例如添加了一个物料主数据,@object_type的值就等于4,@transaction_type的值就等于'A' 。
第三个参数:@num_of_cols_in_key,对象关键字段的数目。例如物料主数据的关键字段是物料编码,他只有一个关键字,所以该值等于1。
第四个参数:@list_of_key_cols_tab_del 代表该对象的关键字段的字段名字,例如物料主数据就是Itemcode,单据就是Docentry.
第五个参数:@list_of_key_cols_tab_del 代表关键字段的值。这时已非常重要的参数。我再次说明一点,经过我测试,SBO的对象再添加修改时会现在数据库里操作完成,然后调用该存储过程。所以我们就靠这个字段来作为验证控制我们的逻辑的入口之一了。
在以上介绍的五个参数之中,最重要的就是@object_type,@transaction_type,@list_of_cols_val_tab_del这三个参数。大家一定要明白他们的含义!

内部的两个重要控制参数:
@error ,好了,揭示了这么多,就数他最重要了。计算机世界的0和1就让他体现的淋漓尽致了。当我么给它赋值为零的时候,SBO的流程继续运行。一旦我们给他赋值为1,好了,效果出现了,你在sbo中操作的对象就再也不能完成它的操作了!牛!就是这个牛的地方可以让我们收拾SBO任何的对象,可以按客户的心花让SBO尽情的怒放。
当然我们经过我们自己的逻辑,把 @error =1,不然SBO按自己的逻辑继续下去了,总也得在SBO中给出个提示把,就像B1的状态栏的提示一样,那您就要动用@error_message这个参数了。200个字符尽情地表述您的一肚子逻辑的解释吧,幽默也好,冷冰冰也罢!

好了我们解释过了这个存储过程的架构,那我接下来看看它的威力。看看SBO的牛皮吹得力量能不能把鸡蛋吹成气球!

四、几个小例子

第一个例子:我们就测试一下物料主数据,并看一下这几个参数。
在查询分析器打开该存储过程,让其处于编辑状态,要仔细找,SBO的存储过程密密麻麻一大堆,看起来确实头疼,对一个顾问来说。但研发人员也许不这样认为。研发人员对代码的好奇心永远是无止境的。我就曾经把SBO的存储过程一个接一个的读了个遍。管他加密的不加密的。读了会有收获的!呵呵。也让咱看看SAP的牛人们使用什么样的代码来操作这个世界的企业用户的数据的!

ALTER proc SBO_SP_TransactionNotification

@object_type nvarchar(25), -- SBO Object Type
@transaction_type nchar(1), -- [A]dd, [U]pdate, [D]elete, [C]ancel, C[L]ose
@num_of_cols_in_key int,
@list_of_key_cols_tab_del nvarchar(255),
@list_of_cols_val_tab_del nvarchar(255)

AS

begin

-- Return values
declare @error int -- Result (0 for no error)
declare @error_message nvarchar (200) -- Error string to be displayed
declare @aaa nvarchar(100) --WLJ test

select @error = 0
select @error_message = N'Ok'

--------------------------------------------------------------------------------------------------------------------------------

-- ADD YOUR CODE HERE
if @object_type='4'--items
begin
if @transaction_type='A'
begin
select @aaa =itemname from oitm where itemcode=@list_of_cols_val_tab_del
if @aaa='Test'
begin
set @error=1
set @error_message='物料主数据描述不能等于Test!'+@aaa +'--'+ @list_of_key_cols_tab_del +'--'+@list_of_cols_val_tab_del +'--'+cast(@num_of_cols_in_key as nvarchar(20))
end
end
else if @transaction_type='D'
begin
set @error=1
set @error_message='不允许小孩子瞎删除!' + @list_of_key_cols_tab_del +'--'+@list_of_cols_val_tab_del +'--'+cast(@num_of_cols_in_key as nvarchar(20))
end
end

--------------------------------------------------------------------------------------------------------------------------------

-- Select the return values
select @error, @error_message

end

在这个例子里,我们首先对添加的物料主数据判断其描述是否等于“Test”如果是,那就不让它添加,对于物料主数据则不允许删除。大家注意分析各参数的内容。我在这个例子里把各个参数的值也传递到SBO的消息提示里边,这样大家学习分析方便!


第二个例子:上边的例子我们测试验证了主数据,我们下边来看一下单据。
ALTER proc SBO_SP_TransactionNotification

@object_type nvarchar(25), -- SBO Object Type
@transaction_type nchar(1), -- [A]dd, [U]pdate, [D]elete, [C]ancel, C[L]ose
@num_of_cols_in_key int,
@list_of_key_cols_tab_del nvarchar(255),
@list_of_cols_val_tab_del nvarchar(255)

AS

begin

-- Return values
declare @error int -- Result (0 for no error)
declare @error_message nvarchar (200) -- Error string to be displayed
declare @aaa nvarchar(100) --WLJ test

select @error = 0
select @error_message = N'Ok'

--------------------------------------------------------------------------------------------------------------------------------

-- ADD YOUR CODE HERE

if @object_type='17'--salseorder
begin
if @transaction_type='A'
begin
set @error=1
set @error_message='添加出错提示!' + @list_of_key_cols_tab_del +'--'+@list_of_cols_val_tab_del +'--'+cast(@num_of_cols_in_key as nvarchar(20))
end
else if @transaction_type='U'
begin
set @error=1
set @error_message='更新出错提示!' + @list_of_key_cols_tab_del +'--'+@list_of_cols_val_tab_del +'--'+cast(@num_of_cols_in_key as nvarchar(20))
end
end


--------------------------------------------------------------------------------------------------------------------------------

-- Select the return values
select @error, @error_message

end
当然这个例子我写得简单,只是测试在销售订单添加或更新的时候强不允许添加或更新。大家可以根据自己的逻辑来实际处理。我这里只是给大家提供一个思路。

整合,当然我们实际工作中不可能只对一个对象操作,有可能对很对对象同时验证,那就把上边的合起来即可,即可以对物料主数据控制也可以对销售订单控制。我给大家写了个小架构供大家参考使用。
ALTER proc SBO_SP_TransactionNotification

@object_type nvarchar(25), -- SBO Object Type
@transaction_type nchar(1), -- [A]dd, [U]pdate, [D]elete, [C]ancel, C[L]ose
@num_of_cols_in_key int,
@list_of_key_cols_tab_del nvarchar(255),
@list_of_cols_val_tab_del nvarchar(255)

AS

begin

-- Return values
declare @error int -- Result (0 for no error)
declare @error_message nvarchar (200) -- Error string to be displayed
select @error = 0
select @error_message = N'Ok'

declare @aaa nvarchar(100)

if @object_type='2' --BusinessPartners
begin
if @transaction_type='A'
begin
set @error=1
set @error_message='添加出错提示!' + @list_of_key_cols_tab_del +'--'+@list_of_cols_val_tab_del +'--'+cast(@num_of_cols_in_key as nvarchar(20))
end
end
else if @object_type='4'--items
begin
if @transaction_type='A'
begin
select @aaa =itemname from oitm where itemcode=@list_of_cols_val_tab_del
if @aaa='Test'
begin
set @error=1
set @error_message='添加出错提示!'+@aaa +'--'+ @list_of_key_cols_tab_del +'--'+@list_of_cols_val_tab_del +'--'+cast(@num_of_cols_in_key as nvarchar(20))
end
end
else if @transaction_type='D'
begin
set @error=1
set @error_message='更新出错提示!' + @list_of_key_cols_tab_del +'--'+@list_of_cols_val_tab_del +'--'+cast(@num_of_cols_in_key as nvarchar(20))
end
end
else if @object_type='17'--salseorder
begin
if @transaction_type='A'
begin
set @error=1
set @error_message='添加出错提示!' + @list_of_key_cols_tab_del +'--'+@list_of_cols_val_tab_del +'--'+cast(@num_of_cols_in_key as nvarchar(20))
end
else if @transaction_type='U'
begin
set @error=1
set @error_message='更新出错提示!' + @list_of_key_cols_tab_del +'--'+@list_of_cols_val_tab_del +'--'+cast(@num_of_cols_in_key as nvarchar(20))
end
--else if @object_type='17'--salseorder
--begin
--end
--..........
--.........
end


-- Select the return values
select @error, @error_message

end

五、结束语。其实这个功能也是我们业界的一个资深顾问给我的提示,因为在我们这个行业中有很多善于研究的顾问高手在这个市场里通过它淋漓尽致的在SBO里使展着无穷无尽的创意!在他们眼力,没有不可能的事,只有不可能的人!每当面对这句话的时候,我对自己以前顾问提出的需求做出不可能的回答而感到汗颜与惭愧!

你可能感兴趣的:(职场,休闲,Sbo,SBO存储过程,sbo软件)