Classical Reports in SAP ABAP
Classical Reports in SAP ABAP
Below are the list of Report Events. In ABAP, every event have importance.
Load-of-program
Initialization
At Selection-Screen output
At Selection-Screen on field
At Selection-Screen on value request
At Selection-Screen on help request
At Selection-Screen
Start-of-Selection
End-of-Selection
Top-of-Page
End-of-Page
LOAD-OF-PROGRAM:
This is the first event in execution sequence. This event loads the program into memory
for execution.
All Data Declarations, Type Declarations will execute in this event only.
INITIALIZIATON:
This event is used to initialize variables, Screen values and other default actions.
We can provide default values to the selection screen which includes calculations.
We can provide default values in the declaration statement also. But we cannot perform
default values with calculations here.
Example :
INITIALIZATION.
s_date-sign = ‘I’.
s_date-option = ‘EQ’.
s_date-low = sy-datum – 30.
s_date-high = sy-datum.
APPEND s_date.
AT SELECTION-SCREEN OUTPUT:
By using this event we can manipulate dynamic selection-screen changes.
This event triggers at the screen event PBO of the selection screen.
EXAMPLE :
REPORT ZBP_CLASSICAL_EVENTS.
LOOP AT SCREEN.
IF P_ENABLE = ‘X’ . ” If check box is selected
IF SCREEN-GROUP1 = ‘IN1’ .
SCREEN-ACTIVE = 1.
MODIFY SCREEN.
ENDIF.
ELSE.
IF SCREEN-GROUP1 = ‘IN1’ .
SCREEN-ACTIVE = 0.
MODIFY SCREEN.
ENDIF.
ENDIF.
ENDLOOP.
AT SELECTION-SCREEN ON FIELD :
This event is used to validate a single selection-screen input parameter.
START-OF-SELECTION :
This is default event which is used to write actual business logic .
END-OF-SELECTION :
We can use this event just to state that start-of-selection is ended, this event is used
with logical databases, logical databases are in HR ABAP only. In normal ABAP we
don`t have much importance .
TOP-OF-PAGE :
This event prints constant heading for all pages.
END-OF-PAGE :
This event prints constant footer for all pages.
Before using this event, we need to reserve some lines for displaying footer .
CLASSICAL REPORTS
Events associated with classical report are as follows and each one will be discussed
in detail.
- INITIALIZATION
- AT SELECTION-SCREEN
- AT SELECTION-SCREEN ON <field>
- START-OF-SELECTION
- TOP-OF-PAGE
- END-OF-PAGE
- END-OF-SELECTION
In this case first three events are associated with selection screen. Rest of the events
are associated with your list.
INITIALIZATION
We have already seen how to fill default values for the selection criteria. But in many
cases you need to calculate the value and then put it in selection criteria. For example,
say, you are accepting date from user and you need to fill in the default value for
lower range as sy-datum – 30 days and sy-datum for higher range. In this case you are
calculating lower range and then filling the criteria. This can be done in
INITIALIZATION event. Piece of code to do the above task would look like the
following:
Tables: Sflight.
Select-options: fldate1 for sflight-fldate.
INITIALIZATION.
Data: date1 like SY-DATUM.
Date1 = sy-datum – 30.
Fldate1-low = date1.
Fldate1-high = sy-datum.
Append fldate1.
* Here appending is required because fldate1 is int’ table
This event is triggered when you execute your program for the first time i.e., before
selection screen is displayed.
AT SELECTION-SCREEN
When user enters the values in the fields of selection screen and clicks on execute
button, this event gets triggered. This event is basically for checking the values
entered by the user for the fields of the selection screen i.e., data validity checking.
This event is for entire selection screen. For example:
You are accepting carrid, connid, fldate from user and you don’t want to proceed if
user enters no value for carrid and fldate. Using AT SELECTION-SCREEN can do
this.
AT SELECTION-SCREEN.
If carrid1-low ne ‘ ’ and fldate1-low = ‘ ’.
Error message.
Endif.
In this case, if both the fields are entered blank, then the user gets error message.
Basically, this event is for many fields on selection screen. Usually, it is for the fields
which are logically related.
AT SELECTION-SCREEN ON <field>
When you want to check for specific value of a field. For example, carrid should be in
the range of ‘LH’ and ‘SQ’. This can be done in this event. Basically, this event is for
checking individual fields. You can have many AT selection-screen events in your
program (i.e., for each field specified in the Select-Options).
AT SELECTION-SCREEN.
If carrid1-low ne ‘LH’ and carrid1-high ne ‘SQ’.
Error message.
Endif.
Here the system will not proceed on entering wrong values.
START-OF-SELECTION
This is the first event for your list. Once all the events are triggered for selection
screen, the data is retrieved from database. Data declaration, select statements are
done in this event. Consider the following example:
START-OF-SELECTION.
Data: mtype i.
Tables: sflight.
Select * from sflight where carrid = ‘LH’.
Write: / sflight-carrid,sflight-connid.
Endselect.
TOP-OF-PAGE
This event is triggered with first WRITE statement or whenever new page is triggered.
Advantage of using this event is that, whatever you write under this event, is
applicable to all the pages. If you don’t have any write statement before TOP-OF-
PAGE or in START-OF-SELECTION, this event is not triggered at all. For example,
if you want the name of company and column headers for all the pages, it can be
written in this event.
TOP-OF-PAGE
Write: / ‘INTELLIGROUP ASIA PVT. LTD.’
Write : / 10 ‘carrid’, 20 ‘connid’, 30 ‘fldate’.
END-OF-PAGE
This event is triggered at the end of page.
End-of-page.
Write : / ‘page number’, sy-pagno.
In this case EOP will never be triggered, as end of page is never reached. The total
Line-count defined for page = 15 in which 3 lines are for footer area. The output of
the above code will be
In output screen, only two lines are written and cursor remains still on 3rd line, the
end-of-page event is not triggered. To trigger end of page event, cursor should reach
at the last position, in this case on 11th line.
Such cases are quite common, and could be overcome by conditional triggering of end
of page.
Sy-linct is the system variable, which gives total line count of a list.
Sy-linno is the system variable, which gives the current line number where the cursor
is placed on the list.
In this case, with all write statement, you don’t reach to the end of page. After all
write statement, m is calculated in this case:
M = 20 – 8 – 1, So m is 12. And 11 lines are skipped after write statement and end of
page is reached. (In this case you have 6 write statement so 6 lines + 1 line for page
number and 1 horizontal line which is displayed for any list. So cursor is on 8th line
and is subtracted from total line count i.e, 20.)
Stating of another event denotes the end of any event. If you forget to mention the
next event then everything is included in the same event. Consider the following case:
AT SELECTION-SCREEN.
If carrid1-low ne ‘ ‘.
Err. or message.
Endif.
Write: / ‘INTELLIGROUP ASIA P. LTD.’
WRITE: / 10 ‘CARRID’, 20 ‘CONNID’, 30 ‘FLDATE’.
START-OF-SELECTION.
….….
….
In this case all the write statement are included in the `at selection screen’ as top-of-
page is not specified. The end of `at selection-screen’ is denoted by the starting of
start-of-selection.
In many cases you need report to execute report at regular interval for certain fixed
values of selection criteria. That means each times you execute the report you need to
enter its values again and again. ABAP/4 provides the facility by which you can
define the values for selection screen and store it. Using VARIANTS can do this. It
can be defined as group of values used for selection criteria while executing report.
For a particular report, you create a variant which means variant created for particular
report cannot be used for another report. The group of values for the selection criteria
is saved and assigned a variant name. So every time you call a report, you need not
specify the values for selection criteria but instead call the variant thus avoiding extra
typing. User can have many variants for a single report. Each of them can be used as
different type of information. For example, if a manager wants to see how an
employee in personnel department or admin department has performed. He need not
enter the department, one has to just execute the report with variant. In case he doesn’t
know about the variant, which is available, he can display list of variants attached to
the report and values assigned to each variant.
Creating variant
Usually the variants are useful when you need to execute the report in background,
which will be discussed in background processing.
REPORT Z_ALVINTER1.
*********************************************************************
***
*TABLE DECLARATION*
*********************************************************************
***
TABLES: vbak , "Sales Document: Header Data
vbap , "Sales Document: Item Data
makt , "Material Descriptions
lips . "SD document: Delivery: Item data
*********************************************************************
***
*DECLARATION OF TYPE-POOL*
*THIS TYPE-POOL CONTAINS THE EVENTS,
*********************************************************************
***
TYPE-POOLS : slis.
*********************************************************************
***
*DECLARATION OF EVENTS*
*********************************************************************
***
DATA: i_event TYPE slis_t_event.
DATA: t_event TYPE slis_alv_event.
*********************************************************************
***
*DECLARATION OF LIST HEADER*
*********************************************************************
***
DATA: i_listheader TYPE slis_t_listheader.
*********************************************************************
***
*DECLARATION OF FIELD CATALOG FOR SCREEN 1*
*********************************************************************
***
DATA: i_fldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
*********************************************************************
***
*DECLARATION OF FIELD CATALOG FOR SCREEN 2*
*********************************************************************
***
DATA: i_fldcat2 TYPE slis_t_fieldcat_alv WITH HEADER LINE.
*********************************************************************
***
*DECLARATION OF FIELD LAYOUT*
*********************************************************************
***
DATA: i_layout TYPE slis_layout_alv.
*********************************************************************
***
*SORTING OF OUTPUT*
*********************************************************************
***
DATA: i_sort TYPE slis_t_sortinfo_alv.
*********************************************************************
***
*DATA DECLARATION
*********************************************************************
***
DATA: v_auart TYPE tvak-auart,
v_vkorg TYPE tvko-vkorg,
v_kunnr TYPE kna1-kunnr,
v_matnr TYPE mara-matnr ,
v_spart TYPE tvta-spart .
END OF it_so .
END OF it_del .
END OF type_vbfa .
*********************************************************************
***
*SELECTION SCREEN *
*********************************************************************
***
*********************************************************************
***
*AT SELECTION SCREEN *
*********************************************************************
***
AT SELECTION-SCREEN.
IF sy-subrc <> 0.
MESSAGE e202.
ENDIF.
*********************************************************************
***
*START OF SELECTION *
*********************************************************************
***
START-OF-SELECTION .
PERFORM data_select.
PERFORM t_sort USING i_sort .
PERFORM event_cat USING i_event .
PERFORM fld_cat USING i_fldcat[] .
PERFORM t_layout USING i_layout .
PERFORM fld_cat2 USING i_fldcat2[] .
PERFORM call_alv.
*********************************************************************
***
* DATA SELECT *
*********************************************************************
***
*&---------------------------------------------------------------------*
*& Form DATA_SELECT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM data_select .
*********************************************************************
***
* COLURING DISPLAY *
*********************************************************************
***
IF sy-subrc = 0.
SELECT vbelv
posnv
vbeln
posnn
vbtyp_n
INTO TABLE it_vbfa
FROM vbfa
FOR ALL ENTRIES IN it_so1
WHERE vbelv = it_so1-vbeln
AND posnn = it_so1-posnr
AND vbtyp_n ='J' .
IF sy-subrc = 0.
SELECT vbeln
posnr
matnr
werks
lgort
charg
lfimg
vrkme
FROM lips INTO TABLE it_del_ful
FOR ALL ENTRIES IN it_vbfa
WHERE vbeln = it_vbfa-vbeln
AND posnr = it_vbfa-posnn.
ENDIF.
ENDIF.
ENDFORM. " DATA_SELECT
*********************************************************************
**
**************** EVENT CATALOG
****************************************
*********************************************************************
**
*&---------------------------------------------------------------------*
*& Form EVENT_CAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_I_EVENT text
*----------------------------------------------------------------------*
REFRESH p_i_event .
IF sy-subrc = 0.
CLEAR t_event .
*********************************************************************
*
**********FORM FOR EVENT
TOP_OF_PAGE**********************************
*********************************************************************
*
FORM top_of_page .
REFRESH i_listheader.
DATA: t_header TYPE slis_listheader.
DATA: v_text(50).
CLEAR t_header.
CLEAR v_text.
* t_header-typ = 'S'.
* t_header-key = 'TITLE'.
* t_header-info = v_text.
* APPEND t_header TO i_listheader.
ENDFORM. "TOP_OF_PAGE
*********************************************************************
***
******** FIRST ALV GRID DISPLAY
***************************************
*********************************************************************
***
*&---------------------------------------------------------------------*
*& Form CALL_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM call_alv .
EXPORTING
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
i_callback_user_command = 'USER_COMMAND1'
i_callback_top_of_page = 'TOP_OF_PAGE'
* I_BACKGROUND_ID = 'ALV_BACKGROUND'
i_grid_title = i_title_vbfa
is_layout = i_layout
it_fieldcat = i_fldcat[]
it_sort = i_sort
it_events = i_event
TABLES
t_outtab = it_so1
.
* IF sy-subrc <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
* ENDIF.
CLEAR i_fldcat.
i_fldcat-fieldname = 'VBELN'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat-tabname = 'IT_SO1'."TABLE NAME
i_fldcat-seltext_m = 'SALES ORDER NO.'.
i_fldcat-col_pos = 1. " POSITION OF THE COLUMN.
i_fldcat-outputlen = 20. " SET THE OUTPUT LENGTH.
i_fldcat-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat-just(1) = 'C'.
APPEND i_fldcat.
CLEAR i_fldcat.
i_fldcat-fieldname = 'AUART'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat-tabname = 'IT_SO1'."TABLE NAME
i_fldcat-seltext_m = 'SALES DOC. TYPE'.
i_fldcat-col_pos = 2. " POSITION OF THE COLUMN.
i_fldcat-outputlen = 15. " SET THE OUTPUT LENGTH.
i_fldcat-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat-just(1) = 'C'.
APPEND i_fldcat.
CLEAR i_fldcat.
i_fldcat-fieldname = 'VKORG'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat-tabname = 'IT_SO1'.
i_fldcat-seltext_m = 'SALES ORG.'.
i_fldcat-col_pos = 3. " POSITION OF THE COLUMN.
i_fldcat-outputlen = 12. " SET THE OUTPUT LENGTH.
i_fldcat-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat-just(1) = 'C'.
APPEND i_fldcat.
CLEAR i_fldcat.
i_fldcat-fieldname = 'SPART'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat-tabname = 'IT_SO1'.
i_fldcat-seltext_m = 'DIVISION'.
i_fldcat-col_pos = 4. " POSITION OF THE COLUMN.
i_fldcat-outputlen = 10. " SET THE OUTPUT LENGTH.
i_fldcat-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat-just(1) = 'C'.
APPEND i_fldcat.
CLEAR i_fldcat.
i_fldcat-fieldname = 'KUNNR'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat-tabname = 'IT_SO1'.
i_fldcat-seltext_m = 'SOLD TO PARTY'.
i_fldcat-col_pos = 5. " POSITION OF THE COLUMN.
i_fldcat-outputlen = 15. " SET THE OUTPUT LENGTH.
i_fldcat-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat-just(1) = 'C'.
APPEND i_fldcat.
CLEAR i_fldcat.
i_fldcat-fieldname = 'POSNR'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat-tabname = 'IT_SO1'.
i_fldcat-seltext_m = 'SALES DOC. ITEM'.
i_fldcat-col_pos = 6. " POSITION OF THE COLUMN.
i_fldcat-outputlen = 17. " SET THE OUTPUT LENGTH.
i_fldcat-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat-just(1) = 'C'.
APPEND i_fldcat.
CLEAR i_fldcat.
CLEAR i_fldcat.
i_fldcat-fieldname = 'MAKTX'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat-tabname = 'IT_SO1'.
i_fldcat-seltext_m = 'DESCRIPTION'.
i_fldcat-col_pos = 8. " POSITION OF THE COLUMN.
i_fldcat-outputlen = 20. " SET THE OUTPUT LENGTH.
i_fldcat-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat-just(1) = 'C'.
APPEND i_fldcat.
CLEAR i_fldcat.
i_fldcat-fieldname = 'KWMENG'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat-tabname = 'IT_SO1'.
i_fldcat-seltext_m = 'QUANTITY'.
i_fldcat-col_pos = 9. " POSITION OF THE COLUMN.
i_fldcat-outputlen = 15. " SET THE OUTPUT LENGTH.
i_fldcat-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat-do_sum = 'X'. " For doing "SUM"
i_fldcat-just(1) = 'C'.
APPEND i_fldcat.
CLEAR i_fldcat.
i_fldcat-fieldname = 'VRKME'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat-tabname = 'IT_SO1'.
i_fldcat-seltext_m = 'SALES UNIT'.
i_fldcat-col_pos = 10. " POSITION OF THE COLUMN.
i_fldcat-outputlen = 10. " SET THE OUTPUT LENGTH.
i_fldcat-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat-just(1) = 'C'.
APPEND i_fldcat.
*********************************************************************
**
****************** ALV SORTING
***************************************
*********************************************************************
**
*&---------------------------------------------------------------------*
*& Form SORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_I_SORT text
*----------------------------------------------------------------------*
*********************************************************************
**
***********FORM FOR EVENT
USER_COMMAND1********************************
*********************************************************************
**
*CASE R_UCOMM .
* WHEN '&IC1' .
*
* IF rs_selfield-FIELDNAME = 'VBELN' .
*
* ENDIF .
*
* WHEN OTHERS .
*
* ENDCASE .
CLEAR wa_so.
REFRESH: it_del1 .
IF sy-subrc = 0.
IF sy-subrc = 0.
CLEAR wa_del.
MOVE wa_it_del_ful TO wa_del.
APPEND wa_del TO it_del1.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
*********************************************************************
********* SECOND ALV GRID DISPLAY
***********************************
*********************************************************************
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
i_callback_user_command = 'USER_COMMAND2'
i_callback_top_of_page = 'TOP_OF_PAGE'
* I_BACKGROUND_ID = 'ALV_BACKGROUND'
i_grid_title = i_title_vbpa
it_fieldcat = i_fldcat2[]
it_sort = i_sort
TABLES
t_outtab = it_del_ful
.
* 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 . "USER_COMMAND1
*********************************************************************
**
********** FORM FOR EVENT USER_COMMAND 2
******************************
*********************************************************************
**
CLEAR wa_so.
REFRESH: it_del1 .
* IF SY-SUBRC = 0.
*
* LOOP AT it_vbfa INTO wa_vbfa WHERE vbelv = WA_SO-vbeln
* AND posnv = WA_SO-posnr.
READ TABLE it_del_ful INTO wa_it_del_ful
WITH KEY vbeln = rs_selfield-value
posnr = wa_vbfa-posnn.
IF rs_selfield-fieldname = 'VBELN'.
ENDIF .
* ENDLOOP.
* ENDIF.
ENDIF.
ENDFORM . "USER_COMMAND2
*********************************************************************
***
********* SECOND FIELDCATALOG
******************************************
*********************************************************************
***
*&---------------------------------------------------------------------*
*& Form FLD_CAT2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_I_FLDCAT2[] text
*----------------------------------------------------------------------*
CLEAR i_fldcat2.
i_fldcat2-fieldname = 'VBELN'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat2-tabname = 'IT_DEL_FUL'."TABLE NAME
i_fldcat2-seltext_m = 'DELIVERY NO.'.
i_fldcat2-col_pos = 1. " POSITION OF THE COLUMN.
i_fldcat2-outputlen = 20. " SET THE OUTPUT LENGTH.
i_fldcat2-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat2-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat2-hotspot = 'X'.
i_fldcat2-just(1) = 'C'.
APPEND i_fldcat2.
CLEAR i_fldcat2.
i_fldcat2-fieldname = 'POSNR'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat2-seltext_m = 'DELIVERY ITEM'.
i_fldcat2-col_pos = 2. " POSITION OF THE COLUMN.
i_fldcat2-outputlen = 20. " SET THE OUTPUT LENGTH.
i_fldcat2-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat2-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat2-just(1) = 'C'.
APPEND i_fldcat2.
CLEAR i_fldcat2.
i_fldcat2-fieldname = 'MATNR'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat2-seltext_m = 'MATERIAL NO.'.
i_fldcat2-col_pos = 3. " POSITION OF THE COLUMN.
i_fldcat2-outputlen = 20. " SET THE OUTPUT LENGTH.
i_fldcat2-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat2-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat2-just(1) = 'C'.
APPEND i_fldcat2.
CLEAR i_fldcat2.
i_fldcat2-fieldname = 'WERKS'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat2-seltext_m = 'PLANT.'.
i_fldcat2-col_pos = 4. " POSITION OF THE COLUMN.
i_fldcat2-outputlen = 20. " SET THE OUTPUT LENGTH.
i_fldcat2-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat2-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat2-just(1) = 'C'.
APPEND i_fldcat2.
CLEAR i_fldcat2.
i_fldcat2-fieldname = 'LGORT'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat2-seltext_m = 'ST. LOCATION'.
i_fldcat2-col_pos = 5. " POSITION OF THE COLUMN.
i_fldcat2-outputlen = 20. " SET THE OUTPUT LENGTH.
i_fldcat2-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat2-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat2-just(1) = 'C'.
APPEND i_fldcat2.
CLEAR i_fldcat2.
i_fldcat2-fieldname = 'CHARG'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat2-seltext_m = 'BATCH NO.'.
i_fldcat2-col_pos = 6. " POSITION OF THE COLUMN.
i_fldcat2-outputlen = 20. " SET THE OUTPUT LENGTH.
i_fldcat2-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat2-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat2-just(1) = 'C'.
APPEND i_fldcat2.
CLEAR i_fldcat2.
i_fldcat2-fieldname = 'LFIMG'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat2-seltext_m = 'ACT. DEL. QTY.'.
i_fldcat2-col_pos = 7. " POSITION OF THE COLUMN.
i_fldcat2-outputlen = 20. " SET THE OUTPUT LENGTH.
i_fldcat2-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat2-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat2-just(1) = 'C'.
APPEND i_fldcat2.
CLEAR i_fldcat2.
i_fldcat2-fieldname = 'VRKME'. "FIELD FOR WHICH CATALOG ID FILLED
i_fldcat2-seltext_m = 'SALES UNIT.'.
i_fldcat2-col_pos = 8. " POSITION OF THE COLUMN.
i_fldcat2-outputlen = 20. " SET THE OUTPUT LENGTH.
i_fldcat2-emphasize = 'X'. " COLOR OF THIS COLUMN.
i_fldcat2-key = 'X'. " SO THAT THIS FIELD IS NOT
"SCROLLABLE AND HIDDABLE.
i_fldcat2-just(1) = 'C'.
APPEND i_fldcat2.
*********************************************************************
***
***************** ALV LAYOUT
*******************************************
*********************************************************************
***
*&---------------------------------------------------------------------*
*& Form LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_I_LAYOUT text
*----------------------------------------------------------------------*
TYPE-POOLS: SLIS.
*type declaration for values from ekko
TYPES: BEGIN OF I_EKKO,
EBELN LIKE EKKO-EBELN,
AEDAT LIKE EKKO-AEDAT,
BUKRS LIKE EKKO-BUKRS,
BSART LIKE EKKO-BSART,
LIFNR LIKE EKKO-LIFNR,
END OF I_EKKO.
* declaration for events table where user comand or set PF status will
* be defined
DATA: V_EVENTS TYPE SLIS_T_EVENT,
WA_EVENT TYPE SLIS_ALV_EVENT.
INITIALIZATION.
V_REPID = SY-REPID.
PERFORM BUILD_FIELDCATLOG.
PERFORM EVENT_CALL.
PERFORM POPULATE_EVENT.
START-OF-SELECTION.
PERFORM DATA_RETRIEVAL.
PERFORM BUILD_LISTHEADER USING IT_LISTHEADER.
PERFORM DISPLAY_ALV_REPORT.
*&--------------------------------------------------------------------*
*& Form BUILD_FIELDCATLOG
*&--------------------------------------------------------------------*
* Fieldcatalog has all the field details from ekko
*---------------------------------------------------------------------*
FORM BUILD_FIELDCATLOG.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'EBELN'.
WA_FIELDCAT-SELTEXT_M = 'PO NO.'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'AEDAT'.
WA_FIELDCAT-SELTEXT_M = 'DATE.'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'BUKRS'.
WA_FIELDCAT-SELTEXT_M = 'COMPANY CODE'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'BUKRS'.
WA_FIELDCAT-SELTEXT_M = 'DOCMENT TYPE'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'LIFNR'.
WA_FIELDCAT-NO_OUT = 'X'.
WA_FIELDCAT-SELTEXT_M = 'VENDOR CODE'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
ENDFORM. "BUILD_FIELDCATLOG
*&--------------------------------------------------------------------*
*& Form EVENT_CALL
*&--------------------------------------------------------------------*
* we get all events - TOP OF PAGE or USER COMMAND in table v_events
*---------------------------------------------------------------------*
FORM EVENT_CALL.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = V_EVENTS
* EXCEPTIONS
* LIST_TYPE_WRONG = 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. "EVENT_CALL
*&--------------------------------------------------------------------*
*& Form POPULATE_EVENT
*&--------------------------------------------------------------------*
* Events populated for TOP OF PAGE & USER COMAND
*---------------------------------------------------------------------*
FORM POPULATE_EVENT.
READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME =
'TOP_OF_PAGE'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'TOP_OF_PAGE'.
MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE
NAME =
WA_EVENT-FORM.
ENDIF.
*&--------------------------------------------------------------------*
*& Form data_retrieval
*&--------------------------------------------------------------------*
* retreiving values from the database table ekko
*---------------------------------------------------------------------*
FORM DATA_RETRIEVAL.
SELECT EBELN AEDAT BUKRS BSART LIFNR FROM EKKO INTO TABLE
IT_EKKO.
ENDFORM. "data_retrieval
*&--------------------------------------------------------------------*
*& Form bUild_listheader
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->I_LISTHEADEtext
*---------------------------------------------------------------------*
FORM BUILD_LISTHEADER USING I_LISTHEADER TYPE
SLIS_T_LISTHEADER.
DATA HLINE TYPE SLIS_LISTHEADER.
HLINE-INFO = 'this is my first alv pgm'.
HLINE-TYP = 'H'.
ENDFORM. "build_listheader
*&--------------------------------------------------------------------*
*& Form display_alv_report
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM DISPLAY_ALV_REPORT.
V_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = V_REPID
* I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
I_GRID_TITLE = I_TITLE_EKKO
* I_GRID_SETTINGS =
* IS_LAYOUT = ALV_LAYOUT
IT_FIELDCAT = I_FIELDCAT[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* i_default = 'ZLAY1'
I_SAVE = 'A'
* is_variant = i_variant
IT_EVENTS = V_EVENTS
TABLES
T_OUTTAB = IT_EKKO
* 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_alv_report
*&--------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_LISTHEADER
* i_logo =
* I_END_OF_LIST_GRID =
.
ENDFORM. "TOP_OF_PAGE
*&--------------------------------------------------------------------*
*& Form USER_COMMAND
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->R_UCOMM text
* -->, text
* -->RS_SLEFIELDtext
*---------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN '&IC1'.
READ TABLE IT_EKKO INTO WA_EKKO INDEX RS_SELFIELD-TABINDEX.
PERFORM BUILD_FIELDCATLOG_EKPO.
PERFORM EVENT_CALL_EKPO.
PERFORM POPULATE_EVENT_EKPO.
PERFORM DATA_RETRIEVAL_EKPO.
PERFORM BUILD_LISTHEADER_EKPO USING IT_LISTHEADER.
PERFORM DISPLAY_ALV_EKPO.
ENDCASE.
ENDFORM. "user_command
*&--------------------------------------------------------------------*
*& Form BUILD_FIELDCATLOG_EKPO
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM BUILD_FIELDCATLOG_EKPO.
WA_FIELDCAT-TABNAME = 'IT_EKPO'.
WA_FIELDCAT-FIELDNAME = 'EBELN'.
WA_FIELDCAT-SELTEXT_M = 'PO NO.'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKPO'.
WA_FIELDCAT-FIELDNAME = 'EBELP'.
WA_FIELDCAT-SELTEXT_M = 'LINE NO'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_EKPO'.
WA_FIELDCAT-FIELDNAME = 'MATNR'.
WA_FIELDCAT-SELTEXT_M = 'MATERIAL NO.'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_EKPO'.
WA_FIELDCAT-FIELDNAME = 'MENGE'.
WA_FIELDCAT-SELTEXT_M = 'QUANTITY'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_EKPO'.
WA_FIELDCAT-FIELDNAME = 'MEINS'.
WA_FIELDCAT-SELTEXT_M = 'UOM'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_EKPO'.
WA_FIELDCAT-FIELDNAME = 'NETPR'.
WA_FIELDCAT-SELTEXT_M = 'PRICE'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
ENDFORM. "BUILD_FIELDCATLOG_EKPO
*&--------------------------------------------------------------------*
*& Form event_call_ekpo
*&--------------------------------------------------------------------*
* we get all events - TOP OF PAGE or USER COMMAND in table v_events
*---------------------------------------------------------------------*
FORM EVENT_CALL_EKPO.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = V_EVENTS
* EXCEPTIONS
* LIST_TYPE_WRONG = 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. "event_call_ekpo
*&--------------------------------------------------------------------*
*& Form POPULATE_EVENT
*&--------------------------------------------------------------------*
* Events populated for TOP OF PAGE & USER COMAND
*---------------------------------------------------------------------*
FORM POPULATE_EVENT_EKPO.
READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME =
'TOP_OF_PAGE'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'TOP_OF_PAGE'.
MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE
NAME =
WA_EVENT-FORM.
ENDIF.
ENDFORM. "POPULATE_EVENT
*&--------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM F_TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_LISTHEADER
* i_logo =
* I_END_OF_LIST_GRID =
.
ENDFORM. "TOP_OF_PAGE
*&--------------------------------------------------------------------*
*& Form USER_COMMAND
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->R_UCOMM text
* -->, text
* -->RS_SLEFIELDtext
*---------------------------------------------------------------------*
FORM DISPLAY_ALV_EKPO.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = V_REPID
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = 'F_USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = '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_TITLE_EKPO
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = I_FIELDCAT[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT =
I_SAVE = 'A'
* IS_VARIANT =
IT_EVENTS = V_EVENTS
TABLES
T_OUTTAB = 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.
REPORT ZSIMPLE_DBPRG.
TABLES MARA.
DATA : WA_MARA LIKE MARA.
START-OF-SELECTION.
**FIRST MARA IS DATABASE TABLE SECOND MARA IS DEFAULT
STRUCTURE
*SELECT SINGLE * FROM MARA INTO MARA.
* SELECT SINGLE * FROM MARA INTO MARA WHERE matnr EQ
‘000000000000000023’.
SELECT SINGLE * FROM MARA INTO MARA WHERE matnr EQ
‘000000000000000023’.
IF SY-SUBRC EQ 0.
WRITE :/10 ‘SELECT SUCCESSFUL’.
move-CORRESPONDING mara to wa_mara.
ELSE.
WRITE :/10 ‘SELECT NOT SUCCESSFUL’.
ENDIF.
END-OF-SELECTION.
if WA_mara is not INITIAL.
WRITE /10 : WA_MARA-MATNR, “MATERIAL NUMBER
WA_MARA-MTART, “MATERIAL TYPE
WA_MARA-MBRSH, “INDUSTRY SECTOR
WA_MARA-MATKL. “MATERIAL ID
else.
write :/10 ‘wa_mara is empty…’.
endif.