Application Development 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: 

CL_ABAP_CHAR_UTILITIES=>cr_lf - how to achieve just 'CR'?

Former Member
0 Kudos

I have a Program that downloads a file using TRANSFER statement.  When I use the method,

  CL_ABAP_CHAR_UTILITIES=>cr_lf, it writes  "CR LF" at the end of the file when viewed in notepad.  Is there a way or any field in the method that I can use for having just "CR" at the end of each line of the file?

Here is part of the code...

  

      DATA: BEGIN OF TREC,
       STRING(299),
       CARRIAGE_RETURN(1) TYPE c,
      END OF TREC.

      LOOP AT TEMPTEST INTO TEMPTEST.
      MOVE TEMPTEST-FLD001 TO TREC-STRING+0(1).
      MOVE TEMPTEST-FLD002 TO TREC-STRING+1(3).
      MOVE TEMPTEST-FLD003 TO TREC-STRING+4(2).
      MOVE TEMPTEST-FLD004 TO TREC-STRING+6(10).
      MOVE TEMPTEST-FLD005 TO TREC-STRING+16(1).
      MOVE TEMPTEST-FLD006 TO TREC-STRING+17(1).
      MOVE TEMPTEST-FLD007 TO TREC-STRING+18(1).
      MOVE TEMPTEST-FLD008 TO TREC-STRING+19(1).
      MOVE TEMPTEST-FLD009 TO TREC-STRING+20(10).
      MOVE TEMPTEST-FLD010 TO TREC-STRING+30(10).
      MOVE TEMPTEST-FLD011 TO TREC-STRING+40(6).
      MOVE TEMPTEST-FLD012 TO TREC-STRING+46(35).
      MOVE TEMPTEST-FLD013 TO TREC-STRING+81(21).
      MOVE TEMPTEST-FLD014 TO TREC-STRING+100(198).
      MOVE CL_ABAP_CHAR_UTILITIES=>cr_lf TO TREC-CARRIAGE_RETURN.
      TRANSFER TREC TO PI_A_FILENAME LENGTH 300 NO END OF LINE.
    ENDLOOP.

Thanks!

19 REPLIES 19

Pawan_Kesari
Active Contributor

try cl_abap_char_utilities=>cr_lf(1)

0 Kudos

Making, cl_abap_char_utilities=>cr_lf(1) did not work....

vigneshyeram
Active Participant
0 Kudos

Dear Anjana,

Above code Transfers the data to application server right?
On application server what do you server?

Thanks & Regards,

Vignesh Yeram

vigneshyeram
Active Participant
0 Kudos

Dear Anjana,

Above code Transfers the data to application server right?
On application server how the character is shown?

because i checked the class

constants cr_lf type abap_cr_lf value %_cr_lf.

abap_cr_lf(2)              type c,

So its a two character.

Please try downloading the file in Notepad ++

Kindly let me know your feedback.

Thanks & Regards,

Vignesh Yeram

0 Kudos

Hi Vignesh,

   Yes, the TRANSFER statement is downloading the file to a server which is AS/400.  There it does not show any characters. I then download the file to Notepad++ using a software that we have and that is where I see the CR LF. 

Making it two character did not work either.

I only made it one character hoping that it would eliminate the LF.  Making it two character did not work either.

I also tried using,

   CALL FUNCTION 'FI_DME_CHARACTERS'
    IMPORTING
      e_cr   = hlp_cr.

MOVE HLP_CR TO TREC-CARRIAGE_RETURN.

That did not work either.  It still shows up as, CR LF.

Thanks!

0 Kudos

Dear Anjana,

Please try to remove the field carraige_return.

then try with below options:-

1) MOVE CL_ABAP_CHAR_UTILITIES=>cr_lf  TO TREC-STRING+298(2).

2) MOVE 'CR' to TREC-STRING+298(2).

Kindly let me know your feedback.

Thanks & Regards,

Vignesh Yeram

0 Kudos

Hi Vignesh,

  They did not work....

  The solution,

1) MOVE CL_ABAP_CHAR_UTILITIES=>cr_lf  TO TREC-STRING+298(2).

    gave the same result with CRLF in the file.

Solution,

2) MOVE 'CR' to TREC-STRING+298(2).

    physically put the character 'CR' in the file with no carriage return which is not the intended result.

Thanks!

Former Member
0 Kudos

Hi,

DATA: BEGIN OF TREC,

       STRING(299),

       CARRIAGE_RETURN(1) TYPE c,  --->instead of this try this 

crlf(1)          type c value cl_abap_char_utilities=>CR_LF,

      END OF TREC.

and no need to do

MOVE CL_ABAP_CHAR_UTILITIES=>cr_lf TO TREC-CARRIAGE_RETURN. in the loop.

try and let me know

Thanks

0 Kudos

Hi Sukumar,

  That solution does the same and puts the CRLF in the file.

Thanks!

former_member491621
Contributor
0 Kudos

Hi Anjana,

Maybe you could try a bit of work around

CONSTANTS: CR TYPE CHAR1 VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.              "CR

or

DATA CR TYPE CHAR1.

CR = CL_ABAP_CHAR_UTILITIES=>CR_LF.

MOVE CR TO TREC-CARRIAGE_RETURN.

0 Kudos

Thanks Aniket..but that does not work either.

raymond_giuseppi
Active Contributor
0 Kudos

What if you replace CL_ABAP_CHAR_UTILITIES=>CR_LF by CL_ABAP_CHAR_UTILITIES=>NEWLINE ?

Regards,

Raymond

0 Kudos

Raymond,

NEWLINE gives the same result with CR LF.

Thanks!

0 Kudos

Can you post the OPEN DATASET line of code ?

Regards,

Raymond

0 Kudos

Raymond,

  Here is the OPEN DATASET code in the Program.

      OPEN DATASET PI_A_FILENAME                     

               FOR OUTPUT
                 IN TEXT MODE
                 MESSAGE S_L-MSG ENCODING    
                 DEFAULT.       

I have tried using LEGACY TEXT MODE and that did not work either.         

Former Member
0 Kudos

Try '\r' at the end of the line

MOVE '\r' TO TREC-CARRIAGE_RETURN.

former_member183804
Active Contributor
0 Kudos

Hello Anjana,

with reference to the online documentation I would not expect an easy possiblity to achieve CR in combination with TRANSFER.

I assume opening the data set in BINARY MODE and doing all the conversions (incl. control chars) own your own shall do.

Regards

  Klaus

kgreenwood
Discoverer

for CR

cl_abap_char_utilities=>NEWLINE

for LF

cl_abap_char_utilities=>FORM_FEED

0 Kudos

Wrong.

Unicode characters are:

CARRIAGE RETURN/CR  = U+000D
NEWLINE/LINEFEED/LF = U+000A FORMFEED/FF = U+000C

Pawan Kesari gave the right answer, but was rejected by the OP because the problem is mixed with TRANSFER (write to file) and potential human error for checking the file contents.