abap2xlsx/src/zdemo_excel44.prog.abap
Gregor Wolf 3bee79156d
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
2019-09-29 17:03:03 +02:00

59 lines
2.0 KiB
ABAP

*&---------------------------------------------------------------------*
*& 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' ).