Skip to Content
0
Former Member
Sep 26, 2005 at 10:02 AM

Function Module

12 Views

I have created function Module. What is happening data package is processed but request is not convertign to greee.

Guys please help...

I am pasting code for yuor reference

-


Example: DataSource for table SFLIGHT

  • TABLES: YSALES,

  • MBEW.

DATA: BEGIN OF I_YSALES OCCURS 0.

INCLUDE STRUCTURE YSALES.

DATA: END OF I_YSALES.

DATA: BEGIN OF I_MBEW OCCURS 0.

INCLUDE STRUCTURE MBEW.

DATA: END OF I_MBEW.

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

S_CURSOR1 TYPE CURSOR.

  • Select ranges

RANGES: L_R_ZYEAR FOR YSALES-ZYEAR,

L_R_ZMONTH FOR YSALES-ZMONTH.

*

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

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

MOVE-CORRESPONDING L_S_SELECT TO L_R_ZYEAR.

APPEND L_R_ZYEAR.

ENDLOOP.

LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'ZMONTH'.

MOVE-CORRESPONDING L_S_SELECT TO L_R_ZMONTH.

APPEND L_R_ZMONTH.

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 *

FROM YSALES .

  • OPEN CURSOR WITH HOLD S_CURSOR1 FOR

  • SELECT (S_S_IF-T_FIELDS)

  • FROM MBEW WHERE YSALES~MATNR

  • AND BWKEY = YSALES~WERKS.

*

  • select BUKRS

  • ZYEAR

  • ZMONTH

  • WERKS

  • MATNR

  • SLSCAT

  • KNDNR

  • SPART

  • MATKL

  • MENGE

  • DMBTR

  • VV702

  • VV703

  • VVADS

  • VV704

  • VV731

  • INTO

  • CORRESPONDING FIELDS OF table I_YSALES

  • PACKAGE SIZE S_S_IF-MAXSIZE

  • FROM YSALES

  • WHERE ZYEAR IN L_R_ZYEAR

  • AND ZMONTH IN L_R_ZMONTH.

  • ENDSELECT.

  • WHERE MATNR IN L_R_MATNR.

  • WHERE WERKS = WERKS

  • AND MATNR = MATNR

  • AND KNDNR = KNDNR

  • AND SPART = SPART.

  • IF SY-SUBRC = 0.

  • SORT I_YSALES BY WERKS MATNR .

  • ENDIF.

  • *

    • IF NOT I_YSALES[] IS INITIAL.

    *

    • SELECT MATNR

    • BWKEY

    • BWTAR

    • LBKUM

    • SALK3

    • BKLAS

    • INTO CORRESPONDING FIELDS OF TABLE I_MBEW

    • PACKAGE SIZE S_S_IF-MAXSIZE

    • FROM MBEW

    • FOR ALL ENTRIES IN I_YSALES

    • WHERE MATNR = I_YSALES-MATNR

    • AND BWKEY = I_YSALES-WERKS.

    • ENDSELECT.

    *

    • ENDIF.

    *

    • LOOP AT I_YSALES .

    • MOVE-CORRESPONDING I_YSALES TO E_T_DATA.

    • READ TABLE I_MBEW WITH KEY MATNR = I_YSALES-MATNR

    • BWKEY = I_YSALES-WERKS.

    • IF SY-SUBRC = 0.

    • MOVE-CORRESPONDING I_MBEW TO E_T_DATA.

    • ENDIF.

    • APPEND E_T_DATA.

    • ENDLOOP.

    *

    *

    *

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

    ENDIF.

    ENDFUNCTION.