In
this example, I am going to integrate Sales Transaction from POS System
to SAP Business One. To do this, I have separated some parts as below
I. Connection
a.
SAP Connection : Connection is the first require that you need to
define. Without connection, you can do nothing. the connection contain
some information such as SAP Server Address, System Landscape Address,
Database Name, Database User, SAP User and SAP user password ( for SAP
User, normally I use user manager for integration ).
b.
POS Connection: To get data from POS database, u need to define
connection to POS System. There are alot of ways to get data from SQL
database such as SQLDataAdapter, Entity, Linq...In this example, I am
going to use Linq to get data from POS Database and integrate to SAP.
II. SAP Components
SAP components, I refer to what object are you going to integrate to
SAP such as Item Master Data, Business Partner Master Data, Sales Order,
Purchase Order,..... you need to define which object? In this example, I
am going to integrate Data from POS to AR Invoice.
III. Let's do it.
a. Variable Declaration
a.1 SAPbobsCOM.Company oCompany;
a.2 SAPbobsCOM.Documents AR = null;
a.3 POSDataContext db = null;
b. Create Function
b1. ConnecttoSAP: you need to set propertied as below
db=new POSDataContext("Data Source=192.168.0.1;Initial Catalog=POSDB;Persist Security Info=True;User ID=sa;Password=1111");
oCompany = new Company();
oCompany.Server = "192.168.0.1"; SAP Server Name
oCompany.LicenseServer = "192.168.0.1"; SAP System Landscape
oCompany.CompanyDB = "SBODEMOAU"; SAP Database Name
oCompany.DbServerType = BoDataServerTypes.dst_MSSQL2014; (It is your SQL Version)
oCompany.DbUserName = "sa";
oCompany.DbPassword = "1111"; SQL sa Password
oCompany.UserName = "manager"; SAP User ( manager )
oCompany.Password = "1111"; // manager password
int i = oCompany.Connect();
Noted: If i=0, mean you connect to SAP successfully
b.2. Integrate Data to AR
foreach (Invoice inv in db.Invoices.Where(x => x.sync==null))//loop that get data from POS DB
{
AR = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(BoObjectTypes.oInvoices);
////BoObjectTypes.oInvoices = AR Invoice, you can define other by just changing this value
AR.CardCode = inv.bpcode;
AR.CardName = inv.bpname;
AR.DocDate = inv.docdate.Value;
foreach (invoiceitem item in inv.invoiceitems)//Loop to detail transaction detail item
{
AR.Lines.ItemCode = item.itemcode;
AR.Lines.ItemDescription = item.itemname;
AR.Lines.Quantity = (double)item.quantity.Value;
AR.Lines.Price = (double)item.unitprice;
AR.Lines.DiscountPercent = (double)item.discountpercent.Value;
AR.Lines.WarehouseCode = item.whscode;
AR.Lines.Add();
}
int haserror=AR.Add() {
Noted: If haserror==0 mean that this transaction already added to AR Invoice in SAP
}
If
you cannot integrate and got some error, you can paste your error in
comment and I will help to solve for you. Have a great day!!!
No comments:
Post a Comment