*&---------------------------------------------------------------------* *& Report /EUTIN/ADBC_DEMO_FULL *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT /eutin/adbc_demo_full. CLASS lcl_main DEFINITION FINAL. PUBLIC SECTION. METHODS: get_data IMPORTING iv_table TYPE dd02l-tabname iv_sqlsmt TYPE string OPTIONAL, generate_output. PROTECTED SECTION. DATA mr_dyn_table TYPE REF TO data. ENDCLASS. PARAMETERS: p_table TYPE dd02l-tabname OBLIGATORY, p_sqlsmt TYPE string OBLIGATORY. INITIALIZATION. *--- default description of selection screen parameter %_p_table_%_app_%-text = 'Table Name'. %_p_sqlsmt_%_app_%-text = 'WHERE Condition'. *--- default selection screen parameter p_table = 'T100'. p_sqlsmt = |WHERE ARBGB = '00' |. START-OF-SELECTION. DATA(o_main) = NEW lcl_main( ). o_main->get_data( EXPORTING iv_table = p_table iv_sqlsmt = p_sqlsmt ). o_main->generate_output( ). CLASS lcl_main IMPLEMENTATION. METHOD get_data. *--- authorization checks CALL FUNCTION 'AUTHORITY_CHECK_TCODE' EXPORTING tcode = 'SA38' EXCEPTIONS ok = 1 not_ok = 2 OTHERS = 3. IF sy-subrc GT 1. *--- You are not authorized to use transaction & MESSAGE s077(s#) WITH 'SA38'. ENDIF. DATA lv_viewname TYPE dd25v-viewname. lv_viewname = iv_table. CALL FUNCTION 'VIEW_AUTHORITY_CHECK' EXPORTING view_action = 'S' view_name = lv_viewname no_warning_for_clientindep = abap_true * CHECK_ACTION_ALTERNATIVE = * CHECK_MAINFLAG = ABAP_FALSE * IMPORTING * GRANTED_ACTVT = * MAINFLAG = * CHANGING * ORG_CRIT_INST = EXCEPTIONS invalid_action = 1 no_authority = 2 no_clientindependent_authority = 3 table_not_found = 4 no_linedependent_authority = 5 OTHERS = 6. IF sy-subrc NE 0. *--- You are not authorized to perform this activity MESSAGE e018(s#). ENDIF. *--- fill up the columns which you want to select from the DB *--- the order should match with the output table SELECT * FROM dd03l INTO TABLE @DATA(lt_dd03l) WHERE tabname EQ @iv_table AND as4local EQ 'A' AND as4vers EQ '0000' ORDER BY position. IF sy-subrc NE 0 OR lt_dd03l[] IS INITIAL. RETURN. ENDIF. DATA: lt_cols TYPE adbc_column_tab, lt_fieldcat TYPE lvc_t_fcat, ls_fieldcat LIKE LINE OF lt_fieldcat. CLEAR: lt_fieldcat, ls_fieldcat. LOOP AT lt_dd03l ASSIGNING FIELD-SYMBOL(). INSERT -fieldname INTO TABLE lt_cols. IF sy-subrc NE 0. MESSAGE 'Unexpected error #1: INSERT -fieldname INTO TABLE lt_cols.' TYPE 'E'. ENDIF. APPEND INITIAL LINE TO lt_fieldcat ASSIGNING FIELD-SYMBOL(). IF sy-subrc NE 0 OR IS NOT ASSIGNED. MESSAGE 'Unexpected error #2: APPEND INITIAL LINE into lt_fieldcatASSIGNING field-symbol().' TYPE 'E'. ENDIF. MOVE-CORRESPONDING TO . -seltext = -fieldname. -key = -keyflag. -key_sel = -keyflag. -scrtext_l = -fieldname. -scrtext_m = -fieldname. -scrtext_s = -fieldname. ENDLOOP. *--- create dynamic table based on given field catalog CALL METHOD cl_alv_table_create=>create_dynamic_table EXPORTING i_style_table = 'X' it_fieldcatalog = lt_fieldcat IMPORTING ep_table = mr_dyn_table EXCEPTIONS generate_subpool_dir_full = 1 OTHERS = 2. IF sy-subrc NE 0. MESSAGE 'Creation of dynamic internal table failed' TYPE 'E'. ENDIF. *--- assign internal table and workarea for inspection data header TRY. FIELD-SYMBOLS TYPE STANDARD TABLE. ASSIGN mr_dyn_table->* TO . IF sy-subrc NE 0 OR IS NOT ASSIGNED. MESSAGE 'Assignment of dynamic internal table failed' TYPE 'E'. ENDIF. CATCH cx_root INTO DATA(lr_cx_root). MESSAGE lr_cx_root->get_text( ) TYPE 'E'. ENDTRY. DATA(lv_query) = |SELECT * FROM { iv_table } { iv_sqlsmt } |. TRY. DATA(lo_sql) = NEW cl_sql_statement( ). GET REFERENCE OF mr_dyn_table INTO DATA(lo_output). DATA(lo_result) = lo_sql->execute_query( lv_query ). lo_result->set_param_table( itab_ref = lo_output corresponding_fields = lt_cols ). IF lo_result->next_package( ) > 0. EXIT. ENDIF. CATCH cx_sql_exception INTO DATA(lx_sql_exception). MESSAGE lx_sql_exception->get_text( ) TYPE 'I' DISPLAY LIKE 'E'. RETURN. CATCH cx_root INTO DATA(lx_root). MESSAGE lx_root->get_text( ) TYPE 'I' DISPLAY LIKE 'E'. RETURN. ENDTRY. ENDMETHOD. METHOD generate_output. IF mr_dyn_table IS NOT BOUND. MESSAGE s094(s#). "No data exists RETURN. ENDIF. TRY. ASSIGN mr_dyn_table->* TO FIELD-SYMBOL(). IF sy-subrc NE 0. MESSAGE 'Assignment of dynamic internal table failed' TYPE 'E'. ENDIF. CATCH cx_root INTO DATA(lx_root1). MESSAGE lx_root1->get_text( ) TYPE 'I' DISPLAY LIKE 'E'. RETURN. ENDTRY. DATA lo_salv_table TYPE REF TO cl_salv_table. TRY. cl_salv_table=>factory( * EXPORTING * list_display = IF_SALV_C_BOOL_SAP=>FALSE * r_container = * container_name = IMPORTING r_salv_table = lo_salv_table CHANGING t_table = ). CATCH cx_salv_msg INTO DATA(lx_salv_msg). MESSAGE lx_salv_msg->get_text( ) TYPE 'I' DISPLAY LIKE 'E'. RETURN. CATCH cx_root INTO DATA(lx_root2). MESSAGE lx_root2->get_text( ) TYPE 'I' DISPLAY LIKE 'E'. RETURN. ENDTRY. lo_salv_table->display( ). ENDMETHOD. ENDCLASS. *--- The End!