2008 Mar 20 11:53 AM
Dear all,
I need help in creating an ALV report with dynamic columns based on the Year and period entered on the selection screen. for example if in the year we enter 2002 and period range from 10 to 12 then we should get the 3 columns display for cost(example) for period 10/2002, 11/2002 and 12/2002.
Can anyone help me in achieving this dynamically since the user can enter the year also in intervals along with the period and data also needs to be populated in the corresponding columns.
An example code would be of great help.
Thanks,
Amit
2008 Mar 20 12:02 PM
Hi,
Use field symbols as follows.
TYPE-POOLS : SLIS.
TABLES : MARC,T001W.
DATA : BEGIN OF ITAB OCCURS 0,
MATNR LIKE MARC-MATNR,
END OF ITAB.
DATA : FIELDSTAB TYPE LVC_T_FCAT,
STAB TYPE LVC_S_FCAT,
T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
S_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
NEW_LINE TYPE REF TO DATA,
NEW_TABLE TYPE REF TO DATA,
INDEX(3) TYPE C,
STR(70),
TEXT(6),
CNT(1),
TEXT1(16),
REPID LIKE SY-REPID.
FIELD-SYMBOLS : <FS> TYPE STANDARD TABLE,
<WA> TYPE ANY.
SELECT-OPTIONS : S_WERKS FOR MARC-WERKS NO INTERVALS,
S_MATNR FOR MARC-MATNR NO INTERVALS.
INITIALIZATION.
REPID = SY-REPID.
START-OF-SELECTION.
SELECT * FROM MARC
INTO CORRESPONDING FIELDS OF TABLE ITAB
WHERE MATNR IN S_MATNR
AND WERKS IN S_WERKS.
SORT ITAB BY MATNR.
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING MATNR.
STAB-FIELDNAME = 'MATNR'.
STAB-DATATYPE = 'CHAR'.
STAB-INTLEN = '18'.
APPEND STAB TO FIELDSTAB.
CLEAR CNT.
LOOP AT S_WERKS.
CLEAR TEXT.
CNT = CNT + 1.
CONCATENATE 'EISLO' CNT INTO TEXT.
STAB-FIELDNAME = TEXT.
STAB-DATATYPE = 'CHAR'.
STAB-INTLEN = '16'.
APPEND STAB TO FIELDSTAB.
CLEAR S_WERKS.
ENDLOOP.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = FIELDSTAB
IMPORTING
EP_TABLE = NEW_TABLE.
ASSIGN NEW_TABLE->* TO <FS>.
CREATE DATA NEW_LINE LIKE LINE OF <FS>.
ASSIGN NEW_LINE->* TO <WA>.
PERFORM MOVE_DATA.
CLEAR S_FIELDCAT.
S_FIELDCAT-FIELDNAME = 'MATNR'.
S_FIELDCAT-TABNAME = ITAB.
S_FIELDCAT-SELTEXT_M = 'Part Number'.
S_FIELDCAT-NO_ZERO = 'X'.
S_FIELDCAT-DDICTXT = 'M'.
APPEND S_FIELDCAT TO T_FIELDCAT.
CLEAR CNT.
LOOP AT S_WERKS.
CLEAR T001W.
CNT = CNT + 1.
SELECT SINGLE * FROM T001W WHERE WERKS = S_WERKS-LOW AND SPRAS = SY-LANGU.
CLEAR TEXT.
CONCATENATE 'EISLO' CNT INTO TEXT.
S_FIELDCAT-FIELDNAME = TEXT.
S_FIELDCAT-SELTEXT_M = T001W-NAME2.
S_FIELDCAT-NO_ZERO = 'X'.
S_FIELDCAT-DDICTXT = 'M'.
APPEND S_FIELDCAT TO T_FIELDCAT.
CLEAR S_WERKS.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = T_FIELDCAT[]
TABLES
T_OUTTAB = <FS>.
&----
*& Form MOVE_DATA
&----
text
----
FORM MOVE_DATA.
LOOP AT ITAB.
CLEAR STR.
CONCATENATE ITAB-MATNR ' ' INTO STR SEPARATED BY SPACE.
LOOP AT S_WERKS.
CLEAR MARC.
SELECT SINGLE * FROM MARC WHERE MATNR = ITAB-MATNR AND WERKS = S_WERKS-LOW.
IF SY-SUBRC EQ 0.
CLEAR TEXT1.
TEXT1 = MARC-EISLO.
CONCATENATE STR TEXT1 INTO STR SEPARATED BY SPACE.
ELSE.
CONCATENATE STR '0' INTO STR SEPARATED BY SPACE.
ENDIF.
ENDLOOP.
<WA> = STR.
APPEND <WA> TO <FS>.
CLEAR ITAB.
ENDLOOP.
ENDFORM. "MOVE_DATA
Reward points if helpful.
Regards,
Sankar..
2008 Mar 20 12:03 PM
2008 Mar 20 12:36 PM
Hi Amit,
Please go through the logic of the standard ALV program
BCALV_TABLE_CREATE.
Regards,
Kumar.