SAP ABAP ALV Report with Double Click Event

sap abap programming report sample code is about using alv double click event and its execution in a alv report.The sample coding is as shown below.


type-pools:
slis.
tables:
mara.

types:
begin of x_mara,
matnr like mara-matnr,
box(1),
end of x_mara.

data:
t_mara type standard table of x_mara,
t_events type SLIS_T_EVENT,
t_fieldcat type SLIS_T_FIELDCAT_ALV with header line.

data:
wa_matnr type x_mara,
WA_FIELDCAT LIKE t_fieldcat.
selection-screen begin of block b1.
select-options:
s_matnr for mara-matnr.
selection-screen end of block b1.

start-of-selection.

select matnr from mara into table t_mara
where matnr in s_matnr.
if sy-subrc = 0.
sort t_mara by matnr.
endif.

t_fieldcat-fieldname = 'BOX'.
t_fieldcat-seltext_l = 'Selection'.
t_fieldcat-tabname = 'T_MARA'.
t_fieldcat-checkbox = 'X'.
t_fieldcat-col_pos = 1.
t_fieldcat-input = 'X'.
t_fieldcat-edit = 'X'.
*T_FIELDCAT-hotspot = 'X'.
append t_fieldcat.

clear t_fieldcat.

t_fieldcat-fieldname = 'MATNR'.
t_fieldcat-seltext_l = 'Material'.
t_fieldcat-tabname = 'T_MARA'.
t_fieldcat-col_pos = 2.
T_FIELDCAT-hotspot = 'X'.
append t_fieldcat.

perform f_get_events.
perform f_display_report.

FORM USER_COMMAND1 USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
data:
l_matnr like mara-matnr.

CALL FUNCTION 'CONVERSION_EXIT_MATN2_INPUT'
EXPORTING
input = rs_selfield-value
IMPORTING
OUTPUT = l_matnr.
IF sy-subrc 0.
  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

delete t_mara where matnr = l_matnr.
perform f_display_report.
  • perform f_display_report.
  • CALL TRANSACTION 'KO03' AND SKIP FIRST SCREEN.
ENDFORM. " USER_COMMAND1

&---------------------------------------------------------------------
*& Form f_display_report
----------------------------------------------------------------------
form f_display_report.

data:
l_prog like sy-repid.
l_prog = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
  • I_INTERFACE_CHECK = ' '
  • I_BYPASSING_BUFFER =
  • I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = l_prog
  • I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = 'USER_COMMAND1'
  • I_CALLBACK_TOP_OF_PAGE = ' '
  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '
  • I_CALLBACK_HTML_END_OF_LIST = ' '
  • I_STRUCTURE_NAME =
  • I_BACKGROUND_ID = ' '
  • I_GRID_TITLE =
  • I_GRID_SETTINGS =
  • IS_LAYOUT =
IT_FIELDCAT = t_fieldcat[]
  • 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_ADD_FIELDCAT =
  • IT_HYPERLINK =
  • I_HTML_HEIGHT_TOP =
  • I_HTML_HEIGHT_END =
  • IT_EXCEPT_QINFO =
  • IMPORTING
  • E_EXIT_CAUSED_BY_CALLER =
  • ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = t_mara
  • 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. " f_display_report

here all meterials are displayed, as N when i click on the material number it will delete the selected material from the list and it will display's the report, like wise your can check the interactive event how it will works.

ABAP Report ALV Block List in SAP Programming

This sap programming report with sample code using abap programming language explains you how to use alv block list to append the report.

REPORT ZALVBLOCK .

TYPE-POOLS : SLIS.

TABLES : AFKO,AFPO.

TYPES : BEGIN OF SAFPO ,
AUFNR LIKE AFPO-AUFNR,
POSNR LIKE AFPO-POSNR,
PLNUM LIKE AFPO-PLNUM,
STRMP LIKE AFPO-STRMP,
MATNR LIKE AFPO-MATNR,
PSMNG LIKE AFPO-PSMNG,
MEINS LIKE AFPO-MEINS,
END OF SAFPO.
TYPES : BEGIN OF SAFKO,
AUFNR LIKE AFKO-AUFNR,
END OF SAFKO.
DATA : IAFKO TYPE TABLE OF SAFKO WITH HEADER LINE,
IAFPO TYPE TABLE OF SAFPO WITH HEADER LINE.

DATA : IFIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV,
WFIELDCAT1 TYPE SLIS_FIELDCAT_ALV,
ILAYOUT1 TYPE SLIS_LAYOUT_ALV,
IEVENT1 TYPE SLIS_T_EVENT,
WEVENT1 TYPE SLIS_ALV_EVENT,
IKEYINFO1 TYPE SLIS_KEYINFO_ALV.

DATA : IFIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV,
WFIELDCAT2 TYPE SLIS_FIELDCAT_ALV,
ILAYOUT2 TYPE SLIS_LAYOUT_ALV,
IEVENT2 TYPE SLIS_T_EVENT,
WEVENT2 TYPE SLIS_ALV_EVENT.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS : S_AUFNR FOR AFKO-AUFNR,
S_GLTRP FOR AFKO-GLTRP.

SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID.
  • I_CALLBACK_PF_STATUS_SET = ' '
  • I_CALLBACK_USER_COMMAND = ' '
  • IT_EXCLUDING =
.

PERFORM GET_DATA.
PERFORM BUILD_FIELDCAT.
PERFORM BUILD_LAYOUT.
PERFORM BUILD_EVENT.
PERFORM BUILD_KEYINFO.

PERFORM BUILD_FIELDCAT2.
PERFORM BUILD_LAYOUT2.
PERFORM BUILD_EVENT2.

PERFORM DISPLAY_BLOCK1.

PERFORM DISPLAY_BLOCK2.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
  • EXPORTING
  • I_INTERFACE_CHECK = ' '
  • IS_PRINT =
  • I_SCREEN_START_COLUMN = 0
  • I_SCREEN_START_LINE = 0
  • I_SCREEN_END_COLUMN = 0
  • I_SCREEN_END_LINE = 0
  • IMPORTING
  • E_EXIT_CAUSED_BY_CALLER =
  • ES_EXIT_CAUSED_BY_USER =
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.
&---------------------------------------------------------------------
*& Form GET_DATA
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM GET_DATA .
SELECT AUFNR FROM AFKO INTO CORRESPONDING FIELDS OF TABLE IAFKO
WHERE AUFNR IN S_AUFNR AND GLTRP IN S_GLTRP.

SELECT AUFNR POSNR PLNUM STRMP MATNR PSMNG MEINS FROM AFPO INTO CORRESPONDING FIELDS OF TABLE
IAFPO WHERE AUFNR IN S_AUFNR.
ENDFORM. " GET_DATA
&---------------------------------------------------------------------
*& Form BUILD_FIELDCAT
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM BUILD_FIELDCAT .
REFRESH : IFIELDCAT1.

*WFIELDCAT1-FIELDNAME = 'AUFNR'.
*WFIELDCAT1-COL_POS = '1'.
*WFIELDCAT1-SELTEXT_L = 'Order No'.
*APPEND WFIELDCAT1 TO IFIELDCAT1.
*CLEAR WFIELDCAT1.
WFIELDCAT1-FIELDNAME = 'GLTRP'.
WFIELDCAT1-COL_POS = '1'.
WFIELDCAT1-SELTEXT_L = 'Basic Finish Time'.
APPEND WFIELDCAT1 TO IFIELDCAT1.
CLEAR WFIELDCAT1.

WFIELDCAT1-FIELDNAME = 'GSTRP'.
WFIELDCAT1-COL_POS = '2'.
WFIELDCAT1-SELTEXT_L = 'Basic Start Time'.
APPEND WFIELDCAT1 TO IFIELDCAT1.
CLEAR WFIELDCAT1.

WFIELDCAT1-FIELDNAME = 'GAMNG'.
WFIELDCAT1-COL_POS = '3'.
WFIELDCAT1-SELTEXT_L = 'Total Order Qty'.
APPEND WFIELDCAT1 TO IFIELDCAT1.
CLEAR WFIELDCAT1.

WFIELDCAT1-FIELDNAME = 'GMEIN'.
WFIELDCAT1-COL_POS = '4'.
WFIELDCAT1-SELTEXT_L = 'UOM'.
APPEND WFIELDCAT1 TO IFIELDCAT1.
CLEAR WFIELDCAT1.

ENDFORM. " BUILD_FIELDCAT
&---------------------------------------------------------------------
*& Form BUILD_LAYOUT
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM BUILD_LAYOUT .
ILAYOUT1-COLWIDTH_OPTIMIZE = 'X'.
ILAYOUT1-ZEBRA = 'X'.

ENDFORM. " BUILD_LAYOUT
&---------------------------------------------------------------------
*& Form BUILD_EVENT
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM BUILD_EVENT .

WEVENT1-FORM = 'TOPOFLIST1'.
WEVENT1-NAME = SLIS_EV_TOP_OF_LIST.
APPEND WEVENT1 TO IEVENT1.

ENDFORM. " BUILD_EVENT
&---------------------------------------------------------------------
*& Form DISPLAY_BLOCK1
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM DISPLAY_BLOCK1 .
*CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_HS_APPEND'
  • EXPORTING
  • IS_LAYOUT = ILAYOUT1
  • IT_FIELDCAT = IFIELDCAT2
  • IS_KEYINFO = IKEYINFO1
  • I_HEADER_TABNAME = 'IAFKO'
  • I_ITEM_TABNAME = 'IAFPO'
  • IT_EVENTS = IEVENT1
    • IT_SORT =
    • I_TEXT = ' '
  • TABLES
  • T_OUTTAB_HEADER = IAFKO
  • T_OUTTAB_ITEM = IAFPO
    • EXCEPTIONS
    • PROGRAM_ERROR = 1
    • MAXIMUM_OF_APPENDS_REACHED = 2
    • OTHERS = 3
  • .
*IF SY-SUBRC 0.
    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
*
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = ILAYOUT1
IT_FIELDCAT = IFIELDCAT1
I_TABNAME = 'IAFKO'
IT_EVENTS = IEVENT1
  • IT_SORT =
  • I_TEXT = ' '
TABLES
T_OUTTAB = IAFKO
EXCEPTIONS
PROGRAM_ERROR = 1
MAXIMUM_OF_APPENDS_REACHED = 2
OTHERS = 3
.
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. " DISPLAY_BLOCK1

FORM TOPOFLIST1.

WRITE :/10 'TABLE AFKO CONTENTS'.
WRITE :/(30) SY-ULINE.

ENDFORM.
&---------------------------------------------------------------------
*& Form BUILD_FIELDCAT2
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM BUILD_FIELDCAT2 .
REFRESH : IFIELDCAT2.
WFIELDCAT2-FIELDNAME = 'AUFNR'.
WFIELDCAT2-COL_POS = '1'.
WFIELDCAT2-SELTEXT_L = 'Order No'.
APPEND WFIELDCAT2 TO IFIELDCAT2.
CLEAR WFIELDCAT2.

WFIELDCAT2-FIELDNAME = 'POSNR'.
WFIELDCAT2-COL_POS = '2'.
WFIELDCAT2-SELTEXT_L = 'Order Item No'.
APPEND WFIELDCAT2 TO IFIELDCAT2.
CLEAR WFIELDCAT2.

WFIELDCAT2-FIELDNAME = 'PLNUM'.
WFIELDCAT2-COL_POS = '3'.
WFIELDCAT2-SELTEXT_L = 'Planned Order No'.
APPEND WFIELDCAT2 TO IFIELDCAT2.
CLEAR WFIELDCAT2.

WFIELDCAT2-FIELDNAME = 'STRMP'.
WFIELDCAT2-COL_POS = '4'.
WFIELDCAT2-SELTEXT_L = 'Strt Dt Plnd ordr No'.
APPEND WFIELDCAT2 TO IFIELDCAT2.
CLEAR WFIELDCAT2.

WFIELDCAT2-FIELDNAME = 'MATNR'.
WFIELDCAT2-COL_POS = '5'.
WFIELDCAT2-SELTEXT_L = 'Material No'.
APPEND WFIELDCAT2 TO IFIELDCAT2.
CLEAR WFIELDCAT2.

WFIELDCAT2-FIELDNAME = 'PSMNG'.
WFIELDCAT2-COL_POS = '6'.
WFIELDCAT2-SELTEXT_L = 'Pland Ordr Qty'.
APPEND WFIELDCAT2 TO IFIELDCAT2.
CLEAR WFIELDCAT2.

WFIELDCAT2-FIELDNAME = 'MEINS'.
WFIELDCAT2-COL_POS = '7'.
WFIELDCAT2-SELTEXT_L = 'UOM'.
APPEND WFIELDCAT2 TO IFIELDCAT2.
CLEAR WFIELDCAT2.
ENDFORM. " BUILD_FIELDCAT2
&---------------------------------------------------------------------
*& Form BUILD_LAYOUT2
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM BUILD_LAYOUT2 .
ILAYOUT2-COLWIDTH_OPTIMIZE = 'X'.
ILAYOUT2-ZEBRA = 'X'.
ENDFORM. " BUILD_LAYOUT2
&---------------------------------------------------------------------
*& Form BUILD_EVENT2
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM BUILD_EVENT2 .

WEVENT2-FORM = 'TOPOFLIST2'.
WEVENT2-NAME = SLIS_EV_TOP_OF_LIST.
APPEND WEVENT2 TO IEVENT2.
CLEAR WEVENT2.

ENDFORM. " BUILD_EVENT2
&---------------------------------------------------------------------
*& Form DISPLAY_BLOCK2
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM DISPLAY_BLOCK2 .
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = ILAYOUT2
IT_FIELDCAT = IFIELDCAT2
I_TABNAME = 'IAFPO'
IT_EVENTS = IEVENT2
  • IT_SORT =
  • I_TEXT = ' '
TABLES
T_OUTTAB = IAFPO
  • EXCEPTIONS
  • PROGRAM_ERROR = 1
  • MAXIMUM_OF_APPENDS_REACHED = 2
  • OTHERS = 3
.
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. " DISPLAY_BLOCK2

FORM TOPOFLIST2.
WRITE : /10 'TABLE AFPO CONTENTS'.
WRITE :/(35) SY-ULINE.
ENDFORM.
&---------------------------------------------------------------------
*& Form BUILD_KEYINFO
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM BUILD_KEYINFO .
IKEYINFO1-HEADER01 = 'AUFNR'.
IKEYINFO1-ITEM01 = 'AUFNR'.
ENDFORM. " BUILD_KEYINFO


ABAP ALV Hirarchical Report Sample Code in sap programming

ABAP programming report for alv hierarchical report in sample code gives you a real time report that tells you in detail with example coding how to write the abap programming report.









&---------------------------------------------------------------------
*& Report Z_HIERARCHIAL_ALV *
*& *
&---------------------------------------------------------------------
*& *
*& *
&---------------------------------------------------------------------

REPORT ZGDEMO_HIERARCHIAL_ALV_9AM .
TYPE-POOLS SLIS.
DATA : IT_EKKO TYPE TABLE OF EKKO,
IT_EKPO TYPE TABLE OF EKPO.

DATA WA_KEYINFO TYPE SLIS_KEYINFO_ALV.

****************************************
  • START-OF-SELECTION. *
****************************************
START-OF-SELECTION.
PERFORM READ_DATA.

PERFORM FILL_KEYINFO.

PERFORM DISPLAY_DATA.

&---------------------------------------------------------------------
*& Form READ_DATA
&---------------------------------------------------------------------
form READ_DATA .

SELECT * INTO TABLE IT_EKKO FROM EKKO UP TO 20 ROWS.

IF NOT IT_EKKO IS INITIAL.
SELECT * INTO TABLE IT_EKPO FROM EKPO
FOR ALL ENTRIES
IN IT_EKKO
WHERE EBELN = IT_EKKO-EBELN.
ENDIF.

endform. " READ_DATA

&---------------------------------------------------------------------
*& Form FILL_KEYINFO
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
form FILL_KEYINFO .
WA_KEYINFO-HEADER01 = 'EBELN'.
WA_KEYINFO-ITEM01 = 'EBELN'.
WA_KEYINFO-ITEM02 = 'EBELP'.
endform. " FILL_KEYINFO
&---------------------------------------------------------------------
*& Form DISPLAY_DATA
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="li" p2="p2" text="text">
----------------------------------------------------------------------
form DISPLAY_DATA .
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
  • I_INTERFACE_CHECK = ' '
I_CALLBACK_PROGRAM = SY-REPID
  • I_CALLBACK_PF_STATUS_SET = ' '
  • I_CALLBACK_USER_COMMAND = ' '
  • IS_LAYOUT =
  • IT_FIELDCAT =
  • IT_EXCLUDING =
  • IT_SPECIAL_GROUPS =
  • IT_SORT =
  • IT_FILTER =
  • IS_SEL_HIDE =
  • I_SCREEN_START_COLUMN = 0
  • I_SCREEN_START_LINE = 0
  • I_SCREEN_END_COLUMN = 0
  • I_SCREEN_END_LINE = 0
  • I_DEFAULT = 'X'
  • I_SAVE = ' '
  • IS_VARIANT =
  • IT_EVENTS =
  • IT_EVENT_EXIT =
i_tabname_header = 'IT_EKKO'
i_tabname_item = 'IT_EKPO'
I_STRUCTURE_NAME_HEADER = 'EKKO'
I_STRUCTURE_NAME_ITEM = 'EKPO'
is_keyinfo = WA_KEYINFO
  • IS_PRINT =
  • IS_REPREP_ID =
  • I_BYPASSING_BUFFER =
  • I_BUFFER_ACTIVE =
  • IMPORTING
  • E_EXIT_CAUSED_BY_CALLER =
  • ES_EXIT_CAUSED_BY_USER =
tables
t_outtab_header = IT_EKKO
t_outtab_item = IT_EKPO
  • 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. " DISPLAY_DATA

Related Posts:

SAP ABAP HR report for EEOC
ABAP Programming hr new hire report
SAP ABAP HR PAYROLL REPORT
ABAP HR head count report for sap
SAP ABAP FICO REPORT FOR GROUP CURRENCY RECONCILIATION
fico reconcilation report for company code currency report

 SAP ABAP FICO report about profitability analysis
SAP ABAP fico report profitability analysis report
 My sapcrm customers and consumer segmentation
Organizational challenges in crm and mysap solutions
Business View and Mysap.com
What is SAP R/3 introduction to mysap.com
SAP FICO cross company code reconciliation report
sap sales and distribution back orders report in abap

sales in erp programming invoice report
sap abap programming in mm module report about purchase order
abap programming sample report for materiel documents
sap programming report with oops concept

ABAP Programming Report sample code with OOPS concept

This abap programming report with sap can be used to get the data from sap data base using oops concept is as shown below.

The variant on selection screen


Material ............ 100-100 to 100-200
Plant................ 1000 to 2000
BOM Usage............ 1 to 1
BOM status........... 01 to 01
BOM category........ D to P

SAMPLE CODE

**---------------------------------------------------------------------
*
*                           T Y P E S                                 *
*---------------------------------------------------------------------*
TYPES:
* Material Data
BEGIN OF TYPE_MAST,
 MATNR LIKE MAST-MATNR,             " Material Number
 WERKS LIKE MAST-WERKS,             " Plant
 STLAN LIKE MAST-STLAN,             " BOM Usage
 STLNR LIKE MAST-STLNR,             " Bill of material
 STLAL LIKE MAST-STLAL,             " Alternative BOM
END OF TYPE_MAST,

* Material Description Data
BEGIN OF TYPE_MAKT,
 MATNR LIKE MAKT-MATNR,             " Material Number
 MAKTX LIKE MAKT-MAKTX,             " Material Description
END OF TYPE_MAKT,

* BOM Header Data
BEGIN OF TYPE_STKO,
 STLTY LIKE STKO-STLTY,             " BOM category
 STLNR LIKE STKO-STLNR,             " Bill of material
 STLAL LIKE STKO-STLAL,             " Alternative BOM
 DATUV LIKE STKO-DATUV,             " Valid-From Date
 BMENG LIKE STKO-BMENG,             " Base Quantity
 STKTX LIKE STKO-STKTX,             " Alternative BOM Text
 STLST LIKE STKO-STLST,             " BOM status
END OF TYPE_STKO,

* BOM Text Data
BEGIN OF TYPE_STZU,
 STLTY LIKE STZU-STLTY,             " BOM category
 STLNR LIKE STZU-STLNR,             " Bill of material
 ZTEXT LIKE STZU-ZTEXT,             " BOM text
END OF TYPE_STZU,

* BOM Item Data
BEGIN OF TYPE_STPO,
 STLTY LIKE STPO-STLTY,             " BOM category
 STLNR LIKE STPO-STLNR,             " Bill of material
 IDNRK LIKE STPO-IDNRK,             " BOM component
 POSTP LIKE STPO-POSTP,             " Item Category(BOM)
 POSNR LIKE STPO-POSNR,             " BOM Item Number
 MENGE LIKE STPO-MENGE,             " Component quantity
END OF TYPE_STPO,

* Output Data
BEGIN OF TYPE_OUTPUT,

 WERKS LIKE MAST-WERKS,             " Plant
 MATNR LIKE MAST-MATNR,             " Material Number
 MAKTX LIKE MAKT-MAKTX,             " Material Description
 STLNR LIKE MAST-STLNR,             " Bill of material
 STLAN LIKE MAST-STLAN,             " BOM Usage
 STLAL LIKE MAST-STLAL,             " Alternative BOM

 STLTY LIKE STKO-STLTY,             " BOM category
 DATUV LIKE STKO-DATUV,             " Valid-From Date
 BMENG LIKE STKO-BMENG,             " Base Quantity
 STKTX LIKE STKO-STKTX,             " Alternative BOM Text
 STLST LIKE STKO-STLST,             " BOM status
 IDNRK LIKE STPO-IDNRK,             " BOM component
 POSTP LIKE STPO-POSTP,             " Item Category(BOM)
 POSNR LIKE STPO-POSNR,             " BOM Item Number
 MENGE LIKE STPO-MENGE,             " Component quantity
 ZTEXT LIKE STZU-ZTEXT,             " BOM text
END OF TYPE_OUTPUT.

*----------------------------------------------------------------------
*
*                            D A T A
*
*----------------------------------------------------------------------
*
DATA:
W_MATNR TYPE MARA-MATNR,             " Material Number
W_WERKS TYPE MAST-WERKS,             " Plant
W_STLAN TYPE MAST-STLAN,             " BOM Usage
W_STLST TYPE STKO-STLST,             " BOM status
W_STLTY TYPE STKO-STLTY,             " BOM category

W_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
W_ALV_GRID  TYPE REF TO CL_GUI_ALV_GRID,
OK_CODE     LIKE SY-UCOMM.

*---------------------------------------------------------------------*
*                  I N T E R N A L   T A B L E S                      *
*---------------------------------------------------------------------*
DATA:
* Material Data
I_MAST          TYPE STANDARD TABLE OF TYPE_MAST,
WA_MAST         TYPE TYPE_MAST,

* Material Description Data
I_MAKT          TYPE STANDARD TABLE OF TYPE_MAKT,
WA_MAKT         TYPE TYPE_MAKT,

* BOM Header Data
I_STKO          TYPE STANDARD TABLE OF TYPE_STKO,
WA_STKO         TYPE TYPE_STKO,

* BOM Text Data
I_STZU          TYPE STANDARD TABLE OF TYPE_STZU,
WA_STZU         TYPE TYPE_STZU,

* BOM Item Data
I_STPO          TYPE STANDARD TABLE OF TYPE_STPO,
WA_STPO         TYPE TYPE_STPO,

* Output table
I_OUTPUT        TYPE STANDARD TABLE OF TYPE_OUTPUT,
WA_OUTPUT       TYPE TYPE_OUTPUT,

* Field Catalog table
IT_FCAT      TYPE LVC_T_FCAT,         " Internal table for field catal
WA_FCAT      TYPE LVC_S_FCAT.         " Work area for field catalog

*---------------------------------------------------------------------*
*                 S E L E C T I O N     S C R E E N                   *
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-SS1.
SELECT-OPTIONS:
S_MATNR FOR W_MATNR,           " Material Number
S_WERKS FOR W_WERKS OBLIGATORY," Plant
S_STLAN FOR W_STLAN,           " BOM Usage
S_STLST FOR W_STLST,           " BOM status
S_STLTY FOR W_STLTY.           " BOM category
SELECTION-SCREEN END OF BLOCK B1.

*----------------------------------------------------------------------
*
*               A T   S E L E C T I O N   S C R E E N
*
*----------------------------------------------------------------------
*
AT SELECTION-SCREEN.
PERFORM F010_VALIDATE_MATERIAL.
PERFORM F020_VALIDATE_PLANT.
PERFORM F030_VALIDATE_BOM_USAGE.
PERFORM F040_VALIDATE_BOM_STATUS.
PERFORM F050_VALIDATE_BOM_CATEGORY.

*---------------------------------------------------------------------*
*                S T A R T   O F   S E L E C T I O N                  *
*---------------------------------------------------------------------*
START-OF-SELECTION .
PERFORM F210_FETCH_BOM_LINK_DATA.
PERFORM F220_FETCH_MATERIAL_DES_DATA.
PERFORM F230_FETCH_BOM_HEADER_DATA.
PERFORM F240_FETCH_BOM_TEXT.
PERFORM F250_FETCH_BOM_ITEM_DATA.

*---------------------------------------------------------------------*
*                  E N D   O F   S E L E C T I O N                    *
*---------------------------------------------------------------------*
END-OF-SELECTION.
PERFORM F600_POPULATE_DATA.
PERFORM F650_FIELD_CATLOG.
CALL SCREEN 100.


*&--------------------------------------------------------------------*
*&      Form  f010_validate_material                                  *
*&--------------------------------------------------------------------*
*       --Validate Material                                           *
*---------------------------------------------------------------------*
FORM F010_VALIDATE_MATERIAL .

* Validate Material
IF S_MATNR IS NOT INITIAL.

 SELECT MATNR
   INTO W_MATNR
   FROM MARA
  UP TO 1 ROWS
  WHERE MATNR IN S_MATNR.
 ENDSELECT.

 CHECK SY-SUBRC NE 0.

 SET CURSOR FIELD 'S_MATNR'.
 MESSAGE 'Invalid Material' TYPE 'E'.  " Invalid Material

ENDIF.                               " IF s_matnr IS NOT INITIAL.

ENDFORM.                               " f010_validate_material

*&--------------------------------------------------------------------*
*&      Form  f020_validate_plant                                     *
*&--------------------------------------------------------------------*
*       - Validate Plant                                              *
*---------------------------------------------------------------------*
FORM F020_VALIDATE_PLANT .

* Validate Plant
SELECT  WERKS
 INTO W_WERKS
 FROM T001W
 UP TO 1 ROWS
 WHERE WERKS IN S_WERKS.
ENDSELECT.
CHECK SY-SUBRC NE 0.

SET CURSOR FIELD 'S_WERKS'.
MESSAGE 'Invalid Plant' TYPE 'E'.    " Invalid Plant

ENDFORM.                               " f020_validate_plant

*&--------------------------------------------------------------------*
*&      Form  f030_validate_BOM_usage                                 *
*&--------------------------------------------------------------------*
*       -Validate BOM Usage                                           *
*---------------------------------------------------------------------*
FORM F030_VALIDATE_BOM_USAGE .

* Validate BOM Usage
IF S_STLAN IS NOT INITIAL.

 SELECT STLAN
   INTO W_STLAN
   FROM T416
   UP TO 1 ROWS
   WHERE STLAN IN S_STLAN.
 ENDSELECT.
 CHECK SY-SUBRC NE 0.

 SET CURSOR FIELD 'S_STLAN'.
 MESSAGE 'Invalid BOM Usage' TYPE 'E'.  " Invalid BOM Usage

ENDIF.                               " IF s_stlan IS NOT INITIAL.

ENDFORM.                               " f030_validate_BOM_usage

*&--------------------------------------------------------------------*
*&      Form  f040_validate_BOM_status
*&--------------------------------------------------------------------*
*       - Validate BOM Status
*---------------------------------------------------------------------*
FORM F040_VALIDATE_BOM_STATUS .

* Validate BOM Status
IF S_STLST IS NOT INITIAL.

 SELECT  STLST
   INTO W_STLST
   FROM T415S
   UP TO 1 ROWS
   WHERE STLST IN S_STLST.
 ENDSELECT.

 CHECK SY-SUBRC NE 0.

 SET CURSOR FIELD 'S_STLST'.
 MESSAGE 'Invalid BOM Status' TYPE 'E'.  " Invalid BOM Status

ENDIF.                               " IF s_stlst IS NOT INITIAL

ENDFORM.                               " f040_validate_BOM_status

*&--------------------------------------------------------------------*
*&      Form  f050_validate_BOM_category                              *
*&--------------------------------------------------------------------*
*       -Validate BOM Category                                        *
*---------------------------------------------------------------------*
FORM F050_VALIDATE_BOM_CATEGORY .

* Validate BOM Category
IF S_STLTY IS NOT INITIAL.

 SELECT  STLTY
   INTO W_STLTY
   FROM STKO
   UP TO 1 ROWS
   WHERE STLTY IN S_STLTY.
 ENDSELECT.

 CHECK SY-SUBRC NE 0.

 SET CURSOR FIELD 'S_STLTY'.
 MESSAGE 'Invalid BOM Category' TYPE 'E'. " Invalid BOM Category

ENDIF.                               " IF s_stlty IS NOT INITIAL.

ENDFORM.                               " f050_validate_BOM_category

*&--------------------------------------------------------------------*
*&      Form  f210_fetch_bom_link_data                                *
*&--------------------------------------------------------------------*
*       - Fetch Material BOM Link data                                *
*---------------------------------------------------------------------*
FORM F210_FETCH_BOM_LINK_DATA .

* Fetch Material BOM Link data
SELECT MATNR                         " Material Number
      WERKS                         " Plant
      STLAN                         " BOM Usage
      STLNR                         " Bill of material
      STLAL                         " Alternative BOM
 INTO TABLE I_MAST
 FROM MAST
WHERE MATNR IN S_MATNR
  AND WERKS IN S_WERKS.

IF SY-SUBRC NE 0.
 MESSAGE 'No Data Found' TYPE 'E'.  " No Data Found
ENDIF.                               " IF sy-subrc NE 0.

SORT I_MAST BY MATNR WERKS.

ENDFORM.                               " f200_fetch_bom_link_data

*&--------------------------------------------------------------------*
*&      Form  f220_fetch_material_des_data                            *
*&--------------------------------------------------------------------*
*       -Fetch Material Description data                              *
*---------------------------------------------------------------------*
FORM F220_FETCH_MATERIAL_DES_DATA .

SELECT MATNR
      MAKTX
 INTO TABLE I_MAKT
 FROM MAKT
  FOR ALL ENTRIES IN I_MAST
WHERE MATNR EQ I_MAST-MATNR.

IF SY-SUBRC NE 0.
 MESSAGE 'No Data Found' TYPE 'E'.  " No Data Found
ENDIF.                               " IF sy-subrc NE 0.

SORT I_MAKT BY MATNR.

ENDFORM.                               " f200_fetch_material_des_data

*&--------------------------------------------------------------------*
*&      Form  f230_fetch_bom_header_data                              *
*&--------------------------------------------------------------------*
*       - Fetch BOM Header data                                       *
*---------------------------------------------------------------------*
FORM F230_FETCH_BOM_HEADER_DATA .

* Fetch BOM Header data
SELECT STLTY                         " BOM category
      STLNR                         " Bill of material
      STLAL                         " Alternative BOM
      DATUV                         " Valid-From Date
      BMENG                         " Base Quantity
      STKTX                         " Alternative BOM Text
      STLST                         " BOM status
 INTO TABLE I_STKO
 FROM STKO
 FOR ALL ENTRIES IN I_MAST
WHERE STLNR EQ I_MAST-STLNR
AND   STLTY IN S_STLTY
AND   STLST IN S_STLST.

IF SY-SUBRC NE 0.
 MESSAGE 'No Data Found' TYPE 'E'.  " No Data Found
ENDIF.                               " IF sy-subrc NE 0.

SORT I_STKO BY STLTY STLST.

ENDFORM.                               " f200_fetch_bom_header_data

*&--------------------------------------------------------------------*
*&      Form  f240_fetch_bom_text                                     *
*&--------------------------------------------------------------------*
*      - Fetch BOM text Data                                          *
*---------------------------------------------------------------------*
FORM F240_FETCH_BOM_TEXT .
*  DATA:
*    i_stko_temp LIKE TABLE OF wa_stko.
*
*  i_stko_temp = i_stko.
*  SORT i_stko_temp BY stlty stlnr.
*  DELETE ADJACENT DUPLICATES FROM i_stko_temp
*    COMPARING stlty stlnr.
*
*  SELECT stlty                         " BOM category
*         stlnr                         " Bill of material
*         ztext                         " BOM text
*    INTO TABLE i_stzu
*    FROM stzu
*     FOR ALL ENTRIES IN i_stko_temp
*   WHERE stlty EQ i_stko_temp-stlty
*     AND stlnr EQ i_stko_temp-stlnr.
*
*  DATA:
*    i_stzu_temp    LIKE TABLE OF wa_stzu.

SELECT STLTY                         " BOM category
      STLNR                         " Bill of material
      ZTEXT                         " BOM text
 INTO TABLE I_STZU
 FROM STZU
  FOR ALL ENTRIES IN I_STKO
WHERE STLTY EQ I_STKO-STLTY
  AND STLNR EQ I_STKO-STLNR.

IF SY-SUBRC NE 0.
 MESSAGE 'No Data Found' TYPE 'E'.  " No Data Found
ENDIF.                               " IF sy-subrc NE 0.

ENDFORM.                               " f200_fetch_bom_text

*&--------------------------------------------------------------------*
*&      Form  f250_fetch_bom_item_data                                *
*&--------------------------------------------------------------------*
*       - Fetch BOM Item data                                         *
*---------------------------------------------------------------------*
FORM F250_FETCH_BOM_ITEM_DATA .

* Fetch BOM Header data
SELECT STLTY                         " BOM category
      STLNR                         " Bill of material
      IDNRK                         " BOM component
      POSTP                         " Item Category(BOM)
      POSNR                         " BOM Item Number
      MENGE                         " Component quantity
 INTO TABLE I_STPO
 FROM STPO
  FOR ALL ENTRIES IN I_STKO
WHERE STLTY EQ I_STKO-STLTY
  AND STLNR EQ I_STKO-STLNR.

IF SY-SUBRC NE 0.
 MESSAGE 'No Data Found' TYPE 'E'.  " No Data Found
ENDIF.                               " IF sy-subrc NE 0.

ENDFORM.                               " f200_fetch_bom_item_data

*&--------------------------------------------------------------------*
*&      Form  f600_populate_data
*
*&--------------------------------------------------------------------*
*       - Displaying the data                                         *
*---------------------------------------------------------------------*
FORM F600_POPULATE_DATA .

*  SORT i_stko.
*  SORT i_mast.
*  DELETE ADJACENT DUPLICATES FROM i_mast.

LOOP AT I_STPO INTO WA_STPO.
 CLEAR WA_OUTPUT.
 READ TABLE I_STKO INTO WA_STKO WITH KEY STLNR = WA_STPO-STLNR
                                         STLTY = WA_STPO-STLTY
                                         BINARY SEARCH.
*    CHECK sy-subrc eq 0.
 READ TABLE I_STZU INTO WA_STZU WITH KEY STLNR = WA_STKO-STLNR
                                         STLTY = WA_STKO-STLTY
                                         BINARY SEARCH.
*    CHECK sy-subrc Eq 0.
 READ TABLE I_MAST INTO WA_MAST WITH KEY STLNR = WA_STKO-STLNR
                                         BINARY SEARCH.
*    CHECK sy-subrc Eq 0.
 READ TABLE I_MAKT INTO WA_MAKT WITH KEY MATNR = WA_MAST-MATNR
                                         BINARY SEARCH.
*    CHECK sy-subrc Eq 0.
 MOVE:

   WA_STPO-IDNRK TO WA_OUTPUT-IDNRK,
   WA_STPO-POSTP TO WA_OUTPUT-POSTP,
   WA_STPO-POSNR TO WA_OUTPUT-POSNR,
   WA_STPO-MENGE TO WA_OUTPUT-MENGE,

   WA_STKO-STLTY TO WA_OUTPUT-STLTY,
   WA_STKO-DATUV TO WA_OUTPUT-DATUV,
   WA_STKO-BMENG TO WA_OUTPUT-BMENG,
   WA_STKO-STKTX TO WA_OUTPUT-STKTX,
   WA_STKO-STLST TO WA_OUTPUT-STLST,

   WA_STZU-ZTEXT TO WA_OUTPUT-ZTEXT,

   WA_MAST-WERKS TO WA_OUTPUT-WERKS,
   WA_MAST-MATNR TO WA_OUTPUT-MATNR,
   WA_MAKT-MAKTX TO WA_OUTPUT-MAKTX,
   WA_MAST-STLNR TO WA_OUTPUT-STLNR,
   WA_MAST-STLAN TO WA_OUTPUT-STLAN,
   WA_MAST-STLAL TO WA_OUTPUT-STLAL.

 APPEND WA_OUTPUT TO I_OUTPUT.

ENDLOOP.                             " LOOP AT i_stpo

ENDFORM.                               " f600_display_data

*&--------------------------------------------------------------------*
*&      Form  f650_field_catlog                                       *
*&--------------------------------------------------------------------*
*       -Fill Field Catalog                                           *
*---------------------------------------------------------------------*
FORM F650_FIELD_CATLOG .

WA_FCAT-FIELDNAME = 'WERKS'.
WA_FCAT-REF_TABLE = 'MAST'.
WA_FCAT-REF_FIELD = 'WERKS'.
WA_FCAT-COL_POS   = 1.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'MATNR'.
WA_FCAT-REF_TABLE = 'MAST'.
WA_FCAT-REF_FIELD = 'MATNR'.
WA_FCAT-COL_POS   = 2.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'MAKTX'.
WA_FCAT-REF_TABLE = 'MAKT'.
WA_FCAT-REF_FIELD = 'MAKTX'.
WA_FCAT-COL_POS   = 3.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'STLTY'.
WA_FCAT-REF_TABLE = 'STKO'.
WA_FCAT-REF_FIELD = 'STLTY'.
WA_FCAT-COL_POS   = 4.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'STLAN'.
WA_FCAT-REF_TABLE = 'MAST'.
WA_FCAT-REF_FIELD = 'STLAN'.
WA_FCAT-COL_POS   = 5.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'STLNR'.
WA_FCAT-REF_TABLE = 'MAST'.
WA_FCAT-REF_FIELD = 'STLNR'.
WA_FCAT-COL_POS   = 6.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'STLAL'.
WA_FCAT-REF_TABLE = 'MAST'.
WA_FCAT-REF_FIELD = 'STLAL'.
WA_FCAT-COL_POS   = 7.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'STKTX'.
WA_FCAT-REF_TABLE = 'STKO'.
WA_FCAT-REF_FIELD = 'STKTX'.
WA_FCAT-COL_POS   = 8.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'DATUV'.
WA_FCAT-REF_TABLE = 'STKO'.
WA_FCAT-REF_FIELD = 'DATUV'.
WA_FCAT-COL_POS   = 9.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'BMENG'.
WA_FCAT-REF_TABLE = 'STKO'.
WA_FCAT-REF_FIELD = 'BMENG'.
WA_FCAT-COL_POS   = 10.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'STLST'.
WA_FCAT-REF_TABLE = 'STKO'.
WA_FCAT-REF_FIELD = 'STLST'.
WA_FCAT-COL_POS   = 11.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'IDNRK'.
WA_FCAT-REF_TABLE = 'STPO'.
WA_FCAT-REF_FIELD = 'IDNRK'.
WA_FCAT-COL_POS   = 12.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'POSTP'.
WA_FCAT-REF_TABLE = 'STPO'.
WA_FCAT-REF_FIELD = 'POSTP'.
WA_FCAT-COL_POS   = 13.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'POSNR'.
WA_FCAT-REF_TABLE = 'STPO'.
WA_FCAT-REF_FIELD = 'POSNR'.
WA_FCAT-COL_POS   = 14.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'MENGE'.
WA_FCAT-REF_TABLE = 'STPO'.
WA_FCAT-REF_FIELD = 'MENGE'.
WA_FCAT-COL_POS   = 15.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'ZTEXT'.
WA_FCAT-REF_TABLE = 'STZU'.
WA_FCAT-REF_FIELD = 'ZTEXT'.
WA_FCAT-COL_POS   = 16.
APPEND WA_FCAT TO IT_FCAT.

ENDFORM.                               " f650_field_catlog

*&--------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT                                   *
*&--------------------------------------------------------------------*
*       -Calling Function Module                                      *
*---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'BACK'.
*  SET TITLEBAR 'xxx'.

IF W_CONTAINER IS INITIAL.
*    IF cl_gui_alv_grid=>offline( ) IS INITIAL.

 CREATE OBJECT W_CONTAINER
   EXPORTING
*      PARENT                      =
     CONTAINER_NAME              = 'CUSTOM'
*      STYLE                       =
*      LIFETIME                    = lifetime_default
*      REPID                       =
*      DYNNR                       =
*      NO_AUTODEF_PROGID_DYNNR     =
 EXCEPTIONS
   CNTL_ERROR                  = 1
   CNTL_SYSTEM_ERROR           = 2
   CREATE_ERROR                = 3
   LIFETIME_ERROR              = 4
   LIFETIME_DYNPRO_DYNPRO_LINK = 5
   OTHERS                      = 6
     .
 IF SY-SUBRC  EQ 0.
   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 ENDIF.                               " IF sy-subrc  0.
ENDIF.

CREATE OBJECT W_ALV_GRID
 EXPORTING
*      I_SHELLSTYLE      = 0
*      I_LIFETIME        =
   I_PARENT          = W_CONTAINER
*      I_APPL_EVENTS     = space
*      I_PARENTDBG       =
*      I_APPLOGPARENT    =
*      I_GRAPHICSPARENT  =
*      I_NAME            =
 EXCEPTIONS
   ERROR_CNTL_CREATE = 1
   ERROR_CNTL_INIT   = 2
   ERROR_CNTL_LINK   = 3
   ERROR_DP_CREATE   = 4
   OTHERS            = 5
   .
IF SY-SUBRC  EQ 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.                             " IF sy-subrc  0.
*  ENDIF.

CALL METHOD W_ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
*   EXPORTING
*    I_BUFFER_ACTIVE               =
*    I_BYPASSING_BUFFER            =
*    I_CONSISTENCY_CHECK           =
*     i_structure_name              = 'WA_OUTPUT'
*    IS_VARIANT                    =
*    I_SAVE                        =
*    I_DEFAULT                     = 'X'
*    IS_LAYOUT                     =
*    IS_PRINT                      =
*    IT_SPECIAL_GROUPS             =
*    IT_TOOLBAR_EXCLUDING          =
*    IT_HYPERLINK                  =
*    IT_ALV_GRAPHICS               =
*    IT_EXCEPT_QINFO               =
 CHANGING
   IT_OUTTAB                     = I_OUTPUT
   IT_FIELDCATALOG               = IT_FCAT
*    IT_SORT                       =
*    IT_FILTER                     =
 EXCEPTIONS
   INVALID_PARAMETER_COMBINATION = 1
   PROGRAM_ERROR                 = 2
   TOO_MANY_LINES                = 3
   OTHERS                        = 4
       .
IF SY-SUBRC  EQ 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.                               " IF sy-subrc  0.

ENDMODULE.                             " STATUS_0100 OUTPUT

*&--------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT                              *
*&--------------------------------------------------------------------*
*       - Leave Program                                               *
*---------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.

CASE OK_CODE.
 WHEN 'BACK'.
   LEAVE TO SCREEN 0.
ENDCASE.                             " CASE ok_code
CLEAR OK_CODE.

ENDMODULE.                             " USER_COMMAND_0100  INPUT

ABAP Programming for Material Documents for MM Module

Programming with sap abap report lists the material documents that posted for one or more materials. The report’s drill down capacity allows you to view all supporting documents. Material documents are posted with all goods movements, including those in which stock does not actually move (for example, a change in batch number for a material). Material documents are posted from transactions such as purchase order receipts, issuing components to production orders, and the “post goods issue”for a delivery on a sales order.

No prerequisites are required to run this report. However, you should limit the selection criteria to restrict the material document listing. The Setting checkboxes allow you to select different ways the output can be shown at the bottom of the selection screen .

This report generates information that can be used to find all the production order1 receipts for a set of materials in a given time period. For example, you can find all the movements of a particular material batch (lot) within a quarter. From the list, you can select (and view) any of the listed material documents. In addition to viewing a material, you can view the total stock quantities (stock overview) for the material.

This report contains data obtained from material documents and material information. As such, the data cannot be changed or manipulated from the report.

To access the first screen for this report, choose Logistics → Materials management → Inventory management → Environment → List displays → Mat.doc.for material.

1. Enter 3000 in Plant.
2. Enter 101 in Movement type.
3. Enter a date range in Posting date (for example, 01/01/1997 to 12/31/1997).
4. Choose Execute.

This screen shows a listing of material document line items arranged by material. In this example, if you scroll down to material P-100, you find two receipts made on two separate documents.