This Program will Show an error log containing Material No, Source Plant, Destination Plant Status etc. in ALV report which was called from a Module POOL.
STEP 1: Declare an internal table to be displayed in ALV Report
This is the Detailed Structure for ERROR LOG
*--Types for Error Log
types: begin of ty_err_log,
matnr type matnr ,"Material No
from_plant type werks_d ,"Plant
dest_plant type werks_d ,"Plant
from_sloc type lgort_d ,"Str. Location
to_sloc type lgort_d ,"Str. Location
Qty type ktmng ,"Qty
charg type charg_d ,"Batch
msg(132) type c ,"Message
end of ty_err_log.
*--Internal table for error Log
data: itab_err_log type standard table of ty_err_log initial size 0.
STEP 2: create a custom control from Screen Layout (GRID_NAME)
STEP 3: create a container for custom control and assign the grid to container
**&---------------------------------------------------------------------
**
**& Form sub_alv_display
**&---------------------------------------------------------------------
**
** Calls an ALV Report
**----------------------------------------------------------------------
FORM sub_alv_display .
* Local Variable Declaration-------------------------------------------
DATA :
* Local Variable for Screen Container Name
l_screen_container TYPE scrfname VALUE c_grid_name,
ls_stable TYPE lvc_s_stbl.
* Create a Custom Container for the Subcreen
CREATE OBJECT v_container_9300
EXPORTING container_name = l_screen_container.
* Assign the Grid to the Custom Container
CREATE OBJECT v_grid_9300
EXPORTING i_parent = v_container_9300.
STEP 4: Populate the field catalog and display the ALV Report (CALL METHOD v_grid_9300->set_table_for_first_display)
* Set the Field Catalog
PERFORM sub_set_fieldcat.
* Display the values of dynamic table in screen 9003
CALL METHOD v_grid_9300->set_table_for_first_display
EXPORTING
i_structure_name = 'WA_ERR_LOG'
CHANGING
it_fieldcatalog = itab_fieldcat
it_outtab = itab_err_log.
ls_stable-row = 'X'.
ls_stable-col = 'X'.
CALL METHOD v_grid_9300->refresh_table_display
EXPORTING
is_stable = ls_stable
EXCEPTIONS
finished = 1
OTHERS = 2.
*&---------------------------------------------------------------------*
*& Form sub_set_fieldcat
*&---------------------------------------------------------------------*
* Populate the Filed Catalog
*----------------------------------------------------------------------*
FORM sub_set_fieldcat.
REFRESH: itab_fieldcat.
PERFORM sub_create_ctlg_table USING:
'1' 'MATNR' 'ITAB_ERR_LOG' text-001 '' '18' '' '' '' ''
'',
'4' 'DEST_PLANT' 'ITAB_ERR_LOG' text-004 '' '14' '' ''
'' ''
'',
'2' 'FROM_PLANT' 'ITAB_ERR_LOG' text-002 '' '14' '' ''
'' ''
'',
'3' 'FROM_SLOC' 'ITAB_ERR_LOG' text-004 '' '14' '' ''
'' ''
'X',
'5' 'TO_SLOC' 'ITAB_ERR_LOG' text-005 '' '14' '' '' ''
''
'X',
'6' 'QTY' 'ITAB_ERR_LOG' text-006 '' '17' '' '' '' ''
'X',
'7' 'CHARG' 'ITAB_ERR_LOG' text-007 '' '10' '' '' '' ''
'X',
'8' 'MSG' 'ITAB_ERR_LOG' text-008 '' '132' '' '' ''
''
'X'.
- ENDFORM. " create_fieldcatalog
**&-------------------------------------------------------------------*
**& Form sub_create_ctlg_table
**&--------------------------------------------------------------------*
** inserting into field catalog table
**--------------------------------------------------------------------*
FORM sub_create_ctlg_table USING p_colpos
p_fldname
p_tabname
p_dispname
p_reftabname
p_len
p_chk
p_edit
p_key
p_emphasize
p_do_sum.
DATA: wa_fieldcat TYPE lvc_s_fcat. "work area for fieldcat
*Assign required fields into workarea
wa_fieldcat-col_pos = p_colpos.
wa_fieldcat-fieldname = p_fldname.
wa_fieldcat-tabname = p_tabname.
wa_fieldcat-coltext = p_dispname.
wa_fieldcat-ref_table = p_reftabname.
wa_fieldcat-outputlen = p_len.
wa_fieldcat-checkbox = p_chk.
wa_fieldcat-edit = p_edit.
wa_fieldcat-key = p_key.
wa_fieldcat-emphasize = p_emphasize.
wa_fieldcat-do_sum = p_do_sum.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR wa_fieldcat.
ENDFORM . "sub_create_ctlg_table