Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
This is an ABAP/4 training document that has been prepared for handling ABAP/4 Training sessions at the FASIT [Finance Project] Project of Intel, Portland. This training document is useful for handling client fast break ABAP/4 training sessions that will span approximately a week. This can also be used as a quick overview of ABAP/4. This document covers most ABAP/4 topics except dialog programming. The topics covered include: Data Handling, Outputting data, Internal tables, Flow control, modularizing, data dictionary, files, reporting - interactive and non-interactive, Menu painter, BDC and User exits. Author: Venkata Anumukonda
Page 1 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Venkata Anumukonda
PricewaterhouseCoopers
Page 2 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
INDEX
Page
1) 2) 3) 4) 5) 6) 7) 8) 9) 10) 11) 12) 13) 14) 15) 16) 17) 18) 19) 20) 21)
Introduction Topics Characteristics of ABAP/4 Structure of ABAP/4 Program Data Handling Determining attributes of data objects Outputting Data Text Elements Assigning Values Basic Arithmetic Operations Processing Character Strings Flow Control Special Programming Techniques Internal tables Modularizing ABAP/4 Programs Processing Database Tables Working with Files ABAP/4 Data Dictionary Reporting Interactive & Non-interactive Menu Painter BDC User Exits
4 4 5 5 5 7 8 10 10 11 11 12 13 17 19 23 27 31 44 46 55
Page 3 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
INTRODUCTION
1) 2) 3) 4) 5)
ABAP/4 - Advanced Business Application Programming Language Only Tool for Developing SAP Applications Developed by SAP Increasing Requirements of Business Applications 4GL - Contains all Usual Control Structures and modularizing concepts for structured programming
Topics
1) 2) 3) 4) 5) 6) 7)
Basics Data Dictionary Reporting Performance Tuning User Exits BDC Dialog Programming
Page 4 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Characteristics of ABAP/4
1) 2) 3) 4) 5)
Data Handling - Data Types, Text elements, Processing Character strings Flow Control - IF, CASE, DO, WHILE... Special programming Techniques - Internal Tables Modularizing ABAP/4 - Include programs, Subroutines, Function Modules Working with Files
1) 2) 3)
DATA HANDLING
Data Types Predefined
Elementary C, D, F, I, N, P, T, X: ABAP/4 contains 8 predefined elementary data types. TABLE: This predefined structured data type is used only for the typing of formal parameters and field symbols.
User-defined
User-defined elementary data types are based on the predefined elementary data types. Field strings and internal tables: These structured data types can be used for data objects and are user-defined Structured Data Types
Structured
Page 5 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
INITIAL SIZE
1 8 8 4 1 8 6 1
VALID SIZE
1 65535 8 8 4 1 65535 1 16 6 1 65535
INITIAL VALUE
SPACE '00000000 0 0 '00...0' 0 '000000' X'00'
DESCRIPTION
Text, character Date(format:YYYYMMDD) Floating point number Integer(whole number) Numeric text Packed number Time(format: HHMMSS) Hexadecimal
1) 2)
Elementary Data Types - User-Defined Based on Predefined elementary data types Use TYPES statement
Example
1) 2)
Field strings - collection of other data types. Internal tables - consists of several lines of the same type.
DATA <f> [(length>)] <type> [<value>] [<decimals>] Examples DATA: COUNTER TYPE P VALUE 1, DATE TYPE D VALUE '19920601', FLAG TYPE C VALUE IS INITIAL. DATA WEIGHT TYPE P DECIMALS 2 VALUE '1.225'.
Page 6 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
A field string is a group of internal fields in a program. Syntax: DATA: BEGIN OF <fstring>, <component declaration>, .............. END OF <fstring>. Example : DATA: BEGIN OF ADDRESS, NAME(20) TYPE C, STREET(20) TYPE C, NUMBER TYPE P, POSTCODE(5) TYPE N, CITY(20) TYPE C, END OF ADDRESS.
CONSTANTS Statement
Syntax
CONSTANTS <c>[<length>] <type> <value> [<decimals>]. CONSTANTS: BEGIN OF <fstring>, <component declaration>, .............. END OF <fstring>. Examples: CONSTANTS: MYNAME(10) VALUE 'Fred', BIRTHDAY TYPE D VALUE '19600110', ZERO TYPE I VALUE IS INITIAL.
TABLES Statement
Page 7 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
The WRITE Statement Positioning WRITE Output on the Screen Formatting Options Outputting Symbols and Icons on the Screen Lines and Blank Lines on the Output Screen Outputting Field Contents as Checkboxes
WRITE <f>. field <f> can be any data object 1) a field symbol or formal parameter 2) a text symbol 3) Example : PROGRAM SAPMZTST. TABLES SPFLI. ............. WRITE 'Hello, here I am!'. ............. WRITE: 'COMPANY: ', SPFLI-CARRID.
WRITE AT [/][<pos>][(<len>)] <f>. slash '/' denotes a new line, <pos> is a number or variable up to three digits long denoting the position on the screen, <len> is a number or variable of up to three digits long denoting the output length.
Formatting Options
Option LEFT-JUSTIFIED CENTERED RIGHT-JUSTIFIED UNDER <g> NO-GAP USING EDIT MASK <m> USING NO EDIT MASK NO-ZERO
Page 8 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Option NO-SIGN DECIMALS <d> EXPONENT <e> ROUND <r> CURRENCY <c> UNIT <u>
in in in in in
WRITE <symbol-name> AS SYMBOL. WRITE <icon-name> AS ICON. Example: INCLUDE <SYMBOL>. INCLUDE <ICON>. WRITE: / 'Phone Symbol: SYM_PHONE AS SYMBOL. SKIP. WRITE: / 'Alarm Icon:', ICON_ALARM AS ICON.
WRITE <f> AS CHECKBOX. Example: DATA: FLAG1 VALUE ' , FLAG2 VALUE 'X', FLAG3(5) VALUE 'Xenon'. WRITE: / 'Flag 1 ', FLAG1 AS CHECKBOX, / 'Flag 2 ', FLAG2 AS CHECKBOX, / 'Flag 3 ', FLAG3 AS CHECKBOX.
Page 9 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Determines how data appears on the screen. Options: INTENSIFIED INPUT COLOR <n> INVERSE Parameters ON / OFF highlighted display Ready for Input Sets background color <n> influences foreground and background color
FORMAT
Text Elements
Can be maintained in Several Languages title of the program 1) list headings and column headings for page headers of output lists 2) selection texts which appear on a selection screen 3) text symbols which can be used in ABAP/4 statements instead of literals. 4)
WRITE: TEXT-010, / TEXT-AAA, / TEXT-020, / 'Default Text 030'(030), / 'Default Text 040'(040).
Assigning Values:
Using Move MOVE <f1> TO <f2>. or <f2> = <f1>.
MOVE-CORRESPONDING <string1> TO <string2>. Using Write WRITE <f1> TO <f2> [<option>]. Resetting Values to Initial Values CLEAR <f>.
Page 10 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Explanation
Trigonometric functions. Hyperbolic functions. Exponential function with base e (e=2.7182818285). Natural logarithm with base e. Logarithm with base 10. Square root.
Page 11 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
FLOW CONTROL
Keywords to control the flow of a Program
1) 2)
Comparisons with Character Strings and Numeric Strings <operator> CO CN CA NA CS NS CP NP Meaning Contains Contains Contains contains Contains contains Contains contains Logical Expression <f1> CO <f2> <f1> CN <f2> <f1> CA <f2> <f1> NA <f2> <f1> CS <f2> <f1> NS <f2> <f1> CP <f2> <f1> NP <f2>
Only Not only Any Not Any String No String Pattern No Pattern
Conditional Branching using IF IF <condition1>. <statement block> ELSEIF <condition2>. <statement block> ELSEIF <condition3>. <statement block> ..... ELSE. <statement block> ENDIF. Conditional Branching with CASE CASE <f>.
Page 12 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
WHEN <f1>. <statement block> WHEN <f2>. <statement block> WHEN <f3>. <statement block> WHEN ... ...... WHEN OTHERS. <statement block> ENDCASE.
Unconditional Looping using DO DO [<n> TIMES] [VARYING <f> FROM <f1> NEXT <f2>]. <statement block> ENDDO. Conditional Loops using WHILE WHILE <condition> [VARY <f> FROM <f1> NEXT <f2>]. <statement block> ENDWHILE. The system continues processing the statement block introduced by WHILE and concluded by ENDWHILE statements as long as <condition> is true or until the system finds an EXIT, STOP, or REJECT statement Terminating Loops Keyword CONTINUE CHECK EXIT Purpose Terminating a Loop Pass Unconditionally Terminating a Loop Pass Conditionally Terminating a Loop Entirely
Temporary table to store data temporarily in a program Characteristics of Internal Tables Exists only during Run time 1) To create a sorted list with control levels 2) To process datasets with same structure 3) To perform table calculations on subsets of database tables 4)
Page 13 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
DATA : BEGIN OF < tab> OCCURS <n>, ......, END OF <tab>. DATA : <tab> TYPE <t_tab> WITH HEADER LINE. Note: If you do not know the size of the internal table before hand, you can set the OCCURS parameter to 0. When you know your internal table will be smaller than 8 KB, you can specify the no. of table lines in the OCCURS Parameter.
Example: REPORT RSBBB03A. TABLES SFLIGHT. TYPES : BEGIN OF T_ITAB, CARRID LIKE SFLIGHT-CARRID, CONNID LIKE SFLIGHT-CONNID, FLDATE LIKE SFLIGHT-FLDATE, PAYMENTSUM LIKE SFLIGHT-PAYMENTSUM, END OF T_ITAB. DATA : ITAB TYPE T_ITAB OCCURS 100 WITH HEADERLINE. Filling an Internal Table with Header APPEND <tab>.
CAR LH LH LH DL DL
COLLECT <tab>. CAR LH LH LH DL DL Id 0400 0400 0402 1699 1699 Sales (Before Collect) 36,750.00 9,700.00 36,750.00 24,500.13 13,100.00 Sales (After Collect) 36,750.00 46,450.00 83,200.00 24,500.13 37,600.13
Page 14 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
REPORT RSBBB03A. TABLES SFLIGHT. TYPES : BEGIN OF T_ITAB, CARRID LIKE SFLIGHT-CARRID, CONNID LIKE SFLIGHT-CONNID, FLDATE LIKE SFLIGHT-FLDATE, PAYMENTSUM LIKE SFLIGHT-PAYMENTSUM, END OF T_ITAB. DATA : ITAB TYPE T_ITAB OCCURS 100 WITH HEADERLINE. ........ * Fill the internal Table ........ SORT ITAB BY FLDATE CARRID CONNID. ....... ....... SORT ITAB. ...... ..... SORT ITAB BY CARRID ASCENDING PAYMENTSUM DESCENDING.
REPORT RSBBB03A. TABLES SFLIGHT. ........ DATA : ITAB TYPE T_ITAB OCCURS 100 WITH HEADERLINE. ........ * Fill the internal Table ....... * Sort the internal Table ........ LOOP AT ITAB. WRITE : / ITAB-CARRID COLOR COL_KEY, ITAB-CONNID COLOR COL_KEY, ITAB-FLDATE COLOR COL_NORMAL,
Page 15 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
ENDLOOP.
READ TABLE <ITAB> [INTO <WA>] INDEX <IDX>. READ TABLE <ITAB> [INTO <WA>] WITH KEY <KEY> [BINARY SEARCH].
MODIFY <ITAB> [FROM <WA>] [INDEX <IDX>] [WHERE <CONDITION>]. Deleting Lines.
DELETE <ITAB>. in a loop DELETE <ITAB> INDEX <IDX>. Using Index DELETE ADJACENT DUPLICATE ENTRIES FROM <ITAB> [COMPARING <COMP>]. Delete adjacent duplicate records. DELETE < ITAB> [FROM <n1>] [TO <n2>] [ WHERE < condition>]. Delete selected lines Initializing Internal Tables REFRESH < ITAB>. Resets an Internal Table to initial state before it was filled. CLEAR <ITAB>. Clears only table work area i.e., the internal table with Header line. FREE <ITAB>. Reset an Internal table and to release the memory. CONTROL LEVELS : INTERNAL TABLES AT FIRST. ....... ENDAT. AT LAST. ....... ENDAT. AT NEW <field>. ...... ENDAT. AT END OF <field>. ...... ENDAT.
Page 16 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
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>
REPORT RSBBB03B. TABLES SFLIGHT. ........ DATA : ITAB TYPE T_ITAB OCCURS 100 WITH HEADERLINE. ........ * Fill the internal Table ....... * Sort the internal Table SORT ITAB BY CARRID CONNID HWAER DESCENDING. LOOP AT ITAB. AT NEW CONNID. WRITE: / ITAB-CARRID, ITAB-CONNID. ENDAT. WRITE : / 5 ITAB-FLDATE , ITAB-SEATSMAX, ITAB-SEATSOCC. AT END OF CONNID. ... ULINE. WRITE : / TEXT-001, ITAB-HWAER. ENDAT. AT END OF CARRID. ..... WRITE : / TEXT-002, ITAB-CARRID, ITAB-PAYMENTSUM. ENDAT. ENDLOOP.
Easy to read Easy to Maintain Improve their structure Techniques Source code modules 1) Subroutines 2) Function Modules 3)
Source code modules Same Sequence of statements in several programs - Include Programs Cannot run independently 1) Called from other programs 2)
Page 17 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
3) 4) 5)
Can call other include programs Cannot call themselves Cannot contain PROGRAM or REPORT STATEMENTS Lengthy data declarations, Module pool
Example :
Subroutines
1) 2)
Program modules which can be called from ABAP/4 Programs Frequently used parts of a program or algorithms
Block of code introduced by FORM and concluded by ENDFORM. FORM <subr> [<pass>]. < statement block> ENDFORM. <Pass> option not required for internal subroutines as they can access all data objects declared in main ABAP/4 Program. Decide whether to declare data objects in common parts of memory. Calling Subroutines
PERFORM <subr> [<pass>]. Example : PROGRAM SAPMZTST. DATA: NUM1 TYPE I, NUM2 TYPE I, SUM TYPE I. NUM1 = 2. NUM2 = 4.PERFORM ADDIT. NUM1 = 7. NUM2 = 11.PERFORM ADDIT. FORM ADDIT. SUM = NUM1 + NUM2. PERFORM OUT. ENDFORM. FORM OUT. WRITE: / 'Sum of', NUM1, 'and', NUM2, 'is', SUM. ENDFORM.
Page 18 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
FORM <subr> [TABLES <formal table list>] [USING <formal input list>] [CHANGING <formal output list>].... PERFORM <subr>[(<prog>)] [TABLES <actual table list>] [USING <actual input list>] [CHANGING <actual output list>]....
Function Modules
1) 2) 3) 4)
Special External subroutines stored in a central library. Predefined function modules. Can create own function modules. Several function modules form a function group.
Syntax CALL FUNCTION <module> [EXPORTING f1 = a1 .... fn = an] [IMPORTING f1 = a1 .... fn = an] [CHANGING f1 = a1 .... fn = an] [TABLES f1 = a1 .... fn = an] [EXCEPTIONS e1 = r1 .... en = rn [ERROR_MESSAGE = rE] [OTHERS = ro]].
SELECT <result> FROM <source> [INTO <target>] [WHERE <condition>] [GROUP BY <fields>] [ORDER BY <sort_order>].
Example :
TABLES SPFLI. SELECT * FROM SPFLI WHERE CITYFROM EQ 'FRANKFURT'. ... WRITE : / SPFLI-CARRID, SPFLI-CONNID, SPFLI-CITYFROM, SPFLI-CITYTO.... ENDSELECT
Page 19 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Example :
TABLES SPFLI. SELECT SINGLE * FROM SPFLI WHERE CARRID EQ 'LH' AND CONNID EQ '2407'. WRITE: / SPFLI-CARRID, SPFLI-CONNID, SPFLI-CITYFROM, SPFLI-CITYTO.
SELECT [SINGLE [FOR UPDATE]] [DISTINCT] <s1> <s2> ... INTO ...
Aggregate Expressions
Extract characteristic data from a column <a> of the database table. MAX: returns the maximum value of the column <a> 1) MIN: returns the minimum value of the column <a> 2) AVG: returns the average value of the column <a> 3) SUM: returns the sum value of the column <a> 4) COUNT: counts values or lines as follows: 5) COUNT( DISTINCT <a> ) returns the number of distinct values for the column <a>. 6) COUNT( * ) returns the total number of lines in the selection. 7)
SELECT ..... INTO TABLE <itab>. In this case, SELECT does not start a loop, and no ENDSELECT statement is allowed.
Example:
TABLES SPFLI. DATA ITAB LIKE SPFLI OCCURS 10 WITH HEADER LINE. SELECT * FROM SPFLI INTO TABLE ITAB WHERE CARRID = 'LH'. LOOP AT ITAB. WRITE: / ITAB-CONNID, ITAB-CARRID. ENDLOOP.
Page 20 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
For reading data into a work area: SELECT ... INTO CORRESPONDING FIELDS OF <wa> ........ For reading data into an internal table: SELECT ... INTO CORRESPONDING FIELDS OF TABLE <itab> ........ For appending data to an internal table: SELECT ... APPENDING CORRESPONDING FIELDS OF TABLE <itab> ......
Grouping Lines
Example :
TABLES SFLIGHT. DATA CARRID LIKE SFLIGHT-CARRID. DATA: MINIMUM TYPE P DECIMALS 2, MAXIMUM TYPE P DECIMALS 2. SELECT CARRID MIN( PRICE ) MAX( PRICE ) INTO (CARRID, MINIMUM, MAXIMUM) FROM SFLIGHT GROUP BY CARRID. WRITE: / CARRID, MINIMUM, MAXIMUM. ENDSELECT.
Sorting by Primary Key SELECT * ..... ORDER BY PRIMARY KEY. Sorting by Specified Fields .... ORDER BY <f1> [ASCENDING | DESCENDING] <f2> [ASCENDING | DESCENDING] ... Changing the Contents of Database Tables Operation INSERT ABAP/4 keywords You use the INSERT statement to add new lines, i.e. lines with a primary key, which does not already exist in the database table. You use the UPDATE statement to change existing lines in a database table. i.e. lines with a primary key, which already exists in the database table. You use the MODIFY statement to add new lines if no line with the primary key of the line to be added exists. Otherwise, you change the existing line. You use the DELETE statement to delete lines from a database table.
UPDATE
MODIFY
DELETE
Page 21 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
INSERT <dbtab> [CLIENT SPECIFIED] FROM TABLE <itab> [ACCEPTING DUPLICATE KEYS].
Example :
TABLES SPFLI. DATA ITAB LIKE SPFLI OCCURS 10 WITH HEADER LINE. ITAB-CARRID = 'UA'. ITAB-CONNID = '0011'. ITAB-CITYFROM = ..APPEND ITAB. ITAB-CARRID = 'LH'. ITAB-CONNID = '1245'. ITAB-CITYFROM = ..APPEND ITAB. ITAB-CARRID = 'AA'. ITAB-CONNID = '4574'. ITAB-CITYFROM = ..APPEND ITAB. ................ INSERT SPFLI FROM TABLE ITAB ACCEPTING DUPLICATE KEYS.
Example :
TABLES SFLIGHT. UPDATE SFLIGHT SET PLANETYPE = 'A310' FLPRICE = FLPRICE - '100.00' WHERE CARRID = 'LH'.
Example :
TABLES SPFLI. DATA ITAB LIKE SPFLI OCCURS 10 WITH HEADER LINE. ITAB-CARRID = 'UA'. ITAB-CONNID = '0011'. ITAB-CITYFROM = .. APPEND ITAB. ITAB-CARRID = 'LH'. ITAB-CONNID = '1245'. ITAB-CITYFROM = .. APPEND ITAB. ITAB-CARRID = 'AA'. ITAB-CONNID = '4574'. ITAB-CITYFROM = .. APPEND ITAB. ................ UPDATE SPFLI FROM TABLE ITAB.
Example :
AND
CARRID = 'LH'.
Page 22 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Example :
TABLES SPFLI. DATA ITAB LIKE SPFLI OCCURS 10 WITH HEADER LINE. ITAB-CARRID = 'UA'. ITAB-CONNID = '0011'. APPEND ITAB. ITAB-CARRID = 'LH'. ITAB-CONNID = '1245'. APPEND ITAB. ITAB-CARRID = 'AA'. ITAB-CONNID = '4574'. APPEND ITAB. ................ DELETE SPFLI FROM TABLE ITAB.
Example: TABLES SPFLI. DATA FLAG. SPFLI-CARRID = 'UA'. SPFLI-CONNID = '0011'. SPFLI-CITYFROM = ............ INSERT SPFLI. IF SY-SUBRC <> 0. FLAG = 'X'. ENDIF. SPFLI-CARRID = 'LH'. SPFLI-CONNID = '1245'. SPFLI-CITYFROM = ............ INSERT SPFLI. IF SY-SUBRC <> 0. FLAG = 'X'. ENDIF. SPFLI-CARRID = 'AA'. SPFLI-CONNID = '4574'. SPFLI-CITYFROM = ............ INSERT SPFLI. IF SY-SUBRC <> 0. FLAG = 'X'. ENDIF. ................ ................ IF FLAG = 'X'. ROLLBACK WORK. ELSE. COMMIT WORK. ENDIF.
Page 23 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Opening of A File Basic Form of the OPEN DATASET Statement Opening a File for Reading
OPEN DATASET <dsn> FOR INPUT. Example : DATA FNAME(60) VALUE 'myfile'. OPEN DATASET FNAME FOR INPUT. IF SY-SUBRC = 0. WRITE / 'File opened'. ELSE. WRITE / 'File not found'. ENDIF.
OPEN DATASET <dsn> FOR OUTPUT. Example : DATA: MESS(60), FNAME(10) VALUE '/tmp'. OPEN DATASET FNAME FOR OUTPUT MESSAGE MESS. IF SY-SUBRC <> 0. WRITE: 'SY-SUBRC:', SY-SUBRC, / 'System Message:', MESS. ENDIF.
OPEN DATASET <dsn> FOR APPENDING. DATA FNAME(60) VALUE 'myfile'. DATA NUM TYPE I. OPEN DATASET FNAME FOR OUTPUT. DO 5 TIMES. NUM = NUM + 1. TRANSFER NUM TO FNAME. ENDDO. OPEN DATASET FNAME FOR INPUT. OPEN DATASET FNAME FOR APPENDING. NUM = 0. DO 5 TIMES. NUM = NUM + 10. TRANSFER NUM TO FNAME. ENDDO.
Example:
Page 24 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
OPEN DATASET FNAME FOR INPUT. DO. READ DATASET FNAME INTO NUM. IF SY-SUBRC <> 0. EXIT. ENDIF. WRITE / NUM. ENDDO.
CLOSE DATASET <dsn>. Example : DATA FNAME(60) VALUE 'myfile'. OPEN DATASET FNAME FOR OUTPUT. ..... CLOSE FNAME. OPEN DATASET FNAME FOR INPUT. ..... CLOSE FNAME. OPEN DATASET FNAME FOR INPUT AT POSITION <pos>. ..... CLOSE FNAME.
Closing a File
Deleting a File
DELETE DATASET <dsn>. Example : DATA FNAME(60) VALUE 'myfile'. OPEN DATASET FNAME FOR OUTPUT. OPEN DATASET FNAME FOR INPUT. IF SY-SUBRC = 0. WRITE / 'File found'.ELSE. WRITE / 'File not found'. ENDIF. DELETE DATASET FNAME. OPEN DATASET FNAME FOR INPUT. IF SY-SUBRC = 0. WRITE / 'File found'. ELSE. WRITE / 'File not found'. ENDIF.
Page 25 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Example : DATA FNAME(60) VALUE 'myfile'. TYPES: BEGIN OF LINE, COL1 TYPE I, COL2 TYPE I, END OF LINE. TYPES ITAB TYPE LINE OCCURS 10. DATA: LIN TYPE LINE, TAB TYPE ITAB. DO 5 TIMES. LIN-COL1 = SY-INDEX. LIN-COL2 = SY-INDEX ** 2. APPEND LIN TO TAB. ENDDO. OPEN DATASET FNAME FOR OUTPUT. LOOP AT TAB INTO LIN. TRANSFER LIN TO FNAME. ENDLOOP. CLOSE DATASET FNAME. OPEN DATASET FNAME FOR INPUT. DO. READ DATASET FNAME INTO LIN. IF SY-SUBRC <> 0. EXIT. ENDIF. WRITE: / LIN-COL1, LIN-COL2. ENDDO. CLOSE DATASET FNAME.
Example :
DATA FNAME(60) VALUE 'myfile'. DATA: TEXT1(12) VALUE 'abcdefghijkl', TEXT2(5), OPEN DATASET FNAME FOR OUTPUT IN BINARY MODE. TRANSFER TEXT1 TO FNAME. CLOSE DATASET FNAME. OPEN DATASET FNAME FOR INPUT IN BINARY MODE. DO. READ DATASET FNAME INTO TEXT2 LENGTH LENG. WRITE: / SY-SUBRC, TEXT2, LENG. IF SY-SUBRC <> 0. EXIT. ENDIF. ENDDO. CLOSE DATASET FNAME.
LENG TYPE I.
Page 26 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Central source of information for the data in a data management system. To support the creation and management of data definitions.
Basic objects
1) 2) 3)
Tables : Tables contain fields, which refer to data elements. Domains : Technical characteristics. Data Elements : Semantic definition, Text description. I. Different fields from different tables can use different data elements. II. Different data elements can use same domains.
Tables
Delivery class: The Delivery class determines whether a table is maintained by SAP or by the customer. In addition, the delivery class determines how the table behaves in upgrades, transports and client copies. Table maintenance allowed: With this parameter you can specify whether the table entries can be accessed using standard table maintenance, that is, whether users can insert, change or delete entries via the standard table maintenance. Standard maintenance should not be allowed for tables, which are filled and changed automatically via programs. Activation type: The Activation type determines whether the table can be activated directly from the ABAP/4 Dictionary or whether the runtime object must first be generated by a C program. Specification of an activation type is optional and important only for tables in the runtime environment.
Table Attributes
Technical Settings
To optimize storage space requirements and table access behavior for database tables.
Data class: The Data class establishes the physical area of the database (tablespace) in which your
table is to be stored. 1. APPL0: Master data - frequently accessed but rarely updated 2. APPL1: Transaction data - data that is changed frequently
Page 27 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
3. APPL2: Organizational data - customizing data that is entered when the system is configured and is rarely changed
Size category: The Size category allows you to specify estimated space requirements for the table
in the database. When the table is created in the database, the necessary information about the storage area and the probable table size is determined from the technical settings. Categories 1 to 4.
Buffering authorization: You can specify here whether the table can be buffered. Buffering a table enhances the performance when accessing the data records contained in it. Buffering type: If the table can be buffered, you have to specify a buffering type (full, singlerecord, generic). The buffering type determines how many records of the table are loaded to the buffer when an entry in the table is accessed. Full buffering: With full buffering, either the whole table or none of the table is located in the
buffer. When a read access takes place, the entire table is loaded into the buffer.
Generic buffering: When you access a record from a table that is generically buffered, all records
whose generic key fields correspond to this record are loaded into the buffer. In other words, the generic areas of a table are fully buffered. Within the buffer, the generic areas are treated as objects in their own right (like fully buffered tables).
buffer. This saves storage space in the buffer. However, this type of buffering involves more administrative tasks than full buffering. In addition many more database accesses are needed to load the records of the table.
Single-record buffering: Only those records of a table actually being accessed are loaded into the
Logging: With this parameter you can stipulate whether changes to table entries are to be logged.
If logging is active, each change to a record of the table is recorded in a log table.
When a table is activated, a physical table definition in the database is added to the table definition stored in the ABAP/4 Dictionary.
Indexes
1) 2) 3) 4)
To speed up the scanning of a table for data records satisfying specific search criteria. Copy of a database table reduced to specific fields. Fast access to the data records of the table Sequence of fields in the index determines the speed of access.
Primary Index: key fields of the table Secondary Index: other fields of the table (If selections are frequently made involving attributes that are not contained in the primary index)
Page 28 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Aggregate Objects
Formed from several related tables. Aggregate objects are based on a table, which is termed the primary table of the aggregate object. Other tables can be added to this primary table. These tables must be connected to the primary table by means of foreign keys or join conditions. These additional tables are called secondary tables of the aggregate object. Transitive connections between primary table and secondary tables are possible.
1) 2) 3)
VIEWS
To directly access specific data. The structure of such a view is defined by specifying the tables and fields to be contained in the virtual table. A view can be used to summarize data, which is distributed among several tables. In addition, superfluous fields can be suppressed, keeping interfaces to a minimum. A view relates logically to one or more tables. That is, the data of a view is not actually physically stored. The data of a view is instead derived from one or more other tables. At its most simple, this derivation process might involve simply suppressing the display of one or more fields of a base table (projection) or transferring only certain records from a base table to the view (selection). More complex views can be assembled from several tables, with these tables being linked by the relational join operation . The first step in the definition of a view involves choosing the base tables of the view. In the second step, these are linked by the definition of join conditions. It is possible to take the join condition from a foreign key defined between two tables. In the third step the fields of the base tables which are to be included in the view are chosen. In the fourth step, the selection conditions which restrict the records in the view can be formulated.
Example:
Table: UPERS Field Name EUNR EUNA ADRE Text Number of a university member Name of university member Address of a university member
Page 29 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Table: UNAMA Field Name NAMNR BUERNR AUFGA BEKLA FABNR Table: UFACH Field Name FABNR FBNAM Text Faculty number Faculty description Text Personnel number of an administrative employee Office number of administrative staff Administrative staff job description Salary class of administrative staff Faculty number
Specify the other fields required. Finally the output will be as follows.
Field Name EUNR EUNA BUERNR AUFGA FABNR FBNAM Text Number of a university member Name of university member Office number of administrative staff Administrative staff job description Faculty number Faculty description
Tool to help you search for data records in the system. Matchcodes are an efficient and user-friendly search aid for cases where the key of a record is unknown. Matchcodes are defined in two stages in the ABAP/4 Dictionary: The relevant tables and fields are stipulated in a Matchcode object. A Matchcode object describes the set of all possible search paths for a search term.
MATCHCODES
Page 30 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
One or more Matchcode ID can be defined for a Matchcode object. A Matchcode ID describes a special search path for a search term. The fields or combinations of fields via which the search is to take place are defined in the Matchcode ID. Maximum of 36 Matchcode IDs can be defined for any one Matchcode object. The numbers 0 to 9 are reserved for customers to define their own Matchcode IDs for SAP Matchcodes. A Matchcode can contain fields from several tables. It describes a comprehensive logical view into one or more tables The first table to be selected is the primary table of the Matchcode object. Other secondary tables can be added to this primary table. These tables must be connected to the primary table by means of foreign keys.
LOCK OBJECTS
Simultaneous accessing of the same data record by two users in the SAP system is synchronized by a lock mechanism. When dialog transactions are programmed, locks are set and released by calling certain function modules. These function modules are generated automatically from the definition of so-called lock objects in the ABAP/4 Dictionary. To synchronize the access to a table by setting and removing locks, a Lock object has to be defined in the ABAP/4 Dictionary. Activating the lock object automatically creates function modules for setting and removing locks. These function modules must be included when programming interactive transactions. Function modules ENQUEUE_<Object_name> and DEQUEUE_<Object_name> are generated. The ENQUEUE function module is used for setting a lock, the DEQUEUE function module for lifting an existing lock. This lock mechanism fulfills two main functions: 1. A transaction can protect data records, which it is changing or reading against a parallel change via another transaction. 2. A transaction can prevent itself reading data, which are currently being changed by another transaction.
REPORTS
Program, which reads and Analyzes data from database tables without modifying the database. Result is in the form of a list, which is output to the screen or sent to a printer. Selecting data : Accessing data with SELECT. Can read and Analyze data from all database tables known to SAP system by using SELECT Statement. Accessing data using Logical Databases. A logical database is a special ABAP/4 program, which combines the contents of certain database tables. It has a 3-character name where the last letter denotes the application. You can link a logical database to an ABAP/4 report program as an attribute. The logical database then supplies the report program with a set of hierarchically structured table lines, which can be taken from different database tables. The sequence in which the data is made available to the programs is determined by a tree structure. The following table compares two report programs which both read data from the hierarchically structured database tables SPFLI, SFLIGHT, and SBOOK.
Page 31 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Report with SELECT statements REPORT TABLES: SPFLI, SFLIGHT, SBOOK. SELECT * FROM SPFLI WHERE <processing block>.. SELECT * FROM SFLIGHT WHERE .... <processing block>.. SELECT * FROM SBOOK WHERE. <processing block> ENDSELECT. ENDSELECT. ENDSELECT.
Report with logical databases REPORT ......... TABLES: SPFLI, SFLIGHT, SBOOK. GET SPFLI. <processing block> GET SPFLI. <processing block> GET SBOOK. <processing block>
If you do not want to use a logical database to read data, dont specify a database in the attributes. A dummy database becomes active and provides an empty selection screen. You can design the selection screen using report specific parameters or selection options.
Eliminate to program the data retrieval from the database tables. In your report program, you do not have to define how the information should be retrieved, but only how it should be presented on the screen. After each table line is transferred, a GET event occurs and the report program is able to process it by activating the appropriate processing block. If you do not specify a logical database in the program attributes, the GET events never occur. When you are working with logical databases, you do not have to program a selection screen for user input since this is created automatically. If you are only working with SELECT statements, however, you have to program the selection screen yourself. A report can only work with one logical database, but each logical database can be used by several reports. This offers considerable advantages over integrating the database accesses with SELECT statements into each report program.
Page 32 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
GET SPFLI. * PROCESSING OF SPFLI RECORDS WRITE: / SPFLI-CARRID, SPFLI-CONNID, SPFLI-CITYFROM, SPFLI-CITYTO, SPFLIDEPTIME, SPFLI-ARRTIME, SPFLI-FLTIME. GET SFLIGHT. * PROCESSING OF SFLIGHT RECORDS WRITE: /10 SFLIGHT-FLDATE, SFLIGHT-PRICE, SFLIGHT-CURRENCY. GET SBOOK. * PROCESSING OF SBOOK RECORDS WRITE: /20 SBOOK-BOOKID, SBOOK-CUSTOMID, SBOOK-CUSTTYPE.
Example: Report
.
GET SPFLI FIELDS CARRID CONNID CITYFROM CITYTO DEPTIME ARRTIME FLTIME. * PROCESSING OF SPFLI RECORDS, GET EVENT WITH FIELD SELECTION WRITE: / SPFLI-CARRID, SPFLI-CONNID, SPFLI-CITYFROM, SPFLI-CITYTO, SPFLI-DEPTIME, SPFLI-ARRTIME, SPFLI-FLTIME. GET SFLIGHT FIELDS FLDATE PRICE CURRENCY. * PROCESSING OF SFLIGHT RECORDS, GET EVENT WITH FIELD SELECTION WRITE: /10 SFLIGHT-FLDATE, SFLIGHT-PRICE, SFLIGHT-CURRENCY. GET SBOOK FIELDS BOOKID CUSTOMID CUSTTYPE. * PROCESSING OF SBOOK RECORDS, GET EVENT WITH FIELD SELECTION WRITE: /20 SBOOK-BOOKID, SBOOK-CUSTOMID, SBOOK-CUSTTYPE.
Event keyword
INITIALIZATION AT SELECTION-SCREEN START-OF-SELECTION GET <table> END-OF-SELECTION
Page 33 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Program flow
REPORT <name>. DATA : ..... ......... INITIALIZATION ....Statements..... START-OF-SELECTION. ....Statements..... GET < table>. ....Statements..... END-OF-SELECTION. ....Statements.....
TOP-OF-PAGE. END-OF-PAGE.
Text Elements
REPORT <name>
NO STANDARD PAGE HEADING LINE-SIZE <col> LINE-COUNT <lin>
Page 34 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
MESSAGE-ID <XX>
TOP-OF-PAGE.
After the page break, the system triggers the TOP-OF-PAGE event.
END-OF-PAGE. If a new page is started during the creation of a list, the system processes the processing block for the END-OF-PAGE event before the page break is performed. Example:
REPORT ZSAMPLE NO STANDARD PAGE HEADING. TOP-OF-PAGE. FORMAT COLOR COL_HEADING. WRITE : /5 User : , sy-uname, 20 Date : , sy-datum. ULINE. END-OF-PAGE. ULINE. WRITE : /30 Page Footer . START-OF-SELECTION. ..... END-OF-SELECTION. ......
NEW-LINE.
Page 35 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
SKIP <n>. SKIP TO LINE <n>. POSITION <n>. SET BLANK LINES ON/OFF. Example:
REPORT ZSAMPLE. TABLES : SCUSTOM. PARAMETERS : LANG LIKE SY-LANGU DEFAULT E, CNTRY LIKE T005X-LAND. ...... SET COUNTRY CNTRY. ..... SET LANGUAGE LANG. ..... SELECT * FROM SCUSTOM. RESERVE 4 LINES. WRITE : / SCUSTOM-ID, SCUSTOM-NAME, / SCUSTOM-POSTCODE, SCUSTOM-CITY, / SCUSTOM-TELEPHONE, SCUSTOM-STATE. SKIP 1. ENDSELECT. TOP-OF-PAGE. SET LEFT SCROLL-BOUNDARY COLUMN 10.
Description
Runtime: Current line of an internal table Return value after specific ABAP/4 statements Number of loop passes Number of elements in edited dataset with DB operations Location of a string Cursor position (column) Cursor position (line) Report title from text elements Number of lines from the report Statement Index of the displayed list level Line width from the current window Number of lines in the current window Number of columns in the current window Number of current page Number of current line Number of current column
Page 36 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
NEW-PAGE
PRINT ON NO DIALOG LINE-COUNT <n> LINE-SIZE <n> DESTINATION <dest> IMMEDIATELY <x>
PRINT-CONTROL
FONT <font> CPI <cpi> LPI <lpi> SIZE <size> COLOR <black/red/blue/yellow...> LEFT MARGIN <col>.
SELECTION SCREEN
Page 37 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
SELECT-OPTIONS
SELECT-OPTIONS <name> FOR <field> DEFAULT <value1> DEFAULT <value1> TO <value2> MATCHCODE OBJECT <mobj> NO-DISPLAY LOWER CASE OBLIGATORY NO-EXTENSION NO INTERVALS NO DATABASE SELECTION
Page 38 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
PARAMETERS
PARAMETERS <name> DEFAULT < value> TYPE <type> DECIMALS <dec> LIKE <g> MATCHCODE OBJECT <mobj> NO-DISPLAY LOWER CASE OBLIGATORY AS CHECKBOX RADIOBUTTON GROUP <radi>
SELECTION-SCREEN BEGIN OF BLOCK <block> WITH FRAME TITLE title ....... SELECTION-SCREEN END OF BLOCK <block>
SELECTION-SCREEN BEGIN OF LINE COMMENT <format> <name> POSITION <pos> ....... SELECTION-SCREEN END OF LINE
Example:
TITLE B1_TXT.
Page 39 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
PARAMETERS: P_RADI1 RADIOBUTTON GROUP G1 DEFAULT 'X', P_RADI2 RADIOBUTTON GROUP G1. SELECT-OPTIONS: S_SELE FOR BKPF-BUDAT NO-EXTENSION. SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF LINE . SELECTION-SCREEN : COMMENT 1(15) TEXT-001, POSITION 35. PARAMETERS : PRICE LIKE SFLIGHT-PRICE OBLIGATORY. SELECTION-SCREEN : COMMENT 50(8) TEXT-002, POSITION 70. PARAMETERS : CURRENCY LIKE SFLIGHT-CURRENCY. SELECTION-SCREEN END OF LINE .
Interface to a selection screen. Selection set of values in one selection set. Pre-setting selections to run the report program at regular intervals with the same data. Can create any number of variants for a report program.
VARIANTS
Description: Enter short description upto 30 chars. Background only: Specify if you want to use in background processing only. Protected Variant: Mark this field if you want to protect against being changed by others.
Environment Attributes
Type: Specifies whether the field is a parameter or select-options Protected: Mark this field for each field, you want to protect from being overwritten. Invisible: The system will not display the corresponding field on the selection screen the user sees when executing the report.
Field Attributes
MESSAGE CLASS
Each ABAP/4 program can be associated with a message class. A message class is identified by an ID nn where nn is any two alpha-numeric characters. A message class contains one or more messages. Specify a message class in your program's PROGRAM or REPORT statement.
Page 40 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
I W E A X
MESSAGE TYPES
INFO WARNING ERROR ABEND EXIT Press Enter to continue Correction possible Correction required Transaction terminated Transaction terminated with short dump
Syntax:
MESSAGE xnnn. Where x is any one of I/W/E/A/X and nnn is the message number. MESSAGE ID mid TYPE type NUMBER mnr. where ID is message ID TYPE is message type NUMBER is message number.
Page 41 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Option: ...WITH f1 ....... f4 Example: MESSAGE E010 WITH value. MESSAGE ID XX TYPE E NUMBER 010 WITH value.
With interactive reporting you can generate secondary lists and windows, which are generated using function keys and output on the screen. Interactive reporting is event driven. Basic List START-OF-SELECTION. .... GET ... .... END-OF-SELECTION. ... TOP-OF-PAGE. .... END-OF-PAGE. .... Interactive Reporting AT PFnn. .... AT LINE-SELECTION. .... AT USER-COMMAND. .... TOP-OF-PAGE DURING LINE-SELECTION.
INTERACTIVE REPORTING
Event keyword
AT LINE-SELECTION AT USER-COMMAND AT PF<nn> TOP-OF-PAGE DURING LINESELECTION
Event
Point at which the user selects a line Point at which the user presses a function key or enters a command in the command field Point at which the user presses the function key with the function code PF<n> Occurs when creating secondary lists.
Top-of-page occurs only when you create a basic list. The event TOP-OF-PAGE DURING LINESELECTION occurs when creating the secondary lists. AT LINE SELECTION is assigned to the Choose function (Double click or F2) AT PF<i> is assigned to each Function Key F<i>.
Page 42 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Beyond the basic list, upto nine secondary lists can exist in parallel. SY-LSIND contains the list level. REPORT RSBBB06A. TABLES: SPFLI,SFLIGHT, SBOOK, SCARR. GET SPFLI. ..... GET SFLIGHT. ...... AT LINE-SELECTION. CASE SY-LSIND. WHEN '1'. SELECT * FROM SBOOK WHERE CARRID EQ SFLIGHT-CARRID AND CONNID EQ SFLIGHT-CONNID AND FLDATE EQ SFLIGHT-FLDATE. WRITE: / SBOOK-BOOKID, SBOOK-CUSTOMID, SBOOK-CUSTTYPE. ENDSELECT. ..... WHEN '2'. DO 15 TIMES. WRITE: / TEXT-001, SY-LSIND. ENDDO. WHEN '3'. SY-LSIND = SY-LSIND - 1. DO 15 TIMES. WRITE: / TEXT-004, TEXT-005, SY-LSIND. ENDDO. ENDCASE. TOP-OF-PAGE. WRITE 70 TEXT-002. ULINE. TOP-OF-PAGE DURING LINE-SELECTION. CASE SY-LSIND. WHEN '1'. WRITE: 60 TEXT-003, SY-LSIND, / TEXT-009, TEXT-006, TEXT-007, TEXT-008. ULINE. WHEN '2'. WRITE: 60 TEXT-003 , SY-LSIND. ULINE. WHEN '3'. WRITE: 60 TEXT-003 , SY-LSIND. ULINE. ENDCASE.
Page 43 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
MENU PAINTER
To define functions that should be available on a screen in connection with a specific status and assign them to the appropriate menubar, standard tool bar or application tool bar.
Page 44 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
ACTIVATING A GUI INTERFACE SET PF-STATUS STATUS. SET TITLEBAR tit. Refer to a status you have defined with the menu painter. A status name can consist of upto 8 alphanumeric characters and must be capitalized. Screen title can be upto 3 characters, and the description upto 70 characters. Event -AT USER COMMAND occurs in the report if the user activates the corresponding function. Processed when the user presses a function key in the list, which is assigned, to a function code. Example : REPORT ZSAMPLE. ....... END-OF-SELECTION.
Page 45 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
SET PF-STATUS BASE. ...... ...... AT USER-COMMAND. CASE SY-UCOMM. WHEN CARR. ....... WHEN FLIG. .......
3)
4)
Transferring data into the SAP System from other SAP Systems and non-SAP Systems. Both batch input methods work by carrying out normal SAP transactions, just as a user would. However, batch-input can execute the transactions automatically and is therefore suitable for entering large amounts of data that are already available in electronic form. No manual interaction is required during data transfer. If the data to be transferred is already available in electronic form (on a tape, for example), then you can enter the data automatically into the SAP System using batch input. Batch input ensures data integrity. Batch input enters data into the SAP System using the same transactions that interactive users do. Batch input data is therefore submitted to all of the checks and controls that apply to data entered by normal interactive means.
Methods of BDC.
1. Classical Batch Input 2. Call transaction using 3. Call Dialog
Page 46 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
The most important aspects of the session interface are: Asynchronous processing 1) Transfers data for multiple transactions 2) Synchronous database update (During processing, no transaction is started until the previous 3) transaction has been written to the database.) A batch input processing log is generated for each session 4) Sessions cannot be generated in parallel 5) The batch input program must not open a session until it has closed the preceding session. 6)
Program uses the ABAP/4 CALL TRANSACTION USING statement to run an SAP transaction. Batch-input data does not have to be deposited in a session for later processing. Instead, the entire batch-input process takes place inline in your program. Batch input by way of CALL TRANSACTION USING offers faster processing if you need it to get your batch input done in the time slot that is available for it. CALL TRANSACTION USING offers, however, less support for error recovery and management of batch input. The most important aspects of the CALL TRANSACTION USING interface are:
1) 2) 3) 4) 5) 6) 7)
Synchronous processing Transfers data for a single transaction Synchronous and asynchronous database updating both possible The program specifies which kind of updating is desired. Separate LUW for the transaction The system performs a database commit immediately before and after the CALL TRANSACTION USING statement. No batch input processing log is generated
the transaction code, if you do not already know it which fields require input which fields you can allow to default to standard values the names, types, and lengths of the fields that are used by a transaction the identifiers of the functions that you will need to call to have the transaction process the batch input data.
Page 47 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
3. On each screen, note the program name and screen (dynpro) number. Display these by choosing System ! Status. The relevant fields are Program (dynpro) and Dynpro number. If pop-up windows occur during execution, you can get the program name and screen number by pressing F1 on any field or button on the screen. The Technical info pop-up shows not only the field information but also the program and screen. 4. For each field, check box, and radio button on each screen, press F1 (help) and then choose Technical info. Note the following information: I. The field name for batch input, which you'll find in its own box. II. The length and data type of the field. You can display this information by double clicking on the Data element field. 5. Find out the identification code for each function (button or menu) that you must execute to process the batch input data. Put the cursor on the button or menu entry while holding down the left mouse button. Then press F1. In the pop-up window that follows, choose Technical info and note the code that is shown in the Function field. You can also run any function that is assigned to a function key by way of the function key number. To display the list of available function keys, click on the right mouse button. Note the key number that is assigned to the functions you want to run.
read data in, often from a sequential file that has been exported from another system or prepared by a data transfer program
2) 3)
if necessary, perform data conversions or error-checking prepare the data for batch input processing by storing the data in the batch input data structure, BDCDATA.
4)
generate a batch-input session for classical batch input, or process the data directly with CALL TRANSACTION USING.
Page 48 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
The batch-input structure stores the data that is to be entered into SAP System and the actions that are necessary to process the data. The batch-input structure is used by all of the batch-input methods. Within a BDCDATA structure, data is organized by the screens in a transaction.
DATA : BEGIN OF <bdc table> OCCURS < occurs parameter>. INCLUDE STRUCTURE BDCDATA. DATA : END OF <bdc table> .
BDCDATA STRUCTURE. Field Name Type PROGRAM CHAR DYNPRO NUMC DYNBEGIN CHAR FNAM CHAR FVAL CHAR
Length 8 4 1 35 80
Description BDC Module Pool BDC Dynpro Number BDC Starting a DYNPRO BDC Field Name BDC Field Value
Identifying a Screen
The first record for each screen must contain information that identifies the screen: program name, screen name and a start-of-screen indicator. Example : BDCDATA-PROGRAM = 'sapms38m'. BDCDATA-DYNPRO = '0100'. BDCDATA-DYNBEGIN = 'x'. APPEND BDCDATA.
After the dynpro-start record, you must add a record for each field that is to receive a value. You need fill only the FNAM and FVAL fields. Example : BDCDATA-FNAM = 'RS38M-FUNC_EDIT'. BDCDATA-FVAL = 'x'. APPEND BDCDATA.
Page 49 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Executing a Function
You can execute a function in a transaction by entering the function code or function key number in the command field of an SAP session. You use the FNAM and FVAL fields to enter this information, just as you would for normal screen fields. The command field is identified by a special name in batch input, BDC_OKCODE. constant and always identifies the command field. Example : BDCDATA-FNAM = 'BDC_OKCODE'. BDCDATA-FVAL = '/11'. Save ( F11 ) or BDCDATA-FNAM = 'BDC_OKCODE'. BDCDATA-FVAL = '=UPDA'. Save ( function code ) This name is
Some screen fields need multiple values, one on each line. To provide input to one of these loop fields, you must use an explicit line index : Example : BDCDATA-FNAM = 'fieldx(5)'. BDCDATA-FVAL = 'value'. The line index (in the example: (5), line 5) indicates in which loop line on the screen values are to appear.
To position the cursor on a particular field, you must use the special cursor field: BDCDATA-FNAM = 'BDC_CURSOR'. BDCDATA-FVAL = 'fieldx'. To position the cursor on a loop field, you must use again an index: BDCDATA-FNAM = 'BDC_CURSOR'. BDCDATA-FVAL = 'fieldy(5)'.
One of the two recommended ways to process batch input data is to store the data in a batch-input session. This session can then be run in the SAP System to enter the batch input data into the system. In general, preparing a session is the best and most comfortable way to process batch input data. However, you may wish to use the alternate method, CALL TRANSACTION USING, if your batchinput sessions cannot be run quickly enough.
Page 50 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
To create a session, program the following procedure using the following BDC_ function modules: Open the batch-input session using function module BDC_OPEN_GROUP . For each transaction in the session: Fill the BDCDATA structure with values for all screens and fields that must be processed in the transaction. Transfer the transaction to the session with BDC_INSERT . Close the batch input session with BDC_CLOSE_GROUP.
Processing batch input data with CALL TRANSACTION USING is the faster of the two recommended batch input methods. In this method, batch input data is processed inline in your batch input program. Prepare a BDCDATA structure for the transaction that you wish to run. Call the transaction and pass the BDCDATA structure to it as batch input. CALL TRANSACTION <tcode> USING BDCTABLE < bdc table> MODE <display mode> UPDATE < update mode> DISPLAY MODE A E N UPDATE MODE S A L Display All Display only error No Display
Continue Processing when update is terminated Continue Processing immediately Local Update
Page 51 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
The following program demonstrates both the creation of sessions, and the use of CALL TRANSACTION USING. REPORT RJBDC200 LINE-SIZE 120. *----------------------------------------------------------------* * Add a line in a report * *----------------------------------------------------------------* PARAMETERS : BDCTYPE TYPE C DEFAULT 'M', " M = Create batch input session " T = Call transaction " Only used for batch input sessions GROUP(12) TYPE C DEFAULT 'BDCTEST', " group name of session USER(12) TYPE C DEFAULT SY-UNAME, " user name for starting the session in background KEEP(1) TYPE C, " ' ' = delete session after processing 'X' = keep session after successful processing HOLDDATE LIKE SY-DATUM, * " Only used for call transaction * DMODE TYPE C DEFAULT 'A'. " Display mode 'A' = display all screens 'E' = display only errors 'N' = display nothing * Batch input data for a single transaction DATA: BEGIN OF BDCDATA OCCURS 0. INCLUDE STRUCTURE BDCDATA. DATA: END OF BDCDATA. DATA: BEGIN OF MESSTAB OCCURS 0. INCLUDE STRUCTURE BDCMSGCOLL. DATA: END OF MESSTAB. * Generate batch input CASE BDCTYPE. WHEN 'M'. PERFORM CREATE_GROUP. EXIT. WHEN 'T'. PERFORM CALL_TRANSACTION. EXIT. ENDCASE. * Create batch input session FORM CREATE_GROUP. WRITE: / 'Create group'. * " Open batch input group CALL FUNCTION 'BDC_OPEN_GROUP' * *
Page 52 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
= SY-MANDT GROUP = GROUP USER = USER KEEP = KEEP HOLDDATE = HOLDDATE. WRITE: / 'BDC_OPEN_GROUP rc ='(999), SY-SUBRC. * " Insert first transaction PERFORM GEN_BDC_DATA. CALL FUNCTION 'BDC_INSERT' EXPORTING TCODE = 'SE38' TABLES DYNPROTAB = BDCDATA. WRITE: / 'BDC_INSERT rc ='(999), SY-SUBRC.
EXPORTING
CLIENT
* " Insert second transaction PERFORM GEN_BDC_DATA. CALL FUNCTION 'BDC_INSERT' EXPORTING TCODE = 'SE38' TABLES DYNPROTAB = BDCDATA. WRITE: / 'BDC_INSERT rc ='(999), SY-SUBRC. * " Close batch input group CALL FUNCTION 'BDC_CLOSE_GROUP'. WRITE: / 'BDC_CLOSE_GROUP rc ='(999), SY-SUBRC. ENDFORM. " End CREATE_GROUP * Call Transaction Using FORM CALL_TRANSACTION. WRITE: / 'Call Transaction RC ='(999). PERFORM GEN_BDC_DATA. CALL TRANSACTION 'SE38' USING BDCDATA MODE DMODE MESSAGES INTO *
MESSTAB.
WRITE: SY-SUBRC, SY-MSGTY, SY-MSGID, SY-MSGNO, SY-MSGV1. WRITE: / ' ', SY-MSGV2. WRITE: / ' ', SY-MSGV3. WRITE: / ' ', SY-MSGV4. ENDFORM. " End CALL_TRANSACTION *----------------------------------------------------------------* * Create batch input data for * * transaction SE38 * *----------------------------------------------------------------* FORM GEN_BDC_DATA. DATA: LINE LIKE BDCDATA-FVAL. REFRESH BDCDATA.
Page 53 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
*------------------------------------------------------------* * First screen of transaction * *------------------------------------------------------------* PERFORM BDC_DYNPRO USING 'SAPMS38M' '0100'. PERFORM BDC_FIELD USING 'RS38M-PROGRAMM' 'RJBDC999'. PERFORM BDC_FIELD USING 'bdc_cursor' 'chap'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'. *------------------------------------------------------------* * In editor, go to bottom of report * *------------------------------------------------------------* PERFORM BDC_DYNPRO USING 'SAPMSEDT' '2310'. PERFORM BDC_FIELD USING 'RSTXP-TDCOMMLINE' 'BOT'. *------------------------------------------------------------* * Insert line into report * *----------------------------------------------------- ------* PERFORM BDC_DYNPRO USING 'SAPMSEDT' '2310'. PERFORM BDC_FIELD USING 'RSTXP-TDLINECOM(17)' 'I'. *------------------------------------------------------------* * Go to bottom of report again * *------------------------------------------------------------* PERFORM BDC_DYNPRO USING 'SAPMSEDT' '2310'. PERFORM BDC_FIELD USING 'RSTXP-TDCOMMLINE' 'BOT'. *------------------------------------------------------------* * Modify line in report and save report * * (Enter f11 in ok-code) * *------------------------------------------------------------* PERFORM BDC_DYNPRO USING 'SAPMSEDT' '2310'. LINE = 'Batchinput'. LINE+20 = SY-DATUM. LINE+30 = SY-UZEIT. PERFORM BDC_FIELD USING 'RSTXP-TDLINE(17)' LINE. PERFORM BDC_FIELD USING 'BDC_OKCODE' '/11'. *------------------------------------------------------------* * Leave the editor (enter f3 in ok-code) * *------------------------------------------------------------* PERFORM BDC_DYNPRO USING 'SAPMSEDT' '2310'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '/3'. *------------------------------------------------------------* * Leave transaction se38 (enter f15 in * * ok-code) * *------------------------------------------------------------* PERFORM BDC_DYNPRO USING 'SAPMS38M' '0100'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '/15'. ENDFORM. "End GEN_BDC_DATA *----------------------------------------------------------------* * In the batch-input data, start a new screen * *----------------------------------------------------------------* FORM BDC_DYNPRO USING PROGRAM DYNPRO. CLEAR BDCDATA. BDCDATA-PROGRAM = PROGRAM. BDCDATA-DYNPRO = DYNPRO.
Page 54 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
BDCDATA-DYNBEGIN = 'X'. APPEND BDCDATA. ENDFORM. "End BDC_DYNPRO *----------------------------------------------------------------* * In the batch-input data, insert a field * *----------------------------------------------------------------* FORM BDC_FIELD USING FNAM FVAL. CLEAR BDCDATA. BDCDATA-FNAM = FNAM. BDCDATA-FVAL = FVAL. APPEND BDCDATA. ENDFORM.
Enhancements using customer exits Customers potential requirements, which are not included in the standard software, are incorporated in the standard as empty modification shell. Customers can then fill these with their own coding. Enhancements can relate to programs, menus and screens. Enhancements to ABAP/4 Dictionary elements Creation of table appends, text enhancements, customer specific keywords and documentation for data elements and field exits(creation of additional coding for data elements).
2)
1. Do not affect standard SAP Source Code. The code and screens you create are encapsulated as separate objects. 2. Do not affect software upgrades. Customer objects adhere to strict naming conventions.
1)
Types of Exits
2)
Function Module Exits Add functionality to R/3 Applications. CALL CUSTOMER-FUNCTION 001 Menu Exits Add items to pull down menus. Screen Exits Add fields to screens. Keyword Exits Add Documentation to the data elements.
3)
4)
Page 55 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
An add-on project contains a series of exits and the add-ons, such as menu entries or function modules that you develop to hook onto these exits. To create an add-on project, From workbench menu, choose Utilities ! Enhancements ! Project Management Decide which application, application component, or specific standard transaction you would like to add your own functionality. Factors to keep in mind when creating an add-on project. Include an SAP Enhancement package and the customer exits it contains in one project only. The same SAP enhancement may not appear in two different customer projects. Activate the add-on project. When activated, all the exits associated with that will be activated. It is not possible to activate Specific exits only.
1. 2. 3. 4.
Specify the name of the project and choose create. Describe the nature of the project by providing a short descriptive text. Choose Save and assign a transport request. Specify which SAP enhancements packages you want to include in your project by choosing SAP Enhancements 5. Enter the names of all the SAP enhancements in the spaces provided.
After attaching all the add-on functionality to the exits in the project, activate the project. Activating a project turns on all the add-ons. After transporting it from a development system to a production system, it needs to be activated again. If you need to make any changes to any of the add-ons, first deactivate the project, change the add-ons and then activate it.
Page 56 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP
Go to the related main SAP Program . Search for the CALL CUSTOMER FUNCTION... in the program. Go to the user exit ( function module ) you want to modify by double clicking. You will enter into the function module like function exit_sapleinm_001. There will be a statement viz., include zxnnnu01 which will be according to customer naming conventions. Confirm that you want to create the include program. Enter your functions source code in the editor. Save the program. Generate the main SAP Program.
Page 57 of 57
All Rights of Use and Reproduction Reserved. Copyright 1999 PricewaterhouseCoopers LLP