Sub Total & Total in Script


Step1. Here we have the script page window, select the window and click on the text element.

Step2. Provide the below text elements, one for displaying the records, one for displaying the sub total and one for displaying the Total. Go back and activate the script.

Step3. Here we have the program which reads the flight details and calls the script. Here for every connoid the sub total is displayed and at the end the total is displayed.


DATA : lt TYPE TABLE OF sflight,

             ls TYPE sflight.

DATA : sub_tot TYPE sflight-price,

             total TYPE sflight-price.


SELECT * FROM sflight INTO TABLE lt UP TO 50 ROWS .

SORT lt BY carrid connid ASCENDING.

CALL FUNCTION ‘OPEN_FORM’.


CALL FUNCTION ‘START_FORM’

 EXPORTING

  form    = ‘ZSCRIPT_WORK1’.

LOOP AT lt INTO ls .


CALL FUNCTION ‘WRITE_FORM’

EXPORTING

   element    = ‘TXT_ELEM_1’

   “FUNCTION   = ‘SET’

   type       = ‘BODY’

   window     = ‘MAIN’.

 sub_tot = sub_tot + ls-price.


AT END OF CONNID.


CALL FUNCTION ‘WRITE_FORM’

EXPORTING

   element    = ‘TXT_ELEM_SUB_TOT’

   “FUNCTION   = ‘SET’

   type       = ‘BODY’

   window     = ‘MAIN’.

CLEAR sub_tot.

ENDAT.


total = total + ls-price.


CLEAR ls.

ENDLOOP.

CALL FUNCTION ‘WRITE_FORM’

EXPORTING

   element    = ‘TXT_ELEM_TOTAL’

   “FUNCTION   = ‘SET’

   type       = ‘BODY’

   window     = ‘MAIN’.


CALL FUNCTION ‘END_FORM’.

CALL FUNCTION ‘CLOSE_FORM’.



Step4. Run the  above report and we have the below out put with sub total and total.


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s