ABAP Export data to memory - Demonstrate use of ABAP program to retrieve data for use in BSP

Below is an example ABAP program which will populate a simple internal table(it_ekpo) with data and either display it as an ALV grid or export it to memory. Purpose of this example is to demonstrate use of ABAP report to retrieve data for BSP application.


*&-------------------------------------------------------------*
*& Report  ZBSP_GETDATA                                        *
*&                                                             *
*&-------------------------------------------------------------*
*&                                                             *
*& Example of a simple data retrieval                          *
*& ...................................                         *
*&                                                             *
*& Used to demonstrate executing a report via a BSP application*
*& and using the data retrieved as the basis for the BSP app.  *
*&                                                             *
*& If report is executed via a BSP then data is extracted to   *
*& memory and then retrievd by the BSP....                     *
*&-------------------------------------------------------------*
REPORT  zbsp_getdata                 .
TABLES:     tstc.
type-pools: slis.                                 "ALV Declarations
parameters: p_bsp(1) type c no-display.
*Data Declaration
*----------------
TYPES: BEGIN OF t_tstc,
  TCODE type tstc-tcode,
  PGMNA type tstc-pgmna,
 END OF t_tstc.
DATA: it_tstc TYPE STANDARD TABLE OF t_tstc INITIAL SIZE 0,
      wa_tstc TYPE t_tstc.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
      gd_tab_group type slis_t_sp_group_alv,
      gd_layout    type slis_layout_alv,
      gd_repid     like sy-repid.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
  perform data_retrieval.
  perform build_fieldcatalog.
  perform build_layout.
  perform display_alv_report.
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.
  fieldcatalog-fieldname   = 'TCODE'.
  fieldcatalog-seltext_m   = 'Trans code'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-emphasize   = 'X'.
  fieldcatalog-key         = 'X'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.
  fieldcatalog-fieldname   = 'PGMNA'.
  fieldcatalog-seltext_m   = 'Program'.
  fieldcatalog-col_pos     = 1.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.
endform.                    " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-totals_text       = 'Totals'(201).
endform.                    " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
  if p_bsp EQ 'X'. "If report run from BSP application
    export it_tstc to memory id sy-uname.
  else.
    gd_repid = sy-repid.
    call function 'REUSE_ALV_GRID_DISPLAY'
         exporting
              i_callback_program      = gd_repid
              is_layout               = gd_layout
              it_fieldcat             = fieldcatalog[]
              i_save                  = 'X'
         tables
              t_outtab                = it_tstc
         exceptions
              program_error           = 1
              others                  = 2.
 endif.
endform.                    " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
data: r_tcode type range of tstc-tcode with header line.
r_tcode-sign   = 'I'.
r_tcode-option = 'CP'.
r_tcode-low    = 'SE*'.
append r_tcode.
  select tcode pgmna
   up to 10 rows
    from tstc
    into table it_tstc
   where tcode in r_tcode.
endform.                    " DATA_RETRIEVAL

Related Articles

Javascript to capture when a user closes or leaves sap bsp html page
Using AJAX functionality within our SAP BSP
Close BSP Session (type 'Pluggin HTTP') including when in SAP portal
SAP BSP to auto select region when user selects country using HTML and Javascript
HTML and Javascript code to force enter key to perform tab
JavaScrip command getElementById useful examples
MVC BSP input field - Demonstrate how to retrieve a value entered into text input field
Allowing multiple instances of a BSP application to be run by a user
Execute Standard SAP Transaction from BSP using dynamically created shortcut
Uplaod file within SAP BSP application using HTML and ABAP coding
UUseful SAP BSP application code - ABAP, HTML, HTMLB, Javascript, CSS
Creating a BSP Application class to help store and pass data betwenn your BSP pages
Training Course and Workshop Booking Form
BSP checkboxes using HTML and the OnInputProcessing BSP Event
BSP checkboxes using HTML and the OnInputProcessing BSP Event
Check HTML checkbox is checked using Javascript within your SAP BSP
BSP Dropdown List - create a BSP dropdown list which allows user selection!!
ABAP BSP to allow user to select from SAP HR org structure - CSS file
Java script to display tree structure on your SAP BSP web page
Create a Simple BSP - Simple BSP to display text and call section BSP page using HTML
SAP BSP Training course booking - Creating an example training course booking form using BSP
Creating an SAP BSP which executes an ABAP report to retrieve data for use within BSP application
org selection BSP - detials.htm page
Display page of the SAP BSP example application to store favourite tcodes as a cookie
Execute.htm page of the SAP BSP example application to store favourite tcodes as a cookie
Favourites cookie bsp - initial page to display input fields and retrieve user input
BSP using cookies - Demonstrate use of cookies within a BSP to store user favourits
MVC BSP HTMLB input field - Demonstrate how to retrieve a value entered into text input field
BSP development using standard HTML code instead of Business HTML (HTMLB)
Business HTML (HTMLB) - List of business HTML tags you can use within your BSP
Adding JavaScript to BSP (HTML) pages - Shows how to add javascript to your BSP pages
Example JavaScript code which can be added to your BSP application
BSP MIME Objects for Org. search application
Call onInputProcessing event from SAP BSP page via href or button
Organisation selection BSP - close internet window using javascript
Organisation selection BSP - get server side cookie ( get_server_cookie )
orgaisation selection BSP - set and get server side cookie ( set_server_cookie )
Display orgaisation selection BSP
BSP which allows HR Organisation Structure search and selection using javascript
Organisation update program - get server side cookie ( get_server_cookie )
BSP to capture user entry into HTML input fields
Capture BSP radiobutton selection using HTML and the OnInputProcessing BSP Event
BSP checkboxes using HTML and the OnInputProcessing BSP Event
Stateful and stateless BSP applications
Get user entry into HTML input fields with SAP BSP
Javascript to capture when a user closes or leaves sap bsp html page
Creating a BSP using the Model View Controller ( MVC ) technique
Using SAP Model View Controller (MVC) development techniques to develop BSPs
Adding a JavaScript date selection field to a BSP
Creating a BSP using the Model View Controller ( MVC ) technique
Creating a BSP using the Model View Controller(MVC) technique
Creating a BSP using the Model View Controller ( MVC ) technique
Retrieve value from input text field within a model view controller ( MVC) BSP
Web Application Development - Example code and information on development using BSP
SAP BSP / Business Server Pages combine ABAP and other web technologies such as HTML, CSS
BSP development screen - developing application using business server pages
Standard Program created in SE38 or SE80