0% found this document useful (0 votes)
75 views

SPparaSAPB1 SQL

This document contains SQL code blocks that validate data and set error codes and messages for different SAP B1 objects and transactions. The code blocks check for things like required fields, duplicate values, invalid status combinations, and restricted user permissions. The document also includes a table listing various SAP B1 table names, descriptions, primary keys and object types.

Uploaded by

Yen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

SPparaSAPB1 SQL

This document contains SQL code blocks that validate data and set error codes and messages for different SAP B1 objects and transactions. The code blocks check for things like required fields, duplicate values, invalid status combinations, and restricted user permissions. The document also includes a table listing various SAP B1 table names, descriptions, primary keys and object types.

Uploaded by

Yen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

SP para SAP B1-SQL

Ejecutar en una db de prueba para revisar la funcionalidad

/*
@OBJECTTYPE.- RETURNS A STRING REPRESENTING THE TYPE OF OBJECT WHICH IS A NUMERICAL
VALUE
@TRANSACTION_TYPE.-
IT MAY HAVE VALUES OF:

A (WHERE A RECORD WAS ADDED)


U (WHERE A RECORD WAS UPDATED)
D (WHERE A RECORD WAS DELETED),
C (WHERE A DOCUMENT WAS CANCELED)
L (WHERE A DOCUMENT WAS CLOSED)
@LIST_OF_COLS_VAL_TAB_DEL.-THIS RETURNS A TAB-DELIMITED LIST OF VALUES REQUIRED TO
RETRIEVE THE OBJECT FROM B1.
@ERROR.- A INTEGER VALUE SHOWS THE NUMBER
@ERROR_MESSAGE.- MESSAGE NEEDS TO BE SHOW AS A MESSAGE TO USER*/

--AL CREAR A O ACTUALIZAR U, UNA OFERTA DE VENTA, EL CAMPO COMMENTS DEBE TENER
INFORMACIÓN

IF @OBJECT_TYPE = '23' AND @TRANSACTION_TYPE IN ('A','U')


BEGIN
IF (SELECT COMMENTS FROM OQUT WHERE DOCENTRY = @LIST_OF_COLS_VAL_TAB_DEL) IS NULL
BEGIN
SET @ERROR=1
SET @ERROR_MESSAGE='ERROR, ERROR, ERROR'
END
END

--BLOQUEAR ITEMS DUPLICADOS EN OFERTA DE VENTA

IF @OBJECT_TYPE='23' AND @TRANSACTION_TYPE IN ('A')


BEGIN
IF EXISTS (SELECT QUT1.ITEMCODE, COUNT(QUT1.ITEMCODE) FROM QUT1 WHERE QUT1.DOCENTRY
= @LIST_OF_COLS_VAL_TAB_DEL
GROUP BY QUT1.ITEMCODE HAVING COUNT(QUT1.ITEMCODE)>1)
SET @ERROR=1
SET @ERROR_MESSAGE='EL NUMERO DEL ARTÍCULO NO DEBE SER REPETIDO EN DIFERENTES FILAS'
END

--VALIDAR LA ENTREGA (OBJECT_TYPE 15) UNICAMENTE DE UN ALMACEN ESPECIFICO

IF @OBJECT_TYPE = '15' AND @TRANSACTION_TYPE IN ('A')


BEGIN
IF
(SELECT COUNT(T1.WHSCODE) FROM ODLN T0 INNER JOIN DLN1 T1 ON
T1.DOCENTRY = T0.DOCENTRY
WHERE T0.DOCENTRY = @LIST_OF_COLS_VAL_TAB_DEL AND T1.WHSCODE IN
('02','03','04')) >= 1
BEGIN
SET @ERROR = 102
SET @ERROR_MESSAGE = 'ALMACEN INCORRECTO - SOLO SE PUEDEN
REALIZAR ENTREGAS DESDE 01'
END

END

-- NO PODER CREAR UNA FACTURA SI NO HAY INFORMACION EN EL CAMPO NÚMERO DE REFERENCIA


DE DEUDOR EN LA FACTURA DE CLIENTES.

IF @OBJECT_TYPE = '15' AND @TRANSACTION_TYPE = 'U'


BEGIN
IF (SELECT OINV.NUMATCARD FROM OINV WHERE OINV.DOCENTRY =
@LIST_OF_COLS_VAL_TAB_DEL) IS NULL
BEGIN
SET @ERROR = -5002
SET @ERROR_MESSAGE = 'EL CAMPO NUMERO DE REFERENCIA NO PUEDE ESTAR
VACIO'
END
END

-- NO SE PUEDE CREAR UNA FACTURA DE COMPRA SI NO VIENE DE UN DOCUMENTO BASE.

IF @OBJECT_TYPE = '18' AND @TRANSACTION_TYPE = 'A'


BEGIN
IF EXISTS(SELECT ITEMCODE FROM PCH1 T0 WHERE T0.BASEENTRY IS NULL AND
T0.DOCENTRY = @LIST_OF_COLS_VAL_TAB_DEL)
BEGIN
SET @ERROR = -5003
SET @ERROR_MESSAGE = 'LA FACTURA SOLO PUEDE SER CREADA SI VIENE DE UN
DOCUMENTO BASE'
END
END

-- NO SE PUEDE CREAR ODEN DE COMPRA CON MONTO 0

IF @OBJECT_TYPE = '22' AND @TRANSACTION_TYPE IN ('A','U')


BEGIN
IF EXISTS(SELECT T0.DOCNUM FROM OPOR T0 WHERE T0.DOCTOTAL = 0 AND
T0.DOCENTRY = @LIST_OF_COLS_VAL_TAB_DEL)
BEGIN
SET @ERROR = -5003
SET @ERROR_MESSAGE = 'EVITE CREAR ORDENES DE COMPRA CON MONTO 0'
END
END

-- VALIDAR QUE SE INTRODUZCA EL INDICADOR DE IMPUESTOS A NIVEL DE LINEA

IF @OBJECT_TYPE = '22' AND @TRANSACTION_TYPE IN ('A','U')


BEGIN

IF EXISTS (SELECT T2.ITEMCODE FROM OPOR T1 INNER JOIN POR1 T2 ON T2.[DOCENTRY]=T1.


[DOCENTRY]
WHERE (T2.TAXCODE IS NULL OR T2.TAXCODE='' ) AND T1.OBJTYPE = 22
AND
T2.DOCENTRY=@LIST_OF_COLS_VAL_TAB_DEL)

BEGIN
SET @ERROR=1
SET @ERROR_MESSAGE ='INTRODUZCA EL INDICADOR DE
IMPUESTOS'
END
END

--VALIDAR NOMBRES DUPLICADOS DE SN LEAD ANTES DE CREAR

IF @OBJECT_TYPE='2' AND @TRANSACTION_TYPE IN ('A')


BEGIN

DECLARE @DESC NVARCHAR(100)


SELECT @DESC=T0.CARDNAME FROM OCRD T0 WHERE (T0.CARDTYPE = 'L' AND
T0.CARDCODE = @LIST_OF_COLS_VAL_TAB_DEL)

DECLARE @COUNT INT

SELECT @COUNT=COUNT(*) FROM OCRD T1 WHERE T1.CARDNAME=@DESC

IF (@COUNT > 1)
BEGIN

SET @ERROR = -1

SET @ERROR_MESSAGE = 'YA EXISTE UN REGISTRO CON EL MISMO NOMBRE SN'

END

END

--RECHAZAR LA CREACIÓN DE ÓRDENES DE COMPRA POR EL USUARIO MANAGER.

IF @OBJECT_TYPE = '22' AND @TRANSACTION_TYPE IN ('A', 'U')


BEGIN
IF EXISTS(SELECT T0.DOCTOTAL FROM OPOR T0 WHERE T0.USERSIGN = 1 AND
T0.DOCENTRY = @LIST_OF_COLS_VAL_TAB_DEL)
BEGIN
SET @ERROR = -5006
SET @ERROR_MESSAGE = 'EL USUARIO MANAGER NO DEBE CREAR OC'
END
END

Table Table description Primary Key Object


Type
OACT G/L Accounts AcctCode 1
OCRD Business Partner CardCode 2
ODSC Bank Codes AbsEntry 3
OITM Items ItemCode 4
OVTG Tax Definition Code 5
OPLN Price Lists ListNum 6
OSPP Special Prices CardCode, ItemCode 7
OITG Item Properties ItmsTypCod 8
ORTM Rate Differences LineNum, IsSysCurr 9
OCRG Card Groups GroupCode 10
OCPR Contact Persons CntctCode 11
OUSR Users USERID 12
OINV A/R Invoice DocEntry 13
ORIN A/R Credit Memo DocEntry 14
ODLN Delivery DocEntry 15
ORDN Returns DocEntry 16
ORDR Sales Order DocEntry 17
OPCH A/P Invoice DocEntry 18
ORPC A/P Credit Memo DocEntry 19
OPDN Goods Receipt PO DocEntry 20
ORPD Goods Return DocEntry 21
OPOR Purchase Order DocEntry 22
OQUT Sales Quotation DocEntry 23
ORCT Incoming Payment DocEntry 24
ODPS Deposit DeposId 25
OMTH Reconciliation History MthAcctCod, IsInternal, 26
MatchNum
OCHH Check Register CheckKey 27
OBTF Journal Voucher Entry BatchNum, TransId 28
OBTD Journal Vouchers List BatchNum 29
OJDT Journal Entry TransId 30
OITW Items – Warehouse ItemCode, WhsCode 31
OADP Print Preferences PrintId 32
OCLG Activities ClgCode 33
ORCR Recurring Postings RcurCode, Instance 34
ONNM Document Numbering ObjectCode, DocSubType 35
OCRC Credit Cards CreditCard 36
OCRN Currency Codes CurrCode 37
OIDX CPI Codes IdexCode 38
OADM Administration Code 39
OCTG Payment Terms GroupNum 40
OPRF Preferences FormNumber, UserSign 41
OBNK External Bank Statement AcctCode, Sequence 42
Received
OMRC Manufacturers FirmCode 43
OCQG Card Properties GroupCode 44
OTRC Journal Entry Codes TrnsCode 45
OVPM Outgoing Payments DocEntry 46
OSRL Serial Numbers ItemCode, SerialNum 47
OALC Loading Expenses AlcCode 48
OSHP Delivery Types TrnspCode 49
OLGT Length Units UnitCode 50
OWGT Weight Units UnitCode 51
OITB Item Groups ItmsGrpCod 52
OSLP Sales Employee SlpCode 53
OFLT Report – Selection Criteria FormNum, UserSign, FilterName 54
OTRT Posting Templates TrtCode 55
OARG Customs Groups CstGrpCode 56
OCHO Checks for Payment CheckKey 57
OINM Whse Journal TransNum, Instance 58
OIGN Goods Receipt DocEntry 59
OIGE Goods Issue DocEntry 60
OPRC Cost Center PrcCode 61
OOCR Cost Rate OcrCode 62
OPRJ Project Codes PrjCode 63
OWHS Warehouses WhsCode 64
OCOG Commission Groups GroupCode 65
OITT Product Tree Code 66
OWTR Inventory Transfer DocEntry 67
OWKO Production Instructions OrderNum 68
OIPF Landed Costs DocEntry 69
OCRP Payment Methods CrTypeCode 70
OCDT Credit Card Payment Code 71
OCRH Credit Card Management AbsId, Instance 72
OSCN Customer/Vendor Cat. No. ItemCode, CardCode, Substitute 73
OCRV Credit Payments AbsId, PayId, Instance 74
ORTT CPI and FC Rates RateDate, Currency 75
ODPT Postdated Deposit DeposId 76
OBGT Budget AbsId 77
OBGD Budget Cost Assess. Mthd BgdCode 78
ORCN Retail Chains ChainCode 79
OALT Alerts Template Code 80
OALR Alerts Code 81
OAIB Received Alerts AlertCode, UserSign 82
OAOB Message Sent AlertCode, UserSign 83
OCLS Activity Subjects Code 84
OSPG Special Prices for Groups CardCode, ObjType, ObjKey 85
SPRG Application Start LineNum, UserCode 86
OMLS Distribution List Code 87
OENT Shipping Types DocEntry 88
OSAL Outgoing DocEntry 89
OTRA Transition DocEntry 90
OBGS Budget Scenario AbsId 91
OIRT Interest Prices Numerator 92
OUDG User Defaults Code 93
OSRI Serial Numbers for Items ItemCode, SysSerial 94
OFRT Financial Report AbsId 95
Templates
OFRC Financial Report TemplateId, CatId 96
Categories
OOPR Opportunity OpprId 97
OOIN Interest Num 98
OOIR Interest Level Num 99
OOSR Information Source Num 100
OOST Opportunity Stage Num 101
OOFR Defect Cause Num 102
OCLT Activity Types Code 103
OCLO Meetings Location Code 104
OISR Service Calls RequestNum 105
OIBT Batch No. for Item ItemCode, BatchNum, WhsCode 106
OALI Alternative Items 2 OrigItem, AltItem 107
OPRT Partners PrtId 108
OCMT Competitors CompetId 109
OUVV User Validations IndexID, LineNum 110
OFPR Posting Period AbsEntry 111
ODRF Drafts DocEntry 112
OSRD Batches and Serial ItemCode, DocType, DocEntry, 113
Numbers DocLineNum
OUDC User Display Cat. CodeID 114
OPVL Lender – Pelecard Code 115
ODDT Withholding Tax Numerator 116
Deduction Hierarchy
ODDG Withholding Tax Numerator 117
Deduction Groups
OUBR Branches Code 118
OUDP Departments Code 119
OWST Confirmation Level WstCode 120
OWTM Approval Templates WtmCode 121
OWDD Docs. for Confirmation WddCode 122
OCHD Checks for Payment CheckKey 123
Drafts
CINF Company Info Version 124
OEXD Freight Setup ExpnsCode 125
OSTA Sales Tax Authorities Code, Type 126
OSTT Sales Tax Authorities AbsId 127
Type
OSTC Sales Tax Codes Code 128
OCRY Countries Code 129
OCST States Country, Code 130
OADF Address Formats Code 131
OCIN A/R Correction Invoice DocEntry 132
OCDC Cash Discount Code 133
OQCN Query Catagories CategoryId 134
OIND Triangular Deal Code 135
ODMW Data Migration Code 136
OCSTN Workstation ID Code 137
OIDC Indicator Code 138
OGSP Goods Shipment Code 139
OPDF Payment Draft DocEntry 140
OQWZ Query Wizard Code 141
OASG Account Segmentation AbsId 142
OASC Account Segmentation SegmentId, Code 143
Categories
OLCT Location Code 144
OTNN 1099 Forms FormCode 145
OCYC Cycle Code 146
OPYM Payment Methods for PayMethCod 147
Payment Wizard
OTOB 1099 Opening Balance VendCode, Form1099, Box1099 148
ORIT Dunning Interest Rate Code 149
OBPP BP Priorities PrioCode 150
ODUN Dunning Letters LineNum 151
CUFD User Fields – Description TableID, FieldID 152
OUTB User Tables TableName 153
OCUMI My Menu Items UserSign , Id_ 154
OPYD Payment Run Code 155
OPKL Pick List AbsEntry 156
OPWZ Payment Wizard IdNumber 157
OPEX Payment Results Table AbsEntry 158
OPYB Payment Block AbsEntry 159
OUQR Queries IntrnalKey, Qcategory 160
OCBI Central Bank Ind. Indicator 161
OMRV Inventory Revaluation DocEntry 162
OCPI A/P Correction Invoice DocEntry 163
OCPV A/P Correction Invoice DocEntry 164
Reversal
OCSI A/R Correction Invoice DocEntry 165
OCSV A/R Correction Invoice DocEntry 166
Reversal
OSCS Service Call Statuses statusID 167
OSCT Service Call Types callTypeID 168
OSCP Service Call Problem prblmTypID 169
Types
OCTT Contract Template TmpltName 170
OHEM Employees empID 171
OHTY Employee Types typeID 172
OHST Employee Status statusID 173
OHTR Termination Reason reasonID 174
OHED Education Types edType 175
OINS Customer Equipment Card insID 176
OAGP Agent Name AgentCode 177
OWHT Withholding Tax WTCode 178
ORFL Already Displayed 347, DocEntry, ReportType, DocType, 179
349 and WTax Reports LineNum, TaxCode, OrdinalNum
OVTR Tax Report AbsEntry 180
OBOE Bill of Exchange for BoeKey 181
Payment
OBOT Bill Of Exchang AbsEntry 182
Transaction
OFRM File Format AbsEntry 183
OPID Period Indicator Indicator 184
ODOR Doubtful Debts AbsEntry 185
OHLD Holiday Table HldCode 186
OCRB BP – Bank Account Country, BankCode, Account, 187
CardCode
OSST Service Call Solution Number 188
Statuses
OSLT Service Call Solutions SltCode 189
OCTR Service Contracts ContractID 190
OSCL Service Calls callID 191
OSCO Service Call Origins originID 192
OUKD User Key Description TableName, KeyId 193
OQUE Queue queueID 194
OIWZ Inflation Wizard AbsEntry 195
ODUT Dunning Terms TermCode 196
ODWZ Dunning Wizard WizardId 197
OFCT Sales Forecast AbsID 198
OMSN MRP Scenarios AbsEntry 199
OTER Territories territryID 200
OOND Industries IndCode 201
OWOR Production Order DocEntry 202
ODPI A/R Down Payment DocEntry 203
ODPO A/P Down Payment DocEntry 204
OPKG Package Types PkgCode 205
OUDO User-Defined Object Code 206
ODOW Data Ownership – Objects Object, SubObject 207
ODOX Data Ownership – QueryId, Object, SubObject 208
Exceptions
209
OHPS Employee Position posID 210
OHTM Employee Teams teamID 211
OORL Relationships OrlCode 212
ORCM Recommendation Data DocEntry 213
OUPT User Autorization Tree AbsId 214
OPDT Predefined Text AbsEntry 215
OBOX Box Definition BoxCode, ReportType, BosCode 216
OCLA Activity Status statusID 217
OCHF 312 ObjName 218
OCSHS User-Defined Values IndexID 219
OACP Periods Category AbsEntry 220
OATC Attachments AbsEntry 221
OGFL Grid Filter FormID, GridID, UserCode 222
OLNG User Language Table Code 223
OMLT Multi-Language TranEntry 224
Translation
OAPA3 225
OAPA4 226
OAPA5 227
SDIS Dynamic Interface FormId, ItemId, ColumnId, 229
(Strings) Language
OSVR Saved Reconciliations acctCode 230
DSC1 House Bank Accounts AbsEntry 231
RDOC Document DocCode 232
ODGP Document Generation AbsEntry 233
Parameter Sets
OMHD #740 AlertCode 234
OACG Account Category AbsId 238
OBCA Bank Charges Allocation Code 239
Codes
OCFT Cash Flow Transactions – CFTId 241
Rows
OCFW Cash Flow Line Item CFWId 242
OBPL Business Place BPLId 247
OJPE Local Era Calendar Code 250
ODIM Cost Accounting DimCode 251
Dimension
OSCD Service Code Table AbsEntry 254
OSGP Service Group for Brazil AbsEntry 255
OMGP Material Group AbsEntry 256
ONCM NCM Code AbsEntry 257
OCFP CFOP for Nota Fiscal ID 258
OTSC CST Code for Nota Fiscal ID 259
OUSG Usage of Nota Fiscal ID 260
OCDP Closing Date Procedure ClsDateNum 261
ONFN Nota Fiscal Numbering ObjectCode, DocSubType 263
ONFT Nota Fiscal Tax Category AbsId 264
(Brazil)
OCNT Counties AbsId 265
OTCD Tax Code Determination AbsId 266
ODTY BoE Document Type AbsEntry 267
OPTF BoE Portfolio AbsEntry 268
OIST BoE Instruction AbsEntry 269
OTPS Tax Parameter AbsId 271
OTFC Tax Type Combination AbsId 275
OFML Tax Formula Master Table AbsId 276
OCNA CNAE Code AbsId 278
OTSI Sales Tax Invoice DocEntry 280
OTPI Purchase Tax Invoice DocEntry 281
OCCD Cargo Customs CCDNum 283
Declaration Numbers
ORSC Resources ResCode 290
ORSG Resource Properties ResTypCod 291
ORSB ResGrpCod ResGrpCod 292
RecordSet 300
Bridge 305
OITR Internal Reconciliation ReconNum 321
OPOS POS Master Data EquipNo 541
ODRF Stock Transfer Draft DocEntry 1179
OMSG Messaging Service USERID 10000105
Settings
OBTN Batch Numbers Master AbsEntry 10000044
Data
OSRN Serial Numbers Master AbsEntry 10000045
Data
OIVK IVL Vs OINM Keys TransSeq 10000062
OIQR Inventory Posting DocEntry 10000071
OFYM Financial Year Master AbsId 10000073
OSEC Sections AbsId 10000074
OCSN Certificate Series AbsId 10000075
ONOA Nature of Assessee AbsId 10000077
RTYP Document Type List CODE 10000196
OUGP UoM Group UgpEntry 10000197
OUOM UoM Master Data UomEntry 10000199
OBFC Bin Field Configuration AbsEntry 10000203
OBAT Bin Location Attribute AbsEntry 10000204
OBSL Warehouse Sublevel AbsEntry 10000205
OBIN Bin Location AbsEntry 10000206
ODNF DNF Code AbsEntry 140000041
OUGR Authorization Group GroupId 231000000
OEGP E-Mail Group EmlGrpCode 234000004
OGPC Government Payment AbsId 243000001
Code
OIQI Inventory Opening DocEntry 310000001
Balance
OBTW Batch Attributes in AbsEntry 310000008
Location
OLLF Legal List Format AbsEntry 410000005
OHET Object: HR Employee TransferID 480000001
Transfer
OTCX Tax Code Determination DocEntry 540000005
OPQT Purchase Quotation DocEntry 540000006
ORCP Recurring Transaction AbsEntry 540000040
Template
OCCT Cost Center Type CctCode 540000042
OACR Accrual Type Code 540000048
ONFM Nota Fiscal Model AbsEntry 540000056
OBFI Brazil Fuel Indexer ID 540000067
OBBI Brazil Beverage Indexer ID 540000068
OCPT Cockpit Main Table AbsEntry 121000000
0
OWTQ Inventory Transfer DocEntry 125000000
Request 1
OOAT Blanket Agreement AbsID 125000002
5
OKPI Key Performance AbsEntry 132000000
Indicator Package 0
OTGG Target Group TargetCode 132000000
2
OCPN Campaign CpnNo 132000001
2
OROC Retorno Operation Codes AbsEntry 132000002
8
OPSC Product Source Code Code 132000003
9
ODTP Fixed Assets Depreciation Code 147000000
Types 0
OADT Fixed Assets Account Code 147000000
Determination 2
ODPA Fixed Asset Depreciation Code 147000000
Areas 3
ODPP Depreciation Type Pools Code 147000000
4
OACS Asset Classes Code 147000003
2
OAGS Asset Groups Code 147000004
6
ODMC G/L Account DmcId 147000004
Determination Criteria – 8
Inventory
OACQ Capitalization DocEntry 147000004
9
OGAR G/L Account Advanced AbsEntry 147000005
Rules 7
OACD Credit Memo DocEntry 147000006
0
OBCD Bar Code Master Data BcdEntry 147000006
2
OINC Inventory Counting DocEntry 147000006
5
OEDG Discount Groups AbsEntry 147000007
7
OCCS Cycle Count WhsCode 147000009
Determination 2
OPRQ Purchase Request DocEntry 147000011
3
OWLS Workflow – Task Details TaskID 162000000
0

You might also like