<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Capturing ALV layout converting it into XLS file in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678071#M2016767</link>
    <description>&lt;P&gt;Okay I think you have to concatenate the fixed structure dynamically into x_attachment-line according to the position of columns in the layout of ALV-grid. So you need a list with fieldnames of the column in order by position. In other words you need an actual fieldcatalog.&lt;/P&gt;&lt;P&gt;You can get the fieldcatalog in this way like my example describes. On the other hand you can get the actual fieldcatalog according to the layout also using FM LT_DBDATA_READ_FROM_LTDX. &lt;/P&gt;&lt;P&gt;At first you fetch an LVC-fieldcatalog for your structure using FM LVC_FIELDCATALOG_MERGE. After that you can synchronize it with the result of  FM LT_DBDATA_READ_FROM_LTDX. And then you can concatenate dynamically using the fieldcatalog.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;  CLEAR gs_ltdx. "gs_ltdx like structure LTDX&lt;BR /&gt;  SELECT SINGLE * FROM ltdx INTO gs_ltdx&lt;BR /&gt;    WHERE relid = 'LT'&lt;BR /&gt;    AND report = sy-repid&lt;BR /&gt;    AND variant = p_vari.  "contains name of layout&lt;BR /&gt;  MOVE-CORRESPONDING gs_ltdx TO gs_varkey.&lt;BR /&gt;&lt;BR /&gt;  CALL FUNCTION 'LT_DBDATA_READ_FROM_LTDX'&lt;BR /&gt;    EXPORTING&lt;BR /&gt;*     I_TOOL       = 'LT'&lt;BR /&gt;      is_varkey    = gs_varkey  "gs_varkey is like structure LTDXKEY&lt;BR /&gt;    TABLES&lt;BR /&gt;      t_dbfieldcat = gt_dbfcat "Note: this is not a LVC-fieldcatalog, gt_dbfcat is table with structure LTXDATA&lt;BR /&gt;*     T_DBSORTINFO =&lt;BR /&gt;*     T_DBFILTER   =&lt;BR /&gt;*     T_DBLAYOUT   =&lt;BR /&gt;    EXCEPTIONS&lt;BR /&gt;      not_found    = 1&lt;BR /&gt;      wrong_relid  = 2&lt;BR /&gt;      OTHERS       = 3.&lt;BR /&gt;  IF sy-subrc &amp;lt;&amp;gt; 0.&lt;BR /&gt;* Implement suitable error handling here&lt;BR /&gt;  ENDIF.&lt;BR /&gt;&lt;BR /&gt;* Synchronize LVC-fieldcatalog by fieldcatalog from layout&lt;BR /&gt;  DELETE gt_dbfcat WHERE param NE 'COL_POS' AND param NE 'NO_OUT'.&lt;BR /&gt;&lt;BR /&gt;  LOOP AT gt_dbfcat ASSIGNING FIELD-SYMBOL(&amp;lt;dbfcat&amp;gt;).&lt;BR /&gt;    READ TABLE gt_fieldcat ASSIGNING FIELD-SYMBOL(&amp;lt;fcat&amp;gt;)  "LVC-fieldcatalog getting before with FM LVC_FIELDCATALOG_MERGE &lt;BR /&gt;    WITH KEY fieldname = &amp;lt;dbfcat&amp;gt;-key1.&lt;BR /&gt;    IF sy-subrc EQ 0.&lt;BR /&gt;      ASSIGN COMPONENT &amp;lt;dbfcat&amp;gt;-param OF STRUCTURE &amp;lt;fcat&amp;gt; TO &amp;lt;target&amp;gt;.&lt;BR /&gt;      &amp;lt;target&amp;gt; = &amp;lt;dbfcat&amp;gt;-value.&lt;BR /&gt;    ENDIF.&lt;BR /&gt;  ENDLOOP.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 17 May 2023 04:04:55 GMT</pubDate>
    <dc:creator>jens_michaelsen</dc:creator>
    <dc:date>2023-05-17T04:04:55Z</dc:date>
    <item>
      <title>Capturing ALV layout converting it into XLS file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678067#M2016763</link>
      <description>&lt;P&gt;Hi, this local file button were able to capture the current column layout of the ALV. Now, I was able to save in a layout in a variant named ZALV_LOUT1.&lt;/P&gt;
  &lt;P&gt;I'm trying to do is&lt;/P&gt;
  &lt;P&gt;SA38: Execute the program for displaying this ALV&amp;gt; Input the variant, and input the email address in the field wherein the report in XLS/Excel file will be sent&amp;gt; Execute(When executed, the column positions of ALV should be the same in the XLS file&amp;gt; Then the will be displayed.&lt;/P&gt;
  &lt;P&gt;The default layout of ALV:&lt;/P&gt;
  &lt;P&gt;Student# | Name | Address | Age&lt;/P&gt;
  &lt;P&gt;Layout of ALV in variant ZALV_LOUT1:&lt;/P&gt;
  &lt;P&gt;Name | Student # | Age | Address.&lt;/P&gt;
  &lt;P&gt;When saving the alv into the local file, the layout is correct but when sending it into my email, it is not.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 10:01:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678067#M2016763</guid>
      <dc:creator>walkerist79</dc:creator>
      <dc:date>2023-05-16T10:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing ALV layout converting it into XLS file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678068#M2016764</link>
      <description>&lt;P&gt;I understand, that you want to write a report with 2 input fields. One input field for layout of alv-grid, one input field for e-mail adress. When the report is executed, you want to send an excel file with data and the positions of the columns according to the layout.&lt;/P&gt;&lt;P&gt;You can build an excel file using classes CL_SALV_EX_UTIL=&amp;gt;FACTORY_RESULT_DATA_TABLE and CL_SALV_BS_LEX=&amp;gt;EXPORT_FROM_RESULT_DATA_TABLE. &lt;/P&gt;&lt;P&gt;For CL_SALV_EX_UTIL=&amp;gt;FACTORY_RESULT_DATA_TABLE you need the data and an actual fieldcatalog, which describes the positions of the columns. &lt;/P&gt;&lt;P&gt;If you are use the FM REUSE_ALV_GRID_DISPLAY in your report, you get the fieldcatalog (and the data) using the methods of the class CL_SALV_BS_RUNTIME_INFO. You can use this class, if you start your original report by a second report per SUBMIT.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FIELD-SYMBOLS &amp;lt;fs_itab&amp;gt; TYPE STANDARD TABLE.&lt;BR /&gt;&lt;BR /&gt;    cl_salv_bs_runtime_info=&amp;gt;set(&lt;BR /&gt;    display  = abap_false    "supress display of alv_grid&lt;BR /&gt;    metadata = abap_true&lt;BR /&gt;    data     = abap_true ).&lt;BR /&gt;&lt;BR /&gt;    SUBMIT my_report_with_reuse_alv_grid_display USING SELECTION-SCREEN '1000'&lt;BR /&gt;          WITH p_vari = p_vari   "name of the layout&lt;BR /&gt;    AND RETURN.&lt;BR /&gt;&lt;BR /&gt;    TRY.&lt;BR /&gt;        cl_salv_bs_runtime_info=&amp;gt;get_data_ref(&lt;BR /&gt;        IMPORTING r_data = DATA(gr_alv_itab) ).&lt;BR /&gt;&lt;BR /&gt;        ASSIGN gr_alv_itab-&amp;gt;* TO &amp;lt;fs_itab&amp;gt;.&lt;BR /&gt;        DATA(gs_meta) = cl_salv_bs_runtime_info=&amp;gt;get_metadata( ).&lt;BR /&gt;        cl_salv_bs_runtime_info=&amp;gt;clear_all( ).&lt;BR /&gt;&lt;BR /&gt;        DATA(go_salv_ex_res) = cl_salv_ex_util=&amp;gt;factory_result_data_table( r_data          = REF #( &amp;lt;fs_itab&amp;gt; )&lt;BR /&gt;                                                                          t_fieldcatalog  = gs_meta-t_fcat ).&lt;BR /&gt;        DATA:gv_xls TYPE xstring.&lt;BR /&gt;        cl_salv_bs_lex=&amp;gt;export_from_result_data_table( EXPORTING&lt;BR /&gt;                                                         is_format            = if_salv_bs_lex_format=&amp;gt;mc_format_xlsx&lt;BR /&gt;                                                         ir_result_data_table = go_salv_ex_res&lt;BR /&gt;                                                       IMPORTING&lt;BR /&gt;                                                         er_result_file       = gv_xls ).&lt;BR /&gt;&lt;BR /&gt;        PERFORM send_mail USING p_email         "mailadress&lt;BR /&gt;                           'Hello world'        "mail content&lt;BR /&gt;                                  gv_xls .      "excel as xstring for attachment &lt;BR /&gt;&lt;BR /&gt;      CATCH cx_root INTO DATA(e_txt).&lt;BR /&gt;        MESSAGE e_txt-&amp;gt;get_text( ) TYPE 'S'.&lt;BR /&gt;    ENDTRY.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 May 2023 10:50:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678068#M2016764</guid>
      <dc:creator>jens_michaelsen</dc:creator>
      <dc:date>2023-05-16T10:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing ALV layout converting it into XLS file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678069#M2016765</link>
      <description>&lt;P&gt;Thanks for this and for the effort. &lt;/P&gt;&lt;P&gt;I'm trying to fix an existing program that were already able to send the attachment in .XLS format when the program is executed and before the ALV shows up on screen. However, I'm having trouble on how the xls is built.&lt;/P&gt;&lt;P&gt;My details is found in table T_FINAL_DATA, and were looped into X_FINAL_DATA. However my T_FINAL_DATA table were coded like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA:begin of t_data  occurs 0&lt;BR /&gt;        werks like ekpo-werks,&lt;BR /&gt;        eindt like ekes-eindt,&lt;BR /&gt;        uzeit like ekes-uzeit,&lt;BR /&gt;        slfdt TYPE eket-slfdt,&lt;BR /&gt;        ekgrp like ekko-ekgrp.&lt;BR /&gt;     end of t_data.&lt;BR /&gt;LOOP AT t_data INTO x_data .&lt;BR /&gt;  MOVE-CORRESPONDING x_data  TO x_data_final .&lt;BR /&gt;  APPEND x_data_final  TO t_data_final .&lt;BR /&gt;ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;CONCATENATE &lt;/P&gt;&lt;P&gt;x_data_final-werks&lt;/P&gt;&lt;P&gt;x_data_final-eindt&lt;/P&gt;&lt;P&gt;x_data_final-uzeit&lt;/P&gt;&lt;P&gt;x_data_final-slfdt&lt;/P&gt;&lt;P&gt;x_data_final-ekgrp&lt;/P&gt;&lt;P&gt;INTO x_attachment-line SEPARATED BY '#'.&lt;BR /&gt;APPEND x_attachment TO t_attachment.&lt;/P&gt;&lt;P&gt;Then this t_attachment were used to some FM *XSTRING* to build the XLS.&lt;/P&gt;&lt;P&gt;My dilemna is sometimes the UZEIT is first in column in ALV however, in the attachment, the WERKS is still the first. Is it because of how is it concatenated? if yes, what is the possible solution?&lt;/P&gt;&lt;P&gt;x_data_final-werks&lt;/P&gt;&lt;P&gt;x_data_final-eindt&lt;/P&gt;&lt;P&gt;x_data_final-uzeit&lt;/P&gt;&lt;P&gt;x_data_final-slfdt&lt;/P&gt;&lt;P&gt;x_data_final-ekgrp&lt;/P&gt;&lt;P&gt;CONCATENATE &lt;/P&gt;&lt;P&gt;x_data_final-werks &lt;/P&gt;&lt;P&gt;x_data_final-eindt &lt;/P&gt;&lt;P&gt;x_data_final-uzeit &lt;/P&gt;&lt;P&gt;x_data_final-slfdt &lt;/P&gt;&lt;P&gt;x_data_final-ekgrp &lt;BR /&gt;INTO x_attachment-line SEPARATED BY lc_tab. &lt;BR /&gt;APPEND x_attachment TO t_attachment.&lt;/P&gt;&lt;P&gt;Then this t_attachment were used to some FM *XSTRING* to build the XLS.&lt;/P&gt;&lt;P&gt;My dilemna is sometimes the UZEIT is first in column in ALV however, in the attachment, the WERKS is still the first. Is it because of how is it concatenated? if yes, what is the possible solution?&lt;/P&gt;&lt;P&gt;x_data_final-werks&lt;/P&gt;&lt;P&gt;x_data_final-eindt&lt;/P&gt;&lt;P&gt;x_data_final-uzeit&lt;/P&gt;&lt;P&gt;x_data_final-slfdt&lt;/P&gt;&lt;P&gt;x_data_final-ekgrp&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 14:46:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678069#M2016765</guid>
      <dc:creator>walkerist79</dc:creator>
      <dc:date>2023-05-16T14:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing ALV layout converting it into XLS file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678070#M2016766</link>
      <description>&lt;P&gt;What I thought is this:&lt;/P&gt;&lt;P&gt;MOVE x_data_final TO X_ATTACHMENT-LINE.&lt;/P&gt;&lt;P&gt;However, the arrangement of x_data_final is not aligned with the alv column layout.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 14:54:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678070#M2016766</guid>
      <dc:creator>walkerist79</dc:creator>
      <dc:date>2023-05-16T14:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing ALV layout converting it into XLS file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678071#M2016767</link>
      <description>&lt;P&gt;Okay I think you have to concatenate the fixed structure dynamically into x_attachment-line according to the position of columns in the layout of ALV-grid. So you need a list with fieldnames of the column in order by position. In other words you need an actual fieldcatalog.&lt;/P&gt;&lt;P&gt;You can get the fieldcatalog in this way like my example describes. On the other hand you can get the actual fieldcatalog according to the layout also using FM LT_DBDATA_READ_FROM_LTDX. &lt;/P&gt;&lt;P&gt;At first you fetch an LVC-fieldcatalog for your structure using FM LVC_FIELDCATALOG_MERGE. After that you can synchronize it with the result of  FM LT_DBDATA_READ_FROM_LTDX. And then you can concatenate dynamically using the fieldcatalog.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;  CLEAR gs_ltdx. "gs_ltdx like structure LTDX&lt;BR /&gt;  SELECT SINGLE * FROM ltdx INTO gs_ltdx&lt;BR /&gt;    WHERE relid = 'LT'&lt;BR /&gt;    AND report = sy-repid&lt;BR /&gt;    AND variant = p_vari.  "contains name of layout&lt;BR /&gt;  MOVE-CORRESPONDING gs_ltdx TO gs_varkey.&lt;BR /&gt;&lt;BR /&gt;  CALL FUNCTION 'LT_DBDATA_READ_FROM_LTDX'&lt;BR /&gt;    EXPORTING&lt;BR /&gt;*     I_TOOL       = 'LT'&lt;BR /&gt;      is_varkey    = gs_varkey  "gs_varkey is like structure LTDXKEY&lt;BR /&gt;    TABLES&lt;BR /&gt;      t_dbfieldcat = gt_dbfcat "Note: this is not a LVC-fieldcatalog, gt_dbfcat is table with structure LTXDATA&lt;BR /&gt;*     T_DBSORTINFO =&lt;BR /&gt;*     T_DBFILTER   =&lt;BR /&gt;*     T_DBLAYOUT   =&lt;BR /&gt;    EXCEPTIONS&lt;BR /&gt;      not_found    = 1&lt;BR /&gt;      wrong_relid  = 2&lt;BR /&gt;      OTHERS       = 3.&lt;BR /&gt;  IF sy-subrc &amp;lt;&amp;gt; 0.&lt;BR /&gt;* Implement suitable error handling here&lt;BR /&gt;  ENDIF.&lt;BR /&gt;&lt;BR /&gt;* Synchronize LVC-fieldcatalog by fieldcatalog from layout&lt;BR /&gt;  DELETE gt_dbfcat WHERE param NE 'COL_POS' AND param NE 'NO_OUT'.&lt;BR /&gt;&lt;BR /&gt;  LOOP AT gt_dbfcat ASSIGNING FIELD-SYMBOL(&amp;lt;dbfcat&amp;gt;).&lt;BR /&gt;    READ TABLE gt_fieldcat ASSIGNING FIELD-SYMBOL(&amp;lt;fcat&amp;gt;)  "LVC-fieldcatalog getting before with FM LVC_FIELDCATALOG_MERGE &lt;BR /&gt;    WITH KEY fieldname = &amp;lt;dbfcat&amp;gt;-key1.&lt;BR /&gt;    IF sy-subrc EQ 0.&lt;BR /&gt;      ASSIGN COMPONENT &amp;lt;dbfcat&amp;gt;-param OF STRUCTURE &amp;lt;fcat&amp;gt; TO &amp;lt;target&amp;gt;.&lt;BR /&gt;      &amp;lt;target&amp;gt; = &amp;lt;dbfcat&amp;gt;-value.&lt;BR /&gt;    ENDIF.&lt;BR /&gt;  ENDLOOP.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2023 04:04:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678071#M2016767</guid>
      <dc:creator>jens_michaelsen</dc:creator>
      <dc:date>2023-05-17T04:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing ALV layout converting it into XLS file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678072#M2016768</link>
      <description>&lt;P&gt; &lt;SPAN class="mention-scrubbed"&gt;jens_michaelsen&lt;/SPAN&gt; Thanks! But I'm not familiar on the the data types of the following:&lt;/P&gt;&lt;P&gt;gs_ltdx like LTDX&lt;/P&gt;&lt;P&gt;gs_varkey  like LTDXKEY&lt;/P&gt;&lt;P&gt;gt_dbfcat &amp;lt;--I'm not sure how to declare this. This is what I did: gt_dbfcat LIKE TABLE OF LTDXDATA.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 05:45:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678072#M2016768</guid>
      <dc:creator>walkerist79</dc:creator>
      <dc:date>2023-05-17T05:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing ALV layout converting it into XLS file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678073#M2016769</link>
      <description>&lt;P&gt;I'm encountering issues with LT_DBDATA_READ_FROM_LTDX. It returns a result of "WRONG_RELID". How do I know why does that happen?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;  DATA: gs_varkey LIKE LTDXKEY,&lt;BR /&gt;        gt_dbfcat LIKE TABLE OF LTDXDATA.&lt;BR /&gt;  DATA: lt_fieldcat_fg TYPE STANDARD TABLE OF ltdxdata.&lt;BR /&gt;  SELECT *&lt;BR /&gt;    FROM ltdx&lt;BR /&gt;    INTO @DATA(ls_ltdx)&lt;BR /&gt;    UP TO 1 ROWS&lt;BR /&gt;    WHERE relid = 'LT'&lt;BR /&gt;    AND report = @sy-repid&lt;BR /&gt;    AND variant = @p_layout.&lt;BR /&gt;  ENDSELECT.&lt;BR /&gt;  IF sy-subrc = 0.&lt;BR /&gt;    DATA(ls_varkey_fg) = CORRESPONDING ltdxkey( ls_ltdx ).&lt;BR /&gt;    CALL FUNCTION 'LT_DBDATA_READ_FROM_LTDX'&lt;BR /&gt;      EXPORTING&lt;BR /&gt;        i_tool       = 'LT'&lt;BR /&gt;        is_varkey    = ls_varkey_fg &lt;BR /&gt;      TABLES&lt;BR /&gt;        t_dbfieldcat = lt_fieldcat_fg&lt;BR /&gt;      EXCEPTIONS&lt;BR /&gt;        not_found    = 1&lt;BR /&gt;        wrong_relid  = 2&lt;BR /&gt;        OTHERS       = 3.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2023 12:20:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/capturing-alv-layout-converting-it-into-xls-file/m-p/12678073#M2016769</guid>
      <dc:creator>walkerist79</dc:creator>
      <dc:date>2023-05-17T12:20:44Z</dc:date>
    </item>
  </channel>
</rss>

