Skip to Content
0

Generic Extractor

May 25, 2017 at 08:27 PM

83

avatar image
Former Member

Z_MASS_READING_STANDARD_TEXTS works as a FM. It returns all the records I need but when I go to RSA3 to test it. I get 0 records returned. The bottom code RSAX_BIW_GET_DATA_SIMPLE is an SAP sample. I know I need to use the "FETCH NEXT CURSOR" for the

  IF SY-SUBRC <> 0.
  CLOSE CURSOR S_CURSOR.
  RAISE NO_MORE_DATA.
  ENDIF.

to work but I have no idea how to do a nested cursor like I'm doing a nested loop.

Thanks for your help.

FUNCTION Z_MASS_READING_STANDARD_TEXTS.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(I_REQUNR) TYPE  SRSC_S_IF_SIMPLE-REQUNR
*"     VALUE(I_DSOURCE) TYPE  SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL
*"     VALUE(I_MAXSIZE) TYPE  SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL
*"     VALUE(I_INITFLAG) TYPE  SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL
*"     REFERENCE(I_READ_ONLY) TYPE  SRSC_S_IF_SIMPLE-READONLY
*"     REFERENCE(I_REMOTE_CALL) TYPE  SBIWA_FLAG
*"  TABLES
*"      I_T_SELECT TYPE  SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL
*"      I_T_FIELDS TYPE  SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL
*"      E_T_DATA STRUCTURE  ZSTXL_STR OPTIONAL
*"  EXCEPTIONS
*"      NO_MORE_DATA
*"----------------------------------------------------------------------

*TYPE-POOLS SBIWA.
*TYPE-POOLS SRSC.

* Constant values for flags
CONSTANTS: SBIWA_C_FLAG_ON   TYPE SBIWA_FLAG VALUE 'X',
           SBIWA_C_FLAG_OFF  TYPE SBIWA_FLAG VALUE ' '.

TYPES: BEGIN OF TY_STXL,
          TDNAME TYPE STXL-TDNAME,
          CLUSTR TYPE STXL-CLUSTR,
          CLUSTD TYPE STXL-CLUSTD,
        END OF TY_STXL.
DATA: T_STXH TYPE STANDARD TABLE OF STXH,
       W_STXH TYPE STXH.
DATA:  T_STXL TYPE STANDARD TABLE OF TY_STXL.
DATA: WA_STXL TYPE ZSTXL_STR.
DATA: TROW TYPE NUMC09.
DATA: W_LINES TYPE NUMC09.
FIELD-SYMBOLS: <STXL> TYPE TY_STXL.
FIELD-SYMBOLS: <TLINE> TYPE TLINE.
TYPES: BEGIN OF TY_STXL_RAW,
          CLUSTR TYPE STXL-CLUSTR,
          CLUSTD TYPE STXL-CLUSTD,
          TDNAME TYPE STXL-TDNAME,
        END OF TY_STXL_RAW.
DATA:  T_STXL_RAW TYPE STANDARD TABLE OF TY_STXL_RAW.
DATA:  W_STXL_RAW TYPE TY_STXL_RAW.
* decompressed text
DATA:  T_TLINE TYPE STANDARD TABLE OF TLINE.

IF i_initflag = sbiwa_c_flag_on.

  SELECT TDNAME TDOBJECT TDID
     FROM STXH
       INTO CORRESPONDING FIELDS OF TABLE T_STXH
    WHERE TDOBJECT EQ 'ZSURTEXT'.
*  AND THEN
*   select compressed text lines in blocks of 3000 (adjustable)

  SELECT TDNAME CLUSTR CLUSTD FROM STXL
          INTO TABLE T_STXL
*          PACKAGE SIZE 3000
          FOR ALL ENTRIES IN T_STXH "WITH APPLICATION DATA AND TDNAME
          WHERE RELID    = 'TX'          "standard text
            AND TDOBJECT = T_STXH-TDOBJECT
            AND TDNAME   = T_STXH-TDNAME
            AND TDID     = T_STXH-TDID
            AND TDSPRAS  = SY-LANGU.
     REFRESH E_T_DATA.
     LOOP AT T_STXL ASSIGNING <STXL>.
*     decompress text
       CLEAR: T_STXL_RAW[], T_TLINE[].
       W_STXL_RAW-CLUSTR = <STXL>-CLUSTR.
       W_STXL_RAW-CLUSTD = <STXL>-CLUSTD.
       W_STXL_RAW-TDNAME = <STXL>-TDNAME.
       APPEND W_STXL_RAW TO T_STXL_RAW.
       IMPORT TLINE = T_TLINE FROM INTERNAL TABLE T_STXL_RAW.
*      access text lines for further processing
       TROW = '0'.
       LOOP AT T_TLINE ASSIGNING <TLINE>.
           TROW = TROW + '1'.
           WA_STXL-TXTID = <STXL>-TDNAME.
           WA_STXL-TXTROW = TROW.
           WA_STXL-TXTLINE = <TLINE>-TDLINE.
           APPEND WA_STXL TO E_T_DATA.
       ENDLOOP.
     ENDLOOP.
   ELSE.
     RAISE NO_MORE_DATA.
   ENDIF.
ENDFUNCTION.
FUNCTION RSAX_BIW_GET_DATA_SIMPLE.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(I_REQUNR) TYPE  SRSC_S_IF_SIMPLE-REQUNR
*"     VALUE(I_DSOURCE) TYPE  SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL
*"     VALUE(I_MAXSIZE) TYPE  SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL
*"     VALUE(I_INITFLAG) TYPE  SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL
*"     VALUE(I_READ_ONLY) TYPE  SRSC_S_IF_SIMPLE-READONLY OPTIONAL
*"     VALUE(I_REMOTE_CALL) TYPE  SBIWA_FLAG DEFAULT SBIWA_C_FLAG_OFF
*"  TABLES
*"      I_T_SELECT TYPE  SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL
*"      I_T_FIELDS TYPE  SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL
*"      E_T_DATA STRUCTURE  SFLIGHT OPTIONAL
*"  EXCEPTIONS
*"      NO_MORE_DATA
*"      ERROR_PASSED_TO_MESS_HANDLER
*"----------------------------------------------------------------------

* Example: DataSource for table SFLIGHT
  TABLES: SFLIGHT.

* Auxiliary Selection criteria structure
  DATA: L_S_SELECT TYPE SRSC_S_SELECT.

* Maximum number of lines for DB table
  STATICS: S_S_IF TYPE SRSC_S_IF_SIMPLE,

* counter
          S_COUNTER_DATAPAKID LIKE SY-TABIX,

* cursor
          S_CURSOR TYPE CURSOR.
* Select ranges
  RANGES: L_R_CARRID  FOR SFLIGHT-CARRID,
          L_R_CONNID  FOR SFLIGHT-CONNID.

* Initialization mode (first call by SAPI) or data transfer mode
* (following calls) ?
  IF I_INITFLAG = SBIWA_C_FLAG_ON.

************************************************************************
* Initialization: check input parameters
*                 buffer input parameters
*                 prepare data selection
************************************************************************

* Check DataSource validity
    CASE I_DSOURCE.
      WHEN '0SAPI_SFLIGHT_SIMPLE'.
      WHEN OTHERS.
        IF 1 = 2. MESSAGE E009(R3). ENDIF.
* this is a typical log call. Please write every error message like this
        LOG_WRITE 'E'                  "message type
                  'R3'                 "message class
                  '009'                "message number
                  I_DSOURCE   "message variable 1
                  ' '.                 "message variable 2
        RAISE ERROR_PASSED_TO_MESS_HANDLER.
    ENDCASE.

    APPEND LINES OF I_T_SELECT TO S_S_IF-T_SELECT.

* Fill parameter buffer for data extraction calls
    S_S_IF-REQUNR    = I_REQUNR.
    S_S_IF-DSOURCE = I_DSOURCE.
    S_S_IF-MAXSIZE   = I_MAXSIZE.

* Fill field list table for an optimized select statement
* (in case that there is no 1:1 relation between InfoSource fields
* and database table fields this may be far from beeing trivial)
    APPEND LINES OF I_T_FIELDS TO S_S_IF-T_FIELDS.

  ELSE.                 "Initialization mode or data extraction ?

************************************************************************
* Data transfer: First Call      OPEN CURSOR + FETCH
*                Following Calls FETCH only
************************************************************************

* First data package -> OPEN CURSOR
    IF S_COUNTER_DATAPAKID = 0.

* Fill range tables BW will only pass down simple selection criteria
* of the type SIGN = 'I' and OPTION = 'EQ' or OPTION = 'BT'.
      LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'CARRID'.
        MOVE-CORRESPONDING L_S_SELECT TO L_R_CARRID.
        APPEND L_R_CARRID.
      ENDLOOP.

      LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'CONNID'.
        MOVE-CORRESPONDING L_S_SELECT TO L_R_CONNID.
        APPEND L_R_CONNID.
      ENDLOOP.

* Determine number of database records to be read per FETCH statement
* from input parameter I_MAXSIZE. If there is a one to one relation
* between DataSource table lines and database entries, this is trivial.
* In other cases, it may be impossible and some estimated value has to
* be determined.
      OPEN CURSOR WITH HOLD S_CURSOR FOR
      SELECT (S_S_IF-T_FIELDS) FROM SFLIGHT
                               WHERE CARRID  IN L_R_CARRID AND
                                     CONNID  IN L_R_CONNID.
    ENDIF.                             "First data package ?

* Fetch records into interface table.
*   named E_T_'Name of extract structure'.
    FETCH NEXT CURSOR S_CURSOR
               APPENDING CORRESPONDING FIELDS
               OF TABLE E_T_DATA
               PACKAGE SIZE S_S_IF-MAXSIZE.

    IF SY-SUBRC <> 0.
      CLOSE CURSOR S_CURSOR.
      RAISE NO_MORE_DATA.
    ENDIF.

    S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.

  ENDIF.              "Initialization mode or data extraction ?

ENDFUNCTION.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Koen Hesters Aug 04, 2017 at 08:15 AM
0

Hi,

you need to extract first the data into your e_t_data via fetch cursor, as second step you can loop over your e_t_data and develop your nested loops there.

IT_STXH should become your e_t_data CURSOR filled datapackage

Grtz

Koen

Share
10 |10000 characters needed characters left characters exceeded