Skip to Content

Pic 41This 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 1Picture 1
Picture 1

We give our WebService a name like “ZDOCUMENT_FLAT” and a description like “My flat Document”.



Picture 2

Picture 2

Define the description…
Pic 3

Picture 3

Go to the tab “Extraction” and define the name of the service. I call it “FLATDOCUMENT”.

Pic 4Picture 4

Got to tab “Fields” and define the flat structure.

Pic 5
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’.

Pic 6
Picture 6

The segment (.INCLUDE) has the following structure.
BL707
Pic 7
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…

Pic 8
Picture 8

Define the new name … (in this case ZZDOCUMENT)

Pic 9
Pic 9
Picture 9

Choose the fields and save / activate the new structure.
Pic 10
Picture 10

Create Segment 2 (‘ZZDOCITEM’) from the component type ‘/BIC/CQZDOCUME000010000001’
 in transaction SE11. Choose the fields and safe / activate the structure …

Pic 11
Picture 11

Create Segment 3 (‘ZZZMATERIAL’) from the component type ‘/BIC/CQZDOCUME000010000001’
 in transaction SE11. Choose copy…

Pic 12
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 …

Pic 13
Picture 13

Choose ‘Table type …’

Pic 14
Picture 14

The line type is the corresponding structure like ‘ZZDOCITEM’ for the first table type ‘ZZDOCITEMT’.

Pic 15
Picture 15

The line type is the corresponding structure like ‘ZZMATERIAL’ for the second table type ‘ZZMATERIALT’.

Pic 16
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.

Pic 17
Pic 17
Picture 17

We add the item with table type ‘ZZDOCITEMT’.

Pic 18
Picture 18

Activate and save

Now we enhance the ITEM structure ‘ZZDOCITEM’ with the table type ‘ZZMATERIALT’.

Pic 19
Picture 19

Choose change …

Pic 20
Picture 20

Activate and save

Now we have got the full defined data structure of one document. (‘ZZDOCUMENT’)

Pic 21
Picture 21

Now we create a table type ‘ZZDOCUMENTT’ out of this structure ‘ZZDOCUMENT’.

Pic 22
Picture 22

Choose create …

and the Type “Table type … ‘

BL723
Pic 23
Picture 23

Add the structure name ‘ZZDOCUMENT’.

Pic 24
Picture 24

Done, the table type is created ‘ZZDOCUMENTT” and can be used as inport parameter for the Web Service.

Pic 25
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’.

Pic 26
Picture 26

The function module input parameter type is still the generated structure.
Pic 27
Picture 27

I remove the existing coding and exchange the import parameter type to ‘ZZDOCUMENTT’.

BL728
Pic 28
Pic 28
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.

Pic 29
Picture 29

Go to Menu: Utilities –> More Utilities –> Create a WebService –> From the Function Module.

BL730
Pic 30
Picture 30

The Wizard starts.

BL731
Pic 31
Picture 31

Click Continue

Define the name for the Service. We call it in our example ‘zzdeepdocument’.
The descripiton is ‘Deep Structured Web Service’.

Pic 32
Picture 32

Click Continue

Choose the End point (this is the functionmodule)

Pic 33
Picture 33

Click Continue

Configure the Serivice… choose ‘Release Service for Runtime’….

Pic 34
Picture 34

Click Continue

Choose Complete on the last screen in the Wizard.

Pic 35
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’.

Pic 36
Picture 36

Start the Web Serivice:

Pic 37
Picture 37

Choose Continue

Pic 38
Picture 38

Choose Test

BL739
Pic 39
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

Pic 40
Picture 40

The response is OK.

Pic 41
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.

Pic 42
Picture 42

Thanks a lot for going through this…

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply