Home > SAP software/management Tips > SAP ABAP/Java developer tips > Convert SAPScript or ABAP lists to PDF format
SAP Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

SAP ABAP/JAVA DEVELOPER TIPS

Convert SAPScript or ABAP lists to PDF format


Mani Ramakrishnan
09.26.2002
Rating: -2.31- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


SAP has provided a standard program in 4.6C, RSTXPDFT4, which you can use to convert any Spool request or ABAP Lists to a PDF File.

This proved to be quite useful as we can save reports and other printouts in read-only format (PDF).

This could be a temporary solution for many reports/formats which need to be communicated beyond company's boundaries - like vendors/customers/partners/legal advisors and so on. The program is tested in 4.6C, but will probably work with earlier versions as well.



Code

REPORT RSTXPDFT4 line-size 80.
*
* Read spool job contents (OTF or ABAP list) and convert
* to PDF, download PDF
*
PARAMETERS:
  SPOOLNO LIKE TSP01-RQIDENT,
  DOWNLOAD AS CHECKBOX DEFAULT 'X',
  P_FILE LIKE RLGRAP-FILENAME DEFAULT 'C:tempfile.pdf'. "#EC NOTEXT
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.
tables: tsp01.

select single * from tsp01 where rqident = spoolno.
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
*           CHARCO        =
*           CREATER       =
*           CREDATE       =
*           DELDATE       =
*           MAX_CREDATE   =
*           MAX_DELDATE   =
*           NON_UNIQ      =
*           NOOF_PARTS    =
*           RECTYP        =
*           SIZE          =
*           STOTYP        =
            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                    = spoolno
        NO_DIALOG                      = ' '
*       DST_DEVICE                     =
*       PDF_DESTINATION                =
      IMPORTING
        PDF_BYTECOUNT                  = numbytes
        PDF_SPOOLID                    = pdfspoolid
*       OTF_PAGECOUNT                  =
        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.
  case sy-subrc.
  when 0.
    WRITE: / 'Funktion CONVERT_OTFSPOOLJOB_2_PDF erfolgreich'(001)
          COLOR COL_POSITIVE.
  when 1.
    WRITE: / 'Kein OTF- und kein ABAP-Spoolauftrag'(002)
          COLOR COL_negative.
    exit.
  when 2.
    WRITE: / 'Spoolauftrag existiert nicht'(003)
          COLOR COL_negative.
    exit.
  when 3.
    WRITE: / 'Keine Berechtigung zum Lesen Spoolauftrag'(004)
          COLOR COL_negative.
    exit.
  when others.
    WRITE: / 'Fehler bei Funktion CONVERT_OTFSPOOLJOB_2_PDF'(005)
              COLOR COL_negative.
    exit.
  endcase.
else.
  CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
      EXPORTING
        SRC_SPOOLID                    = spoolno
        NO_DIALOG                      = ' '
*       DST_DEVICE                     =
*       PDF_DESTINATION                =
      IMPORTING
        PDF_BYTECOUNT                  = numbytes
        PDF_SPOOLID                    = pdfspoolid
*       LIST_PAGECOUNT                 =
        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.
  case sy-subrc.
  when 0.
    WRITE: / 'Funktion CONVERT_ABAPSPOOLJOB_2_PDF erfolgreich'(006)
          COLOR COL_POSITIVE.
  when 1.
    WRITE: / 'Kein OTF- und kein ABAP-Spoolauftrag'(002)
          COLOR COL_negative.
    exit.
  when 2.
    WRITE: / 'Spoolauftrag existiert nicht'(003)
          COLOR COL_negative.
    exit.
  when 3.
    WRITE: / 'Keine Berechtigung zum Lesen Spoolauftrag'(004)
          COLOR COL_negative.
    exit.
  when others.
    WRITE: / 'Fehler bei Funktion CONVERT_ABAPSPOOLJOB_2_PDF'(007)
              COLOR COL_negative.
    exit.
  endcase.
endif.
*************** download PDF file ***********
check download = 'X'.
if not ( jobname is initial ).
  WRITE: / 'Konvertierung per Hintergrundjob'(008)
            COLOR COL_normal,
            jobname, jobcount.
  exit.
endif.
CALL FUNCTION 'DOWNLOAD'
     EXPORTING
          BIN_FILESIZE            = NUMBYTES
          FILENAME                = P_FILE
          FILETYPE                = 'BIN'
     IMPORTING
          ACT_FILENAME            = P_FILE
          FILESIZE                = NUMBYTES
          CANCEL                  = CANCEL
     TABLES
          DATA_TAB                = PDF.
if cancel = space.
  WRITE: / NUMBYTES, 'Bytes heruntergeladen in Datei'(009), P_FILE.
endif.


Rate this Tip
To rate tips, you must be a member of SearchSAP.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
SAP ABAP/Java developer tips
How to do additional dialog processing after SAP COMMIT WORK statement
How to find a piece of SAP ABAP code without debugging
How to read an SAP transaction in an ABAP code
How to provide an SAP R/3 4.5B application server with a Web service interface
How to find owners and transports of deleted ABAP programs
Fixing a common OPEN_FORM and START_FORM error in SAPscript
Select Text fields: Case-insensitive
Is this the quickest way to find a BADI?
Easily debug error messages in SAP processes
Accessing private attributes in ABAP Objects

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



NetWeaver SAP White Papers
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
SearchSAP.com is a search service provided by TechTarget and is completely
independent of and not affiliated with SAP AG.
  TechTarget - The IT Media ROI Experts