Skip to Content

Add trailing spaces to a text

Hello All,

I have an issue with concatenate instruction;

In fact, I want to concatenate some data in several lines, each line must have the length of 128 char.

To get those 128 char filled I should concatenate each time with a trailing space constante V_TRAIL

Then I should output those data to a file.

DATA: BEGIN OF IT_OUTB OCCURS 0,
    LINE(128) TYPE c,
END OF IT_OUTB.
DATA: V_TRAIL(60) TYPE C.
.
.
.
CONCATENATE V_1 V_2 V_TRAIL INTO IT_OUTB-LINE RESPECTING BLANKS.
APPEND IT_OUTB.
.
.
.
DATA: LV_DOS TYPE STRING.
.
.
.
OPEN DATASET LV_DOS FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT IT_OUTB.
    TRANSFER IT_OUTB TO LV_DOS LENGTH 128.
ENDLOOP.
CLOSE DATASET LV_DOS.

The problem is my output file is not generated with the trailing spaces => length of each line is less then 128.

Could you please help me.

Regards,

Moez.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Mar 03, 2010 at 03:23 PM

    You can try this

    DATA: lv_space TYPE string.
    
    lv_space = cl_abap_conv_in_ce=>uccp( '00a0' ).
    
    OPEN DATASET LV_DOS FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    LOOP AT IT_OUTB.
        Lv_pos = strlen( IT_OUTB-line ).
        do 2 times.
        IT_OUTB+lv_pos(1) = lv_space.
        l_pos = lv_pos + 1.
        enddo.
        TRANSFER IT_OUTB TO LV_DOS.
    ENDLOOP.
    CLOSE DATASET LV_DOS.
    

    Add a comment
    10|10000 characters needed characters exceeded

    • Thank you Keshav for your response.

      I did some changes in your suggestion and it's working now:

      OPEN DATASET LV_DOS FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
      LV_SPACE = CL_ABAP_CONV_IN_CE=>UCCP( '00a0' ).
      LOOP AT IT_OUTB.
         WRITE LV_SPACE TO IT_OUTB-LINE+127(1).
         TRANSFER IT_OUTB-LINE TO LV_DOS LENGTH 128.
      ENDLOOP.
      CLOSE DATASET LV_DOS.
      

      Thanks for all.

  • Posted on Mar 03, 2010 at 11:13 AM

    Character variables always have spaces at their end and they will always be ignored. Please read my [blog|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/15889] [original link is broken] [original link is broken] [original link is broken];. Instead using char variables use string variables. Or use LENGTH attribute in your transfer statement.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Mar 03, 2010 at 11:14 AM

    Hi,

    Directly you are concatenating the blan spaces.

    Your not checking the length of filed LINe is < 128 or >128.

    for every line your concatenating....

    Regards,

    Shankar.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Mar 03, 2010 at 11:16 AM

    Hello,

    I think you cannot achieve this using character literals instead use STRING literals (in that case you have to use CL_ABAP_CHAR_UTILITIES=>CR_LF or CL_ABAP_CHAR_UTILITIES=>NEWLINE to get the line break after every 128 characters)

    Read Rainer's blog on Character v/s String Literals, this will help you to get concepts clear.

    BR,

    Suhas

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 03, 2010 at 04:16 PM

    Hi, <li> I believe it works if you change the below way. Instead of

    CONCATENATE V_1 V_2 V_TRAIL INTO IT_OUTB-LINE RESPECTING BLANKS.
    APPEND IT_OUTB.
    
    Change to
    IT_OUTB-LINE+0(63)    = v_1.  "Lets say V_1 has 63 char length
    IT_OUTB-LINE+63(64)   = v_2.  "Lets say V_2 has 64 char length
    IT_OUTB-LINE+127(63)  = space."Blank space
    APPEND IT_OUTB.
    
    Thanks Venkat.O

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.