0% found this document useful (0 votes)
201 views13 pages

Methods ZPO - BO905

This document describes the implementation of an object type for a purchase order (ZPO_BO905) in ABAP. It includes the object's data definition and several methods for common tasks like displaying the purchase order, getting approver email addresses, updating the purchase order status, getting reminder dates, selecting approvers, and sending reminder emails. The methods access backend systems and use transactions to complete their processing.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
201 views13 pages

Methods ZPO - BO905

This document describes the implementation of an object type for a purchase order (ZPO_BO905) in ABAP. It includes the object's data definition and several methods for common tasks like displaying the purchase order, getting approver email addresses, updating the purchase order status, getting reminder dates, selecting approvers, and sending reminder emails. The methods access backend systems and use transactions to complete their processing.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

*****

Implementation of object type ZPO_BO905

*****

INCLUDE <OBJECT>. BEGIN_DATA OBJECT. " Do not change.. DATA is generated * only private members may be inserted into structure private DATA: " begin of private, " to declare private attributes remove comments and " insert private attributes here ... " end of private, BEGIN OF KEY, EBELN LIKE EKKO-EBELN, END OF KEY, NAME1 TYPE LFA1-NAME1, _EKKO LIKE EKKO. END_DATA OBJECT. " Do not change.. DATA is generated

BEGIN_METHOD DISPLAY_DOCUMENT CHANGING CONTAINER.

*Business logic *Set the document number in first screen SET PARAMETER ID 'BES' FIELD OBJECT-KEY-EBELN.

*Display PO CALL TRANSACTION 'ME23' AND SKIP FIRST SCREEN.

END_METHOD.

BEGIN_METHOD GET_OUTLOOK_EMAIL CHANGING CONTAINER. *1.Data declaration DATA: APPROVER TYPE WFSYST-AGENT, MANAGER TYPE WFSYST-AGENT, EMAIL_MANAGER TYPE SZA5_D0700-SMTP_ADDR, EMAIL_APPROVER TYPE SZA5_D0700-SMTP_ADDR. *2.Get IMPORT Parameters SWC_GET_ELEMENT CONTAINER 'APPROVER' APPROVER. SWC_GET_ELEMENT CONTAINER 'MANAGER' MANAGER. *3.Business logic *Remove prefix 'US' from user ids APPROVER = APPROVER+2(12). MANAGER = MANAGER+2(12). CALL FUNCTION 'EFG_GEN_GET_USER_EMAIL' EXPORTING I_UNAME IMPORTING E_EMAIL_ADDRESS = EMAIL_APPROVER. = APPROVER

CALL FUNCTION 'EFG_GEN_GET_USER_EMAIL' EXPORTING I_UNAME IMPORTING E_EMAIL_ADDRESS = EMAIL_MANAGER. = MANAGER

*4.Set EXPORT Parameters

SWC_SET_ELEMENT CONTAINER 'EMAIL_MANAGER' EMAIL_MANAGER. SWC_SET_ELEMENT CONTAINER 'EMAIL_APPROVER' EMAIL_APPROVER. END_METHOD.

BEGIN_METHOD UPDATE_DOCUMENT CHANGING CONTAINER.

*BDC Recording to update fields in a CHANGE(ME22) transaction *OR *Call BAPI to update PO Status *OR UPDATE EKKO SET STATU = 'A' WHERE EBELN = OBJECT-KEY-EBELN.

END_METHOD.

BEGIN_METHOD GET_REMINDERS CHANGING CONTAINER. *Data declaration DATA: DATE_REM TYPE SYST-DATUM, TIME_REM TYPE SYST-UZEIT, duration type c. *Business logic DO 3 TIMES.

*set the duration if sy-index = '1'. duration = '2'. elseif sy-index = '2'. duration = '4'. elseif sy-index = '3'. duration = '6'. endif. *get next working date using DURATION CALL FUNCTION 'END_TIME_DETERMINE' EXPORTING DURATION * UNIT = duration "2 OR 4 OR 6 = by default in days-TAG, Week-WCH, Minutes-MIN

FACTORY_CALENDAR = '01' "Germany Standard factory Calendar-SCAL IMPORTING END_DATE END_TIME CHANGING START_DATE START_TIME = SY-DATUM "start date = SY-UZEIT. "Start time = DATE_REM "Calculated Reminder Date = TIME_REM "Calculated Reminder time

*Set EXPORT Parameters IF SY-INDEX = 1. SWC_SET_ELEMENT CONTAINER 'DATE_REM1' DATE_REM.

ELSEIF SY-INDEX = 2. SWC_SET_ELEMENT CONTAINER 'DATE_REM2' DATE_REM.

ELSEIF SY-INDEX = 3.

SWC_SET_ELEMENT CONTAINER 'TIME_REM' TIME_REM. SWC_SET_ELEMENT CONTAINER 'DATE_REM3' DATE_REM. ENDIF. ENDDO. END_METHOD.

BEGIN_METHOD GET_APPROVERS CHANGING CONTAINER. *data declaration DATA: APPROVER TYPE WFSYST-AGENT, MANAGER TYPE WFSYST-AGENT, I_APPRL_MATRIX TYPE STANDARD TABLE OF ZAPPRL_MATRIX WITH HEADER LINE, i_return_tab type standard table of DDSHRETVAL with header line. *Business logic *Access Approvers and Managers from database table SELECT * FROM ZAPPRL_MATRIX INTO TABLE I_APPRL_MATRIX. *Display listbox for Approver selection CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING RETFIELD DYNPPROG DYNPNR VALUE_ORG TABLES = 'APPROVER' "Column value to be returned = SY-REPID "Program name = SY-DYNNR "Screen Number = 'S' "Structural display

VALUE_TAB RETURN_TAB

= I_APPRL_MATRIX "Data Internal table = I_RETURN_TAB. "Return Internal table

*Check the APPROVER(I_RETURN_TAB-FIELDVAL) selected READ TABLE I_RETURN_TAB INDEX 1. *Get his manager READ TABLE I_APPRL_MATRIX with key APPROVER = I_RETURN_TAB-FIELDVAL. *Prefix US to user ids Concatenate 'US' I_APPRL_MATRIX-APPROVER INTO I_APPRL_MATRIX-APPROVER. Concatenate 'US' I_APPRL_MATRIX-MANAGER INTO I_APPRL_MATRIX-MANAGER. *set export parameters SWC_SET_ELEMENT CONTAINER 'APPROVER' I_APPRL_MATRIX-APPROVER. SWC_SET_ELEMENT CONTAINER 'MANAGER' I_APPRL_MATRIX-MANAGER. END_METHOD.

BEGIN_METHOD SEND_OUTLOOK_EMAIL CHANGING CONTAINER. *DATA DECLARATIONS DATA: EMAIL_APPROVER TYPE SZA5_D0700-SMTP_ADDR, REM_LEVEL TYPE SYST-INPUT, EMAIL_MANAGER TYPE SZA5_D0700-SMTP_ADDR. *GET IMPORT PARAMETERS SWC_GET_ELEMENT CONTAINER 'EMAIL_APPROVER' EMAIL_APPROVER. SWC_GET_ELEMENT CONTAINER 'REM_LEVEL' REM_LEVEL.

SWC_GET_ELEMENT CONTAINER 'EMAIL_MANAGER' EMAIL_MANAGER. *---------------------------------------------------------*Business logic: *---------------------------------------------------------*1. Prepare Email Subject Data psubject(100). concatenate 'WF905: Reminder' REM_LEVEL ':PO Approval Request:' OBJECT-KEY-EBELN into psubject separated by space.

*2. Fill Control Information DATA gd_doc_data LIKE sodocchgi1. gd_doc_data-obj_name = 'SAPRPT'. gd_doc_data-obj_descr = psubject. gd_doc_data-obj_langu = sy-langu. * "Confidential P,functional F, Standard 0 gd_doc_data-sensitivty = 'F'. gd_doc_data-doc_size = 1.

*3.Specify Recepient Email IDs data:it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE. it_receivers-receiver = EMAIL_APPROVER. *Receiver Type *U -> Internet Address *B -> SAP User *R -> SAP User in another SAP System

*A -> External Address *F -> Fax Number *L -> Telex Number *H -> Organizational unit/Position *K -> Pager/SMS it_receivers-rec_type = 'U'. *Transmission Method:Fax TELFAX, Telex TELEX, SAPoffice internal INT it_receivers-com_type = 'INT'.

*Acknowledgment of receipt expected it_receivers-notif_del = 'X'. APPEND it_receivers.

* Give the Email Of MANAGER for 2nd and 3rd Reminders only if REM_LEVEL > 1. CLEAR it_receivers. it_receivers-receiver = EMAIL_Manager. it_receivers-rec_type = 'U'. it_receivers-com_type = 'INT'. *Send: As copy / blindcopy it_receivers-copy = 'X'. * it_receivers-blindcopy = 'X'. APPEND it_receivers. endif.

*4. Prepare Email body text *Data formating data : V_REM(3) , v_rdays(15). if REM_LEVEL = 1. v_rem = '1st'. v_rdays = '4 working days'. elseif rem_level = 2. v_rem = '2nd'. v_rdays = '2 working days'. elseif REM_LEVEL = 3. v_rem = '3rd'. v_rdays = ''. endif.

*Paragraph 1 : Line 1 -Max 255 characters DATA: it_message TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE. data v_text(255). concatenate 'Purchase Order' object-key-EBELN 'is blocked for processing' into v_text separated by space. APPEND v_text TO it_message. *Paragraph 2 / line 2-----------------------------------concatenate 'This is the' v_rem 'reminder email to a workflow mail sent to you as the' 'Purchase Order Approver.' 'Unfortunately we have not received your answer yet and the '

'referenced Purchase Order cannot be processed.' into v_text separated by space. APPEND v_text TO it_message.

*Paragraph 3 / line 3-----------------------------------if rem_level le 2. concatenate 'After' v_rdays 'this work item will be removed from your workflow' 'inbox and forwarded to your manager' into v_text separated by space. APPEND v_text TO it_message. else. concatenate 'work item is ALREADY removed from your workflow inbox and' 'forwarded to your manager FOR ESCALATION' into v_text separated by space. APPEND v_text TO it_message. endif. *Call function to generate an email IF NOT IT_RECEIVERS[] IS INITIAL. CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1' EXPORTING DOCUMENT_DATA PUT_IN_OUTBOX COMMIT_WORK TABLES = gd_doc_data "2.Control Data + 1.Subject = 'X' = 'X'

OBJECT_CONTENT RECEIVERS IF SY-SUBRC <> 0. ENDIF. ENDIF. END_METHOD.

= it_message

"4.Message Body text

= it_receivers. "3.Email IDs

TABLES EKKO. * GET_TABLE_PROPERTY EKKO. DATA SUBRC LIKE SY-SUBRC. * Fill TABLES EKKO to enable Object Manager Access to Table Properties PERFORM SELECT_TABLE_EKKO USING SUBRC. IF SUBRC NE 0. EXIT_OBJECT_NOT_FOUND. ENDIF. END_PROPERTY. * * Use Form also for other(virtual) Properties to fill TABLES EKKO FORM SELECT_TABLE_EKKO USING SUBRC LIKE SY-SUBRC. * Select single * from EKKO, if OBJECT-_EKKO is initial IF OBJECT-_EKKO-MANDT IS INITIAL AND OBJECT-_EKKO-EBELN IS INITIAL. SELECT SINGLE * FROM EKKO CLIENT SPECIFIED WHERE MANDT = SY-MANDT

AND EBELN = OBJECT-KEY-EBELN. SUBRC = SY-SUBRC. IF SUBRC NE 0. EXIT. ENDIF. OBJECT-_EKKO = EKKO. ELSE. SUBRC = 0. EKKO = OBJECT-_EKKO. ENDIF. ENDFORM.

GET_PROPERTY NAME1 CHANGING CONTAINER. *Business logic SELECT SINGLE NAME1 INTO OBJECT-NAME1 FROM LFA1 WHERE LIFNR = OBJECT-_EKKO-LIFNR.

SWC_SET_ELEMENT CONTAINER 'NAME1' OBJECT-NAME1. END_PROPERTY.

You might also like