10-09-2015 9:16 AM
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:
PERNR | ENDDA | BEGDA | SLART |
12 | 2015.02.01 | 2015.01.02 | BC |
12 | 2014.10.08 | 2014.09.01 | AC |
12 | 2013.12.20 | 2013.12.10 | DE |
My request is that the itens should be inline as follows:
PERNR | ENDDA | BEGDA | SLART | ENDDA1 | BEGDA1 | SLART1 | ENDDA2 | BEGDA2 | SLART2 |
12 | 2015.02.01 | 2015.01.02 | BC | 2014.10.08 | 2014.09.01 | AC | 2013.12.20 | 2013.12.10 | DE |
How can I achieve this?
Thanks in advance,
Ana
10-09-2015 9:35 AM
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
10-09-2015 9:44 AM
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
10-09-2015 2:19 PM
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>.
10-09-2015 6:25 PM