on 2017 Jun 05 3:53 PM
Hi experts,
I am trying to make logging for InfoCube working for BPC for S4HANA based on the document in attachment. (How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit).
There is a step where report below should produce a DB table from predefined structure.
It is deriving the schema name as "SAP" and ID of my system that is GED.
But the table is not being produced, when debugging it, it seems that the schema name is not correct...
Have somebody faced this issue?
Thanks,
Tomas.
*&---------------------------------------------------------------------*
*& Report Z_CREATE_DB_TABLE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_CREATE_DB_TABLE.
DATA: l_r_connection TYPE REF TO cl_sql_connection,
l_r_statement TYPE REF TO cl_sql_statement,
l_sql_statement TYPE string,
l_field_list type string,
l_r_cx_root TYPE REF TO CX_ROOT,
l_o_structdesc TYPE REF TO cl_abap_structdescr,
l_t_components TYPE abap_component_tab,
l_s_components LIKE LINE OF l_t_components,
l_target TYPE ADBC_NAME,
l_schema TYPE ADBC_NAME,
l_s_dd04l type dd04l,
l_s_dbdomain type DBDOMAIN,
l_r_elemdescr type ref to CL_ABAP_ELEMDESCR,
l_fieldname type string.
PARAMETERS: struct(20) type c.
* l_target = struct.
* the name of the schema consist of the prefix 'SAP' and the system name.
CONCATENATE 'SAP' sy-sysid into l_schema.
concatenate '"' l_schema '"."' struct '"' into l_target.
TRY.
* get the fields of the logging table
l_o_structdesc ?= cl_abap_typedescr=>describe_by_name( struct ).
l_t_components = l_o_structdesc->get_components( ).
* open the data abse connection
l_r_connection = cl_sql_connection=>get_connection( ).
* fill the sql statement
l_r_statement = l_r_connection->create_statement( ).
* sample statement:
*drop table ZIC_02_LOG;
*create column table ZIC_02_LOG
*(
* MYUSER nvarchar(12),
* MYDATE nvarchar(8),
* MYTIME nvarchar(6),
* CALYEAR nvarchar(4),
* CALMONTH nvarchar(6),
* CURRENCY nvarchar(5),
* UNIT nvarchar(3),
* [...]
* D_NW_QUANT decimal(17,3),
* D_NW_REB decimal(17,3),
* D_NW_TRNSP decimal(17,3),
* SAVEID nvarchar(32)
*
* );
loop at l_t_components into l_s_components.
*name is the name in the structure
* type is a class, help_id in the class contains the data element
l_r_elemdescr ?= l_s_components-type.
* get the ABAP information
select single * from dd04L into l_s_dd04l
where rollname = l_r_elemdescr->help_id.
* get the BD type
CALL FUNCTION 'DB_MAP_DDTYPE'
EXPORTING
DATATYPE = l_s_dd04l-datatype
* DBSYS = SY-DBSYS
DECIMALS = l_s_dd04l-decimals
LENG = l_s_dd04l-leng
* WITH_CHECK = ' '
* WITH_STRING = ' '
IMPORTING
DBDOMAIN = l_s_dbdomain.
* TYPESTRING =
* EXCEPTIONS
* NOT_MAPPABLE = 1
* OTHERS = 2 .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
exit.
ENDIF.
clear l_fieldname.
concatenate '"' l_s_components-name '"' into l_fieldname.
if l_s_dbdomain-type = 'DECIMAL'.
concatenate
l_field_list
l_fieldname
l_s_dbdomain-type '(' l_s_dbdomain-length ',' l_s_dbdomain-decimals '),'
into l_field_list SEPARATED BY SPACE.
elseif l_s_dbdomain-type = 'INTEGER' or l_s_dbdomain-type = 'DOUBLE'.
concatenate
l_field_list
l_fieldname
l_s_dbdomain-type ','
into
l_field_list SEPARATED BY SPACE.
else.
concatenate
l_field_list
l_fieldname
l_s_dbdomain-type '(' l_s_dbdomain-length '),'
into
l_field_list SEPARATED BY SPACE.
endif.
endloop.
shift l_field_list RIGHT DELETING TRAILING ','.
* make sure we have any fields at all!
check not l_field_list is INITIAL.
* clear the old table
concatenate
'drop table'
l_target
into l_sql_statement SEPARATED BY SPACE.
CATCH cx_root INTO l_r_cx_root.
MESSAGE E000(00) with 'Table creation failed.'.
exit.
ENDTRY.
try.
* execute the sql statement
CALL METHOD l_r_statement->execute_query
EXPORTING
statement = l_sql_statement.
CATCH cx_root INTO l_r_cx_root.
* MESSAGE E000(00) with 'Table creation failed.'.
* exit.
* If we have an error here then probably the data table does not exist yet. So just continue.
ENDTRY.
try.
* build up the actual statement
clear l_sql_statement.
concatenate
'create column table'
l_target
'('
l_field_list
')'
into l_sql_statement SEPARATED BY SPACE.
* execute the sql statement
CALL METHOD l_r_statement->execute_query
EXPORTING
statement = l_sql_statement.
l_r_connection->close( ).
CATCH cx_root INTO l_r_cx_root.
MESSAGE E000(00) with 'Table creation failed.'.
exit.
ENDTRY.
Write: 'The table ', l_target, ' has been created successfully in schema ',
l_schema, '.' .
How to… Log Changes in Plan Data when using the SAP BW Planning Applications Kit
Request clarification before answering.
The schema cannot be generated by the default approach.
The schema name is different and had to be hard-coded.
commented out: CONCATENATE 'SAP' sy-sysid into l_schema.
new line: l_schema = 'SAPABAP1'.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 7 | |
| 7 | |
| 6 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.