cancel
Showing results for 
Search instead for 
Did you mean: 

Upload Excel file - WD vs traditional ABAP problem

Former Member
0 Kudos

Hi all,

I want to upload a simple Excel file to SAP via FileUpload UI Element.

The file structure is as follows (1 column with header line):

Header

Item line

Item line

...

I'm using FM 'TEXT_CONVERT_XLS_TO_SAP' as the following link does:

http://www.sapdevelopment.co.uk/file/file_upexcel.htm

When I test the program with traditional ABAP code, it goes well.

But when I embed the code into a WD program, it comes to an exception: Exception condition "CNTL_ERROR" raised.

Does anyone have knowledge about this situation? Every help is welcomed.

Best regards,

Nguyen

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Nguyen,

When you try to make use of the FM TEXT_CONVERT_XLS_TO_SAP in Web dynpro ABAP it doesn't work coz this FM tries to work with the standard R/3 custom container classes which are unavailable in Web Dynpro ABAP. But why do you want to use this FM after uploading your data into your context node using the FileUpload UI element?

Regards,

Uday

Former Member
0 Kudos

Hi Uday,

Thanks for your answer.

I know that when using FileUpload UIElement, the file content will be automatically transferred to data property, however in XSTRING format. The major problem here is every text in Excel file appeared as ???? in the data property, so it isn't helpful at all.

That's why I want to try the second approach: using a FM, providing with the file name retrieved by the FileUpload (in Filename property), to import the Excel content to an internal table. Finally I came to the obstacle as mentioned previous too.

So if you have some experienced or tips that can solve my problem, please tell me.

Thank you,

Nguyen

uday_gubbala2
Active Contributor
0 Kudos

Hi Nguyen,

Yes you are right the system does convert the data into XSTRING format before transferring the file contents to the data property of the ui element. You will have to then convert it from this format into your understandable format. For this you will have to make use of the CREATE & READ methods available in class CL_ABAP_CONV_IN_CE. Try going through the code snippet shown below for reference.

Regards,

Uday

DATA: XCONTENT TYPE XSTRING,
            NAME TYPE STRING,
            MIME_1 TYPE STRING.
 
  DATA: ROWS TYPE STANDARD TABLE OF STRING,
            WA_ROWS(300) TYPE C,
            CONV TYPE REF TO CL_ABAP_CONV_IN_CE.
 
   
WD_CONTEXT->GET_ATTRIBUTE( EXPORTING NAME = 'UPLOAD'  IMPORTING VALUE = XCONTENT ).
 
  WD_CONTEXT->GET_ATTRIBUTE( EXPORTING NAME = 'FILENAME'  IMPORTING VALUE = NAME ).
 
  WD_CONTEXT->GET_ATTRIBUTE( EXPORTING NAME = 'MIMETYPE'  IMPORTING VALUE = MIME_1 ).
 
" Creates a Conversion Instance
  CONV = CL_ABAP_CONV_IN_CE=>CREATE( INPUT = XCONTENT ).
 
" Converts and Increases Read Position in Input Buffer by 1
  CONV->READ( IMPORTING DATA = CONTENT ).
 
" Handle the carriage return's within the data
  SPLIT CONTENT AT CL_ABAP_CHAR_UTILITIES=>CR_LF INTO TABLE ROWS .

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Uday,

Thank you for your information.

I also found that there is no direct way to upload an Excel file into Web Dynpro. Just want to double-check if there have recently been some tips from experts

I've completed my application for uploading text file.

Thank you once more.

Best regards,

Nguyen

Former Member
0 Kudos

Hi nguyen tang ,

If your major tak is to upload a execl file the i feel you can do this by using file upload element.

Please refere the following thread

regards

Pankaj Giri

Former Member
0 Kudos

Hi Pankaj Giri and Uday,

Thank you for your solution.

However when I did as you both have suggested, there was an error: A character set conversion is not possible.. The error happened in the method READ of program CL_ABAP_CONV_IN_CE.

Could you please tell me how to overcome this obstacle?

Best regards,

Nguyen

uday_gubbala2
Active Contributor
0 Kudos

Hi Nguyen,

Did you specify the encoding type and all? Try go through this complete code fragment below which converts an XSTRING to a STRING.

Regards,

Uday

data : loc_conv type ref to cl_abap_conv_in_ce,
            var_string type string.
 
 
*        Convert XString to String
call method cl_abap_conv_in_ce=>create exporting input = item_filecontent
                                                                           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.

Former Member
0 Kudos

Hi Uday,

Thank you for your solution.

After I tried doing as your code did, I encountered no errors, however the XSTRING could not be converted in a readable format.

For clear understanding of my scenario, I hereby provide the Excel file's content and the return STRING after conversion:

- Excel file:

A B

1 BUKRS TXT50

2 0001 Laptop VAIO

3 0001 Camera CANON G10

4 RECO Mobile Softbank

5 RECO Badminton racket Yonex

- Data property (XSTRING): D0CF11E0A1B11AE1000000000000000000000000000000003E000300FEFF090006000000000000000000000001000000190000000000000000100000FEFFFFFF00000000FEFFFFFF0000000018000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

- Return STRING: ??#ࡱ#?################>###??##############################????####????########?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

It seems that there is no way to upload an Excel file to Web Dynpro, doesn't it?

Best regards,

Nguyen

uday_gubbala2
Active Contributor
0 Kudos

Hi Nguyen,

Did try reading around and learned that there is no direct way by which we can upload an excel file. We will have to first convert int into an tab delimited format and then the same procedure which you have been using now would work out for that. Check this [thread|; in which Thomas Jung clearly says,

"Now normal Excel content is saved in a binary, priopriatery Microsoft format. This can't really be processed very easily within ABAP. What usually happens is that the Excel file must be saved to some open format - like text tab delimited or XML. You then have the possibility to parse the file content and read it into an ABAP internal table. The exact procedure differs depending upon which format the Excel file is actually in."

Regards,

Uday

Former Member
0 Kudos

This message was moderated.