Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Downloading ALV Report using Layout Variant

Former Member
0 Kudos
1,457

I want to download an Alv grid report output using layout varaint to Presentation server and also wants to mail to user .

i.e...

I am facing a problem in downloading and in sending mail.

My requirement is, user will choose layout variant

As per Variant chosen, i have to download that alv grid output to presentation server and also to mail.

These download and mail sending options is in selction screen

Will rewards to helpfull ans

2 REPLIES 2

Former Member
0 Kudos
299

Hello,

Do like this.


FORM DOWNLOAD_FILE TABLES P_T_LISTE STRUCTURE G_T_LISTE.

  G_R_DISP_VARIANT-REPORT = SY-REPID.
  G_R_DISP_VARIANT-VARIANT = PA_VAR.

  CALL FUNCTION 'REUSE_ALV_VARIANT_SELECT'
       EXPORTING
            I_DIALOG            = 'N'
            I_USER_SPECIFIC     = 'A'
            I_DEFAULT           = 'X'
            IT_DEFAULT_FIELDCAT = G_T_FIELDCAT
            I_LAYOUT            = G_R_LAYOUT
       IMPORTING
            ET_FIELDCAT         = G_T_FIELDCAT
            ES_LAYOUT           = G_R_LAYOUT
       CHANGING
            CS_VARIANT          = G_R_DISP_VARIANT
       EXCEPTIONS
            ERROR_MESSAGE       = 4
            OTHERS              = 4.

  LOOP AT G_T_FIELDCAT INTO G_R_FIELDCAT WHERE NO_OUT NE 'X'
                                           AND TECH IS INITIAL
                                           AND FIELDNAME NE 'ICON'.
    MOVE-CORRESPONDING G_R_FIELDCAT TO IS_FIELDCAT.
    IS_FIELDCAT-FIELDNAME = G_R_FIELDCAT-FIELDNAME.
    IS_FIELDCAT-INTTYPE   = G_R_FIELDCAT-INTTYPE.
    IS_FIELDCAT-OUTPUTLEN = G_R_FIELDCAT-OUTPUTLEN.
    IS_FIELDCAT-REF_FIELD = G_R_FIELDCAT-FIELDNAME.
    IS_FIELDCAT-REF_TABLE = G_R_FIELDCAT-REF_TABNAME.
    APPEND IS_FIELDCAT TO IT_FIELDCAT.
  ENDLOOP.

  DATA: WA_LISTE LIKE P_T_LISTE.
  CLEAR:IT_OUTTAB.
  REFRESH: IT_OUTTAB.

  LOOP AT P_T_LISTE INTO WA_LISTE.
    WA_OUTTAB-PSPID = WA_LISTE-PSPID .
    WA_OUTTAB-POSID = WA_LISTE-POSID.
    WA_OUTTAB-POST1 = WA_LISTE-POST1.
    WA_OUTTAB-STTXT_INT = WA_LISTE-STTXT_INT.
    WA_OUTTAB-STTXT_EXT = WA_LISTE-STTXT_EXT.
    APPEND WA_OUTTAB TO IT_OUTTAB.
  ENDLOOP.
**dynamic table creation for data
  ASSIGN LT_DATA TO <FS_DATA>.

* Create a new Table
  CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
  EXPORTING
        IT_FIELDCATALOG = IT_FIELDCAT
  IMPORTING
        EP_TABLE = <FS_DATA>
  EXCEPTIONS
      GENERATE_SUBPOOL_DIR_FULL = 1
      OTHERS                    = 2.

  IF SY-SUBRC = 0.
    ASSIGN <FS_DATA>->* TO <FS_1>.
    CREATE DATA NEW_LINE LIKE LINE OF <FS_1>.
*** A field-symbol to access that work area
    ASSIGN NEW_LINE->*  TO <FS_2>.
**MOVE DATA
    LOOP AT IT_OUTTAB INTO WA_OUTTAB.

      CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT'
           EXPORTING
                INPUT  = WA_OUTTAB-PSPID
           IMPORTING
                OUTPUT = WA_OUTTAB-PSPID.

      CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT'
           EXPORTING
                INPUT  = WA_OUTTAB-POSID
           IMPORTING
                OUTPUT = WA_OUTTAB-POSID.

      LOOP AT G_T_FIELDCAT INTO G_R_FIELDCAT
                          WHERE NO_OUT IS INITIAL
                            AND TECH IS INITIAL.
        ASSIGN COMPONENT G_R_FIELDCAT-FIELDNAME OF STRUCTURE
                                                WA_OUTTAB TO <FS_5>.
        ASSIGN COMPONENT G_R_FIELDCAT-FIELDNAME OF STRUCTURE
                                                <FS_2> TO <FS_3>.
        <FS_3> = <FS_5>.
      ENDLOOP.
      INSERT <FS_2> INTO TABLE <FS_1>.
    ENDLOOP.
  ELSE.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE.
  IF SY-SUBRC EQ 0.
    LOOP AT <FS_1> ASSIGNING <FS_2>.
      TRANSFER  <FS_2> TO P_FILE.
    ENDLOOP.
  ELSE.
    MESSAGE E041(S9) WITH P_FILE.
  ENDIF.
  CLOSE DATASET P_FILE.
ENDFORM.                    " download_file
* 002 vsm1kor 13.06.06 - en

Regards,

Vasanth

0 Kudos
299

Hi Vasanth,

In this downloading is done for Application server but my requirement is for downloading to Presentation server and for sending Mail.

In this i declare G_R_Fieldcat and G_T_Fieldcat as of same type .but it showing error as G_R_Fieldcat cannot be converted to line type of G_T_Fieldcat.

Data type for P_T_Liste , LT_Data, <FS_Data>, IT_OUTTAB is not known.