This blog will explain an example how to create a Web Service by using a deep input structure. The reason I provide this information is that the normal WebService DataSource in BI does not support deep structures. So, if your source application provides a XML file like:
Document number
Document date
Document item 1 (1:n)
Material
Language (1:n)
Text
....
Customer
Amount
Currency
....
There are 3 options going around this:
1. Modify the XML file externally to a flat structure.
2. Use XI as an intermediate stage.
3. Create a WebService in BI that can handle deep structures as intermediate stage
The first one must be handled by the sender application. The second one is described in the How to Guide "How to send XML data to BI". The link can be found in the blog:
SAP NetWeaver 7.0 BI: How to send XML data to BI - enhancement
The third option is described below.
So, we use the sample XML I have show above. Our external application sends a XML file with a number of documents that includes X number of items. The language dependent text of the material used in the item is delivered as well.
We know that the BI Web Service can not handle deep structures like this. What we do is, we create a Web Service flatten the input structure and send it to the generated BI Web Service (Function Module).
How do we create a Web Service that can handle a deep structures?
Step 1 Create a deep structure:
Create the flatten Web Service DataSource.
Go to the WebService Source System and click Create DataSource ...![]()

Picture 1
We give our WebService a name like "ZDOCUMENT_FLAT" and a description like "My flat Document".![]()
![]()
![]()

![]()
Picture 2
Define the description...
![]()
Picture 3
Go to the tab "Extraction" and define the name of the service. I call it "FLATDOCUMENT".
Picture 4
Got to tab "Fields" and define the flat structure.
Picture 5
Activate the DataSource. The Web Service and the Function Module is generated. I have defined the keys of the DataSource as well. (DOCNUMBER, DOC_ITEMS, LANGU). This is not a must.
The name of the Function module is '/BIC/CFFLATDOCUMENT' and the Web Service '/BIC/CFFLATDOCUMENT'.
based on Function module we create the intermediate Service to flatten the data.
By bouble Click on the Function module name we junp into the Function Module maintenance, (Transaction SE37).
The type of the importing paramter is in this case '/BIC/WCQZDOCUME00001000'. The import parameter is a flat structure. The flat structure consist of a includes (the component type ) '/BIC/CQZDOCUME000010000001'.
Picture 6
The segment (.INCLUDE) has the following structure.
BL707
Picture 7
We use this segment to create a deep structure.
The name of the deep structure will be in our example 'ZZMYDEEPSTRUC', but first
we go to transaction SE11 and create 3 structures
1. Document (ZZDOCUMENT)
2. Document item (ZZDOCITEM)
3, Material text (ZZMATERIAL)
Create Segment 1 ('ZZDOCUMENT') from the component type '/BIC/CQZDOCUME000010000001'
in transaction SE11. Choose copy...
Picture 8
Define the new name ... (in this case ZZDOCUMENT)
![]()
Picture 9
Choose the fields and save / activate the new structure.
Picture 10
Create Segment 2 ('ZZDOCITEM') from the component type '/BIC/CQZDOCUME000010000001'
in transaction SE11. Choose the fields and safe / activate the structure ...
Picture 11
Create Segment 3 ('ZZZMATERIAL') from the component type '/BIC/CQZDOCUME000010000001'
in transaction SE11. Choose copy...
Picture 12
Since the the Document item and the Material text are 1:n relations to the main segment Document we need to create 2 table types based on the structures (segments) 2 and 3 we already created.
1. Document item (ZZDOCITEMT)
2, Material text (ZZMATERIALT)
Go to transcation SE11 and create the data table types . Choose Create ...
Picture 13
Choose 'Table type ...'
Picture 14
The line type is the corresponding structure like 'ZZDOCITEM' for the first table type 'ZZDOCITEMT'.
Picture 15
The line type is the corresponding structure like 'ZZMATERIAL' for the second table type 'ZZMATERIALT'.
Picture 16
Tip: We do not need to craete a table type for the document 'ZZDOCUMENT'.
Now we have got all data types to create the deep data structure ''ZZDOCUMENT''.
Go to transaction SE11 and change the 'ZZDOCUMENT' structure.
![]()
Picture 17
We add the item with table type 'ZZDOCITEMT'.
Picture 18
Activate and save
Now we enhance the ITEM structure 'ZZDOCITEM' with the table type 'ZZMATERIALT'.
Picture 19
Choose change ...
Picture 20
Activate and save
Now we have got the full defined data structure of one document. ('ZZDOCUMENT')
Picture 21
Now we create a table type 'ZZDOCUMENTT' out of this structure 'ZZDOCUMENT'.
Picture 22
Choose create ...
and the Type "Table type ... '
BL723
Picture 23
Add the structure name 'ZZDOCUMENT'.
Picture 24
Done, the table type is created 'ZZDOCUMENTT'' and can be used as inport parameter for the Web Service.
Picture 25
Now we create the function module using this type 'ZZDOCUMENTT' as the Import data type. Doing this I copy the generated Function Module '/BIC/CFFLATDOCUMENT'.
Picture 26
The function module input parameter type is still the generated structure.
Picture 27
I remove the existing coding and exchange the import parameter type to 'ZZDOCUMENTT'.
BL728![]()

Picture 28
Step 2 Create the coding to map the deep to the flat structure.
The deep structure is 'ZZDOCUMENTT' and the flat structure is in this case 'BIC/WCQZDOCUME00001000'. By the way we are working to fix the DDIC structure for the WebService as well.
After we have flatten the data, we call the generated Function module '/BIC/CFFLATDOCUMENT'.
The coding of the function module is as follow.
FUNCTION ZZDEEPDOCUMENT.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(DATA) TYPE ZZDOCUMENTT
*" EXCEPTIONS
*" INTERNAL_ERROR
*"----------------------------------------------------------------------
data: e_data type /BIC/WCQZDOCUME00001000,
item type ZZDOCITEM,
mattext type ZZMATERIAL,
document type ZZDOCUMENT,
e_s_data type /BIC/CQZDOCUME00001000.
* Flat the structure
loop at data into document.
loop at document-item into item.
loop at item-mattext into mattext.
move-corresponding document to e_s_data.
move-corresponding item to e_s_data.
move-corresponding mattext to e_s_data.
append e_s_data to e_data.
endloop.
endloop.
endloop.
* call Function Module from WebService interface
CALL FUNCTION '/BIC/CFFLATDOCUMENT'
EXPORTING
DATA = e_data
EXCEPTIONS
INTERNAL_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFUNCTION.
Step 3 Create the Web Service.
Go to transaction SE37 --> display the Function Module 'ZZDEEPDOCUMENT' thet we have created in step 2.

Picture 29
Go to Menu: Utilities --> More Utilities --> Create a WebService --> From the Function Module.
BL730
Picture 30
The Wizard starts.
BL731
Picture 31
Click Continue
Define the name for the Service. We call it in our example 'zzdeepdocument'.
The descripiton is 'Deep Structured Web Service'.
Picture 32
Click Continue
Choose the End point (this is the functionmodule)
Picture 33
Click Continue
Configure the Serivice... choose 'Release Service for Runtime'....
Picture 34
Click Continue
Choose Complete on the last screen in the Wizard.
Picture 35
.... the system generates the WebService and can be tested.,,,
Step 4 Test Web Service
Go to transaction WSADMIN
Select the WebService we created in Step 3. In this case it is 'ZZDEEPDOCUMENT'.
Picture 36
Start the Web Serivice:
Picture 37
Choose Continue
Picture 38
Choose Test
BL739
Picture 39
Select the WebService
Now you are able to enter a test document
Choose Test to send the document to the DataSource ... through the created WebServices
Picture 40
The response is OK.
Picture 41
As the result, we can see that the data has been flatten and send to the DataSoruce (PSA) 'ZDOCUMENT_FLAT'. Record 3 and 4 are the once that have been created.
Picture 42
Thanks a lot for going through this...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 524 | |
| 263 | |
| 238 | |
| 234 | |
| 167 | |
| 157 | |
| 152 |