Application Development and Automation 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: 
Read only

Database Table

Former Member
0 Likes
1,067

Hi Friends,

Try to resolve the below query

I am using a Custom Table with a following fields

mandt, empid, empname, salary etc.

I am having a flatfile which contains values for

empid, empname, salary etc.

I declared an itab as follows

data : itab like dbtable occurs 0 with header line.

Then I used WS_UPLOAD (GUI_UPLOAD) to upload the

contents of flatfile to itab.

In this scenario, the field empid is assigned to MANDT in internal table &

empname is assigned to empid in internal table & so on.

How to resolve the same.

FYI :

I have used the "A" as delivery Class & "APPl0" as DataClass.

I also have a query.

1. What should be my filetype (ASC, DAT, WK1) in the following cases

a. Continuous flatfile without any delimiters

b. Tab delimited text file

c. File with a specific delimiter as comma

8 REPLIES 8
Read only

Former Member
0 Likes
1,002

Hi,

Try creating an internal table without the MANDT field,

Eg.

begin of itab occurs 0,

empid(5) type i,

empname(20) type c,

salary(5) type i,

end of itab.

After populating the itab, try appending records to the table.

Read only

0 Likes
1,002

Hi,

For Sridevi, you can't specify length for a type i.

As for the request,

you can use a *.CSV file with comma separator then in the ABAP you put the following code :


  DATA: line             TYPE string,
        filename         TYPE string,
        t_file TYPE TABLE OF string.
  filename = p_filename.

    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                = filename
        filetype                = 'ASC'
      TABLES
        data_tab                = t_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.
*--

  LOOP AT t_table.
    SPLIT t_file AT ';' INTO   t_table-empid
                               t_table-empname  
                               t_table-salary.

    APPEND t_table.
  ENDLOOP

Hope this helps.

Erwan.

Read only

Former Member
0 Likes
1,002

Hi,

You may wish to define the ITAB fields individually rather than by using 'like dbtab'. This will help in case your dbtable has 'float' or 'packed decimal' fields like salary, and your file has the data in char form.

cheers,

Read only

Former Member
0 Likes
1,002

Best way is to declare a type with only required fields like this:

begin of XXXX,

empid type ....

.

.

end of XXXXX.

data: YYY type standard table of XXXXX.

File type is ASC

For download you should use a table with a single column like the one below:

BEGIN OF download,

row(1500) TYPE c,

END OF final.

All download values are concatenated and appended to the above table. For continuous text you will just concatenate all values but for tab delimited declare a constant like this:

c_tab(1) TYPE x VALUE '09' and use this in SEPARATED BY clause.

Hope this help.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,002

Hi,

Your filetype should be 'ASC' if you are uploading text file.If you want Tab delimited ouput,then Has_field_separator parameter should be 'X'.

If you declare like that,

types : begin of db,

...delcare other fields except mandt

end of db.

data itab type standard table of db.

Then you will get correct output.

If you function module documentation,then you can see the example coding.

Read only

Former Member
0 Likes
1,002

Friends,

The task does not end with just uploading the contents of

flat file to itab, from itab the contents has to be again posted to the dbtable.

If we assign all fields except mandt, i am getting pblem while

inserting the contents to dbtable. Pls help to resolve the same.

Friends, my query is the mandt field should automatically populated isn't it?!!!

Regards.

Usha

Read only

0 Likes
1,002

Hi,

It is not like that mandt is automatically populated while uploading.

But if you defined user defined datatype as I mentioned in my previous reply,you will get the contents in an itab without that mandt field.

So declare

data itab type standard table of db.

loop at itab into wa.

move-corresponding wa to wa1.

append wa1 to itab1.

endloop.

But you can use the table itab1 to insert into database.Here it will be populated automatically.

Insert db from table itab.

Read only

Former Member
0 Likes
1,002

Friends,

Thanks for your replies.

The problem is solved

The solution is as follows.

1. Declare an itab with all fields except mandt

2. Populate this itab with flatfile contents

3. Declare another itab with dbtable type

4. Move the corresponding fields of first itab to second itab

5. Insert the second itab contents to dbtable.

The program is now working!!

Once again thanks for your replies friends.

Jayanthi, thanks a lot.

Regards,

Usha