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

Error in excel upload on Application server using CG3Z

mohit_bansal3
SAP Mentor
SAP Mentor
0 Likes
1,585

Hello Experts,

I have to upload Excel using on Application Server.

I have tried it with CG3Z but Using AL11 when i view iy, Showing Lot of ##############.

I have to get excel data into my program also. But it is giving Dump while writing following code :

OPEN DATASET GV_FILENAME FOR INPUT IN text MODE ENCODING DEFAULT.

IF SY-SUBRC = 0 .

DO.

READ DATASET GV_FILENAME INTO GT_FILEDATA.

IF sy-subrc = 0.

APPEND GT_FILEDATA.

ELSE.

EXIT.

ENDIF.

ENDDO.

ELSEIF sy-subrc <> 0.

MESSAGE e005(ZCORP).

ENDIF.

CLOSE DATASET GV_FILENAME.

Please let me know, how to upload excel file correctly in Application Server and how to call it in the program.

Regards'

Mohit

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
802

Hi....

go through the sample code to upload file from presentation to application:

REPORT zupl_presentation_to_appl.

  • Local data ----------------------------------------------------------

DATA: l_filelength TYPE i.

types : begin of ty_dt_tab,

txt(4096) TYPE c,

end of ty_dt_tab.

DATA : lt_input TYPE ty_dt_tab OCCURS 0,

wa_input TYPE ty_dt_tab.

DATA: l_filename TYPE string.

DATA: l_auth_filename LIKE authb-filename,

e_flg_open_error TYPE boolean,

e_os_message TYPE c,

success(1),

lv_string TYPE string.

FIELD-SYMBOLS : <wa> type ty_dt_tab.

CONSTANTS:

sabc_act_read(4) VALUE 'READ',

sabc_act_write(5) VALUE 'WRITE'.

CONSTANTS: lc_fileformat_ascii LIKE rlgrap-filetype

VALUE 'ASC'.

CONSTANTS: lc_fileformat_binary LIKE rlgrap-filetype

VALUE 'BIN'.

PARAMETERS : frnt_end TYPE rcgfiletr-ftfront, "Front end path

appl_ser TYPE rcgfiletr-ftappl, "Application server path

overwrit TYPE c AS CHECKBOX. "Overwrite

START-OF-SELECTION.

  • Function body -------------------------------------------------------

  • init

e_flg_open_error = ' '.

CLEAR: e_os_message,success.

l_filename = frnt_end.

  • check the authority to write the file to the application server

l_auth_filename = appl_ser.

CALL FUNCTION 'AUTHORITY_CHECK_DATASET'

EXPORTING

  • PROGRAM =

activity = sabc_act_write

filename = l_auth_filename

EXCEPTIONS

no_authority = 1

activity_unknown = 2

OTHERS = 3.

IF NOT sy-subrc IS INITIAL.

CASE sy-subrc.

WHEN 1.

STOP.

    • no auhtority

  • RAISE ap_no_authority.

WHEN OTHERS.

STOP.

  • RAISE ap_file_open_error.

ENDCASE.

ENDIF.

TRY.

  • open the file on the application server for reading to check if the

  • file exists on the application server

OPEN DATASET appl_ser FOR INPUT MESSAGE e_os_message

IN TEXT MODE ENCODING NON-UNICODE.

IF sy-subrc IS INITIAL.

IF overwrit = ' '.

CLOSE DATASET appl_ser.

STOP.

ENDIF.

ENDIF.

CLOSE DATASET appl_ser.

  • catch exceptions

CATCH cx_root.

BREAK-POINT.

EXIT.

ENDTRY.

  • open dataset for writing

OPEN DATASET appl_ser FOR OUTPUT MESSAGE e_os_message

IN TEXT MODE ENCODING NON-UNICODE.

IF NOT sy-subrc IS INITIAL.

  • e_flg_open_error = true.

STOP.

ELSE.

lv_string = frnt_end.

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = lv_string

filetype = 'ASC'

has_field_separator = ' '

  • IMPORTING

  • filelength =

  • header =

CHANGING

data_tab = lt_input

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

not_supported_by_gui = 17

error_no_gui = 18

OTHERS = 19

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

stop.

ENDIF.

  • write the file to the application server

LOOP AT lt_input ASSIGNING <wa>.

TRANSFER <wa> TO appl_ser.

success = 'X'.

ENDLOOP.

  • close the dataset

CLOSE DATASET appl_ser.

ENDIF.

IF success = 'X'.

CLEAR success .

MESSAGE 'successfully uploaded.' TYPE 'S'.

ENDIF.

3 REPLIES 3
Read only

Former Member
0 Likes
802

Hi ,

What is your exact requirement ? If you want to upload a file to application server , use:

OPEN DATASET......

loop at t_data ( internal table containing data)

...

...

TRANSFER t_data TO file_name.

...

...

endloop.

CLOSE DATASET.....

Also do check the innumerable threads on SDN !

Regards,

Deepthi

Read only

Former Member
0 Likes
802

Hi Mohit,

The # symbol is the delimiter which seperates the data in the two consecutive cells in an excel when u see in the appl server.

when u go to the next cell with out writing any thing in the excel , even then it adds another # to the data in appl server..

and if no data is present in 2 and 2rd cell but present in only 1 and 4 then it gives 1st ###4th.

when u download the file from al11 on to ur system into an excel file then it will generate correctly, use

Function module ARCHIVFILE_SERVER_TO_CLIENT and check.

pls revert back if more information is required.

regards,

Dinesh.

Read only

Former Member
0 Likes
803

Hi....

go through the sample code to upload file from presentation to application:

REPORT zupl_presentation_to_appl.

  • Local data ----------------------------------------------------------

DATA: l_filelength TYPE i.

types : begin of ty_dt_tab,

txt(4096) TYPE c,

end of ty_dt_tab.

DATA : lt_input TYPE ty_dt_tab OCCURS 0,

wa_input TYPE ty_dt_tab.

DATA: l_filename TYPE string.

DATA: l_auth_filename LIKE authb-filename,

e_flg_open_error TYPE boolean,

e_os_message TYPE c,

success(1),

lv_string TYPE string.

FIELD-SYMBOLS : <wa> type ty_dt_tab.

CONSTANTS:

sabc_act_read(4) VALUE 'READ',

sabc_act_write(5) VALUE 'WRITE'.

CONSTANTS: lc_fileformat_ascii LIKE rlgrap-filetype

VALUE 'ASC'.

CONSTANTS: lc_fileformat_binary LIKE rlgrap-filetype

VALUE 'BIN'.

PARAMETERS : frnt_end TYPE rcgfiletr-ftfront, "Front end path

appl_ser TYPE rcgfiletr-ftappl, "Application server path

overwrit TYPE c AS CHECKBOX. "Overwrite

START-OF-SELECTION.

  • Function body -------------------------------------------------------

  • init

e_flg_open_error = ' '.

CLEAR: e_os_message,success.

l_filename = frnt_end.

  • check the authority to write the file to the application server

l_auth_filename = appl_ser.

CALL FUNCTION 'AUTHORITY_CHECK_DATASET'

EXPORTING

  • PROGRAM =

activity = sabc_act_write

filename = l_auth_filename

EXCEPTIONS

no_authority = 1

activity_unknown = 2

OTHERS = 3.

IF NOT sy-subrc IS INITIAL.

CASE sy-subrc.

WHEN 1.

STOP.

    • no auhtority

  • RAISE ap_no_authority.

WHEN OTHERS.

STOP.

  • RAISE ap_file_open_error.

ENDCASE.

ENDIF.

TRY.

  • open the file on the application server for reading to check if the

  • file exists on the application server

OPEN DATASET appl_ser FOR INPUT MESSAGE e_os_message

IN TEXT MODE ENCODING NON-UNICODE.

IF sy-subrc IS INITIAL.

IF overwrit = ' '.

CLOSE DATASET appl_ser.

STOP.

ENDIF.

ENDIF.

CLOSE DATASET appl_ser.

  • catch exceptions

CATCH cx_root.

BREAK-POINT.

EXIT.

ENDTRY.

  • open dataset for writing

OPEN DATASET appl_ser FOR OUTPUT MESSAGE e_os_message

IN TEXT MODE ENCODING NON-UNICODE.

IF NOT sy-subrc IS INITIAL.

  • e_flg_open_error = true.

STOP.

ELSE.

lv_string = frnt_end.

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = lv_string

filetype = 'ASC'

has_field_separator = ' '

  • IMPORTING

  • filelength =

  • header =

CHANGING

data_tab = lt_input

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

not_supported_by_gui = 17

error_no_gui = 18

OTHERS = 19

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

stop.

ENDIF.

  • write the file to the application server

LOOP AT lt_input ASSIGNING <wa>.

TRANSFER <wa> TO appl_ser.

success = 'X'.

ENDLOOP.

  • close the dataset

CLOSE DATASET appl_ser.

ENDIF.

IF success = 'X'.

CLEAR success .

MESSAGE 'successfully uploaded.' TYPE 'S'.

ENDIF.