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

Upload comma separated data from CSV file to a custom database table

jayaraj2018
Product and Topic Expert
Product and Topic Expert
0 Likes
4,147

Hi All,

I am new to ABAP and currently working on an ABAP program that will read data from a comma separated text file and upload to a custom table that i created.

After referring to loads of videos in youtube and in Sap community sites, i manged to do half of my requirement.

The below code reads the csv file using GUI_UPLOAD function into an Internal table called UTAB. UTAB contains data of format 1 - Name,Address, Contact

An other Internal table called DTAB is defined that will read the data from UTAB and splits the value using comma (,) and stores the data like this.

1.Name

2.Address

3.Contact

Now i need to somehow loop through these values in DTAB and store them in my custom table ZCUST_DETAIL.

Please help me complete the code.

REPORT ZZ_UPLOAD_GEACACCOUNT.
PARAMETERS: P_FNAME TYPE STRING OBLIGATORY

DATA UTAB TYPE TABLE OF CHAR300.
FIELD-SYMBOLS <FS_UTAB> LIKE LINE OF UTAB.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
    EXPORTING
      FILENAME = P_FNAME
    CHANGING
      DATA_TAB = UTAB
    EXCEPTIONS
      FILE_OPEN_ERROR = 1.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
* EXCEL DATA IS NOW IN UTAB TABLE
DATA DTAB TYPE TABLE OF CHAR100.
FIELD-SYMBOLS <FS_DTAB> LIKE LINE OF DTAB.
LOOP AT UTAB ASSIGNING <FS_UTAB> FROM 2.  
    SPLIT <FS_UTAB> AT ',' INTO TABLE DTAB
ENDLOOP. 
1 ACCEPTED SOLUTION
Read only

arpan_shukla
Explorer
2,776

Dear M Jay,

Instead of this:

SPLIT <FS_UTAB> AT ',' INTO TABLE DTAB

Please try this:

DATA: Dtab TYPE STANDARD TABLE OF ZCUST_DETAIL,
      wa_dtab TYPE ZCUST_DETAIL.
"(you can also define internal table structure manually instead of using standard table)

............
............
............


SPLIT <FS_UTAB> AT ',' INTO wa_dtab-name wa_dtab-address wa_dtab-contact.
Append wa_dtab INTO dtab.

Please let me know if you need further clarifications on this.

Thanks and Regards,

Arpan Shukla

Dear M Jay,

Instead of this:

SPLIT <FS_UTAB> AT ',' INTO TABLE DTAB

Please try this:

DATA: Dtab TYPE STANDARD TABLE OF ZCUST_DETAIL,
      wa_dtab TYPE ZCUST_DETAIL.
"(you can also define internal table structure manually instead of using standard table)

............
............
............


SPLIT <FS_UTAB> AT ',' INTO wa_dtab-name wa_dtab-address wa_dtab-contact.
Append wa_dtab INTO dtab.

Please let me know if you need further clarifications on this.

Thanks and Regards,

Arpan Shukla

3 REPLIES 3
Read only

matt
Active Contributor
2,776

Please in future use the code button when entering code. I've done it for you this time.

Matt Billigham - SAP Community Moderator

Read only

arpan_shukla
Explorer
2,777

Dear M Jay,

Instead of this:

SPLIT <FS_UTAB> AT ',' INTO TABLE DTAB

Please try this:

DATA: Dtab TYPE STANDARD TABLE OF ZCUST_DETAIL,
      wa_dtab TYPE ZCUST_DETAIL.
"(you can also define internal table structure manually instead of using standard table)

............
............
............


SPLIT <FS_UTAB> AT ',' INTO wa_dtab-name wa_dtab-address wa_dtab-contact.
Append wa_dtab INTO dtab.

Please let me know if you need further clarifications on this.

Thanks and Regards,

Arpan Shukla

Read only

jayaraj2018
Product and Topic Expert
Product and Topic Expert
0 Likes
2,776

Thank you Arpan!