Pages

Tuesday, 16 September 2014

BAPI - step by step creation


BAPI- Business Application Programming Interface

Step1: Creating a structure in SE11

Step2: Creating the function module in SE37
Step 3: Creating the business object in SWO1
Step 4: Viewing the created BAPI in BAPI Explorer
Step 5: Test your BAPI in SWO1


Step1: Creating a structure in SE11


Simple OOPS Concept ALV

*&---------------------------------------------------------------------*
*& Report  ZDEMO123
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report  zdemo123.

*----------------------------------------------------------------------*
*       CLASS local DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class local definition .
 public section .
   data: it_bkpf type standard table of bkpf .
   types : r_belnr  type range of bkpf-belnr .
   methods:get_data importing belnr type r_belnr,
           fieldcat exporting e_fcat type lvc_t_fcat,
           build_alv importing i_fcat type lvc_t_fcat  .
endclass .                    "local DEFINITION

*----------------------------------------------------------------------*
*       CLASS local IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class local implementation .

 method:get_data.
   select * from bkpf into table it_bkpf where belnr in belnr .
 endmethod .                    "get_data
 method fieldcat .

   call function 'LVC_FIELDCATALOG_MERGE'
    exporting
*      I_BUFFER_ACTIVE              =
      i_structure_name             = 'BKPF'
*      I_CLIENT_NEVER_DISPLAY       = 'X'
*      I_BYPASSING_BUFFER           =
*      I_INTERNAL_TABNAME           = IT_BKPF
     changing
       ct_fieldcat                  = e_fcat
    exceptions
      inconsistent_interface       = 1
      program_error                = 2
      others                       = 3  .

*    lc_fcat = e_fcat .
 endmethod .                    "fieldcat


 method: build_alv .
   data lo_grid type ref to cl_gui_alv_grid.
   data: c_fcat type lvc_t_fcat .
   create object lo_grid
     exporting
       i_parent = cl_gui_custom_container=>screen0.
   c_fcat = i_fcat .
   call method lo_grid->set_table_for_first_display
     changing
       it_outtab                     = it_bkpf
       it_fieldcatalog               = c_fcat
     exceptions
       invalid_parameter_combination = 1
       program_error                 = 2
       too_many_lines                = 3
       others                        = 4.

 endmethod .                    "build_alv

endclass .                    "local IMPLEMENTATION

data: obj_local type ref to local.
data: cfcat type lvc_t_fcat .
tables: bkpf .

select-options : s_belnr for bkpf-belnr .
selection-screen begin of screen 1001 .
selection-screen end of screen 1001.

start-of-selection .


 create object obj_local .

 obj_local->get_data( exporting belnr = s_belnr[] ) .
 obj_local->fieldcat( importing e_fcat = cfcat ) .

 obj_local->build_alv( exporting i_fcat = cfcat ) .

 call selection-screen 1001 ."STARTING AT 8 8 ENDING AT 85 22.