Skip to Content
avatar image
Former Member

Regarding .XLS file upload to database with " Filepload" ui element.

Hi Everybody,

I have a problem regarding uploading the data into the sap table with the help of " fileupload " ui element.When i am uploading the data with the help of fileupload ,it is storring it in context which is of type xstring.It is shown below.

data content type xstring.

data size type i.

wd_context->get_attribute( exporting name = 'FILECONTENT' importing value = content ).

size = xstrlen( content ).

wd_context->set_attribute( name = 'SIZE' value = size ).

Now I am calling the method " cl_abap_conv_in_ce ".

When I am giving this .xls file , the junk data is coming to the internal table "IT_SAAHELP".

CALL METHOD cl_abap_conv_in_ce=>create

EXPORTING

input = content

encoding = 'UTF-8'

replacement = '?'

ignore_cerr = abap_true

RECEIVING

conv = loc_conv.

*Read the file contents

TRY.

CALL METHOD loc_conv->read

IMPORTING

data = var_string.

CATCH cx_sy_conversion_codepage.

*Should ignore errors in code conversions

CATCH cx_sy_codepage_converter_init.

*Should ignore errors in code conversions

CATCH cx_parameter_invalid_type.

CATCH cx_parameter_invalid_range.

ENDTRY.

SPLIT var_string AT TAB INTO TABLE it_saahelp.

Now i want that the proper data should be there into the internal table from .xls file which i have provided.

Is there present any other method which will convert this xstring data to the internal table.

Is there are some classes and methods related to this which can be used here.

Or any other way to upload the data into the table in web dynpro abap with the .xls file.

Thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Mar 28, 2008 at 08:31 AM

    Hi Vaibhav,

    The bad news is: In almost all cases you are in a native browser environment you can forget all APIs, function modules, classes and so on containing the string GUI and/or ALV in their names, because all of them assume that they are in a SAPGUI environment.

    That is if you are in a browser environment your are "on the dark side of the moon" when trying to interpret xstring files.

    Any chances to move to the "bright side of the moon"? ... Yes and No - depending on your situation.

    If your users also have access to a SAPGUI you may embed your WDA application within a SAPGUI transaction and all the doors are opened for you...

    If this is not true (that's what I assume) I think you have the following chances:

    1. Tell your users to convert their excel sheets into CSV files before they upload them and then in your context you will find a comma-separated ASCII string ...

    2 Tell your users to convert their excel sheets into HTML or XML files by using "save as..." before they upload them and then in your context you will find XML / HTML strings ...

    3. use MS Office 2003 - as far as I know the office files from up to this versions are stored in some kind of an XML syntax (but I'm not really sure that this is a solution - never tried it).

    4. Try the awful and cumbersome and error-prone way to convert binary data to character data; but this can work only, if you are well aware of the structure and strings used in the excel files to be uploaded. In this case you can scan the xstring for the byte strings you are interested in ... like already mentioned: this is a job for "dead men walking ...". We have done it and it works - but with many conventions/restrictions.

    manipulate your excel binary string object with the following tools:

    Use Conversion Function Modules from Function Group SCMS_CONV like

    CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'

    CALL FUNCTION 'SCMS_BIN_TO_TEXT'

    Use ABAP string operations like

    SEARCH lv_xstring FOR lv_searchstring IN BYTE MODE STARTING AT lv_startpos

    CONCATENATE...INTO...

    REPLACE SECTION OFFSET ...

    and so on.

    Like already mentioned: It's a "dead man walking job" and you cannot be sure that the solution you create will work with the next excel release. The better ways are - like already mentioned:

    Tell your users to convert their excel sheets to csv before uploading them. this is the easiest way.

    Use MS Office 2003 and store your excel sheets in XML format.

    Reward pts if found helpfull 😊

    Sathish

    Add comment
    10|10000 characters needed characters exceeded