There is several folder in our workplace like inbox, outbox, private folder.
This simple program will display mail list in inbox folder.
Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK BLC01 WITH FRAME TITLE TEXT-S10.
PARAMETERS: P_UNAME LIKE SY-UNAME OBLIGATORY DEFAULT SY-UNAME.
SELECTION-SCREEN END OF BLOCK BLC01.
Class Definition
CLASS LCL_MAIN DEFINITION.
PUBLIC SECTION.
METHODS: DISPLAY_INBOX.
* DISPLAY_MAIL IMPORTING IM_MAILID TYPE STRING.
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.
ENDCLASS. "lcl_main DEFINITION
CLASS LCL_HANDLER DEFINITION.
PUBLIC SECTION.
METHODS HANDLE_MESSAGE
FOR EVENT MESSAGE OF LCL_MAIN
IMPORTING MSG1 MSG2 MSG3 MSG4.
ENDCLASS. "lcl_handler DEFINITION
Class Implementation
CLASS LCL_MAIN IMPLEMENTATION.
*----------------------------------------------*
* METHOD clear_data *
*----------------------------------------------*
METHOD CLEAR_DATA.
CLEAR: USER,
UDAT,
FDAT,
IT_FDAT[],
WA_FDAT,
FOLD_ID
ENDMETHOD. "clear_data
*----------------------------------------------*
* METHOD DISPLAY_INBOX *
*----------------------------------------------*
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,
'' 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
*----------------------------------------------*
* METHOD GET_INBOX_CONTENT *
*----------------------------------------------*
METHOD GET_INBOX_CONTENT.
MOVE P_UNAME TO USER-SAPNAME.
CALL FUNCTION 'SO_USER_READ_API1'
EXPORTING
USER = USER
* prepare_for_folder_access = 'X'
IMPORTING
USER_DATA = UDAT
EXCEPTIONS
USER_NOT_EXIST = 1
PARAMETER_ERROR = 2
X_ERROR = 3
OTHERS = 4.
IF SY-SUBRC NE 0.
CASE SY-SUBRC.
WHEN 1. MSG1 = 'User Does not exist !'.
WHEN 2. MSG1 = 'Parameter Error !'.
WHEN 3. MSG1 = 'X Error!'.
WHEN 4. MSG1 = 'Others Error !'.
ENDCASE.
RAISE EVENT MESSAGE EXPORTING MSG1 = MSG1.
ENDIF.
* Select inbox folder
MOVE UDAT-INBOXFOL TO FOLD_ID.
CALL FUNCTION 'SO_FOLDER_READ_API1'
EXPORTING
FOLDER_ID = FOLD_ID
IMPORTING
FOLDER_DATA = FDAT
TABLES
FOLDER_CONTENT = IT_FDAT
EXCEPTIONS
FOLDER_NOT_EXIST = 1
OPERATION_NO_AUTHORIZATION = 2
X_ERROR = 3
OTHERS = 4.
IF SY-SUBRC NE 0.
CASE SY-SUBRC.
WHEN 1. MSG1 = 'Folder Does not exist !'.
WHEN 2. MSG1 = 'No Authorization !'.
WHEN 3. MSG1 = 'X Error!'.
WHEN 4. MSG1 = 'Others Error !'.
ENDCASE.
RAISE EVENT MESSAGE EXPORTING MSG1 = MSG1.
ENDIF.
ENDMETHOD. "GET_INBOX_CONTENT
ENDCLASS. "lcl_main IMPLEMENTATION
CLASS LCL_HANDLER IMPLEMENTATION.
METHOD HANDLE_MESSAGE .
MESSAGE I398(00) WITH MSG1 MSG2 MSG3 MSG4.
LEAVE LIST-PROCESSING..
ENDMETHOD. "handle_message
ENDCLASS. "lcl_handler IMPLEMENTATION
Main Program
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.
Selection Screen:
*Inbox Content:*
No comments:
Post a Comment