Sunteți pe pagina 1din 6

How to Auto-Increment Business

Partner Code for SAP Business


One

Applies to:
Business One

Summary
This article includes two proposed solutions to address how to set up SAP Business One to automatically
calculate the next card code for new Business Partners.
Author:

Idit Frydman-Saguey

Company: SAP
Created on: 14 May 2009

SAP COMMUNITY NETWORK


2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


1

How to Auto-Increment Business Partner Code for SAP Business One

Table of Contents
Business Problem...............................................................................................................................................3
Solution One ...................................................................................................................................................3
Solution Two ...................................................................................................................................................4
Related Contents ................................................................................................................................................5
Copyright.............................................................................................................................................................6

SAP COMMUNITY NETWORK


2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


2

How to Auto-Increment Business Partner Code for SAP Business One

Business Problem
You would like the system to automatically calculate and propose the next card code when a new Business
Partner is added to SAP Business One. Codes for Customers and Leads will always start with "2", and
Vendors will always start with "1". When creating a new Business Partner, the user should be able to look up
the "next Vendor code" or "next Customer code" by using the keyboard combination Shift+F2.
Solution One
You could enable a simple lookup of next Business Partner Code. This method does not automatically
enforce a numeric code, however, it provides a simple solution that requires no code.
The prerequisite for this solution is that all the codes or Business Partners in the database should adhere to
the same rules:

Same number of characters

Same constant in beginning of code

All codes are numeric

Follow these short steps:


1. Link the following query to the card code field:
if $[ocrd.cardtype]='L' or $[ocrd.cardtype]='C'
Begin
select max (cardcode+1)
from ocrd where ocrd.cardcode Like '<select number>%%'
end
else
begin select max (cardcode+1)
from ocrd
where ocrd.cardcode like '<select number>%%'
END

2. Replace the <select number> text with the constant (2 or 1).


3. When you add a customer, choose the type first.
4. Activate formatted search using Shift+F2 when the cursor is in the code field.
Next number will appear.

SAP COMMUNITY NETWORK


2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


3

How to Auto-Increment Business Partner Code for SAP Business One

Solution Two
It is possible to create a slightly more sophisticated solution with a relatively small amount of code. By
responding to several item events, we can auto-populate the CardCode using a query similar to the one
provided in the first solution.
First, you need to add code to respond to the Item Event in which the CardCode field gets focus while the
form is in Add mode. This event will fire if the user switches from Find mode to Add mode.
'RESPOND TO BP CARDCODE GOTFOCUS WHILE FORM IS IN ADD MODE
If pVal.FormType = 134 And pVal.FormMode = fm_ADD_MODE And _
pVal.ItemUID = "5" And pVal.EventType = et_GOT_FOCUS Then
Set frm = pApp.Forms.Item(FormUID)
Set edit = frm.Items("5").Specific
Set cmb = frm.Items("40").Specific
Dim pRS As SAPbobsCOM.Recordset
Dim sSQL As String
If (cmb.Selected.Value = "C" Or cmb.Selected.Value = "L") Then _
sSQL = "SELECT MAX (CardCode)+1 as NewValue FROM OCRD WHERE "
sSQL = sSQL & "OCRD.CardCode Like '2%'"
Else
sSQL = "SELECT MAX (CardCode)+1 as NewValue FROM OCRD WHERE "
sSQL = sSQL & "OCRD.CardCode Like '1%'"
End If
Set pRS = pCompany.GetBusinessObject(BoRecordset)
pRS.DoQuery sSQL
pRS.MoveFirst
edit.String = pRS.Fields("NewValue").Value
End If

Next, add a similar block of code that will respond to the event in which the Business Partner Type
(CardType) is changed using the Lost Focus event:
'RESPOND TO BP TYPE CHANGED WHILE FORM IS IN ADD MODE
If pVal.FormType = 134 And pVal.FormMode = fm_ADD_MODE And _
pVal.ItemUID = "40" And pVal.EventType = et_LOST_FOCUS Then
' ...Same logic as above applies here again...

Finally, you can add code to the Add button click event to ensure that the CardCode value is numeric:
'RESPOND TO 'ADD' BUTTON CLICK IN BUSINESS PARTNER MAINENANCE FORM
'******** Ensure that the CardCode is numeric
If pVal.FormType = 134 And pVal.FormMode = fm_ADD_MODE And _
pVal.ItemUID = "1" And pVal.EventType = et_CLICK Then
Set frm = pApp.Forms.Item(FormUID)
Set edit = frm.Items("5").Specific
If Not IsNumeric(edit.String) Then
pApp.MessageBox "The Business Partner Code must be numeric."
BubbleEvent = False
frm.Items("5").Click
End If
End If

SAP COMMUNITY NETWORK


2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


4

How to Auto-Increment Business Partner Code for SAP Business One

Related Contents
For more information, visit the Business One homepage.

SAP COMMUNITY NETWORK


2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


5

How to Auto-Increment Business Partner Code for SAP Business One

Copyright
Copyright 2009 SAP AG. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG.
The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9,
iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server,
PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes,
BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX,
Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems
Incorporated in the United States and/or other countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of
Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts
Institute of Technology.
Java is a registered trademark of Sun Microsystems, Inc.
JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by
Netscape.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned
herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries.
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and
other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered
trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company.
All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document
serves informational purposes only. National product specifications may vary.
These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP
Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or
omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the
express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an
additional warranty.

SAP COMMUNITY NETWORK


2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


6

S-ar putea să vă placă și