ABAP Workbench Programming Techniques - BC402

b>Data object Naming convention
30 chars - Not use ( ) + . , : Data declaration
Global - Defined outside of program (data dictionary)
Local - Within program (or within sub-routine)

ABAP Program components
• Source code
• Screen
• Interface
• Text elements
• Documentation

Types of program
1 - Executable program
M - Module pool
F - Function Group
I - Include program
J - Global interface
K - Global class
S - Subroutine pool (obsolete, replaced by func groups)

Report xyz
Must be included at the start of each report.

LINE-COUNT   	55(4)  	- 55 rows
			- 4 lines reserved for footer
LINE-SIZE 	255	- Line width

Create List / Report Header
• From within display report(executed report) System->List->List header
• From within Code Goto->Text elements->List Headings
• Write Text Symbol (i.e. TEXT-001) within TOP-OF-PAGE event

Pre-Defined data types
ACCP - Accounting period YYYYMM
CHAR - Character string
CLNT - Client
CUKY - Currency key, referenced by CURR field
CURR - Currency field, stored as DEC
DATS - Date field (YYYMMDD), stored as CHAR(8)
DEC - Calculation or amount field with + and -.
FLTP - Floating point number with eight-byte accuracy
INT1 - 1 byte integer. Whole num <= 255
INT2 - 2 byte integer. Only for length field before LCHR or LRAW
INT4 - 4 byte integer. Whole number with + or - sign.
LANG - Language key
LCHR - Long char string. Must be proceeded by an INT2
LRAW - Long byte string. Must be proceeded by an INT2
NUMC - Character string containing only digits
PREC - Accuracy of QUAN field
QUAN - Quality field. Points to a units field with type UNIT
UNIT - Unit key for QUAN field
RAW - Uninterpreted byte sequence
TIMS - Time fields(HHMMSS), stored as CHAR(6).
VARC - long char string (not supported after release 3.0)
STRING - Character string of variable length
RAWSTRING - Byte sequence of variable length

Default variable declaration
DATA: var = Char 1
Var(2) = Char 2
Var(2) type c = Char 2

Internal table
Internal tables have the following components:

Line type - Attributes of individual field types
Key definition - Which fields are key fields. Can also use the DEFAULT Key addition (when creating within ABAP)
Key type - Unique/Non-unique
Access type - Can use index or Key. (STANDARD, SORTED, HASHED, INDEX, ANY)

• Internal table default size is 8K
• When writing price you should also use the currency key I.e. Write: sflight-price CURRENCY sflight-currency
• Also when writing Quantity you should use the Unit key. I.e. Write: sflight-quantity UNIT sflight-unit.

Sorted tables
• Should not append to sorted table as if new entry is not in sequence the program will abend.
• Can not use the 'SORT' command on a sorted table.

Select options
SELECT-OPTIONS: so_conn for spfli-connid.
* Need the TABLES statement to reference spfli-connid in select-option. Acts as an interface between ABAP processor and the screen processor.

Structure of SELECT-OPTION: <table> Sign Option Low High I BT 1 10 E EQ 5 Etc
*Creates table with header line

Range table
DATA: r_conn type RANGE of spfli-connid.
*The RANGES statement is obsolete

TABLES statement
Make available to my program a work area with the same name.

TABLES: EKKO creates a wa called EKKO with the same structure as the EKKO table.

Turns structure into internal table but is really obsolete now and should use TYPE standard table of ..
DATA: begin of new1.. "Structure
DATA: begin of new1 occurs 0... "Internal table

New Method
DATA: new1 type standard table of t_ekko...

Logical databases
Logical databases provide an easy way to see relationships between tables.
Do a where used on a table, in logical database and it will produce a list of all logical databases which uae that table. You can then view the LDB's and see if they have the appropriate relationships.

Fields Symbols
Used as pointers to data variable
ASSIGN d_int to
= 17. " and d_int would have the value 17
UNASSIGN . "or ASSIGN to another variable

DATA: int type I value 15.
DATA: d_ref1 type ref to data.

GET REFERENCE of int INTO d_ref1.

Dynmic type casting
Allows you to assign a structure to a field/wa dynamically during run time.
Parameters: pa_dbtab type dd021-tabname.
DATA: line(65535).
Select from (pa_dbtab) INTO line.
ASSIGN line to casting TYPE (pa_dbtab)

Declaring data object dynamically
Parameters: pa_dbtab type dd021-tabname.
DATA: d_ref TYPE ref to data.
CREATE DATA d_ref TYPE (pa_dbtab).
ASSIGN d_ref->* to . "Assigns structure to field symbol(->*).

Number of lines in an itab (DESCRIBE)
See here for information on the ABAP DESCRIBE statement

Internal table without header line
Clears contents of internal table.

Internal table with header line.
Clears header line.
REFRESH clears the contents of the table.

Fields population
Char fields
• Char fields are filled with letters from left to right
• Char fields are filled with numbers from right to left

Numeric fields
• Numeric fields are filled from right to left and filled with leading zeros if required.


VAR+0(3) = THU
VAR+5(1) = D

Date/Time manipulation
* Date is store as number of days from a particular date, therefor SAP can easily add/subtract days.

DATE1 = sy-datum - 125 (todays date - 125 days)
TIME1 = sy-uzeit - 7200 (Current time - 7200 secons)

Program attributes check box:
Fix point arithmetic - Exact values
Floating point arithmetic - Used for approximation

USE LIKE when creating something the same as something that has already been created using the TYPE statement. ? i.e. itab1 like itab2.

Function modules
See here for information on the ABAP Function Modules

See here for information on the ABAP Subroutines

• Can have 6 external sessions
• Can have 9 internal sessions within each external session.

SUBMIT WITH p_carrid EQ 'AA' WITH p_connid EQ '0017' AND RETURN.
See here for information on the ABAP SUBMIT statement

Environment -> Controls examples

Reuse Components.
Business addins CL_EX_*
Implementation of class and business addins CL_IM_*
Controls CL_GUI_*

List levels (SY-LSIND)

Get Technical Information of a field
F1 -> Technical Info(F9)

Authorisation object values
01 - Create
02 - Change
03 - Display
04 - List

What is the Dispatcher
Takes from user and gives it to most appropriate work process(i.e. the one that is not busy)

SAP ABAP messages
X - Short dump
A - Program termination
E - Return to last displayed list
W - "
I - Information
S - Success message

ABAP code to modify Screen fields

Loop at screen.
	If screen-name EQ 'SFLIGHT-CONNID'
Or	If screen-group
                  Screen-input = ' '.
                  Modify screen.

Related Articles

Beginners Guide to learning SAP development starting with logging into SAP
ABAP Programming EVENTS in SAP
ABAP Function Module basics in SAP
DATA and @DATA Inline ABAP declarations available from release 7.40 to help make your code cleaner and more readable
ABAP rules to consider before creating a bespoke abap report or program
ABAP Subroutine basics in SAP
Get access to an SAP system for individual needs
SAP Base 64 encoding and decoding using ABAP code
Call web URl from ABAP report or SAP help documentation
Direct download, downloading sap objects
SAP Icons
SAP icons and some ABAP code to display them
SAP icons list and their associated codes
Internal Program Environment diplays all internal/external objects and operations used by an SAP program
minisap installation on your local pc to allow ABAP development, your own local SE80
SAP minisap installation on your local pc to allow ABAP development for free
SAP module based information such FI, HR, MM, PM, BW etc
Need an SAP ABAP program created?
SAP repository objects - List of useful standard and bespoke SAP repository objects
Retrieve SAP objects using transport entry in SE10 to restore objects that have been deleted
SAP Help for all areas for SAP ABAP Development inc ABAP, ALV, Web dynpro, bsp, HR, BW
ABAP tutorial - Logging into an SAP system for the first time
Manage and delete SAP sessions using ABAP code
SAP module areas
Increase & Decrease size of SAP editor text
ABAP development information and code examples for producing be-spoke SAP functionality
ABAP Development Info - Example code and information on various areas of ABAP development
SAP command field entries - box in top left corner
Force new page when printing abap source code
ABAP FIELD SYMBOL - Techniques for manupulating data using the FIELD-SYMBOL statement
Hiding ABAP Source Code so that it can not be viewed by anyone
ABAP Internal table declaration - Various methods of creating internal data structures and tables
Parameter ID - ABAP code to demonstrate how to set and get a parameter ID
RANGE statement - Example ABAP code to demonstrate the RANGE command
Change SAP logo in top right hand corner of SAP client
ABAP SELECT statement within SAP - Example ABAP code to demonstrate the SELECT command
Create desktop Shortcut to SAP function
SAP Note assistant - Using transaction SNOTE to read and apply OSS note fix
VARYING command - Example ABAP code to demonstrate the VARYING command
Creating your first helloworld ABAP report in SAP