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

itab concatenate

Former Member
0 Likes
1,170

Hi Frnds,

Can any body tell..

In my ITAB i have some records with single field. I want to concatenate all records into one variable.

if that variable full i want to concatenate into another variable.

Thanks & Regards,

Kumar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,116

your solution

DATA : BEGIN OF it_try OCCURS 0,

id TYPE matnr,

END OF it_try.

DATA : try1 TYPE c length 80.

DATA : try TYPE c length 40.

data : i type i value 1.

data : n type i value 0.

it_try-id = '0000000000000019' .

APPEND it_try.

it_try-id = '0000000000000018' .

APPEND it_try.

n = 36 / 18 .

" 36 because there are to records in itab and 18 is due

" to lenght of a single field is 18 . you know these

if n < 3 .

do n times .

READ TABLE it_try INTO it_try index i.

concatenate it_try-id try into try .

i = i + 1.

enddo.

else.

do n times .

READ TABLE it_try INTO it_try index i.

concatenate it_try-id try1 into try1 .

i = i + 1.

enddo.

endif.

do reward if helpful

Edited by: Ashish Paliwal on Apr 16, 2008 2:46 PM

Hi Frnds,

Can any body tell..

In my ITAB i have some records with single field. I want to concatenate all records into one variable.

if that variable full i want to concatenate into another variable.

Thanks & Regards,

Kumar

8 REPLIES 8
Read only

Former Member
0 Likes
1,116

Hi ,

Check the STRLEN of the field if it is already full then concatenate it to next field.

Gaurav sood

Read only

0 Likes
1,116

Hi Gourav,

How can i concatenate my itab records into variable.

Ex..

itab contains.

1000

1001

1002

1003

1004

1005

.

.

.

.

1100

all these recods i want to concatenate into varialbe like.

1000, 1001, 1002, 1003, 1004,.....1100

how can i do.

Thanks

Kumar.

Read only

0 Likes
1,116

Hope this will satisy..

reward full points ....


DATA: BEGIN OF itab OCCURS 1 ,
 a(2),
 END OF itab.
 
DATA: BEGIN OF itab1 OCCURS 1 ,
b TYPE string,
END OF itab1.
 
DO 20 TIMES.
  itab-a = sy-index.
  APPEND itab.
ENDDO.
 
LOOP AT itab.
  IF sy-tabix = 1.
    itab1-b = itab-a.
  ELSE.
    CONCATENATE itab1-b ',' itab-a INTO  itab1-b.
  ENDIF.
ENDLOOP.
WRITE:/ itab1-b.
APPEND itab1.

regards

sas.

Read only

0 Likes
1,116

hi kumar,

please make sure that your variable is long enough to hold the values of the internal table.

use this code.


data:
 ld_var1(1000) type c,
 ld_var2(1000) type c,
 ld_len1 type i,
 ld_len2 type i,
 ld_diff type i,
 ld_ctr type i,
 ld_sctr(3) type c,
 ld_field type string.

field-symbol:
 <fs_var> type any.

move 1 to ld_ctr.
move ld_ctr to ld_sctr.

shift ld_sctr left deleting leading space.

concatenate 'LD_VAR' ld_sctr into ld_field.

assign (ld_field) to <fs_var>.

loop at itab.
  ld_len1 = strlen( <fs_var> ).
  ld_len2 = strlen( itab-field ).

  ld_diff = ld_len1 + ld_len2.

  if ld_len eq 1000 or ld_diff ge 1000.
   add 1 to ld_ctr.
 
   move ld_ctr to ld_sctr.
   shift ld_sctr left deleting leading space.

   concatenate 'LD_VAR' ld_sctr into ld_field.

   assign (ld_field) to <fs_var>.
 
  endif.

  if ld_var is initial.
    move itab-field1 to ld_var.
  else.
    concatenate ld_var ',' space itab-field1 into ld_var.
  endif.
endloop.

regards,

Peter

Edited by: Peter Ruiz on Apr 16, 2008 5:27 PM

Read only

Former Member
0 Likes
1,117

your solution

DATA : BEGIN OF it_try OCCURS 0,

id TYPE matnr,

END OF it_try.

DATA : try1 TYPE c length 80.

DATA : try TYPE c length 40.

data : i type i value 1.

data : n type i value 0.

it_try-id = '0000000000000019' .

APPEND it_try.

it_try-id = '0000000000000018' .

APPEND it_try.

n = 36 / 18 .

" 36 because there are to records in itab and 18 is due

" to lenght of a single field is 18 . you know these

if n < 3 .

do n times .

READ TABLE it_try INTO it_try index i.

concatenate it_try-id try into try .

i = i + 1.

enddo.

else.

do n times .

READ TABLE it_try INTO it_try index i.

concatenate it_try-id try1 into try1 .

i = i + 1.

enddo.

endif.

do reward if helpful

Edited by: Ashish Paliwal on Apr 16, 2008 2:46 PM

Read only

Former Member
0 Likes
1,116

Loop at itab into wa.

conacteante wa to wrk_string seperated by space.

endloop.

where wrk_string is a variable of type string.

Read only

Former Member
0 Likes
1,116

hi check this ...

report .

data: begin of itab occurs 0,

test1(30) type c value 'test',

test2 type i ,

test3 type i ,

test4 type i ,

test5 type i ,

test6 type i ,

end of itab.

data:v_test1(5) type c,

v_test2(5) type c,

v_test3(5) type c,

v_test4(5) type c,

v_test5(5) type c ,

v_test6(5) type c,

test type string .

itab-test2 = 1002.

itab-test3 = 3002.

itab-test4 = 4003.

itab-test5 = 8005.

itab-test6 = 1092.

append itab.

itab-test2 = 1333.

itab-test3 = 2312.

itab-test4 = 1234.

itab-test5 = 6547.

itab-test6 = 8976.

append itab.

loop at itab.

move itab-test1 to v_test1.

move itab-test2 to v_test2.

move itab-test3 to v_test3.

move itab-test4 to v_test4.

move itab-test5 to v_test5.

move itab-test6 to v_test6.

concatenate v_test2 v_test3 v_test4 v_test5 v_test6 into test .

itab-test1 = test.

write:/ itab-test1.

endloop.

regards,

venkat

Read only

prasanth_kasturi
Active Contributor
0 Likes
1,116

try this code

data : begin of itab occurs 0,

b type c,

end of itab.

data : a type string.

itab-b = '1'.

append itab.

itab-b = '2'.

append itab.

itab-b = '3'.

append itab.

loop at itab.

write / itab-b.

endloop.

data ch type c.

loop at itab.

ch = itab-b.

CONCATENATE a ch

INTO a.

endloop.

write / a.

regards

prasanth