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

How to upload file CSV with Integer type ?

0 Likes
1,002

I have a problem with my code to upload a record to my table with internal table.

Example :

I have 5 record at my CSV File, but it just 4 record can attach to my table and have 1 record with value 'Blank' '000000' '0'.

this is my source code :


REPORT  ZEDWINCSV2COBA.

TABLES ZRVCOBAHTG.

TYPES: BEGIN OF ttab,
        rec(1000) type C,
        END OF ttab.
TYPES: BEGIN OF tdat,
        fld1(8) TYPE C,
        fld2(6) TYPE C,
        fld3(14) TYPE C,
        END OF tdat.
DATA: itab TYPE TABLE OF ttab WITH HEADER LINE.
DATA: idat TYPE TABLE OF tdat WITH HEADER LINE.
DATA: file_str TYPE string.

PARAMETERS: p_file TYPE localfile.

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.
file_str = p_file.
call FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = file_str
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.

LOOP AT itab.
   CLEAR idat.
SPLIT itab-rec AT ',' INTO idat-fld1 idat-fld2 idat-fld3.
APPEND idat.
ENDLOOP.
LOOP AT idat.
   WRITE:/ idat-fld1, idat-fld2, idat-fld3.
INSERT ZRVCOBAHTG.
ZRVCOBAHTG-KODECUSTOMER = idat-fld1.
ZRVCOBAHTG-PERIODE      = idat-fld2.
ZRVCOBAHTG-VALUEHTG     = idat-fld3.
ENDLOOP.

SELECT * from ZRVCOBAHTG.
   write :/ ZRVCOBAHTG-KODECUSTOMER, ZRVCOBAHTG-PERIODE, ZRVCOBAHTG-VALUEHTG.
ENDSELECT.


Notes :

KODECUSTOMER type CHAR.

PERIODE type ACCP.

VALUEHTG type DEC.

anyone can help with my code? thank you before.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
780

Hello Donny,

Put the command "INSERT ZRVCOBAHTG" before the ENDLOOP command. You as inserting the first line in blank:

LOOP AT itab.

     CLEAR idat.

     SPLIT itab-rec AT ',' INTO idat-fld1 idat-fld2 idat-fld3.

     APPEND idat.

ENDLOOP.


LOOP AT idat.

     WRITE:/ idat-fld1, idat-fld2, idat-fld3.    

*     INSERT ZRVCOBAHTG. "it's in blank at this time

     ZRVCOBAHTG-KODECUSTOMER = idat-fld1.

     ZRVCOBAHTG-PERIODE      = idat-fld2.

     ZRVCOBAHTG-VALUEHTG     = idat-fld3.

     INSERT ZRVCOBAHTG. "now have values

ENDLOOP.

3 REPLIES 3
Read only

Former Member
0 Likes
780

Hi

Check below Note ,

1066919 - Showcase GUI_UPLOAD: Comma separated value (CSV)

also check with below code .

DATA WA_ZRVCOBAHTG TYPE ZRVCOBAHTG.

  

  LOOP AT IDAT.

     WRITE:/ IDAT-FLD1, IDAT-FLD2, IDAT-FLD3.

     WA_ZRVCOBAHTG-KODECUSTOMER = IDAT-FLD1.

     WA_ZRVCOBAHTG-PERIODE              = IDAT-FLD2.

     WA_ZRVCOBAHTG-VALUEHTG           = IDAT-FLD3.

    

     INSERT INTO ZRVCOBAHTG VALUES WA_ZRVCOBAHTG.

    

   ENDLOOP.

Regard's

Smruti

Read only

Former Member
0 Likes
781

Hello Donny,

Put the command "INSERT ZRVCOBAHTG" before the ENDLOOP command. You as inserting the first line in blank:

LOOP AT itab.

     CLEAR idat.

     SPLIT itab-rec AT ',' INTO idat-fld1 idat-fld2 idat-fld3.

     APPEND idat.

ENDLOOP.


LOOP AT idat.

     WRITE:/ idat-fld1, idat-fld2, idat-fld3.    

*     INSERT ZRVCOBAHTG. "it's in blank at this time

     ZRVCOBAHTG-KODECUSTOMER = idat-fld1.

     ZRVCOBAHTG-PERIODE      = idat-fld2.

     ZRVCOBAHTG-VALUEHTG     = idat-fld3.

     INSERT ZRVCOBAHTG. "now have values

ENDLOOP.

Read only

0 Likes
780

thanks for Mr. Renan William for the answer...