0% found this document useful (0 votes)
7 views

Extraction from HANA code

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Extraction from HANA code

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Select query:

Select:

SELECT

"AIRCRAFT_TYPE",

"SOURCE_TYPE",

"SOURCE_ID",

"AMM_HIERARCHY",

"AMM_INV_HIERARCHY",

"AMM_TASK_SOLUTION_ID",

"AMM_TASK_INV",

"AMM_TASK_SOL_DESCRIPTION",

"AMM_TASK_SOL_TYPE",

"LEVEL",

"ITEM_TYPE",

"ITEM",

"DESIGNATION",

"QUANTITY",

"APPLICABILITY",

"STATUS",

"CLASSIFICATION",

"WAY",

"ITEM_INV",

"PART_NUMBER",

"MANUF_NUMBER",

"PN_DESIGNATION",

"PN_MATERIAL_GROUP",

"AMM_FIN",

"AMM_FIN_FAMILY",

"CSN",

"FIGURE_INV",
"FIGURE_SOL_REFERENCE",

"FIGURE_SOL_DESCRIPTION",

"AMM_HIERARCHY_FATHER",

"OBJ_HIERARCHY",

"EFFECTIVITY",

"FIN_LIST",

"IS_AMM_TASK_0",

"CSN_COUNT",

"AMM_FIN_COUNT",

"NHA",

"ITEM_SYMMETRY"

FROM
"_SYS_BIC"."airbus.cs.DM04-PNR_List.ENGINE-V2.REPORTING/CV_OUTPUT_CALC_SRC_
COUNT" WHERE ( ( AIRCRAFT_TYPE = 'A320') AND ( SOURCE_TYPE = 'MPD') AND
( SOURCE_ID = '200001-01') )

Internal table fields

Complete source code:

REPORT ztestr_1.

TYPES: BEGIN OF ts_calculation_src_state,


aircraft_type TYPE zdhdme_aircraft_type, "DM04: Aircraft Type
source_type TYPE zdhdme_source_type, " DM04: LT Source Type
source_id TYPE zdhdme_source_id, " DM04: LT Source ID
source_task_sol_desc TYPE zdhdme_source_task_sol_desc, " Descri
ption
source_code TYPE zdhdme_source_task_sol_code, "
lt_status TYPE zdhdme_lt_status, " Expert analysis status
lt_uname TYPE zdhdme_lt_uname, "
lt_aetmt TYPE zdhdme_lt_timestamp, " Last LT rules update
calc_depth TYPE zdhdme_calc_depth, "
calc_way TYPE zdhdme_way, "
clc_stat TYPE zdhdme_calc_status, " Calculation State
clc_aetmt TYPE zdhdme_calc_timestamp, " Last Calculation Date
applicability TYPE zdhdme_source_appl_flag, "
amm_count TYPE string, "
effectivity TYPE zdhdme_effectivity, "
fin_list TYPE zdhdme_fin_list, "
* mfrpn TYPE zdhdme_part_number, "
* mfrnr TYPE zdhdme_part_number, "
END OF ts_calculation_src_state.
TYPES: BEGIN OF ty_field_type,
type(1) TYPE c,
END OF ty_field_type.
DATA:li_field_type TYPE TABLE OF ty_field_type,

li_tab_def TYPE abap_component_tab,


lw_tab_defwa TYPE abap_componentdescr,
lo_new_type TYPE REF TO cl_abap_structdescr,
lo_table_type TYPE REF TO cl_abap_tabledescr,
lw_id(3) TYPE n.

FIELD-SYMBOLS: <fs_field_type> TYPE ty_field_type.


DATA: gi_hana TYPE STANDARD TABLE OF STRING,"ts_calculation_src_state,
GS_HANA TYPE ts_calculation_src_state,

lw_query TYPE string VALUE 'select * from "_SYS_BIC"."airbus.cs.DM04-


PNR_List.ENGINE-V2.REPORTING/CV_OUTPUT_SRC_STATE"'.

DATA:
lo_rs TYPE REF TO cl_sql_result_set,
lo_con TYPE REF TO cl_sql_connection,
lo_sqlerr TYPE REF TO cx_sql_exception,
lo_hdm_exc TYPE REF TO zcx_hdm_exception,
* lw_query TYPE string,
lw_message TYPE string,
lw_field(50000) TYPE c,
lw_counter(5) TYPE n,
lw_line TYPE string,
lw_start_line TYPE c,
lw_row_package TYPE i,
lw_row_all TYPE i.

FIELD-SYMBOLS:
<ls_calcul> TYPE any,
<lw_field> TYPE any,
<fs_table> TYPE ANY TABLE.
DATA: lo_hdm_model_appl_para TYPE REF TO zcl_hdm_model_appl_para,
lo_tref TYPE REF TO data.

CALL METHOD zcl_hdm_model_appl_para=>get_instance


RECEIVING
ro_self = lo_hdm_model_appl_para.

TRY.
* Create Connection

lo_con = cl_sql_connection=>get_connection( lo_hdm_model_appl_para-


>get_db_connect( ) ). "'DMDS-1S79-DHC' ).
IF lo_con IS NOT INITIAL.
* Create Statement
* lo_stmt = lo_con->create_statement( ).
* Execute Query
lo_rs = lo_con->create_statement( )->execute_query( lw_query ).
ENDIF.
CATCH cx_sql_exception INTO lo_sqlerr.
WRITE: / 'error execute query cx_sql_exception'(e03),
lo_sqlerr->db_error,
lo_sqlerr->sql_code,
lo_sqlerr->sql_message.
RETURN.
CATCH zcx_hdm_exception INTO lo_hdm_exc.
lw_message = lo_hdm_exc->if_message~get_text( ).
WRITE: / 'error ', lw_message.

RETURN.

ENDTRY.

** Create new type from component table


* lo_new_type = cl_abap_structdescr=>create( p_components = li_tab_def p
_strict = '' ).
*
** Create new table type
* lo_table_type = cl_abap_tabledescr=>create( lo_new_type ).

* Create dynamic internal table and assign to Field Symbol


* CREATE DATA lw_tref TYPE HANDLE lo_table_type.
CREATE DATA lo_tref TYPE TABLE OF ts_calculation_src_state .
* ASSIGN lw_tref->* TO <fs_table_1>.
* CLEAR: lo_tref.
** Assign result to table
* GET REFERENCE OF <fs_table> INTO lo_ref.

ASSIGN lo_tref->* TO <fs_table>.


"Process result
IF lo_rs IS BOUND.
lo_rs->set_param_table( itab_ref = lo_tref ).
lw_row_all = 0.
TRY.
DO.

* Get next package of rows


lw_row_package = lo_rs->next_package( ).
lw_row_all = lw_row_all + lw_row_package.
BREAK-POINT.
* Stop is nothing read
IF lw_row_package = 0.
EXIT.
ENDIF.

* CSV formatting
LOOP AT <fs_table> ASSIGNING <ls_calcul>.
* Prepare target line
CLEAR lw_line.
CLEAR lw_start_line.

* Build line
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <ls_calcul> TO <lw_f
ield> .
IF sy-subrc <> 0.
EXIT.
ENDIF.
WRITE <lw_field> TO lw_field.
REPLACE ALL OCCURRENCES OF ';' IN lw_field WITH ' '.

IF lw_start_line = space.
lw_line = lw_field.
lw_start_line = 'X'.
ELSE.
lw_line = lw_line && ';' && lw_field.
ENDIF.
ENDDO.

*** Save line into file

APPEND lw_line TO GI_HANA.

* CLEAR GS_HANA
** TRANSFER lw_line TO p_file.
** IF sy-subrc <> 0.
** MESSAGE 'File transfer error'(e01) TYPE 'E'.
** ENDIF.

ENDLOOP.
CLEAR <fs_table>.

lw_counter = lw_counter + 1.
* MESSAGE i016(38) WITH 'Package' lw_counter.
* $ $ $ $

ENDDO.

lo_rs->close( ).
CATCH cx_sql_exception INTO lo_sqlerr.
"Do nothing, connection have to be close at the end
WRITE: / 'error close cx_sql_exception'(e02),
lo_sqlerr->db_error,
lo_sqlerr->sql_code,
lo_sqlerr->sql_message.

ENDTRY.
ENDIF.

"close connection
IF lo_con IS BOUND.
TRY.
lo_con->close( ).
CATCH cx_sql_exception INTO lo_sqlerr.
WRITE: / 'error close cx_sql_exception'(e02),
lo_sqlerr->db_error,
lo_sqlerr->sql_code,
lo_sqlerr->sql_message.
ENDTRY.
ENDIF.

You might also like