Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ALV - lines/columns

Former Member
0 Kudos

Hello all,

I´m trying to do an ALV to displays the courses in IT0022 but i´m stuck on the following:

for example on the querys the results are displays as follows:

PERNRENDDABEGDASLART
122015.02.012015.01.02BC
122014.10.082014.09.01AC
122013.12.202013.12.10DE

My request is that the itens should be inline as follows:

PERNRENDDABEGDASLARTENDDA1BEGDA1SLART1ENDDA2BEGDA2SLART2
122015.02.012015.01.02BC2014.10.082014.09.01AC2013.12.202013.12.10DE

How can I achieve this?

Thanks in advance,

Ana

4 REPLIES 4

Former Member
0 Kudos

Hello Ana,

you have to create table and line types at runtime:

Fill components with different Names.

lo_descr = cl_abap_tabledescr=>create(cl_abap_structdescr=>create(lt_component))

After tha you can create a table with

create data lr_data type handle lo_Descr.

assign lr_data->* to <data>.

and s.o.

Regards,

Richard

former_member185587
Participant
0 Kudos

Hi Ana,

As Richard Martens rightly suggested you need to make use of RTTS in order to create dynamic elements in order to achieve your requirement.

In your case, if you know that the number of line items are finite, you may declare your respective structure and internal table accordingly; but it seems that in your case that the number of line items (in the result) in unknown until runtime; hence you need to create your resulting structure accordingly dynamically based on the result of line items that you get in the code preceding your display logic.

I would suggest you to go through RunTime Type Services (RTTS) topic to understand the strength and beauty of the concept. After, which you shall be able to relate to the suggestion given by Mr. Richard Martens.

Regards,

Kiran

former_member289261
Active Contributor
0 Kudos

Hi,

This can be achieved as following :

1. Count maximum count of records present for an employee among all employees. 3 in your case.

2. Create a fieldcatalog :

You need to create a set of fields required. ( BEGDA, ENDDA, SLART in your case ).

Repeat this set the max count times in the fieldcatalog.

3. Create internal table from this fieldcatalog.

4. Fill this internal table

------------------------------------------------------------------------------------------------------------------------------------

DATA :    LV_NUM    TYPE    N    LENGTH    2,

                    LV_FIELDNAME    TYPE    FIELDNAME.

CLEAR LS_FCAT.

LS_FCAT-FIELDNAME    =    'PERNR'.

LS_FCAT-COL_POS          =    1.

LS_FCAT-REF_FIELD    =    'PERNR'.

LS_FCAT-REF_TABLE    =    'PA0022'.

APPEND LS_FCAT    TO      GT_FCAT.

DO    MAX_RECORD_COUNT    TIMES.

    LV_NUM    =    SY-INDEX.

    LV_FIELDNAME    =    |BEGDA_{    LV_NUM    }|.

    CLEAR LS_FCAT.

    LS_FCAT-FIELDNAME    =    LV_FIELDNAME.

    LS_FCAT-COL_POS          =    LV_NUM    +    1.

    LS_FCAT-REF_FIELD    =    'BEGDA'.

    LS_FCAT-REF_TABLE    =    'PA0022'.

    APPEND LS_FCAT    TO      GT_FCAT.

    LV_FIELDNAME    =    |ENDDA_{    LV_NUM    }|.

    CLEAR LS_FCAT.

    LS_FCAT-FIELDNAME    =    LV_FIELDNAME.

    LS_FCAT-COL_POS          =    LV_NUM    +    1.

    LS_FCAT-REF_FIELD    =    'ENDDA'.

    LS_FCAT-REF_TABLE    =    'PA0022'.

    APPEND LS_FCAT    TO      GT_FCAT.

    LV_FIELDNAME    =    |SLART_{    LV_NUM    }|.

    CLEAR LS_FCAT.

    LS_FCAT-FIELDNAME    =    LV_FIELDNAME.

    LS_FCAT-COL_POS          =    LV_NUM    +    1.

    LS_FCAT-REF_FIELD    =    'SLART'.

    LS_FCAT-REF_TABLE    =    'PA0022'.

    APPEND LS_FCAT    TO      GT_FCAT.

ENDDO.


This will give you the desired fieldcat and the internal table from it which you need to fill.

DATA    :    GT_ITAB    TYPE REF TO DATA,

                    WA              TYPE REF TO DATA.

FIELD-SYMBOLS    :    <FS_ITAB>    TYPE STANDARD TABLE,

                                        <FS_WA>     TYPE ANY,

                                        <FS_FIELD>     TYPE SIMPLE.

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

    EXPORTING

          IT_FIELDCATALOG    =    GT_FCAT

    IMPORTING

          EP_TABLE                    =    GT_ITAB.

ASSIGN    GT_ITAB->*    TO    <FS_ITAB>.

CHECK    <FS_ITAB>    IS ASSIGNED.

    CREATE DATA    WA    LIKE LINE OF    <FS_ITAB>.

     ASSIGN     WA->*     TO     <FS_WA>.

     CHECK <FS_WA>     IS ASSIGNED.

     SORT     GT_0022     BY PERNR.

     LOOP     AT GT_0022     ASSIGNING     FIELD-SYMBOL(<FS_0022>).

          AT NEW PERNR.

               CLEAR     LV_NUM.

               LOOP     AT     GT_0022     ASSIGNING     FIELD-SYMBOL(<FS>)     WHERE     PERNR     =     <FS_0022>-PERNR.

                    LV_NUM     =     LV_NUM     +     1.

                    ASSIGN COMPONENT     'PERNR'     OF     STRUCTURE     <FS_WA>     TO      <FS_FIELD>.

                    CHECK  <FS_FIELD>     IS ASSIGNED.

                         <FS_FIELD>     =     <FS>-PERNR.

                         UNASSIGN     <FS_FIELD>.

              

                    LV_FIELDNAME     =     |BEGDA_{     LV_NUM     }|.

                    ASSIGN     COMPONENT     LV_FIELDNAME     OF     STRUCTURE     <FS_WA>     TO      <FS_FIELD>.

                    CHECK     <FS_FIELD>     IS     ASSIGNED.

                         <FS_FIELD>     =     <FS>-BEGDA.

                         UNASSIGN     <FS_FIELD>.

              

                    LV_FIELDNAME     =     |ENDDA_{     LV_NUM     }|.

                    ASSIGN     COMPONENT     LV_FIELDNAME     OF     STRUCTURE     <FS_WA>     TO      <FS_FIELD>.

                    CHECK     <FS_FIELD>     IS     ASSIGNED.

                         <FS_FIELD>     =     <FS>-ENDDA.

                         UNASSIGN     <FS_FIELD>.

              

                    LV_FIELDNAME     =     |SLART_{     LV_NUM     }|.

                    ASSIGN     COMPONENT     LV_FIELDNAME     OF     STRUCTURE     <FS_WA>     TO      <FS_FIELD>.

                    CHECK     <FS_FIELD>     IS     ASSIGNED.

                         <FS_FIELD>     =     <FS>-SLART.

                         UNASSIGN     <FS_FIELD>.

              

               ENDLOOP.

              

               APPEND <FS_WA>     TO     <FS_ITAB>.

               CLEAR     <FS_WA>.

          ENDAT.

     ENDLOOP.

     CALL FUNCTION     'REUSE_ALV_GRID_DISPLAY'

          IMPORTING

               IT_FIELDCAT     =     GT_FCAT

          TABLES

               T_OUTTAB          =     <FS_ITAB>.

VenkatRamesh_V
Active Contributor
0 Kudos

Hi Ana,

View the link,

https://scn.sap.com/docs/DOC-53788

Hope it helpful,

Regards,

Venkat.