Skip to Content
0
Former Member
Jul 29, 2010 at 03:50 AM

Problem with generic datasource using function module

38 Views

Hi Experts,

My extractor is picking only one data packet. I have come to know that this is happening because of the wrong placing of the end if statement. There should be an end if statement after open cursor statement. Can anyone sugguest me a solution.

Logic Implemented in the code:

FUNCTION z_fi_gl_openitems.

*"----


""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

*" 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 ZFI_GL_OPITEM OPTIONAL

*" EXCEPTIONS

*" NO_MORE_DATA

*" ERROR_PASSED_TO_MESS_HANDLER

*"----


  • Example: DataSource for table SFLIGHT

TABLES: bseg,bkpf,bsis,bsid,bsik.

  • 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

DATA: bsis_cursor TYPE cursor,

bsik_cursor TYPE cursor,

bsid_cursor TYPE cursor,

bseg_cursor TYPE cursor.

  • Select ranges

RANGES: zgjahr FOR bseg-gjahr,

zbukrs FOR bseg-bukrs,

zbudat FOR bsis-budat,

zmonat FOR bsis-monat,

ZBELNR for BSEG-BELNR.

  • 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 'ZFI_GL_OPENITEMS'.

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 = 'GJAHR'.

MOVE-CORRESPONDING l_s_select TO zgjahr.

APPEND zgjahr.

ENDLOOP.

LOOP AT s_s_if-t_select INTO l_s_select WHERE fieldnm = 'BUKRS'.

MOVE-CORRESPONDING l_s_select TO zbukrs.

APPEND zbukrs.

ENDLOOP.

LOOP AT s_s_if-t_select INTO l_s_select WHERE fieldnm = 'MONAT'.

MOVE-CORRESPONDING l_s_select TO zmonat.

APPEND zmonat.

ENDLOOP.

LOOP AT s_s_if-t_select INTO l_s_select WHERE fieldnm = 'BUDAT'.

MOVE-CORRESPONDING l_s_select TO zbudat.

APPEND zbudat.

ENDLOOP.

LOOP AT s_s_if-t_select INTO l_s_select WHERE fieldnm = 'BELNR'.

MOVE-CORRESPONDING l_s_select TO zbelnr.

APPEND zbelnr.

ENDLOOP.

*

OPEN CURSOR bsis_cursor FOR

SELECT bukrs gjahr belnr

FROM bsis WHERE xopvw = 'X'

AND bukrs IN zbukrs

AND gjahr IN zgjahr

AND BELNR IN ZBELNR

AND budat IN zbudat

AND monat IN zmonat.

FETCH NEXT CURSOR bsis_cursor

APPENDING CORRESPONDING FIELDS

OF TABLE itab_bsis

PACKAGE SIZE s_s_if-maxsize.

  • IF sy-subrc <> 0.

  • CLOSE CURSOR bsis_cursor.

  • RAISE no_more_data.

  • ENDIF.

SORT itab_bsis .

DELETE ADJACENT DUPLICATES FROM itab_bsis.

APPEND LINES OF itab_bsis TO itab_final.

*

OPEN CURSOR bsik_cursor FOR

SELECT bukrs gjahr belnr

FROM bsik WHERE bukrs IN zbukrs

AND gjahr IN zgjahr

AND BELNR IN ZBELNR

AND budat IN zbudat

AND monat IN zmonat.

FETCH NEXT CURSOR bsik_cursor

APPENDING CORRESPONDING FIELDS

OF TABLE itab_bsik

PACKAGE SIZE s_s_if-maxsize.

  • IF sy-subrc <> 0.

  • CLOSE CURSOR bsik_cursor.

  • RAISE no_more_data.

  • ENDIF.

SORT itab_bsik .

DELETE ADJACENT DUPLICATES FROM itab_bsik.

APPEND LINES OF itab_bsik TO itab_final.

OPEN CURSOR BSID_CURSOR FOR

SELECT BUKRS GJAHR BELNR

FROM BSID WHERE bukrs IN zbukrs

AND gjahr IN zgjahr

AND BELNR IN ZBELNR

AND budat IN zbudat

AND monat IN zmonat.

FETCH NEXT CURSOR BSID_CURSOR

APPENDING CORRESPONDING FIELDS

OF TABLE ITAB_BSID

PACKAGE SIZE S_S_IF-MAXSIZE.

  • IF SY-SUBRC <> 0.

  • CLOSE CURSOR BSID_CURSOR.

  • RAISE NO_MORE_DATA.

  • ENDIF.

SORT ITAB_BSID .

DELETE ADJACENT DUPLICATES FROM ITAB_BSID.

APPEND LINES OF ITAB_BSID TO ITAB_FINAL.

SORT itab_final.

DELETE ADJACENT DUPLICATES FROM itab_final.

**IF ITAB_FINAL[] IS NOT INITIAL.

*

OPEN CURSOR with hold BSEG_CURSOR for

SELECT bukrs belnr gjahr buzei hkont koart umskz bschl wrbtr dmbtr valut augdt augbl kokrs kostl prctr aufnr projk

werks gsber fkber pprct pargb vbund xref3 sgtxt xnegp zuonr

from BSEG FOR ALL ENTRIES IN itab_final

WHERE bukrs EQ itab_final-bukrs

AND gjahr EQ itab_final-gjahr

AND belnr EQ itab_final-belnr.

FETCH NEXT CURSOR BSEG_CURSOR

APPENDING CORRESPONDING FIELDS OF TABLE E_T_DATA

PACKAGE SIZE S_S_IF-MAXSIZE.

IF SY-SUBRC <> 0.

CLOSE CURSOR BSEG_CURSOR.

RAISE NO_MORE_DATA.

ENDIF.

S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.

  • 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.

*IF ITAB_FINAL[] IS NOT INITIAL.

*

  • SELECT bukrs belnr gjahr buzei hkont koart umskz bschl wrbtr dmbtr valut augdt augbl kokrs kostl prctr aufnr projk

  • werks gsber fkber pprct pargb vbund xref3 sgtxt xnegp zuonr

  • FROM bseg INTO CORRESPONDING FIELDS OF TABLE e_t_data

  • FOR ALL ENTRIES IN itab_final

  • WHERE bukrs EQ itab_final-bukrs

  • AND gjahr EQ itab_final-gjahr

  • AND belnr EQ itab_final-belnr

  • AND BUZEI EQ itab_final-buzei.

*

  • DATA v_awsys TYPE bkpf-awsys.

  • SELECT awsys INTO v_awsys

  • FROM bkpf "into CORRESPONDING FIELDS OF TABLE E_T_DATA

  • FOR ALL ENTRIES IN itab_final

  • WHERE bukrs EQ itab_final-bukrs

  • AND gjahr EQ itab_final-gjahr

  • AND belnr EQ itab_final-belnr.

  • READ TABLE e_t_data WITH KEY bukrs = itab_final-bukrs

  • gjahr = itab_final-gjahr

  • belnr = itab_final-belnr

  • buzei = itab_final-buzei.

  • IF sy-subrc EQ 0.

  • e_t_data-awsys = v_awsys.

  • CLEAR v_awsys.

  • MODIFY e_t_data FROM e_t_data TRANSPORTING awsys.

  • ENDIF.

  • ENDSELECT .

*

*

*endif.

ENDIF.

"First data package ?

  • Fetch records into interface table.

  • named E_T_'Name of extract structure'.

ENDIF. "Initialization mode or data extraction ?

ENDFUNCTION.