GUI_UPLOAD or KD_GET_FILENAME_ON_F4

Hi All,
Could you please tell me which function module is very useful for F4 help.
REgards,
AMAR

hi,
hi for F4 value for local directory. even you can use 'F4_FILENAME'
at selection-screen on value-request for p_file.
call function 'WS_FILENAME_GET'
    exporting
        def_filename = space
        def_path = p_file           "File name
        mask = ',*.*.'
        mode = 'O'
        title = title
    importing
        filename = p_file     ""File name
        rc = dummy
    exceptions
        inv_winsys = 04
        no_batch = 08
        selection_cancel = 12
        selection_error = 16.
if sy-subrc ne 0.
    message i872(5g).
endif.
Regards,
Prabhudas

Similar Messages

  • Error while using the function module GUI_UPLOAD

    Hi,
    My requirement is to upload the data from .txt file into internal table.
    I have given my code like this
    PARAMETERS: p_fname LIKE rlgrap-filename.
    data: begin of gt_string occurs 0,
           record type char255,
          end of gt_string.
    AT SELECTION-SCREEN ON VALUE-REQUEST for p_fname.
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
       EXPORTING
        PROGRAM_NAME        = SYST-REPID
        DYNPRO_NUMBER       = SYST-DYNNR
        FIELD_NAME          = ' '
         STATIC              = 'X'
        MASK                = ' '
        CHANGING
          file_name           = p_fname
       EXCEPTIONS
         MASK_TOO_LONG       = 1
         OTHERS              = 2
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename                      = p_fname
         FILETYPE                      = 'ASC'
         HAS_FIELD_SEPARATOR           = 'X'
         HEADER_LENGTH                 = 0
        READ_BY_LINE                  = 'X'
        DAT_MODE                      = ' '
        CODEPAGE                      = ' '
        IGNORE_CERR                   = ABAP_TRUE
        REPLACEMENT                   = '#'
        CHECK_BOM                     = ' '
        NO_AUTH_CHECK                 = ' '
      IMPORTING
        FILELENGTH                    =
        HEADER                        =
        tables
          data_tab                      = gt_string
       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.
    Here I am getting dump error as 'Type conflict when calling a function module.
    The function module interface allows you to specify only fields
    of a particular type under "FILENAME". The field "P_FNAME" specified here has a different field type'.
    What would be the reason for this error?
    Can anyone help me?
    Regards,
    Hema

    see this sample program for F4 help
    *& Report  ZSD_EXCEL_INT_APP
    REPORT  ZSD_EXCEL_INT_APP.
    parameter: file_nm type localfile.
    types : begin of it_tab1,
            f1(20),
            f2(40),
            f3(20),
           end of it_tab1.
    data : it_tab type table of ALSMEX_TABLINE with header line,
           file type rlgrap-filename.
    data : it_tab2 type it_tab1 occurs 1,
           wa_tab2 type it_tab1,
           w_message(100)  TYPE c.
    at selection-screen on value-request for file_nm.
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      PROGRAM_NAME        = SYST-REPID
      DYNPRO_NUMBER       = SYST-DYNNR
      FIELD_NAME          = ' '
       STATIC              = 'X'
      MASK                = ' '
      CHANGING
       file_name           = file_nm
    EXCEPTIONS
       MASK_TOO_LONG       = 1
       OTHERS              = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    start-of-selection.
    refresh it_tab2[].clear wa_tab2.
    file = file_nm.
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
      EXPORTING
        filename                      = file
        i_begin_col                   = '1'
        i_begin_row                   =  '1'
        i_end_col                     = '10'
        i_end_row                     = '35'
      tables
        intern                        = it_tab
    EXCEPTIONS
       INCONSISTENT_PARAMETERS       = 1
       UPLOAD_OLE                    = 2
       OTHERS                        = 3
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    loop at it_tab.
      case it_tab-col.
       when '002'.
        wa_tab2-f1 = it_tab-value.
       when '004'.
        wa_tab2-f2 = it_tab-value.
      when '008'.
        wa_tab2-f3 = it_tab-value.
    endcase.
    at end of row.
      append wa_tab2 to it_tab2.
    clear wa_tab2.
      endat.
    endloop.
    data : p_file TYPE  rlgrap-filename value 'TEST3.txt'.
    OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    *--- Display error messages if any.
      IF sy-subrc NE 0.
        MESSAGE e001(zsd_mes).
        EXIT.
      ELSE.
    *---Data is downloaded to the application server file path
        LOOP AT it_tab2 INTO wa_tab2.
          TRANSFER wa_tab2 TO p_file.
        ENDLOOP.
      ENDIF.
    *--Close the Application server file (Mandatory).
      CLOSE DATASET p_file.
    loop at it_tab2 into wa_tab2.
      write : / wa_tab2-f1,wa_tab2-f2,wa_tab2-f3.
    endloop.

  • Error in gui_upload

    hi guru,
    iam doing some bdc program.. but ity will going to dump on gui_upload.. so plz help me.
    An exception occurred that is explained in detail
    The exception, which is assigned to class 'CX_SY_DYN_CALL_ILLEGAL_TYPE', was
    not caught in.
    procedure "F_UPLOAD_FILE" "(FORM)", nor was it propagated by a RAISING clause.
    Since the caller of the procedure could not have anticipated that the
    exception would occur, the current program is terminated.
    The reason for the exception is:
    The call to the function module "GUI_UPLOAD" is incorrect:
    The function module interface allows you to specify only
    fields of a particular type under "FILENAME".
    The field "P_P_FILE" specified here is a different
    field type
    SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-h01.                         
    PARAMETERS: p_file LIKE rlgra-filename                                                                               
    SELECTION-SCREEN : END OF BLOCK b1.                                                                                .----
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.                                                                               
    PERFORM f_get_file USING p_file.                                                                               
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'       
    *EXPORTING-                                                                               
    CHANGING                                                                               
    FILE_NAME           = p_p_file                                                                               
    endform.               
    form f_upload_file  using    p_p_file.                                                                               
    CALL FUNCTION 'GUI_UPLOAD'                                                                               
    EXPORTING                                                                               
    FILENAME                      = p_p_file                                                                               
    FILETYPE                      = 'DAT'                                                                               
    endform.

    Hi,
    Refer the program given below. it is working fine for me.
    make the paramerter as:
    pa_dfile TYPE rcgfiletr-ftfront.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_dfile.
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
        EXPORTING
          static        = 'X'
          mask          = '(Text file|*.TXT'
        CHANGING
          file_name     = pa_dfile
        EXCEPTIONS
          mask_too_long = 1
          OTHERS        = 2.
      IF sy-subrc <> 0.
        MESSAGE ID 'PG' TYPE 'E' NUMBER '016'
              WITH 'Error in F4 help'(005).
        "The provided file is not an excel sheet.
        RETURN.
      ENDIF.
    DATA: lv_filetype(10) TYPE c,
            lv_gui_sep TYPE c,
            lv_file_name TYPE string.
      lv_filetype = 'ASC'.
      lv_gui_sep = 'X'.
      lv_file_name = pa_dfile.
    FM call to upload file
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename                = lv_file_name
          filetype                = lv_filetype
          has_field_separator     = lv_gui_sep 
        TABLES
          data_tab                = gi_table
        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.
    Hope it helps.
    Regards
    Rajesh Kumar
    Edited by: Rajesh Kumar on Jul 24, 2009 7:11 AM

  • Excel data transfer into SAP internal table with GUI_UPLOAD

    hi all,
      i m using SRM4 system and i wanted to develop one report which will upload data from excel and convert it into IT.
    i know that many threads are posted on this topic.
    but my requirement is slight different. in the system only one function module is available that is "GUI_UPLOAD" and we want that user shd not save file as tab delimited before calling this fm. instead, program shd take care of all these things...
    please suggest something asap..
    helpful ans will be rewarded..
    thanks,
    jigs.

    Dear Jigs,
    Please go though the following lines of code:
    D A T A D E C L A R A T I O N *
    TABLES: ANEP,
    BKPF.
    TYPES: BEGIN OF TY_TABDATA,
    MANDT LIKE SY-MANDT, " Client
    ZSLNUM LIKE ZSHIFTDEPN-ZSLNUM, " Serial Number
    ZASSET LIKE ZSHIFTDEPN-ZASSET, " Original asset that was transferred
    ZYEAR LIKE ZSHIFTDEPN-ZYEAR, " Fiscal Year
    ZPERIOD LIKE ZSHIFTDEPN-ZPERIOD, " Fiscal Period
    ZSHIFT1 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 1
    ZSHIFT2 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 2
    ZSHIFT3 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 3
    END OF TY_TABDATA.
    Declaration of the Internal Table with Header Line comprising of the uploaded data.
    DATA: BEGIN OF IT_FILE_UPLOAD OCCURS 0.
    INCLUDE STRUCTURE ALSMEX_TABLINE. " Rows for Table with Excel Data
    DATA: END OF IT_FILE_UPLOAD.
    S E L E C T I O N - S C R E E N *
    SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME,
    BEGIN OF BLOCK B2 WITH FRAME.
    PARAMETERS: P_FNAME LIKE RLGRAP-FILENAME OBLIGATORY.
    SELECTION-SCREEN: END OF BLOCK B2,
    END OF BLOCK B1.
    E V E N T : AT S E L E C T I O N - S C R E E N *
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
    PROGRAM_NAME = SYST-REPID
    DYNPRO_NUMBER = SYST-DYNNR
    FIELD_NAME = ' '
    STATIC = 'X'
    MASK = '.'
    CHANGING
    FILE_NAME = P_FNAME
    EXCEPTIONS
    MASK_TOO_LONG = 1
    OTHERS = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    E V E N T : S T A R T - O F - S E L E C T I O N *
    START-OF-SELECTION.
    Upload Excel file into Internal Table.
    PERFORM UPLOAD_EXCEL_FILE.
    Organize the uploaded data into another Internal Table.
    PERFORM ORGANIZE_UPLOADED_DATA.
    E V E N T : E N D - O F - S E L E C T I O N *
    END-OF-SELECTION.
    *& Form UPLOAD_EXCEL_FILE
    text
    --> p1 text
    <-- p2 text
    FORM UPLOAD_EXCEL_FILE .
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
    FILENAME = P_FNAME
    I_BEGIN_COL = 1
    I_BEGIN_ROW = 3
    I_END_COL = 7
    I_END_ROW = 32000
    TABLES
    INTERN = IT_FILE_UPLOAD
    EXCEPTIONS
    INCONSISTENT_PARAMETERS = 1
    UPLOAD_OLE = 2
    OTHERS = 3
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " UPLOAD_EXCEL_FILE
    *& Form ORGANIZE_UPLOADED_DATA
    text
    --> p1 text
    <-- p2 text
    FORM ORGANIZE_UPLOADED_DATA .
    SORT IT_FILE_UPLOAD BY ROW
    COL.
    LOOP AT IT_FILE_UPLOAD.
    CASE IT_FILE_UPLOAD-COL.
    WHEN 1.
    WA_TABDATA-ZSLNUM = IT_FILE_UPLOAD-VALUE.
    WHEN 2.
    WA_TABDATA-ZASSET = IT_FILE_UPLOAD-VALUE.
    WHEN 3.
    WA_TABDATA-ZYEAR = IT_FILE_UPLOAD-VALUE.
    WHEN 4.
    WA_TABDATA-ZPERIOD = IT_FILE_UPLOAD-VALUE.
    WHEN 5.
    WA_TABDATA-ZSHIFT1 = IT_FILE_UPLOAD-VALUE.
    WHEN 6.
    WA_TABDATA-ZSHIFT2 = IT_FILE_UPLOAD-VALUE.
    WHEN 7.
    WA_TABDATA-ZSHIFT3 = IT_FILE_UPLOAD-VALUE.
    ENDCASE.
    AT END OF ROW.
    WA_TABDATA-MANDT = SY-MANDT.
    APPEND WA_TABDATA TO IT_TABDATA.
    CLEAR: WA_TABDATA.
    ENDAT.
    ENDLOOP.
    ENDFORM. " ORGANIZE_UPLOADED_DATA
    In the subroutine --> ORGANIZE_UPLOADED_DATA, data are organized as per the structure declared above.
    Regards,
    Abir
    Don't forget to award points *

  • GUI_Upload & GUI_Download for excel files

    Hi experts,
    I want to upload excel file into sap. i am trying with GUI_Upload function module. when i see the data it is filled with # and other special char. When i save the excel file as .txt file and then read the txt file. Now i am getting correct data. Is it possible to read Excel data using GUI_UPLOAD directly without changing .xls to .txt.
    Also, how to change data in  second or  third tab of excel file using GUI_Download.
    -RK

    Hi
    Actually ur file selection s wrong.
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
        EXPORTING
          PROGRAM_NAME  = SYST-REPID
          DYNPRO_NUMBER = SYST-DYNNR
          FIELD_NAME    = 'P_FNAME'
          STATIC        = 'X'
         MASK          = '*.txt'
        CHANGING
          FILE_NAME     = P_FNAME
        EXCEPTIONS
          MASK_TOO_LONG = 1
          OTHERS        = 2.
    Upload:
    CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          FILENAME                = LV_FNAME
          FILETYPE                = 'ASC'
          HAS_FIELD_SEPARATOR     = 'X'
        TABLES
          DATA_TAB                = IT_UEXBANK01
        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.

  • GUI_UPLOAD error

    Hi,
    I am getting a dump error while using the FM GUI_UPLOAD, i am using the FM KD_GET_FILENAME_ON_F4 to get the file name and the Parameter is defined as parameters: p_pcfile type rlgrap-filename. The error is  CALL_FUNCTION_CONFLICT_TYPE
    CX_SY_DYN_CALL_ILLEGAL_TYPE
    Is there any other way to over come this issue.
    Thanks
    Kumar

    hi check this simple example.....
    send the file to a string before giving it to the gui_upload.
    REPORT  ZVENKATTEST0.
    data: begin of itab occurs 0,
          a type c,
          c type c,
          b type i,
          end of itab.
    itab-a = 'a' .
    itab-c = ':'.
    itab-b = 1 .
    append itab .
    itab-a = 'b' .
    itab-c = ':'.
    itab-b = 2 .
    append itab .
    itab-a = 'c' .
    itab-c = ':'.
    itab-b = 3 .
    append itab .
    data: file type string .
    file = 'C:\Documents and Settings\venkatapp\Desktop\testing1.txt'.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        FILENAME                        = file
       FILETYPE                        = 'ASC'
       WRITE_FIELD_SEPARATOR           = ':'
      TABLES
        DATA_TAB                        = itab.

  • Bdc upload file data into internal table problem with gui_upload fm

    Hello experts,
    my coding is like this ..
    data : begin of itab occurs 0 .
    field1 like mara-matnr,
    field2......
    etc,
    end of itab.
    data: file1 type string.
    parameter :file like rlgrap-filename.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR file.
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
    static = 'X'
    mask = space
    field_name = 'FILE'
    CHANGING
    file_name = file.
    START-OF-SELECTION.
    FILE1 = FILE . "HERE I AM PASSING INTO STRING
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = FILE1
    FILETYPE = 'ASC'
    has_field_separator = 'X'
    TABLES
    data_tab = itab. " here the data is not populating from the file , it is giving the error like speified table not found.
    HERE i am getting the message like "specified table name not recgonised" . the data is not populating into the itab from the file.
    file structure is same as the internal table.
    I stored the file as .txt( ie in notepad).
    my file is like this..
    10000 200 323 sunndarrr.......
    i had a problem with this bdc , i am getting like "specified table name not recgonised" in the fm gui_upload while debugging.
    when i am using the ws_upload it is working fine.
    please guide me where i have done the mistake.
    thank you so much for all the replies.

    Hi,
    Have a look on the following code.
    TABLES: kna1.
    DATA: BEGIN OF itab1 OCCURS 0,
          str(255),
          END OF itab1.
    DATA: itab2 TYPE kna1 OCCURS 0 WITH HEADER LINE.
    CALL FUNCTION 'WS_UPLOAD'
      EXPORTING
        filename                = 'D:\ABAP EVE\ffile1.txt'
        filetype                = 'ASC'
      TABLES
        data_tab                = itab1
      EXCEPTIONS
        conversion_error        = 1
        file_open_error         = 2
        file_read_error         = 3
        invalid_type            = 4
        no_batch                = 5
        unknown_error           = 6
        invalid_table_width     = 7
        gui_refuse_filetransfer = 8
        customer_error          = 9
        no_authority            = 10
        OTHERS                  = 11.
    IF sy-subrc <> 0.
      WRITE:/ 'sorry'.
    ELSE.
      LOOP AT itab1.
        SPLIT itab1-str AT ',' INTO itab2-kunnr itab2-name1.
        APPEND itab2.
      ENDLOOP.
      IF sy-subrc = 0.
        LOOP AT itab2.
          WRITE:/ itab2-kunnr,itab2-name1.
          INSERT INTO kna1 VALUES itab2.
        ENDLOOP.
        IF sy-subrc = 0.
          WRITE:/ 'inserted'.
        ELSE.
          WRITE:/ 'not inserted'.
        ENDIF.
      ELSE.
        WRITE:/ 'fail'.
      ENDIF.
    ENDIF.
    Flat file:
    10001,Sadney
    10003,Yogesh
    20005,Madan
    1.U need to define internal table with one field of max size
    2.upload the flat file data into that internal table
    3.split that internal table data into another internal table(having fields)
    <REMOVED BY MODERATOR>
    thanks,
    Chandu
    Edited by: Alvaro Tejada Galindo on Apr 30, 2008 12:17 PM

  • Can 'GUI_UPLOAD'  to be used to upload excel file lonely?

    Hi experts,
    I wonder that can 'GUI_UPLOAD'  to be used to upload excel file lonely. I tried and use 'asc' as the L_FILETYPE, but the data uploaded contain many '###yyy'. But if I save the excel file as a txt file,
    the data can be uploaded by 'GUI_UPLOAD' correctly. So what is the problem?

    Excel files be can't uploaded using "GUI_UPLOAD".
    Use the FM "ALSM_EXCEL_TO_INTERNAL_TABLE"
    Try this code:
    * Upload data direct from excel.xls file to SAP
    REPORT ZEXCELUPLOAD.
    PARAMETERS: filename LIKE rlgrap-filename MEMORY ID M01,
                begcol TYPE i DEFAULT 1 NO-DISPLAY,
                begrow TYPE i DEFAULT 1 NO-DISPLAY,
                endcol TYPE i DEFAULT 100 NO-DISPLAY,
                endrow TYPE i DEFAULT 32000 NO-DISPLAY.
    * Tick don't append header
    PARAMETERS: kzheader AS CHECKBOX.
    DATA: BEGIN OF intern OCCURS 0.
            INCLUDE STRUCTURE  alsmex_tabline.
    DATA: END OF intern.
    DATA: BEGIN OF intern1 OCCURS 0.
            INCLUDE STRUCTURE  alsmex_tabline.
    DATA: END OF intern1.
    DATA: BEGIN OF t_col OCCURS 0,
           col LIKE alsmex_tabline-col,
           size TYPE i.
    DATA: END OF t_col.
    DATA: zwlen TYPE i,
          zwlines TYPE i.
    DATA: BEGIN OF fieldnames OCCURS 3,
            title(60),
            table(6),
            field(10),
            kz(1),
          END OF fieldnames.
    * No of columns
    DATA: BEGIN OF data_tab OCCURS 0,
           value_0001(50),
           value_0002(50),
           value_0003(50),
           value_0004(50),
           value_0005(50),
           value_0006(50),
           value_0007(50),
           value_0008(50),
           value_0009(50),
           value_0010(50),
           value_0011(50),
           value_0012(50),
           value_0013(50),
           value_0014(50),
           value_0015(50),
           value_0016(50),
           value_0017(50),
           value_0018(50),
           value_0019(50),
           value_0020(50),
           value_0021(50),
           value_0022(50),
           value_0023(50),
           value_0024(50),
           value_0025(50),
           value_0026(50),
           value_0027(50),
           value_0028(50),
           value_0029(50),
           value_0030(50),
           value_0031(50),
           value_0032(50),
           value_0033(50),
           value_0034(50),
           value_0035(50),
           value_0036(50),
           value_0037(50),
           value_0038(50),
           value_0039(50),
           value_0040(50),
           value_0041(50),
           value_0042(50),
           value_0043(50),
           value_0044(50),
           value_0045(50),
           value_0046(50),
           value_0047(50),
           value_0048(50),
           value_0049(50),
           value_0050(50),
           value_0051(50),
           value_0052(50),
           value_0053(50),
           value_0054(50),
           value_0055(50),
           value_0056(50),
           value_0057(50),
           value_0058(50),
           value_0059(50),
           value_0060(50),
           value_0061(50),
           value_0062(50),
           value_0063(50),
           value_0064(50),
           value_0065(50),
           value_0066(50),
           value_0067(50),
           value_0068(50),
           value_0069(50),
           value_0070(50),
           value_0071(50),
           value_0072(50),
           value_0073(50),
           value_0074(50),
           value_0075(50),
           value_0076(50),
           value_0077(50),
           value_0078(50),
           value_0079(50),
           value_0080(50),
           value_0081(50),
           value_0082(50),
           value_0083(50),
           value_0084(50),
           value_0085(50),
           value_0086(50),
           value_0087(50),
           value_0088(50),
           value_0089(50),
           value_0090(50),
           value_0091(50),
           value_0092(50),
           value_0093(50),
           value_0094(50),
           value_0095(50),
           value_0096(50),
           value_0097(50),
           value_0098(50),
           value_0099(50),
           value_0100(50).
    DATA: END OF data_tab.
    DATA: tind(4) TYPE n.
    DATA: zwfeld(19).
    FIELD-SYMBOLS: <fs1>.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
           EXPORTING
                mask      = '*.xls'
                static    = 'X'
           CHANGING
                file_name = filename.
    START-OF-SELECTION.
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           EXPORTING
                filename                = filename
                i_begin_col             = begcol
                i_begin_row             = begrow
                i_end_col               = endcol
                i_end_row               = endrow
           TABLES
                intern                  = intern
           EXCEPTIONS
                inconsistent_parameters = 1
                upload_ole              = 2
                OTHERS                  = 3.
      IF sy-subrc <> 0.
        WRITE:/ 'Upload Error ', SY-SUBRC.
      ENDIF.
    END-OF-SELECTION.
      LOOP AT intern.
        intern1 = intern.
        CLEAR intern1-row.
        APPEND intern1.
      ENDLOOP.
      SORT intern1 BY col.
      LOOP AT intern1.
        AT NEW col.
          t_col-col = intern1-col.
          APPEND t_col.
        ENDAT.
        zwlen = strlen( intern1-value ).
        READ TABLE t_col WITH KEY col = intern1-col.
        IF sy-subrc EQ 0.
          IF zwlen > t_col-size.
            t_col-size = zwlen.
    *                          Internal Table, Current Row Index
            MODIFY t_col INDEX sy-tabix.
          ENDIF.
        ENDIF.
      ENDLOOP.
      DESCRIBE TABLE t_col LINES zwlines.
      SORT intern BY row col.
      IF kzheader = 'X'.
        LOOP AT intern.
          fieldnames-title = intern-value.
          APPEND fieldnames.
          AT END OF row.
            EXIT.
          ENDAT.
        ENDLOOP.
      ELSE.
        DO zwlines TIMES.
          WRITE sy-index TO fieldnames-title.
          APPEND fieldnames.
        ENDDO.
      ENDIF.
      SORT intern BY row col.
      LOOP AT intern.
        IF kzheader = 'X'
        AND intern-row = 1.
          CONTINUE.
        ENDIF.
        tind = intern-col.
        CONCATENATE 'DATA_TAB-VALUE_' tind INTO zwfeld.
        ASSIGN (zwfeld) TO <fs1>.
        <fs1> = intern-value.
        AT END OF row.
          APPEND data_tab.
          CLEAR data_tab.
        ENDAT.
      ENDLOOP.
      CALL FUNCTION 'DISPLAY_BASIC_LIST'
           EXPORTING
                file_name     = filename
           TABLES
                data_tab      = data_tab
                fieldname_tab = fieldnames.
    *-- End of Program

  • How to ijntroduce PUSH Button in KD_GET_FILENAME_ON_F4

    Dear Experts,
    I am new to ABAP.
    I know how to use push button in Sel-Screen. But my requirement is:
    1)How can I use a push button in "KD_GET_FILENAME_ON_F4" so that on hitting the push button a PopUp screen appears.
    2) This Pop up screen should be a file directory screen from which I can select a file.
    3) This file on one click should get considered as "file_name" of the call function "KD_GET_FILENAME_ON_F4."
    Looking forward for advise from experts.
    Regards
    Chandan Kumar

    Dear Mr Klaus,
    Thanks for your reply. The method suggested by you will definitely help the user to directly open a file dialogue box. But I want the code to make it more simpler for the user. After I execute the code The use should get a Push Button. On hitting this push button a POP UP screen should appear. This pop up screen should lear us to the target folder.
    In your suggestion it was possible to open a folder path pop up screen. just I want to intriduce a PUSH button there. Also I want multi selection to be possible. In your suggestion above when I wrote the code as:
    DATA: file_str1 type string.
    data: it_tab TYPE STANDARD TABLE OF file_table,
          lw_file LIKE LINE OF it_tab,
          gd_subrc TYPE i.
    SELECTION-SCREEN begin of block blk with frame title text-100.
    SELECTION-SCREEN SKIP 2.
    parameters : p_file like rlgrap-filename .
    SELECTION-SCREEN end of block blk.
    *F4 input file
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
    window_title = 'Select only Text File'
    default_filename = '.azt'
    multiselection = 'X'
    CHANGING
    file_table = it_tab
    rc = gd_subrc.
    READ TABLE it_tab INTO lw_file INDEX 1.
    p_file = lw_file-FILENAME.
    Start-of-Selection.
      file_str1 = P_file.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                      = file_str1
    *    filename                      = '\\10.10.1.92\Volume_1\_projekte\Zeiterfassung-SAP\test.azt'
      tables
        data_tab                      = it_string
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    In the above code when I use Multiselection = 'X' then in the folder pop up multiselection is possible but the multiselection deosn't
    gets selected for upload.
    Looking forward for your suggestions.
    That is my requirement.
    Regards,
    Chandan

  • GUI_UPLOAD to upload flat file to internal table

    Hi Experts,
    I have to upload a flat file which has multiple records ,from a local server.The fields in records are ~ saperated.
    Presently i am only looking into uploading the flat file into internal table.
    I have done the following coding;
    TYPES: BEGIN OF gt_frmgt ,
           tablety  type c length 10 ,
           tablenm  type c length 30,
           numin  type  c length 2,
           END OF gt_frmgt.
    TYPES: begin of gt_frmgto,
             rec(1000) type c,
            end of gt_frmgto.
    DATA: Itgt_frmgt type table of gt_frmgt with header line.
    DATA: itgt_frmgto type table of gt_frmgto with header line.
    DATA: lfile_path type string.
    PARAMETERS: f_path type localfile.
    at selection-screen on value-request for f_path.
      call function 'KD_GET_FILENAME_ON_F4'
        EXPORTING
          static    = 'X'
        CHANGING
          file_name = f_path.
    start-of-selection.
      lfile_path = f_path.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          FILENAME                      = lfile_path
          FILETYPE                      = 'ASC'
         HAS_FIELD_SEPARATOR           = 'X'
        HEADER_LENGTH                 = 0
        READ_BY_LINE                  = 'X'
        DAT_MODE                      = ' '
        CODEPAGE                      = ' '
        IGNORE_CERR                   = ABAP_TRUE
        REPLACEMENT                   = '#'
        CHECK_BOM                     = ' '
        VIRUS_SCAN_PROFILE            =
        NO_AUTH_CHECK                 = ' '
      IMPORTING
        FILELENGTH                    =
        HEADER                        =
        TABLES
          DATA_TAB                      =  itgt_frmgto
      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.
      delete itgt_frmgto index 1.
      loop at itgt_frmgto.
        clear Itgt_frmgt.
        split itgt_frmgto-rec at cl_abap_char_utilities=>vertical_tab
        into Itgt_frmgt-tablety
        Itgt_frmgt-tablenm
        Itgt_frmgt-numin.
        append Itgt_frmgt.
      endloop.
      loop at Itgt_frmgt.
        write:/ Itgt_frmgt-tablety, Itgt_frmgt-tablenm, Itgt_frmgt-numin.
    The input file in Local path is ;
    XXXXXXX~~Export the invoice
    2~19980501~19980531
    // The first invoice:
    0~00130698114000010004119980512059611000276233.350.1711076.66????321000789010005???????????????????130601000000000??????????18? 3352051????532611-3357211???~~~
    0~????????176233.350.1711076.6676233.350~1510
    // The second invoice:
    0~00130698114000010007219980512059611000440482.000.175882.00????110108078901007?????????61? 68744479?????????????462088-07?????130601000000000??????????18? 3352051????532611-3357211???????????~~~
    0~????????139780.000.175780.0039780.000~1510
    0~????3.5"10702.000.17102.0070.20~1510
    and the output is :
    XXXXXXX~~
    2~~1998050
    // The fir
    0~00~1
    0~????~?
    // The sec
    0~00~1
    0~????~?
    0~????
    I am unable to understand why this split is happening .According to me the first 3 fields should be displayed without field saperater.
    It would be very much appreciated if any body has little idea about this.
    Thankx,
    Priya
    Message was edited by:
            Priya Parmeshwar Shiggaon
    Message was edited by:
            Priya Parmeshwar Shiggaon

    if it is one time upload then u can use transaction CG3Z n upload file on application server.
    u can tno use Gui_upload in background.
    Program to upload file via gui_upload in foreground  -(open fiel in Excel format and then make changes and save it as text tab file and upload tht file) -
    REPORT  Z_AMIT_BAPI
    no standard page heading line-size 255.
    parameters: p_file like rlgrap-filename default 'C:\temp\emp.txt'.
    data :begin of itab occurs 0,
             pernr(8),
             bdate(10),
             edate(10),
             mail(30) ,
            end of itab.
    Start-of-selection.
    Perform read_file.
    *&      Form  read_file
          text
    -->  p1        text
    <--  p2        text
    FORM read_file .
    DATA: full_file_name    TYPE string.
    full_file_name = p_file.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = full_file_name
        FILETYPE                      = 'ASC'
        HAS_FIELD_SEPARATOR           = ','
      HEADER_LENGTH                 = 0
      READ_BY_LINE                  = 'X'
      DAT_MODE                      = ' '
      CODEPAGE                      = ' '
      IGNORE_CERR                   = ABAP_TRUE
      REPLACEMENT                   = '#'
      CHECK_BOM                     = ' '
      NO_AUTH_CHECK                 = ' '
    IMPORTING
      FILELENGTH                    =
      HEADER                        =
      TABLES
        DATA_TAB                      = itab
    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 e000(000) WITH 'Upload-Error; RC:' sy-subrc.
    ENDIF.
    ENDFORM.                    " read_file
    reward points if helpfull
    amit

  • GUI_UPLOAD data problem

    we are uploading .DAT file in following program, after uploading the data into sap system, we are not able to see the complete data
    first row last two three fields are missing, the total field values length is 331 character, even if i given the 5000 character also same values is showing when i runtime.
    even i have dowloaded the tabtyp_tbl at runtime into .DAT format, i am not able to see the last field values
    please provide the reason behind this one
    SELECTION-SCREEN BEGIN OF BLOCK file WITH FRAME TITLE text-s01.
    PARAMETERS:
             r1 RADIOBUTTON GROUP rad1 DEFAULT 'X',
             p_file_u TYPE file DEFAULT
                       'XXX_TR.DAT',
             r2 RADIOBUTTON GROUP rad1,
             p_file TYPE localfile.
    SELECTION-SCREEN END OF BLOCK file.
    TYPES: BEGIN OF rectyp_tbl,
           data(331),                       "tarn72 "gb13032009 D
             data(5000),                       "gb13032009 I
           end(2),
      END OF rectyp_tbl.
      data : tabtyp_tbl TYPE standard TABLE OF rectyp_tbl.
                WITH NON-UNIQUE DEFAULT KEY
                INITIAL SIZE 500."gb13032009 D
                 INITIAL SIZE 1000."gb13032009 I
    DATA:
          l_gui_filename  TYPE string,     " Filetype
          l_gui_filetype(10)   TYPE c,     " Filetype
          l_gui_filz         TYPE i.       " Filesize
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
        EXPORTING
          mask      = ',TR.DAT file,tr*.dat'
          static    = 'X'
        CHANGING
          file_name = p_file.
        MOVE p_file TO l_gui_filename.
        MOVE 'ASC'      TO l_gui_filetype.
    start-of-selection.
    CALL FUNCTION 'GUI_UPLOAD'
          EXPORTING
            filename        = l_gui_filename
            filetype        = l_gui_filetype
    HAS_FIELD_SEPARATOR     = 'X'
          IMPORTING
            filelength      = l_gui_filz
          TABLES
            data_tab        = tabtyp_tbl
          EXCEPTIONS
            file_open_error = 01
            file_read_error = 02
            invalid_type    = 03
            unknown_error   = 04.
        CASE sy-subrc.
          WHEN 01.
            MESSAGE e000(fb) WITH 'Cannot open file'(125) p_file.
          WHEN 02.
            MESSAGE e000(fb) WITH 'Cannot read file'(126) p_file.
          WHEN 03.
            MESSAGE e000(fb) WITH 'File'(127) p_file
                              'has invalid file type'(128) l_gui_filetype.
          WHEN 04.
            MESSAGE e000(fb) WITH 'Unknown error, file'(129) p_file.
        ENDCASE.

    Hi ,
    There are few very little changes that I want to suggest you, please make the below made changes into your existing code and try to execute.
    data : tabtyp_tbl TYPE standard TABLE OF rectyp_tbl with header line.
    start-of-selection.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = l_gui_filename
    filetype = l_gui_filetype
    *HAS_FIELD_SEPARATOR = 'X' " REMOVE THIS PARAMETER
    *IMPORTING " REMOVE - NO NEED
    *filelength = l_gui_filz " REMOVE - NO NEED
    TABLES
    data_tab = tabtyp_tbl[] " BRACKETS
    EXCEPTIONS
    file_open_error = 01
    file_read_error = 02
    invalid_type = 03
    unknown_error = 04.
    CASE sy-subrc.
    WHEN 01.
    MESSAGE e000(fb) WITH 'Cannot open file'(125) p_file.
    WHEN 02.
    MESSAGE e000(fb) WITH 'Cannot read file'(126) p_file.
    WHEN 03.
    MESSAGE e000(fb) WITH 'File'(127) p_file
    'has invalid file type'(128) l_gui_filetype.
    WHEN 04.
    MESSAGE e000(fb) WITH 'Unknown error, file'(129) p_file.
    ENDCASE.
    Hope this will solve your issue.
    Regards,
    Ashish Arora

  • Upload data using 'GUI_UPLOAD'

    Hi all,
          l like to upload data from local file.
    My question is how to upload data from .xls file using function 'GUI_UPLOAD', and then transfert that data into local internal table.
    Bob

    hI,
    To Upload the excel file FM 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    BElow is the sample code.
    report ztest.
    types: begin of ttab ,
          fld1(30) type c,
          fld2(30) type c,
          fld3(30) type c,
          fld4(30) type c,
          fld5(30) type c,
          end of ttab.
    data: itab type table of ttab with header line.
    selection-screen skip 1.
    parameters: p_file type localfile default
                'C:\test.txt'.
    selection-screen skip 1.
    at selection-screen on value-request for p_file.
      call function 'KD_GET_FILENAME_ON_F4'
           exporting
                static    = 'X'
           changing
                file_name = p_file.
    start-of-selection.
      clear itab. refresh itab.
      perform upload_data.
      loop at itab.
        write:/ itab-fld1, itab-fld2, itab-fld3, itab-fld4, itab-fld5.
      endloop.
    Upload_Data
    form upload_data.
      data: file type  rlgrap-filename.
      data: xcel type table of alsmex_tabline with header line.
      file = p_file.
      call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           exporting
                filename                = file
                i_begin_col             = '1'
                i_begin_row             = '1'
                i_end_col               = '200'
                i_end_row               = '10000'
           tables
                intern                  = xcel
           exceptions
                inconsistent_parameters = 1
                upload_ole              = 2
                others                  = 3.
      loop at xcel.
        case xcel-col.
          when '0001'.
            itab-fld1 = xcel-value.
          when '0002'.
            itab-fld2 = xcel-value.
          when '0003'.
            itab-fld3 = xcel-value.
          when '0004'.
            itab-fld4 = xcel-value.
          when '0005'.
            itab-fld5 = xcel-value.
        endcase.
        at end of row.
          append itab.
          clear itab.
        endat.
      endloop.
    endform.
    Reward Points if it is Useful.
    Thanks,
    Manjunath MS

  • To upload an excel file from front end using GUI_UPLOAD

    Hi All,
    Please give me the code to upload data from front end to internal table only using GUI_UPLOAD.
    Thanks,
    Kumar

    Check this program , reward points if helpful
    *& Report  ZEXCEL_UPLOAD                                               *
    report  ZEXCEL_UPLOAD    message-id ZMSG.
    tables :T001.
    data : begin of ITAB occurs 0,
          BUKRS like T001-BUKRS,
          BUTXT like T001-BUTXT,
          ORT01 like T001-ORT01,
          LAND1 like T001-LAND1,
          WAERS like T001-WAERS,
          end of ITAB.
    data : WA_T001_EXCEL like ITAB.
    data : IT_T001_EXCEL like standard table of WA_T001_EXCEL.
    data IT_TEXT like ITAB occurs 0 with header line.
    data : IT_RETURN  like standard table of ALSMEX_TABLINE,
           WA_RETURN like ALSMEX_TABLINE,
            WA_RETURNS like ALSMEX_TABLINE.
    data : V_FILE type STRING,V_MASK(10) type C.
    selection-screen  begin of block B1 with frame title TEXT-001.
    parameters P_FILE like RLGRAP-FILENAME .
    selection-screen end of block B1.
    selection-screen  begin of block B2 with frame title TEXT-002.
    parameter : R_TXT  radiobutton group G1 default 'X' user-command C1,
                R_EXCEL radiobutton group G1.
    selection-screen end of block B2.
    at selection-screen on value-request for P_FILE.
      if R_TXT = 'X'.
        V_MASK = '*TXT'.
      elseif R_EXCEL = 'X'.
        V_MASK = '*XLS'.
      endif.
      call function 'KD_GET_FILENAME_ON_F4'
        exporting
          PROGRAM_NAME  = SYST-REPID
          DYNPRO_NUMBER = SYST-DYNNR
          MASK          = V_MASK
        changing
          FILE_NAME     = P_FILE.
    at selection-screen.
      translate P_FILE to upper case.
      if R_TXT = 'X'.
        search P_FILE for '*TXT'.
        if SY-SUBRC <> 0.
          message E011.
        endif.
      endif.
      if R_EXCEL = 'X'.
        search P_FILE for '*XLS'.
        if SY-SUBRC <> 0.
          message E012.
        endif.
      endif.
    start-of-selection.
      V_FILE = P_FILE.
      if R_TXT = 'X'.
        call function 'GUI_UPLOAD'
          exporting
            FILENAME            = V_FILE
            FILETYPE            = 'ASC'
            HAS_FIELD_SEPARATOR = 'X'
          tables
            DATA_TAB            = IT_TEXT.
        if SY-SUBRC eq 0.
          message I013 with V_FILE.
          loop at IT_TEXT .
        write :/ IT_TEXT-BUKRS color 4, IT_TEXT-BUTXT color 3,IT_TEXT-ORT01
        color 5,
        IT_TEXT-LAND1 color 2,IT_TEXT-WAERS color 1.
          endloop.
        endif.
      elseif R_EXCEL = 'X'.
        call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
          exporting
            FILENAME    = P_FILE
            I_BEGIN_COL = 1
            I_BEGIN_ROW = 1
            I_END_COL   = 4
            I_END_ROW   = 2
          tables
            INTERN      = IT_RETURN.
        if SY-SUBRC eq 0.
          message I014 with P_FILE.
          sort IT_RETURN by ROW COL.
          loop at IT_RETURN into WA_RETURNS.
            WA_RETURN = WA_RETURNS.
            case WA_RETURN-COL.
              when 1.
                WA_T001_EXCEL-BUKRS = WA_RETURN-VALUE.
              when 2.
                WA_T001_EXCEL-BUTXT = WA_RETURN-VALUE.
              when 3.
                WA_T001_EXCEL-ORT01 = WA_RETURN-VALUE.
              when 4.
                WA_T001_EXCEL-LAND1 = WA_RETURN-VALUE.
            endcase.
            at end of ROW.
              append WA_T001_EXCEL to IT_T001_EXCEL.
              clear : WA_RETURN, WA_T001_EXCEL.
            endat.
          endloop.
        endif.
        loop at IT_T001_EXCEL into WA_T001_EXCEL.
          write :/ WA_T001_EXCEL-BUKRS color 1, WA_T001_EXCEL-BUTXT color 2,
                   WA_T001_EXCEL-ORT01 color 3,WA_T001_EXCEL-LAND1 color 4.
        endloop.
      endif.

  • Difference between GUI_UPLOAD and WS_UPLOAD

    Hi,
    Please make me clear about the difference between GUI_UPLOAD and WS_UPLOAD. In which cases we need to use these modules...??
    Thanks,
    Satish

    I would suggest to always use the GUI_UPLOAD.  I say this because this is the function module which is used in the GUI_UPLOAD method of the class CL_GUI_FRONTEND_SERVICES.   Really, you should probably use the class/method instead of the function module.
      data: filename type string.
      filename = p_file.
      call method cl_gui_frontend_services=>gui_upload
             exporting
                  filename                = filename
                  filetype                = 'ASC'
             changing
                  data_tab                = iflatf
             exceptions
                  file_open_error         = 1
                  file_read_error         = 2
                  no_batch                = 3
                  gui_refuse_filetransfer = 4
                  no_authority            = 6
                  unknown_error           = 7
                  bad_data_format         = 8
                  unknown_dp_error        = 12
                  access_denied           = 13
                  others                  = 17.
    Regards,
    Rich Heilman

  • Gui_upload

    Hi  i have  one zprogram, it is written for to get the data from application server ,
    now i need to change the code to take the file from local drive.
    here iam giving the code ,could any one help me in this.
    INCLUDE zppiforecasttop.
    INCLUDE zppiforecastf01.
    SELECTION SCREEN EVENTS
    *Check the splitting rules against source file format
    AT SELECTION-SCREEN ON RADIOBUTTON GROUP r4.
    IF rb_spmon = 'X' AND rb_week = 'X'.
    MESSAGE e005(z1) WITH text-t13.
    ENDIF.
    IF rb_spday <> 'X' AND rb_daily = 'X'.
    MESSAGE e005(z1) WITH text-t14.
    ENDIF.
    F4 value help on filename field
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    CLEAR: w_choice, t_filelist.
    REFRESH: t_filelist.
    w_proc = 'proc'.
    w_txt = 'txt'.
    get and open logical filename
    CALL FUNCTION 'FILE_GET_NAME'
    EXPORTING
    logical_filename = p_lognam
    parameter_1 = i_para_1
    parameter_2 = i_para_2
    parameter_3 = i_para_3
    IMPORTING
    file_name = w_dir
    EXCEPTIONS
    file_not_found = 1
    OTHERS = 2.
    IF sy-subrc NE 0.
    MESSAGE e005(z1) WITH text-t18.
    ENDIF.
    CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
    EXPORTING
    dir_name = w_dir
    file_mask = '.'
    TABLES
    dir_list = t_files
    EXCEPTIONS
    invalid_eps_subdir = 1
    sapgparam_failed = 2
    build_directory_failed = 3
    no_authorization = 4
    read_directory_failed = 5
    too_many_read_errors = 6
    empty_directory_list = 7
    OTHERS = 8.
    *If the return code is not 0 exit from event
    IF sy-subrc <> 0.
    EXIT.
    ELSE.
    *Loop at list of files and convert to display format
    LOOP AT t_files.
    only show processed files with filename 'proc'
    SEARCH t_files-name FOR w_proc.
    IF sy-subrc = 0.
    t_filelist-name = t_files-name.
    t_filelist-size = t_files-size.
    APPEND t_filelist.
    ENDIF.
    only show processed files with filename 'txt'
    SEARCH t_files-name FOR w_txt.
    IF sy-subrc = 0.
    t_filelist-name = t_files-name.
    t_filelist-size = t_files-size.
    APPEND t_filelist.
    ENDIF.
    ENDLOOP.
    IF t_filelist[] IS INITIAL.
    EXIT.
    ENDIF.
    ENDIF.
    *Display list of available files in a popup screen
    CALL FUNCTION 'POPUP_WITH_TABLE_DISPLAY'
    EXPORTING
    endpos_col = '100'
    endpos_row = '23'
    startpos_col = '10'
    startpos_row = '5'
    titletext = 'Select File'
    IMPORTING
    choise = w_choice
    TABLES
    valuetab = t_filelist
    EXCEPTIONS
    break_off = 1
    OTHERS = 2.
    IF sy-subrc = 0.
    READ TABLE t_filelist INDEX w_choice.
    CONCATENATE w_dir t_filelist-name INTO p_file.
    ELSE.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Start of Selection
    START-OF-SELECTION.
    *Check that the filetype corresponds to the selection
    PERFORM check_file.
    *Upload the file by resolving logical filename.
    PERFORM upload_file.
    *Depending on the selection criteria, alter the input data into the
    *desired format and store.
    PERFORM populate_post_split_table.
    *Build the idoc of type SOPGEN01
    PERFORM post_idoc.
    Rename the file extension from '.txt' to '*.proc_yyyymmdd', if
    *reprocessing a file do nothing
    SEARCH p_file FOR '*txt'.
    IF sy-subrc = 0.
    PERFORM rename_file.
    ENDIF.
    End of Selection
    END-OF-SELECTION.
    *Output error report
    PERFORM error_report.
    Top of Page
    TOP-OF-PAGE.
    PERFORM top_of_page.
    &#9668;.........this is the first include........................
    &#9668;----
    INCLUDE ZPPIFORECASTTOP *
    TABLES
    TABLES: marc, "Plant Data for Material
    marm, "Units of Measure for Material
    edidd, "Data record (IDoc)
    edidc, "Control Segment
    e1lipm0, "General characteristic segment
    e1lipv0, "General version segment
    e1lipp0. "Performance measure segment
    SELECTION SCREEN
    SELECTION-SCREEN BEGIN OF BLOCK b1.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t01.
    PARAMETERS: rb_1000 RADIOBUTTON GROUP r1 DEFAULT 'X',
    rb_1005 RADIOBUTTON GROUP r1.
    SELECTION-SCREEN END OF BLOCK b2.
    SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-t02.
    PARAMETERS: rb_mgx RADIOBUTTON GROUP r2 DEFAULT 'X',
    rb_other RADIOBUTTON GROUP r2.
    SELECTION-SCREEN END OF BLOCK b3.
    SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-t03.
    PARAMETERS: rb_month RADIOBUTTON GROUP r3 DEFAULT 'X',
    rb_week RADIOBUTTON GROUP r3,
    rb_daily RADIOBUTTON GROUP r3.
    SELECTION-SCREEN END OF BLOCK b4.
    SELECTION-SCREEN BEGIN OF BLOCK b5 WITH FRAME TITLE text-t04.
    PARAMETERS: rb_spmon RADIOBUTTON GROUP r4 DEFAULT 'X',
    rb_spwk RADIOBUTTON GROUP r4,
    rb_spday RADIOBUTTON GROUP r4.
    SELECTION-SCREEN END OF BLOCK b5.
    SELECT-OPTIONS: so_datum FOR sy-datum, " (Planning time horizon)
    so_matnr FOR marc-matnr. " (Material Master)
    PARAMETERS: p_lognam LIKE filenameci-fileintern
    DEFAULT 'ZPPIFORECAST_FILENAME' NO-DISPLAY,
    p_file LIKE rlgrap-filename OBLIGATORY. "(Input file)
    SELECTION-SCREEN END OF BLOCK b1.
    TYPES
    TYPES: BEGIN OF workdate,
    datum LIKE sy-datum,
    day TYPE p,
    workday(1) TYPE c,
    END OF workdate.
    TYPES: BEGIN OF postsplit.
    INCLUDE STRUCTURE zppiforecast.
    TYPES: fromdat LIKE sy-datum,
    todat LIKE sy-datum,
    split_date LIKE sy-datum,
    split_value(10) TYPE c,
    flg_noscp(1) TYPE c,
    END OF postsplit.
    TYPES: BEGIN OF exception.
    INCLUDE STRUCTURE zppiforecast.
    TYPES: docnum TYPE docnum,
    message TYPE edi_statx_,
    END OF exception.
    TYPES: BEGIN OF filelist,
    name TYPE epsfilnam,
    size(10) TYPE c,
    END OF filelist.
    DATA
    DATA: t_files TYPE TABLE OF epsfili INITIAL SIZE 0 WITH HEADER LINE,
    i_file TYPE TABLE OF zppiforecast INITIAL SIZE 0 WITH HEADER LINE,
    t_exception TYPE TABLE OF exception INITIAL SIZE 0
    WITH HEADER LINE,
    i_post_split TYPE TABLE OF postsplit INITIAL SIZE 0
    WITH HEADER LINE,
    t_workdates TYPE TABLE OF workdate INITIAL SIZE 0
    WITH HEADER LINE,
    t_filelist TYPE TABLE OF filelist INITIAL SIZE 0 WITH HEADER LINE.
    DATA: t_edidc TYPE TABLE OF edidc INITIAL SIZE 0 WITH HEADER LINE,
    t_edidd TYPE TABLE OF edidd INITIAL SIZE 0 WITH HEADER LINE,
    t_edids TYPE TABLE OF edids INITIAL SIZE 0 WITH HEADER LINE.
    DATA: w_choice TYPE sy-tabix, "Index of chosen file
    w_line(100), "100 character string
    w_dir LIKE epsf-epsdirnam, "Directory path
    w_hiper LIKE t445p-hiper, "Forecast lower limit
    w_fuper LIKE t445p-fuper, "Forecast upper limit
    w_count TYPE i, "Counter
    w_total TYPE i, "Total
    w_start LIKE sy-datum, "Start date in the range
    w_end LIKE sy-datum, "End date in the range
    w_date LIKE sy-datum, "Curent Date
    w_first LIKE sy-datum, "First working date in range
    w_flg_noscp(1) TYPE c, "No SCP UoM flag
    w_days TYPE butag, "No of days
    w_day TYPE p, "Day of the week indicator
    w_value LIKE zppiforecast-value, "Record Value
    w_post_split TYPE postsplit, "Work area for post split table line
    w_docnum LIKE edidc-docnum, "IDOC number
    w_docnum_no_zero LIKE w_docnum, " IDOC number wthout zeros
    w_statva LIKE stacust-statva,
    w_error(1) TYPE c,
    w_matnr TYPE matnr,
    w_tabix TYPE sytabix,
    w_messg TYPE message,
    w_msgln TYPE i,
    w_todat LIKE sy-datum,
    w_fromdat LIKE sy-datum,
    w_lines TYPE i,
    w_count_idoc_errors TYPE i,
    w_count_recs_uploaded TYPE i,
    w_count_idoc_posted TYPE i.
    DATA: w_proc(4) TYPE c.
    DATA: w_txt(4) TYPE c.
    DATA: logsys LIKE tbdls-logsys.
    CONSTANTS
    CONSTANTS: c_uom LIKE marm-meinh VALUE 'SCP', "Unit of measure
    c_delim TYPE x VALUE '09',
    c_type LIKE rlgrap-filetype VALUE 'DAT',
    c_werks_1000 LIKE marc-werks VALUE '1000',
    c_werks_1005 LIKE marc-werks VALUE '1005',
    c_pltyp_805 LIKE t445p-sctyp VALUE 'Z_805',
    c_pltyp_810 LIKE t445p-sctyp VALUE 'Z_810',
    c_mestyp_805 TYPE edi_mestyp VALUE 'LIP805',
    c_mestyp_810 TYPE edi_mestyp VALUE 'LIP810',
    c_rcvprt TYPE edi_rcvprt VALUE 'LS',
    c_sndprn TYPE edi_sndprn VALUE 'WEBM_LS',
    c_sndprt TYPE edi_sndprt VALUE 'LS'.
    &#9668;..............this is the second include.................
    &#9668;----
    INCLUDE ZPPIFORECASTF01 *
    *& Form upload_file
    form upload_file.
    data: w_matnr like mara-matnr,
    w_datum like sy-datum.
    *Open file in read mode
    open dataset p_file for input in text mode.
    if sy-subrc = 0.
    do.
    clear: t_exception.
    *Read line of data into text string variable
    read dataset p_file into w_line.
    *If successful. append the internal file table
    if sy-subrc = 0.
    add 1 to w_count_recs_uploaded.
    *Split the string at delimiter into internal file table
    split w_line at c_delim into i_file-matnr
    i_file-datum
    i_file-value.
    call function 'CONVERSION_EXIT_MATN1_INPUT'
    exporting
    input = i_file-matnr
    importing
    output = w_matnr
    exceptions
    length_error = 1
    others = 2.
    i_file-index = sy-index.
    *Check that the date is in the correct format.
    call function 'CONVERT_DATE_TO_INTERN_FORMAT'
    exporting
    datum = i_file-datum
    dtype = 'DATS'
    importing
    error = w_error
    idate = i_file-datum
    messg = w_messg
    msgln = w_msgln.
    *If an error has occurred write entry to error table, otherwise append
    *record list
    if not w_error is initial.
    t_exception = i_file.
    t_exception-message = text-006.
    append t_exception.
    else.
    check i_file-datum in so_datum.
    append i_file.
    endif.
    else.
    exit.
    endif.
    enddo.
    else.
    message w005(z1) with 'File ' p_file ' cannot be opened'.
    endif.
    *Close the file
    close dataset p_file.
    endform. " upload_file
    *& Form process_monthly
    form process_monthly.
    data: w_mm type bumon,
    w_yyyy type bdatj.
    w_mm = i_file-datum+4(2).
    w_yyyy = i_file-datum(4).
    *Get the number of days in the month
    call function 'NUMBER_OF_DAYS_PER_MONTH_GET'
    exporting
    par_month = w_mm
    par_year = w_yyyy
    importing
    par_days = w_days.
    *Set date variable to first day
    w_date = i_file-datum.
    *Get the first working day in the month
    perform get_first_day.
    *Set date variable to last day in the month
    w_date = i_file-datum + w_days - 1.
    *Get the last working day in the month
    perform get_last_day.
    *Populate the post split table with monthly value
    i_post_split-split_value = w_value.
    i_post_split-matnr = i_file-matnr.
    i_post_split-fromdat = w_fromdat.
    i_post_split-todat = w_todat.
    i_post_split-datum = i_file-datum.
    i_post_split-value = i_file-value.
    i_post_split-index = i_file-index.
    i_post_split-split_date = i_file-datum.
    i_post_split-flg_noscp = w_flg_noscp.
    append i_post_split.
    endform. " process_monthly
    *& Form check_material
    form check_material using value(plant) value(pltyp).
    *Check that the material plant combination exists
    select single matnr from marc into w_matnr
    where matnr = i_file-matnr
    and werks = plant.
    *Check return code, if no record found, write to error table and delete
    if sy-subrc <> 0.
    w_tabix = sy-tabix.
    t_exception = i_file.
    t_exception-message = text-001.
    append t_exception.
    delete i_file index w_tabix.
    w_error = 'X'.
    exit.
    endif.
    Start DEVK931385
    if plant = c_werks_1000. "DEVK931385
    *Check that the material exists in the infotype hierarchy
    select single matnr from s805e into w_matnr where ssour = space
    and werks = plant
    and matnr = i_file-matnr.
    else. "DEVK931385
    *Check that the material exists in the infotype hierarchy S810e
    select single matnr from s810e into w_matnr where ssour = space
    and werks = plant
    and matnr = i_file-matnr.
    endif. "DEVK931385
    End DEVK931385
    if sy-subrc <> 0.
    w_tabix = sy-tabix.
    t_exception = i_file.
    t_exception-message = text-006.
    append t_exception.
    delete i_file index w_tabix.
    w_error = 'X'.
    exit.
    endif.
    *Get the forcast limits from info structure
    select single hiper fuper from t445p into (w_hiper, w_fuper)
    where sctyp = pltyp.
    *Determine start and end limits for forecasting based on current date
    w_start = sy-datum - w_hiper.
    Start DEVK931340
    w_end = sy-datum + w_fuper. "DEL
    w_end = sy-datum + ( ( w_fuper * 7 ) / 5 ).
    END DEVK931340
    endform. " check_material
    12:33:06 PM&#9668;&----
    *& Form process_weekly
    form process_weekly.
    data: w_mm type bumon,
    w_yyyy type bdatj.
    clear: w_total.
    w_date = i_file-datum.
    w_mm = i_file-datum+4(2).
    w_yyyy = i_file-datum(4).
    *If the souce file is in monthly format
    if rb_month = 'X'.
    *Get the number of days in the current month
    call function 'NUMBER_OF_DAYS_PER_MONTH_GET'
    exporting
    par_month = w_mm
    par_year = w_yyyy
    importing
    par_days = w_days.
    *Set date variable to last day in the month
    w_date = i_file-datum + w_days - 1.
    *Get the last working day in the month
    perform get_last_day.
    *Set date variable to first day
    w_date = i_file-datum.
    *Get the first working day in the month
    perform get_first_day.
    else.
    *Otherwise set for days in week
    w_days = 7.
    endif.
    do w_days times.
    *Clear the table of workdates
    clear: t_workdates.
    *Check if the day is a working day
    call function 'DATE_CHECK_WORKINGDAY'
    exporting
    date = w_date
    factory_calendar_id = 'GB'
    message_type = 'I'
    exceptions
    date_after_range = 1
    date_before_range = 2
    date_invalid = 3
    date_no_workingday = 4
    others = 5.
    *If successful, set the workday flag to (Y)es
    if sy-subrc = 0.
    t_workdates-datum = w_date.
    t_workdates-workday = 'Y'.
    *Increment the counter for total number of workdays
    add 1 to w_total.
    else.
    *Otherwise (N)o
    t_workdates-datum = w_date.
    t_workdates-workday = 'N'.
    endif.
    *Get the day in the week of the current date, (1 = Monday, 7 = Sunday)
    call function 'DAY_IN_WEEK'
    exporting
    datum = w_date
    importing
    wotnr = t_workdates-day.
    append t_workdates.
    add 1 to w_date.
    enddo.
    loop at t_workdates.
    *If the day is a workday
    if t_workdates-workday = 'Y'.
    *If the fromdate is blank, set to current date in loop (first working
    *day)
    if i_post_split-fromdat is initial.
    i_post_split-fromdat = t_workdates-datum.
    i_post_split-split_date = t_workdates-datum.
    endif.
    *Set variable to pick up last working date
    i_post_split-todat = t_workdates-datum.
    *Increment loop counter
    add 1 to w_count.
    endif.
    *If the day is a Sunday
    if ( ( t_workdates-day = 7 or t_workdates-datum+6(2) = w_days )
    and w_count <> 0 ).
    *Poplulate the post split table
    if rb_month = 'X'.
    i_post_split-fromdat = w_fromdat.
    i_post_split-todat = w_todat.
    endif.
    i_post_split-matnr = i_file-matnr.
    i_post_split-datum = i_file-datum.
    i_post_split-value = i_file-value.
    i_post_split-index = i_file-index.
    i_post_split-split_value = ( ( w_value / w_total ) * w_count ).
    i_post_split-flg_noscp = w_flg_noscp.
    append i_post_split.
    clear: w_count,
    i_post_split.
    endif.
    endloop.
    endform. " process_weekly
    *& Form get_first_day
    form get_first_day.
    do w_days times.
    call function 'DATE_CHECK_WORKINGDAY'
    exporting
    date = w_date
    factory_calendar_id = 'GB'
    message_type = 'I'
    exceptions
    date_after_range = 1
    date_before_range = 2
    date_invalid = 3
    date_no_workingday = 4
    others = 5.
    if sy-subrc = 0.
    w_fromdat = w_date.
    exit.
    endif.
    add 1 to w_date.
    enddo.
    endform. " get_first_day
    *& Form get_last_day
    form get_last_day.
    do w_days times.
    call function 'DATE_CHECK_WORKINGDAY'
    exporting
    date = w_date
    factory_calendar_id = 'GB'
    message_type = 'I'
    exceptions
    date_after_range = 1
    date_before_range = 2
    date_invalid = 3
    date_no_workingday = 4
    others = 5.
    if sy-subrc = 0.
    w_todat = w_date.
    exit.
    endif.
    subtract 1 from w_date.
    enddo.
    endform. " get_last_day
    12:33:30 PM&#9668;
    *& Form process_daily
    form process_daily.
    data: w_mm type bumon,
    w_yyyy type bdatj,
    new_w_date like w_date.
    clear: w_total.
    w_mm = i_file-datum+4(2).
    w_yyyy = i_file-datum(4).
    w_date = i_file-datum.
    if rb_month = 'X'.
    *Get the number of days in the current month
    call function 'NUMBER_OF_DAYS_PER_MONTH_GET'
    exporting
    par_month = w_mm
    par_year = w_yyyy
    importing
    par_days = w_days.
    *If the source file is in weekly format set to days in week
    elseif rb_week = 'X'.
    w_days = 7.
    else.
    *If source file is daily, set to day
    w_days = 1.
    endif.
    do w_days times.
    clear: t_workdates.
    *Check the current day is a workday
    call function 'DATE_CHECK_WORKINGDAY'
    exporting
    date = w_date
    factory_calendar_id = 'GB'
    message_type = 'I'
    exceptions
    date_after_range = 1
    date_before_range = 2
    date_invalid = 3
    date_no_workingday = 4
    others = 5.
    *If successful, set workday flag to (Y)es and append workday table
    if sy-subrc = 0.
    t_workdates-datum = w_date.
    t_workdates-workday = 'Y'.
    append t_workdates.
    *Increment total
    add 1 to w_total.
    START PKA01
    else.
    Add 1 to w_date and w_days to make it loop again until a the next work
    day is found!!!!!
    END PKA01
    if rb_daily = 'X'.
    new_w_date = w_date.
    while new_w_date ne ''.
    add 1 to new_w_date.
    *Check the current day is a workday
    call function 'DATE_CHECK_WORKINGDAY'
    exporting
    date = new_w_date
    factory_calendar_id = 'GB'
    message_type = 'I'
    exceptions
    date_after_range = 1
    date_before_range = 2
    date_invalid = 3
    date_no_workingday = 4
    others = 5.
    if sy-subrc = 0.
    t_workdates-datum = new_w_date.
    t_workdates-workday = 'Y'.
    append t_workdates.
    add 1 to w_total.
    exit.
    endif.
    endwhile.
    endif.
    endif.
    *Increment date
    add 1 to w_date.
    enddo.
    *Get the number of workdays in the period
    describe table t_workdates lines w_lines.
    *Get the first entry in the table
    read table t_workdates index 1.
    w_fromdat = t_workdates-datum.
    *Get the last entry in the table
    read table t_workdates index w_lines.
    w_todat = t_workdates-datum.
    loop at t_workdates.
    *Populate the post split table
    i_post_split-fromdat = w_fromdat.
    i_post_split-todat = w_todat.
    i_post_split-split_date = t_workdates-datum.
    i_post_split-matnr = i_file-matnr.
    i_post_split-datum = i_file-datum.
    i_post_split-value = i_file-value.
    i_post_split-index = i_file-index.
    i_post_split-split_value = w_value / w_total.
    i_post_split-flg_noscp = w_flg_noscp.
    START PKA01
    For daily sorce data which is split daily check that an entry doesnt
    already exist in the post split table for this date - only the fromdat
    is checked because for daily split fromdat = todat
    read table i_post_split into w_post_split
    with key matnr = i_file-matnr
    fromdat = i_file-datum
    split_date = t_workdates-datum.
    if sy-subrc = 0.
    ...an entry exist so add the new value to the existing one and update
    the table record
    i_post_split-split_value = i_post_split-split_value +
    w_post_split-split_value.
    append i_post_split.
    MODIFY i_post_split from w_post_split index sy-tabix.
    else.
    END PKA01
    append i_post_split.
    START PKA01
    endif.
    END PKA01
    endloop.
    endform. " process_daily
    *& Form check_range
    form check_range.
    *If file date is not in forcast range discard
    if i_file-datum < w_start or i_file-datum > w_end.
    w_tabix = sy-tabix.
    t_exception = i_file.
    t_exception-message = text-002.
    append t_exception.
    delete i_file index w_tabix.
    w_error = 'X'.
    endif.
    endform. " check_range
    *& Form check_uom
    form check_uom.
    *Get the alternative UoM for Material
    select single * from marm where matnr = i_file-matnr
    and meinh = c_uom.
    if sy-subrc = 0.
    w_value = ( i_file-value * ( marm-umren / marm-umrez ) ).
    else.
    w_value = i_file-value.
    w_flg_noscp = 'X'.
    endif.
    w_flg_noscp = 'X'. "jsa01
    endform. " check_uom
    *& Form check_first_day
    form check_first_day.
    *If the date is not the first of the month, copy to error table, delete
    *and end current loop process
    if i_file-datum+6(2) <> '01'.
    w_tabix = sy-tabix.
    t_exception = i_file.
    t_exception-message = text-003.
    append t_exception.
    delete i_file index w_tabix.
    w_error = 'X'.
    endif.
    endform. " check_first_day
    12:34:00 PM&#9668;&----
    *& Form check_monday
    form check_monday.
    call function 'DAY_IN_WEEK'
    exporting
    datum = i_file-datum
    importing
    wotnr = w_day.
    *If the day is not a monday, copy to error table, delete
    *and end current loop process
    if w_day <> 1.
    w_tabix = sy-tabix.
    t_exception = i_file.
    t_exception-message = text-004.
    append t_exception.
    delete i_file index w_tabix.
    w_error = 'X'.
    endif.
    endform. " check_monday
    *& Form populate_post_split_table
    form populate_post_split_table.
    *Sort the uploaded table by material and date
    sort i_file by matnr datum.
    loop at i_file.
    perform material_internal_format.
    *clear loop variables
    clear: w_hiper,
    w_fuper,
    w_count,
    w_error,
    w_fromdat,
    w_todat,
    w_flg_noscp,
    t_exception.
    *Clear the contents of the internal table which holds work days
    refresh: t_workdates.
    *If plant radiobutton is set
    if rb_1000 = 'X'.
    *Check the material/plant combination
    perform check_material using c_werks_1000 c_pltyp_805.
    else.
    *Check the material/plant combination
    perform check_material using c_werks_1005 c_pltyp_810.
    endif.
    if w_error = 'X'.
    continue.
    endif.
    *If the uploaded file is in monthly format
    if rb_month = 'X'.
    *Check that the record is for the first day of the month
    perform check_first_day.
    if w_error = 'X'.
    continue.
    endif.
    *Check the value is within the range for the infotype
    perform check_range.
    if w_error = 'X'.
    continue.
    endif.
    *Check that an 'SCP' unit of measure exists and convert value
    perform check_uom.
    *Otherwise if the file is in weekly format
    elseif rb_week = 'X'.
    *Check that the record corresponds to a monday
    perform check_monday.
    if w_error = 'X'.
    continue.
    endif.
    *Check the value is within the range for the infotype
    perform check_range.
    if w_error = 'X'.
    continue.
    endif.
    *Check that an 'SCP' unit of measure exists and convert value
    perform check_uom.
    else.
    *Check the value is within the range for the infotype
    perform check_range.
    if w_error = 'X'.
    continue.
    endif.
    *Check that an 'SCP' unit of measure exists and convert value
    perform check_uom.
    endif.
    *If split monthly flag has been chosen
    if rb_spmon = 'X'.
    *Process value using split monthly process
    perform process_monthly.
    *Otherwise, if weekly split
    elseif rb_spwk = 'X'.
    *Process value using split weekly process
    perform process_weekly.
    *Otherwise daily split
    else.
    *Process value using split daily process
    perform process_daily.
    endif.
    endloop.
    endform. " populate_post_split_table
    *& Form build_idoc
    Build and submit the idoc for processing
    form post_idoc.
    *Get the logical system for ALE processing
    perform get_ale_data.
    check not logsys is initial.
    *Populate the IDOC control record
    perform build_control_data.
    *Sort the data by material, date and value
    sort i_post_split by matnr datum value fromdat todat split_date.
    *Build idocs and post them
    loop at i_post_split.
    clear: e1lipp0,
    t_exception.
    *Move i_post_split header to a work area
    w_post_split = i_post_split.
    at new datum.
    clear: e1lipm0, e1lipv0, t_edidd.
    refresh t_edidd.
    *Build the general characteristic segment
    perform build_e1lipm0_segment.
    *Build the general version segment
    perform build_e1lipv0_segment.
    endat.
    *Build the performance measure segment
    perform build_e1lipp0_segment.
    at end of datum.
    *Submit IDOC for inbound processing
    perform submit_idoc.
    endat.
    endloop.
    endform. " build_idoc
    12:34:22 PM&#9668;&----
    *& Form submit_idoc
    Start inbound processing of IDOC
    form submit_idoc.
    clear: w_docnum_no_zero.
    call function 'IDOC_WRITE_AND_START_INBOUND'
    exporting
    i_edidc = edidc
    do_commit = 'X'
    importing
    docnum = w_docnum
    tables
    i_edidd = t_edidd
    exceptions
    idoc_not_saved = 1
    others = 2.
    if sy-subrc = 0.
    call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
    exporting
    input = w_docnum
    importing
    output = w_docnum_no_zero.
    perform check_idoc_status_records.
    else.
    t_exception-index = w_post_split-index.
    t_exception-matnr = w_post_split-matnr.
    t_exception-datum = w_post_split-datum.
    t_exception-message = t_edids-statxt.
    append t_exception.
    w_error = 'X'.
    endif.
    *If the no SCP UoM flag is set, write an entry to exception table
    if w_post_split-flg_noscp = 'X'.
    t_exception-index = w_post_split-index.
    t_exception-matnr = w_post_split-matnr.
    t_exception-datum = w_post_split-datum.
    t_exception-value = w_post_split-value.
    t_exception-docnum = w_docnum_no_zero.
    t_exception-message = text-005.
    append t_exception.
    endif.
    endform. " write_idoc
    *& Form build_control_data
    *& Build the IDOC control record
    form build_control_data.
    clear edidc.
    edidc-idoctp = 'SOPGEN01'. " Basic type
    if rb_1000 = 'X'.
    edidc-mestyp = c_mestyp_805. " Message type
    else.
    edidc-mestyp = c_mestyp_810. " Message type
    endif.
    edidc-rcvprt = c_rcvprt. " Partner type of receiver
    concatenate 'SAP' sy-sysid(3) into edidc-rcvpor. " Receiver port
    concatenate sy-sysid(3) 'CLNT' sy-mandt into edidc-rcvprn.
    edidc-direct = '2'. " Inbound
    concatenate 'SAP' sy-sysid(3) into edidc-sndpor.
    edidc-sndprt = c_sndprt. " Partner type of sender
    edidc-sndprn = c_sndprn. " Partner number of sender
    endform. " get_control_data
    *& Form get_ale_data
    Get logical system for ALE processing
    form get_ale_data.
    call function 'OWN_LOGICAL_SYSTEM_GET'
    importing
    own_logical_system = logsys
    exceptions
    own_logical_system_not_defined = 1
    others = 2.
    if sy-subrc <> 0.
    clear logsys.
    endif.
    endform. " get_ale_data
    *& Form build_e1lipv0_segment
    Create the general version segment
    form build_e1lipv0_segment.
    e1lipv0-vrsio = 'A00'.
    e1lipv0-avrsi = 'X'.
    e1lipv0-vetxt = 'Active Version'.
    move e1lipv0 to t_edidd-sdata.
    move 'E1LIPV0' to t_edidd-segnam.
    t_edidd-hlevel = '02'.
    append t_edidd.
    endform. " send_idoc
    *& Form build_e1lipm0_segment
    form build_e1lipm0_segment.
    e1lipm0-vontg = w_post_split-fromdat.
    e1lipm0-bistg = w_post_split-todat.
    e1lipm0-perio = '0'.
    if rb_1000 = 'X'.
    e1lipm0-m01 = c_werks_1000.
    else.
    e1lipm0-m01 = c_werks_1005.
    endif.
    e1lipm0-m02 = w_post_split-matnr.
    e1lipm0-m03 = 'SCP'.
    e1lipm0-m06 = 'T'.
    move e1lipm0 to t_edidd-sdata.
    move 'E1LIPM0' to t_edidd-segnam.
    t_edidd-hlevel = '01'.
    append t_edidd.
    endform. " build_e1lipm0_segment
    *& Form build_e1lipp0_segment
    form build_e1lipp0_segment.
    e1lipp0-sptag = w_post_split-split_date.
    if rb_mgx = 'X'.
    e1lipp0-kz02 = w_post_split-split_value.
    e1lipp0-kz03 = '/'.
    else.
    e1lipp0-kz02 = '/'.
    e1lipp0-kz03 = w_post_split-split_value.
    endif.
    move e1lipp0 to t_edidd-sdata.
    move 'E1LIPP0' to t_edidd-segnam.
    t_edidd-hlevel = '03'.
    append t_edidd.
    endform. " build_e1lipp0_segment
    *& Form check_idoc_status_records
    form check_idoc_status_records.
    clear: t_edids.
    refresh: t_edids.
    select * from edids into table t_edids where docnum = w_docnum.
    clear: w_error.
    loop at t_edids.
    clear: w_statva.
    select single statva from stacust into w_statva
    where status = t_edids-status.
    case w_statva.
    *When the status group is of type 'E' or 'F'.
    when 'E' or 'F'.
    t_exception-value = w_post_split-value.
    t_exception-index = w_post_split-index.
    t_exception-matnr = w_post_split-matnr.
    t_exception-datum = w_post_split-datum.
    t_exception-docnum = w_docnum_no_zero.
    t_exception-message = t_edids-statxt.
    append t_exception.
    w_error = 'X'.
    when others.
    endcase.
    endloop.
    if w_error is initial.
    add 1 to w_count_idoc_posted.
    else.
    add 1 to w_count_idoc_errors.
    endif.
    endform. " check_idoc_status_records
    12:34:35 PM&#9668;&----
    *& Form rename_file
    Form to rename file
    form rename_file.
    data: l_filename_new(120), " New filename
    l_filename_temp(120), " Temporary filename
    l_command(250), " Unix command line
    w_extension(14).
    move p_file to l_filename_new.
    *Replace the file extension of the file to indicate that it has been
    *processed
    concatenate '.proc_' sy-datum into w_extension.
    replace '.txt' with w_extension into l_filename_new.
    Create UNIX rename command
    concatenate 'mv' p_file l_filename_new
    into l_command separated by space.
    Create temporary unique file name
    concatenate p_file 'TEMP'
    into l_filename_temp.
    move l_filename_new to p_file.
    Open temporary dataset but use the filter command to execute the UNIX
    rename command 'mv'.
    This method has been used instead of SAP external commands because
    of file length limitations. The external command only allows a line of
    128 chars which means filenames can only be about 62chars when doing
    a move i.e. mv <file1> <file2>
    open dataset l_filename_temp for output filter l_command.
    if sy-subrc ne 0.
    message e005(z1) with text-007.
    exit.
    endif.
    Close the temporary dataset
    close dataset l_filename_temp.
    if sy-subrc ne 0.
    message e005(z1) with text-007.
    exit.
    endif.
    Delete the temporary dataset
    delete dataset l_filename_temp.
    if sy-subrc ne 0.
    message e005(z1) with text-007.
    exit.
    endif.
    endform. " rename_file
    *& Form material_internal_format
    form material_internal_format.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
    input = i_file-matnr
    importing
    output = i_file-matnr.
    endform. " material_internal_format
    *& Form error_report
    form error_report.
    format color col_normal.
    skip.
    *Loop at exception table and output contents
    loop at t_exception.
    write: / t_exception-index,
    t_exception-matnr,
    24 t_exception-datum,
    t_exception-value right-justified,
    t_exception-docnum,
    t_exception-message.
    endloop.

    hi,
    define internal table. e.g. it_data & follow the steps
    PARAMETERS: p_rfname LIKE rlgrap-filename OBLIGATORY.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_rfname.
      PERFORM get_desktop_file_help.
         Form  get_desktop_file_help
    FORM get_desktop_file_help.
      DATA : v_file LIKE rlgrap-filename.
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
        EXPORTING
          program_name  = syst-repid
          dynpro_number = syst-dynnr
          field_name    = 'P_RFNAME'
        CHANGING
          file_name     = v_file
        EXCEPTIONS
          mask_too_long = 1
          OTHERS        = 2.
      IF sy-subrc <> 0.
        MESSAGE i368(00) WITH 'Enter Correct File'.
        STOP.
      ELSE.
        MOVE : v_file TO p_rfname.
      ENDIF.
    ENDFORM.                    " get_desktop_file_help
    START-OF-SELECTION.
      PERFORM upload_file_from_desktop CHANGING g_error.
         Form  upload_file_from_desktop
    FORM upload_file_from_desktop CHANGING p_error.
      IF NOT sy-batch IS INITIAL.
        MESSAGE e368(00) WITH 'Files can only be uploaded'
                              'in foreground'.
      ELSE.
        CALL FUNCTION 'WS_UPLOAD'
          EXPORTING
            filename                = p_rfname
            filetype                = 'DAT'
          TABLES
            data_tab                = it_data
          EXCEPTIONS
            conversion_error        = 1
            invalid_table_width     = 2
            invalid_type            = 3
            no_batch                = 4
            unknown_error           = 5
            gui_refuse_filetransfer = 6
            OTHERS                  = 7.
        IF sy-subrc NE 0.
          MESSAGE i368(00) WITH 'Error while reading data from file'.
          MOVE : 'X' TO p_error.
        ENDIF.
      ENDIF.
    ENDFORM.                    "upload_file_from_desktop
    raj

Maybe you are looking for