Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

XLS Download using Dataset.

Former Member
0 Likes
862

Hi Experts,

I am working on SAP version 4.6B

I've a query. During download on Application Server in XLS format using DATASET, the complete data appears in one column in XLS file and has to first convert into Text to Columns for proper display. Is there any option using DATASET, to get it download in separate columns as we donwload using simple download function in forground?

I am writing the code as below:

OPEN DATASET N_FILE FOR OUTPUT IN TEXT MODE MESSAGE MSG1.

IF SY-SUBRC EQ 0.

LOOP AT FINAL3.

TRANSFER FINAL3 TO N_FILE.

ENDLOOP.

CLOSE DATASET N_FILE.

ELSE.

WRITE:/10 'Process Failed'.

ENDIF.

Thanks in advance for expert comments.

Best Regards,

Anil

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
809

Hi,

Please follow this link.

The following code is used to upload data from Application server to Internal table.

Sample Code:

CONSTANTS: c_con_cret TYPE c VALUE

cl_abap_char_utilities=>horizontal_tab.

  • Transfer the data from file to Internal Table

OPEN DATASET pv_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc 0.

pv_not_open = 'X'.

ENDIF.

IF pv_not_open NE 'X'.

DO.

  • Read data from the file

READ DATASET pv_filename INTO wa_filedata.

IF sy-subrc = 0.

SPLIT wa_filedata AT c_con_cret INTO:

wa_filedata-zznmssrc wa_filedata-prodowner

wa_filedata-prodfam wa_filedata-prodid

wa_filedata-scripts wa_filedata-units

wa_filedata-dchnl wa_filedata-spbup.

APPEND wa_filedata TO it_filedata.

ELSE.

EXIT.

ENDIF.

ENDDO.

    • Close Dataset .

CLOSE DATASET pv_filename.

ENDIF.

Hope this will helps you

Regards,

Kiran

Hi Experts,

I am working on SAP version 4.6B

I've a query. During download on Application Server in XLS format using DATASET, the complete data appears in one column in XLS file and has to first convert into Text to Columns for proper display. Is there any option using DATASET, to get it download in separate columns as we donwload using simple download function in forground?

I am writing the code as below:

OPEN DATASET N_FILE FOR OUTPUT IN TEXT MODE MESSAGE MSG1.

IF SY-SUBRC EQ 0.

LOOP AT FINAL3.

TRANSFER FINAL3 TO N_FILE.

ENDLOOP.

CLOSE DATASET N_FILE.

ELSE.

WRITE:/10 'Process Failed'.

ENDIF.

Thanks in advance for expert comments.

Best Regards,

Anil

5 REPLIES 5
Read only

Former Member
0 Likes
810

Hi,

Please follow this link.

The following code is used to upload data from Application server to Internal table.

Sample Code:

CONSTANTS: c_con_cret TYPE c VALUE

cl_abap_char_utilities=>horizontal_tab.

  • Transfer the data from file to Internal Table

OPEN DATASET pv_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc 0.

pv_not_open = 'X'.

ENDIF.

IF pv_not_open NE 'X'.

DO.

  • Read data from the file

READ DATASET pv_filename INTO wa_filedata.

IF sy-subrc = 0.

SPLIT wa_filedata AT c_con_cret INTO:

wa_filedata-zznmssrc wa_filedata-prodowner

wa_filedata-prodfam wa_filedata-prodid

wa_filedata-scripts wa_filedata-units

wa_filedata-dchnl wa_filedata-spbup.

APPEND wa_filedata TO it_filedata.

ELSE.

EXIT.

ENDIF.

ENDDO.

    • Close Dataset .

CLOSE DATASET pv_filename.

ENDIF.

Hope this will helps you

Regards,

Kiran

Read only

Former Member
0 Likes
809

You could add delimiters before your your save to apps server file (not really an upload or download, since desktop is not involved!). To accomplish that, you could loop at your internal table, then put the row of data into a file with one field, with tabs (or other delimiter) between each field.

Search forum for how to do that, if you have not done this before.

Read only

0 Likes
809

Hi,

Thanks for support. I've tried comma as a separator with each field.

Also the file type CSV used instead of XLS.

It's working as per testing in Development & Quality server from my end.

Once testing comfirmation from end user, I'll update you all.

Thanks again.

Regards,

Anil

Read only

0 Likes
809

Hi Dave,

As per my query, I am able to download all the columns separately without any shifting of data.

Now only issue comes in for description fields.

As per different lengths, data alignment has been disturbed.

Example:

Item Item Description Item Group Item Group Description UOM Std. Cost

1GX5-50-577 RUN. CAPACITOR A21 Others EA 0.01

08NA30033 HISTORY CARD A21 Others EA 10

05B06-00-339 DISCHARGE VALVE A18 Valves & Regulators EA 12

It should come like

Item Item Description Item Group Item Group Description UOM Std. Cost

1GX5-50-577 RUN. CAPACITOR A21 Others EA 0.01

08NA30033 HISTORY CARD A21 Others EA 10

05B06-00-339 DISCHARGE VALVE A18 Valves & Regulators EA 12

Before calling dataset I've tried to fix the length as shown below:

MOVE 'Item ,' TO FINAL3-BISMT.

MOVE 'Item Description ,' TO FINAL3-MAKTX.

MOVE 'Item Group,' TO FINAL3-MATKL.

MOVE 'Item Group Description,' TO FINAL3-WGBEZ.

MOVE 'UOM,' TO FINAL3-MEINS.

MOVE 'Std. Cost ,' TO FINAL3-STPRS.

APPEND FINAL3.

similarly for data inside the loop.

Headings are coming ok now as they are fixed in width.

But data may vary in length.

Can you suggest something on this?

Best Regards,

Anil

Read only

0 Likes
809

Anil,

I think you are having a problem with trailing spaces while writing the file to application server.Before the open data set

use the below statement.It will keep the trailing blanks intact.Try and check the result.


PERFORM set_trail_blanks(saplgrap) USING ' '.

Thanks,

K.Kiran.