Application Development 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: 

how can i add total in Module Pool Programming

Former Member
0 Kudos
1,097

Hai abapers,

My problem is I have 15 fields in a tablecontrol.The 15th field is total field...

When ever user enter a values in remaing fields,the 15 the field must be updated...

how can i achieve in module pool programming..................

i have one more problem.That is when user pressing any key.my content in table control r clearing..i need to restrict clearing values..how can i achieve it ...

Waiting for y r favourable replies

Regards

Maruthi

5 REPLIES 5

Former Member
0 Kudos
233

Hi,

There are two ways you can do the summation thing..

1. Make any field of other 14 fields as <b>'responds to double click'</b> and fill fcode , say 'select' for F2 function key in GUI Status .

then program for it like:

case 'ok_code'.

when 'select'.

15 field = sum of all 14 fields .

endcase.

2. If you would like to do the sum for all the rows in one go ,then:

create a <b>pushbutton</b> with ok_code sum.

and after filling all 14 fields , you can get the sum programmed for this push button in a case statement.

Regarding clearing of the table control,

<b>perhaps you have not included a loop for populating your table control in your PBO .</b>

Pls reward if useful ..Feel free to ask anything else.

Warm Regards,

Shweta Soni

Former Member
0 Kudos
233

Check the following ex code.

You need to write logic in PAI event for this.

PROCESS AFTER INPUT.

*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'TC1'

*BREAK POINT.

LOOP AT G_TC1_ITAB.

CHAIN.

FIELD ZFG_SRNO-ZSRNO.

MODULE TC1_MODIFY ON CHAIN-REQUEST.

  • MODULE TC1_MODIFY.

ENDCHAIN.

MODULE MESSAGE .

MODULE DELETE_RECORD.

ENDLOOP.

MODULE TC1_MODIFY INPUT.

*break-point.

  • MOVE-CORRESPONDING ZFG_SRNO TO G_TC1_ITAB.

  • MODIFY G_TC1_ITAB INDEX TC1-CURRENT_LINE.

  • G_TC1_COPIED = 'X'.

  • REFRESH CONTROL 'TC1' FROM SCREEN '8001'.

MOVE-CORRESPONDING ZFG_SRNO TO G_TC1_WA.

MODIFY G_TC1_ITAB

FROM G_TC1_WA

INDEX TC1-CURRENT_LINE.

G_TC1_COPIED = 'X'.

if sy-subrc ne 0.

append G_TC1_WA to G_TC1_ITAB.

endif.

ENDMODULE.

Former Member
0 Kudos
233

Hi Maruthi,

The problem you are facing is having a common solution which you can use..



PBO

MODULE CALCULATE_TOTAL.

LOOP AT INTERNAL_TABLE INTO WORK_AREA WITH CONTROL TABLE_CONTROL.

MODULE POPULATE_TABLE_CONTROL.

ENDLOOP.


PAI

LOOP AT INTERNAL_TABLE.

FIELD: <i>**mention all the fields in the internal table</i>
           MODULE FETCH_DATA.

ENDLOOP.

********************************************************************************

MODULE POPULATE_TABLE_CONTROL.

<b>******move contents of the fields from internal table to field structure of the table control.</b>

*END OF MODULE POPULATE_TABLE_CONTROL

MODULE CALCULATE_TOTAL.

LOOP AT INTERNAL_TABLE INTO WORK_AREA.

**add the fields you would wish to find the total for.
W_TOTAL = W_TOTAL + WORK_AREA-PRICE.


MOVE W_TOTAL TO WORK_AREA-PRICE.

**this statement is written assuming that there are 15 lines already existing in the **internal table. If this is not the case then you can use append to add the total to last **line. or you can modify the logic as per your requirements.

MODIFY WORK_AREA TO INTERNAL_TABLE INDEX 15.

ENDLOOP.

*END OF MODULE CALCULATE_TOTAL.

MODULE FETCH_DATA.

***copy all the data from the table control structure in to work area for the internal table.
***append the work area into the internal table

*END OF MODULE FETCH_DATA.

Regards,

Kunjal

Former Member
0 Kudos
233

maruthi,

1. when user pressing any key.my content in table control r clearing..i need to

restrict clearing values..how can i achieve it ...

Ans. When ever you press button it will go first to PAI event and will go back to

PBO.So in PBO event you might have wriiten some coding that will get

process and updated in Table control.That time your updated data will get

removed.

For this take all your function codes of your buttons on screen and write

condition

if sy-ucom ne 'ADD' or

sy-ucom ne 'Delete'.

********Here you keep your PBO code

endif.

Now it will work fine.

2.When ever user enter a values in remaing fields,the 15 the field must be updated

Ans)After you entered the data in 14 fields some event has to get trigger then

only you can achieve your goal.

In PBO write

If SY-UCOM is eq 'ADD'.

collect all fields records and add here

move total value to 15th record .

Endif.

when you press ADD button you will achieve .

Pls. reward if useful

Former Member
0 Kudos
233

Hi,

Any type of user interaction with the module pool screen triggers the PBO of your module pool. This is the reason why the contents of your table control are getting refreshed. The only way out is to capture the current state of your table control into some internal table and refresh the table control in the PBO using this internal table.

***********************Reward points if found useful***********************

Regards,

Kriththika