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

CSV file into SAP

Former Member
0 Likes
1,046

Hi Experts,

I am trying to upload CSV file into SAP it is working fine,

File format:

Test,12333,"Reg. Organisational Development Delegate, TEST TEST, HFHFHFHF, JKSDFAS ",7373737

Problem:

When i am trying to SPLIT with ',' it is taking 3 column "Reg. Organisational Development Delegate, TEST TEST, HFHFHFHF, JKSDFAS" into diff-diff columns but my requirement is i want file data into 4 fields of internal table.

-Rajneesh Gupta

Hi Experts,

I am trying to upload CSV file into SAP it is working fine,

File format:

Test,12333,"Reg. Organisational Development Delegate, TEST TEST, HFHFHFHF, JKSDFAS ",7373737

Problem:

When i am trying to SPLIT with ',' it is taking 3 column "Reg. Organisational Development Delegate, TEST TEST, HFHFHFHF, JKSDFAS" into diff-diff columns but my requirement is i want file data into 4 fields of internal table.

-Rajneesh Gupta

6 REPLIES 6
Read only

Former Member
0 Likes
979

Hi, maybe split the line into workfields, fill the table with the workfields and append the line. Succes

Read only

Former Member
0 Likes
979

>

> Test,12333,"Reg. Organisational Development Delegate, TEST TEST, HFHFHFHF, JKSDFAS ",7373737

Hi,

Then you should not give comma inside "Reg. Organisational Development Delegate, TEST TEST, HFHFHFHF, JKSDFAS ", use some other delimiter inside double quotes.

Regards

Karthik D

Read only

0 Likes
979

Hi Karthik D,

I have file in this format only, this i have given a example.

-Rajneesh

Read only

0 Likes
979

Hi,

First split the file into a string variable.

Concatenate the required fileds and then move it into fieldstring and then append to the internal table.

Or split first all into six columns ,then concatenate 3, 4, 5 fields into a variable and then populate into 4 columned internal table

Read only

0 Likes
979

Hi Sreesudha Gulla,

You are talking about the static solution, but that is not the case, i don't know in which column i will get the situation.

-Rajneesh

Read only

Former Member
0 Likes
979

Hi Rajneesh,

I too had the same problem some months before.

c the link below. it solved my problem. in mean time i search for my code in prog and send u.

[;

check my code.

loop at gt_raw into  gwa_raw.
    if sy-tabix > 1.
      split gwa_raw at ',' into table gt_string.
      describe table gt_string lines gv_fields.
*   If extra commas: field count higher than actual field count
      if gv_fields > 10.
        perform f_reassemble.
      endif.


      loop at gt_string into gwa_string.
        replace all occurrences of '"' in gwa_string with ''.
        case sy-tabix.
          when 1.
            gwa_cust-cust_code = gwa_string.
          when 2.
            gwa_cust-cust_name = gwa_string.
          when 3.
                      :           
                      :
          when 10.
            gwa_cust-osc_code = gwa_string.
        endcase.
      endloop.
      append gwa_cust to gt_cust.
      clear: gwa_cust.
    endif.
  endloop.

form f_reassemble .
  data: lastpos    type i,
        lastchar   type c,
        currtoken  type sy-tabix,
        nexttoken  type sy-tabix,
        gwa_next   type string.

  loop at gt_string into gwa_string.
    lastpos  = strlen( gwa_string ) - 1.
    lastchar = gwa_string+lastpos(1).
*   field starts with quote but does not end with one =>
*   must merge with the next field
    if gwa_string+0(1) = '"' and lastchar ne '"'.
      currtoken = sy-tabix.
      nexttoken = sy-tabix + 1.
      read table gt_string into gwa_next index nexttoken.
      concatenate gwa_string gwa_next into gwa_string separated by ','.
      modify gt_string from gwa_string index currtoken.
      delete gt_string index nexttoken.
    endif.
  endloop.
endform.                    " f_reassemble

Regards,

Sakthi.

Edited by: sakthi sri on Sep 10, 2009 5:42 PM