Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
mk1909_sap
Active Participant
Hello Team,

Greetings for the Day !!!

Consider we have Main User Defined Object named "Mahi_H" and It's child table is "Mahi_D1". If You want to Add / Updated records in Child table "Mahi_D1". We can do using SAP B1 General Service as follows.

 
SAPbobsCOM.GeneralService oGeneralService = null;
SAPbobsCOM.GeneralData oGeneralData = null;
SAPbobsCOM.GeneralDataParams oGeneralParams = null;
SAPbobsCOM.CompanyService sCmp = null;
SAPbobsCOM.GeneralData oChild = null;
SAPbobsCOM.GeneralDataCollection oChildren = null;
sCmp = Main.Mahi_Company.GetCompanyService();

oRs = ((SAPbobsCOM.Recordset)(Main.Mahi_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)));
string selquery = "select " + '"' + "DocEntry" + '"' + ",'1' as " + '"' + "LineId" + '"' + ",'0' as " + '"' + "VisOrder" + '"' + ",'SQ_AC' as " + '"' + "Object" + '"' + ",null as " + '"' + "LogInst" + '"' + ",'Y' as " + '"' + "U_Checked" + '"' + "," + '"' + "U_DocNum" + '"' + "," + '"' + "U_SQSeries" + '"' + "," + '"' + "U_SQLineId" + '"' + "," + '"' + "U_iCode" + '"' + "," + '"' + "U_iName" + '"' + "," + '"' + "U_LineId" + '"' + " from " + '"' + "@SQAC_H" + '"';

oRs.DoQuery(selquery);

try
{
oGeneralService = sCmp.GetGeneralService("Mahi_H"); // Main UDO Name
for (int i = 1; i <= 6; i++)
{
// Get UDO record
oGeneralParams = ((SAPbobsCOM.GeneralDataParams)(oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams)));
oGeneralParams.SetProperty("DocEntry", oRs.Fields.Item("DocEntry").Value); //Primary Key
oGeneralData = oGeneralService.GetByParams(oGeneralParams);

// Add lines on UDO Child Table
oChildren = oGeneralData.Child("Mahi_D1"); // Child Table Of Main UDO

// Create data for rows in the child table
oChild = oChildren.Add(); // Adds Blank Line in Child Table
oChild.SetProperty("U_SQLineId", oRs.Fields.Item("U_SQLineId").Value);
//oChild.SetProperty("VisOrder", oRs.Fields.Item("VisOrder").Value);
oChild.SetProperty("U_Checked", oRs.Fields.Item("U_Checked").Value);
oChild.SetProperty("U_DocNum", oRs.Fields.Item("U_DocNum").Value);
oChild.SetProperty("U_SQSeries", oRs.Fields.Item("U_SQSeries").Value);
oChild.SetProperty("U_SQLineId", oRs.Fields.Item("U_SQLineId").Value);
oChild.SetProperty("U_iCode", oRs.Fields.Item("U_iCode").Value);
oChild.SetProperty("U_iName", oRs.Fields.Item("U_iName").Value);

//Update the UDO Record
oGeneralService.Update(oGeneralData); // If Child Table doesnot have any record it will create else update the existing one
oRs.MoveNext();
}
}
catch (Exception ex)
{
Main.Mahi_Application.MessageBox(ex.Message, 1, "OK", null, null);
}

 

Thanks,

Mahendrakumar

 
2 Comments
Labels in this area