`

Getting Spool Request Number for the Output type

    博客分类:
  • ABAP
阅读更多
refer to:http://wiki.sdn.sap.com/wiki/display/ABAP/Getting+Spool+Request+Number+for+the+Output+type

I came across this query several times to how to find the spool request number when you know the Output Type. Untill when I require the same I didn't try to think deep on it.So, I thought of putting the solution here for others also.

Whenever a print is issued, there is a corresponding entry in the table NAST along with that there is a entry in the table CMFP also. This entry is stored as an error message management og type I.

The below mention class fetch the value of spool and convert it to PDF and download.

Class Technical Name: ZCL_CREATE_PDF_SPOOL

Class Description: Convert Spool Request to PDF and Download

Class Long Description:

This class will fetch the spool request number for the given output type and download it in PDF format.

Condition Handle -

This Class can be called either by passing the Spool Number (I_SPOOL) or by passing Application Type (I_KAPPL), Object Key (I_OBJKY), Condition Type (I_KSCHL) and Run Date (I_DATE).

If all the values are passed to the class SPOOL NUMBER has the preference over the others.

Class Instantiation:  Public

Super Class: ZCL_CREATE_PDF_SPOOL

Class Attributes:

W_ERROR    Instance          Public Type   FLAG             General Flag                                                                                                 

W_SPOOL     Instance          Public Type   RSPOID         Spool request number                                                                                                                                   

C_WFMC       Constant        Public Type   CM_APLID   Error Management

C_I                  Constant        Public Type   MSGTY          Message number    

C_VN             Constant        Public Type   ARBGB          Application Area   

C_342             Constant        Public Type   MSGNR         Message number     

Class Methods: The following methods will be defined in the class:

Method Technical Name: GET_SPOOL_NUMBER

Method Description: Get Condition record to fetch the spool. This method will be called inside the method GET_PDF_FROM_SPOOL.

Declaration Level/Vision:  Instance/Private

Importing Parameters:  

I_KAPPL       Type   KAPPL                 

Application Type. This will determine the Output Type.
I_OBJKY        Type   OBJKY

Object Key. This will determine the unique key to extract records from NAST table along with KAPPL, KSCHL & DATE.
I_KSCHL       Type   KSCHL

Condition Type. This will determine the condition type for the given output type.
I_RUNDAT   Type   DATS

Creation Date. This will give the date of creation of entry in NAST table.
Exporting Parameters:

E_ERROR      Type   FLAG

Return Message. Return E for Error and S for Success.
E_SPOOL      Type   RSPOID

Spool Number. Return Spool Number.
Exceptions: None

________________________________________________________________

Method Technical Name: GET_PDF_FROM_SPOOL

Method Description: Get the PDF from the Spool number

Declaration Level/Vision:  Instance/Public

Importing Parameters: 

I_KAPPL       Type   KAPPL           OPTIONAL

Application Type. This will determine the Output Type.
I_OBJKY        Type   OBJKY           OPTIONAL

Object Key. This will determine the unique key to extract records from NAST table along with KAPPL, KSCHL & DATE.
I_KSCHL       Type   KSCHL           OPTIONAL

Condition Type. This will determine the condition type for the given output type.
I_SPOOL       Type   RSPOID         OPTIONAL

Spool Number. Spool Number to convert and download the PDF file.
I_DATE          Type   DATS              OPTIONAL

Creation Date. This will give the date of creation of entry in NAST table.
I_PATH          Type   STRING

Application Server Path. Path to download the file.
Exporting Parameters:

E_RETURN   Type   FLAG

Return Message. Return E for Error and S for Success.
Exceptions: None

Code for Method GET_SPOOL_NUMBER
METHOD get_spool_number.

**--Types Declaration
  TYPES: BEGIN OF type_nast,
         objky  TYPE na_objkey,
         erdat  TYPE dats,
         eruhr  TYPE tims,
         datvr  TYPE dats,
         uhrvr  TYPE tims,
         cmfpnr TYPE na_cmf_nr,
         END OF type_nast.

**--Table Type Declaration
  TYPES: tt_nast TYPE STANDARD TABLE OF type_nast.

**--Internal Table Declaration
  DATA: tl_nast TYPE tt_nast.

**--Field Symbols Declaration
  FIELD-SYMBOLS:<l_nast> TYPE type_nast.

**--Data Declaration
  DATA: wl_cmfpnr TYPE na_cmf_nr, "Error Management Number
        wl_temp   TYPE symsgv.

**--Check if the Importing Parameters are initial

  IF ( i_kappl IS INITIAL AND
       i_objky IS INITIAL AND
       i_kschl IS INITIAL ).

**--Retrun Error Message
    e_error = c_e.        "Return Error Message
    EXIT.

  ENDIF.

**--Extract Error Management Number from NAST table for the combination of
**--Aplication Type, Output Type & Object Key

  SELECT objky           "Object Key
         erdat           "Date of creation
         eruhr           "time of Creation
         datvr           "Date of Process
         uhrvr           "Time of Process
         cmfpnr          "Error Management Number
         FROM nast
         INTO TABLE tl_nast
         WHERE kappl = i_kappl
         AND   objky = i_objky
         AND   kschl = i_kschl
         AND   ( erdat = i_rundat
         OR      datvr = i_rundat ).

  IF sy-subrc = 0.

    SORT tl_nast BY datvr uhrvr DESCENDING.

    READ TABLE tl_nast ASSIGNING <l_nast> INDEX 1.

    IF sy-subrc = 0.
      wl_cmfpnr = <l_nast>-cmfpnr.
    ENDIF.

**--Select Message Text 1 from CMFP table based on the error management number
    SELECT SINGLE msgv1  "Message Text
           FROM cmfp
           INTO wl_temp
           WHERE aplid = c_wfmc
           AND   nr    = wl_cmfpnr
           AND   arbgb = c_vn
           AND   msgty = c_i
           AND   msgnr = c_342.

**--If the corresponding data found
    IF sy-subrc = 0.
**--Pass Spool Request Number to Corresponding export Parameter
      e_spool = wl_temp.
**--Return success message
      e_error = c_s.
    ELSE.
**--If no data found return error message
      e_error = c_e.
    ENDIF.
  ENDIF.

ENDMETHOD.

Code for Method GET_PDF_FROM_SPOOL
METHOD get_pdf_from_spool.

**--Data Declaration
  DATA: wl_numbytes   TYPE i,                            "Bytecount
        wl_pdfspoolid TYPE tsp01-rqident,                "Spool Id
        wl_jobname    TYPE tbtcjob-jobname,              "Job Name
        wl_jobcount   TYPE tbtcjob-jobcount,             "Job Count
        wl_fullpath   TYPE string.                         "File Path

**--Constants Declaration
  CONSTANTS: c_path TYPE rlgrap-filename VALUE 'C:\temp\file.pdf'.

**--Internal Table & wORK aREA dECLARATION
  DATA: tl_pdf  TYPE STANDARD TABLE OF tline,
        wal_pdf TYPE tline.

**--Clear Variable
  CLEAR w_spool.

**--Check if the Spool Number (Importing) is initial
  IF i_spool IS INITIAL.

**--Check if the Spool is initial then APPlication Type
**--Output Type, Object Key & Date are not initial
    IF ( NOT i_kappl IS INITIAL AND
         NOT i_objky IS INITIAL AND
         NOT i_kschl IS INITIAL AND
         NOT i_date  IS INITIAL ).

**--Call method GET_SPOOL_NUMBER of the same class to fetch spool number
      CALL METHOD me->get_spool_number
        EXPORTING
          i_kappl  = i_kappl
          i_objky  = i_objky
          i_kschl  = i_kschl
          i_rundat = i_date
        IMPORTING
          e_error  = w_error
          e_spool  = w_spool.

**--Check Return Message
      IF w_error = c_e.
**--Return Error Message
        e_return = w_error.
        EXIT.
      ENDIF.

    ENDIF.

  ELSE.
**--If successful pass the apool number to local variable
    w_spool = i_spool.

  ENDIF.

**--Check Spool Number is inital
  IF NOT w_spool IS INITIAL.

**--Call FM CONVERT_OTFSPOOLJOB_2_PDF to convert the spool to PDF

    CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
      EXPORTING
        src_spoolid              = w_spool
        no_dialog                = ' '
      IMPORTING
        pdf_bytecount            = wl_numbytes
        pdf_spoolid              = wl_pdfspoolid
        btc_jobname              = wl_jobname
        btc_jobcount             = wl_jobcount
      TABLES
        pdf                      = tl_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.

**--Check if the PDF Return table is initial
    IF tl_pdf IS NOT INITIAL.
**--Pass Download file path
      wl_fullpath = c_path.
*--Check if the call is in Foreground or Background
      IF sy-batch NE 'X'.

**--Call FM GUI_DOWNLOAD to download the file in Foreground/Presentation Server

        CALL METHOD cl_gui_frontend_services=>gui_download
          EXPORTING
            bin_filesize = wl_numbytes
            filename     = wl_fullpath
            filetype     = 'BIN'
          IMPORTING
            filelength   = wl_numbytes
          CHANGING
            data_tab     = tl_pdf.

**--Return Success message if File downloaded to given path
        IF sy-subrc = 0.
          e_return = c_s.
        ENDIF.

      ELSE.
**--Call OPEN Dataset to download in Background/Aplication Server
        OPEN DATASET wl_fullpath FOR OUTPUT IN BINARY MODE.

        IF sy-subrc = 0.
          CLEAR: wal_pdf.
**--Trnasfer contents to detination file
          LOOP AT tl_pdf INTO wal_pdf.
            TRANSFER wal_pdf TO wl_fullpath.
            CLEAR: wal_pdf.
          ENDLOOP.
**--Close the file
          CLOSE DATASET wl_fullpath.
**--Return Success mesage
          e_return = c_s.
        ELSE.
**--Return Error Message
          e_return = c_e.
        ENDIF.
      ENDIF.
    ENDIF.
  ELSE.
**--Return Error Message
    e_return = c_e.
  ENDIF.

ENDMETHOD.
分享到:
评论

相关推荐

    spool oracle数据导出

    stmt.execute("SPOOL output.sql"); // 假设这是在SQL*Plus环境下的操作 stmt.executeQuery(sql); System.out.println("SPOOLING OFF"); stmt.execute("SPOOL OFF"); } catch (Exception e) { e....

    Oracle9i spool续写实例

    Oracle的Spool功能是数据库管理员和开发人员常用的一种工具,用于将SQL查询结果或PL/SQL块的输出重定向到文本文件中,而非在屏幕显示。在Oracle 10g及更高版本中,Spool引入了`CREATE`, `REPLACE`, 和 `APPEND` 参数...

    测试中可以一用的命令spool

    SPOOL output.txt SELECT * FROM your_table; SPOOL OFF ``` 执行以上命令后,`your_table`表的所有数据都会被写入到“output.txt”文件中。 此外,`spool`还可以与其他命令结合使用,例如`append`模式,使得每次`...

    oracle spool

    ### Oracle Spool 常见用法详解 在Oracle数据库管理与操作中,`Spool`命令是一项非常实用的功能,它允许用户将SQL查询结果、命令执行情况等输出到一个文件中,而不是显示在屏幕上。这对于批量处理数据、保存查询...

    关于spool 和 sqlldr 的实例代码

    在数据库管理中,`Spool` 和 `SQL*Loader` 是两种非常重要的工具,尤其在数据导入导出和批量处理方面。本实例将探讨如何在Linux环境下利用Shell脚本配合这两种工具实现高效的数据操作。 首先,`Spool` 是Oracle SQL...

    oracle sqlplus 中spool 的使用

    ### Oracle SQLPlus中Spool命令的使用详解 在Oracle数据库管理与开发过程中,SQLPlus作为一款功能强大的命令行工具被广泛使用。其中,`spool`命令是SQLPlus中的一个重要特性,它允许用户将SQL查询结果或命令输出到...

    spool常用设置

    这将把接下来的所有输出都重定向到指定的`output.txt`文件中,直到使用`spool off`命令关闭该重定向功能。 #### 常用设置详解 在使用`spool`命令时,常常会结合其他设置命令来优化输出格式,提高输出效率。下面...

    Oracle_spool_用法详解

    ### Oracle Spool 用法详解 #### 一、Spool 命令简介 `Spool` 是 Oracle SQL*Plus 工具中的一个重要命令,用于将查询结果或 SQL 脚本执行过程中产生的输出重定向到一个外部文件中。这对于批量处理数据、备份查询...

    spool导出与sqlldr导入

    在Oracle数据库管理中,"spool"和"sqlldr"是两种非常实用的工具,用于数据的导出和导入操作。下面将详细解释这两个概念及其使用方法。 **1. Spool导出** Spool是Oracle SQL*Plus中的一个功能,它允许用户将SQL*...

    打印信息获取(分析SPOOL文件)

    每一个打印任务在发送给打印机前都会将任务压缩成制定文件(SHD, SPL)一...这里提供了可以解析spool的工具以及根据其方法自己编写的解析spool文件的示例代码,虽然不是很全面,但是只要看明白,剩下的均可自己实现。

    spool和set的基本用法

    根据日常应用整理归纳的,spool和set用法总结,希望对大家有用。

    windows和unix下通过spool导出oracle数据(导成insert语句)

    4. **结束spool**:导出完成后,使用`SPOOL OFF`命令关闭spool功能,此时SQL*Plus的输出会返回到屏幕。 5. **整理文件**:在导出的文件中,可能需要进一步的编辑和处理,比如删除多余的信息,添加合适的头尾注释,...

    ERP系统信息化资料:SPOOL2SAP 入门培训.DOC

    ERP系统信息化资料:SPOOL2SAP 入门培训.DOC

    Oracle spool 元数据(过程、函数、包、类型)导出

    Oracle Spool元数据导出是数据库管理中一个关键的操作,主要用于备份或迁移Oracle数据库中的过程、函数、包和类型等对象。这些对象是PL/SQL编程的基础,它们定义了数据库中自定义的操作逻辑和数据处理规则。下面我们...

    操作系统安全:var spool cron.docx

    cron的配置位于/var/spool/cron目录下,每个用户都有一个对应的cron文件,比如root用户的cron文件是/var/spool/cron/root。系统管理员可以通过crontab命令来管理这些文件,如使用`crontab -e -u root`编辑root用户的...

    How To Save MRP List To Soft Copy

    5. Download Method 1 - Menu &gt; Spool request &gt; Forward &gt; Export as text. 5 6. Download Method 1 - File is downloaded into the directory of C: Drive . 7 7. Download Method 1 - C: Drive C:\Documents and ...

    EMFSpoolfileReader.zip_EMF SPOOLFILE_emf_emfspoolfilereader_spoo

    "EMF Spoolfile Reader" 是一个工具,专门设计用来读取和处理打印机的SPOOL文件,特别是那些以EMF格式编码的文件。这种工具允许用户查看、翻页和预览打印作业,而无需实际打印。这对于调试打印问题、检查文档布局...

    spool:通过函数的线程参数

    线轴 npm install spool spool采用以下功能: function add ( a , b ) { return a + b}function sub ( a , b ) { return a - b}add ( sub ( add ( 1 , 9 ) , 2 ) , 5 ) // 13 并让您这样称呼他们: import spool ...

    Vibration-insensitive fiber spool for laser stabilization

    Excess frequency noise induced by mechanical vibration is the dominant noise ... By carefully choosing the optimal geometry parameters of the fiber spool, we achieve acceleration sensitivity of 8 × 10

Global site tag (gtag.js) - Google Analytics