Child pages
  • A template for generic data extraction using function module
Skip to end of metadata
Go to start of metadata

FUNCTION <Function module Name>.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(I_REQUNR) TYPE  SBIWA_S_INTERFACE-REQUNR
*"     VALUE(I_CHABASNM) TYPE  SBIWA_S_INTERFACE-CHABASNM OPTIONAL
*"     VALUE(I_MAXSIZE) TYPE  SBIWA_S_INTERFACE-MAXSIZE OPTIONAL
*"     VALUE(I_INITFLAG) TYPE  SBIWA_S_INTERFACE-INITFLAG OPTIONAL
*"     VALUE(I_UPDMODE) TYPE  SBIWA_S_INTERFACE-UPDMODE OPTIONAL
*"     VALUE(I_DATAPAKID) TYPE  SBIWA_S_INTERFACE-DATAPAKID OPTIONAL
*"     VALUE(I_S_TIMEINT) TYPE  SBIWA_S_TIMEINT OPTIONAL
*"  TABLES
*"      I_T_SELECT TYPE  SBIWA_T_SELECT OPTIONAL
*"      I_T_FIELDS TYPE  SBIWA_T_FIELDS OPTIONAL
*"      E_T_DATA STRUCTURE  <Extract Structure> OPTIONAL
*"  EXCEPTIONS
*"      NO_MORE_DATA
*"      ERROR_PASSED_TO_MESS_HANDLER
*"----------------------------------------------------------------------

*

* Auxiliary Selection criteria structure

* Maximum number of lines for DB table
  STATICS: SV_MAXSIZE TYPE SBIWA_S_INTERFACE-MAXSIZE.
* steering flags
  STATICS: SV_LAST_DATA_FLAG TYPE XFELD.
* actual data
  DATA: LV_LOCALSIZE TYPE SY-TABIX.

  concatenate sy-sysid
              'CLNT'
              sy-mandt
              into g_sysname.

  clear g_deltapointer.

  g_datasource = '<Datasource Name>'.

*Set the Update mode by comparing the delta field

        LOOP AT I_T_SELECT INTO WA_SELECT WHERE FIELDNM = '<Delta Relevant field>'.

          select single deltaid
                        from roosgendlm
                        into g_deltapointer
                        where oltpsource = g_datasource.

*         If Record Exists - Deltas Exist else this is the first Delta load
          if sy-subrc = 0.
            I_UPDMODE = 'D'.
          else.
            I_UPDMODE = 'I'.
          endif.

      ENDLOOP.

* Check for update Mode Delta
  if I_UPDMODE = 'D' .                                      "If loop 1

Put in delta logic and determine the delta relevant criterion

*Select all the material numbers for which the configuration has been
*updated

  endif. "End of If Loop 1

* Initialization mode (first call by SAPI) or data transfer mode
* (following calls) ?
*i_initflag = 'X'.

  IF I_INITFLAG = SBIWA_C_FLAG_ON.                          "If loop 3

    IF NOT G_FLAG_INTERFACE_INITIALIZED IS INITIAL.
      IF 1 = 2. MESSAGE E008(R3). ENDIF.
      LOG_WRITE 'E'                    "message type
                'R3'                   "message class
                '008'                  "message number
                ' '                    "message variable 1
                ' '.                   "message variable 2
      RAISE ERROR_PASSED_TO_MESS_HANDLER.
    ENDIF.

    APPEND LINES OF I_T_SELECT TO G_T_SELECT.

* Fill parameter buffer for data extraction calls
    G_S_INTERFACE-REQUNR    = I_REQUNR.
    G_S_INTERFACE-ISOURCE   = I_CHABASNM.
    G_S_INTERFACE-MAXSIZE   = I_MAXSIZE.
    G_S_INTERFACE-INITFLAG  = I_INITFLAG.
    G_S_INTERFACE-UPDMODE   = I_UPDMODE.
    G_S_INTERFACE-DATAPAKID = I_DATAPAKID.
    G_FLAG_INTERFACE_INITIALIZED = SBIWA_C_FLAG_ON.

* Fill field list table for an optimized select statement
    APPEND LINES OF I_T_FIELDS TO G_T_FIELDS.

  ELSE.  "Initialization mode or data extraction ? - If loop 3

************************************************************************
* Data transfer: First Call      OPEN CURSOR + FETCH
*                Following Calls FETCH only
************************************************************************
* First data package -> OPEN CURSOR
    IF G_COUNTER_DATAPAKID = 0.                             "If loop 7

* Fill range tables for fixed InfoSources.
      LOOP AT G_T_SELECT INTO WA_SELECT WHERE FIELDNM = '<Selection field 1>'.
        MOVE-CORRESPONDING WA_SELECT TO GR_EBELN.
        APPEND GR_EBELN.
      ENDLOOP.

      LOOP AT G_T_SELECT INTO WA_SELECT WHERE FIELDNM = '<Selection Field 2>'.
        MOVE-CORRESPONDING WA_SELECT TO GR_EBELP.
        APPEND GR_EBELP.
      ENDLOOP.

.
.
.
.
.
Additional Selections that you want to process.

* Determine number of database records to be read per FETCH statement
* from input parameter I_MAXSIZE.
      SV_MAXSIZE = G_S_INTERFACE-MAXSIZE.

Now open the cursors for fetching the data.

      if I_UPDMODE = 'D' .  "If loop 8
*Fetch all the delta records

here itab_delta holds the changed records identified earlier

        OPEN CURSOR WITH HOLD G_CURSOR FOR
        SELECT * FROM  <Table>
        for all entries in itab_delta
        where <Matches for selection criteria>.

*      "If loop 8
      elseif I_UPDMODE = 'F' OR I_UPDMODE = 'I' OR I_UPDMODE IS INITIAL.
*Fetch all records - this is an Init call
        OPEN CURSOR WITH HOLD G_CURSOR FOR
        SELECT * FROM  <table>.

      endif. "End of If Loop 8
    ENDIF.           "First data package ? end of If loop 7

*.. last data already sent ?
    IF SV_LAST_DATA_FLAG EQ CON_ANGEKREUZT.                 "If loop 9
      RAISE NO_MORE_DATA.
    ENDIF. "End of If Loop 9

* Fetch records into interface table.

    DO.

      FETCH NEXT CURSOR G_CURSOR INTO <Extract Structure work area>.

      if sy-subrc <> 0.
      exit.
      endif.
      if sy-subrc = 0.

Complete any further processing for the data

        APPEND <Work Area for extract structure> TO E_T_DATA.
      else.
        EXIT.
      ENDIF. "End of If Loop 10
    ENDDO.

* Last record reached!!!
    IF LV_LOCALSIZE LT SV_MAXSIZE. " If Loop 20
      CLOSE CURSOR G_CURSOR.
      SV_LAST_DATA_FLAG = CON_ANGEKREUZT.
    ENDIF. "End If Loop 20

    G_COUNTER_DATAPAKID = G_COUNTER_DATAPAKID + 1.

  ENDIF.          "Initialization mode or data extraction ? - If Loop 3

ENDFUNCTION.

GLOBAL DATA INCLUDE

INCLUDE LRSAXD01.

TYPE-POOLS: ibco2.

DATA:   CON_ANGEKREUZT       TYPE XFELD VALUE 'X'.

*...... global ranges for SELECT-Statement
RANGES: GR_MATNR FOR MARA-MATNR,
        GR_MTART FOR MARA-MTART,
        GR_RLTYP FOR IRLOT-RLTYP,
        GR_EBELN FOR EKPO-EBELN,
        GR_EBELP FOR EKPO-EBELP,
        GR_BELNR FOR EKBE-BELNR,
        GR_cpudt for EKBE-cpudt.

  • No labels