START-OF-SELECTION.
lcl_my_class=>main( )->execute( ).
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* METHOD lm_build_records: Build a table with nn records...
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
METHOD lm_build_records.
DO p_recs TIMES.
APPEND VALUE lty_struct( key1 = 900 + sy-index
key2 = sy-index
field1 = |A Text Field - { sy-index }|
a_date_field = sy-datum + sy-index
summary_field = sy-index * 10 )
TO et_test_table.
ENDDO.
ENDMETHOD. " lm_build_records
PRIVATE SECTION.
TYPES: BEGIN OF lty_struct,
key1 TYPE matnr,
key2 TYPE rsrnumc10,
field1 TYPE string,
a_date_field TYPE sydatum,
summary_field TYPE i,
END OF lty_struct,
lty_tab TYPE STANDARD TABLE OF lty_struct,
lty_stab TYPE SORTED TABLE OF lty_struct WITH UNIQUE KEY key1 key2.
TYPES: BEGIN OF lty_struct,
key1 TYPE matnr,
key2 TYPE rsrnumc10,
field1 TYPE string,
a_date_field TYPE sydatum,
summary_field TYPE i,
END OF lty_struct,
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* METHOD lm_process_standard_table: Pre-740 Method to process a
* standard table.
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
METHOD lm_process_standard_table.
DATA: lt_temp_table TYPE lty_tab,
lt_sum_table TYPE lty_tab,
lw_rec TYPE lty_struct.
lt_temp_table[] = it_test_table[].
lt_sum_table[] = it_test_table[].
SORT lt_temp_table BY key1 key2.
SORT lt_sum_table BY key1 key2.
"This will double the summary_field entries...
LOOP AT lt_temp_table INTO lw_rec.
COLLECT lw_rec INTO lt_sum_table.
ENDLOOP.
lm_display( CHANGING ct_report = lt_sum_table ).
ENDMETHOD. " lm_process_standard_table
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* METHOD lm_process_sorted_table: Pre-740 Logic to process a
* sorted table.
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
METHOD lm_process_sorted_table.
DATA: lt_temp_table TYPE lty_stab,
lt_sum_table TYPE lty_stab,
lt_pass_table TYPE lty_tab,
lw_rec TYPE lty_struct.
FIELD-SYMBOLS: <lw_rec> TYPE lty_struct.
LOOP AT it_test_table INTO lw_rec.
INSERT lw_rec INTO TABLE lt_temp_table.
INSERT lw_rec INTO TABLE lt_sum_table.
ENDLOOP.
"This will double the summary_field entries...
CLEAR lw_rec.
LOOP AT lt_temp_table INTO lw_rec.
UNASSIGN <lw_rec>.
READ TABLE lt_sum_table ASSIGNING <lw_rec>
WITH TABLE KEY key1 = lw_rec-key1
key2 = lw_rec-key2.
IF <lw_rec> IS ASSIGNED.
"Add the summary_field...
<lw_rec>-summary_field = <lw_rec>-summary_field + lw_rec-summary_field.
ENDIF.
ENDLOOP.
lt_pass_table[] = lt_sum_table[].
lm_display( CHANGING ct_report = lt_pass_table ).
ENDMETHOD. " lm_process_sorted_table
data(lw_record5) = lt_sum_table[ 5 ].
data(lw_record5) = lt_sum_table[ key1 = '905' key2 = '5' ].
if line_exists( lt_sum_table[ key1 = '905' key2 = '5' ] ).
data(lw_record5) = lt_sum_table[ key1 = '905' key2 = '5' ].
endif.
if line_exists( lt_sum_table[ key1 = ' 905' key2 = '0000000005' ] ).
data(lw_record5) = lt_sum_table[ key1 = ' 905' key2 = '0000000005' ].
endif.
data(lw_record5) = lt_sum_table[ key1 = lt_temp_table[ 5 ]-key1 key2 = lt_temp_table[ 5 ]-key2 ].
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* METHOD lm_process_new_abap: Use New ABAP Features to process a table.
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
METHOD lm_process_new_abap.
DATA: lt_temp_table TYPE lty_stab,
lt_sum_table TYPE lty_stab,
lt_pass_table TYPE lty_tab.
LOOP AT it_test_table INTO DATA(lw_rec).
INSERT lw_rec INTO TABLE lt_temp_table.
INSERT lw_rec INTO TABLE lt_sum_table.
ENDLOOP.
"This will double the summary_field entries...
"The bracket notation [] finds the record with that key, then we can update it...
CLEAR lw_rec.
LOOP AT lt_temp_table INTO lw_rec.
IF line_exists( lt_sum_table[ key1 = lw_rec-key1 key2 = lw_rec-key2 ] ).
lt_sum_table[ key1 = lw_rec-key1 key2 = lw_rec-key2 ]-summary_field =
lt_sum_table[ key1 = lw_rec-key1 key2 = lw_rec-key2 ]-summary_field + lw_rec-summary_field.
ENDIF.
ENDLOOP.
lt_pass_table[] = lt_sum_table[].
lm_display( CHANGING ct_report = lt_pass_table ).
ENDMETHOD. " lm_process_new_abap
IF line_exists( lt_sum_table[ key1 = lw_rec-key1 key2 = lw_rec-key2 ] ).
lt_sum_table[ key1 = lw_rec-key1 key2 = lw_rec-key2 ]-summary_field =
lt_sum_table[ key1 = lw_rec-key1 key2 = lw_rec-key2 ]-summary_field + lw_rec-summary_field.
ENDIF.
LOOP AT lt_temp_table INTO lw_rec.
IF line_exists( lt_sum_table[ key1 = lw_rec-key1 key2 = lw_rec-key2 ] ).
lt_sum_table[ key1 = lw_rec-key1 key2 = lw_rec-key2 ]-summary_field =
lt_sum_table[ key1 = lw_rec-key1 key2 = lw_rec-key2 ]-summary_field + lw_rec-summary_field.
ENDIF.
ENDLOOP.
FIELD-SYMBOLS: <lfs_sum> TYPE lty_struct.
LOOP AT lt_temp_table INTO lw_rec.
UNASSIGN <lfs_sum>.
ASSIGN lt_sum_table[ key1 = lw_rec-key1 key2 = lw_rec-key2 ] TO <lfs_sum>.
IF <lfs_sum> IS ASSIGNED.
<lfs_sum>-summary_field = <lfs_sum>-summary_field + lw_rec-summary_field.
ENDIF.
ENDLOOP.
REPORT zjctest_tables.
SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS: rb_std RADIOBUTTON GROUP g1,
rb_sort RADIOBUTTON GROUP g1,
rb_new RADIOBUTTON GROUP g1,
p_recs TYPE syindex DEFAULT '20000'.
SELECTION-SCREEN END OF BLOCK b1.
CLASS lcl_my_class DEFINITION CREATE PRIVATE FINAL.
PUBLIC SECTION.
CLASS-METHODS:
main
RETURNING VALUE(r_obj) TYPE REF TO lcl_my_class.
METHODS:
execute.
PRIVATE SECTION.
TYPES: BEGIN OF lty_struct,
key1 TYPE matnr,
key2 TYPE rsrnumc10,
field1 TYPE string,
a_date_field TYPE sydatum,
summary_field TYPE i,
END OF lty_struct,
lty_tab TYPE STANDARD TABLE OF lty_struct,
lty_stab TYPE SORTED TABLE OF lty_struct WITH UNIQUE KEY key1 key2.
METHODS:
constructor,
lm_process_standard_table
IMPORTING it_test_table TYPE lty_tab,
lm_process_sorted_table
IMPORTING it_test_table TYPE lty_tab,
lm_process_new_abap
IMPORTING it_test_table TYPE lty_tab,
lm_display
CHANGING ct_report TYPE table,
lm_build_alv_table
CHANGING ct_report TYPE table
RETURNING VALUE(rt_alv) TYPE REF TO cl_salv_table,
lm_build_records
EXPORTING et_test_table TYPE lty_tab.
ENDCLASS.
CLASS lcl_my_class IMPLEMENTATION.
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* METHOD constructor: Initialize my object.
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
METHOD constructor.
ENDMETHOD. " constructor
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* METHOD main: Instantiate the object
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
METHOD main.
CREATE OBJECT r_obj.
ENDMETHOD. "MAIN
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* METHOD lm_process_standard_table: Pre-740 Method to process a
* standard table.
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
METHOD lm_process_standard_table.
DATA: lt_temp_table TYPE lty_tab,
lt_sum_table TYPE lty_tab,
lw_rec TYPE lty_struct.
lt_temp_table[] = it_test_table[].
lt_sum_table[] = it_test_table[].
SORT lt_temp_table BY key1 key2.
SORT lt_sum_table BY key1 key2.
"This will double the summary_field entries...
LOOP AT lt_temp_table INTO lw_rec.
COLLECT lw_rec INTO lt_sum_table.
ENDLOOP.
lm_display( CHANGING ct_report = lt_sum_table ).
ENDMETHOD. " lm_process_standard_table
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* METHOD lm_process_sorted_table: Pre-740 Logic to process a
* sorted table.
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
METHOD lm_process_sorted_table.
DATA: lt_temp_table TYPE lty_stab,
lt_sum_table TYPE lty_stab,
lt_pass_table TYPE lty_tab,
lw_rec TYPE lty_struct.
FIELD-SYMBOLS: <lw_rec> TYPE lty_struct.
LOOP AT it_test_table INTO lw_rec.
INSERT lw_rec INTO TABLE lt_temp_table.
INSERT lw_rec INTO TABLE lt_sum_table.
ENDLOOP.
"This will double the summary_field entries...
CLEAR lw_rec.
LOOP AT lt_temp_table INTO lw_rec.
UNASSIGN <lw_rec>.
READ TABLE lt_sum_table ASSIGNING <lw_rec>
WITH TABLE KEY key1 = lw_rec-key1
key2 = lw_rec-key2.
IF <lw_rec> IS ASSIGNED.
"Add the summary_field...
<lw_rec>-summary_field = <lw_rec>-summary_field + lw_rec-summary_field.
ENDIF.
ENDLOOP.
lt_pass_table[] = lt_sum_table[].
lm_display( CHANGING ct_report = lt_pass_table ).
ENDMETHOD. " lm_process_sorted_table
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* METHOD lm_process_new_abap: Use New ABAP Features to process a table.
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
METHOD lm_process_new_abap.
DATA: lt_temp_table TYPE lty_stab,
lt_sum_table TYPE lty_stab,
lt_pass_table TYPE lty_tab.
FIELD-SYMBOLS: <lfs_sum> TYPE lty_struct.
LOOP AT it_test_table INTO DATA(lw_rec).
INSERT lw_rec INTO TABLE lt_temp_table.
INSERT lw_rec INTO TABLE lt_sum_table.
ENDLOOP.
"This will double the summary_field entries...
"The bracket notation [] finds the record with that key, then we can update it...
CLEAR lw_rec.
LOOP AT lt_temp_table INTO lw_rec.
UNASSIGN <lfs_sum>.
ASSIGN lt_sum_table[ key1 = lw_rec-key1 key2 = lw_rec-key2 ] TO <lfs_sum>.
IF <lfs_sum> IS ASSIGNED.
<lfs_sum>-summary_field = <lfs_sum>-summary_field + lw_rec-summary_field.
ENDIF.
ENDLOOP.
lt_pass_table[] = lt_sum_table[].
lm_display( CHANGING ct_report = lt_pass_table ).
ENDMETHOD. " lm_process_new_abap
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* METHOD lm_build_records: Build a table with nn records...
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
METHOD lm_build_records.
DO p_recs TIMES.
APPEND VALUE lty_struct( key1 = 900 + sy-index
key2 = sy-index
field1 = |A Text Field - { sy-index }|
a_date_field = sy-datum + sy-index
summary_field = sy-index * 10 )
TO et_test_table.
ENDDO.
ENDMETHOD. " lm_build_records
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* METHOD execute: Execute the work for my object.
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
METHOD execute.
DATA: lt_report TYPE lty_tab.
"Create records...
lm_build_records( IMPORTING et_test_table = lt_report ).
"Mess up the sorting, so that we can process and test, below...
SORT lt_report DESCENDING.
IF rb_std = abap_true.
lm_process_standard_table( lt_report ).
ELSEIF rb_sort = abap_true.
lm_process_sorted_table( lt_report ).
ELSEIF rb_new = abap_true.
lm_process_new_abap( lt_report ).
ENDIF.
ENDMETHOD. "execute
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* METHOD lm_display: Show the report...
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
METHOD lm_display.
lm_build_alv_table( CHANGING ct_report = ct_report )->display( ).
ENDMETHOD. "display
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* METHOD lm_build_alv_table: Build the ALV Table...
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
METHOD lm_build_alv_table.
DATA: lv_functions TYPE REF TO cl_salv_functions_list,
lv_columns TYPE REF TO cl_salv_columns_table,
lv_display TYPE REF TO cl_salv_display_settings,
lv_col_tab TYPE salv_t_column_ref,
lv_key TYPE salv_s_layout_key,
lv_layout TYPE REF TO cl_salv_layout,
lv_oref TYPE REF TO cx_root,
lv_text TYPE bapi_msg,
lv_ltext TYPE scrtext_l,
lv_mtext TYPE scrtext_m,
lv_stext TYPE scrtext_s,
lv_select TYPE REF TO cl_salv_selections.
FIELD-SYMBOLS: <lfs_w_col> TYPE salv_s_column_ref.
CLEAR lv_text.
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = rt_alv
CHANGING
t_table = ct_report ).
CATCH cx_salv_msg INTO lv_oref.
lv_text = lv_oref->get_text( ).
RETURN.
ENDTRY.
lv_functions = rt_alv->get_functions( ).
lv_functions->set_all( ).
lv_columns = rt_alv->get_columns( ).
lv_columns->set_optimize( if_salv_c_bool_sap=>true ).
lv_col_tab = lv_columns->get( ).
LOOP AT lv_col_tab ASSIGNING <lfs_w_col>.
CASE <lfs_w_col>-columnname.
WHEN 'KEY1'.
<lfs_w_col>-r_column->set_short_text( 'Key1' ).
<lfs_w_col>-r_column->set_medium_text( 'Key Field #1' ).
<lfs_w_col>-r_column->set_long_text( 'Key Field #1' ).
WHEN 'KEY2'.
<lfs_w_col>-r_column->set_short_text( 'Key2' ).
<lfs_w_col>-r_column->set_medium_text( 'Key Field #2' ).
<lfs_w_col>-r_column->set_long_text( 'Key Field #2' ).
WHEN 'FIELD1'.
<lfs_w_col>-r_column->set_short_text( 'Field1' ).
<lfs_w_col>-r_column->set_medium_text( 'Text Field1' ).
<lfs_w_col>-r_column->set_long_text( 'Text Field1' ).
WHEN 'A_DATE_FIELD'.
<lfs_w_col>-r_column->set_short_text( 'DateField' ).
<lfs_w_col>-r_column->set_medium_text( 'A Date Field' ).
<lfs_w_col>-r_column->set_long_text( 'The First Date Field' ).
WHEN 'SUMMARY_FIELD'.
<lfs_w_col>-r_column->set_short_text( 'SumField' ).
<lfs_w_col>-r_column->set_medium_text( 'Summary Field' ).
<lfs_w_col>-r_column->set_long_text( 'Summary Field' ).
ENDCASE.
ENDLOOP.
lv_display = rt_alv->get_display_settings( ).
lv_display->set_striped_pattern( if_salv_c_bool_sap=>true ).
lv_layout = rt_alv->get_layout( ).
lv_key-report = sy-repid.
lv_layout->set_key( lv_key ).
lv_layout->set_default( abap_true ).
lv_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).
lv_select = rt_alv->get_selections( ).
lv_select->set_selection_mode( if_salv_c_selection_mode=>multiple ).
ENDMETHOD. "lm_build_alv_table
ENDCLASS.
*---------------------------------------------------------------------*
* I N I T I A L I Z A T I O N *
*---------------------------------------------------------------------*
INITIALIZATION.
%_rb_std_%_app_%-text = 'Standard Table'.
%_rb_sort_%_app_%-text = 'Sorted Table'.
%_rb_new_%_app_%-text = 'New ABAP'.
%_p_recs_%_app_%-text = 'Number of Records'.
*---------------------------------------------------------------------*
* S T A R T O F S E L E C T I O N
*---------------------------------------------------------------------*
START-OF-SELECTION.
lcl_my_class=>main( )->execute( ).
*---------------------------------------------------------------------*
* E N D O F S E L E C T I O N
*---------------------------------------------------------------------*
END-OF-SELECTION.
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 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |