Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to get 'linenum' from the order form matrix

I'v been trying to get this to work for the past 4 hours now and I can't find a solution.

I have a button on the sales order form, when the user clicks on this button a second screen will appear with more information (stored in a usertable).

However to be able to get this information from my usertable I need to have the linenum of the selected line (in the matrix).

I know I can get the 'row' property but this doesn't give me the linenum (wich is the unique key in the RDR1 table).

Also the 'visorder' column doesn't work since I have textlines in the order that can be placed anywhere and can be more than 1.

Consider the following scenario:

Order with the following lines:


article line (actual orderline) (linenum = 1 / visorder = 0 / row = 2)

article line (actual orderline) (linenum = 2 / visorder = 1 / row = 3)

article line (actual orderline) (linenum = 3 / visorder = 2 / row = 4)



article line (actual orderline) (linenum = 4 / visorder = 3 / row = 6)---- (this line has been deleted)

article line (actual orderline) (linenum = 5 / visorder = 3 / row = 6)

So in total 6 lines.

How do I get the 'linenum' from the last line (note that linenum 4 has disappeared because of the deleted row)?

I looked into using the dbdatasource but with this I gets the entire RDR1 table (for that order) and can't get the linenum (correct one) out off it since the textlines mess up the order.

Anyone know how to do this?


Hi Marc,

Assuming the document is saved, you can use something like the following:

SAPbouiCOM.Form sboForm = (SAPbouiCOM.Form)_sboApp.Forms.GetForm(ItemEvent.FormTypeEx, ItemEvent.FormTypeCount);
SAPbouiCOM.Matrix sboMatrix = (SAPbouiCOM.Matrix)sboForm.Items.Item("38").Specific;

// Get the document number
SAPbouiCOM.EditText sboEdit = (SAPbouiCOM.EditText)sboForm.Items.Item("8").Specific;
string sDocNum = sboEdit.Value;

if (sDocNum == "") // No document is selected in this window so report error
    _sboApp.SetStatusBarMessage("No document has been selected", SAPbouiCOM.BoMessageTime.bmt_Short, true);
    if (sboForm.Mode == SAPbouiCOM.BoFormMode.fm_ADD_MODE || sboForm.Mode == SAPbouiCOM.BoFormMode.fm_UPDATE_MODE) // Document must be saved to ensure VisOrder is correct in the database
        _sboApp.SetStatusBarMessage("Please save the document first", SAPbouiCOM.BoMessageTime.bmt_Short, true);
        int iVisOrder = -1;

        string sMessage = "The Line Numbers on this document are: " + System.Environment.NewLine;

        for (int i = 1; i < sboMatrix.RowCount; i++) // Last row is always blank so loop while i is LESS than RowCount
            SAPbouiCOM.ComboBox sboCombo = (SAPbouiCOM.ComboBox)sboMatrix.Columns.Item("257").Cells.Item(i).Specific;
            string sLineType = sboCombo.Selected.Value.ToString();

            if (sLineType == "") // Not a text line or a subtotal
                iVisOrder++; // Increment your counter to get the next VisOrder value
                SAPbobsCOM.Recordset sboRec = (SAPbobsCOM.Recordset)_sboCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
                    sboRec.DoQuery("select T0.LineNum from RDR1 T0 inner join ORDR T1 on T0.DocEntry = T1.DocEntry where T0.VisOrder = " + iVisOrder.ToString() + " and T1.DocNum = " + sDocNum);
                    if (!sboRec.EoF)
                        sMessage += "Row " + i.ToString() + " in the matrix is LineNum " + sboRec.Fields.Item("LineNum").Value.ToString() + System.Environment.NewLine;
                    sboRec = null;
        _sboApp.MessageBox(sMessage, 1, "Ok", "", "");

Basically you have a counter that you increment if the matrix line is not a text or subtotal line. This will match the VisOrder value in the RDR1 table which you can use to get the LineNum value.

Kind Regards,


0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question