Skip to Content

A few months ago, a friend of mine ask me if it was possible to develop a Dynamic ALV List Display…At first I thought that it was a hard job to do…Because he want ALV List for every key field in a database table…So I take the best know tables in the MiniSAP system

SCARR and SPFLI

and start to work on it.

As you may know, for this kind of ALV reports, you need to call

REUSE_ALV_BLOCK_LIST_APPEND

function module, for each ALV list…But when you don’t know how many ALV list are going to be…You can of course use some ABAP Objects to save the day.

************************************************************************

  • Date/Author: 26.08.2006 / Alvaro Tejada Galindo.                     *

************************************************************************

REPORT Z_DUMMY_ALV.

—-


  • TYPE-POOLS                                                          *

—-


TYPE-POOLS: SLIS.

—-


  • TABLES                                                              *

—-


TABLES: SCARR, SPFLI.

—-


  • VARIABLES                                                           *

—-


DATA: G_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

      G_SORT TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE,

      GT_PRINT TYPE SLIS_PRINT_ALV,

      GS_LAYOUT TYPE SLIS_LAYOUT_ALV,

      GT_EVENTS TYPE SLIS_T_EVENT,

      G_PROGRAM TYPE SY-REPID,

      TAB_NAME TYPE STRING,

      W_TABIX TYPE STRING.

—-


  • TYPES                                                               *

—-


TYPES: BEGIN OF TY_SPFLI,

       MANDT TYPE SPFLI-MANDT,

       CARRID TYPE SPFLI-CARRID,

       CONNID TYPE SPFLI-CONNID,

       COUNTRYFR TYPE SPFLI-COUNTRYFR,

       CITYFROM TYPE SPFLI-CITYFROM,

       AIRPFROM TYPE SPFLI-AIRPFROM,

       COUNTRYTO TYPE SPFLI-COUNTRYTO,

       CITYTO TYPE SPFLI-CITYTO.

TYPES: END OF TY_SPFLI.

TYPES: BEGIN OF TY_STUFF,

       TABNAME TYPE TABNAME,

       TDREF TYPE REF TO DATA,

END OF TY_STUFF.

DATA T_STUFF TYPE TABLE OF TY_STUFF WITH NON-UNIQUE KEY TABNAME.

DATA: DESCR_STRUCT_REF TYPE REF TO CL_ABAP_STRUCTDESCR,

      DATAREF TYPE REF TO DATA,

      WA_FCAT TYPE LVC_S_FCAT,

      IT_FIELDCATALOG TYPE LVC_T_FCAT.

—-


  • FIELD-SYMBOLS                                                       *

—-


FIELD-SYMBOLS: .

—-


  • INTERNAL TABLES                                                     *

—-


DATA: T_SPFLI TYPE STANDARD TABLE OF TY_SPFLI WITH HEADER LINE,

      T_SPFLI_HEADER TYPE STANDARD TABLE OF TY_SPFLI WITH HEADER LINE,

      T_SPFLI_DETAIL TYPE STANDARD TABLE OF TY_SPFLI WITH HEADER LINE.

—-


  • MACROS                                                              *

—-


DEFINE CLEAN_TABLE.

  CLEAR &1.

  REFRESH &1.

END-OF-DEFINITION.

—-


  • SELECTION SCREEN                                                    *

—-


SELECTION-SCREEN BEGIN OF BLOCK B01 WITH FRAME TITLE TEXT-B01.

SELECT-OPTIONS:

               S_CARRID FOR SCARR-CARRID.

SELECTION-SCREEN END OF BLOCK B01.

—-


  • PRINCIPAL

—-


START-OF-SELECTION.

  PERFORM GET_DATA.

  PERFORM GENERATE_ALV.

  PERFORM GENERATE_ALV_LIST.

—-


  •       FORM GET_DATA                                                 *

—-


  •       Retrieve data                                                 *

—-


FORM GET_DATA.

  SELECT MANDT CARRID CONNID COUNTRYFR CITYFROM

         AIRPFROM COUNTRYTO CITYTO

  INTO TABLE T_SPFLI

  FROM SPFLI

  WHERE CARRID IN S_CARRID.

  IF NOT T_SPFLI[] IS INITIAL.

    T_SPFLI_HEADER[] = T_SPFLI[].

    DELETE ADJACENT DUPLICATES FROM T_SPFLI_HEADER

    COMPARING CARRID.

  ENDIF.

ENDFORM.

&—-


*&      Form  GENERATE_ALV                                             *

&—-


  •       Generate the ALV                                               *

—-


FORM GENERATE_ALV.

  IF NOT T_SPFLI_HEADER[] IS INITIAL.

    PERFORM CUSTOM_DATA_ALV USING G_FIELDCAT[].

    PERFORM BUILD_SORT.

  ENDIF.

ENDFORM.                    “GENERATE_ALV

&—-


*&      Form  CUSTOM_DATA_ALV                                          *

&—-


  •       Create ALV Catalog.                                            *

—-


FORM CUSTOM_DATA_ALV USING T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

  DATA: L_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

  CLEAR: T_FIELDCAT.

  REFRESH: T_FIELDCAT.

  CLEAR L_FIELDCAT.

  L_FIELDCAT-TABNAME        = ‘T_SPFLI’.

  L_FIELDCAT-FIELDNAME      = ‘CARRID’.

  L_FIELDCAT-SELTEXT_L      = ‘Airline carrier ID’.

  L_FIELDCAT-COL_POS        = 1.

  L_FIELDCAT-OUTPUTLEN      = 15.

  APPEND L_FIELDCAT TO T_FIELDCAT.

  CLEAR L_FIELDCAT.

  L_FIELDCAT-TABNAME        = ‘T_SPFLI’.

  L_FIELDCAT-FIELDNAME      = ‘CONNID’.

  L_FIELDCAT-SELTEXT_L      = ‘Flight connection Id’.

  L_FIELDCAT-COL_POS        = 2.

  L_FIELDCAT-OUTPUTLEN      = 15.

  APPEND L_FIELDCAT TO T_FIELDCAT.

  CLEAR L_FIELDCAT.

  L_FIELDCAT-TABNAME        = ‘T_SPFLI’.

  L_FIELDCAT-FIELDNAME      = ‘COUNTRYFR’.

  L_FIELDCAT-SELTEXT_L      = ‘Country key’.

  L_FIELDCAT-COL_POS        = 3.

  L_FIELDCAT-OUTPUTLEN      = 15.

  APPEND L_FIELDCAT TO T_FIELDCAT.

  CLEAR L_FIELDCAT.

  L_FIELDCAT-TABNAME        = ‘T_SPFLI’.

  L_FIELDCAT-FIELDNAME      = ‘CITYFROM’.

  L_FIELDCAT-SELTEXT_L      = ‘City of departure’.

  L_FIELDCAT-COL_POS        = 4.

  L_FIELDCAT-OUTPUTLEN      = 15.

  APPEND L_FIELDCAT TO T_FIELDCAT.

  CLEAR L_FIELDCAT.

  L_FIELDCAT-TABNAME        = ‘T_SPFLI’.

  L_FIELDCAT-FIELDNAME      = ‘AIRPFROM’.

  L_FIELDCAT-SELTEXT_L      = ‘Airport of departure’.

  L_FIELDCAT-COL_POS        = 5.

  L_FIELDCAT-OUTPUTLEN      = 15.

  APPEND L_FIELDCAT TO T_FIELDCAT.

  CLEAR L_FIELDCAT.

  L_FIELDCAT-TABNAME        = ‘T_SPFLI’.

  L_FIELDCAT-FIELDNAME      = ‘COUNTRYTO’.

  L_FIELDCAT-SELTEXT_L      = ‘Country key’.

  L_FIELDCAT-COL_POS        = 6.

  L_FIELDCAT-OUTPUTLEN      = 15.

  APPEND L_FIELDCAT TO T_FIELDCAT.

  CLEAR L_FIELDCAT.

  L_FIELDCAT-TABNAME        = ‘T_SPFLI’.

  L_FIELDCAT-FIELDNAME      = ‘CITYTO’.

  L_FIELDCAT-SELTEXT_L      = ‘Arrival city’.

  L_FIELDCAT-COL_POS        = 7.

  L_FIELDCAT-OUTPUTLEN      = 15.

  APPEND L_FIELDCAT TO T_FIELDCAT.

ENDFORM.                    “CUSTOM_DATA_ALV

&—-


*&      Form  BUILD_SORT                               *

&—-


  •       Build Sort table                                              *

—-


FORM BUILD_SORT.

  CLEAR G_SORT.

  G_SORT-SPOS      = 1.

  G_SORT-FIELDNAME = ‘CARRID’.

  G_SORT-UP        = ‘X’.

  APPEND G_SORT.

ENDFORM.

—-


  •       FORM GENERATE_ALV_LIST                                        *

—-


  •       Generate ALV list                                             *

—-


FORM GENERATE_ALV_LIST.

  DATA L_STUFF TYPE TY_STUFF.

  G_PROGRAM = SY-REPID.

  CALL FUNCTION ‘REUSE_ALV_BLOCK_LIST_INIT’

       EXPORTING

            I_CALLBACK_PROGRAM = G_PROGRAM.

  LOOP AT T_SPFLI_HEADER.

    W_TABIX = SY-TABIX.

    CLEAN_TABLE T_SPFLI_DETAIL.

    LOOP AT T_SPFLI INTO T_SPFLI_DETAIL

    WHERE CARRID EQ T_SPFLI_HEADER-CARRID.

      APPEND T_SPFLI_DETAIL.

    ENDLOOP.

    CONCATENATE ‘TABLE_’ W_TABIX INTO

    TAB_NAME.

    PERFORM CREATE_TABLE USING ‘SPFLI’ TAB_NAME.

    LOOP AT T_SPFLI_DETAIL ASSIGNING .

  ENDLOOP.

  CALL FUNCTION ‘REUSE_ALV_BLOCK_LIST_DISPLAY’

       EXPORTING

            IS_PRINT = GT_PRINT.

ENDFORM.

—-


  •       FORM CREATE_ALV_LIST                                        *

—-


  •       Create ALV List                                             *

—-


FORM CREATE_ALV_LIST TABLES T_TABLE STRUCTURE T_SPFLI_DETAIL.

  CALL FUNCTION ‘REUSE_ALV_BLOCK_LIST_APPEND’

       EXPORTING

            IT_FIELDCAT = G_FIELDCAT

            IS_LAYOUT   = GS_LAYOUT

            I_TABNAME   = ‘T_SPFLI’

            IT_EVENTS   = GT_EVENTS

       TABLES

            T_OUTTAB    = T_TABLE.

ENDFORM.

—-


  •       FORM CREATE_TABLE                                             *

—-


  •       Create dynamic table                                          *

—-


FORM CREATE_TABLE USING MY_TAB TAB_NAME.

  DATA L_STUFF TYPE TY_STUFF.

  CREATE DATA DATAREF TYPE (MY_TAB).

  ASSIGN DATAREF->* TO

image

As you may see…I’m just creating a new Dynamic table named TABLE_X where X is going to a number from 1 to 20 ( Because 20 is the SAP restriction -:P )

I hope you enjoy it…If your ever asked to do something like this…

P.S: Important…Please uncheck the unicode check in other to get this app working…I’m working on fixing this.

P.S 2: Now it’s fixed -;)

To report this post you need to login first.

9 Comments

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

  1. Anonymous
    This is very interesting Alvaro.I am curious to know whether you have used this technique in any real time applications.
    (0) 
    1. Alvaro Tejada Galindo Post author
      Hi Ravi:

      Thanx for your comment -:) As I say in my blog…A friend of mine ask me for thar code…I have never used it on a real app, but you never know…Sometimes clients ask for really weird things…For example, in one project, the client made some Power Builder screens and ask me to ported to ABAP…The result was more than 23,000 lines of code full dynpro application -:O

      Greetings,

      Blag.

      (0) 
        1. Alvaro Tejada Galindo Post author
          Thanx for the link Durairaj, I haven’t read that blog -:D

          But sadly…The limitation also works for REUSE_ALV_BLOCK_LIST_APPEND as I said in my blog…Even if I can create 50 dynamic tables…The FM also allow me to create 20 ALV blocks…

          Greetings,

          Blag.

          (0) 
          1. Kathirvel Balakrishnan
            Hi Alvaro

            Nice one again. I got more stuck to the splitter controls and CL_GUI_ALV_GRID class as those where the more frequest requirements I have come across. This is something different pal.

            Keep it going…

            Regards
            Kathirvel

            (0) 
  2. Dan Perecky
    >>At first I thought that it was a hard job to do

      I was having my thoughts about this same thing, after looking for days. Your post should provide all that’s necessary.

      Have you found the more obscure FM’s such as REUSE_ALV_BLOCK_LIST_DATA_GET,
    REUSE_ALV_BLOCK_LIST_DATA_SET, and
    REUSE_ALV_BLOCK_LIST_REFRESH useful?

    Great Job,         Dan P.

    (0) 
    1. Alvaro Tejada Galindo Post author
      Hi Dan:

      Actually, I wasn’t aware of that FM’s -:P So, thanks for the tip -:D If I can do something nice with them, I will blog about it -;)

      Greetings,

      Blag.

      (0) 

Leave a Reply