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

integer doubt??

Former Member
0 Likes
3,477

Hi all,

I am using as follows

data : num1(60) type c value 'what'.

data: num2(10) type c value 'who'.

in the o/p i will be getting num2 after 61 column..correct...how to get num2 after num1 just seperated by tab..how to remove empty columns..i want o/p as:::

what who (seperated by tab space)

50 REPLIES 50
Read only

abdul_hakim
Active Contributor
0 Likes
289

hi use the below code..

data : num1(60) type c value 'what'.

num2(10) type c value 'who',

res(70) type c.

concatenate num1 num2 into res separated by space.

Cheers,

Abdul Hakim

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
289

If you are outputting this to a file, you can do something like this. On the output list here, the # represents the TAB. But in a .txt file it would be a tab.



report zrich_0006.

data : num1(60) type c value 'what'.
data: num2(10) type c value 'who'.

data: output_string type string.

concatenate num1 num2 into output_string
    separated by cl_abap_char_utilities=>horizontal_tab.

write:/ output_string.

If you just want to put a space in between in your list display, then you can the same, but separated by space.


report zrich_0006.

data : num1(60) type c value 'what'.
data: num2(10) type c value 'who'.

data: output_string type string.

concatenate num1 num2 into output_string
    separated by space.

write:/ output_string.

REgards,

Rich Heilman

Read only

0 Likes
289

Hi

thanks ..

can i use data: output_string type c.?

Read only

0 Likes
289

hi you can use but specify the length

for eg,

data output_string(80) type c.

Cheers,

Abdul Hakim

Read only

0 Likes
289

data: output_string type c will only have a default legth of 1 char unless you explcitly specify the legth.

With a data type STRING you need not specify the length, it is dynamically assigned at runtime by the system.

Regards,

Suresh datti

Read only

0 Likes
289

hi all,

can i write

......seperated by tab.

Thanks

Read only

0 Likes
289

hi no u cannot if you want to use tab then refer the code given by Rich..

Cheers,

Abdul Hakim

Read only

0 Likes
289

hi,,

it is giving error for

separated by cl_abap_char_utilities=>horizontal_tab

Thanks

Read only

0 Likes
289

If you are writing this to a list display, tab does you no good. If you are writing this out to a .txt file, then tab would definitly work. You must use the class=>attribute that I have provided above. If you are on earlier version of SAP, this class will not exists, so you must use the hex value instead.

report zrich_0006.

data : num1(60) type c value 'what'.
data: num2(10) type c value 'who'.

data: output_string type string.
<b>CONSTANTS: c_tab TYPE x VALUE '09'.
</b>

concatenate num1 num2 into output_string
    separated by <b>c_tab</b>.

write:/ output_string.

Regards,

Rich Heilman

Read only

0 Likes
289

you are in which version of SAP?

Cheers,

Abdul Hakim

Read only

0 Likes
289

hi,

i am in 4.6C ...

Read only

0 Likes
289

hi i m in 4.7 so i think it doesnt exits in 4.6c so ref the code given by Rich...

Cheers,

Abdul Hakim

Read only

0 Likes
289

That's right Abdul, I'm on 46c as well and it does not exists.

Regards,

Rich Heilman

Read only

0 Likes
289

Hi,

see i am having 10 fields to be displayed in seperate format o/p as::

12 10

12 23 45 45

12

56 78 34

and some fileds are having length of 50 60...

I want the o/p to be displayed just like above but for adjacent fields seperated by tab???????

each field in each row seperated by tab space/////

Read only

0 Likes
289

Ok, do these values reside in an internal table? If not, this would be the best approach.

REgards,

Rich Heilman

Read only

0 Likes
289

first row consists of constant values

second row is also constant

<b>third row is field values...it may goto 10 rows</b>

and 4th and 5th rows are constants..similar to 1st and 2nd......

Read only

0 Likes
289

Ok, check out this sample. Here all of the data resides in an internal table. We are writing out all of the fields that actually have some data in it and separating with a tab.



report zrich_0006.


data: begin of itab occurs 0,
      fld1(10) type c,
      fld2(20) type c,
      fld3(30) type c,
      fld4(40) type c,
      fld5(50) type c,
      end of itab.

data: output_string type string.
field-symbols: <fs>.
constants: c_tab type x value '09'.


itab-fld1 = '01'.
itab-fld2 = '02'.
itab-fld3 = '03'.
append itab.

itab-fld1 = '21'.
itab-fld2 = '22'.
itab-fld3 = '23'.
itab-fld4 = '24'.
append itab.

itab-fld1 = '31'.
itab-fld2 = '32'.
itab-fld3 = '33'.
itab-fld4 = '34'.
itab-fld5 = '35'.
append itab.


loop at itab.

  clear output_string.
  do.
    assign component sy-index of structure itab to <fs>.
    if sy-subrc <> 0 .
      exit.
    endif.

    check not <fs> is initial.

    if sy-index  =  1.
      output_string = <fs>.
    else.
      concatenate output_string <fs>
               into output_string separated by c_tab.
    endif.

  enddo.

  write:/ output_string.


endloop.

Regards,

Rich Heilman

Read only

0 Likes
289

my exact o/p should be.

10 20(constant)

30 40 (constant)

50 AP EC 30...

TD MN..

.......(variables..)

60 80(constant)

90 100(constant)

Read only

0 Likes
289

hi

are your data reside in an internal table?

if so use the code sample given by Rich.

Cheers,

Abdul Hakim

Read only

0 Likes
289

thats what i want to ask...

first 2 rows are constants..can i keep them in internal table...

3rd row i have to keep in internal table because the values may vary ...it may go upto 10 rows..or more

and last 2 rows are constants...

please help me....

Read only

0 Likes
289

I would suggest setting up all of the data in question in a separate internal table, then use the code to write out with tabs. So first build you internal table with the constant values, and then the variabe data and finish off with the other contants, the proceed. Make sense?

Regards,

Rich Heilman

Read only

0 Likes
289

hi

you can keep.

jus define an internal table with the maximum number of columns you are expecting to store the values and then play with it..

Cheers,

Abdul Hakim

Read only

0 Likes
289

Hi,

but some fields are integer type...it is displaying error if i am using concatenate statment...

Read only

0 Likes
289

Right. You must use character based fields, so make sure that you ITAB contains only TYPE C fields, you may move TYPE I fields to TYPE C fields when building your ITAB.

Regards,

Rich Heilman

Read only

0 Likes
289

thanks...

but values i will be getting from the standard table fields...how to convert integer values to C.

and moreover in my o/p every field is seperated by #????

why so?????

Thanks in advance

Read only

0 Likes
289

Please help me out......

why fields are separeted by # i want to be separetd by tab space and if any field is having null value it should separetd by tab space...i.e, if num2 has null value then num1 and num3 should be separetd by 3 tab spaces...correct????

Read only

0 Likes
289

When you are retreiving the values from the table, you can put them into internal table which is TYPEd like the standard table. Then loop at that table when building the ITAB which will have all fields as character moving the TYPE I fields to the TYPE C fields.

Loop at istab.
clear itab.
itab-fld1 = istab-ifield. " Move from TYPE I to TYPE C
append itab.
Endloop.

Regards,

Rich Heilman

Read only

0 Likes
289

Ok, the # represents the TAB. I was assuming that the fields in the string will all be filled except the last ones in the string. If not, we have some more work to do.

You will want to remove the line of code that says.

CHECK not <fs> is initial.

When you do this, it will allow to put a tab when a field is blank. But now you will have TABs at the end of the string. This may be ok for you. If not you will need to remove them. There are a couple ways of doing so. If you are writing this output string to a .txt file there is really no need to remove them.

Regards,

Rich Heilman

Read only

0 Likes
289

i didnt got the code u wrote

Loop at istab.

clear itab.

itab-fld1 = istab-ifield. " Move from TYPE I to TYPE C

append itab.

Endloop.

??????????

I AM MOVING THE O/P AUTOMATICALLY(BACKGROUND) TO APPLICATION SERVER (AL11 TCODE)...

so what all changes do i need to do....just brief it

Thanks in advance....

Read only

0 Likes
289

This code....



select * into table istab
          from some_table
                 where.....

Loop at istab.
clear itab.
itab-fld1 = istab-ifield. " Move from TYPE I to TYPE C
append itab.
Endloop.

Is just showing you how you can take the data from the database, and move it to your output internal table, you can move the TYPE I field from your your internal tabe which the data came from DB to your output internal table. Then all of the fields will by TYPE C and you can use the concatenate statement.

Since you are writing this to app server, you may not need to remove the trailing tabs.

If you do, this may work.

shift output_string right deleting trailing c_tab.
shift output_string left deleting leading space.

You can write to the app server using OPEN DATASET, READ DATASET, and CLOSE DATASET.

Regards,

Rich Heilman

Read only

0 Likes
289

Is your issue resolved? If so, please make sure to award points for any helpful answers and mark your post as solved. Thanks.

Regards,

Rich Heilman

Read only

0 Likes
289

Hi rich,

i have used concatenate statements for all the rows...

but for the row 3 the lines may vary..it may go to n lines...

just think that o/p file first 2 rows and last 2 rows are constant and middle rows will contain data based on he PO number...

can i use the same concatenate statment for 3 row??

so i have to keep in loop or other...

concatenate r_id

sp_n

c_date

c_time

f_format

f_version

into output_string1

separated by tab.

concatenate r_id1

o_id

o_name

into output_string2

separated by tab.

***********************3rd row

concatenate r_id2

o_id1

num12

num23

into output_string3

separated by tab.

***********************

concatenate r_id3

o_id2

o_name1

d_r_count

into output_string4

separated by tab.

concatenate r_id4

e_r_count

file_record_count

write 😕 output_string1.

write 😕 output_string2.

write 😕 output_string3.

write 😕 output_string4.

write 😕 output_string5.

it is interface program..so it runs in background..and file will be created in AL11.when i execute report the o/p gives as seperated by #..will it be tab space in AL11?

Read only

0 Likes
289

hi

you can use concatenate no issues.

  1. indicates tab.

Cheers,

Abdul Hakim

Mark all useful answers..

Read only

0 Likes
289

Yes, it will be TAB delimited in the file itself.

Regards,

Rich Heilman

Read only

0 Likes
289

So you are saying that row three will contain a bunch off po numbers like this.

123456 123457 123458 123459 123460 123461

If so, I assume that these are contained in an internal table? If so, then yes, you can just loop at that table and concatenate them together the same.

Regards,

Rich Heilman

Read only

0 Likes
289

hi,

but in the code the 3rd will be displayed only once..

i want the data to be displayed based on some conditions..

e.g: lfa1-name1 = 'tom'

so to display all the PO based on tom..it will 10(suppose)..

but i am getting only one record...

how to keep loop based on what conditions...

Thanks in advance

Read only

0 Likes
289

Hi,

the o/p will be for 3 rd row..

1000004567 45 v1 b1...

1000000569 98 j1 b1..

1000000023 67 m1 n1....

any how first 2 and last 2 rows are constants...so we can put direct concatenate statment..but how to concatenate 3 rd row and how to keep loop?do i need to take internal table..

please explain by giving code or insert in above code..

Thanks in advance

Read only

0 Likes
289

Let us say you write out the first two rows. You have the POs related to TOM in an internal table. You loop at this internal table and write all of them out. After the loop, you write the last two rows. So essetially your logic will be as follows.

row1

row2

loop at itab.

write itab information.

endloop.

row-last-but-one.

row-last.

Read only

0 Likes
289

Easiest is to give us your current code here.