ab1003 - abap reports - classical and interactive - v1.0
DESCRIPTION
sap abapTRANSCRIPT
India SAP CoE, Slide 1
AB1003 – ABAP reports – Classical AB1003 – ABAP reports – Classical and interactive – v1.0and interactive – v1.0
India SAP CoE, Slide 2
ABAP reports – Classical and interactiveABAP reports – Classical and interactive
1 Introduction
2 Syntax Description
3 Demonstration
4 Exercises
5 HelpMe
India SAP CoE, Slide 3
ABAP reports – Classical and interactiveABAP reports – Classical and interactive
1 Introduction
2 Syntax Description
3 Demonstration
4 Exercises
5 HelpMe
India SAP CoE, Slide 4
IntroductionIntroduction
• PurposePurpose
• UseUse
India SAP CoE, Slide 5
PurposePurpose
Reports are Programs that read data from the database, Reports are Programs that read data from the database, processes the data and displays the data to the required format.processes the data and displays the data to the required format.
India SAP CoE, Slide 6
UseUse
•Reports are uses in day to day business environment. For egReports are uses in day to day business environment. For eg– Displaying the purchase orders vendor wiseDisplaying the purchase orders vendor wise– Displaying the balance of vendors to be paid till a particular dateDisplaying the balance of vendors to be paid till a particular date
•Enhance the efficiency & transparency of Business ProcessesEnhance the efficiency & transparency of Business Processes
•Sound Decision making with the control of master data andSound Decision making with the control of master data and
accurate reporting accurate reporting
•Relevant Documents immediately available for in case of drill down Relevant Documents immediately available for in case of drill down reportsreports
•Multiple angles of Data representing and Forecasting ValuesMultiple angles of Data representing and Forecasting Values
India SAP CoE, Slide 7
ABAP reports – Classical and interactiveABAP reports – Classical and interactive
1 Introduction
2 Syntax description
3 Demonstration
4 Exercises
5 HelpMe
India SAP CoE, Slide 8
Process FlowProcess Flow
India SAP CoE, Slide 9
Interactive Process FlowInteractive Process Flow
event keyword
processing blockinternal control
event keyword
processing blockinternal control
…...
external controlexternal control
external controlexternal control
event beginevent begin
event endevent end
India SAP CoE, Slide 10
EventsEvents
INITIALIZATIONINITIALIZATION
AT SELECTION-SCREENAT SELECTION-SCREEN
START-OF-SELECTIONSTART-OF-SELECTION
END-OF-SELECTIONEND-OF-SELECTION
Interactive EventsInteractive Events
} TOP-OF-PAGE
END-OF-PAGETOP-OF-PAGE DURING
LINE-SELECTIONAT LINE-SELECTIONAT USER-COMMAND
AT PF<nn>
India SAP CoE, Slide 11
Events Events Cont..Cont..
• INITIALIZATION INITIALIZATION – Before the standard selection screen is displayedBefore the standard selection screen is displayed
• AT SELECTION-SCREENAT SELECTION-SCREEN– After user input on a selection screen has been processed, but while the After user input on a selection screen has been processed, but while the
selection screen is still activeselection screen is still active • START-OF-SELECTION START-OF-SELECTION
– After the standard selection screen has been processed, before data is read After the standard selection screen has been processed, before data is read from the databasefrom the database
• END-OF-SELECTIONEND-OF-SELECTION – After all data has been read by the database After all data has been read by the database
• TOP-OF-PAGETOP-OF-PAGE– In list processing when a new page startsIn list processing when a new page starts
• END-OF-PAGEEND-OF-PAGE– In list processing when a page endsIn list processing when a page ends
India SAP CoE, Slide 12
Events Events Cont..Cont..
ABAP/4 report programs are event driven programsABAP/4 report programs are event driven programsThe different events in a report Program are:The different events in a report Program are:
Initialization.Initialization.Initialization of all the values. You can fill your selection screen Initialization of all the values. You can fill your selection screen with some values at runtime.with some values at runtime.
At Selection-Screen.At Selection-Screen.Validation & Checks of inputted values happen hereValidation & Checks of inputted values happen here
Start-of-Selection.Start-of-Selection.Here the program starts selecting values from tables.Here the program starts selecting values from tables.
End-of-selection.End-of-selection.After all the data has been selected this event writes the data to After all the data has been selected this event writes the data to the screen.the screen.
Interactive Events.Interactive Events.Used for interactive reporting. It is used to create a detailed list Used for interactive reporting. It is used to create a detailed list from a basic list.from a basic list.
India SAP CoE, Slide 13
Events Events Cont..Cont..
InitializationInitialization•Processed before the presentation of the selection screenProcessed before the presentation of the selection screen
Can be used to initialize values in the selection screen or to assign Can be used to initialize values in the selection screen or to assign values to any parameters that appear on the selection screenvalues to any parameters that appear on the selection screen
At Selection-ScreenAt Selection-Screen•Processing block is started after the user has specified all the criteria in the Processing block is started after the user has specified all the criteria in the selection screenselection screen
This event can also be called on a particular parameter or select-option This event can also be called on a particular parameter or select-option using At Selection-Screen on <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 If an error message is displayed from this processing block then the system displays the selection screen again and wrong input fields have system displays the selection screen again and wrong input fields have to be filled again.to be filled again.
India SAP CoE, Slide 14
Events Events Cont..Cont..
Start-Of-SelectionStart-Of-Selection–Processing block is executed after processing the selection screenProcessing block is executed after processing the selection screen–All the data is selected in this block.All the data is selected in this block.–All the main processing on the data except for interactive reporting is All the main processing on the data except for interactive reporting is handled in this block.handled in this block.
End-Of-SelectionEnd-Of-Selection–Data which is selected and has been processed is printed to the Data which is selected and has been processed is printed to the screen in this block.screen in this block.–List Processing happens in this blockList Processing happens in this block
Top-of-Page.Top-of-Page.End-of-Page.End-of-Page.
India SAP CoE, Slide 15
Events Events Cont..Cont..
Events during List ProcessingEvents during List ProcessingTop-of-Page.Top-of-Page.
Triggered by the first write statement in the programTriggered by the first write statement in the programIt is used to have a standard header in the program for all the pages.It is used to have a standard header in the program for all the pages.
New-Page.New-Page.Can be used when one wants to display different data on different pagesCan be used when one wants to display different data on different pagesTerminates the current page and continues output on a new page.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 Will not trigger the Top-of-Page or End-of-Page. Executes on the first write statement.statement.
End-of-Page.End-of-Page.It is used to have a standard footer for all the pages.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 Triggered by the program if the number of records exceed the line-count of the program.the program.
India SAP CoE, Slide 16
Text SymbolsText Symbols
– Text symbols are simple text literal.Text symbols are simple text literal.
– they can be translated to any other Language.they can be translated to any other Language.
– You can address text symbols in a program one of two ways: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)
– '<Text>'(<xxx>) (xxx is a three digit character sequence)'<Text>'(<xxx>) (xxx is a three digit character sequence)
India SAP CoE, Slide 17
Select StatementSelect Statement
•SELECT <result> SELECT <result> INTO <target> INTO <target> FROM <source> FROM <source> [WHERE <condition>] [WHERE <condition>] [GROUP BY <fields>] [GROUP BY <fields>] [ORDER BY <fields>]. [ORDER BY <fields>].
•ENDSELECT.ENDSELECT.
Select StatementSelect Statement
India SAP CoE, Slide 18
Select StatementSelect Statement
•Reading the Whole LineReading the Whole Line – SELECT * FROM EMP INTO TMPTABLE WHERE EMPNO = EMPNOSELECT * FROM EMP INTO TMPTABLE WHERE EMPNO = EMPNO– ENDSELECT.ENDSELECT.
•Reading a Single LineReading a Single Line– SELECT SINGLE * FROM EMP WHERE EMPNO = EMPNO.SELECT SINGLE * FROM EMP WHERE EMPNO = EMPNO.
•Reading Lines Using Up ToReading Lines Using Up To– SELECT * FROM EMP WHERE EMPNO IN EMPNO UPTO N ROWS.SELECT * FROM EMP WHERE EMPNO IN EMPNO UPTO N ROWS.– ENDSELECT.ENDSELECT.
•Reading Single ColumnsReading Single Columns– SELECT NAME EMPNAME FROM EMP WHERE EMPNO = EMPNO.SELECT NAME EMPNAME FROM EMP WHERE EMPNO = EMPNO.– ENDSELECT.ENDSELECT.
•Reading Data DynamicallyReading Data Dynamically – SELECT (TMPEMP) FROM (TBLNAME) WHERE EMPNO = EMPNO.SELECT (TMPEMP) FROM (TBLNAME) WHERE EMPNO = EMPNO.– ENDSELECT.ENDSELECT.
•CLIENT SPECIFIED, BYPASSING BUFFER.CLIENT SPECIFIED, BYPASSING BUFFER.
India SAP CoE, Slide 19
Where ConditionWhere Condition
<Condition><Condition>EQ, = EQ, =
NE, <>, ><NE, <>, ><
LT, <LT, <
GT, >GT, >
LE , <=LE , <=
GT , >=GT , >=
[NOT] BETWEEN[NOT] BETWEEN
[NOT] LIKE[NOT] LIKE
[NOT] IN[NOT] IN
MeaningMeaningEqualEqual
Not EqualNot Equal
Less ThanLess Than
Greater ThanGreater Than
Less Than or EqualLess Than or Equal
Greater Than or EqualGreater Than or Equal
BetweenBetween
Like PattenLike Patten
InIn
India SAP CoE, Slide 20
Select Statement Select Statement Cont..Cont..
•Specifying Internal TablesSpecifying Internal Tables – SELECT ... INTO|APPENDING [CORRESPONDING FIELDS OF] <itab>SELECT ... INTO|APPENDING [CORRESPONDING FIELDS OF] <itab>– ENDSELECT.ENDSELECT.– SELECT ... INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE SELECT ... INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE
<itab><itab>– SELECT * FROM …INTO …. SELECT * FROM …INTO ….
FOR ALL ENTRIES IN Itab FOR ALL ENTRIES IN Itab WHERE .. = Itab-….. WHERE .. = Itab-…..
•Using JOINUsing JOIN– SELECT employee_name, manager_name SELECT employee_name, manager_name
FROM employees AS e INNER JOIN managers AS m FROM employees AS e INNER JOIN managers AS m ON e.manager_id = m.manager_id ON e.manager_id = m.manager_id
– SELECT employee_name, manager_name SELECT employee_name, manager_name FROM employees AS e OUTER JOIN managers AS m FROM employees AS e OUTER JOIN managers AS m ON e.manager_id = m.manager_id ON e.manager_id = m.manager_id
India SAP CoE, Slide 21
CursorCursor
• OPEN CURSOR <c> FOR SELECT <result> OPEN CURSOR <c> FOR SELECT <result> FROM <source> FROM <source> [WHERE <condition>]. [WHERE <condition>].
• FETCH NEXT CURSOR <c> INTO <target>.FETCH NEXT CURSOR <c> INTO <target>.
• CLOSE CURSOR <c>.CLOSE CURSOR <c>.
India SAP CoE, Slide 22
Select StatementSelect Statement Cont..Cont..
• Specifying a Database TableSpecifying a Database Table – INSERT INTO <dbtab> [CLIENT SPECIFIED] <lines>.INSERT INTO <dbtab> [CLIENT SPECIFIED] <lines>.
• Inserting a Single LineInserting a Single Line– INSERT INTO <target> VALUES <wa> . INSERT INTO <target> VALUES <wa> .
• Inserting Several LinesInserting Several Lines– INSERT <target> FROM TABLE <itab> [ACCEPTING DUPLICATE KEYS] .INSERT <target> FROM TABLE <itab> [ACCEPTING DUPLICATE KEYS] .
• Specifying a Database TableSpecifying a Database Table – UPDATE <dbtab> [CLIENT SPECIFIED] <lines>. UPDATE <dbtab> [CLIENT SPECIFIED] <lines>.
• Changing Lines Column by ColumnChanging Lines Column by Column – UPDATE <target> SET <set1> <set 2> ... WHERE <cond>.UPDATE <target> SET <set1> <set 2> ... WHERE <cond>.
• Overwriting Individual Lines From a Work AreaOverwriting Individual Lines From a Work Area – UPDATE <target> FROM <wa> / TABLE <ITAB>UPDATE <target> FROM <wa> / TABLE <ITAB>
• Deleting Lines.Deleting Lines.– DELETE [FROM] <target> <lines>.DELETE [FROM] <target> <lines>.
• Changing a Database Table Changing a Database Table – MODIFY dbtab FROM wa. MODIFY dbtab FROM wa.
India SAP CoE, Slide 23
Database StatementsDatabase Statements• Committing Database ChangesCommitting Database Changes..
– COMMIT WORK.COMMIT WORK.• COMMIT WORK always concludes a database LUW and starts a new COMMIT WORK always concludes a database LUW and starts a new
one. one.
– ROLLBACK WORK.ROLLBACK WORK.• ROLLBACK WORK always undoes all changes back to the start of the ROLLBACK WORK always undoes all changes back to the start of the
database LUW. database LUW.
• Authorization ChecksAuthorization Checks– AUTHORITY-CHECK OBJECT <authorization object> AUTHORITY-CHECK OBJECT <authorization object>
ID <authority field 1> FIELD <field value 1>. ID <authority field 1> FIELD <field value 1>. ID <authority field 2> FIELD <field value 2>. ID <authority field 2> FIELD <field value 2>. ... ... ID <authority-field n> FIELD <field value n>. ID <authority-field n> FIELD <field value n>.
– To check the authorization of the user of an ABAP program, use the To check the authorization of the user of an ABAP program, use the
AUTHORITY-CHECK statementAUTHORITY-CHECK statement
India SAP CoE, Slide 24
SAP LocksSAP Locks
• SAP Locking.SAP Locking.Activating a lock object causes the system to generate special function Activating a lock object causes the system to generate special function
modules for locking and unlocking the objects. These function modules are called: modules for locking and unlocking the objects. These function modules are called: • ENQUEUE_<lock-object-name> 'For locking objectsENQUEUE_<lock-object-name> 'For locking objects• DEQUEUE_<lock-object-name> 'For unlocking objectsDEQUEUE_<lock-object-name> 'For unlocking objects
Call function ENQUEUE_<lock-object-name>.Call function ENQUEUE_<lock-object-name>.
Update / modify database.Update / modify database.
Commit / roll back.Commit / roll back.
Call function DEQUEUE_<lock-object-name>.Call function DEQUEUE_<lock-object-name>.
India SAP CoE, Slide 25
Data DeclarationData Declaration
India SAP CoE, Slide 26
Elementary Data TypesElementary Data Types
TypeType Output lengthOutput length OutputOutput Initial Value Initial Value
CC LenLen left-justifiedleft-justified BLANKBLANK
DD 88 left-justifiedleft-justified 0000000000000000
FF 2222 right-justifiedright-justified ZEROZERO
II 1111 right-justifiedright-justified ZEROZERO
NN LenLen left-justifiedleft-justified ZEROZERO
PP2*Len or 2*Len or
2*len+1(Decimal)2*len+1(Decimal) right-justifiedright-justifiedZEROZERO
TT 6 6 left-justifiedleft-justified 000000000000
XX 2*Len 2*Len left-justifiedleft-justified 0000
India SAP CoE, Slide 27
Arithmetic CalculationArithmetic Calculation
OperatorOperator+, -, * , / , DIV+, -, * , / , DIV
MODMOD
****
ABSABS
CEILCEIL
FLOORFLOOR
TRUNCTRUNC
FRACFRAC
MeaningMeaningMathematical Mathematical
Remainder of integer divisionRemainder of integer division
PowersPowers
Absolute value of argument Absolute value of argument
Smallest integer value Smallest integer value
Largest integer valueLargest integer value
Integer part of argument Integer part of argument
Fraction part of argumentFraction part of argument
India SAP CoE, Slide 28
Processing StringsProcessing Strings– SHIFT <c> [BY <n> PLACES] [<mode>]. SHIFT <c> [BY <n> PLACES] [<mode>]. – REPLACE <str1> WITH <str2> INTO <c> [LENGTH <l>]. REPLACE <str1> WITH <str2> INTO <c> [LENGTH <l>].
– TRANSLATE <c> TO UPPER CASE / LOWER CASE.TRANSLATE <c> TO UPPER CASE / LOWER CASE.
– SEARCH <c> FOR <str> .SEARCH <c> FOR <str> .
– STRLEN( WORD1 ). STRLEN( WORD1 ).
– CONDENSE <c> [NO-GAPS]. CONDENSE <c> [NO-GAPS].
– CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED BY <s>].CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED BY <s>].
– SPLIT f AT g INTO h1 ... hn [<mode>}.SPLIT f AT g INTO h1 ... hn [<mode>}.
– STRLEN( f ).STRLEN( f ).
Use SPACE Keyword to work with a blank CharacterUse SPACE Keyword to work with a blank Character
Use DESCRIBE Keyword to get the attributes of a objects.Use DESCRIBE Keyword to get the attributes of a objects.
India SAP CoE, Slide 29
FIELD SYMBOLSFIELD SYMBOLS
– FIELD-SYMBOLS <FS> [<type>|STRUCTURE <s> DEFAULT <wa>]. FIELD-SYMBOLS <FS> [<type>|STRUCTURE <s> DEFAULT <wa>].
– ASSIGN <f> TO <FS>. ASSIGN <f> TO <FS>.
– ASSIGN <f>[+<o>][(<l>)] TO <FS>. ASSIGN <f>[+<o>][(<l>)] TO <FS>.
– ASSIGN (<f>) TO <FS>. ASSIGN (<f>) TO <FS>.
India SAP CoE, Slide 30
Simple ReportsSimple Reports– Attributes.Attributes.
• Source code Source code • Text elements Text elements • Documentation Documentation •
VariantsVariants Report Statement.Report Statement.
REPORT ZREPNAME [NO STANDARD PAGE HEADING] [LINE-SIZE col] REPORT ZREPNAME [NO STANDARD PAGE HEADING] [LINE-SIZE col] [LINE-COUNT n(m)] [MESSAGE-ID mid].[LINE-COUNT n(m)] [MESSAGE-ID mid].
NO STANDARD PAGE HEADING - Suppresses output of the standard page NO STANDARD PAGE HEADING - Suppresses output of the standard page header header •LINE-SIZE col - Creates a report with col columns per line.LINE-SIZE col - Creates a report with col columns per line.•LINE-COUNT n(m) -LINE-COUNT n(m) - Creates a report list with n lines per page, of which m Creates a report list with n lines per page, of which m lines are reserved for the END-OF-PAGE processing.lines are reserved for the END-OF-PAGE processing.
SUBMIT <rep> [AND RETURN] [<options>].SUBMIT <rep> [AND RETURN] [<options>].starts the report whose name is stored in field <rep>starts the report whose name is stored in field <rep>
India SAP CoE, Slide 31
Storing Data Objects in MemoryStoring Data Objects in Memory
•EXPORT <f1> [FROM <g1>] <f2> [FROM <g2>] ... TO MEMORY ID EXPORT <f1> [FROM <g1>] <f2> [FROM <g2>] ... TO MEMORY ID <key>.<key>.
•To write data objects from an ABAP/4 program to ABAP/4 memoryTo write data objects from an ABAP/4 program to ABAP/4 memory
•IMPORT <f1> [TO <g1>] <f2> [TO <g2>] ... FROM MEMORY ID <key>.IMPORT <f1> [TO <g1>] <f2> [TO <g2>] ... FROM MEMORY ID <key>.•To read data objects from ABAP/4 memory into an ABAP/4 programTo read data objects from ABAP/4 memory into an ABAP/4 program
•SET PARAMETER ID 'RID' FIELD <FIELD NAME1>.SET PARAMETER ID 'RID' FIELD <FIELD NAME1>.•The system stores the value in <field name1> in the SPA parameter 'RID'. The The system stores the value in <field name1> in the SPA parameter 'RID'. The field values saved globally in memory.field values saved globally in memory.
•GET PARAMTER ID 'RID' FIELD <FIELD NAME2>.GET PARAMTER ID 'RID' FIELD <FIELD NAME2>.•The system reads the contents of 'RID' and transfers them to <FIELD The system reads the contents of 'RID' and transfers them to <FIELD NAME2>. The field values saved globally in memory.NAME2>. The field values saved globally in memory.
India SAP CoE, Slide 32
Selection ScreenSelection ScreenParameters.Parameters. PARAMETERS <p> LIKE (<name>) PARAMETERS <p> LIKE (<name>)
• DEFAULT <f> DEFAULT <f> • OBLIGATORY OBLIGATORY • AS CHECKBOX AS CHECKBOX • RADIOBUTTON GROUP <radi>RADIOBUTTON GROUP <radi>
• Select-options.Select-options. SELECT-OPTIONS <seltab> FOR <f>. SELECT-OPTIONS <seltab> FOR <f>. • NO-EXTENSION NO-EXTENSION • NO INTERVALS NO INTERVALS • SIGNSIGN I stands for inclusive, E stands for exclusive.I stands for inclusive, E stands for exclusive.• OPTIONOPTION EQ, NE, GT, LE, LT,CP, BT, NB and NP EQ, NE, GT, LE, LT,CP, BT, NB and NP
– CHECK SELECT-OPTIONS.CHECK SELECT-OPTIONS.• check the contents of the actual database tablecheck the contents of the actual database table
India SAP CoE, Slide 33
Selection Screen Selection Screen Cont..Cont..
Formatting Selection Screen.Formatting Selection Screen.
• SELECTION-SCREEN SKIP [<n>].SELECTION-SCREEN SKIP [<n>].– To produce blank lines on the selection screenTo produce blank lines on the selection screen
• SELECTION-SCREEN ULINE [[/]<pos(len)>] [MODIF ID <key>].SELECTION-SCREEN ULINE [[/]<pos(len)>] [MODIF ID <key>].– To underline a line or part of a line on the selection screenTo underline a line or part of a line on the selection screen
• SELECTION-SCREEN COMMENT [/]<pos(len)> <name> [FOR FIELD <f>] SELECTION-SCREEN COMMENT [/]<pos(len)> <name> [FOR FIELD <f>] [MODIF ID <key>].[MODIF ID <key>].– To write text on the selection screenTo write text on the selection screen
• SELECTION-SCREEN BEGIN OF BLOCK <block> [WITH FRAME [TITLE SELECTION-SCREEN BEGIN OF BLOCK <block> [WITH FRAME [TITLE <title>]][NO INTERVALS].<title>]][NO INTERVALS].
......• SELECTION-SCREEN END OF BLOCK <block>.SELECTION-SCREEN END OF BLOCK <block>.
– To create a logical block of elements on the selection screenTo create a logical block of elements on the selection screen
India SAP CoE, Slide 34
Write StatementWrite Statement
/p(I)/ = Line Feedp = Column PositionI = Output Length
<format><format>
Output Value Fieldor Literal
<value><value>
/ Format Options
<options><options>
WRITE <format> <value> <options>.WRITE <format> <value> <options>.
India SAP CoE, Slide 35
Write - OptionsWrite - Options• LEFT-JUSTIFIEDLEFT-JUSTIFIED
– Output is left-justified.Output is left-justified.• CENTEREDCENTERED
– Output is centered.Output is centered.• RIGHT-JUSTIFIEDRIGHT-JUSTIFIED
– Output is right-justified.Output is right-justified.• UNDER <g>UNDER <g>
– Output starts directly under field <g>.Output starts directly under field <g>.• NO-GAPNO-GAP
– The blank after field <f> is omitted.The blank after field <f> is omitted.• NO-ZERONO-ZERO
– If a field contains only zeros, these are replaced by blanks. For type C and N If a field contains only zeros, these are replaced by blanks. For type C and N fields, leading zeros are replaced automatically.fields, leading zeros are replaced automatically.
• AS SYMBOLAS SYMBOL– Writes the output as a symbol Will have to INCLUDE <symbol>. Writes the output as a symbol Will have to INCLUDE <symbol>.
• RESERVE n LINES RESERVE n LINES – If there is not enough space left on the current page for at least n lines, this 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. statement starts a new page. n can be a constant (1,2,3,...) or a variable. • AS ICON.AS ICON.
– Writes the output as a icon Will have to INCLUDE <icon>.Writes the output as a icon Will have to INCLUDE <icon>.
India SAP CoE, Slide 36
Write – Options Write – Options Cont..Cont..
• WRITE AT [/][<pos>][(<len>)] <f>.WRITE AT [/][<pos>][(<len>)] <f>.– position the output of a WRITE statement on the list by making a format position the output of a WRITE statement on the list by making a format
specification specification • ULINE [AT [/][<pos>][(<len>)]].ULINE [AT [/][<pos>][(<len>)]].
– generate horizontal lines on the output screen generate horizontal lines on the output screen • WRITE [AT [/][<pos>][(<len>)]] SY-ULINE WRITE [AT [/][<pos>][(<len>)]] SY-ULINE
– generate horizontal lines on the output screen generate horizontal lines on the output screen • WRITE [AT [/][<pos>]] SY-VLINE WRITE [AT [/][<pos>]] SY-VLINE
– generate vertical lines on the output screen generate vertical lines on the output screen • SKIP [<n>].SKIP [<n>].
– generate blank lines on the screen generate blank lines on the screen • SKIP TO LINE <n>. SKIP TO LINE <n>.
– allows you to move the output position upwards or downwards allows you to move the output position upwards or downwards • WRITE <f> AS CHECKBOXWRITE <f> AS CHECKBOX
– output the first character of a field as a checkbox on the output screen.output the first character of a field as a checkbox on the output screen.
India SAP CoE, Slide 37
Write – Options Write – Options Cont..Cont..
• ABAP/4 output FormattingABAP/4 output Formatting..Format Color n. Format Color n. Format Color n Intensified On.Format Color n Intensified On.FORMAT COLOR OFF INTENSIFIED OFF INVERSE OFF FORMAT COLOR OFF INTENSIFIED OFF INVERSE OFF HOTSPOT OFF INPUT HOTSPOT OFF INPUT Off.Off.
India SAP CoE, Slide 38
Internal TablesInternal Tables
India SAP CoE, Slide 39
Internal Tables Internal Tables Cont..Cont..
• Standard tables.Standard tables.– The time for key access to entries is in linear relation to the number of The time for key access to entries is in linear relation to the number of
entries in the tableentries in the table
• Sorted tables are always sorted correctlySorted tables are always sorted correctly– The time for key access to entries is in logarithmic relation to the number The time for key access to entries is in logarithmic relation to the number
of entries in the tableof entries in the table
• Hashed tables contain records that all have a unique keyHashed tables contain records that all have a unique key– The time for key access to entries is constant regardless of the number The time for key access to entries is constant regardless of the number
of entries in the table of entries in the table
– Key access can only be used to read entries in a hashed tableKey access can only be used to read entries in a hashed table
– Index operations are not allowedIndex operations are not allowed
India SAP CoE, Slide 40
Internal Tables Internal Tables Cont..Cont..
Comparison of Standard, Sorted and HashedComparison of Standard, Sorted and Hashed table.table.
StandardStandard SortedSorted HashedHashed
Key AccessKey Access
Access Time Access Time For n EntriesFor n Entries
Access UsingAccess Using
Table ScanTable Scan Binary SrchBinary Srch Hash FunctionHash Function
Increases LinearlyIncreases Linearly(O(n))(O(n))
Increases LogarithmicallyIncreases Logarithmically(O(log(n))(O(log(n))
Remains ConstantRemains Constant(O(1))(O(1))
PredominantlyPredominantlyIndexIndex
PredominantlyPredominantlyKeyKey
Key OnlyKey Only
NON-UNIQUENON-UNIQUE UNIQUE| NON-UNIQUEUNIQUE| NON-UNIQUE UNIQUEUNIQUEUniquenessUniqueness
India SAP CoE, Slide 41
Internal Tables Internal Tables Cont..Cont..
Comparison of Standard, Sorted and HashedComparison of Standard, Sorted and Hashed table.table.
India SAP CoE, Slide 42
Internal Tables Internal Tables Cont..Cont..
Operations without header Operations without header lineline
INSERT <wa> INTO TABLE <itab>.INSERT <wa> INTO TABLE <itab>.
COLLECT <wa> INTO <itab>.COLLECT <wa> INTO <itab>.
READ TABLE <itab> ... INTO <wa>. READ TABLE <itab> ... INTO <wa>.
MODIFY TABLE <itab> FROM <wa>.MODIFY TABLE <itab> FROM <wa>.
MODIFY <itab> FROM <wa>WHEREMODIFY <itab> FROM <wa>WHERE
DELETE TABLE <itab> FROM <wa>.DELETE TABLE <itab> FROM <wa>.
Operations with header Operations with header lineline
INSERT TABLE ITAB INSERT TABLE ITAB
COLLECT <itab>.COLLECT <itab>.
READ TABLE <itab> READ TABLE <itab>
MODIFY TABLE <itab>MODIFY TABLE <itab>
MODIFY <itab> WHERE MODIFY <itab> WHERE
DELETE TABLE <itab>.DELETE TABLE <itab>.
India SAP CoE, Slide 43
Internal Tables Internal Tables Cont..Cont..
• Reading data from Internal Tables.Reading data from Internal Tables.• Loop and endloop.Loop and endloop.
• loop at it [into wa] [from m] [to n] [where exp]. --- loop at it [into wa] [from m] [to n] [where exp]. --- endloopendloop..
<level><level> MeaningMeaning
FIRSTFIRST First line of the internal tableFirst line of the internal table
LASTLAST Last line of the internal tableLast line of the internal table
NEW <f>NEW <f> Beginning of a group of lines with the same contents Beginning of a group of lines with the same contents in the field <f> and in the fields left of <f>in the field <f> and in the fields left of <f>
END Of <f>END Of <f> End of a group of lines with the same contents in the End of a group of lines with the same contents in the field <f> and in the fields left of <f>field <f> and in the fields left of <f>
ON CHANGE OF <f>ON CHANGE OF <f> Executes the processing block enclosed by the "ON Executes the processing block enclosed by the "ON CHANGE OF f" and "ENDON" statements whenever the CHANGE OF f" and "ENDON" statements whenever the contents of the field f change (control break contents of the field f change (control break processing). processing).
India SAP CoE, Slide 44
Internal Tables Internal Tables Cont..Cont..
• Reading data from Internal Tables using BINARY SEARCH.Reading data from Internal Tables using BINARY SEARCH.• Read table.Read table.
• READ TABLE <itab> <key> <result>. READ TABLE <itab> <key> <result>.
• READ TABLE itab WITH KEY k1 = v1 ... kn = vn READ TABLE itab WITH KEY k1 = v1 ... kn = vn [BINARY SEARCH] [BINARY SEARCH]
– It is mandatory for the internal table to be sorted in ascending order in It is mandatory for the internal table to be sorted in ascending order in the sequence of the specified key fields. the sequence of the specified key fields.
• READ TABLE itab INDEX i READ TABLE itab INDEX i
• SORT - Sorting an Internal Table SORT - Sorting an Internal Table – SORT itab [ASCENDING / DESCENDING] BY f1 f2 ... fn SORT itab [ASCENDING / DESCENDING] BY f1 f2 ... fn
India SAP CoE, Slide 45
ExtractsExtracts• Extracts Extracts
– Defining an Extracts.Defining an Extracts.• FIELD-GROUPS <fg>. FIELD-GROUPS <fg>.
– Filling an Extract with Data.Filling an Extract with Data.• INSERT <f1>... <f n> INTO <fg>. INSERT <f1>... <f n> INTO <fg>.
– Reading an ExtractReading an Extract• LOOP.LOOP.
[AT FIRST | AT <fgi> [WITH <fg j>] | AT LAST. [AT FIRST | AT <fgi> [WITH <fg j>] | AT LAST. ENDAT.] ENDAT.]ENDLOOP.ENDLOOP.
– Sorting an Extract Sorting an Extract • SORT [ASCENDING|DESCENDING] SORT [ASCENDING|DESCENDING]
India SAP CoE, Slide 46
IF ConditionIF Condition• Logical ExpressionLogical Expression
– If < Cond>.If < Cond>.• {statements}{statements}
– Elseif.Elseif.• {statements}{statements}
– Endif.Endif.
India SAP CoE, Slide 47
Case StatementCase Statement
India SAP CoE, Slide 48
DO and While LoopsDO and While Loops
India SAP CoE, Slide 49
CHECK and EXITCHECK and EXIT
SAP recommends that you only SAP recommends that you only use CHECK within loops. use CHECK within loops.
India SAP CoE, Slide 50
Interactive ReportingInteractive Reporting
The following are the different events associated with Interactive The following are the different events associated with Interactive ReportingReporting
Event KeywordEvent Keyword EventEvent
At Line-SelectionAt Line-Selection Event is triggered by either the user double Event is triggered by either the user double clicking a particular line or using F2 to select itclicking a particular line or using F2 to select it
At User-CommandAt User-Command Event triggered by user pressing a function keyEvent triggered by user pressing a function key
At PFnAt PFn
Where n is between 0 to 99Where n is between 0 to 99
Event triggered on press of a function key.Event triggered on press of a function key.
Top-of-Page during Line Top-of-Page during Line SelectionSelection
Event called during list processing when a detailed Event called during list processing when a detailed list is calledlist is called
India SAP CoE, Slide 51
Interactive Reporting Interactive Reporting Cont..Cont..
•READ - Reading a Line from a List READ - Reading a Line from a List Reads line number line of the list, usually after a line selection Reads line number line of the list, usually after a line selection READ LINE line.READ LINE line.READ LINE line OF CURRENT PAGE.READ LINE line OF CURRENT PAGE.READ LINE line OF PAGE pag READ LINE line OF PAGE pag READ CURRENT LINEREAD CURRENT LINE
•MODIFY LINE n.MODIFY LINE n.Change a List Line Change a List Line INDEX idx - Changes the corresponding line in the list at list INDEX idx - Changes the corresponding line in the list at list level idx level idx
FIELD VALUE f1 FROM g1 ... fn FROM gnFIELD VALUE f1 FROM g1 ... fn FROM gn
WINDOW STARTING AT x1 y1 ENDING AT x2 y2.WINDOW STARTING AT x1 y1 ENDING AT x2 y2.Displays the current secondary list as a modal dialog box only up to 20 Displays the current secondary list as a modal dialog box only up to 20 windowswindows
India SAP CoE, Slide 52
Interactive Reporting Interactive Reporting Cont..Cont..
HotspotHotspotIf one drags the mouse over the data displayed in the report using the FORMAT 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 fingerstatement then the cursor changes to a Hand with an Outstretched Index finger Syntax: Format Hotspot On (Off).Syntax: Format Hotspot On (Off).
HideHideThis command helps you to store the field names based on which one will be doing 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 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 statement for a field. When a row is selected the values get automatically filled in the variables for further use.the variables for further use. Syntax: Hide <field-name>.Syntax: Hide <field-name>.
Get Cursor CommandGet Cursor CommandLike Hide this is also used for getting the values after selection of a row.Like Hide this is also used for getting the values after selection of a row. Syntax: Get Cursor field cur_name value cur_value.Syntax: Get Cursor field cur_name value cur_value. cur_name and cur_value are variables.cur_name and cur_value are variables.CALL TRANSACTION '<TRAN>' AND SKIP FIRST SCREEN.CALL TRANSACTION '<TRAN>' AND SKIP FIRST SCREEN.
Call a SAP transaction from ABAP Code.Call a SAP transaction from ABAP Code.
India SAP CoE, Slide 53
Logical databasesLogical databases
It is another way of retrieving data for a program.It is another way of retrieving data for a program. Logical databases are created by transaction SE36Logical databases are created by transaction SE36 The data is selected by another program and one can access the data using 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 GET <table-name> command which places the data in the work area <table-name>.<table-name>. Advantages of a logical database over normal Select queries.Advantages of a logical database over normal Select queries.
It offers check conditions to see whether the input is correct, complete and It offers check conditions to see whether the input is correct, complete and plausibleplausible It contains central authorization checks for database accessIt contains central authorization checks for database access Enhancements such as improvement in performance immediately apply to all Enhancements such as improvement in performance immediately apply to all reports which use logical database.reports which use logical database.
Note: Logical database is not used in most of the casesNote: Logical database is not used in most of the cases ..
India SAP CoE, Slide 54
A Few More PointsA Few More Points
VariantsVariantsVariants are input data which are filled in the selection screen and then saved so 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 that at runtime the variant can be selected and then the entire selection screen is filled with the desired values.filled with the desired values.
Background ProcessingBackground ProcessingWhen a program takes a long time to execute then one can execute the program 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.in background so that a job is set up for that program.The job can be seen in transaction SM37.The job can be seen in transaction SM37.The job log gives the exact start time and the end time for the job.The job log gives the exact start time and the end time for the job.
CATCH - Catching Runtime Errors CATCH - Catching Runtime Errors CATCH SYSTEM-EXCEPTIONS except1 = rc1 ... exceptn = rcn. CATCH SYSTEM-EXCEPTIONS except1 = rc1 ... exceptn = rcn. ENDCATCH. ENDCATCH.
The CATCH…ENDCATCH block allows the programmer to catch ABAP The CATCH…ENDCATCH block allows the programmer to catch ABAP runtime errors and assign these to a SY_SUBRC valueruntime errors and assign these to a SY_SUBRC value
Comments.Comments.Commented lines in the program start with asterisk (*)Commented lines in the program start with asterisk (*)To comment a part of line use double codes (“).To comment a part of line use double codes (“).
India SAP CoE, Slide 55
ModularizationModularization
•Subroutines Subroutines •Subroutines are procedures that you can define in any ABAP Subroutines are procedures that you can define in any ABAP program and also call from any program. program and also call from any program.
•Function modules Function modules •Function modules are procedures that are defined in function Function modules are procedures that are defined in function groups and can be called from any ABAP program. groups and can be called from any ABAP program.
•IncludeInclude•If you want to use the same sequence of statements in several If you want to use the same sequence of statements in several programs, you can code them once in an include program. programs, you can code them once in an include program.
India SAP CoE, Slide 56
SubroutinesSubroutines
•Defining Subroutines Defining Subroutines FORM <subr> [USING ... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ] FORM <subr> [USING ... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ] [CHANGING... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ]. [CHANGING... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ]. ......ENDFORM.ENDFORM.
•The Parameter InterfaceThe Parameter Interface• Parameters Passed by ReferenceParameters Passed by Reference
list these parameters after USING without the VALUE addition list these parameters after USING without the VALUE addition •Parameters Passed by ValueParameters Passed by Value
list these parameters after USING with the VALUE addition list these parameters after USING with the VALUE addition •Passing by Value and ResultPassing by Value and Result
If you want to return a changed output If you want to return a changed output parameter from a subroutine to the calling program only after the parameter from a subroutine to the calling program only after the subroutine has run successfully, use CHANGING for the <pass> subroutine has run successfully, use CHANGING for the <pass> option of the FORM and PERFORMoption of the FORM and PERFORM
India SAP CoE, Slide 57
Subroutines Subroutines Cont..Cont..
Calling SubroutinesCalling SubroutinesPERFORM... [USING ... <pi>... ] PERFORM... [USING ... <pi>... ] [CHANGING... <pi>... ]. [CHANGING... <pi>... ].
•Static VariableStatic VariableIf you want to keep the value of a local data object after exiting the subroutine, you 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 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 STATICS you declare a data object that is globally defined, but only locally visible from the subroutine in which it is defined. from the subroutine in which it is defined.
STATICS f_text TYPE f_word VALUE 'INIT'.STATICS f_text TYPE f_word VALUE 'INIT'.
India SAP CoE, Slide 58
Function modulesFunction modules
•Calling Function ModulesCalling Function Modules•CALL FUNCTION <module>CALL FUNCTION <module> [EXPORTING f1 = a 1.... f n = a n] [EXPORTING f1 = a 1.... f n = a n] [IMPORTING f1 = a 1.... f n = a n] [IMPORTING f1 = a 1.... f n = a n] [CHANGING f1 = a 1.... f n = a n] [CHANGING f1 = a 1.... f n = a n] [TABLES 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] [EXCEPTIONS e1 = r 1....en = rn [ERROR_MESSAGE = r E] [OTHERS = ro]]. [OTHERS = ro]].
•Creating Function Modules (SE37)Creating Function Modules (SE37)•AttributesAttributes•Parameter Interface Parameter Interface •TablesTables•Exceptions Exceptions •Source Code Source Code
India SAP CoE, Slide 59
Function modules Function modules Cont..Cont..
India SAP CoE, Slide 60
Function modules Function modules Cont..Cont..
Calling A Function modules - PatternCalling A Function modules - Pattern
India SAP CoE, Slide 61
Function modules Function modules Cont..Cont..
Testing A Function modules – SE37Testing A Function modules – SE37
India SAP CoE, Slide 62
IncludeInclude
Creating Include.Creating Include.
Use Transaction SE38 to create a include program.Use Transaction SE38 to create a include program.
Using Include.Using Include.
Include <incl>Include <incl>
This inserts the source code <incl> into the ABAP/4 program during the syntax check 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 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 were to copy the source code of <incl> to the position of the statement in the calling program.program.
India SAP CoE, Slide 63
Working With FilesWorking With Files
•Presentation Server.Presentation Server.
•Application Server.Application Server.
India SAP CoE, Slide 64
Files – Presentation ServerFiles – Presentation Server
To Upload data from the Presentation Server use the Function ModuleTo Upload data from the Presentation Server use the Function Module
GUI_UPLOAD GUI_UPLOAD
To Download data to the Presentation Server use the Function ModuleTo Download data to the Presentation Server use the Function Module
GUI_DOWNLOAD GUI_DOWNLOAD
India SAP CoE, Slide 65
Files – Application ServerFiles – Application Server•OPEN DATASET <dsn> [options]OPEN DATASET <dsn> [options]
•This statement opens file <dsn>.This statement opens file <dsn>.•FOR INPUT FOR INPUT open a file for reading open a file for reading •FOR OUTPUT FOR OUTPUT open a file for writing.open a file for writing.•FOR APPENDINGFOR APPENDING open a file for Appending. open a file for Appending.
•CLOSE DATASET <dsn>CLOSE DATASET <dsn>•Closes a file on application sever.Closes a file on application sever.
•TRANSFER <f> to <dsn> [LENGTH <len>].TRANSFER <f> to <dsn> [LENGTH <len>].•write data to a file on the application server.write data to a file on the application server.
•READ DATASET <dsn> INTO <f> [LENGTH <len>].READ DATASET <dsn> INTO <f> [LENGTH <len>].•read data from a file on the application server.read data from a file on the application server.
•DELETE DATASET <dsn>.DELETE DATASET <dsn>.•delete a file on the application serverdelete a file on the application server
India SAP CoE, Slide 66
System Variables - SYSTSystem Variables - SYST
• SY-CPAGESY-CPAGE Current page numberCurrent page number• SY-CUCOLSY-CUCOL Horizontal cursor position Horizontal cursor position • SY-CUROWSY-CUROW Vertical cursor position Vertical cursor position • SY-DATUMSY-DATUM Current (application server) dateCurrent (application server) date• SY-LANGUSY-LANGU Current languageCurrent language• SY-LISELSY-LISEL Content of selected rowContent of selected row• SY-INDEXSY-INDEX Current loop passCurrent loop pass• SY-LSINDSY-LSIND Index of detail listIndex of detail list• SY-MANDTSY-MANDT Client number from logonClient number from logon• SY-REPIDSY-REPID Current main programCurrent main program• SY-SUBRCSY-SUBRC Return value after ABAP statementReturn value after ABAP statement• SY-LILLISY-LILLI Absolute number of the line which triggered the eventAbsolute number of the line which triggered the event• SY-BATCHSY-BATCH Program runs in the backgroundProgram runs in the background
India SAP CoE, Slide 67
ABAP reports – Classical and interactiveABAP reports – Classical and interactive
1 Introduction
2 Syntax Description
3 Demonstration
4 Exercises
5 HelpMe
India SAP CoE, Slide 68
Simple ReportsSimple ReportsSimple ReportsSimple Reports
REPORT TEST.REPORT TEST.Initialization.Initialization.Data : Data : a a typetype I value 10, I value 10,
b b type type I value 15,I value 15,sumsum type type I.I.
start-of-selection.start-of-selection.WRITE 'This is a statement‘WRITE 'This is a statement‘*This is commented line*This is commented line*The write statement can also be written as.*The write statement can also be written as.end-of-selection.end-of-selection.WRITE 'This' & WRITE 'This' & ' is ' & ' is ' & 'a statement'. 'a statement'.
Sum = a + b.Sum = a + b.Write:/ sum.Write:/ sum.
India SAP CoE, Slide 69
Data DeclarationData Declarationdata: begin of it1 occurs 10, data: begin of it1 occurs 10, "has a header line "has a header line Name(10), Name(10), Phno type i, Phno type i, end of it1.end of it1.
data it2 like it1 occurs 100. data it2 like it1 occurs 100. "doesn't have a header line "doesn't have a header line data it3 like it1 occurs 100 with header line. "it does nowdata it3 like it1 occurs 100 with header line. "it does now
Name PhnoHeaderHeader
Internal Internal Table BodyTable Body
India SAP CoE, Slide 70
Data Declaration Data Declaration Cont..Cont..
DATA:DATA: PLAYER(35)PLAYER(35) TYPE C,TYPE C,NICKNAME(35),NICKNAME(35),POINTSPOINTS TYPE I.TYPE I.
DATA:DATA: GAMESGAMES TYPE ITYPE I VALUE ‘10’,VALUE ‘10’,AVERAGE(5)AVERAGE(5) TYPE P,TYPE P,STARTER,STARTER,ACQUIREDACQUIRED TYPE D.TYPE D.
DATA:DATA: PLAYER(35)PLAYER(35) TYPE CTYPE C VALUE ‘CapGemini’,VALUE ‘CapGemini’,NICKNAMENICKNAME LIKE PLAYER,LIKE PLAYER,ACQUIREDACQUIRED LIKE SY-DATUM.LIKE SY-DATUM.
Data Declaration Data Declaration
India SAP CoE, Slide 71
Data Declaration Data Declaration Cont..Cont..
CONSTANTS:TEAM1(20)CONSTANTS:TEAM1(20) TYPE CTYPE C VALUE ‘76ers’,VALUE ‘76ers’, TEAM2TEAM2 LIKE LIKE TEAM1 TEAM1 VALUE ‘Celtics’,VALUE ‘Celtics’,
TOT_GAMESTOT_GAMES TYPE TYPE II VALUE 82.VALUE 82.TYPE-POOLS Z400.TYPE-POOLS Z400.TYPES:TYPES: NAME(35) NAME(35) TYPE C,TYPE C,
TEAMS(20)TEAMS(20) TYPE C.TYPE C.
DATA:DATA: PLAYERPLAYER TYPE NAMETYPE NAME VALUE ‘CapGemini’,VALUE ‘CapGemini’,NICKNAMENICKNAME LIKE PLAYER.LIKE PLAYER.
CONSTANTS:CONSTANTS: TEAM1TEAM1 TYPE TEAMSTYPE TEAMS VALUE ‘76ers’,VALUE ‘76ers’,TEAM2TEAM2 LIKE TEAM1 LIKE TEAM1 VALUE ‘Celtics’.VALUE ‘Celtics’.
The “CLEAR” statement sets a field back to its initial value, not its The “CLEAR” statement sets a field back to its initial value, not its default value.default value.
Data Declaration Data Declaration
India SAP CoE, Slide 72
Data Declaration Data Declaration Cont..Cont..
Value AssignmentValue Assignment
DATA:DATA: TITLE(25),TITLE(25),SORT_NAME(10),SORT_NAME(10),SALARY(10) TYPE N,SALARY(10) TYPE N,CNVSALARY(10) TYPE N,CNVSALARY(10) TYPE N,GRID_LEVEL TYPE I.GRID_LEVEL TYPE I.
MOVE ‘President’ TO TITLE.MOVE ‘President’ TO TITLE.MOVE 5 TO GRID_LEVEL.MOVE 5 TO GRID_LEVEL.COMPUTE SALARY = 5000000.COMPUTE SALARY = 5000000.CNVSALARY = SALARY * 3.CNVSALARY = SALARY * 3.ADD 1000 TO SALARY.ADD 1000 TO SALARY.
Data Declaration Data Declaration
India SAP CoE, Slide 73
Data Declaration Data Declaration Cont..Cont..
Calculating Values.Calculating Values.
DATA:DATA: COUNTER COUNTER TYPE TYPE I,I,AMOUNT AMOUNT TYPE TYPE P P VALUE 1000,VALUE 1000,SUM SUM TYPE TYPE P,P,RESULT RESULT TYPE TYPE P,P,NUMBER(2) NUMBER(2) TYPE TYPE C C VALUE ’99’,VALUE ’99’,ROOT ROOT TYPE TYPE F.F.
COUNTER = COUNTER + 2.COUNTER = COUNTER + 2.RESULT = AMOUNT * COUNTER.RESULT = AMOUNT * COUNTER.SUM = RESULT + NUMBER – COUNTER.SUM = RESULT + NUMBER – COUNTER.RESULT = COUNTER * ( AMOUNT + NUMBER ).RESULT = COUNTER * ( AMOUNT + NUMBER ).BREAK-POINT.BREAK-POINT. “Creates a breakpoints.“Creates a breakpoints.ROOT = SQRT ( NUMBER + COUNTER ).ROOT = SQRT ( NUMBER + COUNTER ).
India SAP CoE, Slide 74
Select StatementSelect Statement
Select Statement.Select Statement.
Select * from bfpf Select * from bfpf into itab into itab where where bukrs = ‘0001’bukrs = ‘0001’ andand
belnr eq ’00200689’ belnr eq ’00200689’ andandgjahr gt ‘2005’.gjahr gt ‘2005’.
Append itab. Clear itab.Append itab. Clear itab.EndselectEndselect
Select * from bfpf Select * from bfpf into into table table itab itab where where bukrs = ‘0001’bukrs = ‘0001’ andand
belnr eq ’00200689’ belnr eq ’00200689’ andandgjahr gt ‘2005’.gjahr gt ‘2005’.
India SAP CoE, Slide 75
Select Statement Select Statement Cont..Cont..
Select Statement - Join.Select Statement - Join.
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, custidENDSELECT.
India SAP CoE, Slide 76
Select Statement Select Statement Cont..Cont..
Select Statement – FOR ALL ENTRIES.Select Statement – FOR ALL ENTRIES.
Select * from BKPF into table it_bkpf where <conditions>.
If it_bkpf[] is not initial.
Select * from bseg into table it_bseg FOR ALL ENTRIES IN IT_BKPFWHERE BELNR = it_bkpf-belnr and
BUKRS = it_bkpf-bukrs andGJAHR = it_bkpf-gjahr andBUZEI = it_bkpf-buzei.
Endif.
India SAP CoE, Slide 77
Field SymbolsField Symbols
Field SymbolsField Symbols
REPORT demo_field_symbols_type .REPORT demo_field_symbols_type .
DATA: BEGIN OF line,DATA: BEGIN OF line, col1(1) TYPE c, col1(1) TYPE c, col2(1) TYPE c VALUE 'X', col2(1) TYPE c VALUE 'X', END OF line. END OF line.
FIELD-SYMBOLS <fs> LIKE line.FIELD-SYMBOLS <fs> LIKE line.
ASSIGN line TO <fs>.ASSIGN line TO <fs>.
MOVE <fs>-col2 TO <fs>-col1.MOVE <fs>-col2 TO <fs>-col1.
WRITE:/ <fs>-col1WRITE:/ <fs>-col1
India SAP CoE, Slide 78
Internal TableInternal TableInternal 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 79
Internal Table Internal Table Cont..Cont..
Internal Tables - ReadingInternal Tables - Reading
TYPES: BEGIN OF line_type,TYPES: BEGIN OF line_type, f1, f2, f3,f1, f2, f3, END OF line_type.END OF line_type.
DATA: tab1 TYPE STANDARD TABLE OF line_type WITH KEY f1 f2,DATA: tab1 TYPE STANDARD TABLE OF line_type WITH KEY f1 f2, wa type line_type.wa type line_type.
wa-f1 = 'B'.wa-f1 = 'B'.wa-f2 = '5'.wa-f2 = '5'.wa-f3 = '12.45'.wa-f3 = '12.45'.
READ TABLE tab1 FROM wa INTO wa.READ TABLE tab1 FROM wa INTO wa.READ TABLE tab1 WITH TABLE KEY f1 = 'B'READ TABLE tab1 WITH TABLE KEY f1 = 'B'
f2 = '5' INTO wa.f2 = '5' INTO wa.
Wa before Wa after read
Work area wa
Internal Table tab1
India SAP CoE, Slide 80
SubroutinesSubroutinesTYPES: BEGIN OF LINE,TYPES: BEGIN OF LINE, COL1, COL1, COL2, COL2, END OF LINE. END OF LINE.
DATA: WA TYPE LINE,DATA: WA TYPE LINE, ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1, ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1, KEY(4) VALUE 'COL1'. KEY(4) VALUE 'COL1'.WA-COL1 = 'X'. INSERT WA INTO TABLE ITAB.WA-COL1 = 'X'. INSERT WA INTO TABLE ITAB.WA-COL1 = 'Y'. INSERT WA INTO TABLE ITAB.WA-COL1 = 'Y'. INSERT WA INTO TABLE ITAB.
PERFORM DEMO USING ITAB.PERFORM DEMO USING ITAB.
FORM DEMO USING P TYPE ANY TABLE.FORM DEMO USING P TYPE ANY TABLE.DATA: T_WA TYPE LINE.DATA: T_WA TYPE LINE. “LOCAL VARIABLE FOR SUBROUTINE. “LOCAL VARIABLE FOR SUBROUTINE. READ TABLE P WITH TABLE KEY (KEY) = 'X' INTO WA. READ TABLE P WITH TABLE KEY (KEY) = 'X' INTO WA.WRITE:/ T_WA-COL1.WRITE:/ T_WA-COL1.ENDFORM.ENDFORM.
India SAP CoE, Slide 81
Subroutines Subroutines Cont..Cont..Data: begin of itab occurs,Data: begin of itab occurs,
matnr like mara-matnr,matnr like mara-matnr,mtart like mara-mtart,mtart like mara-mtart,meins like mara-meins,meins like mara-meins,
End of itab.End of itab.
Perform get_data.Perform get_data.Perform download_data.Perform download_data.
Form get_data.Form get_data.Select matnr mtart meins into table itab from mara up to 50 rows.Select matnr mtart meins into table itab from mara up to 50 rows.Endform.Endform.
Form download_data.Form download_data.CALL FUNCTION 'GUI_DOWNLOAD'CALL FUNCTION 'GUI_DOWNLOAD' EXPORTINGEXPORTING FILENAME = 'c:\mara.txt'FILENAME = 'c:\mara.txt' FILETYPE = 'ASC'FILETYPE = 'ASC' TABLESTABLES DATA_TAB = itab.DATA_TAB = itab.Endform.Endform.
India SAP CoE, Slide 82
Catch - EndcatchCatch - Endcatch• To code the first part of a CATCH…ENDCATCH block it is necessary to code CATCH SYSTEM - To code the first part of a CATCH…ENDCATCH block it is necessary to code CATCH SYSTEM -
EXCEPTIONS and specify one of the following:EXCEPTIONS and specify one of the following:– Error Class Error Class – Specific error IDSpecific error ID– OTHERS, which traps all catchable runtime errorsOTHERS, which traps all catchable runtime errors
DATA: DATA: int type I, int type I,
char(3) type C value ‘ABC’.char(3) type C value ‘ABC’.
[…..][…..]
CATCH SYSTEM-EXCEPTIONS CATCH SYSTEM-EXCEPTIONS
CONVERSION_ERRORS = 1.CONVERSION_ERRORS = 1.
[…..][…..]
MOVE char TO int.MOVE char TO int. “MOVE keyword to trigger CATCH“MOVE keyword to trigger CATCH
[…..][…..]
ENDCATCH.ENDCATCH.
IF SY-SUBRC = 1.IF SY-SUBRC = 1.
WRITE: / ‘Conversion error has occurred’.WRITE: / ‘Conversion error has occurred’.
ENDIF.ENDIF.
India SAP CoE, Slide 83
DebuggerDebuggerExecute
Single Step
Run Completely
Variables
Break Points
India SAP CoE, Slide 84
Debugger Debugger Cont..Cont..
FieldsFieldsThe scrollable field display contains the contents of up to eight fields. The contents of the 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 three most important system fields are always displayed. This is the default display mode in the Debugger. See also Processing Fieldsthe Debugger. See also Processing Fields
TableTable Displays the contents of an internal table. This mode allows you to display and edit the Displays the contents of an internal table. This mode allows you to display and edit the entries in an internal table. entries in an internal table. See also Processing Internal TablesSee also Processing Internal Tables
BreakpointsBreakpoints A scrollable display containing up to 30 breakpoints. Next to each breakpoint is a counter. 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 BreakpointsYou can also delete breakpoints in this display. See also Managing Dynamic Breakpoints
WatchpointsWatchpoints You can set a watchpoint for a field so that the program is interrupted whenever the value 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 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 programs to which they are assigned, the current values of the fields, and the conditions upon which the watchpoint is activated. See also Setting Watchpointsupon which the watchpoint is activated. See also Setting Watchpoints
CallsCalls This mode displays the current sequence of events, and the sequence of calls up to the 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 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-listed in reverse chronological order. When an event (for example, START-OF-SELECTION) concludes, it is deleted from the display.SELECTION) concludes, it is deleted from the display.
OverviewOverview This mode displays the structure of the program. It lists its events, subroutines, and This mode displays the structure of the program. It lists its events, subroutines, and modules, and shows which sections belong to which events. modules, and shows which sections belong to which events. It also displays the section It also displays the section currently being processed.currently being processed.
SettingsSettings This mode displays the current Debugger settings. You can change the settings by This mode displays the current Debugger settings. You can change the settings by selecting or deselecting various options. selecting or deselecting various options. For further information, refer to Settings and For further information, refer to Settings and WarningsWarnings
India SAP CoE, Slide 85
Releasing RequestReleasing RequestReleasing Your Transport Request – SE09Releasing Your Transport Request – SE09
Enter Your Login ID and view the Modifiable RequestsEnter Your Login ID and view the Modifiable Requests
Select Your Request and click on Release Directly.Select Your Request and click on Release Directly.
India SAP CoE, Slide 86
ABAP reports – Classical and interactiveABAP reports – Classical and interactive
1 Introduction
2 Syntax Description
3 Demonstration
4 Exercises
5 HelpMe
India SAP CoE, Slide 87
Exercises - 1Exercises - 1•Read a set of results from table EKPO.Read a set of results from table EKPO.•Create a selection screen with an input field for Create a selection screen with an input field for EKPO-EBELN (Document Number).EKPO-EBELN (Document Number).•Define a structure as a work area by referring to your table EKPO.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 Program a SELECT loop that reads the data specified by the user and places it in your work area.in your work area.•Using the WRITE statement within the SELECT loop, display the following Using the WRITE statement within the SELECT loop, display the following fields:fields:
EBELPEBELP Item Number of Purchasing DocumentItem Number of Purchasing Document
MATNRMATNR Material NumberMaterial Number
LGORTLGORT Storage LocationStorage Location
MATKLMATKL Material GroupMaterial Group
MENGEMENGE Purchase order quantityPurchase order quantity
MEINSMEINS Order UnitOrder Unit
NETPRNETPR Net priceNet price•To generate a line feed, precede the data object you want to display with the ‘/’ To generate a line feed, precede the data object you want to display with the ‘/’ character.Example:WRITE : / wa_EKPO-EBELP, …character.Example:WRITE : / wa_EKPO-EBELP, …
India SAP CoE, Slide 88
Exercises - 2Exercises - 2• Create a list of all FI Documents between the dates entered by the user.Create a list of all FI Documents between the dates entered by the user.• Create a selection screen with an input field for Create a selection screen with an input field for BKPF-BKPF-
BUDAT (Document Date).BUDAT (Document Date).• Select BELNR (Document Number), BUKRS (Company Code) and GJAHR (Fiscal Select BELNR (Document Number), BUKRS (Company Code) and GJAHR (Fiscal
Year) from the table BKPF and correspondingly select BUZEI (Line item number), Year) from the table BKPF and correspondingly select BUZEI (Line item number), DMBTR (Amount). DMBTR (Amount).
• Within the loop, avail the vendor / customer a discount of 10% on DMBTR using the 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. corresponding field of the work area. Append your work area to the internal table.
• Sort the internal table according to the net price.Sort the internal table according to the net price.• Display the following fields:Display the following fields:
BELNRBELNR Document NumberDocument Number
BUKRSBUKRS Company CodeCompany Code
GJAHRGJAHR Fiscal YearFiscal Year
BUDATBUDAT Document DateDocument Date
BUZEIBUZEI Document Item NumberDocument Item Number
DMBTRDMBTR AmountAmount
India SAP CoE, Slide 89
Exercises - 3Exercises - 3• Create a tabulated list of Vendors entered by the user.Create a tabulated list of Vendors entered by the user.• Create a selection screen with an input field for Create a selection screen with an input field for
LFA1-LIFNR (Vendor).LFA1-LIFNR (Vendor).• Select Vendors from the table LIFNR from the selection-screen. Select Vendors from the table LIFNR from the selection-screen. • Display the list of vendors selected on the basic list. Display the list of vendors selected on the basic list. • If the User chooses a particular Vendor Display this contact details with a If the User chooses a particular Vendor Display this contact details with a
HOTSPOT on his Name on a detailed list.HOTSPOT on his Name on a detailed list.• If the user click in this hotspot call the transaction FBL2N (Vendor Balance) If the user click in this hotspot call the transaction FBL2N (Vendor Balance)
with the current fiscal year and skip the initial screen.with the current fiscal year and skip the initial screen.
India SAP CoE, Slide 90
ABAP reports – Classical and interactiveABAP reports – Classical and interactive
1 Introduction
2 Syntax Description
3 Demonstration
4 Exercises
5 HelpMe
India SAP CoE, Slide 91
HelpMeHelpMe
• Tips and TricksTips and Tricks
• Additional InfoAdditional Info
India SAP CoE, Slide 92
Tips and TricksTips and Tricks
•Keep the Result Set Small Keep the Result Set Small
•Minimize the Amount of Data Transferred Minimize the Amount of Data Transferred
•Minimize the Number of Data TransfersMinimize the Number of Data Transfers
•Minimize the Search Overhead Minimize the Search Overhead
•Reduce the Database Load Reduce the Database Load
•Use T-Code “SE30” to view run time analysis of your programUse T-Code “SE30” to view run time analysis of your program
•For Example Code on each topic use T-Code “ABAPDOCU”.For Example Code on each topic use T-Code “ABAPDOCU”.
•Use Pretty Printer for code alignment.Use Pretty Printer for code alignment.
•For SQL Trace Use T-Code “ST05”.For SQL Trace Use T-Code “ST05”.
India SAP CoE, Slide 93
Additional InfoAdditional Info
Use the below link for complete details on ABAP.Use the below link for complete details on ABAP.
http://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511dhttp://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm1829f0000e829fbfe/frameset.htm