There are sometimes specific need to create a single spool request combining number of spool requests together, generated for a given job.

The following program creates a single spool merging all the other spools creted when the job is run. The program needs to be added as the last member in the same job for which the other spool requests nee to be merged.

The main program is as follows:

REPORT  z_spool_merge NO STANDARD PAGE HEADING
                            MESSAGE-ID 00
                            LINE-SIZE 1023
                            LINE-COUNT 60.
************************************************************************
* Includes                                                             *
************************************************************************
  INCLUDE z_spool_top.     ” Data Declaration
  INCLUDE z_spool_gui.     ” Selection screen
  INCLUDE z_spool_cd1.     ” Class definition
  INCLUDE z_spool_ci1.     ” Class implementation

************************************************************************
*   START-OF-SELECTION                                                 *
************************************************************************
  START-OF-SELECTION.
    CREATE OBJECT ob_ref_application.

Include Programs:

INCLUDE z_spool_top.     ” Data Declaration

************************************************************************
* Class Definition and Declaration
************************************************************************
CLASS lcl_application        DEFINITION DEFERRED.
DATA: ob_ref_application     TYPE REF TO lcl_application,
      bdcdata TYPE STANDARD TABLE OF  bdcdata WITH HEADER LINE.

  INCLUDE z_spool_cd1.     ” Class definition

*———————————————————————-*
*       INTERFACE if_data_declaration DEFINITION
*———————————————————————-*
*
*———————————————————————-*
INTERFACE if_data_declaration .
  TYPES: BEGIN OF ty_tbtcp,
            jobname   TYPE btcjob,
            jobcount  TYPE btcjobcnt,
            stepcount TYPE btcstepcnt,
            listident TYPE btclistid,
            pdest     TYPE sypdest,
            END OF ty_tbtcp,
            BEGIN OF ty_spoolid,
            spoolid TYPE btclistid,
            END OF ty_spoolid.
ENDINTERFACE.                    “if_data_declaration DEFINITION

*———————————————————————-*
*       CLASS lcl_application DEFINITION
*———————————————————————-*
*
*———————————————————————-*
CLASS lcl_application DEFINITION.

  PUBLIC SECTION.
    INTERFACES if_data_declaration.
    METHODS: constructor.

  PRIVATE SECTION.
* LOCAL DATA DECLARATION
    DATA:  lwa_tbtcp TYPE if_data_declaration~ty_tbtcp,
           ltb_tbtcp TYPE STANDARD TABLE OF if_data_declaration~ty_tbtcp,
           ltb_spoolid TYPE STANDARD TABLE OF if_data_declaration~ty_spoolid,
           lwa_spoolid TYPE if_data_declaration~ty_spoolid,
           lwa_buffer(200) TYPE c,
           ltb_buffer LIKE STANDARD TABLE OF lwa_buffer,
           ltb_buffer_final LIKE STANDARD TABLE OF lwa_buffer,
           lwa_handle TYPE sy-tabix,
           lw_rqident TYPE tsp01-rqident,
           lw_jobcount TYPE btcjobcnt.

    METHODS:   get_table_data,
               process_data.

ENDCLASS.                    “lcl_application DEFINITION
*———————————————————————-*
*       CLASS lcl_exception DEFINITION
*———————————————————————-*
*
*———————————————————————-*
CLASS lcl_exception DEFINITION INHERITING FROM cx_static_check.

  PUBLIC SECTION.
    DATA: lw_text TYPE zadeu_s_ecm_data_alv-message.

    METHODS:
      constructor
        IMPORTING i_text TYPE zadeu_s_ecm_data_alv-message.

ENDCLASS.                    “lcl_exception DEFINITION

INCLUDE z_spool_ci1.     ” Class implementation

———————————————————————-*
*       CLASS lcl_application IMPLEMENTATION
*———————————————————————-*
*
*———————————————————————-*
  CLASS lcl_application IMPLEMENTATION.

    METHOD constructor.
      DATA: lob_exec TYPE REF TO lcl_exception.
      TRY.
          CALL METHOD me->get_table_data.
          CALL METHOD me->process_data.
        CATCH lcl_exception INTO lob_exec.
          MESSAGE s208  WITH lob_exec->lw_text.
      ENDTRY.
    ENDMETHOD.                    “constructor

    METHOD get_table_data.
      SELECT MAX( jobcount )
      INTO lw_jobcount
      FROM tbtcp
      WHERE  jobname = p_jbnam
      AND    sdldate = sy-datum.
      IF sy-subrc = 0.
        SELECT  spoolid
        INTO TABLE ltb_spoolid
        FROM  tbtc_spoolid
        WHERE jobname = p_jbnam
        AND jobcount = lw_jobcount.
      ENDIF.
    ENDMETHOD.                    “get_table_data

    METHOD process_data.
* Begin of changes************************
      DATA : w_arcpar TYPE arc_params  ,
             w_pripar TYPE pri_params ,
             w_val TYPE c .
* End of changes**************************

*   Begin of changes**********************
*      IF ltb_spoolid IS NOT INITIAL.
*        IF sy-batch = ‘X’.
          CALL FUNCTION ‘GET_PRINT_PARAMETERS’
            EXPORTING
              destination            = ‘LOCL’
              layout                 = ‘X_65_255’
              line_count             = 65
              line_size              = 255
              no_dialog              = ‘ ‘
            IMPORTING
              out_parameters         = w_pripar
              out_archive_parameters = w_arcpar
              valid                  = w_val.
*
*          NEW-PAGE PRINT ON NEW-SECTION
*                        PARAMETERS w_pripar
*                        ARCHIVE PARAMETERS w_arcpar
*                        NO DIALOG.
*          Write:/ ‘Hello’.
*
*
*          NEW-PAGE PRINT OFF.
*        ENDIF.
*      ENDIF.
* End of changes*******************
      IF ltb_spoolid IS NOT INITIAL.
        LOOP AT ltb_spoolid INTO lwa_spoolid.
          CLEAR lw_rqident.
          lw_rqident = lwa_spoolid-spoolid.
          REFRESH ltb_buffer.
          CALL FUNCTION ‘RSPO_RETURN_ABAP_SPOOLJOB’
            EXPORTING
              rqident              = lw_rqident
            TABLES
              buffer               = ltb_buffer
            EXCEPTIONS
              no_such_job          = 1
              not_abap_list        = 2
              job_contains_no_data = 3
              selection_empty      = 4
              no_permission        = 5
              can_not_access       = 6
              read_error           = 7
              OTHERS               = 8.
          IF sy-subrc <> 0.
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          ELSE.
            IF ltb_buffer_final IS INITIAL.
              ltb_buffer_final = ltb_buffer.
            ELSE.
              LOOP AT ltb_buffer INTO lwa_buffer.
                APPEND lwa_buffer TO ltb_buffer_final.
              ENDLOOP.
            ENDIF.
          ENDIF.
        ENDLOOP.
        READ TABLE ltb_tbtcp INTO lwa_tbtcp INDEX 1.
        CALL FUNCTION ‘RSPO_OPEN_SPOOLREQUEST’
          EXPORTING
            dest            = lwa_tbtcp-pdest
            name            = w_pripar
            suffix1         = w_arcpar
            suffix2         = w_val
            copies          = 1
            immediate_print = ‘G’
            doctype         = ‘LIST’
          IMPORTING
            handle          = lwa_handle.

        LOOP AT ltb_buffer_final INTO lwa_buffer.
          CALL FUNCTION ‘RSPO_WRITE_SPOOLREQUEST’
            EXPORTING
              handle           = lwa_handle
              text             = lwa_buffer
            EXCEPTIONS
              handle_not_valid = 1
              OTHERS           = 2.
          IF sy-subrc <> 0.
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          ENDIF.
        ENDLOOP.

        CALL FUNCTION ‘RSPO_CLOSE_SPOOLREQUEST’
          EXPORTING
            handle           = lwa_handle
          EXCEPTIONS
            handle_not_valid = 1
            OTHERS           = 2.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
      ENDIF.
    ENDMETHOD.                    “process_data
  ENDCLASS.                    “lcl_application IMPLEMENTATION
*———————————————————————-*
*       CLASS lcl_exception IMPLEMENTATION
*———————————————————————-*

  CLASS lcl_exception IMPLEMENTATION.
* Class for raising message & display it into the screen
    METHOD constructor.
      super->constructor( ).
      me->lw_text = i_text.

    ENDMETHOD.                    “constructor

  ENDCLASS.                    “lcl_exception IMPLEMENTATION

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Bruce Tjosvold

    You have a custom object in your code. What is the definition of this,  zadeu_s_ecm_data_alvmessage   ???????


    class lcl_exception definition inheriting from cx_static_check.

       public section.
         data: lw_text type zadeu_s_ecm_data_alvmessage.

         methods:
           constructor
             importing i_text type zadeu_s_ecm_data_alvmessage.

    endclass.                    “lcl_exception DEFINITION

    (0) 

Leave a Reply