cancel
Showing results for 
Search instead for 
Did you mean: 

scripts:totaling of all items

Former Member
0 Kudos

hi

i am facing a small problem

actually i used the below code for summing of all items coming into g_dmshb and g_mhngf.

but am not able to get get overall total am able to get only for last two items

can u suggest me whether the above code is correct or not

thank u

LOOP AT INTAB WHERE NAME = 'F150D-MHNGF' .

IF SY-SUBRC = 0.

MOVE INTAB-VALUE TO G_MHNGF1.

G_MHNGF1 = INTAB-VALUE .

ENDIF.

ENDLOOP.

G_TOT2 = G_DMSHB + G_MHNGF1.

DATA G_TOT3(15).

CLEAR OUTTAB.

READ TABLE OUTTAB WITH KEY NAME = 'G_TOT2'.

IF SY-SUBRC = 0.

WRITE G_TOT2 TO G_TOT3 CURRENCY 'GBP'.

OUTTAB-VALUE = G_TOT3.

CONDENSE OUTTAB-VALUE NO-GAPS.

MODIFY OUTTAB INDEX 1 TRANSPORTING VALUE.

ENDIF.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Shouldn't you statement G_TOT2 = G_DMSHB + G_MHNGF1. be inside the loop so that you get all the values to sun up.

Regards

Ravi

Note : Please mark all the helpful answers

Former Member
0 Kudos

hi ravi

i used the below code and as u sugested i kept g_tot2 = g_dmshb +g_mhngf in the loop.still am not able to get the required sum result.

LOOP AT INTAB WHERE NAME = 'MHND-DMSHB' .

if sy-subrc = 0.

replace ',' in intab-value with '' .

condense intab-value no-gaps.

move intab-value to g_dmshb.

endif.

*g_tot1 = g_dmshb + intab-value.

  • g_tot2 = g_tot1 + intab-value.

reAD TABLE INTAB WITH KEY NAME = 'F150D-MHNGF'.

IF SY-SUBRC = 0.

MOVE INTAB-VALUE TO G_MHNGF1.

*G_MHNGF1 = INTAB-VALUE .

ENDIF.

g_tot2 = g_dmshb + g_mhngf1.

endloop.

Thanks

Former Member
0 Kudos

itz urgent

Former Member
0 Kudos

Hi,

I am not clear with the table structures you are using can you give the table details and also which columns should be considered for summing.

Regards,

Ravi

Former Member
0 Kudos

Hi Chinna,

Could you post your code?

Regards,

Vicky

Former Member
0 Kudos

Tables : F150D,MHND

DMSHB from MHND table and MHNGF1 from F150D table To be

summing.

Thanks

Former Member
0 Kudos

I was talking about the structure of the internal tables.

Regards,

Ravi

Former Member
0 Kudos

hi

FORM SUB_FORM4 TABLES INTAB STRUCTURE ITCSY OUTTAB STRUCTURE ITCSY.

DATA: G_DMSHB LIKE MHND-DMSHB,

G_MHNGF1 LIKE F150D-MHNGF.

DATA: G_TOT2 LIKE F150D-SALFW,

Thanks

Former Member
0 Kudos

Hi,

Try this.



LOOP AT INTAB WHERE NAME = 'MHND-DMSHB' .
clear : g_dmshb, g_mhgf1.
if sy-subrc = 0.
replace ',' in intab-value with '' .
condense intab-value no-gaps.
move intab-value to g_dmshb.
endif.
reAD TABLE INTAB WITH KEY NAME = 'F150D-MHNGF'.
IF SY-SUBRC = 0.
MOVE INTAB-VALUE TO G_MHNGF1.
ENDIF.
g_tot2 = g_dmshb + g_mhngf1.
endloop.

Notice the clear statements inside the loop.

Regards,

Ravi

Note :Please mark all the helpful answers

Former Member
0 Kudos

eventhough sum is taking for only last two values.

Thanks

Former Member
0 Kudos

Hi,

Can you give me sample data of the table along with the NAME , VALUE COLUMNS. I am still confused with the structures. The READ in the loop might be creating problems. Give 3 rows and also let me know what is the expected total.

Regards,

Ravi

Former Member
0 Kudos

can u send me ur personal id

so that i can send mail the screen shot

Thanks

Former Member
0 Kudos

Hi,

Its there in the business card. Please do send a mail.

regards,

Ravi

Former Member
0 Kudos

Hi,

There is an error in your logic see my comments at the side of your code.

LOOP AT INTAB WHERE NAME = 'MHND-DMSHB' .

if sy-subrc = 0.

replace ',' in intab-value with '' .

condense intab-value no-gaps.

  • Here the value of intab-value is moved to g_dmshb

move intab-value to g_dmshb.

endif.

*g_tot1 = g_dmshb + intab-value.

  • g_tot2 = g_tot1 + intab-value.

reAD TABLE INTAB WITH KEY NAME = 'F150D-MHNGF'.

IF SY-SUBRC = 0.

MOVE INTAB-VALUE TO G_MHNGF1.

*G_MHNGF1 = INTAB-VALUE .

ENDIF.

  • Now here you add it to g_tot2

g_tot2 = g_dmshb + g_mhngf1.

endloop.

In accumulating a value the logic shoud be like

Loop

a = a + b.

endloop.

So your code should look something like this

LOOP AT INTAB WHERE NAME = 'MHND-DMSHB' .

if sy-subrc = 0.

replace ',' in intab-value with '' .

condense intab-value no-gaps.

move intab-value to g_dmshb.

  • Here you add g_dmshb to g_tot2

add g_dmshb to g_tot2.

endif.

reAD TABLE INTAB WITH KEY NAME = 'F150D-MHNGF'.

IF SY-SUBRC = 0.

MOVE INTAB-VALUE TO G_MHNGF1.

ENDIF.

  • Here you add g_mhngf1 to g_tot2 so you have the sum of

  • both for entries with name = MHND-DMSHB and F150D-MHNGF

g_tot2 = g_tot2 + g_mhngf1. "<- should be like this

endloop.

If you want an optimized code try this one below.

LOOP AT INTAB WHERE NAME = 'MHND-DMSHB' .

IF sy-subrc = 0.

REPLACE ',' IN intab-value WITH '' .

CONDENSE intab-value no-gaps.

MOVE intab-value TO g_dmshb.

ENDIF.

READ TABLE INTAB WITH KEY NAME = 'F150D-MHNGF'.

IF SY-SUBRC = 0.

MOVE intab-value TO g_mhngf1.

ENDIF.

  • Here you add g_mhngf1 to g_tot2 so you have the sum of

  • both for entries with name = MHND-DMSHB and F150D-MHNGF

  • code should be like this:

g_tot2 = g_tot2 + g_dmshb + g_mhngf1.

ENDLOOP.

Former Member
0 Kudos

HI

there is 7 line items which are taking from the MHND-DMSHB

and the last value in the line item are taking from the F150D-MHNGF.

it's taking sum from first line item MHND and from the Last line item F150D. passing sum to the G_tot2

and refreshing the valueG_TOT2,

next time it's talking value from second line item and from last, and refreshing the G_tot2.

so the entire process is like sum of 1st + last line item, next refreshing.

then 2nd + last line item taking sum and refreshing.

at last it's taking sum from the 7th line item + last line item, it's printing sum, but not summ all the 7 + last line item.

may be i need to pass these sum to one static variable.

how to do this.

Thanks

Former Member
0 Kudos

Hi,

Can you replace this g_tot2 = g_dmshb + g_mhngf1 with

<b>g_tot2 = g_dmshb + g_mhngf1 + g_tot2 </b>.

Regards,

Ravi

Former Member
0 Kudos

Hi Ravi

I replace code to g_tot2 = g_dmshb + g_mhngf1 + g_tot2

even thought total is not coming.

Thanks

Former Member
0 Kudos

Mail me the entire code and a screen shot of the data in the INTTAB table (DEBUG mode) and the total you are expecting ..

Former Member
0 Kudos

Hi,

I am not sure how you have declared this variable inside the SMART Form, declare that in reference to a database amount field. Once you do that, it will take care of the formatting, by itself.

Regards,

Ravi

Note :Please mark the helpful answers and close the post if resolved.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

I was able to see the screen shot, but that could not give the details I was looking for. I want to see the data in INTTAB table along with the columns.

Can you send me the data for INTTAB table which contains both the fields which you are summing.

Regards,

Ravi

Former Member
0 Kudos

u are using where condition may be only those two records satisfies the condition.