Skip to Content
avatar image
Former Member

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

9 Answers

  • Best Answer
    avatar image
    Former Member
    Jun 16, 2008 at 02:42 PM

    take v_file name as RLGRAP-FILENAME

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 16, 2008 at 02:44 PM

    For TEXT_CONVERT_CSV_TO_SAP

    You have to define v_file as RLGRAP-FILENAME and not as a string

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Friends,

      I tried the following.

      I commented v_file.

      I have kept p_file from my code.

      I passed that in fm"TEXT_CONVERT_CSV_TO_SAP.

      Didn't get the earlier error message. But got the following one....

      The function module interface allows you to specify only fields of a particular type under "I_TAB_RAW_DATA".

      The field "DATA_TAB" specified here is a different field type.

      Inputs please,

      Regards,

      Hari Kiran

  • Jun 16, 2008 at 02:44 PM

    Hi Friend,

    Make the type of V_FILE to RLGRAP-FILENAME (now it is string).

    Hope it will solve ur problem.

    Regards

    Krishnendu

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      here's the changed code,

      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.

      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.

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

      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 = p_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.

  • avatar image
    Former Member
    Jun 16, 2008 at 02:44 PM

    Declare the field v_file of type RLGRAP-FILENAME instead of STRING. It solves your problem.

    Regards,

    Kiran Bobbala

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 16, 2008 at 03:29 PM

    (change the data type) in place of the below code

    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

    place this.

    data:

    • this table with out header line

    data_tab type TRUXS_T_TEXT_DATA,

    • work area for the table.

    wa_data_tab(4096) type c .

    Edited by: S.r.v.r.Kumar on Jun 16, 2008 8:59 PM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 16, 2008 at 03:46 PM

    paste the below code

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

    TYPE-POOLS truxs.

    DATA:

    data_tab TYPE truxs_t_text_data,

    wa_data_tab(4096) TYPE c.

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

    delete the below code from ur program

    TYPES : BEGIN OF flat_itab,

    rec(500) TYPE c,

    END OF flat_itab.

    DATA: data_tab TYPE TABLE OF flat_itab WITH HEADER LINE.

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

    i will not change all the program, if you have any dought ask me i will give answers.

    i am not worried about points.

    if i write the whole code what you will do.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Kumar ,

      I tried your code.

      Made the changes you asked.

      There is no error now.

      But when I executed it and checked the table PTRV_KMSUM;

      Data is not getting placed. 😔

      Are you sure , if the changes you asked are all I need to do or do I need to do something else.

      Here's my code now-------

      REPORT zhr_t_ptrv_kmsum NO STANDARD PAGE HEADING LINE-SIZE 200.

      • MESSAGE-ID /rpm/migration.

      TYPE-POOLS truxs.

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

      • INTERNAL TABLE DECLARATION *

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

      *

      *TYPES : BEGIN OF flat_itab,

      *rec(500) TYPE c,

      *END OF flat_itab.

      *

      data: data_tab type TRUXS_T_TEXT_DATA,

      wa_data_tab(4096) type c .

      *DATA: data_tab TYPE standard table of flat_itab." WITH *HEADER LINE. " Internal table to hold flat 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(75) TYPE c. "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.

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

      • 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 = p_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.

      Warm regards,

      Hari Kiran

  • avatar image
    Former Member
    Jun 16, 2008 at 04:46 PM

    REPORT zhr_t_ptrv_kmsum NO STANDARD PAGE HEADING LINE-SIZE 200.

    *MESSAGE-ID /rpm/migration.

    TYPE-POOLS truxs.

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

    *INTERNAL TABLE DECLARATION *

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

    data: i_tab_raw_data type TRUXS_T_TEXT_DATA,

    wa_data_tab(4096) type c .

    data:g_file type string.

    DATA: it_kmsum TYPE STANDARD TABLE OF ptrv_kmsum.

    data:i_tab_converted_data type STANDARD TABLE OF PTRV_KMSUM.

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

    *SPECIFY THE FILE LOCATION *

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

    PARAMETERS: p_file TYPE rlgrap-filename.

    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.

    start-of-selection.

    g_file = p_file.

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    filename = g_file

    TABLES

    data_tab = i_tab_raw_data

    .

    CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'

    EXPORTING

    I_FIELD_SEPERATOR = ','

    • I_LINE_HEADER = I_LINE_HEADER

    i_tab_raw_data = i_tab_raw_data

    • I_FILENAME = I_FILENAME

    TABLES

    i_tab_converted_data = i_tab_converted_data

    • EXCEPTIONS

    • CONVERSION_FAILED = 1

    .

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

    *NOW LOAD INTO THE TABLE PTRV_KMSUM FROM THE INTERNAL TABLE

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

    CALL FUNCTION 'TRIPS_WRITE_KMSUM'

    TABLES

    kmsum = i_tab_converted_data

    EXCEPTIONS

    MODIFY_ERROR = 1

    OTHERS = 2

    .

    IF sy-subrc eq 0.

    MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO

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

    ENDIF.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi kumar,

      no syntax error nothing.

      Everything looks great.It executed.

      I got the green colored "Nike"symbol or "ok" symbol

      in status bar with 0.00 besides it when I executed.

      But data didn't get placed.

      I had a doubt In GUI _UPLOAD.

      You didnt give the file type???

      Reply soon.

      Thank you so much once again.

  • avatar image
    Former Member
    Jun 17, 2008 at 07:33 AM

    write a break-point before the statement CALL FUNCTION 'TRIPS_WRITE_KMSUM'. and check data in table i_tab_converted_data. you will get all the data that is there in ur file, i think there is a problem in 'TRIPS_WRITE_KMSUM' function module or data in the file.

    no need to pass file type in GUI uplode if the file is notepad

    by the by what is ur file type.

    Edited by: S.r.v.r.Kumar on Jun 17, 2008 1:03 PM

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi ,

      In debugging mode I am getting the message-----

      "Specified table name not recognised " for

      i_tab_converted_data.

      I had the placed the break point in the FM --Text_Convert_CSV_to_SAP.

      I have also not used GUI_UPLOAD.

      I want to pull the data from CSV file using the FM Text_Convert_CSV_to_SAP.Then place it in a internal table.

      Then load using the FM " TRIPS_WRITE_KMSUM".

      Warm regards,

      Hari Kiran

  • avatar image
    Former Member
    Jun 16, 2008 at 02:42 PM

    you can load the csv file and then pass it to the table using split.

    Add comment
    10|10000 characters needed characters exceeded