Skip to content

Commit

Permalink
fix #844 to remove all macros (#860)
Browse files Browse the repository at this point in the history
* fix #844 to remove all macros 

* abaplint.json avoid_use/define false -> true

Co-authored-by: sandraros <sandra.rossi@gmail.com>
Co-authored-by: Abo <andrea@borgia.bo.it>
  • Loading branch information
3 people committed Nov 1, 2021
1 parent dc3962a commit 3b2423e
Show file tree
Hide file tree
Showing 6 changed files with 745 additions and 324 deletions.
2 changes: 1 addition & 1 deletion abaplint.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"allowed_object_types": false,
"ambiguous_statement": false,
"avoid_use": {
"define": false,
"define": true,
"describeLines": false,
"statics": false,
"defaultKey": false,
Expand Down
130 changes: 90 additions & 40 deletions src/demos/zdemo_excel27.prog.abap
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,37 @@

REPORT zdemo_excel27.

CLASS lcl_app DEFINITION.
PUBLIC SECTION.
METHODS main.
PRIVATE SECTION.
METHODS conditional_formatting_cellis
IMPORTING
column TYPE simple
row TYPE zexcel_cell_row
rule TYPE zexcel_condition_rule
op TYPE zexcel_condition_operator
f TYPE zexcel_style_formula
f2 TYPE zexcel_style_formula
numfmt TYPE string.
METHODS conditional_formatting_textfun
IMPORTING
column TYPE simple
row TYPE zexcel_cell_row
txtfun TYPE zcl_excel_style_cond=>tv_textfunction
text TYPE string
numfmt TYPE string.
ENDCLASS.

CONSTANTS: c_fish TYPE string VALUE 'Fish'.

DATA: lo_app TYPE REF TO lcl_app.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_worksheet TYPE REF TO zcl_excel_worksheet,
lo_range TYPE REF TO zcl_excel_range,
lo_data_validation TYPE REF TO zcl_excel_data_validation,
lo_style_cond TYPE REF TO zcl_excel_style_cond,
lo_style_1 TYPE REF TO zcl_excel_style,
lo_style_2 TYPE REF TO zcl_excel_style,
lo_style TYPE REF TO zcl_excel_style,
lv_style_1_guid TYPE zexcel_cell_style,
lv_style_2_guid TYPE zexcel_cell_style,
lv_style_guid TYPE zexcel_cell_style,
Expand All @@ -32,7 +53,17 @@ INCLUDE zdemo_excel_outputopt_incl.


START-OF-SELECTION.
CREATE OBJECT lo_app.
lo_app->main( ).


CLASS lcl_app IMPLEMENTATION.

METHOD main.

DATA:
lo_style_cond TYPE REF TO zcl_excel_style_cond,
lo_style TYPE REF TO zcl_excel_style.

" Creates active sheet
CREATE OBJECT lo_excel.
Expand Down Expand Up @@ -101,65 +132,84 @@ START-OF-SELECTION.
ip_stop_row = 2 ).

" Conditional formatting for all operators
DEFINE conditional_formatting_cellis.
conditional_formatting_cellis( column = 'C' row = 4 rule = zcl_excel_style_cond=>c_rule_cellis op = zcl_excel_style_cond=>c_operator_equal f = '="Anchovy"' f2 = '' numfmt = 'equal to Anchovy' ).
conditional_formatting_cellis( column = 'C' row = 4 rule = zcl_excel_style_cond=>c_rule_cellis op = zcl_excel_style_cond=>c_operator_equal f = '="Anchovy"' f2 = '' numfmt = 'equal to Anchovy' ).
conditional_formatting_cellis( column = 'D' row = 4 rule = zcl_excel_style_cond=>c_rule_cellis op = zcl_excel_style_cond=>c_operator_notequal f = '="Anchovy"' f2 = '' numfmt = 'not equal to Anchovy' ).
conditional_formatting_cellis( column = 'E' row = 4 rule = zcl_excel_style_cond=>c_rule_cellis op = zcl_excel_style_cond=>c_operator_between f = '="B"' f2 = '="CC"' numfmt = 'between B and CC' ).
conditional_formatting_cellis( column = 'F' row = 4 rule = zcl_excel_style_cond=>c_rule_cellis op = zcl_excel_style_cond=>c_operator_greaterthan f = '="Catfish"' f2 = '' numfmt = 'greater than Catfish' ).
conditional_formatting_cellis( column = 'G' row = 4 rule = zcl_excel_style_cond=>c_rule_cellis op = zcl_excel_style_cond=>c_operator_greaterthanorequal f = '="Catfish"' f2 = '' numfmt = 'greater than or equal to Catfish' ).
conditional_formatting_cellis( column = 'H' row = 4 rule = zcl_excel_style_cond=>c_rule_cellis op = zcl_excel_style_cond=>c_operator_lessthan f = '="Catfish"' f2 = '' numfmt = 'less than Catfish' ).
conditional_formatting_cellis( column = 'I' row = 4 rule = zcl_excel_style_cond=>c_rule_cellis op = zcl_excel_style_cond=>c_operator_lessthanorequal f = '="Catfish"' f2 = '' numfmt = 'less than or equal to Catfish' ).

" Conditional formatting for all text functions
conditional_formatting_textfun( column = 'C' row = 6 txtfun = zcl_excel_style_cond=>c_textfunction_beginswith text = 'A' numfmt = 'begins with A' ).
conditional_formatting_textfun( column = 'D' row = 6 txtfun = zcl_excel_style_cond=>c_textfunction_containstext text = 'h' numfmt = 'contains text h' ).
conditional_formatting_textfun( column = 'E' row = 6 txtfun = zcl_excel_style_cond=>c_textfunction_endswith text = 'p' numfmt = 'ends with p' ).
conditional_formatting_textfun( column = 'F' row = 6 txtfun = zcl_excel_style_cond=>c_textfunction_notcontains text = 'h' numfmt = 'not contains h' ).

*** Create output
lcl_output=>output( lo_excel ).

ENDMETHOD.


METHOD conditional_formatting_cellis.

DATA:
lo_style TYPE REF TO zcl_excel_style,
lo_style_cond TYPE REF TO zcl_excel_style_cond.

lo_style = lo_excel->add_new_style( ).
lo_style->font->color-rgb = zcl_excel_style_color=>c_white.
lo_style->number_format->format_code = '@\ "' && &7 && '"'.
lo_style->number_format->format_code = '@\ "' && numfmt && '"'.
lo_style->alignment->wraptext = abap_true.
lv_style_guid = lo_style->get_guid( ).

lo_worksheet->set_cell( ip_row = &2 ip_column = &1 ip_formula = '$C$2' ip_style = lv_style_guid ).
lo_worksheet->set_cell( ip_row = row ip_column = column ip_formula = '$C$2' ip_style = lv_style_guid ).

lo_style_cond = lo_worksheet->add_new_style_cond( ).
lo_style_cond->rule = &3.
ls_cellis-operator = &4.
ls_cellis-formula = &5.
ls_cellis-formula2 = &6.
lo_style_cond->rule = rule.
ls_cellis-operator = op.
ls_cellis-formula = f.
ls_cellis-formula2 = f2.
ls_cellis-cell_style = lv_style_1_guid.
lo_style_cond->mode_cellis = ls_cellis.
lo_style_cond->priority = 1.
lo_style_cond->set_range( ip_start_column = &1
ip_start_row = &2
ip_stop_column = &1
ip_stop_row = &2 ).
END-OF-DEFINITION.

conditional_formatting_cellis 'C' 4 zcl_excel_style_cond=>c_rule_cellis zcl_excel_style_cond=>c_operator_equal '="Anchovy"' '' 'equal to Anchovy'.
conditional_formatting_cellis 'D' 4 zcl_excel_style_cond=>c_rule_cellis zcl_excel_style_cond=>c_operator_notequal '="Anchovy"' '' 'not equal to Anchovy'.
conditional_formatting_cellis 'E' 4 zcl_excel_style_cond=>c_rule_cellis zcl_excel_style_cond=>c_operator_between '="B"' '="CC"' 'between B and CC'.
conditional_formatting_cellis 'F' 4 zcl_excel_style_cond=>c_rule_cellis zcl_excel_style_cond=>c_operator_greaterthan '="Catfish"' '' 'greater than Catfish'.
conditional_formatting_cellis 'G' 4 zcl_excel_style_cond=>c_rule_cellis zcl_excel_style_cond=>c_operator_greaterthanorequal '="Catfish"' '' 'greater than or equal to Catfish'.
conditional_formatting_cellis 'H' 4 zcl_excel_style_cond=>c_rule_cellis zcl_excel_style_cond=>c_operator_lessthan '="Catfish"' '' 'less than Catfish'.
conditional_formatting_cellis 'I' 4 zcl_excel_style_cond=>c_rule_cellis zcl_excel_style_cond=>c_operator_lessthanorequal '="Catfish"' '' 'less than or equal to Catfish'.

DEFINE conditional_formatting_textfun.
lo_style_cond->set_range( ip_start_column = column
ip_start_row = row
ip_stop_column = column
ip_stop_row = row ).

ENDMETHOD.


METHOD conditional_formatting_textfun.

DATA:
lo_style TYPE REF TO zcl_excel_style,
lo_style_cond TYPE REF TO zcl_excel_style_cond.

lo_style = lo_excel->add_new_style( ).
lo_style->font->color-rgb = zcl_excel_style_color=>c_white.
lo_style->number_format->format_code = '@\ "' && &6 && '"'.
lo_style->number_format->format_code = '@\ "' && numfmt && '"'.
lo_style->alignment->wraptext = abap_true.
lv_style_guid = lo_style->get_guid( ).

lo_worksheet->set_cell( ip_row = &2 ip_column = &1 ip_formula = '$C$2' ip_style = lv_style_guid ).
lo_worksheet->set_cell( ip_row = row ip_column = column ip_formula = '$C$2' ip_style = lv_style_guid ).

lo_style_cond = lo_worksheet->add_new_style_cond( ).
lo_style_cond->rule = &3.
ls_textfunction-textfunction = &4.
ls_textfunction-text = &5.
lo_style_cond->rule = zcl_excel_style_cond=>c_rule_textfunction.
ls_textfunction-textfunction = txtfun.
ls_textfunction-text = text.
ls_textfunction-cell_style = lv_style_1_guid.
lo_style_cond->mode_textfunction = ls_textfunction.
lo_style_cond->priority = 1.
lo_style_cond->set_range( ip_start_column = &1
ip_start_row = &2
ip_stop_column = &1
ip_stop_row = &2 ).
END-OF-DEFINITION.
lo_style_cond->set_range( ip_start_column = column
ip_start_row = row
ip_stop_column = column
ip_stop_row = row ).

conditional_formatting_textfun 'C' 6 zcl_excel_style_cond=>c_rule_textfunction zcl_excel_style_cond=>c_textfunction_beginswith 'A' 'begins with A'.
conditional_formatting_textfun 'D' 6 zcl_excel_style_cond=>c_rule_textfunction zcl_excel_style_cond=>c_textfunction_containstext 'h' 'contains text h'.
conditional_formatting_textfun 'E' 6 zcl_excel_style_cond=>c_rule_textfunction zcl_excel_style_cond=>c_textfunction_endswith 'p' 'ends with p'.
conditional_formatting_textfun 'F' 6 zcl_excel_style_cond=>c_rule_textfunction zcl_excel_style_cond=>c_textfunction_notcontains 'h' 'not contains h'.
ENDMETHOD.

*** Create output
lcl_output=>output( lo_excel ).

ENDCLASS.
40 changes: 27 additions & 13 deletions src/demos/zdemo_excel_outputopt_incl.prog.abap
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,34 @@ CLASS lcl_output IMPLEMENTATION.
METHOD parametertexts.
* If started in language w/o textelements translated set defaults
* Furthermore I don't have to change the selectiontexts of all demoreports.
DEFINE default_parametertext.
IF %_&1_%_app_%-text = '&1' OR
%_&1_%_app_%-text IS INITIAL.
%_&1_%_app_%-text = &2.
ENDIF.
END-OF-DEFINITION.

default_parametertext: rb_down 'Save to frontend',
rb_back 'Save to backend',
rb_show 'Direct display',
rb_send 'Send via email',

p_path 'Frontend-path to download to',
p_email 'Email to send xlsx to'.
TYPES: BEGIN OF ty_parameter,
name TYPE string,
text TYPE string,
END OF ty_parameter.
DATA: parameters TYPE TABLE OF ty_parameter,
parameter TYPE ty_parameter,
parameter_text_name TYPE string.
FIELD-SYMBOLS: <parameter> TYPE ty_parameter,
<parameter_text> TYPE c.

parameter-name = 'RB_DOWN'. parameter-text = 'Save to frontend'. APPEND parameter TO parameters.
parameter-name = 'RB_BACK'. parameter-text = 'Save to backend'. APPEND parameter TO parameters.
parameter-name = 'RB_SHOW'. parameter-text = 'Direct display'. APPEND parameter TO parameters.
parameter-name = 'RB_SEND'. parameter-text = 'Send via email'. APPEND parameter TO parameters.
parameter-name = 'P_PATH'. parameter-text = 'Frontend-path to download to'. APPEND parameter TO parameters.
parameter-name = 'P_EMAIL'. parameter-text = 'Email to send xlsx to'. APPEND parameter TO parameters.

LOOP AT parameters ASSIGNING <parameter>.
parameter_text_name = |%_{ <parameter>-name }_%_APP_%-TEXT|.
ASSIGN (parameter_text_name) TO <parameter_text>.
IF sy-subrc = 0.
IF <parameter_text> = <parameter>-name OR
<parameter_text> IS INITIAL.
<parameter_text> = <parameter>-text.
ENDIF.
ENDIF.
ENDLOOP.

ENDMETHOD. "parametertexts

Expand Down
Loading

0 comments on commit 3b2423e

Please sign in to comment.