Common SAP R/3 Functions Manual
Common SAP R/3 Functions Manual
Springer
London
Berlin
Heidelberg
New York
Hong Kong
Milan
Paris
Tokyo
William Lawlor
, Springer
William Lawlor, MSc
QA76.76.I57L382003
005.75'85--dc22 2003060693
Apart from any fair dealing for the purposes of research or private study, or criticism or review, as permitted under the
Copyright, Designs and Patents Act 1988, this publication may only be reproduced, stored or transmitted, in any form or
by any means, with the prior permission in writing of the publishers, or in the case of reprographic reproduction in
accordance with the terms of licences issued by the Copyright Licensing Agency. Enquiries concerning reproduction
outside those terms should be sent to the publishers.
Additional material to this book can be downloaded from http://extras.springer.com.
ISBN 1-85233-775-3 Springer-Verlag London Berlin Heidelberg
A member of BertelsmannSpringer Science + Business Media GmbH
springeronline.com
The use of registered names, trademarks etc. in this publication does not imply, even in the absence of a specific statement,
that such names are exempt from the relevant laws and regulations and therefore free for general use.
The publisher makes no representation, express or implied, with regard to the accuracy of the information contained in this
book and cannot accept any legal responsibility or liability for any errors or omissions that may be made.
It is well recognised that programs written to the standard and in the style of the host system
are inherently easier to maintain and upgrade. SAP is no different. Those programs that are
written with as much standard SAP code as possible are better equipped to cope with changes
in the system that could otherwise cause a custom program to malfunction.
Customised code can be notoriously difficult to decipher and change during upgrade proj-
ects. It is much better to utilise existing SAP code, which offers a degree of standardisation in
programs. Reducing the amount of re-coding for problems, for which SAP has already writ-
ten, tested, and provided solutions, in turn eliminates further sources of program errors and
cuts the all-important program development time, and hence costs.
The growing complexity of SAP has resulted in over 105,000 individual function modules
in the 4.6B system, and this number will continue to increase as new features are added to the
system. With no existing or consistent documentation for most of these modules, the author
has undertaken the task of producing the first concise reference of a broad range of modules
designed to solve common problems encountered in most ABAP-programming projects.
The modules chosen were based on analysis of thousands of custom developments and the
author's own many years of ABAP development. The modules described herein offer applica-
tion developers the most complete and consistent documentation available and should be a
welcome addition to any ABAP developer's library.
David Quirke
Project Manager, SAP
v
About the Author
William Lawlor has been involved in the IT industry, since the late 1980s. He has been pro-
gramming and involved in application development for over 10 years in several languages,
such as C and C+ +, Visual Basic, and COBOL. As a consultant, he has spent the last 6 years
working almost exclusively in ABAP. During this time he worked on three full SAP imple-
mentations and numerous version upgrades. He has also developed several ABAP utilities,
such as an authorisation-reporting tool for IMG transactions and a utility program to secure
transportable objects between systems.
He has attended numerous courses provided by SAP in ABAP, BASIS, Finance and Costing,
Sales and Distribution, Material Management, and Production Planning. He currently works
as an ABAP Consultant and Author.
vii
Contents
Contents .........................................................•............•... ix
Introduction xix
Layout of Reference Entries •..........•.•..................•.................•...... xxi
An Introduction to SAP .....•..........................................•............ xxiii
Using Function Modules ........•...........................•....•............•.....xxvii
1. System 1
ABAP4_CALL_TRANSAGION -Initiates a transaction in a separate window 1
ARFC_GET_TID - Returns IP address of the server (in hexadecimal) . .. . .. .. . 2
AUTHORITY_CHECK_DATASET - Checks file access authorization 3
BP_ EVENT_RAISE - Triggers background event. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
CAT_CHECK_RFCDESTINATION - Checks the RFC destinations and connections. . . . . . . . 6
CAT_PING - Checks RFC system and configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
DEQUEUE_ES_PROG - Releases program locks 8
ENQUEUCES_PROG - Prevents parallel execution of program 8
FTP_COMMAND - Executes a command on the FTP server 9
FTP_CONNEG - Opens connection to the FTP server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 10
FTP_DISCONNEG - Closes connection to the FTP server 12
GET_JOB_RUNTIMLINFO - Retrieves detailed job information.. . .. .. . .. .. 13
GULEXEC - Starts an external program asynchronously 13
GULGET_DESKTOP_INFO - Returns information about the end-users desktop . . . . . . . .. 14
GULRUN - Starts program with ShellExecute 16
GWY_READ_CONNEGIONS - Checks gateway connection 17
HLP_MODE_CREATE - Creates another session in system 18
IW_CGET_FRONTEND_VERSION - Version of SAP front-end installed on a PC 19
RFCMAIL - Sends e-mail to another SAP system 20
RSPO_FIND_SPOOL_REQUESTS - Finds a spool number 20
RSPO_OUTPUT_SPOOL_REQUEST - Outputs same request on a different printer. .. 22
RSPO_RPRINT_SPOOLREQ - Triggers spool to print automatically ..... ,. .. . 23
SAPWL_GET_SUMMARY_STATISTIC - Summary of object usage statistics 23
SAPWL_WORKLOAD_GET_DIREGORY - Timeframe of statistics on SAP database 25
SAPWL_WORKLOAD_GET_STATISTIC - Object usage statistics 26
SHOW_JOBSTATE - Checks the status of a job 27
SO_SPOOl_READ - Returns printer spool information 29
ix
x Contents
2. Conversions.................................................................... 47
BAPLCURRENCY_CONV_TO_EXTERNAL - Converts currency format to external format 47
BAPLCURRENCY_CONV_TO_INTERNAL - Converts currency format to internal format 48
CF_UT_UNIT_CONVERSION - Converts material unit quantities 49
CONVERSION_EXIT_ALPHAJNPUT - Converts number to a string filled with zeroes 50
CONVERSION_EXIT_ALPHA_OUTPUT - Converts number with zeroes into an integer 51
CONVERSION_EXIT_AUART_INPUT - Converts sales document type to SAP format 51
CONVERSION_EXIT_AUART_OUTPUT - Converts sales document type to display format 52
CONVERSION_EXIT_CUNIT_INPUT - Converts external unit to SAP's internal unit 53
CONVERSION_EXIT_CUNIT_OUTPUT - Converts internal unit to commercial unit. . . . . . . . .. 54
CONVERSION_EXIT_LUNIT_INPUT - Converts technical unit for internal unit 55
CONVERSION_EXILLUNIT_OUTPUT - Converts internal unit to technical unit 56
CONVERSIONJAaOR_GET - Returns conversion factors for a unit 57
CONVERT_ABAPSPOOUOB_2_PDF - Converts ABAP spool output to PDF 59
CONVERT_OTFSPOOUOB_2_PDF - Converts an OTF (SAPscript) spool to PDF 61
CONVERT_TOJOREIGN_CURRENCY - Converts local currency to foreign currency 63
CONVERT_TO_LOCAL_CURRENCY - Converts foreign currency to local currency 64
CURRENCY_AMOUNT_SAP_TO_IDOC - Converts currency to IDOC format 66
CURRENCY_CODUSO_TO_SAP -ISO currency code to SAP's currency code 67
CURRENCY_CODE_SAP_TO_ISO - SAP currency code to ISO currency code 68
DATCSTRING_CONVERT - Converts string date into DATE type 68
DIMENSION_CHECK - Checks internal unit of dimension 69
DIMENSION_GET - Retrieves internallD of specified dimension 71
DIMENSION_GET_FOR_UNIT - Textual description of dimension 71
HR_ROUND_NUMBER - Rounds a number according to rules 72
HRCM_AMOUNT_TO_STRING_CONVERT - Converts an amount to a character string 73
HRCM_STRING_TO_AMOUNT_CONVERT - Converts a character string to an amount , 74
MATERIAL_UNIT_CONVERSION - Converts base unit to alternative unit...... 75
MD_CONVERT_MATERIAL_UNIT - Conversion of material units. . . . . . . . . . . . . . . . . . . . . . . . . 76
ROUND - Rounds value to a number of decimal places 77
Contents xi
4. Files 151
C13ZJILCDOWNLOAD_ASCII - Downloads a file in ASCII format 151
C13Z_FILE_DOWNLOAD_BINARY - Downloads a file in binary format. . . . . . . . . . . . . . . . . .. 155
C13ZJILCUPLOAD_ASCII - Uploads a file in ASCII format. . . . . . . . . . . . . . . . . . . . . . . . . . .. 156
C13Z_FILE_UPLOAD_BINARY - Uploads a file in binary format. . . . . . . . . . . . . . . . . . . . . . . .. 157
DOWNLOAD - Downloads a file to the PC 157
EPS_GET_DIRECTORY_L1STING - Lists filenames from the application server. . . . . . . . . . .. 160
EPS_GETJILE_ATTRIBUTES - Returns attributes for a file 161
GULCREATE_DIRECTORY - Creates a directory on the presentation server 162
GULDELETE_FILE - Deletes a file on the presentation server. . . . . . . . . . . . . . . . . . . . . . .. 164
GUI_DOWNLOAD - Downloads a file to the presentation server. . . . . . . . . . . . . . . . . . . .. 165
GULREMOVCDIRECTORY - Deletes a directory in the presentation server 166
GULUPLOAD - Uploads a file from the presentation server 166
LIST_DOWNLOAD - Downloads report to local file. . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . .. 167
PROFILE_GET - Reads an entry in an INI file on the frontend 168
PROFILE_SET - Writes an entry to an INI file on the frontend 169
RS_DELETE_PROGRAM - Deletes an ABAP program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 170
RSPO_DOWNLOAD_SPOOUOB - Downloads program spool to a file. . . . . . . . . . . . . . . . . .. 171
RZL_READ_DIR - Reads a directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 172
RZL_READ_FILE - Reads a file 173
RZL_WRITEJILE_LOCAL - Saves internal table to the presentation server 174
SO_SPLlTJILE_AND_PATH - Splits a path into a filename and a path 175
Contents xiii
S. Lists 189
DYNP_VALUES_READ - Reads screen values before PAl transport 189
DYNP_VALUES_UPDATE - Changes screen field contents without PBO . . . . . . . . . . . . . . .. 193
F4IUNT_TABLE_VALUE_REQUEST - Standard help at process on value-request 193
HR_DISPLAY_BASIC_LIST - Provides a table control for data 194
K_ABCDOKU_SHOW - Reads documentation from local program. . . . . . . . . . . . . . . . . .. 195
L1ST_FROM_MEMORY - Retrieves the output of report from memory 196
L1ST_TO_ASCI - Converts an ABAP report to ASCII ................................• 197
RPY_DYNPRO_READ - Reads screen objects, including screen flow •....•............ 198
RS_COVERPAGE_SELEaIONS - Returns the selection parameters for a report 199
RS_CREATE_VARIANT - For creating dynamic variants ...•........................... 200
RS_REFRESH_FROM_SELEaOPTIONS - Returns the selection parameters for a report. . .. 202
RS_SET_SELSCREEN_STATUS - Deactivates function codes on screen 203
RS_TOOL_ACCESS - Reads documentation from another program 204
RS_VARIANT_CONTENTS - Values of a variant returned in a table 206
RS_VARIANT_DELETE - Deletes a variant from a program 206
RS_VARIANT_EXISTS - Checks whether a variant exists for a report 207
RS_VARIANT_TEXT - Returns short description of variant 207
RS_VARIANT_VALUES_TECH_DATA - Reads variant parameters of a report 208
RZL_SUBMIT - Submits a remote report for execution 209
SAPGULPROGRESS_INDICATOR - Displays a progress bar on the SAP GUI 209
SAVE_LIST - Saves report as list container 210
VRM_SET_VALUES - Customises values on a drop-down field 211
WRITE_LIST - Contents from LIST_FROM_MEMORY 212
WWWJTAB_TO_HTML - Converts internal table to HTMl format ................•..•. 213
WWW_L1ST_TO_HTML-Converts report list to HTMl format ......................•.. 214
Numbers . . . . . . . . .. . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 328
CLOI_PUT_SIGN_INJRONT -Moves negative sign of a number. . . . . . . . . . . . . . . . . . . . . .. 328
G_DECIMAL_PLACES_GET -Number of decimal places set for currency 329
NUMERICCHECK - Returns the format of a number . . . . . . . . . . . . . . . . . .. 329
QFOS_RANDOM - Returns a random number between 0 and 1 330
QFOS_RANDOM_INTEGER - Returns a random number. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 331
Printing 332
ADDRESS_INTO_PRINTFORM - Formats an address for printing. . . . . . . . . . . . . . . . . . . . . . .. 332
FM_SELECTION_CRITERIA_PRINT - Displays criteria used in selection screen 333
GET_PRINT]ARAMETERS - Reads and changes spool print parameters 334
LOAD_PRINT]ARAMETERS - User default printer settings 336
PRINT_SELECTIONS - Builds criteria table used in selection screen '" 337
SET_PRINT_PARAMETERS - Sets users print settings for a report 337
STORE_PRINT_PARAMETERS - Saves users current print settings 338
Various 366
CALL_BROWSER - Calls default web browser or file manger 366
CHANGEDOCUMENT_READ_HEADERS - Gets change document header 367
CHANGEDOCUMENT_READ_POSITIONS - Gets change document details 369
CL_TABLCEDITOR - Displays and edits internal table data 370
CSAP_MAT_BOM_READ - Displays simple material BOMs 371
DDIFJIELDINFO_GET - Information about tables 372
FORMAT_MESSAGE - Formats error message for display 373
K_WERKS_OF_BUKRSJIND - Lists all plants for a given company code 374
MATERIAL_BTCLSELECTION_NEW - Selects the correct views on material master 375
MATERIAL_BTCLTEXT - BDC fields and OK codes for materials 377
REGISTRY_GET - Reads an entry from the registry 378
REGISTRY_SET - Sets an entry in the registry '" 379
RV_ORDER_FLOW_INFORMATION - Reads sales document flow 380
WRITE_MESSAGE - Formats error message for display 381
This book is a reference guide to the functions provided by the SAP R/3 system.
The SAP R/3 (SAP for short) system provides many built-in functions (approximately
237,000 as of release 4.6C) to assist in the rapid development of ABAP-programming projects,
by reducing the amount of "reinventing the wheel" code that would otherwise be required.
Some of the functions are extremely specific, written by SAP to solve a particular problem
in a single program. Many of them, however, are generalised enough for repeated use in a variety
of circumstances in ABAP programs. These are the foci of this book.
The problem of using SAP's functions is that most of them are either poorly documented
or have no documentation at all, and there is almost no information on what functions are
actually available, their purpose, or their method of operation. It is often a long and arduous
process of investigation, trial and error, and sheer luck to discover a suitable function.
This book intends to change all that by providing a central resource for the most commonly
used SAP functions. Each function contains a summary of its purpose, a longer detailed descrip-
tion or other pertinent information (such as if the function has been superseded or is obsolete), an
explanation of the most commonly used parameters (input, output, changing, tables) with a list
of possible values passed to them (where appropriate), a fully worked example of the function in
action, and ending with references to other related functions documented elsewhere in the book.
Contained within these pages are those functions that are most likely to be required in your
ABAP-programming projects. They include time, date, and numeric conversions, popup dia-
logue boxes, uploading and downloading MS Excel and ordinary file data, sending e-mail
onto the Internet, date and time calculations, and much more.
Functions are arranged alphabetically within each chapter. So if you need to know on what
day Easter will fall for any year, GET_EASTER_DATE will be found in the Date and Time routines
chapter. Similarly, to upload Excel data to an ABAP-internal table, look at ALSM_EXCEL_
TO_INTERNAL_TABLE in the Office Integration chapter.
Lists describing the most commonly used parameters to a function are also provided. These
lists offer a clear textual description of the parameter, which can be of help to the more obscurely
named parameters. In some modules, parameter tables list the values that an input parameter
takes, and describes each individually.
Each function described also contains a simple but fully working example (4.6B). To offer
the reader a more complete understanding of the function, some closely related modules (e.g.
the RSPO_ >I- group) are coded into one complete program, demonstrating how the functions
interact with each other. Each function ends with references to other related documented
functions, if appropriate.
This information often takes years to accumulate. The seasoned ABAPer should have at
least seen some of these functions before, and the beginner now has instant access to a host of
cross-application functionality, which will be of immense value in any ABAP-programming
project, or thumbed through as a reference at leisure, away from the Pc.
xix
Layout of Reference Entries
I~--------Summa~
Uploads file from the application server.
II r - - - - Desaiption
Replaces WS_UPLOAD.
Parameten
EXPORTING
FI LENAME Path and fllename to download
FIL[TYPE Fi le type:
Value Meanlng
ASC ASCII (default!
BIN Binary
DBF DBASE
IBM ASC I I with I BM code page convers i on
WKI Spreadsheet
OAT ASCII data table with column tab
TABLES
DATA_TAB Table of data
Example
REPORT ZEXAMPLE.
DA TA, BEG I N OF !TAB OCCU RS O.
COLA(\O).
COLB(\O) •
ENO OF !TAB.
Set Also
~ UPLOAD, WS_UPLOAD
Y I See also: Names of related functions documented in the book
xxi
An Introduction to SAP
The SAP name (pronounced S-A-P not "sap") is derived from the German "Systeme,
Andwendungen, Produkte in der Datenverarbeitung': or in English, "Systems, Applications,
and Products in Data Processing".
SAP AG, the company behind the system, was founded in 1972 by five ex-IBM employees.
Their global headquarters is based in Walldorf, Germany and has subsidiaries in over 50 coun-
tries around the world. SAP AG is now the third largest software maker in the world with over
17,500 customers, including more than half of the world's 500 top companies.
SAP R/3 is the leading example of an Enterprise Resource Planning (ERP) system, used by
medium to large companies to track and manage in real time, business information, such as
sales, production, and financial data. The R/3 system is known simply as SAP. It consists of
suites of major business applications, which can be viewed as a tightly integrated collection
of logical business modules. A module is a set of programs (or transactions) that deal with the
same area of business functionality, such as Financial Accounting, Materials Management,
and Human Resource Management. The software was developed with this idea of componen-
tisation of business functions in mind.
Each module, which is based on detailed analyses of industry best practices, implements
a specific segment of enterprise operations and are in themselves, extremely complex. The
modules work in close cooperation and this comprehensive integration offers complete har-
monisation across all business functions. For example, when a vendor completes a purchase
order, inventory levels are adjusted in Materials Management, and triggers the issuing of an
invoice from Financial Accounting.
There are 11 modules in SAP, usually referred to by a two-letter acronym. The BASIS sys-
tem could also be considered a module, but is the heart of the SAP system and is not normally
evident to users. All these modules need not be implemented in a company:
xxiii
xxiv An Introduction to SAP
SAP is delivered to customers with selected standard processes turned on and it is the
process of configuration which gives SAP its great flexibility. This configuration is done by
business analysts, people experienced in identifying and mapping (or where necessary, chang-
ing) business processes. They customise the modules by adjusting the thousands of possible
values within each module. This phase precedes going live and no programming is normally
required at this stage.
The SAP R/2 system, that was released into the German market in 1979, was designed
purely to operate as a mainframe system, and was the first integrated, enterprise-wide com-
puter system. In line with the trends in technology towards the end of the 1980s, SAP AG
launched R/3 in 1992, which runs under the three-tier client/server paradigm. These tiers
include:
The programming language ABAP/4 (or now officially just called ABAP, "Advanced Business
Application Language") originated in the R/2 system, and was used exclusively for reporting.
With each release of SAP, the scope of the language has expanded to include new features, and
is now a modern fourth-generation language with object-oriented functionality.
Basic programs and reports are written entirely in ABAP and do not require any additional
assistance from the numerous tools and utilities within SAP. Usually, the ABAP editor
(Transaction SE38) is enough. Complex programs, called Transactions, require several develop-
ment tools, such as Screen Painter (Transaction SE51) to create and design interactive screens and
Menu Painter (Transaction S£41) to create custom screen titles and menu bars for each screen.
As with all modern-programming languages, SAP comes with a host of pre-written proce-
dures available for reuse in ABAP programs, called Function Modules, which can be accessed
from Transaction SE37. A function module is an independent routine that can be called from
within an ABAP program (using the CALL FUNCTION statement) to perform a specific task.
Examples include determining the IP address of a terminal, to finding the number of seconds,
hours, days, months and years between two dates.
Each function module is unique and is global to all ABAP programs, which is to say that no
special "include" statements need be inserted into the beginning of ABAP programs, unlike
for some functions in the C language, for example. Each module forms part of a function
group (pool), which is a way of grouping together modules with similar functionality. These
can be accessed from Transaction SE80.
Most function modules can be tested independently of the calling program, within
Transaction SE37. Exceptions defined in the module can be used to flag error conditions.
These errors are not necessarily ABAP coding errors, but could be a legitimate response coded
in the function module to certain conditions.
For example, if the date 31 September is passed into a function, the module can determine
that this is an invalid date and raise it as an exception, to be handled by the calling program.
Usually, each exception is given a unique (per module) numerical value, which is placed in the
system variable SY-SUBRC. The calling program can then examine the contents of this vari-
able to determine whether or not an exception has been triggered and, if so, which exception,
and take the appropriate action. A value of zero in this variable signifies that no errors
occurred in the function module.
A program snippet calling a function and handling errors would typically look something
like this:
REPORT ZEXAMPLE.
DATA V_YEARS TYPE I.
PARAMETERS: BIRTHDAY LIKE SY-DATUM.
xxvii
xxviii Using Function Modules
There is no guarantee that a desired function module exists, but SAP has developed a module
to cover almost every conceivable requirement, sometimes more than one to do a similar job.
There is no sure fire way of finding the module you need either, but generally the best method
is to enter a string containing the likely text of the function module in the function name box
in S£37, surrounded by asterisks (*) for wild-card characters.
If a list of functions is returned, simply double click on the function name, click the test
button, and enter appropriate input values. Check the results to determine if it suits your
requirements. The function module can be easily copied into a program by selecting the
Pattern button in Transaction S£38 and entering the function's name. All import, export, and
exception parameters are automatically pasted into the program, Optional parameters are
commented out (usually in a blue colour), while required parameters are coloured black,
ready to be assigned a value,