<?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: Alv Variant in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-variant/m-p/3756021#M903605</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please refer the code below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
PARAMETERS: sp_vari LIKE disvariant-variant.        "Dispaly Variant

* Data for ALV variant
DATA  gv_repname          LIKE sy-repid.
DATA  gv_x_variant        LIKE disvariant.
DATA  gv_exit(1)          TYPE c.
DATA  gv_save(1)          TYPE c.
DATA  gv_variant          LIKE disvariant.

INITIALIZATION.

  PERFORM f_initialize_variant.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR sp_vari.
  PERFORM f_f4_for_variant.

AT SELECTION-SCREEN.

*  Validating selection screen fields
  PERFORM f_at_selection_screen.


FORM f_initialize_variant .

  CLEAR gv_variant.
  gv_save           = 'X'.
  gv_variant-report = gv_repname.
  gv_x_variant      = gv_variant.

  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save     = gv_save
    CHANGING
      cs_variant = gv_x_variant
    EXCEPTIONS
      not_found  = 2.

  IF sy-subrc = 0.

    sp_vari = gv_x_variant-variant.

  ENDIF.

ENDFORM.                    " f_initialize_variant

FORM f_f4_for_variant .
  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
    EXPORTING
      is_variant = gv_variant
      i_save     = gv_save
    IMPORTING
      e_exit     = gv_exit
      es_variant = gv_x_variant
    EXCEPTIONS
      not_found  = 2.

  IF sy-subrc = 2.
    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    IF gv_exit = space.
      sp_vari = gv_x_variant-variant.
    ENDIF.
  ENDIF.

ENDFORM.                    " f_f4_for_variant

FORM f_at_selection_screen .

* ALV Layout variant
  IF NOT sp_vari IS INITIAL.

    MOVE gv_variant TO gv_x_variant.
    MOVE sp_vari    TO gv_x_variant-variant.

    CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
      EXPORTING
        i_save     = gv_save
      CHANGING
        cs_variant = gv_x_variant.
    gv_variant = gv_x_variant.

  ELSE.

    PERFORM f_initialize_variant.

  ENDIF.

ENDFORM.                    " f_at_selection_screen
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sriram Ponna.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 24 Apr 2008 14:07:43 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-04-24T14:07:43Z</dc:date>
    <item>
      <title>Alv Variant</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-variant/m-p/3756018#M903602</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to save data into an excel file according to the variant selected. if that variant contains 4 fields out of 10, then those 4 fields should only be in that excel file. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;how to get the field names being used in that particular variant?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;ANUPAM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 13:58:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-variant/m-p/3756018#M903602</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T13:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: Alv Variant</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-variant/m-p/3756019#M903603</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have to use a FM to get the current field catalog and then create a dynamic table which should be passed to the excel function module&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 14:02:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-variant/m-p/3756019#M903603</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T14:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: Alv Variant</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-variant/m-p/3756020#M903604</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;method GET_FRONTEND_FIELDCATALOG&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and then something like this:&lt;/P&gt;&lt;P&gt;LOOP AT G_T_FIELDCAT INTO G_R_FIELDCAT WHERE NO_OUT NE 'X'&lt;/P&gt;&lt;P&gt;AND TECH IS INITIAL&lt;/P&gt;&lt;P&gt;AND FIELDNAME NE 'ICON'.&lt;/P&gt;&lt;P&gt;MOVE-CORRESPONDING G_R_FIELDCAT TO IS_FIELDCAT.&lt;/P&gt;&lt;P&gt;IS_FIELDCAT-FIELDNAME = G_R_FIELDCAT-FIELDNAME.&lt;/P&gt;&lt;P&gt;IS_FIELDCAT-INTTYPE = G_R_FIELDCAT-INTTYPE.&lt;/P&gt;&lt;P&gt;IS_FIELDCAT-OUTPUTLEN = G_R_FIELDCAT-OUTPUTLEN.&lt;/P&gt;&lt;P&gt;IS_FIELDCAT-REF_FIELD = G_R_FIELDCAT-FIELDNAME.&lt;/P&gt;&lt;P&gt;IS_FIELDCAT-REF_TABLE = G_R_FIELDCAT-REF_TABNAME.&lt;/P&gt;&lt;P&gt;APPEND IS_FIELDCAT TO IT_FIELDCAT.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: WA_LISTE LIKE P_T_LISTE.&lt;/P&gt;&lt;P&gt;CLEAR:IT_OUTTAB.&lt;/P&gt;&lt;P&gt;REFRESH: IT_OUTTAB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT P_T_LISTE INTO WA_LISTE.&lt;/P&gt;&lt;P&gt;WA_OUTTAB-PSPID = WA_LISTE-PSPID .&lt;/P&gt;&lt;P&gt;WA_OUTTAB-POSID = WA_LISTE-POSID.&lt;/P&gt;&lt;P&gt;WA_OUTTAB-POST1 = WA_LISTE-POST1.&lt;/P&gt;&lt;P&gt;WA_OUTTAB-STTXT_INT = WA_LISTE-STTXT_INT.&lt;/P&gt;&lt;P&gt;WA_OUTTAB-STTXT_EXT = WA_LISTE-STTXT_EXT.&lt;/P&gt;&lt;P&gt;APPEND WA_OUTTAB TO IT_OUTTAB.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;**dynamic table creation for data&lt;/P&gt;&lt;P&gt;ASSIGN LT_DATA TO &amp;lt;FS_DATA&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Create a new Table &lt;/P&gt;&lt;P&gt;CALL METHOD CL_ALV_TABLE_CREATE=&amp;gt;CREATE_DYNAMIC_TABLE&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;IT_FIELDCATALOG = IT_FIELDCAT&lt;/P&gt;&lt;P&gt;IMPORTING&lt;/P&gt;&lt;P&gt;EP_TABLE = &amp;lt;FS_DATA&amp;gt;&lt;/P&gt;&lt;P&gt;EXCEPTIONS&lt;/P&gt;&lt;P&gt;GENERATE_SUBPOOL_DIR_FULL = 1&lt;/P&gt;&lt;P&gt;OTHERS = 2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF SY-SUBRC = 0.&lt;/P&gt;&lt;P&gt;ASSIGN &amp;lt;FS_DATA&amp;gt;-&amp;gt;* TO &amp;lt;FS_1&amp;gt;.&lt;/P&gt;&lt;P&gt;CREATE DATA NEW_LINE LIKE LINE OF &amp;lt;FS_1&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A field-symbol to access that work area &lt;/P&gt;&lt;P&gt;ASSIGN NEW_LINE-&amp;gt;* TO &amp;lt;FS_2&amp;gt;.&lt;/P&gt;&lt;P&gt;**MOVE DATA&lt;/P&gt;&lt;P&gt;LOOP AT IT_OUTTAB INTO WA_OUTTAB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT'&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;INPUT = WA_OUTTAB-PSPID&lt;/P&gt;&lt;P&gt;IMPORTING&lt;/P&gt;&lt;P&gt;OUTPUT = WA_OUTTAB-PSPID.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT'&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;INPUT = WA_OUTTAB-POSID&lt;/P&gt;&lt;P&gt;IMPORTING&lt;/P&gt;&lt;P&gt;OUTPUT = WA_OUTTAB-POSID.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT G_T_FIELDCAT INTO G_R_FIELDCAT&lt;/P&gt;&lt;P&gt;WHERE NO_OUT IS INITIAL&lt;/P&gt;&lt;P&gt;AND TECH IS INITIAL.&lt;/P&gt;&lt;P&gt;ASSIGN COMPONENT G_R_FIELDCAT-FIELDNAME OF STRUCTURE&lt;/P&gt;&lt;P&gt;WA_OUTTAB TO &amp;lt;FS_5&amp;gt;.&lt;/P&gt;&lt;P&gt;ASSIGN COMPONENT G_R_FIELDCAT-FIELDNAME OF STRUCTURE&lt;/P&gt;&lt;P&gt;&amp;lt;FS_2&amp;gt; TO &amp;lt;FS_3&amp;gt;.&lt;/P&gt;&lt;P&gt;&amp;lt;FS_3&amp;gt; = &amp;lt;FS_5&amp;gt;.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;INSERT &amp;lt;FS_2&amp;gt; INTO TABLE &amp;lt;FS_1&amp;gt;.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;ELSE.&lt;/P&gt;&lt;P&gt;MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO&lt;/P&gt;&lt;P&gt;WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 14:07:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-variant/m-p/3756020#M903604</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T14:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: Alv Variant</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-variant/m-p/3756021#M903605</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please refer the code below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
PARAMETERS: sp_vari LIKE disvariant-variant.        "Dispaly Variant

* Data for ALV variant
DATA  gv_repname          LIKE sy-repid.
DATA  gv_x_variant        LIKE disvariant.
DATA  gv_exit(1)          TYPE c.
DATA  gv_save(1)          TYPE c.
DATA  gv_variant          LIKE disvariant.

INITIALIZATION.

  PERFORM f_initialize_variant.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR sp_vari.
  PERFORM f_f4_for_variant.

AT SELECTION-SCREEN.

*  Validating selection screen fields
  PERFORM f_at_selection_screen.


FORM f_initialize_variant .

  CLEAR gv_variant.
  gv_save           = 'X'.
  gv_variant-report = gv_repname.
  gv_x_variant      = gv_variant.

  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save     = gv_save
    CHANGING
      cs_variant = gv_x_variant
    EXCEPTIONS
      not_found  = 2.

  IF sy-subrc = 0.

    sp_vari = gv_x_variant-variant.

  ENDIF.

ENDFORM.                    " f_initialize_variant

FORM f_f4_for_variant .
  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
    EXPORTING
      is_variant = gv_variant
      i_save     = gv_save
    IMPORTING
      e_exit     = gv_exit
      es_variant = gv_x_variant
    EXCEPTIONS
      not_found  = 2.

  IF sy-subrc = 2.
    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    IF gv_exit = space.
      sp_vari = gv_x_variant-variant.
    ENDIF.
  ENDIF.

ENDFORM.                    " f_f4_for_variant

FORM f_at_selection_screen .

* ALV Layout variant
  IF NOT sp_vari IS INITIAL.

    MOVE gv_variant TO gv_x_variant.
    MOVE sp_vari    TO gv_x_variant-variant.

    CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
      EXPORTING
        i_save     = gv_save
      CHANGING
        cs_variant = gv_x_variant.
    gv_variant = gv_x_variant.

  ELSE.

    PERFORM f_initialize_variant.

  ENDIF.

ENDFORM.                    " f_at_selection_screen
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sriram Ponna.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 14:07:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-variant/m-p/3756021#M903605</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T14:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Alv Variant</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-variant/m-p/3756022#M903606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt; Thanks for your answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But the problem is the existing code is totally developed using function modules.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is there any function module to get the layout fields informations.&lt;/P&gt;&lt;P&gt;i've tried with REUSE_ALV_GRID_LAYOUT_INFO_GET, but it's returning the original fieldcatalog.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;ANUPAM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2008 06:06:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-variant/m-p/3756022#M903606</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-25T06:06:10Z</dc:date>
    </item>
    <item>
      <title>Re: Alv Variant</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-variant/m-p/3756023#M903607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I am not wrong you want to download only those columns to excel which is currently shown on the screen. For this first identify the code where you populate the table to send to the excel download function module(eg. gui_download). Then using the ALV object and the method get_frontend_fieldcatalog get the current layout of rows and columns. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL METHOD alvobj-&amp;gt;get_frontend_fieldcatalog&lt;/P&gt;&lt;P&gt;IMPORTING&lt;/P&gt;&lt;P&gt;ET_FIELDCATALOG = i_field_catalog.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After you get this leverage the logic mentioned in my previous post to populate the itab which you send to the excel function module. &lt;/P&gt;&lt;P&gt;This code might be different than the normal alv display code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Aparna&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2008 12:58:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-variant/m-p/3756023#M903607</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-25T12:58:52Z</dc:date>
    </item>
  </channel>
</rss>

