Search this site

Saturday, April 2, 2011

Read and write file in SAP ABAP

1)OPEN DATASET
Opens a file for reading, writing or for appending
• Syntax:
OPEN DATASET [FOR INPUT|OUTPUT|APPENDING]
[IN BINARY|TEXT MODE]
[AT POSITION ]
[MESSAGE ]
[FILTER ].
can be a logical or physical file name

2)– READ DATASET
• Reads a file
• Syntax:
READ DATASET INTO [LENGTH ].
can be a logical or physical file names
• Logical file names can be created in customizing

3)TRANSFER DATASET
• Syntax:
- Writing to a dataset
TRANSFER TO [LENGTH ].
4) Closing a dataset
CLOSE DATASET

Function module

1)Step 1 T-code Se37
2) Step2
3)Step 3 Create interface parameters
4)Step 4
5)Step 5 Create table parameter
6)Step 6 Create exceptions
7)step 7 Source code in function module
Function module - Interface parameters
Import
Contains a list of the formal parameters that are used to
pass data to a function module.
Export
Contains a list of the formal parameters that are used to
receive data from a function module.
Changing
Contains a list of the formal parameters that are used
both to pass data to and receive data from a function
module.
Tables
Specifies the tables that are to be passed to a function
module. Table parameters are always passed by
reference.
Exceptions
Shows how the function module reacts to exceptions.
The function definition is written in the editor (Source code)


Friday, April 1, 2011

Subroutines

1)Subroutines
• Program module that can be called by any program.
• You use subroutines to avoid having to write frequently
used program components more than once. Data can be
passed explicitly from and to subroutines.
• Types of subroutine
– internal subroutines
– external subroutines

2)Defining and calling subroutine

Definition - Syntax
FORM .
.
ENDFORM.

Calling - syntax
a)Internal Subroutines
PERFORM .
b)External Subroutines
PERFORM () [IF FOUND].
- Program name
IF FOUND - If this is specified and there is no
subroutine in the program ,
the system ignores the PERFORM statement.

Include Programs

Include Programs
• If we want to use the same sequence of statements in
several programs, we can code them once in an include
program and call it in the other programs wherever it is
required
• Include programs cannot contain PROGRAM or
REPORT Statements
• Include programs cannot call themselves
• Include programs must contain complete statements
----------------------------------------------------------------
How to create include programs -->Click for details

Using Include Programs

***INCLUDE ZTEST_INC.

WRITE: / 'Program started date:', SY-DATUM.

We can then include this program in any other ABAP program to display a standard list header.

PROGRAM ZTEST.
INCLUDE ZTEST_INC.

-------------------------------

The result:

Program started

date: 04/01/2011

How to create include programs


1)Step 1

2)Step 2: Name for include



3)Step 3: Save




Include Programs

Include Programs
• If we want to use the same sequence of statements in
several programs, we can code them once in an include
program and call it in the other programs wherever it is
required
• Include programs cannot contain PROGRAM or
REPORT Statements
• Include programs cannot call themselves
• Include programs must contain complete statements
----------------------------------------------------------------

Using Include Programs

***INCLUDE ZTEST_INC.

WRITE: / 'Program started date:', SY-DATUM.

We can then include this program in any other ABAP program to display a standard list header.

PROGRAM ZTEST.
INCLUDE ZTEST_INC.

-------------------------------

The result:

Program started

date: 04/01/2011

Macros

Macros
• Callable modules of program code
Defining Macros - Syntax
DEFINE .
ENDDEFINE.
Calling Macros - Syntax
[ ….].
--------------------------------------------------------------------------------------------
Example:

REPORT demo_mod_tech_macros.

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.

This 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

In this example, the two macros operation and output are defined. output is nested in operation. operation is called three times with different parameters. Note how the placeholders &1, &2,... are replaced in the macros.

Abap Tips

  1. Check a string is number or not

Check a string is number or not

Example for code as below is to check whether a string is number with decimal ','
or not :

REPORT Z_TEST.
DATA
: count type i,
LW_CREDIT_TEMP TYPE BSEG-DMBTR.
PARAMETER: p_input TYPE char14.
FIND ALL OCCURRENCES OF ',' IN p_input MATCH COUNT count.
Write: ' occurance of the , = ', count.
IF p_input CO '1234567890, ' and count <= 1.
WRITE: /'Yes, valid', p_input.
write: lw_credit_temp.
Else.
WRITE: /'invalid', p_input.
write: lw_credit_temp.
ENDIF.

-------------------------------------------

1)Input : 4,5
Output: 4,5 is valid
2)Input: e
output: e is invalid

Monday, January 10, 2011

AL08-List of all users

AL08 shows the list of all the users who are logged on to the system globally or for all the instances in the system which are active. It shows all the active instances and number of active users in the system. It contains the following columns.

1) Instance - It shows the Instance into which the user logged in

2) Client - It displays the SAP client into which the user is Logged in

3) User Names - SAP user name

4) Terminal
- Terminal at which the user is working

5) T-code - Last executed transaction code

6) Time - Time at which the user last initiated a dialog step by entering data

7) External Sessions - Number of External sessions the user has opened

8) Internal Sessions - Number of Internal sessions the user has opened


The Difference between External and Internal sessions


Internal Session: It is the memory allocated for a program during execution. When we call a program using SUBMIT or Call Transaction then it will be loaded in a new internal Session. To exchange the data between internal sessions we can use ABAP MEMORY.

External Session: It is nothing but a window. Which we can create using SYSTEM -> CREATE SESSION.
We can open up to 6 external sessions (this is set by Basis of course).
We can use SAP Memory to exchange the data between External sessions in a Login.

Abap transaction code

AL08
AL08-List of all users

AL11
SAP directories structure

BAPI
BAPI Explorer, view all sap BAPI's

BUSP
Project management of SAP enhancements

FILE
Maintain Logical file path definition

GRANT_CUSTOMIZE
Customize Grant management screen via SAP's BDT(business data toolset) - Must have permission from SAP to use this method of modification

OAOR
Business document navigator (edit ENJOYSAP_LOGO etc for ALV Tree)

OLE
Examples for OLE Processing



PFTC
Work flow task maintain

SA38
Execute SAP ABAP program

SCC1
Client Copy, copy transport

SCDO
Change Document / Change History

SCOT
SAP connect Administration

SE01
Transport Organizer (extended view)

SE03
Transport Organizer Tools (change package/dev class etc..)

SE09
Workbench organizer

SE11
ABAP Dictionary

SE14
Database utility: Adjust after change to definition, delete….

SE16
Data browser, view/add table data

SE18
Business Add-ins(BADI’s): Definition transaction

SE19
Business Add-ins(BADI’s): Implementation transaction

SE24
Class builder

SE38
Program Editor

SE39
Split screen editor

SE41
Menu Painter

SE51
Screen Painter

SE61
Document maintenance

SE71
Form painter (SAP script)

SE80
Object Navigator ( SAP Development workbench, most development functionality is available from this transaction )

SE81
Application Hierarchy (leads to SE84 for desired area)

SE84
Repository info system

SE91
Message Maintenance

SE93
Maintain Transaction code

SHD0
Create Transaction Variant. Enter name of transaction plus name of new/existing variant.

SHDB
Batch input recorder

SLIN
ABAP program extended syntax check (full check of programs syntax)

SM04
User overview

SM12
Lock entries

SM13
Update Requests

SM21
Online system log analysis

SM30
Maintain table views

SM31
Table maintenance

SM35
Batch input i.e. Recording

SM36
Create background job

SM37
Background job monitor, Select background job

SM49
External Commands

SM50
Process overview (within current server)

SM51
Server overview

SM59
Display and Maintain RFC destination

SM64
Display/maintain Events

SM66
Process(session) overview across all servers

SM69
External commands(Maintain)

SMW0
SAP WEB Repository(binary data) - add/ mod images(used to put in screen containers)

SMX
View background jobs

SNOTE
SAP note assistant (if installed). Install OSS notes for you, usually removes the need for manual code changes

SNRO
Maintain number ranges (use FM 'NUMBER_GET_NEXT' to retrieve next number in range.)

SO10
Standard text editor

SP01
Spool list

SP02
Display your own spool list

SPAD
SAP Spool Administrator

SPAM
Support package manager

SPAU
Modification adjustment

SPRO
SAP System Customizing, IMG

SQ01
Sap Query development

ST02
Database Tune Summary

ST04
DB performance Monitor

STMS
Transport Management system

ST22
ABAP runtime analysis ( ABAP Dump Analysis )

SU01
User Maintenance

SU53
Retrieve authorization data for object, execute after error message is displayed(/nsu53)

SUIM
User info system (New user, Roles, Authorizations, User t-codes etc..)

SXDA
SAP Data transfer workbench

SALE
IDoc and ALE development

VOK2
Output determination by functional area/ output type (Output programs)

WEDI
IDoc and EDI Basis