ALV: Simple list

SAP Tech Pro

SAP Technical Blog
Magzter [CPS] IN

ALV: Simple list

ALV: Simple list


* Global data declaration
INCLUDE VSD03TOP.

* Initialization fieldcatalog
INITIALIZATION.
  G_REPID = SY-REPID.
  PERFORM FIELDCAT_INIT USING GT_FIELDCAT[].

* Data selection
START-OF-SELECTION.
  PERFORM SELECT_DATA TABLES GT_OUTTAB.

* Display list
END-OF-SELECTION.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
            I_CALLBACK_PROGRAM = G_REPID
            IT_FIELDCAT        = GT_FIELDCAT[]
       TABLES
            T_OUTTAB           = GT_OUTTAB.

*-----------------------------------------------------------------------
*    Forms
*-----------------------------------------------------------------------

* Initialization fieldcatalog

FORM FIELDCAT_INIT
      USING RT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
  DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
  DATA: POS TYPE I VALUE 1.

  clear ls_fieldcat.
  LS_FIELDCAT-COL_POS       =  POS.
  LS_FIELDCAT-FIELDNAME     = 'SCARR-CARRID'.
  ls_fieldcat-ref_fieldname = 'CARRID'.
  LS_FIELDCAT-REF_TABNAME   = 'SCARR'.
  LS_FIELDCAT-KEY           = 'X'.
     APPEND LS_FIELDCAT TO  RT_FIELDCAT.
  clear ls_fieldcat.
  POS = POS + 1.
  LS_FIELDCAT-COL_POS       =  POS.
  LS_FIELDCAT-FIELDNAME     = 'SCARR-CARRNAME'.
  ls_fieldcat-ref_fieldname = 'CARRNAME'.
  LS_FIELDCAT-REF_TABNAME   = 'SCARR'.
     APPEND LS_FIELDCAT TO RT_FIELDCAT.
  clear ls_fieldcat.
  POS = POS + 1.
  LS_FIELDCAT-COL_POS       =  POS.
  LS_FIELDCAT-FIELDNAME     = 'SPFLI-CONNID'.
  ls_fieldcat-ref_fieldname = 'CONNID'.
  LS_FIELDCAT-REF_TABNAME   =  'SPFLI'.
     APPEND LS_FIELDCAT TO RT_FIELDCAT.
  clear ls_fieldcat.
  POS = POS + 1.
  LS_FIELDCAT-COL_POS       =  POS.
  LS_FIELDCAT-FIELDNAME     = 'SPFLI-CITYFROM'.
  ls_fieldcat-ref_fieldname = 'CITYFROM'.
  LS_FIELDCAT-REF_TABNAME   =  'SPFLI'.
     APPEND LS_FIELDCAT TO RT_FIELDCAT.
  clear ls_fieldcat.
  POS = POS + 1.
  LS_FIELDCAT-COL_POS       =  POS.
  LS_FIELDCAT-FIELDNAME     = 'SPFLI-AIRPFROM'.
  ls_fieldcat-ref_fieldname = 'AIRPFROM'.
  LS_FIELDCAT-REF_TABNAME   =  'SPFLI'.
  LS_FIELDCAT-NO_OUT        = 'X'.
     APPEND LS_FIELDCAT TO RT_FIELDCAT.
  clear ls_fieldcat.
  POS = POS + 1.
  LS_FIELDCAT-COL_POS       =  POS.
  LS_FIELDCAT-FIELDNAME     = 'SPFLI-CITYTO'.
  ls_fieldcat-ref_fieldname = 'CITYTO'.
  LS_FIELDCAT-REF_TABNAME   =  'SPFLI'.
     APPEND LS_FIELDCAT TO RT_FIELDCAT.
  clear ls_fieldcat.
  POS = POS + 1.
  LS_FIELDCAT-COL_POS       =  POS.
  LS_FIELDCAT-FIELDNAME     = 'SPFLI-AIRPTO'.
  ls_fieldcat-ref_fieldname = 'AIRPTO'.
  LS_FIELDCAT-REF_TABNAME   = 'SPFLI'.
  LS_FIELDCAT-NO_OUT        = 'X'.
     APPEND LS_FIELDCAT TO RT_FIELDCAT.
  clear ls_fieldcat.
  POS = POS + 1.
  LS_FIELDCAT-COL_POS       =  POS.
  LS_FIELDCAT-FIELDNAME     = 'SPFLI-DEPTIME'.
  ls_fieldcat-ref_fieldname = 'DEPTIME'.
  LS_FIELDCAT-REF_TABNAME   = 'SPFLI'.
     APPEND LS_FIELDCAT TO RT_FIELDCAT.
  clear ls_fieldcat.
  POS = POS + 1.
  LS_FIELDCAT-COL_POS       =  POS.
  LS_FIELDCAT-FIELDNAME     = 'SPFLI-ARRTIME'.
  ls_fieldcat-ref_fieldname = 'ARRTIME'.
  LS_FIELDCAT-REF_TABNAME   = 'SPFLI'.
     APPEND LS_FIELDCAT TO RT_FIELDCAT.
  clear ls_fieldcat.
  POS = POS + 1.
  LS_FIELDCAT-COL_POS       =  POS.
  LS_FIELDCAT-FIELDNAME     = 'SPFLI-DISTANCE'.
  ls_fieldcat-ref_fieldname = 'DISTANCE'.
  LS_FIELDCAT-REF_TABNAME   = 'SPFLI'.
  LS_FIELDCAT-NO_OUT        = 'X'.
     APPEND LS_FIELDCAT TO RT_FIELDCAT.
  clear ls_fieldcat.
  POS = POS + 1.
  LS_FIELDCAT-COL_POS       =  POS.
  LS_FIELDCAT-FIELDNAME     = 'SPFLI-DISTID'.
  ls_fieldcat-ref_fieldname = 'DISTID'.
  LS_FIELDCAT-REF_TABNAME   = 'SPFLI'.
  LS_FIELDCAT-NO_OUT        = 'X'.
     APPEND LS_FIELDCAT TO RT_FIELDCAT.
ENDFORM.   "fieldcat_init


* Data selection
FORM SELECT_DATA
      TABLES RT_OUTTAB LIKE GT_OUTTAB[].
  SELECT DISTINCT SCARR~CARRID SCARR~CARRNAME
                  SPFLI~CONNID SPFLI~CITYFROM
                  SPFLI~AIRPFROM SPFLI~CITYTO
                  SPFLI~AIRPTO SPFLI~DEPTIME
                  SPFLI~ARRTIME SPFLI~DISTANCE
                  SPFLI~DISTID
         INTO    (RT_OUTTAB-SCARR-CARRID, RT_OUTTAB-SCARR-CARRNAME,
                  RT_OUTTAB-SPFLI-CONNID, RT_OUTTAB-SPFLI-CITYFROM,
                  RT_OUTTAB-SPFLI-AIRPFROM, RT_OUTTAB-SPFLI-CITYTO,
                  RT_OUTTAB-SPFLI-AIRPTO, RT_OUTTAB-SPFLI-DEPTIME,
                  RT_OUTTAB-SPFLI-ARRTIME, RT_OUTTAB-SPFLI-DISTANCE,
                  RT_OUTTAB-SPFLI-DISTID)
                  FROM SCARR INNER JOIN SPFLI
                  ON SCARR~CARRID = SPFLI~CARRID
                  WHERE SCARR~CARRID BETWEEN 'AA' AND 'LH'.
    APPEND RT_OUTTAB.
  ENDSELECT.
ENDFORM.   " select_data

*----------------------------------------------------------------------*
*   INCLUDE VSD03TOP                                                   *
*----------------------------------------------------------------------*
REPORT BALVSD03.

* Data declaration
TYPE-POOLS: SLIS.

* Global structure of list
TYPES:        BEGIN OF UD_STRUCT,
                        SCARR LIKE SCARR,
                        SPFLI LIKE SPFLI,
                END OF UD_STRUCT.

TABLES: SCARR, SPFLI.

DATA:   GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA:   GT_OUTTAB  TYPE UD_STRUCT OCCURS 0 WITH HEADER LINE.
DATA:   G_REPID LIKE SY-REPID.

R        Global data                                                                                                                                                                                                                                                    0011

Add comment

Before Buying, Compare Prices at Topprice.in

Topprice.in