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

ABAP - Report Program To Display Sap Inbox Mail Content.

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 lenght 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
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.

No comments:

Post a Comment