Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Data not getting uploaded to the internal table from a text file throug BDC

Former Member
0 Kudos

There are two concerns.

One is in GUI upload.

The import file name should be of type string. But I am not able to declare a variable of type String. it gives me syntax error "Nested data type not allowed". Hence GUI upload throws run time error due to type mismatch.

Secondly, the data from text file is not read into the internal table. I am using tab seperator in my text file. I tried with different seperators and giving 'X' and '#' as field seperator in FM. But internal table does not get populated. My BDC program runs fine if I manually alter the data in the internal table while debugging.

Provide solutions for these

5 REPLIES 5

Former Member
0 Kudos

Hi,

Can you place your code, so that it is easy to rectify.

otherwise once check this code,

PARAMETERS: p_infile LIKE rlgrap-filename

OBLIGATORY DEFAULT '/usr/sap/'..

*DATA: ld_file LIKE rlgrap-filename.

DATA: gd_file type string.

*Internal tabe to store upload data

TYPES: BEGIN OF t_record,

name1 LIKE pa0002-vorna,

name2 LIKE pa0002-name2,

age TYPE i,

END OF t_record.

DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,

wa_record TYPE t_record.

*Internal table to upload data into

DATA: BEGIN OF it_datatab OCCURS 0,

row(500) TYPE c,

END OF it_datatab.

*Text version of data table

TYPES: BEGIN OF t_uploadtxt,

name1(10) TYPE c,

name2(15) TYPE c,

age(5) TYPE c,

END OF t_uploadtxt.

DATA: wa_uploadtxt TYPE t_uploadtxt.

*String value to data in initially.

DATA: wa_string(255) TYPE c.

CONSTANTS: con_tab TYPE x VALUE '09'.

*If you have Unicode check active in program attributes then you will

*need to declare constants as follows:

*class cl_abap_char_utilities definition load.

*constants:

  • con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

************************************************************************

*AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_INFILE.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_infile.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

def_filename = p_infile

mask = ',*.txt.'

mode = 'O'

title = 'Upload File'(078)

IMPORTING

filename = p_infile

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5.

************************************************************************

*START-OF-SELECTION

START-OF-SELECTION.

gd_file = p_infile.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = gd_file

has_field_separator = 'X' "file is TAB delimited

TABLES

data_tab = it_record

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 NE 0.

write: 'Error ', sy-subrc, 'returned from GUI_UPLOAD FM'.

skip.

endif.

  • Alternative method, where by you split fields at each TAB after you

  • have returned the data. No point unless you dont have access to

  • GUI_UPLOAD but just included for information

*

  • CALL FUNCTION 'GUI_UPLOAD'

  • EXPORTING

  • filename = gd_file

  • filetype = 'ASC'

  • TABLES

  • data_tab = it_datatab "ITBL_IN_RECORD[]

  • EXCEPTIONS

  • file_open_error = 1

  • OTHERS = 2.

  • IF sy-subrc NE 0.

  • ELSE.

  • LOOP AT it_datatab.

  • CLEAR: wa_string, wa_uploadtxt.

  • wa_string = it_datatab.

  • SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1

  • wa_uploadtxt-name2

  • wa_uploadtxt-age.

  • MOVE-CORRESPONDING wa_uploadtxt TO wa_record.

  • APPEND wa_record TO it_record.

  • ENDLOOP.

  • ENDIF.

************************************************************************

*END-OF-SELECTION

END-OF-SELECTION.

Regards,

Ravi

0 Kudos

I have declared the variable in the same way as given in the program. But it shows error " Nested Data type not allowed"

0 Kudos

Hi,

Can you show the declaration and the Upload code of your program.

Regards,

Madhukar Shetty

0 Kudos

TABLES:vbak,vbap,z0946_employee.

DATA: p_file1 TYPE ibipparms-path.

TYPES:

BEGIN OF gs_employee,

number TYPE z0946_employee-employee_no,

name TYPE z0946_employee-employee_name,

dob TYPE z0946_employee-date_of_birth,

END OF gs_employee.

data: gi_bdcdata TYPE STANDARD TABLE OF bdcdata,

gw_bdcdata TYPE bdcdata,

gt_messages TYPE STANDARD TABLE OF bdcmsgcoll,

gw_messages TYPE bdcmsgcoll.

DATA: it_employee TYPE STANDARD TABLE OF gs_employee,

wa_employee TYPE gs_employee.

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

*/.. File name

PARAMETERS: p_file TYPE string. This is the error

SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

*To allow user to select location of file.

PERFORM f001_drop_down.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = ' '

IMPORTING

file_name = p_file1.

p_file = p_file1.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = p_file

has_field_separator = 'X'

TABLES

data_tab = it_employee

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.

surajarafath
Contributor
0 Kudos

This is the way i did, it worked well for me you try to do the same,..

PARAMETERS  wp_fname(128) TYPE c OBLIGATORY
            LOWER CASE DEFAULT 'C:\DATA.TXT'.

TYPES:  BEGIN OF ty_file,
        customer TYPE kunnr ,
        risk_cat TYPE ctlpc_cm,
        credit_limit TYPE klimk,
        END OF ty_file.

DATA    wf_fname TYPE string.
DATA:   wt_file TYPE TABLE OF ty_file,
        wa_file TYPE ty_file.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR wp_fname.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      program_name  = syst-repid
      dynpro_number = syst-dynnr
      field_name    = wp_fname
      mask          = '*.*,*.*'
    CHANGING
      file_name     = wp_fname
    EXCEPTIONS
      mask_too_long = 1
      OTHERS        = 2.

  wf_fname = wp_fname.

 CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = wf_fname
      filetype                = 'DAT'
      has_field_separator     = 'X'
      read_by_line            = 'X'
    TABLES
      data_tab                = wt_file
    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.

My txt file looks like this...

41A00001 C01 5,900.00

41A00002 C02 1.00

41A00003 C06 30.00

41A00004 C03 100,000.00