Summary:

The content in this document helps us to  Creates a Spool request–> convert it into a PDF –> Send PDF as mail attachment.

CODE:

*****Select NAST entry based on the input parameter(p_docno)

SELECT *

       FROM nast INTO TABLE gint_nast WHERE objky EQ p_docno.

                                      

DELETE ADJACENT DUPLICATES FROM gint_nast COMPARING kschl.

********Convert current time stamp into UTC format before creating the spool (START TIME)

cl_abap_tstmp=>systemtstmp_syst2utc(               “timestamp in UTC

       EXPORTING

         syst_date = sydatum

         syst_time = syuzeit

       IMPORTING

         utc_tstmp = gw_starttime ).

*******Pass NAST entry and create a spool request using RSNAST00

IF gws_nastvstat = gc_1.

     gws_nasterdat = sydatum.

     gws_nasteruhr = syuzeit.

     gws_nastusnam = syuname.

     gws_nastmanue = gc_x.

     gws_nastvstat = 0.

     CLEAR gws_nastdatvr.

     CLEAR gws_nastuhrvr.

     CLEAR gws_nastcmfpnr.

   ENDIF.

   MOVE gws_nast TO nast.

   PERFORM einzelnachricht_dialog IN PROGRAM rsnast00 USING sysubrc.

   IF sysubrc NE 0.

     PERFORM objekt_entsperren IN PROGRAM rsnast00.

     IF sysubrc EQ 9.

       RAISE print_error_dial.

     ELSE.

       RAISE print_error.

     ENDIF.

   ENDIF.

   SET SCREEN 0.

   PERFORM objekt_entsperren IN PROGRAM rsnast00.

   COMMIT WORK AND WAIT.


*************************************Convert current time stamp into UTC format before creating the spool (END TIME)

  cl_abap_tstmp=>systemtstmp_syst2utc(                         “timestamp in UTC

    EXPORTING

      syst_date = sydatum

      syst_time = syuzeit

    IMPORTING

      utc_tstmp = gw_endtime ).

***********************Fetch Spool numbers from TSP01

   gw_start = gw_starttime.

   CONCATENATE gw_start gc_00 INTO gw_start.

   CONDENSE gw_start NOGAPS.

   gw_end = gw_endtime.

   CONCATENATE gw_end gc_00 INTO gw_end.

   CONDENSE gw_end NOGAPS.

   SELECT * FROM tsp01 INTO TABLE gint_tsp01           “fetch spools from TSP01

     WHERE rqclient EQ symandt

     AND rqowner EQ syuname

     AND rqcretime BETWEEN gw_start AND gw_end.

************************Get Spool Type

SELECT SINGLE * FROM tsp01 INTO w_tsp01 WHERE rqident = w_rqident.

   IF sysubrc <> 0.

     MESSAGE e126(po) WITH w_rqident RAISING no_such_job.

   ENDIF.

* Checks if the job is OTF

   CALL FUNCTION ‘RSPO_GET_TYPE_SPOOLJOB’

     EXPORTING

       rqident        = w_rqident

     IMPORTING

       is_otf         = lw_data_is_otf

     EXCEPTIONS

       can_not_access = 1

       OTHERS         = 2.

   IF sysubrc <> 0.

     MESSAGE ID symsgid TYPE symsgty NUMBER symsgno

             WITH symsgv1 symsgv2 symsgv3 symsgv4.

   ENDIF.


IF lw_data_is_otf = ‘X’.

*************Convert OTF JOB into a PDF


CALL FUNCTION ‘CONVERT_OTFSPOOLJOB_2_PDF’

        EXPORTING

             src_spoolid              = w_rqident

             no_dialog                = ‘X’

*      IMPORTING

*           PDF_BYTECOUNT            = L_BYTECOUNT

        TABLES

             pdf                      = it_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.

   IF sysubrc = 0.

* For page formatting

     CALL FUNCTION ‘QCE1_CONVERT’

       TABLES

         t_source_tab         = it_pdf

         t_target_tab         = objcont

*t_target_tab         = gws_objcont

*        t_target_tab         = it_pdf

       EXCEPTIONS

         convert_not_possible = 1

         OTHERS               = 2.

     IF sysubrc <> 0.

       MESSAGE ID symsgid TYPE symsgty NUMBER symsgno

               WITH symsgv1 symsgv2 symsgv3 symsgv4.

     ENDIF.

   ELSE.

     MESSAGE ID symsgid TYPE symsgty NUMBER symsgno

             WITH symsgv1 symsgv2 symsgv3 symsgv4.

   ENDIF.


ELSE.

*************Convert ABAP JOB into a PDF

CALL FUNCTION ‘CONVERT_ABAPSPOOLJOB_2_PDF’

        EXPORTING

             src_spoolid              = w_rqident

             no_dialog                = ‘X’

*      IMPORTING

*           PDF_BYTECOUNT            = L_BYTECOUNT

        TABLES

             pdf                      = it_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.

   IF sysubrc = 0.

* For page formatting

     CALL FUNCTION ‘QCE1_CONVERT’

       TABLES

         t_source_tab         = it_pdf

         t_target_tab         = objcont

       EXCEPTIONS

         convert_not_possible = 1

         OTHERS               = 2.

     IF sysubrc <> 0.

       MESSAGE ID symsgid TYPE symsgty NUMBER symsgno

               WITH symsgv1 symsgv2 symsgv3 symsgv4.

     ENDIF.

   ELSE.

     MESSAGE ID symsgid TYPE symsgty NUMBER symsgno

             WITH symsgv1 symsgv2 symsgv3 symsgv4.

   ENDIF.

***********Convert PDF into HEX

IF NOT objcont[] IS INITIAL.

         REFRESH int_bin_cont.

         TRY.

             CALL METHOD cl_bcs_convert=>soli_to_solix

               EXPORTING

                 it_soli  = objcont[]

               RECEIVING

                 et_solix = int_bin_cont.

           CATCH cx_bcs.

             MESSAGE e445(so).

         ENDTRY.

*********Create Mail Body

        w_send_request = cl_bcs=>create_persistent( ).

         w_document = cl_document_bcs=>create_document(

               i_type    = ‘RAW’

               i_text    = int_text

               i_subject = w_sub ).

*********Add Attachment to mail Body

TRY.

               w_document->add_attachment(

               i_attachment_type    = ‘PDF’

               i_attachment_subject = mailtitle

               i_att_content_text   = objcont[]

               i_att_content_hex    = int_bin_cont[] ).

             CATCH cx_document_bcs.

*          WRITE : w_err-textid.

               MESSAGE ‘error’ TYPE ‘E’.

           ENDTRY.

***********Send to reciepients

w_send_request->set_document( w_document ).

             CLEAR gws_receivers.

             LOOP AT gint_receivers INTO gws_receivers.

               CASE gws_receiversrec_type.

                 WHEN ‘U’.

                   w_int_address = gws_receiversreceiver.

                   w_camuser = cl_cam_address_bcs=>create_internet_address( w_int_address ).

                   w_recipient = w_camuser.

                 WHEN OTHERS.

                   MESSAGE i865(so) WITH text006.

                   RAISE sending_failed.

               ENDCASE.

               w_send_request->add_recipient( w_recipient ).

             ENDLOOP.

            w_send_request->send_request->set_link_to_outbox( ‘X’ ).

             w_sent_to_all = w_send_request->send( i_with_error_screen = ‘X’ ).

             COMMIT WORK.

             IF w_sent_to_all IS INITIAL.

               RAISE sending_failed.

             ENDIF.




To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply