Skip to Content

Hi All,

Hope every one are doing good

Today, I’m going to share some interesting stuff ( hope so, it will be ) about the Tool which created long back and now i’m posting it for all our people who can make use of this tool and configure in their projects and to their needs.

And tool is called “Performance Monitoring Status Through Email”.

I believe, most of the fresher who started their career in business ware house, had spend quite time in monitoring process chains and system.And In most of support projects we used to continuously monitor the large loads and system performance by checking long running jobs ( which are un necessary and some times triggered by basis team or others), number of roll up jobs running in system and if any failure notify team, CPU utilization, data base index, ACR status. some thing like that.

SO, in our project the first week of month is very crucial and its called the closing period of business, where we used to run many + heavy loads with repsect to 100+ application data in to BW system,  at that time we faced many issues like ACR failures, long running jobs ( with out any progress ), Roll up jobs, Checking the CPU utilization once in 10 times and some times even worse where TREX server failure etc..

And it is guided by our team leads to continuously monitor the system 24*7 for the first week by checking the below list of task manually and send the email update once in every 1 hour to every one in team and some times to business, which makes them that the monitoring is in place for 24*7 and check list is being done.

So here are the list.

1) Check the CPU utilization

2) Check if any long running jobs in SM37

3) Check any roll up jobs ( *rollup* in sm37 )

4) Check if primary index failure or not

5) Check ACR, which is currently running or failure by tcode changerunmoni.

Had a thought that instead of checking it manually and sending out the status with different colours of red, green ,yellow through email. I created ABAP program by automating the entire process.

So my below out put is something like this, the Zautomation program will be scheduled in background and its according to their need, if they want to run in every half an hour or 1 hours they can.

Here is the sample out put, where the programs does al the manual task and send the output in email itself. And status indicates different colours in green, yellow, red of those jobs in the system. also you can configure number of email you want and any DL’s email groups in CC ( to your need )

Where CPU utilization is 66% so it is green, if its less than 30% then it will be in red if it 45% above and below 65% it will be in yellow ( this is to my project perspective , so i configured it ) and there is no ACR jobs so it is green and if there is any long running jobs more than 2 hours then will be in red with those job details.

You can customize the code to your need as well.

Untitled.png

Code is below, Please keep in mind this is in need for project specific and also it can be a general Performance monitoring tool for all SAP BW systems, where we need to identify some of tasks related to other projects and common task can be made in general list and it can used as common Performance Monitoring Tool

Code looks very simple, but experts please excuse if I didn’t follow any standards

*—————————————–*

*&

*&

*&———————————————————————*

*&*”———————————————————————-

*   M Sivaramakrishnan

*

*

*  Version: 1.0 Automation of Performance monitoring status through email.

*

*

*”———————————————————————-

*

*&———————————————————————*

REPORT  ZAUTOMATION.

*WRITE ‘hi awesome’.

CONSTANTS:

            GC_RAW           TYPE CHAR03           VALUE ‘RAW’,

            C_SPACE          TYPE SO_OBJ_DES       VALUE ,

            CON_TAB          TYPE C                VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,

            CON_CRET         TYPE C                VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.

* local variables

DATA: LV_SUBJECT        TYPE C   LENGTH 255   VALUE ‘CPU Util.&job status for’,

       LV_FINAL_DATE     TYPE C   LENGTH 10,

       LV_SYMBOL         TYPE C   LENGTH 1     VALUE ‘:’,

       LV_MESSAGE        TYPE C   LENGTH 255,

       LV_RESULT         TYPE OS_BOOLEAN,

       LV_EMAIL          TYPE ADR6SMTP_ADDR,

       LV_DATE           TYPE SYDATUM,

       LV_TIMLO          LIKE SYTIMLO,

       LV_STATUS         TYPE STRING,

       LV_LRJ_DESC       TYPE STRING,

       LV_MAX_VALUE      TYPE I,

       LV_LRJ_MINUTES    TYPE I,

       L_SUBRC           TYPE I,

       GD_REPID          LIKE SYREPID,

       G_SAVE            TYPE C                 VALUE ‘X’,

       G_VARIANT         TYPE DISVARIANT,

       GX_VARIANT        TYPE DISVARIANT,

       G_EXIT            TYPE C,

       LV_CPU_VALUE      TYPE C    LENGTH 2,

       LV_CPU_DESC       TYPE STRING,

       LV_LRJ            TYPE STRING,

       LV_CPU_STATUS     TYPE STRING,

       LV_STATUS_ACR     TYPE STRING,

       LV_STATUS_ROLLUP  TYPE STRING,

       LV_STATUS_MISSING_INDEX TYPE STRING,

       LV_DESC_MISSING_INDEX TYPE STRING,

       LS_VALUE          TYPE STRING             VALUE ‘CPU Utilization’,

       LV_CPU_TEXT       TYPE STRING,

       FROM_DATE         TYPE SYDATUM,

       TO_DATE           TYPE SYDATUM,

       FROM_TIME         TYPE BTCSTIME,

       TO_TIME           TYPE BTCSTIME,

       LV_TIMLO_HRS(2),

       LV_TIMLO_MINS(2),

       LV_FINAL_TIMLO(10),

       LV_YEAR(4),

       LV_DAY(2),

       LV_COUNTER        TYPE I VALUE ‘0’,

       LV_COUNT          TYPE I,

       LV_MONTH(2),

       JOBNAME2(66),

       LV_STATUS_CHANGERUNMONI TYPE STRING,

       LV_CHANGERUNMONI TYPE STRING,

       LV_STATUS_CHANGERUNMONI_TEXT TYPE STRING,

       LV_CHANGERUNMONI_TEXT TYPE STRING,

       LV_STATUS_CHANGERUNMONI_IMG TYPE STRING,

       LV_DESC_ROLLUP TYPE STRING.

* All global variable declaration

DATA:

           GC_SUBJECT        TYPE        SO_OBJ_DES,

           LO_EX_BCS         TYPE REF TO CX_BCS,

           GV_MLREC          TYPE        SO_OBJ_NAM,

           GV_SENT_TO_ALL    TYPE        OS_BOOLEAN,

           GV_EMAIL          TYPE        ADR6SMTP_ADDR,

           GV_SUBJECT        TYPE        SO_OBJ_DES,

           GV_TEXT           TYPE        BCSY_TEXT, “t_html

           GV_TEXT1          TYPE        BCSY_TEXT, “LT_HTML_

           GR_SEND_REQUEST   TYPE REF TO CL_BCS,

           GR_BCS_EXCEPTION  TYPE REF TO CX_BCS,

           GV_ADDR_EXCEPTION TYPE REF TO CX_BCS,

           GR_RECIPIENT      TYPE REF TO IF_RECIPIENT_BCS,

           GR_SENDER         TYPE REF TO CL_SAPUSER_BCS,

           GR_DOCUMENT       TYPE REF TO CL_DOCUMENT_BCS.

DATA:     LOGICAL_DESTINATION LIKE  RFCDESRFCDEST,

           F_CPU_ALL_READ      LIKE  DEF_PAR_FUNO_YES,

           ACTIVEFLAG          LIKE  DEF_PAR_FUACTIVEFLAG,

           INTERVAL            LIKE  DEF_PAR_FUINTERVAL,

           OP_SYSTEM           LIKE  DEF_PAR_FUOPSYSTEM,

           DETAILSCOLL         LIKE  DEF_PAR_FUDETAILSCOL,

           DETAILSREQI         LIKE  DEF_PAR_FUDETAILSREQ,

           DETAILSMODE         LIKE  DEF_PAR_FUDETAILSMOD,

           LASTCOLLWRT         LIKE  DEF_PAR_FULASTCOLLWR,

           LASTCOLLINT         LIKE  DEF_PAR_FULASTCOLLIN,

           NORMCOLLINT         LIKE  DEF_PAR_FUNORMCOLLIN.

DATA: L_T_CHABASNM        TYPE RSD_T_IOBJNM,

       L_T_HIEID           TYPE RSHI_T_HIEID,

       P_R_CONTAINER       TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

       P_R_SALV            TYPE REF TO CL_SALV_TABLE,

       P_TS_STATE_CR       TYPE RSDDS_TS_STATE_CR,

       P_TS_CHANM_IN_AGGR  TYPE RSDDS_TS_CHABAS,

       P_TS_CHABASNM_CR    TYPE RSDDS_TS_CHABASNM_CR,

       P_TS_HIER_CR        TYPE RSDDS_TS_HIER_CR,

       P_T_AGGREGATE_CR    TYPE RSDDS_T_AGGREGATE_CR,

       P_TS_TREXAGGR_CR    TYPE RSDDS_TS_TREXAGGR_CR,

       P_TSX_MSG_CR        TYPE RSDDS_TSX_MSG_CR,

       N_WITH_DETAILS      TYPE RS_BOOL.

*&———————————————————————*

*All Strucure declaration

DATA: BEGIN OF STATUS_SET,

                 SCHEDULED_FLAG(1) VALUE ‘ ‘,

                 RELEASED_FLAG(1VALUE ‘ ‘,

                 READY_FLAG(1)     VALUE ‘ ‘,

                 ACTIVE_FLAG(1)    VALUE ‘ ‘,

                 FINISHED_FLAG(1VALUE ‘ ‘,

                 CANCELLED_FLAG(1) VALUE ‘ ‘,

                 SUSPENDED_FLAG(1) VALUE ‘ ‘,

                 CLAUSE(100)       TYPE C,

       END OF    STATUS_SET,

       BEGIN OF  P_STATUS_CLAUSE,

                 PREFIX(2) TYPE C,

                 CLAUSE    LIKE STATUS_SETCLAUSE,

       END OF    P_STATUS_CLAUSE.

*email

TYPES: BEGIN OF MAIL_ID,

                 LV_EMAIL TYPE ADR6SMTP_ADDR,

        END OF   MAIL_ID,

*long running job structure

        BEGIN OF TR_JBSLT_JBLIST,

                 JOBNAME TYPE BTCJOB, “Background job name

                 JOBCOUNT TYPE BTCJOBCNT, “Job ID

                 USERNAME TYPE BTCSDLNM, “Initiator of job/step scheduling

                 STRTDATE TYPE BTCXDATE, “Job start date

                 PRDMINS TYPE BTCPMIN, “Duration period (in minutes) for a background job

                 STATUS TYPE C LENGTH 10,

        END OF   TR_JBSLT_JBLIST,

* Roll up structure

        BEGIN OF ROLLUP,

                 JOBNAME TYPE BTCJOB, “Background job name

                 STATUS TYPE C LENGTH 10,

       END OF ROLLUP,

*Primary Index structure

       BEGIN OF PRIMARY_INDEX,

                 TABNAME TYPE TABNAME,

                 AS4LOCAL TYPE AS4LOCAL,

                 TABCLASS TYPE TABCLASS,

       END OF  PRIMARY_INDEX,

*Missing index structure

       BEGIN OF MISSING_INDEX,

                  TABNAME TYPE TABNAME,

                  FLAG TYPE I,

       END OF   MISSING_INDEX.

*&———————————————————————*

*All internal table declaration

DATA: LT_RECP               TYPE STANDARD TABLE OF AD_SMTPADR,

       T_BODY                TYPE STANDARD TABLE OF SOLI,

       FIELDCATALOG          TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,

       ISPFLI                TYPE TABLE OF SPFLI,

       LT_JBSELECT_JOBLIST   TYPE STANDARD TABLE OF TR_JBSLT_JBLIST,

       LT_EMAIL              TYPE TABLE OF MAIL_ID,

       LT_EMAIL_CC           TYPE TABLE OF MAIL_ID,

       LT_JB_ROLLUP          TYPE STANDARD TABLE OF ROLLUP,

       LT_PRIMARY_INDEX      TYPE STANDARD TABLE OF PRIMARY_INDEX,

       LT_MISSING_INDEX      TYPE STANDARD TABLE OF MISSING_INDEX,

       LT_HTML               TYPE BCSY_TEXT,

       LT_HTML_              TYPE BCSY_TEXT,

       LT_HTML_MISIND        TYPE BCSY_TEXT,

       LT_HTML_RUNACR        TYPE BCSY_TEXT,

       LT_HTML_FAILEDACR     TYPE BCSY_TEXT,

       LT_HTML_DESCACR       TYPE BCSY_TEXT,

       LT_HTML_ROLLUP        TYPE BCSY_TEXT,

       LT_CPU_ALL            TYPE TABLE OF CPU_ALL.

*&———————————————————————*

*All work area deaclaration

DATA: WA_BODY                TYPE  SOLI,

       GD_LAYOUT              TYPE  SLIS_LAYOUT_ALV,

       LWA_JOBSELECT_JOBLIST  TYPE  TR_JBSLT_JBLIST,

       LWA_EMAIL              TYPE  MAIL_ID,

       LWA_EMAIL_CC           TYPE  MAIL_ID,

       LWA_JB_ROLLUP          TYPE  ROLLUP,

       LWA_PRIMARY_INDEX      TYPE  PRIMARY_INDEX,

       LWA_MISSING_INDEX      TYPE  MISSING_INDEX.

*&———————————————————————*

*TYPES: STATUS_SET LIKE STATUS_SET.

*TYPES: JOBSELECT_JOBLIST_S LIKE TBTCJOB_BK.

*DATA:  JOBSELECT_JOBLIST_B TYPE TABLE OF JOBSELECT_JOBLIST_S.

*TYPES: SELECT_VALUES LIKE BTCSELECT.

*DATA: GT_SELECT_VALUES TYPE TABLE OF SELECT_VALUES,

*      WA_GT_SELECT_VALUES TYPE SELECT_VALUES.

*&———————————————————————*

FIELD-SYMBOLS: <FS_LT_CPU_ALL> TYPE CPU_ALL,

                <FS_JBSLT_JBLIST> TYPE TR_JBSLT_JBLIST,

                <FS_ROLLUP> TYPE ROLLUP,

                <FS_MISSING_INDEX> TYPE MISSING_INDEX,

                <FS_ACR> TYPE RSDDS_S_STATE_CR.

*logic to get the status ‘F’ i.e active long running jobs

CONCATENATE P_STATUS_CLAUSE ‘, ‘‘F’INTO P_STATUS_CLAUSE.

STATUS_SETCLAUSE = P_STATUS_CLAUSECLAUSE.

IF NOT STATUS_SETCLAUSE IS INITIAL.

   CONCATENATE ‘(‘ STATUS_SETCLAUSE ‘)’ INTO STATUS_SETCLAUSE.

   CONCATENATE ‘STATUS IN’ STATUS_SETCLAUSE INTO STATUS_SETCLAUSE

     SEPARATED BY SPACE.

ENDIF.

*&———————————————————————*

*&      Form  do_select

*&———————————————————————*

*       text

*———————————————————————-*

*      –>STATUS_SET text

*———————————————————————-*

FORM DO_SELECT USING STATUS_SET  STRUCTURE STATUS_SET.

   DATA: P_STATUS_CLAUSE LIKE TABLE OF STATUS_SETCLAUSE.

   APPEND STATUS_SETCLAUSE TO P_STATUS_CLAUSE.

*  SELECT DISTINCT jobname jobcount sdluname strtdate prdmins status FROM v_op INTO TABLE zjobselect_joblist_it

*      WHERE ( ( ( ( sdlstrtdt = from_date AND  sdlstrttm >= from_time  ) OR  sdlstrtdt > from_date )

*                    AND

*                    ( ( sdlstrtdt = to_date AND sdlstrttm <= to_time  ) OR  sdlstrtdt < to_date ) ) ) AND (p_status_clause).

*

*    sort zjobselect_joblist_it by strtdate ascending.

   “jobname jobocunt username startdate duration in minutes status

*  SELECT distinct jobname jobcount sdluname strtdate prdmins status FROM v_op  INTO TABLE zjobselect_joblist_it

*      WHERE ( ( ( ( sdlstrtdt = from_date AND  sdlstrttm >= from_time  ) OR  sdlstrtdt > from_date )

*                    AND

*                    ( ( sdlstrtdt = to_date AND sdlstrttm <= to_time  ) OR  sdlstrtdt < to_date ) ) ) AND (p_status_clause).

   ” getting long runnnig job details

   SELECT JOBNAME JOBCOUNT SDLUNAME STRTDATE  PRDMINS STATUS FROM V_OP  INTO TABLE LT_JBSELECT_JOBLIST WHERE STATUS IN (‘F’).

   IF SYSUBRC EQ ‘0’.

     SORT LT_JBSELECT_JOBLIST DESCENDING BY PRDMINS.

     CLEAR LT_HTML_.

     APPEND ‘<table><tr><th>JobName</th>’ TO LT_HTML_.

     APPEND ‘<th>Job Count</th>’ TO LT_HTML_.

     APPEND ‘<th>User Name</th>’ TO LT_HTML_.

     APPEND ‘<th>Start Date</th>’ TO LT_HTML_.

     APPEND ‘<th>Duration in Minutes</th>’ TO LT_HTML_.

     APPEND ‘<th>Status</th></tr>’ TO LT_HTML_.

     LOOP AT  LT_JBSELECT_JOBLIST ASSIGNING <FS_JBSLT_JBLIST> FROM 1 TO 5.

       APPEND ‘<tr>’ TO LT_HTML_.

       DO 1 TIMES.

         APPEND ‘<td>’ TO LT_HTML_.

         APPEND <FS_JBSLT_JBLIST>JOBNAME TO LT_HTML_.

         APPEND ‘</td>’ TO LT_HTML_.

         APPEND ‘<td>’ TO LT_HTML_.

         APPEND <FS_JBSLT_JBLIST>JOBCOUNT TO LT_HTML_.

         APPEND ‘</td>’ TO LT_HTML_.

         APPEND ‘<td>’ TO LT_HTML_.

         APPEND <FS_JBSLT_JBLIST>USERNAME TO LT_HTML_.

         APPEND ‘</td>’ TO LT_HTML_.

         APPEND ‘<td>’ TO LT_HTML_.

         APPEND <FS_JBSLT_JBLIST>STRTDATE TO LT_HTML_.

         APPEND ‘</td>’ TO LT_HTML_.

         APPEND ‘<td>’ TO LT_HTML_.

         READ TABLE LT_JBSELECT_JOBLIST TRANSPORTING NO FIELDS INDEX 1.

         IF SYSUBRC EQ 0.

           APPEND <FS_JBSLT_JBLIST>PRDMINS TO LT_HTML_.

         ENDIF.

         APPEND ‘</td>’ TO LT_HTML_.

         APPEND ‘<td>’ TO LT_HTML_.

         APPEND <FS_JBSLT_JBLIST>STATUS TO LT_HTML_.

         APPEND ‘</td>’ TO LT_HTML_.

       ENDDO.

       APPEND ‘</tr>’ TO LT_HTML_.

       LV_LRJ_MINUTES = <FS_JBSLT_JBLIST>PRDMINS .

     ENDLOOP.

     APPEND ‘</tr></table>’ TO LT_HTML_.

   ENDIF.

ENDFORM.                    “do_select

START-OF-SELECTION.

   PERFORM DO_SELECT USING STATUS_SET.

   LV_TIMLO = SYTIMLO.

   LV_TIMLO_HRS = LV_TIMLO+0(2).

   LV_TIMLO_MINS = LV_TIMLO+2(2).

   LV_DATE = SYDATUM.

   LV_DAY = LV_DATE+6(2).

   LV_MONTH = LV_DATE+4(2).

   LV_YEAR = LV_DATE+0(4).

   WRITE: LV_YEAR.

   CONCATENATE LV_DAY LV_MONTH LV_YEAR INTO LV_FINAL_DATE SEPARATED BY ‘.’.

   WRITE: LV_FINAL_DATE.

   REFRESH: LT_EMAIL.

   CLEAR LWA_EMAIL.

   LWA_EMAILLV_EMAIL = ‘sivaramakrishnan.m@xxx.com.

   APPEND LWA_EMAIL TO LT_EMAIL.

   CLEAR LWA_EMAIL.

   LWA_EMAILLV_EMAIL = ‘abc@xxx.com.

   APPEND LWA_EMAIL TO LT_EMAIL.

**REFRESH: lt_email_cc.

**clear ls_email_cc.

*ls_email-lv_email = ‘dileep.konduru@cognizant.com‘.

*append ls_email_cc to lt_email_cc.

   TRY.

       “Create send request

       GR_SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).

       “Email FROM…

       GR_SENDER = CL_SAPUSER_BCS=>CREATE( SYUNAME ).

       “Add sender to send request

       CALL METHOD GR_SEND_REQUEST->SET_SENDER

         EXPORTING

           I_SENDER = GR_SENDER.

       LOOP AT LT_EMAIL INTO  LWA_EMAIL.

         LV_EMAIL LWA_EMAIL.

         GR_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( LV_EMAIL ).

         CALL METHOD GR_SEND_REQUEST->ADD_RECIPIENT

           EXPORTING

             I_RECIPIENT = GR_RECIPIENT.

*          i_express   = ”.

       ENDLOOP.

       CLEAR: LV_EMAIL.

       LOOP AT LT_EMAIL_CC INTO LWA_EMAIL_CC.

         LV_EMAIL = LWA_EMAIL_CC.

         GR_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( LV_EMAIL ).

         CALL METHOD GR_SEND_REQUEST->ADD_RECIPIENT

           EXPORTING

             I_RECIPIENT = GR_RECIPIENT

             I_COPY      = ‘X’. ” CC indicator

       ENDLOOP.

       “Email Subject

       CONCATENATE LV_TIMLO_HRS LV_SYMBOL LV_TIMLO_MINS INTO LV_FINAL_TIMLO.

       CONCATENATE LV_SUBJECT LV_FINAL_DATE LV_FINAL_TIMLO SYZONLO  INTO GC_SUBJECT SEPARATED BY .

*CPU Utilization

       CALL FUNCTION ‘GET_CPU_ALL’

         DESTINATION LOGICAL_DESTINATION

         EXPORTING

           LOCAL_REMOTE                   = ‘LOCAL’

           LOGICAL_DESTINATION            = ‘CTSINTCOVSAP1_BWT_00’

         IMPORTING

           F_CPU_ALL_READ                 = F_CPU_ALL_READ

           ACTIVEFLAG                     = ACTIVEFLAG

           INTERVAL                       = INTERVAL

           OP_SYSTEM                      = OP_SYSTEM

           DETAILSCOLL                    = DETAILSCOLL

           DETAILSREQI                    = DETAILSREQI

           DETAILSMODE                    = DETAILSMODE

           LASTCOLLWRT                    = LASTCOLLWRT

           LASTCOLLINT                    = LASTCOLLINT

           NORMCOLLINT                    = NORMCOLLINT

         TABLES

           TF_CPU_ALL                     = LT_CPU_ALL

         EXCEPTIONS

           INTERNAL_ERROR_ADRESS_FAILED   = 1

           INTERNAL_ERROR_DIFFERENT_FIELD = 2

           INTERNAL_ERROR_NO_NEW_LINE     = 3

           COLLECTOR_NOT_RUNNING          = 4

           SHARED_MEMORY_NOT_AVAILABLE    = 5

           COLLECTOR_BUSY                 = 6

           VERSION_CONFLICT               = 7

           NO_NETWORK_COLLECTOR_RUNNING   = 8

           SYSTEM_FAILURE                 = 9

           COMMUNICATION_FAILURE          = 10

           OTHERS                         = 11.

       IF SYSUBRC = 0.

         LOOP AT LT_CPU_ALL ASSIGNING <FS_LT_CPU_ALL>.

           LV_CPU_VALUE = <FS_LT_CPU_ALL>IDLE_TOTAL.

         ENDLOOP.

         LV_CPU_VALUE = 100 ( LV_CPU_VALUE ).

         IF LV_CPU_VALUE >= 20 AND LV_CPU_VALUE < 100.

           CLEAR: LV_STATUS, LV_CPU_DESC.

           LV_STATUS = ‘<td align=”center”><img src =”success.png”/></td>’.

           LV_CPU_DESC = ‘Currently CPU utilization is’.

           CONCATENATE LV_CPU_DESC LV_CPU_VALUE INTO LV_CPU_DESC.

         ELSEIF LV_CPU_VALUE >= 11 AND LV_CPU_VALUE <= 19.

           CLEAR: LV_STATUS, LV_CPU_DESC.

           LV_STATUS =‘<td align=”center”><img src=”warning.png”/></td>’.

           LV_CPU_DESC = ‘Currently  CPU utilization is’.

           CONCATENATE LV_CPU_DESC LV_CPU_VALUE INTO LV_CPU_DESC.

         ELSEIF LV_CPU_VALUE <= 10.

           CLEAR: LV_STATUS, LV_CPU_DESC.

           LV_STATUS = ‘<td align=”center”><img src=”error.png”/></td>’.

           LV_CPU_DESC = ‘Currently CPU utilization is’.

           CONCATENATE LV_CPU_DESC LV_CPU_VALUE INTO LV_CPU_DESC.

         ELSE.

         ENDIF.

       ENDIF.

* logic to find out the maximum running jobs

       DATA: LWA_1 TYPE TR_JBSLT_JBLIST,

             LWA_2 TYPE TR_JBSLT_JBLIST.

       DATA: MAXVAL TYPE BTCPMIN.

*long running jobs

       LOOP AT LT_JBSELECT_JOBLIST INTO LWA_1.

         READ TABLE LT_JBSELECT_JOBLIST INDEX SYINDEX + 1 INTO LWA_2.

         IF LWA_2PRDMINS > LWA_1PRDMINS.

           LV_LRJ_MINUTES = LWA_2PRDMINS.

         ENDIF.

       ENDLOOP.

       IF LV_LRJ_MINUTES > 500.

         CLEAR: LV_STATUS_ACR, LV_CPU_DESC.

         LV_STATUS_ACR = ‘<td align=”center”><img src=”error.png”/></td>’.

       ELSEIF LV_LRJ_MINUTES > 350 AND LV_LRJ_MINUTES <= 500.

         CLEAR: LV_STATUS_ACR, LV_LRJ_DESC.

         LV_STATUS_ACR =‘<td align=”center”><img src=”warning.png”/></td>’.

       ELSEIF LV_LRJ_MINUTES <= 150.

         CLEAR: LV_STATUS_ACR, LV_LRJ_DESC.

         LV_STATUS_ACR = ‘<td align=”center”><img src=”success.png”/></td>’.

       ELSE.

       ENDIF.

*logic to find out the faield Roll up jobs

*status ‘A’ -> Failed jobs

*status ‘F’ -> Finished jobs

*status ‘R’ -> Active jobs

       FROM_DATE = SYDATUM 1.

       TO_DATE = SYDATUM.

       FROM_TIME = ‘000000’.

       TO_TIME = ‘240000’.

*  SELECT distinct jobname jobcount sdluname strtdate prdmins status FROM v_op  INTO TABLE zjobselect_joblist_it

*      WHERE ( ( ( ( sdlstrtdt = from_date AND  sdlstrttm >= from_time  ) OR  sdlstrtdt > from_date )

*                    AND

*                    ( ( sdlstrtdt = to_date AND sdlstrttm <= to_time  ) OR  sdlstrtdt < to_date ) ) ) AND (p_status_clause).

       SELECT DISTINCT JOBNAME STATUS FROM V_OP INTO TABLE LT_JB_ROLLUP WHERE ( JOBNAME LIKE ‘%ROLLUP%’  OR JOBNAME LIKE  ‘BI_AGGR%’ )

         AND ( ( ( ( SDLSTRTDT = FROM_DATE AND  SDLSTRTTM >= FROM_TIME  ) OR  SDLSTRTDT > FROM_DATE ) AND

         ( ( SDLSTRTDT = TO_DATE AND SDLSTRTTM <= TO_TIME  ) OR  SDLSTRTDT < TO_DATE ) ) ).

*                                              AND ( STATUS LIKE ‘A’

*                                                     ).

       IF LT_JB_ROLLUP IS NOT INITIAL.

         REFRESH  LT_HTML_ROLLUP.

         CLEAR: LV_COUNTER.

         APPEND ‘<br>’ TO LT_HTML_ROLLUP.

         APPEND ‘<table><tr><th>S.No</th>’ TO LT_HTML_ROLLUP.

         APPEND ‘<th>Job Name</th>’ TO LT_HTML_ROLLUP.

         APPEND ‘<th>Status</th>’ TO LT_HTML_ROLLUP.

         APPEND ‘</tr>’ TO LT_HTML_ROLLUP.

         LOOP AT LT_JB_ROLLUP ASSIGNING <FS_ROLLUP>.

           CASE <FS_ROLLUP>STATUS.

*            WHEN ‘A’.

*              LV_STATUS_ROLLUP = ‘<td align=”center”><img src=”error.png”/></td>’.

*              LV_DESC_ROLLUP = ‘Roll up Failed<br>’.

*              APPEND LV_DESC_ROLLUP TO LT_HTML_ROLLUP.

*              APPEND ‘<tr>’ TO LT_HTML_ROLLUP.

*              APPEND ‘<td>’ TO LT_HTML_ROLLUP.

*              LV_COUNTER = LV_COUNTER + 1.

*              APPEND LV_COUNTER TO LT_HTML_ROLLUP.

*              APPEND ‘</td>’ TO LT_HTML_ROLLUP.

*              APPEND ‘<td>’ TO LT_HTML_ROLLUP.

*              APPEND <FS_ROLLUP>-JOBNAME TO LT_HTML_ROLLUP.

*              APPEND ‘</td>’ TO LT_HTML_ROLLUP.

*              APPEND ‘<td>’ TO LT_HTML_ROLLUP.

*              APPEND ‘Failed’ TO LT_HTML_ROLLUP.

*              APPEND ‘</td>’ TO LT_HTML_ROLLUP.

*              APPEND ‘</tr>’ TO LT_HTML_ROLLUP.

             WHEN ‘F’.

               LV_STATUS_ROLLUP = ‘<td align=”center”><img src=”success.png”/></td>’.

*              LV_DESC_ROLLUP = ‘<p>No Roll up is currently running</p>’.

               APPEND ‘<br>’ TO LT_HTML_ROLLUP.

               APPEND LV_DESC_ROLLUP TO LT_HTML_ROLLUP.

               APPEND ‘<tr>’ TO LT_HTML_ROLLUP.

               APPEND ‘<td>’ TO LT_HTML_ROLLUP.

               LV_COUNTER = LV_COUNTER + 1.

               APPEND LV_COUNTER TO LT_HTML_ROLLUP.

               APPEND ‘</td>’ TO LT_HTML_ROLLUP.

               APPEND ‘<td>’ TO LT_HTML_ROLLUP.

               APPEND <FS_ROLLUP>JOBNAME TO LT_HTML_ROLLUP.

               APPEND ‘</td>’ TO LT_HTML_ROLLUP.

               APPEND ‘<td>’ TO LT_HTML_ROLLUP.

               APPEND ‘Success’ TO LT_HTML_ROLLUP.

               APPEND ‘</td>’ TO LT_HTML_ROLLUP.

               APPEND ‘</tr>’ TO LT_HTML_ROLLUP.

*            WHEN ‘R’.

*              LV_STATUS_ROLLUP = ‘<td align=”center”><img src=”warning.png”/></td>’.

*              LV_DESC_ROLLUP = ‘Roll up is currently running’.

*              APPEND LV_DESC_ROLLUP TO LT_HTML_ROLLUP.

*              APPEND ‘<tr>’ TO LT_HTML_ROLLUP.

*              APPEND ‘<td>’ TO LT_HTML_ROLLUP.

*              LV_COUNTER = LV_COUNTER + 1.

*              APPEND LV_COUNTER TO LT_HTML_ROLLUP.

*              APPEND ‘</td>’ TO LT_HTML_ROLLUP.

*              APPEND ‘<td>’ TO LT_HTML_ROLLUP.

*              APPEND <FS_ROLLUP>-JOBNAME TO LT_HTML_ROLLUP.

*              APPEND ‘</td>’ TO LT_HTML_ROLLUP.

*              APPEND ‘<td>’ TO LT_HTML_ROLLUP.

*              APPEND ‘Running’ TO LT_HTML_ROLLUP.

*              APPEND ‘</td>’ TO LT_HTML_ROLLUP.

*              APPEND ‘</tr>’ TO LT_HTML_ROLLUP.

             WHEN OTHERS.

           ENDCASE.

         ENDLOOP.

         APPEND ‘</tr></table>’ TO LT_HTML_ROLLUP.

       ELSE.

*        LV_STATUS_ROLLUP = ‘<td align=”center”><img src=”success.png”/></td>’.

*       LV_DESC_ROLLUP = ‘No Roll up is currently running’.

       ENDIF.

*primary index

       SELECT TABNAME AS4LOCAL TABCLASS FROM DD02L INTO TABLE LT_PRIMARY_INDEX WHERE ( TABCLASS ‘TRANSP’

                                                                       OR TABCLASS = ‘CLUSTER’

                                                                       OR TABCLASS = ‘POOL’   )

                                                                       AND  (

                                                                      TABNAME LIKE ‘/BI0/F%’   OR

                                                                      TABNAME LIKE ‘/BIC/F%’   OR

                                                                      TABNAME LIKE ‘/BI0/E%’   OR

                                                                      TABNAME LIKE ‘/BIC/E%’   OR

                                                                      TABNAME LIKE ‘/BI0/9AF%’ OR

                                                                      TABNAME LIKE ‘/BI0/9AE%’ OR

                                                                      TABNAME LIKE ‘/BIC/9AF%’ OR

                                                                      TABNAME LIKE ‘/BIC/9AE%’ OR

                                                                      TABNAME LIKE  ‘/BIC/%’   OR

                                                                      TABNAME LIKE  ‘/BI0/9A’  OR

                                                                      TABNAME LIKE  ‘/BI0/%’   OR

                                                                      TABNAME LIKE ‘/CEM/%’    OR

                                                                      TABNAME LIKE ‘/B20/%’

                                                                     OR TABNAME LIKE ‘/1SEM/%’ )

                                                                      AND AS4LOCAL =‘A’.

       IF SYSUBRC EQ 0.

         LOOP AT LT_PRIMARY_INDEX INTO LWA_PRIMARY_INDEX FROM 1 TO 50.

           CALL FUNCTION ‘DB_EXISTS_INDEX’

             EXPORTING

               TABNAME         = LWA_PRIMARY_INDEXTABNAME

               INDEXNAME       = ‘0’

             IMPORTING

               SUBRC           = L_SUBRC

             EXCEPTIONS

               PARAMETER_ERROR = 1

               OTHERS          = 2.

           IF L_SUBRC <> 0.

             APPEND LWA_PRIMARY_INDEXTABNAME TO LT_MISSING_INDEX.

           ENDIF.

         ENDLOOP.

       ENDIF.

       IF LT_MISSING_INDEX[] IS NOT INITIAL.

         LV_STATUS_MISSING_INDEX = ‘<td align=”center”><img src=”error.png”/></td>’.

         REFRESH: LT_HTML_MISIND.

         APPEND ‘<table><tr><th>S.No</th>’ TO LT_HTML_MISIND.

         APPEND ‘<th>Missing index objects</th>’ TO LT_HTML_MISIND.

         LOOP AT LT_MISSING_INDEX ASSIGNING <FS_MISSING_INDEX> FROM 1 TO 5.

           CLEAR: LV_COUNTER.

           APPEND ‘<tr>’ TO LT_HTML_MISIND.

           APPEND ‘<td>’ TO LT_HTML_MISIND.

           LV_COUNTER = LV_COUNTER + 1.

           APPEND LV_COUNTER TO LT_HTML_MISIND.

           APPEND ‘</td>’ TO LT_HTML_MISIND.

           APPEND ‘<td>’ TO LT_HTML_MISIND.

           APPEND <FS_MISSING_INDEX>TABNAME TO LT_HTML_MISIND.

           APPEND ‘</td>’ TO LT_HTML_MISIND.

           APPEND ‘</tr>’ TO LT_HTML_MISIND.

         ENDLOOP.

         APPEND ‘</tr></table>’ TO LT_HTML_MISIND.

       ELSE.

         REFRESH: LT_HTML_MISIND.

         LV_STATUS_MISSING_INDEX = ‘<td align=”center”><img src=”success.png”/></td>’.

         LV_DESC_MISSING_INDEX   = ‘<td align=””><p>All objects have index in place.</p></td>’.

         APPEND LV_DESC_MISSING_INDEX TO LT_HTML_MISIND.

       ENDIF.

* ACR

*   DATA: LT_HMTL_RUNACR        TYPE BCSY_TEXT.

       CALL FUNCTION ‘RSDDS_CHANGERUN_MONITOR’

         EXPORTING

           I_WITH_DETAILS     = N_WITH_DETAILS

           I_T_CHABASNM       = L_T_CHABASNM

           I_T_HIEID          = L_T_HIEID

         IMPORTING

           E_TS_STATE_CR      = P_TS_STATE_CR

           E_TS_CHANM_IN_AGGR = P_TS_CHANM_IN_AGGR

           E_TS_HIER_CR       = P_TS_HIER_CR

           E_TS_CHABASNM_CR   = P_TS_CHABASNM_CR

           E_T_AGGREGATE_CR   = P_T_AGGREGATE_CR

           E_TS_TREXAGGR_CR   = P_TS_TREXAGGR_CR

           E_TSX_MSG_CR       = P_TSX_MSG_CR.

       DESCRIBE TABLE P_TS_STATE_CR LINES LV_COUNT.

       IF ( LV_COUNT = 1 ) OR ( LV_COUNT = 0 ).

         CLEAR: LV_CHANGERUNMONI, LV_STATUS_CHANGERUNMONI.

         REFRESH: LT_HTML_RUNACR, LT_HTML_FAILEDACR.

         LV_CHANGERUNMONI = ‘<TD> No ACR Is Currently Running</TD>’.

         LV_STATUS_CHANGERUNMONI = ‘<TD ALIGN=”CENTER”><IMG SRC=”SUCCESS.PNG”/></TD>’.

         APPEND LV_CHANGERUNMONI TO LT_HTML_RUNACR.

       ELSE.

         CLEAR: LV_CHANGERUNMONI, LV_STATUS_CHANGERUNMONI.

         REFRESH: LT_HTML_RUNACR, LT_HTML_FAILEDACR.

         CLEAR: LV_COUNTER.

         APPEND ‘<br>’ TO LT_HTML_RUNACR.

         APPEND ‘<table><tr><th>Change Run ID</th>’ TO LT_HTML_RUNACR.

         APPEND ‘<th>Running</th>’ TO LT_HTML_RUNACR.

         APPEND ‘<th>Start time</th>’ TO LT_HTML_RUNACR.

         APPEND ‘<th>User </th>’ TO LT_HTML_RUNACR.

         APPEND ‘<th>Object Name</th>’ TO LT_HTML_RUNACR.

         APPEND ‘</tr>’ TO LT_HTML_RUNACR.

         LOOP AT P_TS_STATE_CR[] ASSIGNING <FS_ACR>.

           LV_COUNTER = LV_COUNTER.

           APPEND ‘<tr>’ TO LT_HTML_RUNACR.

           APPEND ‘<td>’ TO LT_HTML_RUNACR.

           LV_COUNTER = LV_COUNTER + 1.

           APPEND LV_COUNTER TO LT_HTML_RUNACR.

           APPEND ‘</td>’ TO LT_HTML_RUNACR.

           APPEND ‘<td>’ TO LT_HTML_RUNACR.

           APPEND <FS_ACR>CNSID TO LT_HTML_RUNACR.

           APPEND ‘</td>’ TO LT_HTML_RUNACR.

           APPEND ‘<td>’ TO LT_HTML_RUNACR.

           APPEND <FS_ACR>RUNNING TO LT_HTML_RUNACR.

           IF <FS_ACR>RUNNING NE ‘X’ AND <FS_ACR>RUNNING NE .

             APPEND <FS_ACR>RUNNING TO LT_HTML_FAILEDACR.

             APPEND <FS_ACR>CNSID TO LT_HTML_FAILEDACR.

           ENDIF.

           APPEND ‘</td>’ TO LT_HTML_RUNACR.

           APPEND ‘<td>’ TO LT_HTML_RUNACR.

           APPEND <FS_ACR>STARTTIME TO LT_HTML_RUNACR.

           APPEND ‘</td>’ TO LT_HTML_RUNACR.

           APPEND ‘<td>’ TO LT_HTML_RUNACR.

           APPEND <FS_ACR>USER TO LT_HTML_RUNACR.

           APPEND ‘</td>’ TO LT_HTML_RUNACR.

         ENDLOOP.

         CLEAR LV_COUNT.

         DESCRIBE TABLE LT_HTML_FAILEDACR[] LINES LV_COUNT.

         IF LV_COUNT NE 0.

           CLEAR: LV_CHANGERUNMONI_TEXT.

           CLEAR: LV_STATUS_CHANGERUNMONI, LV_STATUS_CHANGERUNMONI_IMG.

           LV_CHANGERUNMONI_TEXT = ‘<td>ACR is failed</td>’.

           LV_STATUS_CHANGERUNMONI_IMG = ‘<TD ALIGN=”CENTER”><IMG SRC=”error.PNG”/></TD>’.

           APPEND LV_CHANGERUNMONI TO LT_HTML_DESCACR.

         ELSEIF LV_COUNT EQ 0.

           CLEAR LV_STATUS_CHANGERUNMONI.

           LV_CHANGERUNMONI_TEXT = ‘<td>ACR Is Currently Running</td>’.

           LV_STATUS_CHANGERUNMONI_IMG = ‘<td ALIGN=”CENTER”><IMG SRC=”warning.png”/></td>’.

           APPEND LV_CHANGERUNMONI TO LT_HTML_DESCACR.

         ELSE.

           CLEAR LV_STATUS_CHANGERUNMONI.

           LV_CHANGERUNMONI = ‘<td> There are some objects for which ACR is Failed and also ACR is currently running for some objects</td>’.

           LV_STATUS_CHANGERUNMONI_IMG = ‘<td ALIGN=”CENTER”><IMG SRC=”warning.png”/>&<IMG SRC=”error.png”/></td>’.

           APPEND LV_CHANGERUNMONI TO LT_HTML_DESCACR.

         ENDIF.

         APPEND ‘</tr></table>’ TO LT_HTML_RUNACR.

       ENDIF.

       REFRESH: LT_HTML.

       APPEND ‘<html><head dir=”ltr” lang=”en”>’ TO LT_HTML.

*append ‘<link rel=”stylesheet” href=”/sap/public/test/testfirst.css”>’ to LT_HTML.

       APPEND ‘<style>’ TO LT_HTML.

       APPEND ‘body, td { font-family: lucida grande,tahoma,verdana,arial,sans-serif,Calibri (Body); font-size: 11px; } ‘ TO LT_HTML.

       APPEND ‘table.reference, { border-collapse: collapse; width: 40%:} ‘ TO LT_HTML.

       APPEND ‘tbody { display: table-row-group; vertical-align: middle; border-color: inherit; } ‘ TO LT_HTML.

       APPEND ‘table.reference th { color: white; background-color: #555; border: 1px solid #555; } ‘ TO LT_HTML.

       APPEND ‘table.reference th { padding: 3px; vertical-align: top; text-align: left; }’ TO LT_HTML.

       APPEND ‘tr { display: table-row; vertical-align: inherit; border-color: inherit; }’ TO LT_HTML.

       APPEND ‘table, th, td, { font-size: 100%; }’ TO LT_HTML.

       APPEND ‘table.reference td { border: 1px solid #d4d4d4; padding: 5px; padding-top: 7px; padding-bottom: 7px; vertical-align: top; }’ TO LT_HTML.

       APPEND ‘table.reference tr { background-color: #F6F4F0; }’ TO LT_HTML.

       APPEND ‘div.title { font-family: lucida grande,tahoma,verdana,arial,sans-serif,Calibri (Body); font-size: 11px; display: block; border-top: 4px solid #a7a59b;  height: 22px; line-height: 22px; padding: 14px 16px;’ to LT_HTML.

       append ‘ margin-bottom: 13px; clear:both; left: 20px; right: 30px;}’ to LT_HTML.

       APPEND ‘</style>’ TO LT_HTML.

       APPEND ‘</head>’ TO LT_HTML.

       APPEND ‘<body>’ TO LT_HTML.

       APPEND ‘<p>Hi All,</p>’  TO LT_HTML.

       APPEND ‘<p style=postion:; top-left:10px; color: #fff;>Please find the below updated Monitoring Category status information </p><br>’ TO LT_HTML.

       APPEND ‘<table class=reference notranslate width=”900″>’ TO LT_HTML.

       APPEND ‘<tbody><tr>’ TO LT_HTML.

       APPEND ‘<th style=width:8%>Monitoring Category</th> ‘ TO LT_HTML.

       APPEND ‘<th style=width:3%>Status</th>’ TO LT_HTML.

       APPEND ‘<th style=width:30%>Description</th>’ TO LT_HTML.

*append ‘<th style=width:10%>Remarks</th>’ to LT_HTML.

       APPEND ‘</tr>’ TO LT_HTML.

       APPEND ‘<tr>’ TO LT_HTML.

       APPEND ‘<td>CPU Utilization</td>’ TO LT_HTML.

       APPEND LV_STATUS  TO LT_HTML.

       APPEND ‘ <td>’ TO LT_HTML.

       APPEND LV_CPU_DESC TO LT_HTML.

       APPEND ‘%</td>’ TO LT_HTML.

       APPEND ‘</tr>’ TO LT_HTML.

       APPEND ‘<tr>’ TO LT_HTML.

       APPEND ‘<td>ACR</td>’ TO LT_HTML.

       IF LV_STATUS_CHANGERUNMONI NE .

         APPEND LV_STATUS_CHANGERUNMONI TO LT_HTML.

       ELSE.

         APPEND LV_STATUS_CHANGERUNMONI_IMG TO LT_HTML.

       ENDIF.

       APPEND LINES OF LT_HTML_RUNACR TO LT_HTML.

       APPEND ‘</tr>’ TO LT_HTML.

*      APPEND ‘<tr>’ TO LT_HTML.

*      APPEND ‘<td>DB Lock Issues</td>’ TO LT_HTML.

*      APPEND ‘<td width =”5%”></td>’ TO LT_HTML.

*      APPEND ‘<td></td>’ TO LT_HTML.

*      APPEND ‘</tr>’ TO LT_HTML.

*

*      APPEND ‘<tr>’ TO LT_HTML.

*      APPEND ‘<td>Deamon Jobs</td>’ TO LT_HTML.

*      APPEND ‘<td width =”5%”></td>’ TO LT_HTML.

*      APPEND ‘<td></td>’ TO LT_HTML.

       APPEND ‘</tr>’ TO LT_HTML.

       APPEND ‘<tr>’ TO LT_HTML.

       APPEND ‘<td>Primary Index</td>’ TO LT_HTML.

       APPEND LV_STATUS_MISSING_INDEX TO LT_HTML.

       APPEND LINES OF LT_HTML_MISIND TO LT_HTML.

       APPEND ‘</tr>’ TO LT_HTML.

       APPEND ‘<tr>’ TO LT_HTML.

       APPEND ‘<td>Roll Up Job</td>’ TO LT_HTML.

       APPEND LV_STATUS_ROLLUP TO LT_HTML.

       APPEND ‘<td>’ TO LT_HTML.

       APPEND LINES OF LT_HTML_ROLLUP TO LT_HTML.

       APPEND ‘</td>’ TO LT_HTML.

       APPEND ‘</tr>’ TO LT_HTML.

*      APPEND ‘<tr>’ TO LT_HTML.

*      APPEND ‘<td>TREXADMIN</td>’ TO LT_HTML.

*      APPEND ‘<td width =”5%”></td>’ TO LT_HTML.

*      APPEND ‘<td></td>’ TO LT_HTML.

*      APPEND ‘</tr>’ TO LT_HTML.

       APPEND ‘<tr>’ TO LT_HTML.

       APPEND ‘<td>Long Running Jobs</td>’ TO LT_HTML.

       APPEND  LV_STATUS_ACR TO LT_HTML.

       APPEND ‘<td>’ TO LT_HTML.

       APPEND LINES OF LT_HTML_ TO LT_HTML.

       APPEND ‘</td>’ TO LT_HTML.

       APPEND ‘</tr>’ TO LT_HTML.

       APPEND ‘<br>’ TO LT_HTML.

       APPEND ‘</tbody></table>’ TO LT_HTML.

       APPEND ‘<table><tr>’ TO LT_HTML.

       APPEND ‘<td>Thanks –  ONEBI SUPPORT</td><br>’ TO LT_HTML.

       APPEND ‘</tr> </table>’ TO LT_HTML.

       APPEND ‘</body></html>’ TO LT_HTML.

* t_body =  zjobselect_joblist_it.

       CLEAR GR_DOCUMENT.

* Create document email body content

       GR_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(

                      I_TYPE    = ‘HTM’

                       I_TEXT    = LT_HTML

                       I_IMPORTANCE = ‘5’

                       I_SUBJECT = GC_SUBJECT ).

*

*——————————————————————–*

*Image from MIME

*——————————————————————–*

       DATA: O_MR_API         TYPE REF TO IF_MR_API.

       DATA IS_FOLDER TYPE BOOLE_D.

       DATA L_IMG1 TYPE XSTRING.

       DATA L_IMG2 TYPE XSTRING.

       DATA L_IMG3 TYPE XSTRING.

       DATA L_IMG4 TYPE XSTRING.

       DATA L_LOIO TYPE SKWF_IO.

       DATA: LO_DOCUMENT   TYPE REF TO CL_DOCUMENT_BCS.

       CLEAR LO_DOCUMENT.

       IF O_MR_API IS INITIAL.

         O_MR_API = CL_MIME_REPOSITORY_API=>IF_MR_API~GET_API( ).

       ENDIF.

       CALL METHOD O_MR_API->GET

         EXPORTING

           I_URL              = ‘/SAP/PUBLIC/ZDEMO/success.png’

         IMPORTING

           E_IS_FOLDER        = IS_FOLDER

           E_CONTENT          = L_IMG1

           E_LOIO             = L_LOIO

         EXCEPTIONS

           PARAMETER_MISSING  = 1

           ERROR_OCCURED      = 2

           NOT_FOUND          = 3

           PERMISSION_FAILURE = 4

           OTHERS             = 5.

       CALL METHOD O_MR_API->GET

         EXPORTING

           I_URL              = ‘/SAP/PUBLIC/ZDEMO/error.png’

         IMPORTING

           E_IS_FOLDER        = IS_FOLDER

           E_CONTENT          = L_IMG2

           E_LOIO             = L_LOIO

         EXCEPTIONS

           PARAMETER_MISSING  = 1

           ERROR_OCCURED      = 2

           NOT_FOUND          = 3

           PERMISSION_FAILURE = 4

           OTHERS             = 5.

       CALL METHOD O_MR_API->GET

         EXPORTING

           I_URL              = ‘/SAP/PUBLIC/ZDEMO/warning.png’

         IMPORTING

           E_IS_FOLDER        = IS_FOLDER

           E_CONTENT          = L_IMG3

           E_LOIO             = L_LOIO

         EXCEPTIONS

           PARAMETER_MISSING  = 1

           ERROR_OCCURED      = 2

           NOT_FOUND          = 3

           PERMISSION_FAILURE = 4

           OTHERS             = 5.

       CALL METHOD O_MR_API->GET

         EXPORTING

           I_URL              = ‘/SAP/PUBLIC/ZDEMO/information.png’

         IMPORTING

           E_IS_FOLDER        = IS_FOLDER

           E_CONTENT          = L_IMG4

           E_LOIO             = L_LOIO

         EXCEPTIONS

           PARAMETER_MISSING  = 1

           ERROR_OCCURED      = 2

           NOT_FOUND          = 3

           PERMISSION_FAILURE = 4

           OTHERS             = 5.

*Convert XSTRING to ITAB

       DATA :LT_HEX1 TYPE SOLIX_TAB,

             LT_HEX2 TYPE SOLIX_TAB,

             LT_HEX3 TYPE SOLIX_TAB,

             LT_HEX4 TYPE SOLIX_TAB,

             LS_HEX LIKE LINE OF LT_HEX1,

             LV_IMG1_SIZE TYPE SOODOBJLEN,

             LV_IMG2_SIZE TYPE SOODOBJLEN,

             LV_IMG3_SIZE TYPE SOODOBJLEN,

             LV_IMG4_SIZE TYPE SOODOBJLEN.

       CLEAR : LT_HEX1, LT_HEX2, LT_HEX3, LT_HEX4, LS_HEX, LV_IMG1_SIZE, LV_IMG2_SIZE, LV_IMG3_SIZE, LV_IMG4_SIZE .

       WHILE L_IMG1 IS NOT INITIAL.

         LS_HEXLINE = L_IMG1.

         APPEND LS_HEX TO LT_HEX1.

         SHIFT L_IMG1 LEFT BY 255 PLACES IN BYTE MODE.

       ENDWHILE.

       WHILE L_IMG2 IS NOT INITIAL.

         LS_HEXLINE = L_IMG2.

         APPEND LS_HEX TO LT_HEX2.

         SHIFT L_IMG2 LEFT BY 255 PLACES IN BYTE MODE.

       ENDWHILE.

       WHILE L_IMG3 IS NOT INITIAL.

         LS_HEXLINE = L_IMG3.

         APPEND LS_HEX TO LT_HEX3.

         SHIFT L_IMG3 LEFT BY 255 PLACES IN BYTE MODE.

       ENDWHILE.

       WHILE L_IMG4 IS NOT INITIAL.

         LS_HEXLINE = L_IMG4.

         APPEND LS_HEX TO LT_HEX4.

         SHIFT L_IMG4 LEFT BY 255 PLACES IN BYTE MODE.

       ENDWHILE.

*Findthe Size of the image

       DESCRIBE TABLE LT_HEX1 LINES LV_IMG1_SIZE.

       DESCRIBE TABLE LT_HEX2 LINES LV_IMG2_SIZE.

       DESCRIBE TABLE LT_HEX3 LINES LV_IMG3_SIZE.

       DESCRIBE TABLE LT_HEX4 LINES LV_IMG4_SIZE.

       LV_IMG1_SIZE = LV_IMG1_SIZE * 255.

       LV_IMG2_SIZE = LV_IMG2_SIZE * 255.

       LV_IMG3_SIZE = LV_IMG3_SIZE * 255.

       LV_IMG4_SIZE = LV_IMG4_SIZE * 255.

*——————————————————————–*

*Attach Images

*——————————————————————–*

       GR_DOCUMENT->ADD_ATTACHMENT(

         EXPORTING

           I_ATTACHMENT_TYPE     ‘png’                  ” Document Class for Attachment

           I_ATTACHMENT_SUBJECT  ‘success’                ” Attachment Title

           I_ATTACHMENT_SIZE     LV_IMG1_SIZE           ” Size of Document Content

           I_ATT_CONTENT_HEX     LT_HEX1  ” Content (Binary)

       ).

       GR_DOCUMENT->ADD_ATTACHMENT(

         EXPORTING

           I_ATTACHMENT_TYPE     ‘png’                  ” Document Class for Attachment

           I_ATTACHMENT_SUBJECT  ‘error’                ” Attachment Title

           I_ATTACHMENT_SIZE     LV_IMG2_SIZE           ” Size of Document Content

           I_ATT_CONTENT_HEX     LT_HEX2  ” Content (Binary)

       ).

       GR_DOCUMENT->ADD_ATTACHMENT(

         EXPORTING

           I_ATTACHMENT_TYPE     ‘png’                  ” Document Class for Attachment

           I_ATTACHMENT_SUBJECT  ‘warning’                ” Attachment Title

           I_ATTACHMENT_SIZE     LV_IMG3_SIZE           ” Size of Document Content

           I_ATT_CONTENT_HEX     LT_HEX3  ” Content (Binary)

       ).

       GR_DOCUMENT->ADD_ATTACHMENT(

         EXPORTING

           I_ATTACHMENT_TYPE     ‘png’                  ” Document Class for Attachment

           I_ATTACHMENT_SUBJECT  ‘information’                ” Attachment Title

           I_ATTACHMENT_SIZE     LV_IMG4_SIZE           ” Size of Document Content

           I_ATT_CONTENT_HEX     LT_HEX4  ” Content (Binary)

       ).

       “Add document to send request

       CALL METHOD GR_SEND_REQUEST->SET_DOCUMENT( GR_DOCUMENT ).

       TRY.

         CALL METHOD GR_SEND_REQUEST->SET_SEND_IMMEDIATELY

           EXPORTING

             I_SEND_IMMEDIATELY = ‘X’.

*        CATCH CX_SEND_REQ_BCS INTO BCS_EXCEPTION .

**Catch exception here

       ENDTRY.

       DATA: LO_SENDER TYPE REF TO IF_SENDER_BCS VALUE IS INITIAL.

       TRY.

         LO_SENDER = CL_SAPUSER_BCS=>CREATE( SYUNAME ). “sender is the logged in user

* Set sender to send request

         GR_SEND_REQUEST->SET_SENDER(

         EXPORTING

         I_SENDER = LO_SENDER ).

*    CATCH CX_ADDRESS_BCS.

****Catch exception here

       ENDTRY.

       “Send email

       CALL METHOD GR_SEND_REQUEST->SEND(

         EXPORTING

           I_WITH_ERROR_SCREEN = ‘X’

         RECEIVING

           RESULT              = GV_SENT_TO_ALL ).

       IF GV_SENT_TO_ALL = ‘X’.

         WRITE ‘Email sent!’.

       ENDIF.

       “Commit to send email

       COMMIT WORK.

       “Exception handling

     CATCH CX_BCS INTO GR_BCS_EXCEPTION.

       WRITE:

         ‘Error!’,

         ‘Error type:’,

         GR_BCS_EXCEPTION->ERROR_TYPE.

   ENDTRY.

*****************************************************




To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply