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

How do I TRULY remove the CRLF (#) from the last field read in CSV dataset?

Good day, everyone!

PLEASE NOTE: I spent most of yesterday searching SDN and reading all kinds of threads on this topic. Yes, I know, there ARE other threads out there regarding this topic, but I spent all of yesterday afternoon trying every solution posted and nothing worked. So, to my knowledge, nobody has yet to post a definite solution to this problem.

I am reading a comma-delimited CSV file from our Application Server. It was originally in Microsoft Excel but saved as a CSV file. I open the file as follows:

OPEN DATASET p_fname FOR INPUT IN TEXT MODE ENCODING DEFAULT.

Here is my loop to read the entire file into an internal table, splitting it into individual fields:

READ DATASET p_fname INTO wa_unsplit.

WHILE sy-subrc EQ 0.

ADD 1 TO w_unsplit_tot.

SPLIT wa_unsplit AT w_comma INTO:

wa_split-massn

wa_split-massg

wa_split-curr

wa_split-persg

wa_split-pernr

wa_split-persid

wa_split-persk

wa_split-stat2

wa_split-fisc_year

wa_split-funds_center

wa_split-plans

wa_split-orgeh

wa_split-abkrs

wa_split-werks

wa_split-sem_posit

wa_split-ansal

wa_split-bsgrd

wa_split-adm_adj_amt

wa_split-hourly_rate.

APPEND wa_split TO it_split.

CLEAR: wa_unsplit,

wa_split.

READ DATASET p_fname INTO wa_unsplit.

ENDWHILE.

The problem is that the last field, wa_split-hourly_rate (defined as character length 17) gets a '#' appended to the end of it. This happens with each record, and it appears to be the CR/LF character (the value of it in hex is the same as cl_abap_char_utilities=>cr_lf).

I've tried everything previously recommended to strip this character from my hourly_rate field. I've tried another STRIP command. I've tried REPLACE and TRANSLATE and a whole slew of things. Despite all the threads that exist on SDN about this, I've yet to find something that truly works.

Certainly I can't be the first person reading a file from the Application Server and having this issue.

Please do NOT post links to solutions that DO NOT WORK! Full points will be awarded to anyone who can solve this challenge.

Thanks everyone!

Tags:
replied

You can split wa_split-hourly_rate using cl_abap_char_utilities=>cr_lf :

SPLIT wa_split-hourly_rate AT cl_abap_char_utilities=>cr_lf INTO: wa_split-hourly_rate aux.

Regards

1 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question