Sitemap

Amicuk Programming Answers

Mail using ABAP program

2015-10-11   Views:0

Advertisement

Hi all, see below it. TABLES: ZST2. DATA : BEGIN OF ITAB OCCURS 0, EMPNO LIKE ZST2-EMPNO, EMPNAME LIKE ZST2-EMPNAME, END OF ITAB. DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE, receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE, packing_

Hi all,
see below it.
TABLES: ZST2.
DATA : BEGIN OF ITAB OCCURS 0,
EMPNO LIKE ZST2-EMPNO,
EMPNAME LIKE ZST2-EMPNAME,
END OF ITAB.
DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,
receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,
packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,
listobject LIKE abaplist OCCURS 10,
compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,
w_object_hd_change LIKE sood1,
compressed_size LIKE sy-index.
START-OF-SELECTION.
SELECT EMPNO EMPNAME "PERNR ENAME
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM ZST2."WHERE PERNR < 50.
LOOP AT ITAB.
WRITE :/02 SY-VLINE , ITAB-EMPNO, 15 SY-VLINE , ITAB-EMPNAME.
*SY-VLINE.
ENDLOOP.
Receivers
receiver_list-recextnam = '[email protected]'. "-->
EMAIL ADDRESS
RECEIVER_list-RECESC = 'E'. "<-
RECEIVER_list-SNDART = 'INT'."<-
RECEIVER_list-SNDPRI = '1'."<-
APPEND receiver_list.
General data
w_object_hd_change-objla = sy-langu.
w_object_hd_change-objnam = 'Object name'.
w_object_hd_change-objsns = 'P'.
Mail subject
w_object_hd_change-objdes = 'Message subject'.
Mail body
APPEND 'Message content' TO message_content.
Attachment
CALL FUNCTION 'SAVE_LIST'
EXPORTING
list_index = '0'
TABLES
listobject = listobject.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
compressed_size = compressed_size
TABLES
in = listobject
out = compressed_attachment.
DESCRIBE TABLE compressed_attachment.
CLEAR packing_list.
packing_list-transf_bin = 'X'.
packing_list-head_start = 0.
packing_list-head_num = 0.
packing_list-body_start = 1.
packing_list-body_num = sy-tfill.
packing_list-objtp = 'ALI'.
packing_list-objnam = 'Object name'.
packing_list-objdes = 'Attachment description'.
packing_list-objlen = compressed_size.
APPEND packing_list.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = w_object_hd_change
object_type = 'RAW'
owner = sy-uname
TABLES
objcont = message_content
receivers = receiver_list
packing_list = packing_list
att_cont = compressed_attachment.
how prepared it?
thx,
s.suresh

The replay answer
Advertisement
hi,
chek this,,
TABLES :VARID.                   "Variant directory
DATA:  GV_NAMES     LIKE TSP01-RQ2NAME,
      GD_BYTECOUNT        LIKE TST01-DSIZE,
            GD_BUFFER          TYPE STRING,
      PDF_LINES          TYPE TLINE OCCURS 0 WITH HEADER LINE,
SEND_REQUEST       TYPE REF TO CL_BCS,
      L_SUBJECT          LIKE SOOD-OBJDES,
      DOCUMENT           TYPE REF TO CL_DOCUMENT_BCS,
      BCS_EXCEPTION      TYPE REF TO CX_BCS,
      V_CTR              TYPE I VALUE 0,
      IT_INPUT           LIKE BDI_LINE OCCURS 0 WITH HEADER LINE,
      IT_MESS_ATT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
      IT_BINARY_CONT     TYPE SOLIX_TAB,
      LEN_OUT            TYPE I,
T_SPONO LIKE TSP01SYS OCCURS 0 WITH HEADER LINE.
DATA :GV_RQCRETIME LIKE TSP01-RQCRETIME.
DATA IT_VALUE LIKE  RSPARAMS OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF T_VARID OCCURS 0,
      VARIANT LIKE VARID-VARIANT,
      END OF T_VARID.
SELECTION SCREEN                                                     *
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS: S_VAR FOR VARID-VARIANT.
SELECTION-SCREEN END OF BLOCK B1.
Select the varinat name from the table VARID
SELECT VARIANT INTO TABLE T_VARID
                      FROM VARID
                      WHERE REPORT EQ 'ZAMRP003'
                        AND VARIANT IN S_VAR.
SORT T_VARID.
CHECK NOT T_VARID[] IS INITIAL.
LOOP AT T_VARID.
  SUBMIT ZAMRP003 USING SELECTION-SET T_VARID-VARIANT
                  TO SAP-SPOOL SAP COVER PAGE ' '
                         DESTINATION  ' '
                         IMMEDIATELY  'X'
                         KEEP IN SPOOL  'X'
                         LINE-COUNT 60000
                         LINE-SIZE 134
                         LAYOUT      'X_58_170'
                         WITHOUT SPOOL DYNPRO AND RETURN.
  COMMIT WORK AND WAIT.
  CONCATENATE SY-DATUM '000000' INTO GV_RQCRETIME.
  CONCATENATE 'ZAMRP003_' SY-UNAME+0(3) INTO GV_NAMES.
  SELECT * FROM TSP01 INTO TABLE T_SPONO
              WHERE RQCLIENT = SY-MANDT
              AND   RQ0NAME  = 'LIST1S'
              AND   RQ2NAME  = GV_NAMES
              AND   RQOWNER  = SY-UNAME
              AND   RQCRETIME GE GV_RQCRETIME.
  SORT T_SPONO BY RQIDENT DESCENDING.
  CALL FUNCTION 'RS_VARIANT_CONTENTS'
    EXPORTING
      REPORT               = 'ZAMRP003'
      VARIANT              = T_VARID-VARIANT
    TABLES
      VALUTAB              = IT_VALUE
    EXCEPTIONS
      VARIANT_NON_EXISTENT = 1
      VARIANT_OBSOLETE     = 2
      OTHERS               = 3.
  IF SY-SUBRC <> 0.
    MESSAGE E000(ZH) WITH 'Error in processing variant'.
  ENDIF.
Create the email request
  PERFORM CREATE_EMAIL .
  SORT T_SPONO BY RQIDENT DESCENDING.
  READ TABLE T_SPONO INDEX 1.
  IF SY-SUBRC NE 0.
    MESSAGE E000(ZH) WITH 'Error creating spool'
                          RAISING CONVERSION_ERROR.
  ENDIF.
  CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
    EXPORTING
      SRC_SPOOLID              = T_SPONO-RQIDENT
      NO_DIALOG                = ' '
    IMPORTING
      PDF_BYTECOUNT            = GD_BYTECOUNT
    TABLES
      PDF                      = PDF_LINES
    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
      OTHERS                   = 12.
  IF SY-SUBRC <> 0.
    MESSAGE E000(ZH) WITH 'Error converting spool to PDF'
                          RAISING CONVERSION_ERROR.
  ENDIF.
Transfer the 132-long strings to 255-long strings
  LOOP AT PDF_LINES.
    TRANSLATE PDF_LINES USING ' ~'.
    CONCATENATE GD_BUFFER PDF_LINES INTO GD_BUFFER.
  ENDLOOP.
  TRANSLATE GD_BUFFER USING '~ '.
  DO.
    IT_MESS_ATT = GD_BUFFER.
    APPEND IT_MESS_ATT.
    SHIFT GD_BUFFER LEFT BY 255 PLACES.
    IF GD_BUFFER IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.
Convert format of PDF data to that required for email
  REFRESH IT_BINARY_CONT.
  PERFORM CONVERT_134_TO_255_STR TABLES IT_MESS_ATT
                                        IT_BINARY_CONT.
Now add it as an attachment
  CONCATENATE 'ZAMRP003' '.pdf' INTO L_SUBJECT.
  TRY.
      CALL METHOD DOCUMENT->ADD_ATTACHMENT
        EXPORTING
          I_ATTACHMENT_TYPE    = 'PDF'
          I_ATTACHMENT_SUBJECT = L_SUBJECT
          I_ATT_CONTENT_HEX    = IT_BINARY_CONT.
Add document to send request
      CALL METHOD SEND_REQUEST->SET_DOCUMENT( DOCUMENT ).
    CATCH CX_BCS INTO BCS_EXCEPTION.
    Send the message that occurred and then exit
      MESSAGE ID     BCS_EXCEPTION->MSGID
              TYPE   BCS_EXCEPTION->MSGTY
              NUMBER BCS_EXCEPTION->MSGNO
              WITH   BCS_EXCEPTION->MSGV1 BCS_EXCEPTION->MSGV2
                     BCS_EXCEPTION->MSGV3 BCS_EXCEPTION->MSGV4.
      EXIT.
  ENDTRY.
Send the email now
  PERFORM SEND_THE_EMAIL CHANGING SEND_REQUEST.
  COMMIT WORK.
ENDLOOP.
*&      Form  convert_134_to_255_str
      text
FORM CONVERT_134_TO_255_STR  TABLES   PT_134
                                      PT_255.
  DATA: L_DSN(100).
  L_DSN = 'c:\temp\text_workarea.txt'.
Output file in 134 byte blocks
  OPEN DATASET L_DSN FOR OUTPUT IN BINARY MODE.
  IF SY-SUBRC NE 0.
    WRITE :/ 'Error in PDF Conversion'.
    STOP.
  ENDIF.
  LOOP AT PT_134.
    TRANSFER PT_134 TO L_DSN.
  ENDLOOP.
  CLOSE DATASET L_DSN.
Read file in 255 byte blocks
  OPEN DATASET L_DSN FOR INPUT IN BINARY MODE.
  IF SY-SUBRC NE 0.
    WRITE :/ 'Error in PDF Conversion'.
    STOP.
  ENDIF.
  READ DATASET L_DSN INTO PT_255.
  WHILE SY-SUBRC = 0.
    APPEND PT_255.
    READ DATASET L_DSN INTO PT_255.
  ENDWHILE.
  APPEND PT_255.
  CLOSE DATASET L_DSN.
Clear file
  OPEN DATASET L_DSN FOR OUTPUT IN BINARY MODE.
  CLOSE DATASET L_DSN.
ENDFORM.                    " convert_134_to_255_str
*&      Form  send_the_email
      text
FORM SEND_THE_EMAIL  CHANGING P_SEND_REQUEST TYPE REF TO CL_BCS.
  DATA: L_RECIPIENT          TYPE REF TO IF_RECIPIENT_BCS,
        L_SENT_TO_ALL        TYPE OS_BOOLEAN,
        LT_RECIP_ERROR       TYPE BCSY_RE,
        LT_ORIG_ERROR        TYPE BCSY_ERCP,
        LV_STR               TYPE SZA5_D0700-SMTP_ADDR.
  TRY.
Add recipients (e-mail address) ----------------------
      LOOP AT IT_VALUE WHERE SELNAME = 'S_USER'.
  Create recipient
        LV_STR = IT_VALUE-LOW.
        L_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS(
                                        LV_STR ).
  Add recipient with its respective attributes to send request
        SEND_REQUEST->ADD_RECIPIENT( L_RECIPIENT ).
      ENDLOOP.
Send document ---------------------------------------
      CALL METHOD SEND_REQUEST->SEND_WITHOUT_DIALOG(
         IMPORTING
           E_RECIPIENTS_WITH_ERROR = LT_RECIP_ERROR
           E_ORIG_RECS_WITH_ERROR  = LT_ORIG_ERROR
           E_SENT_TO_ALL           = L_SENT_TO_ALL ).
For internet addresses, this should always be OK. It is only later
that an express message is sent if it fails. Hence no need to do
much error processing here.
      IF L_SENT_TO_ALL = 'X'.
        MESSAGE I217(ZH).       "Sent to all recipients.
      ENDIF.
    CATCH CX_BCS INTO BCS_EXCEPTION.
    Send the message that occurred and then exit
      MESSAGE ID     BCS_EXCEPTION->MSGID
              TYPE   BCS_EXCEPTION->MSGTY
              NUMBER BCS_EXCEPTION->MSGNO
              WITH   BCS_EXCEPTION->MSGV1 BCS_EXCEPTION->MSGV2
                     BCS_EXCEPTION->MSGV3 BCS_EXCEPTION->MSGV4.
      EXIT.
  ENDTRY.
ENDFORM.                    " send_the_email
*&      Form  create_email
FORM CREATE_EMAIL.
  DATA: SUB TYPE SO_OBJ_DES,
    WA_TEXT TYPE SOLI,
    LT_TEXT TYPE SOLI_TAB.
  TRY.
-------- create persistent send request ------------------------
      SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).
      SEND_REQUEST->SET_STATUS_ATTRIBUTES( 'E' ).
      SEND_REQUEST->SEND_REQUEST->SET_LINK_TO_OUTBOX( 'X' ).
-------- create and set document with attachment ---------------
      WA_TEXT        = 'Dear Recipient,'.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT        = ' '.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT        = ' '.
      APPEND WA_TEXT TO LT_TEXT.
     wa_text        = 'We apologise for the inaccurate Fixed Asset '.
     APPEND wa_text TO lt_text.
     wa_text =  'Reports sent to you and any inconvenience caused by'.
     APPEND wa_text TO lt_text.
     wa_text = 'this error.'.
     APPEND wa_text TO lt_text.
     wa_text        = ' '.
     APPEND wa_text TO lt_text.
     wa_text = 'The changing of the report from a manual to '.
     APPEND wa_text TO lt_text.
     wa_text = 'automatic process could not be fully tested in a test'
     APPEND wa_text TO lt_text.
     wa_text = ' environment and this has led to the problems that'.
     APPEND wa_text TO lt_text.
     wa_text = ' you have seen. We have now corrected these errors '.
     APPEND wa_text TO lt_text.
     wa_text = 'and the automated process will continue from now on'.
     APPEND wa_text TO lt_text.
     wa_text = ''.
     APPEND wa_text TO lt_text.
     wa_text = 'Thank you for your patience during this time.'.
     APPEND wa_text TO lt_text.
     wa_text = ''.
     APPEND wa_text TO lt_text.
     wa_text = ''.
     APPEND wa_text TO lt_text.
      WA_TEXT  = 'This is the monthly fixed asset report for your'.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT = 'cost centre(s) which shows assets'.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT = 'for the previous calendar month.'.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT        = ' '.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT        = ' '.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT        = 'N.B. The asset locations shown on this report'.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT        = 'may be long out-of-date and are offered for'.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT        = 'guidance only.'.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT        = 'Please note that it is your responsibility to'.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT        = 'know: Where each asset is; What it is; and Why'.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT        = 'it is needed?'.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT        = ' '.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT        = ' '.
      APPEND WA_TEXT TO LT_TEXT.
      WA_TEXT        = 'For any queries regarding the email or report'.
      APPEND WA_TEXT TO LT_TEXT.
*-- Start of changes by SPUSA (001)
     wa_text        = 'please contact [email protected]'.
      WA_TEXT        = 'please contact [email protected]'.com'.
*-- End of changes by SPUSA (001)
      APPEND WA_TEXT TO LT_TEXT.
      SUB = 'Asset Management'.
      DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
                        I_TYPE    = 'RAW'
                        I_TEXT    = LT_TEXT
                        I_LENGTH  = '24'
                        I_SUBJECT = SUB ).
    CATCH CX_BCS INTO BCS_EXCEPTION.
    Send the message that occurred and then exit
      MESSAGE ID     BCS_EXCEPTION->MSGID
              TYPE   BCS_EXCEPTION->MSGTY
              NUMBER BCS_EXCEPTION->MSGNO
              WITH   BCS_EXCEPTION->MSGV1 BCS_EXCEPTION->MSGV2
                     BCS_EXCEPTION->MSGV3 BCS_EXCEPTION->MSGV4.
      EXIT.
  ENDTRY.
ENDFORM.                    " create_email
reward if helpful,
N.Rekha

Go to See the other 4 answers

Send a mail via ABAP program

Category:DefaultRelease time:2015-10-11Views:130

Hello Experts, I want to send mail via ABAP program with the following requirements : 1. Recipient is OUTLOOK email -id 2. Sender address has to be an external email-id 3. Send mail as CC and BCC also to other email-id. Is there any function module w[More]

To post a mail from ABAP program

Category:DefaultRelease time:-0001-11-30Views:130

dear friends               how to post a mail to SAP inbox of a particular user from ABAP program.get the spool no of the program we have standard program rstxpdf4  through that convert it to pdf and through f.m SO_NEW_DOCUMENT_ATT_SEND_API1 u can se[More]

Mail using ABAP program

Category:DefaultRelease time:2015-10-11Views:130

Hi all, see below it. TABLES: ZST2. DATA : BEGIN OF ITAB OCCURS 0, EMPNO LIKE ZST2-EMPNO, EMPNAME LIKE ZST2-EMPNAME, END OF ITAB. DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE, receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE, packing_[More]

After sending attachment through mail using ABAP program.....

Category:DefaultRelease time:-0001-11-30Views:130

Hello Experts, I am facing a problem to fulfill a requirement. My requirement is....sending the data of the internal table to an external mail with attachment(excel format). I have done with this. But when o am opening the excel sheet(attachment) it[More]

Reading email using abap program

Category:DefaultRelease time:-0001-11-30Views:130

Hi All, I have a requirement to read inbox mails through abap program. Also from address, to address, subject. Could someone help me  !! Thanks in advance, Venkat Moderator message : Requirements dumping not allowed, show the work you have already do[More]

Program to send mails from an ABAP program

Category:DefaultRelease time:-0001-11-30Views:130

Hello,        I found the following program on the internet. When i run it i get the status as mail sent, but actually the mail is not delivered to the recipients email address. If i check tcode SBWP, a copy of the sent mail sits in outbox even thoug[More]

Regarding text attachment in Email in ABAP program

Category:DefaultRelease time:2015-10-11Views:130

Hello... Need your expertise in one of the issues. Requirement is seems to be simple but i am stuck up at this moment. i have refereed SDN with Several code but some point its not giving the proper solution. So its a request to you please do not prov[More]

Is it possible to reset password for any user using abap program

Category:DefaultRelease time:2015-10-11Views:130

Hi friends, Is it possible to reset password for any user using abap program by specifying client number and user id. in selection screen. if any code for that to reset password please mail me. Thanks & Regards, YogeshHello Yogesh, Yes you can reset[More]

CONVT_NO_NUMBER Dump error in Process Chain Abap Program

Category:DefaultRelease time:2015-10-11Views:130

Hi Experts, The daily running process chain is failed at ABAP program with the error CONVT_NO_NUMBER. The reason for the exception is:                                        The program attempted to interpret the value "40-799" as a number, but [More]

Abap program - end of process chain

Category:DefaultRelease time:-0001-11-30Views:130

Hi, I have a requirement. At the end of each process chain, the ABAP program must trigger email. The process chains are having naming format of Z<Module name>. Ex: SD process chain will have ZSD, PS process chain will have ZPS etc. Now we are readin[More]

How to implement  mailing in ABAP

Category:DefaultRelease time:-0001-11-30Views:130

Hi all, I want to send mail from my abap program to number of recepient, at a perticular time. Is it possible in ABAP to run a perticuler module at a pericler time say 8 AM every morning?Hi, Check this link for mailing.. /people/thomas.jung3/blog/200[More]

Hot
I have a question regarding the memory compatibility. (The A8-117 is a 1.6 GHz Centrino (Pentuin M processor 730) with 533 MHz FSB, and 2 MB of 2nd level cache, Intel® 915GM Express chipset) At the moment i have 1 chip of 512MB (333MHz, CL 2.5) insta [More]
Hi Experts,   I have searched SDN around 8 hours and could not get any help on my below issue.   I am developing ALV report using function module (Classical ALV). ALV output has 4 input enable fields, if user enters data in any of those fields and cl [More]
Dear  sd experts i know I.P.O ( Individual 3RD Party Purchase Order Process) But tell me Business process why Vendor will send stock to Company ( After Loading The stock ) Again company will receive The stock ( Unloading ) Again Company will send to [More]
Hi, I need to subscribe one report from SSRS to different set of people. EMail list is dynamic and will come from a database table. Could somebody help us please.Hi AjayKumar_MIND, According to your description, you want to configure subscription for [More]
Some apps have files associated with the app, so if the file was included in an email and the user touched it the app would launch and load the file. Is it possible to embed one of these files in an ibook so that when the reader touches it the app wi [More]
I/m not about to install my adobe photoshop elements 13 for my windows pc can someone please assistDo you get any error numbers?  Is it download that is the problem or is it installing that is the problem.  Please explain.Read other 2 answers [More]
I recently upgraded my iPad 2 to iOS8. When I attempted to use an iCloud enabled app, ie. the Calendar, an alert pops up telling me to accept the iCloud terms and conditions. When I choose to continue in order to do so, it directs me to settings. How [More]
Hi, How to modify the screen of infotype standard? I need to include a field in the screen. Thanks, Daniel SanchezHi Daniel- dding fields to standard Infotype SAP allows you to add additional fields to any standard Infotype. Step 1 Using transaction [More]
When playing music via iMac or iPad using my airport express through the hifi the signal repeatedly drops either for a second or two or more recently for hours. Any ideas?Do you currently have the 802.11n AirPort Express Base Station (AXn) configured [More]
Snce upgrading to ios 6 when using facetime or skype i can see/ hear but at he other end they only hear static. I have seen i am not the only one with this prblem? Has anyone a solution that works? Thank you JuanI saw one post where the user said dus [More]