pls friends give me a solution ...........
this is my program
where the actual program
in loop only its staying.......
REPORT ZMM_ASSIGNMENT03.
*PROVIDE TABLES WORKAREA.
TABLES : LFA1,MAKT,MSEG,MKPF.
TYPE-POOLS SLIS.
*PROVIDE DATA OBJECTS.
TYPES : BEGIN OF TY_LFA1,
LIFNR TYPE LIFNR,
NAME1 TYPE NAME1,
END OF TY_LFA1.
TYPES : BEGIN OF TY_MAKT,
MATNR TYPE MATNR,
MAKTX TYPE MAKTX,
END OF TY_MAKT.
TYPES : BEGIN OF TY_MSEG,
MATNR TYPE MATNR,
LIFNR TYPE ELIFN,
MENGE TYPE MENGE_D,
DMBTR TYPE DMBTR,
BUDAT TYPE BUDAT,
END OF TY_MSEG.
TYPES : BEGIN OF TY_FINAL,
KEY TYPE I,
MATNR TYPE MATNR,
MAKTX TYPE MAKTX,
LIFNR TYPE LIFNR,
NAME1 TYPE NAME1,
MENGE TYPE MENGE_D,
AVGPR TYPE DMBTR,
END OF TY_FINAL.
TYPES : BEGIN OF TY_MARA,
MATNR TYPE MATNR,
END OF TY_MARA.
DATA : WA_LFA1 TYPE TY_LFA1,
WA_MAKT TYPE TY_MAKT,
WA_MSEG TYPE TY_MSEG,
WA_MARA TYPE TY_MARA,
WA_FINAL TYPE TY_FINAL,
IT_MARA TYPE TABLE OF TY_MARA,
IT_LFA1 TYPE TABLE OF TY_LFA1,
IT_MAKT TYPE TABLE OF TY_MAKT,
IT_MSEG TYPE TABLE OF TY_MSEG,
IT_FINAL TYPE TABLE OF TY_FINAL,
IT_FINAL1 TYPE TABLE OF TY_FINAL.
*PROVIDE SELECTION SCREEN.
SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-000.
SELECT-OPTIONS : S_MATNR FOR MSEG-MATNR,
S_WERKS FOR MSEG-WERKS,
S_LGORT FOR MSEG-LGORT,
S_BUDAT FOR MKPF-BUDAT,
S_BUKRS FOR MSEG-BUKRS.
SELECTION-SCREEN : END OF BLOCK B1.
DATA : WA_FCAT TYPE SLIS_FIELDCAT_ALV,
IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
KEY TYPE SLIS_KEYINFO_ALV.
CONSTANTS : P_MATNR TYPE SLIS_FIELDNAME VALUE 'MATNR',
P_MAKTX TYPE SLIS_FIELDNAME VALUE 'MAKTX',
P_LIFNR TYPE SLIS_FIELDNAME VALUE 'LIFNR',
P_NAME1 TYPE SLIS_FIELDNAME VALUE 'NAME1',
P_MENGE TYPE SLIS_FIELDNAME VALUE 'MENGE',
P_AVGPR TYPE SLIS_FIELDNAME VALUE 'AVGPR',
P_RFT TYPE C VALUE 'R',
P_LFT TYPE C VALUE 'L',
C_FLAG TYPE C VALUE 'X',
P_TABNAME TYPE SLIS_TABNAME VALUE 'IT_FINAL'.
DATA : DATE(10) TYPE C,
HEADER(10) TYPE C,
MENGE TYPE MENGE_D,
AVGPR TYPE DMBTR,
COUNT TYPE I,
TOTAL TYPE DMBTR.
PERFORM GET_DATA.
PERFORM COMBINE_DATA.
PERFORM KEY.
PERFORM FILL_CAT USING : "FIELD NAME LABEL HOTSPOT DO SUM FORMAT OUTPUTLEN
P_MATNR 'Material Code' SPACE SPACE P_RFT SPACE,
P_MAKTX 'Material Desc' SPACE SPACE P_RFT SPACE,
P_LIFNR 'Vendor Code' SPACE SPACE P_RFT SPACE,
P_NAME1 'Vendor Name' SPACE SPACE P_RFT SPACE,
P_MENGE 'Mat Quantity' SPACE SPACE P_LFT SPACE,
P_MATNR 'Average Price' SPACE SPACE P_LFT SPACE.
PERFORM DISPLAY_HIERSEQ.
FORM GET_DATA.
SELECT MATNR FROM MARA INTO TABLE IT_MARA WHERE MATNR IN S_MATNR.
IF NOT IT_MARA IS INITIAL.
SELECT MATNR MAKTX FROM MAKT INTO TABLE IT_MAKT FOR ALL ENTRIES IN IT_MARA WHERE MATNR = IT_MARA-MATNR.
ENDIF.
SELECT A~MATNR A~LIFNR A~MENGE A~DMBTR
B~BUDAT INTO TABLE IT_MSEG FROM MSEG AS A INNER JOIN MKPF AS B ON A~MBLNR = B~MBLNR WHERE A~MATNR IN S_MATNR
AND A~WERKS IN S_WERKS
AND A~LGORT IN S_LGORT
AND B~BUDAT IN S_BUDAT
AND A~BUKRS IN S_BUKRS.
IF NOT IT_MSEG IS INITIAL.
SELECT LIFNR NAME1 FROM LFA1 INTO TABLE IT_LFA1 FOR ALL ENTRIES IN IT_MSEG WHERE LIFNR = IT_MSEG-LIFNR.
ENDIF.
ENDFORM.
FORM COMBINE_DATA.
LOOP AT IT_MARA INTO WA_MARA.
LOOP AT IT_MSEG INTO WA_MSEG WHERE MATNR = WA_MARA-MATNR.
WA_FINAL-MATNR = WA_MSEG-MATNR.
READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = WA_MSEG-MATNR.
WA_FINAL-MAKTX = WA_MAKT-MAKTX.
READ TABLE IT_LFA1 INTO WA_LFA1 WITH KEY LIFNR = WA_MSEG-LIFNR.
WA_FINAL-LIFNR = WA_LFA1-LIFNR.
WA_FINAL-NAME1 = WA_LFA1-NAME1.
COUNT = COUNT + 1.
TOTAL = TOTAL + WA_MSEG-DMBTR.
ENDLOOP.
MENGE = MENGE + WA_MSEG-MENGE.
WA_FINAL-MENGE = MENGE.
AVGPR = TOTAL / COUNT.
WA_FINAL-AVGPR = AVGPR.
APPEND WA_FINAL TO IT_FINAL.
ENDLOOP.
ENDFORM.
FORM KEY.
KEY-HEADER01 = KEY.
KEY-ITEM01 = KEY.
ENDFORM.
FORM FILL_CAT USING : A B C D E F.
WA_FCAT-TABNAME = P_TABNAME.
WA_FCAT-FIELDNAME = A.
WA_FCAT-SELTEXT_M = B.
WA_FCAT-HOTSPOT = C.
WA_FCAT-DO_SUM = D.
WA_FCAT-JUST = E.
WA_FCAT-OUTPUTLEN = F.
APPEND WA_FCAT TO IT_FCAT.
ENDFORM.
FORM DISPLAY_HIERSEQ.
APPEND LINES OF IT_FINAL TO IT_FINAL1.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
IT_FIELDCAT = IT_FCAT
I_TABNAME_HEADER = 'IT_FINAL1'
I_TABNAME_ITEM = 'IT_FINAL'
IS_KEYINFO = KEY
TABLES
T_OUTTAB_HEADER = IT_FINAL1
T_OUTTAB_ITEM = IT_FINAL.
ENDFORM.