Thursday, January 15, 2009

Enhancements

Enhancements:

It allows us to add our own functionality to SAP’s standard business application without having to modify the original applications.
SAP creates enhancements for specific programs, screens and menus within standard R/3 applications. These enhancements do not contain any functionality.
Instead, the enhancements act as hooks where we can hang our own add-on functionality onto these hooks.

Advantages with Enhancements:
• They do not affect standard SAP source code.
• They do not affect software updates

NOTE: Customer enhancements may not be available for all programs and screens found in the SAP system. You can only use customer exits if they already exist in SAP System.

Enhancement Approaches:
Procedural
- Using Function Modules
- Are called Customer Exits
Object Oriented
- Using Classes and Methods
- Are called BADIs

Procedural, we have two types.
1 – Using Subroutines.
2 – Using Function Modules.

Customer Exits
Types of Exits
Entire SAP Product can be divided in to 3 parts:
- Screens (Front End)
- Programs
- Tables (Back End)

We use:
Screen and Menu Exits to enhance the Front End
Function Exits to enhance the programs
APPEND STRUCTURES/CI Includes to enhance Back End

Menu Exits add items to pull down menus in standard SAP applications. The menu items can be used to call up own screens or to trigger entire add-on applications.
These can be created by defining special menu items in Menu Painter.

Screen Exits add fields to screens in R/3 applications. SAP creates screen exits by placing special subscreen areas on a standard R/3 screen and calling a customer sub-screen from the standard screen’s flow logic.

Function Module Exits add functionality to R/3 applications. They play role in both menu and screen exits.
When new items are added to standard menu, function module exit is used to define the actions that should take place once menu is activated.
Function module ecits also control the data flow between standard programs and screen exit fields.

Note: We can take the advantage of the exits only when SAP provides it in the Standard Transactions.

To locate the exits for any transaction:
Ther are many way for locating the exits, we go through the commonly used ones:
1. Goto SE93 – find the program for the transaction – goto program and find the Package / Development Class bu going to –
GOTO – ATTRIBUTES.
Now, goto SMOD transaction, find out the enhancement for package / development class by pressing F4 on enhancement.
Enter the name of Development Class / Package of the standard program.
Enhancements will be displayed. Select individual enhancement (in case more than one enhancement are there).
Enter enhancement name, select component option and click on display.
Observe the function module exits.
2. Use a piece of code – redundantly available online to pass the transaction and it returns all the enhancements used in the transaction.
3. Open the program in display mode and find the string CALL_CUSTOMER
Double click on CALL CUSTOMER function module exit.

Link to Short Tutorial on User Exits

Tuesday, January 13, 2009

SAP Project Methodology

SAP Project Methodology

1. Project Preparation (Requirement Gathering - generally handled by Client Coordinators):
• Change Charter - Goals and objectives of Organizational Change Management
• Project Plan - This is a first cut focusing on milestones and Work Packages; details to come.
• Scope - Sets the initial definition of the project; input from sales cycle.
• Project Team Organization - Sets the who of the project: Standards & Procedures - Sets the why and how of the project.

2. Business Blueprint - generally handled by Managers(HR, Technical, Project Managers and Test) and Designers
• Requirements reviewed for each SAP Reference Structure item and defined using CI Templates (in the Q&A db).
• This is the output of the Q&A database and is the key document for Phase 3.

3. Realization (Development)
• Master Lists - Define business scenarios and R/3 transactions to be realized in the system.
• BPP - Business Process Procedures representing R/3 transactions; used for unit testing& documentation.
• Planning - Defines how the configuration will be done and how it will be tested.
• Development Programs - Provides details of the external programming requirements.
• EU Training Material - End User training material and process documentation.

4. Final Preparation (Mapping of Requirement)
• Stress & Volume Tests - Plans for confirming the production hardware’s capabilities
• Cutover Plan - The details of how to move to the production environment and go live
• Conduct End User Training - Delivery of the necessary levels of R/3 End User training prior to going live

5. Go Live and Support
• Ensuring system performance through SAP monitoring and feedback.

Links for Project Methodology:
ASAP(Accelerated SAP) Roadmap

LSMW

Legacy System Migration Workbench (LSMW)

Transaction Code: LSMW

LSMW is majorly used by functional consultants to migrate data between third party systems to SAP system.
We can not directly upload the data to SAP tables; we have to use one of the methods given as an option (by SAP) to transfer data to SAP system. The options available through LSMW are:
• Batch / Direct Input
• BDC
• BAPI
• IDoc
• ALE
The above methods are also available from there own individual transactions to be used explicitly rather than from LSMW.
There are several other options to transfer data which are not available in LSMW.
Depending on various factors
LSMW is mostly used for one time data transfer; it can be used for regular data transfers with some workarounds.
There are some great tutorials of LSMW available at SAP Technical: Tutorials on LSMW. I think there is not much I can add on that, so visit
For Direct Input Method
For Batch Recording
For ALE / IDOC
For BAPI

Thursday, January 8, 2009

Batch Data Communication (BDC)

Creating a BDC program.

Requirement:

Upload vendor master using BDCs.
1. Create the text file (use tab button between values to keep uniform distance)
210 0001 0001 0001 Mr. Dallas dl

Lord Krishna Bank IN 950000



2. Goto Tcode SHDB.
3. Click on new recording
4. enter tcode XK01
5. enter
6. create a dummy record
7. save.
8. back
9. select the recording
10. click on program
11. enter program and enter
12. enter short description
13. click on source code
14. double click on BDCREXX1.
15. click on display
16. copy all
17. Back
18. Change program name to include ZTEXT_BDCREX
19. Double click on that
20. Paste code which was copied earlier
21. Activate
22. come back
23. comment all data set statements
( one has to comment a lot performs and datasets, that depends on type of transaction being recorded)
24. Make record to be an internal table writing occurs 0.
DATA: BEGINF OF RECORD OCCURS 0.
After include, write following:
PARAMETERES: P_FILE TYPE RLGRP-FILENAME.
DATA V_FILE TYPE STRING.

Before Start-of-selection,
AT SELECTION-SCREEN ON VALUE REQUEST FOR P_FILE.

CALL FUNCTION ‘F4_FILENAME’.
EXPORTING
PROGRAM_NAME = SYST_CPROG
DYNPRO_NUMBER = SYST_DYNNR
FIELD_NAME = ‘P_FILE’
IMPORTING
FILENAME = P_FILE
25. After START-OF-SELECTION:
START-OF-SELECTION.
V_FILE = P_FILE.
And call the function ‘gui_upload’.
CALL FUNCTION ‘GUI_UPLOAD.
EXPORTING FILENAME = V_FILE
FILETYPE = ‘ASC’.
HAS_FIELD_SEPERATOR = ‘X’.
TABLE
DATA_TAB = RECORD.

26. comment DO and write LOOP at record.
27. comment ENDDO and write ENDLOOP.
28. Execute the program.
29. select call transaction radio button
30. enter processing mode as A
31. in the file name, enter the file path
32. execute

Running Bdc Program Through Session Method
1. Execute the program
2. select “Generate Session’ radio button
3. enter session name
4. tick mark “Keep Session”
5. Enter the filename
6. execute
7. goto SM35
8. Select the session click on process
9. Select background
10. Enter
11. Analysing the background session
12. SM36
13. Click on own jobs.

Scheduling Background Program
1. SM36
2. enter the jobname
3. click on step
4. enter the program name and variant name
5. check and save and come back
6. click immediate
7. start condition.save.check.

Steps to write a BDC program
1. Identify the fields
Press F1 on field, click on technical info.
2. Fill BDCDATA internal table.
BDC data structure
a. Rogram
b. Dynpro
c. Dynbegin
d. Fname
e. Fval
3. Call the transaction
Processing mode in call transaction:
- A = Display all screens
- E= Display error.
- N = Background processing
4. Update Mode
a. L = Dialog work process will update the data
b. S = Synchronous update (update work processor will update)
If 1-100 records are updated and error is in 50th record, then 1-49 will be updated.In synchronous update the sy-subrc is set to 0 only when the particular transaction is executed and also the changes have done to the database,
c. A = asynchronous update work process will update. Incase error is 50th record, then 1-49 records will be updated and 50th will logged as an error. In asynchronous update the sy-subrc is set to 0 if  the transaction is executed without any fail, not the database changes.

Difference between Call Transaction and session method.
Call Transaction Session Method
i. Synchronous Asynchronous

ii. Error needs to be handled Automatically
Manually

iii. Used for relatively less records More records

iv. No function modules are called Multiple transactions called
and used to update one transaction.

v. No session is created. Session is created.
The function modules called are:
• BDC_OPEN_GROU
• BDC_INSERT
• BDC_CLOSE_GROUP.

Dialog Prorgramming

Module Pool Programming
(Also called Screen or Dialog Programming)

Events in module pool programming:
Process Before Output (PBO)
Process After Input (PAI)
Process on Help-request (POH) – F1
Process on Value Request (POV) – F4

PBO: In this event, we write the logic to display the screen layout. Data will transfer from program fields to screen fields with identical names.

PAI: Whenever we do any operation in the screen which is associated with function code, this event will be triggered. Data will pass from screen fields to program fields.
SY-UCOMM is the only we can use PAI.

SE80 : Select PROGRAM from dropdown – enter program name – press enter
– asks for creation – press YES – make sure TOP INCLUDE check is enabled.
Delete * and enter prog name TOP.

IN SE80:
- double click on program – goto change mode – uncomment 001 and I01 include programs.
- Double click on the include programs, create and back.
- Right click on program name – create screen.
- Enter the short description
- Click on element list
- Enter ok_code - we can give any variable name but ok_code is standard.
- Click on layout.
- Click on Textbox – drag it on screen – double click textbox.
- Enter the name and text – give quick info an icon name.
- Similarly make 2 more text boxes. One for second number and one for result.
- Click on input , output box and drag it on screen.
Enter name and format.
- Click on push button, drag it on screen.
Enter name
Enter text.
- enter function code – eg- ADD
- another button for EXIT.
-Design screen. Goto flow logic.
- Uncomment the module after PAI.
Double click on the module - asks for creation - click YES.
- Select I-1 include program.

Module USER_COMMENT_I011 input
Case ok_code.
WHEN ‘ADD’.
R = A + B.
WHEN ‘EXIT’.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.

-Double click on main program.
Two types of fields:
- Screen Fields
- Program Fields
Double click on program, double click on TOP INCLUDE.

NOTE: generally in TOP INCLUDE, we declare all the global variables.
TOP INCLUDE is include at the top.
In TOP INCLUDE write:

DATA: a type I,
B TYPE I,
R TYPE I,
OK_CODE TYPE SY-UCOMM.

- Right click on main program.
- Executing module pool type of program.
- Except report programs, we cant execute any program directly by F8.
- For module pool programs, we execute by creating a TCODE: SE93.
Or
Right click on program – create – transaction.
- Enter transaction code name and short description.
- Select program and screen.
- Enter program name and screen number.
- Click on all the GUI options and SAVE.
- Click on cursor position under attributes.
- Hitting Enter will pass empty function code.
- to avoid this problem: goto screen – goto flow logic, after process before output, create a module.
MODULE CLEAR_OK_CODE.
- Double click on module, it will ask for creation.
- Select 001 include.
- In module we will write:
CLEAR OK_CODE.

Static Screen Changes.
Requirement: Make the result field as display only and the field number as mandatory.

- Double click on the screem – click on layout.
- Goto change mode.
- Double click on the first field.
- Select program tab in attributes under input dropdon – select required.
- Double click on result field, goto program tab – select output only.

OR
- Click on element list tab and change the attributes.

To create a cancel button.
- Double click on screen – click on layout.
- Click on pushbutton – drag it on screen.
- Enter the name, text and function code.
- Select function type as E.
- Click on flowlogic.
- In PAI, create a module of type:
‘at exit_command’.
- MODULE LEAVE AT EXIT_COMMAND.
Double click on module
Select I01(PAI)
-IF OK_CODE = ‘CANCEL’.
LEAVE TO SCREEN 0.
ENDIF.
- SCREEN 0 breaks the screen sequence.

In AT EXIT-COMMAND, field validation is not triggered, so it doesn’t check for fields and comes out.
In report, we do validation in ‘at selection screen’.
Display error message if user enter value A > 10.
- Double click on screen.
In PAI:
FIELD A MODULE VALIDATE_A.
Inside the module write:
MODULE VALIDATE_A INPUT.
IF A .= 10.
MESSAGE “ENTER VALUE LESS THAN 10” TYPE ‘E’.

Field statement:
We use it for single field validation, i.e. if any error occurs in the module, then the field will be enabled, other fields will be disabled

To validate a group of fields:
In this case, double click on screen.

CHAIN.
FIELD A.
FIELD B.
MODULE VALIDATE_A.
ENDCHAIN.

- DYNAMIC SCREEN MODIFICATIONS:
When user click on add, display only result field.
Double click on screen.
Uncomment module after PBO or write a module,
Double click on module.
Select o01.

CASE ‘OK_CODE’.
WHEN : ‘ADD’.
LOOP AT SCREEN.
IF SCREEN-NAME = ‘A’.
SCREEN-ACTIVE = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDCASE.
ENDMODULE.

SCREEN is an internal table defined by the system which contains the field attributes or the screen attributes.

To disable a group of fields, double click on screen, goto layout – double click on fields whose attributes we want to change.
Enter a group name in first input box of groups.
Eg – GR1.
In LOOP AT SCREEN.
Instead of screen-name , can write screen-group1 – ‘GR1’.

TABSTRIP Control.
- Create a module pool type of program.
2 includes will be added automatically PBO and PAI.
- Create a screen.
Enter screen number, short secription.
Goto element list – enter OK_CODE.
- Click on layout
- Click on Tabstrip control – drag it on screen.
- Double click on tabstrip control.
- Enter the name.
- If more than two tabs are required, change the tabtitle
( by default two is the value)
- Double click on tab1.
Enter the name, text and function code.
Color is red for fields i.e. the information is mandatory to be filled.
- Click on Subscreen Area – Drag it on screen.
- Double click on other tab and do the same.
- Click on flow logic:
- Now we need to design subscreens ( that are assigned to tabs).
- Right click on program – Create screen
OR
Goto screen – other object – enter screen number and enter create.
- Short description , Add subscreen.
- Select Subscreen radio button
We will see OK_CODE is not enabled. By default for subscreen.

- After designing the subscreen layouyt, goto flow logic. Uncomment module of PAI.
- Double click on TOP INCLUDE and write following in TOP INCLUDE.
DATA : A TYPE I,
B TYPE I,
R TYPE I.
CONTROLS TAB TYPE TABSTRIP.

Double click on main screen.
Flowlogic:
PBO: Process Before Output.
CALL SUBSCREEN ADD_REF1 INCLUDING ‘ZTABSTRIP’ ‘1011’.
CALL SUBSCREEN MUL_REF1 INCLUDING ‘ZTABSTRIP’ ‘1012’.

PAI : Process After Input.
CALL SUBSCREEN ADD_REF1.
CALL SUBSCREEN MUL_REF1.

Double click on module command.
In main program:
MODULE USER_COMMAND_1010 INPUT.
CASE OK_CODE.
WHEN ‘ADD’.
TAB-ACTIVE TAB = ‘ADD’.
WHEN ‘MUL’.
TBA-ACTIVE TAB – ‘MUL’.
EBDCASE.
ENDMODULE.


TABLE CONTROL:
Create a module pool program.
We will try including screen in report program.
So create a report program:
REPORT ZTEST_TABLECONTROL.
START-OF-SELECTION.
CALL SUBSCREN 1010.
- double click on screen.
- click on element list – enter OK_CODE.
- goto layout – click and drop table control.
- double click on table control.
- check vertical and horizontal separators.
- click on dictionary / program fields ( red button at top) or press F6.
- Enter the table name – select fields and click OK.
- Again F6. Select fields that we want.
- Put it on fields.(drag n drop at the header area of table control.
- Click and drag Push button : make two of them – DISPLAY and EXIT.
- Click on Flow Logic. Write following:
PROCESS BEFORE OUTPUT.
LOOP AT IT_VBAP WITH CONTROL TABLE.
MODULE TRANSPORT.
ENDLOOP.

PROCESS AFTER INPUT.
LOOP AT IT_VBAP.
….
ENDLOOP.

MODULE USER_COMMAND 1010.
CASE ….

ENDCASE.

- Double click on MODULE TRANSPORT – include main program.
Main program:
REPORT ZTEST_TABLECONTROL.
TABLES VBAP.
DATA: OK_CODE TYPE SY-UCOMM.
CONTROLS TABLE TYPE TABLEVIEW USING SCREEN 1010.
TYPES: BEGIN OF TY_VBAP,
POSNR TYPE VBAP-POSNR,
MATNR TYPE VBAP-MATNR,
ARKTX TYPE VBAP-ARKTCX,
NETWR TPE VBAP-NETWR,
KWMENG TYPE VBAP-KWMENG,
END OF TY_VBAP,
TY_T_VBAP TYPE TABLE OF TY_VBAP.
DATA: IT_VBAP TYPE TY_T_VBAP,
X_VBAP TYPE TY_VBAP.
START-OF-SELECTION.
CALL SCREEN 1010.
PROCESS BEFORE OUTPUT.
LOOP AT IT_VBAP INTO X_VBAP WITH CONTROL TABLE.
MODULE TRANSPORT.
ENDLOOP.

PROCESS AFTER INPUT.
LOOP AT IT_VBAP.
ENDLOOP.
MODULE USER_COMMAND_1010.
MODULE TRANSPORT OUTPUT.
MOVE-CORRESPONDING X_VBAP TO VBAP.
ENDMODULE.

MODULE SELECT_DATA OUTPUT.
IF VBAK-SEL = ‘X’. “We can add desired logic
ENDMODULE.

MODULE USER_COMMAND_1010_INPUT.
CASE OK_CODE.
WHEN ‘DISPLAY’/
DATA FILL TYPE SY-TABIX.
SELECT POSNR MATNR ARKTX NETWR KWMENG
INTO TABLE IT_VBAP FROM IT_VBAP
WHERE VBELN = VBAP-VBELN.
DESCBRIBE TABLE IT_VBAP LINES FILL.
TABLE-LINES = FILL “ to make table control scrollable.
WHEN ‘EXIT’.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.

Wednesday, January 7, 2009

Function Modules

FUNCTION MODULES

Repeatedly done piece of codes doing specific tasks can be put into global place.
Stored in R/3 repository.

Creating Function Module:
Requirement: Pass A, B values, get results.

For function modules, we must have function groups.

Creating Function groups
Goto SE 80

Function group contains function module(s) as wel as global data which is used by the function modules.
Global data is stored in TOP INCLUDE of function group.

Goto SE80
Open function group – double clock on it
Click on main program.
Double click on TOP INCLUDE.
Declare variables.
Goto SE37. Enter module name, click on create.
Enter function group name and short description.

Click on Attributes
NOTE: There are 3 types of function modules:
1. Normal – Used for modularization purpose.
2. Remote Enabled – Used to call function module from another server.
3. Update modules. Used to update the database by using the update work processes.
We should use update more often.

Click on IMPORT.
Enter the cariables which are used by the function modules and for which values will come from main program.
NOTE: We can not change input parameter value.

Click on EXPORT
Enter variables which will be passed to main program.

Click on changing
Changing parameters’ value can be changed.

Click on Tables
Here we pass the internal tables.
If more than one table is updating internal table, we can create a structure and define internal table of type structure.
Structure can be defined in source code or TOP INCLUDE.

Click on Source Code
Write the logic.

Callin function modules in the main program.

Create an executable program.

To call the function module: Place cursor where we want to call the function module, click on Pattern ( ctrl + F6)
Enter function module name.

Exception handling in function modules
Open function module in change mode, click on exceptions tab.
Enter exception name. ( eg – RAISE_EX 0)
Goto source code
IF b =0.
RAISE RAISE_EX 0.

Whenever we call the function module for the first time, the total function group will be loaded into the runtime environment along with the global variables.
Function module called twice will be loaded once and used again.
Above is the major difference between function modules and object oriented programming.
Otherwise, function module , like OOPs, also do encapsulation.


Analyzing Short Dump
GOTO tcode: ST22
Click on today or whatever time the error occurred.

Double click on source code extract and system will take us to the line where error has occurred.

Reporting events

REPORTS

In a report we can have any number of initialization of in that case – any event any number of times.
It will collect all same types of events together and execute them together.



Selection Screen

SELECTION-SCREEN BEGIN OF BLOCK BLK WITH FRAM TITLE TEXT-001.
PARAMETERS : A TYPE I,
B TYPE I.
SELECTON-SCREEN END OF BLOCK BLK.
SELECTION-SCREEN BEGIN OF SCREEN 1010.
PARAMETER R TYPE I.
SELECTION SCREEN END OF SCREEN.

INTERACTIVE REPORT
Interactive events
1. AT USER-COMMAND
2. AT LINE-SELECTION
3. AT PFn (obsolete)

Creating Menu Painter
Event for menu painter:
AT USER-COMMAND.
System field is sy-ucomm.
SY-UCOMM is a system field which contains the function code.

CREATING MENU PAINTER

1. Create an executable type of program.
2. PARAMETERS : A TYPE I,
B TYPE I.
DATA: R TYPE I.
AT SELECTION-SCREEN ON A.
IF A < B.
MESSAGE ‘ENTER A VALUE GREATER THAN B’ TYPE e.
ENDIF.
START-OF-SELECTION.
WRITE: /A,B.
WRITE: / ‘CHOOSE THE OPERATION FROM THE MENU’.
SET PF-STATUS ‘STATUS’
Now double click on STATUS. Will ask for creation- continue
Click on + sign in menu bar.
Enter TEXT – CALCULATOR’ and double click.
Enter the code and text
Add Addition
Sub Substraction
Activate
Come back to the main program

AT USER-COMMAND.
CASE: SY-UCOMM.
WHEN ‘ADD’.
R = A+B.
WHEN ‘SUB’.
R = A-B.
ENDCASE.
WRITE: /R.

Creating sub-menu
For sub-menus, we will not have the function codes in the main menu.
Double click on PF-STATUS.
For sub-menus – Enter TEXT only and double click on text.
Enter Fn code and text. MUL MULTIPLY
DIV DIVISION.
We can nest upto 3 levels.
To add separator – Edit – Insert – Separator
Right click – Insert – Separator.

Creating Standard toolbar.
The available ones can be disabled or enabled.
Click on plus sign nearby function keys.

Creating Application toolbar
for often used applications.

Enter the function code, double click on function code, assign function keys.

Disabling Menu Option.
DATA: IT_COMM type table of sy-ucomm.

At USER-COMMAND
CASE : SY-UCOMM.
When ‘ADD’.
REFRESH IT_UCOMM.
APPEND ‘ADD’ TO IT_UCOMM.
R = A + B.
..
..
..
WRITE: /R.
SET PF-STATUS ‘STATUS’ EXCLUDING IT_UCOMM.

For user defined title:
SET TITLE BAR ‘TITLE BAR NAME’.
DOUBLE CLICK ON TITLE BAR NAME.
Enter title bar description.
In pop-up box enter text
Click on ALL TITLE.
ACTIVATE.

INTERACTIVE REPORT
AT LINE-SELECTION.
Requirement: Display the sales order details when user double clicks on particular sales order display VA03 transaction code

DATA: IT_VBAK TYPE TABLE OF VBAK WITH HEADER LINE.
DATA: V_VBELN TYPE VBAK-VBELN, V_FIEL TYPE STRING.
SELECT-OPTIONS: S_VEBELN FOR VBAK-VBELN.
SELECT * FROM VBAK
INTO TABLE IT_VBAK
WHERE VBELN IN S_VBELN.

LOOP AT IT_VBAK.
WRITE: /IT_VBAK-VBELN , IT_VBAK-AUART, IT_VBAK-AUDAT.
ENDLOOP.

AT LINE-SELECTION.
GET CURSOR FIELD V_NAME VALUE V_VBELN,
IF V_FIELD = ‘IT_VBAK-VBELN’.
SET PARAMETER IF ‘AUN’ FIELD V_VBELN.
ENDIF.

To find out the Prrama-ID for order number – press F1 m then click on Technical Info.

HIDE statement:
When we use the HIDE statement, system will store the values of the field which is written in hide in HIDE area.
HIDE can hold any number of values.

Internal Table and its operations, Control Statements, Selection Query

Dataobject declaration in program:

DATA: str_NAME TYPE/LIKE DDIC STRUCTURE / PREDEFINED.
example:
DATA X_MARA TYPE MARA. “MARA is a DDIC table
DATA X_NAME LIKE NAME.
“NAME is a dataobject declared in the current “program.

INTERNAL TABLES:

They are temporary memory buffers in the application server which can hold multiple records.
Internal tables are active till the program is running. Once the program ends, memory will be released / internal tables are erased.


Internal Tables are of two types:
1. Index
- Standard
- Sorted
2. Hashed (One which follows the hash algo)

In order to work with individual records of the internal table, we need to have a structure of same size and type as internal table and that structure is called as field string or work are of header line.

DATA: BEGIN OF IT_SO OCCURS 0,
SONO TYPE VBAP_VBELN,
ITM TYPE VBAP-POSNR,
MATERIAL TYPE VBAP-MATNR,
QTY TYPE VBAP-KWMENG,
END OF IT_SO.

The above code will create:
1. a work area having four fields: SONO, ITM, MATERIAL, QTY
2. an internal table similar to work area.

At any point IT_SO will point to work are and not internal table because we can not point to internal table.

IT_SO-SONO = ‘5000’.
IT_SO-ITM = ‘10’.
IT_SO-MATERIAL = ‘M-09’.
IT_SO-QTY = ‘7’.
APPEND IT_SO.

IT_SO-ITM = ‘20’.
IT_SO-MATERIAL = ‘M-02’.
IT_SO-QTY = ‘11’.
APPEND IT_SO.
WRITE: IT_SO-SONO,
IT_SO-ITM,
IT_SO-MATERIAL,
IT_SO-QTY.
ENDLOOP.

Filling the Internal Table

Syntax: APPEND WA TO ITAB.
In earlier example :
APPEND IT_SO TO IT_SO.
OR
APPEND IT_SO.

Looping through internal table.
LOOP AT IT_SO INTO WA [where condition].
….

….
ENDLOOP.

In place of above, we can write:
LOOP AT IT_SO.
….


ENDLOOP.
“Above can be done provided the internal table has OCCURS 0 (or any other number in place of 0) as addition while declaration.

OCCURS 0. This addition allots 8KB of memory
OCCURS 10. Memory for 10 records is allocated.
OCCURS 5. Memory for 5 records is allocated.
SAP says in ECC 6.0 occurs has become obsolete as SAP system needs to take overhead of memory allocation.

DATA: ITAB type/like table of x [WITH HEADER LINE].


TYPES: BEGIN OF TY_SO, “User defined structure type
POSNR TYPE VBAP-POSNR,
MATNR TYPE VBAP-MATNR,
KWMENG TYPE VBAP-KWMENG,
END OF TY_SO,
TY_T_SO TYPE TABLE OF TY_SO. “User defined table type
DATA: IT_SO TYPE TY_T_SO,
X_SO TYPE TY_SO.

Fetching data from database.

SELECT *
INTO TABLE ITAB
FROM DATABASE_TABLE
WHERE CONDITION.

Structure of the internal table should be same or higher than that of fields specified in the select statement.
The sequence of fields should be same otherwise use:
1. SELECT * INTO…
2. SELECT F1 F2 INTO CORRESPONDING FIELDS OF TABLE ITAB…
But both of the above options should be avoided due to performance reasons.

SELECT A~F1 A~F2 A~F3
B~C1 B~C2 B~C3
INTO TABLE ITAB
FROM DBTAB1
AS A INNER JOIN DBTAB2 AS B
ON A ~ CF = B ~ CF
WHERE CONDITION…
*DBTAB1 and DBTAB2 are database tables
*A is alias name for DBTAB1
*B is alias name for DBTAB2
*F1, F2, F3 are fields of DBTAB1
*C1, C2, C3 are fields of DBTAB2
* CF is the common field in DBTAB1 and DBTAB2

One can bring all fields of structure together through PATTERN button.

Selection Table: Its an internal table with the fields:
SIGN – Include / Exclude
OPTION – BT NB GT LT GE
LOW – Low Value
HIGH -- High Value

Declaring selection fields table:

SELECT-OPTIONS: S_VBAK FOR VBAK-VBELN.
Syntax: SELECT-OPTIONS VAR FOR X_VAR
[OBLIGATORY] [LOWER_CASE]
[DEFAULT ‘’ TO ‘’]
[NO-EXTENSION]
[NO-INTERVALS]

We need to add TABLES: VBAL only for the tables used in SELECTOPTIONS
(in earlier versions, it used to be for all the tables used in the program).

Operations with internal table:
Reading single Records:
READ TABLE ITAB INTO WA
[INDEX|WITH KEY CONDITION]

READ TABLE IT_VBAKVBAP INTO X_VBAKVBAP INDEX 7.
IF SY-SUBRC = 0.
….
..

ENDIF.
SY-SUBRC is a system field which contains return code of previously executed statement.
If 0, it means atleast one record was read for the selection query.

READ TABLE IT_VBAKVBAP INTO X_VBAKVBAP
WITH KEY VBELN = ‘5006’
POSNR = ‘10’.

MODIFY TABLE
MODIFY ITAB FROM WA
[INDEX I | WHERE CONDITION]

READ TABLE IT_VBAKVBAP INTO X_VBAKVBAP INDEX 4.
IF SY-SUBRC = 0.
X_VBAKVBAP-KWMENG = X_VBAKVBAP-KWMENG + 8.
MODIFY IT_VBAKVBAP FORM X_VBAKVBAP INDEX Y
TRANSPORTING KWMENG.
Sorting Internal Table
SORT ITAB BY F1 [ASCENDING / DESCENDING]
F2 [ASCENDING / DESCENDING]
….


[AS TEXT]

By default it is ASCII , AS TEXT addition makes it otherwise.

DELETING INTERNAL TABLE
1. FREE - FREE ITAB. “deletes contents of internal table and releases memory
2. REFRESH – REFRESH INTERNAL TABLE. “Deletes content only, memory remains as it is.
In both above cases, work area will not be affected( in case there is a header line).
3. CLEAR – CLEAR ITAB. “Clears only work area
-- CLEAR ITAB[]. “ clears only the internal table

CONTROL BREAKS

1. AT FIRST….ENDAT
LOOP AT ITAB.
AT FIRST.

….
..
ENDAT.
ENDLOOP.
This will be triggered for the very first loop pass.
We can use for table headers.
Inside AT FIRST, ENDAT – character values will be changed to **, rather numeric values will be changed to 0.
2. AT LAST….ENDAT.
LOOP AT ITAB.
AT LAST.

….
..
ENDAT.
ENDLOOP.

Used for last loop pass. Used for table footers.
3. AT NEW…ENDAT.
LOOP AT ITAB.
AT NEW.

….
..
ENDAT.
ENDLOOP.

AT NEW will be triggered:
- for very first loop pass.
- when the content of control label changes.
- when left side fields of control label changes.
- inside AT NEW and ENDAT, the contents of work area will be changed as follows:
Left side fields and control labels remain as it is rather the right side field will be change to * and 0s based on character and numeric.
4. AT END OF ..ENDAT.
- This will trigger when the control label value changes.
- For the last loop pass.
- When the left side field of control label changes.
Values of work area will be changed same as AT NEW.
5. SUM.
The statement will sum the quantity field value for the corresponding control label and the summed value will be stored in the work area’s quantity fields only.
6. ON CHANGE OF... ENDON.
Triggers on change of the particular control label.

Tuesday, January 6, 2009

Creating and transporting Packages

Creating Packages

GOTO TCODE SE21 or SPACKAGE i.e. Package Builder
- Enter package name – create- software component – enter HOME
- Click on create
- Click on create request
- Short description.
- Enter.

10 digit request number is created
- first 3 letters are machine ID
- next 1 letter is type of request
- next 6 letters are unique number to identify object in the server.

TO Change package for an object:
- Open corresponding object.
- Goto menu – Object Director Entry.
- Goto change mode
- Enter package number.

Transporting the object.
- Goto SE09
- Releaste task first (place cursor on task and click on truck sign)
- Then release the request.

Debugging

Wherever we want to stop the execution and shift to debugger.
Write statement:
BREAK-POINT.

In fields, enter the variable name.
For single line execution , press F5.
For executing the program or to reach the next breakpoint, press F8.

To cancel debugging – Goto Menu – Debugger – Debugging Off.
In order to change the value in debugging mode, change values and click on change field contents (pencil icon).

F5 – next line
F6 – To skip the analysis of execution of perform rather than execution of perform.
F7 – If the current pointer is inside the function or perform, to come back to main program.

To set a user specific breakpoint, we use : BREAK USER.
BREAK USER is a hard breakpoint.
For soft breakpoint, click on STOP.

Ways to start debugger:
- Hard Breakpoint.
- Enter TCODE ‘/h ‘ before F8.
- Adding soft breakpoint.
- Adding watchpoint.

String Operations

STRING OPERATIONS:

In case of string operations, no space between operators.

Split and concatenate
Data: V

DATA : V_D1(10) type c,
V_D2 LIKE V_D1,
D_DD(2) TYPE N,
V_MM(2) TYPE N,
V_YR(4) TYPE N.
V_D1 = ‘27/07/2008’.
SPLIT at ‘/’ V_D1 into V_DD V_MM V_YR.

CONCATENATE V_YR V_MM V_DD INTO V_D2 SEPARATE BY ‘.’.

Control Statements

Control Statements:

  1. IF…ENDIF.
  2. IF….ELSE…ENDIF.
  3. IF….ELSEIF…ENDIF.
  4. DO…ENDDO.
  5. WHILE…ENDWHILE.
  6. CASE…ENDCASE.

PARAMETERS : P_AGE(3) TYPE N.

FI P_AGE >= 18.

WRITE: / ‘ELIGIBLE’.

ENDIF.

DO N TIMES.

….

….

ENDDO.

Inside DO…ENDDO. The system field, SY-INDEX contain current loop index.

Parameters P_NAME TYPE I.

DATA RES TYPE I.

DO 10 TIMES.

RES = P_NUM * SY-INDEX.

WRITE: / P_NUM, ‘*’, SY-INDEX, ‘=’, RES.

ENDDO.

WHILE…ENDWHILE.

WHILE (condition)

…..

ENDWHILE.

PARAMETER P_NUM TYPE I.

WHILE P_NUM <> 0.

P_NUM = P_NUM -1.

P_NUM = 7.

CONTINUE.

ENDIF.

WRITE : /P_NUM.

ENDWHILE.

CONTINUE skips the loop processing.

EXIT cancels the innermost loop.

CASE…ENDCASE.

CASE variable

WHEN ‘ ‘

….

WHEN ‘ ’

….

WHEN OTHERS

….

ENDCASE.

PARAMETERS P_COLOR TYPE I.

CASE P_COLOR.

WHEN ‘1’.

WRITE: /’RED’.

WHEN’2’/

WRITE:/’GREEEN’.

WHEN OTHERS.

WRITE:/’INVALID COLOR’.

ENDCASE.

Programming basics

Write Statement:

Write ‘SAP’.

Write ‘Bangalore

Write ‘India

Output: SAPBangaloreIndia

/ or Skip is used to go to next line for printing

WRITE / ‘Bangalore’.

Semicolon is chain operator.

One is saved from the hassle of writing same command again and again by using chain operator.

Write : ‘SAP’,

/ ‘Bangalore’,

/’India’.

Write ‘SAP Labs’ color 7.

Makes the background will be colored.

Write ‘SAP Labs’ color 7 inverse on.

Only the letters will be colored.

Dataobjects:

  1. Modifiable

- Character:

C Character

N Numeric

D Date

T Time

X Hexadecimal

S String

- Numeric:

I Integer

F Float

P Packed decimal

  1. Non Modifiabale

- Constants

- Literals

For character, numeric and packed, it is mandatory to define the size, for others it is optional.

Declaring Variables:

Data Var(size) type t [decimals d][value 11]

Eg:

Data name (10) type c.

Data roll(3) type n.

Data doj type D value ‘20081007’.

Data per(3) type P decimals 2.

Parameter Var(size) type t

[decimals d]

[obligatory]

[lower case]

[default]

Parameters P_name(10) type C obligatory lower case.

Write: / P_name.

Syntax :

Write : / P(n) ‘ ‘ color n Inverse on.

Where P is the offset position and n is no. of characters.

Write: / 7(3) ‘SAP’.

In data we have value and in parameters we have default as an optional addition to provide initial default values.

Creating a Program:

SE38 – Enter a program name – Create (F5) – Enter Title

Type is executable type.

Single line comments should start with * in the first column.

In ABAP editor, after Report Statement – write the code.

Save Check and Activate after writing the code.

F8 to execute.

By default standard page header contains:

Program name, page number and under line.

In order to suppress default page header:

After report name: write following

NO STANDARD PAGE HEADING.

To comment from middle of line use “.

Write: v_name centered,

/ v_turn centered,

/ sy-datum left-justified,

Uline.

To underline sy-uline

Sy-vline- for vertical line.

Standard selection screen number is 1000.

Search Help

SEARCH HELP:

-SE11 -Search Help –Names –Create – Elementary Search Help- Short Description.

In Selection methods, enter a table or view.
We cant enter here maintenance view.

In Search Help parameter, enter the field names.
Select check box – importing and exporting.
First Line LPOs = 1, SPOs = 1
Second Line LPOs = 2, SPOs = 2
…and so on…
-Save Check and Activate.

ATTACHING SEARCH HELP TO THE TABLE:

Open the Table in change mode
Place cursor where you want to create F4 help.
Click on search help button.
Enter the search help name and press enter (copy).
Save Check and Activate.


Dialog Type:
1. Display values immediately: As soon as F4 is pressed, values will be displayed.
2. Display values with restrictions: As soon as F4 is pressed, restriction box is displayed.
3. Dialogue depending on set of values: In this option, if number of values is less than 100, it behaves as display values immediately, if more than 100, behaves as dialogue with value restrictions.

Importing – Values are copied from screen to search help
Exporting – Values are copied from hit list to screen fields.

If we have two fields in F4 Plant and Material:
For locking we can see: Plant is not copied, rather material is copied, but user can choose material based on plant.
SPOs – Position of field in hitlist
LPOs – Position of field in restriction box.

Activation – When we activate any object, a series of SQL statements will be generated which will trigger database to create object in database.

Lock Objects

Lock Objects: Are used for synchronizing the access by multiple users for a single object.

Lock Objects start with ‘e’
Whenever we activate lock objects ( eg : EMARA), automatically two function modules will be created:
1. Enqueue_EMARA to lock the object
2. Dequeue_EMARA to release the lock.

SM12 is the transaction code to analyze the locks.

Creating Lock Objects:

- SE11 - Select lock object radio button – Enter lock object name (eg – emara)
- Enter short description – Enter Primary table name – enter lock mode
– enter secondary tables.

example - While creating Sales Order, MM02 should not change the material attributes.

Whenever we do changes to an object, there are other dependent objects which should not changed by any other objects.

Click on Lock Parameter – all key fields will appear, we can change it.
Save Check and Activate.
Automatically system gives two function modules.

Order of a lock mechanism:
Lock
Read
Change
Release

Structures

STRUCTURES: It is a group of logically related fields.

Difference between Structure and tables
- Table contains data, structure doesn’t contain data.
- Table must have key fields, structure doesn’t require key fields
There are two types of Structures:
- Include Structure
- Append Structure

Creating Structures:
1. SE11
2. Select Datatype radio button
3. Enter Structure name
4. Click on create
5. Select structure radio button
6. Enter short description
7. Components tab – enter field names, component type enter data element
8. Save Check and Activate

Including a structure: Can be included in any number of tables.
Appending Structure:
- Open a table in change mode
- Click on append structure button
- System proposes a name which we can modify.
But the name should start with Y or Z.

Append structure is always done at the end of structure.

Generally naming convention for fields of append structure are starting with ZZ.

If we have a table with Lchar (long character) as a field datatype, it append at last of the table, we can not have append in that case.

• Include Structure are pre-planned.
• Append Structures are not pre-planned.
• Both are part of enhancements.

Views

Views: They are virtual tables.

  1. Projection View (can make changes if the view contains a single table).
  2. Database View (one or more than one table) using inner join

When we create a database view on more than one table, we can not change the underlying table values by using the view.

  1. Maintenance View

- Uses outer join

- It allows changing values in the underlying tables.

  1. Help View

- Uses Outer Join

- Uses for F4 help

Creating Projection View:

  1. Go to TCODE SE11
  2. Select Radio Button
  3. Enter View Name
  4. Click Create
  5. Select Project View Radio Button
  6. Enter Short Description
  7. Enter Basis Table (Database Table)
  8. Click on Table Fields
  9. Select the required Fields
  10. Select Maintain Status Tab.
  11. Read and Change.

Creating Database View:

  1. Go to TCODE SE11
  2. Select Radio Button
  3. Enter View Name
  4. Click Create
  5. Select Database View Radio Button
  6. Enter Short Description
  7. Enter Basis Table (Database Table)
  8. Enter Table Name in tables column
  9. Click on relationship
  10. Select relationships and click on copy.

Between 2 tables can select only one relationship.

  1. Click on View fields
  2. Click on table fields
  3. Select a table and click choose
  4. Select fields of table and enter.
  5. Do same for other table.
  6. In select conditions tab: Enter condition based on which need to be displayed.
  7. Save, Check and Activate.

NOTE: Check Table is Foreign Key Table.

Maintenance View: Create same a database view. But after activating, we need to create table maintenance generator.

We can write selection query using common fields also ( foreign key fields are never mandatory).

HELP VIEW: Similar to database view.

T-Codes, Tables and Descriptions

List of frequently used transactions for users which may be helpful to know:

T.Code(s) Related Tables

MM01 MM02 MM03(Material) MARA, MARC, MARD, MAKT

XD01 XD02 XD03 (Customer) KNAL KNFL KNCL KNUV KNVP

XK01 XK02 XK03 (Vendor) CFAI CFBI LFMI

VA01 VA02 VA03 (Sales Order) VBAK, VBAP, VBEP, VEKD, VBP6,

VBFA, VBUK, VBUP

VL01n VL02n VL03n LIKP LIPS

(Delivery Note)

VB01 VB02 VB03 VBRK VBRP

(Listing/Exclusion)


ME21N ME22N ME23N EKKO EKPO EKKN EKET

(Purchase Order)


Few common TABLES and description:

TABLE DESCRIPTION KEY FIELDS DESCRIPTION

1. MARA General Material MATNR Material Number

Data

2. MARC Plant Data for MATNR Material Number

Material WERKS Plant

3. MARD Storage location MATNR Material Number

data for material WERKS Plant

4. MVKE Sales data for MATNR Storage Location

Material VKORG Material Number

VTWEG Sales Organization

Distribution Channel

5. MAKT Material MATNR Material Number

Description SPRAS Language Key

6. KNAI General Data in KUNNR Customer Number

Customer Master

7. KNBI Customer Master KUNNR Customer Number/

(Company Code) BUKRS Company Code

8. KNCI Customer Master KUNNR Customer Number/

(Transaction Figures) BUKRS Company Code/

GJAHR FY

9. KNUV Customer Master KUNNR Customer Number/

(Sales Data) VKORG Sales Organization

VTWEG Distribution Channel/ SPART Division

Friday, January 2, 2009

Data Dictionary Notes

Data Dictionary exists in R/3 Repository. R/3 Repository is in Database but the full image is available in Application Server for real time processing.

Data Dictionary stores and manages metadata i.e. centrally manages the metadata.

Domain = Technical Attributes.
It is a reusable object which contains technical attributes of a field.

Data Element = Short Description + Technical Description

Data Element is a reusable object which contains short description or a business context and technical attributes about a field.
We can not assign a domain directly to a field, rather we assign domain to a data element and data element to a field.

To create a field there are two methods, can be named as : Bottom up and Top Down.

Bottom Up method: Domain  Data Element  Table
Top Down: method Table  Data Element  Domain.

Steps to create domain:
1. Goto SE11.
2. Select domain radio button and click create
3. Enter domain name
(Naming convention: user defined object will start with Y or Z)
4. Click Create
5. Enter Short Description
6. Enter Datatype and no. of characters.
7. Save
8. Enter the package name OR Click on Local Object if you don’t want to assign to any package.
9. Check
10. Activate.

Steps to create Data Element
1. Goto TCODE SE11
2. Select data type  zdept-phone
3. Click on create (F5).
4. Select Data Element
5. Enter short description ( more meaningful the better)
6. In Datatype tab  Enter Domain
7. Click on Field Label
8. Enter field labels of short, medium and long
9. Save Check and Activate (ctrl + S, Ctrl + F2, Ctrl F3)
In case you want to add further description: Click on documentation.

Steps to Create Table:
1. Goto TCODE SE11
2. Select Database Table radio button
3. Enter Table name
4. Click on create
5. Enter Short Description
6. In delivery class enter A.
Delivery class (there r seven delivery classes)
7. Select A (application table, master transaction data)
8. Select check box
9. Click on fields tab
10. You can write fields names
11. Select key & int checkboxes (1st filed must,
should be primary key)
12. Click on the data element/direct type
13. Then data type will be enabled
14. Enter data & length
15. Place at cursor at sal (if ur write Sal then ) & click
on currency/quant fields
16. (Sal asks reference table i.e. same table name & ref
field is Sal type.)
17. Click on fields
18. Save(ctr+s)
19. local object
20. click on technical settings
21. type data class(APPLO)
22. click (bcoz A is master data so data class is APPLO)
23. size category 0
24. save
25. back(F3)
26. activate ( ctr F3)
27. to add records utilities – table contents – create entries
28. then you can type records
29. save
30. reset & store another records
31. back
32. to display the records utilities – tale contents – display
NOTE: - All key fields should come first.
-If a data element doesn’t exist, first double click on data element and it takes you to data element browser.
- For more info refer ABAP for newbie: Creating the database tables



Creating Table Maintenance Generator: because end user will not be able to access SE11.
Prerequisites: Need to have function group.
Function Groups  SE80  Dropdown Select function group.
Enter function group name  short description  Save.
Open the Database Table in change mode
Utilities  Table Maintenance generator.
Authorization Group  Enter &nc& (for no authorization).
Enter function group name.
Select Maintenance type as one step.
Over the View Screen  Click on find screen number.
Save and activate.

Creating Transaction Code for a table:
1. Goto SE93
2. Enter desired TCODE name
3. Click on Create (F5)
4. Enter Short Text.
5. Transaction with parameters
6. Transaction SM30
7. Click on GUI attribute
8. Name of screen field ( VIEWNAME UPDATE)
9. Give Value as ZDEPT_DETAILS i.e. the table name.

Domain  Data type, description
Attributes  Decimal Places  for Decimal data type.
Allows to enter how many decimal places.
It is enabled for only data type.
Output Length  When the display format is different than that of input format, we use output length,
Generally Output Length will be same or more than input length,
Color Color Code
Yellow 1
Red 2
Green 3
White 4

Conversion Routines  ZCLR
CONVERSION_EXIT_ZCLR_INPUT  YELLOW  1.
CONVERSION_EXIT_ZCLR_OUTPUT  1  YELLOW

Whenever input storage format is different from output display format (format or value), we use conversion routines.

Eg: if zclr is conversion routine, which we assign in a domain, then create two function modules 
1. Conversion_exit_zclr_input
2. Conversion_exit_zclr_output
 Sign
To display values with leading sign – we use sign for integers.

 Lower Case:
Into the database, everything is taken as upper case, if one wants to make it as mixed case – select this check box.

Value Range  In order to restrict the entries into the field, specify single value limit or intervals (value range).

Tables

Delivery Class – Specifies how table data should behave during a client copy or while upgrade.
 Data Browser / Table View Maintenance
1 – Display maintenance allowed - We can create entries into the table, we can change and we can display.
2 – Display maintenance allowed with restrictions. We can only display the data in this case user creates data through transaction.
3 – Display Maintenance not allowed. You cannot do maintenance.


Technical Settings specify how effectively we are managing table in the Database.

Data Class:
Master Data – APPL 0
Transactional Data – APPL1
Organizational Data APPL2

SIZE Category: Specifies in which portion of database, table is stored.
Size Category  0 – 0 to 24000
When 24,001 record is entered, database allocates another 24,000 records to memory but database has to take overhead of storing extra records.

NOTE: Initial chunk is same for all size category that of 24,000.