Beruflich Dokumente
Kultur Dokumente
Control break statements are like events inside the loop. There are 5 control break statements in
ABAP. These are used within loop.(Except ON CHANGE OF which can be used outside the
loop as well)
AT FIRST - ENDAT
AT NEW - ENDAT
AT END OF - ENDAT
AT LAST - ENDAT
ON CHANGE OF
Explanation:
AT FIRST : Will trigger at the first run of the loop.
AT LAST: Will trigger at the last run of the loop.
The below 3 events are normally used when the table is sorted.
AT END OF : When we use At end for a field, it will trigger whenever there is any change in
any of the fields from the left to that of the particular field. The trigger point will be the at the
last occurrence of the same value for the field.
AT NEW: When we use At new for a field, it will trigger whenever there is any change in any of
the fields from the left to that of the particular field.The trigger point will be the at the
first occurrence of the new value for the field.
ON CHANGE OF: On change of it triggers only when there is any change in the particular
field.
On change of can be used outside the loop too
Example Program:
Here is an example program which gives you the practical understanding of all control break
statements.
Control break statements are statements which are used to control the sequence of execution of
statements with in loop.....endloop.
These statements are executed only with in loop...endloop.
Control break statements are
AT FIRST
AT LAST
specific field.
ON CHANGE OF <field name>
ITAB-F2 = 'ONE'.
ITAB-F3 = 10.
ITAB-F4 = '1000.00'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1
ITAB-F2
ITAB-F3
ITAB-F4
=
=
=
=
1.
'ONE'.
20.
'2000.00'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1
ITAB-F2
ITAB-F3
ITAB-F4
=
=
=
=
1.
'ONE'.
30.
'3000.00'.
APPEND ITAB.
CLEAR ITAB.
*--2
ITAB-F1
ITAB-F2
ITAB-F3
ITAB-F4
=
=
=
=
2.
'TWO'.
10.
'1000.00'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1
ITAB-F2
ITAB-F3
ITAB-F4
=
=
=
=
2.
'TWO'.
20.
'2000.00'.
APPEND ITAB.
CLEAR ITAB.
*-- 3
ITAB-F1
ITAB-F2
ITAB-F3
ITAB-F4
=
=
=
=
3.
'THREE'.
10.
'1000.00'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1
ITAB-F2
ITAB-F3
ITAB-F4
=
=
=
=
3.
'THREE'.
20.
'2000.00'.
APPEND ITAB.
CLEAR ITAB.
WRITE: / 'SUB TOTAL :' COLOR 3 INVERSE ON, SUB_TOT COLOR 3 INVERSE ON.
CLEAR SUB_TOT.
ENDAT.
AT LAST.
SUM.
ULINE.
WRITE: 'SUM:', ITAB-F4.
ULINE.
ENDAT.
ENDLOOP.
SUM.
WRITE:/ gwa_spfli-carrid,58 gwa_spfli-distance.
ULINE.
ENDAT.
AT LAST.
SUM.
WRITE:/ 'Total',58 gwa_spfli-distance.
WRITE:/ 'End of Loop'.
ENDAT.
ENDLOOP.
** *Data Declaration *
*
DATA: gwa_spfli TYPE spfli.
DATA: gt_spfli TYPE TABLE OF spfli.
SELECT * UP TO 5 ROWS FROM spfli INTO TABLE gt_spfli.
LOOP AT gt_spfli INTO gwa_spfli.
AT FIRST.
WRITE:/ 'Flight Details'.
WRITE:/ 'Airline Code' COLOR 5,14 'Connection No.' COLOR 5,
29 'Departure City' COLOR 5, 44 'Arival City' COLOR 5,
58 'Distance' COLOR 5.
ULINE.
ENDAT.
Output
Below table summarizes the differences between AT NEW and ON CHANGE OF statements.
AT NEW
It can be used only in AT
LOOP statement.
Only one control field can be
used.
AT NEW is triggered when a
field left to control level
changes.
Values in the fields to the
right of control level contains
asterisks and zeros.
ELSE addition cannot be
used.
Changes to work area with AT
NEW will be lost.
ON CHANGE OF
It can be used in any loop like
SELECT, DO etc..
Multiple control fields
separated by OR can be used.
ON CHANGE OF is not
triggered when a field left to
control level changes.
Values in the fields to the
right of control level contains
original values.
ELSE addition can be used.
Changes to work area with
ON CHANGE OF will not be
lost.
AT FIRST
2)
AT NEW
3)
AT END OF
4)
AT LAST
5)
SUM
6)
ON CHANGE OF
AT LAST
It is the loop event. It triggers in the last loop operation
Using this event we can find calculate the grand totals.
SYNTAX
AT LAST END AT.
SUM
Sum is the keyword to find the totals.
ON CHANG OF
On change of it triggers only when there is any change in the particular field, we can use ON
CHANGE OF loop and outside the Loop also.
We can use Logical expressions like AND OR can be used with ON CHANGE OF
SYNTAX
ON CHANGE OF END OF.
EXAMPLE PROGRAM:
*&*
*& Report ZCEVENTS
*&
*&*
*&
*&
*&*
REPORT ZCEVENTS NO STANDARD PAGE HEADING.
*// Tables declaration.
TABLES marc.
Click on Execute.
If user clicks on Mul button then I want display multiplication of P_value1 and P_value2 in
P_Result.
If user clicks on Div button then I want display Division of P_value1 and P_value2 in P_Result.
Step 1: Go to SE38
create a program (Program name starts must with Z or Y).
Step 2: Copy and paste the below code in your program.
*&*
*& Report ZPUSH_BUTTONS_IN_SEL_SCREEN1
*& Created By Sapsimplified.com
*&*
*&
*&
*&*
REPORT ZPUSH_BUTTONS_IN_SEL_SCREEN1.
*//Tables declaration
TABLES: SSCRFIELDS.
*//Selection Screen design
PARAMETERS : P_value1 type i obligatory,
P_value2 type i obligatory,
P_result type i.
SELECTION-SCREEN skip 2.
SELECTION-SCREEN PUSHBUTTON /05(10) TEXT-002 USER-COMMAND PB1.
SELECTION-SCREEN PUSHBUTTON 20(10) TEXT-003 USER-COMMAND PB2.
Case 2: Provide
P_value1 and P_value2 and click on SUB button then you will get subtraction of P_value1 and
P_value2 in P_Result as shown below.
Case 3: Provide
P_value1 and P_value2 and click on MUL button then you will get multiplication of P_value1
and P_value2 in P_Result as shown below.
Case 4: Provide
P_value1 and P_value2 and click on DIV button then you will get division of P_value1 and
P_value2 in P_Result as shown below.
SE93 is a transaction code to create Transaction code for table maintenance generator.
Follow the below steps to create transaction code for table maintenance generator.
Step1: Go to SE93 Transaction code and Provide Transaction code Name (Starts With Z or Y)
and Click On Create.
Step
2: Enter shot text and select Transaction with Parameters (Parameter Transaction) Radio button
and click on enter.
Step 4: Enter Transaction as SM30 and select skip initial screen check box.
Do the changes as shown below and click on save button.
Click on save.
Go to Table Contents and check your entries.
thats it.
Case 2: If I select Sales Data radio button then I Material Number input filed will be disable as
shown below.
Note: By default select the material radio button and keep Sales order number selection screen
in disable mode.
Step 1: Go to SE38 create a program (Program name starts must with Z or Y).
Step 2: Copy and paste the below code in your program.
*&*
*& Report ZREPORT_01
*&
*&*
*&
*&
*&*
REPORT ZREPORT_01 no standard page heading.
*//Tables declaration
tables : mara,vbak.
*//Types declaration for MARA
types : begin of ty_mara,
matnr type matnr,
ERSDA TYPE ERSDA,
ERNAM TYPE ERNAM,
LAEDA TYPE LAEDA,
AENAM TYPE AENAM,
end of ty_mara.
*//Types declaration for VBAK
types : begin of ty_vbak,
VBELN TYPE VBELN_VA,
ERDAT TYPE ERDAT,
ERZET TYPE ERZET,
end of ty_vbak.
*//Internal table declaration
data : lt_mara type table of ty_mara,
lt_vbak type table of ty_vbak.
*//Work area declaration
data : wa_mara type ty_mara,
wa_vbak type ty_vbak.
*//Selection screen design
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-s02.
select-options:s_matnr for mara-matnr modif id SC1,
s_vbeln for vbak-vbeln modif id SC2.
start-of-selection.
*//Retriving data from MARA
if p_rad1 eq X.
if s_matnr is not initial.
select matnr ersda ernam laeda aenam
from mara
into table lt_mara
where matnr in s_matnr.
else.
message Enter material number type I.
endif.
if lt_mara is not initial.
*//Displaying output
loop at lt_mara into wa_mara.
write :/ wa_mara-matnr, wa_mara-ersda,wa_mara-ernam, wa_mara-laeda,wa_mara-aenam.
endloop.
else.
message NO DATA type I.
endif.
elseif p_rad2 eq X.
if s_vbeln is not initial.
select vbeln erdat erzet
from vbak
into table lt_vbak
where vbeln in s_vbeln.
else.
message Enter sales order number type I.
endif.
if lt_vbak is not initial.
*//Displaying output
loop at lt_vbak into wa_vbak.
write :/ wa_vbak-vbeln, wa_vbak-erdat,wa_vbak-erzet.
endloop.
else.
message NO DATA type I.
endif.
endif.
OUTPUT:
Save your and active your program and press F8 button to execute.
By default material radio button is selected and Sales order number selection screen is in
disable mode.
Case 1: If you want to retrieve the sales data then select Sales Radio button. If you select the
sales radio button then automatically Material number field gets disable.
Enter the Sales order number and click on execute button (F8) to retrieve sales data.
Case 2: If you want to retrieve the material data then select the Material data radio button. If
you select the Material radio button then automatically Sales number field gets disable.
Enter the Material number and click on execute Button(F8) to retrieve the material data.
Table Maintenance Generator is a user interface tool which is used to customize the tables
created by end users and can be changed as required, such as you can insert a data into the table,
deleting an entry from the table, updating an entry of table.
In ABAP we can maintain table entries using SM30 or SE11 Transaction codes for the tables
having TMG, We can also archive this functionality using VIEW_MAINTENANCE_CALL
Function Module.
Prerequisite: Need a database table with table maintenance generator created in SE11.
Table Maintenance using VIEW_MAINTENANCE_CALL function module.
Step 1: Go to SE 37 transaction code and enter Function Module Name
VIEW_MAINTENANCE_CALL.
Step
2: Click on Execute button.
S
tep 3: It will open the following screen. Fill the Action and View Name (Table Name) and click
on execute.
Step 4: It will open following screen, Click on display -> Change To Enter the New Records.
Enter the new records and click on save button to store data in your table.
This is only possible when en entry exists in TVDIRor any view maintained for that
specific table.
It is used when user defined object link with SAP system data type.
LIKE:
Like is a keyword used to copy the existing properties of already existing data object.
Like, you assign the datatype of another object to the declaring data object. The data type
is referenced indirectly.
Requirement:
Display particular column data as a Pushbutton in the ALV Report Output. (In
this example I am displaying company code(BUKRS)data as a Pushbutton).
When the user clicks on pushbutton display the vendor(Call XK03 Tcode)
details in popup screen.
*&*
*& Report ZALV_BUTTON_IN_OUTPUT_LIST
*&
*&*
*&
*&
*&*
REPORT ZALV_BUTTON_IN_OUTPUT_LIST.
*// Types declaration for LFB1
TYPES : BEGIN OF TY_LFB1,
LIFNR TYPE LIFNR,
BUKRS TYPE BUKRS,
PERNR TYPE PERNR_D,
ERNAM TYPE ERNAM_RF,
END OF ty_lfb1.
*// Internal table declaration
DATA : LT_LFB1 type table of ty_lfb1,
LT_FIELDCAT TYPE LVC_T_FCAT.
*// Work Area declaration
DATA : WA_LFB1 type ty_lfb1,
wa_filedcat type LVC_S_FCAT.
*//Conatiners
DATA : LRV_GRID TYPE REF TO CL_GUI_ALV_GRID,
LRV_CONTAINER TYPE REF TO cl_gui_docking_container.
DATA : okcode type sy-ucomm.
*//Selection Screen Design.
PARAMETERS: p_bukrs TYPE bukrs obligatory.
**
*
CLASS lc_eventhandler DEFINITION
**
*
**
CLASS lc_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
button_click_event FOR EVENT button_click OF cl_gui_alv_grid
IMPORTING
es_col_id
es_row_no
sender.
ENDCLASS.
lc_eventhandler DEFINITION
**
*
CLASS lc_eventhandler IMPLEMENTATION
**
*
**
CLASS lc_eventhandler IMPLEMENTATION.
METHOD button_click_event.
* define local data
DATA:
ls_lfb1 TYPE lfb1,
ls_col_id TYPE lvc_s_col.
READ TABLE lt_lfb1 INTO ls_lfb1 INDEX es_row_no-row_id.
CHECK ( ls_lfb1-lifnr IS NOT INITIAL ).
SET PARAMETER ID LIF FIELD ls_lfb1-lifnr.
SET PARAMETER ID BUK FIELD ls_lfb1-bukrs.
CALL TRANSACTION XK03 AND SKIP FIRST SCREEN.
ENDMETHOD.
ENDCLASS.
button_click_event
lc_eventhandler IMPLEMENTATION
START-OF-SELECTION.
*// Retreving Data From LFB1
SELECT LIFNR BUKRS PERNR ERNAM
FROM lfb1
INTO TABLE lt_lfb1
WHERE bukrs = p_bukrs.
**Create docking container
**Select Pattern button
**Select ABAP Objects Pattrens radio button and click on enter
**And select create object radio button enter the instance(LRV_CONTAINER) & class (cl_gui_
docking_container)
**Click on enter
CREATE OBJECT LRV_CONTAINER
EXPORTING
parent
= cl_gui_container=>screen0
ratio
= 90
EXCEPTIONS
CNTL_ERROR
=1
CNTL_SYSTEM_ERROR
=2
CREATE_ERROR
=3
LIFETIME_ERROR
=4
LIFETIME_DYNPRO_DYNPRO_LINK = 5
others
= 6.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
**Create ALV grid
**Select Pattern button
**Select ABAP Objects Pattrens radio button and click on enter
**And select create object radio button enter the instance(LRV_GRID) & class (CL_GUI_ALV_
GRID)
CREATE OBJECT LRV_GRID
EXPORTING
i_parent
= LRV_CONTAINER
EXCEPTIONS
ERROR_CNTL_CREATE = 1
ERROR_CNTL_INIT = 2
ERROR_CNTL_LINK = 3
ERROR_DP_CREATE = 4
others
= 5.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*//Set the event handler
SET HANDLER:
lc_eventhandler=>button_click_event FOR LRV_GRID.
USER_COMMAND_0100 INPUT
*&*
*&
Form BUILD_FIELDCATALOG_KNB1
*&*
*
text
*-*
* > p1
text
* < p2
text
*-*
FORM build_fieldcatalog_knb1 .
*// Populate Fieldcatlog
wa_filedcat-col_pos = 1.
wa_filedcat-FIELDNAME = LIFNR.
wa_filedcat-outputlen = 10.
wa_filedcat-seltext = Vendor Number.
APPEND wa_filedcat TO LT_FIELDCAT.
CLEAR wa_filedcat.
wa_filedcat-col_pos = 2.
wa_filedcat-FIELDNAME = BUKRS.
wa_filedcat-outputlen = 10.
BUILD_FIELDCATALOG_KNB1
Note:Copy and past above code in SE38, Double click on screen number in the statement CALL
SCREEN 0100. to create a screen,Provide OKCODE in Elementary List and create MODULE
STATUS_0100 and MODULE user_command_0100 modules in flow logic tab as shown above.
Output:
Enjoy
Also Read:
Enter Your
Display PO And Goods Receipt Details Against Purchase Requisition SAP Reports
Business Application Programming Interface Introduction BAPI
Interactive reports in SAP ABAP