‎2011 Jul 20 11:58 AM
Hi All,
I have to write a file on the application server. I've used CONDENSE for the data to be written but there is always a blank space after every field( before the added delimiter) . A delimiter has also been used after every field. The output is coming in the below format:-
EAR_LCR , ,0006036387,EXTERNAL ,0001, , , ,Y,EUR ,
I need to suppress these spaces. Please suggest.
‎2011 Jul 20 12:02 PM
Hi,
pass the values to string type variable and do condence the check .
i think this may helps,
Srini.
‎2011 Jul 20 12:02 PM
Hi,
pass the values to string type variable and do condence the check .
i think this may helps,
Srini.
‎2011 Jul 20 12:04 PM
Hi,
Try to use SHIFT LEFT <variable_name> DELETING LEADING SPACE.
Regards,
Pranav
‎2011 Jul 20 12:22 PM
I cannot use shift-left as the I need to modify an existing program with more than 100 variables.
Is there any command which I can use
‎2011 Jul 20 12:33 PM
Hi neha,
please post a couple of code lines so that we know how you proceed with creation aof application server (text?) file..
You may use REPLACE ALL OCCURRENCES OF ` ,` WITH `,` IN <output> - Note: ` ,` means space followed by comma delimiter enclosed in back hyphens to be replaced by comma delimiter only.
Regards
Clemens
‎2011 Jul 20 12:37 PM
This is the code for the program
OPEN DATASET l_fname FOR OUTPUT IN TEXT MODE. " ENCODING DEFAULT.
LOOP AT it_custtemplate .
MOVE: g_delim TO it_custtemplate-dl1,
g_delim TO it_custtemplate-dl2,
g_delim TO it_custtemplate-dl3,
g_delim TO it_custtemplate-dl4,
CONDENSE it_custtemplate.
TRANSFER it_custtemplate TO l_fname.
CLEAR it_custtemplate.
ENDLOOP.
CLOSE DATASET l_fname.
‎2011 Jul 20 12:45 PM
I am working with 4.6C version SAP and I did not find ' Replace all occurrences'. Only replace is available
‎2011 Jul 20 2:11 PM
Hi
Try condesing the individual fields of the internal field , concatenate them and then write to file, writing the complete work area is resulting in spaces. I am not sure if the mentioned result is for the same piece of code ?.
Regards
Pawan
‎2011 Jul 20 5:41 PM
Hi neha jindal,
it seems that your DL1, DL2, etc. fields contain 2 characters. Otherwise, it means the other fields of your internal table contain an erroneous leading space. Use debug to make sure what is the exact reason.
BR
Sandra
‎2011 Jul 20 10:16 PM
Hi neja,
how do you fill the fields of it_custtemplate? Transfer statement will copy the fields in full length.
You could
data:
lv_string type string.
CONCATENATE
it_custtemplate-value01
it_custtemplate-value02
...
it_custtemplate-valuenn
INTO lv_string
SEPARATED BY ','
TRANSFER lv_string TO l_fname.Regards,
Clemens
‎2011 Jul 21 6:04 AM
Hello Pawan,
The problem why I am not condensing or concatenating individual fields is there are more than 30 programs with 100 fields in each program in my case.
So , please let me know if there is any command which can remove these trailing spaces from the entire work area. but, In case there is no work around available I'll try and do it with the concatenation of individual fields.
The structure of it_custtemplate is like below:-
DATA : BEGIN OF it_custtemplate OCCURS 0,
name1 LIKE kna1-name1, " LIKE kna1-name1,
dl1 TYPE c,
stceg LIKE kna1-stceg,
dl2 TYPE c,
kunnr LIKE kna1-kunnr,
dl3(1),
kdgrp(10), " LIKE KNVV-KDGRP,
dl4(1),
brsch LIKE kna1-brsch,
dl5(1),
Thanks for your help.
‎2011 Jul 21 8:21 AM
Neha Jindal,
I believe you can REPLACE atleast, so try below solution.
Before your loop write the below code.
-
data: lt_comp type TABLE OF RSTRUCINFO,
lv_count type i.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-repid
fieldname = 'IT_CUSTTEMPLATE'
tables
components = lt_comp
.
DESCRIBE TABLE lt_comp lines lv_count. "no. of fields in internal table
lv_count = lv_count / 2. "only half are delimiters
-
Then, just after your condense statement, use
do lv_count times.
replace ' ,' in it_custtemplate WITH ','. "space, into ,
enddo.
-
This should solve your problem as it can be pasted directly in any number of programs. Let me know in case of any issue.
Regards,
Diwakar
Edited by: Diwakar Aggarwal on Jul 21, 2011 1:18 PM
‎2011 Jul 21 9:12 AM
Thank you so much Diwakar. The problem is solved now. I won't have to change all the fields in all the programs now .
‎2011 Jul 22 8:44 PM
Hi Neha
I would then suggest you to code the replace all occurences logic (as advised by Clemens) self in a subroutine and reuse it in ur programs. Something like this :
n = strlen( l_string ).
data : offset1 type i value is initial,
offset2 type i value is initial,
l_char_prev type c,
l_char_curr type c.
l_char_curr = l_string+offset1(1).
offset1 = offset1 + 1.
While offset1 le n.
l_char_prev = l_char_curr.
l_char_curr = l_string+offset1(1).
if l_char_curr = ',' and l_char_prev = ' '.
offset2 = offset1 - 1.
REPLACE SECTION OFFSET offset2 LENGTH 2 OF l_string WITH ','.
offset1 = offset2.
else.
offset1 = offset1 + 1.
Endif.
Endwhile.
Write 😕 l_string.
Offcourse this does not handle the pattern ' ,' present in a variable but neither does the SAP standard replace all occurences.
Regards
Pawan
‎2011 Jul 20 12:06 PM
Try using the below statement before the open dataset statement.
PERFORM set_trail_blanks(saplgrap) USING 'X'.
Thanks,
K.Kiran.
‎2011 Jul 20 12:20 PM
Hello Kiran,
I tried using the suggested Perform but , there was no chnage in the output format
‎2011 Jul 20 12:12 PM
Hi neha jindal,
you may try [CONDENSE addition NO-GAPS|http://help.sap.com/abapdocu_702/en/abapcondense.htm].
This will remove all blanks.
Regards,
Clemens
‎2011 Jul 20 12:19 PM
Hello Clemens,
Condense with no gaps will remove all spaces i. in between the words also. So, I cannot use it.
Thanks