Sunday, April 29, 2012

Program to send 2 internal tables data as two attachments to mail id outside SAP System

·        
This code helps in sending 2 internal tables data as two separate attachments in a single mail id outside sap system                                                             
REPORT  ZBC_ITAB_TO_EXCEL_NEW                  
CLASS: cl_abap_char_utilities DEFINITION LOAD.
DATA: docdata LIKE sodocchgi1,
      objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
      objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
      objbin1 LIKE solisti1 OCCURS 10 WITH HEADER LINE,
      objbin2 LIKE solisti1 OCCURS 10 WITH HEADER LINE,
      objbin_final LIKE solisti1 OCCURS 10 WITH HEADER LINE,
      reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
      tab_lines TYPE sy-tabix.
DATA: gd_sender_type LIKE soextreci1-adr_typ.
DATA: c_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
      c_ret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
DATA: c_dev TYPE sy-sysid.
DATA: BEGIN OF i_data OCCURS 0,
      a(20),
      b(20),
      END OF i_data.
DATA: BEGIN OF st,
      f1(2) TYPE c,
      f2(2) TYPE n,
      END OF st.
DATA: itab1 LIKE TABLE OF st WITH HEADER LINE,
      itab2 LIKE TABLE OF st WITH HEADER LINE.
DATA: n TYPE i.
PARAMETER: p_email1 LIKE somlreci1-receiver
                    DEFAULT 'example@yahoo.com',
           p_sender LIKE somlreci1-receiver.
START-OF-SELECTION.
  itab1-f1 = 'AA'. itab1-f2 = '01'. APPEND itab1.
  itab1-f1 = 'BB'. itab1-f2 = '02'. APPEND itab1.
  itab1-f1 = 'CC'. itab1-f2 = '03'. APPEND itab1.
  itab2-f1 = 'ZZ'. itab2-f2 = '26'. APPEND itab2.
  itab2-f1 = 'YY'. itab2-f2 = '25'. APPEND itab2.
  LOOP AT itab1.
    CONCATENATE itab1-f1 itab1-f2 INTO objbin1 separated BY c_tab.
    CONCATENATE c_ret objbin1 INTO objbin1.
    APPEND objbin1.
  ENDLOOP.
  LOOP AT itab2.
    CONCATENATE itab2-f1 itab2-f2 INTO objbin2 separated BY c_tab.
    CONCATENATE c_ret objbin2 INTO objbin2.
    APPEND objbin2.
  ENDLOOP.
  LOOP AT objbin1.
    MOVE objbin1-line TO objbin_final-line.
    APPEND objbin_final.
  ENDLOOP.
  LOOP AT objbin2.
    MOVE objbin2-line TO objbin_final-line.
    APPEND objbin_final.
  ENDLOOP.
  PERFORM process_email.
  c_dev = sy-sysid.
  IF sy-sysid = c_dev.
    wait up to 5 seconds.
    SUBMIT rsconn01 WITH mode = 'INT'
    WITH output = 'X'
    AND RETURN.
  ENDIF.
  IF sy-subrc = 0.
    WRITE: / 'Email succesfilly delivered'.
  ELSE.
    WRITE: / 'failure'.
  ENDIF.
*&--------------------------------------------------------------------*
*&      Form  process_email
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM process_email.
  IF p_sender EQ space.
    gd_sender_type = space.
  ELSE.
    gd_sender_type = 'INT'.
  ENDIF.
*Body
  docdata-obj_name = 'Mail_Excel_File'.
  docdata-obj_descr = 'Excel file attachment'.
  objtxt = 'Attached is the sample Excel file'.
  APPEND objtxt.
  DESCRIBE TABLE objtxt LINES tab_lines.
  READ TABLE objtxt INDEX tab_lines.
  docdata-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).
  CLEAR objpack-transf_bin.
  objpack-head_start = 1.
  objpack-head_num = 0.
  objpack-body_start = 1.
  objpack-body_num = tab_lines.
  objpack-doc_type = 'RAW'.
  APPEND objpack.
*Attachment 1
  n = 1.
  DESCRIBE TABLE objbin1 LINES tab_lines.
  objpack-doc_size = tab_lines * 255.
  objpack-transf_bin = 'X'.
  objpack-head_start = 1.
  objpack-head_num = 1.
  objpack-body_start = n.
  objpack-body_num = tab_lines.
  objpack-doc_type = 'XLS'.
  docdata-obj_name = 'Excel_File_Attachment1'.
  objpack-obj_descr = 'Excel File Attachment1'.
  APPEND objpack.
*Attachment 2
  n = n + tab_lines.
  DESCRIBE TABLE objbin2 LINES tab_lines.
  objpack-doc_size = tab_lines * 255.
  objpack-transf_bin = 'X'.
  objpack-head_start = 1.
  objpack-head_num = 1.
  objpack-body_start = n.
  objpack-body_num = tab_lines.
  objpack-doc_type = 'XLS'.
  docdata-obj_name = 'Excel_File_Attachment2'.
  objpack-obj_descr = 'Excel File Attachment2'.
  APPEND objpack.
*Create the list of recipients
  reclist-receiver = p_email1.
  reclist-rec_type = 'U'.
  reclist-express = 'X'.
  APPEND reclist.
*Send the e-mail
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = docdata
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = objpack
      contents_bin               = objbin_final
      contents_txt               = objtxt
      receivers                  = 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.
  COMMIT WORK.
ENDFORM.                    "process_email


 

11 comments:

  1. thanks
    --
    Find the best job in mykareer. com .India's No. 1 Job Site. Sales Jobs, Marketing Jobs, IT Jobs, Telecom Jobs, Software Jobs, HR Jobs, Banking Jobs, Finance Jobs, Gulf Jobs, International Jobs.Dream Jobs for Freshers/Professionals/Executives in Delhi/NCR, Mumbai, Bangalore, Hyderabad, Pune and Chennai.Post your Resume now to find your Dream Job!
    http://www.mykareer.com/post_resume.php

    ReplyDelete
  2. Free job posting Site, Fresher Jobs, Latest Jobs


    NCR-Jobs.com provides Free Job Posting Services for the Employers and Job seekers to post and search jobs all over the India & Delhi NCR. Delhi NCR Provides Job Posting for the Employers and Job seekers to post and search jobs all over the India.

    Keywords: - Delhi Jobs for fresher, Delhi Jobs IT, Delhi Jobs Marketing, Ghaziabad Jobs Fresher, Ghaziabad Jobs IT, Ghaziabad jobs Marketing, Noida Jobs for fresher, Noida Jobs IT, Noida Jobs Marketing


    Contact Us

    Brainguru Technologies Pvt. Ltd. Noida
    C - 17, FF, Sector 2
    Noida, Uttar Pradesh 201301
    PH: - 0120 4299500
    http://www.ncr-jobs.com/

    ReplyDelete
  3. Jobs in India - Free Job Posting Site, Fresher Jobs, Latest Jobs


    NCR-Jobs.com provides Free Job Posting Services for the Employers and Job seekers to post and search jobs all over the India Delhi NCR. Delhi NCR Provides Job Posting for the Employers and Job seekers to post and search jobs in all over India.

    Keywords:-

    Latest Jobs, Fresher Jobs, Jobs in India, Free job posting Site, Delhi Jobs for fresher, Delhi Jobs IT, Delhi Jobs Marketing, Ghaziabad Jobs Freshers, Ghaziabad Jobs IT, Ghaziabad jobs Marketing, Noida Jobs for fresher, Noida Jobs IT, Noida Jobs Marketing

    Brainguru Technologies Pvt Ltd.
    C -17, First Floor
    Sector - 2, Noida
    Call Us: +91-8010010000, 0120-4299500
    Email us: info@brainguru.in
    http://ncr-jobs.com/

    ReplyDelete
  4. Jobs in India - Free job posting Site, Fresher Jobs, Latest Jobs

    NCR-Jobs are provided Free Job Services in NCR Specially Employers and Job seekers who want search jobs in all over India like Dept Manager, Tele Caller, Marketing Executive (Fresher) and SEO Trainee (Fresher).

    Keyword-
    Latest Jobs, Fresher Jobs, Jobs in India, Free job posting Site, Delhi Jobs for fresher, Delhi Jobs IT, Delhi Jobs Marketing, Ghaziabad Jobs Freshers, Ghaziabad Jobs IT, Ghaziabad jobs Marketing, Noida Jobs for fresher, Noida Jobs IT, Noida Jobs Marketing

    Contact-
    Brainguru Technologies Pvt Ltd.
    D -67
    Sector - 2, Noida
    Call Us: +91-8010010000, 0120-4299500
    Email us: info@brainguru.in
    http://ncr-jobs.com/

    ReplyDelete
  5. NCR Jobs is the free job posting site in India. NCR jobs provides you the easy platform to connect with the latest vacancy according to your profile.

    FREE JOB POSTING SITE

    ReplyDelete
  6. Nice article, always loved to read your articles.I would like to share some more information related to free job posting in india

    ReplyDelete
  7. Recruitment Notification is one of the Top most Job Portal Govt jobs karnataka notificationsthere

    ReplyDelete