Skip to Content
author's profile photo Former Member
Former Member

SAP sales quotes in PDF via BAPI

We have SAP 4.6C installed at our organisation. I'm currently creating sales quotes via a front-end and .NCo 2.0. I can also retrieve the quote data from another BAPI. This all works great.

Currently we have a mechanism that allows our sales folks to get the quotes in PDF via the SAP GUI. This PDF is emailed to them. The PDF is pre-formatted and has all the legal verbiage too. I would like to retrieve this PDF file via a BAPI (probably a custom one that needs to be created).

From what i've been told by the SAP tech guys at out org that it's probably not possible or they need time to research. They did mention that a quick solution might be to trigger a batch command that will do some emulation and will email that PDF to a certain account (based on a BAPI call where i pass in the quote number and email address).

So my questions:

1. Has anyone tapped into the PDF quote creation process in SAP? Any thoughts on whether it will be possible to do this via a BAPI?

2. Is there anyway to have a BAPI stream back data? I've used those BAPI_DOCUMENT_GET bapis that was really using FTP behind the scenes but i'm talking about getting file data back from the normal RPC.

Any thoughts is much appreciated.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Dec 17, 2004 at 03:56 PM

    Hi Hithesh,

    Yes, I am doing this for our customer inquiry web site.

    Customers view order confirmations, packing lists, invoices and bill of ladings as PDF's in their browsers.

    Here is what I did:

    I created an RFC that takes a document type and document number as arguments.

    The RFC then reprints the document via a BDC.

    The RFC grabs the resulting spool file and via

    CONVERT_OTFSPOOLJOB_2_PDF, creates the PDF in an ABAP table.

    The RFC passes the table to my C# application and I make a byte array out of it.

    I pass the byte array to ASP.NET via System.Web.HttpContext and System.Web.HttpResponse.

    The PDF is displayed in a browser window.

    This is fairly high level so if you need some further clarification, let me know.

    Andy Jacobs

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2005 at 09:29 PM

    Thanks for the code that was posted.

    Here is my issue. I followed all the above suggestions, but I am getting an error when you open the PDF file. The error is "An unrecognized token 'q0.80' was found", any ideas?

    Here is My code.

    RFC Function

    FUNCTION Z_RFC_SPOOL_TO_PDF.

    *"----


    ""Local interface:

    *" IMPORTING

    *" VALUE(SPOOL_ID) TYPE TSP01-RQIDENT

    *" EXPORTING

    *" VALUE(BYTE_SIZE) TYPE TST01-DSIZE

    *" TABLES

    *" PDF_OUTPUT STRUCTURE SOLISTI1 OPTIONAL

    *"----


    DATA otf like itcoo occurs 100 with header line.

    DATA CANCEL.

    DATA PDF LIKE TLINE OCCURS 100 WITH HEADER LINE.

    DATA DOCTAB LIKE DOCS OCCURS 1 WITH HEADER LINE.

    DATA: NUMBYTES TYPE I,

    ARC_IDX LIKE TOA_DARA,

    pdfspoolid like tsp01-rqident,

    jobname like tbtcjob-jobname,

    jobcount like tbtcjob-jobcount,

    is_otf.

    data: client like tst01-dclient,

    name like tst01-dname,

    objtype like rststype-type,

    type like rststype-type.

    DATA: gd_buffer TYPE string.

    DATA: it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE.

    tables: tsp01.

    select single * from tsp01 where rqident = SPOOL_ID.

    if sy-subrc <> 0.

    WRITE: / 'Spoolauftrag existiert nicht'(003)

    COLOR COL_negative.

    exit.

    endif.

    client = tsp01-rqclient.

    name = tsp01-rqo1name.

    CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

    EXPORTING

    AUTHORITY = 'SP01'

    CLIENT = client

    NAME = name

    PART = 1

    IMPORTING

    TYPE = type

    OBJTYPE = objtype

    EXCEPTIONS

    FB_ERROR = 1

    FB_RSTS_OTHER = 2

    NO_OBJECT = 3

    NO_PERMISSION = 4.

    if objtype(3) = 'OTF'.

    is_otf = 'X'.

    else.

    is_otf = space.

    endif.

    if is_otf = 'X'.

    CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

    EXPORTING

    SRC_SPOOLID = SPOOL_ID

    NO_DIALOG = ' '

    IMPORTING

    PDF_BYTECOUNT = numbytes

    PDF_SPOOLID = pdfspoolid

    BTC_JOBNAME = jobname

    BTC_JOBCOUNT = jobcount

    TABLES

    PDF = pdf

    EXCEPTIONS

    ERR_NO_OTF_SPOOLJOB = 1

    ERR_NO_SPOOLJOB = 2

    ERR_NO_PERMISSION = 3

    ERR_CONV_NOT_POSSIBLE = 4

    ERR_BAD_DSTDEVICE = 5

    USER_CANCELLED = 6

    ERR_SPOOLERROR = 7

    ERR_TEMSEERROR = 8

    ERR_BTCJOB_OPEN_FAILED = 9

    ERR_BTCJOB_SUBMIT_FAILED = 10

    ERR_BTCJOB_CLOSE_FAILED = 11.

    else.

    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

    EXPORTING

    SRC_SPOOLID = SPOOL_ID

    NO_DIALOG = ' '

    IMPORTING

    PDF_BYTECOUNT = numbytes

    PDF_SPOOLID = pdfspoolid

    BTC_JOBNAME = jobname

    BTC_JOBCOUNT = jobcount

    TABLES

    PDF = pdf

    EXCEPTIONS

    ERR_NO_ABAP_SPOOLJOB = 1

    ERR_NO_SPOOLJOB = 2

    ERR_NO_PERMISSION = 3

    ERR_CONV_NOT_POSSIBLE = 4

    ERR_BAD_DESTDEVICE = 5

    USER_CANCELLED = 6

    ERR_SPOOLERROR = 7

    ERR_TEMSEERROR = 8

    ERR_BTCJOB_OPEN_FAILED = 9

    ERR_BTCJOB_SUBMIT_FAILED = 10

    ERR_BTCJOB_CLOSE_FAILED = 11.

    endif.

    • Transfer the 132-long strings to 255-long strings

    LOOP AT pdf.

    TRANSLATE pdf USING ' ~'.

    CONCATENATE gd_buffer pdf INTO gd_buffer.

    ENDLOOP.

    TRANSLATE gd_buffer USING '~ '.

    DO.

    it_mess_att = gd_buffer.

    APPEND it_mess_att.

    SHIFT gd_buffer LEFT BY 255 PLACES.

    IF gd_buffer IS INITIAL.

    EXIT.

    ENDIF.

    ENDDO.

    *

    PDF_OUTPUT[] = it_mess_att[].

    byte_size = numbytes.

    ENDFUNCTION.

    Here is my code from vb.net using the .net connector

    Dim tSAP As Boolean

    Dim compcode As String

    Dim byteSize As Integer

    Dim pdft As New SOLISTI1Table

    Try

    tSAP = TestSAPConn()

    If tSAP <> True Then

    Return Nothing

    End If

    SAPFunctions.Z_Rfc_Spool_To_Pdf(18158, byteSize, pdft)

    Dim ds As DataSet = New DataSet

    ds.Tables.Add(pdft.ToADODataTable)

    Dim sb As StringBuilder = New StringBuilder

    For Each dr As DataRow In ds.Tables(0).Rows

    Dim dataline As String = dr(0)

    If dataline.Length < 134 Then

    dataline = dataline.PadRight(134, " ")

    End If

    sb.Append(dataline)

    Next

    Dim pdf As String = sb.ToString

    Dim encoding As Encoding = encoding.ASCII

    Dim pdfLength As Integer = pdf.Length

    Dim filename As String = "testPDF.pdf"

    Dim pdfBtyes() As Byte = encoding.GetBytes(pdf.ToCharArray(), 0, pdfLength)

    If File.Exists(Application.StartupPath + "\" + filename) Then

    File.Delete(Application.StartupPath + "\" + filename)

    End If

    Dim ot As New FileStream(Application.StartupPath + "\" + filename, FileMode.Create)

    ot.Write(pdfBtyes, 0, pdfLength)

    ot.Close()

    If compcode <> "" Then

    Return compcode

    Else

    Return Nothing

    End If

    Catch ex As Exception

    MessageBox.Show(ex.Message)

    Return Nothing

    Exit Function

    End Try

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Ryan,

      Was able to send out a email with a pdf Attachment in a different way. We just read the spool contents using FM RSPO_RETURN_SPOOLJOB(in OTF format) and sent the same out as a "OTF" attachment using the FM 'SO_DOCUMENT_SEND_API1'. We let the system do the conversion using the conversion rules setup for email (From OTF to PDF), in transaction SCOT and it worked perfectly. I guess, we will use this solution.

      Thanks again.

      Regards

      Narasimhan

  • author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2007 at 09:58 AM

    Hi,

    I too got a same error in PDF "Unrecognised token Td0 was found".

    The Problem is that in my SAP-Code i have been translated the PDF into 255 string.But i am retreiving using 132 string.So, i resolved in this way.

    <b>For Each dr As DataRow In ds.Tables(0).Rows

    Dim dataline As String = dr(0)

    If dataline.Length < 255 Then

    dataline = dataline.PadRight(255, " ")

    End If

    sb.Append(dataline)

    Next.</b>

    This code worked Perfectly in my code.

    May be this Thread is useful to Others.

    Regards,

    Rajender.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.