Skip to Content
avatar image
Former Member

How to display dynamic ALV in ABAP ?

Hi Experts,

I have to write an ALV list with dynamic list generation.Is there any function for this type displaying or am I have to

write code.

Code is below ;

TABLES : EKPO,EKKO,EKET .

TYPE-POOLS: SLIS.

DATA: LT_FLDCAT     TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
       ALV_LAYOUT    TYPE SLIS_LAYOUT_ALV,
       GT_HEADER     TYPE SLIS_T_LISTHEADER WITH HEADER LINE,
       LS_FLDCAT     TYPE SLIS_FIELDCAT_ALV,
       GS_GRID       TYPE LVC_S_GLAY,
       GV_REPID      LIKE SY-REPID,
       OK_CODE LIKE SY-UCOMM.

DATA :BEGIN OF ITAB OCCURS 0,

       MATNR LIKE EKPO-MATNR,
       TXZ01 LIKE EKPO-TXZ01,
       KTMNG LIKE EKPO-KTMNG,
       MEINS LIKE EKPO-MEINS,
       NETPR LIKE EKPO-NETPR,
       PEINH LIKE EKPO-PEINH,
       EBELN LIKE EKPO-EBELN,
       EBELP LIKE EKPO-EBELP,
       EINDT LIKE EKET-EINDT,
       BEDAT LIKE EKKO-BEDAT,
       SUBMI LIKE EKKO-SUBMI,
       LIFNR LIKE EKKO-LIFNR,
       NAME1 LIKE LFA1-NAME1,
       ACKLM(50)  TYPE C ,

   END OF ITAB.

  DATA: GT_FIELDCAT TYPE SLIS_FIELDCAT_ALV OCCURS 1 WITH HEADER LINE.


  SELECTION-SCREEN: BEGIN OF BLOCK ITAB1 WITH FRAME TITLE TEXT-001.

    SELECT-OPTIONS :   S_EBELN FOR EKKO-EBELN,
                       S_SUBMI FOR EKKO-SUBMI,
                       S_LIFNR FOR EKKO-LIFNR.

    PARAMETERS  :      S_MATNR LIKE EKPO-MATNR.

    SELECT-OPTIONS :   S_BEDAT FOR EKKO-BEDAT.


    SELECTION-SCREEN:END OF BLOCK ITAB1 .
******************************************************************
    START-OF-SELECTION .

     SELECT
         EKPO~MATNR
         EKPO~TXZ01
         EKPO~KTMNG
         EKPO~MEINS
         EKPO~NETPR
         EKPO~PEINH
         EKPO~EBELN
         EKPO~EBELP
         EKPO~MATNR

         EKKO~SUBMI
         EKKO~LIFNR
         EKKO~EBELN
         EKKO~BEDAT

         EKET~EINDT

   INTO CORRESPONDING FIELDS OF TABLE ITAB

      FROM EKPO


INNER JOIN EKKO ON EKPO~EBELN EQ EKKO~EBELN
INNER JOIN EKET ON EKPO~EBELN EQ EKET~EBELN


           WHERE
           EKKO~BEDAT IN S_BEDAT AND
           EKKO~EBELN IN S_EBELN AND
           EKKO~SUBMI IN S_SUBMI AND
           EKKO~LIFNR IN S_LIFNR AND
           EKPO~MATNR EQ S_MATNR.

DATA: TITAB LIKE TLINE OCCURS 0 WITH HEADER LINE.
DATA: NAME5 LIKE THEAD-TDNAME.

LOOP AT ITAB .

**   CLEAR: NAME5, TITAB.
**    REFRESH: TITAB[], TITAB.
**    CONCATENATE ITAB-EBELN  ITAB-EBELP INTO NAME5.
**
**    CALL FUNCTION 'READ_TEXT'
**      EXPORTING
**        CLIENT                  = 100
**        ID                      = 'A01'
**        LANGUAGE                = SY-LANGU
**        NAME                    = NAME5
**        OBJECT                  = 'EKPO'
**      TABLES
**        LINES                   = TITAB
**      EXCEPTIONS
**        ID                      = 1
**        LANGUAGE                = 2
**        NAME                    = 3
**        NOT_FOUND               = 4
**        OBJECT                  = 5
**        REFERENCE_CHECK         = 6
**        WRONG_ACCESS_TO_ARCHIVE = 7
**        OTHERS                  = 8.
**
**    LOOP AT TITAB.
**      CONCATENATE TITAB-TDLINE SPACE INTO ITAB-ACKLM.
**    ENDLOOP.

         SELECT SINGLE NAME1 INTO ITAB-NAME1
         FROM LFA1
         WHERE LIFNR EQ ITAB-LIFNR.


MODIFY ITAB.

ENDLOOP.

PERFORM GOSTER.
*&---------------------------------------------------------------------*
*&      Form  GOSTER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GOSTER .

    DATA: GV_COL_POS TYPE I.
    DEFINE ADD-FIELDCAT.
     GT_FIELDCAT-FIELDNAME     = &1.
     GT_FIELDCAT-REF_TABNAME   = &2.
     GT_FIELDCAT-REF_FIELDNAME = &3.
     GT_FIELDCAT-SELTEXT_S     = &4.
     GT_FIELDCAT-SELTEXT_M     = &4.
     GT_FIELDCAT-SELTEXT_L     = &4.
     GT_FIELDCAT-REPTEXT_DDIC  = &4.
     GT_FIELDCAT-DDICTXT       = 'L'.
     "  GT_FIELDCAT-no_out        = &5
     GT_FIELDCAT-COL_POS       = GV_COL_POS.
     ADD 1 TO GV_COL_POS.
     APPEND GT_FIELDCAT. CLEAR  GT_FIELDCAT.
   END-OF-DEFINITION.


   ADD-FIELDCAT 'MATNR' 'EKPO' 'MATNR' 'Ürün No'   .
   ADD-FIELDCAT 'TXZ01' 'EKPO' 'TXZ01' 'Ürün Kodu'   .
   ADD-FIELDCAT 'KTMNG' 'EKPO' 'KTMNG' 'Talep Miktar'   .
   ADD-FIELDCAT 'MEINS' 'EKPO' 'MEINS' 'Ölçü Birimi'.
   ADD-FIELDCAT 'ACKLM' '' '' 'MARKA'   .
   ADD-FIELDCAT 'NETPR' 'EKPO' 'NETPR' 'FIRMA ISMI'   .
   ADD-FIELDCAT 'PEINH' 'EKPO' 'PEINH' 'Fiyat Birimi'   .
   ADD-FIELDCAT 'EINDT' 'EKET' 'EINDT' 'Termin Tarihi'   .
   ALV_LAYOUT-GET_SELINFOS = 'X'.
   ALV_LAYOUT-ZEBRA = 'X'.
   ALV_LAYOUT-BOX_FIELDNAME = 'SEL'.


   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
       IT_FIELDCAT              = GT_FIELDCAT[]
       IS_LAYOUT                = ALV_LAYOUT
      " I_CALLBACK_TOP_OF_PAGE   = 'TOP_OF_PAGE'
       I_CALLBACK_PROGRAM       = GV_REPID
      " I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
       I_CALLBACK_USER_COMMAND  = 'USER_COMMAND_GRID'
     TABLES
       T_OUTTAB                 = ITAB[].

ENDFORM.                    " GOSTER

I will use read text function and dynamic ALV list.The OUTPUT have to be like below;

Ürün No Ürün Kodu Talep Miktar Ölçü Birimi MARKA Firma İsmi Fiyat Birimi Termin Tarihi MARKA Firma İsmi Fiyat Birimi Termin Tarihi ekpo-matnr ekpo-txz01 ekpo-ktmng ekpo-meins read-text function ekpo-netpr ekpo-peinh

ekpo-ebeln = eket-ebeln

eket-eindt

read-text function ekpo-netpr ekpo-peinh

ekpo-ebeln = eket-ebeln

eket-eindt













After the "termin tarihi"  if there are five Marka the ALV will display dynamically all of them.

Thanks for answers

Regards.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Jul 28, 2012 at 09:44 AM

    There is no dynamic table in your code.

    Use CL_SALV_TABLE and forget about all your issues - no field catalog definition, no macros. Search for the excellent blogs of Rich Heilman or other sources on ALV object model.

    For dynamic internal tables, search for RTTS.

    Note: You never need a TABLES statement. You need no BOX_FIELDNAME and field for this if you use CL_SALV_TABLE and set selection mode (ROW_COLUMN or CELL) and you have what you need.

    Regards

    Clemens

    Add comment
    10|10000 characters needed characters exceeded