Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

CSV to Internal table

Hi friends,

Have a look at my code.

The basic requirement is to load into table PTRV_KMSUM.

I was able to do that using GUI upload FM from a notepad .

But now the requirement is using a CSV file to load into PTRV_KMSUM.

REPORT zhr_t_ptrv_kmsum NO STANDARD PAGE HEADING LINE-SIZE 200.

  • .

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

  • INTERNAL TABLE DECLARATION *

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

TYPES : BEGIN OF flat_itab,

rec(500) TYPE c,

END OF flat_itab.

DATA: data_tab TYPE TABLE OF flat_itab WITH HEADER LINE. " Internal table to hold CSV file data

DATA: it_kmsum TYPE STANDARD TABLE OF ptrv_kmsum WITH HEADER LINE.

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

  • SPECIFY THE FILE LOCATION *

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

PARAMETERS: p_file TYPE rlgrap-filename.

DATA: v_file TYPE string.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

  • EXPORTING

  • PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

IMPORTING

file_name = p_file.

MOVE p_file TO v_file.

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

  • POPULATE THE INTERNAL TABLE FROM THE CSV FILE *

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

CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'

EXPORTING

I_FIELD_SEPERATOR = ','

  • I_LINE_HEADER =

i_tab_raw_data = data_tab

I_FILENAME = v_file

tables

i_tab_converted_data = it_kmsum

  • EXCEPTIONS

  • CONVERSION_FAILED = 1

  • OTHERS = 2

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

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

NOW LOAD INTO THE TABLE PTRV_KMSUM FROM THE INTERNAL TABLE

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

CALL FUNCTION 'TRIPS_WRITE_KMSUM'

TABLES

kmsum = it_kmsum

  • EXCEPTIONS

  • MODIFY_ERROR = 1

  • OTHERS = 2

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Note:- I am getting the following error message.

The function module interface allows you to specify only fieldsd of a particular type under 'I_FILENAME'.

The field 'V_FILE' specified here is a different field type.

Regards,

Hari kiran

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question