AB1003 ABAP reports Classical and interactive v1.
India SAP CoE, Slide 1
ABAP reports Classical and interactive
1 2
Introduction Syntax Description
3
Demonstration
Exercises HelpMe
5
India SAP CoE, Slide 2
ABAP reports Classical and interactive
1 2
Introduction Syntax Description
3
Demonstration
Exercises HelpMe
5
India SAP CoE, Slide 3
Introduction
Purpose Use
India SAP CoE, Slide 4
Purpose
Reports are Programs that read data from the database, processes the data and displays the data to the required format.
India SAP CoE, Slide 5
Use
Reports are uses in day to day business environment. For eg
Displaying the purchase orders vendor wise Displaying the balance of vendors to be paid till a particular date
Enhance the efficiency & transparency of Business Processes Sound Decision making with the control of master data and accurate reporting Relevant Documents immediately available for in case of drill down reports Multiple angles of Data representing and Forecasting Values
India SAP CoE, Slide 6
ABAP reports Classical and interactive
1 2
Introduction Syntax description
3
Demonstration
Exercises HelpMe
5
India SAP CoE, Slide 7
Process Flow
India SAP CoE, Slide 8
Interactive Process Flow
event keyword
event begin event end processing block internal control event keyword processing block internal control external control
external control
...
India SAP CoE, Slide 9
Events
INITIALIZATION AT SELECTION-SCREEN
START-OF-SELECTION
END-OF-SELECTION Interactive Events
India SAP CoE, Slide 10
TOP-OF-PAGE
END-OF-PAGE TOP-OF-PAGE DURING LINE-SELECTION AT LINE-SELECTION AT USER-COMMAND AT PF<nn>
Events
INITIALIZATION
Before the standard selection screen is displayed
Cont..
AT SELECTION-SCREEN
After user input on a selection screen has been processed, but while the selection screen is still active After the standard selection screen has been processed, before data is read from the database After all data has been read by the database In list processing when a new page starts In list processing when a page ends
START-OF-SELECTION
END-OF-SELECTION
TOP-OF-PAGE
END-OF-PAGE
India SAP CoE, Slide 11
Events
Initialization.
Cont..
ABAP/4 report programs are event driven programs The different events in a report Program are:
Initialization of all the values. You can fill your selection screen with some values at runtime.
At Selection-Screen.
Validation & Checks of inputted values happen here
Start-of-Selection.
Here the program starts selecting values from tables.
End-of-selection.
After all the data has been selected this event writes the data to the screen.
Interactive Events.
Used for interactive reporting. It is used to create a detailed list from a basic list.
India SAP CoE, Slide 12
Events
Initialization
Cont..
Processed before the presentation of the selection screen Can be used to initialize values in the selection screen or to assign values to any parameters that appear on the selection screen
At Selection-Screen
Processing block is started after the user has specified all the criteria in the selection screen This event can also be called on a particular parameter or select-option using At Selection-Screen on <parameter or select-option> If an error message is displayed from this processing block then the system displays the selection screen again and wrong input fields have to be filled again.
India SAP CoE, Slide 13
Events
Start-Of-Selection
Cont..
Processing block is executed after processing the selection screen All the data is selected in this block. All the main processing on the data except for interactive reporting is handled in this block.
End-Of-Selection Data which is selected and has been processed is printed to the screen in this block. List Processing happens in this block Top-of-Page. End-of-Page.
India SAP CoE, Slide 14
Events
Events during List Processing Top-of-Page.
Cont..
Triggered by the first write statement in the program It is used to have a standard header in the program for all the pages.
New-Page.
Can be used when one wants to display different data on different pages Terminates the current page and continues output on a new page. Will not trigger the Top-of-Page or End-of-Page. Executes on the first write statement.
End-of-Page.
It is used to have a standard footer for all the pages. Triggered by the program if the number of records exceed the line-count of the program.
India SAP CoE, Slide 15
Text Symbols
Text symbols are simple text literal. they can be translated to any other Language. You can address text symbols in a program one of two ways: TEXT-<xxx> (xxx is a three digit character sequence) '<Text>'(<xxx>) (xxx is a three digit character sequence)
India SAP CoE, Slide 16
Select Statement
Select Statement
SELECT <result> INTO <target> FROM <source> [WHERE <condition>] [GROUP BY <fields>] [ORDER BY <fields>]. ENDSELECT.
India SAP CoE, Slide 17
Select Statement
Reading the Whole Line
SELECT * FROM EMP INTO TMPTABLE WHERE EMPNO = EMPNO ENDSELECT.
Reading a Single Line
SELECT SINGLE * FROM EMP WHERE EMPNO = EMPNO.
Reading Lines Using Up To
SELECT * FROM EMP WHERE EMPNO IN EMPNO UPTO N ROWS. ENDSELECT.
Reading Single Columns
SELECT NAME EMPNAME FROM EMP WHERE EMPNO = EMPNO. ENDSELECT.
Reading Data Dynamically
SELECT (TMPEMP) FROM (TBLNAME) WHERE EMPNO = EMPNO. ENDSELECT.
CLIENT SPECIFIED, BYPASSING BUFFER.
India SAP CoE, Slide 18
Where Condition
<Condition>
EQ, = NE, <>, >< LT, < GT, > LE , <= GT , >= [NOT] BETWEEN [NOT] LIKE [NOT] IN
Meaning
Equal Not Equal Less Than Greater Than Less Than or Equal Greater Than or Equal Between Like Patten In
India SAP CoE, Slide 19
Select Statement
Specifying Internal Tables
Cont..
SELECT ... INTO|APPENDING [CORRESPONDING FIELDS OF] <itab> ENDSELECT. SELECT ... INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE <itab> SELECT * FROM INTO . FOR ALL ENTRIES IN Itab WHERE .. = Itab-..
Using JOIN
SELECT employee_name, manager_name FROM employees AS e INNER JOIN managers AS m ON e.manager_id = m.manager_id SELECT employee_name, manager_name FROM employees AS e OUTER JOIN managers AS m ON e.manager_id = m.manager_id
India SAP CoE, Slide 20
Cursor
OPEN CURSOR <c> FOR SELECT <result> FROM <source> [WHERE <condition>]. FETCH NEXT CURSOR <c> INTO <target>.
CLOSE CURSOR <c>.
India SAP CoE, Slide 21
Select Statement
Specifying a Database Table
INSERT INTO <dbtab> [CLIENT SPECIFIED] <lines>.
Cont..
Inserting a Single Line
INSERT INTO <target> VALUES <wa> .
Inserting Several Lines
INSERT <target> FROM TABLE <itab> [ACCEPTING DUPLICATE KEYS] .
Specifying a Database Table
UPDATE <dbtab> [CLIENT SPECIFIED] <lines>.
Changing Lines Column by Column
UPDATE <target> SET <set1> <set 2> ... WHERE <cond>.
Overwriting Individual Lines From a Work Area
UPDATE <target> FROM <wa> / TABLE <ITAB>
Deleting Lines.
DELETE [FROM] <target> <lines>.
Changing a Database Table
MODIFY dbtab FROM wa.
India SAP CoE, Slide 22
Database Statements
Committing Database Changes. COMMIT WORK.
COMMIT WORK always concludes a database LUW and starts a new one.
ROLLBACK WORK.
ROLLBACK WORK always undoes all changes back to the start of the database LUW.
Authorization Checks
AUTHORITY-CHECK OBJECT <authorization object> ID <authority field 1> FIELD <field value 1>. ID <authority field 2> FIELD <field value 2>. ... ID <authority-field n> FIELD <field value n>.
To check the authorization of the user of an ABAP program, use the AUTHORITY-CHECK statement
India SAP CoE, Slide 23
SAP Locks
SAP Locking.
Activating a lock object causes the system to generate special function modules for locking and unlocking the objects. These function modules are called: ENQUEUE_<lock-object-name> 'For locking objects DEQUEUE_<lock-object-name> 'For unlocking objects
Call function ENQUEUE_<lock-object-name>. Update / modify database. Commit / roll back. Call function DEQUEUE_<lock-object-name>.
India SAP CoE, Slide 24
Data Declaration
India SAP CoE, Slide 25
Elementary Data Types
Type
C D F I N P T X
Output length
Len 8 22 11 Len 2*Len or 2*len+1(Decimal) 6 2*Len
Output
left-justified left-justified right-justified right-justified left-justified right-justified left-justified left-justified
Initial Value
BLANK 00000000 ZERO ZERO ZERO ZERO
000000 00
India SAP CoE, Slide 26
Arithmetic Calculation
Operator
+, -, * , / , DIV MOD ** ABS CEIL FLOOR TRUNC FRAC
Meaning
Mathematical Remainder of integer division Powers Absolute value of argument Smallest integer value Largest integer value Integer part of argument
Fraction part of argument
India SAP CoE, Slide 27
Processing Strings
SHIFT <c> [BY <n> PLACES] [<mode>]. REPLACE <str1> WITH <str2> INTO <c> [LENGTH <l>]. TRANSLATE <c> TO UPPER CASE / LOWER CASE. SEARCH <c> FOR <str> . STRLEN( WORD1 ). CONDENSE <c> [NO-GAPS]. CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED BY <s>]. SPLIT f AT g INTO h1 ... hn [<mode>}. STRLEN( f ).
Use SPACE Keyword to work with a blank Character Use DESCRIBE Keyword to get the attributes of a objects.
India SAP CoE, Slide 28
FIELD SYMBOLS
FIELD-SYMBOLS <FS> [<type>|STRUCTURE <s> DEFAULT <wa>].
ASSIGN <f> TO <FS>. ASSIGN <f>[+<o>][(<l>)] TO <FS>. ASSIGN (<f>) TO <FS>.
India SAP CoE, Slide 29
Simple Reports
Attributes.
Source code Text elements Documentation Variants
Report Statement.
REPORT ZREPNAME [NO STANDARD PAGE HEADING] [LINE-SIZE col] [LINE-COUNT n(m)] [MESSAGE-ID mid]. NO STANDARD PAGE HEADING - Suppresses output of the standard page header LINE-SIZE col - Creates a report with col columns per line. LINE-COUNT n(m) - Creates a report list with n lines per page, of which m lines are reserved for the END-OF-PAGE processing.
SUBMIT <rep> [AND RETURN] [<options>].
starts the report whose name is stored in field <rep>
India SAP CoE, Slide 30
Storing Data Objects in Memory
EXPORT <f1> [FROM <g1>] <f2> [FROM <g2>] ... TO MEMORY ID <key>.
To write data objects from an ABAP/4 program to ABAP/4 memory
IMPORT <f1> [TO <g1>] <f2> [TO <g2>] ... FROM MEMORY ID <key>.
To read data objects from ABAP/4 memory into an ABAP/4 program
SET PARAMETER ID 'RID' FIELD <FIELD NAME1>.
The system stores the value in <field name1> in the SPA parameter 'RID'. The field values saved globally in memory.
GET PARAMTER ID 'RID' FIELD <FIELD NAME2>.
The system reads the contents of 'RID' and transfers them to <FIELD NAME2>. The field values saved globally in memory.
India SAP CoE, Slide 31
Selection Screen
Parameters. PARAMETERS <p> LIKE (<name>) DEFAULT <f> OBLIGATORY AS CHECKBOX RADIOBUTTON GROUP <radi>
Select-options.
SELECT-OPTIONS <seltab> FOR <f>.
NO-EXTENSION NO INTERVALS SIGN I stands for inclusive, E stands for exclusive. OPTION EQ, NE, GT, LE, LT,CP, BT, NB and NP
CHECK SELECT-OPTIONS.
check the contents of the actual database table
India SAP CoE, Slide 32
Selection Screen
Formatting Selection Screen.
Cont..
...
SELECTION-SCREEN SKIP [<n>]. To produce blank lines on the selection screen SELECTION-SCREEN ULINE [[/]<pos(len)>] [MODIF ID <key>]. To underline a line or part of a line on the selection screen SELECTION-SCREEN COMMENT [/]<pos(len)> <name> [FOR FIELD <f>] [MODIF ID <key>]. To write text on the selection screen SELECTION-SCREEN BEGIN OF BLOCK <block> [WITH FRAME [TITLE <title>]][NO INTERVALS].
SELECTION-SCREEN END OF BLOCK <block>. To create a logical block of elements on the selection screen
India SAP CoE, Slide 33
Write Statement
WRITE <format> <value> <options>.
<format> /p(I) / = Line Feed <value> p = Column Position I = Output Length Output Value Field or Literal
<options>
/ Format Options
India SAP CoE, Slide 34
Write - Options
LEFT-JUSTIFIED
Output is left-justified.
CENTERED
Output is centered. Output is right-justified. Output starts directly under field <g>.
RIGHT-JUSTIFIED UNDER <g> NO-GAP
The blank after field <f> is omitted.
If a field contains only zeros, these are replaced by blanks. For type C and N fields, leading zeros are replaced automatically.
NO-ZERO AS SYMBOL
Writes the output as a symbol Will have to INCLUDE <symbol>.
RESERVE n LINES
If there is not enough space left on the current page for at least n lines, this statement starts a new page. n can be a constant (1,2,3,...) or a variable.
AS ICON.
Writes the output as a icon Will have to INCLUDE <icon>.
India SAP CoE, Slide 35
Write Options
WRITE AT [/][<pos>][(<len>)] <f>.
Cont..
position the output of a WRITE statement on the list by making a format specification
ULINE [AT [/][<pos>][(<len>)]].
generate horizontal lines on the output screen
WRITE [AT [/][<pos>][(<len>)]] SY-ULINE
generate horizontal lines on the output screen
WRITE [AT [/][<pos>]] SY-VLINE
generate vertical lines on the output screen
SKIP [<n>].
generate blank lines on the screen
SKIP TO LINE <n>.
allows you to move the output position upwards or downwards
WRITE <f> AS CHECKBOX
output the first character of a field as a checkbox on the output screen.
India SAP CoE, Slide 36
Write Options
ABAP/4 output Formatting.
Cont..
Format Color n. Format Color n Intensified On. FORMAT COLOR OFF INTENSIFIED OFF INVERSE OFF HOTSPOT OFF INPUT Off.
India SAP CoE, Slide 37
Internal Tables
India SAP CoE, Slide 38
Internal Tables
Standard tables.
Cont..
The time for key access to entries is in linear relation to the number of entries in the table
Sorted tables are always sorted correctly
The time for key access to entries is in logarithmic relation to the number of entries in the table
Hashed tables contain records that all have a unique key
The time for key access to entries is constant regardless of the number of entries in the table Key access can only be used to read entries in a hashed table Index operations are not allowed
India SAP CoE, Slide 39
Internal Tables
Standard Sorted
Cont.. Hashed
Comparison of Standard, Sorted and Hashed table.
Key Access Access Time For n Entries
Table Scan
Binary Srch
Hash Function
Increases Linearly (O(n))
Increases Logarithmically Remains Constant (O(log(n)) (O(1))
Access Using
Predominantly Index
Predominantly Key
Key Only
Uniqueness
NON-UNIQUE
UNIQUE| NON-UNIQUE
UNIQUE
India SAP CoE, Slide 40
Internal Tables
Cont..
Comparison of Standard, Sorted and Hashed table.
India SAP CoE, Slide 41
Internal Tables
Operations without header line
INSERT <wa> INTO TABLE <itab>. COLLECT <wa> INTO <itab>. READ TABLE <itab> ... INTO <wa>. MODIFY TABLE <itab> FROM <wa>. MODIFY <itab> FROM <wa>WHERE
Cont..
Operations with header line
INSERT TABLE ITAB COLLECT <itab>. READ TABLE <itab> MODIFY TABLE <itab> MODIFY <itab> WHERE DELETE TABLE <itab>.
DELETE TABLE <itab> FROM <wa>.
India SAP CoE, Slide 42
Internal Tables
Reading data from Internal Tables.
Loop and endloop.
Cont..
loop at it [into wa] [from m] [to n] [where exp]. --endloop.
<level>
FIRST LAST NEW <f> END Of <f> ON CHANGE OF <f>
Meaning
First line of the internal table Last line of the internal table Beginning of a group of lines with the same contents in the field <f> and in the fields left of <f> End of a group of lines with the same contents in the field <f> and in the fields left of <f> Executes the processing block enclosed by the "ON CHANGE OF f" and "ENDON" statements whenever the contents of the field f change (control break processing).
India SAP CoE, Slide 43
Internal Tables
Read table. READ TABLE <itab> <key> <result>.
Cont..
Reading data from Internal Tables using BINARY SEARCH.
READ TABLE itab WITH KEY k1 = v1 ... kn = vn [BINARY SEARCH] It is mandatory for the internal table to be sorted in ascending order in the sequence of the specified key fields. READ TABLE itab INDEX i
SORT - Sorting an Internal Table
SORT itab [ASCENDING / DESCENDING] BY f1 f2 ... fn
India SAP CoE, Slide 44
Extracts
Extracts
Defining an Extracts.
FIELD-GROUPS <fg>.
Filling an Extract with Data.
INSERT <f1>... <f n> INTO <fg>.
Reading an Extract
LOOP. [AT FIRST | AT <fgi> [WITH <fg j>] | AT LAST. ENDAT.] ENDLOOP.
Sorting an Extract
SORT [ASCENDING|DESCENDING]
India SAP CoE, Slide 45
IF Condition
Logical Expression
If < Cond>.
{statements}
Elseif.
{statements}
Endif.
India SAP CoE, Slide 46
Case Statement
India SAP CoE, Slide 47
DO and While Loops
India SAP CoE, Slide 48
CHECK and EXIT
SAP recommends that you only use CHECK within loops.
India SAP CoE, Slide 49
Interactive Reporting
The following are the different events associated with Interactive Reporting
Event Keyword
At Line-Selection At User-Command At PFn Where n is between 0 to 99 Top-of-Page during Line Selection
Event
Event is triggered by either the user double clicking a particular line or using F2 to select it Event triggered by user pressing a function key Event triggered on press of a function key. Event called during list processing when a detailed list is called
India SAP CoE, Slide 50
Interactive Reporting
READ - Reading a Line from a List Reads line number line of the list, usually after a line selection READ LINE line. READ LINE line OF CURRENT PAGE. READ LINE line OF PAGE pag READ CURRENT LINE
Cont..
MODIFY LINE n. Change a List Line INDEX idx - Changes the corresponding line in the list at list level idx
FIELD VALUE f1 FROM g1 ... fn FROM gn
WINDOW STARTING AT x1 y1 ENDING AT x2 y2. Displays the current secondary list as a modal dialog box only up to 20 windows
India SAP CoE, Slide 51
Interactive Reporting
Hotspot
Cont..
If one drags the mouse over the data displayed in the report using the FORMAT statement then the cursor changes to a Hand with an Outstretched Index finger Syntax: Format Hotspot On (Off).
Hide
This command helps you to store the field names based on which one will be doing further processing to get a detailed list. It is written directly after the WRITE statement for a field. When a row is selected the values get automatically filled in the variables for further use. Syntax: Hide <field-name>.
Get Cursor Command
Like Hide this is also used for getting the values after selection of a row. Syntax: Get Cursor field cur_name value cur_value. cur_name and cur_value are variables.
CALL TRANSACTION '<TRAN>' AND SKIP FIRST SCREEN.
Call a SAP transaction from ABAP Code.
India SAP CoE, Slide 52
Logical databases
It is another way of retrieving data for a program. Logical databases are created by transaction SE36 The data is selected by another program and one can access the data using GET <table-name> command which places the data in the work area <table-name>. Advantages of a logical database over normal Select queries. It offers check conditions to see whether the input is correct, complete and plausible It contains central authorization checks for database access Enhancements such as improvement in performance immediately apply to all reports which use logical database. Note: Logical database is not used in most of the cases.
India SAP CoE, Slide 53
A Few More Points
Variants
Variants are input data which are filled in the selection screen and then saved so that at runtime the variant can be selected and then the entire selection screen is filled with the desired values.
Background Processing
When a program takes a long time to execute then one can execute the program in background so that a job is set up for that program. The job can be seen in transaction SM37. The job log gives the exact start time and the end time for the job.
CATCH - Catching Runtime Errors
CATCH SYSTEM-EXCEPTIONS except1 = rc1 ... exceptn = rcn. ENDCATCH. The CATCHENDCATCH block allows the programmer to catch ABAP runtime errors and assign these to a SY_SUBRC value
Comments. Commented lines in the program start with asterisk (*) To comment a part of line use double codes ().
India SAP CoE, Slide 54
Modularization
Subroutines
Subroutines are procedures that you can define in any ABAP program and also call from any program.
Function modules
Function modules are procedures that are defined in function groups and can be called from any ABAP program.
Include
If you want to use the same sequence of statements in several programs, you can code them once in an include program.
India SAP CoE, Slide 55
Subroutines
Defining Subroutines
FORM <subr> [USING ... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ] [CHANGING... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ]. ... ENDFORM.
The Parameter Interface
Parameters Passed by Reference list these parameters after USING without the VALUE addition Parameters Passed by Value list these parameters after USING with the VALUE addition Passing by Value and Result If you want to return a changed output parameter from a subroutine to the calling program only after the subroutine has run successfully, use CHANGING for the <pass> option of the FORM and PERFORM
India SAP CoE, Slide 56
Subroutines
Calling Subroutines
PERFORM... [USING ... <pi>... ] [CHANGING... <pi>... ].
Cont..
Static Variable
If you want to keep the value of a local data object after exiting the subroutine, you must use the STATICS statement to declare it instead of the DATA statement. With STATICS you declare a data object that is globally defined, but only locally visible from the subroutine in which it is defined. STATICS f_text TYPE f_word VALUE 'INIT'.
India SAP CoE, Slide 57
Function modules
Calling Function Modules
CALL FUNCTION <module> [EXPORTING f1 = a 1.... f n = a n] [IMPORTING f1 = a 1.... f n = a n] [CHANGING f1 = a 1.... f n = a n] [TABLES f1 = a 1.... f n = a n] [EXCEPTIONS e1 = r 1....en = rn [ERROR_MESSAGE = r E] [OTHERS = ro]].
Creating Function Modules (SE37)
Attributes Parameter Interface Tables Exceptions Source Code
India SAP CoE, Slide 58
Function modules
Cont..
India SAP CoE, Slide 59
Function modules
Calling A Function modules - Pattern
Cont..
India SAP CoE, Slide 60
Function modules
Testing A Function modules SE37
Cont..
India SAP CoE, Slide 61
Include
Creating Include.
Use Transaction SE38 to create a include program.
Using Include.
Include <incl> This inserts the source code <incl> into the ABAP/4 program during the syntax check and during generation. The INCLUDE statement performs the same function as if you were to copy the source code of <incl> to the position of the statement in the calling program.
India SAP CoE, Slide 62
Working With Files
Presentation Server. Application Server.
India SAP CoE, Slide 63
Files Presentation Server
To Upload data from the Presentation Server use the Function Module
GUI_UPLOAD
To Download data to the Presentation Server use the Function Module
GUI_DOWNLOAD
India SAP CoE, Slide 64
Files Application Server
OPEN DATASET <dsn> [options] This statement opens file <dsn>. FOR INPUT open a file for reading FOR OUTPUT open a file for writing. FOR APPENDING open a file for Appending. CLOSE DATASET <dsn> Closes a file on application sever. TRANSFER <f> to <dsn> [LENGTH <len>]. write data to a file on the application server. READ DATASET <dsn> INTO <f> [LENGTH <len>]. read data from a file on the application server. DELETE DATASET <dsn>. delete a file on the application server
India SAP CoE, Slide 65
System Variables - SYST
SY-CPAGE SY-CUCOL SY-CUROW SY-DATUM SY-LANGU SY-LISEL SY-INDEX SY-LSIND SY-MANDT SY-REPID SY-SUBRC SY-LILLI SY-BATCH Current page number Horizontal cursor position Vertical cursor position Current (application server) date Current language Content of selected row Current loop pass Index of detail list Client number from logon Current main program Return value after ABAP statement Absolute number of the line which triggered the event Program runs in the background
India SAP CoE, Slide 66
ABAP reports Classical and interactive
1 2
Introduction Syntax Description
3
Demonstration
Exercises HelpMe
5
India SAP CoE, Slide 67
Simple Reports
Simple Reports
REPORT TEST. Initialization. Data : a type I value 10, b type I value 15, sum type I. start-of-selection. WRITE 'This is a statement *This is commented line *The write statement can also be written as. end-of-selection. WRITE 'This' & ' is ' & 'a statement'.
Sum = a + b. Write:/ sum.
India SAP CoE, Slide 68
Data Declaration
data: begin of it1 occurs 10, Name(10), Phno type i, end of it1. "has a header line
data it2 like it1 occurs 100. "doesn't have a header line data it3 like it1 occurs 100 with header line. "it does now
Name
Header
Phno
Internal Table Body
India SAP CoE, Slide 69
Data Declaration
Data Declaration
DATA: PLAYER(35) TYPE C, NICKNAME(35), POINTS GAMES TYPE I AVERAGE(5) STARTER, ACQUIRED PLAYER(35) TYPE C NICKNAME ACQUIRED TYPE I. VALUE 10, TYPE P, TYPE D. VALUE CapGemini, LIKE PLAYER, LIKE SY-DATUM.
Cont..
DATA:
DATA:
India SAP CoE, Slide 70
Data Declaration
Data Declaration
CONSTANTS:TEAM1(20) TYPE C TEAM2 LIKE TOT_GAMES TYPE-POOLS Z400. TYPES: NAME(35) TYPE C, TEAMS(20) VALUE 76ers, TEAM1 VALUE Celtics, TYPE I VALUE 82.
Cont..
TYPE C.
DATA:
PLAYER
TYPE NAME VALUE CapGemini, NICKNAME LIKE PLAYER.
TEAM1 TYPE TEAMS VALUE 76ers, TEAM2 LIKE TEAM1 VALUE Celtics.
CONSTANTS:
The CLEAR statement sets a field back to its initial value, not its default value.
India SAP CoE, Slide 71
Data Declaration
Data Declaration Value Assignment
DATA: TITLE(25), SORT_NAME(10), SALARY(10) TYPE N, CNVSALARY(10) TYPE N, GRID_LEVEL TYPE I.
Cont..
MOVE President TO TITLE. MOVE 5 TO GRID_LEVEL. COMPUTE SALARY = 5000000. CNVSALARY = SALARY * 3. ADD 1000 TO SALARY.
India SAP CoE, Slide 72
Data Declaration
Calculating Values.
DATA: COUNTER TYPE I, AMOUNT TYPE P VALUE 1000, SUM TYPE P, RESULT TYPE P, NUMBER(2) TYPE C VALUE 99, ROOT TYPE F. COUNTER = COUNTER + 2. RESULT = AMOUNT * COUNTER. SUM = RESULT + NUMBER COUNTER. RESULT = COUNTER * ( AMOUNT + NUMBER ). BREAK-POINT. Creates a breakpoints. ROOT = SQRT ( NUMBER + COUNTER ).
Cont..
India SAP CoE, Slide 73
Select Statement
Select Statement.
Select * from bfpf into itab where bukrs = 0001 and belnr eq 00200689 gjahr gt 2005. Append itab. Clear itab. Endselect Select * from bfpf into table itab where bukrs = 0001 and belnr eq 00200689 gjahr gt 2005.
and
and
India SAP CoE, Slide 74
Select Statement
Select Statement - Join.
Cont..
REPORT SELECT t1~carrid t1~connid t2~customid INTO (carrid, connid, custid) FROM sflight AS t1 INNER JOIN sbook AS t2 ON t1~carrid = t2~carrid WHERE t1~connid = t2~connid AND t1~fldate = t2~fldate. WRITE:/ carrid, connid, custid ENDSELECT.
India SAP CoE, Slide 75
Select Statement
Select Statement FOR ALL ENTRIES.
Select * from BKPF into table it_bkpf where <conditions>. If it_bkpf[] is not initial.
Cont..
Select * from bseg into table it_bseg FOR ALL ENTRIES IN IT_BKPF WHERE BELNR = it_bkpf-belnr and BUKRS = it_bkpf-bukrs and GJAHR = it_bkpf-gjahr and BUZEI = it_bkpf-buzei.
Endif.
India SAP CoE, Slide 76
Field Symbols
Field Symbols
REPORT demo_field_symbols_type . DATA: BEGIN OF line, col1(1) TYPE c, col2(1) TYPE c VALUE 'X', END OF line. FIELD-SYMBOLS <fs> LIKE line. ASSIGN line TO <fs>. MOVE <fs>-col2 TO <fs>-col1. WRITE:/ <fs>-col1
India SAP CoE, Slide 77
Internal Table
Internal Tables - Sorted REPORT TYPES: BEGIN OF line_type, f1, f2, END OF line_type. DATA: tab1 TYPE SORTED TABLE OF line_type WITH UNIQUE KEY f1 WITH HEADER LINE. tab1-f1 = Y. Tab1-f2 = 1. INSERT TABLE tab1. tab1-f1 = X. Tab1-f2 = 1. INSERT TABLE tab1. tab1-f1 = A. Tab1-f2 = 1. INSERT TABLE tab1.
READ TABLE tab1 WITH TABLE KEY f1 = A.
LOOP AT tab1. WRITE:/ tab1-f1, tab1-f2. ENDLOOP.
India SAP CoE, Slide 78
Internal Table
Internal Tables - Reading TYPES: BEGIN OF line_type, f1, f2, f3, END OF line_type. DATA: tab1 TYPE STANDARD TABLE OF line_type WITH KEY f1 f2, wa type line_type. wa-f1 = 'B'. wa-f2 = '5'. wa-f3 = '12.45'. READ TABLE tab1 FROM wa INTO wa. READ TABLE tab1 WITH TABLE KEY f1 = 'B' f2 = '5' INTO wa.
Cont..
Work area wa
Wa before Wa after read
Internal Table tab1
India SAP CoE, Slide 79
Subroutines
TYPES: BEGIN OF LINE, COL1, COL2, END OF LINE. DATA: WA TYPE LINE, ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1, KEY(4) VALUE 'COL1'. WA-COL1 = 'X'. INSERT WA INTO TABLE ITAB. WA-COL1 = 'Y'. INSERT WA INTO TABLE ITAB. PERFORM DEMO USING ITAB. FORM DEMO USING P TYPE ANY TABLE. DATA: T_WA TYPE LINE. LOCAL VARIABLE FOR SUBROUTINE. READ TABLE P WITH TABLE KEY (KEY) = 'X' INTO WA. WRITE:/ T_WA-COL1. ENDFORM.
India SAP CoE, Slide 80
Subroutines
Data: begin of itab occurs, matnr like mara-matnr, mtart like mara-mtart, meins like mara-meins, End of itab. Perform get_data. Perform download_data. Form get_data. Select matnr mtart meins into table itab from mara up to 50 rows. Endform. Form download_data. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING FILENAME = 'c:\[Link]' FILETYPE = 'ASC' TABLES DATA_TAB = itab. Endform.
India SAP CoE, Slide 81
Cont..
Catch - Endcatch
To code the first part of a CATCHENDCATCH block it is necessary to code CATCH SYSTEM EXCEPTIONS and specify one of the following: Error Class Specific error ID OTHERS, which traps all catchable runtime errors
DATA: [..] CATCH SYSTEM-EXCEPTIONS CONVERSION_ERRORS = 1. [..] MOVE char TO int. MOVE keyword to trigger CATCH [..] ENDCATCH. int type I, char(3) type C value ABC.
IF SY-SUBRC = 1. WRITE: / Conversion error has occurred. ENDIF.
India SAP CoE, Slide 82
Debugger
Execute Run Completely Break Points Single Step
Variables
India SAP CoE, Slide 83
Debugger
Fields Table
Cont..
The scrollable field display contains the contents of up to eight fields. The contents of the three most important system fields are always displayed. This is the default display mode in the Debugger. See also Processing Fields Displays the contents of an internal table. This mode allows you to display and edit the entries in an internal table. See also Processing Internal Tables A scrollable display containing up to 30 breakpoints. Next to each breakpoint is a counter. You can also delete breakpoints in this display. See also Managing Dynamic Breakpoints You can set a watchpoint for a field so that the program is interrupted whenever the value of that field changes. This display mode contains a list of Watchpoints, the fields and programs to which they are assigned, the current values of the fields, and the conditions upon which the watchpoint is activated. See also Setting Watchpoints This mode displays the current sequence of events, and the sequence of calls up to the current breakpoint. The last active call is displayed at the top of the list; previous calls are listed in reverse chronological order. When an event (for example, START-OF-SELECTION) concludes, it is deleted from the display. This mode displays the structure of the program. It lists its events, subroutines, and modules, and shows which sections belong to which events. It also displays the section currently being processed. This mode displays the current Debugger settings. You can change the settings by selecting or deselecting various options. For further information, refer to Settings and Warnings
Breakpoints
Watchpoints
Calls
Overview
Settings
India SAP CoE, Slide 84
Releasing Request
Releasing Your Transport Request SE09
Enter Your Login ID and view the Modifiable Requests Select Your Request and click on Release Directly.
India SAP CoE, Slide 85
ABAP reports Classical and interactive
1 2
Introduction Syntax Description
3
Demonstration
Exercises HelpMe
5
India SAP CoE, Slide 86
Exercises - 1
Read a set of results from table EKPO. Create a selection screen with an input field for EKPO-EBELN (Document Number). Define a structure as a work area by referring to your table EKPO. Program a SELECT loop that reads the data specified by the user and places it in your work area. Using the WRITE statement within the SELECT loop, display the following fields: EBELP Item Number of Purchasing Document MATNR Material Number LGORT Storage Location MATKL Material Group MENGE Purchase order quantity MEINS Order Unit NETPR Net price To generate a line feed, precede the data object you want to display with the / [Link]:WRITE : / wa_EKPO-EBELP,
India SAP CoE, Slide 87
Exercises - 2
Create a list of all FI Documents between the dates entered by the user. Create a selection screen with an input field for BKPF-BUDAT (Document Date). Select BELNR (Document Number), BUKRS (Company Code) and GJAHR (Fiscal Year) from the table BKPF and correspondingly select BUZEI (Line item number), DMBTR (Amount). Within the loop, avail the vendor / customer a discount of 10% on DMBTR using the corresponding field of the work area. Append your work area to the internal table. Sort the internal table according to the net price. Display the following fields: BELNR Document Number BUKRS Company Code GJAHR Fiscal Year BUDAT Document Date BUZEI Document Item Number DMBTR Amount
India SAP CoE, Slide 88
Exercises - 3
Create a tabulated list of Vendors entered by the user. Create a selection screen with an input field for LFA1-LIFNR (Vendor). Select Vendors from the table LIFNR from the selection-screen. Display the list of vendors selected on the basic list. If the User chooses a particular Vendor Display this contact details with a HOTSPOT on his Name on a detailed list. If the user click in this hotspot call the transaction FBL2N (Vendor Balance) with the current fiscal year and skip the initial screen.
India SAP CoE, Slide 89
ABAP reports Classical and interactive
1 2
Introduction Syntax Description
3
Demonstration
Exercises HelpMe
5
India SAP CoE, Slide 90
HelpMe
Tips and Tricks Additional Info
India SAP CoE, Slide 91
Tips and Tricks
Keep the Result Set Small
Minimize the Amount of Data Transferred Minimize the Number of Data Transfers Minimize the Search Overhead Reduce the Database Load Use T-Code SE30 to view run time analysis of your program For Example Code on each topic use T-Code ABAPDOCU. Use Pretty Printer for code alignment. For SQL Trace Use T-Code ST05.
India SAP CoE, Slide 92
Additional Info
Use the below link for complete details on ABAP.
[Link] 1829f0000e829fbfe/[Link]
India SAP CoE, Slide 93