‎2006 Jun 21 10:26 PM
hi,
my o/p will be each field seperated by tab space..when there is no value for any field then it should be seperated by tab space...how to do for below code
CONSTANTS : c_tab TYPE x VALUE '09'.
CONCATENATE lv_r_i
lv_sp_id
lv_sp_name
lv_c_date
lv_c_time
lv_file_format
lv_file_version
INTO output_string1
SEPARATED BY c_tab.
WRITE 😕 output_string1.
‎2006 Jun 21 11:44 PM
Hi Vj,
I am sorry if i confused you.
The same code that you are using should work.
Try this.. and let me know if it works.
CONCATENATE lv_r_i
lv_sp_id
lv_sp_name
lv_c_date
lv_c_time
lv_file_format
lv_file_version
INTO output_string1
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
WRITE 😕 output_string1.
Regds
Puneet
‎2006 Jun 21 10:31 PM
You will need to put a value in there before concatenating. SOme kind of placeholder. You will need to check each field first.
CONSTANTS : c_tab TYPE x VALUE '09'.
if lv_r_i is initial.
lv_r_i = <placeholder>.
endif.
if lv_sp_id is initial.
lv_sp_id = <placeholder>.
endif.
.......
CONCATENATE lv_r_i
lv_sp_id
lv_sp_name
lv_c_date
lv_c_time
lv_file_format
lv_file_version
INTO output_string1
SEPARATED BY c_tab.
translate output_string1 '<placeholder> '.
WRITE :/ output_string1.
Regards,
Rich Heilman
‎2006 Jun 21 10:34 PM
Hi Rich,
I am using 30 fields ...for each if write
if lv_r_i is initial.
lv_r_i = <placeholder>.
endif.
it will be lengthy...suggest any other code...
and what is that <placeholder>.
‎2006 Jun 21 10:56 PM
hi vj,
try this:
FIELD-SYMBOLS : <FS1> TYPE ANY.
DATA : L_STRING TYPE STRING.
LOOP AT ITAB.
DO 20 TIMES.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE ITAB TO <FS1>.
IF SY-INDEX NE 1.
CONCATENATE L_STRING <FS1> INTO L_STRING SEPARATED BY
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
ELSE.
L_STRING = <FS1>.
ENDIF.
ENDDO.
WRITE: / L_STRING.
ENDLOOP..
Depending on the number of fields , you can change the count in the DO loop E.g. if you have 30 fields make it DO 30 times.
Using this even if the field is blank, there will be a tabspace for that field too..
Hope this helps.
Thanks,
Puneet
‎2006 Jun 21 11:24 PM
‎2006 Jun 21 11:44 PM
Hi Vj,
I am sorry if i confused you.
The same code that you are using should work.
Try this.. and let me know if it works.
CONCATENATE lv_r_i
lv_sp_id
lv_sp_name
lv_c_date
lv_c_time
lv_file_format
lv_file_version
INTO output_string1
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
WRITE 😕 output_string1.
Regds
Puneet
‎2006 Jun 21 11:53 PM
I was going to suggest that you do this dynamically as Puneet has suggested early, but I noticed that your fields are not part of a structure. So, I would suggest putting them into a structure. For example.
data: begin of x,
lv_r_i(20) type c,
lv_sp_id(20) type c,
lv_sp_name(20) type c,
lv_c_date(20) type c,
lv_c_time(20) type c,
lv_file_format(20) type c,
lv_file_version(20) type c,
end of x.put the values into this structure.
NOw you can use this logic to put all the fields
into your string separated by the tab.
data: l_string type string.
field-symbols: <fs1>.
DO .
ASSIGN COMPONENT SY-INDEX OF STRUCTURE x TO <FS1>.
if sy-subrc <> 0.
exit.
endif.
if <fs1> is initial.
<fs1> = '%'. " placeholder
endif.
IF SY-INDEX NE 1.
CONCATENATE L_STRING <FS1> INTO L_STRING SEPARATED BY
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
ELSE.
L_STRING = <FS1>.
ENDIF.
ENDDO.
translate l_string using '% '.
write:/ l_string.
Make sense now?
Regards,
Rich Heilman
‎2006 Jun 21 11:56 PM
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
this statement is giving error ..i m using 4.6c
‎2006 Jun 21 11:59 PM
‎2006 Jun 22 12:12 AM
HEre is a test program which is working good.
report zrich_0001.
data: begin of x,
lv_r_i(20) type c,
lv_sp_id(20) type c,
lv_sp_name(20) type c,
lv_c_date(20) type c,
lv_c_time(20) type c,
lv_file_format(20) type c,
lv_file_version(20) type c,
end of x.
data: l_string type string.
field-symbols: <fs1>.
CONSTANTS : c_tab TYPE x VALUE '09'.
* Fill the structure
x-lv_r_i = 'ABC'.
x-lv_sp_id = 'DEF'.
x-lv_sp_name = space . "'GHI'. <--- Empty field
x-lv_c_date = 'JKL'.
x-lv_c_time = 'MNO'.
x-lv_file_format = 'PQR'.
x-lv_file_version = 'STU'.
do .
assign component sy-index of structure x to <fs1>.
if sy-subrc <> 0.
exit.
endif.
* CHeck the field value, and provide a placeholder
if <fs1> is initial.
<fs1> = '%'. " placeholder
endif.
if sy-index ne 1.
concatenate l_string <fs1> into l_string
separated by c_tab.
else.
l_string = <fs1>.
endif.
enddo.
translate l_string using '% '.
write:/ l_string.
REgards,
Rich Heilman
‎2006 Jun 22 12:11 AM
Hi Vj,
I thought you were on 5.0.
For 4.6C , your original code should work fine.
Can you tell me what is the exact problem that you are facing?
Thanks,
Puneet