Hi Experts,
I have a program that I built a custom formatted excel document attachement with CL_IXML and sent through CL_DOCUMENT_BCS. I have had not issues with the output file until now. The original report was just showing exceptions, and the request was made to add a selection option to show the full dataset with no exception checking and this only changes the build of the internal table to contain more data all of the same formats. All of the code is the same to build the report and the excel document. The only difference at all in the program is that the exception report tends to have about 15-30 items, and the full report tends to have about 1200. The program also displays the output in an ALV and everything works perfectly, but the requirement is to send the output in excel through email in a background job, so just using the ALV to export to excel does not work and does not provide the neccesary formatting. For the excel document created, the exception report works perfectly, but the full report excel document cannot open with the error in the below screen shot. Is there something about the size of the internal table that would make this happpen? In debug, the only difference at all when working through building the report table and the excel document is that the exception output that works the internal table (same for both the exception and full report) is much smaller and no code was modified in the file output sections. I have searched the forums and seen some posts referencing the same error as below, but none had the exact scenario where the program does actually work sometimes but only seemingly for the smaller set of data. Any help is greatly appreciated.
This works perfectly with the 2 items in DEV, and works perfectly in production with an average of about 15-30 items
This is what happens with a dataset that is about 1200 items.
Here is some of the code:
xml_file = cl_ixml=>create( ).
xl_doc = xml_file->create_document( ).
* Create Root Node Workbook
element = xl_doc->create_simple_element( name = 'Workbook' parent = xl_doc ).
element->set_attribute( name = 'xmlns' value = 'urn:schemas-microsoft-com:office:spreadsheet' ).
namespace = xl_doc->create_namespace_decl( name = 'ss' prefix = 'xmlns' uri = 'urn:schemas-microsoft-com:office:spreadsheet' ).
element->set_attribute_node( namespace ).
namespace = xl_doc->create_namespace_decl( name = 'x' prefix = 'xmlns' uri = 'urn:schemas-microsoft-com:office:excel' ).
element->set_attribute_node( namespace ).
* Create node for document properties
properties = xl_doc->create_simple_element( name = 'DLX_SAP_BATCHES' parent = element ).
value = sy-uname.
xl_doc->create_simple_element( name = 'Author' value = value parent = properties ).
* Styles
styles = xl_doc->create_simple_element( name = 'Styles' parent = element ).
* Header Style
style = xl_doc->create_simple_element( name = 'Style' parent = styles ).
style->set_attribute_ns( name = 'ID' prefix = 'ss' value = 'Header' ).
format = xl_doc->create_simple_element( name = 'Font' parent = style ).
format->set_attribute_ns( name = 'Bold' prefix = 'ss' value = '1' ).
* Worksheet
worksheet = xl_doc->create_simple_element( name = 'Worksheet' parent = element ).
worksheet->set_attribute_ns( name = 'Name' prefix = 'ss' value = 'Sheet1' ).
* Table
table = xl_doc->create_simple_element( name = 'Table' parent = worksheet ).
table->set_attribute_ns( name = 'FullColumns' prefix = 'x' value = '1' ).
table->set_attribute_ns( name = 'FullRows' prefix = 'x' value = '1' ).
* Column Header Row
xrow = xl_doc->create_simple_element( name = 'Row' parent = table ).
xrow->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '1' ).
* SLoc
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
xdata = xl_doc->create_simple_element( name = 'Data' value = 'S. Loc' parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* Material
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
xdata = xl_doc->create_simple_element( name = 'Data' value = 'Material' parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* Description
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
xdata = xl_doc->create_simple_element( name = 'Data' value = 'Desc.' parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* UOM
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
xdata = xl_doc->create_simple_element( name = 'Data' value = 'UOM' parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* Batch
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
xdata = xl_doc->create_simple_element( name = 'Data' value = 'Batch' parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* DLX Qty
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
xdata = xl_doc->create_simple_element( name = 'Data' value = 'DLX Qty' parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* SAP Qty
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
xdata = xl_doc->create_simple_element( name = 'Data' value = 'SAP Qty' parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* Difference
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
xdata = xl_doc->create_simple_element( name = 'Data' value = 'Difference' parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* DLX Prod. Date
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
xdata = xl_doc->create_simple_element( name = 'Data' value = 'DLX Prod.' parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* SAP Prod. Date
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
xdata = xl_doc->create_simple_element( name = 'Data' value = 'SAP Prod.' parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* DLX Expire Date
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
xdata = xl_doc->create_simple_element( name = 'Data' value = 'DLX Expire' parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* SAP Expire Date
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
xdata = xl_doc->create_simple_element( name = 'Data' value = 'SAP Expire' parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* Blank Row
xrow = xl_doc->create_simple_element( name = 'Row' parent = table ).
* Build excel data
LOOP AT rep_tab ASSIGNING <fs>.
CLEAR xl_num.
xrow = xl_doc->create_simple_element( name = 'Row' parent = table ).
* Sloc
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' value = 'Data' ).
value = <fs>-lgort.
xdata = xl_doc->create_simple_element( name = 'Data' value = value parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* Material
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' value = 'Data' ).
value = <fs>-matnr.
xdata = xl_doc->create_simple_element( name = 'Data' value = value parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'Number' ).
* Description
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' value = 'Data' ).
value = <fs>-maktx.
xdata = xl_doc->create_simple_element( name = 'Data' value = value parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* UOM
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' value = 'Data' ).
value = <fs>-meins.
xdata = xl_doc->create_simple_element( name = 'Data' value = value parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
* Batch
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' value = 'Data' ).
value = <fs>-charg.
xdata = xl_doc->create_simple_element( name = 'Data' value = value parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'Number' ).
* DLX Qty
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' value = 'Data' ).
xl_num = <fs>-untqty.
value = xl_num.
CONDENSE value NO-GAPS.
xdata = xl_doc->create_simple_element( name = 'Data' value = value parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'Number' ).
* SAP Qty
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' value = 'Data' ).
xl_num = <fs>-lbkum.
value = xl_num.
CONDENSE value NO-GAPS.
xdata = xl_doc->create_simple_element( name = 'Data' value = value parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'Number' ).
* Difference
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' value = 'Data' ).
xl_num = <fs>-diff.
value = xl_num.
CONDENSE value NO-GAPS.
xdata = xl_doc->create_simple_element( name = 'Data' value = value parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'Number' ).
* DLX Prod. Date
IF <fs>-mandte IS NOT INITIAL.
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' value = 'Data' ).
CONCATENATE <fs>-mandte+4(2) '/' <fs>-mandte+6(2) '/' <fs>-mandte+0(4) INTO value.
xdata = xl_doc->create_simple_element( name = 'Data' value = value parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
ENDIF.
* SAP Prod. Date
IF <fs>-hsdat IS NOT INITIAL.
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' value = 'Data' ).
CONCATENATE <fs>-hsdat+4(2) '/' <fs>-hsdat+6(2) '/' <fs>-hsdat+0(4) INTO value.
xdata = xl_doc->create_simple_element( name = 'Data' value = value parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
ENDIF.
* DLX Expire Date
IF <fs>-expire_dte IS NOT INITIAL.
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' value = 'Data' ).
CONCATENATE <fs>-expire_dte+4(2) '/' <fs>-expire_dte+6(2) '/' <fs>-expire_dte+0(4) INTO value.
xdata = xl_doc->create_simple_element( name = 'Data' value = value parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
ENDIF.
* SAP Expire Date
IF <fs>-vfdat IS NOT INITIAL.
xcell = xl_doc->create_simple_element( name = 'Cell' parent = xrow ).
xcell->set_attribute_ns( name = 'StyleID' value = 'Data' ).
CONCATENATE <fs>-vfdat+4(2) '/' <fs>-vfdat+6(2) '/' <fs>-vfdat+0(4) INTO value.
xdata = xl_doc->create_simple_element( name = 'Data' value = value parent = xcell ).
xdata->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
ENDIF.
ENDLOOP.
* Create output stream
xstream = xml_file->create_stream_factory( ).
ostream = xstream->create_ostream_itable( table = xml_table ).
* Render output
renderer = xml_file->create_renderer( ostream = ostream document = xl_doc ).
rc = renderer->render( ).
xml_size = ostream->get_num_written_raw( ).
* Build attachement file
LOOP AT xml_table INTO xml_s.
CLEAR obj_bin.
obj_bin-line = xml_s-data.
APPEND obj_bin TO excel_attachment.
ENDLOOP.