Tuesday, 18 November 2014

SCRIPT: Determining Sub Total & Total in SAP 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.






































































--------------------------------------------------------------------------------------------

No comments:

Comments system

Disqus Shortname