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

concatenate in loop

Former Member
0 Likes
6,746

Hi all how to this i want content in diff line items to be displayed in single line in o/p

ACTUAL ALV GRID DISPLAY

MATNR SLoc Batch QTY CONTENT

20000130 2100 11 58 nag

20000130 2100 11 290 jan

20000130 2100 11 290 aug

20000164 2100 11 500 mar

20000164 2100 11 500.000 apr

WANT IN THIS FORMAT

MATNR SLoc Batch QTY CONTENT

20000130 2100 11 638.000 nag,jan,aug

20000164 2100 11 500.000 mar,apr

Thanks

lalith

Hi all how to this i want content in diff line items to be displayed in single line in o/p

ACTUAL ALV GRID DISPLAY

MATNR SLoc Batch QTY CONTENT

20000130 2100 11 58 nag

20000130 2100 11 290 jan

20000130 2100 11 290 aug

20000164 2100 11 500 mar

20000164 2100 11 500.000 apr

WANT IN THIS FORMAT

MATNR SLoc Batch QTY CONTENT

20000130 2100 11 638.000 nag,jan,aug

20000164 2100 11 500.000 mar,apr

Thanks

lalith

6 REPLIES 6
Read only

Former Member
0 Likes
2,728

Dear,

First you use COLLECT statement to add all the numeric values to one line then you can concatinate easily.

Regards,

Bohra.

Read only

Former Member
0 Likes
2,728

Make one internal table with the same structure like

it_final :

MATNR SLoc Batch QTY CONTENT

20000130 2100 11 638.000 nag,jan,aug

20000164 2100 11 500.000 mar,apr

and make the loop to this internal table

data : var(10).

data : var2(25).

data: val type i.

itab:

MATNR SLoc Batch QTY CONTENT

20000130 2100 11 58 nag

20000130 2100 11 290 jan

20000130 2100 11 290 aug

20000164 2100 11 500 mar

20000164 2100 11 500.000 apr

int the loop.

loop at itab.

it_final-matnr = itab-matnr.

val = val + itab-field2.

concatenate itab-filed3 var2 into var2.

at end of matnr.

it_final-matnr = itab-matnr.

it_final-sloc = itab-sloc.

it_final-qty = val.

it_final-final_fld = var2.

append it_final.

clear :it_final,var2,var,val.

endloop.

This is sinple please try it.

Regards,

madan.

Read only

Former Member
0 Likes
2,728

hi lalith

u can use the command AT END

and Apply it ion matnr and write ur code under this comand to have desired output

Cheers

Snehi Chouhan

Edited by: snehi chouhan on May 12, 2008 9:36 AM

Read only

Former Member
0 Likes
2,728

Hi,

First read internal table using loop at.

see below code.

check this link.

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/collect.htm

DATA: BEGIN OF LINE,

COL1(3) TYPE C,

COL2(2) TYPE N,

COL3 TYPE I,

END OF LINE.

DATA ITAB LIKE SORTED TABLE OF LINE

WITH NON-UNIQUE KEY COL1 COL2.

LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 3.

COLLECT LINE INTO ITAB.

WRITE / SY-TABIX.

LINE-COL1 = 'def'. LINE-COL2 = '34'. LINE-COL3 = 5.

COLLECT LINE INTO ITAB.

WRITE / SY-TABIX.

LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 7.

COLLECT LINE INTO ITAB.

WRITE / SY-TABIX.

LOOP AT ITAB INTO LINE.

WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.

ENDLOOP.

The output is:

1

2

1

abc 12 10

def 34 5

in your requirement

use collect statement in loop .

line is work area and itab is body of internal table.

table:begin of itab.

your fields,

end of itab.

select*----


loop at itab.

collect itab.

endloop.

.

*reward if usefull

Edited by: jeevitha on May 12, 2008 1:09 PM

Read only

peter_ruiz2
Active Contributor
0 Likes
2,728

hi lalith,

use this code,


data: v_line type char90.

loop at itab into wa_itab.
at new matnr.
  move v_line to wa_itab2.

  append wa_itab2 to itab2.
  
  clear wa_itab2.
  clear v_line.
  concatenate wa_itab-matnr wa_itab-sloc wa_itab-batch wa_itab-qty
  into v_line.
endat.

concatenate v_line wa_itab-content ',' into v_line
endloop.

regards,

Peter

Edited by: Peter Ruiz on May 12, 2008 3:43 PM

Read only

Former Member
0 Likes
2,728

Hi,

See the code below......

types : begin of t_itab,

MATNR type matnr,

SLoc type LGORT_D,

Batch type CHARG_D,

QTY type DZMENG,

CONTENT(50) type c,

end of t_itab.

data : itab type STANDARD TABLE OF t_itab,

fitab type STANDARD TABLE OF t_itab.

data : wa1 like LINE OF itab,

waf like LINE OF itab.

data : lmatnr type matnr,

tot_qty type DZMENG,

l_batch type CHARG_D,

cont_str(50) type c.

data : flag type i VALUE 0.

sort itab by matnr.

loop at itab into wa1.

if lmatnr <> wa1-matnr.

if flag = 1.

waf-matnr = lmatnr.

waf-matnr = tot_qty.

waf-content = cont_str.

waf-batch = l_batch.

append waf to fitab.

endif.

lmatnr = wa1-matnr.

cont_str = wa1-content.

tot_qty = wa1-qty.

l_batch = wa1-batch.

flag = 1.

else.

tot_qty = tot_qty + wa1-qty.

CONCATENATE cont_str ', ' wa1-content into cont_str.

endif.

endloop.

N.B. ==>

1. adjust the field 'CONTENT' accordingly.

2. 'fitab' contains the final output.

Reward points if helpful..........