No line if empty by kwaishang (#629)

* Update zcl_excel_worksheet.clas.abap

Allow int8 type columns

* Option to create empty file 

Allow to create empty excel file even if input table is empty

* Update zcl_excel_worksheet.clas.abap

Add the option to create the file or not if the input table is empty

*  Test report zdemo_excel43 

When using CSV mainly, if the input table is empty, the csv file contained a line with empty fields and separators.
This fooled some automation process thinking there's data to process in the file.
When optional input parameter "iv_no_line_if_empty" of method "zcl_excel_worksheet->bind_table"  is checked, there's no more empty line in this case.

* User demo report 44 instead of 43

Mistake in test program name

* Fix internal renaming of test report 44

* Correct filename and test both cases

* Include test 44
This commit is contained in:
Gregor Wolf 2019-09-29 17:03:03 +02:00 committed by GitHub
parent e02733290f
commit 3bee79156d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 97 additions and 2 deletions

View File

@ -107,6 +107,7 @@ CLASS zcl_excel_worksheet DEFINITION
!it_field_catalog TYPE zexcel_t_fieldcatalog OPTIONAL !it_field_catalog TYPE zexcel_t_fieldcatalog OPTIONAL
!is_table_settings TYPE zexcel_s_table_settings OPTIONAL !is_table_settings TYPE zexcel_s_table_settings OPTIONAL
value(iv_default_descr) TYPE c OPTIONAL value(iv_default_descr) TYPE c OPTIONAL
!IV_NO_LINE_IF_EMPTY type ABAP_BOOL default ABAP_FALSE
EXPORTING EXPORTING
!es_table_settings TYPE zexcel_s_table_settings !es_table_settings TYPE zexcel_s_table_settings
RAISING RAISING
@ -3030,7 +3031,7 @@ CLASS ZCL_EXCEL_WORKSHEET IMPLEMENTATION.
ADD 1 TO lv_row_int. ADD 1 TO lv_row_int.
ENDLOOP. ENDLOOP.
IF sy-subrc <> 0. "create empty row if table has no data IF sy-subrc <> 0 AND iv_no_line_if_empty = abap_false. "create empty row if table has no data
me->set_cell( ip_column = lv_column_alpha me->set_cell( ip_column = lv_column_alpha
ip_row = lv_row_int ip_row = lv_row_int
ip_value = space ). ip_value = space ).
@ -4876,7 +4877,8 @@ CLASS ZCL_EXCEL_WORKSHEET IMPLEMENTATION.
ep_value_type = lv_value_type ). ep_value_type = lv_value_type ).
ENDIF. ENDIF.
CASE lv_value_type. CASE lv_value_type.
WHEN cl_abap_typedescr=>typekind_int OR cl_abap_typedescr=>typekind_int1 OR cl_abap_typedescr=>typekind_int2. WHEN cl_abap_typedescr=>typekind_int OR cl_abap_typedescr=>typekind_int1 OR cl_abap_typedescr=>typekind_int2
OR cl_abap_typedescr=>typekind_int8. "Allow INT8 types columns
lo_addit = cl_abap_elemdescr=>get_i( ). lo_addit = cl_abap_elemdescr=>get_i( ).
CREATE DATA lo_value_new TYPE HANDLE lo_addit. CREATE DATA lo_value_new TYPE HANDLE lo_addit.
ASSIGN lo_value_new->* TO <fs_numeric>. ASSIGN lo_value_new->* TO <fs_numeric>.

View File

@ -77,6 +77,7 @@ START-OF-SELECTION.
SUBMIT zdemo_excel39 WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Charts SUBMIT zdemo_excel39 WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Charts
SUBMIT zdemo_excel40 WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Demo Printsettings SUBMIT zdemo_excel40 WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Demo Printsettings
SUBMIT zdemo_excel41 WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Inheritance SUBMIT zdemo_excel41 WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Inheritance
SUBMIT zdemo_excel44 WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: No line if empty
SUBMIT zdemo_excel_comments WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Comments SUBMIT zdemo_excel_comments WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Comments
SUBMIT ztest_excel_image_header WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Image in Header and Footer SUBMIT ztest_excel_image_header WITH rb_down = abap_true WITH rb_show = abap_false WITH p_path = p_path AND RETURN. "#EC CI_SUBMIT abap2xlsx Demo: Image in Header and Footer

View File

@ -0,0 +1,58 @@
*&---------------------------------------------------------------------*
*& Report ZDEMO_EXCEL44
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zdemo_excel44.
DATA: lo_excel_no_line_if_empty TYPE REF TO zcl_excel,
lo_excel TYPE REF TO zcl_excel,
lo_worksheet_no_line_if_empty TYPE REF TO zcl_excel_worksheet,
lo_worksheet TYPE REF TO zcl_excel_worksheet.
DATA: lt_field_catalog TYPE zexcel_t_fieldcatalog.
DATA: gc_save_file_name TYPE string VALUE '44_iTabEmpty.csv'.
INCLUDE zdemo_excel_outputopt_incl.
SELECTION-SCREEN BEGIN OF BLOCK b44 WITH FRAME TITLE txt_b44.
* No line if internal table is empty
DATA: p_mtyfil TYPE flag VALUE abap_true.
SELECTION-SCREEN END OF BLOCK b44.
INITIALIZATION.
txt_b44 = 'Testing empty file option'(b44).
START-OF-SELECTION.
" Creates active sheet
CREATE OBJECT lo_excel_no_line_if_empty.
CREATE OBJECT lo_excel.
" Get active sheet
lo_worksheet_no_line_if_empty = lo_excel_no_line_if_empty->get_active_worksheet( ).
lo_worksheet = lo_excel->get_active_worksheet( ).
lo_worksheet_no_line_if_empty->set_title( 'Internal table' ).
lo_worksheet->set_title( 'Internal table' ).
DATA lt_test TYPE TABLE OF sflight.
lo_worksheet_no_line_if_empty->bind_table( ip_table = lt_test
iv_no_line_if_empty = p_mtyfil ).
p_mtyfil = abap_false.
lo_worksheet->bind_table( ip_table = lt_test
iv_no_line_if_empty = p_mtyfil ).
*** Create output
lcl_output=>output( EXPORTING cl_excel = lo_excel_no_line_if_empty
iv_writerclass_name = 'ZCL_EXCEL_WRITER_CSV' ).
gc_save_file_name = '44_iTabNotEmpty.csv'.
lcl_output=>output( EXPORTING cl_excel = lo_excel
iv_writerclass_name = 'ZCL_EXCEL_WRITER_CSV' ).

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_PROG" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<PROGDIR>
<NAME>ZDEMO_EXCEL44</NAME>
<SUBC>1</SUBC>
<RSTAT>T</RSTAT>
<RLOAD>E</RLOAD>
<FIXPT>X</FIXPT>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<TPOOL>
<item>
<ID>I</ID>
<KEY>B44</KEY>
<ENTRY>Testing empty file option</ENTRY>
<LENGTH>50</LENGTH>
</item>
<item>
<ID>R</ID>
<ENTRY>Demo excel 44</ENTRY>
<LENGTH>13</LENGTH>
</item>
<item>
<ID>S</ID>
<KEY>P_MTYFIL</KEY>
<ENTRY>No data =&gt; No empty line</ENTRY>
<LENGTH>32</LENGTH>
</item>
</TPOOL>
</asx:values>
</asx:abap>
</abapGit>