/scripts/ahub.form.attachments.js
0

How to paste mutli rows from excel to matrix

May 24, 2017 at 09:38 AM

193

avatar image
Former Member

Dears,

Wish you can help me.

I have created a UDO, Masterdata type ( header and 4 row tables), I added a matrix and then I added a CFL to the first column of each matrix and used this code to get the values by catch the "ItemEvent":

if (pVal.ColUID == "ItemCode")
 {


string code = oDataTable.GetValue(0, 0).ToString();
 string name = oDataTable.GetValue(1, 0).ToString();
 ((SAPbouiCOM.EditText)mtxSItems.Columns.Item("ItemName").Cells.Item(pVal.Row).Specific).Value = name;
                            
 ((SAPbouiCOM.EditText)mtxSItems.Columns.Item("ItemCode").Cells.Item(pVal.Row).Specific).Value = code;
 if (((SAPbouiCOM.EditText)mtxSItems.Columns.Item("ItemCode").Cells.Item(mtxSItems.RowCount).Specific).Value != "")
 {
       mtxSItems.AddRow(1, -1);
 }
}


sometimes when I click update to save a single value i receive an error of

sometiems it saves, this make me confused.

But when I try to paste mutli-rows from excel this error always shows up

maybe there is something I make wrong.

capture.png (7.7 kB)
10 |10000 characters needed characters left characters exceeded

The best way to get rid off, implement auto add line functionality for your matrix, or call add line functionality in choosefromlist after event. when you copy the value from excel than it will automatic create new row for you. and the first issue this entry already exists check line id column value in datasource of matrix on button pressed before event.

0
Former Member
Vinay Badholia

Dear Vinay,

I have done all what you have said. but still get same error. please check my answer below and check the way i have created this UDO , maybe you can help me

Thanks

0
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
ANKIT CHAUHAN
May 24, 2017 at 10:00 AM
0

Hi,

Since, I do not have the running project at the moment, could you please try something like below:

oMatrixItem.FlushToDataSource();
SetRowNumber();
oMatrixItem.LoadFromDataSource();


Where method SetRowNumber() should be defined as below:


private void SetRowNumber()
        {
            SAPbouiCOM.Matrix oMatrix = (SAPbouiCOM.Matrix)m_SBO_Form.Items.Item(enControlName.Matrix).Specific;
            try
            {
                if (oMatrix.VisualRowCount > 0)
                {
                    oMatrix.FlushToDataSource();
                    int count = _dBDataSourceChild.Size;


                    for (int i = 0; i <= count-1; i++)
                    {
                        this.m_SBO_Form.DataSources.DBDataSources.Item("@TableName").SetValue("U_LineNum", i, (i + 1).ToString());
                    }
                    oMatrix.LoadFromDataSource();
                }
            }
            catch
            {
                throw;
            }
        }

Hope it helps!

Kind regards,

ANKIT CHAUHAN

SAP SME Support

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Yes thank you, it helped

I didnt use the code but I used the idea and the result of the code

Appreciate it

0
avatar image
Former Member May 31, 2017 at 12:51 PM
0

Dear Ankit,

Thanks for your response, but I dont know where to include that code.

I have created a master data table with 4 master data lines tables, then created the object by this code :

 private void Create_UDO()
        {

            GC.Collect();
                            SAPbobsCOM.UserObjectsMD oUserObjectMD = null;
                SAPbobsCOM.UserObjectMD_FormColumns oUDOForm = null;
                oUserObjectMD = (SAPbobsCOM.UserObjectsMD)Connection.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD);
                oUDOForm = oUserObjectMD.FormColumns;
                oUserObjectMD.Code = "CMSNSTNG";
                oUserObjectMD.Name = "Settings";
                oUserObjectMD.TableName = "Settings";

                oUserObjectMD.ChildTables.Add();
                oUserObjectMD.ChildTables.TableName = "SitemsLines";
                oUserObjectMD.ChildTables.Add();
                oUserObjectMD.ChildTables.TableName = "Sitemgrpslines";
                oUserObjectMD.ChildTables.Add();
                oUserObjectMD.ChildTables.TableName = "DitemsLines";
                oUserObjectMD.ChildTables.Add();
                oUserObjectMD.ChildTables.TableName = "Ditemgrpslines";


                oUserObjectMD.ObjectType = SAPbobsCOM.BoUDOObjType.boud_MasterData;
                oUserObjectMD.CanFind = SAPbobsCOM.BoYesNoEnum.tNO;
                oUserObjectMD.CanDelete = SAPbobsCOM.BoYesNoEnum.tNO;
                oUserObjectMD.CanCancel = SAPbobsCOM.BoYesNoEnum.tNO;
                oUserObjectMD.CanClose = SAPbobsCOM.BoYesNoEnum.tNO;
                oUserObjectMD.CanYearTransfer = SAPbobsCOM.BoYesNoEnum.tNO;
                oUserObjectMD.CanLog = SAPbobsCOM.BoYesNoEnum.tNO;
                oUserObjectMD.ManageSeries = SAPbobsCOM.BoYesNoEnum.tNO;
              oUserObjectMD.CanCreateDefaultForm = SAPbobsCOM.BoYesNoEnum.tYES;
                oUserObjectMD.EnableEnhancedForm = SAPbobsCOM.BoYesNoEnum.tYES;
                oUserObjectMD.MenuItem = SAPbobsCOM.BoYesNoEnum.tNO;
                oUserObjectMD.UseUniqueFormType = SAPbobsCOM.BoYesNoEnum.tYES;
                //==============
                lRetCode = oUserObjectMD.Add();
                // check for errors in the process
                if (lRetCode != 0)
                {
                    Connection.oCompany.GetLastError(out lRetCode, out sErrMsg);
                    Application.SBO_Application.MessageBox("" + lRetCode + "  " + sErrMsg);
                }
                GC.Collect(); // Release the handle to the table
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserObjectMD);
            
        }

then I have created a user from then I added some edittexts,datasources,tabs,matrix,CFLs and buttons, I gave a button itemUID = 1 so it can save automatically to the data source new and updates.

but I have a big problem when using a matrix with CFL

so could you please be more specific so I can keep up with you

Thanks a lot

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi,

I hope the issue is resolved for you after binding column "#" to LineID in the table. In that case, I would request you to please close this thread by marking the "Correct Answer".

Kind regards,

ANKIT CHAUHAN

SAP SME Support

0
avatar image
Former Member May 31, 2017 at 03:19 PM
0

Dear Ankit,

Thank you so much, I was missing the idea of binding the column "#" in the matrix. I appreciate your help

When I bind it the column "#" it took values automatically then there will be no conflict

Share
10 |10000 characters needed characters left characters exceeded
Skip to Content