Skip to Content
Author's profile photo Former Member

BW Query results in HTML format

Use/Purpose:

E-mail BW Query results from ABAP program in HTML format

Proposed Solution:

BW provides a mechanism for sending query results as email using Information
Broadcasting. But user requirements sometime get really innovative &
difficult to handle with the standard delivered tools. If you need the ability
to execute a BW query and send the results as a HTML email from an ABAP program,
you can use the following code sample.

Procedure:

Below is the code sample

Code snippet:

    REFRESH IT_QUERY.

    CLEAR WA_QUERY.

    WA_QUERY-NAME     = ‘QUERY’.

    WA_QUERY-VALUE    = QUERY_NAME.

    APPEND WA_QUERY TO IT_QUERY.

    CLEAR WA_QUERY.

    WA_QUERY-NAME     = ‘CMD’.

    WA_QUERY-VALUE    = ‘LDOC’.

    APPEND WA_QUERY TO IT_QUERY.

    CLEAR WA_QUERY.

    WA_QUERY-NAME     = ‘VAR_NAME_1’.

    WA_QUERY-VALUE    = W_PUR_CALMONTH.

    APPEND WA_QUERY TO IT_QUERY.

    CLEAR WA_QUERY.

    WA_QUERY-NAME     = ‘var_operator_1’.

    WA_QUERY-VALUE    = ’BT’.

    APPEND WA_QUERY TO IT_QUERY.

    CLEAR WA_QUERY.

    WA_QUERY-NAME     = ‘var_sign_1’.

    WA_QUERY-VALUE    =  ‘I’.

    APPEND WA_QUERY TO IT_QUERY.

    CLEAR WA_QUERY.

    WA_QUERY-NAME     = ‘var_value_low_ext_1’.

    WA_QUERY-VALUE    = ‘022012’.

    APPEND WA_QUERY TO IT_QUERY.

    CLEAR WA_QUERY.

    WA_QUERY-NAME     = ‘var_value_high_ext_1’.

    WA_QUERY-VALUE    = ‘022012’.

    APPEND WA_QUERY TO IT_QUERY.

    CLEAR WA_QUERY.

    WA_QUERY-NAME     = ‘VAR_NAME_2’.

    WA_QUERY-VALUE    = Z_REPORT_FOR.

    APPEND WA_QUERY TO IT_QUERY.

    CLEAR WA_QUERY.

    WA_QUERY-NAME     = ‘VAR_NODE_IOBJNM_2’.

    WA_QUERY-VALUE    = ‘0HIER_NODE’.

    APPEND WA_QUERY TO IT_QUERY.

    CLEAR WA_QUERY.

    WA_QUERY-NAME     = ‘VAR_OPERATOR_2’.

    WA_QUERY-VALUE    = ‘EQ’.

    APPEND WA_QUERY TO IT_QUERY.

    CLEAR WA_QUERY.

    WA_QUERY-NAME     = ‘var_value_ext_2’.

    WA_QUERY-VALUE    = ‘CA6917’.

    APPEND WA_QUERY TO IT_QUERY.

    CLEAR:  E_R_PAGE, RESULT_CONTENT, CONTENT_TYPE,CONTENT_LENGTH.

    MOVE: ‘text/html’ TO CONTENT_TYPE .

    CLEAR: E_R_PAGE,RESULT_CONTENT .

    CALL FUNCTION ‘RRW3_WEBRFC’

      IMPORTING

        E_R_PAGE       = E_R_PAGE

      TABLES

        QUERY_STRING   = IT_QUERY

      CHANGING

        RETURN_CODE    = RETURN_CODE

        CONTENT_TYPE   = CONTENT_TYPE

        CONTENT_LENGTH = CONTENT_LENGTH.

    RESULT_CONTENT = E_R_PAGE->N_SX_OUTPUT-STRING.

    REPLACE

        ALL

      OCCURRENCES

         OF ‘/webrfc/bw30’

         IN RESULT_CONTENT

       WITH ‘/sap/bw/Mime/BEx’ .

    REPLACE

        ALL

      OCCURRENCES

         OF ‘mime/BEx/StyleSheets/’

         IN RESULT_CONTENT

       WITH ‘/sap/bw/mime/BEx/StyleSheets/’ .

    CLEAR TMP_STR .

    CONCATENATE

    ‘<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″>’

    CL_ABAP_CHAR_UTILITIES=>CR_LF

    ‘<script type=”text/javascript” src=”/sap/bw/Mime/BEx/JavaScript/JSBW_C_Std.js”></script>’

    CL_ABAP_CHAR_UTILITIES=>CR_LF

    INTO TMP_STR .

    REPLACE

        ALL

      OCCURRENCES OF

    ‘<meta http-equiv=”content-type” content=”text/html;charset=iso-8859-1″>’ IN RESULT_CONTENT WITH

    TMP_STR .

    CLEAR TMP_STR .

    REPLACE

       ALL

     OCCURRENCES

        OF ‘BWReports_ie5.css’

        IN RESULT_CONTENT

      WITH ‘BWReports_ie6.css’ .

    REPLACE

       ALL

     OCCURRENCES

        OF ‘Mime/BEx/StyleSheets/’

        IN RESULT_CONTENT

      WITH ‘/sap/bw/Mime/BEx/StyleSheets/’ .

    REPLACE

        ALL

      OCCURRENCES

         OF ‘Mime/BEx/Icons/’

         IN RESULT_CONTENT

       WITH ‘/sap/bw/Mime/BEx/Icons/’ .

    REPLACE

        ALL

      OCCURRENCES

         OF ‘/sap/bw/Mime/BEx/icons/’

         IN RESULT_CONTENT

       WITH ‘/sap/bw/Mime/BEx/Icons/’ .

    CLEAR TMP_STR .

    CONCATENATE W_LINK_A ‘/sap/bw/’ INTO TMP_STR .

    REPLACE

        ALL

      OCCURRENCES

          OF ‘/sap/bw/’

          IN RESULT_CONTENT

        WITH TMP_STR .

    CLEAR TMP_STR .

    CLEAR: CONLENGTH,CONLENGTHS .

    CONLENGTH = STRLEN( RESULT_CONTENT ) .

    CONLENGTHS = CONLENGTH .

    REFRESH TEXT_PUR .

    CALL FUNCTION ‘SCMS_STRING_TO_FTEXT’

      EXPORTING

        TEXT      = RESULT_CONTENT

      TABLES

        FTEXT_TAB = TEXT_PUR.

   SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).

    DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(

      I_TYPE = ‘HTM’

      I_TEXT =   D1

      I_SUBJECT = ‘Sourcing & Controls Scorecard for CSA Requirements’ ).

    CALL METHOD DOCUMENT->ADD_ATTACHMENT

      EXPORTING

        I_ATTACHMENT_TYPE    = ‘htm’

        I_ATTACHMENT_SUBJECT = ‘Purchasing query’

        I_ATT_CONTENT_TEXT   = TEXT_PUR.

Output Screen shot:

S1.png

Assigned tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Very Useful document!! Thanks for sharing this 🙂

      Author's profile photo Jayasri Vinoth
      Jayasri Vinoth

      Very informative... thanks for sharing priya...

      Author's profile photo Former Member
      Former Member

      It is really very informative

      Author's profile photo Former Member
      Former Member

      Its really a very useful Document Priya.. Thanks!!