Application Development 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: 

Tab space

Former Member
0 Kudos

Hi

i want to insert tab space for fields which contains null values also..how to do

CONSTANTS : c_tab TYPE x VALUE '09'.

CONCATENATE lv_r_id

lv_org_id

lv_org_name

INTO output_string

SEPARATED BY c_tab.

write : output_string.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Your code is correct if you are working in version <47. In higher versions you have to change it to

CONCATENATE lv_r_id

lv_org_id

lv_org_name

INTO output_string

SEPARATED BY cl_abap_char_utilities=>HORIZONTAL_TAB.

23 REPLIES 23

Former Member
0 Kudos

Your code is correct if you are working in version <47. In higher versions you have to change it to

CONCATENATE lv_r_id

lv_org_id

lv_org_name

INTO output_string

SEPARATED BY cl_abap_char_utilities=>HORIZONTAL_TAB.

0 Kudos

CONCATENATE lv_r_id

it_ekko-netwr

it_ekko-ebeln

lv_org_name

INTO output_string

is i m using fields from tables..and if the values of those fields are null then it won't print tab space between fields ..i want to insert tab space for null value also..

0 Kudos

How many threads are you going to open about this. Did these answers not help you solve the problem?

You need to put all of your fields into a structure instead of using all of the separated fields, you can then use the logic to dynamically concatenate them depending on how many fields are in your structure.

The code will leave a space for empty fields in the output string.

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

0 Kudos

NO rich..thats why..actually i didn't understand the code..can u write in simple logic...

0 Kudos

All this is doing is showing how you can concatenate all the fields without actually having all of the fields in your concatenate statement. You said, that you have 30 or so? So instead of listing of this, build a structure, lets call it "X", have all of the fields that you want to concatenate together. Move all of the values from your ITAB fields to this structure. Then in the DO loop, we are assigning each field of the structure "X" to a field symbol which is a pointer to the field. Now we have access to the first field, we need to check each field for a value, if no value, then put a place holder value, like '%', put it in the string, next time thru the DO loop we will be getting the second field of the structure "X", checking for value again, and we will concatenate it with the outputstring which still has the first field in it and separate by the tab. ONce all of the fields have been concatenated in to the string, now we will translate all of the placeholders of the string, in this case, it is "%" into a space.

Does this example make sense now?

Regards,

Rich Heilman

Message was edited by: Rich Heilman

0 Kudos

Please make sure that you close the other thread and lets continue with this one. Next time, please don't open multiple threads for the same question. Thanks.

Regards,

Rich Heilman

0 Kudos

Hi rich,

u used this code before can u write it some what elaborate because i want to use if condition for each field for initialization...

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.

0 Kudos

So you want to use IF conditions now?



report zrich_0001.

data:
      lv_r_i(20) type c value 'ABC',
      lv_sp_id(20) type c value 'DEF',
      lv_sp_name(20) type c value space,  "<--- no value
      lv_c_date(20) type c value 'GHI',
      lv_c_time(20) type c value 'JKL',
      lv_file_format(20) type c value 'MNO',
      lv_file_version(20) type c value 'PQR'.

data: output_string1 type string.

constants : c_tab type x value '09'.

if lv_r_i is initial.
  lv_r_i = '%'.
endif.

if lv_sp_id is initial.
  lv_sp_id = '%'.
endif.

if lv_sp_name is initial.
  lv_sp_name = '%'.
endif.

if lv_c_date is initial.
  lv_c_date = '%'.
endif.

if lv_c_time is initial.
  lv_c_time = '%'.
endif.

if lv_file_format is initial.
  lv_file_format = '%'.
endif.

if lv_file_version is initial.
  lv_file_version = '%'.
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 using '% '.

write 😕 output_string1.


Regards,

Rich Heilman

0 Kudos

You can shorten it up a little by using a macro.



report zrich_0001.

data:
      lv_r_i(20) type c value 'ABC',
      lv_sp_id(20) type c value 'DEF',
      lv_sp_name(20) type c value space,  ""<--- no value
      lv_c_date(20) type c value 'GHI',
      lv_c_time(20) type c value 'JKL',
      lv_file_format(20) type c value 'MNO',
      lv_file_version(20) type c value 'PQR'.

data: output_string1 type string.

constants : c_tab type x value '09'.

define macro_check_value.
if &1 is initial.
  &1 = '%'.
endif.

end-of-definition.

macro_check_value lv_r_i.
macro_check_value lv_sp_id.
macro_check_value lv_sp_name.
macro_check_value lv_c_date.
macro_check_value lv_c_time.
macro_check_value lv_file_format.
macro_check_value lv_file_version.

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 using '% '.

write 😕 output_string1.

Regards,

Rich Heilman

0 Kudos

I am using concatenate statment inside the loop..so where shall i write macro statement inside the loop statement or outside...is it correct

data: output_string1 type string.

constants : c_tab type x value '09'.

define macro_check_value.

if &1 is initial.

&1 = '%'.

endif.

end-of-definition.

macro_check_value lv_r_i.

macro_check_value lv_sp_id.

macro_check_value lv_sp_name.

macro_check_value lv_c_date.

macro_check_value lv_c_time.

macro_check_value lv_file_format.

macro_check_value lv_file_version.

<b>loop at itab.</b>

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 using '% '.

write 😕 output_string1.

<b>endloop.</b>

0 Kudos

If you values are in an internal table, then yes, the marcro statements need to be inside the loop. You want do check the values for each line of the internal table, right?



data: output_string1 type string.

constants : c_tab type x value '09'.

define macro_check_value.
if &1 is initial.
&1 = '%'.
endif.

end-of-definition.



loop at itab.

<b>macro_check_value itab-lv_r_i.
macro_check_value itab-lv_sp_id.
macro_check_value itab-lv_sp_name.
macro_check_value itab-lv_c_date.
macro_check_value itab-lv_c_time.
macro_check_value itab-lv_file_format.
macro_check_value itab-lv_file_version.</b>

concatenate <b>itab-lv_r_i
itab-lv_sp_id
itab-lv_sp_name
itab-lv_c_date
itab-lv_c_time
itab-lv_file_format
itab-lv_file_version</b>into output_string1
separated by c_tab.

translate output_string1 using '% '.

write 😕 output_string1.
endloop.


Regards,

Rich Heilman

0 Kudos

Hi Rich,

But in the o/p .. the null value is showing %..will it be tab space while we download to desktop...

0 Kudos

You have to get rid of it after the concatenation.

translate output_string1 using '% '.

REgards,

Rich Heilman

0 Kudos

try

CONCATENATE

lv_r_id

cl_abap_char_utilities=>HORIZONTAL_TAB

lv_org_id

cl_abap_char_utilities=>HORIZONTAL_TAB

lv_org_name

INTO output_string.

regards,

Clemens

0 Kudos

You have to get rid of it after the concatenation.

translate output_string1 using '% '.

i have used above statement..but in the o/p it is displaying %....do i need to convert to some other thing...

0 Kudos

Make sure that this statement include a % and a space.

translate output_string1 using '% '.  <-- See the space next to the %

REgards,

Rich Heilman

0 Kudos

Hi rich,

but iam using loop ...how should i include it...actually my code will be...

loop at itab.

concatenate ...

...

sepearted by c_tab.

into table output_string1.

if v1 = m1.

move : ...

loop at itab1.

concatenate ....

...

separeated by c_tab.

into table output_string2.

endloop.

endloop.

and how do i include below code ....please help me....

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.

0 Kudos

You need to translate it inside the loop, just before you write the OUTPUT_STRING.



loop at itab.
concatenate ...
...
sepearted by c_tab.
into table output_string1.

if v1 = m1.
move : ...
loop at itab1.
concatenate ....
...
separeated by c_tab.
into table output_string2.
<b>translate output_string2 using '% '.
write:/ output_string2.</b>
endloop.
endloop.




Regards,

Rich Heilman

0 Kudos

Yes Rich..

I kept as it is ..but in the o/p it is showing % for null value...but i want tab space instead of it...

Thnaks in advance

0 Kudos

Email me your complete code. The entire program

Regards,

Rich Heilman

0 Kudos

I have mailed my complete code to ...

Thanks in advance..

Message was edited by: vj bb

0 Kudos

Vj, PLEASE remove my email address from your previous post.

Here is the problem. You are not translating the right fields. Both translate statements are using OUTPUT_STRING! Change them to the respective field.



.....


        translate output_string1 using '% '.   <--- output_string6

        write 😕 output_string6.

      endloop.

    else.

      translate output_string1 using '% '. <--- output_string3


      write 😕 output_string3.

    endif.



Regard,

Rich Heilman

0 Kudos

Sorry for writing your mail ID...

its working now...

can u replace macro statements with the if conditons u told earlier..because macro takes much run time performance...

earlier u told to keep the loop for the fields,rather than writing all the fields(initialization to %)..can u do in the code itself and send it again..

Thanks in advance...

Message was edited by: vj bb