cancel
Showing results for 
Search instead for 
Did you mean: 

How to export crystal report directly from SAP Business One to rpt format via API

Former Member
0 Kudos

I need help with exporting crystal report directly from SAP Business One via API (DI, UI) or UDO (add-on) ideally in vb. net code, I found a many solutions where are rpt files converted and exported to other format but I need export rpt file from SBO first with API, which solution will be the best ? I´m a very novice in SAP SDK, thanks a lot for your answers !!!

Accepted Solutions (1)

Accepted Solutions (1)

maik_delly
Active Contributor

Hi Martin,

here is a c# example how to get a rpt file that is assigned for a specific business partner in sales order :


SAPbobsCOM.ReportLayoutsService oLayoutService = (SAPbobsCOM.ReportLayoutsService)SBO_Company.GetCompanyService().GetBusinessService(SAPbobsCOM.ServiceTypes.ReportLayoutsService);

SAPbobsCOM.ReportParams oReportParams = (SAPbobsCOM.ReportParams)oLayoutService.GetDataInterface(SAPbobsCOM.ReportLayoutsServiceDataInterfaces.rlsdiReportParams);

oReportParams.ReportCode = "RDR2";//defined in db table "RTYP"

oReportParams.CardCode = "C20000";//business partner

var oReport = oLayoutService.GetDefaultReport(oReportParams);

BlobParams oBlobParams = (SAPbobsCOM.BlobParams)SBO_Company.GetCompanyService().GetDataInterface(SAPbobsCOM.CompanyServiceDataInterfaces.csdiBlobParams);

oBlobParams.Table = "RDOC";

oBlobParams.Field = "Template";

oBlobParams.FileName = @"C:\salesorder.rpt";

BlobTableKeySegment oKeySegment = oBlobParams.BlobTableKeySegments.Add();

oKeySegment.Name = "DocCode";

oKeySegment.Value = oReport.LayoutCode;

SBO_Company.GetCompanyService().SaveBlobToFile(oBlobParams);

regards,

Maik

Former Member
0 Kudos

Thanks a lot Maik, It´s what I was looking for

edy_simon
Active Contributor
0 Kudos

Hi Martin,

This is how I did it in VB.Net


    Public Sub GetCrystalReportFile(ByVal RDOCCode As String, ByVal outFileName As String)

        Try

            Dim oBlobParams As SAPbobsCOM.BlobParams = oCompany.GetCompanyService().GetDataInterface(SAPbobsCOM.CompanyServiceDataInterfaces.csdiBlobParams)

            oBlobParams.Table = "RDOC"

            oBlobParams.Field = "Template"

            Dim oKeySegment As SAPbobsCOM.BlobTableKeySegment = oBlobParams.BlobTableKeySegments.Add()

            oKeySegment.Name = "DocCode"

            oKeySegment.Value = RDOCCode

            Dim oBlob As SAPbobsCOM.Blob = oCompany.GetCompanyService().GetBlob(oBlobParams)

            Dim sContent As String = oBlob.Content

            Dim buf() As Byte = Convert.FromBase64String(sContent)

            Using oFile As New System.IO.FileStream(outFileName, System.IO.FileMode.Create)

                oFile.Write(buf, 0, buf.Length)

                oFile.Close()

            End Using

        Catch ex As Exception

            Throw ex

        End Try

    End Sub

Hi ,

Just wondering, the SaveBlobToFile, does not specify any file location,

Where does this saved to ?

Regards

Edy

maik_delly
Active Contributor
0 Kudos

Hi Edy,

it is defined in the blob params. In my example

oBlobParams.FileName = @"C:\salesorder.rpt";  


regards,

Maik


edy_simon
Active Contributor
0 Kudos

Hi Maik,

Ahhh... I missed that line.

Thanks.

Edy

Former Member
0 Kudos

Thank you, I used Maik´s solution but your is helpful too....

Answers (0)