Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

 

To send the smartform as a PDF attachment to Internal or External mail id.
Below is the Sample Program.

Error rendering macro 'code': Invalid value specified for parameter 'lang'
REPORT Z_SEND_MAIL.
********Variable Declarations ****************************
DATA: GV_FORM_NAME TYPE RS38L_FNAM, " Used to store the function module generated by Smartform
GV_BIN_FILESIZE TYPE I, " Store the file size
GV_POS TYPE I,
GV_LEN TYPE I,
GV_TAB_LINES TYPE I.
*******Constants ******************************************
DATA : GC_TEXT(11) TYPE C VALUE 'Form Output',
GC_TST(3) TYPE C VALUE 'TST',
GC_TESTING(7) TYPE C VALUE 'Testing'.
********Work Area Declarations ****************************
DATA: GS_DOCDATA TYPE SODOCCHGI1, " Data of an object which can be changed
GS_CTRLOP TYPE SSFCTRLOP, " Smart Forms: Control structure
GS_OUTOPT TYPE SSFCOMPOP, " SAP Smart Forms: Smart Composer (transfer) options
GS_OTFDATA TYPE SSFCRESCL, " Smart Forms: Return value at end of form printing
GS_RECLIST TYPE SOMLRECI1, " SAPoffice: Structure of the API Recipient List
GS_PDF_TAB TYPE TLINE, " Workarea for SAP Script Text Lines
GS_OBJBIN TYPE SOLISTI1, " SAPoffice: Single List with Column Length 255
GS_OBJPACK TYPE SOPCKLSTI1. " SAPoffice: Description of Imported Object Components
********Internal tables Declarations ****************************
DATA: GT_RECLIST TYPE TABLE OF SOMLRECI1, " SAPoffice: Structure of the API Recipient List
GT_PDF_TAB TYPE TABLE OF TLINE, " SAPscript: Text Lines
GT_OTF TYPE TABLE OF ITCOO, " OTF Structure
GT_OBJBIN TYPE TABLE OF SOLISTI1, " SAPoffice: Single List with Column Length 255
GT_OBJPACK TYPE TABLE OF SOPCKLSTI1. " SAPoffice: Description of Imported Object Components
DATA: CUSTOMER TYPE SCUSTOM,
      BOOKINGS TYPE TY_BOOKINGS,
      CONNECTIONS TYPE TY_CONNECTIONS.
CLEAR : GV_FORM_NAME,
GS_CTRLOP,
GS_OUTOPT,
GS_OTFDATA,
GV_BIN_FILESIZE,
GV_POS,
GV_LEN,
GV_TAB_LINES.
START-OF-SELECTION.
* Generate Function Module name
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      FORMNAME           = 'SF_EXAMPLE_01'
    IMPORTING
      FM_NAME            = GV_FORM_NAME
    EXCEPTIONS
      NO_FORM            = 1
      NO_FUNCTION_MODULE = 2
      OTHERS             = 3.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
* Assigning values to Form Control Structure and Form Composer
  GS_CTRLOP-GETOTF = 'X'.
  GS_CTRLOP-DEVICE = 'PRINTER'.
  GS_CTRLOP-PREVIEW = ''.
  GS_CTRLOP-NO_DIALOG = 'X'.
  GS_OUTOPT-TDDEST = 'LOCL'.
* Getting the OTFDATA
  CALL FUNCTION GV_FORM_NAME
    EXPORTING
      CONTROL_PARAMETERS = GS_CTRLOP
      OUTPUT_OPTIONS     = GS_OUTOPT
      USER_SETTINGS      = ' '
      CUSTOMER           = CUSTOMER
      BOOKINGS           = BOOKINGS
      CONNECTIONS        = CONNECTIONS
    IMPORTING
      JOB_OUTPUT_INFO    = GS_OTFDATA
    EXCEPTIONS
      FORMATTING_ERROR   = 1
      INTERNAL_ERROR     = 2
      SEND_ERROR         = 3
      USER_CANCELED      = 4.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
* Assigning the OTFDATA to OTF Structure table
  CLEAR GT_OTF.
  GT_OTF[] = GS_OTFDATA-OTFDATA[].
* Convert the OTF DATA to SAP Script Text lines
  CLEAR GT_PDF_TAB.
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      FORMAT                = 'PDF'
      MAX_LINEWIDTH         = 132
    IMPORTING
      BIN_FILESIZE          = GV_BIN_FILESIZE
    TABLES
      OTF                   = GT_OTF
      LINES                 = GT_PDF_TAB
    EXCEPTIONS
      ERR_MAX_LINEWIDTH     = 1
      ERR_FORMAT            = 2
      ERR_CONV_NOT_POSSIBLE = 3
      OTHERS                = 4.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
* Assigning the Description of the object sent in the mail
  CLEAR GS_DOCDATA.
  GS_DOCDATA-OBJ_NAME = GC_TST.
  GS_DOCDATA-OBJ_DESCR = GC_TESTING.
* Assigning the email id to Structure of the API Recipient List table
  CLEAR : GT_RECLIST, GS_RECLIST.
*  IF internal mail id
  GS_RECLIST-RECEIVER = SY-UNAME.
  GS_RECLIST-REC_TYPE = 'B'.
*  if external mail id
*  gs_reclist-receiver = 'shakti.agnihotri@gmail.com'.
*  gs_reclist-rec_type = 'U'.
  APPEND GS_RECLIST TO GT_RECLIST.
* Passing the SAP Script text lines to SAPoffice: Single List with Column Length 255 table
  CLEAR : GS_OBJBIN, GS_PDF_TAB.
  LOOP AT GT_PDF_TAB INTO GS_PDF_TAB.
    GV_POS = 255 - GV_LEN.
    IF GV_POS > 134. "length of pdf_table
      GV_POS = 134.
    ENDIF.
    GS_OBJBIN+GV_LEN = GS_PDF_TAB(GV_POS).
    GV_LEN = GV_LEN + GV_POS.
    IF GV_LEN = 255. "length of out (contents_bin)
      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.
* Filling the details in SAPoffice: Description of Imported Object Components table
  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'.
    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'.
    GS_OBJPACK-OBJ_NAME = 'ATTACHMENT'.
    GS_OBJPACK-OBJ_DESCR = 'test'.
    APPEND GS_OBJPACK TO GT_OBJPACK.
  ENDIF.
* Sending the Form Output in the PDF format to email
  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
      CONTENTS_BIN               = GT_OBJBIN
      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.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ELSE.
    WRITE 'Sent Successfully'.
  ENDIF.
  SUBMIT RSCONN01
  WITH MODE EQ 'INT'
  AND RETURN.
END-OF-SELECTION.

 

 

  • No labels