Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
raja_thangamani
Active Contributor
*UPDATE: *Type definition updated. 

*Introduction:-* Your Business Workplace on Web!!!. This weblog will explain you how to trigger the Workflow and Execute (Decision making) the Workitem from Web using BSP Application. Also you can play around with Workitem with various options like Reserve/Re-submit/Reset etc... *Scenario:-* I took simple scenario to let everyone understand. Applying leave request from web, Applicant will get the initial notification and Manager will get an Workitem to "Approve"/"Reject" the Leave request. As soon as the decision is taken from Manager, applicant will be informed regarding the status. Note: This blog is not intended to explain Workflow concepts. *Highlights: - *Let's look at the roadmap before we start.

  1. A Quick view of Workflow, which I used.
  2. Development of Leave request BSP application - To apply a leave. Also this will send the initial notification to applicant and submit the request for approval in the form of workitem in Manager's (as set in Workflow) Inbox.
  3. Result-1: - Notification in applicant inbox and Workitem in Manager's Inbox.
  4. Development of Web Business Workplace where your Manager can look at all the Workitems & carry out the necessary actions (decision making).
  5. Configuration involved to link your Workflow Task & BSP Application to make it more dynamic.
  6. Result-2: - View all the responsible Workitems and select one of the item to carry out the decision making.
Before we start our steps, lets look at the Workflow, which we are going to use.
  1. Workflow used.




  2. Let's start with simple task...
  3. *Development of Leave request application *Create the BSP Application called *YMY_LEAVE*.*Page attribute:*0.1. 0.2. *OnInputProcessing:* * event handler for checking and processing user input and * for defining navigation * Container Set Element DEFINE SWC_SET_ELEMENT. CALL FUNCTION 'SWC_ELEMENT_SET' EXPORTING ELEMENT = &2 FIELD = &3 TABLES CONTAINER = &1 EXCEPTIONS OTHERS = 1. END-OF-DEFINITION. DATA : IT_CONTAINER TYPE TABLE OF SWCONT, WF_ID TYPE SWWWIHEAD-WI_ID. DATA: FIELDS TYPE TIHTTPNVP, DB_START TYPE SYDATUM, DB_END TYPE SYDATUM, WA_FIELDS LIKE LINE OF FIELDS. DATA EVENT TYPE REF TO CL_HTMLB_EVENT. EVENT ?= CL_HTMLB_MANAGER=>GET_EVENT_EX( REQUEST ). IF NOT EVENT IS INITIAL. IF EVENT->SERVER_EVENT EQ 'myLeave'. CALL METHOD REQUEST->GET_FORM_FIELDS CHANGING FIELDS = FIELDS. READ TABLE FIELDS INTO WA_FIELDS WITH KEY NAME = 'start_date'. IF SY-SUBRC EQ 0. START_DATE = WA_FIELDS-VALUE. CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL' EXPORTING DATE_EXTERNAL = START_DATE IMPORTING DATE_INTERNAL = DB_START EXCEPTIONS DATE_EXTERNAL_IS_INVALID = 1 OTHERS = 2. ENDIF. READ TABLE FIELDS INTO WA_FIELDS WITH KEY NAME = 'end_date'. IF SY-SUBRC EQ 0. END_DATE = WA_FIELDS-VALUE. CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL' EXPORTING DATE_EXTERNAL = END_DATE IMPORTING DATE_INTERNAL = DB_END EXCEPTIONS DATE_EXTERNAL_IS_INVALID = 1 OTHERS = 2. ENDIF. READ TABLE FIELDS INTO WA_FIELDS WITH KEY NAME = 'reason'. IF SY-SUBRC EQ 0. REASON = WA_FIELDS-VALUE. ENDIF. * Set the data into Workflow container SWC_SET_ELEMENT IT_CONTAINER 'start_date' DB_START. SWC_SET_ELEMENT IT_CONTAINER 'end_date' DB_END. SWC_SET_ELEMENT IT_CONTAINER 'reason' REASON. * Start the Workflow CALL FUNCTION 'EWW_WORKFLOW_START' EXPORTING X_TASK = 'WS90200031' IMPORTING Y_WORKFLOW_ID = WF_ID TABLES X_CONTAINER = IT_CONTAINER EXCEPTIONS INVALID_TASK = 1 NO_ACTIVE_PLVAR = 2 START_FAILED = 3 GENERAL_ERROR = 4 OTHERS = 5. IF SY-SUBRC = 0. COMMIT WORK. NAVIGATION->GOTO_PAGE( 'result.htm' ). ELSE. V_MESSAGE = 'Your Leave Request is not posted into System, Try again later...'. ENDIF. ENDIF. ENDIF. 0.1. Create the *result.htm* page to display the results with following Layout.*OnInputProcessing:-* DATA EVENT TYPE REF TO CL_HTMLB_EVENT.EVENT ?= CL_HTMLB_MANAGER=>GET_EVENT_EX( REQUEST ).IF NOT EVENT IS INITIAL. IF EVENT->SERVER_EVENT EQ 'back'. NAVIGATION->GOTO_PAGE( 'Apply_Leave.htm' ). ENDIF.ENDIF. 0.1. 0.2. Let's look at the outcome of the Step-1. 0.1. Execute the BSP Application YMY_LEAVE and enter the data as follows: 0.2. 0.3. Click on Submit button: 0.4. 0.5. Let me look at my Business workplace (Tcode: SBWP), I must have received a notification mail in my Inbox. 0.6. 0.7. Let me login into my approver's Inbox; must have got the workitem as follows: 0.8. 0.9. Select the workitem & Click on execute button to look at the workitem details. 0.10. 0.11. Now the challenging part is how we are going to achieve Decision steps of workflow on web. I would like to make this process *dynamically* so that it will work for any workitems, not only for Leave request workflow. 0.1. 0.2. *Development of web workplace* 0.1. Develop a BSP Application called YWORKPLACE where you can see & execute all the workitems. 0.2. 0.1. Create a page called *main.htm* *Note:* This page will show all the workitems from Inbox and Re-submission folder with options to Execute/Reserve/Re-submit/Reset etc. 0.1. Make the page as "Stateful" 0.2. 0.3. *Layout*:*Page attributes:*0.1. 0.2. *Type Definition:* * types: t_swr_wihdr type table of swr_wihdr.types: begin of uwl_line, wi_text type witext, statustext type sww_statxt, wi_cd type sww_cd, wi_rhtext type sww_rhtext, wi_stat type sww_wistat, wi_id type sww_wiid, wi_rh_task type sww_task, end of uwl_line.types: uwl type table of uwl_line.types: begin of mail_line, subject type SO_OBJ_DES, OBJTP type SO_OBJ_TP, OBJYR type SO_OBJ_YR, OBJNO type SO_OBJ_NO, end of mail_line.types: mail type table of mail_line.types: t_swfvtv type table of swfvtv.types: tvc type table of tableviewcontrol. 0.1. *OnInitialization:* * event handler for data retrieval DATA: USERNAME TYPE SY-UNAME, ERROR TYPE BAPIRET2_T, ADDR TYPE BAPIADDR3. DATA: STATUS_FILTER TYPE SWRTSTATUS. CONSTANTS: WAITING TYPE CHAR12 VALUE 'WAITING'. USERNAME = SY-UNAME. CALL FUNCTION 'BAPI_USER_GET_DETAIL' EXPORTING USERNAME = USERNAME IMPORTING ADDRESS = ADDR TABLES RETURN = ERROR. CONCATENATE ADDR-LASTNAME ADDR-FIRSTNAME INTO V_NAME SEPARATED BY SPACE. CONCATENATE 'Workitems for' V_NAME INTO HEADER SEPARATED BY SPACE. * Select the customizing for visulization of the workflow tasks REFRESH: I_SWFVTV. SELECT * FROM SWFVTV INTO TABLE I_SWFVTV WHERE VTYP EQ 'BSP_STD'. * Add status waiting if submission is selected IF RE_SUB IS NOT INITIAL. APPEND WAITING TO STATUS_FILTER. ENDIF. * Select workitems for user REFRESH: WORKLIST, I_WORKITEM. CLEAR: WORKLINE, WA_WORKITEM. CALL FUNCTION 'SAP_WAPI_CREATE_WORKLIST' EXPORTING USER = USERNAME READ_TASK_TEXT = 'X' IM_STATUS_FILTER = STATUS_FILTER TABLES WORKLIST = WORKLIST. * Match Workitems wit customizing LOOP AT WORKLIST INTO WORKLINE. READ TABLE I_SWFVTV INTO I_SWFVTV_LINE WITH KEY TASK = WORKLINE-WI_RH_TASK. IF SY-SUBRC EQ 0. MOVE-CORRESPONDING WORKLINE TO WA_WORKITEM. APPEND WA_WORKITEM TO I_WORKITEM. CLEAR WA_WORKITEM. ENDIF. ENDLOOP. 0.1. *OnInputProcessing:* * event handler for checking and processing user input and * for defining navigation DATA: EVENT TYPE REF TO CL_HTMLB_EVENT. DATA: TABLEVIEW_EVENT TYPE REF TO CL_HTMLB_EVENT_TABLEVIEW. * Default values CONSTANTS: NEW_WINDOW TYPE XFELD VALUE 'X', "Open new window = Yes READY TYPE CHAR12 VALUE 'READY', "Status ready WAITING TYPE CHAR12 VALUE 'WAITING'. "Status waiting CLEAR: URL, I_SWFVTV_LINE, OPEN_WINDOW. * Get event of process EVENT = CL_HTMLB_MANAGER=>GET_EVENT( RUNTIME->SERVER->REQUEST ). * Select appropriate action IF EVENT IS NOT INITIAL. CASE EVENT->ID. WHEN 'worklist'. * If an entry in the workitemlist is selected TABLEVIEW_EVENT ?= EVENT. * The data of the selected row is read into wa_workitem IF NOT TABLEVIEW_EVENT->ROW_INDEX EQ SEL_ROW. CLEAR: WA_WORKITEM, SEL_ROW. SEL_ROW = TABLEVIEW_EVENT->ROW_INDEX. READ TABLE I_WORKITEM INTO WA_WORKITEM INDEX SEL_ROW. ELSE. CLEAR: WA_WORKITEM, SEL_ROW. ENDIF. WHEN 'execute'. IF RE_SUB IS INITIAL. * Select URL from customizing READ TABLE I_SWFVTV INTO I_SWFVTV_LINE WITH KEY TASK = WA_WORKITEM-WI_RH_TASK VTYP = 'BSP_STD' VPAR = 'APPLICATION'. IF SY-SUBRC EQ 0. * Prepare URL of BSP page to process work item task (*.htm) CONCATENATE I_SWFVTV_LINE-VVAL '?workitem_id=' WA_WORKITEM-WI_ID INTO URL. * Set work item to reserved CALL FUNCTION 'SAP_WAPI_RESERVE_WORKITEM' EXPORTING WORKITEM_ID = WA_WORKITEM-WI_ID. CLEAR: I_SWFVTV_LINE, OPEN_WINDOW. * Selects settings for workitem task for new window READ TABLE I_SWFVTV INTO I_SWFVTV_LINE WITH KEY TASK = WA_WORKITEM-WI_RH_TASK VTYP = 'BSP_STD' VPAR = 'OPEN_WINDOW'. IF SY-SUBRC NE 0 OR I_SWFVTV_LINE-VVAL IS INITIAL. * If no new window is selected, call URL directly NAVIGATION->GOTO_PAGE( URL = URL ). ELSE. MOVE I_SWFVTV_LINE-VVAL TO OPEN_WINDOW. ENDIF. CLEAR I_SWFVTV_LINE. ENDIF. ENDIF. WHEN 'work_rebox'. * Set conrols for page display IF RE_SUB IS INITIAL. RE_SUB = 'X'. ELSE. CLEAR RE_SUB. ENDIF. WHEN 'submission'. IF RE_SUB IS INITIAL. * Set status of work item to waiting CALL FUNCTION 'SAP_WAPI_SET_WORKITEM_STATUS' EXPORTING WORKITEM_ID = WA_WORKITEM-WI_ID STATUS = WAITING. ELSE. * Set status of work item to ready CALL FUNCTION 'SAP_WAPI_SET_WORKITEM_STATUS' EXPORTING WORKITEM_ID = WA_WORKITEM-WI_ID STATUS = READY. * Set status of work item to reserved CALL FUNCTION 'SAP_WAPI_RESERVE_WORKITEM' EXPORTING WORKITEM_ID = WA_WORKITEM-WI_ID. ENDIF. WHEN 'reset'. * If button 'Reset' is pressed IF NOT WA_WORKITEM-WI_STAT EQ WAITING. * Set status of work item to ready (if work item was reserved) CALL FUNCTION 'SAP_WAPI_SET_WORKITEM_STATUS' EXPORTING WORKITEM_ID = WA_WORKITEM-WI_ID STATUS = READY. ENDIF. WHEN 'reserve'. * SET STATUS OF WORK ITEM TO RESERVED CALL FUNCTION 'SAP_WAPI_RESERVE_WORKITEM' EXPORTING WORKITEM_ID = WA_WORKITEM-WI_ID. WHEN OTHERS. ENDCASE. ENDIF. 0.1. Let's work on Decision making page. This page has *Dynamic* capability to make decision making for any workitem, just you need to pass the workitem as parameter to it. You can create separate BSP Application or else you can create another page in YWORKPLACE Application itself. Name the Page as *"decision.htm". *


  4. *Layout**Page Attribute:*0.1. 0.2. *OnInitialization* 0.1. CALL FUNCTION 'SAP_WAPI_DECISION_READ' EXPORTING WORKITEM_ID = WORKITEM_ID IMPORTING DECISION_TITLE = DECISION_TITLE TABLES ALTERNATIVES = ALTERNATIVES. CALL FUNCTION 'SAP_WAPI_WORKITEM_DESCRIPTION' EXPORTING WORKITEM_ID = WORKITEM_ID TABLES TEXT_LINES = TEXT_LINES HTML_TEXT_LINES = HTML_TEXT_LINES. 0.2. *OnInputProcessing:* DATA: EVENT TYPE REF TO CL_HTMLB_EVENT. DATA: RETURN_CODE LIKE SY-SUBRC, NEW_STATUS TYPE SWW_WISTAT. DATA: WA_MESSAGE_LINES LIKE LINE OF MESSAGE_LINES. EVENT = CL_HTMLB_MANAGER=>GET_EVENT( RUNTIME->SERVER->REQUEST ). IF EVENT->NAME = 'button' AND EVENT->EVENT_TYPE = 'click'. DECISION_CODE = EVENT->SERVER_EVENT. CALL FUNCTION 'SAP_WAPI_DECISION_COMPLETE' EXPORTING WORKITEM_ID = WORKITEM_ID DECISION_KEY = DECISION_CODE IMPORTING RETURN_CODE = RETURN_CODE NEW_STATUS = NEW_STATUS TABLES MESSAGE_LINES = MESSAGE_LINES. ENDIF. 0.1. Last step is, linking our workflow Task (Decision making Task) & BSP Application (Basically Page/controller which used for decision making) using *Customization*. Follow the steps: 0.1. Goto Tcode SWFVISU & Click on "New Entries" 0.2. 0.3. Enter the Task number which is responcisble for desicion making & Visualization Type as "BSP Standard" 0.4. 0.5. Select the entered row & double click on Visualization Parameter under "Task Visualization" 0.6. 0.7. Enter the following Parameters. In my case, I created another page in same BSP Application. You can also create the another BSP Application for decision making process. 0.8. 0.9. Save the entries. It might as you customizing request to save. 0.10. 0.1. 0.2. Now we all set to see output 0.1. Let me Execute BSP Application "YWORKPLACE" Page "main.htm" using "Approvers" user ID. Page will display all the workitems as shown below: 0.2. 0.3. Once you select the workitem, relevant buttons will be enabled to process the workitems 0.4. 0.5. You can Execute/Reserve/Re-submit/Reset etc. Just for demo, let me click on Reserve button 0.6. 0.7. Look at the workitem in GUI, status should changed into "Reserve" as shown below: 0.8. 0.9. Key thing here is, execution of workitem. Let's click on "Execute". *Dynamic decision-making *screen will pop-up as per our customization. 0.10. 0.11. Click on "Approve": 0.12. 0.13. The workitem must have vanished since it's approved and applicant will be informed via mail as shown below: 0.14.
23 Comments
Labels in this area