* raise
* message ... raising
Using the raise Statement
Use the raise statement to exit the function module and set the value of sy-subrc on return.
Syntax for the raise Statement
The following is the syntax for the raise statement.
raise xname.
where:
* xname is the name of the exception to be raised.
The following points apply:
* xname can be any name that you make up. It does not have to be previously defined anywhere. It can be up to 30 characters in length. All characters are allowed except " ' . , and :.
* Do not enclose xname within quotes.
* xname cannot be a variable.
When the raise statement is executed, control returns immediately to the call function statement and a value is assigned to sy-subrc based on the exceptions you have listed there. Values assigned to export parameters are not copied back to the calling program. Listings 1.7 and 1.8 and Figure 1.9 illustrate how this happens.
Listing 1.7 How to Set the Value of SY-SUBRC from Within a Function Module
1 report ztx2007.
2 parameters parm_in default 'A'.
3 data vout(4) value 'INIT'.
4 call function 'Z_TX_2008'
5 exporting
6 exname = parm_in
7 importing
8 pout = vout
9 exceptions
10 error_a = 1
11 error_b = 4
12 error_c = 4
13 others = 99.
14 write: / 'sy-subrc =', sy-subrc,
15 / 'vout =', vout.
Listing 1.8 This Is the Function Module Called from Listing 1.7
1 function z_tx_2008.
2 *"------------------------------------------------------------
3 *"*"Local interface:
4 *" IMPORTING
5 *" VALUE(EXNAME)
6 *" EXPORTING
7 *" VALUE(POUT)
8 *" EXCEPTIONS
9 *" ERROR_A
10 *" ERROR_B
11 *" ERROR_C
12 *" ERROR_X
13 *"------------------------------------------------------------
14 pout = 'XXX'.
15 case exname.
16 when 'A'. raise error_a.
17 when 'B'. raise error_b.
18 when 'C'. raise error_c.
19 when 'X'. raise error_x.
20 endcase.
21 endfunction.
The code in Listings 1.7 and 1.8 produce this output, if you specify a value of A for parm_in:
sy-subrc = 1
vout = INIT
* In Listing 1.7, line 4 takes the value from parm_in and passes it to the function module z_tx_2007. Control transfers to line 1 of Listing 1.8.
* In Listing 1.8, line 14 assigns a value to the pout parameter. This parameter is passed by value, so the change is only to the local definition of pout. The original has not yet been modified.
* In Listing 1.8, line 15 examines the value passed via parameter exname. The value is B, so line 17-raise error_b-is executed. Control transfers to line 9 of Listing 1.7. Because the raise statement has been executed, the value of pout is not copied back to the calling program, thus the value of vout will be unchanged.
* In Listing 1.7, the system scans lines 10 through 13 until it finds a match for the exception named by the just-executed raise statement. In this case, it's looking for error_b. Line 11 matches.
* On line 11, the value on the right-hand side of the equals operator is assigned to sy-subrc. Control then transfers to line 20.
The special name others on line 13 of Listing 1.7 will match all exceptions not explicitly named on the exceptions addition. For example, if line 7 of Listing 20.8 were executed, exception error_x would be raised. This exception is not named in Listing 1.7, so others will match and the value of sy-subrc will be set to 99. You can code any numbers you want for exception return codes.
If an export parameter is passed by value, after a raise its value remains unchanged in the calling program even if a value was assigned within the function module before the raise statement was executed. If the parameter was passed by reference, it will be changed in the caller (it has the Reference flag turned on in the Export/Import Parameters screen). This effect is shown in Listing 20.7. The value of pout is changed in the function module and, if a raise statement is executed, the changed value is not copied back into the calling program.
Click Here to Read More !!!!
ABAP,ABAP report,Interactive Report,ALV grid,ALV list,IDOC,User Exit,RFC,Smartform,sapscript,ABAP Performance,Remote Function Module( RFC ),Function Module,Modularization techniques,ABAP tools,ALV report Generator,ABAP Interview Questions,BDC,BAPI,ALE,BADI, EDI,InternalTable,DataStructure,LSMW,Domain,DataElement,Basis and Administration ,ABAP HR development,ABAP Debugger,BW,ExceptionHandling,Download FI, CO, MM, PP, SD, PM, PS, QM, SM, HR, BW, APO,ABAP Tutorial
Search on this Website
Saturday, February 16, 2008
Using the raise Statement in Function Module
Thursday, July 12, 2007
Standard Function Module : BDC , Miscellaneous ,File , Calender
(1) BDC
(i)BDC_RECORD_PLAY Run A BDC Session using a Session name and the QID
(ii)BDC_RECORD_FUNCTION_CREATE Create a FM for that BDC recording.
(iii)BDC_RECORD_DATA_CREATE Creating test data for BDC.
(iv)ENQUEUE_BDC_QID
(v)BDC_START_GROUP Calling a BDC QID:
1. First we need to ENQUEUE the BDC using QID using the FM 'ENQUEUE_BDC_QID'
2.To run in background we need to open a JOB and submit the code to the standard program 'RSBDCBTC'
(vi)RSBDCBTC This program will process the BDC session in background.
(vii)PERFORM enqueue_tab IN PROGRAM saplsvix USING 'ZSDT_STK_REQ' v_key c_e c_e. Perform to lock a single entry of table-Note this case is only applicable if there is a maintenance view of the table.
(viii) TH_REMOTE_TRANSACTION Run a transaction on a remote server. Optionally provide BDC data to be used in the transaction
(2) Miscellaneous
(i)HELP_VALUES_GET_NO_DD_NAMEThis is used to display the F4 values for any field.
(ii)Z_MESSAGE_DISPLAY To display Message Logs as an ALV.
(iii)DD_SHLP_CALL_FROM_DYNPThis function is used to provide F4 help using matchcodes.
(iv)WWW_LIST_TO_HTMLAfter running a report, call this function to convert the list output to HTML.
(v)WS_VOLUME_GETGet the label from a frontend device.
(vi)WS_MSG Create a dialog box in which you display an one line message
(vii)WS_EXECUTE execute a program on a windows PC
(viii)WS_EXCEL Start EXCEL on the PC
(ix)WRITE_LIST Useful for writing out the list contents that result from the function LIST_FROM_MEMORY.
(x)UNIT_CONVERSION_SIMPLEconvert weights from one UOM to another.
(xi)TMP_GUI_DIRECTORY_LIST_FILESRetrieve all of the files and subdirectories on the Presentation Server (PC) for a given directory. When a value other than * or *.* is used for the filter, you will not get any directories, unless they match your wildcard filter. For example, if you entered *.png, then only files and directories that end in png will be returned by the function
(xii)TH_USER_LISTShow which users are logged into an app server
(xiii) TH_USER_INFOGive information about the current user (sessions, workstation logged in from, etc)
(xiv) TH_DELETE_USER Logoff a user. Similar results to using SM04.
(xv) TERMINAL_ID_GETReturn the terminal id
(xvi) SXPG_COMMAND_LIST_GET Select a list of external OS command definitions.
(xvii)SXPG_COMMAND_EXECUTECheck a user's authorization to use a command, as in SXPG_COMMAND_CHECK. If the authorization check is successful, then execute the command on the target host system.
(xviii) SXPG_COMMAND_DEFINITION_GETRead the definition of a single external OS command from the R/3 System's database.
(xviv) SXPG_COMMAND_CHECK Check whether the user is authorized to execute the specified command on the target host system with the specified arguments.
(xx)SXPG_CALL_SYSTEM you can check the user's authorization for the specified command and run the command. The command runs on the host system on which the function module is executed. The function module is RFC capable. It can therefore be run on the host system at which a user happens to be active or on another designated host system at which an R/3 server is active.
(xxi)TH_POPUP Display a popup system message on a specific users screen.
(3)File
WS_FILENAME_GET Call File Selector
WS_FILE_DELETE Delete File at the Frontend
UPLOAD_FILES Will load one or more files from app or presentation server
UPLOAD upload a file to the presentation server (PC)
(4)Calender
WEEK_GET_FIRST_DAYFor a given week (YYYYMM format), this function returns the date of the Monday of that week.
(5)System Information
TH_ENVIRONMENT Get the UNIX environment
Click Here to Read More !!!!
Wednesday, July 11, 2007
Standard Function Module :- text processing,Workflow,Smartforms/Sapscript,SD,Application Log Maintenance
(1) Miscellaneous
(i)VIEW_MAINTENANCE_CALL Call of the complete maintenance dialog- just like SM30
(ii)ABAP_DOCU_DOWNLOAD Download ABAP documentation in HTML format.
(iii)AUTHORITY_CHECK_TCODE checks whether a user has authorisation to a transaction.
(iv)STATUS_TEXT_EDIT This gets the statuses of the document like Work Orders.
(v)WFMC_MESSAGE_SINGLE Pass the NAST as the parameter and get the print.
(vi)FIEB_PASSWORD_ENCRYPT
(vi)FIEB_PASSWORD_DECRYPT
(2)Text Processing
(i)READ_TEXT Read long text of an object into an internal table
(ii)SAVE_TEXT Create or change long text for an object
(iii)DELETE_TEXT Delete long text of an object
(iv)EDIT_TEXT_INLINE Edit online the long text of an object
(v)READ_TEXT_INLINE Called before EDIT_TEXT_INLINE to get the long text
(vi)LIST_TO_ASCI Stores the report output into an internal table. This can be used to capture a list output and send it via email.
(3)Workflow
(i)SWE_EVENT_CREATE Create an event from any application or system program
(ii)SWE_TEMPLATE Function group for holding templates. The FM's in this can be copied to create various FM's required for workflow programming
(iii)BAPI_ORGUNITEXT_DATA_GET Get data on organizational unit, returns the organizational structure in an internal table., This can be used for agent determination.
(4)Smartforms/Sapscript
(i)SSF_FUNCTION_MODULE_NAME Used in Smartforms. This FM is calle din a print program. It generates a function module which is actually a generation of the SMARTFORMS which can be called in print program.
(5)SD
(i)CO_ZF_ORDER_LOCK_MULTI Checks if the order is locked. Check sy-msg2 and sy-msg1 to check if the order was locked.
(ii)MD_STOCK_REQUIREMENTS_LIST_API Determines material stock availability for in the supply plant. The result should be similar to MD04.
(6)Application Log Maintenance
(i)APPL_LOG_DELETE With this function module you delete logs in the database according to specified selection conditions
(ii)APPL_LOG_DISPLAY With this function module you can analyze logs in the database.
(iii)APPL_LOG_DISPLAY_INTERN With this function module you can analyze logs in local memory, e.g. when you have only collected log records at runtime and do not want to write to the database.
(iv)APPL_LOG_INIT This function module checks whether the specified object or sub-object exists and deletes all existing associated data in local memory.
(v)APPL_LOG_READ_DB With this function module you read the log data in the database for an object or sub-object according to specified selection conditions.
(vi)APPL_LOG_READ_INTERN With this function module you read all log data whose log class has at least the specified value, from local memory, for the specified object or sub-object.
(vii)APPL_LOG_SET_OBJECT With this function module, you create a new object or sub-object for writing in local memory. With a flag you can control whether the
(viii)APPL_LOG_WRITE_... messages are written in local memory or are output on the screen.
(ix)APPL_LOG_WRITE_DB With this function module you write all data for the specified object or sub-object in local memory to the database. If the log for the object or sub-object in question is new, the log number is returned to the calling program.
(x)APPL_LOG_WRITE_HEADER With this function module, you write the log header data in local memory.
(xi)APPL_LOG_WRITE_LOG_PARAMETERS With this function module, you write the name of the log parameters and the associated values for the specified object or sub-object in local memory. If this function module is called repeatedly for the same object or sub-object, the existing parameters are updated accordingly. If you do not specify an object or sub-object with the call, the most recently used is assumed.
(xii)APPL_LOG_WRITE_MESSAGE_PARAMS With this function module you write a single message, with parameters, in local memory. Otherwise the function module works like
(xiv)APPL_LOG_WRITE_SINGLE_MESSAGE.
(xv)APPL_LOG_WRITE_MESSAGES With this function module you write one or more messages, without parameters, in local memory.
(xvi)APPL_LOG_WRITE_SINGLE_MESSAGE With this function module you write a single message, without parameters, in local memory. If no header entry has yet been written for the object or sub-object, it is created. If you do not specify an object or sub-object with the call, the most recently used is assumed.
Click Here to Read More !!!!
Tuesday, July 10, 2007
SAP Standard Function Module-Selection Screen ,System Information
(1) Selection Screen
(a)F4IF_INT_TABLE_VALUE_REQUEST *New
"This FM gives an F4 help for a parameter/select-option for a field which doesnot have a valuetable in DDIC. The FM can be used as under:
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = inttable field name within quotes
value_org = 'S'
TABLES
value_tab = fetched values of parnr
return_tab = any int.table of this type
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3. return_tab contains the field value selected by the user at run-time. field fieldval has to be read from this internal table and assigned to the respective selection-screen field. "
(b)RS_REFRESH_FROM_SELECTOPTIONS
Stores the selection screen data in an internal table.
(c) RS_LIST_SELECTION_TABLE Writes selection screen contents on the output list. This will help the user see the selection criteria of the report along with the program output.
Selection Screen RS_SET_SELSCREEN_STATUS Sets another GUI status defined in the same ABAP program, or deactivates functions of the standard GUI status.
RS_VARIANT_EXISTS Checks whether a variant exists
RS_CREATE_VARIANT Checks whether a variant exists
RS_CHANGE_CREATED_VARIANT Change a created variant
RS_EXTERNAL_SELSCREEN_STATUS Sets a GUI status defined in an external function group. You must use the SET PF-STATUS statement to set the status in a special function module in this function group. You must pass the name of the function module that sets the status as a parameter to the function module RS_EXTERNAL_SELSCREEN_STATUS.
(2) System Information
TH_SYSTEM_INFO Gets the SAP system information like the OS, database etc
DYNP_VALUES_READ Captures field contents of a SAP screen into an internal table. This is especially useful in field exits.
TH_CREATE_MODE Creates a new SAP session.
CONVERSION_EXIT_ALPHA_INPUT/OUTPUT Adds/ removes leading zeroes from a numeric string
CONVERSION_EXIT_CUNIT_INPUT/OUTPUT Converts between external and internal representations of unit of measure.
Click Here to Read More !!!!
Monday, May 28, 2007
Modularization Techniques
Processing blocks that are called from ABAP programs:
- Subroutines
- Function modules
- Methods
Procedures
Procedures contain a set of statements, and are called from other ABAP programs.
The processing blocks that you call from ABAP programs are called procedures
You define procedures in ABAP programs. When the program is generated, they remain as standalone modules. You can call procedures in the program in which they are defined, or from external programs. Procedures have an interface for passing data, and can also contain local data.
ABAP contains the following kinds of procedures:
Subroutines are principally for local modularization, that is, they are generally called from the program in which they are defined. You can use subroutines to write functions that are used repeatedly within a program. You can define subroutines in any ABAP program.
Function modules are for global modularization, that is, they are always called from a different program. Function modules contain functions that are used in the same form by many different programs. They are important in the R/3 System for encapsulating processing logic and making it reusable. Function modules must be defined in a function group, and can be called from any program.
Methods describe the functions and behavior of classes and their instances in ABAP Objects. Methods must be defined in classes. When you call them, you must observe certain special rules of object-oriented programming.
Subroutines are procedures that you can define in any ABAP program and also call from any program. Subroutines are normally called internally, that is, they contain sections of code or algorithms that are used frequently locally. If you want a function to be reusable throughout the system, use a function module.
subroutine is a block of code introduced by FORM and concluded by ENDFORM.
FORM
...
ENDFORM.
subroutines cannot be nested. You should therefore place your subroutine definitions at the end of the program
Calling Subroutines
PERFORM... [USING ...
Subroutines can call other subroutines (nested calls) and may also call themselves (recursive calls). Once a subroutine has finished running, the calling program carries on processing after the PERFORM statement. You can use the USING and CHANGING additions to supply values to the parameter interface of the subroutine.
Function modules are procedures that are defined in function groups (special ABAP programs with type F) and can be called from any ABAP program. Function groups act as containers for function modules that logically belong together.
Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Function Builder. The actual ABAP interface definition remains hidden from the programmer. You can define the input parameters of a function module as optional. You can also assign default values to them. Function modules also support exception handling. This allows you to catch certain errors while the function module is running.
Function groups are containers for function modules. You cannot execute a function group. When you call an function module, the system loads the whole of its function group into the internal session of the calling program (if it has not already been loaded).
This is used by the system to create the components of the group (main program and corresponding include programs). When you create a function group or function module in the Function Builder , the main program and include programs are generated automatically.
The main program SAPL
L
L
L
The include programs L
All of the function modules in a function group can access the global data of the group. For this reason, you should place all function modules that use the same data in a single function group.
Function modules can have the following interface parameters:
Import parameters. These must be supplied with data when you call the function module, unless they are flagged as optional. You cannot change them in the function module.
Export parameters. These pass data from the function module back to the calling program. Export parameters are always optional. You do not have to receive them in your program.
Changing parameters. These must be supplied with data when you call the function module, unless they are flagged as optional. They can be changed in the function module. The changed values are then returned to the calling program.
Tables parameters. You use these to pass internal tables. They are treated like CHANGING parameters. However, you can also pass internal tables with other parameters if you specify the parameter type appropriately.
You can specify the types of the interface parameters, either by referring to ABAP Dictionary types or elementary ABAP types. When you call a function module, you must ensure that the actual parameter and the interface parameters are compatible.
Interface parameters are, by default, passed by value. However, they can also be passed by reference. Tables parameters can only be passed by reference. You can assign default values to optional importing and changing parameters. If an optional parameter is not passed in a function module call, it either has an initial value, or is set to the default value.
Exceptions are used to handle errors that occur in function modules. The calling program checks whether any errors have occurred and then takes action accordingly.
Calling Function Modules in ABAP
To call a function module, use the CALL FUNCTION statement:
CALL FUNCTION
You can specify the name of the function module
After EXPORTING, you must supply all non-optional import parameters with values appropriate to their type. You can supply values to optional import parameters if you wish.
After IMPORTING, you can receive the export parameters from the function module by assigning them to variables of the appropriate type.
After CHANGING or TABLES, you must supply values to all of the non-optional changing or tables parameters. When the function module has finished running, the changed values are passed back to the actual parameters. You can supply values to optional changing or tables parameters if you wish.
You can use the EXCEPTIONS option to handle the exceptions of the function module. If an exception
If you specify of ERROR_MESSAGE in the exception list you can influence the message handling of function modules. Normally, you should only call messages in function modules using the MESSAGE ... RAISING statement. With ERROR_MESSAGE you can force the system to treat messages that are called without the RAISING option in a function module as follows:
- Messages of classes S, I, and W are ignored (but written to the log in a background job).
- Messages of classes E and A stop the function module as if the exception ERROR_MESSAGE had occurred (SY-SUBRC is set to
).
If you specify OTHERS after EXCEPTIONS, the system assigns a single return code to all other exceptions that you have not specified explicitly in the list.
You can use the same number
You can trigger exceptions in the function module using either the RAISE or the MESSAGE ... RAISING statement. If the calling program handles the exception, both statements return control to the program. The MESSAGE ..... RAISING statement does not display a message in this case. Instead, it sets the following system fields:
- Message class ® SY-MSGID
- Message type ® SY-MSGTY
- Message number ® SY-MSGNO
- SY-MSGV1 to SY-MSGV4 (contents of fields
to , included in a message).
You can use the system fields to trigger the message from the calling program.
Raising Exceptions
There are two ABAP statements for raising exceptions. They can only be used in function modules:
RAISE
and
MESSAGE..... RAISING
The effect of these statements depends on whether the calling program handles the exception or not. If the name
If the calling program does not handle the exception
- The RAISE statement terminates the program and switches to debugging mode.
- The MESSAGE ..... RAISING statement display the specified message. How the processing continues depends on the message type.
If the calling program handles the exception, both statements return control to the program. No values are transferred. The MESSAGE ..... RAISING statement does not display a message. Instead, it fills the system fields SY-MSGID, SY-MSGTY, SY-MSGNO, and SY-MSGV1 to SY-MSGV4.
To implement a remote function module in ABAP, perform the following steps:
1. Register the module as remotely callable in the RFC server system.
Asynchronous remote function calls (aRFCs) are similar to transactional RFCs, in that the user does not have to wait for their completion before continuing the calling dialog. There are three characteristics, however, that distinguish asynchronous RFCs from transactional RFCs:
- When the caller starts an asynchronous RFC, the called server must be available to accept the request.
The parameters of asynchronous RFCs are not logged to the database, but sent directly to the server. - Asynchronous RFCs allow the user to carry on an interactive dialog with the remote system.
- The calling program can receive results from the asynchronous RFC.
You can use asynchronous remote function calls whenever you need to establish communication with a remote system, but do not want to wait for the function’s result before continuing processing. Asynchronous RFCs can also be sent to the same system. In this case, the system opens a new session (or window) and allows you to switch back and forth between the calling dialog and the called session.
To start a remote function call asynchronously, use the following syntax:
CALL FUNCTION RemoteFunction STARTING NEW TASK taskname
Destination ...
EXPORTING...
TABLES ...
EXCEPTIONS...
The following calling parameters are available:
TABLES
passes references to internal tables. All table parameters of the function module must contain values.
EXPORTING
passes values of fields and field strings from the calling program to the function module. In the function module, the correponding formal parameters are defined as import parameters.
EXCEPTIONS
see Using Pre-Defined Exceptions for RFC
RECEIVE RESULTS FROM FUNCTION func is used within a FORM routine to receive the results of an asynchronous remote function call. The following receiving parameters are available:
- IMPORTING
- TABLES
- EXCEPTIONS
The addition KEEPING TASK prevents an asynchronous connection from being closed after receiving the results of the processing. The relevant remote context (roll area) is kept for re-use until the caller terminates the connection.
Call a transaction asynchronally and display it in an amodal window:
DATA: MSG_TEXT(80) TYPE C. "Message text
...
* Asynchronous call to transaction SM59 ->
* Create a new session
CALL FUNCTION ‘ABAP4_CALL_TRANSACTION’ STARTING NEW TASK ‘TEST’
DESTINATION ‘NONE’
EXPORTING
TCODE = ‘SM59’
EXCEPTIONS
COMMUNICATION_FAILURE = 1 MESSAGE MSG_TEXT
SYSTEM_FAILURE = 2 MESSAGE MSG_TEXT
IF SY-SUBRC NE 0.
WRITE: MSG_TEXT.
ELSE.
WRITE: ‘O.K.’
ENDIF.
You must not use IMPORTING when calling aRFCs.
Transactional Remote Function Calls
RfcInstallTransactionControlinstalls four functions to control transactional behaviour.
RFC_ON_CHECK_TIDis called when a local transaction is starting.
RfcCreateTransID Get a unique transaction-ID for calling an
ABAP function module using the transactional RFC InterfaceRfcIndirectCall Call an ABAP function module using the
transactional RFC InterfaceRFC_ON_COMMIT is called when a local transaction ends.
RFC_ON_CONFIRM_TID is called when a local transaction is
completed.RFC_ON_ROLLBACK is called when a local transaction ends with
failure.RFC_ONCALL
Transactional Remote Function Call
Theoretical Processing Flow of a Transactional RFC:
(1a) At the COMMIT WORK statement, function Remote is called as asynchronous RFC with destination 'NONE'.
(1b) Immediate response that function module can be called remotely.
(2a) Process the program.
(2b) Process the function module. Start the tRFC administration (database tables ARFCSSTATE and ARFCSDATA), which plans the call of function module Remote in system SYS2 as batch job.
As well as modularization in processing blocks, ABAP allows you to modularize source code by placing ABAP statements either in local macros or global include programs.
INCLUDE AND MACROS:
When you modularize source code, you place a sequence of ABAP statements in a module. Then, instead of placing all of the statements in your main program, you just call the module.
Include programs are global R/3 Repository objects. They are solely for modularizing source code, and have no parameter interface.
They have the following functions:
Library: Include programs allow you to use the same source code in different programs. For example, this can be useful if you have lengthy data declarations that you want to use in different programs.
Order. Include programs allow you to manage complex programs in an orderly way. Function groups and module pools use include programs to store parts of the program that belong together. The ABAP Workbench supports you extensively when you create such complex programs by creating the include programs automatically and by assigning them unique names.
Creating Your Own Include Programs
An include program cannot run independently, but must be built into other programs. Include programs can contain other includes.
The only restrictions for writing the source code of include programs are:
- Include programs cannot call themselves.
- Include programs must contain complete statements.
The INCLUDE statement has the same effect as copying the source code of the include program
***INCLUDE STARTTXT.
WRITE: / 'Program started by', SY-UNAME,/ 'on host', SY-HOST, 'date:', SY-DATUM, 'time:', SY-UZEIT.ULINE.
We can then include this program in any other ABAP program to display a standard list header.
PROGRAM SAPMZTST.INCLUDE STARTTXT.
............
This could produce the following output:
Program started by KELLERH
on host ds0025 date: 03/19/1998 time: 09:00:39
Macros
If you want to reuse the same set of statements more than once in a program, you can include them in a macro. For example, this can be useful for long calculations or complex WRITE statements. You can only use a macro within the program in which it is defined, and it can only be called in lines of the program following its definition.
The following statement block defines a macro
DEFINE
END-OF-DEFINITION.
Macros do not belong to the definition part of the program. This means that the DEFINE...END-OF-DEFINITION block is not interpreted before the processing blocks in the program. At the same time, however, macros are not operational statements that are executed within a processing block at runtime. When the program is generated, macro definitions are not taken into account at the point at which they are defined
A macro definition inserts a form of shortcut at any point in a program and can be used at any subsequent point in the program. As the programmer, you must ensure that the macro definition occurs in the program before the macro itself is used. Particular care is required if you use both macros and include programs, since not all include programs are included in the syntax check (exception: TOP include).
To use a macro, use the following form:
. You can use macros within macros. However, a macro cannot call itself.
Inserting the macro changes nothing in the generated form of the program.
When the program is generated, the system replaces
DATA: RESULT TYPE I,N1 TYPE I VALUE 5,N2 TYPE I VALUE 6.
DEFINE OPERATION. RESULT = &1 &2 &3.OUTPUT &1 &2 &3 RESULT.END-OF-DEFINITION.
DEFINE OUTPUT. WRITE: / 'The result of &1 &2 &3 is', &4.END-OF-DEFINITION.
OPERATION 4 + 3.OPERATION 2 ** 7.OPERATION N2 - N1.
The produces the following output:
The result of 4 + 3 is 7
The result of 2 ** 7 is 128
The result of N2 - N1 is 1
Click Here to Read More !!!!