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

help in this code

Former Member
0 Likes
1,628

Hi,

This is a sample Program which i m using to add using collect.

<code>

REPORT Z_F2004A2PS738_4 line-count 20(5)

no standard page heading.

tables : z739.

data : begin of it_z739 occurs 0,

name like z739-name,

date like z739-dat,

amount like z739-amount,

end of it_z739.

data sum type i value 0.

selection-screen begin of block b1 with frame title text-001.

select-options : s_date for z739-dat.

selection-screen end of block b1.

select name dat amount from z739 into table it_z739 where dat in s_date.

perform summation.

form summation.

loop at it_z739.

on change of it_z739-name.

collect it_z739.

write: it_z739-name,'=',it_z739-amount.uline.

endon.

endloop.

endform.

</code>

I hav data in db table like.

NAME AMOUNT

HARI 100

HARI 200

HARI 399

PURA 400

PURA 500

Regards,

Suraj

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,602

hi,

instead of summing in loop u fetch sum in selecct statement like:

select name sum( amount ) from z739 into table it_z739 where dat in s_date group by name.

and read this entries using read table stmt.

Jogdand M B

17 REPLIES 17
Read only

Former Member
0 Likes
1,602

form summation.

loop at it_z739.

collect it_z739.

write: it_z739-name,'=',it_z739-amount.uline.

endloop.

endform.

Read only

0 Likes
1,602

Hi ravi,

When ur using that statement .. its only taking the whole data from database table and displaying its not collecting.

Regards,

suraj

Read only

0 Likes
1,602
hi suraj,

 try this..

form summation.

loop at it_z739.
at end of name.
SUM.
write: / it_z739-name,
it_z739-date,
it_z739-amount.
endat.
endloop.
Read only

Former Member
0 Likes
1,602

Hi,

Try this,

loop at it_z739.

on change of it_z739-name.

write: it_z739-name,'=',it_z739-amount.uline.

endon.

collect it_z739.

endloop.

Reward if useful!

Read only

Former Member
0 Likes
1,602

Hi,

Pasete & Check this code for Form Summation :

form summation.

sort it_z739 by name.

data : total type netpr.

clear : total.

loop at it_z739 into it_z739.

total = total + it_z739-amount.

at end of name.

write: it_z739-name,'=',total.uline.

clear total.

endat.

endloop.

endform.

Reward Points, if helpful,

Sandeep Kaushik

Message was edited by:

Sandeep Kaushik

Read only

Former Member
0 Likes
1,602

Frnds

When i m using that code its not working out.

<code>

REPORT Z_F2004A2PS738_4 line-count 20(5)

no standard page heading.

tables : z739.

data : begin of it_z739 occurs 0,

name like z739-name,

date like z739-dat,

amount like z739-amount,

end of it_z739.

data sum type i value 0.

selection-screen begin of block b1 with frame title text-001.

select-options : s_date for z739-dat.

selection-screen end of block b1.

select name dat amount from z739 into table it_z739 where dat in s_date.

perform summation.

form summation.

loop at it_z739.

at end of name.

collect it_z739.

write: / it_z739-name,

it_z739-date,

it_z739-amount.

skip.

endat.

endloop.

endform.

</code>

When i m executing i m getting ******* as output.

Can anyone help me regarding this.

Regards,

suraj

Read only

0 Likes
1,602

At the start of a new control level (i.e. immediately after AT), the following occurs in the output area of the current LOOP statement:

All character type fields (on the right) are filled with "*" after the current control level key.

All other fields (on the right) are set to their initial values after the current control level key.

Read only

0 Likes
1,602

Hi,

copy and paste my code from my earlier reply, it will work.

Reward Points, if helpful,

Sandeep kaushik

Read only

0 Likes
1,602

Change the code of form summation as below .


FORM summation.

  DATA : it_copy TYPE TABLE OF z739 WITH HEADER LINE .

  LOOP AT it_z739.
    it_copy = it_z739 .
    COLLECT it_copy .
  ENDLOOP.

  LOOP AT it_copy .
    WRITE: / it_copy-name,
             it_copy-date,
             it_copy-amount.
    SKIP.
  ENDLOOP.

ENDFORM.

Read only

0 Likes
1,602

HI,

TRY LIKE THIS,

SORT it_z739 BY NAME.

DATA: FLAG TYPE C.

LOOP AT it_z739.

AT FIRST.

WRITE:/10 'EMPNAME'.

/25 'DATE'.

/40 'AMOUNT'.

WRITE:/10 it_z739-name,

25 it_z739-date,

40 it_z739-amount.

AT NEW NAME.

FLAG = 'X'.

IF FLAG = 'X'.

WRITE:/10 it_z739-name,

25 it_z739-date,

40 it_z739-amount.

/* AT END OF NAME.

COLLECT it_z739. */

ENDLOOP.

IF HELPFUL REWARD SOME POINTS.

WITH REGARDS,

SURESH.A

Read only

Former Member
0 Likes
1,603

hi,

instead of summing in loop u fetch sum in selecct statement like:

select name sum( amount ) from z739 into table it_z739 where dat in s_date group by name.

and read this entries using read table stmt.

Jogdand M B

Read only

Former Member
0 Likes
1,602

Frnds,

Tank u for ur reply but i hav to use only collect to get the output.

Read only

sukhbold_altanbat
Active Participant
0 Likes
1,602

Hi Suraj,

if you remove field (date like z739-dat) from internal table , then your code will work fine because date is not number type. so collect works when name and date are same.

if you really want to include date field. try this:

loop at it_z739.

on change of it_z739-name.

write:/ 'checking'.

endon.

collect it_z739.

write: it_z739-name,'=',it_z739-amount.uline.

endloop.

Regards,

Sukhee

Read only

Former Member
0 Likes
1,602

Hello Frnds,

Still i m facing problem i m not getting.

what i feel is , we cant use COLLECT to add up the numeric fields.

Plz help me.

Regards,

suraj

Read only

0 Likes
1,602

Hi,

use

loop at it_z739.
at end of it_z739-name.
sum.
write: it_z739-name,'=',it_z739-amount.uline.
endat.
endloop.

Regards,

Sesh

Read only

0 Likes
1,602

HI,

COLLECT STATEMENT WORKS AT THE TIME OF FILLING UP OF THE INTERNAL TABLE WHEN U DO NOT USE APPEND STATEMENT. SUM STATEMENT WILL ONLY WORK FOR YOU. ALSO MOVE THE DATE TYPE FIELD ABOVE THE NAME FIELD IN DECLARATION SO THAT ****** DO NOT COME. SEE THE EG BELOW.

data : begin of itAB occurs 0,

date like SY-DATUM,

name(15),

amount TYPE P,

end of itAB.

data sum type i value 0.

ITAB-NAME = 'AAA'.

ITAB-DATE = SY-DATUM.

ITAB-AMOUNT = 1010.

aPPEND ITAB.

ITAB-NAME = 'AAA'.

ITAB-DATE = SY-DATUM.

ITAB-AMOUNT = 1020.

aPPEND ITAB.

ITAB-NAME = 'AAA'.

ITAB-DATE = SY-DATUM.

ITAB-AMOUNT = 1030.

aPPEND ITAB.

ITAB-NAME = 'AAA'.

ITAB-DATE = SY-DATUM.

ITAB-AMOUNT = 1040.

aPPEND ITAB.

ITAB-NAME = 'BBB'.

ITAB-DATE = SY-DATUM.

ITAB-AMOUNT = 2010.

aPPEND ITAB.

ITAB-NAME = 'BBB'.

ITAB-DATE = SY-DATUM.

ITAB-AMOUNT = 2020.

aPPEND ITAB.

ITAB-NAME = 'BBB'.

ITAB-DATE = SY-DATUM.

ITAB-AMOUNT = 2030.

aPPEND ITAB.

sort itAB by NAME. "it now looks like figure 13.9

loop at itAB.

at new NAME.

sum.

write: / 'total:', itAB-NAME, itAB-DATE, itAB-AMOUNT.

endat.

endloop.

free itAB.

Read only

Former Member
0 Likes
1,602

Thank u all for such a gr8 contribution