Skip to Content
0
Jun 22, 2022 at 01:42 PM

How to upload notepad file into an internal table in alv?

79 Views

How to upload notepad file into an internal table in alv? I used 'GUI_UPLOAD' FM and gave the filetype as 'ASC', has_field_separator = 'X' and giving a dump. Please help.

TYPES: BEGIN OF st_final,

       pos TYPE  string ,
       seri TYPE string,
      num  TYPE string,
      limit TYPE string,
      ifsc TYPE string,
      num1 TYPE string,
      pri_lim TYPE string,
      jnl_num TYPE string,
      date TYPE string,
      num2 TYPE string,
      vendor TYPE string,
      neft TYPE string,
      num3 TYPE string,

       END OF st_final.

       data:  wa_final TYPE st_final,
              it_final TYPE  TABLE OF st_final,
              dd_filename TYPE rlgrap-filename ,
              dd_string TYPE string.

       DATA: WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
             IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                      = 'C:\Users\Deepak\OneDrive\Desktop\YES.TXT'
     FILETYPE                      = 'ASC'
     HAS_FIELD_SEPARATOR           = 'X'

    tables
      data_tab                      = it_final

   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
            .
 LOOP at it_final INTO wa_final.
   CONCATENATE
               wa_final-pos
               wa_final-seri
               wa_final-num
               wa_final-limit
               wa_final-ifsc
               wa_final-num1
               wa_final-pri_lim
               wa_final-jnl_num
               wa_final-date
               wa_final-num2
               wa_final-vendor
               wa_final-neft
               wa_final-num3

                INTO dd_string SEPARATED BY '' .
   ENDLOOP.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
   I_CALLBACK_PROGRAM                =  SY-REPID
   IT_FIELDCAT                       = it_fieldcat
  TABLES
    t_outtab                          = it_final
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .

WA_FIELDCAT-col_pos = '1'.
WA_FIELDCAT-fieldname = 'POS'.
WA_FIELDCAT-seltext_l = 'POSITION'.
WA_FIELDCAT-tabname = 'IT_FINAL'.


APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.


WA_FIELDCAT-col_pos = '2'.
WA_FIELDCAT-fieldname = 'SERI'.
WA_FIELDCAT-seltext_l = 'SERIES'.
WA_FIELDCAT-tabname = 'IT_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.


WA_FIELDCAT-col_pos = '3'.
WA_FIELDCAT-fieldname = 'NUM'.
WA_FIELDCAT-seltext_l = 'NUMBER'.
WA_FIELDCAT-tabname = 'IT_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.


WA_FIELDCAT-col_pos = '4'.
WA_FIELDCAT-fieldname = 'LIMIT'.
WA_FIELDCAT-seltext_l = 'PVT. LIMIT'.
WA_FIELDCAT-tabname = 'IT_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.


WA_FIELDCAT-col_pos = '5'.
WA_FIELDCAT-fieldname = 'IFSC'.
WA_FIELDCAT-seltext_l = 'IFSC'.
WA_FIELDCAT-tabname = 'IT_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.



WA_FIELDCAT-col_pos = '6'.
WA_FIELDCAT-fieldname = 'NUM1'.
WA_FIELDCAT-seltext_l = 'NUMBER1'.
WA_FIELDCAT-tabname = 'IT_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.


WA_FIELDCAT-col_pos = '7'.
WA_FIELDCAT-fieldname = 'PRI_LIM'.
WA_FIELDCAT-seltext_l = 'PVT. LIMITED'.
WA_FIELDCAT-tabname = 'IT_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.


WA_FIELDCAT-col_pos = '8'.
WA_FIELDCAT-fieldname = 'JNL_NUM'.
WA_FIELDCAT-seltext_l = 'JNL_NUM'.
WA_FIELDCAT-tabname = 'IT_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.


WA_FIELDCAT-col_pos = '9'.
WA_FIELDCAT-fieldname = 'DATE'.
WA_FIELDCAT-seltext_l = 'DATE'.
WA_FIELDCAT-tabname = 'IT_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.


WA_FIELDCAT-col_pos = '10'.
WA_FIELDCAT-fieldname = 'NUM2'.
WA_FIELDCAT-seltext_l = 'NUMBER2'.
WA_FIELDCAT-tabname = 'IT_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.


WA_FIELDCAT-col_pos = '11'.
WA_FIELDCAT-fieldname = 'VENDOR'.
WA_FIELDCAT-seltext_l = 'VENDOR'.
WA_FIELDCAT-tabname = 'IT_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.


WA_FIELDCAT-col_pos = '12'.
WA_FIELDCAT-fieldname = 'NEFT'.
WA_FIELDCAT-seltext_l = 'NEFT PAYMENT'.
WA_FIELDCAT-tabname = 'IT_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.


WA_FIELDCAT-col_pos = '13'.
WA_FIELDCAT-fieldname = 'NUM3'.
WA_FIELDCAT-seltext_l = 'NUMBER3'.
WA_FIELDCAT-tabname = 'IT_FINAL'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.