*&---------------------------------------------------------------------*
*& Report YTMP_DYN_TAB_W_KEYS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ytmp_dyn_tab_w_keys.
START-OF-SELECTION.
DATA table_w_keys_handle TYPE REF TO cl_abap_tabledescr.
DATA keyless_table_handle TYPE REF TO cl_abap_tabledescr.
DATA keys TYPE abap_table_keydescr_tab.
DATA struct_desc TYPE REF TO cl_abap_structdescr.
DATA table_w_keys TYPE REF TO data.
DATA keyless_table TYPE REF TO data.
PERFORM get_struct
CHANGING
struct_desc.
PERFORM get_keys
CHANGING
keys.
cl_abap_tabledescr=>create_with_keys(
EXPORTING
p_line_type = struct_desc " Type Description Object of Row Type of Table
p_keys = keys " Table Keys
RECEIVING
p_result = table_w_keys_handle " Type Description Object of Table
).
CREATE DATA table_w_keys TYPE HANDLE table_w_keys_handle.
cl_abap_tabledescr=>create(
EXPORTING
p_line_type = struct_desc " Line Type
RECEIVING
p_result = keyless_table_handle " Result Type
).
CREATE DATA keyless_table TYPE HANDLE keyless_table_handle.
PERFORM select_data
CHANGING table_w_keys.
PERFORM select_data
CHANGING keyless_table.
PERFORM read_with_key
USING table_w_keys.
PERFORM read_wo_key
USING keyless_table.
WRITE 'Done'.
*&---------------------------------------------------------------------*
*& Form GET_STRUCT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_STRUCT_DESC text
*----------------------------------------------------------------------*
FORM get_struct
CHANGING
ch_struct_desc TYPE REF TO cl_abap_structdescr.
DATA fields TYPE abap_component_tab.
DATA field LIKE LINE OF fields.
field-name = 'CARRID'.
field-type ?= cl_abap_datadescr=>describe_by_name( p_name = 'S_CARR_ID' ).
APPEND field TO fields.
field-name = 'CONNID'.
field-type ?= cl_abap_datadescr=>describe_by_name( p_name = 'S_CONN_ID' ).
APPEND field TO fields.
field-name = 'FLDATE'.
field-type ?= cl_abap_datadescr=>describe_by_name( p_name = 'S_DATE' ).
APPEND field TO fields.
field-name = 'BOOKID'.
field-type ?= cl_abap_datadescr=>describe_by_name( p_name = 'S_BOOK_ID' ).
APPEND field TO fields.
field-name = 'SMOKER'.
field-type ?= cl_abap_datadescr=>describe_by_name( p_name = 'S_SMOKER' ).
APPEND field TO fields.
field-name = 'CLASS'.
field-type ?= cl_abap_datadescr=>describe_by_name( p_name = 'S_CLASS' ).
APPEND field TO fields.
ch_struct_desc ?= cl_abap_structdescr=>create(
p_components = fields
).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_KEYS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_KEYS text
*----------------------------------------------------------------------*
FORM get_keys
CHANGING
ch_keys TYPE abap_table_keydescr_tab.
DATA key LIKE LINE OF ch_keys.
DATA component LIKE LINE OF key-components.
component-name = 'CARRID'.
APPEND component TO key-components.
component-name = 'CONNID'.
APPEND component TO key-components.
component-name = 'FLDATE'.
APPEND component TO key-components.
component-name = 'BOOKID'.
APPEND component TO key-components.
key-name = 'MY_KEY'.
key-is_primary = abap_true.
key-is_unique = abap_true.
key-access_kind = cl_abap_tabledescr=>tablekind_sorted.
key-key_kind = cl_abap_tabledescr=>keydefkind_user.
APPEND key TO ch_keys.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SELECT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_TABLE_W_KEYS text
*----------------------------------------------------------------------*
FORM select_data
CHANGING
ch_table_w_keys TYPE REF TO data.
FIELD-SYMBOLS <any_table> TYPE ANY TABLE.
ASSIGN ch_table_w_keys->* TO <any_table>.
SELECT * FROM sbook
INTO CORRESPONDING FIELDS OF TABLE <any_table>.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form READ_WITH_KEY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_TABLE_W_KEYS text
*----------------------------------------------------------------------*
FORM read_with_key
USING
im_table_w_keys TYPE REF TO data.
FIELD-SYMBOLS <any_table> TYPE ANY TABLE.
ASSIGN im_table_w_keys->* TO <any_table>.
READ TABLE <any_table> TRANSPORTING NO FIELDS
WITH TABLE KEY ('CARRID') = 'SQ'
('CONNID') = '0002'
('FLDATE') = '20170915'
('BOOKID') = '00000002'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form READ_WO_KEY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_KEYLESS_TABLE text
*----------------------------------------------------------------------*
FORM read_wo_key
USING
im_keyless_table TYPE REF TO data.
FIELD-SYMBOLS <any_table> TYPE ANY TABLE.
ASSIGN im_keyless_table->* TO <any_table>.
READ TABLE <any_table> TRANSPORTING NO FIELDS
WITH KEY ('CARRID') = 'SQ'
('CONNID') = '0002'
('FLDATE') = '20170915'
('BOOKID') = '00000002'.
ENDFORM.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |