Printing Total, Carry forward amount and Grand total in SAP Script

...Previous

Step 3: Calling the Print Program using SE38.
*"Table declarations...................................................
tables:
sflight.                               "Flight Details
*"--------------------------------------------------------------------*
* Type declaration of the structure to hold                           *
* FLIGHT CONNECTION DETAILS                                 *
* from TABLE SFLIGHT                                                     *
*"--------------------------------------------------------------------*
types:
 begin of type_s_sflight,
   carrid    type sflight-carrid,      " Airline code
   connid    type sflight-connid,      " Flight connection number
   fldate    type sflight-fldate,      " Flight date
   planetype type sflight-planetype,   " Plane Type
   price     type sflight-price,       " Airfare
 end of type_s_sflight.
*"--------------------------------------------------------------------*
* Field string declaration of the structure to hold                  *
* FLIGHT CONNECTION DETAILS from TABLE           *
* SFLIGHT                                                                            *
*"--------------------------------------------------------------------*
data
  fs_sflight type type_s_sflight.
*"--------------------------------------------------------------------*
* Internal table to hold Flight details                                    *
*"--------------------------------------------------------------------*
data
  t_sflight like
   standard table of fs_sflight.
*"Selection screen elements...........................................
select-options:
  s_carrid for sflight-carrid.         " Airline code
*" Data declarations...................................................
*"--------------------------------------------------------------------*
* Work variables                                                                   *
*"--------------------------------------------------------------------*
data:
  w_index type n value 1,              " Serial number
  w_sum   type p decimals 2.           " Sum variable
*"--------------------------------------------------------------------*
*                       START-OF-SELECTION EVENT             *
*"--------------------------------------------------------------------*
start-of-selection.
*&---------------------------------------------------------------------*
*&      Subroutines for displaying the data                              *
*&---------------------------------------------------------------------*
  perform getsflightrecords.
  perform open_form.
  perform start_form using 'Z_SCRIPTS'.
  perform main_window.
  perform end_form.
  perform start_form using 'Z_SCRI_LAND'.
  perform landscape_format.
  perform end_form.
  perform close_form.
*&---------------------------------------------------------------------*
*&      Form  GETSFLIGHTRECORDS
*&---------------------------------------------------------------------*
* This subroutine gets the Flight records from the table SFLIGHT
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine.
*----------------------------------------------------------------------*
form getsflightrecords .
  select carrid                        " Airline code
         connid                        " Flight connection number
         fldate                        " Flight date
         planetype                     " Plane type
         price                         " Airfare
  from sflight
  into table t_sflight
  where carrid in s_carrid.
  if sy-subrc ne 0.
    message 'Records Not Found'(001) type 'S'.
  endif.
endform.                    " GETSFLIGHTRECORDS
*&---------------------------------------------------------------------*
*&      Form  OPEN_FORM
*&---------------------------------------------------------------------*
*  This subroutine opens the script form Z_SCRIPTS
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.
*----------------------------------------------------------------------*
form open_form .
  call function 'OPEN_FORM'
   exporting
*   APPLICATION                       = 'TX'
*   ARCHIVE_INDEX                     =
*   ARCHIVE_PARAMS                    =
*   DEVICE                            = 'PRINTER'
*   DIALOG                            = 'X'
     form                              = 'Z_SCRIPTS'
     language                          = sy-langu
*   OPTIONS                           =
*   MAIL_SENDER                       =
*   MAIL_RECIPIENT                    =
*   MAIL_APPL_OBJECT                  =
*   RAW_DATA_INTERFACE                = '*'
*   SPONUMIV                          =
* IMPORTING
*   LANGUAGE                          =
*   NEW_ARCHIVE_PARAMS                =
*   RESULT                            =
   exceptions
     canceled                          = 1
     device                            = 2
     form                              = 3
     options                           = 4
     unclosed                          = 5
     mail_options                      = 6
     archive_error                     = 7
     invalid_fax_number                = 8
     more_params_needed_in_batch       = 9
     spool_error                       = 10
     codepage                          = 11
     others                            = 12.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
endform.                    " OPEN_FORM
*&---------------------------------------------------------------------*
*&      Form  MAIN_WINDOW
*&---------------------------------------------------------------------*
*  This subroutine prints the SFLIGHT records in a MAIN window
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.
*----------------------------------------------------------------------*
form main_window .
  loop at t_sflight into fs_sflight.
    call function 'WRITE_FORM'
      exporting
      element                          = 'SFLIGHT'
*   FUNCTION                           = 'SET'
*   TYPE                               = 'BODY'
        window                         = 'MAIN'
* IMPORTING
*   PENDING_LINES                      =
      exceptions
        element                        = 1
        function                       = 2
        type                           = 3
        unopened                       = 4
        unstarted                      = 5
        window                         = 6
        bad_pageformat_for_print       = 7
        spool_error                    = 8
        codepage                       = 9
        others                         = 10.
    if sy-subrc <> 0.
      message id sy-msgid type sy-msgty number sy-msgno
              with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
*&---------------------------------------------------------------------*
*&  This statement is used to display the grand total for the last page   
*&---------------------------------------------------------------------*
    at last.
      call function 'WRITE_FORM'
       exporting
       element                          = 'GRAND_TOTAL'
*   FUNCTION                            = 'SET'
*   TYPE                                = 'BODY'
         window                         = 'MAIN'
* IMPORTING
*   PENDING_LINES                       =
       exceptions
         element                        = 1
         function                       = 2
         type                           = 3
         unopened                       = 4
         unstarted                      = 5
         window                         = 6
         bad_pageformat_for_print       = 7
         spool_error                    = 8
         codepage                       = 9
         others                         = 10.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
      exit.
    endat.
    w_index  = w_index + 1.
    if w_index eq 6.
      call function 'WRITE_FORM'
   exporting
   element                          = 'PAGE_TOTAL'
*   FUNCTION                        = 'SET'
*   TYPE                            = 'BODY'
     window                         = 'MAIN'
* IMPORTING
*   PENDING_LINES                   =
   exceptions
     element                        = 1
     function                       = 2
     type                           = 3
     unopened                       = 4
     unstarted                      = 5
     window                         = 6
     bad_pageformat_for_print       = 7
     spool_error                    = 8
     codepage                       = 9
     others                         = 10.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
      call function 'CONTROL_FORM'
        exporting
          command   = 'NEW-PAGE'
        exceptions
          unopened  = 1
          unstarted = 2
          others    = 3.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
      w_index = 1.
    endif.
  endloop.
endform.                    " MAIN_WINDOW                    " WRITE_FORM
*&---------------------------------------------------------------------*
*&      Form  CLOSE_FORM
*&---------------------------------------------------------------------*
* This subroutine closes the form Z_SCRIPTS
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine.
*----------------------------------------------------------------------*
form close_form .
  call function 'CLOSE_FORM'
* IMPORTING
*   RESULT                          =
*   RDI_RESULT                      =
* TABLES
*   OTFDATA                         =
   exceptions
     unopened                       = 1
     bad_pageformat_for_print       = 2
     send_error                     = 3
     spool_error                    = 4
     codepage                       = 5
     others                         = 6.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
endform.                    " CLOSE_FORM
*&---------------------------------------------------------------------*
*&      Form  LANDSCAPE_FORMAT
*&---------------------------------------------------------------------*
* This subroutine prints the instructions on the landscape page
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine.
*----------------------------------------------------------------------*
form landscape_format .
  call function 'WRITE_FORM'
   exporting
     element                        = 'INSTRUCTIONS'
*   FUNCTION                       = 'SET'
*   TYPE                           = 'BODY'
     window                         = 'MAIN'
* IMPORTING
*   PENDING_LINES                  =
   exceptions
     element                        = 1
     function                       = 2
     type                           = 3
     unopened                       = 4
     unstarted                      = 5
     window                         = 6
     bad_pageformat_for_print       = 7
     spool_error                    = 8
     codepage                       = 9
     others                         = 10.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
endform.                    " LANDSCAPE_FORMAT
*&---------------------------------------------------------------------*
*&      Form  START_FORM
*&---------------------------------------------------------------------*
*  This subroutine fetches the form Z_SCRIPTS
*----------------------------------------------------------------------*
*      -->P_0068   -- Z_SCRIPTS
*----------------------------------------------------------------------*
form start_form  using value(p_0068).
  call function 'START_FORM'
   exporting
*   ARCHIVE_INDEX          =
     form                    = p_0068
*   LANGUAGE               = ' '
*   STARTPAGE              = ' '
*   PROGRAM                = ' '
*   MAIL_APPL_OBJECT       =
* IMPORTING
*   LANGUAGE               =
   exceptions
     form                    = 1
     format                  = 2
     unended                 = 3
     unopened                = 4
     unused                  = 5
     spool_error             = 6
     codepage                = 7
     others                  = 8.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
endform.                    " START_FORM
*&---------------------------------------------------------------------*
*&      Form  END_FORM
*&---------------------------------------------------------------------*
* This subroutine ends the form Z_SCRI_LAND
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine.
*----------------------------------------------------------------------*
form end_form .
  call function 'END_FORM'
* IMPORTING
*   RESULT                        =
   exceptions
     unopened                       = 1
     bad_pageformat_for_print       = 2
     spool_error                    = 3
     codepage                       = 4
     others                         = 5.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
endform.                    " END_FORM

Click here to continue...

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image