cancel
Showing results for 
Search instead for 
Did you mean: 

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

brad_bohn
Active Contributor
0 Kudos

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.

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member181879
Active Contributor
0 Kudos

Moving this thread to CRM forum for the community benefit.

brad_bohn
Active Contributor
0 Kudos

I stopped the browser hang by suppressing the ProtectDoubleSubmit functionality using the onClientClick attribute of my Excel button definition and the following javascript code (borrowed from another SDN post on the BSP forum):


function stop_wait()
 {
 window.setTimeout('showProtectDoubleSubmitWindow(false)', 4000);
 window.setTimeout('showProtectActive = null', 4010);
 };

I am still using the CSV (vice XLS) format because of the added javascript problem. According to one of our Microsoft developers, based on a registry setting, Excel normally looks at the first 8 rows to determine how to render the content. Our setting here forces Excel to look at all rows, and the added javascript code is forcing all content into one cell for XLS. Though I will eventually track down where the javascript text is being added to the response, I'm not too concerened about it at this point. The users can ignore it or delete it.

Former Member
0 Kudos

Wow I had to raked my brain to remember all of this.

So then you are basically up and running in an OK fashion? You might want to check out the new CRM forum for more help.

brad_bohn
Active Contributor
0 Kudos

Yep, good to go with the exception of the added text at the bottom of the CSV file. Thanks for your previous response by the way. I did try it out but didn't have any luck with it in the WebClient. For the browser hang, according to SAP, the WebClient expects a specific type of response. If you change it, then the ProtectDoubleSubmit function that stops all input doesn't know when to quit. If you suppress it, then everything goes OK.

Former Member
0 Kudos

Good to know, did they say this is a bug or feature or anything like that?

Former Member
0 Kudos

Hi Brad.

I was having the same exact problem you had, I used the stop_wait function and it worked greate, although I still have the Javascript issue, but my question is, how did you do for preventing the pop-up window, where I can open or save the excel, from showing up at the state description, the big combobox at the top of the ICWC? you know?, becouse if I click there, the browser hang issue comes back.

Could you help me? Thanks in advance.

brad_bohn
Active Contributor
0 Kudos

Well, #1 and #3 are mostly solved. I went back to '.xls' instead of '.csv' and added horizontal tabs from the CHAR utilities class. It still does not work on my machine (all contents show in the first cell), but it seems to work OK for any other developer and the javascipt code is gone. Now, I guess I've got to narrow down the difference on my PC (If I can't I'll just chuck mine out the window and request a new one).

I still have the browser hang issue. Either there's an additional method I need to call from the view controller class or I need to stop that javascript 'Wait' message from popping up. Any ideas would be appreciated.

Thanks,

Brad

Former Member
0 Kudos

Have you checked out this weblog for the browser hang issue?

/people/sap.user72/blog/2004/11/10/bsphowto-generate-pdf-output-from-a-bsp