Sie sind auf Seite 1von 46

Control Break Statements in SAP ABAP

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.

Example Program for Control Break Statements


NOTE: It is important to note that we need a temporary work-area apart from the work-area used
in loop for the last 3 control break statements. If we directly use the work-area of the loop, then
we will get **** value and not the output we are expecting.
*&---------------------------------------------------------------------*
*& Report ZAU_CONTROLBREAK
*&
*&---------------------------------------------------------------------*
*& NEW TO SAP CONTROL BREAK EXAMPLE
*& http://www.newtosap.info
*&
*&---------------------------------------------------------------------*
REPORT zau_controlbreak.
TYPES: BEGIN OF ty_marc,
matnr TYPE marc-matnr,
werks TYPE marc-werks,
END OF ty_marc.
DATA: it_marc TYPE STANDARD TABLE OF ty_marc,
wa_marc TYPE ty_marc,
wa_temp TYPE ty_marc.
SELECT matnr werks FROM marc INTO TABLE it_marc UP TO 10 ROWS WHERE matnr ge 40.

SORT it_marc BY matnr.


FIELD-SYMBOLS : <matnr> type matnr.
WRITE:/ 'FULL TABLE'.
LOOP AT it_marc INTO wa_marc.
wa_temp = wa_marc.
WRITE: / sy-tabix , wa_temp-matnr, wa_temp-werks.
ENDLOOP.
WRITE:/ 'AT FIRST AND LAST'.
LOOP AT it_marc INTO wa_marc.
wa_temp = wa_marc.
AT FIRST.
WRITE:/ 'First Entry'.
WRITE:/ wa_temp-matnr, wa_temp-werks.
ENDAT.
AT LAST.
WRITE:/ 'Last Entry'.
WRITE:/ wa_temp-matnr, wa_temp-werks.
ENDAT.
ENDLOOP.

WRITE:/ 'AT END OF'.


LOOP AT it_marc INTO wa_marc.
wa_temp = wa_marc.
AT END OF matnr.
WRITE: / sy-tabix , wa_temp-matnr, wa_temp-werks.
ENDAT.
ENDLOOP.
WRITE:/ 'AT NEW'.
LOOP AT it_marc INTO wa_marc.
wa_temp = wa_marc.
AT NEW matnr.
WRITE: / sy-tabix , wa_temp-matnr, wa_temp-werks.
ENDAT.
ENDLOOP.
WRITE:/ 'ON CHANGE OF'.
LOOP AT it_marc INTO wa_marc.
wa_temp = wa_marc.
ASSIGN wa_marc-matnr TO <matnr>.
ON CHANGE OF wa_marc-matnr.
WRITE: / sy-tabix ,wa_temp-matnr, wa_temp-werks.
ENDON.
ENDLOOP.

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

- This statement is executed/triggered for the first iteration of loop (SY-TABIX = 1 ).

- This statement is executed/triggered for the last iteration of loop.

AT NEW <field name>

- This is executed when ever there is a new value on specified field.

AT END OF <field name>

- This statement is executed whenever the new value ends on

specific field.
ON CHANGE OF <field name>

- It is same as AT NEW and is obsolete in ECC 6.0.

Control Break Statements


If my internal table have 3 numeric fields & i want to be grand total for
each fields (3 fields.)can i used at last statement for totling of these 3
fields.

* Using AT FIRST , AT NEW, AT THE END OF , AT LAST.


DATA: BEGIN OF ITAB OCCURS 0,
F1 TYPE I,
F2(6) TYPE C,
F3(10) TYPE N,
F4(16) TYPE P DECIMALS 2,
END OF ITAB.

DATA: SUB_TOT(10) TYPE P DECIMALS 3.


**--1
ITAB-F1 = 1.

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.

SORT ITAB BY F1.


LOOP AT ITAB.
AT FIRST.
WRITE: /35 ' MATERIAL DETAILS:'.
ULINE.
ENDAT.
AT NEW F1.
WRITE: / 'DETAILS OF MATERIAL:' COLOR 7 , ITAB-F1.
ULINE.
ENDAT.
WRITE: / ITAB-F1, ITAB-F2, ITAB-F3, ITAB-F4.
SUB_TOT = SUB_TOT + ITAB-F4.
AT END OF F1.
ULINE.

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.

Control Break Processing in ABAP Internal Tables


Continued
In AT FIRST and AT LAST event blocks the numeric values in the work area contains zeros.
SUM statement calculates the totals of numeric fields and places the totals in the corresponding
fields of work area.
In AT NEW and AT END OF event blocks SUM statement finds all the rows within the control
level and calculates the totals of numeric fields that are right to the control level and places the
totals in the corresponding fields of work area.
** *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.
AT NEW carrid.
WRITE:/ gwa_spfli-carrid, ' : New Airline'.
ULINE.
ENDAT.
WRITE:/14 gwa_spfli-connid,29 gwa_spfli-cityfrom,
44 gwa_spfli-cityto,58 gwa_spfli-distance.
AT END OF carrid.
ULINE.

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.

ON CHANGE OF behaves similar to AT NEW. The syntax is as follows.


ON CHANGE OF <control level1> [or <control level2> . .].
[ELSE.]
ENDON.

** *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.

ON CHANGE OF gwa_spfli-carrid. WRITE:/ gwa_spfli-carrid, : New Airline. ULINE.


ENDON.
WRITE:/14 gwa_spfli-connid,29 gwa_spfli-cityfrom,
44 gwa_spfli-cityto,58 gwa_spfli-distance.
ENDLOOP.

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.

Control Break Statements in SAP ABAP


Control break events are used to control the sequence data flow inside the loops in ABAP.
List of control break events in ABAP:
1)

AT FIRST

2)

AT NEW

3)

AT END OF

4)

AT LAST

5)

SUM

6)

ON CHANGE OF

Note: AT-FIRST, AT-NEW,AT-END-OF,AT-LAST this events works only in between LOOP


ENDLOOP, We are also calling it as LOOP EVENTS
AT FIRST
It is the loop event, it triggers at first run of the loop.
Using this event we can display the page header.
SYNTAX:
AT FIRST - END AT.
AT NEW
It is the loop event. Whenever the new field value is occurred then AT NEW event will trigger.
The trigger point will be at the first occurrence of the new value for the field.
SYNTAX
AT NEW END AT.
AT END OF
It is the loop event. It triggers at end of every field value.
Using this event we can calculate the subtotals.
SYNTAX
AT END OFS END AT.

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.

*//Types declaration for ty_marc.


TYPES : BEGIN OF ty_marc,
matnr TYPE matnr,
werks TYPE werks_d,
pstat TYPE pstat_d,
lvorm TYPE lvowk,
plifz TYPE plifz,
END OF ty_marc.
*//Types declaration for ty_marc1.
TYPES : BEGIN OF ty_marc1,
werks TYPE werks_d,
pstat TYPE pstat_d,
lvorm TYPE lvowk,
plifz TYPE plifz,
matnr TYPE matnr,
END OF ty_marc1.
*//Internal table declaration.
DATA : lt_marc TYPE TABLE OF ty_marc,
lt_marc1 TYPE TABLE OF ty_marc1.
*//Workarea declaration.
DATA : wa_marc TYPE ty_marc,
wa_marc1 TYPE ty_marc1.
*//selection screen design.
SELECT-OPTIONS : s_matnr FOR marc-matnr.
*//Retrive the data from mara.
SELECT matnr werks pstat lvorm plifz
FROM marc
INTO TABLE lt_marc
WHERE matnr IN s_matnr.
IF sy-subrc EQ 0.
*//populating data into final internal table.
LOOP AT lt_marc INTO wa_marc.
***** wa_marc1-matnr = wa_marc-matnr.
***** wa_marc1-werks = wa_marc-werks.
***** wa_marc1-pstat = wa_marc-pstat.

***** wa_marc1-lvorm = wa_marc-lvorm.


***** wa_marc1-plifz = wa_marc-plifz.
MOVE-CORRESPONDING wa_marc TO wa_marc1.
APPEND wa_marc1 TO lt_marc1.
CLEAR wa_marc1.
ENDLOOP.
ENDIF.
*// sort by specific field
SORT lt_marc1 BY pstat.
*******//Display output.
******LOOP AT lt_marc1 INTO wa_marc1.
****** WRITE : / wa_marc1-matnr,wa_marc1-werks,wa_marc1-pstat,wa_marc1lvorm,wa_marc1-plifz.
******ENDLOOP.
*//Apply the control break events.
LOOP AT lt_marc1 INTO wa_marc1.
*//AT FIRST.
AT FIRST.
WRITE : / PLANT DATA.
ULINE.
SKIP 2.
ENDAT.
******//AT NEW.
***** AT NEW pstat.
***** WRITE : / MAINTENANCE STATUS: ,wa_marc1-pstat.
*****
***** ENDAT.
***** WRITE : /,/ wa_marc1-matnr,wa_marc1-werks,wa_marc1-pstat,wa_marc1lvorm,wa_marc1-plifz .
*//ON CHANGE OF.
ON CHANGE OF wa_marc1-pstat.
write : /,/ MAINTENANCE STATUS :,wa_marc1-pstat.
endon.
write : / wa_marc1-matnr,wa_marc1-werks,wa_marc1-pstat,wa_marc1-lvorm,wa_marc1-plifz.

*//AT END OF.


AT END OF pstat.
sum .
write : /30 subtotal, wa_marc1-plifz.
ENDAT.
*//AT LAST.
AT LAST.
SUM.
WRITE : /30 GRAND TOTAL,wa_marc1-plifz.
ENDAT.
ENDLOOP.
Output:

Click on Execute.

Creating Pushbuttons on Selection Screen


Requirement:
Create 3 input text files using parameters statement.
Created 4 pushbuttons and name it as Add, Sub, Mul and Div as shown below.
For example if user clicks on Add button then I want display addition of P_value1 and P_value2
in P_Result.
If user clicks on Sub button then I want display subtraction of P_value1 and P_value2 in
P_Result.

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.

SELECTION-SCREEN PUSHBUTTON 35(10) TEXT-004 USER-COMMAND PB3.


SELECTION-SCREEN PUSHBUTTON 50(10) TEXT-005 USER-COMMAND PB4.
at selection-screen.
Case SSCRFIELDS.
when PB1.
P_result = p_value1 + p_value2.
when PB2.
P_result = p_value1 - p_value2.
when PB3.
P_result = p_value1 * p_value2.
when PB4.
P_result = p_value1 / p_value2.
endcase.
Step 3: Save and execute (F8) your program.
You will get a screen as shown below.
Case 1: Provide P_value1 and P_value2 and click on Add button then you will get addition of
P_value1 and P_value2 in P_Result as shown below.

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.

How to Create Transaction Code for Table Maintenance


Generator in SAP
Table Maintenance Generator :
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.
Prerequisite to create TMG:
To make this feature works, you should select Data Browser/Table View Maint as
Display/maintenance allow in the Delivery and Maintenance tab while creating the database
table 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 3: Below screen is trigger.

Step 4: Enter Transaction as SM30 and select skip initial screen check box.
Do the changes as shown below and click on save button.

Step 5: Enter the package name and click on save.

Below message will


appear at the status bar.
OUTPUT:
Go to the Transaction ZTMG

Following screen will appear.

Click On New Entries


To Create new records.

Enter few entries.

Click on save.
Go to Table Contents and check your entries.
thats it.

Dynamic selection screen in SAP ABAP


Requirement:
Create a selection screen with 2 Select-options (Material Number, Sales Order Number) and 2
radio buttons (Material Data, Sales Data) as shown.
Case 1: If I select Material Data radio button then Sales Order Number input filed will be
disable as shown below.

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.

SELECTION-SCREEN END OF BLOCK blk1.


**//Check Boxes Design
* SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN POSITION 10.
* PARAMETERS: p_chk1 AS CHECKBOX.
* SELECTION-SCREEN COMMENT 13(15) text-cb1.
* PARAMETERS: p_chk2 AS CHECKBOX.
* SELECTION-SCREEN COMMENT 32(15) text-cb2.
* SELECTION-SCREEN End of LINE.
*//Radio button design
SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-s01.
*//Radio buttons design
selection-screen begin of line.
parameters: p_rad1 radiobutton group grp1 user-command test.
selection-screen comment 15(15) text-010 for field p_rad1.
parameters: p_rad2 radiobutton group grp1.
selection-screen comment 35(15) text-011 for field p_rad2.
selection-screen end of line.
SELECTION-SCREEN END OF BLOCK blk2.
*//validating selection screen
AT SELECTION-SCREEN OUTPUT .
LOOP AT SCREEN.
IF screen-group1 = SC2.
screen-input = 0.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
if p_rad2 = X.
loop at screen.
if screen-group1 = SC1.
screen-input = 0.
modify screen.
elseif screen-group1 = SC2.
screen-input = 1.
modify screen.
endif.
endloop.
endif.

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 without using SE11 and SE30


Transaction Codes

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.

Difference between Type and Like in SAP ABAP


TYPE:

Type is a keyword used to refer to a data type.

It will allocate memory during execution (object type).

Type will improve performance.

It is used when user defined object link with SAP system data type.

Type refers to the user defined data types

Type, assign datatype directly to the data object while declaring.

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.

It will allocate memory immediately.

It is when data object link with the other data object.

Like refers to existing datatype of data object

List of Transaction Codes in SAP ABAP


Transaction code:
Transaction code is the collection of the screens where we can develop our object, sap provided
their own transaction code for each and every concept those are called standard transaction codes
.
If you want we can create your own transaction code those are called as custom transaction codes
In SAP there are more than 115200 standard Tcodes are there.
List of Transaction codes used in ABAP:
SE01 Transport Organizer (Extended view)
SE03 Transport Organizer Tools
SE09 Transport Organizer
SE10 Transport Organizer
SE11 ABAP/4 Dictionary
SE12 ABAP/4 Dictionary Display
SE13 Dictionary Technical Settings
SE14 ABAP/4 Dictionary: Database Utility
SE15 Object Navigator

SE16 Data Browser : Initial Screen


SE16N General Table Display
SE17 General Table Display
SE18 BADI Builder :Initial Screen For Definitions
SE19 BADI Builder : Initial Screen For Implementations
SE21 Package Builder: Initial Screen
SE24 Class Builder : Initial Screen
SE29 Application Packets
SE30 Run Time Analysis : Initial Screen
SE32 SAP
SE33 Context Builder : Initial Screen
SE35 Maintain Dialog Modules
SE36 Logical Database Builder
SE37 Function Builder : Initial Screen
SE38 ABAP Editor : Initial Screen
SE39 ABAP Splitscreen Editor : Initial Screen
SE41 Menu Painter : Initial Screen
SE43 Area Menu Maintenance
SE51 Screen Painter: Initial Screen
SE54 Generate table Maintenance Dialog : Initial Table/ View Screen
SE55 Generate table Maintenance Dialog : Initial Table/ View Screen
SE56 Generate table Maintenance Dialog : Initial Table/ View Screen

SE57 Generate table Maintenance Dialog : Initial Table/ View Screen


SE61 Document Maintenance :
SE62 Short Text Conversion Activation
SE63 Translation
SE71 Form Painter
SE72 Style : Request
SE73 SAP Script Font Maintenance : Initial Screen
SE74 SAP Script Format Conversion
SE75 SAP Script Settings
SE76 SAP Script From Translation
SE77 SAP Script Style Conversion
SE78 Administration For Graphics
SE80 Object Navigator
SE81&SE82 Application Hierarchy : Display
SE83 Display Reuse Library
SE84 Object Navigator
SE85 Object Navigator
SE90 Object Navigator
SE91 Message Maintenance : Initial Screen
SE92 Maintain system log messages
SE93 Transaction Code Creation
SM12 Lock table entries (unlock locked tables)

SM04 User List


SM30 Maintain Table Views : Initial Screen
SM31 Maintain Table Views
SM32 Table Maintenance
SM35 Batch Input : Session Overview
SM36 Define Background Job
SM37 Simple Job Selection
SM50 Process Over View
SM51 SAP Servers
ST01 System Trace
ST02 Tune Summary
ST05 SQL Trace
ST22 ABAP Run Time Error
SPRO Customizing : Execute Project
SU01 Display User Name
SMOD SAP enhancements
COMD Project Management For SAP Enhancements
SHDB Recording Overview
SMARTFORMS For Smart Form Creation
NACE Conditions For Output Control
LSMW Legacy System Migration Workbench
SP01 Output Control: Spool Request Selection Screen

SP02 Output Control : Spool Request List


SO10 Standard Text
AL11 Application server path
WEDI EDI Menu. IDOC and EDI base
WE02 IDOC list
WE07 IDOC statistics
WE31 Segment creation
WE30 IDOC type creation
WE81 To create message type
WE82 - assign the message type to IDOC types
WE 20 Partner profile
WE21 Port creation
ST01 System trace
ST11 Error log files
SM21 System log
SM13 Update requests
SM 02 -System messages
SALE Display ALE customizing
STUN Performance monitoring
ST12 Application monitor
ST01 SAP system monitor
ST06 Operating system monitor

SICK Installation rheck


SLIN Extended rheck
Sp01 Spool rontrol
Sp02 Display output request
CG3Y Transfer file from application server to front end
CG3Z transfer file from front end to application server
SWO1 Business object builder
SWO2 Bussiness object repository browser

Display a Column As a Pushbutton in the ALV Report


Output
Flares Twitter 1 Facebook 26 Google+ 0 LinkedIn 0 Email -- Pin It Share 0

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.

*// Populatefieldcatalog and set button for field BUKRS


PERFORM build_fieldcatalog_knb1.
**Display data
**Display the data in the grid format by using set_table_for_first_display Method
**Click on patter button
**Select ABAP Objects Pattrens radio button and click on enter
**Click on enter
**Select the first radio button call method
**Enter the class name (CL_GUI_ALV_GRID), instance(LRV_GRID), method names (set_table
_for_first_display) and click on enter
CALL METHOD LRV_GRID->set_table_for_first_display
CHANGING
it_outtab
= lt_lfb1
it_fieldcatalog = LT_FIELDCAT.
**Link the docking container to the target dynpro
**Click on patter button
**Select ABAP Objects Pattrens radio button and click on enter
**Click on enter
**Select the first radio button call method
**Enter the class name(cl_gui_docking_container), instance(LRV_CONTAINER), method(link)
names and click on enter
CALL METHOD LRV_CONTAINER->link
EXPORTING
repid
= syst-repid
dynnr
= 0100.
*//Call The Screen
CALL SCREEN 0100.
END-OF-SELECTION.
*&*
*&
Module STATUS_0100 OUTPUT
*&*
*
text
*-*
MODULE status_0100 OUTPUT.

SET PF-STATUS STATUS_0100.


* SET TITLEBAR xxx.
ENDMODULE.
STATUS_0100 OUTPUT
*&*
*&
Module USER_COMMAND_0100 INPUT
*&*
*
text
*-*
MODULE user_command_0100 INPUT.
*//Back Button Functinality
CASE okcode.
WHEN BACK.
SET SCREEN 0. LEAVE SCREEN.
WHEN OTHERS.
ENDCASE.
CLEAR: okcode.
ENDMODULE.

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.

wa_filedcat-seltext = Company Code.


APPEND wa_filedcat TO LT_FIELDCAT.
CLEAR wa_filedcat.
wa_filedcat-col_pos = 3.
wa_filedcat-FIELDNAME = PERNR.
wa_filedcat-outputlen = 10.
wa_filedcat-seltext = Personnel Number.
APPEND wa_filedcat TO LT_FIELDCAT.
CLEAR wa_filedcat.
wa_filedcat-col_pos = 4.
wa_filedcat-FIELDNAME = ERNAM.
wa_filedcat-outputlen = 15.
wa_filedcat-seltext = who Created the Object.
APPEND wa_filedcat TO LT_FIELDCAT.
CLEAR wa_filedcat.
*//set button for field BUKRS
LOOP AT LT_FIELDCAT INTO wa_filedcat
WHERE ( fieldname = BUKRS ).
wa_filedcat-style = cl_gui_alv_grid=>mc_style_button.
MODIFY LT_FIELDCAT FROM wa_filedcat.
ENDLOOP.
ENDFORM.

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:

List of Transaction Codes in SAP ABAP.


Difference between Type and Like in SAP ABAP.
Creating Pushbuttons on Selection Screen.
Like this Article? Subscribe to Get Daily Updates!
Enter Your

Enter Your

27 Flares Twitter 1 Facebook 26 Google+ 0 LinkedIn 0 Email -- Pin It Share 0


ABAP Tutorials, ALV Reports, OO ABAP, OO AVL, SAP, SAP ABAP Tutorials, sap abap
tutorials for beginners
Related Posts
Difference Between Main Window and Variable Window in SAP

Display PO And Goods Receipt Details Against Purchase Requisition SAP Reports
Business Application Programming Interface Introduction BAPI
Interactive reports in SAP ABAP

SAP ABAP report with checkbox to Download selected records at Runtime

Das könnte Ihnen auch gefallen