Functions for Data Transformation
RSAU_READ_MASTER_DATA
Very often you need to read a characteristic's attribute during a data transformation process, e.g. in an update rule. Rather than accessing the characteristic's attribute table (e.g. the view /BI0/MMATERIAL) directly with a SELECT statement, it is better to use the function module RSAU_READ_MASTER_DATA. It has been designed exactly for this scope. Taking advantage of it, you can avoid writing explicit data access code in the Data Transformation Layer routines.
Here are four examples which illustrate how to use this function in four different scanarios.
Read a single attribute value for a single characteristic value
You need to get the value of an attribute (e.g. 0SOLD_TO) corresponding to a characteristic value (e.g. 0SOLD_TO = 'CUST_CODE'). In this case you need to export to the function the name of the involved characteristic (parameter I_IOBJNM), its value (parameter I_CHAVL), and the name of the attribute (parameter I_ATTRNM). Notice that the parameter I_CHAVL expects a RSGENERAL-CHAVL data format. The function returns the attribute value in the parameter E_ATTRVAL.
DATA: CUST_CLASS, SOLD_TO LIKE RSGENERAL-CHAVL. SOLD_TO = DATA_PACKAGE-SOLD_TO. " in an update rule, for instance CALL FUNCTION 'RSAU_READ_MASTER_DATA' EXPORTING I_IOBJNM = '0SOLD_TO' I_CHAVL = SOLD_TO * I_T_CHAVL = * I_DATE = * I_FLG_WHOLE_TABLE = I_ATTRNM = '0CUST_CLASS' IMPORTING * E_STRUCTURE = * E_TABLE = E_ATTRVAL = CUST_CLASS EXCEPTIONS READ_ERROR = 1 NO_SUCH_ATTRIBUTE = 2 WRONG_IMPORT_PARAMETERS = 3 CHAVL_NOT_FOUND = 4 OTHERS = 5 .
Notice that even for a custom attribute, the simple attribute name needs to be exported (e.g. ZATTR), and not the field name as it appears in the attribute table (e.g. /BIC/ZATTR). Remember also that the name of both the characteristic and the attribute must be upper case (i.e. is case sensitive). Lastly, the import parameter I_DATE may be used to specify the key date when a time-dependent characteristic is involved. The output attribute value will fulfil the temporal condition that the key date is in the validity time interval of the characteristic.
Read all attributes of a single characteristic value
You need to get the value of several (or all) attributes for a given characteristic value (e.g. 0MATERIAL = 'MAT_CODE'). Again, you need to export the name of the involved characteristic (parameter I_IOBJNM) and its value (parameter I_CHAVL). The attribute names are not needed, since all the attributes will be fetched. In fact their value will be returned in the E_STRUCTURE structure. This structure has to have the same structure of the attribute view of the involved charateristic (e.g. /BI0/MMATERIAL). Notice that you have to use the M-view structure and not the P-table structure, as only the former is valid when time-dependent attributes are defined for the characteristic.
DATA: MATERIAL LIKE RSGENERAL-CHAVL, WA_MATERIAL LIKE /BI0/MMATERIAL, MATERIAL = DATA_PACKAGE-MATERIAL. " in an update, rule for instance CALL FUNCTION 'RSAU_READ_MASTER_DATA' EXPORTING I_IOBJNM = '0MATERIAL' I_CHAVL = MATERIAL * I_T_CHAVL = * I_DATE = * I_FLG_WHOLE_TABLE = * I_ATTRNM = IMPORTING E_STRUCTURE = WA_MATERIAL * E_TABLE = * E_ATTRVAL = EXCEPTIONS READ_ERROR = 1 NO_SUCH_ATTRIBUTE = 2 WRONG_IMPORT_PARAMETERS = 3 CHAVL_NOT_FOUND = 4 OTHERS = 5 .
Read all attributes for many characteristic values
You need to read the attributes of a set of values of a characteristic (e.g. 0SALESORG). You need to fill an internal table of type rsd_t_chavl with the characteristic values and pass them with the I_T_CHAVL import parameter. The attribute values for the characteristic values passed in I_T_CHAVL are returned in the E_TABLE table. As in the point above, this table has to have the same structure as the attribute view of the involved charateristic (e.g. /BI0/MMATERIAL).
DATA: WA_MATERIAL TYPE RSD_CHAVL, LT_MATERIAL_VALUES LIKE RSD_T_CHAVL, LT_MATERIAL_ATTRIBUTES TYPE STANDARD TABLE OF /BI0/MMATERIAL. LOOP AT DATA_PACKAGE. LT_MATERIAL_VALUES = DATA_PACKAGE-MATERIAL. ENDLOOP. CALL FUNCTION 'RSAU_READ_MASTER_DATA' EXPORTING I_IOBJNM = '0MATERIAL' * I_CHAVL = I_T_CHAVL = LT_MATERIAL_VALUES * I_DATE = * I_FLG_WHOLE_TABLE = * I_ATTRNM = IMPORTING * E_STRUCTURE = E_TABLE = LT_MATERIAL_ATTRIBUTES * E_ATTRVAL = EXCEPTIONS READ_ERROR = 1 NO_SUCH_ATTRIBUTE = 2 WRONG_IMPORT_PARAMETERS = 3 CHAVL_NOT_FOUND = 4 OTHERS = 5 .
Read all attribute for all the characteristic values
You need to read all the values of a characteristic (e.g. 0SALESORG). Since you are interested in all the values, you do not input a characteristic value, but just the characteristic name (parameter I_IOBJNM). To actually fetch the values, you need to set the boolean parameter I_FLG_WHOLE_TABLE. All the contents of the attribute view are pushed into an internal table, which has to have its same structure.
DATA: ITAB_SALESORG LIKE TABLE OF /BI0/MSALESORG. CALL FUNCTION 'RSAU_READ_MASTER_DATA' EXPORTING I_IOBJNM = '0SALESORG' I_CHAVL = I_T_CHAVL = I_DATE = I_FLG_WHOLE_TABLE = 'X' I_ATTRNM = IMPORTING E_STRUCTURE = E_TABLE = ITAB_SALESORG\[\] E_ATTRVAL = EXCEPTIONS READ_ERROR = 1 NO_SUCH_ATTRIBUTE = 2 WRONG_IMPORT_PARAMETERS = 3 CHAVL_NOT_FOUND = 4 OTHERS = 5 .
RSNDI_SHIE_STRUCTURE_GET
Similarly to the above cases, it is often advisable not to access the hierarchy tables directly to get hierarchy data. You can use the function module RSNDI_SHIE_STRUCTURE_GET instead. You pass the internal hierarchy ID in the input parameter I_S_HIEKEY. The internal hierarchy ID identifies the hierarchy uniquely. You can get this ID opening the detail window from the hierarchy maintenace screen:
The return code of the function call is passed back in the E_SUBRC parameter. The contents of the hierarchy table (e.g. /BI0/HMATERIAL) are returned in an internal table with structure RSHIERSTRUCT (parameter E_T_HIERSTRUCT). Optional output messages are put in an internal table with structure RSNDI_S_MESSAGE (parameter E_T_MESSAGE).
data: i_s_hiekey type rsndi_s_hiekey, e_subrc like sy-subrc, itab_hierstruc like rshierstruc occurs 100 with header line, e_t_message like rsndi_s_message. i_s_hiekey = '4QHTHQKJDTCKVXT63NOICJ9LX'. call function 'RSNDI_SHIE_STRUCTURE_GET' exporting i_s_hiekey = i_s_hiekey * I_S_HIESEL = * I_NO_NODENM_TABLE = RS_C_FALSE importing * E_S_HIEDIR = e_subrc = e_subrc tables * E_T_HIEDIRT = e_t_hierstruc = itab_hierstruc * E_T_MHIERNODE = * E_T_THIERNODE = * E_T_HIERINTVL = * E_T_NODENAMES = e_t_message = e_t_message .
The GUID or the hierarchy ID for the hierarchy given can be found from the table RSHIEDIR which has the hierarchy header information.
Since BW 3.x the similar function module RSNDI_SHIE_STRUCTURE_GET3 is defined as well, which has a more flexible interface.
5 Comments
Unknown User (99crb0s3)
Hi Davide,
Very Good information & Very helpful. It saved me lot of my time today. Bring more of BW ABAP stuff.
Cheers
POPS
Unknown User (98bkqq5t)
Hello David, very useful information.
Is there any FM to read master data which is time dependent. Eg: 0EMPLOYEE, 0HRPOSITION.
Anonymous
Hi there,
I have added a short hint regarding time dependant attributes. Do you feel free to add more details and post an example as soon as you will have tested. The Wiki's not a weblog ;^)
Cheers
Unknown User (taick1m)
Hello, Davide. Very useful information.What about characteristics with compounding?
Unknown User (105ke4nd0)
Hi Davide
Helpful information in your blog.
I have just coded your example and it seems that your first example has error in field name.
Code fragment should not contain zero(0) in front of field name.
Your code:
I_ATTRNM = '0CUST_CLASS'
Correct Code:
I_ATTRNM = 'CUST_CLASS'
Can you please confirm that this is the case.
Best regards, Marko.