HI...i am fresher i have a problem
I have created a zbom report ,but the problem is that it shows all components of all alternate bom in single alternate bom number.
what i need is it has to show components according to alternate bom number,,,,
and here is my code please help for this issue,
*&---------------------------------------------------------------------*
*& Report ZNEW_BOM *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZNEW_BOM .
TYPE-POOLS: SLIS.
TYPES : BEGIN OF ty_mast,
matnr TYPE mast-matnr, "Main Material (Parent)
werks TYPE mast-werks, "plant
stlan TYPE mast-stlan, "bom usage
stlnr TYPE mast-stlnr, "bom
stlal TYPE mast-stlal, "altbom
END OF ty_mast.
TYPES : BEGIN OF ty_stko,
stlnr TYPE stko-stlnr,
stlal TYPE stko-stlal,
datuv TYPE stko-datuv,
bmein TYPE stko-bmein,
bmeng TYPE stko-bmeng,
END OF ty_stko.
TYPES : BEGIN OF ty_stpo,
stlnr TYPE stpo-stlnr,
datuv TYPE stpo-datuv,
idnrk TYPE stpo-idnrk, "BOM Component (Child)
posnr TYPE stpo-posnr,
meins TYPE stpo-meins,
menge TYPE stpo-menge, "Bom Material Req Qty.
END OF ty_stpo.
TYPES : BEGIN OF ty_mara,
matnr TYPE mara-matnr,
brgew TYPE mara-brgew,
END OF ty_mara.
* Output Data
TYPES: BEGIN OF type_output,
werks TYPE mast-werks, " Plant
matnr TYPE mast-matnr, " Material Number
brgew TYPE mara-brgew,
stlnr TYPE mast-stlnr, " Bill of material
stlan TYPE mast-stlan, " BOM Usage
stlal TYPE mast-stlal, " Alternative BOM
datuv TYPE stko-datuv,
bmein TYPE stko-bmein,
bmeng TYPE stko-bmeng,
idnrk TYPE stpo-idnrk, "Material Component (Child)
posnr TYPE stpo-posnr,
meins TYPE stpo-meins,
menge TYPE stpo-menge, "Bom Material Req Qty.
END OF type_output.
*&---------------------------------------------------------------------*
*& DATA DECLARATION
*&---------------------------------------------------------------------*
DATA : it_mast TYPE TABLE OF ty_mast,
wa_mast LIKE LINE OF it_mast.
DATA : it_mara TYPE TABLE OF ty_mara,
wa_mara LIKE LINE OF it_mara.
DATA : it_stko TYPE TABLE OF ty_stko,
wa_stko LIKE LINE OF it_stko.
DATA : it_stpo TYPE TABLE OF ty_stpo,
wa_stpo LIKE LINE OF it_stpo.
* Output table
DATA: it_output TYPE STANDARD TABLE OF type_output,
wa_output TYPE type_output.
* Field Catalog table
DATA: it_fcat TYPE TABLE OF slis_fieldcat_alv, " Internal table for field catal
wa_fcat TYPE slis_fieldcat_alv. " Work area for field catalog
*&---------------------------------------------------------------------*
*& LAYOUT
*&---------------------------------------------------------------------*
PARAMETERS : p_matnr TYPE mara-matnr,
p_werks TYPE mseg-werks,
P_stlan type mast-stlan.
*&---------------------------------------------------------------------*
*& MAIN PROGRAM
*&---------------------------------------------------------------------*
perform fetch.
perform fieldcat.
*&---------------------------------------------------------------------*
*& Form fetch
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fetch .
SELECT matnr werks stlan stlnr stlal
FROM mast INTO TABLE it_mast
WHERE matnr = p_matnr and
werks = p_werks and
stlan = p_stlan.
IF it_mast IS NOT INITIAL.
SELECT stlnr stlal datuv bmein bmeng
FROM stko INTO TABLE it_stko
FOR ALL ENTRIES IN it_mast
WHERE stlnr = it_mast-stlnr AND
stlal = it_mast-stlal.
ENDIF.
IF it_stko IS NOT INITIAL.
SELECT stlnr datuv idnrk posnr meins menge
FROM stpo INTO TABLE it_stpo
FOR ALL ENTRIES IN it_mast
WHERE stlnr = it_mast-stlnr.
ENDIF.
IF it_stpo IS NOT INITIAL.
SELECT matnr brgew
FROM mara INTO TABLE it_mara
FOR ALL ENTRIES IN it_stpo
WHERE matnr = it_stpo-idnrk.""""""""""""""""
ENDIF.
loop at it_mast into wa_mast.
MOVE: wa_mast-werks TO wa_output-werks,
wa_mast-matnr TO wa_output-matnr,
wa_mast-stlnr TO wa_output-stlnr,
wa_mast-stlan TO wa_output-stlan,
wa_mast-stlal TO wa_output-stlal.
READ TABLE it_stko INTO wa_stko WITH KEY stlnr = wa_mast-stlnr.
move: wa_stko-datuv TO wa_output-datuv,
wa_stko-bmeng TO wa_output-bmeng,
wa_stko-bmein to wa_output-bmein,
wa_stko-stlnr to wa_output-stlnr.
clear wa_stko.
loop at it_stpo INTO wa_stpo where stlnr = wa_mast-stlnr.
move: wa_stpo-idnrk TO wa_output-idnrk,
wa_stpo-posnr TO wa_output-posnr,
wa_stpo-menge TO wa_output-menge,
wa_stpo-meins to wa_output-meins.
APPEND wa_output TO it_output.
clear wa_stpo.
Endloop.
READ TABLE it_mara INTO wa_mara WITH KEY MATNR = wa_mast-stlnr.
MOVE: wa_mara-matnr TO wa_output-matnr,
wa_mara-brgew to wa_output-brgew.
CLEAR WA_MARA.
APPEND wa_output TO it_output.
ENDLOOP.
ENDFORM. " fetch
*&---------------------------------------------------------------------*
*& Form fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fieldcat .
WA_FCAT-COL_POS = '1'.
WA_FCAT-FIELDNAME = 'MATNR'.
WA_FCAT-TABNAME = 'IT_OUTPUT'.
WA_FCAT-SELTEXT_L = 'MATERIAL'.
WA_FCAT-OUTPUTLEN = '9'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '2'.
WA_FCAT-FIELDNAME = 'WERKS'.
WA_FCAT-TABNAME = 'IT_OUTPUT'.
WA_FCAT-SELTEXT_L = 'PLANT'.
WA_FCAT-OUTPUTLEN = '8'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '3'.
WA_FCAT-FIELDNAME = 'STLAN'.
WA_FCAT-TABNAME = 'IT_OUTPUT'.
WA_FCAT-SELTEXT_L = 'BOM USAGE'.
WA_FCAT-OUTPUTLEN = '9'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '4'.
WA_FCAT-FIELDNAME = 'STLAL'.
WA_FCAT-TABNAME = 'IT_OUTPUT'.
WA_FCAT-SELTEXT_L = 'ALTBOM'.
WA_FCAT-OUTPUTLEN = '9'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '5'.
WA_FCAT-FIELDNAME = 'STLNR'.
WA_FCAT-TABNAME = 'IT_OUTPUT'.
WA_FCAT-SELTEXT_L = 'BOM'.
WA_FCAT-OUTPUTLEN = '9'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '6'.
WA_FCAT-FIELDNAME = 'IDNRK'.
WA_FCAT-TABNAME = 'IT_OUTPUT'.
WA_FCAT-SELTEXT_L = 'BOM COMPONENT'.
WA_FCAT-OUTPUTLEN = '20'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '7'.
WA_FCAT-FIELDNAME = 'BMENG'.
WA_FCAT-TABNAME = 'IT_OUTPUT'.
WA_FCAT-SELTEXT_L = 'BASE QUANTITY'.
WA_FCAT-OUTPUTLEN = '6'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '8'.
WA_FCAT-FIELDNAME = 'BRGEW'.
WA_FCAT-TABNAME = 'IT_OUTPUT'.
WA_FCAT-SELTEXT_L = 'GROSS WEIGHT'.
WA_FCAT-OUTPUTLEN = '6'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '9'.
WA_FCAT-FIELDNAME = 'MEINS'.
WA_FCAT-TABNAME = 'IT_OUTPUT'.
WA_FCAT-SELTEXT_L = 'BASE UNIT OF MEASURE'.
WA_FCAT-OUTPUTLEN = '6'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '10'.
WA_FCAT-FIELDNAME = 'MENGE'.
WA_FCAT-TABNAME = 'IT_OUTPUT'.
WA_FCAT-SELTEXT_L = 'COMPONENT QUANTITY'.
WA_FCAT-OUTPUTLEN = '10'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '11'.
WA_FCAT-FIELDNAME = 'MEINS'.
WA_FCAT-TABNAME = 'IT_OUTPUT'.
WA_FCAT-SELTEXT_L = 'BASE UNIT'.
WA_FCAT-OUTPUTLEN = '6'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-CPROG
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME = WA_OUTPUT
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = IT_FCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_OUTPUT
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " fieldcat