Skip to Content
-3
Jun 10 at 06:34 AM

Two different conditions for ALV and Excel output

46 Views Last edit Jun 10 at 07:23 AM 4 rev

Hello.

I have a job to make Selection screen with two radio buttons for ALV and Excel output and there are two different conditions for every output with different columns. How to make two different outputs? Now it`s making all of two outputs in one viev.

Here`s my code:


*&---------------------------------------------------------------------*

*& Report  ZTASK2_REPORT

*&---------------------------------------------------------------------*



REPORT ztask2_report.



TABLES: aufm, caufv.



TYPES: BEGIN OF my_tab,

  mblnr TYPE aufm-mblnr,

  matnr TYPE aufm-matnr,

  shkzg TYPE aufm-shkzg,

  menge TYPE aufm-menge,

  dmbtr TYPE aufm-dmbtr,

  ktext TYPE caufv-ktext,

  erdat TYPE caufv-erdat,

  auart TYPE caufv-auart,

END OF my_tab.



DATA: gt_aufmcaufv TYPE TABLE OF my_tab.



***Excel

DATA:

  lo_table TYPE REF TO cl_salv_table,

  lx_xml   TYPE xstring.

***



SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: a_bldat FOR aufm-bldat.

PARAMETERS: rg_op1 RADIOBUTTON GROUP opx DEFAULT 'X'. "ALV

PARAMETERS: rg_op2 RADIOBUTTON GROUP opx.             "Excel

SELECTION-SCREEN END OF BLOCK bl1.



START-OF-SELECTION.



***

  IF rg_op1 EQ 'X'. "ALV



    SELECT

      au~mblnr

      au~matnr

      au~shkzg

      au~menge

      au~dmbtr

      au~bldat

      au~aufnr

      ca~ktext

      ca~auart

      ca~erdat

      ca~aufnr

    INTO CORRESPONDING FIELDS OF TABLE gt_aufmcaufv

    FROM

          aufm AS au

    INNER JOIN

          caufv AS ca

    ON

      au~bldat = ca~erdat

    WHERE

      au~aufnr = ca~aufnr

      AND

      ca~auart = 'PI01'.



  ELSEIF rg_op2 EQ 'X'. "Excel



    SELECT

      au~matnr

      au~menge

      au~dmbtr

    INTO CORRESPONDING FIELDS OF TABLE gt_aufmcaufv

    FROM

          aufm AS au

    INNER JOIN

          caufv AS ca

    ON

      au~bldat = ca~erdat

      WHERE

        au~shkzg = 'S'.



  ENDIF.



***



  IF rg_op1 EQ 'X'. "ALV



    PERFORM display_alv.



  ELSEIF rg_op2 EQ 'X'. "Excel



    TRY.

        cl_salv_table=>factory(

        IMPORTING

          r_salv_table = lo_table

        CHANGING

          t_table      = gt_aufmcaufv ).   "my table

      CATCH cx_salv_msg.

    ENDTRY.



    lx_xml = lo_table->to_xml( xml_type = '10' ). "XLSX



    CALL FUNCTION 'XML_EXPORT_DIALOG'

      EXPORTING

        i_xml                      = lx_xml

        i_default_extension        = 'XLSX'

        i_initial_directory        = ''

        i_default_file_name        = 'export.XLSX'

        i_mask                     = 'Excel (*.XLSX)|*.XLSX'

      EXCEPTIONS

        application_not_executable = 1

        OTHERS                     = 2.



  ENDIF.



END-OF-SELECTION.



*** Form display_alv



FORM display_alv.



  DATA:

       gc_alv_table TYPE REF TO cl_salv_table,

       gc_functions TYPE REF TO cl_salv_functions,

       gc_columns TYPE REF TO cl_salv_columns_table.



  cl_salv_table=>factory(

      IMPORTING r_salv_table = gc_alv_table

      CHANGING t_table = gt_aufmcaufv[]

  ).



  gc_alv_table->display( ).



ENDFORM.                    "display_alv
SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}.L0S31 {
font-style: italic;
color: #808080;
}.L0S32 {
color: #3399FF;
}.L0S33 {
color: #4DA619;
}.L0S52 {
color: #0000FF;
}.L0S55 {
color: #800080;
}.L0S70 {
color: #808080;
}