Skip to Content
0
Mar 15, 2005 at 08:39 PM

Issues w/ CRM IC WebClient and Exporting View Results to Excel

35 Views

Hi All--

I am customizing the CRM IC WebClient by adapting most of the BP related views to meet our company's needs. One of the views I customized is the BuPaSelectCustomer view which displays BP search results. In addition to adding additional fields and sort capability to the grid, I have added 'Export to Excel' functionality using the solution provided in the forum FAQs. The issues I'm having are as follows:

1) I could not use the '.xls' format and the 'SEPARATED BY SPACE' addition in the CONCATENATE statement for the string build. When I did this, all of the contents showed up in one cell (even if I replaced the SPACE with a tab separator from the CHAR utilities class). I wound up using CSV instead. Any ideas?

2) My browser session hangs with the standard message 'Wait - your request is being processed', even after the Excel window is closed. Is there an additional method that needs to be called to close the loop?

3) The Excel file contains some javascript code a few lines below the cell contents - where is this added?

Any ideas or solutions on the above would be great. My code for the implementation class method is shown below. Sorry for the long post!

Thanks,

Brad

METHOD EH_ONEXCEL .

* Moved local type from ZCL_CRM_IC_BUPASELECTCUST_CN00 class
* Need to make dynamic later
  TYPES: BEGIN OF TY_SELCUST,
            BP_NUMBER        TYPE BU_PARTNER,
            NAME1            TYPE BU_NAMEOR1,
            CITY             TYPE AD_CITY1,
            POSTL_COD1       TYPE AD_PSTCD1,
            STREET           TYPE AD_STREET,
            HOUSE_NO         TYPE AD_HSNM1,
            REGION           TYPE REGIO,
            COUNTRY          TYPE LAND1,
            TELEPHONETEL     TYPE AD_TLNMBR,
            EXTENSIONTEL     TYPE AD_TLXTNS,
            E_MAILSMT        TYPE AD_SMTPADR,
            DISTRICT         TYPE AD_CITY2,
            MIDDLENAME       TYPE BU_NAMEMID,
            SECONDNAME       TYPE BU_NAMEPL2,
            HOME_CITY        TYPE AD_CITY3,
            SEARCHTERM1      TYPE BU_SORT1,
            SEARCHTERM2      TYPE BU_SORT2,
            REGIOGROUP       TYPE REGIOGROUP,
         END OF TY_SELCUST.

* Local structures
  DATA: LS_CUST              TYPE TY_SELCUST,
        LS_HEADER            TYPE CRMST_HEADER_OBJECT_BUIL,
        LS_ADDRESS           TYPE CRMST_ADDRESS_BUIL.

* Local tables
  DATA: LT_CUST              TYPE TABLE OF TY_SELCUST.

* Local variables
  DATA: LV_STRING            TYPE STRING,
        LV_TEMPSTRING        TYPE STRING,
        LV_XSTRING           TYPE XSTRING.

* Local references
  DATA: LR_WRAPPER           TYPE REF TO CL_BSP_WD_COLLECTION_WRAPPER,
        LR_BO                TYPE REF TO IF_BOL_BO_PROPERTY_ACCESS,
        LR_HDRENTITY         TYPE REF TO CL_CRM_BOL_ENTITY,
        LR_ADDRENTITY        TYPE REF TO CL_CRM_BOL_ENTITY,
        LR_EXT_INT           TYPE REF TO IF_BSP_WD_EXT_PROPERTY_ACCESS,
        LR_BUPACONTROLLER    TYPE REF TO ZCL_CRM_IC_BUPACONTROLLER_IMPL.

* Field symbols
  FIELD-SYMBOLS: <FS_FIELD>  TYPE ANY.


* Get reference to custom controller
  LR_BUPACONTROLLER ?= GET_CUSTOM_CONTROLLER( 'BuPaController' ).

  CHECK LR_BUPACONTROLLER IS BOUND.

* Get the customer collection wrapper
  LR_WRAPPER = TYPED_CONTEXT->CUSTOMERS->GET_COLLECTION_WRAPPER( ).

* Get the first item in the collection
  LR_BO = LR_WRAPPER->GET_FIRST( ).
  CHECK LR_BO IS BOUND.

* Build a new table with the sort column values
  DO.

*   Get the BOL entity (header)
    TRY.
        LR_HDRENTITY ?= LR_BO.

      CATCH CX_SY_MOVE_CAST_ERROR.

        TRY.
            LR_EXT_INT ?= LR_BO.
            LR_HDRENTITY  ?= LR_EXT_INT->GET_MODEL_NODE( ).
          CATCH CX_SY_MOVE_CAST_ERROR.
            EXIT.
        ENDTRY.

    ENDTRY.

    CHECK LR_HDRENTITY IS BOUND.

    TRY.

*       Get the related address entity
        LR_ADDRENTITY ?=
        LR_HDRENTITY->GET_RELATED_ENTITY('BuilStandardAddressRel').

      CATCH: CX_CRM_GENIL_MODEL_ERROR.

    ENDTRY.


*   Get the header attributes in a structure
    CALL METHOD LR_HDRENTITY->GET_PROPERTIES
      IMPORTING
        ES_ATTRIBUTES = LS_HEADER.

*   Get the address attributes in a structure
    CALL METHOD LR_ADDRENTITY->GET_PROPERTIES
      IMPORTING
        ES_ATTRIBUTES = LS_ADDRESS.

*   Move the attributes to the table work area
    MOVE-CORRESPONDING: LS_HEADER  TO LS_CUST,
                        LS_ADDRESS TO LS_CUST.

*   Add the record to the internal table
    APPEND LS_CUST TO LT_CUST.
    CLEAR  LS_CUST.

*   Check for next object
    LR_BO = LR_WRAPPER->GET_NEXT( ).
    IF NOT LR_BO IS BOUND.
      EXIT.
    ENDIF.

  ENDDO.

* Put the internal table contents into a string
  LOOP AT LT_CUST INTO LS_CUST.

    CLEAR LV_TEMPSTRING.

    DO.

      ASSIGN COMPONENT SY-INDEX OF STRUCTURE LS_CUST TO <FS_FIELD>.
      IF SY-SUBRC NE 0.
        EXIT.
      ENDIF.

      IF SY-INDEX EQ 1.
        LV_TEMPSTRING = <FS_FIELD>.
      ELSE.
        CONCATENATE LV_TEMPSTRING <FS_FIELD> INTO LV_TEMPSTRING
                                             SEPARATED BY ','.
      ENDIF.

    ENDDO.

    IF NOT LV_STRING IS INITIAL.
      CONCATENATE LV_STRING
                  LV_TEMPSTRING
                  CL_ABAP_CHAR_UTILITIES=>CR_LF
                  INTO LV_STRING.
    ELSE.
      CONCATENATE LV_TEMPSTRING
                  CL_ABAP_CHAR_UTILITIES=>CR_LF
                  INTO LV_STRING.
    ENDIF.

  ENDLOOP.

* Convert the string to binary format
  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      TEXT     = LV_STRING
      MIMETYPE = 'APPLICATION/MSEXCEL'
    IMPORTING
      BUFFER   = LV_XSTRING
    EXCEPTIONS
      FAILED   = 1
      OTHERS   = 2.

  RESPONSE->SET_HEADER_FIELD( NAME = 'content-type'
  VALUE = 'APPLICATION/MSEXCEL' ).

* Delete header fields to prevent cache errors
  RESPONSE->DELETE_HEADER_FIELD( NAME =
  IF_HTTP_HEADER_FIELDS=>CACHE_CONTROL ).

  RESPONSE->DELETE_HEADER_FIELD( NAME =
  IF_HTTP_HEADER_FIELDS=>EXPIRES ).

  RESPONSE->DELETE_HEADER_FIELD( NAME =
  IF_HTTP_HEADER_FIELDS=>PRAGMA ).

* Open Excel
  RESPONSE->SET_HEADER_FIELD(
            NAME  = 'content-disposition'
            VALUE = 'attachment; filename=bbtest.csv' ).

  RESPONSE->SET_DATA( DATA = LV_XSTRING ).

* Finished
  NAVIGATION->RESPONSE_COMPLETE( ).

ENDMETHOD.