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

need code

Former Member
0 Likes
1,412

hi,

my reqmt is ...

in my itab i am having like this...

pernr rank m1

101 01 25

101 02 10

101 01 15

102 01 10

102 02 12

102 01 15

i need o/p in this format

pernr rank m1

101 01 40

101 02 10

102 01 25

102 02 12....

pls suggest me a code...

thanks in advance ..

With Regards,

S.Barani

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,392

Use the collect statement. Make ITAB2 just like ITAB1 and loop at the iTAB1 and COLLECT into ITAB2.

Loop at itab1. 
  move-corresponding itab1 to itab2.
  collect itab2.
endloop.

Regards,

Rich Heilman

13 REPLIES 13
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,393

Use the collect statement. Make ITAB2 just like ITAB1 and loop at the iTAB1 and COLLECT into ITAB2.

Loop at itab1. 
  move-corresponding itab1 to itab2.
  collect itab2.
endloop.

Regards,

Rich Heilman

Read only

0 Likes
1,392

hi,

i have tried the same code,

but it is not getting added....

kindly suggest me..

With Regards,

S.Barani

Read only

0 Likes
1,392

Hello,

Whether the field mark is a integer field or a character field.

if it is integer then definely collect should work.

Vasanth

Read only

0 Likes
1,392

Can you post the code that you have so far?

Regards,

Rich Heilman

Read only

0 Likes
1,392

hi,

i am having the itab as....

rank1(6) type n,

matnr type mara-matnr,

meins type mseg-meins, " UOM

menge type mseg-menge. " quantity

rank1 matnr meins menge

1000 10024 kg 10

1000 10025 kg 15

1000 10026 TO 12

1001 10027 TO 20

1001 10028 KG 30

1001 10029 TO 20

I NEED O/P AS

rank1 meins menge

1000 kg 25

1000 TO 12

1001 TO 40

1001 KG 30

With Regards,

S.Barani

Read only

0 Likes
1,392

Oh, so you don't want MATNR, then remove it from the second itab and do the logic that I suggest above using the COLLECT. So in the second ITAB, you will only have RANK1, MEINS, and MENGE.

Regards,

Rich Heilman

Read only

0 Likes
1,392

report zrich_0001 .

data: begin of itab1 occurs 0,
      rank1(6) type n,
      matnr type mara-matnr,
      meins type mseg-meins, " UOM
      menge type mseg-menge. " quantity
      end of itab1.


data: begin of itab2 occurs 0,
      rank1(6) type n,
      meins type mseg-meins, " UOM
      menge type mseg-menge. " quantity
      end of itab2.


Loop at itab1.
  move-corresponding itab1 to itab2.
  collect itab2.
endloop.

ITAB2 will now have the required data.

Regards,

Rich Heilman

Read only

0 Likes
1,392

Problem solved.....

Thanks Rich...

THANKS TO ALL......FOR U R VALUABLE CONTRIBUTIONS...

With Regards,

S.Barani

Read only

Former Member
0 Likes
1,392

loop at itab into wa_temp.

wa_final-pernr = wa_temp-pernr.

wa_final-rank = wa_temp-rank1.

wa_final-m1 = wa_temp-m1.

COLLECT wa_final INTO itab_final .

endloop.

Read only

Former Member
0 Likes
1,392

HEllo,

While filling the int table use <b>COLLECT ITAB</b>

Vasanth

Read only

Former Member
0 Likes
1,392

Use Internal table events properly ,

see the example code :

&----


*& Report ZTEST_IEVENTS

*&

&----


*&

*&

&----


REPORT ZTEST_IEVENTS no standard page heading

line-count 40(2).

tables : vbap.

data : begin of i_vbap occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

matnr like vbap-matnr,

kwmeng like vbap-kwmeng,

netpr like vbap-netpr,

end of i_vbap.

data wa_vbap like line of i_vbap.

data v_flag type c.

select-options s_vbeln for vbap-vbeln obligatory.

start-of-selection.

select vbeln

posnr

matnr

kwmeng

netpr from vbap

into table i_vbap

where vbeln in s_vbeln.

sort i_vbap by vbeln posnr.

end-of-selection.

loop at i_vbap.

move i_vbap to wa_vbap.

at first.

write:/2 'Order #',15 'Item #',28 'Material #',50 'Qty', 70 'Net value'.

skip 1.

endat.

at new vbeln.

write:/2 wa_vbap-vbeln,15 wa_vbap-posnr,28 wa_vbap-matnr,

47 wa_vbap-kwmeng,65 wa_vbap-netpr.

v_flag = 'X'.

endat.

if v_flag ne 'X'.

write:/15 wa_vbap-posnr,28 wa_vbap-matnr,

47 wa_vbap-kwmeng,65 wa_vbap-netpr.

endif.

at end of vbeln.

sum.

skip 1.

write:/5 'Sub totals', 47 i_vbap-kwmeng,65 i_vbap-netpr.

skip 1.

endat.

at last .

skip 1.

sum.

write:/5 'Grand Totals',47 i_vbap-kwmeng,65 i_vbap-netpr.

skip 1.

write:/ 'end of page', 'Footer'.

endat.

clear v_flag.

endloop.

Read only

Former Member
0 Likes
1,392

Hi,

Use control break statements.

Syntax

AT NEW <f>.

AT END OF <f>.

AT FIRST.

AT LAST.

AT <fg>.

These statements are used in control level processing with extract datasets or internal tables.

Each introduces a statement block that you must conclude with the ENDAT statement. The

statements between AT and ENDAT are executed whenever the corresponding control level

change occurs.

Ex.

REPORT DEMO.

DATA: T1(4), T2 TYPE I.

FIELD-GROUPS: HEADER.

INSERT T2 T1 INTO HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

T1 ='BBCC'. T2 = 2. EXTRACT HEADER.

T1 ='AAAA'. T2 = 2. EXTRACT HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

T1 ='BBBB'. T2 = 2. EXTRACT HEADER.

T1 ='BBCC'. T2 = 2. EXTRACT HEADER.

T1 ='AAAA'. T2 = 1. EXTRACT HEADER.

T1 ='BBBB'. T2 = 1. EXTRACT HEADER.

T1 ='AAAA'. T2 = 3. EXTRACT HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

SORT BY T1 T2.

LOOP.

AT FIRST.

WRITE 'Start of LOOP'.

ULINE.

ENDAT.

AT NEW T1.

WRITE / ' New T1:'.

ENDAT.

AT NEW T2.

WRITE / ' New T2:'.

ENDAT.

WRITE: /14 T1, T2.

AT END OF T2.

WRITE / 'End of T2'.

ENDAT.

AT END OF T1.

WRITE / 'End of T1'.

ENDAT.

AT LAST.

ULINE.

ENDAT.

ENDLOOP.

Regards,

Bhaskar

Read only

Former Member
0 Likes
1,392

See the code :

data : begin of itab occurs 0,

pernr(3) type c,

rank(2) type c,

m1 type i,

end of itab.

start-of-selection.

itab-pernr = '101'.

itab-rank = '01'.

itab-m1 = 25.

collect itab.

itab-pernr = '101'.

itab-rank = '02'.

itab-m1 = 10.

collect itab.

itab-pernr = '101'.

itab-rank = '01'.

itab-m1 = 15.

collect itab.

itab-pernr = '102'.

itab-rank = '01'.

itab-m1 = 10.

collect itab.

itab-pernr = '102'.

itab-rank = '02'.

itab-m1 = 12.

collect itab.

itab-pernr = '102'.

itab-rank = '01'.

itab-m1 = 15.

collect itab.

loop at itab.

write:/2 itab-pernr,15 itab-rank,25 itab-m1.

endloop.