Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member202771
Contributor
4,941

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 = sy-datum

         syst_time = sy-uzeit

       IMPORTING

         utc_tstmp = gw_starttime ).

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

IF gws_nast-vstat = gc_1.

     gws_nast-erdat = sy-datum.

     gws_nast-eruhr = sy-uzeit.

     gws_nast-usnam = sy-uname.

     gws_nast-manue = gc_x.

     gws_nast-vstat = 0.

     CLEAR gws_nast-datvr.

     CLEAR gws_nast-uhrvr.

     CLEAR gws_nast-cmfpnr.

   ENDIF.

   MOVE gws_nast TO nast.

   PERFORM einzelnachricht_dialog IN PROGRAM rsnast00 USING sy-subrc.

   IF sy-subrc NE 0.

     PERFORM objekt_entsperren IN PROGRAM rsnast00.

     IF sy-subrc 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 = sy-datum

      syst_time = sy-uzeit

    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 NO-GAPS.

   gw_end = gw_endtime.

   CONCATENATE gw_end gc_00 INTO gw_end.

   CONDENSE gw_end NO-GAPS.

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

     WHERE rqclient EQ sy-mandt

     AND rqowner EQ sy-uname

     AND rqcretime BETWEEN gw_start AND gw_end.

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

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

   IF sy-subrc <> 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 sy-subrc <> 0.

     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

   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 sy-subrc = 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 sy-subrc <> 0.

       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

     ENDIF.

   ELSE.

     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

   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 sy-subrc = 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 sy-subrc <> 0.

       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

     ENDIF.

   ELSE.

     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

   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_receivers-rec_type.

                 WHEN 'U'.

                   w_int_address = gws_receivers-receiver.

                   w_camuser = cl_cam_address_bcs=>create_internet_address( w_int_address ).

                   w_recipient = w_camuser.

                 WHEN OTHERS.

                   MESSAGE i865(so) WITH text-006.

                   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.




1 Comment
Labels in this area