Object-specific IDoc handlers that support the Retrieve verb do not receive business object data from the initial IDoc handler. Y_XR_IDOC_HANDLER passes the value of the first attribute marked isKey in the business object data using the parameter OBJECT_KEY_IN. It is the IDoc handlers responsibility to use this key to retrieve all information relevant to this instance of the object using ABAP SQL and format that data in the appropriate IDoc structure.
The following code supports the Sales Quote example. The Sales Quote object must retrieve data from tables VBAK, VBUK, VBPO, VBAP, VBUP, VBKD, KNOV, and VBPA. The tables follow the hierarchy and cardinality of IDoc type ZSLSQUOT. The code does the following:
The code for IDoc type ZSLSQUOT is:
*- Clear the interface structures. clear: g_text, object_key_out, return_code, return_text, idoc_data. refresh: idoc_data. * If no key value is specified, log it as an error and exit. if object_key_in is initial or object_key_in = c_cxignore_const. perform log_update(saplyxr1) using c_error_log text-e02 space space space. return_code = 1. return_text = text-e02. exit. endif. perform initialize_global_structures. perform fill_internal_tables. if not return_code is initial. exit. endif. * Build Idoc segments from internal tables perform fill_idoc_inttab. return_code = 0. return_text = text-s01. perform log_update(saplyxr1) using c_information_log text-s01 space space space. endfunction.
The two most important parameters are OBJECT_KEY_IN for the inbound key and IDOC_DATA for the outbound data. Note that OBJECT_KEY_IN may even be a multiple key depending on the conventions you have defined.
The VBAK table drives the selection criteria for the child tables, so each table is loaded into working tables. Using the VBAK table, you can retrieve the child tables with additional keys. So, for the Sales Quote example, the code is as follows:
form fill_internal_tables. * Get information from VBAK, VBUK, VBAP, VBKD, KONV, VBPA select single * from vbak where vbeln = object_key_in. if sy-subrc <> 0. perform log_update(saplyxr1) using c_error_log text-e01 object_key_out c_blank c_blank. return_code = '1'. g_text = text-e01. replace '&' with order_number into g_text. return_text = g_text. exit. endif. select single * from vbuk where vbeln = vbak-vbeln. select * from vbap into table t_vbap where vbeln = vbak-vbeln. * Continue for other tables
The following code is used to copy the requested data from the application database into internal tables and working variables. Then it creates segments that directly correspond to the WebSphere business object definition and puts it into the SAP segment structure.
In some cases for close matches on fields between the IDoc type and the working structure, you can do an ABAP move-corresponding command. In other cases, it is more preferable to do manual moves from the working table to the IDoc type table because of the relatively few fields to move in comparison to the overall number of fields in the structure. Simply, it is used to transfer data from the working data structures into the IDoc structures and then in the flat data field.
The code is:
form fill_idoc_inttab. perform fill_zsqvbak." Fill the Sales Quote Header perform fill_zsqvbuk." Fill the Sales Quote Status perform fill_zsqvbap." Fill Sales Quote Lines endform." FILL_IDOC_INTTAB *-- fill the Sales Quote Header form fill_zsqvbak. clear idoc_data. clear zsqvbak. idoc_data-segnam = 'ZSQVBAK'. move-corresponding vbak to zsqvbak. move zsqvbak to idoc_data-sdata. append idoc_data. endform." FILL_ZSQVBAK *-- fill the Sales Quote Header Status form fill_zsqvbuk. clear idoc_data. clear zsqvbuk. idoc_data-segnam = 'ZSQVBUK'. move-corresponding vbuk to zsqvbuk. move zsqvbuk to idoc_data-sdata. append idoc_data. endform." FILL_ZSQVBAK *-- fill the Sales Quote Line and the Line Child segments form fill_zsqvbap. loop at t_vbap. clear idoc_data. clear zsqvbap. idoc_data-segnam = 'ZSQVBAP'. move-corresponding t_vbap to zsqvbap. move zsqvbap to idoc_data-sdata. append idoc_data. perform fill_zsqvba2. perform fill_zsqvbup. perform fill_zsqvbkd. perform fill_zsqkonv. perform fill_zsqvbpa. endloop. endform. *-- fill second part of vbap form fill_zsqvba2. " etc.