Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Spool to pdf format

Former Member
0 Likes
9,218

Hi...

In my code i used the function module CONVERT_OTFSPOOLJOB_2_PDF for converting spool to pdf format.....but iam getting runtime error .

this is my code

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

      EXPORTING

        SRC_SPOOLID                    = i_itcpp

*      NO_DIALOG                      =

*      DST_DEVICE                     =

*      PDF_DESTINATION                =

*      NO_BACKGROUND                  =

*    IMPORTING

*      PDF_BYTECOUNT                  =

*      PDF_SPOOLID                    =

*      OTF_PAGECOUNT                  =

*      BTC_JOBNAME                    =

*      BTC_JOBCOUNT                   =

*      BIN_FILE                       =

     TABLES

       PDF                            = it_pdf_output

     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

       OTHERS                         = 12

              .

    IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
8,290

Hi Everyone,

Thanx for all your replies. Bcs of ur help i completed my object. Here iam providing for future refrence.

   REPORT  ZPHF_VMS                                .

*  ----------------------------------------------------------------------*

*  &                  TABLE DECLARATION                                  *

*  ----------------------------------------------------------------------*

   TABLES : LFA1, ITCPO.                     "Vendor Master (General Section)

*  ----------------------------------------------------------------------*

*  &                    DATA DECLARATION                                 *

*  ----------------------------------------------------------------------*

   DATA : V_LIFNR TYPE LIFNR.

   DATA : I_ITCPP TYPE ITCPP.

   DATA :W_ERREUR TYPE I VALUE 0.

   DATA : STRUCT TYPE ITCPO.

   DATA: GD_RECSIZE TYPE I.

   DATA: PDFTAB TYPE TABLE OF TLINE WITH HEADER LINE,

         DATAB TYPE TABLE OF ITCOO WITH HEADER LINE.

   DATA: BINFILESIZE TYPE I,

   FILE_NAME TYPE STRING,

   FILE_PATH TYPE STRING,

   FULL_PATH TYPE STRING.

   DATA : p_email1 TYPE SZA1_D0100-SMTP_ADDR.

*  ----------------------------------------------------------------------*

*  &                    TYPE DECLARATION                                 *

*  ----------------------------------------------------------------------*

   TYPES : BEGIN OF TY_LFA1,

           LIFNR TYPE   LIFNR,

           LAND1  TYPE LAND1_GP,

           NAME1  TYPE NAME1_GP,

           NAME2  TYPE NAME2_GP,

           NAME3  TYPE NAME3_GP,

           NAME4  TYPE NAME4_GP,

           ORT01  TYPE ORT01_GP,

           ORT02  TYPE ORT02_GP,

           PFACH  TYPE PFACH,

           PSTL2  TYPE PSTL2,

           PSTLZ  TYPE PSTLZ,

           REGIO  TYPE REGIO,

           SORTL  TYPE SORTL,

           STRAS  TYPE STRAS_GP,

           SPRAS  TYPE SPRAS,

           ADRNR  TYPE ADRNR,

   END OF TY_LFA1.

*  ----------------------------------------------------------------------*

*  &                   Binary store for PDF                              *

*  ----------------------------------------------------------------------*

   DATA: BEGIN OF IT_PDF_OUTPUT OCCURS 0.

           INCLUDE STRUCTURE TLINE.

   DATA: END OF IT_PDF_OUTPUT.

*  ----------------------------------------------------------------------*

*  &                    INTERNAL TABLE  DECLARATION                      *

*  ----------------------------------------------------------------------*

   DATA : IT_LFA1 TYPE STANDARD TABLE OF TY_LFA1,

          WA_LFA1 TYPE TY_LFA1.

   DATA : T_OTF TYPE TABLE OF ITCOO.                                             "OTF Structure

*  ----------------------------------------------------------------------*

*  &                    Selection Screen DECLARATION                     *

*  ----------------------------------------------------------------------*

   SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

   SELECT-OPTIONS : S_LIFNR FOR V_LIFNR.

   PARAMETERS : P_EMAIL LIKE p_email1.

   SELECTION-SCREEN END OF BLOCK B1.

*  ----------------------------------------------------------------------*

*  &                    Start of selection                               *

*  ----------------------------------------------------------------------*

   SELECT LIFNR

         LAND1

         NAME1

         NAME2

         NAME3

         NAME4

         ORT01

         ORT02

         PFACH

         PSTL2

         PSTLZ

         REGIO

         SORTL

         STRAS

         SPRAS

         ADRNR

     FROM LFA1

     INTO TABLE IT_LFA1

     WHERE LIFNR IN S_LIFNR

     AND   SPRAS = SY-LANGU.                   "Message language

   PERFORM TRAITEMENT.

   PERFORM CONVERSION.

*  PERFORM process_email.

*  &---------------------------------------------------------------------*

*  &      Form  TRAITEMENT

*  &---------------------------------------------------------------------*

*         text

*  ----------------------------------------------------------------------*

*    -->  p1        text

*    <--  p2        text

*  ----------------------------------------------------------------------*

   FORM TRAITEMENT .

     PERFORM OPEN_FORM.

     PERFORM WRITE_FORM.

     PERFORM CLOSE_FORM.

   ENDFORM.                    " TRAITEMENT

*  &---------------------------------------------------------------------*

*  &      Form  OPEN_FORM

*  &---------------------------------------------------------------------*

*         text

*  ----------------------------------------------------------------------*

*    -->  p1        text

*    <--  p2        text

*  ----------------------------------------------------------------------*

   FORM OPEN_FORM .

     ITCPO-TDGETOTF = 'X'.

     STRUCT-TDDEST = 'LP01'.

*To specify no Print Preview

     STRUCT-TDNOPREV = 'X'.

*To access the SAP Script output in OTF format

     STRUCT-TDGETOTF = 'X'.

     CALL FUNCTION 'OPEN_FORM'

      EXPORTING

*       APPLICATION                       = 'TX'

*       ARCHIVE_INDEX                     =

*       ARCHIVE_PARAMS                    =

        DEVICE                            = 'PRINTER'

        DIALOG                            = SPACE

        FORM                              = 'ZPHF_VMS1'

        LANGUAGE                          = sy-langu        "Message language

        OPTIONS                           = STRUCT

*       MAIL_SENDER                       =

*       MAIL_RECIPIENT                    =

*       MAIL_APPL_OBJECT                  =

*       RAW_DATA_INTERFACE                = '*'

*       SPONUMIV                          =

*     IMPORTING

*       LANGUAGE                          = sy-langu

*       NEW_ARCHIVE_PARAMS                =

*       RESULT                            =

*     EXCEPTIONS

*       CANCELED                          = 1

*       DEVICE                            = 2

*       FORM                              = 3

*       OPTIONS                           = 4

*       UNCLOSED                          = 5

*       MAIL_OPTIONS                      = 6

*       ARCHIVE_ERROR                     = 7

*       INVALID_FAX_NUMBER                = 8

*       MORE_PARAMS_NEEDED_IN_BATCH       = 9

*       SPOOL_ERROR                       = 10

*       CODEPAGE                          = 11

*       OTHERS                            = 12

               .

     IF SY-SUBRC <> 0.

*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*           WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

     ENDIF.

   ENDFORM.                    " OPEN_FORM

*  &---------------------------------------------------------------------*

*  &      Form  WRITE_FORM

*  &---------------------------------------------------------------------*

*         text

*  ----------------------------------------------------------------------*

*    -->  p1        text

*    <--  p2        text

*  ----------------------------------------------------------------------*

   FORM WRITE_FORM .

     CALL FUNCTION 'WRITE_FORM'

      EXPORTING

        ELEMENT                        = 'HEADER1'

*     FUNCTION                       = 'SET'

*     TYPE                           = 'BODY'

        WINDOW                         = 'HEADER'.

     CALL FUNCTION 'WRITE_FORM'

      EXPORTING

        ELEMENT                        = 'LINE'

*     FUNCTION                       = 'SET'

*     TYPE                           = 'BODY'

        WINDOW                         = 'LINE_HD'.

     LOOP AT IT_LFA1 INTO WA_LFA1.

       CALL FUNCTION 'WRITE_FORM'

        EXPORTING

          ELEMENT                        = 'MAIN1'

*     FUNCTION                       = 'SET'

*     TYPE                           = 'BODY'

          WINDOW                         = 'MAIN'.

     ENDLOOP.

   ENDFORM.                    " WRITE_FORM

*  &---------------------------------------------------------------------*

*  &      Form  CLOSE_FORM

*  &---------------------------------------------------------------------*

*         text

*  ----------------------------------------------------------------------*

*    -->  p1        text

*    <--  p2        text

*  ----------------------------------------------------------------------*

   FORM CLOSE_FORM .

     CALL FUNCTION 'CLOSE_FORM'

     IMPORTING

     RESULT                         = I_ITCPP

*     RDI_RESULT                     =

    TABLES

      OTFDATA                        = T_OTF

      EXCEPTIONS

      UNOPENED                       = 1

      BAD_PAGEFORMAT_FOR_PRINT       = 2

      SEND_ERROR                     = 3

      SPOOL_ERROR                    = 4

      CODEPAGE                       = 5

        OTHERS                         = 6

               .

     IF SY-SUBRC <> 0.

       W_ERREUR = W_ERREUR + 1.

     ENDIF.

   ENDFORM.                    " CLOSE_FORM

*  &---------------------------------------------------------------------*

*  &      Form  CONVERSION spool to pdf format

*  &---------------------------------------------------------------------*

*         text

*  ----------------------------------------------------------------------*

*    -->  p1        text

*    <--  p2        text

*  ----------------------------------------------------------------------*

   FORM CONVERSION .

     DATA: l_xstring TYPE xstring.

     CALL FUNCTION 'CONVERT_OTF'

      EXPORTING

        FORMAT                      = 'PDF'

        MAX_LINEWIDTH               = 132

*     ARCHIVE_INDEX               = ' '

*     COPYNUMBER                  = 0

*     ASCII_BIDI_VIS2LOG          = ' '

*     PDF_DELETE_OTFTAB           = ' '

*     PDF_USERNAME                = ' '

        IMPORTING

        BIN_FILESIZE                = BINFILESIZE

        BIN_FILE                    = l_xstring

       TABLES

         OTF                         T_OTF

         LINES                       = PDFTAB[]

* EXCEPTIONS

*   ERR_MAX_LINEWIDTH           = 1

*   ERR_FORMAT                  = 2

*   ERR_CONV_NOT_POSSIBLE       = 3

*   ERR_BAD_OTF                 = 4

*   OTHERS                      = 5

               .

     IF sy-subrc = 0.

       DATA send_request  TYPE REF TO cl_bcs.

       DATA document      TYPE REF TO cl_document_bcs.

       DATA recipient     TYPE REF TO if_recipient_bcs.

       DATA bcs_exception TYPE REF TO cx_bcs.

       DATA pdf_size      TYPE so_obj_len.

       DATA pdf_content   TYPE solix_tab.

       DATA pdf_xstring   TYPE xstring.

       DATA sent_to_all   TYPE os_boolean.

       DATA:   l_document  TYPE REF TO cl_document_bcs.   " Mail body

       TRY.

*-------- create persistent send request ------------------------

           send_request = cl_bcs=>create_persistent( ).

*-------- create and set document -------------------------------

           pdf_content = cl_bcs_convert=>xstring_to_solix( l_xstring ).

           pdf_size = BINFILESIZE "v_len_in.

           DATA:l_text TYPE bcsy_text.                " Mail body

           APPEND 'Hi,' TO l_text.

           APPEND 'The vendor master details are attached for further reference.' to l_text.

           Append 'Regards,' to l_text.

           APPEND 'Meenakshi.' to l_text.

*      append 'Hello world!' to text.

           document = cl_document_bcs=>create_document(

                           i_type    = 'RAW'

                           i_text    = l_text

                           i_length  = '12'

                           i_subject = 'Vendor Master details') .

           CALL METHOD document->add_attachment

             EXPORTING

               i_attachment_type    = 'PDF'

               i_attachment_subject = 'My attachment'

               i_att_content_hex    = pdf_content.

*     add document object to send request

           send_request->set_document( document ).

*     --------- add recipient (e-mail address) -----------------------

*     create recipient object

           recipient = cl_cam_address_bcs=>create_internet_address( p_email ).

*     add recipient object to send request

           send_request->add_recipient( recipient ).

           SEND_REQUEST->SET_SEND_IMMEDIATELY( 'X' ).

*     ---------- send document ---------------------------------------

           sent_to_all = send_request->send( i_with_error_screen = 'X' ).

           COMMIT WORK.

           IF sent_to_all IS INITIAL.

             MESSAGE i500(sbcoms) WITH p_email.

           ELSE.

             MESSAGE s022(so).

           ENDIF.

*   ------------ exception handling ----------------------------------

*   replace this rudimentary exception handling with your own one !!!

         CATCH cx_bcs INTO bcs_exception.

           MESSAGE i865(so) WITH bcs_exception->error_type.

       ENDTRY.

     ENDIF.

thanq

55 REPLIES 55
Read only

Former Member
0 Likes
1,651

HI Everyone,

how can i send this to email id specified in the selection screen.

Read only

0 Likes
1,651

Hi Meenakshi,

We shall use the function module SO_NEW_DOCUMENT_ATT_SEND_API1 to send mail with PDF as attachment.

Following is the main code part

LOOP AT gt_pdf_tab INTO gs_pdf_tab.
             gv_pos = 255 - gv_len.
             IF gv_pos > 134.
               gv_pos = 134.
             ENDIF.
             gs_objbin+gv_len = gs_pdf_tab(gv_pos).
             gv_len = gv_len + gv_pos.
             IF gv_len = 255.
               APPEND gs_objbin TO gt_objbin.
               CLEAR: gs_objbin, gv_len.
               IF gv_pos < 134.
                 gs_objbin = gs_pdf_tab+gv_pos.
                 gv_len = 134 - gv_pos.
               ENDIF.
             ENDIF.
           ENDLOOP.
           IF gv_len > 0.
             APPEND gs_objbin TO gt_objbin.
           ENDIF.

           DESCRIBE TABLE gt_objtxt LINES gv_tab_lines.


           READ TABLE gt_objtxt INTO gs_objtxt INDEX gv_tab_lines.

           gs_docdata-doc_size = ( gv_tab_lines - 1 ) * 255 + STRLEN( gs_objtxt ).
           CLEAR gs_objpack-transf_bin.
           gs_objpack-head_start = 1.
           gs_objpack-head_num = 0.
           gs_objpack-body_start = 1.
           gs_objpack-body_num = gv_tab_lines.
           gs_objpack-doc_type = 'htm'(026).
           APPEND gs_objpack TO gt_objpack.
           CLEAR  gs_objpack.

           DESCRIBE TABLE gt_objbin LINES gv_tab_lines.


           CLEAR gs_objbin.
           READ TABLE gt_objbin INTO gs_objbin INDEX gv_tab_lines.
           IF sy-subrc = 0.
             gs_objpack-doc_size = ( gv_tab_lines - 1 ) * 255 + STRLEN( gs_objbin ).
             gs_objpack-transf_bin = 'X'(003).
             gs_objpack-head_start = 1.
             gs_objpack-head_num = 0.
             gs_objpack-body_start = 1.
             gs_objpack-body_num = gv_tab_lines.
             gs_objpack-doc_type = 'PDF'(006).
             gs_objpack-obj_name = 'ATTACHMENT'(030).
             gs_objpack-obj_descr = 'SLIP'(031).
             APPEND gs_objpack TO gt_objpack.
             CLEAR gs_objpack.
           ENDIF.

           CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
             EXPORTING
               document_data              = gs_docdata
               put_in_outbox              = 'X'
               commit_work                = 'X'
             TABLES
               packing_list               = gt_objpack
               object_header              = gt_objtxt
               contents_bin               = gt_objbin
               contents_txt               = gt_objtxt
               receivers                  = gt_reclist
             EXCEPTIONS
               too_many_receivers         = 1
               document_not_sent          = 2
               document_type_not_exist    = 3
               operation_no_authorization = 4
               parameter_error            = 5
               x_error                    = 6
               enqueue_error              = 7
               OTHERS                     = 8.
           IF sy-subrc <> 0.
             w_sent-pernr      = w_final_t-pernr.
             w_sent-usrid_long = w_final_t-usrid_long.
             w_sent-name       = w_final_t-ename.
             w_sent-status     = 'NO'(035).
             APPEND w_sent TO i_sent.
             CLEAR  w_sent.
*        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
           ELSE.
             w_sent-pernr      = w_final_t-pernr.
             w_sent-usrid_long = w_final_t-usrid_long.
             w_sent-name       = w_final_t-ename.
             w_sent-status     = 'YES'(036).
             APPEND w_sent TO i_sent.
             CLEAR  w_sent.
           ENDIF.

           WAIT UP TO 2 SECONDS.
           SUBMIT rsconn01 WITH mode = 'INT'(038) AND RETURN.

With Regards,

Gurulakshmi

Read only

0 Likes
1,651

Hi meena,

Refer the following code to send the mail to a particular person,

Don't forget to give reward if it's helpful answer.

REPORT  zr_hr_emp_instatus.

TYPES : BEGIN OF ty_instatus,
pernrpak         
TYPE zdt_tr_insurance-pernrpak,
emp_name         
TYPE zdt_tr_insurance-emp_name,
ttk_id           
TYPE zdt_tr_insurance-ttk_id,
claimant_name    
TYPE zdt_tr_insurance-claimant_name,
relationship     
TYPE zdt_tr_insurance-relationship,
gender           
TYPE zdt_tr_insurance-gender,
type_of_claim    
TYPE zdt_tr_insurance-type_of_claim,
claimed_amount   
TYPE zdt_tr_insurance-claimed_amount,
claimed_date     
TYPE zdt_tr_insurance-claimed_date,
settled_amount   
TYPE zdt_tr_insurance-settled_amount,
settled_date     
TYPE zdt_tr_insurance-settled_date,
claim_status     
TYPE zdt_tr_insurance-claim_status,
END OF ty_instatus.

DATA:  it_instatus       
TYPE TABLE OF ty_instatus,
lt_mailrecipients 
TYPE STANDARD TABLE OF somlrec90,
lt_mailtext       
TYPE TABLE OF  soli,
lt_mailsubject    
TYPE sodocchgi1,
ls_mailrecipients 
TYPE  somlrec90,
ls_mailtext       
TYPE soli,
wa_instatus       
TYPE ty_instatus,
lv_date           
TYPE datum,
lv_index          
TYPE i,
lv_count          
TYPE i,
lv_dat_con        
TYPE string,
lv_dd             
TYPE string,
lv_mm             
TYPE string,
lv_yy             
TYPE string.

*PARAMETERS : p_mail TYPE string.
constants: p_mail
type string value 'Urmail@gmail.com'. or pass the parameter
lv_date = sy-datum -
45.

SELECT pernrpak
emp_name
ttk_id
claimant_name
relationship
gender
type_of_claim
claimed_amount
claimed_date
settled_amount
settled_date
claim_status
FROM zdt_tr_insurance
INTO TABLE it_instatus
WHERE begdapak BETWEEN lv_date AND sy-datum.

DESCRIBE TABLE it_instatus LINES lv_count.

LOOP AT it_instatus INTO wa_instatus.

lv_index = lv_index +
1.

AT FIRST.

ls_mailtext-line =
'Dear HR,'.
APPEND ls_mailtext TO lt_mailtext.

ls_mailtext-line =
'<P>'.
APPEND ls_mailtext TO lt_mailtext.

ls_mailtext-line =
'The Employee Insurance Transaction details are as follows' .
APPEND ls_mailtext TO lt_mailtext.

ls_mailtext-line =
'</P>'.
APPEND ls_mailtext TO lt_mailtext.

ls_mailtext-line =
' <TABLE BORDER = 2 width = 50% > <TR> <td align=center><B>Emp ID</B></td>'.
APPEND ls_mailtext TO lt_mailtext.

ls_mailtext-line =
'<td align=center><B>Employee Name</B></td>'.
APPEND ls_mailtext TO lt_mailtext.

ls_mailtext-line =
'<td align=center><B>TTK ID</B></td><td align=center><B>Claimant Name</B></td>'.
APPEND ls_mailtext TO lt_mailtext.

ls_mailtext-line =
'<td align=center><B>Relationship</B></td>'.
APPEND ls_mailtext TO lt_mailtext.

ls_mailtext-line =
'<td align=center><B>Gender</B></td><td align=center><B>Type of claim</B></td>'.
APPEND ls_mailtext TO lt_mailtext.

ls_mailtext-line =
'<td align=center><B>Claimed Amount</B></td><td align=center><B>Claimed Date</B></td>'.
APPEND ls_mailtext TO lt_mailtext.

ls_mailtext-line =
'<td align=center><B>Settled Amount</B></td><td align=center><B>Settled Date</B></td>'.
APPEND ls_mailtext TO lt_mailtext.

ls_mailtext-line =
'<td align=center><B>Claim Status</B></td></TR>'.
APPEND ls_mailtext TO lt_mailtext.

ENDAT.
*--------------------------------------------------------------------*
" date format conversion..
DATA : lv_claimdate TYPE string,
lv_settleddate
TYPE string.

lv_yy = wa_instatus-claimed_date+0(4).
lv_mm = wa_instatus-claimed_date+5(2).
lv_dd = wa_instatus-claimed_date+8(2).
CONCATENATE lv_dd '-' lv_mm '-' lv_yy INTO lv_claimdate.

lv_yy = wa_instatus-settled_date+0(4).
lv_mm = wa_instatus-settled_date+5(2).
lv_dd = wa_instatus-settled_date+8(2).
CONCATENATE lv_dd '-' lv_mm '-' lv_yy INTO lv_settleddate.
*--------------------------------------------------------------------*

CONCATENATE '<tr> <td>'  wa_instatus-pernrpak
'</td> <td>' wa_instatus-emp_name
'</td> <td>' wa_instatus-ttk_id
'</td> <td>' wa_instatus-claimant_name
'</td> <td>' wa_instatus-relationship
'</td> <td>' wa_instatus-gender
'</td> <td>' wa_instatus-type_of_claim
'</td> <td>' wa_instatus-claimed_amount
'</td> <td>' lv_claimdate
'</td> <td>' wa_instatus-settled_amount
'</td> <td>' lv_settleddate
'</td> <td>' wa_instatus-claim_status
'</td> </tr> '

INTO ls_mailtext-line.

APPEND ls_mailtext TO lt_mailtext.

CLEAR : wa_instatus, ls_mailtext, lv_claimdate, lv_settleddate.

IF lv_index = lv_count.

ls_mailtext-line =
'</TABLE>'.
APPEND ls_mailtext TO lt_mailtext.

ls_mailtext =
'<br><br> <b><font color=red>This E-Mail has been Generated Automatically. Please do not reply!</font></b>'.
APPEND ls_mailtext TO lt_mailtext.

ls_mailtext-line =
'<br><br> Thanks and Regards,'.
APPEND ls_mailtext TO lt_mailtext.

ls_mailtext-line =
'<br>Altimetrik Pvt Ltd.'.
APPEND ls_mailtext TO lt_mailtext.

ENDIF.

ENDLOOP.

" Mail Recipients
ls_mailrecipients-rec_type  =
'U'.
ls_mailrecipients-receiver = p_mail.
APPEND ls_mailrecipients TO lt_mailrecipients.
CLEAR ls_mailrecipients .

"Mail Subject

lt_mailsubject-obj_name =
'Employee Insurance status'.
lt_mailsubject-obj_descr =
'Employee Insurance status'.

" Function module to Send mail.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data              = lt_mailsubject
document_type              =
'htm'
put_in_outbox              =
'X'
commit_work                =
'X'
TABLES
object_content             = lt_mailtext
receivers                  = lt_mailrecipients
EXCEPTIONS
too_many_receivers         =
1
document_not_sent          =
2
document_type_not_exist    =
3
operation_no_authorization =
4
parameter_error            =
5
x_error                    =
6
enqueue_error              =
7
OTHERS                     = 8.

IF sy-subrc = 0.

MESSAGE 'Mail Successfully sent' TYPE 'S'.

ELSE.

MESSAGE 'Mail not sent due to some network Problem' TYPE 'E'.

ENDIF.

I hope this will helpful to you.

Warm Regards,

John.

Read only

0 Likes
1,651

Hi Gurulakshmi,

We cannot directly pass the function module.....need to change the string value...?

Regards,

Meenakshi

Read only

0 Likes
1,651

Hi Meenakshi,

I hope that you are asking regarding, passing the email-id to the FM.

If so, we need to add the following code .


           gs_reclist-receiver = w_final_t-usrid_long. (Pass the E-mail Id)
           gs_reclist-rec_type = 'U'(012).
           APPEND gs_reclist TO gt_reclist.

With Regards,

Gurulakshmi

Read only

0 Likes
1,651

Hi John,

Not to particular person but to the email id giving in selection screen

Read only

0 Likes
1,651

This message was moderated.

Read only

0 Likes
1,651

Hi meena,

   For your understanding i am mentioning mail id as constants, There i commanded the parameter you can pass that parameter p_mail id it will work fine,

FYI,

This is no need for you just command those lines.

*PARAMETERS : p_mail TYPE string.
constants: p_mail
type string value 'Urmail@gmail.com'. or pass the parameter

You directly pass your selection screen mail id parameter as i mention here

" Mail Recipients
ls_mailrecipients-rec_type  =
'U'.
ls_mailrecipients-receiver = p_mail. "Here you should pass the     

                                   selection screen mail id parameter.
APPEND ls_mailrecipients TO lt_mailrecipients.
CLEAR ls_mailrecipients .

Now it will work fine.

Warm Regards,

John.


Read only

0 Likes
1,651

Hi meena,

    Is your problem is solved or still are you struggling some where?

Warm Regards,

John.

Read only

0 Likes
1,651

Hi John,

Still struggling....

Read only

0 Likes
1,651

Hi,

  Tell us the issue if your struggling sending the mail please go through the code which i posted earlier to you that is easy one only, Or Every thing is correct but the mail will not trigger just go to SOST transaction and see the result of your mail is sent or not.

Warm Regards,

John.

Read only

former_member212705
Active Participant
0 Likes
1,651

Hi Meenakshi,

Refere to the below link..

http://wiki.sdn.sap.com/wiki/display/XI/Generation+of+PDF+File+from+Internal+Table,+SAP+Script,+Smat...

Hope it will solve your problem.

Regards,

Ashish

Read only

Former Member
0 Likes
1,651

Hi meenakshi,

check the below document; http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/49e15474-0e01-0010-9cba-e62df8244...

I suspect that you are not passing the tdgetotf flag in the open_form. check and give the same as per the above document.

Regards,

Karthik

Read only

former_member209120
Active Contributor
0 Likes
1,651

Hi,

Try this code.

data:g_val  type c,

  w_pripar  type pri_params,

  w_arcpar  type arc_params,

  input_length type i,

  content_x type xstring,

  content_s type string,

  spool_no  like tsp01-rqident,

  it_pdftype table of tline with header line,
  wa_pdflike line of it_pdf,

  file_tab  type standard table of solisti1,

  bin_file  type xstring,

  bytecount type i,

  zip   type xstring,

  path_table   type table of char1024.

data: begin of it_t001 occurs 0,

  bukrs   type t001-bukrs,
  butxt   type t001-butxt,
end of it_t001.

data:g_zipper   type ref to cl_abap_zip.

data:file_name  type string value 'Report_output.pdf'.

data:file_path  type string value 'D:\pdf_report.pdf'.

start-of-selection.

  perform get_data.

  perform print_data changing spool_no.

  perform convert_spool_2_pdf.

  perform download_pdf_file.

*&---------------------------------------------------------------------*

*&Form  get_data

*&---------------------------------------------------------------------*

form get_data .

  select * from t001

  into corresponding fields of table it_t001 up to 10 rows.

endform.              " get_data

*&---------------------------------------------------------------------*

*&Form  print_data

*&---------------------------------------------------------------------*

form print_data  changing spool_no.

  call function 'GET_PRINT_PARAMETERS'

  exporting

in_archive_parameters  = w_arcpar
in_parameters   = w_pripar
layout          = 'X_65_132'
line_count      = 65
line_size       = 132
no_dialog       = 'X'

  importing

out_archive_parameters = w_arcpar
out_parameters  = w_pripar
valid           = g_val.

  if g_val  ne space and sy-subrc = 0.

  w_pripar-prrel = space.

  w_pripar-primm = space.

  new-page print on new-section parameters w_pripar archive parameters w_arcpar no dialog.

  "Output which is gone to spool

  loop at it_t001.

write:/ it_t001.

  endloop.

  new-page print off.

  call function 'ABAP4_COMMIT_WORK'.

  endif.

  if not sy-spono is initial.

  spool_no = sy-spono.

  endif.

endform.              " print_data

*&---------------------------------------------------------------------*

*&Form  convert_spool_2_pdf

*&---------------------------------------------------------------------*

form convert_spool_2_pdf .

  call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

  exporting

src_spoolid   = spool_no
no_dialog   = space

  importing

pdf_bytecount = bytecount

  tables

pdf     = it_pdf.

  call function 'SX_TABLE_LINE_WIDTH_CHANGE'

  exporting

line_width_src = 134
line_width_dst = 255

  tables

content_in  = it_pdf
content_out = file_tab.

endform.              " convert_spool_2_pdf

*&---------------------------------------------------------------------*

*&Form  download_PDF_file

*&---------------------------------------------------------------------*

form download_PDF_file .

  "Save the file

  call function 'GUI_DOWNLOAD'

  exporting

bin_filesize = bytecount
filename  = file_path
filetype  = 'BIN'

  tables

data_tab  = file_tab.
endform.              " download_PDF_file
Read only

0 Likes
1,651

This message was moderated.

Read only

Former Member
0 Likes
8,291

Hi Everyone,

Thanx for all your replies. Bcs of ur help i completed my object. Here iam providing for future refrence.

   REPORT  ZPHF_VMS                                .

*  ----------------------------------------------------------------------*

*  &                  TABLE DECLARATION                                  *

*  ----------------------------------------------------------------------*

   TABLES : LFA1, ITCPO.                     "Vendor Master (General Section)

*  ----------------------------------------------------------------------*

*  &                    DATA DECLARATION                                 *

*  ----------------------------------------------------------------------*

   DATA : V_LIFNR TYPE LIFNR.

   DATA : I_ITCPP TYPE ITCPP.

   DATA :W_ERREUR TYPE I VALUE 0.

   DATA : STRUCT TYPE ITCPO.

   DATA: GD_RECSIZE TYPE I.

   DATA: PDFTAB TYPE TABLE OF TLINE WITH HEADER LINE,

         DATAB TYPE TABLE OF ITCOO WITH HEADER LINE.

   DATA: BINFILESIZE TYPE I,

   FILE_NAME TYPE STRING,

   FILE_PATH TYPE STRING,

   FULL_PATH TYPE STRING.

   DATA : p_email1 TYPE SZA1_D0100-SMTP_ADDR.

*  ----------------------------------------------------------------------*

*  &                    TYPE DECLARATION                                 *

*  ----------------------------------------------------------------------*

   TYPES : BEGIN OF TY_LFA1,

           LIFNR TYPE   LIFNR,

           LAND1  TYPE LAND1_GP,

           NAME1  TYPE NAME1_GP,

           NAME2  TYPE NAME2_GP,

           NAME3  TYPE NAME3_GP,

           NAME4  TYPE NAME4_GP,

           ORT01  TYPE ORT01_GP,

           ORT02  TYPE ORT02_GP,

           PFACH  TYPE PFACH,

           PSTL2  TYPE PSTL2,

           PSTLZ  TYPE PSTLZ,

           REGIO  TYPE REGIO,

           SORTL  TYPE SORTL,

           STRAS  TYPE STRAS_GP,

           SPRAS  TYPE SPRAS,

           ADRNR  TYPE ADRNR,

   END OF TY_LFA1.

*  ----------------------------------------------------------------------*

*  &                   Binary store for PDF                              *

*  ----------------------------------------------------------------------*

   DATA: BEGIN OF IT_PDF_OUTPUT OCCURS 0.

           INCLUDE STRUCTURE TLINE.

   DATA: END OF IT_PDF_OUTPUT.

*  ----------------------------------------------------------------------*

*  &                    INTERNAL TABLE  DECLARATION                      *

*  ----------------------------------------------------------------------*

   DATA : IT_LFA1 TYPE STANDARD TABLE OF TY_LFA1,

          WA_LFA1 TYPE TY_LFA1.

   DATA : T_OTF TYPE TABLE OF ITCOO.                                             "OTF Structure

*  ----------------------------------------------------------------------*

*  &                    Selection Screen DECLARATION                     *

*  ----------------------------------------------------------------------*

   SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

   SELECT-OPTIONS : S_LIFNR FOR V_LIFNR.

   PARAMETERS : P_EMAIL LIKE p_email1.

   SELECTION-SCREEN END OF BLOCK B1.

*  ----------------------------------------------------------------------*

*  &                    Start of selection                               *

*  ----------------------------------------------------------------------*

   SELECT LIFNR

         LAND1

         NAME1

         NAME2

         NAME3

         NAME4

         ORT01

         ORT02

         PFACH

         PSTL2

         PSTLZ

         REGIO

         SORTL

         STRAS

         SPRAS

         ADRNR

     FROM LFA1

     INTO TABLE IT_LFA1

     WHERE LIFNR IN S_LIFNR

     AND   SPRAS = SY-LANGU.                   "Message language

   PERFORM TRAITEMENT.

   PERFORM CONVERSION.

*  PERFORM process_email.

*  &---------------------------------------------------------------------*

*  &      Form  TRAITEMENT

*  &---------------------------------------------------------------------*

*         text

*  ----------------------------------------------------------------------*

*    -->  p1        text

*    <--  p2        text

*  ----------------------------------------------------------------------*

   FORM TRAITEMENT .

     PERFORM OPEN_FORM.

     PERFORM WRITE_FORM.

     PERFORM CLOSE_FORM.

   ENDFORM.                    " TRAITEMENT

*  &---------------------------------------------------------------------*

*  &      Form  OPEN_FORM

*  &---------------------------------------------------------------------*

*         text

*  ----------------------------------------------------------------------*

*    -->  p1        text

*    <--  p2        text

*  ----------------------------------------------------------------------*

   FORM OPEN_FORM .

     ITCPO-TDGETOTF = 'X'.

     STRUCT-TDDEST = 'LP01'.

*To specify no Print Preview

     STRUCT-TDNOPREV = 'X'.

*To access the SAP Script output in OTF format

     STRUCT-TDGETOTF = 'X'.

     CALL FUNCTION 'OPEN_FORM'

      EXPORTING

*       APPLICATION                       = 'TX'

*       ARCHIVE_INDEX                     =

*       ARCHIVE_PARAMS                    =

        DEVICE                            = 'PRINTER'

        DIALOG                            = SPACE

        FORM                              = 'ZPHF_VMS1'

        LANGUAGE                          = sy-langu        "Message language

        OPTIONS                           = STRUCT

*       MAIL_SENDER                       =

*       MAIL_RECIPIENT                    =

*       MAIL_APPL_OBJECT                  =

*       RAW_DATA_INTERFACE                = '*'

*       SPONUMIV                          =

*     IMPORTING

*       LANGUAGE                          = sy-langu

*       NEW_ARCHIVE_PARAMS                =

*       RESULT                            =

*     EXCEPTIONS

*       CANCELED                          = 1

*       DEVICE                            = 2

*       FORM                              = 3

*       OPTIONS                           = 4

*       UNCLOSED                          = 5

*       MAIL_OPTIONS                      = 6

*       ARCHIVE_ERROR                     = 7

*       INVALID_FAX_NUMBER                = 8

*       MORE_PARAMS_NEEDED_IN_BATCH       = 9

*       SPOOL_ERROR                       = 10

*       CODEPAGE                          = 11

*       OTHERS                            = 12

               .

     IF SY-SUBRC <> 0.

*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*           WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

     ENDIF.

   ENDFORM.                    " OPEN_FORM

*  &---------------------------------------------------------------------*

*  &      Form  WRITE_FORM

*  &---------------------------------------------------------------------*

*         text

*  ----------------------------------------------------------------------*

*    -->  p1        text

*    <--  p2        text

*  ----------------------------------------------------------------------*

   FORM WRITE_FORM .

     CALL FUNCTION 'WRITE_FORM'

      EXPORTING

        ELEMENT                        = 'HEADER1'

*     FUNCTION                       = 'SET'

*     TYPE                           = 'BODY'

        WINDOW                         = 'HEADER'.

     CALL FUNCTION 'WRITE_FORM'

      EXPORTING

        ELEMENT                        = 'LINE'

*     FUNCTION                       = 'SET'

*     TYPE                           = 'BODY'

        WINDOW                         = 'LINE_HD'.

     LOOP AT IT_LFA1 INTO WA_LFA1.

       CALL FUNCTION 'WRITE_FORM'

        EXPORTING

          ELEMENT                        = 'MAIN1'

*     FUNCTION                       = 'SET'

*     TYPE                           = 'BODY'

          WINDOW                         = 'MAIN'.

     ENDLOOP.

   ENDFORM.                    " WRITE_FORM

*  &---------------------------------------------------------------------*

*  &      Form  CLOSE_FORM

*  &---------------------------------------------------------------------*

*         text

*  ----------------------------------------------------------------------*

*    -->  p1        text

*    <--  p2        text

*  ----------------------------------------------------------------------*

   FORM CLOSE_FORM .

     CALL FUNCTION 'CLOSE_FORM'

     IMPORTING

     RESULT                         = I_ITCPP

*     RDI_RESULT                     =

    TABLES

      OTFDATA                        = T_OTF

      EXCEPTIONS

      UNOPENED                       = 1

      BAD_PAGEFORMAT_FOR_PRINT       = 2

      SEND_ERROR                     = 3

      SPOOL_ERROR                    = 4

      CODEPAGE                       = 5

        OTHERS                         = 6

               .

     IF SY-SUBRC <> 0.

       W_ERREUR = W_ERREUR + 1.

     ENDIF.

   ENDFORM.                    " CLOSE_FORM

*  &---------------------------------------------------------------------*

*  &      Form  CONVERSION spool to pdf format

*  &---------------------------------------------------------------------*

*         text

*  ----------------------------------------------------------------------*

*    -->  p1        text

*    <--  p2        text

*  ----------------------------------------------------------------------*

   FORM CONVERSION .

     DATA: l_xstring TYPE xstring.

     CALL FUNCTION 'CONVERT_OTF'

      EXPORTING

        FORMAT                      = 'PDF'

        MAX_LINEWIDTH               = 132

*     ARCHIVE_INDEX               = ' '

*     COPYNUMBER                  = 0

*     ASCII_BIDI_VIS2LOG          = ' '

*     PDF_DELETE_OTFTAB           = ' '

*     PDF_USERNAME                = ' '

        IMPORTING

        BIN_FILESIZE                = BINFILESIZE

        BIN_FILE                    = l_xstring

       TABLES

         OTF                         T_OTF

         LINES                       = PDFTAB[]

* EXCEPTIONS

*   ERR_MAX_LINEWIDTH           = 1

*   ERR_FORMAT                  = 2

*   ERR_CONV_NOT_POSSIBLE       = 3

*   ERR_BAD_OTF                 = 4

*   OTHERS                      = 5

               .

     IF sy-subrc = 0.

       DATA send_request  TYPE REF TO cl_bcs.

       DATA document      TYPE REF TO cl_document_bcs.

       DATA recipient     TYPE REF TO if_recipient_bcs.

       DATA bcs_exception TYPE REF TO cx_bcs.

       DATA pdf_size      TYPE so_obj_len.

       DATA pdf_content   TYPE solix_tab.

       DATA pdf_xstring   TYPE xstring.

       DATA sent_to_all   TYPE os_boolean.

       DATA:   l_document  TYPE REF TO cl_document_bcs.   " Mail body

       TRY.

*-------- create persistent send request ------------------------

           send_request = cl_bcs=>create_persistent( ).

*-------- create and set document -------------------------------

           pdf_content = cl_bcs_convert=>xstring_to_solix( l_xstring ).

           pdf_size = BINFILESIZE "v_len_in.

           DATA:l_text TYPE bcsy_text.                " Mail body

           APPEND 'Hi,' TO l_text.

           APPEND 'The vendor master details are attached for further reference.' to l_text.

           Append 'Regards,' to l_text.

           APPEND 'Meenakshi.' to l_text.

*      append 'Hello world!' to text.

           document = cl_document_bcs=>create_document(

                           i_type    = 'RAW'

                           i_text    = l_text

                           i_length  = '12'

                           i_subject = 'Vendor Master details') .

           CALL METHOD document->add_attachment

             EXPORTING

               i_attachment_type    = 'PDF'

               i_attachment_subject = 'My attachment'

               i_att_content_hex    = pdf_content.

*     add document object to send request

           send_request->set_document( document ).

*     --------- add recipient (e-mail address) -----------------------

*     create recipient object

           recipient = cl_cam_address_bcs=>create_internet_address( p_email ).

*     add recipient object to send request

           send_request->add_recipient( recipient ).

           SEND_REQUEST->SET_SEND_IMMEDIATELY( 'X' ).

*     ---------- send document ---------------------------------------

           sent_to_all = send_request->send( i_with_error_screen = 'X' ).

           COMMIT WORK.

           IF sent_to_all IS INITIAL.

             MESSAGE i500(sbcoms) WITH p_email.

           ELSE.

             MESSAGE s022(so).

           ENDIF.

*   ------------ exception handling ----------------------------------

*   replace this rudimentary exception handling with your own one !!!

         CATCH cx_bcs INTO bcs_exception.

           MESSAGE i865(so) WITH bcs_exception->error_type.

       ENDTRY.

     ENDIF.

thanq