Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Function Module error

Former Member
0 Likes
1,718

Hello Friends I created a function module to generate a extractor, but i am getting this error SRSC_S_IF_SIMPLE is UNKNOWN. Kindly let me know what i need to change in Funtion module Function Pool to make it work.

Please tell me your email so I can send the screen shots for the Tabs in MY FM.

Please help me with some minor correction in code to make it work.

Extractor Logic is simple: Pick up N fields from KNA1 Customer master and then go to KNB1 to pick up zterm and akont where KUNNR -KNA1 = KUNNR - KNB1 AND KUNNR-ERDAT = KNB1-ERDAT. My custom table ZBW_SFLI001_DS is that will be populated by the code below

My code is as below.

FUNCTION Z_CUSTOMER.

*"----


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

*" EXCEPTIONS

*" NO_MORE_DATA

*" ERROR_PASSED_TO_MESS_HANDLER

*"----


************************************************************************

*Soniya KAPOOR

*

  • This code is an example of providing data to a generic extractor

  • based on a function module.

*

  • Our generic extractor uses the ZBW_SFLI001_DS table as its extract

  • structure. The ZCALWEEK and ZKUNNR fields will have selections

  • enabled in the generic extractor.

*

  • this structure will be used to decode selections passed from the

  • extractor

DATA: l_s_select TYPE SRSC_S_SELECT.

  • The following static variables are populated in the first call

  • (the initialization call) to the extractor and then are used in

  • subsequent calls.

  • the S_S_IF structure is used to hold incoming parameters.

STATICS: s_s_if TYPE SRSC_S_IF_SIMPLE,

  • a simple counter

s_counter_datapakid LIKE SY-TABIX,

  • a database cursor that will read and return records

s_cursor TYPE CURSOR.

  • Select ranges

  • When the function module is called for the first time the

  • I_T_SELECT table holds any selections from the infopackage.

  • We will extract those selections and store them in these

  • ranges. We will then use these ranges to limit the amount

  • of data returned to BW.

RANGES: l_r_zcalweek FOR ZBW_SFLI001_DS-ZCALWEEK,

l_r_ZKUNNR FOR ZBW_SFLI001_DS-ZKUNNR.

  • The extractor will have a selection for calendar week but the

  • data is stored in the KNA1 table by calendar day. We'll include

  • logic later in the function module to take the incoming calendar

  • week selections and create calendar day selections. We'll put

  • those calendar day selections in this range and then use it

  • to limit the amount of data coming from KNA1.

RANGES: l_r_ERDAT FOR KNA1-ERDAT.

  • Helper variable if we need to loop on week ranges

DATA: zweek LIKE ZBW_SFLI001_DS-ZCALWEEK.

  • Helper internal table to hold KNA1 records that match our

  • selections

DATA: ZKNA1 LIKE KNA1 OCCURS 0 WITH HEADER LINE.

  • Helper internal table to hold KNB1 records that match our

  • selections

DATA: ZKNB1 LIKE KNB1 OCCURS 0 WITH HEADER LINE.

  • Helper internal table to accumulate data from KNA1

DATA: zitab LIKE ZBW_SFLI001_DS OCCURS 0 WITH HEADER LINE.

  • Now we are getting into the real logic of the function module.

  • The function module is called several times; once for an

  • initialization and then several more times (once for each data

  • packet) until the function module signals that there is no

  • more data available.

  • The I_INITFLAG is an IMPORT parameter that indicates if this

  • is the first call. If so, validate the datasource and put

  • away the other initialization fields into static variables

  • for use in later calls.

IF I_INITFLAG = SBIWA_C_FLAG_ON. "Step (A)

  • This should never happen, but just in case.

CASE I_DSOURCE.

WHEN 'ZBW_SFLI001_DS'.

WHEN OTHERS.

IF 1 = 2. MESSAGE E009(R3). ENDIF.

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.

  • Make a static copy of the selection field ranges

APPEND LINES OF I_T_SELECT TO s_s_if-t_select. "Step (B)

  • This grabs a copy of the IMPORT parameters into static variables.

  • These static variables can be used in later calls to the function

  • module.

s_s_if-requnr = I_REQUNR. "Step (B)

s_s_if-dsource = I_DSOURCE. "Step (B)

s_s_if-maxsize = I_MAXSIZE. "Step (B)

  • The I_T_FIELDS table holds the fields that the extractor is

  • expecting. You can use this field list to minimize the

  • fields read from database tables.

APPEND LINES OF I_T_FIELDS TO s_s_if-t_fields. "Step (B)

ELSE. "Initialization mode or data extraction ?

  • This batch of code is for later calls into the function module

  • (to gather and return data).

  • If we haven't returned any data packets yet (this is the first

  • function module call asking for data packets), then gather up

  • the necessary data.

IF s_counter_datapakid = 0. "Step (C)

"Begin of Step (D)

  • In the initialization call we copied the incoming I_T_SELECT

  • table (which holds infopackage selections) into the S_S_IF

  • static variable. Now interrogate those selections to create

  • ranges that will be used to restrict the database records read.

  • We know (because we defined the extractor) that the only two fields

  • that can have selections are ZCALWEEK and ZKUNNR.

LOOP AT s_s_if-t_select INTO l_s_select WHERE FIELDNM = 'ZCALWEEK'.

MOVE-CORRESPONDING l_s_select TO l_r_zcalweek.

APPEND l_r_zcalweek.

ENDLOOP.

LOOP AT s_s_if-t_select INTO l_s_select WHERE FIELDNM = 'ZKUNNR'.

MOVE-CORRESPONDING l_s_select TO l_r_ZKUNNR.

APPEND l_r_ZKUNNR.

ENDLOOP.

  • The generic extractor has selections on calendar week, but our data

  • (in the KNA1 table) is captured by flight date. So we need to

  • take our calendar week selections and convert them into flight

  • date selections.

  • The ZCALWEEK range could be a single week, it could be a range

  • of weeks, or it could be several of both.

LOOP AT l_r_zcalweek.

  • handle either single values (EQ) or ranges (BT)

CASE l_r_zcalweek-option.

WHEN 'EQ'.

  • convert the low value to a date range

CALL FUNCTION 'WEEK_GET_FIRST_DAY'

EXPORTING

WEEK = l_r_zcalweek-low

IMPORTING

DATE = l_r_ERDAT-low

EXCEPTIONS

WEEK_INVALID = 1

OTHERS = 2.

l_r_ERDAT-high = l_r_ERDAT-low + 7.

l_r_ERDAT-sign = 'I'.

l_r_ERDAT-option = 'BT'.

APPEND l_r_ERDAT.

when 'BT'.

zweek = l_r_zcalweek-low.

WHILE zweek <= l_r_zcalweek-high.

  • convert the low value to a date range

CALL FUNCTION 'WEEK_GET_FIRST_DAY'

EXPORTING

WEEK = zweek

IMPORTING

DATE = l_r_ERDAT-low

EXCEPTIONS

WEEK_INVALID = 1

OTHERS = 2.

l_r_ERDAT-high = l_r_ERDAT-low + 7.

l_r_ERDAT-sign = 'I'.

l_r_ERDAT-option = 'BT'.

APPEND l_r_ERDAT.

zweek = zweek + 1.

ENDWHILE.

ENDCASE.

ENDLOOP.

"End of Step (D)

  • Now it's time to gather the data and populate our ZBW_SFLI001_DS

  • table. But first let's make sure we don't have any residual data

  • already in the table for this same request identifier.

  • For example, if we use RSA3 to test the extractor, the request

  • identifier is always TEST. Let's make sure we don't have any

  • left over from previous tests.

DELETE FROM ZBW_SFLI001_DS "Step (E)

WHERE ZREQUNR = s_s_if-requnr.

  • Now lets go get data from the KNA1 table that meets our selection

  • criteria.

SELECT * FROM KNA1 "Step (F)

INTO TABLE ZKNA1

WHERE ERDAT IN l_r_ERDAT

AND KUNNR IN l_r_ZKUNNR.

  • Now get all matching KNB1 records (we need these to calculate

  • our expected revenue)

SELECT * FROM KNB1 "Step (F)

INTO TABLE ZKNB1

FOR ALL ENTRIES IN ZKNA1

WHERE KUNNR = ZKNA1-KUNNR

AND ERDAT = ZKNA1-ERDAT.

"Begin of Step (G)

  • now take the KNA1 records and build records to send back to BW

LOOP AT ZKNA1.

  • set the request identZfier

zitab-zrequnr = s_s_if-requnr.

  • set the calendar week based on the flight date

CALL FUNCTION 'DATE_GET_WEEK'

EXPORTING

DATE = ZKNA1-ERDAT

IMPORTING

WEEK = zitab-zcalweek

EXCEPTIONS

DATE_INVALID = 1

OTHERS = 2.

  • set class

zitab-ZKUNNR = ZKNA1-KUNNR.

  • set total passengers

zitab-ZREGIO = ZKNA1-REGIO.

  • accumulate revenue

zitab-ZFAKSD = ZKNA1-FAKSD.

  • look up the matching KNB1 record to get expected revenue

READ TABLE ZKNB1 WITH KEY KUNNR = ZKNA1-KUNNR

ERDAT = zKNA1-ERDAT.

IF sy-subrc = 0.

zitab-ZZTERM = ZKNB1-ZTERM.

ELSE.

zitab-ZZTERM = 'NULL'.

ENDIF.

  • set currency key

zitab-ZAKONT = ZKNB1-AKONT.

*

    • accumulate baggage weight

  • zitab-ztotbagwt = zKNA1-luggweight.

*

    • set baggage weight unit

  • zitab-zwtunit = zKNA1-wunit.

*

    • this will accumulate key figures that have the same characteristics

  • COLLECT zitab.

ENDLOOP.

"End of Step (G)

  • finally, write the accumulated, summarized records to the database

INSERT ZBW_SFLI001_DS FROM TABLE zitab. "Step (H)

  • open a database cursor to gather the data from the database

  • table and pass it back to BW. Here the S_S_IF-T_FIELDS

  • internal table (copied from the I_T_FIELDS internal table

  • passed to this function module by BW) is used to make sure we

  • only get the fields that BW actually needs.

OPEN CURSOR WITH HOLD s_cursor FOR "Step (I)

SELECT (S_S_IF-T_FIELDS) FROM ZBW_SFLI001_DS

WHERE zrequnr = s_s_if-requnr.

ENDIF. "First data package ?

  • This code actually returns a packet of data to BW. It gets the

  • next packet of data from our database table (using the cursor)

  • and puts the data into the E_T_DATA internal table. This

  • internal table is then handed back to BW as a packet of data.

FETCH NEXT CURSOR s_cursor "Step (J)

APPENDING CORRESPONDING FIELDS

OF TABLE E_T_DATA

PACKAGE SIZE S_S_IF-MAXSIZE.

  • If there is no more data, close the cursor, remove the data

  • from the ZBW_SFLI001_DS table (since we don't need it anymore)

  • and signal BW that there is no more data.

IF SY-SUBRC <> 0. "Step (K)

CLOSE CURSOR S_CURSOR. "Step (L)

DELETE FROM zbw_sfli001_ds "Step (M)

WHERE zrequnr = s_s_if-requnr.

RAISE NO_MORE_DATA. "Step (N)

ENDIF.

  • accumulate our packet counter

s_counter_datapakid = s_counter_datapakid + 1. "Step (O)

4 REPLIES 4
Read only

Former Member
0 Likes
828

Hi Soniya,

Can you tell what is SRSC_S_IF_SIMPLE. As I looked into SE11 but not able to find this. So you may need to define this.

Regards,

Atish

Read only

Former Member
0 Likes
828

Hi Soniya,

<b>The types and constants specified in a type group have global validity, you cannot use the statement within a FORM or FUNCTION. </b>

So declare your import parameters using standard Data Elements present in SAP like <b>RSREQUNR</b> for <b>ROOSOURCER</b>

<b>ROOSOURCER</b> for <b>I_DSOURCE</b>

.

.

like wise.

Hope this solves your problem.

Regards,

Amit

*Always reward points for helpful answers

Read only

0 Likes
828

Can u please help me edit my code as i am not able to get what is that you want me to change on the code

thanks

soniya

Read only

0 Likes
828

HI Soniya,

Change the declaration of your import parameters and tables declaration.

Instead of declaring them as

I_REQUNR TYPE SRSC_S_IF_SIMPLE-REQUNR

I_DSOURCE TYPE SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL

I_MAXSIZE TYPE SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL

I_INITFLAG TYPE SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL

I_READ_ONLY TYPE SRSC_S_IF_SIMPLE-READONLY OPTIONAL

I_T_SELECT TYPE SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL

I_T_FIELDS TYPE SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL

use standard data element and structures to declare them as

I_REQUNR TYPE RSREQUNR

I_DSOURCE TYPE ROOSOURCER

I_MAXSIZE TYPE RSMAXSIZE

I_INITFLAG TYPE RSINITFLG

I_READ_ONLY TYPE C

I_T_SELECT LIKE RSSELECT

I_T_FIELDS LIKE RSFIELDSEL

This should solve the problem.

Regards,

Amit

*Always reward points for helpful answers