Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
lakshminarasimhan_n4
Active Contributor
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.

  1. BAPI_IOBJ_CREATE --> Infoobject creation

  2. 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.

 

I prepared a CSV file with just one InfoObject "YTEMP_1" and ran the program.



The CSV file prepared must be entered using F4 help.




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".

 

 

 
15 Comments
Labels in this area