{"id":7759,"date":"2025-09-07T02:34:06","date_gmt":"2025-09-06T21:04:06","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?question=how-to-create-api-to-download-an-excel-sheet"},"modified":"2025-09-07T02:34:06","modified_gmt":"2025-09-06T21:04:06","slug":"how-to-create-api-to-download-an-excel-sheet","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=how-to-create-api-to-download-an-excel-sheet","title":{"rendered":"How to create API to download an Excel sheet"},"content":{"rendered":"<p>create a CDS view<\/p>\n<p>custom Entity:<\/p>\n<p style=\"margin: 0\"><span style=\"color: #a99c8c\">@EndUserText.label:<\/span> <span style=\"color: #a99c8c\">&#8216;template Download&#8217;<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #a99c8c\">@ObjectModel:<\/span> <span style=\"color: #a99c8c\">{<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #a99c8c\">query:<\/span> <span style=\"color: #a99c8c\">{<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #a99c8c\">implementedBy:<\/span> <span style=\"color: #a99c8c\">&#8216;ABAP: ZCL_DOWN_TEMPLATE&#8217;<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #a99c8c\">}<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #a99c8c\">}<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cc7832;font-weight: bold\">define<\/span> <span style=\"color: #cc7832;font-weight: bold\">root<\/span> <span style=\"color: #cc7832;font-weight: bold\">custom<\/span> <span style=\"color: #cc7832;font-weight: bold\">entity<\/span> Z<span style=\"color: #cccccc\">CHM__TMP_DWN<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cc7832;font-weight: bold\">{<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cc7832;font-weight: bold\">key<\/span> <span style=\"color: #cccccc\">docnum<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">10<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc\">comp_code<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">4<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc\">sales_org<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">4<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc\">distr_chn<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">2<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc\">division<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">2<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc\">ref_doc<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">20<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc\">currency<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">8<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc\">ref_item<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">10<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc\">material<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc\">matl_group<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">9<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc\">net_amount<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc\">gross<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">15<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc\">quantity<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">13<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc\">price_unit<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">5<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc\">bill_unit<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">char<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span><span style=\"color: #5be9fe\">3<\/span><span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cccccc;text-decoration: underline\">file_content<\/span> <span style=\"color: #cc7832;font-weight: bold\">:<\/span> <span style=\"color: #cccccc;font-style: italic;text-decoration: underline\">abap<\/span><span style=\"color: #cc7832;font-weight: bold\">.<\/span><span style=\"color: #cccccc;font-style: italic\">string<\/span><span style=\"color: #cc7832;font-weight: bold\">(<\/span> <span style=\"color: #5be9fe\">999999999<\/span> <span style=\"color: #cc7832;font-weight: bold\">);<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #cc7832;font-weight: bold\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>then Create a Class where you can write you logic to create the template and pass the file content to the front end.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"background-color: #1e1f22;padding: 0px 0px 0px 2px\">\n<div style=\"color: #cccccc;background-color: #1e1f22;font-size: 8pt\">\n<p style=\"margin: 0\"><span style=\"color: #56a5e4;border: dashed 1pt #40abfe\">CLASS<\/span><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">zcl_down_template<\/span><span style=\"color: #56a5e4\"> DEFINITION<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> PUBLIC FINAL<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> CREATE PUBLIC.<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> PUBLIC SECTION.<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> INTERFACES <\/span><span style=\"color: #cccccc\">if_rap_query_provider<\/span><span style=\"color: #56a5e4\">.<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> PRIVATE SECTION.<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> TYPES: BEGIN OF <\/span><span style=\"color: #cccccc\">lty_template<\/span><span style=\"color: #56a5e4\">,<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">docnum<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">Process_type<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">comp_code<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">sales_org<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">distr_chn<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">division<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">ref_doc<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">currency<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><span style=\"color: #56a5e4\"><\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">material<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">matl_group<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">net_amount<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">gross<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">quantity<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">price_unit<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">bill_unit<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">c<\/span><span style=\"color: #56a5e4\"> LENGTH <\/span><span style=\"color: #5be9fe\">40<\/span><span style=\"color: #56a5e4\">,<\/span><span style=\"color: #56a5e4\"><\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> END OF <\/span><span style=\"color: #cccccc\">lty_template<\/span><span style=\"color: #56a5e4\">.<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> DATA <\/span><span style=\"color: #cccccc\">et_result<\/span><span style=\"color: #56a5e4\"> TYPE TABLE OF <\/span><span style=\"color: #cccccc\">lty_template<\/span><span style=\"color: #56a5e4\">.<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> DATA <\/span><span style=\"color: #cccccc\">es_result<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">lty_template<\/span><span style=\"color: #56a5e4\">.<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> DATA <\/span><span style=\"color: #cccccc\">et_res<\/span><span style=\"color: #56a5e4\"> TYPE TABLE OF z<\/span><span style=\"color: #cccccc\">tmp_dwn<\/span><span style=\"color: #56a5e4\">.<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> DATA <\/span><span style=\"color: #cccccc\">es_res<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">ztmp_dwn<\/span><span style=\"color: #56a5e4\">.<\/span><span style=\"color: #56a5e4\"><\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4;border: dashed 1pt #40abfe\">ENDCLASS<\/span><span style=\"color: #56a5e4\">.<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\">CLASS <\/span><span style=\"color: #cccccc\">zcl_down_template<\/span><span style=\"color: #56a5e4\"> IMPLEMENTATION.<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> METHOD <\/span><span style=\"color: #cccccc\">if_rap_query_provider<\/span><span style=\"color: #56a5e4\">~<\/span><span style=\"color: #cccccc\">select<\/span><span style=\"color: #56a5e4\">.<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #808080\">&#8221; TODO: variable is assigned but never used (ABAP cleaner)<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> DATA(<\/span><span style=\"color: #cccccc\">lr_skip<\/span><span style=\"color: #56a5e4\">) = <\/span><span style=\"color: #cccccc\">io_request<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">get_paging<\/span><span style=\"color: #56a5e4\">( )-&gt;<\/span><span style=\"color: #cccccc\">get_offset<\/span><span style=\"color: #56a5e4\">( ).<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #808080\">&#8221; TODO: variable is assigned but never used (ABAP cleaner)<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> DATA(<\/span><span style=\"color: #cccccc\">lr_top<\/span><span style=\"color: #56a5e4\">) = <\/span><span style=\"color: #cccccc\">io_request<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">get_paging<\/span><span style=\"color: #56a5e4\">( )-&gt;<\/span><span style=\"color: #cccccc\">get_page_size<\/span><span style=\"color: #56a5e4\">( ).<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> DATA <\/span><span style=\"color: #cccccc\">lv_index_root<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">i<\/span><span style=\"color: #56a5e4\"> VALUE <\/span><span style=\"color: #5be9fe\">1<\/span><span style=\"color: #56a5e4\">.<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> DATA <\/span><span style=\"color: #cccccc\">lo_document<\/span><span style=\"color: #56a5e4\"> TYPE REF TO <\/span><span style=\"color: #cccccc\">if_xco_xlsx_wa_document<\/span><span style=\"color: #56a5e4\">.<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> DATA <\/span><span style=\"color: #cccccc\">lo_sheet<\/span><span style=\"color: #56a5e4\"> TYPE REF TO <\/span><span style=\"color: #cccccc\">if_xco_xlsx_wa_worksheet<\/span><span style=\"color: #56a5e4\">.<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> DATA <\/span><span style=\"color: #cccccc\">lv_sheet_name<\/span><span style=\"color: #56a5e4\"> TYPE <\/span><span style=\"color: #cccccc\">string<\/span><span style=\"color: #56a5e4\">.<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">lv_sheet_name<\/span><span style=\"color: #56a5e4\"> = |<\/span><span style=\"color: #1eb540\">Download_Template_<\/span><span style=\"color: #56a5e4\">{ <\/span><span style=\"color: #cccccc\">cl_abap_context_info<\/span><span style=\"color: #56a5e4\">=&gt;<\/span><span style=\"color: #cccccc\">get_system_date<\/span><span style=\"color: #56a5e4\">( ) }|.<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">lo_document<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #cccccc\">xco_cp_xlsx<\/span><span style=\"color: #56a5e4\">=&gt;<\/span><span style=\"color: #cccccc\">document<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">empty<\/span><span style=\"color: #56a5e4\">( )-&gt;<\/span><span style=\"color: #cccccc\">write_access<\/span><span style=\"color: #56a5e4\">( ).<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">lo_sheet<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #cccccc\">lo_document<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">get_workbook<\/span><span style=\"color: #56a5e4\">( )-&gt;<\/span><span style=\"color: #cccccc\">worksheet<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">at_position<\/span><span style=\"color: #56a5e4\">( <\/span><span style=\"color: #cccccc\">lv_index_root<\/span><span style=\"color: #56a5e4\"> ).<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">lo_sheet<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">set_name<\/span><span style=\"color: #56a5e4\">( <\/span><span style=\"color: #cccccc\">iv_name<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #cccccc\">lv_sheet_name<\/span><span style=\"color: #56a5e4\"> ).<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">et_result<\/span><span style=\"color: #56a5e4\"> = VALUE #( <\/span><span style=\"color: #56a5e4\">( <\/span><span style=\"color: #cccccc\">docnum<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;ID&#8217;<\/span><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">Process_type<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;Template&#8217;<\/span><span style=\"color: #56a5e4\"> )<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> ( <\/span><span style=\"color: #cccccc\">docnum<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;DOCNUM&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">Process_type<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;PAYTYPE&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">comp_code<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;COMP_CODE&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">sales_org<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;SALES_ORG&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">distr_chn<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;DISTR_CHAN&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">division<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;DIVISION&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">ref_doc<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;REF_DOC&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">currency<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;CURRENCY&#8217;<\/span><span style=\"color: #1eb540\"><\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">material<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;MATERIAL&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">matl_group<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;MATL_GROUP&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">net_amount<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;NET_AMOUNT&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">gross<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;GROSS&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">quantity<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;QUANTITY&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">price_unit<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;PRICE_UNIT&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">bill_unit<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;BILL_UNIT&#8217;<\/span><span style=\"color: #56a5e4\">)<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> ( <\/span><span style=\"color: #cccccc\">docnum<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;*Document Number(10)&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">Process_type<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;*Process Type(4)&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">comp_code<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;*Company Code(4)&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">sales_org<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;*Sales Organization(4)&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">distr_chn<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;*Distribution Channel(2)&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">division<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;*Division&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">ref_doc<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;*Reference Document&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">currency<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;*Currency&#8217;<\/span><span style=\"color: #1eb540\"><\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">ref_item<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;*Item No(10)&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">material<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;*Material(40)&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">matl_group<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;Material Group(9)&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">net_amount<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;NetAmount(15)&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">gross<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;Gross(15)&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">quantity<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;Quantuity(13)&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">price_unit<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;PriceUnit(5)&#8217;<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">bill_unit<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #1eb540\">&#8216;BillUnit(3)&#8217;<\/span><span style=\"color: #1eb540\"><\/span><span style=\"color: #56a5e4\"> ) ).<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> DATA(<\/span><span style=\"color: #cccccc\">lo_pattern<\/span><span style=\"color: #56a5e4\">) = <\/span><span style=\"color: #cccccc\">xco_cp_xlsx_selection<\/span><span style=\"color: #56a5e4\">=&gt;<\/span><span style=\"color: #cccccc\">pattern_builder<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">simple_from_to<\/span><span style=\"color: #56a5e4\">( )-&gt;<\/span><span style=\"color: #cccccc\">get_pattern<\/span><span style=\"color: #56a5e4\">( ).<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">lo_sheet<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">select<\/span><span style=\"color: #56a5e4\">( <\/span><span style=\"color: #cccccc\">lo_pattern<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> )-&gt;<\/span><span style=\"color: #cccccc\">row_stream<\/span><span style=\"color: #56a5e4\">(<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> )-&gt;<\/span><span style=\"color: #cccccc\">operation<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">write_from<\/span><span style=\"color: #56a5e4\">( REF #( <\/span><span style=\"color: #cccccc\">et_result<\/span><span style=\"color: #56a5e4\"> )<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> )-&gt;<\/span><span style=\"color: #cccccc\">execute<\/span><span style=\"color: #56a5e4\">( ).<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> DATA(<\/span><span style=\"color: #cccccc\">ld_excel<\/span><span style=\"color: #56a5e4\">) = <\/span><span style=\"color: #cccccc\">lo_document<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">get_file_content<\/span><span style=\"color: #56a5e4\">( ).<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> DATA(<\/span><span style=\"color: #cccccc\">lv_base64_encoding<\/span><span style=\"color: #56a5e4\">) = <\/span><span style=\"color: #cccccc\">xco_cp<\/span><span style=\"color: #56a5e4\">=&gt;<\/span><span style=\"color: #cccccc\">xstring<\/span><span style=\"color: #56a5e4\">( <\/span><span style=\"color: #cccccc\">ld_excel<\/span><span style=\"color: #56a5e4\"> )-&gt;<\/span><span style=\"color: #cccccc\">as_string<\/span><span style=\"color: #56a5e4\">( <\/span><span style=\"color: #cccccc\">xco_cp_binary<\/span><span style=\"color: #56a5e4\">=&gt;<\/span><span style=\"color: #cccccc\">text_encoding<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">base64<\/span><span style=\"color: #56a5e4\"> )-&gt;<\/span><span style=\"color: #cccccc\">value<\/span><span style=\"color: #56a5e4\">.<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">es_res<\/span><span style=\"color: #56a5e4\">&#8211;<\/span><span style=\"color: #cccccc\">file_content<\/span><span style=\"color: #56a5e4\"> = <\/span><span style=\"color: #cccccc\">lv_base64_encoding<\/span><span style=\"color: #56a5e4\">.<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> APPEND <\/span><span style=\"color: #cccccc\">es_res<\/span><span style=\"color: #56a5e4\"> TO <\/span><span style=\"color: #cccccc\">et_res<\/span><span style=\"color: #56a5e4\">.<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> IF <\/span><span style=\"color: #cccccc\">io_request<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">is_total_numb_of_rec_requested<\/span><span style=\"color: #56a5e4\">( ).<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">io_response<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">set_total_number_of_records<\/span><span style=\"color: #56a5e4\">( <\/span><span style=\"color: #cccccc\">lines<\/span><span style=\"color: #56a5e4\">( <\/span><span style=\"color: #cccccc\">et_res<\/span><span style=\"color: #56a5e4\"> ) ).<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> ENDIF.<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> IF <\/span><span style=\"color: #cccccc\">io_request<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">is_data_requested<\/span><span style=\"color: #56a5e4\">( ).<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> <\/span><span style=\"color: #cccccc\">io_response<\/span><span style=\"color: #56a5e4\">-&gt;<\/span><span style=\"color: #cccccc\">set_data<\/span><span style=\"color: #56a5e4\">( <\/span><span style=\"color: #cccccc\">et_res<\/span><span style=\"color: #56a5e4\"> ).<\/span><\/p>\n<p style=\"background-color: #292929;margin: 0\"><span style=\"color: #56a5e4\"> ENDIF.<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\"> ENDMETHOD.<\/span><\/p>\n<p style=\"margin: 0\"><span style=\"color: #56a5e4\">ENDCLASS.<\/span><\/p>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Now activate the class and expose it the service definition and at last create a web API v4 and pass the URL to the front person to fetch and download the excel sheet.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[173],"question_tags":[178,201,199,200,177],"class_list":["post-7759","question","type-question","status-publish","hentry","question-category-cdsviews","question_tags-abap","question_tags-btp","question_tags-cds","question_tags-rap","question_tags-sap"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7759","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question"}],"about":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7759"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7759"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7759"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}