Skip to Content
Author's profile photo Shahid Imam Shaik

Generic Datasource with Functional module

Generic Datasource with Function module:

Whenever the given SAP solutions like Views and Infoset queries are not able to fulfil the requirement, then we need to replace it with custom program. We can do it with the help of creating Functional module.

Function modules are created in the transaction SE37. They need to be assigned to a group; You need to create a function group in SE80.

Steps to create a custom Datasource:

  1. Create Function group. Go to SE80, and create Function group to assign FM, as shown in the figure below.

GF1.png

2. Create a structure called ZSTRUCT. Go to SE11 and select data type radio button.

Give fields from the table SPFLI, these fields are:

CARRID, CONNID, COUNTRYFR, CITYFROM

AIRPFROM, COUNTRYTO, CITYTO, AIRPTO

GF2.png

3. Create a table type, Go to SE11 and select the data type radio button. Now select the table type and create. Give the name of the structure and activate.

GF3.png

4. In SE37, enter the Function module

      RSAX_BIW_GET_DATA

Then, click copy button, and give to function module

Former Function module: RSAX_BIW_GET_DATA

To Function module     : ZRSAX_BIW_GET_DATA

Function Group: ZFM_1

GF4.png

Now, click on copy.

Now open the function module you created. Give the name in SE37, then click on change button.

Go to source code, select everything and delete it as shown in the figure.

GF5.png

All the other tabs like Import, export, tables, exceptions will remain as we copied.

5. Click GOTO in the menu –> main program –> double-click on the top include.

Now add

TYPE-POOLS SBIWA. As shown in the figure below.

GF6.png

Now, activate it.

6. In function module, there is a tables tab.  In tables tab, there are two internal tables *E_T_DATA* and *E_T_SOURCE_STRUCTURE*.

These two tables are important for the extract structure. So, it is important to declare these two tables as our structure as shown below.

GF7.png

7. As we have deleted the source code to write our code, we wrote our code as shown in the figure below.

GF9.png

The code we have written is:

FUNCTION ZRSAX_BIW_GET_DATA.

STATICS C1 TYPE CURSOR.

RANGES R_CARRID FOR SPFLI_CARRID.

RANGES R_CONNID FOR SPFLI_CONNID.

IF I_INITFLAG = SPACE.

IF C1 IS INITIAL.

READ TABLE I_T_SELECT WITH KEY FIELDNM = *CARRID*.

IF SY-SUBRC = 0.

MOVE-CORRESPONDING I_T_SELECT TO R_CARRID.

APPEND R_CARRID.

ENDIF.

READ TABLE I_T_SELECT WITH KEY FIELDNM = *CONNID*.

IF SY-SUBRC = 0.

MOVE-CORRESPONDING I_T_SELECT TO R_CONNID.

APPEND R_CONNID.

ENDIF.

OPEN CURSOR WITH HOLD C1 FOR

SELECT CARRID

    CONNID

    CITYFROM

    CITYTO

FROM SPFLI

    WHERE CARRID IN R_CARRID AND CONNID IN R_CONNID.

ENDIF.

FETCH NEXT CURSOR C1 INTO

CORRESPONDING FIELDS OF TABLE E_T_DATA

PACKAGE SIZE I_MAXSIZE.

IF SY-SUBRC <> 0.

CLOSE CURSOR C1.

RAISE NO_MORE_DATA.

ENDIF.

ENDIF.

ENDFUNCTION.

After writing the code, given above, save and activate the function module.

8. Now, GO TO  RSO2, and create a Generic datasource, *ZFM_DS*, as given below.

GF10.png

As you can see above, function module and the extract structure is given. Save your Datasource, and give selections.

9. Now, go to RSA3 to check the data in the Datasource, as shown below.

GF11.png

As you can see above, we have 26 data records available in this DS. Now, create the BI dataflow to extract this data.

Steps in BI side:

*

10. Replicate the DS in BI side:

Now, Go to RSOSFIELDMAP, and search for the infoobjects for your fields.

Create SDSO

Create Transofrmation and DTP using source as ZTEST_DS, datasouece, and target as SDSO.

Create the Infocube.

Create Transformation and DTP using source as ZTEST_DS DS, and target as Infocube.

Create a Infopackage, and load the data to DS.

Execute the DTP and load the data to the Infoobject.

Please visit my website for more Bi posts and information.

http://www.shaikshahidimam.com/

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Suman Chakravarthy K
      Suman Chakravarthy K

      Hi Shahid,

      One observation from my side. Your doc is good, but it is a standard one. It would be great if you can share any of your tough scenarios, which will be more interesting for us. I saw your website and could not see any BI posts there.

      Regards,

      Suman

      Author's profile photo Shahid Imam Shaik
      Shahid Imam Shaik
      Blog Post Author

      Hi Suman, thanks for checking my document. I wanted to post the procedure of the functional module, for the beginners, not for the experts.

      Please select the dropdown of categories on my website, and select SAP BI. I have been posting there. Anybody who want's to watch the videos, can get the links to my youtube there as well.

      I hope my document will be helpful...

      Best regards,

      Shahid.