Hello.
May a bit late but this is how I have managed the convertion in VBA code from Memory data of query:
Set Func = sapConn.Add("RSAQ_REMOTE_QUERY_CALL") Func.Exports("WORKSPACE") = " " Func.Exports("QUERY") = "YCS_AUFK_COMPL" Func.Exports("USERGROUP") = "YCS" Func.Exports("VARIANT") = "TEST" Func.Exports("DBACC") = "0" Func.Exports("SKIP_SELSCREEN") = " " Func.Exports("DATA_TO_MEMORY") = "X" Func.Exports("EXTERNAL_PRESENTATION") = "X" Set tblSEL_SCREEN = Func.Tables("SELECTION_TABLE") Set tblLDATA = Func.Tables("LDATA") Set tblDESC = Func.Tables("LISTDESC") Set tblFPAIRS = Func.Tables("FPAIRS") If Func.Call = False Then MsgBox Func.Exception Exit Sub Else Application.ScreenUpdating = False If tblDESC.RowCount > 0 Then ThisWorkbook.Sheets("TEST").Activate For intCol1 = 1 To tblDESC.RowCount ThisWorkbook.Sheets("TEST").Cells(1, intCol1).Value = tblDESC(intCol1, "FCOL") Next Columns.AutoFit End If If tblLDATA.RowCount > 0 Then For intRow1 = 1 To tblLDATA.RowCount strLINE = strLINE & tblLDATA(intRow1, "LINE") Next split_line strLINE, (tblDESC.RowCount + 1) ThisWorkbook.Sheets("TEST").Activate End If Application.ScreenUpdating = True End If Set sapConn = Nothing Set Func = Nothing Set tblSEL_SCREEN = Nothing Set tblLDATA = Nothing Set tblDESC = Nothing Set tblFPAIRS = Nothing End Sub
Public Sub split_line(strLINE As String, iCol as Integer) Dim lenLINE As Long Dim strVALUE As String Dim lenVALUE As Integer Dim strFIELD As String Dim lenFIELD As Integer Dim a As Integer Dim b As Long b = 2 lenLINE = Len(strLINE) Do Until Len(strLINE) < 4 DoEvents a = 1 Do Until (a Mod iCol = 0 Or Len(strLINE) < 4) DoEvents If Len(strLINE) > 4 Then lenFIELD = Left(strLINE, 3) strVALUE = Left(strLINE, (4 + lenFIELD)) strFIELD = Right(strVALUE, lenFIELD) ThisWorkbook.Sheets("TEST").Cells(b, a).Value = strFIELD lenLINE = lenLINE - (1 + lenFIELD + 4) strLINE = Right(strLINE, lenLINE) lenLINE = Len(strLINE) a = a + 1 End If Loop b = b + 1 Loop Columns.AutoFit End Sub
The first code snippet receive data into Excel. The second public Sub reorganize the Memory data into a Excel Grid.