03-03-2010 11:08 AM
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.
03-03-2010 3: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.
03-03-2010 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.
03-03-2010 11:15 AM
Hi Rainer,
I already use the length parameter in my transfer instruction.
Regards,
Moez.
03-03-2010 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.
03-03-2010 11:18 AM
Hi Shankar,
I know exactly the length of each field V_1 , V_2 ...
That's why I know exactly the length of each V_TRAIL in each line.
For the value of V_TRAIL I keep it initial (blank) as it's defined.
Regards,
Moez.
03-03-2010 11:31 AM
To be honest its hard to believe that the length parameter will fail.
If the value of len is greater than the number of characters or bytes in dobj, hexadecimal 0 or blank characters are transferred to the file instead of the missing bytes or characters, depending on whether the file was opened as a (legacy) text file or a (legacy) binary file.
Try using string as output variable. Of course you need to make sure that the len is 128, for tesing i would like to insert a strlen( ) test.
03-03-2010 1:01 PM
Rainer,
I will try with strings and feed you back.
Thanks,
Rgrds,
Moez.
03-03-2010 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
03-03-2010 3: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.
03-03-2010 4:07 PM
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.
03-03-2010 4:16 PM
Hi,
<li> I believe it works if you change the below way.
Instead of
Change to
CONCATENATE V_1 V_2 V_TRAIL INTO IT_OUTB-LINE RESPECTING BLANKS.
APPEND IT_OUTB.
Thanks
Venkat.O
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.
03-03-2010 5:45 PM
You cannot realize SPACEs with character literals but can do so using string literals.
BR,
Suhas