Skip to Content
0
Former Member
Feb 04, 2011 at 07:52 AM

GUI_UPLOAD not working for text file upload with '|' as a saperater

904 Views

Dear all,

I have used 'GUI_UPLOAD' to upload data from text file having below format,

1000|HBK1|HKTI

1000|HBK2|HKTI

1000|HBK3|HKTI

My code is as below

*&---------------------------------------------------------------------*
*& Report  ZTEST_NEW1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZTEST_NEW1.
TYPE-POOLS: truxs,
            kcde.
TYPES :     BEGIN     OF             ty_data2          ,
            zbukr     TYPE           payr-zbukr       ,
            hbkid     TYPE           payr-hbkid       ,
            hktid     TYPE           payr-hktid       ,

           END       OF             ty_data2         .


DATA :            it_file   TYPE           filetable        .

DATA :      wa_file   LIKE LINE OF   it_file          .

DATA :      w_rc      TYPE           i                ,
            lv_file   TYPE           string           .

DATA : it_data2 TYPE TABLE OF ty_data2,
       wa_data2 LIKE LINE OF it_data2.


SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE text-020.
PARAMETER : pr_file   TYPE           rlgrap-filename         .
SELECTION-SCREEN END OF BLOCK bk1                            .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR pr_file.

  PERFORM get_file.


START-OF-SELECTION.

  PERFORM get_data.

FORM get_file .
 CALL METHOD cl_gui_frontend_services=>file_open_dialog
*  EXPORTING
*    WINDOW_TITLE            =
*    DEFAULT_EXTENSION       =
*    DEFAULT_FILENAME        =
*    FILE_FILTER             =
*    INITIAL_DIRECTORY       =
*    MULTISELECTION          =
*    WITH_ENCODING           =
    CHANGING
      file_table              = it_file
      rc                      = w_rc
*    USER_ACTION             =
*    FILE_ENCODING           =
   EXCEPTIONS
     file_open_dialog_failed = 1
     cntl_error              = 2
     error_no_gui            = 3
     not_supported_by_gui    = 4
     OTHERS                  = 5
          .
  IF sy-subrc EQ 0.

    CLEAR : wa_file.

    LOOP AT it_file INTO wa_file.
      pr_file = wa_file-filename.
      CLEAR : wa_file.
    ENDLOOP.

  ELSE.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ENDIF.
ENDFORM.                    " get_file

FORM get_data .
 IF pr_file IS INITIAL.

    MESSAGE 'Enter file name'(002) TYPE 'E'.

  ENDIF.

  IF pr_file CP '*.xls'
    or pr_file CP '*.xlsx' . " Added




  ELSEIF pr_file CP '*.txt'.
CONSTANTS : c_del TYPE c LENGTH 1 VALUE '|'.
    lv_file = pr_file.
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      = lv_file
   FILETYPE                      = 'ASC'
   HAS_FIELD_SEPARATOR           = c_del
*   HEADER_LENGTH                 = 1
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
*   VIRUS_SCAN_PROFILE            =
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  TABLES
    DATA_TAB                      = it_data2
* 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.
ENDFORM.                    " get_data

In my output I am only getting company codes and not getting other two columns, can any body guide me where I am doing wrong?

I have checked many other same kind of threads and I have done the same as suggested to do but still I am facing issue.

Thanks in advance.

Regards,

Umang