Google Search - Blog...........

ABAP - Report Program To Delete Mail In SAP Inbox Folder

Description:
This snippet code will show how to delete email from SAP Inbox Folder.
My previous program is display Inbox Folder content and display mail content. Now I add new delete mail function in my previous program.
Class Definition
Adding DELETE_MAIL method.
CLASS LCL_MAIN DEFINITION.
PUBLIC SECTION.
METHODS: DISPLAY_INBOX,
DISPLAY_MAIL IMPORTING IM_MAILID TYPE STRING,
DELETE_MAIL. " -- 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.

DATA: WA_OBJCONT TYPE SOLI,
IT_OBJCONT TYPE TABLE OF SOLI,
OBJECT_HD_DISPLAY TYPE SOOD2.

ENDCLASS. "lcl_main DEFINITION
DELETE_MAIL Implementation
METHOD DELETE_MAIL.
CALL FUNCTION 'SO_OBJECT_DELETE'
EXPORTING
FOLDER_ID = FOLD_ID
OBJECT_ID = MAIL_ID
OWNER = P_UNAME
EXCEPTIONS
FOLDER_NOT_EMPTY = 23
FOLDER_NOT_EXIST = 14
FOLDER_NO_AUTHORIZATION = 15
FORWARDER_NOT_EXIST = 16
OBJECT_NOT_EXIST = 17
OBJECT_NO_AUTHORIZATION = 18
OPERATION_NO_AUTHORIZATION = 19
OTHERS = 1000.


IF SY-SUBRC NE 0.
RAISE EVENT MESSAGE EXPORTING MSG1 = 'Error delete mail.'.
ELSE.
RAISE EVENT MESSAGE EXPORTING MSG1 = 'Email Deleted !'.
ENDIF.
ENDMETHOD. "DELETE_MAIL
Display_Mail Implementation
We have to change Display_Mail Implementation by adding new Delete Icon at the top of screen, so user can delete current mail.
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.
WRITE: ICON_DELETE AS ICON HOTSPOT ON, " -- added code --
'Delete this mail' HOTSPOT ON. " -- added code --

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
AT LINE SELECTION
To make user enable delete mail we need change AT-LINE-SELECTION code.
AT LINE-SELECTION.
DATA MAIL_ID TYPE STRING.

IF SY-LISEL(2) = '11'. "Icon Delete " -- added code --
CALL METHOD O_MAIN->DELETE_MAIL. " -- added code --
ELSE. " -- added code --
MAIL_ID = SY-LISEL+1(17).
CALL METHOD O_MAIN->DISPLAY_MAIL( MAIL_ID ).
ENDIF. " -- added code --

1 comment: