List of all pages
Pages at first level
I have been working on an upgrade project for the past 6 months and recently came across a dump on ECC 6.0. The dump analysis says "Relationship ATTA Can No Longer Be Used with this Interface". The problem occurred because of a function module SREL_GET_NEXT_NEIGHBORS which doesn't work as desired in ECC like it worked in 4.6. I searched on SDN and googled for the same. But no great results. Finally I managed to find a solution for the same and thought of sharing it with the people out here.
I am attaching a code snippet that might help people facing similar problem in upgrade projects.
4.6 Code :
CALL FUNCTION 'SREL_GET_NEXT_NEIGHBORS' EXPORTING object = g_bor_object roletype = 'APPLOBJ' relationtype = 'ATTA' TABLES neighbors = l_neighbors EXCEPTIONS internal_error = 1 no_logsys = 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.
ECC Replacement :
TRY. DATA: l_rol TYPE oblroltype. l_rol = 'GOSAPPLOBJ'. CALL METHOD cl_binary_relation=>read_links_of_binrel EXPORTING is_object = g_bor_object ip_logsys = g_bor_logsys ip_relation = 'ATTA' ip_role = l_rol IMPORTING et_links = l_neighbors. CATCH cx_obl_parameter_error . CATCH cx_obl_internal_error . CATCH cx_obl_model_error . ENDTRY.
I hope this helps many and solve the problems faced by them in upgrade issues.
This page contains ABAP snippets which send emails.
The program is used to convert output of ALV/CLASSICAL reports into HTML format and mail it as attachment to the mail id’s specified in a custom distribution list.The distribution lists can be maintained using transaction SO23 or please check following link http://help.sap.com/saphelp_nw04/helpdata/en/a8/809d1dfc8711d2a2b400a0c943858e/content.htm
General program flow.
Step 1: With input values the report is executed using Submit and Return ,and exported to spool
Step 2: The spool is retrieved.
Step 3: Using Fun.Mod. Compress the table .
Step 4: Create attachment .
Step 5: Send mail using SO_NEW_DOCUMENT_ATT_SEND_API1.
Step 6: Run report "rsconn01" to release the queue and send mails.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'*&---------------------------------------------------------------------* *& Report ZALV_MAIL *&---------------------------------------------------------------------* REPORT zalv_mail. *=======================================================================* *PROGRAM ID : zalv_mail *PROGRAM TITLE : Mail ALV Report *AUTHOR : Harikrishnan.S *SUPPLIER : *DATE : 10.03.2011 *DEVELOPMENT ID : *CHANGE REQUEST NO : *DESCRIPTION : Mail any ALV/classical report output as * Attachment(HTML) *=======================================================================* INCLUDE zalv_mail_top. "TOP INCLUDE zalv_mail_performs. "PERFORMS INCLUDE zalv_mail_forms. "FORMS *&---------------------------------------------------------------------* *& Include ZALV_MAIL_TOP * *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* * DECLARATIONS *&---------------------------------------------------------------------* TABLES: tsp01,zdmail1. DATA: docdata LIKE sodocchgi1, objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE, objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE, objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE, objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE, objhex LIKE solix OCCURS 10 WITH HEADER LINE, reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE. DATA: tab_lines TYPE i, doc_size TYPE i, att_type LIKE soodk-objtp. DESCRIBE TABLE objbin LINES tab_lines. DATA:t_msg_att TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE. DATA:mstr_print_parms LIKE pri_params, mc_valid(1) TYPE c, mi_bytecount TYPE i, mi_length TYPE i, mi_rqident LIKE tsp01-rqident. DATA:it_zdmail TYPE TABLE OF zdmail1, wa_zdmail LIKE LINE OF it_zdmail. SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME. PARAMETER: p_repid TYPE sy-repid OBLIGATORY, p_varnt(25) TYPE c , p_attnam(25) TYPE c OBLIGATORY, p_title(25) TYPE c OBLIGATORY, p_body(255) TYPE c. PARAMETER p_dlid TYPE zdmail1-dlid OBLIGATORY. SELECTION-SCREEN END OF BLOCK b2. SELECTION-SCREEN END OF BLOCK b1. *&---------------------------------------------------------------------* *& Include ZALV_MAIL_PERFORMS * *&---------------------------------------------------------------------* * EXECUTE THE REPORT AND EXPORT TO SPOOL PERFORM call_report. * GET SPOOL REQUEST NO PERFORM get_spool_number USING p_repid sy-uname CHANGING mi_rqident. * GET DATA FRM SPOOL AND SEND MAIL PERFORM get_data_mail. *&---------------------------------------------------------------------* *& Include ZALV_MAIL_FORMS * *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form call_report *&---------------------------------------------------------------------* * Call any ALV REPORT *----------------------------------------------------------------------* FORM call_report . *SUBMIT ALV GRID REPORT TO SPOOL AND RETURN SUBMIT (p_repid) TO SAP-SPOOL USING SELECTION-SET p_varnt WITHOUT SPOOL DYNPRO DESTINATION space * COVER TEXT '' NEW LIST IDENTIFICATION 'X' IMMEDIATELY space AND RETURN. ENDFORM. " call_report *&---------------------------------------------------------------------* *& Form get_spool_number *&---------------------------------------------------------------------* * GET THE SPOOL REQUEST NO rq2name FROM TABLE TSP01 *----------------------------------------------------------------------* FORM get_spool_number USING: f_repid f_uname CHANGING f_rqident. DATA: lc_rq2name LIKE tsp01-rq2name. CONCATENATE f_repid "+0(8) f_uname+0(3) INTO lc_rq2name SEPARATED BY '_'. SELECT * FROM tsp01 WHERE rq2name = lc_rq2name ORDER BY rqcretime DESCENDING. f_rqident = tsp01-rqident. EXIT. ENDSELECT. IF sy-subrc NE 0. CLEAR f_rqident. ENDIF. ENDFORM." get_spool_number *&---------------------------------------------------------------------* *& Form spool_to_html *&---------------------------------------------------------------------* FORM spool_to_html . ENDFORM. " spool_to_html *&---------------------------------------------------------------------* *& Form GET_DATA_MAIL *&---------------------------------------------------------------------* FORM get_data_mail . DATA: mem_tab LIKE abaplist OCCURS 10. *GET DATA FRM SPOOL AND EXPORT AS LIST TO MEMORY SUBMIT rspolist EXPORTING LIST TO MEMORY AND RETURN WITH rqident = mi_rqident WITH first = '1' WITH last = '0'. CALL FUNCTION 'LIST_FROM_MEMORY' TABLES listobject = mem_tab EXCEPTIONS not_found = 1 OTHERS = 2. *COMPRESS LIST TO TABLE CALL FUNCTION 'TABLE_COMPRESS' * IMPORTING * COMPRESSED_SIZE = TABLES in = mem_tab out = objbin EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. MESSAGE ID '61' TYPE 'E' NUMBER '731' WITH 'TABLE_COMPRESS'. ENDIF. ** NOTE: Creation of attachment is finished yet. ** For your report, the attachment should be placed into table ** objtxt for plain text or ** objbin for binary content. ** Now create the message and send the document.'recipients!'. ** Create Message Body ** Title and Description docdata-obj_name = 'Royal Enfield'. docdata-obj_descr = p_title. ** Main Text objtxt = p_body. APPEND objtxt. objtxt = text-002. APPEND objtxt. objtxt = 'Have a nice day.'. APPEND objtxt. * ** Write Packing List (Main) * 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. ** Create Message Attachment * ** Write Packing List (Attachment) * att_type = 'ALI'. DESCRIBE TABLE objbin LINES tab_lines. READ TABLE objbin INDEX tab_lines. objpack-doc_size = ( tab_lines - 1 ) * 255 + strlen( objbin ). objpack-transf_bin = 'X'. objpack-head_start = 1. objpack-head_num = 0. objpack-body_start = 1. objpack-body_num = tab_lines. objpack-doc_type = att_type. objpack-obj_name = 'ATTACHMENT'. objpack-obj_descr = p_attnam. APPEND objpack. * ** Create receiver list CLEAR: it_zdmail, wa_zdmail. SELECT * INTO TABLE it_zdmail FROM zdmail1 WHERE dlid = p_dlid. *ADD THE EMAIL IDS TO RECLIST-RECEIVER * loop changed 10/MAY/2011 - HKS LOOP AT it_zdmail INTO wa_zdmail. reclist-receiver = wa_zdmail-email. "<-- change address reclist-rec_type = 'U'. APPEND reclist. ENDLOOP. reclist-receiver = sy-uname. "<-- change internal user reclist-rec_type = 'B'. APPEND reclist. ** Send Message * CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = docdata put_in_outbox = 'X' commit_work = 'X' "used from rel.6.10 TABLES packing_list = objpack object_header = objhead contents_bin = objbin receivers = reclist. * ADDED BY HARIKRISHNAN-HBS:06.05.2011 * REASON: "reclist" IF NOT CLEARED THE MAIL WILL BE REPEATEDLY * SENT TO SAME ADDRESS CLEAR reclist. * END OF ADDITION BY HARIKRISHNAN-HBS:06.05.2011 IF sy-subrc <> 0. *RELEASE AND SEND MESSAGES IN QUEUE CALL FUNCTION 'SO_DEQUEUE_UPDATE_LOCKS' EXCEPTIONS communication_failure = 1 system_failure = 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. SUBMIT rsconn01 WITH mode = 'INT' WITH output = ' ' AND RETURN. ENDIF. ENDFORM. " GET_DATA_MAIL
TABLE DETAILS (ZTABLE FOR DIST LIST)
FIELD |
KEY |
INITIAL |
DATAELEMENT |
DATA TYPE |
LENGTH |
DECIMAL |
DESCRIPTION |
---|---|---|---|---|---|---|---|
MANDT |
X |
X |
MANDT |
CLNT |
3 |
0 |
CLIENT |
SRNR |
X |
X |
ZSRNR |
INT4 |
10 |
0 |
SERIAL NO |
DLID |
|
|
ZDLID |
CHAR |
20 |
0 |
DISTRIBUTION LIST ID |
EMAIL |
|
|
AD_SMTPADR |
CHAR |
241 |
0 |
EMAIL ADDRESS |
Now you can maintain data by creating a parameter transaction.
the signature of CL_DOCUMENT_BCS~ADD_ATTACHMENT:
Back to Sending Mails - Home Page
I have seen many approaches for sending mail with attachment. Here i am writing a function module to send mail with attachment using object oriented approach. The use of this approach would eliminate bulky coding.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'FUNCTION ZNPI_SEND_MAIL. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(SUBJECT) TYPE SO_OBJ_DES *" VALUE(MESSAGE_BODY) TYPE BCSY_TEXT *" VALUE(ATTACHMENTS) TYPE RMPS_T_POST_CONTENT OPTIONAL *" VALUE(SENDER_UID) TYPE SYUNAME OPTIONAL *" VALUE(RECIPIENT_UID) TYPE SYUNAME OPTIONAL *" VALUE(SENDER_MAIL) TYPE ADR6-SMTP_ADDR OPTIONAL *" VALUE(RECIPIENT_MAIL) TYPE ADR6-SMTP_ADDR OPTIONAL *" EXPORTING *" VALUE(RESULT) TYPE BOOLEAN *" TABLES *" RECIPIENTS STRUCTURE UIYS_IUSR OPTIONAL *"---------------------------------------------------------------------- *Data Declaration DATA: lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL, l_send type ADR6-SMTP_ADDR , l_rec type ADR6-SMTP_ADDR . Data : ITAB TYPE TABLE OF SVAL, LS_ITAB TYPE SVAL, i_RETURN. DATA: lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL. * DATA: * lt_message_body TYPE bcsy_text VALUE IS INITIAL, DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL, attachment_subject type SO_OBJ_DES. DATA: lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL. data: ls_recipient like line of recipients, ls_attachment like line of attachments. DATA: lv_recipient_uid TYPE uname, lv_recipient_mail TYPE adr6-smtp_addr. *Prepare Mail Object CLASS cl_bcs DEFINITION LOAD. lo_send_request = cl_bcs=>create_persistent( ). * Message body and subject data: lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL. lo_document = cl_document_bcs=>create_document( i_type = 'RAW' i_text = message_body i_subject = subject ). *Send attachment loop at attachments into ls_attachment. attachment_subject = ls_attachment-subject. TRY. lo_document->add_attachment( EXPORTING i_attachment_type = ls_attachment-OBJTP i_attachment_subject = attachment_subject i_att_content_hex = ls_attachment-CONT_HEX ). CATCH cx_document_bcs INTO lx_document_bcs. ENDTRY. endloop. * Pass the document to send request lo_send_request->set_document( lo_document ). try. if sender_mail is not initial. lo_sender = cl_cam_address_bcs=>create_internet_address( sender_mail ). elseif sender_uid is not initial. lo_sender = cl_sapuser_bcs=>create( sender_uid ). else. lo_sender = cl_sapuser_bcs=>create( sy-uname ). endif. * Set sender lo_send_request->set_sender( EXPORTING i_sender = lo_sender ). catch CX_ADDRESS_BCS. return. endtry. * Set recipients if recipients[] is initial. if recipient_mail is not initial. lo_recipient = cl_cam_address_bcs=>create_internet_address( recipient_mail ). elseif recipient_uid is not initial. lo_recipient = cl_sapuser_bcs=>create( recipient_uid ). else. lo_recipient = cl_sapuser_bcs=>create( sy-uname ). endif. lo_send_request->add_recipient( EXPORTING i_recipient = lo_recipient i_express = 'X' ). else. loop at recipients into ls_recipient. if ls_recipient-iusrid is not initial. lv_recipient_uid = ls_recipient-iusrid. lo_recipient = cl_sapuser_bcs=>create( lv_recipient_uid ). elseif ls_recipient-email is not initial. lv_recipient_mail = ls_recipient-email . lo_recipient = cl_cam_address_bcs=>create_internet_address( lv_recipient_mail ). endif. lo_send_request->add_recipient( EXPORTING i_recipient = lo_recipient i_express = 'X' ). endloop. endif. try. ** Send email lo_send_request->send( EXPORTING i_with_error_screen = 'X' RECEIVING result = result ). COMMIT WORK. wait up to 1 seconds. catch cx_send_req_bcs. result = ''. endtry. ENDFUNCTION.
DATA method1 LIKE sy-ucomm. DATA g_user LIKE soudnamei1. DATA g_user_data LIKE soudatai1. DATA g_owner LIKE soud-usrnam. DATA g_receipients LIKE soos1 OCCURS 0 WITH HEADER LINE. DATA g_document LIKE sood4 . DATA g_header LIKE sood2. DATA g_folmam LIKE sofm2. DATA g_objcnt LIKE soli OCCURS 0 WITH HEADER LINE. DATA g_objhead LIKE soli OCCURS 0 WITH HEADER LINE. DATA g_objpara LIKE selc OCCURS 0 WITH HEADER LINE. DATA g_objparb LIKE soop1 OCCURS 0 WITH HEADER LINE. DATA g_attachments LIKE sood5 OCCURS 0 WITH HEADER LINE. DATA g_references LIKE soxrl OCCURS 0 WITH HEADER LINE. DATA g_authority LIKE sofa-usracc. DATA g_ref_document LIKE sood4. DATA g_new_parent LIKE soodk. DATA: BEGIN OF g_files OCCURS 10 , text(4096) TYPE c, END OF g_files. DATA : fold_number(12) TYPE c, fold_yr(2) TYPE c, fold_type(3) TYPE c. PARAMETERS ws_file(4096) TYPE c DEFAULT 'Insert ur Document' here''. * Can me any file fromyour pc ....either xls or word or ppt etc ... g_user-sapname = sy-uname. CALL FUNCTION 'SO_USER_READ_API1' EXPORTING user = g_user IMPORTING user_data = g_user_data EXCEPTIONS USER_NOT_EXIST = 1 PARAMETER_ERROR = 2 X_ERROR = 3 OTHERS = 4 . fold_type = g_user_data-outboxfol+0(3). fold_yr = g_user_data-outboxfol+3(2). fold_number = g_user_data-outboxfol+5(12). CLEAR g_files. REFRESH : g_objcnt, g_objhead, g_objpara, g_objparb, g_receipients, g_attachments, g_references, g_files. method1 = 'SAVE'. g_document-foltp = fold_type. g_document-folyr = fold_yr. g_document-folno = fold_number. g_document-objtp = g_user_data-object_typ. *g_document-OBJYR = '27'. *g_document-OBJNO = '000000002365'. *g_document-OBJNAM = 'MESSAGE'. g_document-objdes = 'sap-img.com testing by program'. g_document-folrg = 'O'. *g_document-okcode = 'CHNG'. g_document-objlen = '0'. g_document-file_ext = 'TXT'. g_header-objdes = 'sap-img.com testing by program'. g_header-file_ext = 'TXT'. CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER' EXPORTING method = method1 office_user = sy-uname ref_document = g_ref_document new_parent = g_new_parent IMPORTING authority = g_authority TABLES objcont = g_objcnt objhead = g_objhead objpara = g_objpara objparb = g_objparb recipients = g_receipients attachments = g_attachments references = g_references files = g_files CHANGING document = g_document header_data = g_header. * File from the pc to send... method1 = 'ATTCREATEFROMPC'. g_files-text = ws_file. APPEND g_files. CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER' EXPORTING method = method1 office_user = g_owner ref_document = g_ref_document new_parent = g_new_parent IMPORTING authority = g_authority TABLES objcont = g_objcnt objhead = g_objhead objpara = g_objpara objparb = g_objparb recipients = g_receipients attachments = g_attachments references = g_references files = g_files CHANGING document = g_document header_data = g_header. method1 = 'SEND'. g_receipients-recnam = 'MK085'. g_receipients-recesc = 'B'. g_receipients-sndex = 'X'. APPEND g_receipients. CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER' EXPORTING method = method1 office_user = g_owner ref_document = g_ref_document new_parent = g_new_parent IMPORTING authority = g_authority TABLES objcont = g_objcnt objhead = g_objhead objpara = g_objpara objparb = g_objparb recipients = g_receipients attachments = g_attachments references = g_references files = g_files CHANGING document = g_document header_data = g_header. *-- End of Program
Author: Runal Singh
Submitted: 16/01/2008
FUNCTION z_send_email_itab_uname. *"----------------------------------------------------------------------*" *"Local interface: *" IMPORTING *" VALUE(APPLICATION) LIKE SOOD1-OBJNAM *" VALUE(EMAILTITLE) LIKE SOOD1-OBJDES *" VALUE(RECEXTNAM) LIKE SOOS1-RECEXTNAM OPTIONAL *" VALUE(SENDER) LIKE SOUD-USRNAM DEFAULT SY-UNAME *" VALUE(UNAME) LIKE SOOS1-RECEXTNAM OPTIONAL *" EXPORTING *" VALUE(RETURN_CODE) LIKE SY-SUBRC *" TABLES *" TEXTTAB STRUCTURE SOLI *"---------------------------------------------------------------------- * tables TABLES: pa0105, "Employee detail for username and email address usr21, "Login addition address data adr6. "Address table for email addresses *- local data declaration DATA: ohd LIKE sood1, oid LIKE soodk, to_all LIKE sonv-flag, t_uname LIKE sy-uname, okey LIKE swotobjid-objkey. DATA: BEGIN OF receivers OCCURS 0. INCLUDE STRUCTURE soos1. DATA: END OF receivers. *- fill odh CLEAR ohd. ohd-objla = sy-langu. ohd-objnam = application. ohd-objdes = emailtitle. ohd-objpri = 3. ohd-objsns = 'F'. ohd-ownnam = sy-uname. IF NOT uname IS INITIAL. * Find personnel number of username CONDENSE uname NO-GAPS. WHILE uname CS ','. t_uname = uname+0(sy-fdpos). ADD 1 TO sy-fdpos. SHIFT uname LEFT BY sy-fdpos PLACES. PERFORM find_email_address USING t_uname CHANGING recextnam. ENDWHILE. *Do the last record IF uname <> space. t_uname = uname. PERFORM find_email_address USING t_uname CHANGING recextnam. ENDIF. ENDIF. *- send Email IF NOT recextnam IS INITIAL. CONDENSE recextnam NO-GAPS. CHECK recextnam CS '@'. ENDIF. *- for every individual recipient send an Email* WHILE recextnam CS ','. PERFORM init_rec TABLES receivers. READ TABLE receivers INDEX 1. r eceivers-recextnam = recextnam+0(sy-fdpos). ADD 1 TO sy-fdpos. SHIFT recextnam LEFT BY sy-fdpos PLACES. MODIFY receivers INDEX 1. PERFORM so_object_send_rec TABLES texttab receivers USING ohd sender. ENDWHILE. *- check last recipient in recipient list IF recextnam <> space. PERFORM init_rec TABLES receivers. READ TABLE receivers INDEX 1. receivers-recextnam = recextnam. MODIFY receivers INDEX 1. PERFORM so_object_send_rec TABLES texttab receivers USING ohd sender. ENDIF. ENDFUNCTION. *---------------------------------------------------------------------* * FORM SO_OBJECT_SEND_REC * *---------------------------------------------------------------------* FORM so_object_send_rec TABLES objcont STRUCTURE soli receivers STRUCTURE soos1 USING object_hd STRUCTURE sood1 sender LIKE soud-usrnam. DATA: oid LIKE soodk, to_all LIKE sonv-flag, okey LIKE swotobjid-objkey. CALL FUNCTION 'SO_OBJECT_SEND' EXPORTING extern_address = 'X' object_hd_change = object_hd object_type = 'RAW' outbox_flag = 'X' sender = sender IMPORTING object_id_new = oid sent_to_all = to_all office_object_key = oke TABLES objcont = objcont receivers = receivers EXCEPTIONS active_user_not_exist = 1 communication_failure = 2 component_not_available = 3 folder_not_exist = 4 folder_no_authorization = 5 forwarder_not_exist = 6 note_not_exist = 7 object_not_exist = 8 object_not_sent = 9 object_no_authorization = 10 object_type_not_exist = 11 operation_no_authorization = 12 owner_not_exist = 13 parameter_error = 14 substitute_not_active = 15 substitute_not_defined = 16 system_failure = 17 too_much_receivers = 18 user_not_exist = 19 x_error = 20 OTHERS = 21. IF sy-subrc <> 0. CASE sy-subrc. WHEN 1. MESSAGE i999(b1) WITH 'Activer user does not exist.' 'Send Mail failed!'. WHEN 2. MESSAGE i999(b1) WITH 'Communication Failure.' 'Send Mail failed!'. WHEN 3. MESSAGE i999(b1) WITH 'Component not available.' 'Send Mail failed!'. WHEN 4. MESSAGE i999(b1) WITH 'Folder does not exist.' 'Send Mail failed!'. WHEN 5. MESSAGE i999(b1) WITH 'No authorization for folder.' 'Send Mail failed!'. WHEN 6. MESSAGE i999(b1) WITH 'Forwarder does not exist.' 'Send Mail failed!'. WHEN 7. MESSAGE i999(b1) WITH 'Note does not exist.' 'Send Mail failed!'. WHEN 8. MESSAGE i999(b1) WITH 'Object does not exist.' 'Send Mail failed!'. WHEN 9. MESSAGE i999(b1) WITH 'Object not sent.' 'Send Mail failed!'. WHEN 10. MESSAGE i999(b1) WITH 'No authorization for object.' 'Send Mail failed!'. WHEN 11. MESSAGE i999(b1) WITH 'Object type does not exist.' 'Send Mail failed!'. WHEN 12. MESSAGE i999(b1) WITH 'No authorization for operation.' 'Send Mail failed!'. WHEN 13. MESSAGE i999(b1) WITH 'Owner does not exist.' 'Send Mail failed!'. WHEN 14. MESSAGE i999(b1) WITH 'Parameter Error.' 'Send Mail failed!'. WHEN 15. MESSAGE i999(b1) WITH 'Substitute not active.' 'Send Mail failed!'. WHEN 16. MESSAGE i999(b1) WITH 'Substitute not defined.' 'Send Mail failed!'. WHEN 17. MESSAGE i999(b1) WITH 'System failure.' 'Send Mail failed!'. WHEN 18. MESSAGE i999(b1) WITH 'Too many receivers.' 'Send Mail failed!'. WHEN 19. MESSAGE i999(b1) WITH 'User does not exist.' 'Send Mail failed!'. WHEN 20. MESSAGE i999(b1) WITH 'Unknown error ocurred.' 'Send Mail failed!'. WHEN 21. MESSAGE i999(b1) WITH 'Unknown error ocurred.' 'Send Mail failed!'. ENDCASE. ENDIF. ENDFORM. "so_object_send_rec *****----------------------------------------------------------------------* * FORM INIT_REC **-------------------------------------------------------------------------* FORM init_rec TABLES receivers STRUCTURE soos1. CLEAR receivers. REFRESH receivers. MOVE sy-datum TO receivers-rcdat . MOVE sy-uzeit TO receivers-rctim. MOVE '1' TO receivers-sndpri. MOVE 'X' TO receivers-sndex. MOVE 'U-' TO receivers-recnam. MOVE 'U' TO receivers-recesc. MOVE 'INT' TO receivers-sndart. MOVE '5' TO receivers-sortclass. APPEND receivers. ENDFORM. "init_rec *&---------------------------------------------------------------------* *& Form find_email_address *&---------------------------------------------------------------------* * Returns the email address for a USERID whether they are an * employee or just a user. *----------------------------------------------------------------------* * <--P_RECEXTNAM Email address * -->P_UNAME USERID *----------------------------------------------------------------------* FORM find_email_address USING p_uname CHANGING p_recextnam LIKE soos1-recextnam. DATA: t_pernr LIKE pa0105-pernr, t_email LIKE pa0105-usrid_long. * STEP 1 - Find personnel number for UNAME SELECT SINGLE pernr INTO t_pernr FROM pa0105 WHERE subty = '0001' AND endda >= sy-datum AND begda <= sy-datum AND usrid = p_uname. * Employee record found IF sy-subrc = 0. * STEP 2 - Find email address for personnel number SELECT SINGLE usrid_long INTO t_email FROM pa0105 WHERE pernr = t_pernr AND subty = '0022' AND endda >= sy-datum AND begda <= sy-datum. IF sy-subrc = 0. IF NOT p_recextnam IS INITIAL. CONCATENATE p_recextnam t_email INTO p_recextnam SEPARATED BY ','. ELSE. p_recextnam = t_email. ENDIF. ELSE. "Never found an email address for employee *** WHO SHOULD WE SEND TO HERE??? *** ENDIF. * Employee number not found. *Search in ADR6 table ELSE. * See if user name is in the username table. * i.e. The user is not an employee SELECT SINGLE addrnumber persnumber INTO (usr21-addrnumber, usr21-persnumber) FROM usr21 WHERE bname = p_uname. IF sy-subrc = 0. * Found user name now let's get the email address SELECT SINGLE smtp_addr INTO t_email FROM adr6 WHERE addrnumber = usr21-addrnumber AND persnumber = usr21-persnumber. IF sy-subrc <> 0 OR t_email IS INITIAL. *** WHO SHOULD WE SEND TO HERE??? *** ELSE. "Found email IF NOT p_recextnam IS INITIAL. CONCATENATE p_recextnam t_email INTO p_recextnam SEPARATED BY ','. ELSE. p_recextnam = t_email. ENDIF. ENDIF. ELSE. "UNAME just does not have an email address addigned at all *** WHO SHOULD WE SEND TO HERE??? *** ENDIF. ENDIF. ENDFORM. " find_email_address
Back to Sending Mails - Home Page
Generates PDF output from pre-existing ZFHR_TRAVEL_REQUEST Adobe Form.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'DATA : function TYPE funcname, ftype TYPE fpinterfacetype, fname TYPE funcname. DATA : outputparams TYPE sfpoutputparams. PARAMETER: p_email TYPE adr6-smtp_addr OBLIGATORY. outputparams-nodialog = 'X'. outputparams-preview = 'X'. outputparams-dest = 'PDF1'. outputparams-getpdf = 'X'. DATA: fp_docparams TYPE sfpdocparams. DATA: fp_formoutput TYPE fpformoutput. CALL FUNCTION 'FP_JOB_OPEN' CHANGING ie_outputparams = outputparams * EXCEPTIONS * CANCEL = 1 * USAGE_ERROR = 2 * SYSTEM_ERROR = 3 * INTERNAL_ERROR = 4 * OTHERS = 5 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CALL FUNCTION 'FP_FUNCTION_MODULE_NAME' EXPORTING i_name = 'ZFHR_TRAVEL_REQUEST' IMPORTING e_funcname = function e_interface_type = ftype ev_funcname_inbound = fname. fp_docparams-langu = 'E'. fp_docparams-country = 'IN'. fp_docparams-fillable = 'X'. CALL FUNCTION function EXPORTING /1bcdwb/docparams = fp_docparams employeename = '00050104' IMPORTING /1bcdwb/formoutput = fp_formoutput * EXCEPTIONS * USAGE_ERROR = 1 * SYSTEM_ERROR = 2 * INTERNAL_ERROR = 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. CALL FUNCTION 'FP_JOB_CLOSE' * IMPORTING * E_RESULT = * EXCEPTIONS * USAGE_ERROR = 1 * SYSTEM_ERROR = 2 * INTERNAL_ERROR = 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. ************************************************************ *Download file DATA: filename TYPE string, path TYPE string, fullpath TYPE string, default_extension TYPE string VALUE 'PDF'. cl_gui_frontend_services=>file_save_dialog( EXPORTING default_extension = default_extension CHANGING filename = filename path = path fullpath = fullpath ). CHECK fullpath IS NOT INITIAL. DATA: data_tab TYPE TABLE OF x255. CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING buffer = fp_formoutput-pdf TABLES binary_tab = data_tab. *filename = 'E:\adobe\emptest.pdf'. cl_gui_frontend_services=>gui_download( EXPORTING filename = filename filetype = 'BIN' CHANGING data_tab = data_tab ). cl_gui_frontend_services=>execute( EXPORTING document = filename ). ************************************************************ * Mail * BCS data DATA send_request TYPE REF TO cl_bcs. DATA text TYPE bcsy_text. 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 sent_to_all TYPE os_boolean. DATA pdf_content TYPE solix_tab. DATA lp_pdf_size TYPE so_obj_len. TRY. * --------- create persistent send request --------------------- send_request = cl_bcs=>create_persistent( ). * --------- add document --------------------------------------- * get PDF xstring and convert it to BCS format lp_pdf_size = XSTRLEN( fp_formoutput-pdf ). pdf_content = cl_document_bcs=>xstring_to_solix( ip_xstring = fp_formoutput-pdf ). document = cl_document_bcs=>create_document( i_type = 'PDF' i_hex = pdf_content i_length = lp_pdf_size i_subject = 'Travel Request form' ). "#EC NOTEXT * add document to send request send_request->set_document( document ). * --------- add recipient (e-mail address) --------------------- recipient = cl_cam_address_bcs=>create_internet_address( i_address_string = p_email ). * add recipient to send request send_request->add_recipient( i_recipient = recipient ). * --------- send document -------------------------------------- sent_to_all = send_request->send( i_with_error_screen = 'X' ). IF sent_to_all = 'X'. MESSAGE i022(so). ENDIF. * --------- explicit 'commit work' is mandatory! --------------- COMMIT WORK. * ------------------------------------------------------------------ * * exception handling * ------------------------------------------------------------------ * * replace this very rudimentary exception handling * * with your own one !!! * ------------------------------------------------------------------ CATCH cx_bcs INTO bcs_exception. WRITE: text-001. WRITE: text-002, bcs_exception->error_type. EXIT. ENDTRY.
Hi All
I always struggle to analyze the classes in so50 tcode, not able to debug them when triggered via a mail ,Nevertheless I found a way of simulating it.
Isn't standard program BCS_TEST03 sufficient for testing inbound emails?
Here is custom built code
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'REPORT z_so50_exit. TYPES: BEGIN OF ty_range_att_type, zatt TYPE c LENGTH 4, zdesc TYPE char50, END OF ty_range_att_type. DATA: gv_rc TYPE i, gv_len TYPE i, gv_filename TYPE string. DATA: gs_x TYPE bcss_t100m, gs_text TYPE soli. DATA: gt_rc TYPE bcsy_smtpa, gt_doc TYPE bcsy_sodoc, gt_solix TYPE solix_tab, gt_text TYPE bcsy_text. DATA: go_pdfmail TYPE REF TO if_inbound_exit_bcs, go_cont TYPE REF TO cl_gui_custom_container, go_req TYPE REF TO cl_send_request_bcs, go_addr TYPE REF TO cl_cam_address_bcs, go_document TYPE REF TO cl_document_bcs, go_maint TYPE REF TO cl_ibnd_rules_maint_bcs, lt_range_att_type TYPE TABLE OF ty_range_att_type, lt_bcsy_smtp2 TYPE bcsy_smtp2, ls_range_att_type TYPE ty_range_att_type. PARAMETERS: p_file TYPE tdlen255 LOWER CASE, p_file1 TYPE ad_smtpadr LOWER CASE, p_file2 TYPE seoclsname LOWER CASE, p_file3(3). AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. DATA: gt_file TYPE filetable, gs_file TYPE file_table, gv_user_action TYPE i. CALL METHOD cl_gui_frontend_services=>file_open_dialog EXPORTING default_extension = '*' file_filter = '*' CHANGING file_table = gt_file rc = gv_rc user_action = gv_user_action EXCEPTIONS file_open_dialog_failed = 1 cntl_error = 2 error_no_gui = 3 not_supported_by_gui = 4 OTHERS = 5. READ TABLE gt_file INTO gs_file INDEX 1. p_file = gs_file-filename. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file3. CLEAR:lt_range_att_type. ls_range_att_type-zatt = 'PDF'. ls_range_att_type-zdesc = 'PDF'. APPEND ls_range_att_type TO lt_range_att_type. ls_range_att_type-zatt = 'XLS'. ls_range_att_type-zdesc = 'XLS'. APPEND ls_range_att_type TO lt_range_att_type. CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING retfield = 'ZDESC' dynpprog = sy-repid dynpnr = sy-dynnr dynprofield = 'P_FILE3' value_org = 'S' TABLES value_tab = lt_range_att_type. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file2. CLEAR:lt_bcsy_smtp2. CREATE OBJECT: go_cont EXPORTING container_name = 'CCONT' , go_maint EXPORTING io_cont = go_cont. go_maint->read_smtp_entries( IMPORTING et_entries = lt_bcsy_smtp2 ). CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING retfield = 'CLS_NAME' dynpprog = sy-repid dynpnr = sy-dynnr dynprofield = 'P_FILE2' value_org = 'S' TABLES value_tab = lt_bcsy_smtp2. START-OF-SELECTION. gv_filename = p_file. cl_gui_frontend_services=>gui_upload( EXPORTING filename = gv_filename filetype = 'BIN' IMPORTING filelength = gv_len CHANGING data_tab = gt_solix EXCEPTIONS OTHERS = 1 ). CHECK sy-subrc = 0. go_req = cl_send_request_bcs=>create( ). go_addr = cl_cam_address_bcs=>create_internet_address( i_address_string = p_file1 ). go_req->setu_sender( go_addr ). go_req->set_tech_sender( go_addr ). gs_text = 'Hello'. APPEND gs_text TO gt_text. go_document = cl_document_bcs=>create_document( i_type = 'RAW' i_text = gt_text i_length = '0' i_subject = 'Dummy text' ). go_document->add_attachment( i_attachment_type = p_file3 i_attachment_subject = 'My attachment' i_att_content_hex = gt_solix ). go_req->setu_document( i_document = go_document ). *create object reference of type class CALL METHOD (p_file2)=>if_inbound_exit_bcs~create_instance RECEIVING ro_ref = go_pdfmail. *casting of object reference to interface go_pdfmail->process_inbound( EXPORTING io_sreq = go_req it_recipients = gt_rc it_doctypes = gt_doc IMPORTING e_retcode = gv_rc es_t100msg = gs_x ).
Author: Pratik Mallick
Submitted: 5th August,2008
Description
In the code gallery I have found a number of examples showing how to attach an attachment to an email. There are examples of multi attachments too. But what the code snippets lack is proper explanation. Most of them are just codes which needs to be copy pasted without proper understanding. I have attempted to simplify the understanding by this simple, basic example of attaching an attachment. In code comments I have tried to explain the requirement of each step. Hope this is appreciated. Thank You.
*CODE* REPORT z_pratik_attachment LINE-SIZE 132 LINE-COUNT 65 NO STANDARD PAGE HEADING. *********************************************************************** * INTERNAL TABLES * *********************************************************************** DATA: i_objpack TYPE STANDARD TABLE OF sopcklsti1, i_objtext TYPE STANDARD TABLE OF solisti1, i_objbin TYPE STANDARD TABLE OF solisti1, i_receivers TYPE STANDARD TABLE OF somlreci1. *********************************************************************** * WORK AREAS * *********************************************************************** DATA: wa_email_doc TYPE sodocchgi1, wa_objpack TYPE sopcklsti1, wa_objtext TYPE solisti1, wa_receivers TYPE somlreci1. *********************************************************************** * CONSTANTS * *********************************************************************** CONSTANTS: c_x TYPE flag VALUE 'X', c_u TYPE char1 VALUE 'U'. *********************************************************************** * START-OF-SELECTION * *********************************************************************** START-OF-SELECTION. *********************************************************************** * END-OF-SELECTION * *********************************************************************** END-OF-SELECTION. wa_email_doc-obj_name = 'Attachment Example'. "Mail Subject wa_email_doc-obj_descr = 'How to attach Multiple Attachments to an Email'. * Main Mail body Text in itab i_objtext wa_objtext+0(36) = 'We are not going to print this line.'. APPEND wa_objtext TO i_objtext. CLEAR wa_objtext. wa_objtext+0(46) = 'This is the body of the email. We have skipped'. APPEND wa_objtext TO i_objtext. CLEAR wa_objtext. wa_objtext+0(45) = ' the first line of the mail and printed from '. wa_objtext+45(12) = 'second line.'. APPEND wa_objtext TO i_objtext. CLEAR wa_objtext. * Text for the attachments in itab i_objbin wa_objtext+0(21) = 'This is attachment 1.'. APPEND wa_objtext TO i_objbin. CLEAR wa_objtext. wa_objtext+0(31) = 'We have got another attachment.'. APPEND wa_objtext TO i_objbin. CLEAR wa_objtext. wa_objtext+0(28) = 'This is attachment number 2.'. APPEND wa_objtext TO i_objbin. CLEAR wa_objtext. ** Creating the entry for the compressed document *--(1): Creating entry for the Main Mail body text in itab i_objtext " wa_objpack-transf_bin " Flag for indicating an obj. to be transported in binary form. " If this flag is activated ('X'), the table entry describes an " object stored in binary format. The content of the object is in " the table CONTENTS_BIN. If the flag is not activated, the object " content is in the table CONTENTS_TXT in ASCII format. wa_objpack-transf_bin = ' '. " Starting index(row) For header information in the itab i_objpack wa_objpack-head_start = 1. " No of lines for the header information in itab i_objpack wa_objpack-head_num = 1. " The row(index) of the itab i_objtext from where the Mail Body starts wa_objpack-body_start = 2. "Skipped the first Line " The number of lines in the Mail body wa_objpack-body_num = 2. "We have two lines from the 2nd row " Document type. There are also whole lot of other options wa_objpack-doc_type = 'RAW'. wa_objpack-obj_name = 'MAIN BODY'. wa_objpack-obj_descr = 'MAIL BODY TEXT'. wa_objpack-obj_langu = ' '. " In this case one can skip this. Normally ist calculated as " no of linex * 255 wa_objpack-doc_size = ' '. APPEND wa_objpack TO i_objpack. CLEAR wa_objpack. *--(2): Creating entry for the Attachment text in itab i_objbin *----Attachment 1----* wa_objpack-transf_bin = c_x. wa_objpack-head_start = 2. wa_objpack-head_num = 1. wa_objpack-body_start = 1. "Itab i_objbin row number wa_objpack-body_num = 2. wa_objpack-doc_size = 510 . "Approximately for 2 Lines-> 255 * 2 wa_objpack-doc_type = 'RAW'. wa_objpack-obj_name = 'Attachment 1'. wa_objpack-obj_descr = 'Attachment 1'. wa_objpack-obj_langu = ' '. APPEND wa_objpack TO i_objpack. *--(3): Creating entry for the Attachment text in itab i_objbin *----Attachment 2----* wa_objpack-transf_bin = c_x. wa_objpack-head_start = 3. wa_objpack-head_num = 1. wa_objpack-body_start = 3. "Itab i_objbin row number wa_objpack-body_num = 1. wa_objpack-doc_size = 255 . "Approximately for 1 Line wa_objpack-doc_type = 'RAW'. wa_objpack-obj_name = 'Attachment 2'. wa_objpack-obj_descr = 'Attachment 2'. wa_objpack-obj_langu = ' '. APPEND wa_objpack TO i_objpack. *Building the recepient list ** Receipient information wa_receivers-receiver = sy-uname. wa_receivers-rec_type = 'B'. "To SAP Inbox APPEND wa_receivers TO i_receivers. CLEAR wa_receivers. wa_receivers-receiver = 'abc@gmail.com'. wa_receivers-rec_type = c_u. APPEND wa_receivers TO i_receivers. CLEAR wa_receivers. * Finally Send the Document CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = wa_email_doc put_in_outbox = 'X' commit_work = 'X' TABLES packing_list = i_objpack contents_bin = i_objbin contents_txt = i_objtext receivers = i_receivers 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. ENDIF.
REPORT ztsapmail. DATA: x_object_type LIKE sood-objtp. DATA: BEGIN OF x_object_hd_change. INCLUDE STRUCTURE sood1. DATA: END OF x_object_hd_change. DATA: BEGIN OF x_objcont OCCURS 10. INCLUDE STRUCTURE soli. DATA: END OF x_objcont. DATA: BEGIN OF x_objhead OCCURS 0. INCLUDE STRUCTURE soli. DATA: END OF x_objhead. DATA: BEGIN OF raw_head. INCLUDE STRUCTURE sorh. DATA: END OF raw_head. DATA: BEGIN OF x_receivers OCCURS 0. INCLUDE STRUCTURE soos1. DATA: END OF x_receivers. PARAMETERS: receiver LIKE x_receivers-recnam. " Name *BUILD MESSAGE HEADERMOVE 'Sort field goes here' TO X_OBJECT_HD_CHANGE-OBJSRT. " Sort field MOVE 'Name of the object goes here' TO x_object_hd_change-objnam. " Name MOVE 'Document title goes here' TO x_object_hd_change-objdes. " Title MOVE 'F' TO x_object_hd_change-objsns. " Functional OBJECT MOVE 'E' TO x_object_hd_change-objla. " Language * Object type of the new documentMOVE 'RAW' TO X_OBJECT_TYPE. CLEAR x_objcont. MOVE 'Contents of mail' TO x_objcont-line. APPEND x_objcont. CLEAR x_objcont-line. APPEND x_objcont. MOVE 'More contents' TO x_objcont-line. APPEND x_objcont. MOVE 'Still more contents' TO x_objcont-line. APPEND x_objcont. MOVE ' ' TO x_objcont-line. APPEND x_objcont. * Specific header (Dependent on the object type, here RAW)REFRESH X_OBJHEAD. DESCRIBE TABLE x_objcont LINES raw_head-rawsiz. MOVE raw_head TO x_objhead. APPEND x_objhead. *RECEIVERS tableCLEAR X_RECEIVERS. REFRESH x_receivers. MOVE receiver TO x_receivers-recnam. " Name MOVE 'B' TO x_receivers-recesc. " Receiver type MOVE 'X' TO x_receivers-sndcp. " Send as a copy MOVE 'X' TO x_receivers-sndex. " EXPRESS DOCUMENT APPEND x_receivers. CALL FUNCTION 'SO_OBJECT_SEND' EXPORTING folder_id = 'OUTBOX' object_hd_change = x_object_hd_change object_type = x_object_type outbox_flag = 'X' owner = sy-uname tablesobjcont = x_objcont objhead = x_objhead receivers = x_receivers.Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
* Sending Emails and Sap mail using ABAP REPORT ztunixmail. DATA : to_address LIKE sy_lisel,from_address LIKE sy-lisel, subject LIKE sy-lisel, attachment_name LIKE sy_lisel, data_file_path LIKE sxpgcolist-parameters, body_file_path LIKE sxpgcolist-parameters. DATA : BEGIN OF int_email_attach OCCURS 0, txtline TYPE char255, END OF int_email_attach. DATA : BEGIN OF int_email_body OCCURS 0, txtline TYPE char255, END OF int_email_body. CLEAR : int_exec_protocol,int_email_attach,int_email_body. REFRESH : int_exec_protocol,int_email_attach,int_email_body. int_email_attach-txtline = 'Put all attachment text in this table'. APPEND int_email_attach. CLEAR int_email_attach. int_email_body-txtline = 'Put all attachment text in this table'. APPEND int_email_body. CLEAR int_email_body. CONCATENATE to_addressfrom_address subject body_file_path data_file_path attachment_name INTO v_parameters. IF NOT int_email_attach[] IS INITIAL. OPEN DATASET data_file_path FOR OUTPUT IN TEXT MODE. LOOP AT int_email_attach. TRANSFER int_email_attach-txtline TO data_file_path. ENDLOOP. CLOSE DATASET data_file_path. ENDIF. IF NOT int_email_body[] IS INITIAL. OPEN DATASET body_file_path FOR OUTPUT IN TEXT MODE. LOOP AT int_email_body. TRANSFER int_email_body-txtline TO body_file_path. ENDLOOP. CLOSE DATASET body_file_path. ENDIF. CALL FUNCTION 'SXPG_CALL_SYSTEM' EXPORTING commandname = 'Z_EMAIL' " Command calling unix script parameters = v_parameters tablesexec_protocol = int_exec_protocol EXCEPTIONS no_permission = 1 command_not_found = 2 parameters_too_long = 3 security_risk = 4 wrong_check_call_interface = 5 program_start_error = 6 program_termination_error = 7 x_error = 8 parameter_expected = 9 too_many_parameters = 10 illegal_command = 11 OTHERS = 12.
Author: Runal Singh
Submitted: 16/01/2008
FUNCTION z_send_email_itab_uname. *"----------------------------------------------------------------------*" *"Local interface: *" IMPORTING *" VALUE(APPLICATION) LIKE SOOD1-OBJNAM *" VALUE(EMAILTITLE) LIKE SOOD1-OBJDES *" VALUE(RECEXTNAM) LIKE SOOS1-RECEXTNAM OPTIONAL *" VALUE(SENDER) LIKE SOUD-USRNAM DEFAULT SY-UNAME *" VALUE(UNAME) LIKE SOOS1-RECEXTNAM OPTIONAL *" EXPORTING *" VALUE(RETURN_CODE) LIKE SY-SUBRC *" TABLES *" TEXTTAB STRUCTURE SOLI *"---------------------------------------------------------------------- * tables TABLES: pa0105, "Employee detail for username and email address usr21, "Login addition address data adr6. "Address table for email addresses *- local data declaration DATA: ohd LIKE sood1, oid LIKE soodk, to_all LIKE sonv-flag, t_uname LIKE sy-uname, okey LIKE swotobjid-objkey. DATA: BEGIN OF receivers OCCURS 0. INCLUDE STRUCTURE soos1. DATA: END OF receivers. *- fill odh CLEAR ohd. ohd-objla = sy-langu. ohd-objnam = application. ohd-objdes = emailtitle. ohd-objpri = 3. ohd-objsns = 'F'. ohd-ownnam = sy-uname. IF NOT uname IS INITIAL. * Find personnel number of username CONDENSE uname NO-GAPS. WHILE uname CS ','. t_uname = uname+0(sy-fdpos). ADD 1 TO sy-fdpos. SHIFT uname LEFT BY sy-fdpos PLACES. PERFORM find_email_address USING t_uname CHANGING recextnam. ENDWHILE. *Do the last record IF uname <> space. t_uname = uname. PERFORM find_email_address USING t_uname CHANGING recextnam. ENDIF. ENDIF. *- send Email IF NOT recextnam IS INITIAL. CONDENSE recextnam NO-GAPS. CHECK recextnam CS '@'. ENDIF. *- for every individual recipient send an Email* WHILE recextnam CS ','. PERFORM init_rec TABLES receivers. READ TABLE receivers INDEX 1. receivers-recextnam = recextnam+0(sy-fdpos). ADD 1 TO sy-fdpos. SHIFT recextnam LEFT BY sy-fdpos PLACES. MODIFY receivers INDEX 1. PERFORM so_object_send_rec TABLES texttab receivers USING ohd sender. ENDWHILE. *- check last recipient in recipient list IF recextnam <> space. PERFORM init_rec TABLES receivers. READ TABLE receivers INDEX 1. receivers-recextnam = recextnam. MODIFY receivers INDEX 1. PERFORM so_object_send_rec TABLES texttab receivers USING ohd sender. ENDIF. ENDFUNCTION. *---------------------------------------------------------------------* * FORM SO_OBJECT_SEND_REC * *---------------------------------------------------------------------* FORM so_object_send_rec TABLES objcont STRUCTURE soli receivers STRUCTURE soos1 USING object_hd STRUCTURE sood1 sender LIKE soud-usrnam. DATA: oid LIKE soodk, to_all LIKE sonv-flag, okey LIKE swotobjid-objkey. CALL FUNCTION 'SO_OBJECT_SEND' EXPORTING extern_address = 'X' object_hd_change = object_hd object_type = 'RAW' outbox_flag = 'X' sender = sender IMPORTING object_id_new = oid sent_to_all = to_all office_object_key = oke TABLES objcont = objcont receivers = receivers EXCEPTIONS active_user_not_exist = 1 communication_failure = 2 component_not_available = 3 folder_not_exist = 4 folder_no_authorization = 5 forwarder_not_exist = 6 note_not_exist = 7 object_not_exist = 8 object_not_sent = 9 object_no_authorization = 10 object_type_not_exist = 11 operation_no_authorization = 12 owner_not_exist = 13 parameter_error = 14 substitute_not_active = 15 substitute_not_defined = 16 system_failure = 17 too_much_receivers = 18 user_not_exist = 19 x_error = 20 OTHERS = 21. IF sy-subrc <> 0. CASE sy-subrc. WHEN 1. MESSAGE i999(b1) WITH 'Activer user does not exist.' 'Send Mail failed!'. WHEN 2. MESSAGE i999(b1) WITH 'Communication Failure.' 'Send Mail failed!'. WHEN 3. MESSAGE i999(b1) WITH 'Component not available.' 'Send Mail failed!'. WHEN 4. MESSAGE i999(b1) WITH 'Folder does not exist.' 'Send Mail failed!'. WHEN 5. MESSAGE i999(b1) WITH 'No authorization for folder.' 'Send Mail failed!'. WHEN 6. MESSAGE i999(b1) WITH 'Forwarder does not exist.' 'Send Mail failed!'. WHEN 7. MESSAGE i999(b1) WITH 'Note does not exist.' 'Send Mail failed!'. WHEN 8. MESSAGE i999(b1) WITH 'Object does not exist.' 'Send Mail failed!'. WHEN 9. MESSAGE i999(b1) WITH 'Object not sent.' 'Send Mail failed!'. WHEN 10. MESSAGE i999(b1) WITH 'No authorization for object.' 'Send Mail failed!'. WHEN 11. MESSAGE i999(b1) WITH 'Object type does not exist.' 'Send Mail failed!'. WHEN 12. MESSAGE i999(b1) WITH 'No authorization for operation.' 'Send Mail failed!'. WHEN 13. MESSAGE i999(b1) WITH 'Owner does not exist.' 'Send Mail failed!'. WHEN 14. MESSAGE i999(b1) WITH 'Parameter Error.' 'Send Mail failed!'. WHEN 15. MESSAGE i999(b1) WITH 'Substitute not active.' 'Send Mail failed!'. WHEN 16. MESSAGE i999(b1) WITH 'Substitute not defined.' 'Send Mail failed!'. WHEN 17. MESSAGE i999(b1) WITH 'System failure.' 'Send Mail failed!'. WHEN 18. MESSAGE i999(b1) WITH 'Too many receivers.' 'Send Mail failed!'. WHEN 19. MESSAGE i999(b1) WITH 'User does not exist.' 'Send Mail failed!'. WHEN 20. MESSAGE i999(b1) WITH 'Unknown error ocurred.' 'Send Mail failed!'. WHEN 21. MESSAGE i999(b1) WITH 'Unknown error ocurred.' 'Send Mail failed!'. ENDCASE. ENDIF. ENDFORM. "so_object_send_rec *----------------------------------------------------------------------* * FORM INIT_REC *----------------------------------------------------------------------* FORM init_rec TABLES receivers STRUCTURE soos1. CLEAR receivers. REFRESH receivers. MOVE sy-datum TO receivers-rcdat . MOVE sy-uzeit TO receivers-rctim. MOVE '1' TO receivers-sndpri. MOVE 'X' TO receivers-sndex. MOVE 'U-' TO receivers-recnam. MOVE 'U' TO receivers-recesc. MOVE 'INT' TO receivers-sndart. MOVE '5' TO receivers-sortclass. APPEND receivers. ENDFORM. "init_rec *&---------------------------------------------------------------------* *& Form find_email_address *&---------------------------------------------------------------------* * Returns the email address for a USERID whether they are an * employee or just a user. *----------------------------------------------------------------------* * <--P_RECEXTNAM Email address * -->P_UNAME USERID *----------------------------------------------------------------------* FORM find_email_address USING p_uname CHANGING p_recextnam LIKE soos1-recextnam. DATA: t_pernr LIKE pa0105-pernr, t_email LIKE pa0105-usrid_long. * STEP 1 - Find personnel number for UNAME SELECT SINGLE pernr INTO t_pernr FROM pa0105 WHERE subty = '0001' AND endda >= sy-datum AND begda <= sy-datum AND usrid = p_uname. * Employee record found IF sy-subrc = 0. * STEP 2 - Find email address for personnel number SELECT SINGLE usrid_long INTO t_email FROM pa0105 WHERE pernr = t_pernr AND subty = '0022' AND endda >= sy-datum AND begda <= sy-datum. IF sy-subrc = 0. IF NOT p_recextnam IS INITIAL. CONCATENATE p_recextnam t_email INTO p_recextnam SEPARATED BY ','. ELSE. p_recextnam = t_email. ENDIF. ELSE. "Never found an email address for employee *** WHO SHOULD WE SEND TO HERE??? *** ENDIF. * Employee number not found. * Search in ADR6 table ELSE. * See if user name is in the username table. * i.e. The user is not an employee SELECT SINGLE addrnumber persnumber INTO (usr21-addrnumber, usr21-persnumber) FROM usr21 WHERE bname = p_uname. IF sy-subrc = 0. * Found user name now let's get the email address SELECT SINGLE smtp_addr INTO t_email FROM adr6 WHERE addrnumber = usr21-addrnumber AND persnumber = usr21-persnumber. IF sy-subrc <> 0 OR t_email IS INITIAL. *** WHO SHOULD WE SEND TO HERE??? *** ELSE. "Found email IF NOT p_recextnam IS INITIAL. CONCATENATE p_recextnam t_email INTO p_recextnam SEPARATED BY ','. ELSE. p_recextnam = t_email. ENDIF. ENDIF. ELSE. "UNAME just does not have an email address addigned at all *** WHO SHOULD WE SEND TO HERE??? *** ENDIF. ENDIF. ENDFORM. " find_email_address
Note the code snippet for sending mails to outlook with URL
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'*** Header DATA : wa_header TYPE sodocchgi1. *** Contents Data DATA : it_content TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0, wa_content TYPE solisti1, *** Receivers Data it_receivers TYPE STANDARD TABLE OF somlreci1 INITIAL SIZE 0, wa_receivers TYPE somlreci1, it_para TYPE STANDARD TABLE OF soparai1 INITIAL SIZE 0, wa_para TYPE soparai1. wa_receivers-receiver = 'abc@sdn.com'. wa_receivers-rec_type = 'U'. wa_receivers-com_type = 'INT'. APPEND wa_receivers TO it_receivers. CLEAR: wa_receivers. wa_header-obj_prio = 1. wa_header-priority = 1. wa_header-obj_langu = sy-langu. wa_header-obj_descr = 'Mail with SAP SDN link'. CONCATENATE 'Dear ' 'SDN ' INTO wa_content-line SEPARATED BY ''. APPEND wa_content TO it_content. CLEAR wa_content. CONCATENATE '<a href="http://www.sdn.sap.com" " target="_blank" >' 'SAP Developer Network (SDN) </a>' ' ' INTO wa_content-line SEPARATED BY ''. APPEND wa_content TO it_content. CLEAR wa_content. CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1' EXPORTING document_data = wa_header document_type = 'RAW' commit_work = 'X' TABLES object_content = it_content object_para = it_para receivers = it_receivers.
Author: Mauricio Lauffer
Submitted: 08/03/2012
Related Links:
Send email with new class CL_BCS is very simple!
Follow a example:
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'*&-------------------------------------------------------------* *& Report ZEMAIL_CL_BCS * *&-------------------------------------------------------------* *& Mauricio Lauffer *&-------------------------------------------------------------* REPORT zemail_cl_bcs. CONSTANTS: gc_subject TYPE so_obj_des VALUE 'ABAP Email with CL_BCS', gc_raw TYPE char03 VALUE 'RAW'. DATA: gv_mlrec TYPE so_obj_nam, gv_sent_to_all TYPE os_boolean, gv_email TYPE adr6-smtp_addr, gv_subject TYPE so_obj_des, gv_text TYPE bcsy_text, gr_send_request TYPE REF TO cl_bcs, gr_bcs_exception TYPE REF TO cx_bcs, gr_recipient TYPE REF TO if_recipient_bcs, gr_sender TYPE REF TO cl_sapuser_bcs, gr_document TYPE REF TO cl_document_bcs. TRY. "Create send request gr_send_request = cl_bcs=>create_persistent( ). "Email FROM... gr_sender = cl_sapuser_bcs=>create( sy-uname ). "Add sender to send request CALL METHOD gr_send_request->set_sender EXPORTING i_sender = gr_sender. "Email TO... gv_email = 'frodo.baggins@outlook.com'. gr_recipient = cl_cam_address_bcs=>create_internet_address( gv_email ). "Add recipient to send request CALL METHOD gr_send_request->add_recipient EXPORTING i_recipient = gr_recipient i_express = 'X'. "Email BODY APPEND 'Hello world! My first ABAP email!' TO gv_text. gr_document = cl_document_bcs=>create_document( i_type = gc_raw i_text = gv_text i_length = '12' i_subject = gc_subject ). "Add document to send request CALL METHOD gr_send_request->set_document( gr_document ). "Send email CALL METHOD gr_send_request->send( EXPORTING i_with_error_screen = 'X' RECEIVING result = gv_sent_to_all ). IF gv_sent_to_all = 'X'. WRITE 'Email sent!'. ENDIF. "Commit to send email COMMIT WORK. "Exception handling CATCH cx_bcs INTO gr_bcs_exception. WRITE: 'Error!', 'Error type:', gr_bcs_exception->error_type. ENDTRY.
Back to Sending Mails - Home Page
* Before using following CODE, Need to Create ITS Service for SAP Trasaction thru tcode : SICF
Note : read comments for more details.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'* Data Declaration related to SAP Link Creation for TRIP ********************************************************* DATA : wda_name TYPE string, in_protocol TYPE string, out_host TYPE string, out_port TYPE string, out_protocol TYPE string, val TYPE string, g_url TYPE string. * Data Declaration related to Mail *********************************** DATA : send_request TYPE REF TO cl_bcs, document TYPE REF TO cl_document_bcs, send TYPE REF TO if_sender_bcs, i_text TYPE soli_tab, wa_text TYPE soli, receiver TYPE REF TO if_recipient_bcs, sent_to_all TYPE os_boolean, sender TYPE adr6-smtp_addr, recipient TYPE adr6-smtp_addr, subject TYPE so_obj_des. DATA : temp_addr TYPE adr6-smtp_addr. *********************************** ********************************************************* * -Generating URL for SAP Trasaction ( SAP GUI for HTML ) ********************************************************* CALL METHOD cl_http_server=>if_http_server~get_location EXPORTING protocol = in_protocol server = cl_wdr_task=>server IMPORTING host = out_host port = out_port out_protocol = out_protocol. val = sy-mandt. CONCATENATE out_protocol '://' out_host ':' out_port '/sap/bc/gui/sap/its/ztrip' INTO g_url. * " /sap/bc/gui/sap/its/ path for ITS service * " ztrip service name for TCODE - TRIP, created thru SICF CALL METHOD cl_http_server=>append_field_url EXPORTING name = 'sap-client' value = val CHANGING url = g_url. *************************************** * Sending mail to Outlook with SAP link *************************************** send_request = cl_bcs=>create_persistent( ). CONCATENATE 'Dear SDN,' '' INTO wa_text-line. APPEND wa_text-line TO i_text. CONCATENATE 'Please find below link for Travel Request ( TRIP ),' '' INTO wa_text-line. APPEND wa_text-line TO i_text. CONCATENATE '<a href="' g_url '" > Link to Travel Request </a>' ' ' INTO wa_text-line. APPEND wa_text-line TO i_text. subject = 'SDN : Mail to Outlook with SAPLink'. document = cl_document_bcs=>create_document( i_type = 'RAW' i_text = i_text i_length = '18' i_subject = subject ). * add document to send request CALL METHOD send_request->set_document( document ). * create internet address for the sender send = cl_cam_address_bcs=>create_internet_address( i_address_string = 'SDN@SAP.COM' i_address_name = 'SAP SDN'). * set the sender to send_request instance CALL METHOD send_request->set_sender EXPORTING i_sender = send. temp_addr = 'sdn@sap.com'. " Receiving Address receiver = cl_cam_address_bcs=>create_internet_address( temp_addr ). " adding receipts CALL METHOD send_request->add_recipient EXPORTING i_recipient = receiver i_express = 'X'. send_request->set_send_immediately( 'X' ). * sending the mail CALL METHOD send_request->send( EXPORTING i_with_error_screen = 'X' RECEIVING result = sent_to_all ). IF sent_to_all = 'X'. WRITE :/ 'Mail has sent successfully'. ENDIF.
With this tutorial it is possible to create contact persons with the BAPI BAPI_ADDRCONTPART_SAVEREPLICA for customers and or vendors.
The example is for customers only.
One of the main problems is that the created contactperson with the BAPI BAPI_ADDRCONTPART_SAVEREPLICA didn't become available in Tcode XD02
This was due to the problem that the table KNVK was not updated trough this BAPI.
Other problem was that with function SD_CUSTOMER_MAINTAIN_ALL not all necessary contact information could be managed like email adress.
DATA: st_sender TYPE bapi_sender, gs_kna1 TYPE kna1, h_kunnr TYPE kunnr, gt_knvk TYPE STANDARD TABLE OF fknvk, gs_knvk TYPE fknvk, new_contactid TYPE bapicontact_01-contact, new_contactid_create TYPE bapi4003_1-objkey_p, gt_bapiad3vl TYPE STANDARD TABLE OF bapiad3vl, gs_bapiad3vl TYPE bapiad3vl, gt_bapiadsmtp TYPE STANDARD TABLE OF bapiadsmtp, gs_bapiadsmtp TYPE bapiadsmtp, gt_bapiadtel TYPE STANDARD TABLE OF bapiadtel, gs_bapiadtel TYPE bapiadtel, objid_cust LIKE bapi4002_1-objkey, gs_return TYPE bapiret2, gt_return TYPE STANDARD TABLE OF bapiret2, gs_commit_return TYPE bapiret2, gs_addr_no TYPE bapi4003_1-addr_no, gs_pers_no TYPE bapi4003_1-pers_no. h_kunnr = '1100'. "example customer code CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = h_kunnr IMPORTING output = h_kunnr. SELECT SINGLE * FROM kna1 INTO gs_kna1 WHERE kunnr EQ h_kunnr. gs_knvk-kunnr = h_kunnr. gs_knvk-name1 = 'lastname'. gs_knvk-namev = 'firstname'. gs_knvk-ernam = sy-uname. gs_knvk-erdat = sy-datum. APPEND gs_knvk TO gt_knvk. *lastname en firstname must be the same as passed to the BAPI! * otherwise the data of KNVK will overwrite the data entered by the BAPI * this can be tested by entering different fpor knvk and the bapi * if xd03 is started and double click on the contact you see the bapi details * if xd02 is started and double click on the contact ****the lastname and firstname of the knvk overwrite the addres data of the bapi * other data entered with the bapi like email telephone and roomnumber maintain the values written with the BAPI CALL FUNCTION 'SD_CUSTOMER_MAINTAIN_ALL' EXPORTING i_kna1 = gs_kna1 i_maintain_address_by_kna1 = ' ' pi_postflag = 'X' TABLES t_xknvk = gt_knvk EXCEPTIONS client_error = 1 kna1_incomplete = 2 knb1_incomplete = 3 knb5_incomplete = 4 knvv_incomplete = 5 kunnr_not_unique = 6 sales_area_not_unique = 7 sales_area_not_valid = 8 insert_update_conflict = 9 number_assignment_error = 10 number_not_in_range = 11 number_range_not_extern = 12 number_range_not_intern = 13 account_group_not_valid = 14 parnr_invalid = 15 bank_address_invalid = 16 tax_data_not_valid = 17 no_authority = 18 company_code_not_unique = 19 dunning_data_not_valid = 20 knb1_reference_invalid = 21 cam_error = 22 OTHERS = 23. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. * Instead of using BAPI_PARTNEREMPLOYEE_GETINTNUM to retrieve the next number for the parnr * I use the function 'SD_CUSTOMER_MAINTAIN_ALL' to retrieve the next number * so the connection with KNVK is already established READ TABLE gt_knvk INDEX 1 INTO gs_knvk. new_contactid_create = gs_knvk-parnr. objid_cust = h_kunnr. gs_bapiad3vl_x-lastname = 'X'. gs_bapiad3vl_x-firstname = 'X'. APPEND gs_bapiad3vl_x TO gt_bapiad3vl_x. *common data *lastname en firstname must be the same as passed to KNVK! gs_bapiad3vl-lastname = 'lastname'. gs_bapiad3vl-firstname = 'firstname'. gs_bapiad3vl-pers_group = 'BP'. gs_bapiad3vl-namcountry = 'NL'. gs_bapiad3vl-langu_p = 'NL'. gs_bapiad3vl-room_no_p = 'roomnumber'. APPEND gs_bapiad3vl TO gt_bapiad3vl. * email gs_bapiadsmtp-e_mail = 'youre@email.adres'. APPEND gs_bapiadsmtp TO gt_bapiadsmtp. * telephone nr gs_bapiadtel-telephone = '020-11'. gs_bapiadtel-extension = '55111'. APPEND gs_bapiadtel TO gt_bapiadtel. * instead of the bapi below also the bapi * BAPI_ADDRESSCONTPART_CHANGE can be used CALL FUNCTION 'BAPI_ADDRCONTPART_SAVEREPLICA' EXPORTING obj_type_p = 'BUS1006001' obj_id_p = new_contactid_create obj_type_c = 'KNA1' obj_id_c = objid_cust iv_check_address = 'X' IMPORTING return = gs_return address_number = gs_addr_no person_number = gs_pers_no TABLES bapiad3vl = gt_bapiad3vl bapiadtel = gt_bapiadtel bapiadsmtp = gt_bapiadsmtp. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X' IMPORTING return = gs_commit_return.
This porgram send the email with multiple attachments. First all I wanted was to avoid the 255 character limit of the SEND_API function module, but I modified the program so that it is useful to every one.
First it appends all the character data to a string, then the string is converted to XSTRING in order to be compressed. And then attached to the mail.
After going through the code I hope you can alter it according to your needs.
Good Luck.
*&---------------------------------------------------------------------* *& Report ZTHILANKA_TEST *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZTHILANKA_TEST. data: binary_content type solix_tab. data: xl_content type xstring . constants: con_tab type c value cl_abap_char_utilities=>horizontal_tab, con_cret type c value cl_abap_char_utilities=>cr_lf. data: xlcontent type xstring, conlength type i, conlengths type so_obj_len, result_content type string, wa_string type string, "This holds all of your data dummy type string. data: send_request type ref to cl_bcs. data: text type bcsy_text. data: document type ref to cl_document_bcs. data: sender type ref to if_sender_bcs. data: recipient type ref to if_recipient_bcs. data: recipients type bcsy_smtpa. data: bcs_exception type ref to cx_bcs. data: sent_to_all type os_boolean. data: e_r_page type ref to cl_rsr_www_page. data: content_length type w3param-cont_len , content_type type w3param-cont_type, return_code type w3param-ret_code . data: html type standard table of w3html . data: server type string , port type string . data: wa_rec type ad_smtpadr . data: bcs_message type string . data: subject type so_obj_des. data: sender_id type ad_smtpadr. data: email type ad_smtpadr. data: gv_file type string, gv_zipfilehex type xstring, go_zipper type ref to cl_abap_zip. "The zip folder object concatenate 'Customer no.' 'CUSTOMER name' 'Subcustomer' 'Sales incoterms' 'Currency' 'Material' 'Mat long text' 'level1' 'level2' 'level3' 'Level 1 description' 'Level 2 description' 'Level 3 description' 'Data' 'Valid from' 'Valid to' into wa_string separated by con_tab. concatenate con_cret con_tab wa_string into wa_string. * After this keep on appending the data to the wa_string data: i type i, true type string. clear: xl_content . * convert the string data to xstring call function 'SCMS_STRING_TO_XSTRING' exporting text = wa_string * MIMETYPE = ' ' * ENCODING = importing buffer = xl_content. * EXCEPTIONS * FAILED = 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. gv_file = 'Data.xls'. "Zip file name create OBJECT go_zipper. go_zipper->add( name = gv_file content = xl_content )."If you have other content to be added to the zip folder, do it here gv_zipfilehex = go_zipper->save( ). concatenate 'Data list ' 'date' into subject . sender_id = 'your_email@yourdomain.tld'. email = 'customer@hisdomain.tld'. refresh binary_content . call function 'SCMS_XSTRING_TO_BINARY' exporting buffer = gv_zipfilehex tables binary_tab = binary_content. *refresh text . clear result_content . *The body message concatenate '<p><font color="#000080">Dear Customer,</font></p>' '<p><font color="#000080">Attached herewith is the data list you requested.</font></p>' into result_content . conlength = strlen( result_content ) . conlengths = conlength . call function 'SCMS_STRING_TO_FTEXT' exporting text = result_content tables ftext_tab = text. try. clear send_request . send_request = cl_bcs=>create_persistent( ). clear document . document = cl_document_bcs=>create_document( i_type = 'HTM' i_text = text i_length = conlengths i_subject = subject ). call method document->add_attachment exporting i_attachment_type = 'zip' i_attachment_subject = 'Price List' "Attachment name i_att_content_hex = binary_content. *You can add multiple attachments like below * CALL METHOD document->add_attachment * EXPORTING * i_attachment_type = 'zip' * i_attachment_subject = 'Subject testing 2' "atta_sub * i_att_content_hex = binary_content. * * CALL METHOD document->add_attachment * EXPORTING * i_attachment_type = 'zip' * i_attachment_subject = 'Subject 3' "atta_sub * i_att_content_hex = binary_content. * add document to send request call method send_request->set_document( document ). clear sender . sender = cl_cam_address_bcs=>create_internet_address( sender_id ). call method send_request->set_sender exporting i_sender = sender. clear wa_rec . * add recipient with its respective attributes to send request * you can add multiple recipients in the same mail by calling * this method repeatedly. clear recipient . wa_rec = email. recipient = cl_cam_address_bcs=>create_internet_address( wa_rec ). * call method send_request->add_recipient * exporting * i_recipient = recipient1 * i_express = 'X'. * call method send_request->add_recipient * exporting * i_recipient = recipient2 * i_express = 'X'. call method send_request->add_recipient exporting i_recipient = recipient i_express = 'X'. call method send_request->set_status_attributes exporting i_requested_status = 'E' i_status_mail = 'E'. call method send_request->set_send_immediately( 'X' ). * ---------- send document --------------------------------------- call method send_request->send( exporting i_with_error_screen = 'X' RECEIVING result = sent_to_all ). if sent_to_all = 'X'. *APPEND 'Mail sent successfully ' TO return . endif. commit work. catch cx_bcs into bcs_exception. bcs_message = bcs_exception->get_text( ). *APPEND bcs_message TO return . exit. endtry.
Submitted: Nov 16 2007
TABLES: ekko. PARAMETERS: p_email TYPE somlreci1-receiver DEFAULT 'test@sapdev.co.uk'. TYPES: BEGIN OF t_ekpo, ebeln TYPE ekpo-ebeln, ebelp TYPE ekpo-ebelp, aedat TYPE ekpo-aedat, matnr TYPE ekpo-matnr, END OF t_ekpo. DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0, wa_ekpo TYPE t_ekpo. TYPES: BEGIN OF t_charekpo, ebeln(10) TYPE c, ebelp(5) TYPE c, aedat(8) TYPE c, matnr(18) TYPE c, END OF t_charekpo. DATA: wa_charekpo TYPE t_charekpo. DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE. DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE. DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE, t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE, t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE, t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE, t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE, w_cnt TYPE i, w_sent_all(1) TYPE c, w_doc_data LIKE sodocchgi1, gd_error TYPE sy-subrc, gd_reciever TYPE sy-subrc. ************************************************************************ *START_OF_SELECTION START-OF-SELECTION. * Retrieve sample data from table ekpo PERFORM data_retrieval. * Populate table with detaisl to be entered into .xls file PERFORM build_xls_data_table. ************************************************************************ *END-OF-SELECTION END-OF-SELECTION. * Populate message body text perform populate_email_message_body. * Send file by email as .xls speadsheet PERFORM send_file_as_email_attachment tables it_message it_attach using p_email 'Example .xls documnet attachment' 'XLS' 'filename' ' ' ' ' ' ' changing gd_error gd_reciever. * Instructs mail send program for SAPCONNECT to send email(rsconn01) PERFORM initiate_mail_execute_program. *&---------------------------------------------------------------------* *& Form DATA_RETRIEVAL *&---------------------------------------------------------------------* * Retrieve data form EKPO table and populate itab it_ekko *----------------------------------------------------------------------* FORM data_retrieval. SELECT ebeln ebelp aedat matnr UP TO 10 ROWS FROM ekpo INTO TABLE it_ekpo. ENDFORM. " DATA_RETRIEVAL *&---------------------------------------------------------------------* *& Form BUILD_XLS_DATA_TABLE *&---------------------------------------------------------------------* * Build data table for .xls document *----------------------------------------------------------------------* FORM build_xls_data_table. CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode con_tab TYPE x VALUE '09'. "OK for non Unicode *If you have Unicode check active in program attributes thnen you will *need to declare constants as follows *class cl_abap_char_utilities definition load. *constants: * con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB, * con_cret type c value cl_abap_char_utilities=>CR_LF. CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR' INTO it_attach SEPARATED BY con_tab. CONCATENATE con_cret it_attach INTO it_attach. APPEND it_attach. LOOP AT it_ekpo INTO wa_charekpo. CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp wa_charekpo-aedat wa_charekpo-matnr INTO it_attach SEPARATED BY con_tab. CONCATENATE con_cret it_attach INTO it_attach. APPEND it_attach. ENDLOOP. ENDFORM. " BUILD_XLS_DATA_TABLE *&---------------------------------------------------------------------* *& Form SEND_FILE_AS_EMAIL_ATTACHMENT *&---------------------------------------------------------------------* * Send email *----------------------------------------------------------------------* FORM send_file_as_email_attachment tables pit_message pit_attach using p_email p_mtitle p_format p_filename p_attdescription p_sender_address p_sender_addres_type changing p_error p_reciever. DATA: ld_error TYPE sy-subrc, ld_reciever TYPE sy-subrc, ld_mtitle LIKE sodocchgi1-obj_descr, ld_email LIKE somlreci1-receiver, ld_format TYPE so_obj_tp , ld_attdescription TYPE so_obj_nam , ld_attfilename TYPE so_obj_des , ld_sender_address LIKE soextreci1-receiver, ld_sender_address_type LIKE soextreci1-adr_typ, ld_receiver LIKE sy-subrc. ld_email = p_email. ld_mtitle = p_mtitle. ld_format = p_format. ld_attdescription = p_attdescription. ld_attfilename = p_filename. ld_sender_address = p_sender_address. ld_sender_address_type = p_sender_addres_type. * Fill the document data. w_doc_data-doc_size = 1. * Populate the subject/generic message attributes w_doc_data-obj_langu = sy-langu. w_doc_data-obj_name = 'SAPRPT'. w_doc_data-obj_descr = ld_mtitle . w_doc_data-sensitivty = 'F'. * Fill the document data and get size of attachment CLEAR w_doc_data. READ TABLE it_attach INDEX w_cnt. w_doc_data-doc_size = ( w_cnt - 1 ) * 255 + STRLEN( it_attach ). w_doc_data-obj_langu = sy-langu. w_doc_data-obj_name = 'SAPRPT'. w_doc_data-obj_descr = ld_mtitle. w_doc_data-sensitivty = 'F'. CLEAR t_attachment. REFRESH t_attachment. t_attachment[] = pit_attach[]. * Describe the body of the message CLEAR t_packing_list. REFRESH t_packing_list. t_packing_list-transf_bin = space. t_packing_list-head_start = 1. t_packing_list-head_num = 0. t_packing_list-body_start = 1. DESCRIBE TABLE it_message LINES t_packing_list-body_num. t_packing_list-doc_type = 'RAW'. APPEND t_packing_list. * Create attachment notification t_packing_list-transf_bin = 'X'. t_packing_list-head_start = 1. t_packing_list-head_num = 1. t_packing_list-body_start = 1. DESCRIBE TABLE t_attachment LINES t_packing_list-body_num. t_packing_list-doc_type = ld_format. t_packing_list-obj_descr = ld_attdescription. t_packing_list-obj_name = ld_attfilename. t_packing_list-doc_size = t_packing_list-body_num * 255. APPEND t_packing_list. * Add the recipients email address CLEAR t_receivers. REFRESH t_receivers. t_receivers-receiver = ld_email. t_receivers-rec_type = 'U'. t_receivers-com_type = 'INT'. t_receivers-notif_del = 'X'. t_receivers-notif_ndel = 'X'. APPEND t_receivers. CALL FUNCTION 'SO_DOCUMENT_SEND_API1' EXPORTING document_data = w_doc_data put_in_outbox = 'X' sender_address = ld_sender_address sender_address_type = ld_sender_address_type commit_work = 'X' IMPORTING sent_to_all = w_sent_all TABLES packing_list = t_packing_list contents_bin = t_attachment contents_txt = it_message receivers = t_receivers 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. * Populate zerror return code ld_error = sy-subrc. * Populate zreceiver return code LOOP AT t_receivers. ld_receiver = t_receivers-retrn_code. ENDLOOP. ENDFORM. *&---------------------------------------------------------------------* *& Form INITIATE_MAIL_EXECUTE_PROGRAM *&---------------------------------------------------------------------* * Instructs mail send program for SAPCONNECT to send email. *----------------------------------------------------------------------* FORM initiate_mail_execute_program. WAIT UP TO 2 SECONDS. SUBMIT rsconn01 WITH mode = 'INT' WITH output = 'X' AND RETURN. ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM *&---------------------------------------------------------------------* *& Form POPULATE_EMAIL_MESSAGE_BODY *&---------------------------------------------------------------------* * Populate message body text *----------------------------------------------------------------------* form populate_email_message_body. REFRESH it_message. it_message = 'Please find attached a list test ekpo records'. APPEND it_message. endform. " POPULATE_EMAIL_MESSAGE_BODY
*& Report ZPLXX_PRO_RE_CS0_EMAIL_INTERF *&---------------------------------------------------------------------* *& Program: Application Server files to Cadbury *& Developer: Marcin Pciak - Nearshore PL *& Date: 05.03.2009 *& *& Short descr: Program to be used mainly in background jobs, however *& may be used directly *& It looks for the file on Application Server generated today *& and sends it to given external address. Programm uses *& global class to populate and dispatch the message. Here data *& are only prepared and later encapsulated in the class *& *& If PA_FULL parameter is checked then entire file name with extension must be *& specified, otherwise program looks for all files matching this subname *& *& Prerequisites: Given file (with today's date) must reside in Application Server *&---------------------------------------------------------------------* REPORT zplxx_pro_re_cs0_email_interf. "first load class definition - provided later CLASS lcl_email_dispatcher DEFINITION DEFERRED. *&---------------------------------------------------------------------* *& SELECTION SCREEN *&---------------------------------------------------------------------* DATA: recip TYPE so_recname. SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-tit. PARAMETERS: pa_dir TYPE epsf-epsdirnam VISIBLE LENGTH 60 OBLIGATORY, "directory pa_file TYPE epsf-epsfilnam VISIBLE LENGTH 40 OBLIGATORY. "file name or its part * pa_ext TYPE c LENGTH 3 VISIBLE LENGTH 3 OBLIGATORY. "extension SELECT-OPTIONS so_recip FOR recip NO INTERVALS OBLIGATORY. PARAMETERS: pa_full AS CHECKBOX. "is path fully specified? SELECTION-SCREEN END OF BLOCK blk. SELECTION-SCREEN BEGIN OF BLOCK bl2 WITH FRAME TITLE text-mes. PARAMETERS pa_subj TYPE so_obj_des OBLIGATORY. SELECTION-SCREEN END OF BLOCK bl2. *&---------------------------------------------------------------------* *& TYPINGS *&---------------------------------------------------------------------* TYPES: tt_fdscr TYPE TABLE OF rlgrap-filename, tt_recip TYPE TABLE OF so_recname, tt_mess TYPE TABLE OF string. *&---------------------------------------------------------------------* *& DATA OBJECTS *&---------------------------------------------------------------------* "tables to populate the message DATA: it_fdscr TYPE tt_fdscr, it_recip TYPE tt_recip, it_mess TYPE tt_mess. DATA: gr_email_dispatcher TYPE REF TO lcl_email_dispatcher. "full file path and name DATA: full_path TYPE epsf-epspath. "directory list DATA: BEGIN OF dir_list OCCURS 0. INCLUDE STRUCTURE epsfili. DATA END OF dir_list. "file attributes DATA: BEGIN OF file, mtime(6) TYPE p, "returns time in secs from 1970 date LIKE sy-datum, time(10) TYPE c, "format 00:00:00 END OF file. INCLUDE ZPLXX_PRO_IN_CS0_EMAIL_INT_C00. *&---------------------------------------------------------------------* *& GO! *&---------------------------------------------------------------------* START-OF-SELECTION. "------------------------ get direcotry listing CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING' EXPORTING dir_name = pa_dir TABLES dir_list = dir_list EXCEPTIONS invalid_eps_subdir = 1 sapgparam_failed = 2 build_directory_failed = 3 no_authorization = 4 read_directory_failed = 5 too_many_read_errors = 6 empty_directory_list = 7 OTHERS = 8. IF sy-subrc <> 0. MESSAGE 'No such directory' TYPE 'I' DISPLAY LIKE 'E'. LEAVE TO SCREEN 0. ENDIF. "------------------------ get direcotry listing LOOP AT dir_list. IF pa_full EQ space. CHECK dir_list-name CS pa_file. "consider only files with this name ELSE. CHECK dir_list-name EQ pa_file. "check exact name ENDIF. "get file attributes CALL FUNCTION 'EPS_GET_FILE_ATTRIBUTES' EXPORTING file_name = dir_list-name dir_name = pa_dir IMPORTING file_mtime = file-mtime EXCEPTIONS read_directory_failed = 1 read_attributes_failed = 2 OTHERS = 3. IF sy-subrc <> 0. CONTINUE. "skip the file ENDIF. "get file timestamp (for this change p6 to time from 1970) PERFORM p6_to_date_time_tz(rstr0400) USING file-mtime file-time file-date. "process file generated today IF file-date EQ sy-datum. CONCATENATE pa_dir '/' dir_list-name INTO full_path. APPEND full_path TO it_fdscr. ENDIF. ENDLOOP. "------------------------ process only if any files found CHECK it_fdscr[] IS NOT INITIAL. "------------------------ set recipients LOOP AT so_recip. APPEND so_recip-low TO it_recip. ENDLOOP. "------------------------ set message APPEND 'This message was automatically generated in order to supply you with SAP Application Server data file(s).' TO it_mess. APPEND 'Check the attachment(s).' TO it_mess. APPEND INITIAL LINE TO it_mess. APPEND 'Please do not reply to this message.' TO it_mess. APPEND INITIAL LINE TO it_mess. APPEND '------------------------' TO it_mess. APPEND 'With Best Regards' TO it_mess. APPEND 'NorthgateArinso team' TO it_mess. "------------------------ crate and dispatch message CREATE OBJECT gr_email_dispatcher EXPORTING im_subject = pa_subj im_tab_mess = it_mess im_tab_fdscr = it_fdscr im_tab_recip = it_recip. *&---------------------------------------------------------------------* *& Include ZPLXX_PRO_IN_CS0_EMAIL_INT_C00 *&---------------------------------------------------------------------* *----------------------------------------------------------------------* * CLASS lcl_email_dispatcher DEFINITION *----------------------------------------------------------------------* CLASS lcl_email_dispatcher DEFINITION. PUBLIC SECTION. METHODS: constructor IMPORTING im_subject TYPE so_obj_des im_tab_mess TYPE tt_mess im_tab_fdscr TYPE tt_fdscr im_tab_recip TYPE tt_recip. PRIVATE SECTION. "tables DATA: it_recipients TYPE TABLE OF somlreci1, it_packing_list TYPE TABLE OF sopcklsti1, it_message TYPE TABLE OF solisti1, it_attachments TYPE TABLE OF solisti1. "structures DATA: doc_attr TYPE sodocchgi1. METHODS: set_doc_attributes IMPORTING f_subject TYPE so_obj_des, "50 chars set_recipients IMPORTING ft_recip TYPE tt_recip, set_automatic_message IMPORTING ft_mess TYPE tt_mess, initialize_packing_list IMPORTING ft_fdscr TYPE tt_fdscr, prepare_data_for_dispatch IMPORTING f_fdscr TYPE rlgrap-filename CHANGING f_lines TYPE i fs_packing_list TYPE sopcklsti1, get_file_name IMPORTING f_path TYPE rlgrap-filename EXPORTING f_file TYPE so_obj_des, dispatch. ENDCLASS. "lcl_email_dispatcher DEFINITION *----------------------------------------------------------------------* * CLASS lcl_email_dispatcher IMPLEMENTATION *----------------------------------------------------------------------* CLASS lcl_email_dispatcher IMPLEMENTATION. METHOD constructor. set_doc_attributes( im_subject ). set_recipients( im_tab_recip ). set_automatic_message( im_tab_mess ). initialize_packing_list( im_tab_fdscr ). dispatch( ). ENDMETHOD. "constructor METHOD set_doc_attributes. "---------------------- Document attributes doc_attr-obj_name = 'WAS_FILESEND'. doc_attr-obj_descr = f_subject. doc_attr-obj_langu = sy-langu. doc_attr-sensitivty = 'F'. "functional message ENDMETHOD. "set_doc_attributes METHOD set_recipients. DATA: wa_recip LIKE LINE OF ft_recip, wa_recipient TYPE somlreci1. "---------------------- Recipcients LOOP AT ft_recip INTO wa_recip. wa_recipient-receiver = wa_recip. wa_recipient-rec_type = 'U'. "internet address wa_recipient-com_type = 'INT'. "send via internet APPEND wa_recipient TO it_recipients. ENDLOOP. ENDMETHOD. "set_recipients METHOD set_automatic_message. DATA: wa_mess LIKE LINE OF ft_mess. LOOP AT ft_mess INTO wa_mess. APPEND wa_mess TO it_message. ENDLOOP. ENDMETHOD. "set_automatic_message METHOD initialize_packing_list. DATA: wa_fdscr LIKE LINE OF ft_fdscr, wa_packing_list TYPE sopcklsti1, l_line TYPE i, index(3) TYPE n, file TYPE so_obj_des. "char50 "--------------------- describe message wa_packing_list-transf_bin = space. wa_packing_list-body_start = 1. DESCRIBE TABLE it_message. wa_packing_list-body_num = sy-tfill. wa_packing_list-doc_type = 'RAW'. APPEND wa_packing_list TO it_packing_list. "---------------------- describe attachemnts (one per line) l_line = 1. LOOP AT ft_fdscr INTO wa_fdscr. "------------------ construct attachement name get_file_name( EXPORTING f_path = wa_fdscr IMPORTING f_file = file ). "------------------ attachment attributes CLEAR wa_packing_list. wa_packing_list-transf_bin = 'X'. wa_packing_list-body_start = l_line. index = sy-tabix. CONCATENATE 'ATTACH' index INTO wa_packing_list-obj_name. wa_packing_list-obj_descr = file. wa_packing_list-obj_langu = sy-langu. wa_packing_list-doc_type = 'DAT'. "send as DAT file "------------------- get the file form Application server CLEAR l_line. prepare_data_for_dispatch( EXPORTING f_fdscr = wa_fdscr CHANGING f_lines = l_line fs_packing_list = wa_packing_list ). "------------------- return read lines wa_packing_list-body_num = l_line. "------------------- new attachemnt starts from next line l_line = wa_packing_list-body_start + wa_packing_list-body_num. APPEND wa_packing_list TO it_packing_list. ENDLOOP. ENDMETHOD. "initialize_packing_list METHOD prepare_data_for_dispatch. DATA: l_len TYPE i, wa_attachment TYPE solisti1. OPEN DATASET f_fdscr FOR INPUT IN BINARY MODE. IF sy-subrc NE 0. "error log here -> can't open file from WAS ELSE. DO. READ DATASET f_fdscr INTO wa_attachment LENGTH l_len. IF sy-subrc NE 0. EXIT. ENDIF. APPEND wa_attachment TO it_attachments. ADD 1 TO f_lines. ADD l_len TO fs_packing_list-doc_size. ENDDO. "---------------------- all data read in one shot IF l_len <> 0. APPEND wa_attachment TO it_attachments. ADD 1 TO f_lines. ADD l_len TO fs_packing_list-doc_size. ENDIF. CLOSE DATASET f_fdscr. ENDIF. ENDMETHOD. "prepare_data_for_dispatch METHOD get_file_name. DATA: off TYPE i, len TYPE i, file_tmp LIKE f_path. WHILE sy-subrc = 0. FIND '/' IN SECTION OFFSET off OF f_path MATCH OFFSET off MATCH LENGTH len. IF sy-subrc = 0. off = off + len. ENDIF. ENDWHILE. file_tmp = f_path. SHIFT file_tmp BY off PLACES LEFT. len = STRLEN( file_tmp ). SUBTRACT 4 FROM len. f_file = file_tmp(len). ENDMETHOD. "get_file_name METHOD dispatch. CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = doc_attr put_in_outbox = 'X' commit_work = 'X' TABLES packing_list = it_packing_list contents_bin = it_attachments contents_txt = it_message receivers = it_recipients 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. WAIT UP TO 2 SECONDS. SUBMIT rsconn01 WITH mode = 'INT' * WITH ouput = 'X' AND RETURN. ENDIF. ENDMETHOD. "send_mail ENDCLASS. "lcl_email_sender IMPLEMENTATION
Back to Sending Mails - Home Page
Author: Martin Lang
Submitted: Aug 3rd 2009
Prerequisites: Check for these Notes and apply if required:
Sample Code:
*&---------------------------------------------------------------------* *& Report ZAG_CAL_ICAL *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* report z_appointment_to_outlook. include <cntn01>. type-pools: sccon. data: mail type text40. * Provide select option to enter multiple attendees SELECTION-SCREEN: BEGIN OF BLOCK org. select-options: email for mail no intervals default 'Joe.Doe@test.com'. SELECTION-SCREEN: END OF BLOCK org. data lo_appointment type ref to cl_appointment. data ls_participant type scspart. data lv_address type swc_object. data ls_address_container like swcont occurs 0 with header line. data lt_text type so_txttab. data ls_text like line of lt_text. data lv_location like scsappt-room. data lo_send_request type ref to cl_bcs. data lv_sent_to_all type os_boolean. create object lo_appointment. * Add multiple attendees loop at email. clear ls_participant. swc_create_object lv_address 'ADDRESS' space. swc_set_element ls_address_container 'AddressString' email-low. swc_set_element ls_address_container 'TypeId' 'U'. swc_call_method lv_address 'Create' ls_address_container. check sy-subrc = 0. * * get key and type of object swc_get_object_key lv_address ls_participant-objkey. check sy-subrc = 0. swc_get_object_type lv_address ls_participant-objtype. check sy-subrc = 0. move sccon_part_sndmail_with_ans to ls_participant-send_mail. ls_participant-comm_mode = 'INT'. lo_appointment->add_participant( participant = ls_participant ). endloop. * Sample Apppointment for specific date/time *lo_appointment->set_date( date_from = '20090801' * time_from = '130000' * date_to = '20090801' * time_to = '140000' * ). * Sample Appointment for All-Day-Event lo_appointment->set_date( date_from = '20090803' date_to = '20090803' ). * Make appointment appear "busy" lo_appointment->set_busy_value( sccon_busy_busy ). * Set Location lo_appointment->set_location_string( 'Location' ). * Set Organizer lo_appointment->set_organizer( sy-uname ). * "Type of Meeting" (value picked from table SCAPPTTYPE) lo_appointment->set_type( 'ABSENT' ). * Make this an all day event lo_appointment->SET_VIEW_ATTRIBUTES( SHOW_ON_TOP = 'X'). * Set Meeting body text ls_text = 'This is the Body Text of the Appointment'. append ls_text to lt_text. lo_appointment->set_text( lt_text ). * Set Meeting Subject lo_appointment->set_title( 'This is the Appointment Subject' ). * Important to set this one to space. Otherwise SAP will send a not user-friendly e-mail lo_appointment->save( send_invitation = space ). * Now that we have the appointment, we can send a good one for outlook by switching to BCS lo_send_request = lo_appointment->create_send_request( ). * don't request read/delivery receipts lo_send_request->set_status_attributes( i_requested_status = 'N' i_status_mail = 'N' ). * Send it to the world lv_sent_to_all = lo_send_request->send( i_with_error_screen = 'X' ). commit work and wait.
Email with attachements can be sent by using CL_BCS class as below :This code sample can be used as a reference :
The standard class CL_BCS is used to send the notification along with attachment . CREATE_PERSISTENT is the method which used to send request object of the standard class CL_BCS.
Method CREATE_DOCUMENT of CL_DOCUMENT_BCS is used for creating the text of the email body.Method ADD_ATTACHMENT of CL_DOCUMENT_BCS is used to creating attachment of the email.Here lt_att_content_hex should contain data
CLASS cl_bcs DEFINITION LOAD. DATA: lo_send_request TYPE REF TO cl_bcs ,lo_document TYPE REF TO cl_document_bcs ,lo_sender TYPE REF TO if_sender_bcs ,lo_recipient TYPE REF TO if_recipient_bcs ,lt_message_body TYPE bcsy_text ,lx_document_bcs TYPE REF TO cx_document_bcs ,lv_send TYPE ad_smtpadr VALUE 'xyz@gmail.com' ,lv_sent_to_all TYPE os_boolean . "create send request lo_send_request = cl_bcs=>create_persistent( ). "create message body and subject APPEND 'Dear Vendor,' TO lt_message_body. APPEND INITIAL LINE to lt_message_body. APPEND 'Please fill the attached .' TO lt_message_body. APPEND INITIAL LINE to lt_message_body. APPEND 'Thank You,' TO lt_message_body. "put your text into the document lo_document = cl_document_bcs=>create_document( i_type = 'RAW' i_text = lt_message_body i_subject = 'Vendor Payment Form' ). TRY. lo_document->add_attachment( EXPORTING i_attachment_type = 'PDF' i_attachment_subject = 'Form' i_att_content_hex = lt_att_content_hex ). CATCH cx_document_bcs INTO lx_document_bcs. ENDTRY. * Add attachment * Pass the document to send request lo_send_request->set_document( lo_document ). "Create sender lo_sender = cl_cam_address_bcs=>create_internet_address( l_send ). "Set sender lo_send_request->set_sender( lo_sender ). "Create recipient lo_recipient = cl_sapuser_bcs=>create( sy-uname ). *Set recipient lo_send_request->add_recipient( EXPORTING i_recipient = lo_recipient i_express = 'X' ). lo_send_request->add_recipient( lo_recipient ). * Send email lo_send_request->send( EXPORTING i_with_error_screen = 'X' RECEIVING result = lv_sent_to_all ). COMMIT WORK.
Author: kalyan Annapareddy
Submitted: 9th june 2008
Related Links:
SAP is a robust system, which gives many facilities in the form of Function Modules (FMs) for connecting to external systems or for use within the system. With a clever use of these FMs we can achieve a lot of things through ABAP code.
This article focuses on ways to send E-mails and SAP Mails using ABAP code.
Firstly SAP Mail
A SAP mail is a mail internal to the SAP system. It is a very good forum to exchange information with other users. Using a SAP mail in ABAP code facilitates exchange of automatic messages at various stages of the business process. It is easy to use and saves many hassles involved in using workflows for exchanging messages.
The ABAP code to send a sap mail is built around the FM SO_OBJECT_SEND which has the following pattern.
CALL FUNCTION 'SO_OBJECT_SEND' * EXPORTING * FOLDER_ID = ' ' * FORWARDER = ' ' * OBJECT_FL_CHANGE = * OBJECT_HD_CHANGE = ' ' * OBJECT_ID = ' ' * OBJECT_TYPE = ' ' * OUTBOX_FLAG = ' ' * OWNER = ' ' * STORE_FLAG = ' ' * DELETE_FLAG = ' ' * SENDER = ' ' * CHECK_SEND_AUTHORITY = ' ' * CHECK_ALREADY_SENT = ' ' * GIVE_OBJECT_BACK = * ORIGINATOR = ' ' * ORIGINATOR_TYPE = 'J' * LINK_FOLDER_ID = ' ' * SEND_REQUEST_OID = ' ' * IP_ENCRYPT = 'U' * IP_SIGN = 'U' * IP_REC_COUNT_ADD = * IMPORTING * OBJECT_ID_NEW = * SENT_TO_ALL = * ALL_BINDING_DONE = * OFFICE_OBJECT_KEY = * ORIGINATOR_ID = * E_SEND_REQUEST_OID = * TABLES * OBJCONT = * OBJHEAD = * OBJPARA = * OBJPARB = * RECEIVERS = * PACKING_LIST = * ATT_CONT = * ATT_HEAD = * NOTE_TEXT = * LINK_LIST = * APPLICATION_OBJECT = * EXCEPTIONS * ACTIVE_USER_NOT_EXIST = 1 * COMMUNICATION_FAILURE = 2 * COMPONENT_NOT_AVAILABLE = 3 * FOLDER_NOT_EXIST = 4 * FOLDER_NO_AUTHORIZATION = 5 * FORWARDER_NOT_EXIST = 6 * NOTE_NOT_EXIST = 7 * OBJECT_NOT_EXIST = 8 * OBJECT_NOT_SENT = 9 * OBJECT_NO_AUTHORIZATION = 10 * OBJECT_TYPE_NOT_EXIST = 11 * OPERATION_NO_AUTHORIZATION = 12 * OWNER_NOT_EXIST = 13 * PARAMETER_ERROR = 14 * SUBSTITUTE_NOT_ACTIVE = 15 * SUBSTITUTE_NOT_DEFINED = 16 * SYSTEM_FAILURE = 17 * TOO_MUCH_RECEIVERS = 18 * USER_NOT_EXIST = 19 * ORIGINATOR_NOT_EXIST = 20 * X_ERROR = 21 * OTHERS = 22 . IF sy-subrc <> 0. * Implement suitable error handling here ENDIF.
Author: Saravanan M
Submitted: <06 Sep 2011>
Related Links:
Class CL_BCS: http://help.sap.com/saphelp_sm32/helpdata/en/2d/1c5d3aebba4c38e10000000a114084/content.htm
Class CL_DOCUMENT_BCS: http://help.sap.com/saphelp_NW70EHP1core/helpdata/en/8c/5bf13b68402b69e10000000a11402f/content.htm
Description
This article describes how to convert internal table value into excel and sending excel in email using class CL_BCS and CL_DOCUMENT_BCS.
Selection Screen:
*&---------------------------------------------------------------------* *& Report ZSDRR_DAILY_FEED *& *&---------------------------------------------------------------------* *& Description : This is the report program to send email with * *& list of new contract created daily, weekly and * *& monthly to specified email ID in the selection * *& screen. * *&---------------------------------------------------------------------* REPORT zsdrr_daily_feed. TABLES: mara. */..Types Declarations TYPES : BEGIN OF ty_vbak, vbeln TYPE vbak-vbeln, erdat TYPE vbak-erdat, auart TYPE vbak-auart, augru TYPE vbak-augru, vkbur TYPE vbak-vkbur, kunnr TYPE vbak-kunnr, END OF ty_vbak, BEGIN OF ty_vbkd, vbeln TYPE vbkd-vbeln, posnr TYPE vbkd-posnr, zzreinstate TYPE vbkd-zzreinstate, zzexpired TYPE vbkd-zzexpired, zzlatesale TYPE vbkd-zzlatesale, zzrenewal TYPE vbkd-zzrenewal, END OF ty_vbkd, BEGIN OF ty_veda, vbeln TYPE veda-vbeln, vposn TYPE veda-vposn, vbegdat TYPE veda-vbegdat, venddat TYPE veda-venddat, vkuegru TYPE veda-vkuegru, vbedkue TYPE veda-vbedkue, END OF ty_veda, BEGIN OF ty_vbap, vbeln TYPE vbap-vbeln, posnr TYPE vbap-posnr, matnr TYPE vbap-matnr, zmeng TYPE vbap-zmeng, kzwi3 TYPE vbap-kzwi3, kzwi5 TYPE vbap-kzwi5, maktx TYPE makt-maktx, mtart TYPE mara-mtart, END OF ty_vbap, BEGIN OF ty_vbpa, vbeln TYPE vbpa-vbeln, posnr TYPE vbpa-posnr, parvw TYPE vbpa-parvw, kunnr TYPE vbpa-kunnr, pernr TYPE vbpa-pernr, adrnr TYPE vbpa-adrnr, END OF ty_vbpa, BEGIN OF ty_vbpa_s, sobid TYPE hrp1001-sobid, kunnr TYPE but000-partner, END OF ty_vbpa_s, BEGIN OF ty_adrc, addrnumber TYPE adrc-addrnumber, name1 TYPE adrc-name1, name2 TYPE adrc-name2, street TYPE adrc-street, city1 TYPE adrc-city1, post_code1 TYPE adrc-post_code1, country TYPE adrc-country, region TYPE adrc-region, tel_number TYPE adrc-tel_number, END OF ty_adrc, BEGIN OF ty_adr6, addrnumber TYPE adrc-addrnumber, smtp_addr TYPE adr6-smtp_addr, END OF ty_adr6, BEGIN OF ty_but000, partner TYPE but000-partner, bpkind TYPE but000-bpkind, bu_group TYPE but000-bu_group, name_last TYPE but000-name_last, name_first TYPE but000-name_first, END OF ty_but000, BEGIN OF ty_hrp1001, otype TYPE hrp1001-otype, objid TYPE hrp1001-objid, plvar TYPE hrp1001-plvar, relat TYPE hrp1001-relat, begda TYPE hrp1001-begda, endda TYPE hrp1001-endda, sclas TYPE hrp1001-sclas, sobid TYPE hrp1001-sobid, END OF ty_hrp1001, BEGIN OF ty_vbfa, vbelv TYPE vbfa-vbelv, posnv TYPE vbfa-posnv, vbeln TYPE vbfa-vbeln, posnn TYPE vbfa-posnn, vbtyp_n TYPE vbfa-vbtyp_n, vbtyp_v TYPE vbfa-vbtyp_v, END OF ty_vbfa, BEGIN OF ty_vbeln, vbeln TYPE vbak-vbeln, posnr TYPE vbap-posnr, END OF ty_vbeln. TYPES: BEGIN OF ty_kna1, kunnr TYPE kna1-kunnr, erdat TYPE kna1-erdat, END OF ty_kna1. TYPES: BEGIN OF x_final, auart TYPE vbak-auart, erdat TYPE vbak-erdat, augru TYPE vbak-augru, vbeln TYPE vbak-vbeln, posnr TYPE vbap-posnr, kunnr TYPE vbak-kunnr, name(60) TYPE c, telf1 TYPE sza1_d0100-tel_number, smtp_addr TYPE sza1_d0100-smtp_addr, street TYPE addr1_data-street, city1 TYPE addr1_data-city1, region TYPE addr1_data-region, post_code1 TYPE addr1_data-post_code1, country TYPE addr1_data-country, kunnr_b TYPE vbak-kunnr, name_b(60) TYPE c, telf1_b TYPE sza1_d0100-tel_number, smtp_addr_b TYPE sza1_d0100-smtp_addr, street_b TYPE addr1_data-street, city1_b TYPE addr1_data-city1, region_b TYPE addr1_data-region, post_code1_b TYPE addr1_data-post_code1, country_b TYPE addr1_data-country, matnr TYPE vbap-matnr, maktx TYPE makt-maktx, zmeng TYPE vbap-zmeng, vbegdat TYPE veda-vbegdat, venddat TYPE veda-venddat, kzwi3 TYPE vbap-kzwi3, con_val TYPE vbap-kzwi3, sales_rep TYPE vbak-kunnr, vkbur TYPE vbak-vkbur, END OF x_final, BEGIN OF x_log, message TYPE string, END OF x_log. */..Workarea Declarations DATA: w_vbak TYPE ty_vbak, w_veda TYPE ty_veda, w_vbkd TYPE ty_vbkd, w_vbap TYPE ty_vbap, w_vbpa TYPE ty_vbpa, w_adrc TYPE ty_adrc, w_adr6 TYPE ty_adr6, w_vbfa TYPE ty_vbfa, w_vbeln TYPE ty_vbeln, w_tvarv TYPE tvarv, w_final TYPE x_final, w_log TYPE x_log, w_veda_new TYPE ty_veda, w_kna1 TYPE ty_kna1. */..Data Declarations DATA : gv_datefrm TYPE sy-datum, gv_dateto TYPE sy-datum, gv_order TYPE string. DATA: t_vbak TYPE STANDARD TABLE OF ty_vbak, t_vbkd TYPE STANDARD TABLE OF ty_vbkd, t_veda TYPE STANDARD TABLE OF ty_veda, t_vbap TYPE STANDARD TABLE OF ty_vbap, t_vbpa TYPE STANDARD TABLE OF ty_vbpa, t_vbpa_s TYPE STANDARD TABLE OF ty_vbpa_s, t_adrc TYPE STANDARD TABLE OF ty_adrc, t_adr6 TYPE STANDARD TABLE OF ty_adr6, t_hrp1001 TYPE STANDARD TABLE OF ty_hrp1001, t_but000 TYPE STANDARD TABLE OF ty_but000, t_vbfa TYPE STANDARD TABLE OF ty_vbfa, t_vbeln TYPE STANDARD TABLE OF ty_vbeln, t_tvarv TYPE STANDARD TABLE OF tvarv, t_final TYPE STANDARD TABLE OF x_final, t_log TYPE STANDARD TABLE OF x_log, t_veda_new TYPE STANDARD TABLE OF ty_veda, t_kna1 TYPE STANDARD TABLE OF ty_kna1. DATA: t_cdhdr TYPE TABLE OF cdhdr, t_cdhdr1 TYPE TABLE OF cdhdr, t_cdpos TYPE TABLE OF cdpos. DATA: w_cdpos TYPE cdpos, w_cdhdr TYPE cdhdr, w_but000 TYPE ty_but000, w_hrp1001 TYPE ty_hrp1001, w_vbpa_s TYPE ty_vbpa_s. DATA: r_beg_dat TYPE RANGE OF vbak-erdat, r_canc_dat TYPE RANGE OF veda-vbedkue, r_parvw TYPE RANGE OF vbpa-parvw, r_auart TYPE RANGE OF vbak-auart, rg_auart TYPE RANGE OF vbak-auart, r_reinst TYPE RANGE OF vbak-erdat, r_expired TYPE RANGE OF vbak-erdat, r_contract TYPE RANGE OF vbak-erdat, r_vkuegru TYPE RANGE OF veda-vkuegru, r_mtart TYPE RANGE OF mara-mtart, r_matnr TYPE RANGE OF mara-matnr. DATA: w_beg_dat LIKE LINE OF r_beg_dat, w_canc_dat LIKE LINE OF r_canc_dat, w_parvw LIKE LINE OF r_parvw, w_auart LIKE LINE OF r_auart, wg_auart LIKE LINE OF rg_auart, w_reinst LIKE LINE OF r_reinst, w_expired LIKE LINE OF r_expired, w_contract LIKE LINE OF r_contract, w_vkuegru LIKE LINE OF r_vkuegru, w_mtart LIKE LINE OF r_mtart. */..Selection screen declaration SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. PARAMETERS: p_rname TYPE makt-maktx OBLIGATORY, p_mid TYPE adr6-smtp_addr OBLIGATORY. SELECT-OPTIONS: s_mat_i FOR mara-matnr, s_mat_p FOR mara-matnr. SELECTION-SCREEN END OF BLOCK b1. * Frequency and Timing SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003. PARAMETERS: p_daily RADIOBUTTON GROUP g1 DEFAULT 'X', p_weekly RADIOBUTTON GROUP g1, p_month RADIOBUTTON GROUP g1. SELECTION-SCREEN END OF BLOCK b3. *-Initialization-* INITIALIZATION. PERFORM initialization. *-Start-of-Selection-* START-OF-SELECTION. */..Get the time period for which the report is run. PERFORM get_daterange. */..Get the Material types based on the selection. PERFORM sub_fill_material_types. PERFORM sub_consolidate_data. *&---------------------------------------------------------------------* *& Form INITIALIZATION *&---------------------------------------------------------------------* FORM initialization . wg_auart-sign = 'I'. wg_auart-option = 'EQ'. wg_auart-low = 'ZC01'. APPEND wg_auart TO rg_auart. CLEAR wg_auart. wg_auart-sign = 'I'. wg_auart-option = 'EQ'. wg_auart-low = 'ZC02'. APPEND wg_auart TO rg_auart. CLEAR wg_auart. wg_auart-sign = 'I'. wg_auart-option = 'EQ'. wg_auart-low = 'ZC03'. APPEND wg_auart TO rg_auart. CLEAR wg_auart. wg_auart-sign = 'I'. wg_auart-option = 'EQ'. wg_auart-low = 'ZR01'. APPEND wg_auart TO rg_auart. CLEAR wg_auart. wg_auart-sign = 'I'. wg_auart-option = 'EQ'. wg_auart-low = 'ZR02'. APPEND wg_auart TO rg_auart. CLEAR wg_auart. ENDFORM. " INITIALIZATION *&---------------------------------------------------------------------* *& Form GET_DATERANGE *&---------------------------------------------------------------------* FORM get_daterange . DATA : lv_date TYPE sy-datum. CLEAR: lv_date, gv_datefrm, gv_dateto. IF p_daily EQ 'X'. */..Set current date gv_datefrm = sy-datum. gv_dateto = sy-datum. ELSEIF p_weekly EQ 'X'. */..get a date in previous week. CALL FUNCTION 'HR_99S_DATE_MINUS_TIME_UNIT' EXPORTING i_idate = sy-datum i_time = 7 i_timeunit = 'D' IMPORTING o_idate = lv_date EXCEPTIONS invalid_period = 1 invalid_round_up_rule = 2 internal_error = 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. */..get the previous week's start and end date. */..by default monday would be the starting day and Sunday would be * the ending day. CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE' EXPORTING date = lv_date IMPORTING * WEEK = monday = gv_datefrm sunday = gv_dateto. ELSEIF p_month EQ 'X'. */..get a date in previous month. CALL FUNCTION 'HR_99S_DATE_MINUS_TIME_UNIT' EXPORTING i_idate = sy-datum i_time = 1 i_timeunit = 'M' IMPORTING o_idate = lv_date EXCEPTIONS invalid_period = 1 invalid_round_up_rule = 2 internal_error = 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. * /..Get the previous month's start and End Date. CALL FUNCTION 'OIL_MONTH_GET_FIRST_LAST' EXPORTING i_date = lv_date IMPORTING e_first_day = gv_datefrm e_last_day = gv_dateto EXCEPTIONS wrong_date = 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. ENDIF. ENDFORM. " GET_DATERANGE *&---------------------------------------------------------------------* *& Form GET_CONTRACT_LIST *&---------------------------------------------------------------------* FORM get_contract_list . */.. Get the Change history value for the given selection. */.. Change history might be Dialy, Weekly or Monthly. */..Based onthe checkbox selected pick the matching contract nos. */..for new orders. REFRESH r_beg_dat. w_beg_dat-sign = 'I'. w_beg_dat-option = 'BT'. w_beg_dat-low = gv_datefrm. w_beg_dat-high = gv_dateto. APPEND w_beg_dat TO r_beg_dat. CLEAR w_beg_dat. */..Get the contract header details. SELECT vbeln erdat auart augru vkbur kunnr FROM vbak INTO TABLE t_vbak WHERE erdat IN r_beg_dat AND auart IN r_auart. IF t_vbak[] IS NOT INITIAL. */..Get the Sales Document: Business Data details. SELECT vbeln posnr zzreinstate zzexpired zzlatesale zzrenewal FROM vbkd INTO TABLE t_vbkd FOR ALL ENTRIES IN t_vbak WHERE vbeln = t_vbak-vbeln. */.. Get the Contract data details SELECT vbeln vposn vbegdat venddat vkuegru vbedkue FROM veda INTO TABLE t_veda FOR ALL ENTRIES IN t_vbak WHERE vbeln = t_vbak-vbeln. * AND vbedkue IN r_canc_dat * AND vkuegru = gv_canc_reason. */..get material and its desc details from VBAP and MAKT table. PERFORM sub_get_item_details USING t_vbak. */..Get partner detials from VBPA table * for the above obtained contracts. *build a range holding only Ship-to, * sold-to and Bill-to partner functions PERFORM sub_get_partner_details USING t_vbak. */.. Get the Address details for Sold to & Bill to partners PERFORM sub_get_partner_address_det USING t_vbpa. */.. Get the E-mail addresses for Sold to & Bill to addresses PERFORM sub_get_email_address USING t_vbpa. */.. Get Sales Rep Details for all the Contract documents PERFORM sub_get_sales_rep_details USING t_vbpa_s. ENDIF. ENDFORM. " GET_CONTRACT_LIST *&---------------------------------------------------------------------* *& Form SUB_CONSOLIDATE_DATA_NEW *&---------------------------------------------------------------------* FORM sub_consolidate_data_new. LOOP AT t_vbak INTO w_vbak WHERE auart IN r_auart. w_final-vbeln = w_vbak-vbeln. w_final-auart = w_vbak-auart. w_final-erdat = w_vbak-erdat. w_final-augru = w_vbak-augru. w_final-vkbur = w_vbak-vkbur. */.. Sold to Party addresses CLEAR w_vbpa. READ TABLE t_vbpa INTO w_vbpa WITH KEY vbeln = w_vbak-vbeln parvw = 'AG'. IF sy-subrc = 0. w_final-kunnr = w_vbpa-kunnr. READ TABLE t_adrc INTO w_adrc WITH KEY addrnumber = w_vbpa-adrnr. IF sy-subrc = 0. CONCATENATE w_adrc-name1 w_adrc-name2 INTO w_final-name SEPARATED BY space. w_final-telf1 = w_adrc-tel_number. w_final-street = w_adrc-street. w_final-city1 = w_adrc-city1. w_final-region = w_adrc-region. w_final-post_code1 = w_adrc-post_code1. w_final-country = w_adrc-country. ENDIF. READ TABLE t_adr6 INTO w_adr6 WITH KEY addrnumber = w_vbpa-adrnr. IF sy-subrc = 0. w_final-smtp_addr = w_adr6-smtp_addr. ENDIF. ENDIF. */.. Bill to party address CLEAR w_vbpa. READ TABLE t_vbpa INTO w_vbpa WITH KEY vbeln = w_vbak-vbeln parvw = 'RE'. IF sy-subrc = 0. w_final-kunnr_b = w_vbpa-kunnr. CLEAR w_adrc. READ TABLE t_adrc INTO w_adrc WITH KEY addrnumber = w_vbpa-adrnr. IF sy-subrc = 0. CONCATENATE w_adrc-name1 w_adrc-name2 INTO w_final-name_b SEPARATED BY space. w_final-telf1_b = w_adrc-tel_number. w_final-street_b = w_adrc-street. w_final-city1_b = w_adrc-city1. w_final-region_b = w_adrc-region. w_final-post_code1_b = w_adrc-post_code1. w_final-country_b = w_adrc-country. ENDIF. CLEAR w_adr6. READ TABLE t_adr6 INTO w_adr6 WITH KEY addrnumber = w_vbpa-adrnr. IF sy-subrc = 0. w_final-smtp_addr_b = w_adr6-smtp_addr. ENDIF. ENDIF. * Line Item Details LOOP AT t_vbap INTO w_vbap WHERE vbeln = w_vbak-vbeln. w_final-posnr = w_vbap-posnr. w_final-matnr = w_vbap-matnr. w_final-maktx = w_vbap-maktx. w_final-zmeng = w_vbap-zmeng. w_final-kzwi3 = w_vbap-kzwi3 + w_vbap-kzwi5. READ TABLE t_vbpa INTO w_vbpa WITH KEY vbeln = w_vbak-vbeln posnr = w_vbap-posnr parvw = 'Z3'. IF sy-subrc = 0. CLEAR w_hrp1001. READ TABLE t_hrp1001 INTO w_hrp1001 WITH KEY sobid = w_vbpa-kunnr. "#EC * IF sy-subrc = 0. w_final-sales_rep = w_hrp1001-sobid. ENDIF. ELSE. CLEAR w_vbpa. READ TABLE t_vbpa INTO w_vbpa WITH KEY vbeln = w_vbak-vbeln parvw = 'Z3'. IF sy-subrc = 0. CLEAR w_hrp1001. READ TABLE t_hrp1001 INTO w_hrp1001 WITH KEY sobid = w_vbpa-kunnr. "#EC * IF sy-subrc = 0. w_final-sales_rep = w_hrp1001-sobid. ENDIF. ENDIF. ENDIF. CLEAR w_veda. READ TABLE t_veda INTO w_veda WITH KEY vbeln = w_vbap-vbeln vposn = w_vbap-posnr. IF sy-subrc = 0. w_final-vbegdat = w_veda-vbegdat. w_final-venddat = w_veda-venddat. ELSE. READ TABLE t_veda INTO w_veda WITH KEY vbeln = w_vbap-vbeln." vposn = w_vbap-posnr. IF sy-subrc = 0. w_final-vbegdat = w_veda-vbegdat. w_final-venddat = w_veda-venddat. ENDIF. ENDIF. APPEND w_final TO t_final. ENDLOOP. CLEAR w_final. CLEAR w_vbap. CLEAR w_vbak. ENDLOOP. REFRESH: t_vbak, t_veda, t_vbkd, t_vbap, t_vbpa, t_adr6, t_adrc. ENDFORM. " SUB_CONSOLIDATE_DATA_NEW *&---------------------------------------------------------------------* *& Form SUB_SEND_MAIL *&---------------------------------------------------------------------* FORM sub_send_mail. * Data Declaration for Mail Sending Options * Receiver DATA: l_recipent TYPE REF TO if_recipient_bcs, * Sender l_sender TYPE REF TO cl_sapuser_bcs, l_attcdoctype TYPE soodk-objtp, l_atttitle TYPE sood-objdes, l_freq TYPE string, l_from TYPE char10, l_to TYPE char10. * Execptions DATA : l_bcs_exception TYPE REF TO cx_bcs, "#EC NEEDED) l_document TYPE REF TO cl_document_bcs, l_send_request TYPE REF TO cl_bcs. DATA: t_mail_text TYPE bcsy_text, wa_mail_text_row TYPE soli, l_subject2 TYPE so_obj_des, l_message TYPE string, l_message1 TYPE string. DATA: l_num_rows TYPE i, l_text_length TYPE so_obj_len, l_num_line TYPE i. DATA: l_line TYPE string, l_zmeng TYPE string, l_kzwi3 TYPE string. DATA: l_venddat TYPE char10, l_vbegdat TYPE char10, l_erdat TYPE char10. DATA: gt_binary_content TYPE solix_tab, gv_size TYPE so_obj_len. CONSTANTS: c_tab TYPE c VALUE cl_bcs_convert=>gc_tab, c_cr TYPE c VALUE cl_bcs_convert=>gc_crlf, c_ext TYPE soodk-objtp VALUE 'XLS', c_x TYPE c VALUE 'X'. TYPES : BEGIN OF ty_tvakt, auart TYPE auart, bezei TYPE bezei20, END OF ty_tvakt, BEGIN OF ty_tvaut, augru TYPE augru, bezei TYPE bezei40, END OF ty_tvaut. DATA : lt_tvakt TYPE STANDARD TABLE OF ty_tvakt, wa_tvakt TYPE ty_tvakt, lt_tvaut TYPE STANDARD TABLE OF ty_tvaut, wa_tvaut TYPE ty_tvaut, lt_ordesc TYPE STANDARD TABLE OF x_final, lv_auart TYPE auart, lv_augru TYPE augru, lv_auarttxt TYPE bezei40, lv_augrutxt TYPE bezei40, c_hyp(3) TYPE c VALUE ' - '. IF NOT t_final IS INITIAL. lt_ordesc = t_final. SORT lt_ordesc BY auart augru. DELETE ADJACENT DUPLICATES FROM lt_ordesc COMPARING auart augru. CLEAR : lt_tvakt, lt_tvaut, lv_auart, lv_augru. SELECT auart bezei INTO TABLE lt_tvakt FROM tvakt FOR ALL ENTRIES IN lt_ordesc WHERE auart EQ lt_ordesc-auart AND spras EQ sy-langu. SORT lt_tvakt BY auart. DELETE ADJACENT DUPLICATES FROM lt_tvakt COMPARING ALL FIELDS. SELECT augru bezei INTO TABLE lt_tvaut FROM tvaut FOR ALL ENTRIES IN lt_ordesc WHERE augru EQ lt_ordesc-augru AND spras EQ sy-langu. SORT lt_tvaut BY augru. DELETE ADJACENT DUPLICATES FROM lt_tvaut COMPARING ALL FIELDS. ENDIF. * Subject - Header l_subject2 = p_rname. CONCATENATE gv_datefrm+4(2) '/' gv_datefrm+6(2) '/' gv_datefrm+0(4) INTO l_from. CONCATENATE gv_dateto+4(2) '/' gv_dateto+6(2) '/' gv_dateto+0(4) INTO l_to. CLEAR l_freq. IF p_daily = c_x. l_freq = 'Daily'. ELSEIF p_weekly = c_x. l_freq = 'Weekly'. ELSEIF p_month = c_x. l_freq = 'Monthly'. ENDIF. DESCRIBE TABLE t_final LINES l_num_line. TRY. wa_mail_text_row = 'Data Selection Details:'. APPEND wa_mail_text_row TO t_mail_text. CLEAR wa_mail_text_row. APPEND wa_mail_text_row TO t_mail_text. CLEAR wa_mail_text_row. CONCATENATE 'Contract Type' ':' gv_order INTO wa_mail_text_row SEPARATED BY space. APPEND wa_mail_text_row TO t_mail_text. CLEAR wa_mail_text_row. CONCATENATE 'Frequency' ':' l_freq INTO wa_mail_text_row SEPARATED BY space. APPEND wa_mail_text_row TO t_mail_text. CLEAR wa_mail_text_row. CONCATENATE 'Date' ':' l_from 'to' l_to INTO wa_mail_text_row SEPARATED BY space. APPEND wa_mail_text_row TO t_mail_text. CLEAR wa_mail_text_row. CLEAR l_message. l_message = l_num_line. CONCATENATE 'No. of Records' ':' l_message INTO wa_mail_text_row SEPARATED BY space. APPEND wa_mail_text_row TO t_mail_text. CLEAR wa_mail_text_row. APPEND wa_mail_text_row TO t_mail_text. APPEND wa_mail_text_row TO t_mail_text. IF t_final[] IS INITIAL. wa_mail_text_row = 'No document exists for this selection.'. APPEND wa_mail_text_row TO t_mail_text. CLEAR wa_mail_text_row. ENDIF. * Define rows and file size DESCRIBE TABLE t_mail_text LINES l_num_rows. l_num_rows = l_num_rows * 255. MOVE l_num_rows TO l_text_length. TRY. CALL METHOD cl_document_bcs=>create_document EXPORTING i_type = 'RAW' i_subject = l_subject2 i_length = l_text_length i_text = t_mail_text RECEIVING result = l_document. CATCH cx_document_bcs . "#EC NO_HANDLER ENDTRY. * IF t_final[] IS NOT INITIAL. * Create Attachment CONCATENATE c_tab text-011 c_tab text-012 c_tab text-013 c_tab text-014 c_tab text-015 c_tab text-016 c_tab text-017 c_tab text-018 c_tab text-019 c_tab text-020 c_tab text-021 c_tab text-022 c_tab text-023 c_tab text-024 c_tab text-025 c_tab text-026 c_tab text-027 c_tab text-028 c_tab text-029 c_tab text-030 c_tab text-031 c_tab text-032 c_tab text-033 c_tab text-034 c_tab text-035 c_tab text-036 c_tab text-037 c_tab text-038 c_tab text-039 c_cr INTO l_line. CLEAR w_final. LOOP AT t_final INTO w_final. l_zmeng = w_final-zmeng. l_kzwi3 = w_final-kzwi3. CLEAR: l_vbegdat, l_venddat, l_erdat. CONCATENATE w_final-vbegdat+4(2) '/' w_final-vbegdat+6(2) '/' w_final-vbegdat+0(4) INTO l_vbegdat. CONCATENATE w_final-venddat+4(2) '/' w_final-venddat+6(2) '/' w_final-venddat+0(4) INTO l_venddat. CONCATENATE w_final-erdat+4(2) '/' w_final-erdat+6(2) '/' w_final-erdat+0(4) INTO l_erdat. IF w_final-auart NE lv_auart. READ TABLE lt_tvakt INTO wa_tvakt WITH KEY auart = w_final-auart. IF sy-subrc EQ 0. lv_auarttxt = wa_tvakt-bezei. CONCATENATE w_final-auart lv_auarttxt INTO lv_auarttxt SEPARATED BY c_hyp. ELSE. lv_auarttxt = w_final-auart. ENDIF. lv_auart = w_final-auart. ENDIF. IF w_final-augru NE lv_augru. READ TABLE lt_tvaut INTO wa_tvaut WITH KEY augru = w_final-augru. IF sy-subrc EQ 0. lv_augrutxt = wa_tvaut-bezei. CONCATENATE w_final-augru lv_augrutxt INTO lv_augrutxt SEPARATED BY c_hyp. ELSE. lv_augrutxt = w_final-augru. ENDIF. lv_augru = w_final-augru. ENDIF. CONCATENATE l_line lv_auarttxt l_erdat lv_augrutxt w_final-vbeln w_final-posnr w_final-kunnr w_final-name w_final-telf1 w_final-smtp_addr w_final-street w_final-city1 w_final-country w_final-post_code1 w_final-region w_final-kunnr_b w_final-name_b w_final-street_b w_final-city1_b w_final-region_b w_final-post_code1_b w_final-telf1_b w_final-matnr w_final-maktx l_zmeng l_vbegdat l_venddat l_kzwi3 w_final-sales_rep w_final-vkbur INTO l_line SEPARATED BY c_tab. CONCATENATE l_line c_cr INTO l_line. CLEAR w_final. ENDLOOP. TRY. cl_bcs_convert=>string_to_solix( EXPORTING iv_string = l_line iv_codepage = '4103' "suitable for MS Excel, leave empty iv_add_bom = 'X' "for other doc types IMPORTING et_solix = gt_binary_content ev_size = gv_size ). CATCH cx_bcs. MESSAGE e445(so). ENDTRY. * ENDIF. * Define File Name l_attcdoctype = c_ext. l_atttitle = p_rname. * Create Document CALL METHOD l_document->add_attachment( i_attachment_type = l_attcdoctype i_attachment_subject = l_atttitle i_attachment_size = gv_size i_att_content_hex = gt_binary_content ). l_send_request = cl_bcs=>create_persistent( ). l_send_request->set_document( l_document ). * Define Sender l_sender = cl_sapuser_bcs=>create( sy-uname ). TRY. CALL METHOD l_send_request->set_sender EXPORTING i_sender = l_sender. CATCH cx_send_req_bcs . "#EC NO_HANDLER ENDTRY. * Define Recipient l_recipent = cl_cam_address_bcs=>create_internet_address( p_mid ). l_send_request->add_recipient( EXPORTING i_recipient = l_recipent ). * Schedule l_send_request->set_send_immediately( 'X' ). l_send_request->send( ). COMMIT WORK AND WAIT. * Catch Execptions CATCH cx_bcs INTO l_bcs_exception. "#EC NO_HANDLER ENDTRY. IF sy-subrc = 0. CONCATENATE gv_order '-' l_message INTO l_message1 SEPARATED BY space. w_log-message = l_message1. APPEND w_log TO t_log. CLEAR w_log. ENDIF. REFRESH t_final. CLEAR w_final. ENDFORM. " SUB_SEND_MAIL *&---------------------------------------------------------------------* *& Form SUB_CONSOLIDATE_DATA *&---------------------------------------------------------------------* FORM sub_consolidate_data. */.. Consolidate and send the New Orders CLEAR gv_order. gv_order = 'New Contracts'. */..Get the list of document types to fetch the contracts. PERFORM get_document_types_new. */..Based on the selected check boxes, pick the required details. PERFORM get_contract_list. */.. Consolidate New orders PERFORM sub_consolidate_data_new. */.. Send New orders PERFORM sub_send_mail. * Display final Log PERFORM sub_display_log. ENDFORM. " SUB_CONSOLIDATE_DATA *&---------------------------------------------------------------------* *& Form SUB_GET_ITEM_DETAILS *&---------------------------------------------------------------------* FORM sub_get_item_details USING t_vbak LIKE t_vbak. REFRESH t_vbap. */..get material and its desc details from VBAP and MAKT table. IF NOT t_vbak[] IS INITIAL. SELECT a~vbeln a~posnr a~matnr a~zmeng a~kzwi3 a~kzwi5 b~maktx c~mtart FROM vbap AS a INNER JOIN makt AS b ON a~matnr = b~matnr INNER JOIN mara AS c ON c~matnr = b~matnr INTO TABLE t_vbap FOR ALL ENTRIES IN t_vbak WHERE a~vbeln = t_vbak-vbeln AND c~matnr IN r_matnr AND c~mtart IN r_mtart. ENDIF. ENDFORM. " SUB_GET_ITEM_DETAILS *&---------------------------------------------------------------------* *& Form SUB_GET_PARTNER_DETAILS *&---------------------------------------------------------------------* FORM sub_get_partner_details USING t_vbak LIKE t_vbak. REFRESH: r_parvw, t_vbpa, t_vbpa_s. w_parvw-sign = 'I'. w_parvw-option = 'EQ'. w_parvw-low = 'AG'. APPEND w_parvw TO r_parvw. CLEAR w_parvw. w_parvw-sign = 'I'. w_parvw-option = 'EQ'. w_parvw-low = 'RE'. APPEND w_parvw TO r_parvw. CLEAR w_parvw. w_parvw-sign = 'I'. w_parvw-option = 'EQ'. w_parvw-low = 'SH'. APPEND w_parvw TO r_parvw. CLEAR w_parvw. w_parvw-sign = 'I'. w_parvw-option = 'EQ'. w_parvw-low = 'Z3'. APPEND w_parvw TO r_parvw. CLEAR w_parvw. SELECT vbeln posnr parvw kunnr pernr adrnr FROM vbpa INTO TABLE t_vbpa FOR ALL ENTRIES IN t_vbak WHERE vbeln = t_vbak-vbeln AND parvw IN r_parvw. LOOP AT t_vbpa INTO w_vbpa WHERE parvw = 'Z3'. w_vbpa_s-sobid = w_vbpa-kunnr. w_vbpa_s-kunnr = w_vbpa-kunnr. APPEND w_vbpa_s TO t_vbpa_s. CLEAR w_vbpa_s. ENDLOOP. ENDFORM. " SUB_GET_PARTNER_DETAILS *&---------------------------------------------------------------------* *& Form SUB_GET_PARTNER_ADDRESS_DET *&---------------------------------------------------------------------* FORM sub_get_partner_address_det USING t_vbpa LIKE t_vbpa. REFRESH t_adrc. IF t_vbpa[] IS NOT INITIAL. SELECT addrnumber name1 name2 street city1 post_code1 region country tel_number FROM adrc INTO TABLE t_adrc FOR ALL ENTRIES IN t_vbpa WHERE addrnumber = t_vbpa-adrnr. ENDIF. ENDFORM. " SUB_GET_PARTNER_ADDRESS_DET *&---------------------------------------------------------------------* *& Form SUB_GET_EMAIL_ADDRESS *&---------------------------------------------------------------------* FORM sub_get_email_address USING t_vbpa LIKE t_vbpa. REFRESH t_adr6. IF t_vbpa[] IS NOT INITIAL. SELECT addrnumber smtp_addr FROM adr6 INTO TABLE t_adr6 FOR ALL ENTRIES IN t_vbpa WHERE addrnumber = t_vbpa-adrnr. ENDIF. ENDFORM. " SUB_GET_EMAIL_ADDRESS *&---------------------------------------------------------------------* *& Form SUB_GET_SALES_REP_DETAILS *&---------------------------------------------------------------------* FORM sub_get_sales_rep_details USING t_vbpa_s LIKE t_vbpa_s. REFRESH: t_but000, t_hrp1001. SELECT otype objid plvar relat begda endda sclas sobid FROM hrp1001 INTO TABLE t_hrp1001 FOR ALL ENTRIES IN t_vbpa_s WHERE sobid = t_vbpa_s-sobid AND otype = 'S' AND plvar = '01' AND relat = '008' AND sclas = 'BP' AND begda < sy-datum AND endda >= sy-datum. SELECT partner bpkind bu_group name_last name_first FROM but000 INTO TABLE t_but000 FOR ALL ENTRIES IN t_hrp1001 WHERE partner = t_hrp1001-sobid+0(10) AND bpkind = '9002'. ENDFORM. " SUB_GET_SALES_REP_DETAILS *&---------------------------------------------------------------------* *& Form SUB_FILL_MATERIAL_TYPES *&---------------------------------------------------------------------* FORM sub_fill_material_types . REFRESH r_mtart. REFRESH r_matnr. IF s_mat_i IS NOT INITIAL. APPEND LINES OF s_mat_i TO r_matnr. ENDIF. IF s_mat_p IS NOT INITIAL. APPEND LINES OF s_mat_p TO r_matnr. ENDIF. ENDFORM. " SUB_FILL_MATERIAL_TYPES *&---------------------------------------------------------------------* *& Form GET_DOCUMENT_TYPES_NEW *&---------------------------------------------------------------------* FORM get_document_types_new . REFRESH r_auart. w_auart-sign = 'I'. w_auart-option = 'EQ'. w_auart-low = 'ZC01'. APPEND w_auart TO r_auart. CLEAR w_auart. w_auart-sign = 'I'. w_auart-option = 'EQ'. w_auart-low = 'ZC02'. APPEND w_auart TO r_auart. CLEAR w_auart. w_auart-sign = 'I'. w_auart-option = 'EQ'. w_auart-low = 'ZC03'. APPEND w_auart TO r_auart. CLEAR w_auart. ENDFORM. " GET_DOCUMENT_TYPES_NEW *&---------------------------------------------------------------------* *& Form GET_DOCUMENT_TYPES_RENEW *&---------------------------------------------------------------------* FORM get_document_types_renew . REFRESH r_auart. w_auart-sign = 'I'. w_auart-option = 'EQ'. w_auart-low = 'ZR01'. APPEND w_auart TO r_auart. CLEAR w_auart. w_auart-sign = 'I'. w_auart-option = 'EQ'. w_auart-low = 'ZR02'. APPEND w_auart TO r_auart. CLEAR w_auart. ENDFORM. " GET_DOCUMENT_TYPES_RENEW *&---------------------------------------------------------------------* *& Form SUB_DISPLAY_LOG *&---------------------------------------------------------------------* FORM sub_display_log . DATA: l_mesg TYPE string. IF t_log IS NOT INITIAL. CONCATENATE 'Email sent to' p_mid 'successfully' INTO l_mesg SEPARATED BY space. ELSE. CONCATENATE 'Email failed to sent -' p_mid INTO l_mesg SEPARATED BY space. ENDIF. WRITE / l_mesg. LOOP AT t_log INTO w_log. WRITE: / w_log-message. CLEAR w_log. ENDLOOP. ENDFORM. " SUB_DISPLAY_LOG *&---------------------------------------------------------------------* *& Form SUB_VALIDATE_PARTNER_DATA *&---------------------------------------------------------------------* FORM sub_validate_partner_data . REFRESH t_cdhdr1[]. SORT t_cdhdr BY objectid. t_cdhdr1[] = t_cdhdr[]. LOOP AT t_cdhdr1 INTO w_cdhdr WHERE change_ind = 'I'. READ TABLE t_cdhdr1 TRANSPORTING NO FIELDS WITH KEY objectid = w_cdhdr-objectid udate = w_cdhdr-udate change_ind = 'U'. IF sy-subrc = 0. DELETE t_cdhdr WHERE objectid = w_cdhdr-objectid. ENDIF. CLEAR w_cdhdr. ENDLOOP. ENDFORM. " SUB_VALIDATE_PARTNER_DATA *&---------------------------------------------------------------------* *& Form SUB_GET_DOCUMENT_TYPE_ADD *&---------------------------------------------------------------------* FORM sub_get_document_type_add . REFRESH r_auart. w_auart-sign = 'I'. w_auart-option = 'EQ'. w_auart-low = 'ZC01'. APPEND w_auart TO r_auart. CLEAR w_auart. w_auart-sign = 'I'. w_auart-option = 'EQ'. w_auart-low = 'ZC02'. APPEND w_auart TO r_auart. CLEAR w_auart. w_auart-sign = 'I'. w_auart-option = 'EQ'. w_auart-low = 'ZC03'. APPEND w_auart TO r_auart. CLEAR w_auart. w_auart-sign = 'I'. w_auart-option = 'EQ'. w_auart-low = 'ZC04'. APPEND w_auart TO r_auart. CLEAR w_auart. w_auart-sign = 'I'. w_auart-option = 'EQ'. w_auart-low = 'ZC05'. APPEND w_auart TO r_auart. CLEAR w_auart. w_auart-sign = 'I'. w_auart-option = 'EQ'. w_auart-low = 'ZC06'. APPEND w_auart TO r_auart. CLEAR w_auart. w_auart-sign = 'I'. w_auart-option = 'EQ'. w_auart-low = 'ZR01'. APPEND w_auart TO r_auart. CLEAR w_auart. w_auart-sign = 'I'. w_auart-option = 'EQ'. w_auart-low = 'ZR02'. APPEND w_auart TO r_auart. CLEAR w_auart. ENDFORM. " SUB_GET_DOCUMENT_TYPE_ADD
REPORT zabap_send_mail. PARAMETERS: psubject(40) TYPE c DEFAULT 'Hello', p_email(40) TYPE c DEFAULT 'write email address' . DATA: it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE, it_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE, it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE, it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE, gd_cnt TYPE i, gd_sent_all(1) TYPE c, gd_doc_data LIKE sodocchgi1, gd_error TYPE sy-subrc. DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE. ************************************************************************ START-OF-SELECTION. PERFORM populate_message_table. *Send email message, although is not sent from SAP until mail send *program has been executed(rsconn01) PERFORM send_email_message. *Instructs mail send program for SAPCONNECT to send email(rsconn01) PERFORM initiate_mail_execute_program. *&--------------------------------------------------------------------- *& Form POPULATE_MESSAGE_TABLE *&--------------------------------------------------------------------- *Adds text to email text table *---------------------------------------------------------------------- FORM populate_message_table. APPEND 'Email line 1' TO it_message. APPEND 'Email line 2' TO it_message. APPEND 'Email line 3' TO it_message. APPEND 'Email line 4' TO it_message. ENDFORM. " POPULATE_MESSAGE_TABLE *&--------------------------------------------------------------------- *& Form SEND_EMAIL_MESSAGE *&--------------------------------------------------------------------- *Send email message *---------------------------------------------------------------------- FORM send_email_message. *Fill the document data. gd_doc_data-doc_size = 1. *Populate the subject/generic message attributes gd_doc_data-obj_langu = sy-langu. gd_doc_data-obj_name = 'SAPRPT'. gd_doc_data-obj_descr = psubject. gd_doc_data-sensitivty = 'F'. *Describe the body of the message CLEAR it_packing_list. REFRESH it_packing_list. it_packing_list-transf_bin = space. it_packing_list-head_start = 1. it_packing_list-head_num = 0. it_packing_list-body_start = 1. DESCRIBE TABLE it_message LINES it_packing_list-body_num. it_packing_list-doc_type = 'RAW'. APPEND it_packing_list. *Add the recipients email address CLEAR it_receivers. REFRESH it_receivers. it_receivers-receiver = p_email. it_receivers-rec_type = 'U'. it_receivers-com_type = 'INT'. it_receivers-notif_del = 'X'. it_receivers-notif_ndel = 'X'. APPEND it_receivers. *Call the FM to post the message to SAPMAIL CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = gd_doc_data put_in_outbox = 'X' IMPORTING sent_to_all = gd_sent_all TABLES packing_list = it_packing_list contents_txt = it_message receivers = it_receivers 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. *Store function module return code gd_error = sy-subrc. *Get it_receivers return code LOOP AT it_receivers. ENDLOOP. ENDFORM. " SEND_EMAIL_MESSAGE *&--------------------------------------------------------------------- *& Form INITIATE_MAIL_EXECUTE_PROGRAM *&--------------------------------------------------------------------- *Instructs mail send program for SAPCONNECT to send email. *---------------------------------------------------------------------- FORM initiate_mail_execute_program. WAIT UP TO 2 SECONDS. IF gd_error EQ 0. SUBMIT rsconn01 WITH mode = 'INT' WITH output = 'X' AND RETURN. ENDIF. ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM
SAP mail is a very robust method of interacting with users within SAP system, it is always good to receive email in Microsoft inbox. This also works like an additional notification to users in case they do not check SAP mail regularly.
Sending an email to the Microsoft Inbox is a way of interacting with a non SAP system through ABAP code and hence is very interesting. A fair knowledge of UNIX shell scripting is assumed here.
The ABAP code to send an email to Microsoft inbox revolves around following UNIX script
Echo "From:" "<"$1">" > <unix file path name>
Echo "To:" "<"$2">" >> <unix file path name>
Echo "Subject:" "<"$3">" >> <unix file path name>
Cat $4 >> <unix file path name>
Uuencode $5 $6 >> <unix file path name>
Cat <unix file path name> | /usr/sbin/sendmail -f $fraddr $toaddr
(Note : the commands in the above script can be case sensitive. Check the actual case on the unix installation in question)
Let us understand the various parts of the above script.
$1 = Sender email address
$2 = Recipient email address
$3 = Subject of the email
$4 = Path of unix server file having email body
Form email body as an internal table in ABAP program, download it to a unix server file
$5 = Path of unix server file to be sent as email attachment
$6 = Name to be given to the attachment (like test1.doc, test1.xls). The corresponding Microsoft icon will be shown in the email for the type of file attached ( Word document, excel document etc)
The script builds a temporary file and pipes the file to the sendmail command to achieve the mission.
This script can be invoked from SAP to send the mail to the intended recipient. Store this small script on the unix server. (Assume script name is sndmail )
To do this we should define a link in the SAP system between a customized command and this unix script.
The FM to define a customized command in SAP system has the following pattern.
CALL FUNCTION 'SXPG_CALL_SYSTEM' EXPORTING commandname = parameters = ' ' IMPORTING status = TABLES exec_protocol = EXCEPTIONS no_permission = 1 command_not_found = 2 parameters_too_long = 3 security_risk = 4 wrong_check_call_interface = 5 program_start_error = 6 program_termination_error = 7 x_error = 8 parameter_expected = 9 too_many_parameters = 10 illegal_command = 11 OTHERS = 12.
The parameters of Function Module are explained below:
Import Parameters Name and Description | Field name | Field function |
Commandname |
| Name of unix shell script to be invoked |
Parameters |
| The parameters to be sent to unix shell script ($1, $2 etc). Send parameters as a concatenated string separated by space and length not exceeding 128 characters |
Table Parameters Name and Description | Field Name | Field function |
Exec_protocol (structure) | Length | Length of the message from external program i.e unix |
| Message | Log message from external program i.e unix |
Export Parameters Name and Description | Field Name | Field function |
Status |
| Scheduling status of external program i.e unix |
Once the above FM is invoked with the necessary parameters the unix program sendmail will send a mail to the inbox of the recipient in Microsoft.
The restriction on the parameter string length of 128 characters can be removed to make way for very long email addresses and subjects. Build the parameters into an internal table and download it as a file on the unix server. Instead of passing each parameter individually, pass the unix server path of this file as the parameter to the unix shell script (sndmail mentioned above). Modify the shell script to read every line of this parameter file as variables to be used in the shell script.
REPORT ztsapmail. DATA: x_object_type LIKE sood-objtp. DATA: BEGIN OF x_object_hd_change. INCLUDE STRUCTURE sood1. DATA: END OF x_object_hd_change. DATA: BEGIN OF x_objcont OCCURS 10. INCLUDE STRUCTURE soli. DATA: END OF x_objcont. DATA: BEGIN OF x_objhead OCCURS 0. INCLUDE STRUCTURE soli. DATA: END OF x_objhead. DATA: BEGIN OF raw_head. INCLUDE STRUCTURE sorh. DATA: END OF raw_head. DATA: BEGIN OF x_receivers OCCURS 0. INCLUDE STRUCTURE soos1. DATA: END OF x_receivers. PARAMETERS: receiver LIKE x_receivers-recnam. " Name *BUILD MESSAGE HEADER MOVE 'Sort field goes here' TO x_object_hd_change-objsrt. " Sort field MOVE 'Name of the object goes here' TO x_object_hd_change-objnam. " Name MOVE 'Document title goes here' TO x_object_hd_change-objdes. " Title MOVE 'F' TO x_object_hd_change-objsns. " Functional OBJECT MOVE 'E' TO x_object_hd_change-objla. " Language * Object type of the new document MOVE 'RAW' TO x_object_type. CLEAR x_objcont. MOVE 'Contents of mail' TO x_objcont-line. APPEND x_objcont. CLEAR x_objcont-line. APPEND x_objcont. MOVE 'More contents' TO x_objcont-line. APPEND x_objcont. MOVE 'Still more contents' TO x_objcont-line. APPEND x_objcont. MOVE ' ' TO x_objcont-line. APPEND x_objcont. * Specific header (Dependent on the object type, here RAW) REFRESH x_objhead. DESCRIBE TABLE x_objcont LINES raw_head-rawsiz. MOVE raw_head TO x_objhead. APPEND x_objhead. *RECEIVERS table CLEAR x_receivers. REFRESH x_receivers. MOVE receiver TO x_receivers-recnam. " Name MOVE 'B' TO x_receivers-recesc. " Receiver type MOVE 'X' TO x_receivers-sndcp. " Send as a copy MOVE 'X' TO x_receivers-sndex. " EXPRESS DOCUMENT APPEND x_receivers. CALL FUNCTION 'SO_OBJECT_SEND' EXPORTING object_hd_change = x_object_hd_change object_type = x_object_type outbox_flag = 'X' owner = sy-uname TABLES objcont = x_objcont objhead = x_objhead receivers = x_receivers. * DATA: to_address LIKE sy_lisel, from_address LIKE sy-lisel, subject LIKE sy-lisel, attachment_name LIKE sy_lisel, data_file_path LIKE sxpgcolist-parameters, body_file_path LIKE sxpgcolist-parameters. DATA : BEGIN OF int_email_attach OCCURS 0, txtline(255), END OF int_email_attach. DATA : BEGIN OF int_email_body OCCURS 0, txtline(255), END OF int_email_body. CLEAR : int_exec_protocol,int_email_attach,int_email_body. REFRESH : int_exec_protocol,int_email_attach,int_email_body. * int_email_attach-txtline = 'Put all attachment text in this table'. APPEND int_email_attach. CLEAR int_email_attach. int_email_body-txtline = 'Put all attachment text in this table'. APPEND int_email_body. CLEAR int_email_body. * CONCATENATE to_address from_address subject body_file_path data_file_path attachment_name INTO v_parameters. * IF NOT int_email_attach[] IS INITIAL. OPEN DATASET data_file_path FOR OUTPUT IN TEXT MODE. LOOP AT int_email_attach. TRANSFER int_email_attach-txtline TO data_file_path. ENDLOOP. CLOSE DATASET data_file_path. ENDIF. * IF NOT int_email_body[] IS INITIAL. OPEN DATASET body_file_path FOR OUTPUT IN TEXT MODE. LOOP AT int_email_body. TRANSFER int_email_body-txtline TO body_file_path. ENDLOOP. CLOSE DATASET body_file_path. ENDIF. * CALL FUNCTION 'SXPG_CALL_SYSTEM' EXPORTING commandname = 'Z_EMAIL' " - Command calling unix script PARAMETERS = v_parameters TABLES exec_protocol = int_exec_protocol EXCEPTIONS no_permission = 1 command_not_found = 2 parameters_too_long = 3 security_risk = 4 wrong_check_call_interface = 5 program_start_error = 6 program_termination_error = 7 x_error = 8 parameter_expected = 9 too_many_parameters = 10 illegal_command = 11 OTHERS = 12.
With the Help of this code u are able to send a mail to the Non SAP system.
Author: Gunda Ravi Kumar
Submitted: 22/05/2007
Sending a mail with file attachment
Description:
I have seen many people asking queries regarding sending mail, and also while attaching the file to a mail. There are standard Function Modules provided by SAP to achieve this task, even then there might be problems while populating the file to be attached or while populating the Function Module parameters. The following code clearly explains the process of sending mail with file attachment.
**Data Declarations
**Internal Table
DATA : BEGIN OF it_spfli OCCURS 0,
carrid LIKE spfli-carrid,
connid LIKE spfli-connid,
END OF it_spfli.
DATA: it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
it_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
** storing receivers
it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
**storing file attachment data
it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE, gd_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc,
l_gntxt LIKE t357g_t-gntxt,
lv_message(100) TYPE c.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE. "storing mail body
DATA : psubject(30) TYPE c VALUE 'Sample Mail'. "subject of the mail
DATA : ld_format TYPE so_obj_tp , "file format
ld_attfilename TYPE so_obj_des, "file name
w_cnt TYPE i.
**Selecting the data
SELECT carrid connid INTO TABLE it_spfli FROM spfli WHERE carrid EQ 'AA'.
**Perform for populating mail body
PERFORM populate_message.
**Perform for populating file attachment
PERFORM populate_attachment.
**Perform for populating mail characteristic info
PERFORM populate_pack.
**Perform for populating receivers
PERFORM populate_receivers.
**Perform to send mail
PERFORM send_mail.
*&---------------------------------------------------------------------*
*& Form populate_message
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM populate_message .
**Populating the body
lv_message = 'Sample mail for testing purpose.'.
APPEND lv_message TO it_message.
ENDFORM. " populate_message
*&---------------------------------------------------------------------*
*& Form populate_attachment
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM populate_attachment .
**Populating the attachment file with the data from final intenal table
CONCATENATE 'CARRIER ID'
'CONNECTION ID'
INTO it_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>cr_lf it_attachment INTO
it_attachment.
APPEND it_attachment.
LOOP AT it_spfli.
CONCATENATE it_spfli-carrid it_spfli-connid INTO it_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>cr_lf it_attachment INTO
it_attachment.
APPEND it_attachment.
ENDLOOP.
ENDFORM. " populate_attachment
*&---------------------------------------------------------------------*
*& Form populate_receivers
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM populate_receivers .
**Populating Mail Recepients
**If there are more than one mail recepient then loop and append them to it_receivers
it_receivers-receiver = Mail-id of the receiver. (eg : 'abc@xyz.com')
it_receivers-rec_type = 'U'.
it_receivers-com_type = 'INT'.
it_receivers-notif_del = 'X'.
it_receivers-notif_ndel = 'X'.
it_receivers-express = 'X'.
APPEND it_receivers.
ENDFORM. " populate_receivers
*&---------------------------------------------------------------------*
*& Form populate_pack
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM populate_pack .
**File Type
ld_format = 'XLS'.
**File Name
ld_attfilename = 'File1'.
* Fill the document data.
gd_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SAPRPT'.
gd_doc_data-obj_descr = psubject .
gd_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
CLEAR gd_doc_data.
* Populate the subject/generic message attributes
gd_doc_data-obj_langu = sy-langu.
READ TABLE it_attachment INDEX w_cnt.
gd_doc_data-doc_size = ( w_cnt - 1 ) * 255 + STRLEN( it_attachment ).
gd_doc_data-obj_name = 'SAPRPT'.
gd_doc_data-obj_descr = psubject.
gd_doc_data-sensitivty = 'F'.
* Describe the body of the message
CLEAR it_packing_list.
REFRESH it_packing_list.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES it_packing_list-body_num.
it_packing_list-doc_type = 'RAW'.
APPEND it_packing_list.
**Describe the attachment info
it_packing_list-transf_bin = 'X'.
it_packing_list-head_start = 1.
it_packing_list-head_num = 1.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_attachment LINES it_packing_list-body_num.
it_packing_list-doc_type = ld_format.
it_packing_list-obj_name = ld_attfilename.
it_packing_list-obj_descr = ld_attfilename.
it_packing_list-doc_size = it_packing_list-body_num * 255.
APPEND it_packing_list.
ENDFORM. " populate_pack
*&---------------------------------------------------------------------*
*& Form send_mail
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM send_mail .
**Function Module to send mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gd_doc_data
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_packing_list
contents_bin = it_attachment
contents_txt = it_message
receivers = it_receivers
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.
ENDFORM. " send_mail
Back to Sending Mails - Home Page
Author: Pratik Mallick
Submitted: 3rd April 2009
Introduction
Send notification is becoming important from business point of view. It adds extra reliability to the process and enables business person to react quickly to customer's requirement. If any error occurred to a process some group of people in the top management will get a notification and react based on the details specified in the notification.
Business Requirements
In some situation we had to send a notification to a group people. Some cases we had to only send the text in the mail body and some cases we had to send the detail records as attachments. Suppose one user ran a program to update the material master and the top management wants to get the success records as one attachment and error records as another attachment in the email.
Methodology
Using the below object oriented technique it can easily obtained.
Create object
The standard class CL_BCS is used to send the notification along with attachment to a group of people. Method CREATE_PERSISTENT is used to create an send request object of the standard class CL_BCS.
Create body of the email
Method CREATE_DOCUMENT of standard class CL_DOCUMENT_BCS is used to create the text of the email body.
Create attachments of the email
Method ADD_ATTACHMENT of standard class CL_DOCUMENT_BCS is used to create attachment of the email. If we want to create the multiple attachment we have call this method multiple times.
Method SET_DOCUMENT of the standard class CL_BCS is used to add the document (email body and attachments) to be send request object.
Create sender
Method CREATE of the standard class CL_SAPUSER_BCS is used to create the sender address.
Method SET_SENDER of standard class CL_BCS is used add the sender address to the send request object.
Create recipient
Method CREATE_INTERNET_ADDRESS of standard class CL_CAM_ADDRESS_BCS is used to create recipient email address.
Method ADD_RECIPIENT of standard class CL_BCS is used to add the recipient email address to the send request object.
Send email
Method SEND of standard class CL_BCS is used to send the send request object to a group of people added in the recipient list.
Sending is done in a queued way; immediate sending can be triggered for very urgent alerts.
Code
data: l_send_request type ref to cl_bcs, " Send request l_body type bcsy_text, " Mail body l_success type bcsy_text, " Atchmnt for success l_error type bcsy_text, " Atchmnt for error wa_text type soli, " Work area for attach l_document type ref to cl_document_bcs, " Mail body l_sender type ref to if_sender_bcs, " Sender address l_recipient type ref to if_recipient_bcs, " Recipient l_size type sood-objlen, " Size of Attachment l_lines type i, " Lines count l_email type ad_smtpadr, " Email ID l_extension type soodk-objtp value 'RAW'. " TXT format * Prepare mail bidy append 'Send multiple file as attachment of a Email.' to l_body. append space to l_body. * Preparing contents of attachment with Change Log * Header line wa_text-line+0 = 'First column'. wa_text-line+20 = 'Second column'. wa_text-line+40 = 'Third column'. wa_text-line+60 = 'Fourth column'. wa_text-line+80 = 'Fifth column'. wa_text-line+100 = 'Sixth column'. wa_text-line+120 = 'Seventh column'. wa_text-line+140 = 'Eighth column'. append wa_text to l_success. append wa_text to l_error. clear : wa_text. * Populate the data part wa_text-line+0 = '111111111'. wa_text-line+20 = '222222222'. wa_text-line+40 = '333333333'. wa_text-line+60 = '333333333'. wa_text-line+80 = '444444444'. wa_text-line+100 = '555555555'. wa_text-line+120 = '666666666'. wa_text-line+140 = '777777777'. append wa_text to l_success. clear : wa_text. wa_text-line+0 = 'aaaaaaaaa'. wa_text-line+20 = 'bbbbbbbbb'. wa_text-line+40 = 'ccccccccc'. wa_text-line+60 = 'ddddddddd'. wa_text-line+80 = 'eeeeeeeee'. wa_text-line+100 = 'fffffffff'. wa_text-line+120 = 'ggggggggg'. wa_text-line+140 = 'hhhhhhhhh'. append wa_text to l_error. clear : wa_text. * Creates persistent send request l_send_request = cl_bcs=>create_persistent( ). * Craete document for mail body l_document = cl_document_bcs=>create_document( i_type = 'RAW' i_text = l_body " Mail body i_subject = 'Mail send as attachment' ). * Attachment for success records l_lines = lines( l_success ). l_size = l_lines * 255. * Add attchment call method l_document->add_attachment exporting i_attachment_type = l_extension i_attachment_subject = 'Success' i_attachment_size = l_size i_att_content_text = l_success. " Attachment for success record * Attachment for error records l_lines = lines( l_error ). l_size = l_lines * 255. * Add attchment call method l_document->add_attachment exporting i_attachment_type = l_extension i_attachment_subject = 'Error' i_attachment_size = l_size i_att_content_text = l_error. " Attachment for error record * Add the document to send request call method l_send_request->set_document( l_document ). * Sender addess l_sender = cl_sapuser_bcs=>create( sy-uname ). call method l_send_request->set_sender exporting i_sender = l_sender. * Recipient address l_email = 'myname@in.ibm.com'. l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ). * Add recipient address to send request call method l_send_request->add_recipient exporting i_recipient = l_recipient i_express = 'X' i_copy = ' ' i_blind_copy = ' ' i_no_forward = ' '. l_email = 'myname@gmail.com'. l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ). * Add recipient address to send request call method l_send_request->add_recipient exporting i_recipient = l_recipient i_express = 'X' i_copy = ' ' i_blind_copy = ' ' i_no_forward = ' '. * E-Mail is placed into queue for sending. In case of very important alerts * use the following parameter to initiate an 'immediate sending'; but notice that * this will trigger a dedicated send process for every single message - which is * very costly for system performance * l_send_request->set_send_immediately( 'X' ). "uncomment for immediate sending * Send mail call method l_send_request->send( ). commit work. */
Mail via SAP ABAP Coding.........
*******************Send mail in SAP ABAP**************************
* Data Declarations DATA: LT_MAILSUBJECT TYPE SODOCCHGI1. DATA: LT_MAILRECIPIENTS TYPE STANDARD TABLE OF SOMLREC90 WITH HEADER LINE. DATA: LT_MAILTXT TYPE STANDARD TABLE OF SOLI WITH HEADER LINE. * Recipients LT_MAILRECIPIENTS-REC_TYPE = 'U'. LT_MAILRECIPIENTS-RECEIVER = 'sheetal@gmail.com'. APPEND LT_MAILRECIPIENTS . CLEAR LT_MAILRECIPIENTS . * Subject. LT_MAILSUBJECT-OBJ_NAME = 'TEST'. LT_MAILSUBJECT-OBJ_LANGU = SY-LANGU. LT_MAILSUBJECT-OBJ_DESCR = 'Mail Subject'. * Mail Contents LT_MAILTXT = 'This is a test mail'. APPEND LT_MAILTXT. CLEAR LT_MAILTXT. * Send Mail CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1' EXPORTING DOCUMENT_DATA = LT_MAILSUBJECT TABLES OBJECT_CONTENT = LT_MAILTXT 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 EQ 0. COMMIT WORK. * Push mail out from SAP outbox SUBMIT RSCONN01 WITH MODE = 'INT' AND RETURN. ENDIF.
****************End ************************************************
Sheetal Gulati
sap.miniarora@gmail.com
Author: Vinod Reddy Vemuru
Submitted: 25/01/2009
This sample code can be used to send Email with HTML attachment.
REPORT z756942. PARAMETERS: po_email TYPE ad_smtpadr LOWER CASE. DATA: li_objcont TYPE STANDARD TABLE OF solisti1, li_reclist TYPE STANDARD TABLE OF somlreci1, li_objpack TYPE STANDARD TABLE OF sopcklsti1, li_objhead TYPE STANDARD TABLE OF solisti1, li_content TYPE STANDARD TABLE OF solisti1, lwa_objcont TYPE solisti1, lwa_reclist TYPE somlreci1, lwa_objpack TYPE sopcklsti1, lwa_objhead TYPE solisti1, lwa_content TYPE solisti1, lwa_doc TYPE sodocchgi1, l_lines TYPE i. REFRESH: li_objcont[], li_reclist[], li_objpack[], li_objhead[], li_content[]. CLEAR: lwa_objcont, lwa_reclist, lwa_objpack, lwa_objhead, lwa_content, lwa_doc. MOVE '<body>' TO lwa_objcont. APPEND lwa_objcont TO li_objcont. MOVE '<p>' TO lwa_objcont. APPEND lwa_objcont TO li_objcont. MOVE 'This is a sample HTML content from test program' TO lwa_objcont. APPEND lwa_objcont TO li_objcont. MOVE '</p>' TO lwa_objcont. APPEND lwa_objcont TO li_objcont. MOVE '</body>' TO lwa_objcont. APPEND lwa_objcont TO li_objcont. lwa_reclist-receiver = po_email. lwa_reclist-rec_type = 'U'. APPEND lwa_reclist TO li_reclist. lwa_objhead = 'test.htm'. APPEND lwa_objhead TO li_objhead. lwa_content = 'Please find attached document for more details'. APPEND lwa_content TO li_content. CLEAR l_lines. DESCRIBE TABLE li_content LINES l_lines. READ TABLE li_content INTO lwa_content INDEX l_lines. lwa_doc-doc_size = ( l_lines - 1 ) * 255 + STRLEN( lwa_content ). lwa_doc-obj_langu = 'E'. lwa_doc-obj_name = 'Test HTML file'. lwa_doc-obj_descr = 'Test HTML file'. CLEAR lwa_objpack-transf_bin. lwa_objpack-head_start = 1. lwa_objpack-head_num = 0. lwa_objpack-body_start = 1. lwa_objpack-body_num = l_lines. lwa_objpack-doc_type = 'RAW'. APPEND lwa_objpack TO li_objpack. CLEAR: lwa_objpack, l_lines. DESCRIBE TABLE li_objcont LINES l_lines. READ TABLE li_objcont INTO lwa_objcont INDEX l_lines. lwa_objpack-doc_size = ( l_lines - 1 ) * 255 + STRLEN( lwa_objcont ). lwa_objpack-transf_bin = 'X'. lwa_objpack-head_start = 1. lwa_objpack-head_num = 0. lwa_objpack-body_start = 1. lwa_objpack-body_num = l_lines. lwa_objpack-doc_type = 'HTM' . lwa_objpack-obj_name = 'Test HTML file'. lwa_objpack-obj_descr = 'Test HTML file'. APPEND lwa_objpack TO li_objpack. *Sending the mail CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = lwa_doc put_in_outbox = 'X' TABLES packing_list = li_objpack object_header = li_objhead contents_bin = li_objcont contents_txt = li_content receivers = li_reclist EXCEPTIONS too_many_receivers = 1 document_not_sent = 2 operation_no_authorization = 4 OTHERS = 99. IF sy-subrc NE 0. WRITE:/ 'Document sending failed'. ELSE. WRITE:/ 'Document successfully sent'. COMMIT WORK. ENDIF.
In some scenario where we have to send error records or some impotent documents to a group of people as attachments via Email.
REPORT ztest_subha_mail. DATA: l_send_request TYPE REF TO cl_bcs, " Send request l_body TYPE bcsy_text, " Mail body l_attach TYPE bcsy_text, " Attachment wa_text TYPE soli, " Work area for attach l_document TYPE REF TO cl_document_bcs, " Mail body l_sender TYPE REF TO if_sender_bcs, " Sender address l_recipient TYPE REF TO if_recipient_bcs, " Recipient l_size TYPE sood-objlen, " Size of Attachment c_tab TYPE abap_char1 VALUE cl_abap_char_utilities=>horizontal_tab, l_lines TYPE i, " Lines count l_email TYPE ad_smtpadr, " Email ID l_extension TYPE soodk-objtp VALUE 'RAW'. " TXT format * Prepare mail bidy APPEND 'Test Mail by Subhankar' TO l_body. * Preparing contents of attachment with Change Log * Header line wa_text-line+0 = 'First column'. wa_text-line+20 = 'Second column'. wa_text-line+40 = 'Third column'. wa_text-line+60 = 'Fourth column'. wa_text-line+80 = 'Fifth column'. wa_text-line+100 = 'Sixth column'. wa_text-line+120 = 'Seventh column'. wa_text-line+140 = 'Eighth column'. APPEND wa_text TO l_attach. CLEAR : wa_text. * Populate the data part wa_text-line+0 = '111111111'. wa_text-line+20 = '222222222'. wa_text-line+40 = '333333333'. wa_text-line+60 = '333333333'. wa_text-line+80 = '444444444'. wa_text-line+100 = '555555555'. wa_text-line+120 = '666666666'. wa_text-line+140 = '777777777'. APPEND wa_text TO l_attach. CLEAR : wa_text. wa_text-line+0 = 'aaaaaaaaa'. wa_text-line+20 = 'bbbbbbbbb'. wa_text-line+40 = 'ccccccccc'. wa_text-line+60 = 'ddddddddd'. wa_text-line+80 = 'eeeeeeeee'. wa_text-line+100 = 'fffffffff'. wa_text-line+120 = 'ggggggggg'. wa_text-line+140 = 'hhhhhhhhh'. APPEND wa_text TO l_attach. CLEAR : wa_text. l_lines = LINES( l_attach ). l_size = l_lines * 255. * Creates persistent send request l_send_request = cl_bcs=>create_persistent( ). * Craete document for mail body l_document = cl_document_bcs=>create_document( i_type = 'RAW' i_text = l_body i_subject = 'Mail send as attachment' ). * Add attchment CALL METHOD l_document->add_attachment EXPORTING i_attachment_type = l_extension i_attachment_subject = 'My attachment' i_attachment_size = l_size i_att_content_text = l_attach. * Add the document to send request CALL METHOD l_send_request->set_document( l_document ). * Sender addess l_sender = cl_sapuser_bcs=>create( sy-uname ). CALL METHOD l_send_request->set_sender EXPORTING i_sender = l_sender. * Recipient address l_email = 'sugarani@in.ibm.com'. l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ). * Add recipient address to send request CALL METHOD l_send_request->add_recipient EXPORTING i_recipient = l_recipient i_express = 'X' i_copy = ' ' i_blind_copy = ' ' i_no_forward = ' '. * Trigger E-Mail immediately l_send_request->set_send_immediately( 'X' ). * Send mail CALL METHOD l_send_request->send( ). COMMIT WORK.
Author: Suresh Maryala
Submitted: 03/24/2008
Purpose of this document is to capture sending multiple attachments of Spool using SAP E-mail. Spool is converted to HTML format before sent as e-mail. There is no limit on how many attachments can be sent.
This is an example of a code sample:
TABLES: sos04, rspotype, soli. PARAMETERS: p_des LIKE sood1-objdes. SELECT-OPTIONS: s_spool FOR rspotype-rqnumber NO INTERVALS, s_emails FOR sos04-l_adr_name NO INTERVALS, s_text FOR soli-line NO INTERVALS. ************************************************************************ * DATA DEFINITION ************************************************************************ *TYPES TYPES: BEGIN OF ty_tbtcp. INCLUDE STRUCTURE tsp01. TYPES: END OF ty_tbtcp. TYPES: BEGIN OF ty_objpack, rqnumber TYPE rspotype-rqnumber, head_start TYPE sopcklsti1-head_start, head_num TYPE sopcklsti1-head_num, body_start TYPE sopcklsti1-body_start, body_num TYPE sopcklsti1-body_num, no_lines TYPE i, END OF ty_objpack. *INTERNAL TABLES DATA: lt_tbtcp TYPE STANDARD TABLE OF ty_tbtcp, lt_objpack TYPE STANDARD TABLE OF ty_objpack, lt_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE, lt_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE, lt_mess_2 LIKE solisti1 OCCURS 0 WITH HEADER LINE, lt_spool_list TYPE STANDARD TABLE OF bapixmspoo WITH HEADER LINE, lt_spool_2 TYPE STANDARD TABLE OF bapixmspoo WITH HEADER LINE, l_spool_id LIKE tsp01-rqident. DATA: ls_tbtcp TYPE ty_tbtcp, ls_objpack TYPE ty_objpack. DATA so_ali LIKE soli OCCURS 0 WITH HEADER LINE. DATA: it_lines LIKE tline OCCURS 0 WITH HEADER LINE. DATA: p_template LIKE wwwdataid-objid. DATA listtab LIKE abaplist OCCURS 1. DATA p_html LIKE bapihtml OCCURS 10 WITH HEADER LINE. DATA lt_html LIKE bapihtml OCCURS 10 WITH HEADER LINE. *STRUCTURES *VARIABLES *VARIABLES DATA: l_spool_nr LIKE tsp01-rqident, l_bytecount LIKE tst01-dsize, l_buffer TYPE string, l_spool_cnt TYPE i, l_cnt TYPE i, l_line_no TYPE i, l_total_cnt TYPE i, p_cnt(3) TYPE c, p_spool_nr(10) TYPE c. DATA: l_subject LIKE sodocchgi1-obj_descr, l_sender_type LIKE soextreci1-adr_typ, l_recsize TYPE i, l_receiver TYPE sy-subrc. DATA: ld_sender_address LIKE soextreci1-receiver, ld_sender_address_type LIKE soextreci1-adr_typ, ld_error TYPE sy-subrc. DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE, t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE, t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE, w_sent_all(1) TYPE c, w_doc_data LIKE sodocchgi1. DATA: tab_lines LIKE sy-tabix. ************************************************************************ * INITIALIZATION ************************************************************************ INITIALIZATION. ************************************************************************ * START-OF-SELECTION ************************************************************************ START-OF-SELECTION. * Read Spool Number PERFORM f_obtain_spool_id. * HTML Logic PERFORM f_convert_spool_to_htm. * E-mail need to be sent as HTML PERFORM f_process_email. * End process IF sy-subrc <> 0. WRITE:/ 'Error Sending Document', / 'Return Code:', sy-subrc. ELSE. WRITE:/ 'Document successfully sent'. ENDIF. ************************************************************************ *END-OF-SELECTON ************************************************************************ END-OF-SELECTION. *&---------------------------------------------------------------------* *& Form f_obtain_spool_id *&---------------------------------------------------------------------* FORM f_obtain_spool_id . * Capture all Spool Numbers into a internal table REFRESH lt_tbtcp. CLEAR ls_tbtcp. SELECT * INTO TABLE lt_tbtcp FROM tsp01 WHERE rqident IN s_spool. * Sort by Spool Number SORT lt_tbtcp BY rqident. * Capture the number of spool numbers entered CLEAR l_total_cnt. DESCRIBE TABLE lt_tbtcp LINES l_total_cnt. ENDFORM. " f_obtain_spool_id *&---------------------------------------------------------------------* *& Form f_process_email *&---------------------------------------------------------------------* FORM f_process_email . * HTML E-mail DESCRIBE TABLE lt_html LINES l_recsize. CHECK l_recsize > 0. PERFORM f_send_email. ENDFORM. " f_process_email *&---------------------------------------------------------------------* *& Form f_send_email *&---------------------------------------------------------------------* FORM f_send_email . CHECK NOT ( s_emails-low IS INITIAL ). REFRESH lt_mess_bod. * Default subject matter l_subject = p_des. IF NOT s_text-low IS INITIAL. LOOP AT s_text. MOVE s_text-low TO lt_mess_bod. APPEND lt_mess_bod. CLEAR lt_mess_bod. ENDLOOP. ENDIF. * HTML Attachment logic PERFORM f_send_email_html_attachment. ENDFORM. " f_send_email *&---------------------------------------------------------------------* *& Form f_convert_spool_to_htm *&---------------------------------------------------------------------* FORM f_convert_spool_to_htm . LOOP AT lt_tbtcp INTO ls_tbtcp. CLEAR p_html. REFRESH p_html. ADD 1 TO l_cnt. l_spool_id = ls_tbtcp-rqident. SUBMIT rspolst2 EXPORTING LIST TO MEMORY AND RETURN WITH rqident = l_spool_id. CALL FUNCTION 'LIST_FROM_MEMORY' TABLES listobject = listtab EXCEPTIONS not_found = 1 OTHERS = 2. IF sy-subrc <> 0. * message e418 raising read_error. ENDIF. IF p_template IS INITIAL. p_template = 'WEBREPORTING_REPORT'. ENDIF. CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT' EXPORTING template_name = p_template TABLES html = p_html listobject = listtab EXCEPTIONS OTHERS = 1. LOOP AT p_html. MOVE-CORRESPONDING p_html TO lt_html. APPEND lt_html. ENDLOOP. * Building table lt_objpack internal table for creating attachments MOVE l_spool_id TO ls_objpack-rqnumber. IF l_cnt = 1. MOVE 1 TO ls_objpack-head_start. MOVE 0 TO ls_objpack-head_num. MOVE 1 TO ls_objpack-body_start. DESCRIBE TABLE lt_html LINES ls_objpack-no_lines. MOVE ls_objpack-no_lines TO ls_objpack-body_num. APPEND ls_objpack TO lt_objpack. ENDIF. IF l_cnt > 1. ls_objpack-head_start = ls_objpack-no_lines + 1. ls_objpack-head_num = ls_objpack-no_lines + 1. ls_objpack-body_start = ls_objpack-no_lines + 1. DESCRIBE TABLE p_html LINES ls_objpack-no_lines. MOVE ls_objpack-no_lines TO ls_objpack-body_num. APPEND ls_objpack TO lt_objpack. * Overwrite total number of lines DESCRIBE TABLE lt_html LINES ls_objpack-no_lines. ENDIF. ENDLOOP. ENDFORM. " f_convert_spool_to_htm *&---------------------------------------------------------------------* *& Form f_send_email_html_attachment *&---------------------------------------------------------------------* FORM f_send_email_html_attachment . * Fill the document data. w_doc_data-doc_size = 1. * Fill the document data and get size of attachment CLEAR w_doc_data. w_doc_data-obj_langu = sy-langu. w_doc_data-obj_name = 'SAPRPT'. w_doc_data-obj_descr = p_des . w_doc_data-sensitivty = 'F'. CLEAR t_attachment. REFRESH t_attachment. t_attachment[] = lt_html[]. * Describe the body of the message CLEAR t_packing_list. REFRESH t_packing_list. DESCRIBE TABLE lt_mess_bod LINES tab_lines. READ TABLE lt_mess_bod INDEX tab_lines. w_doc_data-doc_size = ( tab_lines - 1 ) * 255 + strlen( lt_mess_bod ). CLEAR t_packing_list-transf_bin. t_packing_list-head_start = 1. t_packing_list-head_num = 0. t_packing_list-body_start = 1. t_packing_list-body_num = tab_lines. t_packing_list-doc_type = 'RAW'. APPEND t_packing_list. * Create attachment notification CLEAR: l_line_no. LOOP AT lt_objpack INTO ls_objpack. ADD 1 TO l_line_no. t_packing_list-transf_bin = 'X'. t_packing_list-head_start = ls_objpack-head_start. t_packing_list-head_num = ls_objpack-head_num. t_packing_list-body_start = ls_objpack-body_start. t_packing_list-doc_type = 'HTM'. p_cnt = l_line_no. CONDENSE p_cnt. p_spool_nr = ls_objpack-rqnumber. CONCATENATE 'Attachment' p_cnt INTO t_packing_list-obj_name SEPARATED BY space. * Format Attachment Name. PERFORM get_attachment_name USING p_spool_nr CHANGING t_packing_list-obj_descr. t_packing_list-body_num = ls_objpack-body_num. t_packing_list-doc_size = t_packing_list-body_num * 255. APPEND t_packing_list. ENDLOOP. * Add the recipients email address CLEAR t_receivers. REFRESH t_receivers. LOOP AT s_emails. t_receivers-receiver = s_emails-low. t_receivers-rec_type = 'U'. t_receivers-com_type = 'INT'. t_receivers-notif_del = 'X'. t_receivers-notif_ndel = 'X'. * E-mail Delivery is selected IF NOT p_del IS INITIAL. t_receivers-notif_del = 'X'. ELSE. CLEAR t_receivers-notif_del. ENDIF. * E-mail Read receipt is checked IF NOT p_read IS INITIAL. t_receivers-notif_read = 'X'. ELSE. CLEAR t_receivers-notif_read. ENDIF. APPEND t_receivers. ENDLOOP. ld_sender_address = sy-uname. ld_sender_address_type = 'B'. CALL FUNCTION 'SO_DOCUMENT_SEND_API1' EXPORTING document_data = w_doc_data put_in_outbox = 'X' sender_address = ld_sender_address sender_address_type = ld_sender_address_type commit_work = 'X' IMPORTING sent_to_all = w_sent_all TABLES packing_list = t_packing_list contents_bin = t_attachment contents_txt = lt_mess_att receivers = t_receivers 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. * Populate error return code ld_error = sy-subrc. * Populate zreceiver return code LOOP AT t_receivers. l_receiver = t_receivers-retrn_code. ENDLOOP. ENDFORM. " f_send_email_html_attachment *&---------------------------------------------------------------------* *& Form GET_ATTACHMENT_NAME *&---------------------------------------------------------------------* FORM get_attachment_name USING p_spool_nr CHANGING t_packing_list_obj_descr. CLEAR ls_tbtcp. READ TABLE lt_tbtcp INTO ls_tbtcp WITH KEY rqident = p_spool_nr BINARY SEARCH. IF sy-subrc EQ 0. IF ls_tbtcp-rqtitle IS INITIAL. ls_tbtcp-rqtitle = ls_tbtcp-rq2name. ENDIF. CONCATENATE p_spool_nr '-' ls_tbtcp-rqtitle INTO t_packing_list_obj_descr SEPARATED BY space. ELSE. CONCATENATE p_spool_nr '- Spool' INTO t_packing_list_obj_descr SEPARATED BY space. ENDIF. CONDENSE t_packing_list_obj_descr. ENDFORM. " GET_ATTACHMENT_NAME
Description: In the Business Process Modeling Group I have seen alot of request regarding how to send mail notifications by using ABAP Code.
I have used the below mentioned code in several cases like
Info Letter to all Vendors, Sending PO Via Email, Reminder mails to the Agents in Workflow and also escalation mails to Process Owners when the task is not performed by the agents in the given time.
Prerequisite : SAP Enterprise Edition and above
SAP Connect needs to be configured
Mail Rely should be available
DATA reciever TYPE TABLE OF adr6-smtp_addr. DATA subject TYPE so_obj_des. DATA text TYPE bcsy_text. DATA line TYPE soli-line. 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 sent_to_all TYPE os_boolean. DATA adresse TYPE adr6-smtp_addr. DATA mailflag(1) VALUE space. DATA dat(10). DATA time(10). DATA tfree(12). WRITE sy-datum TO dat. WRITE sy-uzeit TO time. subject = 'This is my Subject '. line = ' I am the body of the message '. APPEND line TO text. *mail send mail out to external mail server . TRY. * create the send request send_request = cl_bcs=>create_persistent( ). document = cl_document_bcs=>create_document( i_type = 'RAW' i_text = text i_subject = betreff ). * add document to send request send_request->set_document( document ). * create recipient and add to send request adresse = 'reciever@xyz.com'. recipient = cl_cam_address_bcs=>create_internet_address( adresse ). send_request->add_recipient( i_recipient = recipient ). * send mail now sent_to_all = send_request->send( i_with_error_screen = 'X' ). IF sent_to_all = 'X'. MESSAGE s022(so). ENDIF. CATCH cx_bcs INTO bcs_exception. MESSAGE e865(so) WITH bcs_exception->error_type. ENDTRY. *Close Transaction. COMMIT WORK.
Many a time our customers ask us if we can send an outlook meeting notice from ABAP. Until now, We did not realize that it was possible, But now we do.
Here is the code snippet of what we had done to achieve this.
The first step was look at a Microsoft outlook meeting invitation as a flat file. For that, we created a meeting notice and downloaded it as a *VCS file. For this please create a dummy invite, invite attendees and save is as a .VCS file. ( File->Save as). Your flat file should look like this.
BEGIN:VCALENDAR PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN VERSION:1.0 BEGIN:VEVENT DTSTART:20070804T183000Z DTEND:20070804T190000Z LOCATION;ENCODING=QUOTED-PRINTABLE:Dennys UID:040000008200E00074C5B7101A82E0080000000070011ADA9FD6C7010000000000000000100 00000F29C2A2ACE5F284382D1B7CC8BA82B8B DESCRIPTION;ENCODING=QUOTED-PRINTABLE:=09 =0D=0A SUMMARY;ENCODING=QUOTED-PRINTABLE:Test Meeting for Code Gallery PRIORITY:3 END:VEVENT END:VCALENDAR
Now , We all know that the function module SO_NEW_DOCUMENT_ATT_SEND_API1 can be used send an e-mail with a file as an attachment. There are tons of messages already on this topic and hence to avoid redundancy, I am skipping that part. for eg please refer
http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
I am only showing the lines that are used to fill and create the calendar file. Please note this is a sample code and hence hardcoded. Please use text elements for constants and work areas to append to internal tables without directly appending them.
* These are the parameters for the attachment file name and the contents of the attachment itself. DATA: t_objhead LIKE solisti1 OCCURS 0 WITH HEADER LINE. DATA: t_objbin LIKE solisti1 OCCURS 20 WITH HEADER LINE. CONSTANTS: c_cr(2) VALUE '0D'. t_objhead = 'testappointment.vcs'. APPEND t_objhead. *hence the file will be sent as a vcs file. now for the details. CONCATENATE 'BEGIN:VCALENDAR' c_cr INTO t_objbin. APPEND t_objbin.
Please add all the other lines in the file in a similar manner.
You can also try to send an e-mail from SBWP to an external address with a VCS attachment and the results would be similar. Please note that the number UID:040000008200E00074C5B7101A82E0080000000070011ADA9FD6C7010000000000000000100
00000F29C2A2ACE5F284382D1B7CC8BA82B8B might vary for diffewrent versions. Also, they can save it into their calendar and you might get a receipt acknowlegement if you are in the same smtp server as them in case you set the flag in SO_NEW_DOCUMENT_ATT_SEND_API1. Please try using this snippet and let me know any problems you face or any questions that you may have. Happy reading.
Any comments to improve this snippet are more than welcome.
Thanks
Ganesh.S
"The following code is used to send automatic email. "define tables DATA: gt_receivers TYPE soos1_tab, gt_obj_cont TYPE soli_tab, gs_object_hd_change TYPE sood1. "define structures and work areas DATA: gs_receivers TYPE soos1, gs_obj_cont TYPE soli, gs_object_hd_change TYPE sood1. "fill two lines of email body gs_obj_cont-line = 'first line of email body'. APPEND gs_obj_cont TO gt_obj_cont. gs_obj_cont-line = 'second line of email body'. APPEND gs_obj_cont TO gt_obj_cont."set receiver gs_receivers-recextnam = 'name.last@email.com'. gs_receivers-recesc = 'E'. gs_receivers-sndart = 'INT'. gs_receivers-sndpri = 1. gs_receivers-mailstatus = 'E'. gs_receivers-rcdat = sy-datum. gs_receivers-rctim = sy-uzeit . gs_receivers-deliver = 'X'. gs_receivers-mailstatus = 'X'. gs_receivers-not_deli = 'X'. APPEND gs_receivers TO gt_receivers. gs_object_hd_change-objla = sy-langu. gs_object_hd_change-objnam = 'Immediate mail'. CALL FUNCTION 'SO_OBJECT_SEND' EXPORTING object_hd_change = gs_object_hd_change object_type = 'RAW' outbox_flag = 'X' TABLES objcont = gt_obj_cont receivers = gt_receivers EXCEPTIONS active_user_not_exist = 1 communication_failure = 2 component_not_available = 3 folder_not_exist = 4 folder_no_authorization = 5 forwarder_not_exist = 6 note_not_exist = 7 object_not_exist = 8 object_not_sent = 9 object_no_authorization = 10 object_type_not_exist = 11 operation_no_authorization = 12 owner_not_exist = 13 parameter_error = 14 substitute_not_active = 15 substitute_not_defined = 16 system_failure = 17 too_much_receivers = 18 user_not_exist = 19 originator_not_exist = 20 x_error = 21 others = 22. COMMIT WORK.
The following is the sample program for Creating OLE Application and in turn which sends the an email by storing a copy in your presentation server.
You can customize according to your requirement.
*&---------------------------------------------------------------------* *& Report YG_ABR20640 *& *&---------------------------------------------------------------------* * Program Name : YGH_ABR20640 * * Program Description : Detail Activity Report * * Developer : Raghavendra.D.S (LZ1162) * * Business Analyst : Vivek Pandey * Transaction code : YG_ABR20640 * *&---------------------------------------------------------------------* REPORT ygh_abr20640 MESSAGE-ID ygf_abr20640 LINE-COUNT 5000 LINE-SIZE 179. *----------------------------------------------------------------------* * TABLES DECLERATIONS * *----------------------------------------------------------------------* TABLES: dpr_project, cgpl_entity, but000. TYPE-POOLS: slis. *----------------------------------------------------------------------* * TYPES DECLERATIONS * *----------------------------------------------------------------------* TYPES : BEGIN OF t_cats_0315, pernr TYPE pernr_d, begda TYPE begda, endda TYPE endda, kostl TYPE skostl, lstar TYPE lstar, plsta TYPE plsta, werks TYPE werks_d, lifnr TYPE elifn, ebeln TYPE sebeln, ebelp TYPE sebelp, lstnr TYPE asnum, sprznr TYPE co_prznr, accnt TYPE c, END OF t_cats_0315, BEGIN OF t_project_id, project_id TYPE dpr_tv_project_id, END OF t_project_id, BEGIN OF t_final, participant_guid TYPE dpr_tv_participant_guid, bupa_guid TYPE bu_partner_guid, comp_code TYPE bukrs, plant TYPE werks_d, pernr TYPE personid, lifnr TYPE lifnr, name TYPE name1_gp, proj_name TYPE dpr_tv_name, name_first TYPE bu_namep_f, name_last TYPE bu_namep_l, text1 TYPE cgpl_text1, role_text TYPE dpr_tv_participant_role_text, staff_action TYPE dpr_bupa_link-staff_action, task_type TYPE dpr_tv_tsk_type, work_effort TYPE dpr_tv_effort, work_unit TYPE dpr_tv_unit, beg_tmstmp_eng TYPE sy-datum, end_tmstmp_eng TYPE sy-datum, location_text TYPE dpr_tv_location_text, task_desc(1000) TYPE c, "tdline, task_name TYPE dpr_tv_name, proj_desc(1000) TYPE c, "tdline, project_id TYPE project_id, object_key(132) TYPE c, actualstart TYPE dpr_tv_bapi_ext_date, actualfinish TYPE dpr_tv_bapi_ext_date, task_number TYPE dpr_tv_task_id, name_pm(40) TYPE c, bpkind(9) TYPE c, flag TYPE c, days_total TYPE dpr_tv_effort, END OF t_final. TYPES : BEGIN OF t_taskassignment, guid TYPE dpr_tv_guid, created_by TYPE dpr_tv_created_by, created_on TYPE dpr_tv_timestamp, changed_by TYPE dpr_tv_changed_by, changed_on TYPE dpr_tv_timestamp, sort_number TYPE dpr_tv_sort_number, participant_guid TYPE dpr_tv_guid, entity_type TYPE cgpl_object_type, entity_guid TYPE dpr_tv_guid, beg_tmstmp TYPE dpr_tv_timestamp, end_tmstmp TYPE dpr_tv_timestamp, work_effort TYPE dpr_tv_assigned_work, work_unit TYPE dpr_tv_unit, responsible TYPE dpr_tv_responsibility, concrete_role TYPE dpr_tv_concrete_role, ea_dummy TYPE dpr_tv_ea_dummy, commentary TYPE dpr_tv_commentary, END OF t_taskassignment, BEGIN OF t_taskdetail, participant_guid TYPE dpr_tv_participant_guid, entity_guid TYPE dpr_tv_guid, task_type TYPE dpr_tv_tsk_type, task_name TYPE dpr_tv_name, task_type_text TYPE dpr_tv_tsk_type_text, task_number TYPE dpr_tv_task_id, task_desc(1000) TYPE c, "tdline, END OF t_taskdetail, BEGIN OF t_output, bpartner TYPE bu_partner, mail(125) TYPE c, status(50) TYPE c, END OF t_output. TYPES : BEGIN OF t_message. INCLUDE STRUCTURE bapiret2. TYPES : END OF t_message. TYPES : BEGIN OF t_bdcdata, program TYPE bdc_prog, dynpro TYPE bdc_dynr, dynbegin TYPE bdc_start, fnam TYPE char140, fval TYPE string, END OF t_bdcdata. *----------------------------------------------------------------------* * DATA DECLERATIONS * *----------------------------------------------------------------------* DATA: v_guid TYPE cgpl_guid16, v_pernr TYPE personid, v_location TYPE dpr_tv_location, v_begdate TYPE sy-datum, v_beg_tmstmp TYPE timestamp, v_enddate TYPE sy-datum, v_end_tmstmp TYPE timestamp, v_location_text TYPE dpr_tv_location_text, v_task_guid TYPE dpr_tv_entity_guid, v_tsk_type TYPE dpr_tv_tsk_type, v_type_text TYPE dpr_tv_type_text, v_project_guid TYPE dpr_tt_guids, v_staff_action TYPE prp_action_id, v_project_guid_s TYPE LINE OF dpr_tt_guids, v_project_guid_1 TYPE dpr_tv_guid, v_text1 TYPE cgpl_text1, v_participant_role TYPE dpr_tv_participant_role, v_role_text TYPE dpr_tv_participant_role_text, v_ltext(1000) TYPE c, v_name(70) TYPE c, v_save_name(70) TYPE c, v_name_sub(100) TYPE c, v_number TYPE dpr_tv_number, v_role_guid TYPE dpr_tv_bapi_guid_role, v_guid_x16 TYPE sysuuid-x, v_guid_c32 TYPE sysuuid-c, v_sucess(4) TYPE c VALUE 0, v_failure(4) TYPE c VALUE 0, v_int_order TYPE project_id, v_name_first_pm TYPE bu_namep_f, v_name_last_pm TYPE bu_namep_l, v_name_pm(40) TYPE c, v_skipflag TYPE c VALUE '0', datediff TYPE tfmatage, v_datediff(4) TYPE n, v_bpkind TYPE bu_bpkind, v_bpkind1 TYPE catsvarian, v_bpkind2 TYPE catsvarian, v_days_total TYPE dpr_tv_assigned_work. "i. DATA : v_vis TYPE i. *----------------------------------------------------------------------* * INTERNAL TABLE DECLERATIONS * *----------------------------------------------------------------------* DATA: i_dpr_bupa_link_final TYPE STANDARD TABLE OF t_final WITH HEADER LINE, i_dpr_bupa_link_final1 TYPE STANDARD TABLE OF t_final WITH HEADER LINE, i_dpr_bupa_link_final2 TYPE STANDARD TABLE OF t_final WITH HEADER LINE, i_dpr_bupa_link_final3 TYPE STANDARD TABLE OF t_final WITH HEADER LINE, i_batchoutput TYPE STANDARD TABLE OF t_final WITH HEADER LINE, i_tline TYPE STANDARD TABLE OF tline WITH HEADER LINE, i_project_id TYPE STANDARD TABLE OF t_project_id WITH HEADER LINE, i_dpr_bupa_link TYPE STANDARD TABLE OF dpr_bupa_link WITH HEADER LINE, i_proj_guid TYPE STANDARD TABLE OF dpr_part WITH HEADER LINE, i_objlink TYPE STANDARD TABLE OF dpr_objlink WITH HEADER LINE, i_taskassignment TYPE STANDARD TABLE OF dpr_entity_link WITH HEADER LINE, i_taskdetail TYPE STANDARD TABLE OF t_taskdetail WITH HEADER LINE, i_taskassignment1 TYPE STANDARD TABLE OF t_taskassignment WITH HEADER LINE, i_output TYPE STANDARD TABLE OF t_output WITH HEADER LINE, i_et_description TYPE STANDARD TABLE OF bapi_ts_description WITH HEADER LINE, i_bapi_ts_description TYPE STANDARD TABLE OF bapi_ts_description WITH HEADER LINE, i_bapi_task_desc TYPE STANDARD TABLE OF bapi_ts_description WITH HEADER LINE, i_et_staffing TYPE STANDARD TABLE OF bapi_ts_prp_staffing_det WITH HEADER LINE, i_et_subject TYPE STANDARD TABLE OF bapi_ts_subobject WITH HEADER LINE, i_months_name TYPE STANDARD TABLE OF t247 WITH HEADER LINE, i_bapi_ts_name TYPE STANDARD TABLE OF bapi_ts_name WITH HEADER LINE, i_message TYPE STANDARD TABLE OF t_message WITH HEADER LINE. *----------------------------------------------------------------------* * WORKAREA DECLERATIONS * *----------------------------------------------------------------------* DATA : wa_0315 TYPE STANDARD TABLE OF t_cats_0315 WITH HEADER LINE, wa_bapi2075_2 TYPE bapi2075_2, wa_participant_guid TYPE bapi_ts_guid, wa_es_projectrole TYPE bapi_ts_prp_projectrole_det, wa_es_projectrole_pm TYPE bapi_ts_prp_projectrole_det, wa_task_guid TYPE bapi_ts_guid, wa_es_task_detail TYPE bapi_ts_task_detail, wa_generaldetail TYPE bapivendor_04, wa_bapi_ts_guid TYPE bapi_ts_guid, wa_bapi_ts_project_def_detail TYPE bapi_ts_project_def_detail, wa_bapi_ts_name TYPE STANDARD TABLE OF bapi_ts_name WITH HEADER LINE. *----------------------------------------------------------------------* * BATCH JOB DECLERATIONS * *----------------------------------------------------------------------* *----------------------------------------------------------------------* * TYPES DECLERATIONS * *----------------------------------------------------------------------* TYPES: t_document_data TYPE sodocchgi1, t_packing_list TYPE sopcklsti1, t_attachment TYPE solisti1, t_body_msg TYPE solisti1, t_receivers TYPE somlreci1. *----------------------------------------------------------------------* * INTERNALTABLE DECLERATIONS * *----------------------------------------------------------------------* DATA : i_document_data TYPE STANDARD TABLE OF t_document_data, i_packing_list TYPE STANDARD TABLE OF t_packing_list, i_attachment TYPE STANDARD TABLE OF t_attachment, i_body_msg TYPE STANDARD TABLE OF t_body_msg, i_receivers TYPE STANDARD TABLE OF t_receivers. *----------------------------------------------------------------------* * WORK AREA DECLERATIONS * *----------------------------------------------------------------------* DATA : w_document_data TYPE t_document_data, w_packing_list TYPE t_packing_list, w_attachment TYPE t_attachment, w_body_msg TYPE t_body_msg, w_receivers TYPE t_receivers. *----------------------------------------------------------------------* * DATA DECLERATIONS * *----------------------------------------------------------------------* DATA : v_work_effort(9) TYPE c, v_beg_tmstmp_eng TYPE sy-datum, v_end_tmstmp_eng TYPE sy-datum, v_beg_tmstmp_eng1(11) TYPE c, v_end_tmstmp_eng1(11) TYPE c, v_date(2) TYPE c, v_month(2) TYPE c, v_year(4) TYPE c, v_start_date TYPE sy-datum, v_end_date TYPE sy-datum, v_email(128) TYPE c, v_recp(128) TYPE c, g_sent_to_all TYPE sonv-flag, g_tab_lines TYPE i. *----------------------------------------------------------------------* * CLASS DECLERATIONS * *----------------------------------------------------------------------* CLASS cl_abap_char_utilities DEFINITION LOAD. *----------------------------------------------------------------------* * CONSTANT DECLERATIONS * *----------------------------------------------------------------------* CONSTANTS : con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab, con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf. CONSTANTS : c_gdd(6) TYPE c VALUE 'GDD590', c_gb2(6) TYPE c VALUE 'GB2590', c_gp1(6) TYPE c VALUE 'GP1590'. *----------------------------------------------------------------------* * RANGES DECLERATION * *----------------------------------------------------------------------* RANGES : r_date FOR sy-datum, r_bpnum FOR but000-partner. *----------------------------------------------------------------------* * ALV Data Declerations * *----------------------------------------------------------------------* DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE, gd_tab_group TYPE slis_t_sp_group_alv, gd_layout TYPE slis_layout_alv, gd_repid LIKE sy-repid, gt_events TYPE slis_t_event, gd_prntparams TYPE slis_print_alv, v_dest LIKE edipoa-logdes, v_handle LIKE sy-tabix, v_spool_id LIKE tsp01-rqident, v_rc TYPE c, v_errmessage(100) TYPE c, v_text(1000) TYPE c. *----------------------------------------------------------------------* * OLE DATA DECLERATION * *----------------------------------------------------------------------* TYPES: BEGIN OF t_catsw, mark TYPE catsmark, skostl TYPE skostl, lstar TYPE lstar, sebeln TYPE sebeln, "PO sebelp TYPE sebelp, "ITEM NUMBER sprznr TYPE sprznr, lstnr TYPE asnum, "ACTIVITY NUMBER rkostl TYPE ekostl, rproj TYPE num8, raufnr TYPE eaufnr, rnplnr TYPE nw_aufnr, raufpl TYPE co_aufpl, raplzl TYPE num8, rkdauf TYPE ekdau, rkdpos TYPE ekdpo, rkstr TYPE ekstr, rprznr TYPE eprznr, paobjnr TYPE rkeobjnr, sumdayw TYPE catswsum, day1 TYPE catshours, day2 TYPE catshours, day3 TYPE catshours, day4 TYPE catshours, day5 TYPE catshours, day6 TYPE catshours, day7 TYPE catshours, day8 TYPE catshours, day9 TYPE catshours, day10 TYPE catshours, day11 TYPE catshours, day12 TYPE catshours, day13 TYPE catshours, day14 TYPE catshours, day15 TYPE catshours, day16 TYPE catshours, day17 TYPE catshours, day18 TYPE catshours, day19 TYPE catshours, day20 TYPE catshours, day21 TYPE catshours, day22 TYPE catshours, day23 TYPE catshours, day24 TYPE catshours, day25 TYPE catshours, day26 TYPE catshours, day27 TYPE catshours, day28 TYPE catshours, day29 TYPE catshours, day30 TYPE catshours, day31 TYPE catshours, vornr TYPE vornr, uvorn TYPE uvorn, bedid TYPE num12, kapar TYPE kapart, arbpl TYPE arbpl, posid TYPE ps_posid, zcpr_guid TYPE char32, zcpr_extid TYPE char24, "TASK NAME zcpr_objguid TYPE char32, zcpr_objgextid TYPE char24, zcpr_objtype TYPE char3, zzcpr_guid TYPE char32, zzcpr_extid TYPE char24, "PROJECT ID zzcpr_objguid TYPE char32, zzcpr_objgextid TYPE char24, "TASK ID zzcpr_objtype TYPE char3, participant_role TYPE char15, "PARTICIPANT ROLE arbid TYPE objektid, werks TYPE werks_d, split TYPE cats_split, ltxa1 TYPE ltxa1, fstad TYPE dats, sstad TYPE dats, fendd TYPE dats, sendd TYPE dats, kbearest TYPE fltp_value, vertl TYPE cr_vertn, autyp TYPE auftyp, kalid TYPE wfcid, rproj_ext TYPE ps_posid, disptextw1 TYPE text40, disptextw2 TYPE text40, kper_single TYPE catsmark, kper_collect TYPE catsmark, END OF t_catsw. INCLUDE ole2incl. DATA: gs_excel TYPE ole2_object, gs_wbooklist TYPE ole2_object, gs_application TYPE ole2_object, gs_wbook TYPE ole2_object, gs_activesheet TYPE ole2_object, gs_sheets TYPE ole2_object, gs_newsheet TYPE ole2_object, gs_cell1 TYPE ole2_object, gs_cell2 TYPE ole2_object, gs_cells TYPE ole2_object, gs_range TYPE ole2_object, gs_font TYPE ole2_object, gs_interior TYPE ole2_object, gs_columns TYPE ole2_object, gs_autofit TYPE ole2_object, gs_table_border TYPE ole2_object, gs_table TYPE ole2_object, gs_save TYPE ole2_object, gs_wactbooklist TYPE ole2_object, gs_comment TYPE ole2_object, g_workbook TYPE ole2_object. DATA: gv_index(2) TYPE c, gv_outer_index LIKE sy-index, gv_sheet_name(26) TYPE c, gv_line_cntr TYPE i, gv_line_cntr_1 TYPE i, v_flag TYPE c VALUE '0'. DATA: i_etworklist TYPE STANDARD TABLE OF t_catsw WITH HEADER LINE. *----------------------------------------------------------------------* * EMAIL DATA DECLERATION * *----------------------------------------------------------------------* DATA : method1 LIKE sy-ucomm, g_user LIKE soudnamei1, g_user_data LIKE soudatai1, g_owner LIKE soud-usrnam, g_receipients LIKE soos1 OCCURS 0 WITH HEADER LINE, g_document LIKE sood4, g_header LIKE sood2, g_folmam LIKE sofm2, g_objcnt LIKE soli OCCURS 0 WITH HEADER LINE, g_objhead LIKE soli OCCURS 0 WITH HEADER LINE, g_objpara LIKE selc OCCURS 0 WITH HEADER LINE, g_objparb LIKE soop1 OCCURS 0 WITH HEADER LINE, g_attachments LIKE sood5 OCCURS 0 WITH HEADER LINE, g_references LIKE soxrl OCCURS 0 WITH HEADER LINE, g_authority LIKE sofa-usracc, g_ref_document LIKE sood4, g_new_parent LIKE soodk. DATA: BEGIN OF g_files OCCURS 10, text(4096) TYPE c, END OF g_files. DATA : fold_number(12) TYPE c, fold_yr(2) TYPE c, fold_type(3) TYPE c. DATA : ws_file TYPE string, "DEFAULT 'C:\Documents and Settings\rd76685\Desktop\test.xls'. ws_email(128) TYPE c, ws_pernr TYPE pernr_d, ws_proid TYPE project_id, ws_begdt(10) TYPE c, ws_enddt(10) TYPE c, w_pernr TYPE pernr_d, w_proid TYPE project_id, w_begdt(10) TYPE c, w_enddt(10) TYPE c, v_begday(2) TYPE c, v_begmnt(2) TYPE c, v_begyear(4) TYPE c, v_endday(2) TYPE c, v_endmnt(2) TYPE c, v_endyear(4) TYPE c, v_begday1(2) TYPE c, v_begmnt1(2) TYPE c, v_begyear1(4) TYPE c, v_endday1(2) TYPE c, v_endmnt1(2) TYPE c, v_endyear1(4) TYPE c, v_datebeg(11) TYPE c, v_datebeg1(10) TYPE c, v_dateend(11) TYPE c, v_dateend1(10) TYPE c, v_begindate(11) TYPE c, v_enddate1(11) TYPE c, v_month_name TYPE fcktx, v_temp_value TYPE dpr_tv_effort, v_status1 TYPE c VALUE '0', v_status2 TYPE c VALUE '0', v_tag1(3) TYPE c VALUE '<(>', v_tag2(3) TYPE c VALUE '<)>', v_ldescription(1000) TYPE c, v_beg_date1 TYPE sy-datum, v_end_date1 TYPE sy-datum. DATA : v_bpnumlow(8) TYPE c, v_bpnumhigh(8) TYPE c. *DATA : bdcdata TYPE STANDARD TABLE OF t_bdcdata WITH HEADER LINE. DATA : bdcdata TYPE STANDARD TABLE OF bdcdata WITH HEADER LINE. DATA : wa_bapibus1006_head TYPE bapibus1006_head, wa_bapiadsmtp TYPE STANDARD TABLE OF bapiadsmtp WITH HEADER LINE. DATA : v_businesspartner TYPE bu_partner. *----------------------------------------------------------------------* * S E L E C T I O N S C R E E N * *----------------------------------------------------------------------* * Selection Parameters/Select Options. SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. SELECT-OPTIONS : s_projid FOR dpr_project-project_id OBLIGATORY MATCHCODE OBJECT ygi_abr20663_projectid, s_bpnum FOR but000-partner. PARAMETERS: p_begdt LIKE sy-datum DEFAULT sy-datum, p_enddt LIKE sy-datum. PARAMETERS : p_trig TYPE xfeld, p_recp(125) TYPE c. SELECTION-SCREEN END OF BLOCK b1. *----------------------------------------------------------------------* * INITIALAZITION * *----------------------------------------------------------------------* INITIALIZATION. PERFORM f_initialaze_rfcdest. *----------------------------------------------------------------------* * AT SELECTION SCREEN * *----------------------------------------------------------------------* **Validating Selection Screen File Type AT SELECTION-SCREEN. IF s_projid[] IS INITIAL AND p_begdt IS INITIAL AND p_enddt IS NOT INITIAL. MESSAGE e000. ELSEIF s_projid[] IS INITIAL AND p_begdt IS NOT INITIAL AND p_enddt IS INITIAL. MESSAGE e001. ELSEIF NOT s_projid[] IS INITIAL AND p_begdt IS INITIAL AND p_enddt IS INITIAL. MESSAGE e003. ELSEIF NOT s_projid[] IS INITIAL AND p_begdt IS INITIAL AND p_enddt IS NOT INITIAL. MESSAGE e000. ELSEIF NOT s_projid[] IS INITIAL AND p_begdt IS NOT INITIAL AND p_enddt IS INITIAL. MESSAGE e001. ELSEIF NOT s_projid[] IS INITIAL AND p_enddt < p_begdt. MESSAGE e004. ELSEIF s_projid[] IS INITIAL AND p_enddt < p_begdt. MESSAGE e004. ELSEIF s_projid[] IS INITIAL AND p_begdt IS INITIAL AND p_enddt IS INITIAL. MESSAGE e003. ENDIF. *----------------------------------------------------------------------* * S T A R T O F S E L E C T I O N * *----------------------------------------------------------------------* START-OF-SELECTION. IF NOT s_bpnum[] IS INITIAL. LOOP AT s_bpnum. v_bpnumlow = s_bpnum-low+2(8). v_bpnumhigh = s_bpnum-high+2(8). r_bpnum-option = s_bpnum-option. r_bpnum-sign = s_bpnum-sign. r_bpnum-low = v_bpnumlow. r_bpnum-high = v_bpnumhigh. APPEND r_bpnum. CLEAR : r_bpnum, v_bpnumlow, v_bpnumhigh. ENDLOOP. ENDIF. r_date-option = 'BT'. r_date-sign = 'I'. r_date-low = p_begdt. r_date-high = p_enddt. APPEND r_date. CLEAR : r_date. CALL FUNCTION 'MONTH_NAMES_GET' EXPORTING language = sy-langu TABLES month_names = i_months_name EXCEPTIONS month_names_not_found = 1 OTHERS = 2. CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS' EXPORTING i_date_from = p_begdt i_date_to = p_enddt IMPORTING e_days = datediff. v_datediff = datediff. v_datediff = v_datediff + 1. SHIFT v_datediff LEFT DELETING LEADING space. IF v_datediff = '0'. v_datediff = 1. SHIFT v_datediff LEFT DELETING LEADING space. ENDIF. v_begdate = p_begdt. v_enddate = p_enddt. v_begyear = p_begdt+0(4). v_begmnt = p_begdt+4(2). v_begday = p_begdt+6(2). LOOP AT i_months_name WHERE mnr EQ v_begmnt. v_month_name = i_months_name-ktx. ENDLOOP. CONCATENATE v_begday v_month_name v_begyear INTO v_datebeg SEPARATED BY '-'. CONCATENATE v_begday v_begmnt v_begyear INTO v_datebeg1 SEPARATED BY '.'. v_endyear = p_enddt+0(4). v_endmnt = p_enddt+4(2). v_endday = p_enddt+6(2). LOOP AT i_months_name WHERE mnr EQ v_endmnt. v_month_name = i_months_name-ktx. ENDLOOP. CONCATENATE v_endday v_month_name v_endyear INTO v_dateend SEPARATED BY '-'. CONCATENATE v_endday v_endmnt v_endyear INTO v_dateend1 SEPARATED BY '.'. CONVERT DATE v_begdate INTO TIME STAMP v_beg_tmstmp TIME ZONE cl_cgpl_scheduling=>m_tzone. CONVERT DATE v_enddate INTO TIME STAMP v_end_tmstmp TIME ZONE cl_cgpl_scheduling=>m_tzone. PERFORM data_retrieval. PERFORM fetch_records. PERFORM filter_records. IF sy-batch NE 'X'. IF p_trig NE 'X' AND i_dpr_bupa_link_final1[] IS NOT INITIAL. PERFORM filter_output_display_alv. IF NOT i_dpr_bupa_link_final1[] IS INITIAL. PERFORM build_fieldcatalog. PERFORM build_layout. PERFORM display_alv_report. ENDIF. ELSEIF p_trig EQ 'X' AND p_recp IS INITIAL AND i_dpr_bupa_link_final1[] IS NOT INITIAL. PERFORM excel_sheet_application. ELSEIF p_trig EQ 'X' AND p_recp IS NOT INITIAL AND i_dpr_bupa_link_final1[] IS NOT INITIAL. PERFORM excel_sheet_mail_recipient USING p_recp. ENDIF. ELSE. PERFORM batch_process_email USING p_recp. ENDIF. CLEAR : v_begday, v_begmnt, v_begyear, v_endday, v_endmnt, v_endyear, v_datebeg, v_dateend, v_datediff, datediff, v_month_name, v_datebeg1, v_dateend1, v_begday1, v_begmnt1, v_begyear1, v_endday1, v_endmnt1, v_endyear1. REFRESH : i_months_name. IF i_dpr_bupa_link_final1[] IS INITIAL. MESSAGE ID 'YGF_ABR20640' TYPE 'I' NUMBER '005'. ENDIF. *&---------------------------------------------------------------------* *& Form DATA_RETRIEVAL *&---------------------------------------------------------------------* FORM data_retrieval . IF NOT s_projid[] IS INITIAL. "AND * p_begdt IS INITIAL AND * p_enddt IS INITIAL. SELECT guid project_id FROM dpr_project INTO CORRESPONDING FIELDS OF TABLE i_project_id WHERE project_id IN s_projid AND version_number EQ space. LOOP AT i_project_id. CALL FUNCTION 'DPR_GET_GUID_BY_ID_FROM_DB' EXPORTING iv_number = i_project_id-project_id iv_version_number = ' ' iv_object_type = 'DPO' IMPORTING et_guid = v_project_guid EXCEPTIONS no_rfc_authorization = 1 not_found = 2 invalid_object_type = 3 OTHERS = 4. IF sy-subrc = 0. READ TABLE v_project_guid INTO v_project_guid_s INDEX 1. SELECT * FROM cgpl_entity INTO CORRESPONDING FIELDS OF TABLE i_proj_guid WHERE project_guid EQ v_project_guid_s AND object_type EQ 'MTG'. IF sy-subrc = 0. IF NOT i_proj_guid[] IS INITIAL. SELECT * APPENDING CORRESPONDING FIELDS OF TABLE i_dpr_bupa_link FROM dpr_bupa_link FOR ALL ENTRIES IN i_proj_guid WHERE participant_guid EQ i_proj_guid-guid AND end_tmstmp >= v_beg_tmstmp AND beg_tmstmp <= v_end_tmstmp. * staff_action = 'CRTD' AND ENDIF. ENDIF. ENDIF. CLEAR : v_project_guid, v_project_guid_s, v_guid. REFRESH : i_proj_guid. ENDLOOP. ELSEIF s_projid[] IS INITIAL. "AND * p_begdt IS NOT INITIAL AND * p_enddt IS NOT INITIAL. SELECT * INTO CORRESPONDING FIELDS OF TABLE i_dpr_bupa_link FROM dpr_bupa_link WHERE end_tmstmp >= v_beg_tmstmp AND beg_tmstmp <= v_end_tmstmp. * staff_action = 'CRTD' AND * ELSEIF NOT s_projid[] IS INITIAL AND * ( p_begdt IS NOT INITIAL OR p_enddt IS NOT INITIAL ). * SELECT guid project_id * FROM dpr_project * INTO CORRESPONDING FIELDS OF TABLE i_project_id * WHERE project_id IN s_projid. * * LOOP AT i_project_id. * CALL FUNCTION 'DPR_GET_GUID_BY_ID_FROM_DB' * EXPORTING * iv_number = i_project_id-project_id * iv_version_number = ' ' * iv_object_type = 'DPO' * IMPORTING * et_guid = v_project_guid * EXCEPTIONS * no_rfc_authorization = 1 * not_found = 2 * invalid_object_type = 3 * OTHERS = 4. * IF sy-subrc = 0. * READ TABLE v_project_guid INTO v_project_guid_s INDEX 1. * SELECT * * FROM cgpl_entity * INTO CORRESPONDING FIELDS OF TABLE i_proj_guid * WHERE project_guid EQ v_project_guid_s AND * object_type EQ 'MTG'. * IF sy-subrc = 0. * IF NOT i_proj_guid[] IS INITIAL. * SELECT * * APPENDING CORRESPONDING FIELDS OF TABLE i_dpr_bupa_link * FROM dpr_bupa_link * FOR ALL ENTRIES IN i_proj_guid * WHERE participant_guid EQ i_proj_guid-guid AND * staff_action = 'CRTD'. * ENDIF. * ENDIF. * ENDIF. * CLEAR : v_project_guid, v_project_guid_s, v_guid. * REFRESH : i_proj_guid. * ENDLOOP. * ELSEIF s_projid[] IS INITIAL AND * p_begdt IS INITIAL AND * p_enddt IS INITIAL. * SELECT * * INTO CORRESPONDING FIELDS OF TABLE i_dpr_bupa_link * FROM dpr_bupa_link * WHERE staff_action = 'CRTD'. ENDIF. ENDFORM. " DATA_RETRIEVAL *&---------------------------------------------------------------------* *& Form FETCH_RECORS *&---------------------------------------------------------------------* FORM fetch_records . DATA : v_length(3) TYPE n. LOOP AT i_dpr_bupa_link. i_dpr_bupa_link_final-bupa_guid = i_dpr_bupa_link-bupa_guid. i_dpr_bupa_link_final-participant_guid = i_dpr_bupa_link-participant_guid. ** to get Personal Number(PERNR) for each BUPA_GUID CALL FUNCTION 'BP_CENTRALPERSON_GET' EXPORTING iv_bu_partner_guid = i_dpr_bupa_link-bupa_guid IMPORTING ev_person_id = v_pernr. i_dpr_bupa_link_final-pernr = v_pernr. DATA : v_name_last TYPE bu_namep_l, v_name_first TYPE bu_namep_f. SELECT SINGLE name_last name_first FROM but000 INTO (v_name_last , v_name_first) WHERE partner_guid = i_dpr_bupa_link-bupa_guid. i_dpr_bupa_link_final-name_first = v_name_first. i_dpr_bupa_link_final-name_last = v_name_last. **To Get LIFNR CALL FUNCTION 'CATS_GET_INFOTYPE_0315' DESTINATION v_dest EXPORTING pernr = v_pernr date = sy-datum IMPORTING i0315 = wa_0315 EXCEPTIONS pernr_not_found = 1 no_record = 2 no_authority = 3 OTHERS = 4. **For ICDR's only * IF sy-subrc NE 0. * CONTINUE. * ENDIF. **For ICDR's only i_dpr_bupa_link_final-lifnr = wa_0315-lifnr. i_dpr_bupa_link_final-pernr = v_pernr. CALL FUNCTION 'BAPI_VENDOR_GETDETAIL' DESTINATION v_dest EXPORTING vendorno = wa_0315-lifnr IMPORTING generaldetail = wa_generaldetail. i_dpr_bupa_link_final-name = wa_generaldetail-name. **Project Name SELECT SINGLE project_guid FROM cgpl_entity INTO v_project_guid_1 WHERE guid = i_dpr_bupa_link-participant_guid AND object_type EQ 'MTG'. SELECT SINGLE text1 FROM cgpl_text INTO v_text1 WHERE guid = v_project_guid_1. i_dpr_bupa_link_final-text1 = v_text1. **Purchase Order Details wa_participant_guid-role_guid = i_dpr_bupa_link-participant_guid. CALL FUNCTION 'BAPI_BUS2177_GET_DETAIL' EXPORTING projectrole_guid = wa_participant_guid-role_guid IMPORTING es_projectrole = wa_es_projectrole. **To get PM Name CALL FUNCTION 'BAPI_BUS2172_GET_SUBOBJECTS' EXPORTING project_definition_guid = wa_es_projectrole-project_guid TABLES et_subobject = i_et_subject. LOOP AT i_et_subject WHERE object_type EQ 'MTG'. CALL FUNCTION 'BAPI_BUS2177_GET_DETAIL' EXPORTING projectrole_guid = i_et_subject-guid IMPORTING es_projectrole = wa_es_projectrole_pm TABLES et_staffing = i_et_staffing. IF wa_es_projectrole_pm-role_type = 'DSRB-PM'. READ TABLE i_et_staffing INDEX 1. IF sy-subrc = 0. SELECT SINGLE name_first name_last FROM but000 INTO (v_name_first_pm, v_name_last_pm) WHERE partner_guid = i_et_staffing-partner_guid. IF sy-subrc = 0. CONCATENATE v_name_first_pm v_name_last_pm INTO v_name_pm SEPARATED BY space. i_dpr_bupa_link_final-name_pm = v_name_pm. CLEAR : v_name_first_pm, v_name_last_pm, v_name_pm. ENDIF. ENDIF. ENDIF. REFRESH : i_et_staffing. CLEAR : wa_es_projectrole_pm. ENDLOOP. REFRESH : i_et_subject. SELECT * FROM dpr_objlink INTO CORRESPONDING FIELDS OF TABLE i_objlink WHERE task_guid = wa_es_projectrole-role_guid AND object_type = '0PURCHORDITEM'. IF sy-subrc = 0. LOOP AT i_objlink. WRITE i_objlink-description TO v_ldescription NO-GAP. CONCATENATE v_ltext i_objlink-object_key+0(10) '/' '(' v_ldescription ')' ',' INTO v_ltext. CONCATENATE v_ltext '/' INTO v_ltext. CLEAR : v_ldescription. ENDLOOP. TRANSLATE v_ltext USING '/ '. SEARCH v_ltext FOR ','. IF sy-subrc = 0. v_length = strlen( v_ltext ). v_length = v_length - 1. v_ltext = v_ltext+0(v_length). ENDIF. * v_ltext = v_ltext+1(131). i_dpr_bupa_link_final-object_key = v_ltext. CLEAR : v_ltext, v_ldescription. ENDIF. CLEAR : wa_participant_guid, wa_es_projectrole, v_length. **Internal Order Number SELECT SINGLE project_guid FROM cgpl_entity INTO v_project_guid_1 WHERE guid = i_dpr_bupa_link-participant_guid AND object_type EQ 'MTG'. CALL FUNCTION 'DPR_GET_ID_BY_GUID_FROM_DB' EXPORTING iv_guid = v_project_guid_1 IMPORTING ev_number = v_number EXCEPTIONS no_rfc_authorization = 1 not_found = 2 invalid_object_type = 3 OTHERS = 4. i_dpr_bupa_link_final-project_id = v_number. **Role Type Text / Role Description wa_participant_guid-role_guid = i_dpr_bupa_link-participant_guid. CALL FUNCTION 'BAPI_BUS2177_GET_DETAIL' EXPORTING projectrole_guid = wa_participant_guid-role_guid IMPORTING es_projectrole = wa_es_projectrole TABLES et_description = i_et_description. IF sy-subrc = 0. CLEAR : v_name. LOOP AT i_et_description. CONCATENATE v_ltext i_et_description-description_line INTO v_ltext SEPARATED BY ','. REPLACE ALL OCCURRENCES OF v_tag1 IN v_ltext WITH ' '. REPLACE ALL OCCURRENCES OF v_tag2 IN v_ltext WITH ' '. ENDLOOP. v_ltext = v_ltext+1(999). i_dpr_bupa_link_final-task_desc = v_ltext. CLEAR : v_ltext. i_dpr_bupa_link_final-role_text = wa_es_projectrole-role_type_text. ENDIF. CLEAR : wa_participant_guid, wa_es_projectrole. **Project Dates wa_bapi_ts_guid-project_definition_guid = v_project_guid_1. CALL FUNCTION 'BAPI_BUS2172_GET_DETAIL' EXPORTING project_definition_guid = wa_bapi_ts_guid-project_definition_guid IMPORTING es_project_definition_detail = wa_bapi_ts_project_def_detail TABLES et_name = i_bapi_ts_name et_description = i_bapi_ts_description. IF sy-subrc = 0. CLEAR : v_ltext. LOOP AT i_bapi_ts_description. CONCATENATE v_ltext i_bapi_ts_description-description_line INTO v_ltext SEPARATED BY ','. REPLACE ALL OCCURRENCES OF v_tag1 IN v_ltext WITH ' '. REPLACE ALL OCCURRENCES OF v_tag2 IN v_ltext WITH ' '. ENDLOOP. v_ltext = v_ltext+1(999). i_dpr_bupa_link_final-proj_desc = v_ltext. CLEAR : v_ltext. ENDIF. LOOP AT i_bapi_ts_name WHERE language = 'EN'. i_dpr_bupa_link_final-proj_name = i_bapi_ts_name-name. ENDLOOP. i_dpr_bupa_link_final-actualstart = wa_bapi_ts_project_def_detail-fixed_start_date. i_dpr_bupa_link_final-actualfinish = wa_bapi_ts_project_def_detail-fixed_finish_date. **Task Type SELECT * FROM dpr_entity_link APPENDING CORRESPONDING FIELDS OF TABLE i_taskassignment WHERE participant_guid EQ i_dpr_bupa_link-participant_guid AND entity_type EQ 'TTO' AND responsible NE 'X'. APPEND : i_dpr_bupa_link_final. CLEAR : v_pernr, wa_0315, v_project_guid, v_number, wa_bapi2075_2, v_text1, v_participant_role,v_guid_x16, v_guid_c32, v_role_text, v_name, v_location, v_location_text, wa_participant_guid, i_dpr_bupa_link_final, v_role_guid, wa_es_projectrole, wa_generaldetail, wa_bapi_ts_project_def_detail, wa_bapi_ts_guid, v_project_guid_1. REFRESH : i_tline, i_objlink, i_et_description, i_bapi_ts_name. ENDLOOP. LOOP AT i_taskassignment. wa_task_guid-task_guid = i_taskassignment-entity_guid. i_bapi_task_desc-language = 'EN'. APPEND i_bapi_task_desc. CALL FUNCTION 'BAPI_BUS2175_GET_DETAIL' EXPORTING task_guid = wa_task_guid-task_guid IMPORTING es_task_detail = wa_es_task_detail TABLES et_name = wa_bapi_ts_name et_description = i_bapi_task_desc. i_taskdetail-participant_guid = i_taskassignment-participant_guid. i_taskdetail-entity_guid = i_taskassignment-entity_guid. i_taskdetail-task_type = wa_es_task_detail-task_type. i_taskdetail-task_type_text = wa_es_task_detail-task_type_text. i_taskdetail-task_number = wa_es_task_detail-task_number. READ TABLE wa_bapi_ts_name INDEX 1. IF sy-subrc = 0. i_taskdetail-task_name = wa_bapi_ts_name-name. ENDIF. READ TABLE i_bapi_task_desc INDEX 1. IF sy-subrc EQ 0. CLEAR : v_ltext. v_ltext = i_bapi_task_desc-description_line. REPLACE ALL OCCURRENCES OF v_tag1 IN v_ltext WITH ' '. REPLACE ALL OCCURRENCES OF v_tag2 IN v_ltext WITH ' '. i_taskdetail-task_desc = v_ltext. "i_bapi_task_desc-description_line. ENDIF. APPEND : i_taskdetail. CLEAR : i_taskdetail, wa_es_task_detail, wa_task_guid, wa_bapi_ts_name, v_ltext. ENDLOOP. ENDFORM. " FETCH_RECORdS *&---------------------------------------------------------------------* *& Form FILTER_RECORDS *&---------------------------------------------------------------------* FORM filter_records . DATA : v_beg_date TYPE sy-datum, v_end_date TYPE sy-datum, v_beg_timestamp TYPE timestamp, v_end_timestamp TYPE timestamp, v_effortvalue(11) TYPE c, v_effortvalue1(4) TYPE n, v_length(4) TYPE c. LOOP AT i_taskassignment. v_beg_timestamp = i_taskassignment-beg_tmstmp. v_end_timestamp = i_taskassignment-end_tmstmp. READ TABLE i_dpr_bupa_link_final WITH KEY participant_guid = i_taskassignment-participant_guid. IF sy-subrc = 0. MOVE-CORRESPONDING i_dpr_bupa_link_final TO i_dpr_bupa_link_final1. CONVERT TIME STAMP v_beg_timestamp TIME ZONE cl_cgpl_scheduling=>m_tzone INTO DATE v_beg_date. CONVERT TIME STAMP v_end_timestamp TIME ZONE cl_cgpl_scheduling=>m_tzone INTO DATE v_end_date. i_dpr_bupa_link_final1-work_effort = i_taskassignment-work_effort. i_dpr_bupa_link_final1-work_unit = i_taskassignment-work_unit. i_dpr_bupa_link_final1-beg_tmstmp_eng = v_beg_date. "I_taskassignment-beg_tmstmp. i_dpr_bupa_link_final1-end_tmstmp_eng = v_end_date. "I_taskassignment-end_tmstmp. **For Checking the work effort days with the **Task Start/End Dates with Report Start /End Dates **For Validating the dates by comparing **Dates selection with Task Start Dates and Task End Dates v_temp_value = i_taskassignment-work_effort. IF i_dpr_bupa_link_final1-beg_tmstmp_eng > p_begdt. IF i_dpr_bupa_link_final1-beg_tmstmp_eng > p_enddt. CONTINUE. ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng > p_enddt. v_days_total = p_enddt - i_dpr_bupa_link_final1-beg_tmstmp_eng. v_days_total = v_days_total + 1 . IF v_days_total EQ '0.00'. v_days_total = '1.00'. ENDIF. IF v_temp_value LE v_days_total. i_dpr_bupa_link_final1-days_total = v_temp_value. ELSE. i_dpr_bupa_link_final1-days_total = v_days_total. ENDIF. i_dpr_bupa_link_final1-flag = 'X'. ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng < p_enddt. v_days_total = i_dpr_bupa_link_final1-end_tmstmp_eng - i_dpr_bupa_link_final1-beg_tmstmp_eng. v_days_total = v_days_total + 1 . IF v_days_total EQ '0.00'. v_days_total = '1.00'. ENDIF. IF v_temp_value LE v_days_total. i_dpr_bupa_link_final1-days_total = v_temp_value. ELSE. i_dpr_bupa_link_final1-days_total = v_days_total. ENDIF. i_dpr_bupa_link_final1-flag = 'X'. ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng = p_enddt. v_days_total = i_dpr_bupa_link_final1-end_tmstmp_eng - i_dpr_bupa_link_final1-beg_tmstmp_eng. v_days_total = v_days_total + 1 . IF v_days_total EQ '0.00'. v_days_total = '1.00'. ENDIF. IF v_temp_value LE v_days_total. i_dpr_bupa_link_final1-days_total = v_temp_value. ELSE. i_dpr_bupa_link_final1-days_total = v_days_total. ENDIF. i_dpr_bupa_link_final1-flag = 'X'. ENDIF. ELSEIF i_dpr_bupa_link_final1-beg_tmstmp_eng < p_begdt. IF i_dpr_bupa_link_final1-end_tmstmp_eng < p_begdt. CONTINUE. ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng > p_enddt. v_days_total = p_enddt - p_begdt. v_days_total = v_days_total + 1 . IF v_days_total EQ '0.00'. v_days_total = '1.00'. ENDIF. IF v_temp_value LE v_days_total. i_dpr_bupa_link_final1-days_total = v_temp_value. ELSE. i_dpr_bupa_link_final1-days_total = v_days_total. ENDIF. i_dpr_bupa_link_final1-flag = 'X'. ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng < p_enddt. v_days_total = i_dpr_bupa_link_final1-end_tmstmp_eng - p_begdt. v_days_total = v_days_total + 1 . IF v_days_total EQ '0.00'. v_days_total = '1.00'. ENDIF. IF v_temp_value LE v_days_total. i_dpr_bupa_link_final1-days_total = v_temp_value. ELSE. i_dpr_bupa_link_final1-days_total = v_days_total. ENDIF. i_dpr_bupa_link_final1-flag = 'X'. ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng = p_enddt. v_days_total = p_enddt - p_begdt. v_days_total = v_days_total + 1 . IF v_days_total EQ '0.00'. v_days_total = '1.00'. ENDIF. IF v_temp_value LE v_days_total. i_dpr_bupa_link_final1-days_total = v_temp_value. ELSE. i_dpr_bupa_link_final1-days_total = v_days_total. ENDIF. i_dpr_bupa_link_final1-flag = 'X'. ENDIF. ELSEIF i_dpr_bupa_link_final1-beg_tmstmp_eng = p_begdt. IF i_dpr_bupa_link_final1-end_tmstmp_eng > p_enddt. v_days_total = p_enddt - i_dpr_bupa_link_final1-beg_tmstmp_eng. v_days_total = v_days_total + 1 . IF v_days_total EQ '0.00'. v_days_total = '1.00'. ENDIF. IF v_temp_value LE v_days_total. i_dpr_bupa_link_final1-days_total = v_temp_value. ELSE. i_dpr_bupa_link_final1-days_total = v_days_total. ENDIF. i_dpr_bupa_link_final1-flag = 'X'. ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng < p_enddt. v_days_total = i_dpr_bupa_link_final1-end_tmstmp_eng - i_dpr_bupa_link_final1-beg_tmstmp_eng. v_days_total = v_days_total + 1 . IF v_days_total EQ '0.00'. v_days_total = '1.00'. ENDIF. IF v_temp_value LE v_days_total. i_dpr_bupa_link_final1-days_total = v_temp_value. ELSE. i_dpr_bupa_link_final1-days_total = v_days_total. ENDIF. i_dpr_bupa_link_final1-flag = 'X'. ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng = p_enddt. v_days_total = p_enddt - p_begdt. v_days_total = v_days_total + 1 . IF v_days_total EQ '0.00'. v_days_total = '1.00'. ENDIF. IF v_temp_value LE v_days_total. i_dpr_bupa_link_final1-days_total = v_temp_value. ELSE. i_dpr_bupa_link_final1-days_total = v_days_total. ENDIF. i_dpr_bupa_link_final1-flag = 'X'. ENDIF. ENDIF. READ TABLE i_taskdetail WITH KEY participant_guid = i_taskassignment-participant_guid entity_guid = i_taskassignment-entity_guid. IF sy-subrc = 0. i_dpr_bupa_link_final1-task_type = i_taskdetail-task_type_text. i_dpr_bupa_link_final1-task_name = i_taskdetail-task_name. i_dpr_bupa_link_final1-task_number = i_taskdetail-task_number. i_dpr_bupa_link_final1-task_desc = i_taskdetail-task_desc. ENDIF. APPEND i_dpr_bupa_link_final1. CLEAR : i_dpr_bupa_link_final1. ELSE. MOVE-CORRESPONDING i_dpr_bupa_link_final TO i_dpr_bupa_link_final1. APPEND i_dpr_bupa_link_final1. CLEAR : i_dpr_bupa_link_final1, v_beg_date, v_end_date, v_beg_timestamp, v_end_timestamp. ENDIF. CLEAR : v_beg_date, v_end_date, v_beg_timestamp, v_end_timestamp. CLEAR : v_temp_value, v_days_total. ENDLOOP. CLEAR : i_dpr_bupa_link_final1. SORT i_dpr_bupa_link_final1 BY pernr. IF NOT r_bpnum[] IS INITIAL. LOOP AT i_dpr_bupa_link_final1. IF i_dpr_bupa_link_final1-pernr IN r_bpnum. CONTINUE. ELSE. DELETE i_dpr_bupa_link_final1 INDEX sy-tabix. ENDIF. ENDLOOP. CLEAR : i_dpr_bupa_link_final1. ENDIF. ENDFORM. " FILTER_RECORDS *&---------------------------------------------------------------------* *& Form BUILD_FIELDCATALOG *&---------------------------------------------------------------------* FORM build_fieldcatalog . fieldcatalog-fieldname = 'DUMMY'. fieldcatalog-col_pos = 1. fieldcatalog-edit = 'X'. fieldcatalog-no_out = 'X'. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'NAME_FIRST'. fieldcatalog-seltext_m = 'First Name'. fieldcatalog-col_pos = 2. fieldcatalog-emphasize = 'X'. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'NAME_LAST'. fieldcatalog-seltext_m = 'Last Name'. fieldcatalog-col_pos = 3. fieldcatalog-emphasize = 'X'. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'LIFNR'. fieldcatalog-seltext_m = 'Vendor Number'. fieldcatalog-col_pos = 4. fieldcatalog-emphasize = 'X'. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'OBJECT_KEY'. fieldcatalog-seltext_m = 'Purchase Order'. fieldcatalog-col_pos = 5. fieldcatalog-emphasize = 'X'. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'TEXT1'. fieldcatalog-seltext_m = 'Project Name'. fieldcatalog-col_pos = 6. fieldcatalog-emphasize = 'X'. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'WORK_EFFORT'. fieldcatalog-seltext_m = 'Task Work Effort'. fieldcatalog-col_pos = 7. fieldcatalog-emphasize = 'X'. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'WORK_UNIT'. fieldcatalog-seltext_m = 'Task Work Unit'. fieldcatalog-col_pos = 8. fieldcatalog-emphasize = 'X'. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'BEG_TMSTMP_ENG'. fieldcatalog-seltext_m = 'Task Begin Date'. fieldcatalog-col_pos = 9. fieldcatalog-emphasize = 'X'. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'END_TMSTMP_ENG'. fieldcatalog-seltext_m = 'Task End Date'. fieldcatalog-col_pos = 10. fieldcatalog-emphasize = 'X'. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'PROJECT_ID'. fieldcatalog-seltext_m = 'Internal Order'. fieldcatalog-col_pos = 11. fieldcatalog-emphasize = 'X'. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'ACTUALSTART'. fieldcatalog-seltext_l = 'Project Actual Start Date'. fieldcatalog-col_pos = 12. fieldcatalog-emphasize = 'X'. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'ACTUALFINISH'. fieldcatalog-seltext_l = 'Project Actual Finish Date'. fieldcatalog-col_pos = 13. fieldcatalog-emphasize = 'X'. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. ENDFORM. " BUILD_FIELDCATALOG *&---------------------------------------------------------------------* *& Form BUILD_LAYOUT *&---------------------------------------------------------------------* FORM build_layout . gd_layout-no_input = 'X'. gd_layout-colwidth_optimize = 'X'. gd_layout-zebra = 'X'. gd_layout-header_text = 'DETAIL ACTIVITY REPORT'. ENDFORM. " BUILD_LAYOUT *&---------------------------------------------------------------------* *& Form DISPLAY_ALV_REPORT *&---------------------------------------------------------------------* FORM display_alv_report . CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = sy-repid is_layout = gd_layout it_fieldcat = fieldcatalog[] i_save = 'X' TABLES t_outtab = i_dpr_bupa_link_final1 EXCEPTIONS program_error = 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. ENDFORM. " DISPLAY_ALV_REPORT *&---------------------------------------------------------------------* *& Form EXCEL_SHEET_APPLICATION *&---------------------------------------------------------------------* FORM excel_sheet_application . DATA : v_name TYPE char80, v_participant_guid TYPE dpr_tv_participant_guid, v_index TYPE sy-tabix, v_times TYPE i, v_effortvalue(11) TYPE c, v_effortvalue1(4) TYPE n, v_pernr_old TYPE personid, v_pernr_new TYPE personid, v_length(4) TYPE c. DATA : return(255) TYPE c, return1(128) TYPE c, type TYPE i, return_file TYPE string, v_email(128) TYPE c. DATA : p_file TYPE localfile. **TO DETERMINE THE CURRENT USERNAME DESKTOP **PATH FOR CREATING FOLDER IN HIS SYSTEM. LOOP AT i_dpr_bupa_link_final1. v_pernr = i_dpr_bupa_link_final1-pernr. CONCATENATE 'E0' v_pernr INTO v_businesspartner. SELECT SINGLE bpkind FROM but000 INTO v_bpkind WHERE partner = v_businesspartner. CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1. IF NOT v_bpkind IS INITIAL. i_dpr_bupa_link_final1-bpkind = v_bpkind1. MODIFY i_dpr_bupa_link_final1 INDEX sy-tabix TRANSPORTING bpkind. ELSE. DELETE i_dpr_bupa_link_final1 INDEX sy-tabix. ENDIF. CLEAR : v_bpkind, v_bpkind1, v_businesspartner, v_pernr. ENDLOOP. i_dpr_bupa_link_final2[] = i_dpr_bupa_link_final1[]. SORT i_dpr_bupa_link_final2 BY participant_guid. DELETE ADJACENT DUPLICATES FROM i_dpr_bupa_link_final2 COMPARING participant_guid. type = '00000000012'. CALL FUNCTION 'GUI_GET_DESKTOP_INFO' EXPORTING type = type CHANGING return = return. CONCATENATE return '\DAR_' sy-datum '_' sy-uzeit INTO return. return1 = return. CALL FUNCTION 'GUI_CREATE_DIRECTORY' EXPORTING dirname = return1 EXCEPTIONS failed = 1 OTHERS = 2. return = return1. LOOP AT i_dpr_bupa_link_final2. v_skipflag = 0. v_index = sy-tabix. v_pernr = i_dpr_bupa_link_final2-pernr. v_participant_guid = i_dpr_bupa_link_final2-participant_guid. v_int_order = i_dpr_bupa_link_final2-project_id. v_bpkind2 = i_dpr_bupa_link_final2-bpkind. *--Forming sheet name gv_index = sy-index . gv_outer_index = sy-index . gv_sheet_name = 'Detail Activity Report'. ***For email checking for individual PERNR CONCATENATE 'E0' v_pernr INTO v_businesspartner. wa_bapibus1006_head-bpartner = v_businesspartner. REFRESH : wa_bapiadsmtp. CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL' EXPORTING businesspartner = wa_bapibus1006_head-bpartner valid_date = sy-datum TABLES bapiadsmtp = wa_bapiadsmtp. IF wa_bapiadsmtp[] IS INITIAL. v_skipflag = 1. ELSE. REFRESH : wa_bapiadsmtp. ENDIF. LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid. IF * i_dpr_bupa_link_final1-lifnr IS INITIAL OR * i_dpr_bupa_link_final1-name IS INITIAL OR i_dpr_bupa_link_final1-pernr IS INITIAL OR i_dpr_bupa_link_final1-project_id IS INITIAL OR i_dpr_bupa_link_final1-proj_name IS INITIAL OR i_dpr_bupa_link_final1-name_pm IS INITIAL OR * i_dpr_bupa_link_final1-object_key IS INITIAL OR i_dpr_bupa_link_final1-proj_desc IS INITIAL. v_skipflag = 1. ENDIF. CONCATENATE i_dpr_bupa_link_final1-name_first i_dpr_bupa_link_final1-name_last INTO v_name SEPARATED BY space. IF v_name IS INITIAL. v_skipflag = 1. ENDIF. IF i_dpr_bupa_link_final1-object_key IS INITIAL AND i_dpr_bupa_link_final1-bpkind EQ 'DSR_ICDR'. v_skipflag = 1. ENDIF. IF i_dpr_bupa_link_final1-task_name IS INITIAL OR i_dpr_bupa_link_final1-task_desc IS INITIAL OR i_dpr_bupa_link_final1-task_type IS INITIAL OR i_dpr_bupa_link_final1-role_text IS INITIAL OR i_dpr_bupa_link_final1-beg_tmstmp_eng IS INITIAL OR i_dpr_bupa_link_final1-end_tmstmp_eng IS INITIAL OR i_dpr_bupa_link_final1-work_effort IS INITIAL. v_skipflag = 1. ENDIF. CLEAR : v_name. ENDLOOP. CONCATENATE 'E0' v_pernr INTO v_businesspartner. SELECT SINGLE bpkind FROM but000 INTO v_bpkind WHERE partner = v_businesspartner. CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1. IF NOT v_bpkind IS INITIAL. CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest EXPORTING sap_variant = v_bpkind1 sap_pernr = v_pernr beg_date = p_begdt end_date = p_enddt TABLES sap_icatsw = i_etworklist. ENDIF. DELETE i_etworklist WHERE zzcpr_extid NE v_int_order. CLEAR : v_bpkind, v_bpkind1. IF i_etworklist[] IS INITIAL. v_skipflag = 1. ENDIF. IF v_skipflag = 0. *--For the first loop, Excel is initiated and one new sheet is added CREATE OBJECT gs_excel 'EXCEL.APPLICATION' . GET PROPERTY OF gs_excel 'Visible' = v_vis. * Set this property to open excel in background SET PROPERTY OF gs_excel 'Visible' = 'False' . GET PROPERTY OF gs_excel 'Workbooks' = gs_wbooklist . GET PROPERTY OF gs_wbooklist 'Application' = gs_application . SET PROPERTY OF gs_application 'SheetsInNewWorkbook' = 1 . CALL METHOD OF gs_wbooklist 'Add' = gs_wbook. GET PROPERTY OF gs_application 'ActiveSheet' = gs_activesheet . GET PROPERTY OF gs_excel 'ActiveWorkbook' = g_workbook. SET PROPERTY OF gs_activesheet 'Name' = gv_sheet_name . GET PROPERTY OF gs_activesheet 'Cells' = gs_cells. GET PROPERTY OF gs_cells 'Font' = gs_font . SET PROPERTY OF gs_font 'Name' = 'Arial' . SET PROPERTY OF gs_font 'Size' = '10' . gv_line_cntr = 1 . "line counter *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = 1 #2 = 1. CALL METHOD OF gs_excel 'Cells' = gs_cell2 EXPORTING #1 = 1 #2 = 15. CALL METHOD OF gs_excel 'Range' = gs_cells EXPORTING #1 = gs_cell1 #2 = gs_cell2. CALL METHOD OF gs_cells 'Select'. *--Merging CALL METHOD OF gs_cells 'Merge'. *--Setting title data CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. SET PROPERTY OF gs_cells 'Value' = 'DETAIL ACTIVITY REPORT' . *--Formatting the title GET PROPERTY OF gs_cells 'Font' = gs_font . SET PROPERTY OF gs_font 'Name' = 'Arial' . SET PROPERTY OF gs_font 'Size' = '12' . SET PROPERTY OF gs_font 'Underline' = 2 . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cells 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cells 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cells 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick SET PROPERTY OF gs_cells 'Locked' = 1. gv_line_cntr = gv_line_cntr + 2 . LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid. ON CHANGE OF i_dpr_bupa_link_final1-participant_guid. PERFORM header_data_display. PERFORM line_title_display. w_proid = i_dpr_bupa_link_final1-project_id. v_flag = 1. ENDON. IF v_flag = 1. v_flag = 0. CONTINUE. ENDIF. PERFORM line_item_display. ENDLOOP. **Code Closed by LZ16662 **FOR DISPLAYING CATSWORKLIST DETAILS **IN EXCEL SHEET **CONSTANTS VALUE FOR ACTIVITY NUMBER BASED ON SYSTEM * CONCATENATE 'E0' v_pernr INTO v_businesspartner. * SELECT SINGLE bpkind * FROM but000 * INTO v_bpkind * WHERE partner = v_businesspartner. * CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1. * IF NOT v_bpkind IS INITIAL. * CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest * EXPORTING * sap_variant = v_bpkind1 * sap_pernr = v_pernr * beg_date = p_begdt * end_date = p_enddt * TABLES * sap_icatsw = i_etworklist. * ENDIF. * DELETE i_etworklist WHERE zzcpr_extid NE v_int_order. * CLEAR : v_int_order, v_bpkind. **Code Closed by LZ16662 gv_line_cntr = gv_line_cntr_1. gv_line_cntr = gv_line_cntr + 2 . **FOR DISPLAYING COLOMN NAMES FOR CATSWORKLIST PERFORM cats_header_data. **FOR DISPLAYING LINE ITEM DETAILS FOR CATSWORKLIST LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid AND flag EQ 'X'. * v_times = i_dpr_bupa_link_final1-days_total. v_temp_value = i_dpr_bupa_link_final1-days_total. "work_effort. v_temp_value = ceil( v_temp_value ). v_effortvalue = v_temp_value. v_length = strlen( v_effortvalue ). v_length = v_length - 3. v_effortvalue = v_effortvalue+0(v_length). SHIFT v_effortvalue LEFT DELETING LEADING space. MOVE v_effortvalue TO v_effortvalue1. IF v_effortvalue1 LE v_datediff. v_times = v_effortvalue1. ELSEIF v_effortvalue1 GT v_datediff. v_times = v_datediff. ENDIF. READ TABLE i_etworklist WITH KEY zzcpr_objgextid = i_dpr_bupa_link_final1-task_number. IF sy-subrc = 0. DO v_times TIMES. gv_line_cntr = gv_line_cntr + 1. PERFORM cats_line_data. ENDDO. ENDIF. CLEAR : v_effortvalue, v_length, v_times, v_effortvalue1, v_temp_value. ENDLOOP. CLEAR : v_bpkind2. PERFORM note_condition. * LOOP AT i_etworklist WHERE sebeln NE space. * gv_line_cntr = gv_line_cntr + 1. * PERFORM cats_line_data. * ENDLOOP. * SET PROPERTY OF gs_activesheet 'PROTECT' = 1. CALL METHOD OF gs_activesheet 'PROTECT' EXPORTING #1 = 'dsr123##$'. CALL METHOD OF g_workbook 'PROTECT' EXPORTING #1 = 'dsr123##$'. REFRESH : i_etworklist. * SET PROPERTY OF gs_activesheet 'PROTECT' = 1. "Protect sheet **TO STORE THE EXCEL FILE FOR DIFFERENT PERSONNEL NUMBER **TO STORE THE SAME IN CREATED DIRECTORY * CONCATENATE i_dpr_bupa_link_final2-name_first i_dpr_bupa_link_final2-name_last INTO v_save_name SEPARATED BY space. CONCATENATE i_dpr_bupa_link_final2-role_text '-' INTO v_save_name. return_file = return. CONCATENATE return '\' i_dpr_bupa_link_final2-project_id '' v_pernr '' v_save_name sy-datum '-' sy-uzeit '.xls' INTO return_file. CALL METHOD OF gs_wbook 'SaveAs' EXPORTING #1 = return_file. * SET PROPERTY OF gs_excel 'DisplayAlerts' = 0. PERFORM free_objects. CONCATENATE 'E0' v_pernr INTO v_businesspartner. wa_bapibus1006_head-bpartner = v_businesspartner. CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL' EXPORTING businesspartner = wa_bapibus1006_head-bpartner valid_date = sy-datum TABLES bapiadsmtp = wa_bapiadsmtp. IF NOT wa_bapiadsmtp[] IS INITIAL. READ TABLE wa_bapiadsmtp INDEX 1. IF sy-subrc = 0. v_email = wa_bapiadsmtp-e_mail. w_pernr = v_pernr. w_begdt = v_datebeg1. w_enddt = v_dateend1. **EMAILING AN ATTACHMENT TO SAPUSER INBOX PERFORM emailing_document USING return_file v_email w_pernr w_proid w_begdt w_enddt. i_output-bpartner = v_businesspartner. i_output-mail = v_email. i_output-status = 'Sucessfully Mailed the Document'. APPEND i_output. CLEAR : i_output. v_sucess = v_sucess + 1. ELSE. i_output-bpartner = v_businesspartner. i_output-status = 'Email Address not Maintained'. APPEND i_output. CLEAR : i_output. v_failure = v_failure + 1. ENDIF. ENDIF. ENDIF. CLEAR : v_participant_guid, v_pernr, return_file, v_businesspartner, wa_bapiadsmtp, wa_bapibus1006_head, v_email, w_proid, w_pernr, w_begdt, w_enddt, ws_pernr, ws_proid, ws_begdt, ws_enddt, v_times, v_save_name, return1. REFRESH : i_etworklist. ENDLOOP. LOOP AT i_output WHERE mail NE space. v_status1 = 1. ENDLOOP. LOOP AT i_output WHERE mail EQ space. v_status2 = 1. ENDLOOP. IF v_status1 = 1. WRITE : / 'Date :', sy-datum. WRITE : / 'Time :', sy-uzeit. WRITE : / 'Result :', v_sucess , 'Record''s mailed sucessfully'. WRITE : / sy-uline. WRITE : / sy-vline , AT 2 'BUSINESS PARTNER' CENTERED INTENSIFIED COLOR 4, AT 20 sy-vline, AT 30 'EMAIL-ID' CENTERED INTENSIFIED COLOR 4 , AT 125 sy-vline, AT 126 'STATUS' CENTERED INTENSIFIED COLOR 4, AT 179 sy-vline. WRITE : / sy-uline. LOOP AT i_output WHERE mail NE space. WRITE : / sy-vline, i_output-bpartner CENTERED INTENSIFIED COLOR 2, AT 20 sy-vline, AT 21 i_output-mail LEFT-JUSTIFIED INTENSIFIED COLOR 2, AT 125 sy-vline, AT 126 i_output-status LEFT-JUSTIFIED INTENSIFIED COLOR 5, AT 179 sy-vline. WRITE : / sy-uline. ENDLOOP. ENDIF. IF v_status2 = 1. WRITE : / 'Result :', v_failure , 'Record''s mailed unsucessfully'. WRITE : / sy-uline. WRITE : / sy-vline , AT 2 'BUSINESS PARTNER' CENTERED INTENSIFIED COLOR 4, sy-vline, AT 30 'EMAIL-ID' CENTERED INTENSIFIED COLOR 4 , AT 125 sy-vline, AT 126 'STATUS' CENTERED INTENSIFIED COLOR 4, AT 179 sy-vline. WRITE : / sy-uline. LOOP AT i_output WHERE mail EQ space. WRITE : / sy-vline, i_output-bpartner CENTERED INTENSIFIED COLOR 2, AT 20 sy-vline, AT 21 i_output-mail LEFT-JUSTIFIED INTENSIFIED COLOR 2, AT 125 sy-vline, AT 126 i_output-status LEFT-JUSTIFIED INTENSIFIED COLOR 6, AT 179 sy-vline. WRITE : / sy-uline. ENDLOOP. ENDIF. * MESSAGE ID 'YGF_ABR20640' TYPE 'I' NUMBER '002' * WITH v_index. ENDFORM. " EXCEL_SHEET_APPLICATION *&---------------------------------------------------------------------* *& Form HEADER_DATA_DISPLAY *&---------------------------------------------------------------------* FORM header_data_display. **To Fill LIFNR Vendor Title and Number *--Writing data CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Cells' = gs_cell2 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Range' = gs_cells EXPORTING #1 = gs_cell1 #2 = gs_cell2. CALL METHOD OF gs_cells 'Select'. **--Merging CALL METHOD OF gs_cells 'Merge'. SET PROPERTY OF gs_cells 'Value' = 'Vendor Number'. SET PROPERTY OF gs_cells 'Locked' = 1. *--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 2. IF NOT i_dpr_bupa_link_final1-lifnr IS INITIAL. SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-lifnr. ELSE. SET PROPERTY OF gs_cell1 'Value' = 'Not Applicable for FSEs'. ENDIF. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick **To Fill NAME Vendor Title and Name gv_line_cntr = gv_line_cntr + 1 . "Header Counter *--Writing data CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Cells' = gs_cell2 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Range' = gs_cells EXPORTING #1 = gs_cell1 #2 = gs_cell2. CALL METHOD OF gs_cells 'Select'. *--Merging CALL METHOD OF gs_cells 'Merge'. SET PROPERTY OF gs_cells 'Value' = 'Vendor Name'. SET PROPERTY OF gs_cells 'Locked' = 1. GET PROPERTY OF gs_cells 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 2. IF NOT i_dpr_bupa_link_final1-name IS INITIAL. SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-name. ELSE. SET PROPERTY OF gs_cell1 'Value' = 'Not Applicable for FSEs'. ENDIF. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick **To Fill PERNR Title and Number gv_line_cntr = gv_line_cntr + 1 . "Header Counter *--Writing data CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Cells' = gs_cell2 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Range' = gs_cells EXPORTING #1 = gs_cell1 #2 = gs_cell2. CALL METHOD OF gs_cells 'Select'. *--Merging CALL METHOD OF gs_cells 'Merge'. SET PROPERTY OF gs_cells 'Value' = 'Personnel Number'. SET PROPERTY OF gs_cells 'Locked' = 1. GET PROPERTY OF gs_cells 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 2. SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-pernr. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick **To Fill project_id Title and Number gv_line_cntr = gv_line_cntr + 1 . *--Writing data CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Cells' = gs_cell2 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Range' = gs_cells EXPORTING #1 = gs_cell1 #2 = gs_cell2. CALL METHOD OF gs_cells 'Select'. *--Merging CALL METHOD OF gs_cells 'Merge'. SET PROPERTY OF gs_cells 'Value' = 'Internal Order'. SET PROPERTY OF gs_cells 'Locked' = 1. GET PROPERTY OF gs_cells 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 2. SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-project_id. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick **To Fill Project Name gv_line_cntr = gv_line_cntr + 1 . *--Writing data CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Cells' = gs_cell2 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Range' = gs_cells EXPORTING #1 = gs_cell1 #2 = gs_cell2. CALL METHOD OF gs_cells 'Select'. *--Merging CALL METHOD OF gs_cells 'Merge'. SET PROPERTY OF gs_cells 'Value' = 'Project Name'. SET PROPERTY OF gs_cells 'Locked' = 1. GET PROPERTY OF gs_cells 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 2. SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-proj_name. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick **To Fill Project Manager Name gv_line_cntr = gv_line_cntr + 1 . *--Writing data CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Cells' = gs_cell2 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Range' = gs_cells EXPORTING #1 = gs_cell1 #2 = gs_cell2. CALL METHOD OF gs_cells 'Select'. *--Merging CALL METHOD OF gs_cells 'Merge'. SET PROPERTY OF gs_cells 'Value' = 'Project Manager'. SET PROPERTY OF gs_cells 'Locked' = 1. GET PROPERTY OF gs_cells 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 2. SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-name_pm. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick **To Fill Firstname and Lastename gv_line_cntr = gv_line_cntr + 1 . *--Writing data CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Cells' = gs_cell2 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Range' = gs_cells EXPORTING #1 = gs_cell1 #2 = gs_cell2. CALL METHOD OF gs_cells 'Select'. *--Merging CALL METHOD OF gs_cells 'Merge'. SET PROPERTY OF gs_cells 'Value' = 'Resource Name'. SET PROPERTY OF gs_cells 'Locked' = 1. GET PROPERTY OF gs_cells 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 2. CONCATENATE i_dpr_bupa_link_final1-name_first i_dpr_bupa_link_final1-name_last INTO v_name SEPARATED BY space. SET PROPERTY OF gs_cell1 'Value' = v_name. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CLEAR : v_name. **To Fill Purchase Order gv_line_cntr = gv_line_cntr + 1 . *--Writing data CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Cells' = gs_cell2 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Range' = gs_cells EXPORTING #1 = gs_cell1 #2 = gs_cell2. CALL METHOD OF gs_cells 'Select'. *--Merging CALL METHOD OF gs_cells 'Merge'. SET PROPERTY OF gs_cells 'Value' = 'Purchase Order'. SET PROPERTY OF gs_cells 'Locked' = 1. GET PROPERTY OF gs_cells 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 2. IF NOT i_dpr_bupa_link_final1-object_key IS INITIAL. SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-object_key . ELSE. SET PROPERTY OF gs_cell1 'Value' = 'Not Applicable for FSEs'. ENDIF. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . SET PROPERTY OF gs_cell1 'WrapText' = 1. CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick **Project Description gv_line_cntr = gv_line_cntr + 1 . *--Writing data CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Cells' = gs_cell2 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Range' = gs_cells EXPORTING #1 = gs_cell1 #2 = gs_cell2. CALL METHOD OF gs_cells 'Select'. *--Merging CALL METHOD OF gs_cells 'Merge'. SET PROPERTY OF gs_cells 'Value' = 'Project Description'. SET PROPERTY OF gs_cells 'Locked' = 1. GET PROPERTY OF gs_cells 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . SET PROPERTY OF gs_cell1 'ColumnWidth' = '20' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 2. SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-proj_desc . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . SET PROPERTY OF gs_cell1 'WrapText' = 1. CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick **Report Start Date v_begyear1 = p_begdt+0(4). v_begmnt1 = p_begdt+4(2). v_begday1 = p_begdt+6(2). LOOP AT i_months_name WHERE mnr EQ v_begmnt1. v_month_name = i_months_name-ktx. ENDLOOP. CONCATENATE v_begday1 v_month_name v_begyear1 INTO v_begindate SEPARATED BY '-'. gv_line_cntr = gv_line_cntr + 1 . *--Writing data CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Cells' = gs_cell2 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Range' = gs_cells EXPORTING #1 = gs_cell1 #2 = gs_cell2. CALL METHOD OF gs_cells 'Select'. *--Merging CALL METHOD OF gs_cells 'Merge'. SET PROPERTY OF gs_cells 'Value' = 'Report Start Date'. SET PROPERTY OF gs_cells 'Locked' = 1. GET PROPERTY OF gs_cells 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . SET PROPERTY OF gs_cell1 'ColumnWidth' = '20' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 2. SET PROPERTY OF gs_cell1 'NumberFormat' = '[$-409]d-mmm-yyyy;@'. SET PROPERTY OF gs_cell1 'Value' = v_begindate. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick **Report End Date v_endyear1 = p_enddt+0(4). v_endmnt1 = p_enddt+4(2). v_endday1 = p_enddt+6(2). LOOP AT i_months_name WHERE mnr EQ v_endmnt1. v_month_name = i_months_name-ktx. ENDLOOP. CONCATENATE v_endday1 v_month_name v_endyear1 INTO v_enddate1 SEPARATED BY '-'. gv_line_cntr = gv_line_cntr + 1 . *--Writing data CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Cells' = gs_cell2 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Range' = gs_cells EXPORTING #1 = gs_cell1 #2 = gs_cell2. CALL METHOD OF gs_cells 'Select'. *--Merging CALL METHOD OF gs_cells 'Merge'. SET PROPERTY OF gs_cells 'Value' = 'Report End Date'. SET PROPERTY OF gs_cells 'Locked' = 1. GET PROPERTY OF gs_cells 'Font' = gs_font . SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . * SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . SET PROPERTY OF gs_cell1 'ColumnWidth' = '20' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 2. SET PROPERTY OF gs_cell1 'NumberFormat' = '[$-409]d-mmm-yyyy;@'. SET PROPERTY OF gs_cell1 'Value' = v_enddate1. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick gv_line_cntr = gv_line_cntr + 2. "Line Item Counter ENDFORM. " HEADER_DATA_DISPLAY *&---------------------------------------------------------------------* *& Form line_title_DISPLAY *&---------------------------------------------------------------------* FORM line_title_display. *----------------------------------------------------------------------* * TASK NAME * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 2. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'TASK NAME' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick gv_line_cntr_1 = gv_line_cntr. gv_line_cntr_1 = gv_line_cntr_1 + 1. *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr_1 #2 = 1. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr_1 * #2 = 2. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-task_name . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * TASK DESCRIPTION * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 2. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 4. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'TASK DESCRIPTION' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr_1 #2 = 2. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr_1 * #2 = 4. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-task_desc . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'ColumnWidth' = '30' . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . SET PROPERTY OF gs_cell1 'WrapText' = 1. CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * TASK TYPE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 3. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 6. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'TASK TYPE' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *1ST LINE OF TASK TYPE-SATYAJIT *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr_1 #2 = 3. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr_1 * #2 = 6. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-task_type . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * ROLE TYPE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 4. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 8. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'ROLE TYPE' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr_1 #2 = 4. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr_1 * #2 = 8. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-role_text . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . SET PROPERTY OF gs_cell1 'ColumnWidth' = '15' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * ASSIGNMENT START DATE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 5. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 11. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'ASSIGNMENT START DATE' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . SET PROPERTY OF gs_cell1 'ColumnWidth' = '23' . SET PROPERTY OF gs_cell1 'WrapText' = 1. CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CLEAR : v_begyear1, v_begmnt1, v_begday1, v_begindate. v_begyear1 = i_dpr_bupa_link_final1-beg_tmstmp_eng+0(4). v_begmnt1 = i_dpr_bupa_link_final1-beg_tmstmp_eng+4(2). v_begday1 = i_dpr_bupa_link_final1-beg_tmstmp_eng+6(2). LOOP AT i_months_name WHERE mnr EQ v_begmnt1. v_month_name = i_months_name-ktx. ENDLOOP. CONCATENATE v_begday1 v_month_name v_begyear1 INTO v_begindate SEPARATED BY '-'. *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr_1 #2 = 5. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr_1 * #2 = 11. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'NumberFormat' = '[$-409]d-mmm-yyyy;@'. SET PROPERTY OF gs_cell1 'Value' = v_begindate . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . SET PROPERTY OF gs_cell1 'ColumnWidth' = '23' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * ASSIGNMENT END DATE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 6. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 13. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'ASSIGNMENT END DATE' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . SET PROPERTY OF gs_cell1 'ColumnWidth' = '23' . SET PROPERTY OF gs_cell1 'WrapText' = 1. CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CLEAR : v_endyear1, v_endmnt1, v_endday1, v_enddate1. v_endyear1 = i_dpr_bupa_link_final1-end_tmstmp_eng+0(4). v_endmnt1 = i_dpr_bupa_link_final1-end_tmstmp_eng+4(2). v_endday1 = i_dpr_bupa_link_final1-end_tmstmp_eng+6(2). LOOP AT i_months_name WHERE mnr EQ v_endmnt1. v_month_name = i_months_name-ktx. ENDLOOP. CONCATENATE v_endday1 v_month_name v_endyear1 INTO v_enddate1 SEPARATED BY '-'. *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr_1 #2 = 6. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr_1 * #2 = 13. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'NumberFormat' = '[$-409]d-mmm-yyyy;@'. SET PROPERTY OF gs_cell1 'Value' = v_enddate1 . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . SET PROPERTY OF gs_cell1 'ColumnWidth' = '23' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * ALLOCATED WORK EFFORTS * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 7. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 16. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'ALLOCATED DAYS' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr_1 #2 = 7. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr_1 * #2 = 16. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-work_effort . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick ENDFORM. "line_title_DISPLAY *&---------------------------------------------------------------------* *& Form LINE_ITEM_DISPLAY *&---------------------------------------------------------------------* FORM line_item_display. gv_line_cntr_1 = gv_line_cntr_1 + 1. *----------------------------------------------------------------------* * TASK NAME * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr_1 #2 = 1. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr_1 * #2 = 2. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-task_name . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * TASK DESCRIPTION * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr_1 #2 = 2. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr_1 * #2 = 4. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-task_desc . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . SET PROPERTY OF gs_cell1 'ColumnWidth' = '30' . SET PROPERTY OF gs_cell1 'WrapText' = 1. CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * TASK TYPE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr_1 #2 = 3. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr_1 * #2 = 6. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-task_type . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . SET PROPERTY OF gs_cell1 'ColumnWidth' = '15' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * ROLE TYPE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr_1 #2 = 4. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr_1 * #2 = 8. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-role_text . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 . SET PROPERTY OF gs_cell1 'ColumnWidth' = '15' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * ASSIGNMENT START DATE * *----------------------------------------------------------------------* CLEAR : v_begyear1, v_begmnt1, v_begday1, v_begindate. v_begyear1 = i_dpr_bupa_link_final1-beg_tmstmp_eng+0(4). v_begmnt1 = i_dpr_bupa_link_final1-beg_tmstmp_eng+4(2). v_begday1 = i_dpr_bupa_link_final1-beg_tmstmp_eng+6(2). LOOP AT i_months_name WHERE mnr EQ v_begmnt1. v_month_name = i_months_name-ktx. ENDLOOP. CONCATENATE v_begday1 v_month_name v_begyear1 INTO v_begindate SEPARATED BY '-'. *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr_1 #2 = 5. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr_1 * #2 = 11. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'NumberFormat' = '[$-409]d-mmm-yyyy;@'. SET PROPERTY OF gs_cell1 'Value' = v_begindate . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . SET PROPERTY OF gs_cell1 'ColumnWidth' = '19' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * ASSIGNMENT END DATE * *----------------------------------------------------------------------* CLEAR : v_endyear1, v_endmnt1, v_endday1, v_enddate1. v_endyear1 = i_dpr_bupa_link_final1-end_tmstmp_eng+0(4). v_endmnt1 = i_dpr_bupa_link_final1-end_tmstmp_eng+4(2). v_endday1 = i_dpr_bupa_link_final1-end_tmstmp_eng+6(2). LOOP AT i_months_name WHERE mnr EQ v_endmnt1. v_month_name = i_months_name-ktx. ENDLOOP. CONCATENATE v_endday1 v_month_name v_endyear1 INTO v_enddate1 SEPARATED BY '-'. *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr_1 #2 = 6. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr_1 * #2 = 13. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'NumberFormat' = '[$-409]d-mmm-yyyy;@'. SET PROPERTY OF gs_cell1 'Value' = v_enddate1 . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . SET PROPERTY OF gs_cell1 'ColumnWidth' = '19' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * ALLOCATED WORK EFFORTS * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr_1 #2 = 7. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr_1 * #2 = 16. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-work_effort . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick ENDFORM. "LINE_ITEM_DISPLAY *&---------------------------------------------------------------------* *& Form CATS_HEADER_DATA *&---------------------------------------------------------------------* FORM cats_header_data . *----------------------------------------------------------------------* * TASK ID * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 2. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'TASK ID' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * TASK NAME * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 2. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 4. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'TASK NAME' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * WORK DATE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 3. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 6. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'WORK DATE' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * DAYS * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 4. SET PROPERTY OF gs_cell1 'Value' = 'DAYS' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * ROLE TYPE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 5. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 9. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'ROLE TYPE' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * UOM * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 6. SET PROPERTY OF gs_cell1 'Value' = 'UOM' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * DATA ENTRY PROFILE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 7. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 13. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'DATA ENTRY PROFILE' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . SET PROPERTY OF gs_cell1 'ColumnWidth' = '24' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * PERSONNEL NUMBER * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 8. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 16. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'PERSONNEL NUMBER' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . SET PROPERTY OF gs_cell1 'ColumnWidth' = '20' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * INTERNAL ORDER * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 9. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 18. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'INTERNAL ORDER' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . SET PROPERTY OF gs_cell1 'ColumnWidth' = '20' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * ACTIVITY TYPE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 10. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 20. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'ACTIVITY TYPE' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . SET PROPERTY OF gs_cell1 'ColumnWidth' = '20' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * SENDER COST CENTER * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 11. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 23. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'SENDER COST CENTRE' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . SET PROPERTY OF gs_cell1 'ColumnWidth' = '29' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * PURCHASE ORDER * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 12. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 25. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'PURCHASE ORDER' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . SET PROPERTY OF gs_cell1 'ColumnWidth' = '20' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * LINE ITEM * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 13. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 27. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'LINE ITEM' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . SET PROPERTY OF gs_cell1 'ColumnWidth' = '14' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * PROJECT ID * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 14. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 29. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'PROJECT ID' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . SET PROPERTY OF gs_cell1 'ColumnWidth' = '16' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * ACTIVITY NUMBER (Service Master) * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 15. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 32. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = 'ACTIVITY NUMBER (Service Master)' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . SET PROPERTY OF gs_cell1 'ColumnWidth' = '45'. CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick ENDFORM. " CATS_HEADER_DATA *&---------------------------------------------------------------------* *& Form CATS_LINE_DATA *&---------------------------------------------------------------------* FORM cats_line_data . DATA : v_task_id TYPE char25, v_lstnr1(18) TYPE c, v_lstnr(19) TYPE c. *----------------------------------------------------------------------* * TASK ID * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 2. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . v_task_id = i_etworklist-zzcpr_objgextid. CONCATENATE '''' v_task_id INTO v_task_id. SET PROPERTY OF gs_cell1 'Value' = v_task_id. SET PROPERTY OF gs_cell1 'Locked' = 1. SET PROPERTY OF gs_cell1 'ColumnWidth' = '22' . **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CLEAR : v_task_id. *----------------------------------------------------------------------* * TASK NAME * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 2. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 4. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . READ TABLE i_dpr_bupa_link_final1 WITH KEY task_number = i_etworklist-zzcpr_objgextid. SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-task_name. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * WORK DATE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 3. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 6. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'NumberFormat' = '[$-409]d-mmm-yyyy;@'. SET PROPERTY OF gs_cell1 'Value' = ' ' . GET PROPERTY OF gs_cell1 'AddComment' = gs_comment . CALL METHOD OF gs_comment 'Text' EXPORTING #1 = 'Enter Date Format in DD-MMM-YYYY'. SET PROPERTY OF gs_cell1 'Locked' = 0 . **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '65280' . SET PROPERTY OF gs_cell1 'WrapText' = 1. CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * DAYS * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 4. SET PROPERTY OF gs_cell1 'NumberFormat' = '0.000'. SET PROPERTY OF gs_cell1 'Value' = '0.000' . **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cell1 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '65280' . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick SET PROPERTY OF gs_cell1 'Locked' = 0 . *----------------------------------------------------------------------* * ROLE TYPE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 5. **--Merging SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final2-role_text . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * UNIT OF MEASUREMENT * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 6. SET PROPERTY OF gs_cell1 'Value' = 'DA' . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * DATA ENTRY PROFILE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 7. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 13. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . IF v_bpkind2 EQ 'DSR_ICDR'. SET PROPERTY OF gs_cell1 'Value' = 'DSR_BICD' . ELSEIF v_bpkind2 EQ 'DSR_FSE'. SET PROPERTY OF gs_cell1 'Value' = 'DSR_BFSE' . ENDIF. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * PERSONNAL NUMBER * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 8. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 16. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = v_pernr . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * INTERNAL ORDER * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 9. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 18. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . IF i_etworklist-raufnr IS INITIAL. SET PROPERTY OF gs_cell1 'Value' = ' ' . ELSE. SET PROPERTY OF gs_cell1 'Value' = i_etworklist-raufnr . ENDIF. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * ACTIVITY TYPE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 10. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 20. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . IF i_etworklist-lstar IS INITIAL. SET PROPERTY OF gs_cell1 'Value' = ' ' . ELSE. SET PROPERTY OF gs_cell1 'Value' = i_etworklist-lstar . ENDIF. SET PROPERTY OF gs_cell1 'Locked' = 1 . **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * SENDER COST CENTRE * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 11. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 23. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . IF i_etworklist-skostl IS INITIAL. SET PROPERTY OF gs_cell1 'Value' = ' ' . ELSE. SET PROPERTY OF gs_cell1 'Value' = i_etworklist-skostl . ENDIF. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * PURCHASE ORDER * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 12. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 25. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . * read table i_dpr_bupa_link_final1 key SET PROPERTY OF gs_cell1 'Value' = i_etworklist-sebeln. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * LINE ITEM * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 13. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 27. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = i_etworklist-sebelp. SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * PROJECT ID * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 14. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 29. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . SET PROPERTY OF gs_cell1 'Value' = i_etworklist-zzcpr_extid . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick *----------------------------------------------------------------------* * ACTIVITY NUMBER * *----------------------------------------------------------------------* *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 15. * CALL METHOD OF gs_excel 'Cells' = gs_cell2 * EXPORTING * #1 = gv_line_cntr * #2 = 32. * CALL METHOD OF gs_excel 'Range' = gs_cells * EXPORTING * #1 = gs_cell1 * #2 = gs_cell2. * CALL METHOD OF gs_cells 'Select' . **--Merging * CALL METHOD OF gs_cells 'Merge' . v_lstnr1 = i_etworklist-lstnr. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = v_lstnr1 IMPORTING output = v_lstnr1. CONCATENATE '''' v_lstnr1 INTO v_lstnr. SET PROPERTY OF gs_cell1 'Value' = v_lstnr . SET PROPERTY OF gs_cell1 'Locked' = 1. **--Formatting the title GET PROPERTY OF gs_cell1 'Font' = gs_font . * SET PROPERTY OF gs_font 'Name' = 'Arial' . * SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 0 . SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 . CALL METHOD OF gs_cell1 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick CLEAR : v_lstnr, v_lstnr1. ENDFORM. " CATS_LINE_DATA *&---------------------------------------------------------------------* *& Form EMAILING_DOCUMENT *&---------------------------------------------------------------------* FORM emailing_document USING return_file v_email w_pernr w_proid w_begdt w_enddt. ws_file = return_file. ws_email = v_email. ws_pernr = w_pernr. ws_proid = w_proid. ws_begdt = w_begdt. ws_enddt = w_enddt. PERFORM bdc_dynpro USING 'YGS_SEND_EXTERNAL_MAIL' '1000'. PERFORM bdc_field USING 'BDC_CURSOR' 'WS_FILE'. PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'. PERFORM bdc_field USING 'WS_FILE' ws_file. PERFORM bdc_field USING 'WS_EMAIL' ws_email. PERFORM bdc_field USING 'WS_PERNR' ws_pernr. PERFORM bdc_field USING 'WS_PROID' ws_proid. PERFORM bdc_field USING 'WS_BEGDT' ws_begdt. PERFORM bdc_field USING 'WS_ENDDT' ws_enddt. PERFORM bdc_dynpro USING 'SAPLSO04' '1000'. PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'. PERFORM bdc_field USING 'BDC_CURSOR' 'SOS04-L_ADR_NAME(01)'. PERFORM bdc_field USING 'SOS04-L_ADR_NAME(01)' v_email. PERFORM bdc_dynpro USING 'SAPLSO04' '1000'. PERFORM bdc_field USING 'BDC_OKCODE' '=SEND'. PERFORM bdc_field USING 'BDC_CURSOR' 'SOS04-L_ADR_NAME(01)'. CALL TRANSACTION 'YG_EMAIL' USING bdcdata MODE 'N' UPDATE 'S'. REFRESH : bdcdata. ENDFORM. " EMAILING_DOCUMENT *----------------------------------------------------------------------* * Start new screen * *----------------------------------------------------------------------* FORM bdc_dynpro USING program dynpro. CLEAR bdcdata. bdcdata-program = program. bdcdata-dynpro = dynpro. bdcdata-dynbegin = 'X'. APPEND bdcdata. ENDFORM. "BDC_DYNPRO *----------------------------------------------------------------------* * Insert field * *----------------------------------------------------------------------* FORM bdc_field USING fnam fval. CLEAR bdcdata. bdcdata-fnam = fnam. bdcdata-fval = fval. APPEND bdcdata. ENDFORM. "BDC_FIELD *&---------------------------------------------------------------------* *& Form EXCEL_SHEET_MAIL_RECIPIENT *&---------------------------------------------------------------------* FORM excel_sheet_mail_recipient USING p_recp. DATA : v_name TYPE char80, v_participant_guid TYPE dpr_tv_participant_guid, v_index TYPE sy-tabix, v_times(4) TYPE c, v_effortvalue(11) TYPE c, v_effortvalue1(4) TYPE n, v_length(4) TYPE c, v_mail(3) TYPE c VALUE 0. DATA : return(255) TYPE c, return1(128) TYPE c, type TYPE i, return_file TYPE string, v_email(128) TYPE c, v_recp(128) TYPE c. DATA : p_file TYPE localfile. **TO DETERMINE THE CURRENT USERNAME DESKTOP **PATH FOR CREATING FOLDER IN HIS SYSTEM. LOOP AT i_dpr_bupa_link_final1. v_pernr = i_dpr_bupa_link_final1-pernr. CONCATENATE 'E0' v_pernr INTO v_businesspartner. SELECT SINGLE bpkind FROM but000 INTO v_bpkind WHERE partner = v_businesspartner. CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1. IF NOT v_bpkind IS INITIAL. i_dpr_bupa_link_final1-bpkind = v_bpkind1. MODIFY i_dpr_bupa_link_final1 INDEX sy-tabix TRANSPORTING bpkind. ELSE. DELETE i_dpr_bupa_link_final1 INDEX sy-tabix. ENDIF. CLEAR : v_bpkind, v_bpkind1, v_businesspartner, v_pernr. ENDLOOP. i_dpr_bupa_link_final2[] = i_dpr_bupa_link_final1[]. SORT i_dpr_bupa_link_final2 BY participant_guid. DELETE ADJACENT DUPLICATES FROM i_dpr_bupa_link_final2 COMPARING participant_guid. type = '00000000012'. CALL FUNCTION 'GUI_GET_DESKTOP_INFO' EXPORTING type = type CHANGING return = return. CONCATENATE return '\DAR_' sy-datum '_' sy-uzeit INTO return. return1 = return. CALL FUNCTION 'GUI_CREATE_DIRECTORY' EXPORTING dirname = return1 EXCEPTIONS failed = 1 OTHERS = 2. return = return1. LOOP AT i_dpr_bupa_link_final2. v_skipflag = 0. v_index = sy-tabix. v_pernr = i_dpr_bupa_link_final2-pernr. v_participant_guid = i_dpr_bupa_link_final2-participant_guid. v_int_order = i_dpr_bupa_link_final2-project_id. v_bpkind2 = i_dpr_bupa_link_final2-bpkind. *--Forming sheet name gv_index = sy-index . gv_outer_index = sy-index . gv_sheet_name = 'Detail Activity Report'. ***For email checking for individual PERNR CONCATENATE 'E0' v_pernr INTO v_businesspartner. wa_bapibus1006_head-bpartner = v_businesspartner. REFRESH : wa_bapiadsmtp. CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL' EXPORTING businesspartner = wa_bapibus1006_head-bpartner valid_date = sy-datum TABLES bapiadsmtp = wa_bapiadsmtp. IF wa_bapiadsmtp[] IS INITIAL. v_skipflag = 1. ELSE. REFRESH : wa_bapiadsmtp. ENDIF. LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid. IF * i_dpr_bupa_link_final1-lifnr IS INITIAL OR * i_dpr_bupa_link_final1-name IS INITIAL OR i_dpr_bupa_link_final1-pernr IS INITIAL OR i_dpr_bupa_link_final1-project_id IS INITIAL OR i_dpr_bupa_link_final1-proj_name IS INITIAL OR i_dpr_bupa_link_final1-name_pm IS INITIAL OR * i_dpr_bupa_link_final1-object_key IS INITIAL OR i_dpr_bupa_link_final1-proj_desc IS INITIAL. v_skipflag = 1. ENDIF. CONCATENATE i_dpr_bupa_link_final1-name_first i_dpr_bupa_link_final1-name_last INTO v_name SEPARATED BY space. IF v_name IS INITIAL. v_skipflag = 1. ENDIF. IF i_dpr_bupa_link_final1-object_key IS INITIAL AND i_dpr_bupa_link_final1-bpkind EQ 'DSR_ICDR'. v_skipflag = 1. ENDIF. IF i_dpr_bupa_link_final1-task_name IS INITIAL OR i_dpr_bupa_link_final1-task_desc IS INITIAL OR i_dpr_bupa_link_final1-task_type IS INITIAL OR i_dpr_bupa_link_final1-role_text IS INITIAL OR i_dpr_bupa_link_final1-beg_tmstmp_eng IS INITIAL OR i_dpr_bupa_link_final1-end_tmstmp_eng IS INITIAL OR i_dpr_bupa_link_final1-work_effort IS INITIAL. v_skipflag = 1. ENDIF. CLEAR : v_name. ENDLOOP. CONCATENATE 'E0' v_pernr INTO v_businesspartner. SELECT SINGLE bpkind FROM but000 INTO v_bpkind WHERE partner = v_businesspartner. CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1. IF NOT v_bpkind IS INITIAL. CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest EXPORTING sap_variant = v_bpkind1 sap_pernr = v_pernr beg_date = p_begdt end_date = p_enddt TABLES sap_icatsw = i_etworklist. ENDIF. DELETE i_etworklist WHERE zzcpr_extid NE v_int_order. CLEAR : v_bpkind, v_bpkind1. IF i_etworklist[] IS INITIAL. v_skipflag = 1. ENDIF. IF v_skipflag = 0. *--For the first loop, Excel is initiated and one new sheet is added CREATE OBJECT gs_excel 'EXCEL.APPLICATION' . GET PROPERTY OF gs_excel 'Visible' = v_vis. *set this property to open excel in background SET PROPERTY OF gs_excel 'Visible' = 'False' . GET PROPERTY OF gs_excel 'Workbooks' = gs_wbooklist . GET PROPERTY OF gs_wbooklist 'Application' = gs_application . SET PROPERTY OF gs_application 'SheetsInNewWorkbook' = 1 . CALL METHOD OF gs_wbooklist 'Add' = gs_wbook. GET PROPERTY OF gs_application 'ActiveSheet' = gs_activesheet . GET PROPERTY OF gs_excel 'ActiveWorkbook' = g_workbook. SET PROPERTY OF gs_activesheet 'Name' = gv_sheet_name . GET PROPERTY OF gs_activesheet 'Cells' = gs_cells. GET PROPERTY OF gs_cells 'Font' = gs_font . SET PROPERTY OF gs_font 'Name' = 'Arial' . SET PROPERTY OF gs_font 'Size' = '10' . gv_line_cntr = 1 . "line counter *--Title *--Selecting cell area to be merged. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = 1 #2 = 1. CALL METHOD OF gs_excel 'Cells' = gs_cell2 EXPORTING #1 = 1 #2 = 15. CALL METHOD OF gs_excel 'Range' = gs_cells EXPORTING #1 = gs_cell1 #2 = gs_cell2. CALL METHOD OF gs_cells 'Select'. *--Merging CALL METHOD OF gs_cells 'Merge'. *--Setting title data CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. SET PROPERTY OF gs_cells 'Value' = 'DETAIL ACTIVITY REPORT' . SET PROPERTY OF gs_cells 'Locked' = 1. GET PROPERTY OF gs_cells 'Font' = gs_font . SET PROPERTY OF gs_font 'Name' = 'Arial' . SET PROPERTY OF gs_font 'Size' = '12' . SET PROPERTY OF gs_font 'Underline' = 2 . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_cells 'HorizontalAlignment' = -4108 . GET PROPERTY OF gs_cells 'Interior' = gs_interior . SET PROPERTY OF gs_interior 'Color' = '10092543' . CALL METHOD OF gs_cells 'BorderAround' EXPORTING #1 = 1 "continuous line #2 = 2. "thick **--Formatting the title gv_line_cntr = gv_line_cntr + 2 . LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid. ON CHANGE OF i_dpr_bupa_link_final1-participant_guid. PERFORM header_data_display. PERFORM line_title_display. w_proid = i_dpr_bupa_link_final1-project_id. v_flag = 1. ENDON. IF v_flag = 1. v_flag = 0. CONTINUE. ENDIF. PERFORM line_item_display. ENDLOOP. **Code Closed by LZ16662 **FOR DISPLAYING CATSWORKLIST DETAILS **IN EXCEL SHEET **CONSTANTS VALUE FOR ACTIVITY NUMBER BASED ON SYSTEM * CONCATENATE 'E0' v_pernr INTO v_businesspartner. * SELECT SINGLE bpkind * FROM but000 * INTO v_bpkind * WHERE partner = v_businesspartner. * CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1. * IF NOT v_bpkind IS INITIAL. * CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest * EXPORTING * sap_variant = v_bpkind1 * sap_pernr = v_pernr * beg_date = p_begdt * end_date = p_enddt * TABLES * sap_icatsw = i_etworklist. * ENDIF. * DELETE i_etworklist WHERE zzcpr_extid NE v_int_order. * CLEAR : v_int_order, v_bpkind. **Code Closed by LZ16662 gv_line_cntr = gv_line_cntr_1. gv_line_cntr = gv_line_cntr + 2 . **FOR DISPLAYING COLOMN NAMES FOR CATSWORKLIST PERFORM cats_header_data. **FOR DISPLAYING LINE ITEM DETAILS FOR CATSWORKLIST LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid AND flag EQ 'X'. * v_times = i_dpr_bupa_link_final1-days_total. v_temp_value = i_dpr_bupa_link_final1-days_total. "work_effort. v_temp_value = ceil( v_temp_value ). v_effortvalue = v_temp_value. v_length = strlen( v_effortvalue ). v_length = v_length - 3. v_effortvalue = v_effortvalue+0(v_length). SHIFT v_effortvalue LEFT DELETING LEADING space. MOVE v_effortvalue TO v_effortvalue1. IF v_effortvalue1 LE v_datediff. v_times = v_effortvalue1. ELSEIF v_effortvalue1 GT v_datediff. v_times = v_datediff. ENDIF. READ TABLE i_etworklist WITH KEY zzcpr_objgextid = i_dpr_bupa_link_final1-task_number. IF sy-subrc = 0. DO v_times TIMES. gv_line_cntr = gv_line_cntr + 1. PERFORM cats_line_data. ENDDO. ENDIF. CLEAR : v_effortvalue, v_length, v_times, v_effortvalue1, v_temp_value. ENDLOOP. CLEAR : v_bpkind2. * LOOP AT i_etworklist WHERE sebeln NE space. * gv_line_cntr = gv_line_cntr + 1. * PERFORM cats_line_data. * ENDLOOP. PERFORM note_condition. * SET PROPERTY OF gs_activesheet 'PROTECT' = 1. CALL METHOD OF gs_activesheet 'PROTECT' EXPORTING #1 = 'dsr123##$'. CALL METHOD OF g_workbook 'PROTECT' EXPORTING #1 = 'dsr123##$'. REFRESH : i_etworklist. **TO STORE THE EXCEL FILE FOR DIFFERENT PERSONNEL NUMBER **TO STORE THE SAME IN CREATED DIRECTORY * CONCATENATE i_dpr_bupa_link_final2-name_first i_dpr_bupa_link_final1-name_last INTO v_save_name SEPARATED BY space. CONCATENATE i_dpr_bupa_link_final2-role_text '-' INTO v_save_name. return_file = return. CONCATENATE return '\' i_dpr_bupa_link_final2-project_id '' v_pernr '' v_save_name sy-datum '-' sy-uzeit '.xls' INTO return_file. CALL METHOD OF gs_wbook 'SaveAs' EXPORTING #1 = return_file. * SET PROPERTY OF gs_excel 'DisplayAlerts' = 0. PERFORM free_objects. CONCATENATE 'E0' v_pernr INTO v_businesspartner. wa_bapibus1006_head-bpartner = v_businesspartner. CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL' EXPORTING businesspartner = wa_bapibus1006_head-bpartner valid_date = sy-datum TABLES bapiadsmtp = wa_bapiadsmtp. IF NOT wa_bapiadsmtp[] IS INITIAL. READ TABLE wa_bapiadsmtp INDEX 1. IF sy-subrc = 0. **EMAILING AN ATTACHMENT TO RECIPIENT ADDRESS SPECIFIED v_email = wa_bapiadsmtp-e_mail. w_pernr = v_pernr. w_begdt = v_datebeg1. w_enddt = v_dateend1. PERFORM emailing_document USING return_file v_email w_pernr w_proid w_begdt w_enddt. i_output-bpartner = v_businesspartner. i_output-mail = v_email. i_output-status = 'Sucessfully Mailed the Document'. APPEND i_output. CLEAR : i_output. v_sucess = v_sucess + 1. ELSE. i_output-bpartner = v_businesspartner. i_output-status = 'Email Address not Maintained'. APPEND i_output. CLEAR : i_output. v_failure = v_failure + 1. ENDIF. ENDIF. **EMAILING AN ATTACHMENT COPY TO RECIPIENT ADDRESS SPECIFIED v_email = p_recp. w_pernr = v_pernr. w_begdt = v_datebeg1. w_enddt = v_dateend1. PERFORM emailing_document USING return_file v_email w_pernr w_proid w_begdt w_enddt. v_mail = v_mail + 1. ENDIF. CLEAR : v_participant_guid, v_pernr, return_file, v_businesspartner, wa_bapiadsmtp, wa_bapibus1006_head, v_email, w_proid, w_pernr, w_begdt, w_enddt, ws_pernr, ws_proid, ws_begdt, ws_enddt, v_times, v_save_name, return1. REFRESH : i_etworklist. ENDLOOP. LOOP AT i_output WHERE mail NE space. v_status1 = 1. ENDLOOP. LOOP AT i_output WHERE mail EQ space. v_status2 = 1. ENDLOOP. IF v_status1 = 1. WRITE : / 'Date :', sy-datum. WRITE : / 'Time :', sy-uzeit. WRITE : / 'Result :', v_sucess , 'Record''s mailed sucessfully'. WRITE : / sy-uline. WRITE : / sy-vline , AT 2 'BUSINESS PARTNER' CENTERED INTENSIFIED COLOR 4, AT 20 sy-vline, AT 30 'EMAIL-ID' CENTERED INTENSIFIED COLOR 4 , AT 125 sy-vline, AT 126 'STATUS' CENTERED INTENSIFIED COLOR 4, AT 179 sy-vline. WRITE : / sy-uline. LOOP AT i_output WHERE mail NE space. WRITE : / sy-vline, i_output-bpartner CENTERED INTENSIFIED COLOR 2, AT 20 sy-vline, AT 21 i_output-mail LEFT-JUSTIFIED INTENSIFIED COLOR 2, AT 125 sy-vline, AT 126 i_output-status LEFT-JUSTIFIED INTENSIFIED COLOR 5, AT 179 sy-vline. WRITE : / sy-uline. ENDLOOP. ENDIF. IF v_status2 = 1. WRITE : / 'Result :', v_failure , 'Record''s mailed unsucessfully'. WRITE : / sy-uline. WRITE : / sy-vline , AT 2 'BUSINESS PARTNER' CENTERED INTENSIFIED COLOR 4, sy-vline, AT 30 'EMAIL-ID' CENTERED INTENSIFIED COLOR 4 , AT 125 sy-vline, AT 126 'STATUS' CENTERED INTENSIFIED COLOR 4, AT 179 sy-vline. WRITE : / sy-uline. LOOP AT i_output WHERE mail EQ space. WRITE : / sy-vline, i_output-bpartner CENTERED INTENSIFIED COLOR 2, AT 20 sy-vline, AT 21 i_output-mail LEFT-JUSTIFIED INTENSIFIED COLOR 2, AT 125 sy-vline, AT 126 i_output-status LEFT-JUSTIFIED INTENSIFIED COLOR 6, AT 179 sy-vline. WRITE : / sy-uline. ENDLOOP. ENDIF. IF v_mail NE 0. WRITE : / 'Result :', 'Record''s mailed sucessfully to -' INTENSIFIED COLOR 5 , p_recp INTENSIFIED COLOR 5. ELSE. WRITE : / 'Result :', 'Record''s mailed unsucessfully to -' INTENSIFIED COLOR 6 , p_recp INTENSIFIED COLOR 6. ENDIF. ENDFORM. " EXCEL_SHEET_MAIL_RECIPIENT *&---------------------------------------------------------------------* *& Form BATCH_PROCESS_EMAIL *&---------------------------------------------------------------------* FORM batch_process_email USING p_recp . DATA : v_participant_guid TYPE dpr_tv_participant_guid, v_name TYPE char80, v_index TYPE sy-tabix, v_times(4) TYPE c, v_effortvalue(11) TYPE c, v_effortvalue1(4) TYPE n, v_length(4) TYPE c. v_recp = p_recp. LOOP AT i_dpr_bupa_link_final1. v_pernr = i_dpr_bupa_link_final1-pernr. CONCATENATE 'E0' v_pernr INTO v_businesspartner. SELECT SINGLE bpkind FROM but000 INTO v_bpkind WHERE partner = v_businesspartner. CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1. IF NOT v_bpkind IS INITIAL. i_dpr_bupa_link_final1-bpkind = v_bpkind1. MODIFY i_dpr_bupa_link_final1 INDEX sy-tabix TRANSPORTING bpkind. ELSE. DELETE i_dpr_bupa_link_final1 INDEX sy-tabix. ENDIF. CLEAR : v_bpkind, v_bpkind1, v_businesspartner, v_pernr. ENDLOOP. i_dpr_bupa_link_final2[] = i_dpr_bupa_link_final1[]. SORT i_dpr_bupa_link_final2 BY participant_guid. DELETE ADJACENT DUPLICATES FROM i_dpr_bupa_link_final2 COMPARING participant_guid. LOOP AT i_dpr_bupa_link_final2. v_skipflag = 0. v_pernr = i_dpr_bupa_link_final2-pernr. v_participant_guid = i_dpr_bupa_link_final2-participant_guid. v_int_order = i_dpr_bupa_link_final2-project_id. v_bpkind2 = i_dpr_bupa_link_final2-bpkind. LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid. IF * i_dpr_bupa_link_final1-lifnr IS INITIAL OR * i_dpr_bupa_link_final1-name IS INITIAL OR i_dpr_bupa_link_final1-pernr IS INITIAL OR i_dpr_bupa_link_final1-project_id IS INITIAL OR i_dpr_bupa_link_final1-proj_name IS INITIAL OR i_dpr_bupa_link_final1-name_pm IS INITIAL OR * i_dpr_bupa_link_final1-object_key IS INITIAL OR i_dpr_bupa_link_final1-proj_desc IS INITIAL. v_skipflag = 1. ENDIF. CONCATENATE i_dpr_bupa_link_final1-name_first i_dpr_bupa_link_final1-name_last INTO v_name SEPARATED BY space. IF v_name IS INITIAL. v_skipflag = 1. ENDIF. IF i_dpr_bupa_link_final1-object_key IS INITIAL AND i_dpr_bupa_link_final1-bpkind EQ 'DSR_ICDR'. v_skipflag = 1. ENDIF. IF i_dpr_bupa_link_final1-task_name IS INITIAL OR i_dpr_bupa_link_final1-task_desc IS INITIAL OR i_dpr_bupa_link_final1-task_type IS INITIAL OR i_dpr_bupa_link_final1-role_text IS INITIAL OR i_dpr_bupa_link_final1-beg_tmstmp_eng IS INITIAL OR i_dpr_bupa_link_final1-end_tmstmp_eng IS INITIAL OR i_dpr_bupa_link_final1-work_effort IS INITIAL. v_skipflag = 1. ENDIF. CLEAR : v_name. ENDLOOP. CONCATENATE 'E0' v_pernr INTO v_businesspartner. SELECT SINGLE bpkind FROM but000 INTO v_bpkind WHERE partner = v_businesspartner. CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1. IF NOT v_bpkind IS INITIAL. CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest EXPORTING sap_variant = v_bpkind1 sap_pernr = v_pernr beg_date = p_begdt end_date = p_enddt TABLES sap_icatsw = i_etworklist. ENDIF. DELETE i_etworklist WHERE zzcpr_extid NE v_int_order. CLEAR : v_bpkind, v_bpkind1. IF i_etworklist[] IS INITIAL. v_skipflag = 1. ENDIF. IF v_skipflag = 0. LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid. ON CHANGE OF i_dpr_bupa_link_final1-participant_guid. IF NOT i_dpr_bupa_link_final1-lifnr IS INITIAL. CONCATENATE 'Vendor Number :' i_dpr_bupa_link_final1-lifnr INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. ELSE. CONCATENATE 'Vendor Number :' 'Not Applicable for FSEs' INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. ENDIF. IF NOT i_dpr_bupa_link_final1-name IS INITIAL. CONCATENATE 'Vendor Name :' i_dpr_bupa_link_final1-name INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. ELSE. CONCATENATE 'Vendor Name :' 'Not Applicable for FSEs' INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. ENDIF. CONCATENATE 'Personnel Number :' i_dpr_bupa_link_final1-pernr INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. CONCATENATE 'Internal Order :' i_dpr_bupa_link_final1-project_id INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. CONCATENATE 'Project Name :' i_dpr_bupa_link_final1-proj_name INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. CONCATENATE 'Project Manager' i_dpr_bupa_link_final1-name_pm INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. CONCATENATE i_dpr_bupa_link_final1-name_first i_dpr_bupa_link_final1-name_last INTO v_name SEPARATED BY space. CONCATENATE v_pernr i_dpr_bupa_link_final1-project_id INTO v_name_sub SEPARATED BY '-'. CONCATENATE 'Resource Name :' v_name INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. IF NOT i_dpr_bupa_link_final1-object_key IS INITIAL. CONCATENATE 'Purchase Order :' i_dpr_bupa_link_final1-object_key INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. ELSE. CONCATENATE 'Purchase Order :' 'Not Applicable for FSEs' INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. ENDIF. CONCATENATE 'Project Description :' i_dpr_bupa_link_final1-proj_desc INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. CONCATENATE 'Report Start Date :' v_datebeg INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. CONCATENATE 'Report End Date :' v_dateend INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. CLEAR : v_name. **Appending Extra Lines for Seperating PERFORM load_data_to_attachment. "Appending Blank Lines PERFORM load_data_to_attachment. "Appending Blank Lines **2nd Stage CONCATENATE 'TASK NAME' 'TASK DESCRIPTION' 'TASK TYPE' 'ROLE TYPE' 'ASSIGNMENT START DATE' 'ASSIGNMENT END DATE' 'ALLOCATED DAYS' ' ' ' ' ' ' ' ' ' ' INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. **2nd stage 1st line item. PERFORM line_item_project_details. v_flag = 1. ENDON. IF v_flag = 1. v_flag = 0. CONTINUE. ENDIF. PERFORM line_item_project_details. ENDLOOP. **Code Closed by LZ16662 **FOR DISPLAYING CATSWORKLIST DETAILS **IN EXCEL SHEET **CONSTANTS VALUE FOR ACTIVITY NUMBER BASED ON SYSTEM * CONCATENATE 'E0' v_pernr INTO v_businesspartner. * SELECT SINGLE bpkind * FROM but000 * INTO v_bpkind * WHERE partner = v_businesspartner. * CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1. * IF NOT v_bpkind IS INITIAL. * CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest * EXPORTING * sap_variant = v_bpkind1 * sap_pernr = v_pernr * beg_date = p_begdt * end_date = p_enddt * IMPORTING * sap_startdate = v_start_date * sap_enddate = v_end_date * TABLES * sap_icatsw = i_etworklist. * ENDIF. * DELETE i_etworklist WHERE zzcpr_extid NE v_int_order. * CLEAR : v_int_order, v_bpkind. **Code Closed by LZ16662 **Appending Extra Lines for Seperating PERFORM load_data_to_attachment. "Appending Blank Lines **FOR DISPLAYING COLOMN NAMES FOR CATSWORKLIST **3rd Stage CONCATENATE 'TASK ID' 'TASK NAME' 'WORK DATE' 'DAYS' 'ROLE TYPE' 'UOM' 'DATA ENTRY PROFILE' 'PERSONNEL NUMBER' 'INTERNAL ORDER' 'ACTIVITY TYPE' 'SENDER COST CENTRE' 'PURCHASE ORDER' 'LINE ITEM' 'PROJECT ID' 'ACTIVITY NUMBER (Service Master)' ' ' INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. **FOR DISPLAYING LINE ITEM DETAILS FOR CATSWORKLIST LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid. v_temp_value = i_dpr_bupa_link_final1-work_effort. v_temp_value = ceil( v_temp_value ). v_effortvalue = v_temp_value. v_length = strlen( v_effortvalue ). v_length = v_length - 3. v_effortvalue = v_effortvalue+0(v_length). SHIFT v_effortvalue LEFT DELETING LEADING space. MOVE v_effortvalue TO v_effortvalue1. IF v_effortvalue1 LE v_datediff. v_times = v_effortvalue1. ELSEIF v_effortvalue1 GT v_datediff. v_times = v_datediff. ENDIF. READ TABLE i_etworklist WITH KEY zzcpr_objgextid = i_dpr_bupa_link_final1-task_number. IF sy-subrc = 0. DO v_times TIMES. PERFORM cats_line_data_output. ENDDO. ENDIF. CLEAR : v_effortvalue, v_length, v_times, v_effortvalue1, v_temp_value. ENDLOOP. CLEAR : v_bpkind2. PERFORM load_data_to_attachment. "Appending Blank Lines PERFORM load_data_to_attachment. "Appending Blank Lines CONCATENATE 'Note : Task Name is repeated No.' 'of days the task has been allocated' 'within the Report Period.' INTO w_attachment. * SEPARATED BY con_tab. PERFORM load_data_to_attachment. * LOOP AT i_etworklist WHERE sebeln NE space. * PERFORM cats_line_data_output. * ENDLOOP. REFRESH : i_etworklist. **Determine the Business Partner Address CONCATENATE 'E0' v_pernr INTO v_businesspartner. wa_bapibus1006_head-bpartner = v_businesspartner. CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL' EXPORTING businesspartner = wa_bapibus1006_head-bpartner valid_date = sy-datum TABLES bapiadsmtp = wa_bapiadsmtp. IF NOT wa_bapiadsmtp[] IS INITIAL. READ TABLE wa_bapiadsmtp INDEX 1. IF sy-subrc = 0. v_email = wa_bapiadsmtp-e_mail. PERFORM send_mail USING v_email v_recp v_name_sub v_start_date v_end_date. ELSE. CLEAR : w_document_data. REFRESH : i_packing_list, i_attachment, i_body_msg, i_receivers. ENDIF. ENDIF. ENDIF. REFRESH : i_packing_list, i_attachment, i_body_msg, i_receivers, i_etworklist. CLEAR : v_pernr, v_participant_guid, v_businesspartner, wa_bapiadsmtp, wa_bapibus1006_head, v_email, v_start_date, v_end_date, v_name_sub. ENDLOOP. ENDFORM. " BATCH_PROCESS_EMAIL *&---------------------------------------------------------------------* *& Form LOAD_DATA_TO_ATTACHMENT *&---------------------------------------------------------------------* FORM load_data_to_attachment . CONCATENATE con_cret w_attachment INTO w_attachment. APPEND w_attachment TO i_attachment. CLEAR w_attachment. ENDFORM. " LOAD_DATA_TO_ATTACHMENT *&---------------------------------------------------------------------* *& Form LINE_ITEM_PROJECT_DETAILS *&---------------------------------------------------------------------* FORM line_item_project_details . WRITE i_dpr_bupa_link_final1-beg_tmstmp_eng TO v_beg_tmstmp_eng. WRITE i_dpr_bupa_link_final1-end_tmstmp_eng TO v_end_tmstmp_eng. CLEAR : v_date, v_month, v_year. v_date = v_beg_tmstmp_eng+0(2). v_month = v_beg_tmstmp_eng+2(2). v_year = v_beg_tmstmp_eng+4(4). LOOP AT i_months_name WHERE mnr EQ v_month. v_month_name = i_months_name-ktx. ENDLOOP. CONCATENATE v_date v_month_name v_year INTO v_beg_tmstmp_eng1 SEPARATED BY '-'. CLEAR : v_date, v_month, v_year. v_date = v_end_tmstmp_eng+0(2). v_month = v_end_tmstmp_eng+2(2). v_year = v_end_tmstmp_eng+4(4). LOOP AT i_months_name WHERE mnr EQ v_month. v_month_name = i_months_name-ktx. ENDLOOP. CONCATENATE v_date v_month_name v_year INTO v_end_tmstmp_eng1 SEPARATED BY '-'. CLEAR : v_date, v_month, v_year. v_work_effort = i_dpr_bupa_link_final1-work_effort. CONCATENATE i_dpr_bupa_link_final1-task_name i_dpr_bupa_link_final1-task_desc i_dpr_bupa_link_final1-task_type i_dpr_bupa_link_final1-role_text v_beg_tmstmp_eng1 v_end_tmstmp_eng1 v_work_effort ' ' ' ' ' ' ' ' ' ' INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. CLEAR : v_work_effort, v_beg_tmstmp_eng1, v_end_tmstmp_eng1, v_beg_tmstmp_eng, v_end_tmstmp_eng. ENDFORM. " LINE_ITEM_PROJECT_DETAILS *&---------------------------------------------------------------------* *& Form CATS_LINE_DATA_OUTPUT *&---------------------------------------------------------------------* FORM cats_line_data_output . DATA : v_task_id TYPE char25, v_task_name TYPE dpr_tv_name, v_lstnr(19) TYPE c, v_bpkind3(8) TYPE c. READ TABLE i_dpr_bupa_link_final1 WITH KEY task_number = i_etworklist-zzcpr_objgextid. IF sy-subrc = 0. v_task_name = i_dpr_bupa_link_final1-task_name. ENDIF. v_task_id = i_etworklist-zzcpr_objgextid. CONCATENATE '''' v_task_id INTO v_task_id. v_lstnr = i_etworklist-lstnr. CONCATENATE '''' v_lstnr INTO v_lstnr. IF v_bpkind2 = 'DSR_ICDR'. v_bpkind3 = v_bpkind2. ELSEIF v_bpkind2 EQ 'DSR_FSE'. v_bpkind3 = v_bpkind2. ENDIF. IF i_etworklist-skostl IS INITIAL AND i_etworklist-lstar IS INITIAL AND i_etworklist-raufnr IS INITIAL . CONCATENATE v_task_id v_task_name ' ' ' ' i_dpr_bupa_link_final2-role_text 'DA' v_bpkind3 v_pernr ' ' ' ' ' ' i_etworklist-sebeln i_etworklist-sebelp i_etworklist-zzcpr_extid v_lstnr ' ' INTO w_attachment SEPARATED BY con_tab. PERFORM load_data_to_attachment. ELSE. CONCATENATE v_task_id v_task_name ' ' ' ' i_dpr_bupa_link_final2-role_text 'DA' v_bpkind3 v_pernr i_etworklist-raufnr i_etworklist-lstar i_etworklist-skostl i_etworklist-sebeln i_etworklist-sebelp i_etworklist-zzcpr_extid v_lstnr ' ' INTO w_attachment SEPARATED BY con_tab. ENDIF. CLEAR : v_task_id, v_task_name, v_bpkind3. ENDFORM. " CATS_LINE_DATA_OUTPUT *&---------------------------------------------------------------------* *& Form SEND_MAIL *&---------------------------------------------------------------------* FORM send_mail USING v_email v_recp v_name_sub v_start_date v_end_date. DATA : v_objdescr(70) TYPE c, v_begindate(11) TYPE c, v_enddate(11) TYPE c, v_temp(30) TYPE c, v_month_name TYPE fcktx. DATA : i_months_name TYPE STANDARD TABLE OF t247 WITH HEADER LINE. "For getting months name in Subject line CALL FUNCTION 'MONTH_NAMES_GET' EXPORTING language = sy-langu TABLES month_names = i_months_name EXCEPTIONS month_names_not_found = 1 OTHERS = 2. "Subject of the mail. w_document_data-obj_name = 'MAIL_TO_HEAD'. CLEAR : v_objdescr. v_year = v_start_date+0(4). v_month = v_start_date+4(2). v_date = v_start_date+6(2). LOOP AT i_months_name WHERE mnr EQ v_month. v_month_name = i_months_name-ktx. ENDLOOP. CONCATENATE v_date v_month_name v_year INTO v_begindate SEPARATED BY '.'. CLEAR : v_year, v_month, v_date, v_month_name. v_year = v_end_date+0(4). v_month = v_end_date+4(2). v_date = v_end_date+6(2). LOOP AT i_months_name WHERE mnr EQ v_month. v_month_name = i_months_name-ktx. ENDLOOP. CONCATENATE v_date v_month_name v_year INTO v_enddate SEPARATED BY '.'. CLEAR : v_year, v_month, v_date, v_month_name. CONCATENATE v_begindate '-' v_enddate INTO v_temp SEPARATED BY space. CONCATENATE 'DAR' v_name_sub v_temp INTO v_objdescr SEPARATED BY '-'. w_document_data-obj_descr = v_objdescr. CLEAR : v_objdescr, v_temp, v_begindate, v_enddate. "Write Packing List for Body DESCRIBE TABLE i_body_msg LINES g_tab_lines. w_packing_list-head_start = 1. w_packing_list-head_num = 0. w_packing_list-body_start = 1. w_packing_list-body_num = g_tab_lines. w_packing_list-doc_type = 'RAW'. APPEND w_packing_list TO i_packing_list. CLEAR w_packing_list. "Write Packing List for Attachment w_packing_list-transf_bin = 'X'. w_packing_list-head_start = 1. w_packing_list-head_num = 1. w_packing_list-body_start = 1. DESCRIBE TABLE i_attachment LINES w_packing_list-body_num. w_packing_list-doc_type = 'XLS'. CONCATENATE v_pernr 'DETAIL ACTIVITY REPORT' INTO v_objdescr SEPARATED BY '-'. w_packing_list-obj_descr = v_objdescr. CLEAR : v_objdescr. w_packing_list-obj_name = 'XLS_ATTACHMENT'. w_packing_list-doc_size = w_packing_list-body_num * 255. APPEND w_packing_list TO i_packing_list. CLEAR w_packing_list. "Fill the document data and get size of attachment w_document_data-obj_langu = sy-langu. READ TABLE i_attachment INTO w_attachment INDEX g_tab_lines. w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + strlen( w_attachment ). "Receivers List. w_receivers-rec_type = 'U'. " U Internet address w_receivers-receiver = v_email. "MAIL ADDRESS APPEND w_receivers TO i_receivers . CLEAR:w_receivers. IF NOT v_recp IS INITIAL. w_receivers-rec_type = 'U'. " U Internet address w_receivers-receiver = v_recp. "MAIL ADDRESS w_receivers-copy = 'X'. APPEND w_receivers TO i_receivers . CLEAR:w_receivers. ENDIF. "Function module to send mail to Recipients CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = w_document_data put_in_outbox = 'X' commit_work = 'X' IMPORTING sent_to_all = g_sent_to_all TABLES packing_list = i_packing_list contents_bin = i_attachment contents_txt = i_body_msg receivers = i_receivers 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 i303(me) WITH 'Mail has been Successfully Sent.'. * ELSE. * WAIT UP TO 2 SECONDS. * "This program starts the SAPconnect send process. * SUBMIT rsconn01 WITH mode = 'INT' * WITH output = 'X' * AND RETURN. * ENDIF. CLEAR : v_email, v_month_name. REFRESH : i_months_name. ENDFORM. " SEND_MAIL *&---------------------------------------------------------------------* *& Form F_INITIALAZE_RFCDEST *&---------------------------------------------------------------------* FORM f_initialaze_rfcdest . DATA : v_datum TYPE sy-datum. CLEAR v_dest. CASE sy-sysid. WHEN 'NRD'. MOVE c_gdd TO v_dest. WHEN 'NRB'. MOVE c_gb2 TO v_dest. WHEN 'NRP'. MOVE c_gp1 TO v_dest. ENDCASE. v_datum = sy-datum + 15. p_enddt = v_datum. CLEAR : v_datum. ENDFORM. " F_INITIALAZE_RFCDEST *&---------------------------------------------------------------------* *& Form FREE_OBJECTS *&---------------------------------------------------------------------* FORM free_objects . CALL METHOD OF gs_wbook 'Close'. CALL METHOD OF gs_excel 'Quit'. FREE OBJECT gs_cell1. FREE OBJECT gs_cell2. FREE OBJECT gs_cells. FREE OBJECT gs_activesheet. FREE OBJECT gs_wbook. FREE OBJECT gs_application. FREE OBJECT gs_wbooklist. FREE OBJECT gs_excel. ENDFORM. " FREE_OBJECTS *&---------------------------------------------------------------------* *& Form NOTE_CONDITION *&---------------------------------------------------------------------* FORM note_condition . gv_line_cntr = gv_line_cntr + 2. CALL METHOD OF gs_excel 'Cells' = gs_cell1 EXPORTING #1 = gv_line_cntr #2 = 1. CALL METHOD OF gs_excel 'Cells' = gs_cell2 EXPORTING #1 = gv_line_cntr #2 = 5. CALL METHOD OF gs_excel 'Range' = gs_cells EXPORTING #1 = gs_cell1 #2 = gs_cell2. CALL METHOD OF gs_cells 'Select'. *--Merging CALL METHOD OF gs_cells 'Merge'. SET PROPERTY OF gs_cells 'Value' = 'Note: Task Name is repeated No. of days the task has been allocated within the Report Period.' . **--Formatting the title GET PROPERTY OF gs_cells 'Font' = gs_font . SET PROPERTY OF gs_font 'Name' = 'Arial' . SET PROPERTY OF gs_font 'Size' = '10' . SET PROPERTY OF gs_font 'Bold' = 1 . SET PROPERTY OF gs_font 'Italic' = 1 . SET PROPERTY OF gs_cells 'HorizontalAlignment' = -4131 . SET PROPERTY OF gs_cells 'Locked' = 1. ENDFORM. " NOTE_CONDITION *&---------------------------------------------------------------------* *& Form FILTER_OUTPUT_DISPLAY_ALV *&---------------------------------------------------------------------* FORM filter_output_display_alv . DATA : v_name TYPE char80, v_participant_guid TYPE dpr_tv_participant_guid, v_index TYPE sy-tabix, v_flag TYPE c VALUE '0'. **TO DETERMINE THE CURRENT USERNAME DESKTOP **PATH FOR CREATING FOLDER IN HIS SYSTEM. LOOP AT i_dpr_bupa_link_final1. v_index = sy-tabix. v_pernr = i_dpr_bupa_link_final1-pernr. CONCATENATE 'E0' v_pernr INTO v_businesspartner. SELECT SINGLE bpkind FROM but000 INTO v_bpkind WHERE partner = v_businesspartner. CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1. IF NOT v_bpkind IS INITIAL. i_dpr_bupa_link_final1-bpkind = v_bpkind1. MODIFY i_dpr_bupa_link_final1 INDEX sy-tabix TRANSPORTING bpkind. ELSE. DELETE i_dpr_bupa_link_final1 INDEX v_index. ENDIF. CLEAR : v_bpkind, v_bpkind1, v_businesspartner, v_pernr, v_index. ENDLOOP. i_dpr_bupa_link_final2[] = i_dpr_bupa_link_final1[]. SORT i_dpr_bupa_link_final2 BY participant_guid. DELETE ADJACENT DUPLICATES FROM i_dpr_bupa_link_final2 COMPARING participant_guid. LOOP AT i_dpr_bupa_link_final2. v_skipflag = 0. v_index = sy-tabix. v_pernr = i_dpr_bupa_link_final2-pernr. v_participant_guid = i_dpr_bupa_link_final2-participant_guid. v_int_order = i_dpr_bupa_link_final2-project_id. LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid. IF * i_dpr_bupa_link_final1-lifnr IS INITIAL OR * i_dpr_bupa_link_final1-name IS INITIAL OR i_dpr_bupa_link_final1-pernr IS INITIAL OR i_dpr_bupa_link_final1-project_id IS INITIAL OR i_dpr_bupa_link_final1-proj_name IS INITIAL OR i_dpr_bupa_link_final1-name_pm IS INITIAL OR * i_dpr_bupa_link_final1-object_key IS INITIAL OR i_dpr_bupa_link_final1-proj_desc IS INITIAL. v_flag = 1. ENDIF. CONCATENATE i_dpr_bupa_link_final1-name_first i_dpr_bupa_link_final1-name_last INTO v_name SEPARATED BY space. IF v_name IS INITIAL. v_flag = 1. ENDIF. IF i_dpr_bupa_link_final1-object_key IS INITIAL AND i_dpr_bupa_link_final1-bpkind EQ 'DSR_ICDR'. v_flag = 1. ENDIF. IF i_dpr_bupa_link_final1-task_name IS INITIAL OR i_dpr_bupa_link_final1-task_desc IS INITIAL OR i_dpr_bupa_link_final1-task_type IS INITIAL OR i_dpr_bupa_link_final1-role_text IS INITIAL OR i_dpr_bupa_link_final1-beg_tmstmp_eng IS INITIAL OR i_dpr_bupa_link_final1-end_tmstmp_eng IS INITIAL OR i_dpr_bupa_link_final1-work_effort IS INITIAL. v_flag = 1. ENDIF. CLEAR : v_name. IF v_flag = 1. DELETE i_dpr_bupa_link_final1 INDEX sy-tabix. v_flag = 0. ENDIF. ENDLOOP. CONCATENATE 'E0' v_pernr INTO v_businesspartner. SELECT SINGLE bpkind FROM but000 INTO v_bpkind WHERE partner = v_businesspartner. CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1. IF NOT v_bpkind IS INITIAL. CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest EXPORTING sap_variant = v_bpkind1 sap_pernr = v_pernr beg_date = p_begdt end_date = p_enddt TABLES sap_icatsw = i_etworklist. ENDIF. DELETE i_etworklist WHERE zzcpr_extid NE v_int_order. CLEAR : v_bpkind, v_bpkind1. IF i_etworklist[] IS INITIAL. DELETE i_dpr_bupa_link_final1 WHERE pernr EQ v_pernr. ENDIF. **To check BP Email Address CONCATENATE 'E0' v_pernr INTO v_businesspartner. wa_bapibus1006_head-bpartner = v_businesspartner. REFRESH : wa_bapiadsmtp. CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL' EXPORTING businesspartner = wa_bapibus1006_head-bpartner valid_date = sy-datum TABLES bapiadsmtp = wa_bapiadsmtp. IF wa_bapiadsmtp[] IS INITIAL. DELETE i_dpr_bupa_link_final1 WHERE pernr EQ v_pernr. ELSE. REFRESH : wa_bapiadsmtp. ENDIF. CLEAR : v_participant_guid, v_pernr, v_businesspartner, v_int_order, wa_bapiadsmtp, wa_bapibus1006_head. REFRESH : i_etworklist. ENDLOOP. ENDFORM. " FILTER_OUTPUT_DISPLAY_ALV *PROGRAM for sending MAIL. transaction code yg_email *&---------------------------------------------------------------------* *& Report YGS_SEND_EXTERNAL_MAIL *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ygs_send_external_mail. *----------------------------------------------------------------------* * DATA DECLERATIONS * *----------------------------------------------------------------------* DATA : method1 LIKE sy-ucomm, g_user LIKE soudnamei1, g_user_data LIKE soudatai1, g_owner LIKE soud-usrnam, g_document LIKE sood4 , g_header LIKE sood2, g_folmam LIKE sofm2, g_authority LIKE sofa-usracc, g_ref_document LIKE sood4, g_new_parent LIKE soodk, fold_number(12) TYPE c, fold_yr(2) TYPE c, fold_type(3) TYPE c. *----------------------------------------------------------------------* * INTERNAL TABLE DECLERATIONS * *----------------------------------------------------------------------* DATA g_objcnt LIKE soli OCCURS 0 WITH HEADER LINE. DATA g_objhead LIKE soli OCCURS 0 WITH HEADER LINE. DATA g_objpara LIKE selc OCCURS 0 WITH HEADER LINE. DATA g_objparb LIKE soop1 OCCURS 0 WITH HEADER LINE. DATA g_attachments LIKE sood5 OCCURS 0 WITH HEADER LINE. DATA g_references LIKE soxrl OCCURS 0 WITH HEADER LINE. DATA g_receipients LIKE soos1 OCCURS 0 WITH HEADER LINE. DATA i_months_name TYPE STANDARD TABLE OF t247 WITH HEADER LINE. "For getting months "name in Subject line DATA: BEGIN OF g_files OCCURS 10 , text(4096) TYPE c, END OF g_files. DATA : v_objdescr(50) TYPE c, v_begindate(11) TYPE c, v_enddate(11) TYPE c, v_temp(30) TYPE c, v_dest LIKE edipoa-logdes, v_start_date TYPE sy-datum, v_end_date TYPE sy-datum, v_date(2) TYPE c, v_month(2) TYPE c, v_year(4) TYPE c, v_businesspartner TYPE bu_partner, v_bpkind TYPE bu_bpkind, v_bpkind1(8) TYPE c, v_month_name TYPE fcktx, v_name_sub(100) TYPE c. *----------------------------------------------------------------------* * CONSTANT DECLERATIONS * *----------------------------------------------------------------------* CONSTANTS : c_gdd(6) TYPE c VALUE 'GDD590', c_gb2(6) TYPE c VALUE 'GB2590', c_gp1(6) TYPE c VALUE 'GP1590'. *----------------------------------------------------------------------* * PARAMETER DECLERATIONS * *----------------------------------------------------------------------* PARAMETER : ws_file TYPE string, ws_email(128) TYPE c, ws_pernr TYPE pernr_d, ws_proid TYPE project_id, ws_begdt TYPE sy-datum, ws_enddt TYPE sy-datum. CLEAR v_dest. CASE sy-sysid. WHEN 'NRD'. MOVE c_gdd TO v_dest. WHEN 'NRB'. MOVE c_gb2 TO v_dest. WHEN 'NRP'. MOVE c_gp1 TO v_dest. ENDCASE. CONCATENATE ws_pernr ws_proid INTO v_name_sub SEPARATED BY '-'. CALL FUNCTION 'MONTH_NAMES_GET' EXPORTING language = sy-langu TABLES month_names = i_months_name EXCEPTIONS month_names_not_found = 1 OTHERS = 2. * Can me any file fromyour pc ....either xls or word or ppt etc ... CLEAR : g_user_data, g_document. g_user-sapname = sy-uname. ws_file = ws_file. CALL FUNCTION 'SO_USER_READ_API1' EXPORTING user = g_user IMPORTING user_data = g_user_data. fold_type = g_user_data-outboxfol+0(3). fold_yr = g_user_data-outboxfol+3(2). fold_number = g_user_data-outboxfol+5(12). CLEAR g_files. REFRESH : g_objcnt, g_objhead, g_objpara, g_objparb, g_receipients, g_attachments, g_references, g_files. method1 = 'SAVE'. g_document-foltp = fold_type. g_document-folyr = fold_yr. g_document-folno = fold_number. g_document-objtp = g_user_data-object_typ. g_document-objdes = 'Detail Activity Report'. g_document-folrg = 'O'. g_document-objlen = '0'. g_document-file_ext = 'XLS'. CONCATENATE 'E0' ws_pernr INTO v_businesspartner. SELECT SINGLE bpkind FROM but000 INTO v_bpkind WHERE partner = v_businesspartner. CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1. CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest EXPORTING sap_variant = v_bpkind1 sap_pernr = ws_pernr beg_date = ws_begdt end_date = ws_enddt IMPORTING sap_startdate = v_start_date sap_enddate = v_end_date. CLEAR : v_bpkind1, v_bpkind. v_year = v_start_date+0(4). v_month = v_start_date+4(2). v_date = v_start_date+6(2). LOOP AT i_months_name WHERE mnr EQ v_month. v_month_name = i_months_name-ktx. ENDLOOP. CONCATENATE v_date v_month_name v_year INTO v_begindate SEPARATED BY '.'. CLEAR : v_date, v_month, v_year, v_month_name. v_year = v_end_date+0(4). v_month = v_end_date+4(2). v_date = v_end_date+6(2). LOOP AT i_months_name WHERE mnr EQ v_month. v_month_name = i_months_name-ktx. ENDLOOP. CONCATENATE v_date v_month_name v_year INTO v_enddate SEPARATED BY '.'. CLEAR : v_date, v_month, v_year, v_month_name. CONCATENATE v_begindate '-' v_enddate INTO v_temp. CONCATENATE 'DAR' v_name_sub v_temp INTO v_objdescr SEPARATED BY '-'. g_header-objdes = v_objdescr. CLEAR : v_objdescr, v_temp, v_begindate, v_enddate, v_start_date, v_end_date. CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER' EXPORTING method = method1 office_user = sy-uname ref_document = g_ref_document new_parent = g_new_parent IMPORTING authority = g_authority TABLES objcont = g_objcnt objhead = g_objhead objpara = g_objpara objparb = g_objparb recipients = g_receipients attachments = g_attachments references = g_references files = g_files CHANGING document = g_document header_data = g_header. * File from the pc to send... method1 = 'ATTCREATEFROMPC'. g_files-text = ws_file. APPEND g_files. CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER' EXPORTING method = method1 office_user = g_owner ref_document = g_ref_document new_parent = g_new_parent IMPORTING authority = g_authority TABLES objcont = g_objcnt objhead = g_objhead objpara = g_objpara objparb = g_objparb recipients = g_receipients attachments = g_attachments references = g_references files = g_files CHANGING document = g_document header_data = g_header. method1 = 'SEND'. g_receipients-recextnam = ws_email. g_receipients-recesc = 'A'. g_receipients-sndex = 'X'. APPEND g_receipients. CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER' EXPORTING method = method1 office_user = g_owner ref_document = g_ref_document new_parent = g_new_parent IMPORTING authority = g_authority TABLES objcont = g_objcnt objhead = g_objhead objpara = g_objpara objparb = g_objparb recipients = g_receipients attachments = g_attachments references = g_references files = g_files CHANGING document = g_document header_data = g_header. * SUBMIT rsconn01 WITH mode = 'INT' * WITH output = 'X' * AND RETURN. REFRESH : g_objcnt, g_objhead, g_objpara, g_objparb, g_receipients, g_attachments, g_references, g_files.
REPORT ztsapmail. DATA: x_object_type LIKE sood-objtp. DATA: BEGIN OF x_object_hd_change. INCLUDE STRUCTURE sood1. DATA: END OF x_object_hd_change. DATA: BEGIN OF x_objcont OCCURS 10. INCLUDE STRUCTURE soli. DATA: END OF x_objcont. DATA: BEGIN OF x_objhead OCCURS 0. INCLUDE STRUCTURE soli. DATA: END OF x_objhead. DATA: BEGIN OF raw_head. INCLUDE STRUCTURE sorh. DATA: END OF raw_head. DATA: BEGIN OF x_receivers OCCURS 0. INCLUDE STRUCTURE soos1. DATA: END OF x_receivers. PARAMETERS: receiver LIKE x_receivers-recnam. " Name *BUILD MESSAGE HEADER MOVE 'Sort field goes here' TO x_object_hd_change-objsrt. " Sort field MOVE 'Name of the object goes here' TO x_object_hd_change-objnam. " Name MOVE 'Document title goes here' TO x_object_hd_change-objdes. " Title MOVE 'F' TO x_object_hd_change-objsns. " Functional OBJECT MOVE 'E' TO x_object_hd_change-objla. " Language * Object type of the new document MOVE 'RAW' TO x_object_type. CLEAR x_objcont. MOVE 'Contents of mail' TO x_objcont-line. APPEND x_objcont. CLEAR x_objcont-line. APPEND x_objcont. MOVE 'More contents' TO x_objcont-line. APPEND x_objcont. MOVE 'Still more contents' TO x_objcont-line. APPEND x_objcont. MOVE ' ' TO x_objcont-line. APPEND x_objcont. * Specific header (Dependent on the object type, here RAW) REFRESH x_objhead. DESCRIBE TABLE x_objcont LINES raw_head-rawsiz. MOVE raw_head TO x_objhead. APPEND x_objhead. *RECEIVERS table CLEAR x_receivers. REFRESH x_receivers. MOVE receiver TO x_receivers-recnam. " Name MOVE 'B' TO x_receivers-recesc. " Receiver type MOVE 'X' TO x_receivers-sndcp. " Send as a copy MOVE 'X' TO x_receivers-sndex. " EXPRESS DOCUMENT APPEND x_receivers. CALL FUNCTION 'SO_OBJECT_SEND' EXPORTING object_hd_change = x_object_hd_change object_type = x_object_type outbox_flag = 'X' owner = sy-uname tablesobjcont = x_objcont objhead = x_objhead receivers = x_receivers.
Author: Jatra Riwayanto
Submitted: 26.09.2007
Related Links:
Description:
My previous snippet is a program that will display Inbox folder content. Now I am adding some code that will display mail content. User can select specific mail and will see the content of this mail.
Report Line-Size
Because length of SOLI-LINE is 255 character, we need to change report line size.
REPORT ZSapInbox NO STANDARD PAGE HEADING LINE-COUNT 65 LINE-SIZE 260.
Class Definition
Adding Display_Mail method and several data variable.
CLASS LCL_MAIN DEFINITION. PUBLIC SECTION. METHODS: DISPLAY_INBOX, DISPLAY_MAIL IMPORTING IM_MAILID TYPE STRING. " -- added code -- EVENTS: MESSAGE EXPORTING VALUE(MSG1) TYPE STRING VALUE(MSG2) TYPE STRING OPTIONAL VALUE(MSG3) TYPE STRING OPTIONAL VALUE(MSG4) TYPE STRING OPTIONAL. PRIVATE SECTION. METHODS: CLEAR_DATA, GET_INBOX_CONTENT. *--------------------------------- * L.O.C.A.L D.A.T.A. *--------------------------------- DATA: USER TYPE SOUDNAMEI1, UDAT TYPE SOUDATAI1, FDAT TYPE SOFOLDATI1, IT_FDAT TYPE TABLE OF SOFOLENTI1, WA_FDAT TYPE SOFOLENTI1. DATA: MSG1 TYPE STRING, MSG2 TYPE STRING, MSG3 TYPE STRING, MSG4 TYPE STRING. DATA: FOLD_ID TYPE SOODK, MAIL_ID TYPE SOODK. " -- added code -- DATA: WA_OBJCONT TYPE SOLI, " -- added code -- IT_OBJCONT TYPE TABLE OF SOLI, " -- added code -- OBJECT_HD_DISPLAY TYPE SOOD2. " -- added code -- ENDCLASS. "lcl_main DEFINITION
Display_Mail Implementation
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'METHOD DISPLAY_MAIL. MOVE IM_MAILID TO MAIL_ID. CALL FUNCTION 'SO_OBJECT_READ' EXPORTING folder_id = FOLD_ID object_id = MAIL_ID owner = P_UNAME IMPORTING object_hd_display = object_hd_display TABLES objcont = IT_objcont EXCEPTIONS active_user_not_exist = 35 communication_failure = 71 component_not_available = 01 folder_not_exist = 06 folder_no_authorization = 05 object_not_exist = 14 object_no_authorization = 13 operation_no_authorization = 21 owner_not_exist = 22 parameter_error = 23 substitute_not_active = 31 substitute_not_defined = 32 system_failure = 72 x_error = 1000. IF SY-SUBRC NE 0. RAISE EVENT MESSAGE EXPORTING MSG1 = 'Error reading mail content'. ELSE. FORMAT COLOR COL_HEADING. ULINE (259). WRITE: / '|',(255) object_hd_display-OBJDES LEFT-JUSTIFIED, '|'. ULINE (259). FORMAT COLOR OFF. LOOP AT IT_OBJCONT INTO WA_OBJCONT. WRITE: / '|', WA_OBJCONT-LINE, '|'. ENDLOOP. ULINE (259). ENDIF. ENDMETHOD. "DISPLAY_MAIL
Hotspot
We need add Hotspot on Object ID column.
METHOD DISPLAY_INBOX. CALL METHOD CLEAR_DATA( ). CALL METHOD GET_INBOX_CONTENT( ). IF IT_FDAT[] IS INITIAL. RAISE EVENT MESSAGE EXPORTING MSG1 = 'No emails in this inbox'. ENDIF. ULINE AT (114). FORMAT COLOR COL_HEADING. WRITE: / '|' NO-GAP, (020) 'Object ID' LEFT-JUSTIFIED, '|' NO-GAP, (030) 'Subject' LEFT-JUSTIFIED, '|' NO-GAP, (015) 'Date Recieved' LEFT-JUSTIFIED, '|' NO-GAP, (040) 'Sender ' LEFT-JUSTIFIED, '|'. ULINE AT /(114). FORMAT COLOR OFF. LOOP AT IT_FDAT INTO WA_FDAT. FORMAT COLOR COL_NORMAL INTENSIFIED ON. WRITE: / '|' NO-GAP, (020) WA_FDAT-OBJECT_ID UNDER 'Email ID' HOTSPOT ON COLOR 5, " -- added code -- '|' NO-GAP, (030) WA_FDAT-OBJ_DESCR LEFT-JUSTIFIED, '|' NO-GAP, (015) WA_FDAT-REC_DATE LEFT-JUSTIFIED, '|' NO-GAP, (040) WA_FDAT-SEND_FNAM LEFT-JUSTIFIED, '|'. ENDLOOP. ULINE AT /(114). ENDMETHOD. "DISPLAY_INBOX
AT LINE SELECTION
To make user enable display mail we need add AT-LINE-SELECTION code after START-OF-SELECTION.
START-OF-SELECTION. DATA: O_MAIN TYPE REF TO LCL_MAIN, O_HANDLER TYPE REF TO LCL_HANDLER. CREATE OBJECT: O_MAIN, O_HANDLER. SET HANDLER O_HANDLER->HANDLE_MESSAGE FOR ALL INSTANCES. CALL METHOD O_MAIN->DISPLAY_INBOX. AT LINE-SELECTION. DATA MAIL_ID TYPE STRING. MAIL_ID = SY-LISEL+1(17). CALL METHOD O_MAIN->DISPLAY_MAIL( MAIL_ID ).
Select Object ID.
Display mail content.
Business Scenarios:
In ETL, many times we have to use the ABAP programs to do processing so that we can implement various business scenarios. Some times users or Support teams need to be notified when something goes wrong in program while dealing with incorrect data. In those cases program goes under infinite loop and program times out. Support team then have to look into dumps and invest lot of time in analyzing the issue to find out where the program went wrong. To avoid all these manual steps we can rite a general program which can be called in different programs to generate the mails with the incorrect values. This automation will help in saving lot of manual effort.
Solution:
The ABAP developer can use the below program to generate the mails to the users and support team.
Step 1. Create a separate program as mentioned.
Go to Transaction SE38 and create program as:
*&--------------------------------------------------------------------- *& FORM ZEMAIL_GENERATION *&--------------------------------------------------------------------- *& This program receives a table containing Data issue list and *& generate mail. *&--------------------------------------------------------------------- FORM zemail_generation TABLES rc. DATA: it_objcont LIKE solisti1 OCCURS 5 WITH HEADER LINE, it_reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE, itab_objhead LIKE soli OCCURS 0 WITH HEADER LINE, itab_receiver LIKE soos1 OCCURS 0 WITH HEADER LINE, t_email_content LIKE soli OCCURS 0 WITH HEADER LINE, lw_originator LIKE soos1-recextnam, lw_originator_type LIKE soos1-recesc, w_mail_header LIKE sood1, it_document TYPE hrhap, it_doc_chng LIKE sodocchgi1, lin LIKE sy-tabix, v_content1 LIKE solisti1, v_content2 LIKE solisti1, v_content3 LIKE solisti1, v_content4 LIKE solisti1, v_content5 LIKE solisti1, header LIKE sodocchgi1-obj_descr, wa_subject TYPE char100, wa_content1 TYPE char100, wa_content2 TYPE solisti1-line, wa_receiver TYPE char20, wa_event_id TYPE char50, wa_stxh_tdname TYPE stxh-tdname, status LIKE hrhap-ap_status, sub_status LIKE hrhap-ap_status_sub, wa_appraisal_id LIKE hrhap-appraisal_id, plan_version TYPE hap_plan_version, email_address TYPE comm_id_long, designate_add TYPE comm_id_long, l_stxh_tdname TYPE stxh-tdname, lw_sender_name TYPE soud-usrnam, lw_send_request_oid TYPE os_guid, sender_pernr TYPE /bi0/oiemployee, sup_pernr TYPE /bi0/oiemployee, appee_pernr TYPE /bi0/oiemployee. DATA objcont LIKE soli OCCURS 5 WITH HEADER LINE. "Mail cont DATA: rc_tbl_new LIKE solisti1 OCCURS 5 WITH HEADER LINE, wa_rc_tbl TYPE solisti1. DATA: BEGIN OF w_ws, count TYPE i, smtp TYPE /bi0/oiemail_addr, err_num LIKE sy-msgno, END OF w_ws. ***End of declarations. CLEAR: wa_receiver, wa_subject , wa_content1, wa_content2, it_document. wa_receiver = 'BW-PRODSUPPORT@XYZ.com'. wa_subject = header = 'EMPLOYEE Hierarchy Going in Infinite Loop'. wa_content1 = 'The Supervisor going in Infinite loop are:'. *Append Receiverlist table. it_reclist-rec_type = 'U'. "Internet-adress it_reclist-receiver = 'BW-PRODSUPPORT@XYZ.com'. " 'BW tier 3'. it_reclist-express = 'X'. APPEND it_reclist. *Set general email message header/subject information w_mail_header-objnam = ''. w_mail_header-objsns = 'C'. w_mail_header-objla = sy-langu. w_mail_header-objdes = header. *Set message header to RAW itab_objhead-line = 'RAW'. APPEND itab_objhead. *Set receiver information itab_receiver-sel = 'X'. itab_receiver-rcdat = sy-datum. itab_receiver-recesc = 'U'. itab_receiver-recnam = ' '. itab_receiver-mailstatus = 'E'. itab_receiver-sortclass = '5'. itab_receiver-sndart = 'INT'. itab_receiver-sndpri = '1'. itab_receiver-sndspo = '0'. itab_receiver-deliver = 'X'. itab_receiver-read = 'X'. itab_receiver-recextnam = w_ws-smtp. APPEND itab_receiver. *Send email *Process the EMAIL using SO_NEW_DOCUMENT_SEND_API1 *Fill the document header it_doc_chng-obj_name = 'URGENT'. it_doc_chng-obj_descr = header. IF sy-sysid = 'HRP'. it_doc_chng-sensitivty = 'P'. ELSE. it_doc_chng-sensitivty = 'O'. ENDIF. it_doc_chng-obj_langu = sy-langu. * fill the text of the mail it_objcont = wa_content1. APPEND it_objcont. *** Append the RCs to the Text of the mail. *RC is an internal table containing incorrect data having issues. APPEND LINES OF rc TO it_objcont. * Read table and get the document size. DESCRIBE TABLE it_objcont LINES lin. READ TABLE it_objcont INDEX lin. it_doc_chng-doc_size = ( lin - 1 ) * 255 + strlen( it_objcont ). IF it_doc_chng-doc_size LT 0. it_doc_chng-doc_size = 0. ENDIF. * Send the email CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1' EXPORTING document_data = it_doc_chng document_type = 'RAW' put_in_outbox = 'X' commit_work = 'X' TABLES object_content = it_objcont receivers = it_reclist EXCEPTIONS document_not_sent = 2. ENDFORM. "ZEMAIL_GENERATION
Step 2. In your main program where you are doing functional processing, create an internal table and keep on filling the same with the values having data issue.
"RC" is an internal table with the values having data issues.
Call program to generate mail by using the below mention code snippet in your main program.
Table "RC" is populated with list of Corrupted RCs.
rc[] = corr_rc_table[]. DESCRIBE TABLE rc LINES lin. IF lin <> 0. *** Call PERFORM to send Email for Corrupted values from RCs. PERFORM zemail_generation TABLES rc . ENDIF.
- Step 3: For testing the functionality of the program:
Got to Transaction SCOT and goto Utilities as shown in screen shot:"
In the "OVERVIEW OF SEND ORDERS", you will see screen as shown below:
"
Select any request to check the body of the mail. Do execute to release the mail from outbox.
REPORT zemail_attach . TABLES: ekko. PARAMETERS: p_email TYPE somlreci1-receiver DEFAULT 'test@sapdev.co.uk'. TYPES: BEGIN OF t_ekpo, ebeln TYPE ekpo-ebeln, ebelp TYPE ekpo-ebelp, aedat TYPE ekpo-aedat, matnr TYPE ekpo-matnr, END OF t_ekpo. DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0, wa_ekpo TYPE t_ekpo. TYPES: BEGIN OF t_charekpo, ebeln(10) TYPE c, ebelp(5) TYPE c, aedat(8) TYPE c, matnr(18) TYPE c, END OF t_charekpo. DATA: wa_charekpo TYPE t_charekpo. DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE. DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE. DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE, t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE, t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE, t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE, t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE, w_cnt TYPE i, w_sent_all(1) TYPE c, w_doc_data LIKE sodocchgi1, gd_error TYPE sy-subrc, gd_reciever TYPE sy-subrc. ************************************************************************ *START_OF_SELECTION START-OF-SELECTION. * Retrieve sample data from table ekpo PERFORM data_retrieval. * Populate table with details to be entered into .xls file PERFORM build_xls_data_table. ************************************************************************ *END-OF-SELECTION END-OF-SELECTION. * Populate message body text PERFORM populate_email_message_body. * Send file by email as .xls speadsheet PERFORM send_file_as_email_attachment TABLES it_message it_attach USING p_email 'Example .xls document attachment' 'XLS' 'filename' ' ' ' ' ' ' CHANGING gd_error gd_reciever. * Instructs mail send program for SAPCONNECT to send email(rsconn01) PERFORM initiate_mail_execute_program. *&---------------------------------------------------------------------* *& Form DATA_RETRIEVAL *&---------------------------------------------------------------------* * Retrieve data form EKPO table and populate itab it_ekko *----------------------------------------------------------------------* FORM data_retrieval. SELECT ebeln ebelp aedat matnr UP TO 10 ROWS FROM ekpo INTO TABLE it_ekpo. ENDFORM. " DATA_RETRIEVAL *&---------------------------------------------------------------------* *& Form BUILD_XLS_DATA_TABLE *&---------------------------------------------------------------------* * Build data table for .xls document *----------------------------------------------------------------------* FORM build_xls_data_table. CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode con_tab TYPE x VALUE '09'. "OK for non Unicode *If you have Unicode check active in program attributes then you will *need to declare constants as follows *class cl_abap_char_utilities definition load. *constants: * con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB, * con_cret type c value cl_abap_char_utilities=>CR_LF. CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR' INTO it_attach SEPARATED BY con_tab. CONCATENATE con_cret it_attach INTO it_attach. APPEND it_attach. LOOP AT it_ekpo INTO wa_charekpo. CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp wa_charekpo-aedat wa_charekpo-matnr INTO it_attach SEPARATED BY con_tab. CONCATENATE con_cret it_attach INTO it_attach. APPEND it_attach. ENDLOOP. ENDFORM. " BUILD_XLS_DATA_TABLE *&---------------------------------------------------------------------* *& Form SEND_FILE_AS_EMAIL_ATTACHMENT *&---------------------------------------------------------------------* * Send email *----------------------------------------------------------------------* FORM send_file_as_email_attachment TABLES pit_message pit_attach USING p_email p_mtitle p_format p_filename p_attdescription p_sender_address p_sender_addres_type CHANGING p_error p_reciever. DATA: ld_error TYPE sy-subrc, ld_reciever TYPE sy-subrc, ld_mtitle LIKE sodocchgi1-obj_descr, ld_email LIKE somlreci1-receiver, ld_format TYPE so_obj_tp , ld_attdescription TYPE so_obj_nam , ld_attfilename TYPE so_obj_des , ld_sender_address LIKE soextreci1-receiver, ld_sender_address_type LIKE soextreci1-adr_typ, ld_receiver LIKE sy-subrc. ld_email = p_email. ld_mtitle = p_mtitle. ld_format = p_format. ld_attdescription = p_attdescription. ld_attfilename = p_filename. ld_sender_address = p_sender_address. ld_sender_address_type = p_sender_addres_type. * Fill the document data. w_doc_data-doc_size = 1. * Populate the subject/generic message attributes w_doc_data-obj_langu = sy-langu. w_doc_data-obj_name = 'SAPRPT'. w_doc_data-obj_descr = ld_mtitle . w_doc_data-sensitivty = 'F'. * Fill the document data and get size of attachment CLEAR w_doc_data. READ TABLE it_attach INDEX w_cnt. w_doc_data-doc_size = ( w_cnt - 1 ) * 255 + strlen( it_attach ). w_doc_data-obj_langu = sy-langu. w_doc_data-obj_name = 'SAPRPT'. w_doc_data-obj_descr = ld_mtitle. w_doc_data-sensitivty = 'F'. CLEAR t_attachment. REFRESH t_attachment. t_attachment[] = pit_attach[]. * Describe the body of the message CLEAR t_packing_list. REFRESH t_packing_list. t_packing_list-transf_bin = space. t_packing_list-head_start = 1. t_packing_list-head_num = 0. t_packing_list-body_start = 1. DESCRIBE TABLE it_message LINES t_packing_list-body_num. t_packing_list-doc_type = 'RAW'. APPEND t_packing_list. * Create attachment notification t_packing_list-transf_bin = 'X'. t_packing_list-head_start = 1. t_packing_list-head_num = 1. t_packing_list-body_start = 1. DESCRIBE TABLE t_attachment LINES t_packing_list-body_num. t_packing_list-doc_type = ld_format. t_packing_list-obj_descr = ld_attdescription. t_packing_list-obj_name = ld_attfilename. t_packing_list-doc_size = t_packing_list-body_num * 255. APPEND t_packing_list. * Add the recipients email address CLEAR t_receivers. REFRESH t_receivers. t_receivers-receiver = ld_email. t_receivers-rec_type = 'U'. t_receivers-com_type = 'INT'. t_receivers-notif_del = 'X'. t_receivers-notif_ndel = 'X'. APPEND t_receivers. CALL FUNCTION 'SO_DOCUMENT_SEND_API1' EXPORTING document_data = w_doc_data put_in_outbox = 'X' sender_address = ld_sender_address sender_address_type = ld_sender_address_type commit_work = 'X' IMPORTING sent_to_all = w_sent_all TABLES packing_list = t_packing_list contents_bin = t_attachment contents_txt = it_message receivers = t_receivers 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. * Populate zerror return code ld_error = sy-subrc. * Populate zreceiver return code LOOP AT t_receivers. ld_receiver = t_receivers-retrn_code. ENDLOOP. ENDFORM. "send_file_as_email_attachment *&---------------------------------------------------------------------* *& Form INITIATE_MAIL_EXECUTE_PROGRAM *&---------------------------------------------------------------------* * Instructs mail send program for SAPCONNECT to send email. *----------------------------------------------------------------------* FORM initiate_mail_execute_program. WAIT UP TO 2 SECONDS. SUBMIT rsconn01 WITH mode = 'INT' WITH output = 'X' AND RETURN. ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM *&---------------------------------------------------------------------* *& Form POPULATE_EMAIL_MESSAGE_BODY *&---------------------------------------------------------------------* * Populate message body text *----------------------------------------------------------------------* FORM populate_email_message_body. REFRESH it_message. it_message = 'Please find attached a list test ekpo records'. APPEND it_message. ENDFORM. " POPULATE_EMAIL_MESSAGE_BODY
Hi,
https://forums.sdn.sap.com/thread.jspa?messageID=3065528�
https://forums.sdn.sap.com/thread.jspa?messageID=2959234�
https://forums.sdn.sap.com/thread.jspa?messageID=2571717�
https://forums.sdn.sap.com/thread.jspa?messageID=2989716�
https://forums.sdn.sap.com/thread.jspa?messageID=2933362�
There are many threads like this to send external and internal emails from SAP. I thought to consolidate them. So, here is the code to send email from SAP with and with out attachments.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'REPORT zemail. DATA: itcpo LIKE itcpo, tab_lines LIKE sy-tabix. * Variables for EMAIL functionality DATA: maildata LIKE sodocchgi1. DATA: mailpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE. DATA: mailhead LIKE solisti1 OCCURS 1 WITH HEADER LINE. DATA: mailbin LIKE solisti1 OCCURS 10 WITH HEADER LINE. DATA: mailtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE. DATA: mailrec LIKE somlrec90 OCCURS 0 WITH HEADER LINE. DATA: solisti1 LIKE solisti1 OCCURS 0 WITH HEADER LINE. PERFORM send_form_via_email. ************************************************************************ * FORM SEND_FORM_VIA_EMAIL * ************************************************************************ FORM send_form_via_email. CLEAR: maildata, mailtxt, mailbin, mailpack, mailhead, mailrec. REFRESH: mailtxt, mailbin, mailpack, mailhead, mailrec. * Creation of the document to be sent File Name maildata-obj_name = 'TEST'. * Mail Subject maildata-obj_descr = 'Subject'. * Mail Contents mailtxt-line = 'Here is your file'. APPEND mailtxt. * Prepare Packing List PERFORM prepare_packing_list. * Set recipient - email address here!!! mailrec-receiver = 'you@yourcompany.com'. mailrec-rec_type = 'U'. APPEND mailrec. * Sending the document CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = maildata put_in_outbox = ' ' TABLES packing_list = mailpack object_header = mailhead contents_bin = mailbin contents_txt = mailtxt receivers = mailrec EXCEPTIONS too_many_receivers = 1 document_not_sent = 2 operation_no_authorization = 4 OTHERS = 99. IF sy-subrc = 0. SUBMIT rsconn01 WITH mode = 'INT' AND RETURN. ENDIF. ENDFORM. "send_form_via_email ************************************************************************ * Form PREPARE_PACKING_LIST ************************************************************************ FORM prepare_packing_list. CLEAR: mailpack, mailbin, mailhead. REFRESH: mailpack, mailbin, mailhead. DESCRIBE TABLE mailtxt LINES tab_lines. READ TABLE mailtxt INDEX tab_lines. maildata-doc_size = ( tab_lines - 1 ) * 255 + strlen( mailtxt ). * Creation of the entry for the compressed document CLEAR mailpack-transf_bin. mailpack-head_start = 1. mailpack-head_num = 0. mailpack-body_start = 1. mailpack-body_num = tab_lines. mailpack-doc_type = 'RAW'. APPEND mailpack. mailhead = 'TEST.TXT'. APPEND mailhead. * File 1 mailbin = 'This is file 1'. APPEND mailbin. DESCRIBE TABLE mailbin LINES tab_lines. mailpack-transf_bin = 'X'. mailpack-head_start = 1. mailpack-head_num = 1. mailpack-body_start = 1. mailpack-body_num = tab_lines. mailpack-doc_type = 'TXT'. mailpack-obj_name = 'TEST1'. mailpack-obj_descr = 'Subject'. mailpack-doc_size = tab_lines * 255. APPEND mailpack. *File 2 mailbin = 'This is file 2'. APPEND mailbin. DATA: start TYPE i. DATA: end TYPE i. start = tab_lines + 1. DESCRIBE TABLE mailbin LINES end. mailpack-transf_bin = 'X'. mailpack-head_start = 1. mailpack-head_num = 1. mailpack-body_start = start. mailpack-body_num = end. mailpack-doc_type = 'TXT'. mailpack-obj_name = 'TEST2'. mailpack-obj_descr = 'Subject'. mailpack-doc_size = tab_lines * 255. APPEND mailpack. ENDFORM. "prepare_packing_list *With PDF Attachment:* CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = 'Z_TEST' IMPORTING fm_name = v_fname. CALL FUNCTION v_fname EXPORTING control_parameters = x_ctrl_p IMPORTING job_output_info = x_output_data. CALL FUNCTION 'CONVERT_OTF' EXPORTING format = 'PDF' max_linewidth = 134 IMPORTING bin_filesize = v_size TABLES otf = x_output_data-otfdata lines = it_lines EXCEPTIONS err_max_linewidth = 1 err_format = 2 err_conv_not_possible = 3 OTHERS = 4. CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE' EXPORTING line_width_dst = 255 TABLES content_in = it_lines content_out = it_soli EXCEPTIONS err_line_width_src_too_long = 1 err_line_width_dst_too_long = 2 err_conv_failed = 3 OTHERS = 4. CALL FUNCTION 'FUNC_CONVERT_DATA_ODC01' EXPORTING iv_byte_mode = 'X' TABLES it_data = it_lines et_data = it_table. *-----To caluculate total number of lines of internal table DESCRIBE TABLE it_table LINES v_lines. *-----Create Message Body and Title and Description it_mess = 'successfully converted smartform from otf format to pdf' . APPEND it_mess. wa_doc_data-obj_name = 'smartform'. wa_doc_data-expiry_dat = sy-datum + 10. wa_doc_data-obj_descr = 'smartform'. wa_doc_data-sensitivty = 'F'. wa_doc_data-doc_size = v_lines * 255. APPEND it_pcklist. *-----PDF Attachment it_pcklist-transf_bin = 'X'. it_pcklist-head_start = 1. it_pcklist-head_num = 0. it_pcklist-body_start = 1. it_pcklist-doc_size = v_lines_bin * 255 . it_pcklist-body_num = v_lines. it_pcklist-doc_type = 'PDF'. it_pcklist-obj_name = 'smartform'. it_pcklist-obj_descr = 'smart_desc'. it_pcklist-obj_langu = 'E'. it_pcklist-doc_size = v_lines * 255. APPEND it_pcklist. *-----Giving the receiver email-id CLEAR it_receivers. it_receivers-receiver = 'abcd@yahoo.com'. it_receivers-rec_type = 'U'. APPEND it_receivers. *-----Calling the function module to sending email CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = wa_doc_data put_in_outbox = 'X' commit_work = 'X' TABLES packing_list = it_pcklist contents_txt = it_mess contents_hex = it_table receivers = it_receivers 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.
Here is the sample code for Emailing reports in HTML format
Code listing for: ZEMAIL
Description: Email Reports in HTML Format
REPORT zemail. DATA: send_request TYPE REF TO cl_bcs. DATA: text TYPE bcsy_text. DATA: document TYPE REF TO cl_document_bcs. DATA: sender_id TYPE REF TO if_sender_bcs. DATA: recipient TYPE REF TO if_recipient_bcs. DATA: bcs_exception TYPE REF TO cx_bcs. DATA: sent_to_all TYPE os_boolean. DATA: conlength TYPE i , conlengths TYPE so_obj_len , result_content TYPE string . DATA: content_length TYPE w3param-cont_len , content_type TYPE w3param-cont_type, return_code TYPE w3param-ret_code . DATA: listobject TYPE TABLE OF abaplist. DATA: html_wa TYPE w3html. DATA: html TYPE STANDARD TABLE OF w3html . DATA: wa_rec TYPE ad_smtpadr . DATA: bcs_message TYPE string . DATA: tmp_str TYPE string . DATA: prog TYPE programm , var TYPE raldb_vari . DATA: recepients TYPE bcsy_smtpa WITH HEADER LINE, return TYPE table_of_strings. DATA : v_rec(40). SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. PARAMETERS: report TYPE program, variant TYPE raldb_vari, sender TYPE ad_smtpadr, subject TYPE so_obj_des. SELECT-OPTIONS: s_rec FOR v_rec NO INTERVALS LOWER CASE. SELECTION-SCREEN END OF BLOCK b1. LOOP AT s_rec. TRANSLATE s_rec-low TO LOWER CASE. recepients = s_rec-low. APPEND recepients. CLEAR recepients . ENDLOOP. *recepients = 'seckharmc@gmail.com'. *append recepients. IF NOT recepients[] IS INITIAL . CLEAR: var, prog . MOVE: report TO prog , variant TO var . TRANSLATE prog TO UPPER CASE . TRANSLATE var TO UPPER CASE . SUBMIT (prog) USING SELECTION-SET var EXPORTING LIST TO MEMORY AND RETURN. CLEAR: listobject , html . REFRESH : listobject, html . CALL FUNCTION 'LIST_FROM_MEMORY' TABLES listobject = listobject. CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT' EXPORTING report_name = prog TABLES html = html listobject = listobject. CLEAR tmp_str . CLEAR : html_wa . LOOP AT html INTO html_wa . CONCATENATE tmp_str html_wa INTO tmp_str. ENDLOOP . CLEAR: conlength,conlengths . conlength = strlen( tmp_str ) . conlengths = conlength . TRY. CLEAR send_request . send_request = cl_bcs=>create_persistent( ). CLEAR document . document = cl_document_bcs=>create_document( i_type = 'HTM' i_text = html i_length = conlengths i_subject = subject ). * add document to send request CALL METHOD send_request->set_document( document ). CLEAR sender_id . sender_id = cl_cam_address_bcs=>create_internet_address( sender ). CALL METHOD send_request->set_sender EXPORTING i_sender = sender_id. CLEAR wa_rec . LOOP AT recepients INTO wa_rec . CLEAR recipient . recipient = cl_cam_address_bcs=>create_internet_address( wa_rec ). * add recipient with its respective attributes to send request CALL METHOD send_request->add_recipient EXPORTING i_recipient = recipient i_express = 'X'. ENDLOOP . CALL METHOD send_request->set_status_attributes EXPORTING i_requested_status = 'E' i_status_mail = 'E'. CALL METHOD send_request->set_send_immediately( 'X' ). * ---------- send document --------------------------------------- CALL METHOD send_request->send( EXPORTING i_with_error_screen = 'X' RECEIVING result = sent_to_all ). IF sent_to_all = 'X'. APPEND 'Mail sent successfully ' TO return . WRITE:/ 'Mail sent successfully '. ENDIF. COMMIT WORK. CATCH cx_bcs INTO bcs_exception. bcs_message = bcs_exception->get_text( ). APPEND bcs_message TO return . EXIT. ENDTRY. ELSE . APPEND 'Specify email address for sending' TO return . ENDIF . *Selection texts *--------------------------------------------------------------------* * REPORT Program Name * SENDER Sender's E-Mail ID * SUBJECT D . * S_REC Receiver Email IDs * VARIANT D . *--------------------------------------------------------------------*
REPORT z_demo_mail. *&---------------------------------------------------------------------* *& Global data declaration *&---------------------------------------------------------------------* DATA: w_document_data LIKE sodocchgi1. DATA: i_object_header TYPE STANDARD TABLE OF solisti1, w_object_header TYPE solisti1, i_object_content TYPE STANDARD TABLE OF solisti1, w_object_content TYPE solisti1, i_contents_hex TYPE STANDARD TABLE OF solix, w_contents_hex TYPE solix, i_object_para TYPE STANDARD TABLE OF soparai1, w_object_para TYPE soparai1, i_object_parb TYPE STANDARD TABLE OF soparbi1, w_object_parb TYPE soparbi1, i_receivers TYPE STANDARD TABLE OF somlreci1, w_receivers TYPE somlreci1. *&---------------------------------------------------------------------* *& Selection screen *&---------------------------------------------------------------------* PARAMETER : uname TYPE syuname DEFAULT sy-uname. *&---------------------------------------------------------------------* *& Start-of-selection event *&---------------------------------------------------------------------* START-OF-SELECTION. * Populate receiver info CLEAR: w_receivers. w_receivers-receiver = uname. w_receivers-rec_type = 'B'. APPEND w_receivers TO i_receivers. * Populate header data w_document_data-obj_name = 'Your action required'. w_document_data-obj_descr = 'Pl. press execute button'. w_document_data-sensitivty = 'O'. w_document_data-proc_type = 'R'. w_document_data-proc_name = 'RSINCL00'. * Populate mail content CLEAR: w_object_content. CONCATENATE 'Please execute report: ' w_document_data-proc_name INTO w_object_content-line SEPARATED BY space. APPEND w_object_content TO i_object_content. CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1' EXPORTING document_data = w_document_data document_type = 'RAW' TABLES object_content = i_object_content object_para = i_object_para receivers = i_receivers 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 s000(z_zzz_ca_messages) WITH 'Mail send successfully'(001). ENDIF.
Author: Himanshu Kanekar
Submitted: 14-Oct-2010
Related Links:
- http://wiki.sdn.sap.com/wiki/display/Snippets/XML+TAGS+simplifies+Excel+Download
- http://wiki.sdn.sap.com/wiki/display/ABAP/Exporting+data+to+Excel+-+XML+to+the+rescue
A very common requirement by the user is to export data to a Formatted Microsoft Excel Spreadsheet and send it to an Email or post it on a FTP Server. If the report is a simple ALV grid then the ALV control can do it automatically, but it would be a simple Excel Spreadsheet without any formatting. In order to create a Formatted Excel Sheet we can either use the OLE (Object Linking & Enabling) Concept or the XML method.
The OLE method involves opening an instance of Microsoft Excel and then preparing the sheet. The major disadvantage of this method is that it can be executed in Foreground only.
An ABAP Program can create an XML file and it can be opened directly into Excel. The advantages and possibilities are endless:
- An xml file is plain text so can be created on the Presentation Server or Application Server;
- It can be sent as an Attachment to an Email;
- Colours, Fonts, Number Formats and so on can be specified;
- Formatting can be applied to Rows, Columns or Single Cells;
- Column Heights and Widths can be specified, or Auto-Formatted;
- Multiple Worksheets can be created;
- Formulas can be entered in cells;
This is a Sample Code for fetching the User Login Details and sending it as an XLS attachment to an Email using the XML method -
REPORT sy-repid. TYPE-POOLS: ixml. *------------------------------------------------------------------------* * Data Declarations * *------------------------------------------------------------------------* * Structure for Final Internal Table TYPES: BEGIN OF ty_final, srno(3) TYPE n, user_id TYPE usr02-bname, full_name TYPE bapiaddr3-fullname, dept TYPE bapiaddr3-department, login(3) TYPE c, END OF ty_final. * Structure for USR02 TYPES: BEGIN OF ty_usr02, bname TYPE usr02-bname, trdat TYPE usr02-trdat, END OF ty_usr02. * Internal Table & Work Area for Final Internal Table DATA: it_final TYPE TABLE OF ty_final, wa_final TYPE ty_final. * Internal Table & Work Area for USR02 Internal Table DATA: it_usr02 TYPE TABLE OF ty_usr02, wa_usr02 TYPE ty_usr02. * Work Area for ADD3_DATA Structre DATA: wa_addr TYPE bapiaddr3. DATA: it_return TYPE TABLE OF bapiret2. DATA: lv_date TYPE d. DATA: lv_filename TYPE string. TYPES: BEGIN OF xml_line, data(255) TYPE x, END OF xml_line. DATA: l_ixml TYPE REF TO if_ixml, l_streamfactory TYPE REF TO if_ixml_stream_factory, l_ostream TYPE REF TO if_ixml_ostream, l_renderer TYPE REF TO if_ixml_renderer, l_document TYPE REF TO if_ixml_document. DATA: l_element_root TYPE REF TO if_ixml_element, ns_attribute TYPE REF TO if_ixml_attribute, r_element_properties TYPE REF TO if_ixml_element, r_element TYPE REF TO if_ixml_element, r_worksheet TYPE REF TO if_ixml_element, r_table TYPE REF TO if_ixml_element, r_column TYPE REF TO if_ixml_element, r_row TYPE REF TO if_ixml_element, r_cell TYPE REF TO if_ixml_element, r_data TYPE REF TO if_ixml_element, l_value TYPE string, l_type TYPE string, l_text(100) TYPE c, r_styles TYPE REF TO if_ixml_element, r_style TYPE REF TO if_ixml_element, r_style1 TYPE REF TO if_ixml_element, r_format TYPE REF TO if_ixml_element, r_border TYPE REF TO if_ixml_element, num_rows TYPE i. DATA: l_xml_table TYPE TABLE OF xml_line, wa_xml TYPE xml_line, l_xml_size TYPE i, l_rc TYPE i. *------------------------------------------------------------------------* * Initialization * *------------------------------------------------------------------------* INITIALIZATION. lv_date = sy-datum - 1. *------------------------------------------------------------------------* * Start of Selection * *------------------------------------------------------------------------* START-OF-SELECTION. PERFORM get_user_data. PERFORM process_xml_data. PERFORM send_mail. *&---------------------------------------------------------------------* *& Form get_user_data *&---------------------------------------------------------------------* * Fetch User details from USR02 *----------------------------------------------------------------------* FORM get_user_data. REFRESH it_final. SELECT DISTINCT bname trdat FROM usr02 INTO TABLE it_usr02. SORT it_usr02 BY bname. IF NOT it_usr02[] IS INITIAL. LOOP AT it_usr02 INTO wa_usr02. CLEAR wa_final. wa_final-srno = sy-tabix. " Serial No. wa_final-user_id = wa_usr02-bname. " User ID CALL FUNCTION 'BAPI_USER_GET_DETAIL' EXPORTING username = wa_usr02-bname IMPORTING address = wa_addr TABLES return = it_return. IF sy-subrc EQ 0. wa_final-full_name = wa_addr-fullname. " Full Name wa_final-dept = wa_addr-department. " Department ENDIF. IF wa_usr02-trdat EQ lv_date. wa_final-login = 'YES'. " Login on Previous Day ELSE. wa_final-login = 'NO'. ENDIF. APPEND wa_final TO it_final. ENDLOOP. ENDIF. ENDFORM. " get_user_data *&---------------------------------------------------------------------* *& Form SEND_MAIL *&---------------------------------------------------------------------* * Send Email *----------------------------------------------------------------------* FORM send_mail. DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE. DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE. DATA: objbin LIKE solix OCCURS 10 WITH HEADER LINE. DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE. DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE. DATA: doc_chng LIKE sodocchgi1. DATA: tab_lines LIKE sy-tabix. DATA: l_num(3). DATA: subj_date(10) TYPE c. * Mail Subject CONCATENATE lv_date+6(2) '-' lv_date+4(2) '-' lv_date+0(4) INTO subj_date. CONCATENATE 'SAP Application Usage Report ' subj_date INTO doc_chng-obj_descr SEPARATED BY space. * Mail Contents objtxt = 'Dear User,'. APPEND objtxt. CLEAR objtxt. APPEND objtxt. CONCATENATE 'Please find the attached SAP Application Usage Report for ' subj_date INTO objtxt SEPARATED BY space. " Mail Contents APPEND objtxt. CLEAR objtxt. APPEND objtxt. objtxt = 'Thanks & Regards,'. APPEND objtxt. objtxt = 'Himanshu Kanekar'. APPEND objtxt. DESCRIBE TABLE objtxt LINES tab_lines. READ TABLE objtxt INDEX tab_lines. doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ). * Packing List For the E-mail Body objpack-head_start = 1. objpack-head_num = 0. objpack-body_start = 1. objpack-body_num = tab_lines. objpack-doc_type = 'RAW'. APPEND objpack. * Creation of the Document Attachment LOOP AT l_xml_table INTO wa_xml. CLEAR objbin. objbin-line = wa_xml-data. APPEND objbin. ENDLOOP. DESCRIBE TABLE objbin LINES tab_lines. objhead = 'SAP Login Details'. APPEND objhead. * Packing List For the E-mail Attachment objpack-transf_bin = 'X'. objpack-head_start = 1. objpack-head_num = 0. objpack-body_start = 1. objpack-body_num = tab_lines. CONCATENATE 'SAP_Login_Details' subj_date INTO objpack-obj_descr SEPARATED BY space. objpack-doc_type = 'XLS'. objpack-doc_size = tab_lines * 255. APPEND objpack. * Target Recipent CLEAR reclist. reclist-receiver = 'user@company.com'. reclist-rec_type = 'U'. APPEND reclist. * Sending the document CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = doc_chng put_in_outbox = 'X' TABLES packing_list = objpack object_header = objhead contents_txt = objtxt contents_hex = objbin receivers = reclist EXCEPTIONS too_many_receivers = 1 document_not_sent = 2 operation_no_authorization = 4 OTHERS = 99. ENDFORM. " SEND_MAIL *&---------------------------------------------------------------------* *& Form process_xml_data *&---------------------------------------------------------------------* * Process XML Data *----------------------------------------------------------------------* FORM process_xml_data . * Creating a ixml Factory l_ixml = cl_ixml=>create( ). * Creating the DOM Object Model l_document = l_ixml->create_document( ). * Create Root Node 'Workbook' l_element_root = l_document->create_simple_element( name = 'Workbook' parent = l_document ). l_element_root->set_attribute( name = 'xmlns' value = 'urn:schemas-microsoft-com:office:spreadsheet' ). ns_attribute = l_document->create_namespace_decl( name = 'ss' prefix = 'xmlns' uri = 'urn:schemas-microsoft-com:office:spreadsheet' ). l_element_root->set_attribute_node( ns_attribute ). ns_attribute = l_document->create_namespace_decl( name = 'x' prefix = 'xmlns' uri = 'urn:schemas-microsoft-com:office:excel' ). l_element_root->set_attribute_node( ns_attribute ). * Create node for document properties. r_element_properties = l_document->create_simple_element( name = 'TEST_REPORT' parent = l_element_root ). l_value = sy-uname. l_document->create_simple_element( name = 'Author' value = l_value parent = r_element_properties ). * Styles r_styles = l_document->create_simple_element( name = 'Styles' parent = l_element_root ). * Style for Header r_style = l_document->create_simple_element( name = 'Style' parent = r_styles ). r_style->set_attribute_ns( name = 'ID' prefix = 'ss' value = 'Header' ). r_format = l_document->create_simple_element( name = 'Font' parent = r_style ). r_format->set_attribute_ns( name = 'Bold' prefix = 'ss' value = '1' ). r_format = l_document->create_simple_element( name = 'Interior' parent = r_style ). r_format->set_attribute_ns( name = 'Color' prefix = 'ss' value = '#92D050' ). r_format->set_attribute_ns( name = 'Pattern' prefix = 'ss' value = 'Solid' ). r_format = l_document->create_simple_element( name = 'Alignment' parent = r_style ). r_format->set_attribute_ns( name = 'Vertical' prefix = 'ss' value = 'Center' ). r_format->set_attribute_ns( name = 'WrapText' prefix = 'ss' value = '1' ). r_border = l_document->create_simple_element( name = 'Borders' parent = r_style ). r_format = l_document->create_simple_element( name = 'Border' parent = r_border ). r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Bottom' ). r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ). r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ). r_format = l_document->create_simple_element( name = 'Border' parent = r_border ). r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Left' ). r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ). r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ). r_format = l_document->create_simple_element( name = 'Border' parent = r_border ). r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Top' ). r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ). r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ). r_format = l_document->create_simple_element( name = 'Border' parent = r_border ). r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Right' ). r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ). r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ). * Style for Data r_style1 = l_document->create_simple_element( name = 'Style' parent = r_styles ). r_style1->set_attribute_ns( name = 'ID' prefix = 'ss' value = 'Data' ). r_border = l_document->create_simple_element( name = 'Borders' parent = r_style1 ). r_format = l_document->create_simple_element( name = 'Border' parent = r_border ). r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Bottom' ). r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ). r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ). r_format = l_document->create_simple_element( name = 'Border' parent = r_border ). r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Left' ). r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ). r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ). r_format = l_document->create_simple_element( name = 'Border' parent = r_border ). r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Top' ). r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ). r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ). r_format = l_document->create_simple_element( name = 'Border' parent = r_border ). r_format->set_attribute_ns( name = 'Position' prefix = 'ss' value = 'Right' ). r_format->set_attribute_ns( name = 'LineStyle' prefix = 'ss' value = 'Continuous' ). r_format->set_attribute_ns( name = 'Weight' prefix = 'ss' value = '1' ). * Worksheet r_worksheet = l_document->create_simple_element( name = 'Worksheet' parent = l_element_root ). r_worksheet->set_attribute_ns( name = 'Name' prefix = 'ss' value = 'Sheet1' ). * Table r_table = l_document->create_simple_element( name = 'Table' parent = r_worksheet ). r_table->set_attribute_ns( name = 'FullColumns' prefix = 'x' value = '1' ). r_table->set_attribute_ns( name = 'FullRows' prefix = 'x' value = '1' ). * Column Formatting r_column = l_document->create_simple_element( name = 'Column' parent = r_table ). r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '40' ). r_column = l_document->create_simple_element( name = 'Column' parent = r_table ). r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '90' ). r_column = l_document->create_simple_element( name = 'Column' parent = r_table ). r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '140' ). r_column = l_document->create_simple_element( name = 'Column' parent = r_table ). r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '150' ). r_column = l_document->create_simple_element( name = 'Column' parent = r_table ). r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '90' ). * Blank Row r_row = l_document->create_simple_element( name = 'Row' parent = r_table ). * Column Headers Row r_row = l_document->create_simple_element( name = 'Row' parent = r_table ). r_row->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '1' ). * Sr. No. r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ). r_data = l_document->create_simple_element( name = 'Data' value = 'Sr. No.' parent = r_cell ). r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). * User Name r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ). r_data = l_document->create_simple_element( name = 'Data' value = 'User Name' parent = r_cell ). r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). * Full Name r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ). r_data = l_document->create_simple_element( name = 'Data' value = 'Full Name' parent = r_cell ). r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). * Department r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ). r_data = l_document->create_simple_element( name = 'Data' value = 'Department' parent = r_cell ). r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). * Login r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ). CONCATENATE 'Login - ' lv_date+6(2) '/' lv_date+4(2) '/' lv_date+0(4) INTO l_value. r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). * Blank Row after Column Headers r_row = l_document->create_simple_element( name = 'Row' parent = r_table ). r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ). r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ). r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ). r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ). r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ). * Data Table LOOP AT it_final INTO wa_final. r_row = l_document->create_simple_element( name = 'Row' parent = r_table ). * Sr. No. r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ). l_value = sy-tabix. CONDENSE l_value NO-GAPS. r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'Number' ). " Cell format * User Name r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ). l_value = wa_final-user_id. r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format * Full Name r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ). l_value = wa_final-full_name. r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format * Department r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ). l_value = wa_final-dept. r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format * Login r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ). l_value = wa_final-login. r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format ENDLOOP. * Creating a Stream Factory l_streamfactory = l_ixml->create_stream_factory( ). * Connect Internal XML Table to Stream Factory l_ostream = l_streamfactory->create_ostream_itable( table = l_xml_table ). * Rendering the Document l_renderer = l_ixml->create_renderer( ostream = l_ostream document = l_document ). l_rc = l_renderer->render( ). * Saving the XML Document l_xml_size = l_ostream->get_num_written_raw( ). ENDFORM. " process_xml_data
The output of the Report is a Formatted Excel Sheet as an email attachment.
END-OF-SELECTION. IF getfile EQ 'X'. IF NOT t_app_letr[] IS INITIAL. PERFORM mail_merge_data_to_ms_word. ELSE. WRITE: / 'NO DATA AVAILABLE FOR THIS SELECTION!'. ENDIF. ENDIF. *&---------------------------------------------------------------------* *& Form MAIL_MERGE_DATA_TO_MS_WORD *&---------------------------------------------------------------------* * Enclosing the other sub modules for the easy maintenance *----------------------------------------------------------------------* * No Parameters for this subroutine *----------------------------------------------------------------------* FORM mail_merge_data_to_ms_word . PERFORM clear_existing_data_file. PERFORM download_employee_data_to_pc. PERFORM start_ms_word. PERFORM fill_ms_word_with_data. ENDFORM. " MAIL_MERGE_DATA_TO_MS_WORD *&---------------------------------------------------------------------* *& FORM CLEAR_EXISTING_DATA_FILE *&---------------------------------------------------------------------* * Clearing the existing DATA file used for Merge *----------------------------------------------------------------------* * No Parameters for this subroutine *----------------------------------------------------------------------* FORM clear_existing_data_file . DATA: file_name TYPE string. DATA: result TYPE abap_bool. DATA: rc TYPE i. file_name = twrkfile. CALL METHOD cl_gui_frontend_services=>file_exist EXPORTING file = file_name RECEIVING result = result EXCEPTIONS cntl_error = 1 error_no_gui = 2 wrong_parameter = 3 OTHERS = 4. CALL METHOD cl_gui_cfw=>flush. IF result EQ abap_true. CALL METHOD cl_gui_frontend_services=>file_delete EXPORTING filename = file_name CHANGING rc = rc EXCEPTIONS OTHERS = 0. * FLUSH TO EXECUTE THE DELETION CALL METHOD cl_gui_cfw=>flush. ENDIF. ENDFORM. " CLEAR_EXISTING_DATA_FILE *&---------------------------------------------------------------------* *& FORM DOWNLAOD_EMPLOYEE_DATA_TO_PC *&---------------------------------------------------------------------* * Download here for e.g. employee data to PC (Data File) *----------------------------------------------------------------------* * No Parameters passed to this subroutine *----------------------------------------------------------------------* FORM download_employee_data_to_pc. DATA: file_name TYPE string. DATA: cnt TYPE i. DATA: lt_download TYPE STANDARD TABLE OF string, lv_download TYPE string, lv_hstr(1024) TYPE c. CLASS cl_abap_char_utilities DEFINITION LOAD. CONSTANTS: lc_tab TYPE string VALUE cl_abap_char_utilities=>horizontal_tab. FIELD-SYMBOLS: <field> TYPE any, <data_tab_wa> TYPE any. PERFORM get_all_field_names. CLEAR lv_download. LOOP AT fieldnames. WRITE fieldnames TO lv_hstr LEFT-JUSTIFIED. IF sy-tabix > 1. CONCATENATE lv_download lc_tab lv_hstr INTO lv_download. ELSE. CONCATENATE lv_download lv_hstr INTO lv_download. ENDIF. ENDLOOP. APPEND lv_download TO lt_download. * THEN THE DATA TABLE LOOP AT t_app_letr ASSIGNING <data_tab_wa>. cnt = 0. CLEAR lv_download. sy-subrc = 0. WHILE sy-subrc = 0. cnt = cnt + 1. ASSIGN COMPONENT cnt OF STRUCTURE <data_tab_wa> TO <field>. CHECK sy-subrc = 0. WRITE <field> TO lv_hstr LEFT-JUSTIFIED. IF cnt > 1. CONCATENATE lv_download lc_tab lv_hstr INTO lv_download. ELSE. CONCATENATE lv_download lv_hstr INTO lv_download. ENDIF. ENDWHILE. APPEND lv_download TO lt_download. ENDLOOP. file_name = twrkfile. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = file_name write_field_separator = 'X' trunc_trailing_blanks = 'X' TABLES data_tab = lt_download EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22. IF sy-subrc <> 0. CASE sy-subrc. WHEN 1. RAISE file_write_error. WHEN 2. RAISE no_batch. WHEN 3. RAISE gui_refuse_filetransfer. WHEN 4. RAISE invalid_type . WHEN 5. RAISE no_authority. WHEN 6. RAISE unknown_error. WHEN 7. RAISE header_not_allowed. WHEN 8. RAISE separator_not_allowed. WHEN 9. RAISE filesize_not_allowed. WHEN 10. RAISE header_too_long. WHEN 11. RAISE dp_error_create. WHEN 12. RAISE dp_error_send. WHEN 13. RAISE dp_error_write. WHEN 14. RAISE unknown_dp_error. WHEN 15. RAISE access_denied. WHEN 16. RAISE dp_out_of_memory. WHEN 17. RAISE disk_full. WHEN 18. RAISE dp_timeout. WHEN 19. RAISE file_not_found. WHEN 20. RAISE dataprovider_exception. WHEN 21. RAISE control_flush_error. WHEN OTHERS. RAISE unknown_error. ENDCASE. ENDIF. ENDFORM. " DOWNLAOD_EMPLOYEE_DATA_TO_PC *&---------------------------------------------------------------------* *& FORM OPEN_MS_WORD *&---------------------------------------------------------------------* * Opens the MS Word Document *----------------------------------------------------------------------* * No parameters passed here. *----------------------------------------------------------------------* FORM start_ms_word . DATA: xcode LIKE sy-xcode, ok_code LIKE sy-xcode, rc TYPE i, platform TYPE i, registry_entry(255) TYPE c, reg_value TYPE string, temp_dir TYPE string. DATA: version_str(80) TYPE c, word_version TYPE i. DATA: documents TYPE ole2_object. * START WITH OLE AUTOMATION CALL METHOD cl_gui_frontend_services=>registry_get_value EXPORTING root = cl_gui_frontend_services=>hkey_classes_root key = 'WORD.BASIC\CURVER' value = '' IMPORTING reg_value = reg_value EXCEPTIONS get_regvalue_failed = 1 cntl_error = 2 error_no_gui = 3 OTHERS = 4. IF sy-subrc <> 0. RAISE download_problem. ENDIF. CALL METHOD cl_gui_cfw=>flush. version_str = reg_value. SHIFT version_str LEFT BY 11 PLACES. MOVE version_str TO word_version. IF word_version < 8. CREATE OBJECT wordobj 'WORD.BASIC'. ELSE. CREATE OBJECT worddoc 'WORD.DOCUMENT'. GET PROPERTY OF worddoc 'APPLICATION' = wordapp. SET PROPERTY OF wordapp 'VISIBLE' = 1. GET PROPERTY OF wordapp 'WORDBASIC' = wordobj. CALL METHOD OF wordobj 'FILECLOSE'. ENDIF. CALL METHOD OF wordobj 'APPSHOW'. * SERIENBRIEFDATEI ЖFFNEN IF word_version > 8. GET PROPERTY OF wordapp 'DOCUMENTS' = documents. CALL METHOD OF documents 'OPEN' EXPORTING #01 = dwrkfile "FILE NAME #02 = 0. "CONFIRM CONVERSION ELSE. CALL METHOD OF wordobj 'FILEOPEN' EXPORTING #01 = dwrkfile #02 = 0. ENDIF. ENDFORM. " OPEN_MS_WORD *&---------------------------------------------------------------------* *& FORM FILL_MS_WORD_WITH_DATA *&---------------------------------------------------------------------* * Fills the MS word merge fields with data *----------------------------------------------------------------------* * No parameters passed for this subroutine *----------------------------------------------------------------------* FORM fill_ms_word_with_data . DATA: passwort(15). CALL METHOD OF wordobj 'MAILMERGEMAINDOCUMENTTYPE' EXPORTING #01 = 0. CALL METHOD OF wordobj 'MAILMERGEOPENDATASOURCE' EXPORTING #01 = twrkfile #02 = 0 #03 = 1 #04 = 0 #05 = 0 #06 = passwort. CALL METHOD OF wordobj 'MAILMERGEEDITMAINDOCUMENT'. CALL METHOD OF wordobj 'MAILMERGETODOC'. ENDFORM. " FILL_MS_WORD_WITH_DATA *&---------------------------------------------------------------------* *& FORM GET_ALL_FIELD_NAMES *&---------------------------------------------------------------------* * Gets all the field names from the input word file name *----------------------------------------------------------------------* * No parameters for this subroutine. *----------------------------------------------------------------------* FORM get_all_field_names. TYPE-POOLS: sydes. TYPE-POOLS slis. DATA: td TYPE sydes_desc. DATA: name_header TYPE sydes_nameinfo. DATA: name LIKE name_header. DATA: types_header TYPE sydes_typeinfo. DATA: type LIKE types_header. DATA: prev_tabix LIKE sy-tabix. DATA: continue_field(1) TYPE c. DATA: search_str(40) TYPE c. DATA: s_length(5) TYPE p. DATA: BEGIN OF stru_tab OCCURS 0, name(30) TYPE c, fldname(30) TYPE c, index LIKE sy-tabix, length(3) TYPE n, type(1) TYPE c, decimals(2) TYPE n, END OF stru_tab. CLEAR: td. DESCRIBE FIELD t_app_letr INTO td. CLEAR: stru_tab[], stru_tab. DO 1000 TIMES. READ TABLE td-types INTO types_header INDEX sy-index. IF sy-subrc NE 0. EXIT. ENDIF. type = types_header. stru_tab-index = type-idx_name. stru_tab-type = type-type. stru_tab-length = type-length. stru_tab-decimals = type-decimals. CHECK stru_tab-index NE 0. APPEND stru_tab. ENDDO. DO 1000 TIMES. READ TABLE td-names INTO name_header INDEX sy-index. IF sy-subrc NE 0. EXIT. ENDIF. name = name_header. IF continue_field NE space. READ TABLE stru_tab INDEX prev_tabix. IF sy-subrc EQ 0. CONCATENATE stru_tab-fldname name-name INTO stru_tab-fldname. MODIFY stru_tab INDEX prev_tabix. CLEAR: prev_tabix, continue_field. ENDIF. ELSE. LOOP AT stru_tab WHERE index EQ sy-index. stru_tab-fldname = name-name. prev_tabix = sy-tabix. MODIFY stru_tab. ENDLOOP. ENDIF. IF name-continue EQ '*'. continue_field = 'X'. ELSE. continue_field = space. ENDIF. ENDDO. * NOW BUILD FIELDNAMES LOOP AT stru_tab. fieldnames-field = stru_tab-fldname. APPEND fieldnames. ENDLOOP. ENDFORM. " GET_ALL_FIELD_NAMES
*&---------------------------------------------------------------------* *& Report ZNVK_SEND_HTML_MAIL *& *&---------------------------------------------------------------------* *following blog will tell you that how to end a email as other webmails. *following Example wil show you that how the Employee data will come in a HTML format *&---------------------------------------------------------------------* REPORT znvk_send_html_mail. *Diclare a types to hold the Employee data TYPES:BEGIN OF ty_employee, pernr TYPE pa0002-pernr, begda TYPE pa0002-begda, endda TYPE pa0002-endda, vorna TYPE pa0002-vorna, nachn TYPE pa0002-nachn, END OF ty_employee. *Diclate a types for employee data table TYPES:tt_employee TYPE STANDARD TABLE OF ty_employee. *Diclate a workarea to hold the Employee data DATA: gf_employee TYPE ty_employee. *Diclate a table to hold the Employee data DATA: gt_employee TYPE tt_employee. *All the diclarations to send the email is same for this also *except that diclare the doc type specify as HTML DATA: *- Structure to hold Output Details in delimited format gf_output_soli TYPE soli, *- Structure to hold Imported Object Components gf_objpack TYPE sopcklsti1, *- Structure to hold data in single line format gf_objhead TYPE solisti1, *- Structure to hold data in single line format gf_objtxt TYPE solisti1, *- Structure to hold data for API Recipient List gf_reclist TYPE somlreci1, *- Structure to hold email data gf_doc_chng TYPE sodocchgi1, *- Internal Table to hold Output Details in delimited format gt_output_soli TYPE TABLE OF soli, *- Internal Table to hold Imported Object Components gt_objpack TYPE TABLE OF sopcklsti1, *- Internal Table to hold data in single line format gt_objhead TYPE TABLE OF solisti1, *- Internal Table to hold data in single line format gt_objtxt TYPE TABLE OF solisti1, *- Internal Table to hold data for API Recipient List gt_reclist TYPE TABLE OF somlreci1. DATA:BEGIN OF lt_emp OCCURS 0, emp TYPE pa0001-pernr, END OF lt_emp. DATA:l_begda(10), l_endda(10). DATA: g_lines TYPE sy-tabix, "To hold number of records g_msg_lines TYPE sy-tabix, "To hold number of records g_sent_all(1) TYPE c. ** C O N S T A N T S ** CONSTANTS : c_int(3) TYPE c VALUE 'INT', "Internet mail address c_doc_type_htm(3) TYPE c VALUE 'HTM', "Code for document class c_rec_type TYPE c VALUE 'U', "Recipient type c_express TYPE c VALUE 'X'. "Send express START-OF-SELECTION. *Hotcoaded few employee numbers lt_emp-emp = 00000003. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000004. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000005. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000006. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000007. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000008. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000009. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000010. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000012. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000013. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000014. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000015. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000016. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000017. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000018. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000024. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000025. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000027. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000028. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000029. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000030. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000032. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000033. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000034. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000035. APPEND lt_emp.CLEAR lt_emp. lt_emp-emp = 00000036. APPEND lt_emp.CLEAR lt_emp. *select to get the employee Biodata SELECT pernr begda endda vorna nachn FROM pa0002 INTO TABLE gt_employee FOR ALL ENTRIES IN lt_emp WHERE pernr = lt_emp-emp. *Once the Employee Diodata came *As following we can pripare the html Body format *Set the Subject line gf_doc_chng-obj_name = 'HTML Format Email from SAP'. gf_doc_chng-obj_descr = 'HTML Format Email from SAP'. *Set the Body background colour gf_objtxt-line = '<body bgcolor = "#E6E6FA">'. *- Append APPEND gf_objtxt TO gt_objtxt. *- Clear CLEAR gf_objtxt. *Set font color and its type CONCATENATE '<FONT COLOR = "#191970" face="Garamond">' '<b>' INTO gf_objtxt-line. *- Append APPEND gf_objtxt TO gt_objtxt. *- Clear CLEAR gf_objtxt. *Pripare mail body CONCATENATE '<p>' 'Dear Sir/Madam,' '</p>' INTO gf_objtxt-line. *- Append APPEND gf_objtxt TO gt_objtxt. *- Clear CLEAR gf_objtxt. gf_objtxt-line = space. *- Append APPEND gf_objtxt TO gt_objtxt. *- Clear CLEAR gf_objtxt. CONCATENATE '<p>' ' The following employee has updated His/Her profile.' '</p>' INTO gf_objtxt-line SEPARATED BY space. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. gf_objtxt-line = '<center>'. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. * Pripare Employee data in table format to dispay in Mail body gf_objtxt-line = '<TABLE width= "100%" border="1">'. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. CONCATENATE '<TR ><td align = "LEFT" BGCOLOR = "#708090">' '<FONT COLOR = "BLUE"><B>Employee number</B> </FONT>' '</td>' INTO gf_objtxt-line. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. CONCATENATE '<td align = "LEFT" BGCOLOR = "#708090">' '<FONT COLOR = "BLUE"> <B>Begin Date</B> </FONT>' '</td>' INTO gf_objtxt-line. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. CONCATENATE '<td align = "LEFT" BGCOLOR = "#708090">' '<FONT COLOR = "BLUE"><B>End date</B> </FONT>' '</td>' INTO gf_objtxt-line. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. CONCATENATE '<td align = "LEFT" BGCOLOR = "#708090">' ' <FONT COLOR = "BLUE"><B>first name</B> </FONT>' '</td>' INTO gf_objtxt-line. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. CONCATENATE '<td align = "LEFT" BGCOLOR = "#708090">' '<FONT COLOR = "BLUE"><B>last name</B> </FONT>' '</td></tr>' INTO gf_objtxt-line. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. LOOP AT gt_employee INTO gf_employee. WRITE: gf_employee-begda TO l_begda. WRITE: gf_employee-endda TO l_endda. CONCATENATE '<TR><td align = "LEFT">' '<FONT COLOR = "BLUE">' gf_employee-pernr '</FONT>' '</td>' INTO gf_objtxt-line. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. CONCATENATE '<td align = "LEFT">' '<FONT COLOR = "BLUE">' l_begda '</FONT>' '</td>' INTO gf_objtxt-line. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. CONCATENATE '<td align = "LEFT">' '<FONT COLOR = "BLUE">' l_endda '</FONT>' '</td>' INTO gf_objtxt-line. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. CONCATENATE '<td align = "LEFT">' '<FONT COLOR = "BLUE">' gf_employee-vorna '</FONT>' '</td>' INTO gf_objtxt-line. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. CONCATENATE '<td align = "LEFT">' '<FONT COLOR = "BLUE">' gf_employee-nachn '</FONT>' '</td></tr>' INTO gf_objtxt-line. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. ENDLOOP. gf_objtxt-line = '</TABLE>'. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. gf_objtxt-line = '</center>'. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. CONCATENATE '<p>' ' Please confirm the appropriate actions' 'have taken place in regards to this change' '</p>' INTO gf_objtxt-line SEPARATED BY space. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. CONCATENATE '<p>' ' For further questions, please contact HR Direct' '</p>' INTO gf_objtxt-line SEPARATED BY space. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. gf_objtxt-line = 'Regards,<br />'. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. gf_objtxt-line = 'Vamsi<br />'. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. gf_objtxt-line = '<br><br><b><center><i><font color = "RED">This is an auto generated Email.'. APPEND gf_objtxt TO gt_objtxt. CLEAR gf_objtxt. gf_objtxt-line = '</FONT></body>'. *- Append APPEND gf_objtxt TO gt_objtxt. *- Clear CLEAR gf_objtxt. END-OF-SELECTION. DESCRIBE TABLE gt_objtxt LINES g_msg_lines. READ TABLE gt_objtxt INTO gf_objtxt INDEX g_msg_lines. gf_doc_chng-doc_size = ( g_msg_lines - 1 ) * 255 + strlen( gf_objtxt ). *- Creation of the entry for the compressed document gf_objpack-transf_bin = ' '. gf_objpack-head_start = 1. gf_objpack-head_num = 0. gf_objpack-body_start = 1. gf_objpack-body_num = g_msg_lines. gf_objpack-doc_type = c_doc_type_htm. *- Append APPEND gf_objpack TO gt_objpack. *- Clear CLEAR gf_objpack. *- Creation of the document attachment *- Describe DESCRIBE TABLE gt_output_soli LINES g_lines. *- Don't create attachment if no data is present IF g_lines <> 0. LOOP AT gt_output_soli INTO gf_output_soli. gf_objtxt = gf_output_soli. *- Append APPEND gf_objtxt TO gt_objtxt. *- Clear CLEAR gf_objtxt. ENDLOOP. ENDIF. *- Completing the recipient list gf_reclist-receiver = 'vamsin@intelligroup.com'. gf_reclist-rec_type = c_rec_type. gf_reclist-express = c_express. *- Append APPEND gf_reclist TO gt_reclist. *- Clear CLEAR gf_reclist. CALL FUNCTION 'SO_DOCUMENT_SEND_API1' EXPORTING document_data = gf_doc_chng put_in_outbox = 'X' sender_address = 'NTWDEV' commit_work = 'X' IMPORTING sent_to_all = g_sent_all TABLES packing_list = gt_objpack object_header = gt_objhead 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. cl_os_transaction_end_notifier=>raise_commit_requested( ). CALL FUNCTION 'DB_COMMIT'. cl_os_transaction_end_notifier=>raise_commit_finished( ). ENDIF.
*send email notification to user using PDF attachment DATA: lv_filesize TYPE i, lv_buffer TYPE string, lv_attachment TYPE i, lv_testo TYPE i. DATA: li_pdfdata TYPE STANDARD TABLE OF tline, li_mess_att TYPE STANDARD TABLE OF solisti1, li_mtab_pdf TYPE STANDARD TABLE OF tline, li_objpack TYPE STANDARD TABLE OF sopcklsti1, li_objtxt TYPE STANDARD TABLE OF solisti1, li_objbin TYPE STANDARD TABLE OF solisti1, li_reclist TYPE STANDARD TABLE OF somlreci1, li_objhead TYPE soli_tab. DATA: lwa_pdfdata TYPE tline, lwa_objpack TYPE sopcklsti1, lwa_mess_att TYPE solisti1, lwa_objtxt TYPE solisti1, lwa_objbin TYPE solisti1, lwa_reclist TYPE somlreci1, lwa_doc_chng TYPE sodocchgi1. CONSTANTS: lc_u TYPE char1 VALUE 'U', lc_0 TYPE char1 VALUE '0', lc_1 TYPE char1 VALUE '1', lc_pdf TYPE char3 VALUE 'PDF', lc_raw TYPE char3 VALUE 'RAW', lc_ordform TYPE char15 VALUE 'ZORDCONFIRM_01', lc_attachment TYPE char10 VALUE 'ATTACHMENT'. CALL FUNCTION 'CONVERT_OTF' EXPORTING format = lc_pdf max_linewidth = 132 IMPORTING bin_filesize = lv_filesize TABLES otf = pv_otfdata lines = li_pdfdata EXCEPTIONS err_max_linewidth = 1 err_format = 2 err_conv_not_possible = 3 err_bad_otf = 4 OTHERS = 5. IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. LOOP AT li_pdfdata INTO lwa_pdfdata. TRANSLATE lwa_pdfdata USING ' ~'. CONCATENATE lv_buffer lwa_pdfdata INTO lv_buffer. CLEAR lwa_pdfdata. ENDLOOP. TRANSLATE lv_buffer USING '~ '. DO. lwa_mess_att = lv_buffer. APPEND lwa_mess_att TO li_mess_att. CLEAR lwa_mess_att. SHIFT lv_buffer LEFT BY 255 PLACES. IF lv_buffer IS INITIAL. EXIT. ENDIF. ENDDO. * Object with PDF. REFRESH li_objbin. li_objbin[] = li_mess_att[]. DESCRIBE TABLE li_objbin LINES lv_attachment. * Object with main text of the mail. lwa_objtxt = space. APPEND lwa_objtxt TO li_objtxt. CLEAR lwa_objtxt. DESCRIBE TABLE li_objtxt LINES lv_testo. * Create the document which is to be sent lwa_doc_chng-obj_name = text-008. lwa_doc_chng-obj_descr = text-008. lwa_doc_chng-sensitivty = lc_0. lwa_doc_chng-obj_prio = lc_1. lwa_doc_chng-doc_size = lv_testo * 225. * Pack to main body. CLEAR lwa_objpack-transf_bin. * header lwa_objpack-head_start = 1. * The document needs no header (head_num = 0) lwa_objpack-head_num = 0. * body lwa_objpack-body_start = 1. lwa_objpack-body_num = lv_testo. lwa_objpack-doc_type = lc_raw. APPEND lwa_objpack TO li_objpack. CLEAR lwa_objpack. * Create the attachment. * Fill the fields of the packing_list for the attachment: lwa_objpack-transf_bin = gc_x . * header lwa_objpack-head_start = 1. lwa_objpack-head_num = 1. * body lwa_objpack-body_start = 1. lwa_objpack-body_num = lv_attachment. lwa_objpack-doc_type = lc_pdf. lwa_objpack-obj_name = lc_attachment. lwa_objpack-obj_descr = text-008. lwa_objpack-doc_size = lv_attachment * 255. APPEND lwa_objpack TO li_objpack. CLEAR lwa_objpack. lwa_reclist-receiver = pv_emailid. lwa_reclist-rec_type = lc_u. lwa_reclist-notif_del = gc_x. lwa_reclist-notif_ndel = gc_x. APPEND lwa_reclist TO li_reclist. IF li_reclist IS NOT INITIAL. CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = lwa_doc_chng put_in_outbox = gc_x TABLES packing_list = li_objpack object_header = li_objhead contents_bin = li_objbin contents_txt = li_objtxt receivers = li_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 'I' NUMBER sy-msgno * WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDIF.
The Notes client is an OLE automation controller and server.External applications can create and reference the automation objects, then work down through the object hierarchies.A Notes client must be installed on the same machine as SAP GUI is installed. Notes runs as a separate process when acting as an OLE automation server.
The automation is based on late binding. A Notes.NotesSession object has to be created and work down through the hierarchies using the available methods. For example, if you want to send a mail, create a Notes.NotesSession OLE automation object, and then use the GetDatabase method of NotesSession to set a reference variable.The below shown codes explains in detail about different OLE objects and how to send a mail.
The following OLE objects must be declared for the process.
- Notessession
- NotesDatabase
- NotesDocument
- NotesRichTextItem
Sample Code .
TYPE-POOLS ole2 .
parameters: email(50).
DATA : notes TYPE ole2_object,
dbdirectory TYPE ole2_object.
database TYPE ole2_object.
document TYPE ole2_object.
attachment TYPE ole2_object.
notesrtf TYPE ole2_object.
notesregistration TYPE ole2_object.
notesstyle TYPE ole2_object.
CREATE OBJECT notes 'Lotus.Notessession'. "Represents the current environment and access to information(Address book,User info etc) CREATE OBJECT database 'Lotus.notesDatabase'."Represents the Notes Database CREATE OBJECT document 'Lotus.notesDocument'. "Represents a document in database CREATE OBJECT notesrtf 'Lotus.notesRichTextItem'."Represents a Rich Text Item type
**// Initialize a COM Session with the current User-Id
CALL METHOD OF notes 'Initialize'.
**// Creates a new DbDirectory object using the name of the server you want to access.
CALL METHOD OF notes 'getdbDirectory' = dbdirectory EXPORTING #1 = ''.
**// Opens the current user's mail database.
CALL METHOD OF dbdirectory 'OpenMailDatabase' = database .
**// Creates a document in a database and returns a Document object that represents the new document.
CALL METHOD OF database 'CreateDocument' = document .
**//Use the "SendTo" property to populate the recievers//
CALL METHOD OF document 'ReplaceItemValue' EXPORTING #1 = 'SendTo' #2 = email.
**//use the "Subject" property to set the subject of the mail
CALL METHOD OF document 'ReplaceItemValue' EXPORTING #1 = 'Subject' #2 = 'hi'.
**//The body of the mail can be created as a rich text item//
CALL METHOD OF document 'CreateRichTextItem' = notesrtf EXPORTING #1 = 'Body'.
**//Append the text to the body of the mail//
CALL METHOD OF notesrtf 'AppendText' EXPORTING #1 = 'Hi...From SAP,through lotus notes..regards..jinesh'.
**// "Send" Method mails a document.
**// If true, the form is stored and sent along with the document. If false, it isn't.
CALL METHOD OF document 'Send' EXPORTING #1 = 'FALSE'. if sy-subrc = 0. write : 'Mail Send Successfully'. endif.
//**Free all the objects.
FREE OBJECT notes. FREE OBJECT dbdirectory . FREE OBJECT database. FREE OBJECT document . FREE OBJECT attachment . FREE OBJECT notesrtf . FREE OBJECT notesregistration . FREE OBJECT notesstyle.
Note : I have not included a proper error handling method in the above code.
There might be a scenario where in an E-mail notification is required in a classical report where data outputted resides in many internal tables with complex logic. Here it is not a feasible option to send the list output to E-mail with excel as it may take lot of time in building the E-mailing logic. This article addresses this issue in a simple way.
Just copy paste below piece of code in a new report to understand the functionality.
Sample Code:
DATA: li_receivers TYPE STANDARD TABLE OF soos1, li_listobject TYPE STANDARD TABLE OF abaplist, li_ali TYPE STANDARD TABLE OF soli, li_ali1 TYPE STANDARD TABLE OF soli, li_ali2 TYPE STANDARD TABLE OF soli, lwa_objecthdchange TYPE sood1, lwa_receivers TYPE soos1, lwa_ali TYPE soli. DATA: l_lines TYPE i, l_length TYPE i. DO 10 TIMES. NEW-LINE. ULINE (99). WRITE: /1 sy-vline, 2 'column1', 24 sy-vline, 25 'Column2', 49 sy-vline, 50 'Column3', 74 sy-vline, 75 'Column4', 99 sy-vline. ENDDO. NEW-LINE. ULINE (99). NEW-LINE. CALL FUNCTION 'SAVE_LIST' EXPORTING list_index = '0' "Pass the list index like 0, 1, 2... TABLES listobject = li_listobject EXCEPTIONS list_index_invalid = 1 OTHERS = 2. IF sy-subrc NE 0. RAISE invalid_list. ENDIF. Convert the list to ALI format CALL FUNCTION 'TABLE_COMPRESS' TABLES in = li_listobject out = li_ali EXCEPTIONS compress_error = 1 OTHERS = 2. IF sy-subrc NE 0. RAISE compress_error. ENDIF. CLEAR: lwa_objecthdchange. DESCRIBE TABLE li_ali LINES l_lines. DESCRIBE FIELD lwa_ali LENGTH l_length IN CHARACTER MODE. lwa_objecthdchange-objlen = l_length * l_lines. lwa_objecthdchange-objla = sy-langu. lwa_objecthdchange-objnam = 'List'. MOVE sy-title TO lwa_objecthdchange-objdes. MOVE: 1 TO lwa_objecthdchange-objpri, 0 TO lwa_objecthdchange-objsns. CLEAR: lwa_receivers. MOVE: 'X' TO lwa_receivers-snddr, 'X' TO lwa_receivers-sndex, 'U' TO lwa_receivers-recesc, 'E-MAIL' TO lwa_receivers-recextnam. "Pass the recipient ID here. APPEND lwa_receivers TO li_receivers.Send email CALL FUNCTION 'SO_OBJECT_SEND' EXPORTING * FOLDER_ID = ' ' * FORWARDER = ' ' * OBJECT_FL_CHANGE = ' ' object_hd_change = lwa_objecthdchange * OBJECT_ID = ' ' object_type = 'ALI' * OUTBOX_FLAG = ' ' owner = sy-uname * STORE_FLAG = ' ' * DELETE_FLAG = ' ' sender = sy-uname * CHECK_SEND_AUTHORITY = ' ' * CHECK_ALREADY_SENT = ' ' * GIVE_OBJECT_BACK = * ORIGINATOR = ' ' * ORIGINATOR_TYPE = 'J' * LINK_FOLDER_ID = ' ' * SEND_REQUEST_OID = ' ' * IP_ENCRYPT = 'U' * IP_SIGN = 'U' * IP_REC_COUNT_ADD =IMPORTING * OBJECT_ID_NEW = * SENT_TO_ALL = * ALL_BINDING_DONE = * OFFICE_OBJECT_KEY = * ORIGINATOR_ID = * E_SEND_REQUEST_OID = TABLES objcont = li_ali * OBJHEAD = * OBJPARA = * OBJPARB = receivers = li_receivers * PACKING_LIST = * ATT_CONT = * ATT_HEAD = * NOTE_TEXT = * LINK_LIST = * APPLICATION_OBJECT = EXCEPTIONS active_user_not_exist = 1 communication_failure = 2 component_not_available = 3 folder_not_exist = 4 folder_no_authorization = 5 forwarder_not_exist = 6 note_not_exist = 7 object_not_exist = 8 object_not_sent = 9 object_no_authorization = 10 object_type_not_exist = 11 operation_no_authorization = 12 owner_not_exist = 13 parameter_error = 14 substitute_not_active = 15 substitute_not_defined = 16 system_failure = 17 too_much_receivers = 18 user_not_exist = 19 originator_not_exist = 20 x_error = 21 OTHERS = 22. IF sy-subrc IS INITIAL. MESSAGE 'Mail has been sent successfully' TYPE 'S'. ELSE. MESSAGE 'Error occured while sending the mail' TYPE 'S'. ENDIF.
Above code shows a sample output of the report without any processing logic. The actual output data determination logic is much complex in real time scenarios. A scanned copy of the output is sent as a mail notification to the recipients i.e. what you see in report output and E-mail is one and the same. This is best suited only for classical reports. For ALV reports it is always better to use E-mail with excel attachment as we have all the data available in one final internal table and lot of options are available with excel.
Thanks,
Vinod.
Author: Prasath Natesan
Submitted: 04-Jan-2008
Modif 08-Mar-2010: Sandra Rossi
Related Links/References:
- http://help.sap.com
- http://www.sdn.sap.com
- OSS Note : 103019
Introduction
Emails are one of the common methods of notifying users about various changes performed in the system. But when the user needs to view/process the data he/she needs to manually login to the system through the required transactions to access the data. SAP shortcuts come handy in these situations enabling the users to login to the required transactions directly.
Using SAP shortcuts through email will benefit the users in the following ways,
- Delivered to a single inbox, hence user does not have to keep checking the UWL/SBWP or other inboxes
- User does not need to remember the different transactions that he/she needs to work on.
- Option of parameter handling simplifies the job of user by preloading the screen with required information
Creating SAP shortcut at run time
The following function module can be used to create a shortcut for any SAP transaction. Further, certain values available in the transaction can be defaulted by passing the values as parameters to this FM. This shortcut created can then be attached in a mail and sent to the appropriate recipients.
Before creating the function modulen you have to define ZST_SHORTCUT_PAR as a DDIC structure, which 2 components FIELDNAME of type C of length 60, and FIELDVALUE of type C of length 255.
Note: if you want to test the program quickly without creating the function module and the DDIC structure, have a look at appendix 2.
FUNCTION zfm_create_shortcut. *"--------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" REFERENCE(RECIPIENT_USER_ID) TYPE SYUNAME *" REFERENCE(TRANSACTION) TYPE TCODE *" EXPORTING *" REFERENCE(CONTENT) TYPE STRING *" TABLES *" SHORTCUT_PARAM STRUCTURE ZST_SHORTCUT_PAR OPTIONAL *"--------------------------------------------------------------------- *** Declaration for shortcut content DATA : parameter TYPE text255, v_pernr(12) TYPE c. DATA : v_tcode TYPE tcode. * Check if transaction code is available CLEAR v_tcode. SELECT SINGLE tcode FROM tstc INTO v_tcode WHERE tcode EQ transaction. IF v_tcode IS INITIAL. MESSAGE 'Enter a valid transaction' TYPE 'E' DISPLAY LIKE 'A'. EXIT. ENDIF. * Populate the parameters to be passed to the shortcut IF NOT shortcut_param[] IS INITIAL. CLEAR parameter. LOOP AT shortcut_param. CONCATENATE parameter shortcut_param-fieldname '=' shortcut_param-fieldvalue ';' INTO parameter. ENDLOOP. ENDIF. *** create the shortcut content for the required transaction CALL FUNCTION 'SWN_CREATE_SHORTCUT' EXPORTING i_transaction = transaction i_parameter = parameter i_sysid = sy-sysid i_client = sy-mandt i_user = recipient_user_id i_language = sy-langu i_windowsize = 'Normal window' IMPORTING shortcut_string = content EXCEPTIONS inconsistent_parameters = 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. ENDFUNCTION.
This FM receives RECIPIENT_USER_ID and TRANSACTION as import parameters. The value of parameters if any can be passed through table parameter SHORCTCUT_PARAM. On execution the shortcut content is created and returned through the export parameter "CONTENT". The table SHORTCUT_PARAM refers to a custom structure described in Appendix 1.
Example scenario
Consider a scenario where the employee has requested for a change in address. Now once the change in address is completed a notification email is sent to the employee indicating the successful change in address. In a normal scenario the employee needs to log into the system manually and enter the required transaction. Then the required details (employee number, infotype and subtype) need to be entered before displaying the updated information.
This process can be simplified by sending a shortcut which will navigate the user to the required transaction with all required data pre-loaded. The sample code for this process is given below
*&---------------------------------------------------------------------* *& Report ZRP_MAIL_SHORTCUT *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT zrp_mail_shortcut. ************************************************************************ *** Report to send mail to employee to display temp address *** ************************************************************************ *** Declarations for attachment creation DATA: doc_chng LIKE sodocchgi1. DATA: tab_lines LIKE sy-tabix, body_start LIKE sy-tabix. DATA: it_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE. DATA: it_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE. DATA: it_objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE. DATA: it_reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE. DATA: it_shortcut_param LIKE zst_shortcut_par OCCURS 0 WITH HEADER LINE. DATA: content TYPE string. *** Pass the required parameters and create the shortcut CLEAR it_shortcut_param. REFRESH it_shortcut_param. it_shortcut_param-fieldname = 'RP50G-PERNR'. it_shortcut_param-fieldvalue = '1001'. "Employee number APPEND it_shortcut_param. it_shortcut_param-fieldname = 'RP50G-CHOIC'. it_shortcut_param-fieldvalue = '0006'. " Address Infotype APPEND it_shortcut_param. it_shortcut_param-fieldname = 'RP50G-TIMR1'. it_shortcut_param-fieldvalue = 'X'. "Period selected as "Today" APPEND it_shortcut_param. it_shortcut_param-fieldname = 'RP50G-SUBTY'. it_shortcut_param-fieldvalue = '2'. "Temporary address subtype APPEND it_shortcut_param. CALL FUNCTION 'ZFM_CREATE_SHORTCUT' EXPORTING recipient_user_id = 'DEVHYD' transaction = 'PA20' IMPORTING content = content TABLES shortcut_param = it_shortcut_param. *** Mail Subject doc_chng-obj_descr = 'Employee address changed'. *** Mail Contents CONCATENATE ' The requested change has been made to your temporary address.' ' Please double click on the attachment and choose display to view the updated address' INTO it_objtxt. APPEND it_objtxt. *** Creation of the entry for the document DESCRIBE TABLE it_objtxt LINES tab_lines. CLEAR it_objpack-transf_bin. it_objpack-head_start = 1. it_objpack-head_num = 0. it_objpack-body_start = 1. it_objpack-body_num = tab_lines. it_objpack-doc_type = 'RAW'. APPEND it_objpack. *** Populate attachment content CLEAR : tab_lines, it_objbin. CONCATENATE content it_objbin-line INTO it_objbin-line. APPEND it_objbin. DESCRIBE TABLE it_objbin LINES tab_lines. *** Creation of the entry for the compressed attachment it_objpack-transf_bin = 'X'. "Will get content from content_bin it_objpack-head_start = 1. it_objpack-head_num = 1. it_objpack-body_start = 1. it_objpack-body_num = tab_lines. it_objpack-doc_type = 'EXT'. it_objpack-obj_name = 'SAPSHORTCUTMAIL'. it_objpack-obj_descr = 'DisplayAddress.SAP'. it_objpack-doc_size = tab_lines * 255. APPEND it_objpack. *** target recipent(s) CLEAR it_reclist. it_reclist-receiver = 'employeemailid@employeecompany.com'. it_reclist-rec_type = 'U'. APPEND it_reclist. *** Sending the document to recipients with the shortcut attachment CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = doc_chng put_in_outbox = 'X' commit_work = 'X' TABLES packing_list = it_objpack contents_bin = it_objbin contents_txt = it_objtxt receivers = it_reclist EXCEPTIONS too_many_receivers = 1 document_not_sent = 2 operation_no_authorization = 4 OTHERS = 99.
The above code uses the function module ZFM_CREATE_SHORTCUT to create the required SAP shortcut and then sends it as attachment by email. The user can now double click on the shortcut from his email and reach the transaction directly with required information preloaded.
When the user double clicks on the attachment the pop up window for entering the password is opened as shown below,
Once the user enters the password and clicks on "Log on" the required transaction is opened up directly as shown below,
As highlighted in the above picture the values - Employee number, Period, Infotype and subtype are preloaded when the user reaches the transaction. The user can now hit the display button and view the required data.
Note: The system on which the shortcut is executed should have SAP GUI installed and have the target system configured in the SAP logon pad. If the configuration is not already available then on launching the shortcut the system asks for the logon details as shown below,
Appendix 1: Structure for passing shortcut parameters
A custom name-value pair structure as shown below was created for passing the shortcut parameters.
Appendix 2: creating the report without the FM and DDIC structure
This section shows how to test the program quickly without creating the function module and the DDIC structure.*
In the program, perform the following changes:
Replace this section |
By this section |
---|---|
REPORT zrp_mail_shortcut. ************************************************************************ *** Report to send mail to employee to display temp address *** ************************************************************************ |
REPORT zrp_mail_shortcut. DATA : BEGIN OF zst_shortcut_par, fieldname TYPE c LENGTH 60, fieldvalue TYPE c LENGTH 255, END OF zst_shortcut_par. ************************************************************************ *** Report to send mail to employee to display temp address *** ************************************************************************ |
CALL FUNCTION 'ZFM_CREATE_SHORTCUT' EXPORTING recipient_user_id = 'DEVHYD' transaction = 'PA20' IMPORTING content = content TABLES shortcut_param = it_shortcut_param. |
PERFORM zfm_create_shortcut TABLES it_shortcut_param USING 'DEVHYD' 'PA20' CHANGING content. |
[At the end of the report] |
*&---------------------------------------------------------------------* *& Form zfm_create_shortcut *&---------------------------------------------------------------------* FORM zfm_create_shortcut TABLES shortcut_param STRUCTURE zst_shortcut_par USING recipient_user_id TYPE syuname transaction TYPE tcode CHANGING content TYPE string. *** Declaration for shortcut content DATA : parameter TYPE text255, v_pernr(12) TYPE c. DATA : v_tcode TYPE tcode. * Check if transaction code is available CLEAR v_tcode. SELECT SINGLE tcode FROM tstc INTO v_tcode WHERE tcode EQ transaction. IF v_tcode IS INITIAL. MESSAGE 'Enter a valid transaction' TYPE 'E' DISPLAY LIKE 'A'. EXIT. ENDIF. * Populate the parameters to be passed to the shortcut IF NOT shortcut_param[] IS INITIAL. CLEAR parameter. LOOP AT shortcut_param. CONCATENATE parameter shortcut_param-fieldname '=' shortcut_param-fieldvalue ';' INTO parameter. ENDLOOP. ENDIF. *** create the shortcut content for the required transaction CALL FUNCTION 'SWN_CREATE_SHORTCUT' EXPORTING i_transaction = transaction i_parameter = parameter i_sysid = sy-sysid i_client = sy-mandt i_user = recipient_user_id i_language = sy-langu i_windowsize = 'Normal window' IMPORTING shortcut_string = content EXCEPTIONS inconsistent_parameters = 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. ENDFORM. "zfm_create_shortcut |
Here is the code to send the Smartform to mail as PDF attachment.
REPORT ztest_nreddy_pdf_mail. * Internal Table declarations DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE, i_tline TYPE TABLE OF tline WITH HEADER LINE, i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE, i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE, * Objects to send mail. i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE, i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE, i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE, i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE, * Work Area declarations wa_objhead TYPE soli_tab, w_ctrlop TYPE ssfctrlop, w_compop TYPE ssfcompop, w_return TYPE ssfcrescl, wa_doc_chng TYPE sodocchgi1, w_data TYPE sodocchgi1, wa_buffer TYPE string, "To convert from 132 to 255 * Variables declarations v_form_name TYPE rs38l_fnam, v_len_in LIKE sood-objlen, v_len_out LIKE sood-objlen, v_len_outn TYPE i, v_lines_txt TYPE i, v_lines_bin TYPE i. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = 'ZTEST' IMPORTING fm_name = v_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. w_ctrlop-getotf = 'X'. w_ctrlop-no_dialog = 'X'. w_compop-tdnoprev = 'X'. CALL FUNCTION v_form_name EXPORTING control_parameters = w_ctrlop output_options = w_compop user_settings = 'X' IMPORTING job_output_info = w_return EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 user_canceled = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. i_otf[] = w_return-otfdata[]. CALL FUNCTION 'CONVERT_OTF' EXPORTING format = 'PDF' max_linewidth = 132 IMPORTING bin_filesize = v_len_in TABLES otf = i_otf lines = i_tline EXCEPTIONS err_max_linewidth = 1 err_format = 2 err_conv_not_possible = 3 OTHERS = 4. IF sy-subrc <> 0. ENDIF. LOOP AT i_tline. TRANSLATE i_tline USING '~'. CONCATENATE wa_buffer i_tline INTO wa_buffer. ENDLOOP. TRANSLATE wa_buffer USING '~'. DO. i_record = wa_buffer. APPEND i_record. SHIFT wa_buffer LEFT BY 255 PLACES. IF wa_buffer IS INITIAL. EXIT. ENDIF. ENDDO. * Attachment REFRESH: i_reclist, i_objtxt, i_objbin, i_objpack. CLEAR wa_objhead. i_objbin[] = i_record[]. * Create Message Body Title and Description i_objtxt = 'test with pdf-Attachment!'. APPEND i_objtxt. DESCRIBE TABLE i_objtxt LINES v_lines_txt. READ TABLE i_objtxt INDEX v_lines_txt. wa_doc_chng-obj_name = 'smartform'. wa_doc_chng-expiry_dat = sy-datum + 10. wa_doc_chng-obj_descr = 'smartform'. wa_doc_chng-sensitivty = 'F'. wa_doc_chng-doc_size = v_lines_txt * 255. * Main Text CLEAR i_objpack-transf_bin. i_objpack-head_start = 1. i_objpack-head_num = 0. i_objpack-body_start = 1. i_objpack-body_num = v_lines_txt. i_objpack-doc_type = 'RAW'. APPEND i_objpack. * Attachment (pdf-Attachment) i_objpack-transf_bin = 'X'. i_objpack-head_start = 1. i_objpack-head_num = 0. i_objpack-body_start = 1. DESCRIBE TABLE i_objbin LINES v_lines_bin. READ TABLE i_objbin INDEX v_lines_bin. i_objpack-doc_size = v_lines_bin * 255 . i_objpack-body_num = v_lines_bin. i_objpack-doc_type = 'PDF'. i_objpack-obj_name = 'smart'. i_objpack-obj_descr = 'test'. APPEND i_objpack. CLEAR i_reclist. i_reclist-receiver = 'nareshreddy.k@gmail.com'. i_reclist-rec_type = 'U'. APPEND i_reclist. CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = wa_doc_chng put_in_outbox = 'X' commit_work = 'X' TABLES packing_list = i_objpack object_header = wa_objhead contents_bin = i_objbin contents_txt = i_objtxt receivers = i_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. WRITE:/ 'Error When Sending the File', sy-subrc. ELSE. WRITE:/ 'Mail sent'. ENDIF.
If you want to send some text as Body of the Mail then follow this once.
When you are calling the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'.. points to remember
- You have to pass the body of content in table CONTENTS_TXT(ia m using I_OBJBIN) (each line a record) then. Suppose i have appended 11 records to the table CONTENTS_TXT
- PACKING_LIST(i am using I_OBJPACK) table you have to append a record as follows
i_objpack-transf_bin = ' '. i_objpack-head_start = 000000000000001. i_objpack-head_num = 000000000000001. i_objpack-body_start = 000000000000002. i_objpack-body_num = 000000000000010. i_objpack-doc_type = 'RAW'. APPEND i_objpack.
By the above code system treat the first line in table I_OBJBIN as header and the 2nd line to 10 lines tread as body.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = wa_doc_chng put_in_outbox = 'X' TABLES packing_list = i_objpack object_header = wa_objhead contents_bin = i_objbin contents_txt = i_objtxt receivers = i_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.
Author: Alessandro Spadoni
Submitted: 16,Nov 2010
Related Links: http://en.wikipedia.org/wiki/Regular_expression
Snippet to validate an Email using class CL_ABAP_REGEX
DATA: regex TYPE REF TO cl_abap_regex, matcher TYPE REF TO cl_abap_matcher, match TYPE c LENGTH 1, mail_to_check(100), result TYPE WDY_BOOLEAN. mail_to_check = 'mail@example.com'. result = abap_true. "Email is valid CREATE OBJECT regex EXPORTING pattern = '\w+(\.\w+)*@(\w+\.)+(\w{2,4})' ignore_case = abap_true. matcher = regex->create_matcher( text = mail_to_check ). IF matcher->match( ) IS INITIAL. result = abap_false. "Email not valid EXIT. ENDIF.
Author: Devendra R Paralkar
Submitted: July 6, 2007
Related Links:
Description
In many cases it is required to send notifications/messages to Users depending upon some event/action that has occurred in SAP. There are standard function modules available in SAP for achieving this functionality. Here we will discuss in addition to sending mails how we can achieve text formatting using a combination of powerful SAP function modules and simple HTML tags.
Program Logic
SAP has provided us many function modules for this purpose. We will use "SO_DOCUMENT_SEND_API1" in our case. One of the parameters that need to be passed to this Function is the structure document_data. Here we have a field doc_type, in order to have required text formatting we pass this parameter as 'HTM'. By using this extension we can format the body of this mail using HTML tags.
REPORT Z_SEND_HTML_MAIL . * Selection screen: enter receiver (default is yourself) PARAMETERS p_rec TYPE so_recname OBLIGATORY DEFAULT sy-uname. PARAMETERS p_typ TYPE so_escape OBLIGATORY DEFAULT 'B'. "sap user * Data Declaration DATA: wa_docdata TYPE sodocchgi1, wa_objpack TYPE sopcklsti1 , it_objpack TYPE TABLE OF sopcklsti1, wa_objtxt TYPE solisti1, it_objtxt TYPE TABLE OF solisti1, wa_reclist TYPE somlreci1, it_reclist TYPE TABLE OF somlreci1. DATA: tab_lines TYPE i. * Start program PERFORM fill_text. PERFORM fill_object_details. *create receiver list PERFORM create_receivers_list. *send mail PERFORM send_mail. WRITE: / 'End of Program'. *---------------------------------------------------------------------* *Form fill_text *---------------------------------------------------------------------* FORM fill_text . wa_objtxt = '<SPAN style="font-family:arial;font-size:10.5pt;color:blue">'. APPEND wa_objtxt TO it_objtxt. wa_objtxt = '<B><U>Test Program for Send Mail.</U></B> <BR>'. APPEND wa_objtxt TO it_objtxt. wa_objtxt = '<A HREF="http://www.sap.com">Best wishes</A>'. APPEND wa_objtxt TO it_objtxt. wa_objtxt = '<I>This code is formatted using HTML.</I>'. APPEND wa_objtxt TO it_objtxt. wa_objtxt = 'Have a nice day.'. APPEND wa_objtxt TO it_objtxt. wa_objtxt = '<SPAN>'. APPEND wa_objtxt TO it_objtxt. ENDFORM. " fill_text *---------------------------------------------------------------------* *Form fill_object_details *---------------------------------------------------------------------* FORM fill_object_details . DESCRIBE TABLE it_objtxt LINES tab_lines. READ TABLE it_objtxt INTO wa_objtxt INDEX tab_lines. wa_docdata-obj_name = 'TEST_HTML'. wa_docdata-obj_descr = 'Test for HTML Code'. wa_docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( wa_objtxt ). CLEAR wa_objpack-transf_bin. wa_objpack-head_start = 1. wa_objpack-head_num = 0. wa_objpack-body_start = 1. wa_objpack-body_num = tab_lines. wa_objpack-doc_type = 'HTM'. APPEND wa_objpack TO it_objpack. ENDFORM. " fill_object_details *---------------------------------------------------------------------* *Form create_receivers_list *---------------------------------------------------------------------* FORM create_receivers_list . wa_reclist-receiver = p_rec. wa_reclist-rec_type = p_typ. APPEND wa_reclist TO it_reclist. ENDFORM. " create_receivers_list *--------------------------------------------------------------------- *Form send_mail *---------------------------------------------------------------------\ FORM send_mail . CALL FUNCTION 'SO_DOCUMENT_SEND_API1' EXPORTING document_data = wa_docdata put_in_outbox = ' ' commit_work = 'X' TABLES packing_list = it_objpack contents_txt = it_objtxt receivers = it_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 'S' NUMBER sy-msgno WITH sy-msgv1. ELSE. WRITE : / 'Mail sent to', p_rec. ENDIF. ENDFORM. " send_mail
Author: Jatra Riwayanto
Submitted: 24.09.2007
Description:
There is several folder in our workplace like inbox, outbox, private folder.
This simple program will display mail list in inbox folder.
Selection Screen
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'SELECTION-SCREEN BEGIN OF BLOCK BLC01 WITH FRAME TITLE TEXT-S10. PARAMETERS: P_UNAME LIKE SY-UNAME OBLIGATORY DEFAULT SY-UNAME. SELECTION-SCREEN END OF BLOCK BLC01.
Class Definition
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'CLASS LCL_MAIN DEFINITION. PUBLIC SECTION. METHODS: DISPLAY_INBOX. * DISPLAY_MAIL IMPORTING IM_MAILID TYPE STRING. EVENTS: MESSAGE EXPORTING VALUE(MSG1) TYPE STRING VALUE(MSG2) TYPE STRING OPTIONAL VALUE(MSG3) TYPE STRING OPTIONAL VALUE(MSG4) TYPE STRING OPTIONAL. PRIVATE SECTION. METHODS: CLEAR_DATA, GET_INBOX_CONTENT. *--------------------------------- * L.O.C.A.L D.A.T.A. *--------------------------------- DATA: USER TYPE SOUDNAMEI1, UDAT TYPE SOUDATAI1, FDAT TYPE SOFOLDATI1, IT_FDAT TYPE TABLE OF SOFOLENTI1, WA_FDAT TYPE SOFOLENTI1. DATA: MSG1 TYPE STRING, MSG2 TYPE STRING, MSG3 TYPE STRING, MSG4 TYPE STRING. DATA: FOLD_ID TYPE SOODK. ENDCLASS. "lcl_main DEFINITION CLASS LCL_HANDLER DEFINITION. PUBLIC SECTION. METHODS HANDLE_MESSAGE FOR EVENT MESSAGE OF LCL_MAIN IMPORTING MSG1 MSG2 MSG3 MSG4. ENDCLASS. "lcl_handler DEFINITION
Class Implementation
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'CLASS LCL_MAIN IMPLEMENTATION. *----------------------------------------------* * METHOD clear_data * *----------------------------------------------* METHOD CLEAR_DATA. CLEAR: USER, UDAT, FDAT, IT_FDAT[], WA_FDAT, FOLD_ID ENDMETHOD. "clear_data *----------------------------------------------* * METHOD DISPLAY_INBOX * *----------------------------------------------* METHOD DISPLAY_INBOX. CALL METHOD CLEAR_DATA( ). CALL METHOD GET_INBOX_CONTENT( ). IF IT_FDAT[] IS INITIAL. RAISE EVENT MESSAGE EXPORTING MSG1 = 'No emails in this inbox'. ENDIF. ULINE AT (114). FORMAT COLOR COL_HEADING. WRITE: / '|' NO-GAP, (020) 'Object ID' LEFT-JUSTIFIED, '|' NO-GAP, (030) 'Subject' LEFT-JUSTIFIED, '|' NO-GAP, (015) 'Date Recieved' LEFT-JUSTIFIED, '|' NO-GAP, (040) 'Sender ' LEFT-JUSTIFIED, '|'. ULINE AT /(114). FORMAT COLOR OFF. LOOP AT IT_FDAT INTO WA_FDAT. FORMAT COLOR COL_NORMAL INTENSIFIED ON. WRITE: / '|' NO-GAP, (020) WA_FDAT-OBJECT_ID UNDER 'Email ID' HOTSPOT ON, '|' NO-GAP, (030) WA_FDAT-OBJ_DESCR LEFT-JUSTIFIED, '|' NO-GAP, (015) WA_FDAT-REC_DATE LEFT-JUSTIFIED, '|' NO-GAP, (040) WA_FDAT-SEND_FNAM LEFT-JUSTIFIED, '|'. ENDLOOP. ULINE AT /(114). ENDMETHOD. "DISPLAY_INBOX *----------------------------------------------* * METHOD GET_INBOX_CONTENT * *----------------------------------------------* METHOD GET_INBOX_CONTENT. MOVE P_UNAME TO USER-SAPNAME. CALL FUNCTION 'SO_USER_READ_API1' EXPORTING USER = USER * prepare_for_folder_access = 'X' IMPORTING USER_DATA = UDAT EXCEPTIONS USER_NOT_EXIST = 1 PARAMETER_ERROR = 2 X_ERROR = 3 OTHERS = 4. IF SY-SUBRC NE 0. CASE SY-SUBRC. WHEN 1. MSG1 = 'User Does not exist !'. WHEN 2. MSG1 = 'Parameter Error !'. WHEN 3. MSG1 = 'X Error!'. WHEN 4. MSG1 = 'Others Error !'. ENDCASE. RAISE EVENT MESSAGE EXPORTING MSG1 = MSG1. ENDIF. * Select inbox folder MOVE UDAT-INBOXFOL TO FOLD_ID. CALL FUNCTION 'SO_FOLDER_READ_API1' EXPORTING FOLDER_ID = FOLD_ID IMPORTING FOLDER_DATA = FDAT TABLES FOLDER_CONTENT = IT_FDAT EXCEPTIONS FOLDER_NOT_EXIST = 1 OPERATION_NO_AUTHORIZATION = 2 X_ERROR = 3 OTHERS = 4. IF SY-SUBRC NE 0. CASE SY-SUBRC. WHEN 1. MSG1 = 'Folder Does not exist !'. WHEN 2. MSG1 = 'No Authorization !'. WHEN 3. MSG1 = 'X Error!'. WHEN 4. MSG1 = 'Others Error !'. ENDCASE. RAISE EVENT MESSAGE EXPORTING MSG1 = MSG1. ENDIF. ENDMETHOD. "GET_INBOX_CONTENT ENDCLASS. "lcl_main IMPLEMENTATION CLASS LCL_HANDLER IMPLEMENTATION. METHOD HANDLE_MESSAGE . MESSAGE I398(00) WITH MSG1 MSG2 MSG3 MSG4. LEAVE LIST-PROCESSING.. ENDMETHOD. "handle_message ENDCLASS. "lcl_handler IMPLEMENTATION
Main Program
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'START-OF-SELECTION. DATA: O_MAIN TYPE REF TO LCL_MAIN, O_HANDLER TYPE REF TO LCL_HANDLER. CREATE OBJECT: O_MAIN, O_HANDLER. SET HANDLER O_HANDLER->HANDLE_MESSAGE FOR ALL INSTANCES. CALL METHOD O_MAIN->DISPLAY_INBOX.
Selection Screen:
*Inbox Content:*
The code below demonstrates how to send an SAP mail to a users inbox (SBWP)
REPORT zsapmail NO STANDARD PAGE HEADING. TABLES: drad, qinf, draw, souc, sofd, drap. DATA: p_return_code LIKE sy-subrc. DATA: d_username LIKE drap-prnam. * mail declarations DATA : BEGIN OF new_object_id. " the newly created email object INCLUDE STRUCTURE soodk. DATA : END OF new_object_id. DATA : BEGIN OF folder_id. " the folder id of the outbox INCLUDE STRUCTURE soodk. DATA : END OF folder_id. DATA : BEGIN OF rec_tab OCCURS 5. " the table which will contain the INCLUDE STRUCTURE soos1. " information on the destination DATA : END OF rec_tab. DATA : BEGIN OF object_hd_change. " the table which contains the INCLUDE STRUCTURE sood1. " info for the object we will be DATA : END OF object_hd_change. " creating DATA : object_type LIKE sood-objtp. " the type of object DATA : BEGIN OF objhead OCCURS 5. " the header of the object INCLUDE STRUCTURE soli. DATA : END OF objhead. DATA : BEGIN OF objcont OCCURS 0. " the contents of the object INCLUDE STRUCTURE soli. " i.e. the text etc DATA : END OF objcont. DATA : BEGIN OF objpara OCCURS 5. " formatting options INCLUDE STRUCTURE selc. DATA : END OF objpara. DATA : BEGIN OF objparb OCCURS 5. " formatting options INCLUDE STRUCTURE soop1. DATA : END OF objparb. DATA : BEGIN OF t_mail_text OCCURS 0, "Message table for messages to string(255), "user via mailbox END OF t_mail_text. PARAMETER: p_uname LIKE sy-uname. ************************************************************************ **START-OF-SELECTION START-OF-SELECTION. d_username = p_uname. PERFORM populate_email_text. PERFORM setup_trx_and_rtx_mailboxes USING p_return_code. PERFORM create_and_send_mail_object. *---------------------------------------------------------------------* * FORM POPULATE_EMAIL_TEXT * *---------------------------------------------------------------------* * Inserts text for email message * *---------------------------------------------------------------------* FORM populate_email_text. CLEAR t_mail_text-string. "puts a blank line in APPEND t_mail_text. APPEND t_mail_text. * adds failed list on to end of success list. t_mail_text-string = 'Test email message line 1'. APPEND t_mail_text. t_mail_text-string = 'Test email message line 1'. APPEND t_mail_text. CLEAR t_mail_text-string. "puts a blank line in APPEND t_mail_text. t_mail_text-string = 'Header1 Header2 Header3'. APPEND t_mail_text. t_mail_text-string = '----------- ---------- -----------'. APPEND t_mail_text. ENDFORM. "POPULATE_EMAIL_TEXT *&---------------------------------------------------------------------* *& Form SETUP_TRX_&_RTX_MAILBOXES *&---------------------------------------------------------------------* * Ensure that the mailboxes of the sender (INTMGR) are set up OK *----------------------------------------------------------------------* FORM setup_trx_and_rtx_mailboxes USING p_return_code. * get the user no of the sender in order to add the mail to the * user name's outbox for future reference SELECT SINGLE * FROM souc WHERE sapnam = sy-uname. "SAP name of a SAPoffice user IF sy-subrc NE 0. "Error finding the SAPoffice user info for the user MESSAGE e064(zr53) WITH sy-uname. p_return_code = 1. EXIT. ENDIF. *Get the outbox No for the sender from the user No where the folder " type is an outbox SELECT * FROM sofd WHERE owntp = souc-usrtp "Owner type from ID AND ownyr = souc-usryr "Owner year from the ID AND ownno = souc-usrno "Owner number from the I AND folrg = 'O'."Output box ENDSELECT. IF sy-subrc NE 0. " Error getting folder information for the user MESSAGE e065(zr53) WITH sy-uname. p_return_code = 1. EXIT. ENDIF. ENDFORM. " SETUP_TRX_&_RTX_MAILBOXES *&---------------------------------------------------------------------* *& Form CREATE_AND_SEND_MAIL_OBJECT *&---------------------------------------------------------------------* FORM create_and_send_mail_object. folder_id-objtp = sofd-foltp. " the folder type ( usually FOL ) folder_id-objyr = sofd-folyr. " the folder year ( usually 22 ) folder_id-objno = sofd-folno. " the folder no. object_type = 'RAW'. " the type of object being added * build up the object information for creating the object object_hd_change-objla = sy-langu. " the language of the email object_hd_change-objnam = 'PS to DM Interface'. " the object name * mail subject 'Mass Linking of QA, pass/fail' MOVE text-002 TO object_hd_change-objdes. object_hd_change-dldat = sy-datum. " the date of the email object_hd_change-dltim = sy-uzeit. " the time of the email object_hd_change-objpri = '1'. " the priority ( highest ) object_hd_change-objsns = 'F'. " the object sensitivity * F is functional, C - company sensitive * object_hd_change-skips = ' '. " Skip first screen * object_hd_change-acnam = 'SM35'. " Batch imput transaction * object_hd_change-vmtyp = 'T'. " Transaction type * add the text lines into the contents of the email CLEAR objcont. REFRESH objcont. * free objcont. " added this to delete the mail contents records LOOP AT t_mail_text. objcont-line = t_mail_text-string. APPEND objcont. ENDLOOP. CLEAR objcont. * build up the table of receivers for the email rec_tab-rcdat = sy-datum. " the date to send the email rec_tab-rctim = sy-uzeit. " the time to send the email * the SAP username of the person who will receive the email rec_tab-recnam = d_username. * the user type of the person who will send the email ( USR ) rec_tab-sndtp = souc-usrtp. * the user year of the person who will send the email ( 22 ) rec_tab-sndyr = souc-usryr. * the user number of the person who will send the email rec_tab-sndno = souc-usrno. * the sap username of the person who will send the email rec_tab-sndnam = sy-uname. * get the user info for the receiver of the document SELECT SINGLE * FROM souc WHERE sapnam = d_username. IF sy-subrc NE 0. WRITE : / text-001, d_username. "usnam. EXIT. ENDIF. * the user number of the person who will receive the email ( USR ) rec_tab-recno = souc-usrno. * the user type of the person who will receive the email ( USR ) rec_tab-rectp = souc-usrtp. * the user year of the person who will receive the email ( USR ) rec_tab-recyr = souc-usryr. * the priority of the email ( highest ) rec_tab-sndpri = '1'. * check for delivery on the email rec_tab-deliver = 'X'. * send express so recipient knows there is a problem rec_tab-sndex = 'X'. * check for a return receipt rec_tab-read = 'X'. * the sap username of the person receiving the email rec_tab-adr_name = d_username. "usnam. * add this receiver to the internal table APPEND rec_tab. CLEAR rec_tab. * call the function to create the object in the outbox of the sender CALL FUNCTION 'SO_OBJECT_INSERT' EXPORTING folder_id = folder_id object_hd_change = object_hd_change object_type = object_type owner = sy-uname IMPORTING object_id = new_object_id TABLES objcont = objcont objhead = objhead objpara = objpara objparb = objparb EXCEPTIONS active_user_not_exist = 1 communication_failure = 2 component_not_available = 3 dl_name_exist = 4 folder_not_exist = 5 folder_no_authorization = 6 object_type_not_exist = 7 operation_no_authorization = 8 owner_not_exist = 9 parameter_error = 10 substitute_not_active = 11 substitute_not_defined = 12 system_failure = 13 x_error = 14 OTHERS = 15. IF sy-subrc NE 0. MESSAGE a063(zr53) WITH sy-subrc. EXIT. ENDIF. * call the function to send the already created email to the receivers CALL FUNCTION 'SO_OBJECT_SEND' EXPORTING folder_id = folder_id object_id = new_object_id outbox_flag = 'X' owner = sy-uname TABLES receivers = rec_tab EXCEPTIONS active_user_not_exist = 1 communication_failure = 2 component_not_available = 3 folder_not_exist = 4 folder_no_authorization = 5 forwarder_not_exist = 6 note_not_exist = 7 object_not_exist = 8 object_not_sent = 9 object_no_authorization = 10 object_type_not_exist = 11 operation_no_authorization = 12 owner_not_exist = 13 parameter_error = 14 substitute_not_active = 15 substitute_not_defined = 16 system_failure = 17 too_much_receivers = 18 user_not_exist = 19 x_error = 20 OTHERS = 21. IF sy-subrc EQ 0. MESSAGE i035(zr53) WITH new_object_id d_username. "usnam. ELSE. MESSAGE i036(zr53) WITH d_username." sy-subrc. ENDIF. ENDFORM. " CREATE_AND_SEND_MAIL_OBJECT
Sending mail from SAP and getting read-receipt.
- BASIS settings to be done : SCOT->Settings->Confirmation of Receipts -> SAP expects receipt confirmations for Internet mail
- Requesting Read Receipt using Class: CLEAR send_request.
TRY.
* ------- create persistent send request -----------------------
send_request = cl_bcs=>create_persistent( ).
* ------- create and set document with attachment --------------
* create document from internal table with text
*Create the content of the mail
ONCATENATE 'This is for test' INTO v_objdes SEPARATED BY space.
APPEND v_objdes TO text.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = i_text
i_subject = v_objdes ).
REFRESH i_text.
CLEAR v_objdes.
CALL METHOD send_request->set_document( document ).
sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
* -------- add recipient (e-mail address) ----------------------
* create recipient - please replace e-mail address !!!
* here only need to specify about read receipt
{}v_mail = 'papiya@gmail.com'.
l_recipient_soos-recesc = 'U'.
l_recipient_soos-recextnam = v_mail.
l_recipient_soos-read = 'X'.
TRY.
CALL METHOD cl_send_request_bcs=>create_recipient_from_soos1
EXPORTING
i_soos1 = l_recipient_soos
RECEIVING
result = recipient.
CATCH cx_send_req_bcs .
ENDTRY.
* add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
CLEAR v_mail.
TRY.
CALL METHOD send_request->set_status_attributes
EXPORTING
i_requested_status = i_requested_status
i_status_mail = i_status_mail.
* CATCH cx_send_req_bcs .
ENDTRY.
SPAN
.L0S33
.L0S52
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).WITH FUNCTION MODULE :
DATA: wa_email TYPE zdm_email_id_s,
wa_document TYPE sodocchgi1,
v_desc_lines TYPE sy-tabix,
it_mail_msg_ob TYPE TABLE OF solisti1,
wa_mail_msg_ob TYPE solisti1,
it_packing_ob TYPE TABLE OF sopcklsti1,
wa_packing_ob TYPE sopcklsti1,
it_receivers_ob TYPE TABLE OF somlreci1,
wa_receivers_ob TYPE somlreci1.
CONSTANTS: c_sender TYPE soextreci1-receiver VALUE 'WF-BATCH',
c_ehs_email_ob TYPE sopcklsti1-obj_name VALUE 'EHS_EMAIL',
c_int_ob TYPE soextreci1-adr_typ VALUE 'INT',
c_255_ob TYPE i VALUE '255',
c_zero_ob(15) TYPE c VALUE '0' ,
c_one_ob(15) TYPE c VALUE '1' ,
c_doc_type_ob(3) TYPE c VALUE 'RAW'.
IF zdm_email[] IS NOT INITIAL.
** Getting the receivers email IDs
wa_receivers_ob-receiver = 'papiya@gmail.com'.
wa_receivers_ob-rec_type = 'U'.
wa_receivers_ob-notif_read = 'X'.
APPEND wa_receivers_ob TO it_receivers_ob.
** Filling the Mail Content
clear wa_mail_msg_ob.
CONCATENATE text-025
text-026
INTO wa_mail_msg_ob
SEPARATED BY space.
APPEND wa_mail_msg_ob to it_mail_msg_ob.
clear wa_mail_msg_ob.
move text-027 to wa_mail_msg_ob.
append wa_mail_msg_ob to it_mail_msg_ob.
move space to wa_mail_msg_ob.
APPEND wa_mail_msg_ob to it_mail_msg_ob.
CONCATENATE 'This is just a test document' '.'
INTO wa_mail_msg_ob
SEPARATED BY space.
APPEND wa_mail_msg_ob TO it_mail_msg_ob.
DESCRIBE TABLE it_mail_msg_ob LINES v_desc_lines.
READ TABLE it_mail_msg_ob INDEX v_desc_lines
INTO wa_mail_msg_ob.
wa_document-doc_size = ( v_desc_lines - 1 ) * c_255_ob
+ STRLEN( wa_mail_msg_ob ).
wa_document-obj_langu = sy-langu.
wa_document-obj_name = c_ehs_email_ob.
** Filling the Mail Title
CONCATENATE 'ATTN:This is test.'
INTO wa_document-obj_descr
SEPARATED BY space.
wa_packing_ob-transf_bin = space.
wa_packing_ob-head_start = c_one_ob.
wa_packing_ob-head_num = c_zero_ob.
wa_packing_ob-body_start = c_one_ob.
DESCRIBE TABLE it_mail_msg_ob LINES wa_packing_ob-body_num.
wa_packing_ob-doc_type = c_doc_type_ob.
APPEND wa_packing_ob TO it_packing_ob.
** Sending Mail for obsolete
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = wa_document
sender_address = c_sender
* SENDER_ADDRESS_TYPE = 'B'
commit_work = 'X'
TABLES
packing_list = it_packing_ob
contents_txt = it_mail_msg_ob
receivers = it_receivers_ob
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.
ENDIF.
ENDIF.
EXIT.
To check if the settings done by you are correct:
You need to check the MIME data of an email:
To check the MIME:
A) Please implement note 845449 if it is not already in your
system.
B) Please run report RSCONN06 and select the Always Save option for
outgoing emails. Send another email and then display the MIME
version of this email. The MIME version can be displayed for outbound
e-mails in transaction SOST by right-clicking on a send job using
'Display MIME display ' or 'MIME version'.
If it is showing like the settings below your settings are perfect.
Disposition-Notification-To: Papiya <papiya@gmail.com>
Return-Receipt-To: Papiya <papiya@gmail.com>
Lastly also these steps has to be noted for the delivery and the read receipt settings to work perfectly:
When 'A' sends email with a *Delivery Receipt* request, to "B" the Delivery Receipt is answered by ESMTP on B's mail server. A Delivery Receipt is sent from the server hosting the recipient's mailbox, when the message is delivered to the mail box. The purpose of this is to confirm to the sender that the message reached the recipient's mailbox's (Delivery Service Notifications) refers to both a service that may optionally be provided by Message Transfer Agents
(MTAs) using the Simple Mail Transfer Protocol (SMTP), and a message format to be used to return indications of message delivery to the sender of that message. Specifically, the DSN SMTP service is used to request that indications of successful delivery or delivery failure (in the DSN format) be returned. Issuance of a DSN upon delivery failure is the default behavior, whereas issuance of a DSN upon successful delivery requires a specific request from the sender.
Moreover some settings need to be done in the recipient client's mail box also.
For Microsoft outlook the settings that need to be done are:
In many email clients, you can configure delivery and read receipts. A delivery receipt is an email alert when your email has been delivered to an accepting mail server for the recipient of your email. A read receipt is an email you receive when a user reads the email. However, a read receipt is only sent if the user desires to send you one - as such I find it unreliable. I also find it annoying when I receive emails with a read receipt request. They cause outlook to give a popup message unless you've configured it to always ignore or always send read receipts. This article will show you how to configure your Outlook 2007 email client (this might also work the same in Outlook 2003 and before) to request delivery receipts (read receipts are on the same screen if you insist) on all emails you send out.
- From the Oulook Tools menu, select Options (if you don't see the Options menu item, you may ahve to expand the menu window with that little double arrow that points downward).
- In the next screen for Options, click on the Email Options button
- In the next screen Email Options, click on the Tracking Options button.
- In the Tracking Options screen, you have a checkmark for Delivery receipt. Click this and all your emails you send out will give you an alert when your email server delivers them.
If you start getting annoyed with all of the delivery receipts, then just come back here and take that check mark off. Also notice the options on this screen for how to reply to read receipts and why I don't believe in them. Never send a response is an option. Additionally, if they have checked Always send a response and it only becomes "read" from their preview pane in Outlook (which you should turn off), but they didn't actually read it, you get a read receipt.
Author: Suresh Maryala
Submitted: 07/10/2008
Related Links:
Selection Screen Details
As part of the Selection screen user inputs Training Name, Location, Begin date, End Date, Pernr or User type and Pernr number or user id. .
Program Logic
Based on information provided to selection screen, program reads infotype 105 to find the user id or pernr and also the e-mail address. User id is stored in sub type 0001 and e-mail address is stored in sub type 0010. Process
- *# Read infotype 0105 to find the PERNR, User ID and E-mail address
- Build internal table for Microsoft calendar entry
- Build training details to be part of text
- Call so_raw_to_rtf to convert the calendar entry details to have line breaks
- Call method send_request to send the e-mail
- Add entry in table TSOPE with VCS and ASCII check box selected
ABAP Code
DATA: text TYPE bcsy_text. DATA: document TYPE REF TO cl_document_bcs. DATA: sender TYPE REF TO cl_sapuser_bcs. DATA: recipient TYPE REF TO if_recipient_bcs. DATA: bcs_exception TYPE REF TO cx_bcs. DATA: sent_to_all TYPE os_boolean. DATA: it_content TYPE soli_tab. DATA: it_attach TYPE soli_tab. DATA: send_request TYPE REF TO cl_bcs. DATA: l_subject LIKE sodocchgi1-obj_descr, l_sender_type LIKE soextreci1-adr_typ, l_recsize TYPE i, l_receiver TYPE sy-subrc. DATA: lt_soli TYPE soli_tab . DATA: ls_soli LIKE LINE OF lt_soli. DATA: lt_soli_new TYPE soli_tab. DATA: ls_email TYPE pa0105-usrid_long. DATA: ls_uname TYPE pa0105-usrid. DATA: ls_pernr TYPE pernr-pernr. DATA: ls_begin(10) TYPE c. DATA: ls_end(10) TYPE c. DATA: result TYPE REF TO cl_document_bcs. DATA: BEGIN OF ls_data, sender TYPE lsoppvar-sender, "sender kbgda TYPE ppvar-kbgda, "begin date kndda TYPE ppvar-endda, "end date kbtim TYPE ppvar-kbtim, "begin time first day ketim TYPE ppvar-ketim, "end time last day kstxt TYPE ppvar-kstxt, "training text b_ort TYPE ppvar-b_ort, "training location rstxt TYPE ppvar-rstxt, "room text amail TYPE lsoppvar-amail, "recipient eMail astxt TYPE ppvar-astxt, "recipient END OF ls_data. FIELD-SYMBOLS: <fs_soli> LIKE ls_soli. ************************************************************************ * SELECTION SCREEN DEFINITION ************************************************************************ SELECTION-SCREEN BEGIN OF BLOCK group WITH FRAME TITLE text-001. PARAMETERS: p_trnam LIKE p1000-stext DEFAULT 'TRAINING NAME', p_locnm LIKE p1000-stext DEFAULT 'LOCATION', p_begda LIKE p1000-begda DEFAULT '20081101', p_endda LIKE p1000-endda DEFAULT '20081104', p_ltype LIKE lso_borkey_participation-learnertype DEFAULT 'P', p_lid LIKE lso_borkey_participation-learnerid DEFAULT '10000137'. SELECTION-SCREEN END OF BLOCK group. ************************************************************************ * INITIALIZATION ************************************************************************ INITIALIZATION. START-OF-SELECTION. CASE p_ltype. WHEN 'P'. * Move PERNR number to variable ls_pernr = p_lid. WHEN 'US'. ls_uname = p_lid. CONDENSE ls_uname. SELECT SINGLE pernr FROM pa0105 INTO ls_pernr WHERE usrid = ls_uname AND begda LE sy-datum AND endda GE sy-datum AND subty = '0001'. ENDCASE. * Read infotype 0105 and subtypes 0001 and 0010 * Sub type 0001 has username * sub type 0010 has e-mail SELECT SINGLE usrid_long FROM pa0105 INTO ls_email WHERE pernr = ls_pernr AND begda LE sy-datum AND endda GE sy-datum AND subty = '0010'. SELECT SINGLE usrid FROM pa0105 INTO ls_uname WHERE pernr = ls_pernr AND begda LE sy-datum AND endda GE sy-datum AND subty = '0001'. PERFORM f_data. *&---------------------------------------------------------------------* *& Form f_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM f_data . * Calendar logic begin ls_soli-line = 'BEGIN:VCALENDAR'. APPEND ls_soli TO lt_soli. ls_soli-line = 'PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN'. APPEND ls_soli TO lt_soli. ls_soli-line = 'VERSION:1.0'. APPEND ls_soli TO lt_soli. ls_soli-line = 'METHOD:REQUEST'. APPEND ls_soli TO lt_soli. ls_soli-line = 'BEGIN:VEVENT'. APPEND ls_soli TO lt_soli. CONCATENATE 'ATTENDEE;CN=' ls_uname ';ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:' ls_email INTO ls_soli-line. APPEND ls_soli TO lt_soli. CONCATENATE 'DTSTART:' p_begda 'T140000Z' INTO ls_soli-line. APPEND ls_soli TO lt_soli. CONCATENATE 'DTEND:' p_endda 'T220000Z' INTO ls_soli-line. APPEND ls_soli TO lt_soli. CONCATENATE 'LOCATION:' p_locnm INTO ls_soli-line. APPEND ls_soli TO lt_soli. ls_soli-line = 'TRANSP:OPAQUE'. APPEND ls_soli TO lt_soli. ls_soli-line = 'SEQUENCE:1'. APPEND ls_soli TO lt_soli. ls_soli-line = 'DESCRIPTION: Course Participation'. APPEND ls_soli TO lt_soli. CONCATENATE 'SUMMARY: Course Participation for ' ls_uname INTO ls_soli-line SEPARATED BY space. APPEND ls_soli TO lt_soli. ls_soli-line = 'PRIORITY:5'. APPEND ls_soli TO lt_soli. ls_soli-line = 'X-MICROSOFT-CDO-IMPORTANCE:1'. APPEND ls_soli TO lt_soli. ls_soli-line = 'CLASS:PUBLIC'. APPEND ls_soli TO lt_soli. ls_soli-line = 'END:VEVENT'. APPEND ls_soli TO lt_soli. ls_soli-line = 'END:VCALENDAR'. APPEND ls_soli TO lt_soli. * End of Calendar * Call this function module to convert data created for calendar entry * CALL FUNCTION 'SO_RAW_TO_RTF' TABLES objcont_old = lt_soli[] objcont_new = lt_soli_new[]. l_subject = 'Course Participation'. ls_soli-line = 'This is to notify following course has been approved'. APPEND ls_soli TO it_content. CLEAR ls_soli. APPEND ls_soli TO it_content. CONCATENATE 'Training Name: ' p_trnam INTO ls_soli-line. APPEND ls_soli TO it_content. CLEAR ls_soli. APPEND ls_soli TO it_content. WRITE p_begda TO ls_begin. WRITE p_endda TO ls_end. CONCATENATE 'Begin Date: ' ls_begin INTO ls_soli-line. APPEND ls_soli TO it_content. CLEAR ls_soli. APPEND ls_soli TO it_content. CONCATENATE 'End Date: ' ls_end INTO ls_soli-line. APPEND ls_soli TO it_content. CLEAR ls_soli. APPEND ls_soli TO it_content. CONCATENATE 'Location Name: ' p_locnm INTO ls_soli-line. APPEND ls_soli TO it_content. CLEAR ls_soli. APPEND ls_soli TO it_content. TRY. * Create persistent send request send_request = cl_bcs=>create_persistent( ). document = cl_document_bcs=>create_document( i_type = 'RAW' i_text = it_content[] i_subject = l_subject ). DESCRIBE TABLE lt_soli. CALL METHOD document->add_attachment EXPORTING i_attachment_type = 'VCS' i_attachment_subject = 'Course' i_att_content_text = lt_soli_new[]. * Add document to send request CALL METHOD send_request->set_document( document ). * Get sender object sender = cl_sapuser_bcs=>create( sy-uname ). * Add sender CALL METHOD send_request->set_sender EXPORTING i_sender = sender. * ------ add recipient (e-mail address) ---------------------- * create recipient * Enter a valid e-mail address recipient = cl_cam_address_bcs=>create_internet_address( ls_email ). * add recipient with its respective attributes to send request CALL METHOD send_request->add_recipient EXPORTING i_recipient = recipient i_express = 'U' i_copy = ' ' i_blind_copy = ' ' i_no_forward = ' '. ********Trigger e-mails immediately**************************** send_request->set_send_immediately( 'X' ). CALL METHOD send_request->send( EXPORTING i_with_error_screen = 'X' RECEIVING result = sent_to_all ). IF sent_to_all = 'X'. WRITE 'Document Sent Successfully'. ENDIF. COMMIT WORK. CATCH cx_document_bcs INTO bcs_exception. WRITE: 'Error Occurred'. WRITE: 'Error Type', bcs_exception->error_type. EXIT. ENDTRY. ENDFORM. " f_data
Author: Subrahmanya Pindiproli
Submitted: 14-May-2012
HTML Formatted attachments using ABAP
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'*-----------------------------------------------------------------------* * Program Name : ZRPT_FORMATTED_EMAIL_1 * * Author : Subrahmanya Pindiproli * * Requested By : N.A * * Date created : 2012/04/12 * * SAP Release : ECC6.0 * * Project Name : N.A * * Task # : * * Description : Formatted Emails using HTML in ABAP using the * * FM : SO_NEW_DOCUMENT_ATT_SEND_API1 * *-----------------------------------------------------------------------* * Change History * *-----------------------------------------------------------------------* * * * * *-----------------------------------------------------------------------* REPORT zrpt_formatted_email_1. *-----------------------------------------------------------------------* * D A T A D E C L A R A T I O N S * *-----------------------------------------------------------------------* DATA: t_objtxt TYPE STANDARD TABLE OF solisti1, " Message body t_objpack TYPE STANDARD TABLE OF sopcklsti1, " Packing list t_reclist TYPE STANDARD TABLE OF somlreci1, " Receipient list t_html TYPE STANDARD TABLE OF w3html. " Html DATA: lv_tmp_str TYPE string, wa_htmlline TYPE w3html. DATA : t_table TYPE STANDARD TABLE OF ssfbin, t_attachment TYPE STANDARD TABLE OF solix. DATA: wa_docdata TYPE sodocchgi1, " Document data wa_objtxt TYPE solisti1, " Message body *wa_objbin TYPE solisti1, " Attachment data wa_objpack TYPE sopcklsti1, " Packing list wa_reclist TYPE somlreci1. " Receipient list *DATA: w_tab_lines TYPE i. " Table lines * Internal Table for Data in Email Body TYPES : BEGIN OF ty_mara, matnr TYPE matnr, bismt TYPE bismt, groes TYPE groes, END OF ty_mara. DATA : t_mara TYPE STANDARD TABLE OF ty_mara, * l_count TYPE i, v_ld_sender_address LIKE soextreci1-receiver, v_ld_sender_address_type LIKE soextreci1-adr_typ, v_sent_all(1) TYPE c. * Constants CONSTANTS : c_u TYPE so_escape VALUE 'U'. "Specification of recipient type * c_x TYPE sonv-flag VALUE 'X'. *-----------------------------------------------------------------------* * S E L E C T I O N S C R E E N * *-----------------------------------------------------------------------* PARAMETERS: p_email TYPE char120 OBLIGATORY VISIBLE LENGTH 40 LOWER CASE. *-----------------------------------------------------------------------* * S T A R T O F S E L E C T I O N * *-----------------------------------------------------------------------* START-OF-SELECTION. * Get Report Data PERFORM get_data. * Process Data ( Placeholder Subroutine ) PERFORM process_data. * Creating message PERFORM create_message. * Sending Message PERFORM send_message. *&---------------------------------------------------------------------* *& Form create_message *&---------------------------------------------------------------------* * Create the Email Title, Description, Body and populate the * * receiver list. * *----------------------------------------------------------------------* FORM create_message . **1 Title, Description & Body PERFORM create_title_desc_body. **2 Receivers PERFORM fill_receivers. ENDFORM. " create_message *&---------------------------------------------------------------------* *& Form CREATE_TITLE_DESC_BODY *&---------------------------------------------------------------------* * Title, Description and body *----------------------------------------------------------------------* FORM create_title_desc_body. PERFORM itab_to_html. PERFORM build_email_body. ENDFORM. " CREATE_TITLE_DESC_BODY *&---------------------------------------------------------------------* *& Form fill_receivers *&---------------------------------------------------------------------* * Filling up the Receivers *----------------------------------------------------------------------* FORM fill_receivers . wa_reclist-receiver = p_email. wa_reclist-rec_type = c_u. APPEND wa_reclist TO t_reclist. CLEAR wa_reclist. ENDFORM. " fill_receivers *&---------------------------------------------------------------------* *& Form send_message *&---------------------------------------------------------------------* * Sending Mail *----------------------------------------------------------------------* FORM send_message . * function module to send email IF NOT t_attachment[] IS INITIAL . *Describe the body of the message CLEAR wa_objpack. REFRESH t_objpack. wa_objpack-transf_bin = space. wa_objpack-head_start = 1. wa_objpack-head_num = 0. wa_objpack-body_start = 1. DESCRIBE TABLE t_objtxt LINES wa_objpack-body_num. wa_objpack-doc_type = 'RAW'. APPEND wa_objpack TO t_objpack. *Create attachment notification wa_objpack-transf_bin = 'X'. wa_objpack-head_start = 1. wa_objpack-head_num = 1. wa_objpack-body_start = 1. *Create packing list DESCRIBE TABLE t_attachment LINES wa_objpack-body_num. wa_objpack-doc_type = 'HTML'. wa_objpack-obj_descr = 'Material Master Data'. wa_objpack-doc_size = wa_objpack-body_num * 255. APPEND wa_objpack TO t_objpack. CLEAR v_sent_all. *Call FM to send e-mail with attachment CALL FUNCTION 'SO_DOCUMENT_SEND_API1' EXPORTING document_data = wa_docdata put_in_outbox = 'X' sender_address = v_ld_sender_address sender_address_type = v_ld_sender_address_type commit_work = 'X' IMPORTING sent_to_all = v_sent_all TABLES packing_list = t_objpack contents_hex = t_attachment contents_txt = t_objtxt receivers = t_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 NE 0. WRITE: 'Sending Failed'. ELSE. WRITE: 'Sending Successful'. ENDIF. ENDIF. ENDFORM. " send_message *&---------------------------------------------------------------------* *& Form GET_DATA *&---------------------------------------------------------------------* * A core subroutine to fetch the data from the corresponding * * database tables. * *----------------------------------------------------------------------* FORM get_data . REFRESH t_mara. SELECT matnr bismt groes UP TO 10 ROWS FROM mara INTO TABLE t_mara. IF sy-subrc EQ 0. SORT t_mara BY matnr. ENDIF. ENDFORM. " GET_DATA *&---------------------------------------------------------------------* *& Form PROCESS_DATA *&---------------------------------------------------------------------* * This is a placeholder subroutine and can be used for processing* * the report data and getting into final internal tables before * * starting the HTML formatting and emailing the data * *----------------------------------------------------------------------* FORM process_data . ENDFORM. " PROCESS_DATA *&---------------------------------------------------------------------* *& Form ITAB_TO_HTML *&---------------------------------------------------------------------* * This is a subroutine which uses standard SAP Function Modules * * WWW_ITAB_TO_HTML_HEADERS, WWW_ITAB_TO_HTML_LAYOUT and * * WWW_ITAB_TO_HTML * *----------------------------------------------------------------------* FORM itab_to_html. DATA: t_header TYPE STANDARD TABLE OF w3head WITH HEADER LINE, " Header t_fields TYPE STANDARD TABLE OF w3fields WITH HEADER LINE, " Fields fs_header TYPE w3head, w_head TYPE w3head. DATA: t_fcat TYPE lvc_t_fcat, " Fieldcatalog wa_fcat LIKE LINE OF t_fcat. *-Populate Fieldcatalog REFRESH t_fcat. CLEAR wa_fcat. wa_fcat-coltext = 'Material Number'. APPEND wa_fcat TO t_fcat. wa_fcat-coltext = 'Old Material No.'. APPEND wa_fcat TO t_fcat. wa_fcat-coltext = 'Size/Dimensions'. APPEND wa_fcat TO t_fcat. *-Fill the Column headings and Properties LOOP AT t_fcat INTO wa_fcat. w_head-text = wa_fcat-coltext. *-Populate the Column Headings CALL FUNCTION 'WWW_ITAB_TO_HTML_HEADERS' EXPORTING field_nr = sy-tabix text = w_head-text fgcolor = 'black' bgcolor = 'red' TABLES header = t_header. *-Populate Column Properties CALL FUNCTION 'WWW_ITAB_TO_HTML_LAYOUT' EXPORTING field_nr = sy-tabix fgcolor = 'black' size = '7' TABLES fields = t_fields. ENDLOOP. *-Title of the Display fs_header-text = 'Automated Emails from SAP Applications'. fs_header-font = 'Arial'. fs_header-size = '2'. *-Preparing the HTML from Intenal Table REFRESH t_html. CALL FUNCTION 'WWW_ITAB_TO_HTML' EXPORTING table_header = fs_header TABLES html = t_html fields = t_fields row_header = t_header itable = t_mara. LOOP AT t_html INTO wa_htmlline. CONCATENATE lv_tmp_str wa_htmlline INTO lv_tmp_str. ENDLOOP . **** Convert HTML data in pit_attach-content to RAW data format IF NOT lv_tmp_str IS INITIAL. CALL FUNCTION 'SSFH_STRING_TO_TABUTF8' EXPORTING cstr_input_data = lv_tmp_str codepage = '4110' * IMPORTING * OSTR_INPUT_DATA_L = TABLES ostr_input_data = t_table EXCEPTIONS conversion_error = 1 internal_error = 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. t_attachment[] = t_table[]. REFRESH: t_table[]. ENDIF. ENDFORM. "ITAB_TO_HTML *&---------------------------------------------------------------------* *& Form BUILD_EMAIL_BODY *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM build_email_body . *...Title wa_docdata-obj_name = 'This is the Email Subject'. *...Description wa_docdata-obj_descr = 'Description of Email with a max length of 50 Chars'. wa_objtxt-line = 'Dear Sir / Madam'. APPEND wa_objtxt TO t_objtxt. wa_objtxt-line = 'This is an Automated Email from SAP Applications. '. APPEND wa_objtxt TO t_objtxt. CLEAR wa_objtxt. APPEND wa_objtxt TO t_objtxt. CLEAR wa_objtxt. APPEND wa_objtxt TO t_objtxt. CLEAR wa_objtxt. APPEND wa_objtxt TO t_objtxt. * Signature with background color wa_objtxt-line = 'Best Regards,'. APPEND wa_objtxt TO t_objtxt. wa_objtxt-line = 'Subrahmanya Pindiproli'. APPEND wa_objtxt TO t_objtxt. wa_objtxt-line = 'Principal Consultant - ERP'. APPEND wa_objtxt TO t_objtxt. ENDFORM. " BUILD_EMAIL_BODY
Sending an email in ABAP should be done via BCS (class CL_BCS and related).
Don't use these obsolete APIs:
- SO_OBJECT_SEND is an old function module for sending emails.
- Etc.
This WIKI can be used as a reference for sending the report output as a screenshot in the body of the E-mail.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'DATA: li_receivers TYPE STANDARD TABLE OF soos1, li_listobject TYPE STANDARD TABLE OF abaplist, li_ali TYPE STANDARD TABLE OF soli, li_ali1 TYPE STANDARD TABLE OF soli, li_ali2 TYPE STANDARD TABLE OF soli, lwa_objecthdchange TYPE sood1, lwa_receivers TYPE soos1, lwa_ali TYPE soli. DATA: l_lines TYPE i, l_length TYPE i. DO 10 TIMES. NEW-LINE. ULINE (99). WRITE: /1 sy-vline, 2 'column1', 24 sy-vline, 25 'Column2', 49 sy-vline, 50 'Column3', 74 sy-vline, 75 'Column4', 99 sy-vline. ENDDO. NEW-LINE. ULINE (99). NEW-LINE. CALL FUNCTION 'SAVE_LIST' EXPORTING list_index = '0' "Pass the list index like 0, 1, 2... TABLES listobject = li_listobject EXCEPTIONS list_index_invalid = 1 OTHERS = 2. IF sy-subrc NE 0. RAISE invalid_list. ENDIF. * Convert the list to ALI format CALL FUNCTION 'TABLE_COMPRESS' TABLES in = li_listobject out = li_ali EXCEPTIONS compress_error = 1 OTHERS = 2. IF sy-subrc NE 0. RAISE compress_error. ENDIF. CLEAR: lwa_objecthdchange. DESCRIBE TABLE li_ali LINES l_lines. DESCRIBE FIELD lwa_ali LENGTH l_length IN CHARACTER MODE. lwa_objecthdchange-objlen = l_length * l_lines. lwa_objecthdchange-objla = sy-langu. lwa_objecthdchange-objnam = 'List'. MOVE sy-title TO lwa_objecthdchange-objdes. MOVE: 1 TO lwa_objecthdchange-objpri, 0 TO lwa_objecthdchange-objsns. CLEAR: lwa_receivers. MOVE: 'X' TO lwa_receivers-snddr, 'X' TO lwa_receivers-sndex, 'U' TO lwa_receivers-recesc, 'E-MAIL' TO lwa_receivers-recextnam. "Pass the recipient ID here. APPEND lwa_receivers TO li_receivers. * Send email CALL FUNCTION 'SO_OBJECT_SEND' EXPORTING * FOLDER_ID = ' ' * FORWARDER = ' ' * OBJECT_FL_CHANGE = ' ' object_hd_change = lwa_objecthdchange * OBJECT_ID = ' ' object_type = 'ALI' * OUTBOX_FLAG = ' ' owner = sy-uname * STORE_FLAG = ' ' * DELETE_FLAG = ' ' sender = sy-uname * CHECK_SEND_AUTHORITY = ' ' * CHECK_ALREADY_SENT = ' ' * GIVE_OBJECT_BACK = * ORIGINATOR = ' ' * ORIGINATOR_TYPE = 'J' * LINK_FOLDER_ID = ' ' * SEND_REQUEST_OID = ' ' * IP_ENCRYPT = 'U' * IP_SIGN = 'U' * IP_REC_COUNT_ADD = * IMPORTING * OBJECT_ID_NEW = * SENT_TO_ALL = * ALL_BINDING_DONE = * OFFICE_OBJECT_KEY = * ORIGINATOR_ID = * E_SEND_REQUEST_OID = TABLES objcont = li_ali * OBJHEAD = * OBJPARA = * OBJPARB = receivers = li_receivers * PACKING_LIST = * ATT_CONT = * ATT_HEAD = * NOTE_TEXT = * LINK_LIST = * APPLICATION_OBJECT = EXCEPTIONS active_user_not_exist = 1 communication_failure = 2 component_not_available = 3 folder_not_exist = 4 folder_no_authorization = 5 forwarder_not_exist = 6 note_not_exist = 7 object_not_exist = 8 object_not_sent = 9 object_no_authorization = 10 object_type_not_exist = 11 operation_no_authorization = 12 owner_not_exist = 13 parameter_error = 14 substitute_not_active = 15 substitute_not_defined = 16 system_failure = 17 too_much_receivers = 18 user_not_exist = 19 originator_not_exist = 20 x_error = 21 OTHERS = 22. IF sy-subrc IS INITIAL. MESSAGE 'Mail has been sent successfully' TYPE 'S'. ELSE. MESSAGE 'Error occured while sending the mail' TYPE 'S'. ENDIF.
For more information, go to the dedicated space: Web Dynpro ABAP Home.
Author: Ashim Chowdhury
Submitted: November 1, 2006
Related Links:
This article explains how to create your own application logging program in ABAP.
SAP provides standard functionality to write into as well as view the application log. This article will explain in detail how to create your own logging function module for application logging using standard SAP log facility. Two transaction code related to application logging are
- SLG0 -> Used to maintain the log object
- SLG1 -> Used to view the log
Configuration step
In this step create a log object.
- Open transaction SLG0. An information message about cross-client table will come.
- 2. Click the button "New Entries". Enter the name and description of your log object (say ZTESTLOG as object name and "Test Log" as object description) and save.
Development Step
The following standard function modules provided by SAP has been used to create the Z function module for logging.
- BAL_GLB_MSG_DEFAULTS_SET
- BAL_DB_SAVE
- BAL_LOG_MSG_ADD
Here are the steps:
1. Go to transaction SE11. Create a z-structure Z_LOG_MESSAGE having the following fields
Component |
Component Type |
---|---|
MSGTY |
SYMSGTY |
MSG_TEXT_1 |
SYMSGV |
MSG_TEXT_2 |
SYMSGV |
MSG_TEXT_3 |
SYMSGV |
MSG_TEXT_4 |
SYMSGV |
2. Crate a message class say ZMESSAGE in transaction SE91 and a message 999 with four placeholder ( & ) as the text.
3. Go to transaction SE37. Create a function group say ZLOG
4. After the function group is created, create a function module in that group. Let is name it ZIU_MESSAGE_LOGGING.
Import parameters:
a. I_LOG_OBJECT type BALOBJ_D -> Application log: Object name (Application code)
b. I_EXTNUMBER type String -> Application Log: External ID
Export parameters: None
Changing parameters: None
Tables parameters:
T_LOG_MESSAGE type Z_LOG_MESSAGE
Exceptions:
LOG_HEADER_INCONSISTENT
LOGGING_ERROR
Paste the code below as the source code
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'FUNCTION ZIU_MESSAGE_LOGGING. *"---------------------------------------------------------------------- *"*"Local interface: *" IMPORTING *" REFERENCE(I_LOG_OBJECT) TYPE BALOBJ_D *" REFERENCE(I_EXTNUMBER) TYPE STRING *" TABLES *" T_LOG_MESSAGE STRUCTURE Z_LOG_MESSAGE *" EXCEPTIONS *" LOG_HEADER_INCONSISTENT *" LOGGING_ERROR *"---------------------------------------------------------------------- * Author :Ashim Chowdhury * DESCRIPTION: This function module is used insert messages in the * application log CONSTANTS: c_message TYPE syst-msgid VALUE 'ZMESSAGE', c_999 TYPE syst-msgno VALUE '999'. DATA: l_log_handle TYPE balloghndl, l_s_log TYPE bal_s_log, l_dummy TYPE string, l_ext_no TYPE bal_s_log-extnumber, l_s_mdef TYPE bal_s_mdef. IF t_log_message[] IS NOT INITIAL. l_s_log-object = i_log_object. l_ext_no = i_extnumber. l_s_log-extnumber = l_ext_no. * Create the log with header data CALL FUNCTION 'BAL_LOG_CREATE' EXPORTING i_s_log = l_s_log IMPORTING e_log_handle = l_log_handle EXCEPTIONS log_header_inconsistent = 1 OTHERS = 2. IF sy-subrc <> 0. CASE sy-subrc. WHEN 1. RAISE log_header_inconsistent. WHEN OTHERS. RAISE logging_error. ENDCASE. ENDIF. l_s_mdef-log_handle = l_log_handle. * Set the default value CALL FUNCTION 'BAL_GLB_MSG_DEFAULTS_SET' EXPORTING i_s_msg_defaults = l_s_mdef EXCEPTIONS OTHERS = 0. * Loop the message table and write the messages into the log LOOP AT t_log_message. * Use the message type ZMESSAGE and msg no 999 * Issue the message in a dummy variable MESSAGE ID c_message TYPE t_log_message-msgty NUMBER c_999 WITH t_log_message-msg_text_1 t_log_message-msg_text_2 t_log_message-msg_text_3 t_log_message-msg_text_4 INTO l_dummy. * The parameters set by message statement will be used * Add the message in the log PERFORM msg_add. ENDLOOP. * save logs in the database CALL FUNCTION 'BAL_DB_SAVE' EXPORTING i_save_all = 'X' EXCEPTIONS log_not_found = 1 save_not_allowed = 2 numbering_error = 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. ENDIF. ENDFUNCTION.Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*-------------------------------------------------------------------- * FORM MSG_ADD *-------------------------------------------------------------------- * Add the message to the log *-------------------------------------------------------------------* FORM msg_add. DATA: l_s_msg TYPE bal_s_msg. * define data of message for Application Log l_s_msg-msgty = sy-msgty. l_s_msg-msgid = sy-msgid. l_s_msg-msgno = sy-msgno. l_s_msg-msgv1 = sy-msgv1. l_s_msg-msgv2 = sy-msgv2. l_s_msg-msgv3 = sy-msgv3. l_s_msg-msgv4 = sy-msgv4. * add this message to log file * (I_LOG_HANDLE is not specified, we want to add to the default log. * If it does not exist we do not care =>EXCEPTIONS log_not_found = 0) CALL FUNCTION 'BAL_LOG_MSG_ADD' EXPORTING * I_LOG_HANDLE = i_s_msg = l_s_msg EXCEPTIONS log_not_found = 0 OTHERS = 1. 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.
Using the function module:
In your ABAP program write the following code and use this function module ZIU_MESSAGE_LOGGING for logging.
* Data declaration-> * Internal table for message logging DATA: it_log_message TYPE STANDARD TABLE OF z_log_message, wa_log_message TYPE z_log_message, l_ext_number TYPE string. Constants: c_obj_zxiproxy TYPE balobj_d VALUE 'ZTESTLOG'. * Now populate the internal table with the log messages as shown below. wa_log_message- * msgty is the type of the message. * E -> Error, W -> Warning, S -> Success * Logging code for insert message into log CLEAR wa_log_message. wa_log_message-msgty = 'E'. " Can use W or S wa_log_message-msg_text_1 = < Message text 1>. wa_log_message-msg_text_2 = < Message text 2> wa_log_message-msg_text_3 = < Message text 3> wa_log_message-msg_text_4 = < Message text 4> * Append the message into the internal table APPEND wa_log_message TO it_log_message. At the end transfer the log message to the system log by calling function module ZIU_MESSAGE_LOGGING. L_EXT_NUMBER will bt any string of your choice. * Function module ZIU_MESSAGE_LOGGING will do the logging * i_log_object is the object type (to be configrd using txn SLG0 CALL FUNCTION 'ZIU_MESSAGE_LOGGING' EXPORTING i_log_object = c_obj_zxiproxy i_extnumber = l_ext_number TABLES t_log_message = it_log_message EXCEPTIONS log_header_inconsistent = 1 logging_error = 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. ENDIF.
The logged messages can be viewed in transaction SLG1. For filtering the messages use the Object type.
- Web Dynpro ABAP
- ABAP - BSP
- SAP GUI Programming (Dynpro, etc.)
- ITS
- creating pfstatus using the class cl_salv_table
Consuming Web Services with ABAP - WSDL
To get the process started, we turn to SE80 TCODE go to workbench & edit object.
From the Enterprise Services Tab, we are going to select Client Proxy and then hit new create button.
Next up we have to choose where our WSDL file is going to come from.
But in this case we are going to connect directly to the WSDL definition to a file on our local machine.
Give the path of WSDL file .
Now we are asked what Package we want to place the generated object in as well as what prefix we want to use. I am going to make the object Local Private by putting in my $TMP package. To follow SAP naming standards, as well as my company's standards, I will get the object a prefix of ZES_
Activate the Client Proxy.
You can see
- ABAP class
- Structures and table types to represent all the importing and exporting data.ABAP CLASS
Structures and table types to represent all the importing and exporting data.
Now we need to configure a Logical Port for it.
We can do this in transaction LPCONFIG.
We can configure more than one Logical Port and specify the one we want at runtime. However for this solution we will just configure one port and make it the default.
Inside the definition of the Logical Port we can adjust settings for the Client Proxy.
settings that were imported from the WSDL definition.
We can then return to SE80 in Enterprise service tag and perform a test on the WebService by hitting F8. We then get a dialog that allows us to set parameters for our test.
you get a success message like the following:
Now coding In SE38
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'PARAMETER: p_isbn(100) TYPE c OBLIGATORY. DATA: * Reference variables for proxy and exception class lo_clientproxy TYPE REF TO zes_co_looky_book_service_soap, lo_sys_exception TYPE REF TO cx_ai_system_fault, * Structures to set and get message content ls_request TYPE zes_get_info_soap_in, ls_response TYPE zes_get_info_soap_out. **Set the input parameter ls_request-value = 'INPUT TEST'. **Create the Proxy and Clall it. CREATE OBJECT lo_clientproxy. TRY. CALL METHOD lo_clientproxy->get_info EXPORTING input = ls_request IMPORTING output = ls_response. CATCH cx_ai_system_fault INTO lo_sys_exception. * Error handling ENDTRY. COMMIT WORK. **Write Out the Basic Information WRITE: / ls_response-value.
List of all pages
Pages at first level
List of all pages
Pages at first level
List of all pages
Pages of first level
REPORT zvenkattest. PARAMETERS: p_file TYPE rlgrap-filename . START-OF-SELECTION . CALL FUNCTION 'GUI_DELETE_FILE' EXPORTING file_name = p_file EXCEPTIONS failed = 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. WRITE:/ 'the file' , p_file , 'removed successfully '.
Author: Janagar Sundaramoorthy
Submitted: <19 Feb 2009>
Description:
TMP_GUI_DIRECTORY_LIST_FILES
The function module retrieves all of the files and subdirectories on the Presentation Server (PC) for a given directory. When a value other than * or *.* is used for the filter, you will not get any directories, unless they match your wildcard filter. For example, if you entered *.png, then only files and directories that end in png will be returned by the function.
DATA: lc_directory LIKE bdschko16-target_dir VALUE 'C:\TEMP\', lc_filter(20) TYPE c VALUE '*.*', li_file_count TYPE i, li_dir_count TYPE i, ltab_dir_table LIKE sdokpath OCCURS 0 WITH HEADER LINE, ltab_file_table LIKE sdokpath OCCURS 0 WITH HEADER LINE. CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES' EXPORTING directory = lc_directory filter = lc_filter IMPORTING file_count = li_file_count dir_count = li_dir_count TABLES file_table = ltab_file_table dir_table = ltab_dir_table EXCEPTIONS cntl_error = 1 OTHERS = 2.
Author: Alessandro Spadoni
Submitted: 21,Mar 2011
How to make a Zip file on Presentation Server : upload a PDF file , create a new zip file and adding to it
DATA: zip_tool TYPE REF TO cl_abap_zip, filename TYPE string VALUE 'C:\test\binfile.pdf', filename_zip TYPE string VALUE 'C:\test\zipfile.zip'. DATA: t_data_tab TYPE TABLE OF x255, bin_size TYPE i, buffer_x TYPE xstring, buffer_zip TYPE xstring. START-OF-SELECTION. **upload file from presentation server CLEAR: t_data_tab[],bin_size. CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = filename filetype = 'BIN' IMPORTING filelength = bin_size * HEADER = TABLES data_tab = t_data_tab EXCEPTIONS file_open_error = 1 file_read_error = 2 no_batch = 3 gui_refuse_filetransfer = 4 invalid_type = 5 no_authority = 6 unknown_error = 7 bad_data_format = 8 header_not_allowed = 9 separator_not_allowed = 10 header_too_long = 11 unknown_dp_error = 12 access_denied = 13 dp_out_of_memory = 14 disk_full = 15 dp_timeout = 16 OTHERS = 17 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. **get xstring CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' EXPORTING input_length = bin_size IMPORTING buffer = buffer_x TABLES binary_tab = t_data_tab EXCEPTIONS failed = 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. **create zip tool CREATE OBJECT zip_tool. **add binary file CALL METHOD zip_tool->add EXPORTING name = 'binfile.pdf' content = buffer_x. **get binary ZIP file CALL METHOD zip_tool->save RECEIVING zip = buffer_zip. CLEAR: t_data_tab[],bin_size. CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING buffer = buffer_zip IMPORTING output_length = bin_size TABLES binary_tab = t_data_tab. **download ZIP file CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING bin_filesize = bin_size filename = filename_zip filetype = 'BIN' TABLES data_tab = t_data_tab EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22. IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.
"Definition of data for get download path DATA : fullpath TYPE string, filename TYPE string, path TYPE string, user_action TYPE i, encoding TYPE abap_encoding. IF p_file IS INITIAL. CALL METHOD cl_gui_frontend_services=>file_save_dialog EXPORTING window_title = 'Gui_Download Demo' with_encoding = 'X' initial_directory = 'D:\SAP' CHANGING filename = filename path = path fullpath = fullpath user_action = user_action file_encoding = encoding EXCEPTIONS cntl_error = 1 error_no_gui = 2 not_supported_by_gui = 3 OTHERS = 4. IF sy-subrc <> 0. EXIT. ENDIF. IF user_action <> cl_gui_frontend_services=>action_ok. EXIT. ENDIF. ELSE. fullpath = p_file. ENDIF. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = fullpath filetype = 'DAT' TABLES data_tab = it_top " download internal table EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.
REPORT zvenkattest. DATA: file_exists TYPE xflag . PARAMETERS: file LIKE rlgrap-filename . AT SELECTION-SCREEN ON VALUE-REQUEST FOR file . CALL FUNCTION 'F4_FILENAME' EXPORTING program_name = syst-cprog dynpro_number = syst-dynnr field_name = 'FILE' IMPORTING file_name = file. START-OF-SELECTION . CALL FUNCTION 'DX_FILE_EXISTENCE_CHECK' EXPORTING filename = file pc = 'X' IMPORTING file_exists = file_exists EXCEPTIONS rfc_error = 1 frontend_error = 2 no_authority = 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. IF file_exists = 'X'. WRITE:/ 'FILE EXISTS' . ELSE . WRITE:/ 'FILE doesnt EXISTS' . ENDIF.
REPORT zvenkattest. *------------------------------------------------------------* * selection screen parameters *------------------------------------------------------------* PARAMETERS: p_source LIKE rlgrap-filename , " This is the source file name p_target LIKE rlgrap-filename . " This is the target file name *------------------------------------------------------------* * start of selection *------------------------------------------------------------* START-OF-SELECTION . CALL FUNCTION 'SCMS_FILE_COPY' EXPORTING src_filename = p_source src_frontend = 'X' dst_filename = p_target dst_frontend = 'X'. *----display the output IF sy-subrc EQ 0. WRITE:/ ' the source file name was:', p_source . WRITE:/ ' the copied file name was:' , p_target . ENDIF.
REPORT zfile_with_delchar. TABLES: mara. TYPES: BEGIN OF ty_out, line(150), END OF ty_out, BEGIN OF ty_mat, matnr TYPE mara-matnr, mtart TYPE mara-mtart, mbrsh TYPE mara-mbrsh, meins TYPE mara-meins, END OF ty_mat. DATA: it_out TYPE STANDARD TABLE OF ty_out WITH HEADER LINE, it_mat TYPE STANDARD TABLE OF ty_mat WITH HEADER LINE. **--Selection-screen Design SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE title. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 5(18) title1. SELECT-OPTIONS: s_matnr FOR mara-matnr. SELECTION-SCREEN POSITION 1 . SELECTION-SCREEN END OF LINE . SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 7(18) title2. PARAMETERS: p_dlim TYPE c OBLIGATORY. SELECTION-SCREEN POSITION 1 . SELECTION-SCREEN END OF LINE . SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 7(18) title3. PARAMETERS: p_file TYPE rlgrap-filename. SELECTION-SCREEN POSITION 1 . SELECTION-SCREEN END OF LINE . SELECTION-SCREEN END OF BLOCK b1. INITIALIZATION . title = 'enter the entries'. title1 = 'material number'. title2 = 'delimiter'. title3 = 'file name'. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file . CALL FUNCTION 'F4_FILENAME' EXPORTING program_name = syst-cprog dynpro_number = syst-dynnr field_name = 'P_FILE' IMPORTING file_name = p_file. START-OF-SELECTION. **--Get the data from material table SELECT matnr mtart mbrsh meins FROM mara INTO TABLE it_mat WHERE matnr IN s_matnr. **--Prepare output file with specified delimit char LOOP AT it_mat. IF p_dlim = 'X'. CONCATENATE it_mat-matnr it_mat-mtart it_mat-mbrsh it_mat-meins INTO it_out-line SEPARATED BY cl_abap_char_utilities=>horizontal_tab. ELSE. CONCATENATE it_mat-matnr it_mat-mtart it_mat-mbrsh it_mat-meins INTO it_out-line SEPARATED BY p_dlim. ENDIF. APPEND it_out. CLEAR: it_out, it_mat. ENDLOOP. **--Download the data DATA: file TYPE string . file = p_file . CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = file TABLES data_tab = it_out EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22. IF sy-subrc = 0. WRITE:/ 'File downloaded successfully'. ENDIF.
REPORT zsave_file_pres_oops . DATA: your_file_name TYPE string, your_file_path TYPE string, the_full_path TYPE string. TYPES: BEGIN OF the_alv_structure, field1(10) TYPE c, field2(10) TYPE c, END OF the_alv_structure. DATA: the_alv_itab TYPE TABLE OF the_alv_structure. DATA: wa LIKE LINE OF the_alv_itab. wa-field1 = 'A1'. wa-field2 = 'B1'. APPEND wa TO the_alv_itab. wa-field1 = 'A2'. wa-field2 = 'B2'. APPEND wa TO the_alv_itab. wa-field1 = 'A3'. wa-field2 = 'B3'. APPEND wa TO the_alv_itab. CALL METHOD cl_gui_frontend_services=>file_save_dialog EXPORTING default_extension = '.xls' default_file_name = 'Text' CHANGING filename = your_file_name path = your_file_path fullpath = the_full_path. CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING filename = the_full_path write_field_separator = 'X' CHANGING data_tab = the_alv_itab.
With this FM we can open our file that we have in byte form (for example: passed by a WebServices) in default presentation server application.
File will be saved in a system temp directory and then open.
To do this we have to pass to the function:
- file name with extension (so the system will know which application should be used to open it)
- file data in byte tab (for example: it can be SOLIX structure or table of X buffer)
FUNCTION ZFILE_OPEN. *"---------------------------------------------------------------------- *"*"Lokalny interfejs: *" IMPORTING *" REFERENCE(FILE_NAME) TYPE STRING *" TABLES *" XTAB *"---------------------------------------------------------------------- DATA: temp_dir TYPE string, separator TYPE c, lfname TYPE string, codepage LIKE tcp00-cpcodepage, dyn_codepage LIKE tcp00-cpcodepage, aba_codepage TYPE abap_encod. * Get the Path to the TEMP Directory CALL METHOD cl_gui_frontend_services=>get_temp_directory CHANGING temp_dir = temp_dir. CALL METHOD cl_gui_cfw=>flush EXCEPTIONS cntl_system_error = 1 cntl_error = 2 OTHERS = 3. IF sy-subrc <> 0. ENDIF. * Get the system`s separator CALL METHOD cl_gui_frontend_services=>get_file_separator CHANGING file_separator = separator. CALL METHOD cl_gui_cfw=>flush EXCEPTIONS cntl_system_error = 1 cntl_error = 2 OTHERS = 3. IF sy-subrc <> 0. ENDIF. * Concatenate file path CONCATENATE temp_dir separator file_name INTO lfname. * Get system codepage CALL FUNCTION 'SYSTEM_CODEPAGE' IMPORTING codepage = codepage current_dynamic_codepage = dyn_codepage. aba_codepage = dyn_codepage. * Save XTAB to file CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = lfname codepage = aba_codepage TABLES data_tab = xtab. IF sy-subrc <> 0. ENDIF. * Execute default file aplication CALL METHOD cl_gui_frontend_services=>execute EXPORTING document = lfname EXCEPTIONS cntl_error = 1 error_no_gui = 2 bad_parameter = 3 file_not_found = 4 path_not_found = 5 file_extension_unknown = 6 error_execute_failed = 7 OTHERS = 8. IF sy-subrc <> 0. ENDIF. ENDFUNCTION.
REPORT zvenkattest. *---------------------------------------------------------------------------------------* * selection screen design *---------------------------------------------------------------------------------------* PARAMETERS: p_file LIKE rlgrap-filename . *---------------------------------------------------------------------------------------* * data declarations *---------------------------------------------------------------------------------------* DATA: pathname TYPE char50 , filename TYPE char50 . *---------------------------------------------------------------------------------------* * at selection screen for field *---------------------------------------------------------------------------------------* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file . CALL FUNCTION 'F4_FILENAME' EXPORTING program_name = syst-cprog dynpro_number = syst-dynnr field_name = 'P_FILE' IMPORTING file_name = p_file. *---------------------------------------------------------------------------------------* * start of selection *---------------------------------------------------------------------------------------* START-OF-SELECTION . CALL FUNCTION '/SAPDMC/LSM_PATH_FILE_SPLIT' EXPORTING pathfile = p_file IMPORTING pathname = pathname filename = filename. *---------------------------------------------------------------------------------------* * display output *---------------------------------------------------------------------------------------* WRITE:/ 'PATHNAME IS : ' ,pathname . WRITE:/ 'FILENAME IS : ' ,filename .
List of all pages
Pages at first level
REPORT zdownload_file. DATA: BEGIN OF itab OCCURS 0, field1 TYPE char9, field2 TYPE char2, field3 TYPE char2, END OF itab. DATA: output(100) TYPE c. PARAMETERS: p_file TYPE localfile . START-OF-SELECTION. itab-field1 = 'name1'. itab-field2 = '11'. itab-field3 = '23' . APPEND itab . itab-field1 = 'name2'. itab-field2 = '41'. itab-field3 = '53' . APPEND itab . itab-field1 = 'name3'. itab-field2 = '53'. itab-field3 = '87' . APPEND itab . OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT . LOOP AT itab. CONCATENATE itab-field1 itab-field2 itab-field3 INTO output SEPARATED BY ','. TRANSFER output TO p_file. ENDLOOP. CLOSE DATASET p_file.
Program for writing into application server from Internal table
REPORT z_opendataset_output. *--------------------------------------------------------------------------------------* * variable declaration *--------------------------------------------------------------------------------------* DATA: w_file(80) TYPE c , w_count TYPE i VALUE 0, w_log(310) TYPE c. *-----------------------------------------------------------------------------------* * internal table declarations *----------------------------------------------------------------------------------* DATA: BEGIN OF it_log OCCURS 0, w_vbeln LIKE vbap-vbeln, "Sales Document w_posnr(6) , " Sales Document Item w_matnr(18) , " material no w_cname(30) , " characteristic name w_ovalue(90) , " old value of characteristic w_nvalue(90) , " new value of characteristic END OF it_log . *-----work area for the table DATA: wa_it_log LIKE LINE OF it_log. *---------------------------------------------------------------------------------------* * selection screen *--------------------------------------------------------------------------------------* PARAMETERS: p_file TYPE ibipparms-path. *---------------------------------------------------------------------------------------* * start of selection *--------------------------------------------------------------------------------------* START-OF-SELECTION . *----this is for the file upload PERFORM log_file_upload. *---------------------------------------------------------------------------------------* * file upload *--------------------------------------------------------------------------------------* FORM log_file_upload . DATA: l_msg(80) TYPE c, l_name(200) TYPE c, l_ext(5) TYPE c, l_file(300) TYPE c. MOVE p_file TO w_file. *----get the count of lines in the table DESCRIBE TABLE it_log LINES w_count. IF NOT w_count IS INITIAL. OPEN DATASET w_log FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. IF sy-subrc <> 0. WRITE:/ 'Error in opening file'. ELSE. *----Setting header wa_it_log-w_vbeln = 'Order'. wa_it_log-w_posnr = 'Item'. wa_it_log-w_matnr = 'Material'. wa_it_log-w_cname = 'Char Name'. wa_it_log-w_ovalue = 'Old Value'. wa_it_log-w_nvalue = 'New Value'. TRANSFER wa_it_log TO w_log. MOVE: sy-uline(255) TO wa_it_log. TRANSFER wa_it_log TO w_log. MOVE: ' ' TO wa_it_log. TRANSFER wa_it_log TO w_log. LOOP AT it_log. CLEAR wa_it_log. wa_it_log-w_vbeln = it_log-w_vbeln. wa_it_log-w_posnr = it_log-w_posnr. wa_it_log-w_matnr = it_log-w_matnr. wa_it_log-w_cname = it_log-w_cname. wa_it_log-w_ovalue = it_log-w_ovalue. wa_it_log-w_nvalue = it_log-w_nvalue. TRANSFER wa_it_log TO w_log. CLEAR w_excel_string. ENDLOOP. *---text-307 'log file saved successfully to :' CONCATENATE text-307 w_log INTO l_msg SEPARATED BY space. MESSAGE l_msg TYPE 'S'. ENDIF. ENDIF. ENDFORM. " log_file_upload
Declare input and output file parameters on selection screen
SELECTION-SCREEN BEGIN OF BLOCK block01 WITH FRAME TITLE text-001. "File Path PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY , "INPUT FILE PATH p_path LIKE rlgrap-filename OBLIGATORY . "Output file path
Providing F4 help for File path
AT SELECTION-SCREEN OUTPUT. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. **Providing F4 help for user to enter file name CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE' EXPORTING directory = p_file IMPORTING serverfile = p_file EXCEPTIONS canceled_by_user = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE e009(zz) WITH p_file. ENDIF. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. **Providing F4 help for user to enter file name CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE' EXPORTING directory = p_path IMPORTING serverfile = p_path EXCEPTIONS canceled_by_user = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE e009(zz) WITH p_path. ENDIF.
To read a file from Application server
DATA : lv_str(50) TYPE c. *Read the data from application server OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT. IF sy-subrc NE 0. MESSAGE e009(zz) WITH p_file. ENDIF. DO. **Writing the data into internal table READ DATASET p_file INTO lv_str. IF sy-subrc = 0. SPLIT lv_str AT '#' INTO gwa_file-f1 gwa_file-f2 gwa_file-f3 gwa_file-f4 gwa_file-f5 append gwa_file to it_file. ELSE. EXIT. ENDIF. ENDDO. CLOSE DATASET p_file.
To Upload file back to application server
DATA : lv_filename TYPE rlgrap-filename, * lv_file(60) TYPE c, lv_string(100) TYPE c , c_con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab. CONCATENATE p_path c_filename INTO lv_filename. * Writing the file to the Application server OPEN DATASET lv_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. IF sy-subrc <> 0. MESSAGE e009(zz) WITH lv_filename. ENDIF. LOOP AT it_final INTO gwa_final. CONCATENATE gwa_file-f1 gwa_file-f2 gwa_file-f3 gwa_file-f4 gwa_file-f5 INTO lv_string SEPARATED BY c_con_tab. TRANSFER lv_string TO lv_filename. ENDLOOP. CLOSE DATASET lv_filename.
*To Open the file from application server : OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT. IF sy-subrc NE 0. MESSAGE e009(message CLASS ) WITH p_file. " Displaying an error message when file is not opened ENDIF. DO. * to read the data from file to a string READ DATASET p_file INTO lv_str. IF sy-subrc = 0. SPLIT lv_str AT '#' INTO gwa_file-country_code. gwa_file-f1 gwa_file-f2 gwa_file-f3 gwa_file-f4 . APPEND gwa_file TO it_file. ELSE. EXIT. ENDIF. ENDDO. CLOSE DATASET p_file.
Applies to:
This document applies to SAP ECC 6.0, SAP Netweaver 2004s. For more information, visit the ABAP homepage.
Summary
This program is used to perform file operation such as Delete\ upload\ download from application server. There is no standard transaction to delete file from application server. So this sample code can be useful when someone wants to delete a file from application server.
Author: Sourabh Batwara
Company: Cognizant Technology Solution
Submitted: 1st December 2010
Author Bio:
Sourabh Batwara is working in Cognizant technology solution as a SAP Consultant. He has 4.5 years of experience in SAP.
Description
While working with file interface we have to delete, upload or download files from application server. but for deletion, there is no standard transaction available in SAP. This program will help to delete file from application server.
Selection screen shots
Upload File:
Download File
Delete File
Program Code
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'*----------------------------------------------------------------------- * Program Name : ZSB_FILE_OPERATION * Creation date : 01.12.2010 * Description : This Test program is used to perform file * operation on application server such as delete/upload/download. *----------------------------------------------------------------------- REPORT zsb_file_operation. *----------------------------------------------------------------------* * DATA DECLEARATION * *----------------------------------------------------------------------* * boolean constants for function-parameters and other objects TYPE-POOLS: esp1. * Boolean values TYPES: boolean TYPE esp1_boolean. DATA: p_file(128), " File path lv_ans, " Popup answer lv_flag LIKE bapistdtyp-boolean. CONSTANTS : c_yes TYPE c VALUE '1', c_no TYPE c VALUE '0', c_upload(4) TYPE c VALUE 'CG3Z', c_dnload(4) TYPE c VALUE 'CG3Y', c_x TYPE c VALUE 'X', c_j TYPE c VALUE 'J', c_n TYPE c VALUE 'N', true TYPE boolean VALUE esp1_true. *----------------------------------------------------------------------* * SELECTION SCREEN * *----------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. PARAMETERS : r_upload RADIOBUTTON GROUP rb1 USER-COMMAND del DEFAULT 'X', " Upload file r_dnload RADIOBUTTON GROUP rb1, " Download file r_delete RADIOBUTTON GROUP rb1. " Delete file SELECTION-SCREEN END OF BLOCK b1. SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002. PARAMETERS: p_dir LIKE rlgrap-filename MODIF ID del, " Dir Path p_file1 LIKE rlgrap-filename MODIF ID del. " Path name SELECTION-SCREEN END OF BLOCK b2. SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003. PARAMETERS: p_local LIKE rcgfiletr-ftfront MODIF ID up, " Dir Path p_path LIKE rcgfiletr-ftappl MODIF ID up, " Path name p_over AS CHECKBOX MODIF ID up. " Overwrite SELECTION-SCREEN END OF BLOCK b3. SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004. PARAMETERS: p_path1 LIKE rcgfiletr-ftappl MODIF ID dn, " Path name p_local1 LIKE rcgfiletr-ftfront MODIF ID dn, " Dir Path p_over1 AS CHECKBOX MODIF ID dn. SELECTION-SCREEN END OF BLOCK b4. *----------------------------------------------------------------------* * AT SELECTION SCREEN OUTPUT * *----------------------------------------------------------------------* AT SELECTION-SCREEN OUTPUT. LOOP AT SCREEN. IF screen-group1 = 'DEL'. IF r_delete = c_x. screen-invisible = c_no . screen-active = c_yes . ELSE. screen-invisible = c_yes . screen-active = c_no . ENDIF. MODIFY SCREEN. ENDIF. IF screen-group1 = 'UP'. IF r_upload = c_x. screen-invisible = c_no . screen-active = c_yes . ELSE. screen-invisible = c_yes . screen-active = c_no . ENDIF. MODIFY SCREEN. ENDIF. IF screen-group1 = 'DN'. IF r_dnload = c_x. screen-invisible = c_no . screen-active = c_yes . ELSE. screen-invisible = c_yes . screen-active = c_no . ENDIF. MODIFY SCREEN. ENDIF. ENDLOOP. *----------------------------------------------------------------------* * AT SELECTION SCREEN ON VALUE REQUEST * *----------------------------------------------------------------------* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_local. CALL FUNCTION 'F4_FILENAME' EXPORTING field_name = 'P_LOCAL' IMPORTING file_name = p_local. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_local1. CALL FUNCTION 'F4_FILENAME' EXPORTING field_name = 'P_LOCAL1' IMPORTING file_name = p_local1. *----------------------------------------------------------------------* * START OF SELECTION * *----------------------------------------------------------------------* START-OF-SELECTION. IF r_upload = c_x. PERFORM file_upload. ELSEIF r_dnload = c_x. PERFORM file_dnload. ELSE. PERFORM file_delete. ENDIF. *&---------------------------------------------------------------------* *& Form FILE_UPLOAD *&---------------------------------------------------------------------* * Form to upload file from frontend to application server *----------------------------------------------------------------------* FORM file_upload . CLEAR lv_flag. IF p_over = c_x. lv_flag = 1. ENDIF. CALL FUNCTION 'C13Z_FILE_UPLOAD_BINARY' EXPORTING i_file_front_end = p_local i_file_appl = p_path i_file_overwrite = lv_flag EXCEPTIONS fe_file_not_exists = 1 fe_file_read_error = 2 ap_no_authority = 3 ap_file_open_error = 4 ap_file_exists = 5. CASE sy-subrc. WHEN '0'. MESSAGE s899(bd) WITH 'File uploaded successfully'. WHEN '1'. MESSAGE e899(bd) WITH 'File does not exist'. WHEN '2'. MESSAGE e899(bd) WITH 'Error in file reading'. WHEN '3'. MESSAGE e899(bd) WITH 'Authorization Error'. WHEN '5'. * file already exists, ask if file can be overwritten CALL FUNCTION 'C14A_POPUP_ASK_FILE_OVERWRITE' IMPORTING e_flg_continue = lv_flag EXCEPTIONS OTHERS = 1. IF sy-subrc = 0 AND lv_flag = true. CALL FUNCTION 'C13Z_FILE_UPLOAD_BINARY' EXPORTING i_file_front_end = p_local i_file_appl = p_path i_file_overwrite = lv_flag. IF sy-subrc IS INITIAL. MESSAGE s899(bd) WITH 'File uploaded successfully'. ENDIF. ENDIF. ENDCASE. ENDFORM. " FILE_UPLOAD *&---------------------------------------------------------------------* *& Form FILE_DNLOAD *&---------------------------------------------------------------------* * Form to download the file from application server to frontend *----------------------------------------------------------------------* FORM file_dnload . CLEAR lv_flag. IF p_over1 = c_x. lv_flag = 1. ENDIF. CALL FUNCTION 'C13Z_FILE_DOWNLOAD_BINARY' EXPORTING i_file_front_end = p_local1 i_file_appl = p_path1 i_file_overwrite = lv_flag EXCEPTIONS fe_file_open_error = 1 fe_file_exists = 2 ap_no_authority = 4. CASE sy-subrc. WHEN '0'. MESSAGE s899(bd) WITH 'File downloaded successfully'. WHEN '1'. MESSAGE e899(bd) WITH 'Error while opening file'. WHEN '2'. * file already exists, ask if file can be overwritten CALL FUNCTION 'C14A_POPUP_ASK_FILE_OVERWRITE' IMPORTING e_flg_continue = lv_flag EXCEPTIONS OTHERS = 1. IF sy-subrc = 0 AND lv_flag = true. CALL FUNCTION 'C13Z_FILE_DOWNLOAD_BINARY' EXPORTING i_file_front_end = p_local1 i_file_appl = p_path1 i_file_overwrite = lv_flag. IF sy-subrc IS INITIAL. MESSAGE s899(bd) WITH 'File downloaded successfully'. ENDIF. ENDIF. WHEN '4'. MESSAGE e899(bd) WITH 'Authorization Error'. ENDCASE. ENDFORM. " FILE_DNLOAD *----------------------------------------------------------------------* * Form FILE_DELETE * *----------------------------------------------------------------------* * Form to delete file from application server * *----------------------------------------------------------------------* FORM file_delete . * File path CONCATENATE p_dir p_file1 INTO p_file. * Check file exists OPEN DATASET p_file FOR INPUT IN BINARY MODE. IF sy-subrc NE 0. MESSAGE e899(bd) WITH p_file 'does not exist'. EXIT. ELSE. * Popup window CALL FUNCTION 'POPUP_CONTINUE_YES_NO' EXPORTING defaultoption = c_n textline1 = p_file titel = 'Are you sure to delete this file?' IMPORTING answer = lv_ans EXCEPTIONS OTHERS = 1. ENDIF. CLOSE DATASET p_file. IF lv_ans EQ c_j. * Delete file DELETE DATASET p_file. IF sy-subrc NE 0. MESSAGE e899(bd) WITH 'Invalid file name' p_file. ELSE. CLOSE DATASET p_file. MESSAGE s899(bd) WITH p_dir p_file1 'has been deleted'. ENDIF. ENDIF. ENDFORM. " FILE_DELETE
REPORT zdelete. *----------------------------------------------------------------------* * Delete a file on the application server. *----------------------------------------------------------------------* PARAMETERS: p_dir LIKE rlgrap-filename DEFAULT '/usr/sap/trans/', p_file1 LIKE rlgrap-filename. DATA: p_file(128). DATA: w_ans. START-OF-SELECTION. CONCATENATE p_dir p_file1 INTO p_file. *----------------------------------------------------------------------* * check file exists *----------------------------------------------------------------------* OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT. IF sy-subrc NE 0. MESSAGE e899(bd) WITH p_file 'DOES NOT EXIST'. EXIT. ELSE. CALL FUNCTION 'POPUP_CONTINUE_YES_NO' EXPORTING defaultoption = 'N' textline1 = p_dir textline2 = p_file1 titel = 'ARE YOU SURE YOU WANT TO DELETE' IMPORTING answer = w_ans EXCEPTIONS OTHERS = 1. ENDIF. CLOSE DATASET p_file. CHECK w_ans = 'J'. *----------------------------------------------------------------------* * delete *----------------------------------------------------------------------* DELETE DATASET p_file. IF sy-subrc NE 0. MESSAGE e899(bd) WITH 'INVALID FILE NAME' p_file. ELSE. CLOSE DATASET p_file. MESSAGE i899(bd) WITH p_dir p_file1 'DELETED SUCCESFULLY'. ENDIF.
Output:-
*Enter the Directory name & File Name *
*Press F8*
*Press Enter*
*Go to Transcation AL11 ->Double Click on DIR_TEMP-> You can find the List of file*
*Before Deleting the File*
*After Deleting the File*
When you access sequential files on the application server using the following statements
- OPEN DATASET
- READ DATASET
- TRANSFER
- DELETE DATASET
the system automatically checks the user’s authorization against the authorization object S_DATASET. Based on the User Role and Authorizations the above activities will be possible.
Hence the developers must check the authorization in ABAP program before accessing the file using the function module AUTHORITY_CHECK_DATASET.
REPORT zshiva_itab_to_xml_app_server. TYPE-POOLS: ixml. TYPES: BEGIN OF xml_line, data(256) TYPE x, END OF xml_line. DATA fname(30) VALUE 'D:\XML\shiva.XML'. DATA: l_ixml TYPE REF TO if_ixml, l_streamfactory TYPE REF TO if_ixml_stream_factory, l_ostream TYPE REF TO if_ixml_ostream, l_renderer TYPE REF TO if_ixml_renderer, l_document TYPE REF TO if_ixml_document. DATA: l_element_flights TYPE REF TO if_ixml_element, l_element_airline TYPE REF TO if_ixml_element, l_element_flight TYPE REF TO if_ixml_element, l_element_from TYPE REF TO if_ixml_element, l_element_to TYPE REF TO if_ixml_element, l_element_dummy TYPE REF TO if_ixml_element, l_value TYPE string. DATA: l_xml_table TYPE TABLE OF xml_line, rec TYPE xml_line, l_xml_size TYPE i, l_rc TYPE i. DATA: lt_spfli TYPE TABLE OF spfli. DATA: l_spfli TYPE spfli. START-OF-SELECTION. * Fill the internal table SELECT * FROM spfli INTO TABLE lt_spfli. * Sort internal table SORT lt_spfli BY carrid. * Start filling xml dom object from internal table LOOP AT lt_spfli INTO l_spfli. AT FIRST. * Creating a ixml factory l_ixml = cl_ixml=>create( ). * Creating the dom object model l_document = l_ixml->create_document( ). * Fill root node with value flights l_element_flights = l_document->create_simple_element( name = 'flights' parent = l_document ). ENDAT. AT NEW carrid. * Create element 'airline' as child of 'flights' l_element_airline = l_document->create_simple_element( name = 'airline' parent = l_element_flights ). * Create attribute 'code' of node 'airline' l_value = l_spfli-carrid. l_rc = l_element_airline->set_attribute( name = 'code' value = l_value ). * Create attribute 'name' of node 'airline' SELECT SINGLE carrname FROM scarr INTO l_value WHERE carrid EQ l_spfli-carrid. l_rc = l_element_airline->set_attribute( name = 'name' value = l_value ). ENDAT. AT NEW connid. * Create element 'flight' as child of 'airline' l_element_flight = l_document->create_simple_element( name = 'flight' parent = l_element_airline ). * Create attribute 'number' of node 'flight' l_value = l_spfli-connid. l_rc = l_element_flight->set_attribute( name = 'number' value = l_value ). ENDAT. * Create element 'from' as child of 'flight' CONCATENATE l_spfli-cityfrom ',' l_spfli-countryfr INTO l_value. l_element_from = l_document->create_simple_element( name = 'from' value = l_value parent = l_element_flight ). * Create attribute 'airport' of node 'from' l_value = l_spfli-airpfrom. l_rc = l_element_from->set_attribute( name = 'airport' value = l_value ). * Create element 'to' as child of 'flight' CONCATENATE l_spfli-cityto ',' l_spfli-countryto INTO l_value. l_element_to = l_document->create_simple_element( name = 'to' value = l_value parent = l_element_flight ). * Create attribute 'airport' of node 'from' l_value = l_spfli-airpto. l_rc = l_element_to->set_attribute( name = 'airport' value = l_value ). * Create element 'departure' as child of 'flight' l_value = l_spfli-deptime. l_element_dummy = l_document->create_simple_element( name = 'departure' value = l_value parent = l_element_flight ). * Create element 'arrival' as child of 'flight' l_value = l_spfli-arrtime. l_element_dummy = l_document->create_simple_element( name = 'arrival' value = l_value parent = l_element_flight ). * Create element 'type' as child of 'flight' CASE l_spfli-fltype. WHEN 'X'. l_value = 'Charter'. WHEN OTHERS. l_value = 'Scheduled'. ENDCASE. l_element_dummy = l_document->create_simple_element( name = 'type' value = l_value parent = l_element_flight ). ENDLOOP. IF sy-subrc NE 0. MESSAGE 'No data into db table ''spfli'', please run program ''SAPBC_DATA_GENERATOR'' with transaction ''SA38''' TYPE 'E'. ENDIF. * Creating a stream factory l_streamfactory = l_ixml->create_stream_factory( ). * Connect internal XML table to stream factory l_ostream = l_streamfactory->create_ostream_itable( table = l_xml_table ). * Rendering the document l_renderer = l_ixml->create_renderer( ostream = l_ostream document = l_document ). l_rc = l_renderer->render( ). * Saving the XML document l_xml_size = l_ostream->get_num_written_raw( ). * OPEN DATASET fname FOR OUTPUT IN BINARY MODE. IF sy-subrc EQ 0. LOOP AT l_xml_table INTO rec. TRANSFER rec TO fname. ENDLOOP. CLOSE DATASET fname. ENDIF.
Author: Vivek Priyadarshi
Submitted: 06/17/2015
Related Links:
- <link>
Description I recently worked on a requirement where a functionality was required to get the modification date of a file on application server and make some decisions based on the same. In this blog, I will discussed a simple technique to get this information for any file stored on the application server. This code resembles the logic in function module EPS_GET_FILE_ATTRIBUTES with minor adjustments (mostly for the modification date property).
/* your snippet */ *----------------------------------------------------------------------* * CLASS lcl_file_property DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_file_property DEFINITION FINAL CREATE PUBLIC. PUBLIC SECTION. TYPES: BEGIN OF ty_file_property , dirname(75) TYPE c, " name of directory. (possibly truncated.) name(75) TYPE c, " name of entry. (possibly truncated.) type(10) TYPE c, " type of entry. len(8) TYPE p DECIMALS 0, " length in bytes. owner(8) TYPE c, " owner of the entry. mtime(10) TYPE p DECIMALS 0, " last modification date, seconds since 1970 mdate TYPE datum, mode(9) TYPE c, " like "rwx-r-x--x": protection mode. errno(3) TYPE c, errmsg(40) TYPE c, END OF ty_file_property. DATA: directory_name TYPE line, file_property TYPE ty_file_property, file_property_t TYPE STANDARD TABLE OF ty_file_property. DATA: lv_mgr_user TYPE as4user, lv_eps_subdir TYPE epsf-epssubdir. DATA: lt_dir_list TYPE STANDARD TABLE OF epsfili, dir_list LIKE LINE OF lt_dir_list, file_counter TYPE epsf-epsfilsiz, error_counter TYPE epsf-epsfilsiz, lv_unix_path TYPE char255. DATA: lt_sections TYPE stringtab, lv_section TYPE string, lv_filename TYPE epsf-epsfilnam, lv_rows TYPE i. METHODS: constructor IMPORTING directory_path TYPE char255, get_file_properties RETURNING value(properties) TYPE ty_file_property. PRIVATE SECTION. CONSTANTS: gc_secs_in_day TYPE i VALUE 86400. METHODS: calculate_modification_date IMPORTING property TYPE ty_file_property RETURNING value(mod_date) TYPE datum. ENDCLASS. "lcl_file_property DEFINITION *----------------------------------------------------------------------* * CLASS lcl_file_property IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_file_property IMPLEMENTATION. METHOD constructor. directory_name = directory_path. *--- Split path to get the file name SPLIT directory_name AT '/' INTO TABLE lt_sections. lv_rows = lines( lt_sections ). READ TABLE lt_sections INTO lv_section INDEX lv_rows. CHECK sy-subrc EQ 0. lv_filename = lv_section. *----- Remove filename from directory path REPLACE FIRST OCCURRENCE OF lv_section IN directory_name WITH space. CONDENSE directory_name. ENDMETHOD. "constructor METHOD get_file_properties. * get directory listing CALL 'C_DIR_READ_FINISH' " just to be sure ID 'ERRNO' FIELD file_property-errno ID 'ERRMSG' FIELD file_property-errmsg. CALL 'C_DIR_READ_START' ID 'DIR' FIELD directory_name ID 'FILE' FIELD lv_filename ID 'ERRNO' FIELD file_property-errno ID 'ERRMSG' FIELD file_property-errmsg. IF sy-subrc <> 0. *** RAISE EXCEPTION TYPE zcx_unix_file_base *** EXPORTING *** textid = zcx_unix_file_base=>read_directory_failed *** unix_path = lv_unix_path. MESSAGE 'Error during reading content of directory path' TYPE 'E'. ENDIF. REFRESH lt_dir_list. CLEAR file_counter. CLEAR error_counter. DO. CLEAR file_property. CLEAR dir_list. CALL 'C_DIR_READ_NEXT' ID 'TYPE' FIELD file_property-type ID 'NAME' FIELD file_property-name ID 'LEN' FIELD file_property-len ID 'OWNER' FIELD file_property-owner ID 'MTIME' FIELD file_property-mtime ID 'MODE' FIELD file_property-mode ID 'ERRNO' FIELD file_property-errno ID 'ERRMSG' FIELD file_property-errmsg. * handle files > 2147483647 byte (int 4) - hen 9.9.2004 IF file_property-len > 2147483647. dir_list-size = -99. ELSE. dir_list-size = file_property-len. ENDIF. dir_list-name = file_property-name. IF sy-subrc = 0. IF file_property-type(1) = 'f' OR " regular file file_property-type(1) = 'F'. ADD 1 TO file_counter. dir_list-rc = 0. APPEND dir_list TO lt_dir_list. file_property-mdate = me->calculate_modification_date( file_property ). APPEND file_property TO file_property_t. ENDIF. ELSEIF sy-subrc = 1. EXIT. ELSE. IF error_counter > 1000. CALL 'C_DIR_READ_FINISH' ID 'ERRNO' FIELD file_property-errno ID 'ERRMSG' FIELD file_property-errmsg. *** RAISE EXCEPTION TYPE zcx_unix_file_base *** EXPORTING *** textid = zcx_unix_file_base=>too_many_read_errors. MESSAGE 'Too many read errors' TYPE 'E'. ENDIF. ADD 1 TO error_counter. dir_list-rc = 18. APPEND dir_list TO lt_dir_list. file_property-mdate = me->calculate_modification_date( file_property ). APPEND file_property TO file_property_t. ENDIF. ENDDO. CALL 'C_DIR_READ_FINISH' ID 'ERRNO' FIELD file_property-errno ID 'ERRMSG' FIELD file_property-errmsg. IF file_counter > 0. SORT lt_dir_list BY name ASCENDING. READ TABLE file_property_t INTO file_property INDEX 1. CHECK sy-subrc EQ 0. properties = file_property. ELSE. *** RAISE EXCEPTION TYPE zcx_unix_file_base *** EXPORTING *** textid = zcx_unix_file_base=>empty_directory_list. MESSAGE 'Directory list is empty' TYPE 'E'. ENDIF. properties = file_property. ENDMETHOD. "get_file_properties METHOD calculate_modification_date. DATA: lv_days TYPE p LENGTH 10 DECIMALS 4, lv_seconds TYPE p LENGTH 10 DECIMALS 0, lv_date TYPE sy-datum VALUE '19691231'. CHECK NOT property-mtime IS INITIAL. *----- 1 Day = 86400 Seconds *----- Get number of days from seconds lv_seconds = property-mtime. lv_days = lv_seconds / me->gc_secs_in_day. lv_date = lv_date + lv_days. mod_date = lv_date. ENDMETHOD. "calculate_modification_date ENDCLASS. "lcl_file_property IMPLEMENTATION
Naresh
Dec 10 2007
Description: ABAP code for retrieving list of files contained within specific Application server directory(SAP).
*&---------------------------------------------------------------------*
*& Report ZDIRFILES *
*&---------------------------------------------------------------------*
REPORT ZDIRFILES .
PARAMETER: p_fdir type pfeflnamel DEFAULT '/usr/sap/tmp'.
data: begin of it_filedir occurs 10.
include structure salfldir.
data: end of it_filedir.
************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
* Get Current Directory Listing for OUT Dir
call function 'RZL_READ_DIR_LOCAL'
exporting
name = p_fdir
tables
file_tbl = it_filedir.
* List of files are contained within table it_filedir
loop at it_filedir.
write: / it_filedir-NAME.
endloop.
To get an F4 help of the application server directories:
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'PARAMETERS : p_dir TYPE char30 LOWER CASE. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dir. CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE' EXPORTING directory = p_dir IMPORTING serverfile = p_dir EXCEPTIONS canceled_by_user = 1 OTHERS = 2.
Subroutine/method to compress a binary file into an existing .zip file.
Payload
io_zip->add( name = iv_file_name content = iv_file_content ). io_zip->save( ).
Signature
FORM zip USING io_zip_file TYPE REF TO cl_abap_zip iv_file_name TYPE csequence iv_file_content TYPE xstring. ENDFORM. OR METHODS zip IMPORTING io_zip_file TYPE REF TO cl_abap_zip iv_file_name TYPE csequence iv_file_content TYPE xstring. METHOD zip. ENDMETHOD.
Below Code will read the Files in ZIP Folder Using Class cl_abap_zip.
Using CL_ABAP_ZIP we can add multiple file to ZIP Folder and we can Read added files in ZIP.
Get the File Content of type XSTRING from Upload UI Element and Pass it to Method LOAD of Class CL_ABAP_ZIP after creating instance of Class.
DATA lo_zipobj TYPE REF TO cl_abap_zip. CREATE OBJECT lo_zipobj. " Instances of class CALL METHOD lo_zipobj->load EXPORTING zip = lv_filecontent. " lv_filecontent is ZIP File Content of type XSTRING *Attribute FILES will have number of files in the ZIP. *Using Get file Method of class CL_ABAP_ZIP get the file content from ZIP and pass it to method READ as below. LOOP AT lo_zipobj->files INTO ls_files. CALL METHOD lo_zipobj->get EXPORTING name = ls_files-name IMPORTING content = lv_xstring. CALL METHOD cl_abap_conv_in_ce=>create EXPORTING input = lv_xstring encoding = 'UTF-8' replacement = '?' ignore_cerr = abap_true RECEIVING conv = l_addr. CALL METHOD l_addr->read IMPORTING data = l_string. ENDLOOP.
Each loop pass l_string will have ZIP Folder File Content
The below program is a sample code on how to transfer files from a FTP Directory into SAP Application server directory. This program will :
(1) Read the files in a particular directory - FTP
(2) Copy the files in to the SAP directory - SAP Application Server
(3) Delete the original file from FTP server.
Additionally a Log table has been created which will track the status of the file.
Table structure - ZTBL_IPL_FTP as below :
FILE_NM |
ZDA_FILNAM |
CHAR |
110 |
0 |
File Name for LPI Files |
LOG_ID |
ZDA_LOG_LPI |
NUMC |
4 |
0 |
Log Id for LPI File |
FDATE |
SYDATUM |
DATS |
8 |
0 |
Current Date of Application Server |
FTIME |
SYUZEIT |
TIMS |
6 |
0 |
Current Time of Application Server |
STAT |
ZSTAT_LPI |
CHAR |
2 |
0 |
Status of file |
MESS |
BAPI_MSG |
CHAR |
220 |
0 |
Message Text |
Code as below :
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'REPORT zftptrasfr NO STANDARD PAGE HEADING LINE-SIZE 255. ************************************************************************ *T Y P E S ************************************************************************ TYPES: BEGIN OF x_cmdout, line(100) TYPE c, END OF x_cmdout. TYPE-POOLS : slis. ************************************************************************ * D A T A ************************************************************************ *data specifications of FTP server *Handler and Key DATA: w_cmd(40) TYPE c, w_hdl TYPE i, w_logid TYPE zda_log_ipl VALUE 1, w_key TYPE i VALUE 26101957, w_slen TYPE i, wa_iplftp TYPE ztbl_ipl_ftp, it_iplftp TYPE STANDARD TABLE OF ztbl_ipl_ftp, wa_cmdout TYPE x_cmdout, it_cmdout TYPE STANDARD TABLE OF x_cmdout. *Constant declarations CONSTANTS: c_dest TYPE rfcdes-rfcdest VALUE 'SAPFTPA', c_host(11) TYPE c VALUE '172.XX.X.XX', c_ftp(6) TYPE c VALUE 'FTPDIRECTORY', c_sap(16) TYPE c VALUE '/sap/inbound/SAPDIRECTORY'. ************************************************************************ * P A R A M E T E R S ************************************************************************ SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. PARAMETERS: p_user(30) TYPE c LOWER CASE , p_pwd(30) TYPE c LOWER CASE , p_host(64) TYPE c LOWER CASE DEFAULT c_host , p_edi TYPE zedi, " 5-character domain containing EDI profiles p_ftp TYPE e_dexcommfilepath LOWER CASE DEFAULT c_ftp, p_sap TYPE esefilepath LOWER CASE DEFAULT c_sap. SELECTION-SCREEN END OF BLOCK b1. ************************************************************************ *AT SELECTION SCREEN Events ************************************************************************ AT SELECTION-SCREEN OUTPUT. LOOP AT SCREEN. CASE screen-name. WHEN 'P_PWD'."Set the password field as invisible screen-invisible = '1'. MODIFY SCREEN. ENDCASE. ENDLOOP. ************************************************************************ * S T A R T - O F - S E L E C T I O N ************************************************************************ START-OF-SELECTION. *Connect to the FTP server. PERFORM ftp_connect. *Find all files in the directory and store inside the Log table PERFORM log_files. *Check for transfer of files to FTP. IF it_iplftp[] IS INITIAL. MESSAGE text-003 TYPE 'I'. LEAVE LIST-PROCESSING. ENDIF. *Change the local save directory and download to SAP application server. PERFORM move_files. *Close the connection PERFORM close_ftp. ************************************************************************ *END-OF-SELECTION ************************************************************************ END-OF-SELECTION. *Display report. PERFORM disp_res. *&--------------------------------------------------------------------- *& Form FTP_CONNECT *&--------------------------------------------------------------------- *Make a connection to the FTP server *---------------------------------------------------------------------- FORM ftp_connect . SET EXTENDED CHECK OFF. w_slen = strlen( p_pwd ). CALL FUNCTION 'HTTP_SCRAMBLE' EXPORTING source = p_pwd sourcelen = w_slen key = w_key IMPORTING destination = p_pwd. CALL FUNCTION 'FTP_CONNECT' EXPORTING user = p_user password = p_pwd host = p_host rfc_destination = c_dest IMPORTING handle = w_hdl EXCEPTIONS not_connected = 1 OTHERS = 2. IF sy-subrc <> 0. *Message will arise in case of any issues in connecting to the FTP server. MESSAGE text-e01 TYPE 'I'. LEAVE LIST-PROCESSING. ENDIF. ENDFORM. " FTP_CONNECT *&--------------------------------------------------------------------- *& Form LOG_FILES *&--------------------------------------------------------------------- *find all the files in the home directory *---------------------------------------------------------------------- FORM log_files . *Change directory to the FTP directory for LUPIN CONCATENATE 'cd' p_ftp INTO w_cmd SEPARATED BY space. CALL FUNCTION 'FTP_COMMAND' EXPORTING handle = w_hdl command = w_cmd compress = 'N' TABLES data = it_cmdout EXCEPTIONS tcpip_error = 1 command_error = 2 data_error = 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. REFRESH it_cmdout. CLEAR w_cmd. w_cmd = 'ls'. CALL FUNCTION 'FTP_COMMAND' EXPORTING handle = w_hdl command = w_cmd compress = 'N' TABLES data = it_cmdout EXCEPTIONS tcpip_error = 1 command_error = 2 data_error = 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. *All customized checks for file to be placed here. LOOP AT it_cmdout INTO wa_cmdout FROM 4. *Check the command line for a file CHECK wa_cmdout-line+68(4) EQ '.txt'. *Move all the files to the FTP table wa_iplftp-file_nm = wa_cmdout-line+39(33). wa_iplftp-log_id = w_logid. *Currently the transfer date/time will be taken wa_iplftp-fdate = sy-datum."WA_CMDOUT-LINE+39(8). wa_iplftp-ftime = sy-uzeit."WA_CMDOUT-LINE+48(6). wa_iplftp-ernam = sy-uname. APPEND wa_iplftp TO it_iplftp. ENDLOOP. REFRESH it_cmdout. ENDFORM. " LOG_FILES *&--------------------------------------------------------------------- *& Form MOVE_FILES *&--------------------------------------------------------------------- FORM move_files . DATA : l_indx TYPE i. CLEAR w_cmd. CONCATENATE 'lcd' p_sap INTO w_cmd SEPARATED BY space. *Change the local directory to the sap inbound directory CALL FUNCTION 'FTP_COMMAND' EXPORTING handle = w_hdl command = w_cmd compress = 'N' TABLES data = it_cmdout EXCEPTIONS command_error = 1 tcpip_error = 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. REFRESH it_cmdout. *Move each file from FTP to SAP inbound directory LOOP AT it_iplftp INTO wa_iplftp WHERE stat EQ space OR stat EQ 'CR'. l_indx = sy-tabix. CLEAR w_cmd. REFRESH it_cmdout. CONCATENATE 'get' wa_iplftp-file_nm INTO w_cmd SEPARATED BY space. CALL FUNCTION 'FTP_COMMAND' EXPORTING handle = w_hdl command = w_cmd compress = 'N' TABLES data = it_cmdout EXCEPTIONS command_error = 1 tcpip_error = 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. READ TABLE it_cmdout INTO wa_cmdout INDEX 2. IF sy-subrc EQ 0. IF wa_cmdout-line CS 'command successful'. wa_iplftp-stat = 'CR'. wa_iplftp-mess = text-004. ELSE. wa_iplftp-stat = 'EF'. wa_iplftp-mess = text-005. ENDIF. ENDIF. MODIFY it_iplftp FROM wa_iplftp INDEX l_indx. *delete from FTP CLEAR w_cmd. CONCATENATE 'delete' wa_iplftp-file_nm INTO w_cmd SEPARATED BY space. CALL FUNCTION 'FTP_COMMAND' EXPORTING handle = w_hdl command = w_cmd compress = 'N' TABLES data = it_cmdout EXCEPTIONS command_error = 1 tcpip_error = 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. ENDLOOP. *Insert all table entries. INSERT ztbl_ipl_ftp FROM TABLE it_iplftp. IF sy-subrc NE 0. MESSAGE text-006 TYPE 'I'. ENDIF. ENDFORM. " MOVE_FILES *&--------------------------------------------------------------------- *& Form CLOSE_FTP *&--------------------------------------------------------------------- FORM close_ftp . CALL FUNCTION 'FTP_DISCONNECT' EXPORTING handle = w_hdl. CALL FUNCTION 'RFC_CONNECTION_CLOSE' EXPORTING destination = c_dest EXCEPTIONS OTHERS = 1. 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. " CLOSE_FTP *&--------------------------------------------------------------------- *& Form DISP_RES *&--------------------------------------------------------------------- *Display the output *---------------------------------------------------------------------- FORM disp_res . DATA : l_layout TYPE slis_layout_alv. l_layout-colwidth_optimize = 'X'. *Display table contents of updated files CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = sy-repid i_structure_name = 'ZTBL_IPL_FTP' is_layout = l_layout TABLES t_outtab = it_iplftp EXCEPTIONS program_error = 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. ENDFORM. " DISP_RES
List of all pages
Pages at first level
Move a file from source to target directories or Delete file. I
Z_ARCH_MV command needs to be created in SM49 transaction for your operating system, to move file (mv command in Unix-like systems).
Selection texts to be created:
P_COPY | Copy |
P_DELE | Delete Source File |
P_MOVE | Move |
P_SFILE | Source File |
P_S_AS | Source Application Server |
P_S_PC | Source Presentation Server |
P_TFILE | Target File |
P_T_AS | Target Application Server |
P_T_PC | Target Presentation Server |
P_XFER | Transfer |
Messages used:
Message class | Number | Text |
---|---|---|
FI | 899 | &1 &2 &3 &4 |
REPORT Z_ARCH_MOVE NO STANDARD PAGE HEADING LINE-SIZE 132. ************************************************************************" * Move a file from source to target directories or Delete file * * This program will not run in a productive client. * * Source and target may be either on the Presentation or Application * servers. * * You can only copy if either source or target is on the Presentation * server. * You can either copy or move if both source and target are on the * Application server. * * When copying, provide the complete file specification for both * source and target. * * I had trouble getting the OS commands to accept an application server * filespec containing spaces. So there's a warning if you use one. Be * aware that the operation may not succeed regardless of the program * messages. * Tables ************************************************************************ ************************************************************************" * Types ************************************************************************" TYPE-POOLS: ABAP. TYPES : BEGIN OF TY_DATA, REC TYPE STRING, END OF TY_DATA. TYPES: TYT_DATA TYPE STANDARD TABLE OF TY_DATA. ************************************************************************ * Classes ************************************************************************" CLASS CL_GUI_FRONTEND_SERVICES DEFINITION LOAD. ************************************************************************ * Data ************************************************************************" DATA: W_ANSWER TYPE CHAR1, W_RC TYPE I. DATA: BEGIN OF W_FLAG, STOP TYPE FLAG, END OF W_FLAG. DATA: T_DATA TYPE TYT_DATA. ************************************************************************ * Selection screen ************************************************************************" * Customising - change the first block to reflect your requirements. * Set the "modif id" to "OUT" to make a field output-only * or to "HID" to hide it completely.* Data selections ***************** SELECTION-SCREEN: BEGIN OF BLOCK ZSELECTIONS WITH FRAME. * Action SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001. * Move or Copy PARAMETERS: P_XFER RADIOBUTTON GROUP ZG1 DEFAULT 'X'. * Delete PARAMETERS: P_DELE RADIOBUTTON GROUP ZG1. SELECTION-SCREEN: END OF BLOCK B1. * Source SELECTION-SCREEN: BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002. * Presentation server PARAMETERS: P_S_PC RADIOBUTTON GROUP ZG2 DEFAULT 'X'. * Application server PARAMETERS: P_S_AS RADIOBUTTON GROUP ZG2. * File name PARAMETERS: P_SFILE TYPE LOCALFILE. SELECTION-SCREEN: END OF BLOCK B2. * Target (Move or Copy only) SELECTION-SCREEN: BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-003. * Presentation server PARAMETERS: P_T_PC RADIOBUTTON GROUP ZG3. * Application server PARAMETERS: P_T_AS RADIOBUTTON GROUP ZG3 DEFAULT 'X'. * File name PARAMETERS: P_TFILE TYPE LOCALFILE. * Between Application servers SELECTION-SCREEN: BEGIN OF BLOCK B4 WITH FRAME TITLE TEXT-004. * Move PARAMETERS: P_MOVE RADIOBUTTON GROUP ZG4 DEFAULT 'X'. * Copy PARAMETERS: P_COPY RADIOBUTTON GROUP ZG4. SELECTION-SCREEN: END OF BLOCK B4. SELECTION-SCREEN: END OF BLOCK B3. SELECTION-SCREEN: END OF BLOCK ZSELECTIONS. ************************************************************************ * Events ************************************************************************" INITIALIZATION. PERFORM NOT_IN_PRODUCTION. AT SELECTION-SCREEN ON BLOCK ZSELECTIONS. PERFORM CHECK_SELECTIONS. AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_SFILE. PERFORM CHOOSE_FILENAME USING 'P_SFILE' 'P_S_PC'. AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_TFILE. PERFORM CHOOSE_FILENAME USING 'P_TFILE' 'P_T_PC'. START-OF-SELECTION. PERFORM DETERMINE_ACTIONS. END-OF-SELECTION. PERFORM STOP_IF_REQUESTED. ************************************************************************ * Forms ************************************************************************" ************************************************************************ FORM CHECK_SELECTIONS. ************************************************************************" DATA: L_TEMPFILE TYPE LOCALFILE. * Need a source file IF P_SFILE IS INITIAL. MESSAGE E899(FI) WITH 'Source must be specified'. ENDIF. * Need a target file for Move or Copy IF P_XFER EQ ABAP_TRUE AND P_TFILE IS INITIAL. MESSAGE E899(FI) WITH 'Target must be specified'. ENDIF. * Check for spaces in source or target IF P_S_AS EQ ABAP_TRUE. L_TEMPFILE = P_SFILE. CONDENSE L_TEMPFILE NO-GAPS. IF L_TEMPFILE NE P_SFILE. MESSAGE W899(FI) WITH 'Spaces in source file name'. ENDIF. ENDIF. IF P_T_AS EQ ABAP_TRUE. L_TEMPFILE = P_TFILE. CONDENSE L_TEMPFILE NO-GAPS. IF L_TEMPFILE NE P_TFILE. MESSAGE W899(FI) WITH 'Spaces in target file name'. ENDIF. ENDIF. ENDFORM. "check_selections ************************************************************************ FORM CHOOSE_FILENAME USING PX_FIELD_FILENAME LIKE DYNPREAD-FIELDNAME PX_FIELD_PCFLAG LIKE DYNPREAD-FIELDNAME. ************************************************************************" DATA: L_LOCATION LIKE DXFIELDS-LOCATION. DATA: LT_DYNP TYPE STANDARD TABLE OF DYNPREAD, L_DYNP TYPE DYNPREAD. L_DYNP-FIELDNAME = PX_FIELD_PCFLAG. APPEND L_DYNP TO LT_DYNP. CALL FUNCTION 'DYNP_VALUES_READ' EXPORTING DYNAME = SY-CPROG DYNUMB = SY-DYNNR TABLES DYNPFIELDS = LT_DYNP EXCEPTIONS OTHERS = 11. IF SY-SUBRC <> 0. MESSAGE E899(FI) WITH 'Error (1) reading selection screen'. ENDIF. READ TABLE LT_DYNP INDEX 1 INTO L_DYNP. IF SY-SUBRC EQ 0. IF L_DYNP-FIELDVALUE EQ ABAP_TRUE. L_LOCATION = 'P'. ELSE. L_LOCATION = 'A'. ENDIF. ELSE. MESSAGE E899(FI) WITH 'Error (2) reading selection screen'. ENDIF. CALL FUNCTION 'F4_DXFILENAME_4_DYNP' EXPORTING DYNPFIELD_FILENAME = PX_FIELD_FILENAME DYNAME = SY-CPROG DYNUMB = SY-DYNNR FILETYPE = 'P' LOCATION = L_LOCATION SERVER = ' '. ENDFORM. "choose_filename ************************************************************************ FORM CONFIRM_DELETE_FILE. ************************************************************************" CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING TEXT_QUESTION = 'Do you really want to delete this file?' DISPLAY_CANCEL_BUTTON = ABAP_FALSE IMPORTING ANSWER = W_ANSWER EXCEPTIONS TEXT_NOT_FOUND = 1 OTHERS = 2. IF SY-SUBRC NE 0 OR W_ANSWER NE 1. W_FLAG-STOP = ABAP_TRUE. MESSAGE S899(FI) WITH 'Deletion not attempted'. STOP. ENDIF. ENDFORM. "confirm_delete_file ************************************************************************ FORM COPY_FILE_ON_PRES_SRVR USING PX_SOURCE TYPE LOCALFILE PX_TARGET TYPE LOCALFILE. ************************************************************************" DATA: L_SFILE TYPE STRING, L_TFILE TYPE STRING. L_SFILE = PX_SOURCE. L_TFILE = PX_TARGET. CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_COPY EXPORTING SOURCE = L_SFILE DESTINATION = L_TFILE OVERWRITE = ABAP_TRUE EXCEPTIONS OTHERS = 13. IF SY-SUBRC EQ 0. FORMAT COLOR COL_POSITIVE. WRITE: / 'Successfully copied file', PX_SOURCE, / 'to', PX_TARGET UNDER PX_SOURCE. ELSE. W_FLAG-STOP = ABAP_TRUE. MESSAGE S899(FI) WITH 'Failed to copy file' PX_SOURCE DISPLAY LIKE 'E'. STOP. ENDIF. ENDFORM. "copy_file_on_pres_srvr ************************************************************************ FORM DELETE_FILE. ************************************************************************" DATA: L_FILE TYPE STRING. IF P_S_PC EQ ABAP_TRUE. * Delete Presentation server file L_FILE = P_SFILE. CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_DELETE EXPORTING FILENAME = L_FILE CHANGING RC = W_RC EXCEPTIONS FILE_DELETE_FAILED = 1 CNTL_ERROR = 2 ERROR_NO_GUI = 3 FILE_NOT_FOUND = 4 ACCESS_DENIED = 5 UNKNOWN_ERROR = 6 NOT_SUPPORTED_BY_GUI = 7 WRONG_PARAMETER = 8 OTHERS = 9. ELSE. * Delete Application server file CATCH SYSTEM-EXCEPTIONS FILE_ACCESS_ERRORS = 4. DELETE DATASET P_SFILE. ENDCATCH. ENDIF. IF SY-SUBRC EQ 0. FORMAT COLOR COL_POSITIVE. WRITE: / 'Successfully deleted file', P_SFILE. ELSE. W_FLAG-STOP = ABAP_TRUE. MESSAGE S899(FI) WITH 'Failed to delete file' P_SFILE DISPLAY LIKE 'E'. STOP. ENDIF. ENDFORM. "delete_file ************************************************************************ FORM DETERMINE_ACTIONS. ************************************************************************" IF P_XFER EQ ABAP_TRUE. PERFORM MOVE_OR_COPY. ELSE. PERFORM CONFIRM_DELETE_FILE. PERFORM DELETE_FILE. ENDIF. ENDFORM. "determine_actions ************************************************************************ FORM MOVE_FILE_ON_APP_SRVR USING PX_SOURCE TYPE LOCALFILE PX_TARGET TYPE LOCALFILE. ************************************************************************" DATA: L_EXITCODE TYPE BTCXPGEXIT, L_PARMS TYPE BTCXPGPAR, L_STATUS TYPE BTCXPGSTAT. DATA: LT_PROTOCOL TYPE STANDARD TABLE OF BTCXPM, L_PROTOCOL TYPE BTCXPM. CONCATENATE PX_SOURCE PX_TARGET INTO L_PARMS SEPARATED BY SPACE. * External command: * - Unix - mv * - Windows - cmd /c move CALL FUNCTION 'SXPG_COMMAND_EXECUTE' EXPORTING COMMANDNAME = 'Z_ARCH_MV' ADDITIONAL_PARAMETERS = L_PARMS IMPORTING STATUS = L_STATUS EXITCODE = L_EXITCODE TABLES EXEC_PROTOCOL = LT_PROTOCOL EXCEPTIONS NO_PERMISSION = 1 COMMAND_NOT_FOUND = 2 PARAMETERS_TOO_LONG = 3 SECURITY_RISK = 4 WRONG_CHECK_CALL_INTERFACE = 5 PROGRAM_START_ERROR = 6 PROGRAM_TERMINATION_ERROR = 7 X_ERROR = 8 PARAMETER_EXPECTED = 9 TOO_MANY_PARAMETERS = 10 ILLEGAL_COMMAND = 11 WRONG_ASYNCHRONOUS_PARAMETERS = 12 CANT_ENQ_TBTCO_ENTRY = 13 JOBCOUNT_GENERATION_ERROR = 14 OTHERS = 15. IF SY-SUBRC NE 0 OR L_STATUS NE 'O' OR L_EXITCODE NE '0'. * Failure FORMAT COLOR COL_NEGATIVE. WRITE: / 'Failed to move' , PX_SOURCE, / 'to', PX_TARGET UNDER PX_SOURCE. FORMAT COLOR COL_NORMAL. LOOP AT LT_PROTOCOL INTO L_PROTOCOL. WRITE: / L_PROTOCOL-MESSAGE+0(L_PROTOCOL-LENGTH). ENDLOOP. ELSE. * Success FORMAT COLOR COL_POSITIVE. WRITE: / 'Successfully moved' , PX_SOURCE, / 'to', PX_TARGET UNDER PX_SOURCE. ENDIF. ENDFORM. "move_file_on_app_srvr ************************************************************************ FORM MOVE_OR_COPY. ************************************************************************" IF P_S_AS EQ ABAP_TRUE AND P_T_AS EQ ABAP_TRUE. * Source and Target both on AppSrvr IF P_MOVE EQ ABAP_TRUE. PERFORM MOVE_FILE_ON_APP_SRVR USING P_SFILE P_TFILE. ELSE. PERFORM READ_APPSRVR_FILE USING P_SFILE CHANGING T_DATA. PERFORM WRITE_APPSRVR_FILE USING P_TFILE T_DATA. ENDIF. ELSEIF P_S_PC EQ ABAP_TRUE AND P_T_PC EQ ABAP_TRUE. * Source and Target both on PresSrvr PERFORM COPY_FILE_ON_PRES_SRVR USING P_SFILE P_TFILE. ELSEIF P_S_PC EQ ABAP_TRUE. * Source on PresSrvr; Target on AppSrvr PERFORM READ_LOCAL_FILE USING P_SFILE CHANGING T_DATA. PERFORM WRITE_APPSRVR_FILE USING P_TFILE T_DATA. ELSE. * Source on AppSrvr; Target on PresSrvr PERFORM READ_APPSRVR_FILE USING P_SFILE CHANGING T_DATA. PERFORM WRITE_LOCAL_FILE USING P_TFILE T_DATA. ENDIF. ENDFORM. "move_or_copy ************************************************************************ FORM NOT_IN_PRODUCTION. ************************************************************************" DATA: L_CCCATEGORY TYPE CCCATEGORY. SELECT SINGLE CCCATEGORY INTO L_CCCATEGORY FROM T000 WHERE MANDT EQ SY-MANDT. IF L_CCCATEGORY EQ 'P'. MESSAGE E899(FI) WITH 'Program' SY-REPID 'is not available in Production clients'. ENDIF. ENDFORM. "not_in_production ************************************************************************ FORM READ_APPSRVR_FILE USING PX_SOURCE TYPE LOCALFILE CHANGING PXT_DATA TYPE TYT_DATA. ************************************************************************" DATA: L_DATA TYPE TY_DATA. CATCH SYSTEM-EXCEPTIONS FILE_ACCESS_ERRORS = 4. OPEN DATASET PX_SOURCE FOR INPUT IN TEXT MODE ENCODING DEFAULT. DO. READ DATASET PX_SOURCE INTO L_DATA-REC. IF SY-SUBRC NE 0. EXIT. ENDIF. APPEND L_DATA TO PXT_DATA. ENDDO. CLOSE DATASET PX_SOURCE. ENDCATCH. IF SY-SUBRC EQ 0. FORMAT COLOR COL_POSITIVE. WRITE: / 'Successfully read', PX_SOURCE. FORMAT COLOR COL_NORMAL. ELSE. W_FLAG-STOP = ABAP_TRUE. MESSAGE S899(FI) WITH 'Unable to read AppSrvr file' PX_SOURCE DISPLAY LIKE 'E'. STOP. ENDIF. ENDFORM. "read_appsrvr_file ************************************************************************ FORM READ_LOCAL_FILE USING PX_SOURCE TYPE LOCALFILE CHANGING PXT_DATA TYPE TYT_DATA. ************************************************************************ DATA: L_FILE TYPE STRING. L_FILE = PX_SOURCE. CALL FUNCTION 'GUI_UPLOAD' EXPORTING FILENAME = L_FILE TABLES DATA_TAB = PXT_DATA EXCEPTIONS OTHERS = 17. IF SY-SUBRC EQ 0. FORMAT COLOR COL_POSITIVE. WRITE: / 'Successfully read', PX_SOURCE. FORMAT COLOR COL_NORMAL. ELSE. W_FLAG-STOP = ABAP_TRUE. MESSAGE S899(FI) WITH 'Unable to read local file' PX_SOURCE DISPLAY LIKE 'E'. STOP. ENDIF. ENDFORM. "read_local_file ************************************************************************ FORM STOP_IF_REQUESTED. ************************************************************************ IF W_FLAG-STOP EQ ABAP_TRUE. STOP. ENDIF. ENDFORM. "stop_if_requested ************************************************************************ FORM WRITE_APPSRVR_FILE USING PX_TARGET TYPE LOCALFILE PXT_DATA TYPE TYT_DATA. ************************************************************************ DATA: L_DATA TYPE TY_DATA. CATCH SYSTEM-EXCEPTIONS FILE_ACCESS_ERRORS = 4. OPEN DATASET PX_TARGET FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. LOOP AT PXT_DATA INTO L_DATA. TRANSFER L_DATA-REC TO PX_TARGET. ENDLOOP. CLOSE DATASET PX_TARGET. ENDCATCH. IF SY-SUBRC EQ 0. FORMAT COLOR COL_POSITIVE. WRITE: / 'Successfully written', PX_TARGET. FORMAT COLOR COL_NORMAL. ELSE. W_FLAG-STOP = ABAP_TRUE. MESSAGE S899(FI) WITH 'Unable to write AppSrvr file' PX_TARGET DISPLAY LIKE 'E'. STOP. ENDIF. ENDFORM. "write_appsrvr_file ************************************************************************ FORM WRITE_LOCAL_FILE USING PX_TARGET TYPE LOCALFILE PXT_DATA TYPE TYT_DATA. ************************************************************************" DATA: L_FILE TYPE STRING. L_FILE = PX_TARGET. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING FILENAME = L_FILE TABLES DATA_TAB = PXT_DATA EXCEPTIONS OTHERS = 17. IF SY-SUBRC EQ 0. FORMAT COLOR COL_POSITIVE. WRITE: / 'Successfully written', PX_TARGET. FORMAT COLOR COL_NORMAL. ELSE. W_FLAG-STOP = ABAP_TRUE. MESSAGE S899(FI) WITH 'Unable to write local file' PX_TARGET DISPLAY LIKE 'E'. STOP. ENDIF. ENDFORM. "write_local_file
This piece of code will help in uploading and downloading .txt or .csv files from application server to presentation server and vice versa.
*Text symbols: *001 File Handling *002 Path *003 YES *004 NO *Selection Texts: *P_CG3Y Download *P_CG3Z Upload *P_FILE Presentation Server Path *P_FILE1 Presentation Server Path *P_O_WRIT Overwrite the file ? *P_PATH Application Server Path *P_PATH1 Application Server Path *&---------------------------------------------------------------------* *& Report Z_CG3_Z_Y *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT z_cg3_z_y NO STANDARD PAGE HEADING. CONSTANTS : c_m1(2) TYPE c VALUE 'M1', c_m2(2) TYPE c VALUE 'M2', c_m3(2) TYPE c VALUE 'M3', c_m4(2) TYPE c VALUE 'M4', c_x(1) TYPE c VALUE 'X'. DATA : w_path TYPE sapb-sappfad, w_file TYPE sapb-sappfad. DATA w_ans(1) TYPE c. DATA : BEGIN OF t_data OCCURS 0, data(3000) TYPE c, END OF t_data. SELECTION-SCREEN : BEGIN OF BLOCK ss01 WITH FRAME TITLE text-001. PARAMETERS : p_cg3z RADIOBUTTON GROUP g1 USER-COMMAND flag DEFAULT 'X' , p_cg3y RADIOBUTTON GROUP g1 . SELECTION-SCREEN : BEGIN OF BLOCK ss02 WITH FRAME TITLE text-002. PARAMETERS : p_file TYPE rlgrap-filename DEFAULT 'D:\test.csv' MODIF ID m1. PARAMETERS : p_path TYPE rlgrap-filename DEFAULT '/tmp/test' MODIF ID m1. PARAMETERS : p_path1(60) TYPE c DEFAULT '/tmp/test' MODIF ID m2. PARAMETERS : p_file1 TYPE rlgrap-filename DEFAULT 'D:\test.txt' MODIF ID m2. SELECTION-SCREEN : END OF BLOCK ss02. SKIP 2. SELECTION-SCREEN : BEGIN OF LINE. SELECTION-SCREEN : POSITION 60. PARAMETERS : p_o_writ AS CHECKBOX MODIF ID m1. SELECTION-SCREEN: COMMENT 62(15) text1 MODIF ID m1. SELECTION-SCREEN : END OF LINE. SELECTION-SCREEN : END OF BLOCK ss01. AT SELECTION-SCREEN OUTPUT. LOOP AT SCREEN. IF p_cg3z EQ c_x AND screen-group1 EQ c_m2. screen-active = 0. ENDIF. IF p_cg3y EQ c_x AND screen-group1 EQ c_m1. screen-active = 0. ENDIF. MODIFY SCREEN. ENDLOOP. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. DATA: t_file_tab TYPE filetable, w1 LIKE LINE OF t_file_tab, w_rc TYPE i. CALL METHOD cl_gui_frontend_services=>file_open_dialog EXPORTING default_extension = 'CSV' CHANGING file_table = t_file_tab rc = w_rc EXCEPTIONS file_open_dialog_failed = 1 cntl_error = 2 error_no_gui = 3 not_supported_by_gui = 4 OTHERS = 5. IF sy-subrc = 0. * MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno * WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. READ TABLE t_file_tab INTO w1 INDEX 1. IF sy-subrc = 0. p_file = w1-filename. ENDIF. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1. DATA: t_file_tab TYPE filetable, w1 LIKE LINE OF t_file_tab, w_rc TYPE i. CALL METHOD cl_gui_frontend_services=>file_open_dialog EXPORTING default_extension = 'CSV' CHANGING file_table = t_file_tab rc = w_rc EXCEPTIONS file_open_dialog_failed = 1 cntl_error = 2 error_no_gui = 3 not_supported_by_gui = 4 OTHERS = 5. IF sy-subrc = 0. * MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno * WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. READ TABLE t_file_tab INTO w1 INDEX 1. IF sy-subrc = 0. p_file1 = w1-filename. ENDIF. INITIALIZATION . text1 = 'Overwrite File'. START-OF-SELECTION. IF p_cg3z EQ c_x. TRANSLATE : p_path TO LOWER CASE, p_path1 TO LOWER CASE, p_file TO LOWER CASE, p_file1 TO LOWER CASE. IF p_o_writ EQ ' '. OPEN DATASET p_path FOR INPUT IN BINARY MODE. IF sy-subrc EQ 0. CLEAR : w_ans. CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING titlebar = 'CONFIRMATION POP-UP ' text_question = 'Are You Sure You WAnt to Over Write The File' text_button_1 = 'YES' text_button_2 = 'NO' display_cancel_button = c_x start_column = 25 start_row = 6 IMPORTING answer = w_ans. 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 w_ans = '1'. CLOSE DATASET p_path. PERFORM f_upload_download . ELSEIF w_ans = '2'. CLOSE DATASET p_path. EXIT. ELSEIF w_ans = 'A'. CLOSE DATASET p_path. EXIT. ENDIF. ELSE. CLOSE DATASET p_path. PERFORM f_upload_download . w_ans = '1'. ENDIF. CLOSE DATASET p_path. ELSE. PERFORM f_upload_download . ENDIF. ELSE. " for dwonload p_cg3y PERFORM f_upload_download . ENDIF. IF p_cg3z EQ c_x. DATA : w_filename TYPE string. MOVE p_file TO w_filename. CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = w_filename TABLES data_tab = t_data. 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. TRANSLATE p_path1 TO LOWER CASE. OPEN DATASET p_path1 FOR INPUT IN TEXT MODE ENCODING DEFAULT. DO. IF sy-subrc <> 0. EXIT. ENDIF. READ DATASET p_path1 INTO t_data . APPEND t_data. CLEAR t_data. ENDDO. CLOSE DATASET p_path1. ENDIF. END-OF-SELECTION. IF w_ans EQ '1' OR p_o_writ EQ 'X'. WRITE : / 'File contents:'. SKIP 1. LOOP AT t_data. WRITE : t_data-data. ENDLOOP. ENDIF. *&---------------------------------------------------------------------* *& Form F_UPLOAD_DOWNLOAD *&---------------------------------------------------------------------* FORM f_upload_download . IF p_cg3z EQ c_x. TRANSLATE p_path TO LOWER CASE. MOVE p_path TO w_path . MOVE p_file TO w_file. CALL FUNCTION 'ARCHIVFILE_CLIENT_TO_SERVER' EXPORTING path = w_file targetpath = w_path EXCEPTIONS error_file = 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. ELSE . MESSAGE 'successfully transfered' TYPE 'S'. ENDIF. ELSE. TRANSLATE : p_path1 TO LOWER CASE, p_file1 TO LOWER CASE. MOVE p_path1 TO w_path . MOVE p_file1 TO w_file. CALL FUNCTION 'ARCHIVFILE_SERVER_TO_CLIENT' EXPORTING path = w_path targetpath = w_file EXCEPTIONS error_file = 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. ELSE. MESSAGE 'successfully transfered' TYPE 'S' . ENDIF. ENDIF. ENDFORM. " F_UPLOAD_DOWNLOAD
Use the Function :
C13Z_APPL_TO_FRONT_END to download the data from the Application server to Presentation.
This has to be restricted due to the functionality for the user can download any file to PC. So the file name has to be checked to restrict the user downloading any file to his PC.
Kind Regards,
Senthilraj Selvaraj
Author: Raghavendra AY
Submitted: February 15, 2007
Since it's not possible to download data to presentation server in background, we first download the data to application server file, then read this application server file and save it to presentation server in foreground, which ideally means each such download program requires another program which takes the file structure into consideration and download it to presentation server.
This code can be used to download data from files on application server to presentation server in foreground
To download data from Application server files to presentation server
Upload / Download / Delete functionality of Application server Program.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'REPORT zapplserver MESSAGE-ID fb. ************************************************************************ * Constants CONSTANTS:c_mask(80) TYPE c VALUE ',.,..', " Mask c_file_type(10) TYPE c VALUE 'ASC', " File type c_mode(1) TYPE c VALUE 'L'. " Mode * Internal tables * DATA: BEGIN OF i_file OCCURS 0, field(3000) TYPE c, END OF i_file. DATA : v_msg(100), struct_file LIKE i_file OCCURS 0. * Parameters PARAMETERS: p_fpath TYPE draw-filep OBLIGATORY, p_lpath TYPE localfile, p_upload AS CHECKBOX DEFAULT 'X', p_dload AS CHECKBOX, p_delete AS CHECKBOX. ************************************************************************ * Check selection-screen entries * ************************************************************************ * At selection screen AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_lpath. PERFORM get_file CHANGING p_lpath. ************************************************************************ * Main * ************************************************************************ * Start of selection START-OF-SELECTION. IF p_upload = 'X'. * Upload to app server PERFORM upload_to_appserver. ENDIF. IF p_dload = 'X'. * Download to desktop PERFORM download_to_desktop. ENDIF. IF p_delete = 'X'. * Delete file on app server DELETE DATASET p_fpath. IF sy-subrc = 0. MESSAGE s000 WITH 'File deleted'. ENDIF. ENDIF. ************************************************************************ * OUTPUT of extracted data * ************************************************************************ * sort. * loop. * * endloop. ************************************************************************ * EVENTS DURING LISTPROCESSING * ************************************************************************ ************************************************************************ * EVENTS AT USER COMMAND ************************************************************************ *at line selection. *at user-command. ************************************************************************ * ROUTINES/FORM * ************************************************************************ *------------------------------------------------------------- * Set file path of local machine *------------------------------------------------------------- FORM get_file CHANGING file_out. DATA: l_filename TYPE localfile. "Local file for upload/download CALL FUNCTION 'WS_FILENAME_GET' EXPORTING mask = c_mask mode = c_mode IMPORTING filename = l_filename EXCEPTIONS inv_winsys = 01 no_batch = 02 selection_cancel = 03 selection_error = 04. p_lpath = l_filename. ENDFORM. "get_file *&---------------------------------------------------------------------* *& Form UPLOAD_TO_APPSERVER *&---------------------------------------------------------------------* * Upload local file to app server *----------------------------------------------------------------------* FORM upload_to_appserver . DATA: l_lpath TYPE string. l_lpath = p_lpath. REFRESH i_file. CLEAR i_file. CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = l_lpath filetype = c_file_type TABLES data_tab = i_file EXCEPTIONS file_open_error = 1 file_read_error = 2 no_batch = 3 gui_refuse_filetransfer = 4 invalid_type = 5 no_authority = 6 unknown_error = 7 bad_data_format = 8 header_not_allowed = 9 separator_not_allowed = 10 header_too_long = 11 unknown_dp_error = 12 access_denied = 13 dp_out_of_memory = 14 disk_full = 15 dp_timeout = 16 OTHERS = 17. OPEN DATASET p_fpath FOR OUTPUT IN TEXT MODE ENCODING DEFAULT MESSAGE v_msg. IF sy-subrc = 0. LOOP AT i_file. " into struct_file. IF NOT i_file IS INITIAL. TRANSFER i_file TO p_fpath. ENDIF. ENDLOOP. ELSE. MESSAGE e000 WITH 'File cannot be opened for output'. ENDIF. CLOSE DATASET p_fpath. ENDFORM. " UPLOAD_TO_APPSERVER *&---------------------------------------------------------------------* *& Form DOWNLOAD_TO_DESKTOP *&---------------------------------------------------------------------* FORM download_to_desktop . OPEN DATASET p_fpath FOR INPUT IN TEXT MODE ENCODING DEFAULT MESSAGE v_msg. IF sy-subrc = 0. REFRESH : i_file. DO. READ DATASET p_fpath INTO i_file. IF sy-subrc = 0. APPEND i_file TO i_file. ELSE. EXIT. ENDIF. ENDDO. ELSE. MESSAGE e000 WITH 'File cannot be opened'. ENDIF. CLOSE DATASET p_fpath. CALL FUNCTION 'DOWNLOAD' EXPORTING filename = p_lpath TABLES data_tab = i_file. ENDFORM. " DOWNLOAD_TO_DESKTOP
REPORT z_arch_move NO STANDARD PAGE HEADING LINE-SIZE 132. ************************************************************************ * Move a file from source to target directories or Delete file * * This program will not run in a productive client. * * Source and target may be either on the Presentation or Application * servers. * * You can only copy if either source or target is on the Presentation * server. * You can either copy or move if both source and target are on the * Application server. * * When copying, provide the complete file specification for both * source and target. * * I had trouble getting the OS commands to accept an application server * filespec containing spaces. So there's a warning if you use one. Be * aware that the operation may not succeed regardless of the program * messages. ************************************************************************ * Tables ************************************************************************ ************************************************************************ * Types ************************************************************************ TYPE-POOLS: abap. TYPES: BEGIN OF ty_data, rec TYPE string, END OF ty_data. TYPES: tyt_data TYPE STANDARD TABLE OF ty_data. ************************************************************************ * Classes ************************************************************************ CLASS cl_gui_frontend_services DEFINITION LOAD. ************************************************************************ * Data ************************************************************************ DATA: w_answer TYPE char1, w_rc TYPE i. DATA: BEGIN OF w_flag, stop TYPE flag, END OF w_flag. DATA: t_data TYPE tyt_data. ************************************************************************ * Selection screen ************************************************************************ * Customising - change the first block to reflect your requirements. * Set the "modif id" to "OUT" to make a field output-only * or to "HID" to hide it completely. * Data selections ***************** SELECTION-SCREEN: BEGIN OF BLOCK zselections WITH FRAME. * Action SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. * Move or Copy PARAMETERS: p_xfer RADIOBUTTON GROUP zg1 DEFAULT 'X'. * Delete PARAMETERS: p_dele RADIOBUTTON GROUP zg1. SELECTION-SCREEN: END OF BLOCK b1. * Source SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME TITLE text-002. * Presentation server PARAMETERS: p_s_pc RADIOBUTTON GROUP zg2 DEFAULT 'X'. * Application server PARAMETERS: p_s_as RADIOBUTTON GROUP zg2. * File name PARAMETERS: p_sfile TYPE localfile. SELECTION-SCREEN: END OF BLOCK b2. * Target (Move or Copy only) SELECTION-SCREEN: BEGIN OF BLOCK b3 WITH FRAME TITLE text-003. * Presentation server PARAMETERS: p_t_pc RADIOBUTTON GROUP zg3. * Application server PARAMETERS: p_t_as RADIOBUTTON GROUP zg3 DEFAULT 'X'. * File name PARAMETERS: p_tfile TYPE localfile. * Between Application servers SELECTION-SCREEN: BEGIN OF BLOCK b4 WITH FRAME TITLE text-004. * Move PARAMETERS: p_move RADIOBUTTON GROUP zg4 DEFAULT 'X'. * Copy PARAMETERS: p_copy RADIOBUTTON GROUP zg4. SELECTION-SCREEN: END OF BLOCK b4. SELECTION-SCREEN: END OF BLOCK b3. SELECTION-SCREEN: END OF BLOCK zselections. ************************************************************************ * Events ************************************************************************ INITIALIZATION. PERFORM not_in_production. AT SELECTION-SCREEN ON BLOCK zselections. PERFORM check_selections. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_sfile. PERFORM choose_filename USING 'P_SFILE' 'P_S_PC'. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_tfile. PERFORM choose_filename USING 'P_TFILE' 'P_T_PC'. START-OF-SELECTION. PERFORM determine_actions. END-OF-SELECTION. PERFORM stop_if_requested. ************************************************************************ * Forms ************************************************************************ ************************************************************************ FORM check_selections. ************************************************************************ DATA: l_tempfile TYPE localfile. * Need a source file IF p_sfile IS INITIAL. MESSAGE e899(fi) WITH 'Source must be specified'. ENDIF. * Need a target file for Move or Copy IF p_xfer EQ abap_true AND p_tfile IS INITIAL. MESSAGE e899(fi) WITH 'Target must be specified'. ENDIF. * Check for spaces in source or target IF p_s_as EQ abap_true. l_tempfile = p_sfile. CONDENSE l_tempfile NO-GAPS. IF l_tempfile NE p_sfile. MESSAGE w899(fi) WITH 'Spaces in source file name'. ENDIF. ENDIF. IF p_t_as EQ abap_true. l_tempfile = p_tfile. CONDENSE l_tempfile NO-GAPS. IF l_tempfile NE p_tfile. MESSAGE w899(fi) WITH 'Spaces in target file name'. ENDIF. ENDIF. ENDFORM. "check_selections ************************************************************************ FORM choose_filename USING px_field_filename LIKE dynpread-fieldname px_field_pcflag LIKE dynpread-fieldname. ************************************************************************ DATA: l_location LIKE dxfields-location. DATA: lt_dynp TYPE STANDARD TABLE OF dynpread, l_dynp TYPE dynpread. l_dynp-fieldname = px_field_pcflag. APPEND l_dynp TO lt_dynp. CALL FUNCTION 'DYNP_VALUES_READ' EXPORTING dyname = sy-cprog dynumb = sy-dynnr TABLES dynpfields = lt_dynp EXCEPTIONS OTHERS = 11. IF sy-subrc <> 0. MESSAGE e899(fi) WITH 'Error (1) reading selection screen'. ENDIF. READ TABLE lt_dynp INDEX 1 INTO l_dynp. IF sy-subrc EQ 0. IF l_dynp-fieldvalue EQ abap_true. l_location = 'P'. ELSE. l_location = 'A'. ENDIF. ELSE. MESSAGE e899(fi) WITH 'Error (2) reading selection screen'. ENDIF. CALL FUNCTION 'F4_DXFILENAME_4_DYNP' EXPORTING dynpfield_filename = px_field_filename dyname = sy-cprog dynumb = sy-dynnr filetype = 'P' location = l_location server = ' '. ENDFORM. "choose_filename ************************************************************************ FORM confirm_delete_file. ************************************************************************ CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING text_question = 'Do you really want to delete this file?' display_cancel_button = abap_false IMPORTING answer = w_answer EXCEPTIONS text_not_found = 1 OTHERS = 2. IF sy-subrc NE 0 OR w_answer NE 1. w_flag-stop = abap_true. MESSAGE s899(fi) WITH 'Deletion not attempted'. STOP. ENDIF. ENDFORM. "confirm_delete_file ************************************************************************ FORM copy_file_on_pres_srvr USING px_source TYPE localfile px_target TYPE localfile. ************************************************************************ DATA: l_sfile TYPE string, l_tfile TYPE string. l_sfile = px_source. l_tfile = px_target. CALL METHOD cl_gui_frontend_services=>file_copy EXPORTING source = l_sfile destination = l_tfile overwrite = abap_true EXCEPTIONS OTHERS = 13. IF sy-subrc EQ 0. FORMAT COLOR COL_POSITIVE. WRITE: / 'Successfully copied file', px_source, / 'to', px_target UNDER px_source. ELSE. w_flag-stop = abap_true. MESSAGE s899(fi) WITH 'Failed to copy file' px_source DISPLAY LIKE 'E'. STOP. ENDIF. ENDFORM. "copy_file_on_pres_srvr ************************************************************************ FORM delete_file. ************************************************************************ DATA: l_file TYPE string. IF p_s_pc EQ abap_true. * Delete Presentation server file l_file = p_sfile. CALL METHOD cl_gui_frontend_services=>file_delete EXPORTING filename = l_file CHANGING rc = w_rc EXCEPTIONS file_delete_failed = 1 cntl_error = 2 error_no_gui = 3 file_not_found = 4 access_denied = 5 unknown_error = 6 not_supported_by_gui = 7 wrong_parameter = 8 OTHERS = 9. ELSE. * Delete Application server file CATCH SYSTEM-EXCEPTIONS file_access_errors = 4. DELETE DATASET p_sfile. ENDCATCH. ENDIF. IF sy-subrc EQ 0. FORMAT COLOR COL_POSITIVE. WRITE: / 'Successfully deleted file', p_sfile. ELSE. w_flag-stop = abap_true. MESSAGE s899(fi) WITH 'Failed to delete file' p_sfile DISPLAY LIKE 'E'. STOP. ENDIF. ENDFORM. "delete_file ************************************************************************ FORM determine_actions. ************************************************************************ IF p_xfer EQ abap_true. PERFORM move_or_copy. ELSE. PERFORM confirm_delete_file. PERFORM delete_file. ENDIF. ENDFORM. "determine_actions ************************************************************************ FORM move_file_on_app_srvr USING px_source TYPE localfile px_target TYPE localfile. ************************************************************************ DATA: l_exitcode TYPE btcxpgexit, l_parms TYPE btcxpgpar, l_status TYPE btcxpgstat. DATA: lt_protocol TYPE STANDARD TABLE OF btcxpm, l_protocol TYPE btcxpm. CONCATENATE px_source px_target INTO l_parms SEPARATED BY space. * External command: * - Unix - mv * - Windows - cmd /c move CALL FUNCTION 'SXPG_COMMAND_EXECUTE' EXPORTING commandname = 'Z_ARCH_MV' additional_parameters = l_parms IMPORTING status = l_status exitcode = l_exitcode TABLES exec_protocol = lt_protocol EXCEPTIONS no_permission = 1 command_not_found = 2 parameters_too_long = 3 security_risk = 4 wrong_check_call_interface = 5 program_start_error = 6 program_termination_error = 7 x_error = 8 parameter_expected = 9 too_many_parameters = 10 illegal_command = 11 wrong_asynchronous_parameters = 12 cant_enq_tbtco_entry = 13 jobcount_generation_error = 14 OTHERS = 15. IF sy-subrc NE 0 OR l_status NE 'O' OR l_exitcode NE '0'. * Failure FORMAT COLOR COL_NEGATIVE. WRITE: / 'Failed to move' , px_source, / 'to', px_target UNDER px_source. FORMAT COLOR COL_NORMAL. LOOP AT lt_protocol INTO l_protocol. WRITE: / l_protocol-message+0(l_protocol-length). ENDLOOP. ELSE. * Success FORMAT COLOR COL_POSITIVE. WRITE: / 'Successfully moved' , px_source, / 'to', px_target UNDER px_source. ENDIF. ENDFORM. "move_file_on_app_srvr ************************************************************************ FORM move_or_copy. ************************************************************************ IF p_s_as EQ abap_true AND p_t_as EQ abap_true. * Source and Target both on AppSrvr IF p_move EQ abap_true. PERFORM move_file_on_app_srvr USING p_sfile p_tfile. ELSE. PERFORM read_appsrvr_file USING p_sfile CHANGING t_data. PERFORM write_appsrvr_file USING p_tfile t_data. ENDIF. ELSEIF p_s_pc EQ abap_true AND p_t_pc EQ abap_true. * Source and Target both on PresSrvr PERFORM copy_file_on_pres_srvr USING p_sfile p_tfile. ELSEIF p_s_pc EQ abap_true. * Source on PresSrvr; Target on AppSrvr PERFORM read_local_file USING p_sfile CHANGING t_data. PERFORM write_appsrvr_file USING p_tfile t_data. ELSE. * Source on AppSrvr; Target on PresSrvr PERFORM read_appsrvr_file USING p_sfile CHANGING t_data. PERFORM write_local_file USING p_tfile t_data. ENDIF. ENDFORM. "move_or_copy ************************************************************************ FORM not_in_production. ************************************************************************ DATA: l_cccategory TYPE cccategory. SELECT SINGLE cccategory INTO l_cccategory FROM t000 WHERE mandt EQ sy-mandt. IF l_cccategory EQ 'P'. MESSAGE e899(fi) WITH 'Program' sy-repid 'is not available in Production clients'. ENDIF. ENDFORM. "not_in_production ************************************************************************ FORM read_appsrvr_file USING px_source TYPE localfile CHANGING pxt_data TYPE tyt_data. ************************************************************************ DATA: l_data TYPE ty_data. CATCH SYSTEM-EXCEPTIONS file_access_errors = 4. OPEN DATASET px_source FOR INPUT IN TEXT MODE. DO. READ DATASET px_source INTO l_data-rec. IF sy-subrc NE 0. EXIT. ENDIF. APPEND l_data TO pxt_data. ENDDO. CLOSE DATASET px_source. ENDCATCH. IF sy-subrc EQ 0. FORMAT COLOR COL_POSITIVE. WRITE: / 'Successfully read', px_source. FORMAT COLOR COL_NORMAL. ELSE. w_flag-stop = abap_true. MESSAGE s899(fi) WITH 'Unable to read AppSrvr file' px_source DISPLAY LIKE 'E'. STOP. ENDIF. ENDFORM. "read_appsrvr_file ************************************************************************ FORM read_local_file USING px_source TYPE localfile CHANGING pxt_data TYPE tyt_data. ************************************************************************ DATA: l_file TYPE string. l_file = px_source. CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = l_file TABLES data_tab = pxt_data EXCEPTIONS OTHERS = 17. IF sy-subrc EQ 0. FORMAT COLOR COL_POSITIVE. WRITE: / 'Successfully read', px_source. FORMAT COLOR COL_NORMAL. ELSE. w_flag-stop = abap_true. MESSAGE s899(fi) WITH 'Unable to read local file' px_source DISPLAY LIKE 'E'. STOP. ENDIF. ENDFORM. "read_local_file ************************************************************************ FORM stop_if_requested. ************************************************************************ IF w_flag-stop EQ abap_true. STOP. ENDIF. ENDFORM. "stop_if_requested ************************************************************************ FORM write_appsrvr_file USING px_target TYPE localfile pxt_data TYPE tyt_data. ************************************************************************ DATA: l_data TYPE ty_data. CATCH SYSTEM-EXCEPTIONS file_access_errors = 4. OPEN DATASET px_target FOR OUTPUT IN TEXT MODE. LOOP AT pxt_data INTO l_data. TRANSFER l_data-rec TO px_target. ENDLOOP. CLOSE DATASET px_target. ENDCATCH. IF sy-subrc EQ 0. FORMAT COLOR COL_POSITIVE. WRITE: / 'Successfully written', px_target. FORMAT COLOR COL_NORMAL. ELSE. w_flag-stop = abap_true. MESSAGE s899(fi) WITH 'Unable to write AppSrvr file' px_target DISPLAY LIKE 'E'. STOP. ENDIF. ENDFORM. "write_appsrvr_file ************************************************************************ FORM write_local_file USING px_target TYPE localfile pxt_data TYPE tyt_data. ************************************************************************ DATA: l_file TYPE string. l_file = px_target. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = l_file TABLES data_tab = pxt_data EXCEPTIONS OTHERS = 17. IF sy-subrc EQ 0. FORMAT COLOR COL_POSITIVE. WRITE: / 'Successfully written', px_target. FORMAT COLOR COL_NORMAL. ELSE. w_flag-stop = abap_true. MESSAGE s899(fi) WITH 'Unable to write local file' px_target DISPLAY LIKE 'E'. STOP. ENDIF. ENDFORM. "write_local_file
REPORT z_appl_presentation_server NO STANDARD PAGE HEADING . *&----------------DATA DECLARATION----------------------------------& INCLUDE z_appl_presentation_server_data_declaration. *&----------------INCLUDE FOR PERFORMS------------------------------&* INCLUDE z_appl_presentation_server_forms. *&----------------AT SELECTION SCREEN EVENT-------------------------&* *& At selection screen output for screen attributes AT SELECTION-SCREEN OUTPUT. PERFORM screen_attributes. *& Providing f4 help path to filmanager on presentation server AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. PERFORM source_destination. *& Providing f4 help path to Application server AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1. PERFORM application_server_path. *&----------------START OF SELECTION--------------------------------&* START-OF-SELECTION. *& Reading data from application server and copy it to presentation server IF p_read = 'X'. PERFORM read_from_server. *& Copy the data from presentation server and write to application server ELSE. PERFORM write_to_server. ENDIF. *&---------------------------------------------------------------------* *& Include z_appl_presentation_server_DATA_DECLARATION *&---------------------------------------------------------------------* *& Types Declaration TYPES : BEGIN OF ty_bseg, "Accounting Document Segment bukrs(4), "Company Code belnr(10), "Accounting Document Number gjahr(4), "Fiscal Year buzei(3), "Number of Line Item Within Accounting Document kostl(10), "Cost Center saknr(10), "G/L Account No END OF ty_bseg. *& Work area and Internal tabel DATA: wa_bseg TYPE ty_bseg, it_bseg TYPE STANDARD TABLE OF ty_bseg. *& Data declaratio for read/write data to application serve DATA: d_filename(128), file TYPE string. *& Selection Screen PARAMETERS: p_read RADIOBUTTON GROUP rad1 DEFAULT 'X' "Copy the file from Application server to PC USER-COMMAND chek, p_write RADIOBUTTON GROUP rad1, "Copy the file from PC to Application server p_file LIKE rlgrap-filename OBLIGATORY DEFAULT 'C:\Documents and Settings\pvora\Desktop\test.txt' MODIF ID g02, "Filename on PC p_file1 LIKE rlgrap-filename DEFAULT '.\Pratik.txt' "Filename on server MODIF ID g01. *&---------------------------------------------------------------------* *& Include z_appl_presentation_server_FORMS *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form read_from_server *&---------------------------------------------------------------------* FORM read_from_server. CLEAR d_filename. d_filename = p_file1. *& Reading file from application server OPEN DATASET d_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT. DO. READ DATASET d_filename INTO wa_bseg. IF sy-subrc <> 0. EXIT. ENDIF. APPEND wa_bseg TO it_bseg. ENDDO. CLOSE DATASET d_filename. *& Dwonloading file to Presentation Server file = p_file. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = file filetype = 'ASC' append = ' ' TABLES data_tab = it_bseg EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21. ENDFORM. " read_from_server *&---------------------------------------------------------------------* *& Form write_to_server *&---------------------------------------------------------------------* FORM write_to_server. *& Uploading file from Presentation server file = p_file. CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = file filetype = 'ASC' TABLES data_tab = it_bseg EXCEPTIONS file_open_error = 1 file_read_error = 2 no_batch = 3 gui_refuse_filetransfer = 4 invalid_type = 5 no_authority = 6 unknown_error = 7 bad_data_format = 8 header_not_allowed = 9 separator_not_allowed = 10 header_too_long = 11 unknown_dp_error = 12 access_denied = 13 dp_out_of_memory = 14 disk_full = 15 dp_timeout = 16. CLEAR d_filename. d_filename = p_file1. *& Writing in the file on application server OPEN DATASET d_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. LOOP AT it_bseg INTO wa_bseg. TRANSFER wa_bseg TO d_filename. ENDLOOP. CLOSE DATASET d_filename. OPEN DATASET d_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT. DO. READ DATASET d_filename INTO wa_bseg. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ wa_bseg-bukrs, wa_bseg-belnr, wa_bseg-gjahr, wa_bseg-kostl, wa_bseg-saknr. ENDDO. CLOSE DATASET d_filename. ENDFORM. " write_to_server *&---------------------------------------------------------------------* *& Form source_destination *&---------------------------------------------------------------------* FORM source_destination. file = p_file. CALL FUNCTION 'KD_GET_FILENAME_ON_F4' EXPORTING program_name = syst-repid dynpro_number = syst-dynnr field_name = p_file * STATIC = ' ' * MASK = ' ' CHANGING file_name = p_file EXCEPTIONS mask_too_long = 1. ENDFORM. " source_destination *&---------------------------------------------------------------------* *& Form application_server_path *&---------------------------------------------------------------------* FORM application_server_path. IF p_read = 'X'. *& Selecting file from server on pressing f4 CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE' EXPORTING directory = '.\' filemask = ' ' IMPORTING serverfile = p_file1 EXCEPTIONS canceled_by_user = 1. ELSE. MESSAGE 'F4 is only valid for transfering data from Server to PC' TYPE 'S'. ENDIF. ENDFORM. " application_server_path *&---------------------------------------------------------------------* *& Form screen_attributes *&---------------------------------------------------------------------* FORM screen_attributes . IF p_write = 'X'. LOOP AT SCREEN. IF screen-group1 = 'G01'. screen-input = 0. MODIFY SCREEN. ENDIF. ENDLOOP. ELSE. LOOP AT SCREEN. IF screen-group1 = 'G02'. screen-input = 0. MODIFY SCREEN. ENDIF. ENDLOOP. ENDIF. ENDFORM. " screen_attributes
File on presentation server
Solution for any ABAP system
Parameters of F4_DXFILENAME_4_DYNP:
filetype:
'P' represents Physical file name
'L' represents Logical file name.
location:
'A' represents Application Server
'P' represents Presentation server.
PARAMETERS p_file TYPE dxfile-filename. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. CALL FUNCTION 'F4_DXFILENAME_4_DYNP' EXPORTING dynpfield_filename = 'P_FILE' dyname = sy-repid dynumb = sy-dynnr filetype = 'P' location = 'A' server = ' '.
Solution for SAP ERP only
With the function module F4_FILENAME.
REPORT zvenkattest. *------------------------------------------------------------* * selection screen parameters *------------------------------------------------------------* PARAMETERS: p_source LIKE rlgrap-filename. *------------------------------------------------------------* * at selection screen for field *------------------------------------------------------------* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_source . CALL FUNCTION 'F4_FILENAME' EXPORTING program_name = syst-cprog dynpro_number = syst-dynnr field_name = 'P_SOURCE' IMPORTING file_name = p_source.
File on application server
Parameters of F4_DXFILENAME_4_DYNP:
filetype:
'P' represents Physical file name
'L' represents Logical file name.
location:
'A' represents Application Server
'P' represents Presentation server.
PARAMETERS p_file TYPE dxfile-filename. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. CALL FUNCTION 'F4_DXFILENAME_4_DYNP' EXPORTING dynpfield_filename = 'P_FILE' dyname = sy-repid dynumb = sy-dynnr filetype = 'P' location = 'A' server = ' '.
Get Name of Files in Excel File from Selected Directory of Local System
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'REPORT zfsl_gdirfn. ************************************************************************ * Declaration of Variables & Internal Tables * ************************************************************************ DATA: it_file LIKE STANDARD TABLE OF sdokpath WITH HEADER LINE, it_dir LIKE STANDARD TABLE OF sdokpath WITH HEADER LINE, file_count TYPE i, dir_count TYPE i. ************************************************************************ * Selection Screen * ************************************************************************ SELECTION-SCREEN: BEGIN OF BLOCK a WITH FRAME TITLE ftitle, BEGIN OF LINE, COMMENT 1(40) lpdirp FOR FIELD pdirp. PARAMETER: pdirp TYPE pfeflnamel OBLIGATORY. " Directory Path from where you want to get Name of Files SELECTION-SCREEN: END OF LINE, BEGIN OF LINE, COMMENT 1(40) lpsavep FOR FIELD psavep. PARAMETER: psavep TYPE string OBLIGATORY. " Excel File Path and Name in which you want to Save Name of Files SELECTION-SCREEN: END OF LINE, END OF BLOCK a. ************************************************************************ * START-OF-SELECTION * ************************************************************************ START-OF-SELECTION. CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES' " To Get the Name of Files in Internal Table of Given Directory EXPORTING directory = pdirp filter = '*.*' IMPORTING file_count = file_count " Number of File in Directory dir_count = dir_count " Number of Directory in Directory TABLES file_table = it_file " Table for Name of Files dir_table = it_dir " Table for Name of Directories EXCEPTIONS cntl_error = 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 file_count IS NOT INITIAL. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = psavep " Path and Name of Excel File with Extension .xls TABLES data_tab = it_file " Internal Table having all Name of Files EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22. 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: 'No file found in the selected Directory' TYPE 'I'. ENDIF. ************************************************************************ * INITIALIZATION * ************************************************************************ INITIALIZATION. ftitle = 'Select from the following Options'. lpdirp = 'Directory of Fiels'. lpsavep = 'Path and Name of Excel File'. pdirp = 'C:\'. psavep = 'C:\test.xls'. ************************************************************************ * AT SELECTION-SCREEN ON VALUE-REQUEST * ************************************************************************ *F4 for Getting Directory Path AT SELECTION-SCREEN ON VALUE-REQUEST FOR pdirp. DATA: fname TYPE string. CALL METHOD cl_gui_frontend_services=>directory_browse EXPORTING window_title = 'Select Directory' CHANGING selected_folder = fname EXCEPTIONS cntl_error = 1 error_no_gui = 2 not_supported_by_gui = 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. pdirp = fname. *F4 for Getting File Path and Name AT SELECTION-SCREEN ON VALUE-REQUEST FOR psavep. DATA: filename TYPE string, path TYPE string. CALL METHOD cl_gui_frontend_services=>file_save_dialog EXPORTING window_title = 'Select path and file name' default_extension = 'XLS' CHANGING filename = filename path = path fullpath = psavep EXCEPTIONS cntl_error = 1 error_no_gui = 2 not_supported_by_gui = 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.
Introduction
SAP has provided us with a lot of standard programs to make our day to day life easier. The standard code suite extends from simple programs to upload or download hierarchies to more complex ones to activate inactive objects in production. The flat file manipulation programs include programs to upload or download flat file to or from the system. But this list does not include one to transpose a flat file.
There are ‘n’ numbers of ways to achieve this. What is given in this article is to consider the separator values e.g. comma (,) or colon (;) as regular expressions and derive the values nested within the separators.
Regular Expressions
In computing, a regular expression provides a concise and flexible means for "matching" (specifying and recognizing) strings of text, such as particular characters, words, or patterns of characters - Wikipedia
For a general overview about regular expressions: Regular Expression
Generally, in a given string any value that occurs repeatedly, be it in regular or random intervals, can be termed as a regular expression. In our case, any flat-file whose values are separated by an expression e.g. comma (,) or colon (;) can be taken to contain regular expressions with the separator as the expression itself.
REGEX
The REGEX command was introduced into ABAP with NetWeaver Release 2004s. It has been widely used for manipulating character strings and to search for specific expressions in text files which are extensive.
A code sample for finding regular expression would be like,
FIND ALL OCCURRENCES OF REGEX <expression> IN <string> RESULTS <t_results>.
The above code would execute the REGEX command over the given string and store all occurrences of the ‘expression’ in an internal table
Note: A regular ‘csv’ file would not have a comma separator at the end of a record. An entry would be manually inserted in the program to identify the last value.
CODE
*&---------------------------------------------------------------------* *& Report ZFILE_TRANSPOSE *& *&---------------------------------------------------------------------* REPORT zfile_transpose. *DECLARATION TYPES: BEGIN OF st_file, rec TYPE string, END OF st_file. TYPES: BEGIN OF st_inter, row_no TYPE i, rec TYPE string, END OF st_inter. DATA : t_file TYPE TABLE OF st_file, "Internal table to read file wa_file TYPE st_file, t_outfile TYPE TABLE OF st_file, wa_outfile TYPE st_file, t_inter TYPE TABLE OF st_inter, "Intermidiate table to store file wa_inter TYPE st_inter. FIELD-SYMBOLS : <fs_file> TYPE st_file. FIELD-SYMBOLS : <fs_inter> TYPE st_inter. DATA : it_csv TYPE match_result_tab, "Internal table for REGEX result wa_it_csv LIKE LINE OF it_csv. DATA : col_count TYPE i, row_count TYPE i, loop_count1 TYPE i, loop_count2 TYPE i, col_len TYPE i, temp1 TYPE i, temp2 TYPE i, temp3 TYPE i, value TYPE string, char_len TYPE string. CONSTANTS: c_filetype TYPE char10 VALUE 'ASC'. "For Filetype DAT PARAMETERS: p_file1 LIKE rlgrap-filename OBLIGATORY. "Get file loacftion PARAMETERS: p_file2 LIKE rlgrap-filename OBLIGATORY. "File loaction for transposed data PARAMETERS: p_sptr TYPE c OBLIGATORY. "Character used for separator AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1. "Get FILE from selection screen *GET FILE PATH PERFORM get_file_path USING p_file1. *&---------------------------------------------------------------------* START-OF-SELECTION. *UPLOAD DATA PERFORM get_data USING p_file1 CHANGING t_file. "Copy FILE data to internal table *&---------------------------------------------------------------------* *CREATE INTERNAL TABLE TO STORE DTO DETAILS READ TABLE t_file INTO wa_file INDEX 1. IF sy-subrc = 0. FIND ALL OCCURRENCES OF p_sptr IN wa_file-rec MATCH COUNT col_count. col_count = col_count + 1. "To count number of columns ENDIF. LOOP AT t_file INTO wa_file. row_count = row_count + 1. "To count number of rows ENDLOOP. LOOP AT t_file INTO wa_file. loop_count1 = sy-tabix. col_len = strlen( wa_file-rec ). "Find length of each row FIND ALL OCCURRENCES OF REGEX p_sptr IN wa_file-rec RESULTS it_csv. IF sy-subrc = 0. wa_it_csv-offset = col_len. "Create entry in regex table APPEND wa_it_csv TO it_csv. "for last comma ELSE. MESSAGE 'Incorrect Separator Value' TYPE 'E'. ENDIF. temp1 = 0. LOOP AT it_csv INTO wa_it_csv. temp2 = temp3 = wa_it_csv-offset. temp2 = temp2 - temp1. value = wa_file-rec+temp1(temp2). "Get value between commas temp1 = temp3 + 1. loop_count2 = sy-tabix. IF loop_count1 = 1. wa_inter-row_no = loop_count2. "Include row number for each record CONCATENATE value p_sptr INTO wa_inter-rec. APPEND wa_inter TO t_inter. ENDIF. IF loop_count1 > 1 AND loop_count1 < row_count. "Adding comma separation to transposed value READ TABLE t_inter ASSIGNING <fs_inter> WITH KEY row_no = loop_count2. IF sy-subrc = 0. CONCATENATE <fs_inter>-rec value p_sptr INTO <fs_inter>-rec. UNASSIGN <fs_inter>. ENDIF. ELSEIF loop_count1 EQ row_count. "No comma needed for last value READ TABLE t_inter ASSIGNING <fs_inter> WITH KEY row_no = loop_count2. IF sy-subrc = 0. CONCATENATE <fs_inter>-rec value INTO <fs_inter>-rec. UNASSIGN <fs_inter>. ENDIF. ENDIF. ENDLOOP. ENDLOOP. LOOP AT t_inter INTO wa_inter. wa_outfile-rec = wa_inter-rec. APPEND wa_outfile TO t_outfile. ENDLOOP. *DOWNLOAD DATA PERFORM put_data USING p_file2 CHANGING t_outfile. "Copy FILE data to internal table IF sy-subrc = 0. MESSAGE 'File transposed Succesfully' TYPE 'S'. ENDIF. *&---------------------------------------------------------------------* *& Form GET_FILE_PATH *&---------------------------------------------------------------------* FORM get_file_path USING p_p_file1. DATA : wsl_upfile LIKE rlgrap-filename VALUE IS INITIAL. wsl_upfile = p_file1. CLEAR: p_file1. CALL FUNCTION 'KD_GET_FILENAME_ON_F4' EXPORTING PROGRAM_NAME = SYST-REPID DYNPRO_NUMBER = SYST-DYNNR CHANGING file_name = wsl_upfile EXCEPTIONS MASK_TOO_LONG = 1 OTHERS = 2. p_file1 = wsl_upfile. ENDFORM. " GET_FILE_PATH *&---------------------------------------------------------------------* *& Form GET_DATA *&---------------------------------------------------------------------* FORM get_data USING p_p_file1 CHANGING p_t_file TYPE table. DATA: l_file TYPE string. l_file = p_p_file1. CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = l_file filetype = c_filetype TABLES data_tab = p_t_file EXCEPTIONS file_open_error = 1 file_read_error = 2 no_batch = 3 gui_refuse_filetransfer = 4 invalid_type = 5 no_authority = 6 unknown_error = 7 bad_data_format = 8 header_not_allowed = 9 separator_not_allowed = 10 header_too_long = 11 unknown_dp_error = 12 access_denied = 13 dp_out_of_memory = 14 disk_full = 15 dp_timeout = 16 OTHERS = 17. IF sy-subrc IS INITIAL. ELSE. MESSAGE s001(00) WITH 'File not found'. STOP. ENDIF. CLEAR l_file. ENDFORM. " GET_DATA *&---------------------------------------------------------------------* *& Form PUT_DATA *&---------------------------------------------------------------------* FORM put_data USING p_p_file2 CHANGING p_t_outfile TYPE table. DATA: l_outfile TYPE string. l_outfile = p_p_file2. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = l_outfile filetype = c_filetype TABLES data_tab = p_t_outfile EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. ENDFORM. " PUT_DATA
Author: Sujeet Mishra
Submitted: 22/8/2013
Description
CALL METHOD cl_gui_frontend_services=>execute EXPORTING document = 'C:\Documents and Settings\xyz\Desktop\hi.txt' * application = * parameter = * default_directory = * maximized = * minimized = * synchronous = * operation = 'OPEN' EXCEPTIONS cntl_error = 1 error_no_gui = 2 bad_parameter = 3 file_not_found = 4 path_not_found = 5 file_extension_unknown = 6 error_execute_failed = 7 synchronous_failed = 8 not_supported_by_gui = 9 others = 10 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.
In SAP6.0, certain function modules have become obsolete. They need to be replaced by new function modules. Here I describe how to handle two of the most important function modules used to download/upload files from server - UPLOAD/ DOWNLOAD. These function modules have been replaced by GUI_UPLOAD/GUI_DOWNLOAD in 6.0. So when upgrading , we need to pay special attention while replacing the old function modules with the new ones as the data dypes and certain other parameters have changed. For example, in DOWNLOAD/UPLOAD function modules, a pop up screen used to appear which asked for the location of the file to be uploaded or downloaded. But the functionality is missing in the replacement fms. So in order to restore the previous functionality, we need to call a class method cl_gui_frontend_services=>file_open_dialog (for upload functionality) and cl_gui_frontend_services=>file_save_dialog (for download functionality) which gives the pop up.
Following code snippet shows how the replacement can be implemented.
DOWNLOAD ::
CALL FUNCTION 'DOWNLOAD' EXPORTING filename = p_out1 "' ' filetype = 'ASC' item = 'Hierarchy'(t17) silent = 'M' col_select = 'X' TABLES data_tab = t_output.
Replaced with ::
DATA: l_p_out1_new TYPE string, l_filename TYPE string, l_fullpath TYPE string, l_path TYPE string. MOVE p_out1 TO l_p_out1_new . CALL METHOD cl_gui_frontend_services=>file_save_dialog EXPORTING default_file_name = l_p_out1_new CHANGING filename = l_filename path = l_path fullpath = l_fullpath. IF sy-subrc <> 0. ENDIF. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = l_fullpath filetype = 'ASC' append = 'X' TABLES data_tab = t_output EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.
UPLOAD ::
CALL FUNCTION 'UPLOAD' EXPORTING codepage = ' ' filename = 'H:\data\BI-TEST.txt' filetype = 'DAT' TABLES data_tab = <p1> EXCEPTIONS conversion_error = 1 invalid_table_width = 2 invalid_type = 3 no_batch = 4 unknown_error = 5 gui_refuse_filetransfer = 6 OTHERS = 7.
Replaced with ::
DATA:lt_file_table TYPE filetable. DATA:lw_file TYPE file_table. DATA:l_rc TYPE i. DATA:BEGIN OF lt_itab OCCURS 0 , l_c1 TYPE string, END OF lt_itab. DATA:l_action TYPE i. DATA l_filename_new TYPE string . CALL METHOD cl_gui_frontend_services=>file_open_dialog EXPORTING default_filename = 'H:TEST.TXT' CHANGING file_table = lt_file_table rc = l_rc user_action = l_action. IF l_action NE 9. READ TABLE lt_file_table INTO lw_file INDEX 1. l_filename_new = lw_file-filename. *Upload FM Replaced with Gui_upload CALL FUNCTION 'GUI_UPLOAD' EXPORTING codepage = '' filename = l_filename_new filetype = 'ASC' has_field_separator = 'X' TABLES data_tab = <p1> EXCEPTIONS no_batch = 4 invalid_type = 3 unknown_error = 5 OTHERS = 7. . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDIF.
Description : There are instances, when some garbage characters creep into the data while reading from a text file ( .txt ) in application server. It may get the upload totoaly wrong and can give incoorect results during execution. Heres a simple snippet to uplaod data from application server into SAP internal Table without any garbage characters in the data. The only thing to be kept in mind is that it works on for text files (.txt)
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'FIELD-SYMBOLS: <fs> TYPE x_upload. FIELD-SYMBOLS: <fs_struc> TYPE any. FIELD-SYMBOLS: <fs_itab> TYPE table. DATA :l_sys_cp LIKE tcp00-cpcodepage. DATA : l_tcp00 LIKE tcp00. DATA : l_lan_cp LIKE tcp00-cpcodepage. * check code page first CALL FUNCTION 'SYSTEM_CODEPAGE' IMPORTING codepage = l_sys_cp. SELECT SINGLE * FROM tcp00 INTO l_tcp00 WHERE cpcodepage = l_sys_cp. CONSTANTS :c_rc4 LIKE sy-subrc VALUE 4. CALL FUNCTION 'SCP_CODEPAGE_FOR_LANGUAGE' EXPORTING language = sy-langu IMPORTING codepage = l_lan_cp EXCEPTIONS OTHERS = c_rc4. IF sy-subrc <> 0. l_lan_cp = l_sys_cp. ENDIF. DATA : i_tab_input_data TYPE truxs_t_text_data. ASSIGN i_tab_input_data[] TO <fs_itab>. ASSIGN LOCAL COPY OF INITIAL LINE OF <fs_itab> TO <fs_struc>. OPEN DATASET p_upload FOR INPUT IN TEXT MODE ENCODING DEFAULT. "also check the option of ... CODE PAGE cp in help WHILE sy-subrc = 0. READ DATASET p_upload INTO <fs_struc>. APPEND <fs_struc> TO <fs_itab>. ENDWHILE. CLOSE DATASET p_upload. DATA: ld_lan_cp TYPE abap_encod. ld_lan_cp = l_lan_cp. CALL FUNCTION 'TRANSLATE_CODEPAGE_IN' EXPORTING codepage_from = ld_lan_cp TABLES t_data = <fs_itab> EXCEPTIONS OTHERS = 0. DATA: l_file_name_string TYPE string, l_file_format_10 TYPE char10. l_file_name_string = p_upload. l_file_format_10 = 'ASC'. CONSTANTS : c_rc0 LIKE sy-subrc VALUE 0, c_rc8 LIKE sy-subrc VALUE 8, c_rc12 LIKE sy-subrc VALUE 12, c_rc16 LIKE sy-subrc VALUE 16. DATA : l_totalsize TYPE i. DATA : l_fm_name LIKE tfdir-funcname. DATA : l_tfdir LIKE tfdir. DATA : i_line_header TYPE char01. l_fm_name = 'TEXT_CONVERT_TXT_TO_SAP'. SELECT SINGLE * FROM tfdir INTO l_tfdir WHERE funcname = l_fm_name. IF sy-subrc = 0. CALL FUNCTION l_fm_name EXPORTING i_fileformat = 'TXT' i_field_seperator = 'X' i_line_header = i_line_header i_tab_raw_data = <fs_itab> i_filename = p_upload i_totalsize = l_totalsize TABLES i_tab_converted_data = it_upload EXCEPTIONS OTHERS = c_rc4. ELSE. MESSAGE e046(fl) WITH l_fm_name RAISING conversion_failed. ENDIF. IF sy-subrc <> c_rc0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 RAISING conversion_failed. ENDIF.
TYPES : BEGIN OF gty_display, f1 TYPE char20, f2 TYPE char20, END OF gty_display. DATA: lv_filename TYPE rlgrap-filename, gs_display TYPE gty_display , lv_timestamp(55) TYPE c, gt_display TYPE gty_display, gt_final TYPE gty_display. CONSTANTS : lc_ex TYPE char4 VALUE '.XLS', gc_con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab. " p_path is where you need to store the file in SAP directory CONCATENATE p_path lc_ex INTO lv_timestamp. lv_filename = lv_timestamp. OPEN DATASET lv_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. LOOP AT gt_display INTO gs_display. CONCATENATE gs_display-f1 gs_displayf2 INTO gt_final SEPARATED BY gc_con_tab. TRANSFER gt_final TO lv_filename. ENDLOOP. CLOSE DATASET lv_filename.
Author: Eswar Kanakanti
Submitted: 20-Apr-2007
Summary:
This is an ABAP program, downloads a file based on the user provided delimit characters on the selection screen dynamically.
In case of Tab delimit character, user has to provide 'T' so that program will create a tab delimit file.
Source Code:
REPORT zfile_with_delchar. TABLES: mara. *******Types Declaration TYPES: **--File Output BEGIN OF ty_out, line(150), END OF ty_out, **--Material Data BEGIN OF ty_mat, matnr TYPE mara-matnr, mtart TYPE mara-mtart, mbrsh TYPE mara-mbrsh, meins TYPE mara-meins, END OF ty_mat. DATA: it_out TYPE STANDARD TABLE OF ty_out WITH HEADER LINE, it_mat TYPE STANDARD TABLE OF ty_mat WITH HEADER LINE. **--Selection-screen Design SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. **--Material numbers SELECT-OPTIONS s_matnr FOR mara-matnr. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 1(15) text-002. **--Delimit char PARAMETERS: p_dchar TYPE c OBLIGATORY. SELECTION-SCREEN COMMENT 20(20) text-003. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN END OF BLOCK b1. CLASS cl_abap_char_utilities DEFINITION LOAD. START-OF-SELECTION. **--Get the data from material table SELECT matnr mtart mbrsh meins FROM mara INTO TABLE it_mat WHERE matnr IN s_matnr. **--Prepare output file with specified delimit char LOOP AT it_mat. IF p_dchar = 'T'. CONCATENATE it_mat-matnr it_mat-mtart it_mat-mbrsh it_mat-meins INTO it_out-line SEPARATED BY cl_abap_char_utilities=>horizontal_tab. ELSE. CONCATENATE it_mat-matnr it_mat-mtart it_mat-mbrsh it_mat-meins INTO it_out-line SEPARATED BY p_dchar. ENDIF. APPEND it_out. CLEAR: it_out,it_mat. ENDLOOP. **--Download the data CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = 'C:\mat.txt' TABLES data_tab = it_out EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22. IF sy-subrc = 0. WRITE:/ 'File is downloaded'. ENDIF.
Selection-screen:
Author: Vijay Babu Dudla
Submitted: 11.08.2008
Description: This report is used to Convert the Internal table to HTML formated table.
'WWW_ITAB_TO_HTML_HEADERS' "This is used to Set the Column properties
'WWW_ITAB_TO_HTML_LAYOUT' "This is used to set the layout properties
'WWW_ITAB_TO_HTML' "Using the Columns Definitions and Internal table this Function converts the internal table data into HTML format.
REPORT zdownload_table_html. *-Internal table Declaration TYPES: BEGIN OF ty_vbap, vbeln TYPE vbeln, posnr TYPE posnr, matnr TYPE matnr, END OF ty_vbap. *-ALL related Declarations DATA: t_header TYPE STANDARD TABLE OF w3head WITH HEADER LINE, "Header t_fields TYPE STANDARD TABLE OF w3fields WITH HEADER LINE, "Fields t_html TYPE STANDARD TABLE OF w3html, wa_header TYPE w3head, w_head TYPE w3head. DATA: it_vbap TYPE STANDARD TABLE OF ty_vbap, it_fcat TYPE lvc_t_fcat WITH HEADER LINE. START-OF-SELECTION. SELECT vbeln posnr matnr FROM vbap INTO TABLE it_vbap UP TO 20 ROWS. END-OF-SELECTION. *-Populate the Columns it_fcat-coltext = 'SalesOrder'. APPEND it_fcat. it_fcat-coltext = 'ItmeNumber'. APPEND it_fcat. it_fcat-coltext = 'Material'. APPEND it_fcat. *-Fill the Column heading and Filed Properties LOOP AT it_fcat. w_head-text = it_fcat-coltext. CALL FUNCTION 'WWW_ITAB_TO_HTML_HEADERS' EXPORTING field_nr = sy-tabix text = w_head-text fgcolor = 'black' bgcolor = 'green' TABLES header = t_header. CALL FUNCTION 'WWW_ITAB_TO_HTML_LAYOUT' EXPORTING field_nr = sy-tabix fgcolor = 'black' size = '3' TABLES fields = t_fields. ENDLOOP. *-Title of the Display wa_header-text = 'Sales Order Details' . wa_header-font = 'Arial'. wa_header-size = '2'. *-Preparing the HTML from Intenal Table REFRESH t_html. CALL FUNCTION 'WWW_ITAB_TO_HTML' EXPORTING table_header = wa_header TABLES html = t_html fields = t_fields row_header = t_header itable = it_vbap. *-Download the HTML into frontend CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = 'C:\Sales.htm' TABLES data_tab = t_html EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. *-Display the HTML file CALL METHOD cl_gui_frontend_services=>execute EXPORTING document = 'C:\Sales.htm' operation = 'OPEN' EXCEPTIONS cntl_error = 1 error_no_gui = 2 bad_parameter = 3 file_not_found = 4 path_not_found = 5 file_extension_unknown = 6 error_execute_failed = 7 synchronous_failed = 8 not_supported_by_gui = 9 OTHERS = 10. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.
REPORT z_zip_files_in_appsvr . DATA: lt_data TYPE TABLE OF x255, ls_data LIKE LINE OF lt_data. DATA: lv_zip_content TYPE xstring , lv_dsn1(100) VALUE '/sap/NSP/sys/test.as', lv_dsn2(100) VALUE '/sap/NSP/sys/test2.mxml', lv_dsn3(100) VALUE '/sap/NSP/sys/testarchive.zip', lv_file_length TYPE i , lv_content TYPE xstring, lo_zip TYPE REF TO cl_abap_zip. CREATE OBJECT lo_zip. * Read the data as a string CLEAR lv_content . OPEN DATASET lv_dsn1 FOR INPUT IN BINARY MODE. READ DATASET lv_dsn1 INTO lv_content . CLOSE DATASET lv_dsn1. lo_zip->add( name = 'test.as' content = lv_content ). CLEAR lv_content . OPEN DATASET lv_dsn2 FOR INPUT IN BINARY MODE. READ DATASET lv_dsn2 INTO lv_content . CLOSE DATASET lv_dsn2. lo_zip->add( name = 'test2.mxml' content = lv_content ). lv_zip_content = lo_zip->save( ). * Conver the xstring content to binary CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING buffer = lv_zip_content IMPORTING output_length = lv_file_length TABLES binary_tab = lt_data. OPEN DATASET lv_dsn3 FOR OUTPUT IN BINARY MODE. LOOP AT lt_data INTO ls_data. TRANSFER ls_data TO lv_dsn3. ENDLOOP. CLOSE DATASET lv_dsn3.
Initial Author: Xinpeng Lin
Submitted: 11.9.2007
Other Authors: see Page History
This Code Snippets will clarify some general process of working with files when ABAP programming. Such as,Uploading/Downloading files from/to Application/Presentation server, adding F4 help to file path on the selection-screen,checking file existence.
Check File Existence
Before we process the file which is input on the selection screen by end-user, we need to check whether this file exists or not. If it does not exist, we just give an error message and need not to go into the main program .This logic should be done within the event 'AT SELECTION-SCREEN'.
presentation server file
For the presentation server file,here intruduce 2 ways, one is Function Module, the other is Class Static Method.
1. Using Funciton Moudle 'DX_FILE_EXISTENCE_CHECK'.
DATA: gdf_file_exist(1) TYPE c. PARAMETERS p_file TYPE dxfile-filename. AT SELECTION-SCREEN. CALL FUNCTION 'DX_FILE_EXISTENCE_CHECK' EXPORTING filename = p_file pc = 'X' * SERVER = IMPORTING file_exists = gdf_file_exist. IF NOT ( sy-subrc = 0 and gdf_file_exist = 'X' ) MESSAGE 'the input file does not exist.' TYPE 'E'. ENDIF.
Pay attention to the importing parameter 'pc', it should be set as 'X'.
2. Using Class Static Method 'CL_GUI_FRONTEND_SERVICES=>FILE_EXIST'
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'DATA: gdf_file_exist(1) TYPE c. PARAMETERS p_file TYPE dxfile-filename. AT SELECTION-SCREEN. CALL METHOD cl_gui_frontend_services=>file_exist EXPORTING file = p_file RECEIVING result = gdf_file_exist. IF NOT ( sy-subrc = 0 and gdf_file_exist = 'X' ) MESSAGE 'the input file does not exist.' TYPE 'E'. ENDIF.
application server file
Open it first within the event 'AT SELECTION-SCREEN'.If it can be opened successfully, this file exists. After open, do not forget to close it.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'PARAMETERS p_file TYPE dxfile-filename. AT SELECTION-SCREEN. OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT. IF sy-subrc = 0. CLOSE DATASET p_file. ELSE. MESSAGE 'the input file does not exist.' TYPE 'E'. ENDIF.
Function Module 'OCS_GET_FILE_INFO'
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'DATA: gdt_ocs_file TYPE TABLE OF ocs_file. PARAMETERS p_file TYPE dxfile-filename. AT SELECTION-SCREEN. CALL FUNCTION 'OCS_GET_FILE_INFO' EXPORTING dir_name = p_file file_name = '*' TABLES dir_list = gdt_ocs_file.
Importing parameter 'file_name' is set as '*' means all the file in the specfied directory will be get and stored in the internal table 'gdt_ocs_file'. If the input file is included in the internal table, this file exists.
Add F4 Help
Adding one F4 Help to the file path on the selection-screen will be very helpful to the end-user.The logic should be under the event 'ON VALUE-REQUEST'.
presentation server file
For the presentation server file,here intruduce 2 ways, one is Function Module, the other is Class Static Method.
1. Using Function Module 'F4_FILENAME'.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'PARAMETERS p_file TYPE dxfile-filename. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. CALL FUNCTION 'F4_FILENAME' * EXPORTING * PROGRAM_NAME = * DYNPRO_NUMBER = * FIELD_NAME = IMPORTING file_name = p_file.
2. Using Method 'CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG'.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'DATA: gdt_filetable TYPE filetable. DATA: gdf_rc TYPE I. PARAMETERS p_file TYPE dxfile-filename. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. CALL METHOD cl_gui_frontend_services=>file_open_dialog EXPORTING WINDOW_TITLE = 'Choose a file' CHANGING file_table = gdt_filetable rc = gdf_rc. IF sy-subrc = 0. READ TABLE gdt_filetable INTO gds_filetable INDEX 1. p_file = gds_filetable-filename. ENDIF.
gdf_rc is the number of selected file, if it is equal -1, error occured.
application server file
Generally it need not to provide F4 help for application server file. If we want it, there is also a Function Module which can be used.
PARAMETERS p_file TYPE dxfile-filename. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. CALL FUNCTION 'F4_DXFILENAME_4_DYNP' EXPORTING dynpfield_filename = 'P_FILE' dyname = sy-repid dynumb = sy-dynnr filetype = 'P' location = 'A' server = ' '.
filetype: 'P' represents Physical file name; 'L' represents Logical file name.
location: 'A' represents Application Server; 'P' represents Presentation server.
Download Files
Sometimes we need to save the internal table data as a file for the further process.For download to presentation server and download to application server,they are 2 different kinds of process methods.
to presentation server
When storing internal table data as a local file on the presentation server, there are 2 methods we can use.
One is using the function modeule, the other is using the class static method.
1. Using Function Module 'GUI_DOWNLOAD'.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA: gdf_filepath type dxfile-filename DATA: gdt_data type table of gts_data. START-OF-SELECTION. gdf_filepath = 'C:\mydata.txt'. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = gdf_filepath filetype = 'ASC' write_field_separator = 'X' TABLES data_tab = gdt_data.
filetype is set by 'X' mens separating columns by Tabs in case of ASCII download.
If sy-subrc is equal 0, file downloading is successful.
2. Using class static method 'CL_GUI_FRONTEND_SERVICES =>GUI_DOWNLOAD'
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'DATA: gdf_filepath type dxfile-filename DATA: gdt_data type table of gts_data. START-OF-SELECTION. gdf_filepath = 'C:\mydata.txt'. CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING filename = gdf_filepath filetype = 'ASC' write_field_separator = 'X' CHANGING data_tab = gdt_data.
filetype is set by 'X' mens separating columns by Tabs in case of ASCII download.
If sy-subrc is equal 0, file downloading is successful.
to application server
If we want to save the internal table data to the application server, there is no function module or class static method which we can use, we must write the code by ourselves.
1. no separator between field columns
DATA: gdf_filepath type dxfile-filename DATA: gdt_data type table of gts_data. DATA: ldf_length type i. FIELD-SYMBOLS: <lfs_outfile> TYPE gts_data START-OF-SELECTION. gdf_filepath = 'C:\mydata.txt'. OPEN DATASET gdf_filepath FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. LOOP AT prt_data ASSIGNING <lfs_outfile>. TRANSFER <lfs_outfile> TO prf_file. ENDLOOP. CLOSE DATASET gdf_filepath.
The prerequisite is the field of prt_data must be character type.
Using this method, every field column will output as the length defined,without separator.
2. tab separator between field columns
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA: gdf_filepath type dxfile-filename DATA: gdt_data type table of gts_data. DATA: ldf_length type i. FIELD-SYMBOLS: <lfs_outfile> TYPE gts_data START-OF-SELECTION. gdf_filepath = 'C:\mydata.txt'. OPEN DATASET gdf_filepath FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. LOOP AT prt_data ASSIGNING <lfs_outfile>. CONCATENATE <LFS_OUTFILE>-BUKRS <LFS_OUTFILE>-BUDAT ... INTO LDF_OUTDATA SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB. TRANSFER LDF_OUTDATA TO gdf_filepath. ENDLOOP. CLOSE DATASET gdf_filepath.
Upload Files
Sometimes we need to upload the file data to the internal table first, and then process it.For upload from presentation server and upload from application server,they are 2 different kinds of process methods.
from presentation server
When we upload a file data from presentation server to the internal table, there are 2 method that we can choose.One is using the Function Moduel, the other is using the class static method.
1. Using function module 'GUI_UPLOAD'
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'DATA: gdt_filedata TYPE TABLE OF gts_filedata. PARAMETERS p_file TYPE dxfile-filename. START-OF-SELECTION. CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = p_file has_field_separator = 'X' TABLES data_tab = gdt_filedata.
parameter has_field_separator is set as 'X' means columns separated by tabs in case of ASCII upload.
2. Using the method 'CL_GUI_FRONTEND_SERVICES =>GUI_UPLOAD'
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'DATA: gdt_filedata TYPE TABLE OF gts_filedata. PARAMETERS p_file TYPE dxfile-filename. START-OF-SELECTION. CALL METHOD cl_gui_frontend_services=>gui_upload EXPORTING filename = p_file has_field_separator = 'X' CHANGING data_tab = prt_table.
parameter 'has_field_separator' is set as 'X' means columns separated by tabs in case of ASCII upload.
from application server
If we want to upload file data from the application server to the internal table, there is no function module or class static method which we can use, we must wirte the code by ourselves.
1. no separator between field columns
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'PARAMETERS p_file TYPE dxfile-filename. START-OF-SELECTION. OPEN DATASET p_file IN TEXT MODE ENCODING DEFAULT FOR INPUT. DO. READ DATASET p_file INTO gds_data. IF sy-subrc <> 0. EXIT. ENDIF. APPEND gds_data TO gdt_data. ENDDO. CLOSE DATASET p_file.
2. tab separator between field columns
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'DATA: gds_field_split type gts_data. FIELD-SYMBOLS: <fs_field> TYPE gts_data. PARAMETERS p_file TYPE dxfile-filename. START-OF-SELECTION. OPEN DATASET prf_file IN TEXT MODE ENCODING DEFAULT FOR INPUT. DO. READ DATASET p_file INTO gds_field. SPLIT gds_field AT cl_abap_char_utilities=>horizontal_tab INTO TABLE gdt_field_split. LOOP AT gdt_field_split into gds_field_split. gdf_index = gdf_index + 1. ASSIGN COMPONENT gdf_index OF STRUCTURE gds_data to <fs_field>. IF sy-subrc = 0. <fs_field> = gds_field_split. ENDIF. ENDLOOP. APPEND gds_data TO gdt_data. ENDDO. CLOSE DATASET p_file.
This program doesn't do what it announces
DATA fname(60) VALUE 'myfile'. DATA: text1(12) VALUE 'abcdefghijkl', text2(5), leng TYPE i. OPEN DATASET fname FOR OUTPUT IN BINARY MODE. TRANSFER text1 TO fname. CLOSE DATASET fname. OPEN DATASET fname FOR INPUT IN BINARY MODE. DO. READ DATASET fname INTO text2 LENGTH leng. WRITE: / sy-subrc, text2, leng. IF sy-subrc <> 0. EXIT. ENDIF. ENDDO. CLOSE DATASET fname.
DATA fname(60) VALUE 'myfile'. DATA: text1(4) VALUE '1234 ', text2(8) VALUE '12345678', text3(2), leng TYPE i. OPEN DATASET fname FOR OUTPUT IN TEXT MODE. TRANSFER: text1 TO fname, text2 TO fname. CLOSE DATASET fname. OPEN DATASET fname FOR INPUT IN TEXT MODE. DO 2 TIMES. READ DATASET fname INTO text3 LENGTH leng. WRITE: / text3, leng. ENDDO. CLOSE DATASET fname.
Author: Waldemar Schakiel
Submitted: 1st April 2016
Description
Open SQL is integrated in ABAP and permits database-independent data Access. There is another way in ABAP to access the database. This variant is native SQL. This variant plays a greater role than in the past in the context of SAP HANA.
The example shows the use of ADBC classes for a simple read access. The SQL statement uses the expressions from the HANA-SQL dialect that are not available in this form in Open SQL.
Note: "days_between" is a stored procedure.
REPORT z_adbc. TYPES: " Definition of result structure BEGIN OF ty_result, carrid TYPE s_carr_id, connid TYPE s_conn_id, fldate TYPE s_date, days TYPE i, END OF ty_result. DATA: lv_statement TYPE string, lt_result TYPE TABLE OF ty_result, lr_result TYPE REF TO data, lo_conn TYPE REF TO cl_sql_connection, lo_statement TYPE REF TO cl_sql_statement, lo_result_set TYPE REF TO cl_sql_result_set, lx_sql TYPE REF TO cx_sql_exception. " Get data reference GET REFERENCE OF lt_result INTO lr_result. " Native SQL-Statement lv_statement = | SELECT carrid, connid, fldate, | && | days_between(fldate, current_utcdate) as days | && | FROM sflight WHERE mandt = '{ sy-mandt }' and | && | days_between(fldate, current_utcdate) < 10 |. TRY. " Prepare SQL-Connection and SQL-Statement lo_conn = cl_sql_connection=>get_connection( ). lo_statement = lo_conn->create_statement( ). lo_result_set = lo_statement->execute_query( lv_statement ). lo_result_set->set_param_table( lr_result ). " Get result lo_result_set->next_package( ). lo_result_set->close( ). LOOP AT lt_result ASSIGNING FIELD-SYMBOL(<ls_result>). WRITE: / <ls_result>-carrid , <ls_result>-connid , <ls_result>-fldate, <ls_result>-days. ENDLOOP. CATCH cx_sql_exception INTO lx_sql. " Error handling WRITE: lx_sql->get_text( ). ENDTRY.
Author: Waldemar Schakiel
Submitted: 1st April 2016
Related Links:
Description
The SAP NetWeaver AS ABAP can acces in addition to his primary database other databases. This is known as so-called secondary databases or secondary database connections.
Here is a sample how we can use the secondary database Connection in ABAP
" Sample for OPEN-SQL DATA: ls_carrier TYPE scarr. SELECT SINGLE * FROM scarr CONNECTION ( 'SECONDARY' ) INTO ls_carrier WHERE carrid = 'LH'. " Sample for native SQL or ADBC DATA: lo_statement TYPE REF TO cl_sql_statement, lo_result_set TYPE REF TO cl_sql_result_set. TRY. lo_statement = cl_sql_connection=>get_connection( 'SECONDARY' )->create_statement( ). lo_result_set = lo_statement->execute_query( |SELECT SINGLE * FROM scarr WHERE carrid = 'LH' AND mandt = { sy-mandt } | ). ... CATCH cx_sql_exception. " Error handling ENDTRY.
Author: Abhijeet More
Submitted: 05-Jan-2008
Related Links:
- You can find more information about FTP commands on following links
http://www.columbia.edu/acis/eds/data_tools/ftp-man/ftp_com.html
http://tldp.org/LDP/gs/app-ftp/node1.html
- To find more ABAP programs to FTP functionality please refer
https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/4743
https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/5564
This documentation outlines how to implement a solution to copy objects (data files, executable, etc.) from FTP locations. Most of the times it is requirement to access files from ftp server using R/3 system without using XI as middleware. E.g. MDM scenarios includes sending or receiving data files from FTP folder. This can be handled by simple ABAP program without using XI as middleware.
Contents
What is FTP?.3
How to connect to FTP using local machine.3
Copying objects from FTP server using ABAP.3
Connect to FTP server using Function Module 'FTP_CONNECT'3
Move to required directory on FTP server from which you are going to copy file..4
Set destination path on your local machine where you are going to copy files.5
Run the FTP command 'GET filename' to copy file from FTP to your local machine.5
Complete code..5
What is FTP?
- The FTP (File Transfer Protocol) utility program is commonly used for copying files to and from other computers. These computers may be at the same site or at different sites thousands of miles apart. FTP is a general protocol that works on UNIX systems as well as a variety of other (non-UNIX) systems.
How to connect to FTP using local machine
To connect you local machine to FTP, type command mentioned below through run command prompt of your local machine
Ftp machinename/number
where machinename is the full machine name of the remote machine, or machinennumber is the net address of the remote machine.
When you enter your own loginname and password for the remote machine, it returns the prompt
ftp>
and permits you access to your own home directory on the remote machine. You should be able to move around in your own directory and to copy files to and from your local machine using the FTP interface commands given on the following page.
Copying objects from FTP server using ABAP
The program demonstrates the sending files to FTP & fetching data back to presentation system.
For help on FTP commands go through following link.
If you are trying to download file from FTP server to your local machine the steps involved are
1. Connect to FTP server by providing user ID & login
2. Move to required directory on FTP server from which you are going to copy file
3. Set destination path on your local machine where you are going to copy files
4. Run the FTP command 'GET filename' to copy file from FTP to your local machine.
Above steps can be implemented in ABAP using following lines of code
Connect to FTP server using Function Module 'FTP_CONNECT'
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'CALL FUNCTION 'FTP_CONNECT' EXPORTING USER = LV_USER PASSWORD = LV_PWD HOST = 'XXX.XX.XX.XX' ...........(specify machine ip of your FTP ) RFC_DESTINATION = 'SAPFTP' IMPORTING HANDLE = MI_HANDLE EXCEPTIONS NOT_CONNECTED = 1 OTHERS = 2. *Note : Your FTP machine user name (case sensitive)
Note : Your FTP host name (case sensitive)
Pass the user name & password. Make sure to give RFC_Destination as 'SAPFTP' as this is the RFC destination which actually calls the FTP server.
Move to required directory on FTP server from which you are going to copy file
Once you connect to FTP next step is to move to folder where files are located. The FTP command used to perform this task is 'LCD filepath'.
CMD ='/test'.
To execute the command we need to run function module 'FTP_COMMAND' to which we will be passing handle obtained above while opening FTP connection MI_HANDLE.
CALL FUNCTION 'FTP_COMMAND' EXPORTING HANDLE = MI_HANDLE COMMAND = CMD TABLES DATA = MTAB_DATA1 EXCEPTIONS TCPIP_ERROR = 1 COMMAND_ERROR = 2 DATA_ERROR = 3 OTHERS = 4 *Since we need to execute the command again & again we will be creating form routing for that as shown below. PERFORM FTP_COMMAND USING CMD. FORM FTP_COMMAND USING P_CMD. CALL FUNCTION 'FTP_COMMAND' EXPORTING HANDLE = MI_HANDLE COMMAND = P_CMD TABLES DATA = MTAB_DATA EXCEPTIONS TCPIP_ERROR = 1 COMMAND_ERROR = 2 DATA_ERROR = 3 OTHERS = 4. IF SY-SUBRC = 0. LOOP AT MTAB_DATA. WRITE: / MTAB_DATA. ENDLOOP. ELSE. WRITE: / 'Error in FTP Command'. ENDIF. ENDFORM. " ftp_command *Table MTAB_DATA contains command execution information.
Set destination path on your local machine where you are going to copy files
This step involves setting destination path on your local machine where you want to copy files from FTP.FTP command for that is 'lcd d:\ftp'.
CMD = 'lcd d:\ftp'.
PERFORM FTP_COMMAND USING CMD.
Run the FTP command 'GET filename' to copy file from FTP to your local machine.
GET command will copy files from FTP location to local machine.
This completes the process of copying file from FTP to local client. Now using this file content to load the data in R3 I will leave it to you, as we can easily access any data file stored on our desktop or server to run BDC or LSMW.
Please see attached below code for whole scenario.
Complete code
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'&--------------------------------------------------------------------- *& Report ZFTP_CONNECT *& &--------------------------------------------------------------------- REPORT ZFTP_CONNECT. DATA: BEGIN OF MTAB_DATA OCCURS 0, LINE(132) TYPE C, END OF MTAB_DATA. DATA: BEGIN OF MTAB_DATA1 OCCURS 0, LINE(132) TYPE C, END OF MTAB_DATA1. DATA : ERROR TYPE STRING. DATA: MC_PASSWORD(20) TYPE C, ERR(20) TYPE C, MI_KEY TYPE I VALUE 26101957, MI_PWD_LEN TYPE I, MI_HANDLE TYPE I. DATA: MAT TYPE BAPIMATALL. DATA: LV_USER(30) TYPE C, LV_PWD(30) TYPE C , LV_HOST(64) TYPE C, IV_FILE_PATH(20) TYPE C, CMD(120). DATA: LV_DEST TYPE RFCDES-RFCDEST. START-OF-SELECTION. CALL FUNCTION 'FTP_CONNECT' EXPORTING Your SAP-UNIX FTP user name (case sensitive) USER = LV_USER PASSWORD = LV_PWDYour SAP-UNIX server host name (case sensitive) HOST = '172.20.15.73' RFC_DESTINATION = 'SAPFTP' IMPORTING HANDLE = MI_HANDLE EXCEPTIONS NOT_CONNECTED = 1 OTHERS = 2. CHECK SY-SUBRC = 0. CMD = 'cd \Material" "Master'. *--This is sender directory path *--Note down that if there is space in directory name it can be handled by " " *--command cd \Material master will generate error PERFORM FTP_COMMAND USING CMD. CMD = 'ascii'. *--FTP transfers are generally performed in either ASCII or binary mode. Binary mode is the preferred mode to transfer non-text files. ASCII mode is the preferred mode to transfer text files. PERFORM FTP_COMMAND USING CMD. CMD = 'lcd d:\ftp'. "This is target directory path on local machine PERFORM FTP_COMMAND USING CMD. CMD = 'ls'.list all the files available under source folder PERFORM FTP_COMMAND USING CMD.MTAB_DATA contains file names of all files under source folder LOOP AT MTAB_DATA FROM 2. CONCATENATE 'get' MTAB_DATA+39(80) INTO CMD SEPARATED BY SPACE. CALL FUNCTION 'FTP_COMMAND' EXPORTING HANDLE = MI_HANDLE COMMAND = CMD TABLES DATA = MTAB_DATA1 EXCEPTIONS TCPIP_ERROR = 1 COMMAND_ERROR = 2 DATA_ERROR = 3 OTHERS = 4 . IF SY-SUBRC = 0. LOOP AT MTAB_DATA1. WRITE: / MTAB_DATA1. ENDLOOP. ELSE.do some error checking. CONCATENATE 'Error in FTP Command while executing' CMD INTO ERROR SEPARATED BY SPACE. WRITE: / ERROR. ENDIF. CLEAR MTAB_DATA1[].concatenate 'delete' MTAB_DATA+39(80) into cmd separated by SPACE.perform ftp_command using cmd.If you want delete file after copy command you can run delete command ENDLOOP. CLEAR MTAB_DATA[]. *--Disconnect from FTP server CALL FUNCTION 'FTP_DISCONNECT' EXPORTING HANDLE = MI_HANDLE EXCEPTIONS OTHERS = 1. *--Close RFC connection CALL FUNCTION 'RFC_CONNECTION_CLOSE' EXPORTING DESTINATION = 'SAPFTP' EXCEPTIONS OTHERS = 1. &--------------------------------------------------------------------- *& Form ftp_command &--------------------------------------------------------------------- * text ---------------------------------------------------------------------- * -->P_CMD text ---------------------------------------------------------------------- FORM FTP_COMMAND USING P_CMD. CALL FUNCTION 'FTP_COMMAND' EXPORTING HANDLE = MI_HANDLE COMMAND = P_CMD TABLES DATA = MTAB_DATA EXCEPTIONS TCPIP_ERROR = 1 COMMAND_ERROR = 2 DATA_ERROR = 3 OTHERS = 4. IF SY-SUBRC = 0. LOOP AT MTAB_DATA. WRITE: / MTAB_DATA. ENDLOOP. ELSE.do some error checking. WRITE: / 'Error in FTP Command'. ENDIF. IF P_CMD <> 'ls'. CLEAR MTAB_DATA[]. ENDIF. ENDFORM. " ftp_command
After execution program will display log for file transfer
Make a note that any file having space in its name need to be handled by " ".
e.g. Command to copy file Exercise 1.doc will be
GET Exercise" "1.doc
Author: Andrea Olivieri
Supported Releases: SAP ECC 6.0
Submitted: 20 September 2010
Code is presented in below pages:
- Job Steps Analysis - Get Report Name & Variant Name from periodic Scheduled Jobs
- Save Variant Data
- Variant Catalog Creation
General Flow and Pre-requisites
During a spin-off project of an Italian company in the automotive industry, the customer asked me to identify all the programs variants (of scheduled jobs) containing a defined value of company code ( i.e 'A001') in the selection screen.
In previous upgrade projects, basically for target release 4.70, I used a specific ASU tool, the restore variant tool,which allowed me to use the old variants again in the new release.
So I asked myself why should I have to implement a program from scratch if there is a standard one out there that does everything I need ?
So starting from the ASU variant restore tool, I cloned the source code of the following standard programs:
- RASUVCAT: Creates a catalog of all variants
- RASUVSAV: Storage of variant information
Since the goal is to identify job's variants containing the value A001 of the company code, I divided the process in the following operational steps:
- Get the program name and variant name from batch jobs
- Create Variant Catalog (For the specified program names)
- Save the variant Data (only parameters of type BUKRS)
Requirements
Function Groups ASU2,ASU4 as well as the DDIC Tables TASUVCAT, TASUVEXT, TASUVSVD and TASUNSVO should exist in the system
How It Works
1 - Job Steps analysis (Optional)
I focused exclusively on programs scheduled as periodic jobs, so I implemented an additional ABAP program which reads the job definitions of all jobs with the following states:
- Scheduled
- Released
- Finished
After that, from the related steps, gets the following information:
- Job name,
- Program name,
- Variant name
- Package.
The output is a raw list.
Copy and paste the column program name from the output list in the selection screen parameter Report(s) of the Variant Catalog Creation program. The snippet of the job steps analysis program could be found here.
2 - Variant Catalog Creation (Mandatory)
Due to performance reasons, first of all you have to create the variant catalog; it's better to restrict the selection to certain reports. is filled .
As result, after the program update run, the TASUVCAT table.
The variant catalog program works in "Delta Mode"; this means that only the variants that were not taken into account during the previous run are cataloged again. The snippet could be found here.
3 - Save Variant Data
Starting from the variant catalog, the current variant data and attributes are stored in both tables TASUVSVD and TASUVSVO.
The TASUVSVD table contains the variant data and TASUVSVO contains the technical field descriptions (TVARV variables, protected fields, and so on).
The program saves only the values of the parameters related to a data element with domain bukrs. The program checks following condition:
(...) * Get active Data Elemnts for Domain BUKRS select rollname from dd04l into table lt_repository bypassing buffer where domname eq 'BUKRS' and ( refkind eq space or refkind eq 'D' ) and as4local eq 'A'. sort lt_repository. (...) read table lt_repository with key rollname = ls_dfies-rollname transporting no fields. check sy-subrc = 0.
The snippet could be found here.
4 - Get The results
You can get the results immediately by the transaction SE16 (table TASUVSVD)
Create, Schedule and release Job in program
This program is useful for create the transaction variant and run in background processing.
This program will create the transaction variant for a program.
New session will be opened using JOB_OPEN function module.
Program will be submit with variant for background schedule.
REPORT ztest_job_call. DATA : jobname TYPE tbtcjob-jobname VALUE 'ZJOBTEST', jobclass TYPE tbtcjob-jobclass VALUE 'A', jobcount TYPE tbtcjob-jobcount, lv_startdate LIKE sy-datum, lv_starttime LIKE sy-uzeit, authcknam TYPE tbtcjob-authcknam, lv_varname TYPE rsvar-variant, lwa_vardesc TYPE varid . DATA: BEGIN OF gt_varid. INCLUDE STRUCTURE varid. DATA: END OF gt_varid. DATA: BEGIN OF gt_varit OCCURS 2. INCLUDE STRUCTURE varit. DATA: END OF gt_varit. DATA: BEGIN OF gt_rsparams OCCURS 0. INCLUDE STRUCTURE rsparams. DATA: END OF gt_rsparams. authcknam = sy-uname. lv_startdate = sy-datum. lv_starttime = sy-uzeit + 300. CONCATENATE 'ABAP' lv_starttime INTO lv_varname. lwa_vardesc-report = 'ZMMREPT_FUTURE_DELIVERY'. * fill VARID structure - Variantenkatalog, variant description gt_varid-mandt = sy-mandt. gt_varid-report = lwa_vardesc-report. gt_varid-variant = lv_varname. gt_varid-flag1 = space. gt_varid-flag2 = space. gt_varid-transport = space. gt_varid-environmnt = 'A'. "Variant for batch and online gt_varid-protected = space. gt_varid-secu = space. gt_varid-version = '1'. gt_varid-ename = sy-uname. gt_varid-edat = sy-datum. gt_varid-etime = sy-uzeit. gt_varid-aename = space. gt_varid-aedat = space. gt_varid-aetime = space. gt_varid-mlangu = sy-langu. *.fill VARIT structure - Variantentexte; variant texts gt_varit-mandt = sy-mandt. gt_varit-langu = sy-langu. gt_varit-report = lwa_vardesc-report. gt_varit-variant = lv_varname. gt_varit-vtext = lv_varname. APPEND gt_varit. gt_rsparams-selname = 'S_PLNT'. gt_rsparams-kind = 'S'. gt_rsparams-sign = 'I'. gt_rsparams-option = 'EQ'. gt_rsparams-low = '1000'. gt_rsparams-high = '3500'. APPEND gt_rsparams. gt_rsparams-selname = 'S_MTART'. gt_rsparams-kind = 'S'. gt_rsparams-sign = 'I'. gt_rsparams-option = 'EQ'. gt_rsparams-low = 'FERT'. gt_rsparams-high = 'ROH'. APPEND gt_rsparams. gt_rsparams-selname = 'S_DDATE'. gt_rsparams-kind = 'S'. gt_rsparams-sign = 'I'. gt_rsparams-option = 'EQ'. gt_rsparams-low = '12.02.2008'. gt_rsparams-high = sy-datum. APPEND gt_rsparams. * Create Variant CALL FUNCTION 'RS_CREATE_VARIANT' EXPORTING curr_report = gt_varid-report curr_variant = gt_varid-variant vari_desc = gt_varid TABLES vari_contents = gt_rsparams vari_text = gt_varit EXCEPTIONS illegal_report_or_variant = 1 illegal_variantname = 2 not_authorized = 3 not_executed = 4 report_not_existent = 5 report_not_supplied = 6 variant_exists = 7 variant_locked = 8 OTHERS = 9. IF sy-subrc <> 0. ENDIF. CALL FUNCTION 'JOB_OPEN' EXPORTING jobname = jobname jobclass = jobclass IMPORTING jobcount = jobcount EXCEPTIONS cant_create_job = 1 invalid_job_data = 2 jobname_missing = 3 OTHERS = 4. IF sy-subrc = 0. CALL FUNCTION 'JOB_SUBMIT' EXPORTING authcknam = authcknam jobcount = jobcount jobname = jobname report = 'ZMMREPT_FUTURE_DELIVERY' variant = 'VAR' EXCEPTIONS bad_priparams = 1 bad_xpgflags = 2 invalid_jobdata = 3 jobname_missing = 4 job_notex = 5 job_submit_failed = 6 lock_failed = 7 program_missing = 8 prog_abap_and_extpg_set = 9 OTHERS = 10. IF sy-subrc = 0. CALL FUNCTION 'JOB_CLOSE' EXPORTING jobcount = jobcount jobname = jobname sdlstrtdt = lv_startdate sdlstrttm = lv_starttime EXCEPTIONS cant_start_immediate = 1 invalid_startdate = 2 jobname_missing = 3 job_close_failed = 4 job_nosteps = 5 job_notex = 6 lock_failed = 7 invalid_target = 8 OTHERS = 9. IF sy-subrc = 0. CALL FUNCTION 'RS_VARIANT_DELETE' EXPORTING report = gt_varid-report variant = gt_varid-variant flag_confirmscreen = 'X' flag_delallclient = 'X' EXCEPTIONS not_authorized = 1 not_executed = 2 no_report = 3 report_not_existent = 4 report_not_supplied = 5 variant_locked = 6 variant_not_existent = 7 no_corr_insert = 8 variant_protected = 9 OTHERS = 10. IF sy-subrc <> 0. ENDIF. ENDIF. ENDIF. ENDIF.
* program to execute jobs based on packet size for parallel processing. * Data declaration. TYPES: BEGIN OF ty_mara, matnr TYPE mara-matnr, END OF ty_mara. TYPES: BEGIN OF ty_jobs, jobname TYPE tbtcjob-jobname, jobcount TYPE tbtcjob-jobcount, END OF ty_jobs. DATA : gt_mara TYPE STANDARD TABLE OF ty_mara. DATA : gv_process TYPE char10, gv_status TYPE tbtcjob-status. DATA: gv_jobnumber TYPE tbtcjob-jobcount, gv_printparam TYPE pri_params, gv_archparam TYPE arc_params, gv_valid TYPE c, gv_jobname TYPE tbtcjob-jobname, gv_count(2) TYPE c, gv_process1 TYPE char10, gv_bucket_size TYPE i. * Local constants CONSTANTS :gc_jobname TYPE tbtcjob-jobname VALUE 'X', gc_text TYPE syprtxt VALUE 'Y', gc_lines TYPE sylinct VALUE '60', gc_rows TYPE sylinct VALUE '240', gc_diff TYPE c VALUE '-'. * Retrieve the distinct Articles from general article data(MARA) SELECT matnr FROM mara INTO TABLE gt_mara WHERE mstae > 17. DATA : lv_lines TYPE i, lv_start TYPE i, lv_end TYPE i, lv_dummy TYPE f, lv_max TYPE i. * Count the no.of records of internal table GT_MARA DESCRIBE TABLE gt_mara LINES lv_lines. * Get the no of records for each process lv_dummy = lv_lines / gv_bucket_size. lv_max = ceil( lv_dummy ). * Initialize Start & End lv_start = 1. * Check for the no.of records in GT_MARA IF lv_lines < gv_bucket_size. lv_end = lv_lines. ELSE. lv_end = gv_bucket_size. ENDIF. gv_process = 1. gv_fname_item = gv_fname. gv_fname_dunit = gv_fname1. DO. CLEAR gr_matnr_r. * Read internal table GT_MATNR for range LOW value READ TABLE gt_mara INTO gwa_mara INDEX lv_start. * Check for the Read statement IF sy-subrc = 0. gr_matnr_r-low = gwa_mara-matnr. * Read internal table GT_MATNR for range HIGH value READ TABLE gt_mara INTO gwa_mara INDEX lv_end. IF sy-subrc = 0. gr_matnr_r-high = gwa_mara-matnr. CONCATENATE gc_jobname gc_diff gv_process INTO gv_jobname. CONDENSE gv_jobname NO-GAPS. *<<<<<< Print Parameters >>>>>>>> CALL FUNCTION 'GET_PRINT_PARAMETERS' EXPORTING no_dialog = gc_x IMPORTING out_parameters = gv_printparam out_archive_parameters = gv_archparam valid = gv_valid EXCEPTIONS archive_info_not_found = 1 invalid_print_params = 2 invalid_archive_params = 3 OTHERS = 4. IF gv_valid <> space AND sy-subrc = 0. CALL FUNCTION 'GET_PRINT_PARAMETERS' EXPORTING in_archive_parameters = gv_archparam in_parameters = gv_printparam line_count = gc_lines line_size = gc_rows list_text = gc_text no_dialog = gc_x IMPORTING out_parameters = gv_printparam valid = gv_valid EXCEPTIONS archive_info_not_found = 0 invalid_print_params = 0 invalid_archive_params = 0 OTHERS = 0. ENDIF. *<<<<<< Job Open >>>>>>>> CALL FUNCTION 'JOB_OPEN' EXPORTING jobname = gv_jobname IMPORTING jobcount = gv_jobnumber EXCEPTIONS cant_create_job = 1 invalid_job_data = 2 jobname_missing = 3 OTHERS = 4. ENDFORM. "process_job IF sy-subrc = 0. CONCATENATE gv_path gc_slash gv_fname_item gc_underscore sy-datum gc_underscore sy-uzeit gc_underscore gv_process INTO gv_fname. CONDENSE gv_fname NO-GAPS. CONCATENATE gv_path gc_slash gv_fname_dunit gc_underscore sy-datum gc_underscore sy-uzeit gc_underscore gv_process INTO gv_fname1. CONDENSE gv_fname1 NO-GAPS. * for each process SUBMIT 'XY' WITH s_matnr IN gr_matnr_r TO SAP-SPOOL SPOOL PARAMETERS gv_printparam WITHOUT SPOOL DYNPRO VIA JOB gv_jobname NUMBER gv_jobnumber AND RETURN. IF sy-subrc = 0. *<<<<<< Job Close >>>>>>>> CALL FUNCTION 'JOB_CLOSE' EXPORTING jobcount = gv_jobnumber jobname = gv_jobname strtimmed = gc_x EXCEPTIONS cant_start_immediate = 1 invalid_startdate = 2 jobname_missing = 3 job_close_failed = 4 job_nosteps = 5 job_notex = 6 lock_failed = 7 OTHERS = 8. IF sy-subrc = 0. gwa_jobs-jobcount = gv_jobnumber. gwa_jobs-jobname = gv_jobname. APPEND gwa_jobs TO gt_jobs. CLEAR: gwa_jobs. ENDIF. * Incriment the process for each Job gv_process = gv_process + 1. ELSE. EXIT. ENDIF. ELSE. EXIT. ENDIF. * Increment Start lv_start = lv_end + 1. IF lv_start > lv_lines. EXIT. ENDIF. * Increment End lv_end = lv_start + gv_bucket_size - 1. IF lv_end > lv_lines. lv_end = lv_lines. ENDIF. * Check for the processess IF gv_process = lv_max AND lv_end < lv_lines. lv_end = lv_lines. ENDIF. ENDDO. * Construct a do loop * DO p_maxbg TIMES. DO lv_max TIMES. READ TABLE gt_jobs INTO gwa_jobs INDEX 1. IF sy-subrc EQ 0. DO. * retrieve the status for the all jobs from table TBTCO SELECT SINGLE status FROM tbtco INTO gv_status WHERE jobname = gwa_jobs-jobname AND jobcount = gwa_jobs-jobcount. * Check for the select statement IF sy-subrc EQ 0 AND ( gv_status = gc_f OR gv_status = gc_a ). * Delete the entry from internal table gt_jobs DELETE gt_jobs INDEX 1. * Clear local var gv_status and Exit from do loop CLEAR : gv_status. * Exit from do loop EXIT. ELSE. * wait for 3 seconds WAIT UP TO 3 SECONDS. ENDIF. ENDDO. ELSE. EXIT. ENDIF. ENDDO.
Author: Chaitanya Raju
Submitted: Dec. 14 2007
Description: For some background update jobs, you might want to stop the user from submitting the jobs twice.
* Do this checks to prevent the users from submitting the * same background job twice. * * Perform the checks before starting your programs. * * Create a MESSAGE-ID, the program will issue an error message * in the Job logs. TABLES: tbtco. "Job status overview table DATA: t_jobcnt(1) TYPE n, t_sdluname LIKE tbtco-sdluname, t_strtdate LIKE tbtco-strtdate, t_strttime LIKE tbtco-strttime. SELECT * FROM tbtco WHERE jobname = 'ZXXX' AND strtdate = sy-datum AND status = 'R'. t_jobcnt = t_jobcnt + 1. IF t_jobcnt = 1. t_sdluname = tbtco-sdluname. t_strtdate = tbtco-strtdate. t_strttime = tbtco-strttime. ENDIF. ENDSELECT. IF sy-subrc = 0. IF t_jobcnt < 1. MESSAGE e899 WITH t_sdluname 'have execute the program on' t_strtdate t_strttime. ENDIF. ENDIF.
Author: Sujeet Mishra
Submitted: 12/08/2013
Description: This program is to Check Background Jobs are Scheduled Correctly or Not??
Note : Program has not any maintained Text Element, so please Maintain text instead of Hard coding it as in below Program, This Program is just a sample template for Reference.
REPORT ZBASIS_BACKJOB TABLES: TBTCP, TBTCO, T000, VARID. DATA: FOUND(1) VALUE SPACE, STATEMENT(120), VALUE(20), ULOCK, UEXIST, DAYS TYPE I. DATA: BEGIN OF I_REPS OCCURS 4, NAME LIKE TBTCP-PROGNAME, DESC(60), END OF I_REPS. DATA: VVAL LIKE RSPARAMS OCCURS 4 WITH HEADER LINE. DATA: VTXT LIKE RSVSELTEXT OCCURS 4 WITH HEADER LINE. DATA: numb TYPE I VALUE 0. DATA: RCODE LIKE SY-SUBRC. DATA: BEGIN OF I_JOBS OCCURS 4, NAME LIKE TBTCO-JOBNAME, REPO LIKE TBTCP-PROGNAME, DATE LIKE TBTCO-STRTDATE, TIME LIKE TBTCO-STRTTIME, MINS LIKE TBTCO-PRDMINS, HOUR LIKE TBTCO-PRDHOURS, DAYS LIKE TBTCO-PRDDAYS, WEEK LIKE TBTCO-PRDWEEKS, MONT LIKE TBTCO-PRDMONTHS, PERI LIKE TBTCO-PERIODIC, VARI LIKE TBTCP-VARIANT, USER LIKE TBTCP-AUTHCKNAM, MAND LIKE TBTCO-AUTHCKMAN, END OF I_JOBS. DATA: I_JOBS_WA LIKE I_JOBS. *Below Jobs are some standard jobs which needs to be run everyday. I_REPS-DESC = 'Delete old spool requests (old) OSS 48400, 16083'. I_REPS-NAME = 'RSPO0041'. APPEND I_REPS. I_REPS-DESC = 'Deletes old job logs'. I_REPS-NAME = 'RSBTCDEL'.APPEND I_REPS. I_REPS-DESC = 'Delete old spool requests (new) OSS 48400, 130978'. I_REPS-NAME = 'RSPO1041'. APPEND I_REPS. I_REPS-DESC = 'Spool consistency check display (old) OSS 48400'. I_REPS-NAME = 'RSPO0043'. APPEND I_REPS. I_REPS-DESC = 'Spool consistency check (new) OSS 48400'. I_REPS-NAME = 'RSPO1043'. APPEND I_REPS. I_REPS-DESC = 'Reorganize batch input logs OSS 16083, 147354'. I_REPS-NAME = 'RSBDCREO'. APPEND I_REPS. I_REPS-DESC = 'Delete old ABAP shortdumps OSS 16803, 126974'. I_REPS-NAME = 'RSSNAPDL'. APPEND I_REPS. I_REPS-DESC = 'Delete old Job statistics OSS 16803'. I_REPS-NAME = 'RSBPSTDE'. APPEND I_REPS. I_REPS-DESC = 'Collector for performance monitor OSS 127642'. I_REPS-NAME = 'RSCOLL00'. APPEND I_REPS. I_REPS-DESC = 'Collector for Job-statistics OSS 16083'. I_REPS-NAME = 'RSBPCOLL'. APPEND I_REPS. I_REPS-DESC = 'Generates or updates WBO indices OSS 18023'. I_REPS-NAME = 'SAPRSEUT'. APPEND I_REPS. I_REPS-DESC = 'Reorganizes WBO indices OSS 18023'. I_REPS-NAME = 'SAPRSLOG'. APPEND I_REPS. I_REPS-DESC = 'Deletes outdated print parameters OSS 307970 16083'. I_REPS-NAME = 'RSBTCPRIDEL'. APPEND I_REPS. I_REPS-DESC = 'Reorganizes table TXMILOGRAW OSS 16083, 182963'. I_REPS-NAME = 'RSXMILOGREORG'. APPEND I_REPS. I_REPS-DESC = 'Needed to start tools & methods Alert Mon. OSS 16083'. I_REPS-NAME = 'RSAL_BATCH_TOOL_DISPATCHING'. APPEND I_REPS. I_REPS-DESC = 'Reorganizes update records OSS 16083, 67014'. I_REPS-NAME = 'RSM13002'. APPEND I_REPS. \*---\- Select last runs \---------------------------------------\- LOOP AT I_REPS. EXEC SQL PERFORMING APPEND_JOBS. SELECT A.JOBNAME , B.PROGNAME , A.STRTDATE , A.STRTTIME , A.PRDMINS , A.PRDHOURS , A.PRDDAYS , A.PRDWEEKS , A.PRDMONTHS , A.PERIODIC , B.VARIANT , B.AUTHCKNAM , A.AUTHCKMAN INTO :I_JOBS_WA FROM TBTCO A , TBTCP B WHERE A.JOBNAME = B.JOBNAME AND A.JOBCOUNT = B.JOBCOUNT AND B.PROGNAME = :I_REPS-NAME AND A.STRTDATE = ( SELECT MAX(A_INNER.STRTDATE) FROM TBTCO A_INNER , TBTCP B_INNER WHERE A_INNER.JOBNAME = B_INNER.JOBNAME AND A_INNER.JOBCOUNT = B_INNER.JOBCOUNT AND B_INNER.PROGNAME = :I_REPS-NAME AND A_INNER.JOBNAME = A.JOBNAME ) ENDEXEC. ENDLOOP. SORT I_JOBS BY NAME REPO DATE TIME DESCENDING. DELETE ADJACENT DUPLICATES FROM I_JOBS COMPARING NAME REPO DATE. SORT I_JOBS BY REPO DATE. SORT I_REPS BY NAME. \*----\- Display \------------------------------------------------\- LOOP AT I_REPS. ADD 1 TO numb. FOUND = SPACE. WRITE:/ '========================================================='. WRITE:/ numb, ' Program : ', I_REPS-NAME. WRITE:/ '========================================================='. LOOP AT I_JOBS. IF I_JOBS-REPO = I_REPS-NAME. FOUND = 'X'. WRITE:/ '---------------------------------------------------------'. WRITE:/ 'Jobname :', I_JOBS-NAME. WRITE:/ 'Description :', I_REPS-DESC. WRITE:/ 'Last run :'. days = sy-datum - i_jobs-date. IF days > 31. WRITE: 'No last run info found for this job'. ELSE. WRITE: I_JOBS-DATE. ENDIF. WRITE:/ 'at :', I_JOBS-TIME. WRITE:/ 'User :', I_JOBS-USER. CALL FUNCTION 'USER_EXISTS' EXPORTING BNAME = I_JOBS-USER CLIENT = I_JOBS-MAND IMPORTING LOCKED = ULOCK EXCEPTIONS USER_DONT_EXIST = 1 USER_EXISTS = 2 OTHERS = 3 . IF SY-SUBRC <> 2. WRITE: '( does not exist \!\! )'. UEXIST = 'X'. ENDIF. IF ULOCK NE SPACE. WRITE: '( is locked \!\! )'. ENDIF. WRITE:/ 'Type :'. CASE I_JOBS-REPO. WHEN 'RSBTCDEL'. WRITE: 'Client-independent (if',i_jobs-user. WRITE: 'has S_BTCH_ADM=Y)'. WHEN 'RSPO1041' OR 'RSPO0041'. WRITE: 'Client-independent (if client = "*" in variant)'. WHEN 'RSPO1043' OR 'RSPO1043'. WRITE: 'Client-dependent due to bug, OSS Note 375964.'. WHEN 'RSBDCREO'. WRITE: 'Client-dependent'. WHEN 'RSSNAPDL'. WRITE: 'Client-independent'. WHEN 'RSBPSTDE'. WRITE: 'Client-independent'. WHEN 'RSCOLL00'. WRITE: 'Client-independent'. WHEN 'RSBPCOLL'. WRITE: 'Client-independent'. WHEN 'SAPRSEUT'. WRITE: 'Client-independent'. WHEN 'SAPRSLOG'. WRITE: 'C