Posted: Thu Feb 19, 2009 3:53 pm Post subject: Maintain Workflow Substitutes centrally
Code:
*& *----------------------------------------------------------------------*
* Report : Z_MAINTAIN_SUBSTITUTE
* Author : Morten Hjorth Nielsen
* Webpage: http://www.mortenhjorthnielsen.com
*
* Purpose: Maintain Workflow Substitutes centrally
*
* This report is meant for inspiration, before you use it in a productive
* environment please Test and Adjust thoroughly
* ----------------------------------------------------------------------*
REPORT z_maintain_substitute.
TABLES: usr02.
DATA:
lv_user TYPE swragent,
lv_subst TYPE swragent,
lt_subst TYPE TABLE OF swr_substitute WITH HEADER LINE,
lt_subst2 TYPE TABLE OF swragent,
lv_return LIKE sy-subrc,
lt_message_lines TYPE TABLE OF swr_messag,
wa_message_lines TYPE swr_messag,
lt_message_struct TYPE TABLE OF swr_mstruc,
BEGIN OF lt_usr OCCURS 0,
user TYPE swragent,
END OF lt_usr.
************************************************************************
* Definition of selection Screen *
************************************************************************
SELECTION-SCREEN: BEGIN OF SCREEN 100.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-010.
SELECT-OPTIONS: user FOR usr02-bname.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-020.
PARAMETER: p_disp RADIOBUTTON GROUP type DEFAULT 'X',
p_add RADIOBUTTON GROUP type,
p_del RADIOBUTTON GROUP type,
p_act RADIOBUTTON GROUP type.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-030.
PARAMETER:
p_subst LIKE usr02-bname MODIF ID dis,
p_from TYPE swr_substbegin DEFAULT sy-datum OBLIGATORY MODIF ID dis,
p_to TYPE swr_substend DEFAULT '99991231' OBLIGATORY MODIF ID dis,
p_activ TYPE swr_substactive DEFAULT ' ' MODIF ID dis.
SELECTION-SCREEN END OF BLOCK b3.
SELECTION-SCREEN END OF SCREEN 100.
************************************************************************
* Screen Logic *
************************************************************************
CALL SELECTION-SCREEN 100.
************************************************************************
* Do not display substitute subscreen if Display is Selected *
* Notice !! Press enter key in order to sispaly subscreen *
************************************************************************
AT SELECTION-SCREEN OUTPUT.
IF p_disp EQ 'X'.
LOOP AT SCREEN.
CHECK screen-group1 = 'DIS'.
screen-active = '0'.
MODIFY SCREEN.
ENDLOOP.
ENDIF.
AT SELECTION-SCREEN ON EXIT-COMMAND.
LEAVE.
START-OF-SELECTION.
************************************************************************
* MAIN CODE LOGIC *
************************************************************************
PERFORM select.
IF p_disp = 'X'.
PERFORM display.
ENDIF.
IF p_add = 'X'.
************************************************************************
* Check if the user has authorization to maintain substitute centrally *
* No standard autthorization object exist for this so S_WF_CUST with *
* Value '*' is used here, but perhaps it would be a better idea to *
* create a specific authorization object for this purpose *
*----------------------------------------------------------------------*
* Recommendation !!! *
* Based on your own security strategy you should create/find the *
* correct autho4rization object in order to control access to the *
* functionality provided in this report *
************************************************************************
AUTHORITY-CHECK OBJECT 'S_WF_SUBST'
ID 'ACTVT' FIELD '*'.
IF sy-subrc = 0.
PERFORM add.
ELSE.
MESSAGE e002(z_message).
* Your not authorized to maintain substitutes for other users
ENDIF.
ENDIF.
IF p_del = 'X'.
PERFORM delete.
ENDIF.
IF p_act = 'X'.
PERFORM activate.
ENDIF.
COMMIT WORK AND WAIT.
**********************************************************************
* FORM : select
* Purpose : select Substituta data into lt_usr
* Created : 11.12.2006 13:14:05
**********************************************************************
FORM select.
SELECT * FROM usr02
WHERE bname IN user.
lv_user-otype = 'US'.
lv_user-objid = usr02-bname.
APPEND lv_user TO lt_usr.
ENDSELECT.
ENDFORM. "select
**********************************************************************
* FORM : displey
* Purpose : List substitute in range
* Created : 11.12.2006 13:12:55
**********************************************************************
FORM display.
LOOP AT lt_usr.
CALL FUNCTION 'SAP_WAPI_SUBSTITUTES_GET'
EXPORTING
substituted_object = lt_usr-user
TABLES
substitutes = lt_subst.
ENDLOOP.
ENDLOOP.
ENDFORM. "display
**********************************************************************
* FORM : add
* Purpose : Add a new substistute to the range of users
* Created : 11.12.2006 14:02:17
**********************************************************************
FORM add .
PERFORM check_user USING p_subst.
LOOP AT lt_usr.
CONCATENATE 'US' p_subst INTO lv_subst.
CALL FUNCTION 'SAP_WAPI_SUBSTITUTE_MAINTAIN'
EXPORTING
substituted_object = lt_usr-user
substitute = lv_subst
subst_begin = p_from
subst_end = p_to
* SUBST_PROFILE =
subst_active = p_activ
* LANGUAGE = SY-LANGU
IMPORTING
return_code = lv_return
TABLES
message_lines = lt_message_lines
message_struct = lt_message_struct
.
* LOOP AT lt_message_lines INTO wa_message_lines.
* WRITE:/ wa_message_lines-msg_type,
* wa_message_lines-line.
* ENDLOOP.
ENDLOOP.
PERFORM display.
ENDFORM. " add
***********************************************************************
* FORM : check_user
* Purpose : Check if user is a valid SAP User
* Created : 11.12.2006 13:54:24
**********************************************************************
FORM check_user USING bname LIKE usr02-bname.
CALL FUNCTION 'SUSR_USER_CHECK_EXISTENCE'
EXPORTING
user_name = bname
EXCEPTIONS
user_name_not_exists = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE e003(z_message) WITH bname.
* User & is not created as a SAP USER
ENDIF.
ENDFORM. " check_user
***********************************************************************
* FORM : delete
* Purpose : Delete a substitute from a list of users
* Created : 11.12.2006 13:12:55
**********************************************************************
FORM delete .
LOOP AT lt_usr.
CONCATENATE 'US' p_subst INTO lv_subst.
APPEND lv_subst TO lt_subst2.
CALL FUNCTION 'SAP_WAPI_SUBSTITUTE_DELETE'
EXPORTING
substituted_object = lt_usr-user
delete_without_date = 'X'
IMPORTING
return_code = lv_return
TABLES
substitutes = lt_subst2
message_lines = lt_message_lines
message_struct = lt_message_struct.
ENDLOOP.
* LOOP AT lt_message_lines INTO wa_message_lines .
* WRITE:/ wa_message_lines-msg_type,
* wa_message_lines-line.
* ENDLOOP.
PERFORM display.
ENDFORM. " delete
***********************************************************************
* FORM : Activate substitution
* Purpose : (de)activate substitution
* Created : 11.12.2006 13:21:54
**********************************************************************
FORM activate .
LOOP AT lt_usr.
CONCATENATE 'US' p_subst INTO lv_subst.
APPEND lv_subst TO lt_subst2.
IF p_activ = 'X'.
CALL FUNCTION 'SAP_WAPI_SUBSTITUTE_ACTIVATE'
EXPORTING
substituted_object = lt_usr-user
IMPORTING
return_code = lv_return
TABLES
substitutes = lt_subst2
message_lines = lt_message_lines
message_struct = lt_message_struct.
ELSE.
CALL FUNCTION 'SAP_WAPI_SUBSTITUTE_DEACTIVATE'
EXPORTING
substituted_object = lt_usr-user
* LANGUAGE = SY-LANGU
IMPORTING
return_code = lv_return
TABLES
substitutes = lt_subst2
message_lines = lt_message_lines
message_struct = lt_message_struct
.
ENDIF.
ENDLOOP.
* LOOP AT lt_message_lines INTO wa_message_lines .
* WRITE:/ wa_message_lines-msg_type,
* wa_message_lines-line.
* ENDLOOP.
PERFORM display.
ENDFORM. " activate
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.