Skip to Content
author's profile photo Former Member
Former Member

Regarding EXCEL TO ITAB

hi friends,

I am reading records from EXcel Sheet to ITab through Function module.

but the file is in C drive and the path is like 'C:\wgt.xls'.

sucessfully its working but i am having one doubt and this is the my requirement also.

if there is no wgt.xls file in C drive i want to diaplay error message like please maintain weight file in C drive.

how to do this one. pls any one can help me

its very urgent

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 16, 2008 at 11:21 AM

    Hi,

    To check for excel file exists or not use the following code.

    DATA : gi_excel_file_exists TYPE i.

    CALL FUNCTION 'WS_QUERY'

    EXPORTING

    • ENVIRONMENT = ' '

    filename = p_xls

    query = 'FE'

    • WINID = ' '

    IMPORTING

    return = gi_excel_file_exists

    EXCEPTIONS

    inv_query = 1

    no_batch = 2

    frontend_error = 3

    OTHERS = 4.

    IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

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

    ENDIF.

    IF gi_excel_file_exists = 1.

    *use ur code

    else.

    WRITE : 'Following file does not exist :'.

    endif.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 16, 2008 at 11:54 AM

    hi,

    use the FM : F4_filename under the event Atselection screen onvalue request.

    so that you can choose the file name from front end.

    you can keep amsg like

    if sy-subrc ne 0.

    message e999 with 'Enter file name'.

    endif.

    Rgds.

    Umakanth

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 16, 2008 at 11:26 AM

    Hi ,

    Check the file existence using the following method, if sy-subrc fails raise an error message.

    • Checks if the file exists

    CALL METHOD cl_gui_frontend_services=>file_exist

    EXPORTING

    file = v_flnam

    RECEIVING

    result = l_result

    EXCEPTIONS

    cntl_error = 1

    error_no_gui = 2

    wrong_parameter = 3

    not_supported_by_gui = 4

    OTHERS = 5.

    IF sy-subrc NE 0.

    MESSAGE e035(zf).

    ENDIF.

    Rajesh.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 16, 2008 at 11:34 AM

    Hi,

    Check the code below:

    CONSTANTS: lc_file TYPE DYNPREAD-FIELDNAME      VALUE 'pa_file'.    
    * Calling the function to get file name
      CALL FUNCTION 'F4_FILENAME'
        EXPORTING
          program_name  = syst-cprog
          dynpro_number = syst-dynnr
          field_name    = lc_file
        IMPORTING
          file_name     = pa_file.
    
    SEARCH pa_file FOR "wgt.xls".
        IF sy-subrc NE 0.
          MESSAGE 000 TYPE E WITH "No Weight File".
          LEAVE LIST-PROCESSING.
        ENDIF.

    Note: File name should be constant here, other wise it wont work.

    Regards

    Kannaiah

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 16, 2008 at 11:44 AM

    Hi,

    You can use this code:

    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

    PARAMETERS: p_file TYPE rlgrap-filename.

    SELECTION-SCREEN END OF BLOCK b1.

    DATA : v_file TYPE string.

    ----


    • AT SELECTION SCREEN ON VALUE-REQUEST

    ----


    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

    CALL FUNCTION 'F4_FILENAME'

    EXPORTING

    program_name = syst-cprog

    dynpro_number = syst-dynnr

    field_name = ' '

    IMPORTING

    file_name = p_file.

    v_file = p_file.

    if v_file ne 'C:\wgt.xls'.

    give message as u required.

    else.

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    filename = v_file

    filetype = 'ASC'

    has_field_separator = 'X'

    TABLES

    data_tab = it_vendor

    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

    OTHERS = 17.

    IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

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

    ENDIF.

    endif.

    Regards

    Sandeep Reddy

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.