Buy

Buy

List of Posts

Get this widget
To get notifications, Please like our Facebook Page >>>>>>

Use Search box to find a topic in this Blog!!!

Step by Step Guide to Create a Generic Datasource Based on Infoset Query Populated Via External Program


Introduction

A Generic datasource is created when no standard business content datasource is available that meets client’s reporting requirements. There are three main methods for generic extraction, namely

 Table or View

 Function Module

 Infoset Query

This document is focused on creation of generic datasource using Infoset Query populated via External Program. 

Comparison - Infoset Query via External Program vs Function Module based Generic Extraction

 Function Module based generic extraction is pretty much rigid in terms of ABAP coding in different sections. On the other hand, Infoset Query via External Program is much more flexible and easier to code.

One needs to understand statements like OPEN CURSOR, CLOSE CURSOR, FETCH NEXT, RANGES etc to build a function module based generic extractor. Infoset Query via External program can be created using local structures, internal tables and key statements *<QUERY_HEAD> and *<QUERY_BODY>

Scenario 

To demonstrate steps for creation of generic datasource using Infoset Query via External Program, we would be combining data from tables A017 (Material Info Record (Plant-Specific)) and KONP (Conditions (Item)) based on field KNUMH (Condition Record Number).


Step By Step Procedure

1. Create a structure ZPU_A017KONP via SE11 transcation. Include all fields from table A017. Include fields KBETR KONWA KPEIN KMEIN from table KONP. Activate the structure.

Goto SE11 transaction. Enter technical name of the structure ZPU_A017KONP in ‘Data Type’ field. Click Create.

 
Select ‘Structure’ and enter.

 

Enter description for structure. Include required fields from A017 and KONP table.

 

In ‘Currency/Quantity fields’ tab, enter the reference table ZPU_A017KONP (Structure name) and reference field KONWA for currency field KBETR. Save and Activate the structure. Ignore warnings (if any).

 

2. Create external program ZINFO_A017 to populate structure ZPU_A017KONP via SE38 transaction.
Goto SE38 transaction. Create program ZINFO_A017. Click ‘Create’.

 

Enter required fields as per screen below and press enter. Select appropriate package or ‘Local Object’.

 

Type the following custom code to populate the structure ZPU_A017KONP. Activate the program.

data:
ZPU_A017KONP type ZPU_A017KONP,
it_data type standard table of ZPU_A017KONP.
field-symbols: <struc> type ZPU_A017KONP.

TYPES : Begin of fs1,
KAPPL type A017-KAPPL,
KSCHL type A017-KSCHL,
LIFNR type A017-LIFNR,
MATNR type A017-MATNR,
EKORG type A017-EKORG,
WERKS type A017-WERKS,
ESOKZ type A017-ESOKZ,
DATBI type A017-DATBI,
DATAB type A017-DATAB,
KNUMH TYPE A017-KNUMH,
end of fs1.
types : begin of fs2,
KBETR TYPE KONP-KBETR,
KONWA TYPE KONP-KONWA,
* PEINH TYPE KONP-PEINH,
KNUMH TYPE A017-KNUMH,
KPEIN TYPE KONP-KPEIN,
KMEIN TYPE KONP-KMEIN,
end of fs2.
types : begin of fs3,
ESOKZ type A017-ESOKZ,
MATNR type A017-MATNR,
WERKS type A017-WERKS,
EKORG type A017-EKORG,
LIFNR type A017-LIFNR,
KSCHL type A017-KSCHL,
DATBI type A017-DATBI,
DATAB type A017-DATAB,
KNUMH TYPE A017-KNUMH,
KBETR TYPE KONP-KBETR,
KONWA TYPE KONP-KONWA,
KPEIN TYPE KONP-KPEIN,
KMEIN TYPE KONP-KMEIN,
end of fs3.
DATA : it1 type table of fs1,
wa1 like line of it1,
it2 type table of fs2,
wa2 like line of it2,
it3 type table of fs3,
wa3 like line of it_data.
*-------------------------------------------------------------------*
* selection screen statements
*-------------------------------------------------------------------*
* (define your selection-screen here)
* !! the following comment MUST NOT BE CHANGED !!
*<QUERY_HEAD>
*-------------------------------------------------------------------*
* read data into IT_DATA

*-------------------------------------------------------------------*
* (select your data here into internal table IT_DATA)
*------------------------------------------------------------*
* output of the data
* (this section can be left unchanged)
*------------------------------------------------------------*
select kappl kschl lifnr matnr ekorg werks esokz datbi datab
knumh
from A017 into table it1 where kappl = 'M'.
select KBETR KONWA KNUMH KPEIN KMEIN from KONP into table it2 for all
entries in it1
where knumh = it1-knumh.
loop at it1 into wa1.
clear : wa3, wa2.
move-corresponding wa1 to wa3.
read table it2 into wa2 with key knumh = wa1-knumh.
if sy-subrc eq 0.
move-corresponding wa2 to wa3.
endif.
append wa3 to it_data.
endloop.
loop at it_data assigning <struc>.
move-corresponding <struc> to ZPU_A017KONP.
* !! the following comment MUST NOT BE CHANGED !!
*<QUERY_BODY>
endloop.

Important Points while writing custom program for Infoset Query.

a) *<QUERY_HEAD> and *<QUERY_BODY> are key statements (even though they are commented).
b) Make all necessary declarations of structures, work areas, internal tables, field symbols before statement *<QUERY_HEAD>.
c) Do all necessary selects and logic for populating internal table between statements *<QUERY_HEAD> and *<QUERY_BODY>.
d) The last statement after *<QUERY_BODY> should be endloop (for populating the final structure).
e) Create a workarea with the same name as final structure (ZPU_A017KONP in this case).
The structure of this model report and the sequence of its parts are regular. The main structure of a model report is given below.



3. Create Infoset ZINFOSET_KONP in Global Area using SQ02 transaction using structure ZPU_A017KONP and program ZINFO_A017. 



 

Enter technical name of Infoset as ZINFOSET_KONP. Click Create.

 


Enter description for Infoset. Select option ‘Data retrieval by program’. Enter structure for Infoset (ZPU_A017KONP) and External Program (ZINFO_A017). Check ‘No automatic text recognition’ (to ignore text fields). Press enter.

 

4. Save and Generate Infoset.

 

5. Create generic datasource ZDS_A017KONP using RSO2 transaction.
Goto transaction RSO2. Enter technical name of datasource as ZDS_A017KONP. Click Create.

 
Select ‘Extraction from Query’ and fill the required description. Click Save.

 

Select ‘Selection Fields’ and Save.

 

6. Test datasource extraction via RSA3 transaction.

 

Verify the results.