Hi developers,

I want to share with you a new way of doing reports. This tool allows you to create reports in 2 minutes. ZQ2R creates quickly reports from a query. The selection screen, selection texts and code are automatically generated.

The ZQ2R code is attached to this post.

An example is shown below.

The Query (SQVI)

After running ZQ2R, press the QuickViewer button

01 - q2r - selection screen.jpg

Here we will create a query to see the flights from New York City.

02 - FlightsFrom_NY.jpg

After you input the query’s name  (FlightsFrom_NY) press the button Create.

In this example we will use the data source “Table join”.

03 - Data source.jpg

Press the insert table button to add the following tables: SPFLI (Flight schedule), SFLIGHT (Flight) and SCARR (Airline).

04 - insert table.jpg

05 - insert table popup.jpg

Once selected the three tables, press the back button (F3).

06 - Data source.jpg

Set the displayed fields and selection fields.

07 - Fields displayed.jpg

After selecting the report fields, you can set the sort sequence.

08 - Sort sequence.jpg

Finally save the query and get the report name.

17 generate program.jpg

10 - Display report name.jpg

11 - Reort name.jpg

ZQ2R

Copy and paste the assigned report (AQ01SYSTQV000001FLIGHTSFROM_NY)

12 - q2r.jpg

After running ZQ2R, set the selection fields behavior.

13 - Selection fields.jpg

You can also define default values ​​by clicking the corresponding check box.

14 - Default Value.jpg

By clicking the “Sel. Text” column you can edit the selection texts.

15 - Selection texts.jpg

Finally press the back button and the zq2r_flightsfrom_ny report will be created!

/wp-content/uploads/2014/05/21_458644.jpg

Now, you can run the newly created report from SE38 transaction

/wp-content/uploads/2014/05/22_458678.jpg

/wp-content/uploads/2014/05/19_458680.jpg

/wp-content/uploads/2014/05/20_458679.jpg

The automatically generated code (zq2r_flightsfrom_ny):

*&—————————————————————–*

*& Report ZQ2R_FLIGHTSFROM_NY

*&—————————————————————–*

REPORT zq2r_flightsfrom_ny.

*&—————————————————————–*

*&  Include ZQ2R_FLIGHTSFROM_NY_TOP

*&—————————————————————–*

CONSTANTS:

  c_cityfr TYPE spfli-cityfrom VALUE ‘NEW YORK’.

TABLES:

  spfli,

  sflight.

TYPES:

  tyr_carrid TYPE RANGE OF spfli-carrid,

  tyr_fldate TYPE RANGE OF sflight-fldate,

  BEGIN OF ty_data,

    cityfrom TYPE spfli-cityfrom,

    cityto   TYPE spfli-cityto,

    carrname TYPE scarr-carrname,

    fldate   TYPE sflight-fldate,

  END OF ty_data,

  tyt_data TYPE STANDARD TABLE OF ty_data.

DATA t_data TYPE STANDARD TABLE OF ty_data.

*&—————————————————————–*

*&  Include ZQ2R_FLIGHTSFROM_NY_SEL

*&—————————————————————–*

SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME.

PARAMETER p_cityfr TYPE spfli-cityfrom DEFAULT c_cityfr.

SELECT-OPTIONS s_carrid FOR spfli-carrid MEMORY ID car.

SELECT-OPTIONS s_fldate FOR sflight-fldate MEMORY ID day OBLIGATORY.

SELECTION-SCREEN END OF BLOCK a.

*&—————————————————————–*

*&  Include ZQ2R_FLIGHTSFROM_NY_F01

*&—————————————————————–*

*&—————————————————————–*

*&      Form  SET_SELECTION_FIELD_DISABLED

*&—————————————————————–*

FORM set_selection_field_disabled USING p_spname TYPE aqs_spname.

  DATA lv_spname_length TYPE i.

  lv_spname_length = strlen( p_spname ).

  LOOP AT SCREEN.

    IF screen-name(lv_spname_length) = p_spname.

      screen-input = 0.

      MODIFY SCREEN.

    ENDIF.

  ENDLOOP.

ENDFORM.                    ” SET_SELECTION_FIELD_DISABLED

*&—————————————————————–*

*&      Form  GET_DATA

*&—————————————————————–*

FORM get_data USING p_cityfr TYPE spfli-cityfrom

                    s_carrid TYPE tyr_carrid

                    s_fldate TYPE tyr_fldate

           CHANGING t_data   TYPE tyt_data.

  SELECT spfli~cityfrom

         spfli~cityto

         scarr~carrname

         sflight~fldate

    FROM ( spfli

           INNER JOIN sflight

           ON  sflight~carrid = spfli~carrid

           AND sflight~connid = spfli~connid

           INNER JOIN scarr

           ON  scarr~carrid = sflight~carrid )

    INTO TABLE t_data

         WHERE spfli~cityfrom = p_cityfr

           AND spfli~carrid IN s_carrid

           AND sflight~fldate IN s_fldate .

ENDFORM.                    ” GET_DATA

*&—————————————————————–*

*&      Form  ALV

*&—————————————————————–*

FORM alv USING t_data TYPE tyt_data.

  DATA:

    o_sorts     TYPE REF TO cl_salv_sorts,

    o_columns   TYPE REF TO cl_salv_columns,

    o_display   TYPE REF TO cl_salv_display_settings,

    o_functions TYPE REF TO cl_salv_functions_list,

    o_layout    TYPE REF TO cl_salv_layout,

    ls_key      TYPE        salv_s_layout_key,

    o_alv       TYPE REF TO cl_salv_table.

* Gel ALV object

  TRY.

      cl_salv_table=>factory(

        IMPORTING

          r_salv_table = o_alv

        CHANGING

          t_table      = t_data ).

    CATCH cx_salv_msg.

      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ENDTRY.

* ALV Sort

  o_sorts = o_alv->get_sorts( ).

  TRY.

      o_sorts->add_sort( ‘CITYFROM’ ).

      o_sorts->add_sort( ‘CITYTO’ ).

      o_sorts->add_sort( ‘CARRNAME’ ).

      CALL METHOD o_sorts->add_sort

        EXPORTING

          columnname = ‘FLDATE’

          sequence   = if_salv_c_sort=>sort_down.

    CATCH cx_salv_not_found

          cx_salv_existing

          cx_salv_data_error.

      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

         WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ENDTRY.

* Get columns

  o_columns = o_alv->get_columns( ).

* Set the column optimization

  o_columns->set_optimize( ).

  o_display = o_alv->get_display_settings( ).

  o_display->set_striped_pattern( abap_true ).

* Generic ALV functions

  o_functions = o_alv->get_functions( ).

  o_functions->set_all( ).

* Layout

  o_layout = o_alv->get_layout( ).

  ls_key-report = sy-repid.

  o_layout->set_key( ls_key ).

  o_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).

  o_alv->display( ).

ENDFORM.                    ” ALV

AT SELECTION-SCREEN OUTPUT.

  PERFORM set_selection_field_disabled: USING ‘P_CITYFR’.

START-OF-SELECTION.

  PERFORM get_data USING p_cityfr

                         s_carrid[]

                         s_fldate[]

                CHANGING t_data.

END-OF-SELECTION.

  PERFORM alv USING t_data.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply