Application Development and Automation 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: 
Read only

Tab space

Former Member
0 Likes
1,301

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.

1 ACCEPTED SOLUTION
Read only

Puneet_Gupta
Contributor
0 Likes
1,217

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

10 REPLIES 10
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,217

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

Read only

0 Likes
1,217

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>.

Read only

Puneet_Gupta
Contributor
0 Likes
1,217

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

Read only

0 Likes
1,217

Hi puneet,

its very confusing ...can u write simple code

Read only

Puneet_Gupta
Contributor
0 Likes
1,218

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

Read only

0 Likes
1,217

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

Read only

0 Likes
1,217

SEPARATED BY cl_abap_char_utilities=>horizontal_tab.

this statement is giving error ..i m using 4.6c

Read only

0 Likes
1,217

Right, this class does not exist in 46c, so use the hex value, as you already have done.

CONSTANTS : c_tab TYPE x VALUE '09'.



.....
separated by c_tab

.

Regards,

Rich Heilman

Read only

0 Likes
1,217

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

Read only

Puneet_Gupta
Contributor
0 Likes
1,217

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