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

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

Similar Messages

  • Saving .csv into internal table - using dataset (',' comes between data)

    Hi experts,
    I need to save .csv from application server to internal table.
    i am using the below code.
    gt_raw and gwa_raw are dxrawdata format.
    OPEN DATASET gv_pfile FOR INPUT IN TEXT MODE ENCODING DEFAULT.
    *--- Display error messages if any.
      IF sy-subrc NE 0.
        WRITE:/ 'FILE UPLOAD FAILED - ERROR NO. : ', sy-subrc.
        EXIT.
      ELSE.
        DO.
          READ DATASET gv_pfile INTO gwa_raw.
          IF sy-subrc NE 0.
            EXIT.
          ELSE.
            APPEND gwa_raw TO gt_raw.
            CLEAR gwa_raw.
          ENDIF.
        ENDDO.
    *--Close the Application server file (Mandatory).
        CLOSE DATASET gv_pfile.
      ENDIF.
      DELETE DATASET gv_pfile.
      LOOP AT gt_raw into gwa_raw.
        IF SY-TABIX > 1.
          SPLIT gwa_raw at ',' into gwa_cust-cust_code
                                    gwa_cust-cust_name
                                    gwa_cust-grp_name
          APPEND gwa_cust TO gt_cust.
          CLEAR: gwa_cust, gwa_raw.
        ENDIF.
      ENDLOOP.
    My program works fine.
    But when the gwa_cust-grp_name contains the value for eg. -> panasonic co., ltd.
    it takes till panasonic co., only
    and leaves ltd. as i am using SPLIT command.
    is there any other way to do this.
    plz help me to solve this issue.
    thanks.

    Hi,
    I notice you have marked the message as answered, but I just wanted to let you know there is a solution. The trick is to parse into an internal table and then to find and reassemble fields that were split because they contgain a comma. The ABAP program below is a commented example.
    Rgds,
    Mark
    REPORT  zcsv_parse.
    DATA:
      tokens       TYPE i.
    TYPES: BEGIN OF ty_result,
      company      TYPE char20,
      compnr       TYPE i,
      city         TYPE char30,
      country      TYPE char30,
    END OF ty_result.
    DATA:
      gt_rawtab    TYPE TABLE OF string,
      gw_rawtab    LIKE LINE OF gt_rawtab,
      gt_result    TYPE TABLE OF ty_result,
      gw_result    LIKE LINE OF gt_result,
      gt_parse     TYPE TABLE OF string,
      gw_parse     LIKE LINE OF gt_parse.
    DEFINE %csvline.
      gw_rawtab = &1.
      append gw_rawtab to gt_rawtab.
    END-OF-DEFINITION.
    START-OF-SELECTION.
    * Create CSV lines, some with a comma inside a token
      %csvline '"CompanyOne NV",500,"Antwerp","Belgium"'.
      %csvline '"CompanyTwo,Inc",600,"New York,NY","USA"'.
      %csvline '"CompanyThree,Ltd",700,"Sydney,NSW","Australia"'.
    * Parse the raw CSV
      LOOP AT gt_rawtab INTO gw_rawtab.
        REFRESH gt_parse.
        SPLIT gw_rawtab AT ',' INTO TABLE gt_parse.
        DESCRIBE TABLE gt_parse LINES tokens.
    *   If extra commas: token count higher than field count
        IF tokens > 4.
          PERFORM reassemble.
        ENDIF.
    *   At this point each entry in GT_PARSE contains exactly
    *   one result field => build the result table
        LOOP AT gt_parse INTO gw_parse.
    *     Strip quotes from text fields
          REPLACE ALL OCCURRENCES OF '"' IN gw_parse WITH ''.
          CASE sy-tabix.
            WHEN 1. gw_result-company = gw_parse.
            WHEN 2. gw_result-compnr = gw_parse.
            WHEN 3. gw_result-city = gw_parse.
            WHEN 4. gw_result-country = gw_parse.
          ENDCASE.
        ENDLOOP.
        APPEND gw_result TO gt_result.
      ENDLOOP.
    * Show the formatted result
      LOOP AT gt_result INTO gw_result.
        WRITE: / gw_result-company, gw_result-compnr,
                 gw_result-city, gw_result-country.
      ENDLOOP.
    *&      Form  reassemble
    *       Merges tokens that were split because they contain a comma
    FORM reassemble.
      DATA: lastpos    TYPE i,
            lastchar   TYPE c,
            currtoken  LIKE sy-tabix,
            nexttoken  LIKE sy-tabix,
            gw_next    LIKE gw_parse.
      LOOP AT gt_parse INTO gw_parse.
        lastpos  = STRLEN( gw_parse ) - 1.
        lastchar = gw_parse+lastpos(1).
    *   Token starts with quote but does not end with one =>
    *   must merge with the next token
        IF gw_parse+0(1) = '"' AND lastchar <> '"'.
          currtoken = sy-tabix.
          nexttoken = sy-tabix + 1.
          READ TABLE gt_parse INTO gw_next INDEX nexttoken.
          CONCATENATE gw_parse gw_next INTO gw_parse SEPARATED BY ','.
          MODIFY gt_parse FROM gw_parse INDEX currtoken.
          DELETE gt_parse INDEX nexttoken.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    "reassemble

  • Function module to convert an internal table to an tab delimited XL file

    hi everyone
    can anyone tell me the name of the function module which can convert the data in the internal table to an Excel file (Tab de-limited).
    vamsi

    Hello Vamsi
    Just in case you need functions for the other way around (e.g. .csv-file -> internal table) SAP provides the following function modules:
    - TEXT_CONVERT_CSV_TO_SAP
    - SAP_CONVERT_TO_CSV_FORMAT
    This function group <b>TRUX </b>contains some more interesting function modules.
    Regards
      Uwe

  • Getting Issue while uploading CSV file into internal table

    Hi,
    CSV file Data format as below
         a             b               c              d           e               f
    2.01E14     29-Sep-08     13:44:19     2.01E14     SELL     T+1
    actual values of column   A is 201000000000000
                     and  columen D is 201000000035690
    I am uploading above said CSV file into internal table using
    the below coding:
    TYPES: BEGIN OF TY_INTERN.
            INCLUDE STRUCTURE  KCDE_CELLS.
    TYPES: END OF TY_INTERN.
    CALL FUNCTION 'KCD_CSV_FILE_TO_INTERN_CONVERT'
        EXPORTING
          I_FILENAME      = P_FILE
          I_SEPARATOR     = ','
        TABLES
          E_INTERN        = T_INTERN
        EXCEPTIONS
          UPLOAD_CSV      = 1
          UPLOAD_FILETYPE = 2
          OTHERS          = 3.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    am getting all columns data into internal table,
    getting problem is columan A & D. am getting values into internal table for both; 2.01E+14. How to get actual values without modifying the csv file format.
    waiting for your reply...
    thanks & regards,
    abhi

    Hi Saurabh,
    Thanks for your reply.
    even i can't double click on those columns.
    b'se the program needs be executed in background there can lot of csv file in one folder. No manual interaction on those csv files.
    regards,
    abhi

  • Download Internal Table in CSV format it gets downloaded in single column

    Hi All
    I am converting Internal Table in CSV format using the FM CONVERT TO CSV FORMAT and then downloading data using GUI_DOWNLOAD FM.
    I have given separator as ','.
    However when I download the data the file is opened in Excel and first 2 to 3 column are merged in to single column and there was separator shown ';'.
    How to overcome this problem.
    Amol

    hI..,
    Check this code..
    <b>
    It first downloads the data in internal table to a CSV format file..
    and then uploads the same data into another internal table and prints it..</b>
    analyze this and use accordingly..
    tables:
      spfli.
    field-symbols : <fs>, <fs1>.
    data:
      w_line(1000),
      w_field(20) type c,
      wa_spfli type spfli.
    data:
      begin of fs_spfli,
        carrid    type spfli-carrid,
        connid    type spfli-connid,
        countryfr type spfli-countryfr,
        countryto type spfli-countryto,
        fltime    type spfli-fltime,
      end of fs_spfli.
    data :
      t_file like standard table
               of w_line
          initial size 0.
    data:
      t_spfli like
    standard table
           of fs_spfli
      initial size 0.
    data:
      t_spfli_up like
        standard table
              of fs_spfli
         initial size 0.
    select carrid
           connid
           countryfr
           countryto
           fltime
      into corresponding fields of table t_spfli
      from spfli.
    loop at t_spfli into fs_spfli.
      do.
        assign component sy-index of structure fs_spfli to <fs>.
        if sy-subrc ne 0.
          exit.
        endif.
        w_field = <fs>.
        condense w_field no-gaps.
        if sy-index eq 1.
          w_line = w_field.
        else.
          concatenate w_line ',' w_field into w_line.
        endif.
      enddo.
      append w_line to t_file.
    endloop.
    call function 'GUI_DOWNLOAD'
      exporting
         BIN_FILESIZE                    =
           filename                        = 'D:\file.txt'
           filetype                        = 'ASC'
         APPEND                          = ' '
         write_field_separator           = ' '
         header                          = '00'
         TRUNC_TRAILING_BLANKS           = ' '
         WRITE_LF                        = 'X'
         COL_SELECT                      = ' '
         COL_SELECT_MASK                 = ' '
         DAT_MODE                        = ' '
         CONFIRM_OVERWRITE               = ' '
         NO_AUTH_CHECK                   = ' '
         CODEPAGE                        = ' '
         IGNORE_CERR                     = ABAP_TRUE
         REPLACEMENT                     = '#'
         WRITE_BOM                       = ' '
         TRUNC_TRAILING_BLANKS_EOL       = 'X'
         WK1_N_FORMAT                    = ' '
         WK1_N_SIZE                      = ' '
         WK1_T_FORMAT                    = ' '
         WK1_T_SIZE                      = ' '
       IMPORTING
         FILELENGTH                      =
      tables
        data_tab                           = t_FILE
         FIELDNAMES                      =
    exceptions
       file_write_error                = 1
       no_batch                        = 2
       gui_refuse_filetransfer         = 3
       invalid_type                    = 4
       no_authority                    = 5
       unknown_error                   = 6
       header_not_allowed              = 7
       separator_not_allowed           = 8
       filesize_not_allowed            = 9
       header_too_long                 = 10
       dp_error_create                 = 11
       dp_error_send                   = 12
       dp_error_write                  = 13
       unknown_dp_error                = 14
       access_denied                   = 15
       dp_out_of_memory                = 16
       disk_full                       = 17
       dp_timeout                      = 18
       file_not_found                  = 19
       dataprovider_exception          = 20
       control_flush_error             = 21
       others                          = 22.
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    clear t_FILE.
    call function 'GUI_UPLOAD'
      exporting
        filename                      = 'D:\file.txt'
       FILETYPE                       = 'ASC'
      HAS_FIELD_SEPARATOR            = 'X'
      HEADER_LENGTH                 = 0
      READ_BY_LINE                  = 'X'
      DAT_MODE                      = ' '
      CODEPAGE                      = ' '
      IGNORE_CERR                   = ABAP_TRUE
      REPLACEMENT                   = '#'
      CHECK_BOM                     = ' '
      VIRUS_SCAN_PROFILE            =
    IMPORTING
      FILELENGTH                    =
      HEADER                        =
      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
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    clear fs_spfli.
    *constants :
    *C_HTAB value CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    loop at t_file into w_line.
      do.
        if w_line eq space.
          exit.
        endif.
        split w_line at ',' into w_field w_line.
        condense w_field no-gaps.
        assign component sy-index of structure fs_spfli to <fs>.
        <fs> = w_field.
      enddo.
      append fs_spfli to t_spfli_up.
    endloop.
    loop at t_spfli_up into fs_spfli.
      do.
        assign component sy-index of structure fs_spfli to <fs>.
        if sy-subrc ne 0.
          exit.
        endif.
        write <fs>.
      enddo.
      skip.
    endloop.
    reward if it helps u..
    sai ramesh

  • Question about reading csv file into internal table

    Some one (thanks those nice guys!) in this forum have suggested me to use FM KCD_CSV_FILE_TO_INTERN_CONVERT to read csv file into internal table. However, it can be used to read a local file only.
    I would like to ask how can I read a CSV file into internal table from files in application server?
    I can't simply use SPLIT as there may be comma in the content. e.g.
    "abc","aaa,ab",10,"bbc"
    My expected output:
    abc
    aaa,ab
    10
    bbb
    Thanks again for your help.

    Hi Gundam,
    Try this code. I have made a custom parser to read the details in the record and split them accordingly. I have also tested them with your provided test cases and it work fine.
    OPEN DATASET dsn FOR input IN TEXT MODE ENCODING DEFAULT.
    DO.
    READ DATASET dsn INTO record.
      PERFORM parser USING record.
    ENDDO.
    *DATA str(32) VALUE '"abc",10,"aaa,ab","bbc"'.
    *DATA str(32) VALUE '"abc","aaa,ab",10,"bbc"'.
    *DATA str(32) VALUE '"a,bc","aaaab",10,"bbc"'.
    *DATA str(32) VALUE '"abc","aaa,ab",10,"b,bc"'.
    *DATA str(32) VALUE '"abc","aaaab",10,"bbc"'.
    FORM parser USING str.
    DATA field(12).
    DATA field1(12).
    DATA field2(12).
    DATA field3(12).
    DATA field4(12).
    DATA cnt TYPE i.
    DATA len TYPE i.
    DATA temp TYPE i.
    DATA start TYPE i.
    DATA quote TYPE i.
    DATA rec_cnt TYPE i.
    len = strlen( str ).
    cnt = 0.
    temp = 0.
    rec_cnt = 0.
    DO.
    *  Start at the beginning
      IF start EQ 0.
        "string just ENDED start new one.
        start = 1.
        quote = 0.
        CLEAR field.
      ENDIF.
      IF str+cnt(1) EQ '"'.  "Check for qoutes
        "CHECK IF quotes is already set
        IF quote = 1.
          "Already quotes set
          "Start new field
          start = 0.
          quote = 0.
          CONCATENATE field '"' INTO field.
          IF field IS NOT INITIAL.
            rec_cnt = rec_cnt + 1.
            CONDENSE field.
            IF rec_cnt EQ 1.
              field1 = field.
            ELSEIF rec_cnt EQ 2.
              field2 = field.
            ELSEIF rec_cnt EQ 3.
              field3 = field.
            ELSEIF rec_cnt EQ 4.
              field4 = field.
            ENDIF.
          ENDIF.
    *      WRITE field.
        ELSE.
          "This is the start of quotes
          quote = 1.
        ENDIF.
      ENDIF.
      IF str+cnt(1) EQ ','. "Check end of field
        IF quote EQ 0. "This is not inside quote end of field
          start = 0.
          quote = 0.
          CONDENSE field.
    *      WRITE field.
          IF field IS NOT INITIAL.
            rec_cnt = rec_cnt + 1.
            IF rec_cnt EQ 1.
              field1 = field.
            ELSEIF rec_cnt EQ 2.
              field2 = field.
            ELSEIF rec_cnt EQ 3.
              field3 = field.
            ELSEIF rec_cnt EQ 4.
              field4 = field.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
      CONCATENATE field str+cnt(1) INTO field.
      cnt = cnt + 1.
      IF cnt GE len.
        EXIT.
      ENDIF.
    ENDDO.
    WRITE: field1, field2, field3, field4.
    ENDFORM.
    Regards,
    Wenceslaus.

  • Program to upload csv file to internal table and insert into database table

    Hi I'm writing a program where I need to upload a csv file into an internal table using gui_upload, but i also need this program to insert the data into my custom database table using the split command.  Anybody have any samples to help, its urgent!

    Hi,
    Check this table may be it will give u an hint...
    REPORT z_table_upload LINE-SIZE 255.
    Data
    DATA: it_dd03p TYPE TABLE OF dd03p,
          is_dd03p TYPE dd03p.
    DATA: it_rdata  TYPE TABLE OF text1024,
          is_rdata  TYPE text1024.
    DATA: it_fields TYPE TABLE OF fieldname.
    DATA: it_file  TYPE REF TO data,
          is_file  TYPE REF TO data.
    DATA: w_error  TYPE text132.
    Macros
    DEFINE write_error.
      concatenate 'Error: table'
                  p_table
                  &1
                  &2
             into w_error
             separated by space.
      condense w_error.
      write: / w_error.
      stop.
    END-OF-DEFINITION.
    Field symbols
    FIELD-SYMBOLS: <table> TYPE STANDARD TABLE,
                   <data>  TYPE ANY,
                   <fs>    TYPE ANY.
    Selection screen
    SELECTION-SCREEN: BEGIN OF BLOCK b01 WITH FRAME TITLE text-b01.
    PARAMETERS: p_file  TYPE localfile DEFAULT 'C:\temp\' OBLIGATORY,
                p_separ TYPE c DEFAULT ';' OBLIGATORY.
    SELECTION-SCREEN: END OF BLOCK b01.
    SELECTION-SCREEN: BEGIN OF BLOCK b02 WITH FRAME TITLE text-b02.
    PARAMETERS: p_table TYPE tabname OBLIGATORY
                                     MEMORY ID dtb
                                     MATCHCODE OBJECT dd_dbtb_16.
    SELECTION-SCREEN: END OF BLOCK b02.
    SELECTION-SCREEN: BEGIN OF BLOCK b03 WITH FRAME TITLE text-b03.
    PARAMETERS: p_create TYPE c AS CHECKBOX.
    SELECTION-SCREEN: END OF BLOCK b03,
                      SKIP.
    SELECTION-SCREEN: BEGIN OF BLOCK b04 WITH FRAME TITLE text-b04.
    PARAMETERS: p_nodb RADIOBUTTON GROUP g1 DEFAULT 'X'
                                   USER-COMMAND rg1,
                p_save RADIOBUTTON GROUP g1,
                p_dele RADIOBUTTON GROUP g1.
    SELECTION-SCREEN: SKIP.
    PARAMETERS: p_test TYPE c AS CHECKBOX,
                p_list TYPE c AS CHECKBOX DEFAULT 'X'.
    SELECTION-SCREEN: END OF BLOCK b04.
    At selection screen
    AT SELECTION-SCREEN.
      IF sy-ucomm = 'RG1'.
        IF p_nodb IS INITIAL.
          p_test = 'X'.
        ENDIF.
      ENDIF.
    At selection screen
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      CALL FUNCTION 'F4_FILENAME'
           EXPORTING
                field_name = 'P_FILE'
           IMPORTING
                file_name  = p_file.
    Start of selection
    START-OF-SELECTION.
      PERFORM f_table_definition USING p_table.
      PERFORM f_upload_data USING p_file.
      PERFORM f_prepare_table USING p_table.
      PERFORM f_process_data.
      IF p_nodb IS INITIAL.
        PERFORM f_modify_table.
      ENDIF.
      IF p_list = 'X'.
        PERFORM f_list_records.
      ENDIF.
    End of selection
    END-OF-SELECTION.
          FORM f_table_definition                                       *
    -->  VALUE(IN_TABLE)                                               *
    FORM f_table_definition USING value(in_table).
      DATA: l_tname TYPE tabname,
            l_state TYPE ddgotstate,
            l_dd02v TYPE dd02v.
      l_tname = in_table.
      CALL FUNCTION 'DDIF_TABL_GET'
           EXPORTING
                name          = l_tname
           IMPORTING
                gotstate      = l_state
                dd02v_wa      = l_dd02v
           TABLES
                dd03p_tab     = it_dd03p
           EXCEPTIONS
                illegal_input = 1
                OTHERS        = 2.
      IF l_state NE 'A'.
        write_error 'does not exist or is not active' space.
      ENDIF.
      IF l_dd02v-tabclass NE 'TRANSP' AND
         l_dd02v-tabclass NE 'CLUSTER'.
        write_error 'is type' l_dd02v-tabclass.
      ENDIF.
    ENDFORM.
          FORM f_prepare_table                                          *
    -->  VALUE(IN_TABLE)                                               *
    FORM f_prepare_table USING value(in_table).
      DATA: l_tname TYPE tabname,
            lt_ftab TYPE lvc_t_fcat.
      l_tname = in_table.
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
           EXPORTING
                i_structure_name = l_tname
           CHANGING
                ct_fieldcat      = lt_ftab
           EXCEPTIONS
                OTHERS           = 1.
      IF sy-subrc NE 0.
        WRITE: / 'Error while building field catalog'.
        STOP.
      ENDIF.
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = lt_ftab
        IMPORTING
          ep_table        = it_file.
      ASSIGN it_file->* TO <table>.
      CREATE DATA is_file LIKE LINE OF <table>.
      ASSIGN is_file->* TO <data>.
    ENDFORM.
          FORM f_upload_data                                            *
    -->  VALUE(IN_FILE)                                                *
    FORM f_upload_data USING value(in_file).
      DATA: l_file    TYPE string,
            l_ltext   TYPE string.
      DATA: l_lengt   TYPE i,
            l_field   TYPE fieldname.
      DATA: l_missk   TYPE c.
      l_file = in_file.
      l_lengt = strlen( in_file ).
      FORMAT INTENSIFIED ON.
      WRITE: / 'Reading file', in_file(l_lengt).
      CALL FUNCTION 'GUI_UPLOAD'
           EXPORTING
                filename = l_file
                filetype = 'ASC'
           TABLES
                data_tab = it_rdata
           EXCEPTIONS
                OTHERS   = 1.
      IF sy-subrc <> 0.
        WRITE: /3 'Error uploading', l_file.
        STOP.
      ENDIF.
    File not empty
      DESCRIBE TABLE it_rdata LINES sy-tmaxl.
      IF sy-tmaxl = 0.
        WRITE: /3 'File', l_file, 'is empty'.
        STOP.
      ELSE.
        WRITE: '-', sy-tmaxl, 'rows read'.
      ENDIF.
    File header on first row
      READ TABLE it_rdata INTO is_rdata INDEX 1.
      l_ltext = is_rdata.
      WHILE l_ltext CS p_separ.
        SPLIT l_ltext AT p_separ INTO l_field l_ltext.
        APPEND l_field TO it_fields.
      ENDWHILE.
      IF sy-subrc = 0.
        l_field = l_ltext.
        APPEND l_field TO it_fields.
      ENDIF.
    Check all key fields are present
      SKIP.
      FORMAT RESET.
      FORMAT COLOR COL_HEADING.
      WRITE: /3 'Key fields'.
      FORMAT RESET.
      LOOP AT it_dd03p INTO is_dd03p WHERE NOT keyflag IS initial.
        WRITE: /3 is_dd03p-fieldname.
        READ TABLE it_fields WITH KEY table_line = is_dd03p-fieldname
                             TRANSPORTING NO FIELDS.
        IF sy-subrc = 0.
          FORMAT COLOR COL_POSITIVE.
          WRITE: 'ok'.
          FORMAT RESET.
        ELSEIF is_dd03p-datatype NE 'CLNT'.
          FORMAT COLOR COL_NEGATIVE.
          WRITE: 'error'.
          FORMAT RESET.
          l_missk = 'X'.
        ENDIF.
      ENDLOOP.
    Log other fields
      SKIP.
      FORMAT COLOR COL_HEADING.
      WRITE: /3 'Other fields'.
      FORMAT RESET.
      LOOP AT it_dd03p INTO is_dd03p WHERE keyflag IS initial.
        WRITE: /3 is_dd03p-fieldname.
        READ TABLE it_fields WITH KEY table_line = is_dd03p-fieldname
                             TRANSPORTING NO FIELDS.
        IF sy-subrc = 0.
          WRITE: 'X'.
        ENDIF.
      ENDLOOP.
    Missing key field
      IF l_missk = 'X'.
        SKIP.
        WRITE: /3 'Missing key fields - no further processing'.
        STOP.
      ENDIF.
    ENDFORM.
          FORM f_process_data                                           *
    FORM f_process_data.
      DATA: l_ltext TYPE string,
            l_stext TYPE text40,
            l_field TYPE fieldname,
            l_datat TYPE c.
      LOOP AT it_rdata INTO is_rdata FROM 2.
        l_ltext = is_rdata.
        LOOP AT it_fields INTO l_field.
          ASSIGN COMPONENT l_field OF STRUCTURE <data> TO <fs>.
          IF sy-subrc = 0.
          Field value comes from file, determine conversion
            DESCRIBE FIELD <fs> TYPE l_datat.
            CASE l_datat.
              WHEN 'N'.
                SPLIT l_ltext AT p_separ INTO l_stext l_ltext.
                WRITE l_stext TO <fs> RIGHT-JUSTIFIED.
                OVERLAY <fs> WITH '0000000000000000'.           "max 16
              WHEN 'P'.
                SPLIT l_ltext AT p_separ INTO l_stext l_ltext.
                TRANSLATE l_stext USING ',.'.
                <fs> = l_stext.
              WHEN 'F'.
                SPLIT l_ltext AT p_separ INTO l_stext l_ltext.
                TRANSLATE l_stext USING ',.'.
                <fs> = l_stext.
              WHEN 'D'.
                SPLIT l_ltext AT p_separ INTO l_stext l_ltext.
                TRANSLATE l_stext USING '/.-.'.
                CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
                     EXPORTING
                          date_external = l_stext
                     IMPORTING
                          date_internal = <fs>
                     EXCEPTIONS
                          OTHERS        = 1.
              WHEN 'T'.
                CALL FUNCTION 'CONVERT_TIME_INPUT'
                     EXPORTING
                          input  = l_stext
                     IMPORTING
                          output = <fs>
                     EXCEPTIONS
                          OTHERS = 1.
              WHEN OTHERS.
                SPLIT l_ltext AT p_separ INTO <fs> l_ltext.
            ENDCASE.
          ELSE.
            SHIFT l_ltext UP TO p_separ.
            SHIFT l_ltext.
          ENDIF.
        ENDLOOP.
        IF NOT <data> IS INITIAL.
          LOOP AT it_dd03p INTO is_dd03p WHERE datatype = 'CLNT'.
          This field is mandant
            ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
                                                          TO <fs>.
            <fs> = sy-mandt.
          ENDLOOP.
          IF p_create = 'X'.
            IF is_dd03p-rollname = 'ERDAT'.
              ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
                                                            TO <fs>.
              <fs> = sy-datum.
            ENDIF.
            IF is_dd03p-rollname = 'ERZET'.
              ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
                                                            TO <fs>.
              <fs> = sy-uzeit.
            ENDIF.
            IF is_dd03p-rollname = 'ERNAM'.
              ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
                                                            TO <fs>.
              <fs> = sy-uname.
            ENDIF.
          ENDIF.
          IF is_dd03p-rollname = 'AEDAT'.
            ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
                                                          TO <fs>.
            <fs> = sy-datum.
          ENDIF.
          IF is_dd03p-rollname = 'AETIM'.
            ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
                                                          TO <fs>.
            <fs> = sy-uzeit.
          ENDIF.
          IF is_dd03p-rollname = 'AENAM'.
            ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
                                                          TO <fs>.
            <fs> = sy-uname.
          ENDIF.
          APPEND <data> TO <table>.
        ENDIF.
      ENDLOOP.
    ENDFORM.
          FORM f_modify_table                                           *
    FORM f_modify_table.
      SKIP.
      IF p_save = 'X'.
        MODIFY (p_table) FROM TABLE <table>.
      ELSEIF p_dele = 'X'.
        DELETE (p_table) FROM TABLE <table>.
      ELSE.
        EXIT.
      ENDIF.
      IF sy-subrc EQ 0.
        FORMAT COLOR COL_POSITIVE.
        IF p_save = 'X'.
          WRITE: /3 'Modify table OK'.
        ELSE.
          WRITE: /3 'Delete table OK'.
        ENDIF.
        FORMAT RESET.
        IF p_test IS INITIAL.
          COMMIT WORK.
        ELSE.
          ROLLBACK WORK.
          WRITE: '- test only, no update'.
        ENDIF.
      ELSE.
        FORMAT COLOR COL_NEGATIVE.
        WRITE: /3 'Error while modifying table'.
        FORMAT RESET.
      ENDIF.
    ENDFORM.
          FORM f_list_records                                           *
    FORM f_list_records.
      DATA: l_tleng TYPE i,
            l_lasti TYPE i,
            l_offst TYPE i.
    Output width
      l_tleng = 1.
      LOOP AT it_dd03p INTO is_dd03p.
        l_tleng = l_tleng + is_dd03p-outputlen.
        IF l_tleng LT sy-linsz.
          l_lasti = sy-tabix.
          l_tleng = l_tleng + 1.
        ELSE.
          l_tleng = l_tleng - is_dd03p-outputlen.
          EXIT.
        ENDIF.
      ENDLOOP.
    Output header
      SKIP.
      FORMAT COLOR COL_HEADING.
      WRITE: /3 'Contents'.
      FORMAT RESET.
      ULINE AT /3(l_tleng).
    Output records
      LOOP AT <table> ASSIGNING <data>.
        LOOP AT it_dd03p INTO is_dd03p FROM 1 TO l_lasti.
          IF is_dd03p-position = 1.
            WRITE: /3 sy-vline.
            l_offst = 3.
          ENDIF.
          ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data> TO <fs>.
          l_offst = l_offst + 1.
          IF is_dd03p-decimals LE 2.
            WRITE: AT l_offst <fs>.
          ELSE.
            WRITE: AT l_offst <fs> DECIMALS 3.
          ENDIF.
          l_offst = l_offst + is_dd03p-outputlen.
          WRITE: AT l_offst sy-vline.
        ENDLOOP.
      ENDLOOP.
    Ouptut end
      ULINE AT /3(l_tleng).
    ENDFORM.
    Regards,
    Joy.

  • Updating internal table with CSV file

    I have a flat file as below:
    aaaa, bbbb, asdc, dfgfhg, sdfsg, sdf, sdf, sdf, dfg, sdf, sgf, drgftfgh, sgf, drgtf, swftgd, sgf,
    'sjhdfjhf','2003-10-11 07:52:37','167','alkjd',NULL,NULL,NULL,NULL,NULL,'MX1',NULL,NULL,'dkjffdj ,',NULL,NULL,NULL,'1',NULL,NULL,'AR, dfkj ',
    Where we can see it is separated by commas.I want to upload this one into onr internal table.I used GUI_UPLOAD and gave the logic as folows:
    TYPES: BEGIN OF ttab,
    rec(1000) TYPE c,
    END OF ttab.
    TYPES: BEGIN OF tdat,
    aaaa type char10
    bbbb type char10,
    asdc  type char10,
    dfgfhg  type char10,
    sdfsg  type char10,
    sdf  type char10,
    sdf  type char10,
    sdf  type char10,
    dfg   type char10,
    sdf    type char10,
    sgf  type char10,
    drgftfgh  type char10,
    sgf  type char10,
    drgtf  type char10,
    swftgd  type char10,
    sgf  type char10,
    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-aaaa
    idat-bbbb ,
    idat-asdc  ,
    idat-dfgfhg  ,
    idat-sdfsg  ,
    idat-sdf  ,
    idat-sdf  ,
    idat-sdf  ,
    idat-dfg   ,
    idat-sdf    ,
    idat-sgf  ,
    idat-drgftfgh  ,
    idat-sgf  ,
    idat-drgtf  ,
    idat-swftgd  ,
    idat-sgf  ,
    APPEND idat.
    ENDLOOP.
    Now the issue is when I use the statement SPLIT itab-rec AT ',' this is not updating the table idat properly.Because the flat file contains the value as 'dkjffdj ,', too.
    Can anyone give me some solution to update the internal table.

    hI
    or you delete ' from csv file before uploading it or after uploading it, in this last case u can use statament replace:
    REPLACE ''' WITH SPACE INTO ITAB-FIELD.
    Max

  • Upload a .CSV File into an Internal table

    Hi,
    What are the parameters to be filled into the Function Modules "GUI_UPLOAD" and "ALSM_EXCEL_TO_INTERNAL_TABLE" to Upload a .CSV File into an internal table.
    Please send a sample code to support this....
    Regards,
    Aadhi.

    Hi,
            Check the below code.
    TYPE-POOLS: truxs.
    TYPES:
      BEGIN OF ty_line,
        vbeln LIKE vbap-vbeln,
        posnr LIKE vbap-posnr,
      END OF ty_line.
    *data:  ty_Lines TYPE STANDARD TABLE of ty_Line WITH DEFAULT KEY.
    DATA: itab   TYPE STANDARD TABLE OF ty_line WITH DEFAULT KEY.
    DATA: itab1  TYPE truxs_t_text_data.
    SELECT
      vbeln
      posnr
      UP TO 10 ROWS
      FROM vbap
      INTO TABLE itab.
    CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
      EXPORTING
        i_field_seperator    = ';'
      TABLES
        i_tab_sap_data       = itab
      CHANGING
        i_tab_converted_data = itab1
      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.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename = 'd:\TEMP\test1.txt'
      TABLES
        data_tab = itab1
      EXCEPTIONS
        OTHERS   = 1.
    IF sy-subrc eq 0.
      WRITE: 'Data downloaded successfully'.
    ENDIF.
    DATA: BEGIN OF IEXCEL OCCURS 0.
          INCLUDE STRUCTURE ALSMEX_TABLINE.
    DATA: END OF IEXCEL.
    PARAMETERS: FILENM   LIKE rlgrap-filename MEMORY ID M01,
                NOHEADER AS CHECKBOX.
    call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
      exporting
        filename                      = FILENM
        i_begin_col                   = 1
        i_begin_row                  = 1
        i_end_col                     = 100
        i_end_row                     = 30000
      tables
        intern                        = IEXCEL
      EXCEPTIONS
        INCONSISTENT_PARAMETERS       = 1
        UPLOAD_OLE                    = 2
        OTHERS                        = 3.
    if sy-subrc <> 0.
       WRITE: / 'EXCEL UPLOAD FAILED ', FILENM, SY-SUBRC.
    endif.

  • Internal Table to CSV

    Hi Experts ,
    How can I convert my data in internal table to CSV ? I am in SAP CRM 4.0. In R/3 I saw FM for converting into CSV format which is SAP_CONVERT_TO_CSV_FORMAT but its not available in CRM 4.0. Is there any FM available in CRM 4.0.
    Please help.
    Many Thanks,
    Neeraj

    Hello Neeraj,
    FM:SAP_CONVERT_TO_CSV_FORMAT is not basis module but belogs to FI-TR. So it is not on CRM. I could't find similar FM on CRM, so you should create your FM refer to FM:SAP_CONVERT_TO_CSV_FORMAT on ERP.
    Regards,
    Masayuki

  • Problem in convering internal table to CSV file

    Hi,
    Iam converting internal table data to CSV format with the code given below.
    LOOP AT it_details_final INTO wa_details_final.
    CLEAR : t_attachment.
    CONSTANTS : c_sep TYPE c VALUE ','.
    CONCATENATE wa_details_final-wf_rectype
                             wa_details_final-wf_bankn
                             wa_details_final-wf_znme1
                             wa_details_final-wf_rzawe
                             wa_details_final-wf_lifnr
                             wa_details_final-wf_chect
                             wa_details_final-wf_rwbtr
                             wa_details_final-wf_chkladat
                        cl_abap_char_utilities=>newline
               INTO t_attachment SEPARATED BY c_sep.
    APPEND t_attachment.
        CLEAR t_attachment.
      ENDLOOP.
    Problem is ,data in one of the fields contain comma ( , ).
    So, data after comma is getting shifted to the adjacent cell.
    Please help me
    Thanks & Regards,
    Sravanthi

    Hello,
    Try this perform
    the ignorefields variable is used if you dont want a particular field in the output. You can ignore it for now
      DATA: p_ignoredfields(1024).
    CONSTANTS : const_sep TYPE c VALUE ','.
    * itab to store data ready to be sent to csv file
      DATA: BEGIN OF wa_csvdata,
        line(4096),
      END OF wa_csvdata.
      DATA: gt_csvdata LIKE TABLE OF wa_csvdata.
    *&      Form  CONVERT_TO_CSV
    *       text
    FORM convert_to_csv  TABLES   lt_datatab USING value(p_ignoredfields).
      FIELD-SYMBOLS: <wa_datatab> TYPE ANY.
      FIELD-SYMBOLS: <wa_field> TYPE ANY.
    * character variable incase table fields are of a diff type (ie: int)
      DATA: lv_data TYPE string.
    * set to X if the no data has been put into the csv workarea
      DATA: flag_firstcol TYPE xflag.
    * move the structure one character to the right since first char
    *  is position 0 in SAP
      SHIFT p_ignoredfields BY 1 PLACES RIGHT.
      REFRESH gt_csvdata.
      CLEAR wa_csvdata.
      LOOP AT lt_datatab ASSIGNING <wa_datatab>.
        flag_firstcol = 'X'.
        DO.
    *  one by one assign each position of the structure to the field
          ASSIGN COMPONENT sy-index OF STRUCTURE <wa_datatab> TO <wa_field>.
          IF sy-subrc <> 0.
            EXIT.
          ELSE.
    *  if the current field needs to be ignored then continue the do loop
            IF p_ignoredfields+sy-index(1) = '.'.
              CONTINUE.
            ENDIF.
    *  we use lv_data since concatenate fails for integer types
            lv_data = <wa_field>.
    *  remove commas in the data
            WHILE sy-subrc = 0.
              REPLACE const_sep WITH '' INTO lv_data.
            ENDWHILE.
    *       if this data belongs to the first non ignored column
            IF flag_firstcol = 'X'.
              wa_csvdata = lv_data.
              flag_firstcol = ''.
            ELSE.
              CONCATENATE wa_csvdata const_sep lv_data INTO wa_csvdata.
            ENDIF.
          ENDIF.
        ENDDO.
        APPEND wa_csvdata TO gt_csvdata.
        CLEAR wa_csvdata.
      ENDLOOP.
    ENDFORM.                    " CONVERT_TO_CSV

  • CSV - Internal table - CVS

    Hi all,
    type-pools: KCDE.
    data:  itab_csv type KCDE_INTERN.
    DATA: i_text(9999) TYPE c OCCURS 0.
    CONSTANTS c_delimiter(1) TYPE c VALUE ';'.
    SELECTION-SCREEN BEGIN OF BLOCK 001.
    PARAMETERS: p_file LIKE RLGRAP-FILENAME OBLIGATORY DEFAULT 'c:\temp\EBV\sap_input_without_header.csv'.
    SELECTION-SCREEN END OF BLOCK 001.
    CALL FUNCTION 'KCD_CSV_FILE_TO_INTERN_CONVERT'
      EXPORTING
        i_filename            = p_file
        i_separator           = c_delimiter
      tables
        e_intern              = itab_csv
    EXCEPTIONS
       UPLOAD_CSV            = 1
       UPLOAD_FILETYPE       = 2
       OTHERS                = 3
    This part of the coding works nice, all CSV content will be IMPORTED to internal table itab_csv.
    Empty cells will be left empty in the internal table as well, so the structure of the itab is: ROW, COLUMN, VALUE.
    Now that I have this information, I'm going to modify some of the values and want to EXPORT the modified itab to CSV format again.
    Is there an appropriate function module available?
    Ciao

    Hi,
    Just create a simple text file with you colums separated by ';'.
    Then save it either on the server or on a local machine.
    To create the file, use
    OPEN DATASET dsn FOR INPUT. "(to open the file)
    TRANSFER line TO dsn. "(to write into the file)
    CLOSE DATASET dsn. "(to close the file)
    Hope that will help.
    Regards,
    Yann

  • CSV separated by ";" to internal table

    Hello,
    I've read a CSV into text internal table like that:
    data: begin of it_text occurs 0,
               text(1024) type c,
             end of it_text.
    But I need the data in another internal table with my fields like that:
    data: begin of it_mats occurs 0,
              matnr type matnr,
              maktx type maktx,
            end of it_mats.
    I can't use gui_upload to read the file because I'm reading the CSV file through FTP and not from a PC.
    My question is, is there any Function Module to fill my it_mats table with the data of it_text table?
    The data of the it_texts looks like that:
    [1] 34;Description of material 34
    [2] 35;Description of material 35
    And I need the output like that:
    [1] MATNR = 34 | MAKTX = Description of material 34
    [2] MATNR = 35 | MAKTX = Description of material 35
    Edited by: Marshal Oliveras on May 13, 2008 11:04 AM

    Hi Marshal,
    Below is the solution for Tab Delimited file and you can extend the below logic with whichever the separator you want:
    constants c_tab type ABAP_CHAR1 value CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    data: begin of it_text occurs 0,
               text(1024) type c,
             end of it_text.
    data: begin of it_mats occurs 0,
              matnr type matnr,
              maktx type maktx,
            end of it_mats.
    loop at it_text.
      split it_text-text at c_tab into it_mats-matnr
                                       it_mats-maktx.
      append it_mats.
      clear  it_mats.
    endloop.
    Regards,
    Satya
    Edited by: satyanarayana tanguturu on May 13, 2008 11:14 AM

  • Error converting CSV file into internal table

    Hi,
    I have to convert a large CSV file (>20.000 entries) into an internal table. I used FM GUI_UPLOAD to get a raw data table then convert this table using FM TEXT_CONVERT_CSV_TO_SAP.
    But this does not seem to work properly: after 16.000 or so, the FM seems stuck as if in an endless loop.
    Note that if I split the CSV file in several parts, the conversion runs successfully.
    Is there any memory limit with this FM ?
    Thanks,
    Florian

    Florian Labrouche,
    Instead of using two function modules, you can use  'TEXT_CONVERT_XLS_TO_SAP' function module once by specifying file name in that function module itself. It does not take much time.
    Check the sample program.
    report  zvenkat-upload-xl  no standard page heading.
    "Declarations.
    "types
    types:
          begin of t_bank_det,
            pernr(8)  type c,
            bnksa(4)  type c,
            zlsch(1)  type c,
            bkplz(10) type c,
            bkort(25) type c,
            bankn(18) type c,
          end of t_bank_det.
    "work areas
    data:
          w_bank_det type t_bank_det.
    "internal tables
    data:
          i_bank_det type table of t_bank_det.
    " selection-screen
    selection-screen begin of block b1 with frame title text_001.
    parameters p_file type localfile.
    selection-screen end of block b1.
    "At selection-screen on value-request for p_file.
    at selection-screen on value-request for p_file.
      perform f4_help.
      "Start-of-selection.
    start-of-selection.
      perform upload_data.
      "End-of-selection.
    end-of-selection.
      perform display_data.
      "Form  f4_help
    form f4_help .
      data:
            l_file_name like  ibipparms-path  .
      call function 'F4_FILENAME'
        exporting
          program_name  = syst-cprog
          dynpro_number = syst-dynnr
          field_name    = 'P_FILE'
        importing
          file_name     = l_file_name.
      p_file = l_file_name.
    endform.                                                    " f4_help
    "Form  upload_data
    form upload_data .
      type-pools:truxs.
      data:li_tab_raw_data type  truxs_t_text_data.
      data:l_filename      like  rlgrap-filename.
      l_filename = p_file.
      call function 'TEXT_CONVERT_XLS_TO_SAP'
        exporting
          i_tab_raw_data       = li_tab_raw_data
          i_filename           = l_filename
        tables
          i_tab_converted_data = i_bank_det
        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.
    endform.                    " upload_data
    " Form  display_data
    form display_data .
      data: char100 type char100.
      loop at i_bank_det into w_bank_det .
        if sy-tabix = 1.
          write w_bank_det.
          write / '------------------------------------------------------------'.
        else.
          write / w_bank_det.
        endif.
      endloop.
    endform.                    " display_data
    Regards,
    Venkat.O

  • Uploading CSV file into internal table

    Hi,
    I want to upload a CSV file into internal table.The flat file is having values as below:
    'AAAAA','2003-10-11 07:52:37','167','Argentina',NULL,NULL,NULL,NULL,NULL,'MX1',NULL,NULL,'AAAA BBBB',NULL,NULL,NULL,'1',NULL,NULL,'AR ',NULL,NULL,NULL,'ARGENT','M1V','MX1',NULL,NULL,'F','F','F','F','F',NULL,'1',NULL,'MX','MMI ',NULL
    'jklhg','2004-06-25 08:01:57','456','hjllajsdk','MANAGUA   ',NULL,NULL,'265-5139','266-5136 al 38','MX1',NULL,NULL,'hjgkid GRÖBER','sdfsdf dfs asdfsdf 380 ad ased,','200 as ads, sfd sfd abajao y 50 m al sdf',NULL,'1',NULL,NULL,'NI ',NULL,NULL,NULL,'sdfdfg','M1V','dds',NULL,NULL,
    Here I can not even split at ',' because some of the values are having value like NULL and some have values with comma too,
    The delimiter is a quote and the separator is a comma here.
    Can anyone help on this?
    Thanks.
    Edited by: Ginger on Jun 29, 2009 9:08 AM

    As long as there can be a comma in a text literal you are right that the spilt command doesn't help. However there is one possibility how to attack this under one assumption:
    - A comma outside a text delimiter is always considered a separator
    - A comma inside a text delimiter is always considered a comma as part of the text
    You have to read you file line by line and then travel along the line string character by character and setting a flag or counter for the text delimiters:
    e.g.
    "Text","Text1, Text2",NULL,NULL,"Text"
    String Index  1: EQ " => lv_delimiter = 'X'
    String Index  2: EQ T => text literal (because lv_delimiter = 'X')
    String Index  3: EQ e => text literal (because lv_delimiter = 'X')
    String Index  4: EQ x => text literal (because lv_delimiter = 'X')
    String Index  5: EQ t => text literal (because lv_delimiter = 'X')
    String Index  6: EQ " => lv_delimiter = ' ' (because it was 'X' before)
    String Index  7: EQ , => This is a separator because lv_delimiter = ' '
    String Index  8: EQ " => lv_delimiter = 'X' (because it was ' ' before)
    String Index  9: EQ T => text literal (because lv_delimiter = 'X')
    String Index 10: EQ e => text literal (because lv_delimiter = 'X')
    String Index 11: EQ x => text literal (because lv_delimiter = 'X')
    String Index 12: EQ t => text literal (because lv_delimiter = 'X')
    String Index 13: EQ 1 => text literal (because lv_delimiter = 'X')
    String Index 14: EQ , => text literal (because lv_delimiter = 'X')
    String Index 15: EQ T => text literal (because lv_delimiter = 'X')
    Whenever you hit a 'real' separator (lv_delimiter = ' ') you pass the value of the string before that up to the previous separator into the next structure field.
    This is not an easy way to do it, but if you might have commas in your text literal and NULL values I gues it is probably the only way to go.
    Hope that helps,
    Michael

Maybe you are looking for

  • Mail didn't migrate when I went from Snow Leopard to Mountain Lion

    Just got a new MacBook Pro with Retina.  It came with Lion on it, I upgraded it to Mountain Lion.  Then, I used Migration Assistant to bring over everything from my Time Machine.  My old MacBook Pro was running Snow Leopard.  The big glitch seems to

  • Macbook Pro (mid 2009) display glitch?

    Hello there, I own a 15" Unibody Macbook pro from mid 2009. I haven't had many issues with it until recently. I've had occasional overheating, and sleep problems within the last 6 months but I never got it checked. Yesterday, I opened my Mac from sle

  • Adobe Dreamweaver CC 2014 crash on startup!

    I'm using Windows 7 32-bit with 4GB of RAM on an Intel i3 processor with 500GB of storage. I've tried every solution available out there, removing preferences, reinstalling, removing caches, but all didn't work! This was the error I got, hope you guy

  • Switching between Displays

    Hello. I have an imac and am using Leopard OS X. I hooked up my HDTV to the computer, and am just wondering. Is there any way to turn off the computer screen and just watch the tv screen. I cannot seem to find any way to turn off the computer screen

  • EDI Idoc -- Receiver JMS Adapter.

    Hi, I'm facing this issue from few days. Sender is EDI Idoc and contains header and Footer. This is placed in the application server of SAP system. From there xi picks the EDI Idoc and sends to JMS server. Facing problem on the receiver JMS Adapter.