sapdev logo background
sapdev logo sapdev logo
Comments

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



comments powered by Disqus