Technical Articles
Automated/Mass InfoObject creation via ABAP Program
Introduction
Create InfoObject using ABAP program.
Applies to
BW/4HANA, BW Powered by HANA, BW 7.x.
Summary
InfoObject’s are the basic building blocks in BW.
Even though we have the fields based modeling in BW Powered by HANA and also in BW/4HANA, the importance of infoobjects cannot be ignored.
In many cases/times when we need to have infoobjects either as attribute or as master data(when we need to have display of the data as both key and text or as Hierarchy).
Definitely the creation of infoobject is time consuming. we can simplify the creation of the infoobject using the ABAP program.
Author : Lakshminarasimhan Narasimhamurthy
Created on : 11/Jul/2021
Body
Requirement
We need to create a hundreds of info objects for a project requirement, maybe it’s a Greenfield implementation or a full fledged new development project or we need to copy all the SAP delivered infoobjects into custom infoobject’s. (Always the preferred approach is to copy the business content object and use them in the project, the reason is that during any upgrade the custom objects remain unaffected).
The process in going to be time consuming and error prone due to manual creation. So we will use the ABAP program to create the Infoobjects.
SAP has provided the BAPI’s(RFC function modules) for the infoobject creation and activation.
- BAPI_IOBJ_CREATE –> Infoobject creation
- BAPI_IOBJ_ACTIVATE_MULTIPLE –> Infoobject activation
The structure “BAPI6108” contains all the details required for the Infoobject creation. The structure must be filled with values. The internal table based on this structure must be populated with values.
Better approach is to fill all the details in the excel sheet(CSV format) with the same structure as BAPI6108. Then upload it to the internal table based on the structure BAPI6108 and this internal table must be passed to the BAPI “BAPI_IOBJ_CREATE”.
*&---------------------------------------------------------------------*
*& Report ZBW_IO_TEMP_TEST
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
report zbw_io_temp_test.
data: begin of data_final occurs 0.
include structure bapi6108.
data: end of data_final.
data: begin of ret_mess occurs 0.
include structure bapiret2.
data: end of ret_mess.
*data : la_conv_tab like line of lt_conv_tab.
data: begin of itab occurs 0,
f1(10000) type c,
end of itab.
data: begin of data_iobj occurs 0.
include structure bapi6108io.
data: end of data_iobj.
data: begin of io_err occurs 0.
include structure bapi6108io.
data: end of io_err.
parameters: lp_file type rlgrap-filename obligatory. " To get the file location
data : temp_ch type string,
names type c length 1000.
data : str3 type string, str4 type string, str5 type string, str6 type string,
str7 type string,
str8 type string, str9 type string, str10 type string, str11 type string, str12 type string,
str13 type string,
data_final_1 TYPE STANDARD TABLE OF bapi6108 WITH HEADER LINE.
*---------------------------------------------------------------------
* AT SELECTION SCREEN ON VALUE REQUEST
*---------------------------------------------------------------------
at selection-screen on value-request for lp_file.
perform help_local_file using lp_file.
start-of-selection.
temp_ch = lp_file.
call function 'GUI_UPLOAD'
exporting
filename = temp_ch
filetype = 'ASC'
* HAS_FIELD_SEPARATOR = ' '
header_length = 0
read_by_line = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
tables
data_tab = itab
exceptions
file_open_error = 1
file_read_error = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* NO_AUTHORITY = 6
* UNKNOWN_ERROR = 7
* BAD_DATA_FORMAT = 8
* HEADER_NOT_ALLOWED = 9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
access_denied = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* OTHERS = 17
.
if sy-subrc = 1.
message 'FILE IS OPEN; PLEASE CHECK THE FILE.' type 'I'.
*WITH "FILE IS OPEN; PLEASE CHECK THE FILE.".
exit.
elseif sy-subrc = 2.
message 'ERROR WHILE READING THE FILE' type 'I'.
exit.
elseif sy-subrc = 13.
message 'ACCESS DENIED.' type 'I'.
exit.
endif.
loop at itab from 2.
names = itab-f1.
" if there are many columns to be split then make use of the FM 'ALSM_EXCEL_TO_INTERNAL_TABLE'
split names at ',' into str3 str4 str5 str6 str7 str8 str9 str10 str11 str12 str13.
IF str5 = 'CHA'.
data_final-infoarea = str3.
data_final-infoobject = str4.
data_iobj-infoobject = str4.
data_final-type = str5.
data_final-textshort = str6.
data_final-textlong = str7.
data_final-datatp = str8.
data_final-intlen = str9.
data_final-outputlen = str10.
data_final-convexit = str11.
data_final-lowercase = str12.
data_final-mastauthfl = ''.
data_final-attribfl = ''.
data_final-NOVALFL = 'X'.
else.
data_final-infoarea = str3.
data_final-infoobject = str4.
data_iobj-infoobject = str4.
data_final-type = str5.
data_final-textshort = str6.
data_final-textlong = str7.
data_final-KYFTP = str8.
data_final-intlen = str9.
data_final-outputlen = str10.
endif.
append data_final to data_final. " Default header area to Internal table
endloop.
loop at data_final into data_final.
CLEAR : data_final_1[], data_final_1.
move-corresponding data_final to data_final_1.
append data_final_1 to data_final_1[].
call function 'BAPI_IOBJ_CREATE'
exporting
details = data_final_1
importing
* infoobject =
return = ret_mess
* tables
* compounds = data_compound
* attributes = data_attributes
* navigationattributes = data_navigation
* atrnavinfoprovider =
* hierarchycharacteristics =
* elimination =
* returntable =
.
clear : data_iobj[].
data_iobj-infoobject = data_final-infoobject.
append data_iobj to data_iobj[].
call function 'BAPI_IOBJ_ACTIVATE_MULTIPLE'
tables
infoobjects = data_iobj[]
infoobjects_error = io_err.
if sy-subrc <> 0.
endif.
endloop.
form help_local_file using filename type dxfile-filename.
data: lt_file_table type filetable,
la_file_table like line of lt_file_table,
l_rc type i,
l_pcdsn type cffile-filename.
refresh lt_file_table.
clear la_file_table.
call method cl_gui_frontend_services=>file_open_dialog
changing
file_table = lt_file_table
rc = l_rc.
read table lt_file_table into la_file_table index 1.
l_pcdsn = la_file_table-filename.
move l_pcdsn to filename.
endform.
in the debug mode, it is visible that the file is split into separate columns
if there are too many columns then we can use the FM ‘ALSM_EXCEL_TO_INTERNAL_TABLE’ to upload the data directly into the internal table.
Create the Infoobject via the BAPI.
Activate the Infoobject via the BAPI.
The InfoObject is now created in the system
In the similar fashion we can create all the Infoobjects present in the excel sheet.
Note – Once the program is run, we can directly see the active version of the Infoobject existing in the RSDIOBJ table.
Please see the additional below infoobjects table for your reference,
RSDCHA – Characteristic Infoobjects ( with referencing Infoobject)
RSDCHABAS – Characteristic Infoobjects details
RSDIOBJCMP – Compounded Infoobjects
RSDBCHATR – Attributes of characteristics(Display and Navigational)
RSDATRNAVT – Navigation Attributes Text
RSDIOBJ – List of all Infoobjects in all versions(D or M or A)
RSDKYF – Keyfigure table
I had different requirement to create a bunch of existing infoobjects with new naming convention hence I had used the above list of tables to populate the BAPI structure “BAPI6108”.
Hello Lakshminarasimhan, Thank you for sharing!
It works like a charm for characteristics
Could you please tell me if you were also able to use it for Key Figures?
It seems like some of the fields/tables are not filled by the BAPI. Therefore, the activation fails with type errors.
The sample I tried on BW/4HANA 2.0:
Errors:
Key Figure * of Invalid type and others
I am not filling length, and there also seems to be no place for KYFTP - AMO/NUM like in some old SCN reference:
Source: https://archive.sap.com/documents/docs/DOC-12249
Hi Sebastian,
Will work for the Keyfigures too now, i have updated the code,
Hi Lakshminarasimhan
The link is not accessible. Could you please update the latest ABAP code change in this blog ?
Thanks for your efforts. Its very useful utility program.
Many Thanks
Kiran
Dear Sebastian Gesiarz,
For keyfigures you need to fill the structure data_final (BAPI6108), all of the keyfigure properties can be taken/derived/referenced from RSDKYF table.
TYPE = 'KYF' mean data_final-TYPE = 'KYF' and for
KYFTP = 'AMO/QUA/FLO/INT etc' can be filled from data_final-KYFTP.
Thanks for response.
Were you able to use it for Key Figures? If so, could you please pass a sample?
I tried multiple combinations of input for BAPI6108 and it does not work.
The structure was wrong e.g. for the KYFTP,
I ended up modifying the code from: https://archive.sap.com/documents/docs/DOC-12249
It works well. It also activates the objects and shows the log.
Sample file:
Code modifications:
yes, i have update the code as well data_final-novalfl = 'X'.
This program is by default creating master data info-object. Which flag do we need to pass in BAPI 6108 import structure to uncheck the "Master Data" check box? I tried to find the flag field in BAPI6108 structure but I did not get it.
Dear Viral,
To uncheck the 'Master Data', you can pass "NOVALFL" flag = 'X' from BAPI6108 import structure in this program. It won't enable master data properties by default.
Just Insert this one line code
DATA_FINAL-NOVALFL = 'X' .
After this ITAB
yes like Ashish and Logavan mentioned, this piece of code will resolve the issue
" data_final-novalfl = 'X'." i have updated in the code now.
Thanks for this. Is there a way to automatically capture the IOs to a transport? The infoobjects created have blank package. I have to add package for each IO and then capture to a transport one by one.
will check that out, but you can collect all io's in oneshot suing RSA1-->Transport connection-->Infoobjects
Yeah, I also did it by 2x clicking the catalog then transport. I was able to capture all IOs. Thanks a lot!!!!!
Looks like the the IOBJ FM for create does not allow IOBJs for Key Figures. So this type of program may not be used for creating Key Figures