A Client is looking to switch to SAP from JBA

IBM i

Oct 11

Bored in my hotel room last night I decided it’s time to do a little research about SAP: There’s been a lot of buzz around SAP since the mid 90’s… 20 years late, I decided to check it out 😉

This blog is an ongoing brain-dump so don’t take it as gospel

What is SAP anyway?

SAP is an Enterprise Resource Planning eBusiness system – covering every part aspect of business requirements. The name SAP is an acronym for Systems, Applications and Products in Data Processing.

SAP iscategorized into 3 core functional areas:

  • Logistics
    • Sales and Distribution (SD)
    • Material Management (MM)
    • Warehouse Management (WM)
    • Production Planning (PP)
    • General Logistics (LO)
    • Quality Management (QM)
  • Financial
    • Financial Accounting (FI)
    • Controlling (CO)
    • Enterprise Controlling (EC)
    • Investment Management (IM)
    • Treasury (TR)
  • Human Resources
    • Personnel Administration (PA)
    • Personnel Development (PD)

it’s like a re-written JBA, a JBA on steroids, written properly with core code that you never change but every program has EXIT ROUTINES that you can modify to your heart’s content… and it’s web enabled… the GUI is ugly but the system as a whole is very modular and virtually every review I read about it was good

SAP graphical user interfaces (SAPGUI) runs on Windows / IBMi / Unix /

What language is it written in?

It’s written in a language called Advance Business Application Programming (ABAP)., which is sort of like just about all of the 4GL languages. It’s very similar to RPG/Free and Java.

Look at this example and compare the structure to RPG – it’s very similar (F/D-specification stuff, then mainline with nested loops):

REPORT ZSBEN002 LINE-SIZE 120 LINE-COUNT 90.

*———————————————————————-*

* Description: The report creates a user list of the system. *

* Useful in a multi-client development system. *

* Fields: user-id, client, printer, profiles *

* *

* Parameters: Mand, when ‘ ‘ sorted by user, when ‘X’ sorted by client *

* *

* Authorization: S_USER_GRP, User Master Anzeigen *

* ( Warning: It is not adequate for a production system ) *

* *

* Class: Report *

* *

* Customizing: – *

* *

* R/3 Release: 3.0d

*

*———————————————————————-*

TABLES: USR04, USR01, TSP03.

PARAMETERS: MAND.

DATA: BEGIN OF U4 OCCURS 0,

MANDT LIKE USR04-MANDT,

BNAME LIKE USR04-BNAME,

MODDA LIKE USR04-MODDA,

MODTI LIKE USR04-MODTI,

MODBE LIKE USR04-MODBE,

NRPRO LIKE USR04-NRPRO,

PROFS LIKE USR04-PROFS.

DATA: END OF U4.

DATA: X TYPE I VALUE 2.

DATA: Y TYPE I VALUE 1.

DATA: Z TYPE I.

FIELD-SYMBOLS: <A>.

TOP-OF-PAGE.

ULINE (102).

WRITE: / ‘|Name’,’ |Cli. |’,’Prin.|’,’Mod.date |’,

‘Creator |’,’User Profile’, 102 ‘|’.

ULINE (102).

SKIP.

ULINE (102).

END-OF-SELECTION.

AUTHORITY-CHECK OBJECT ‘S_USER_GRP’

ID ‘CLASS’ FIELD ‘*’

ID ‘ACTVT’ FIELD ’03’.

IF SY-SUBRC NE 0. EXIT. ENDIF.

REFRESH U4.

CLEAR U4.

SELECT * FROM USR04 CLIENT SPECIFIED.

MOVE-CORRESPONDING USR04 TO U4.

APPEND U4.

CLEAR U4.

ENDSELECT.

IF MAND EQ ‘ ‘.

SORT U4 BY BNAME MANDT.

ELSE.

SORT U4 BY MANDT BNAME.

ENDIF.

LOOP AT U4.

* Check that all profiles of the user is on the same page

Z = ( SY-LINCT – SY-LINNO ) – ( U4-NRPRO – 2 ) / 36 – 1.

IF Z LE 0. NEW-PAGE. ENDIF.

FORMAT INTENSIFIED OFF.

SELECT SINGLE * FROM USR01 CLIENT SPECIFIED WHERE

MANDT EQ U4-MANDT AND

BNAME EQ U4-BNAME.

SELECT SINGLE * FROM TSP03 WHERE PADEST EQ USR01-SPLD.

WRITE: / ‘|’,U4-BNAME INTENSIFIED ON,

‘|’,U4-MANDT,

‘|’,USR01-SPLD,

‘|’,U4-MODDA,

‘|’,U4-MODBE,’|’.

ASSIGN 1 TO <A>.

DO.

ASSIGN U4-PROFS+X(12) TO <A>.

IF <A> EQ ‘ ‘.

EXIT.

ENDIF.

Y = ( X – 2 ) / 12.

IF Y NE 0.

Y = Y MOD 3.

IF Y EQ 0.

WRITE: / ‘| | | | | |’.

ENDIF.

ENDIF.

WRITE: <A>,’|’.

ADD 12 TO X.

ENDDO.

WHILE X > 38.

X = X – 36.

ENDWHILE.

CASE X.

WHEN 26.

WRITE: ‘ |’.

WHEN 38.

WHEN 14.

WRITE: ‘ | |’.

WHEN 2.

WRITE: ‘ | | |’.

WHEN OTHERS.

WRITE: / ‘ez az:’, X.

ENDCASE.

X = 2.

Y = 1.

WRITE: / ‘| |———————————————

—————————————-|’.

AT END OF BNAME.

POSITION 1. WRITE ‘—————‘.

ENDAT.

* New-page at the end of each Client, when sorted by client

AT END OF MANDT.

CHECK MAND EQ ‘X’.

NEW-PAGE.

ENDAT.

ENDLOOP.

White space significance

ABAP has no format restrictions. You can enter statements in any format, so a statement can be indented, you can write several statements on one line, or spread a single statement over several lines. The only requirement is that every statement ends in a period.

You must separate words within a statement with at least one space. The system also interprets the end of line marker as a space.

The two-line “Hello World” program from above could also be written as

PROGRAM TEST. WRITE 'Hello World' .

or even as:

 PROGRAM
 TEST.
 WRITE
  'Hello World'.

Free formatting is convenient, but with complex code, such as deeply nested IF/ELSE blocks, it can get tricky. The ABAP editor therefore offers a “Pretty Printer” function, which can take care of proper indentation.

One obvious exception to the free-formatting rule are text literals. A text literal is a sequence of alphanumeric characters in the program code enclosed in single quotes. If a text literal in an ABAP statement extends across more than one line, then a ‘&’ character must be used to combine a succession of text literals into a single one. Example:

USERPROMPT = 'Please double-click on a line in the output list ' &
  'to see the complete details of the transaction.'.

Case sensitivity

ABAP statements are not case-sensitive. The following code is perfectly permissible:

proGRAm TEsT.
WriTe 'Hello World'.

Users can configure the way source text is presented (all upper case, all lower case, ABAP keywords in upper case and variable names in lower case, etc.) according to their own preference. Typically the keywords are in upper case and everything else (variable, function, method, and class names) in lower case.

Chained statements

The ABAP programming language allows you to concatenate consecutive statements with an identical first part into a chain statement.

To concatenate a sequence of separate statements, write the identical part only once and place a colon (:) after it. After the colon, write the remaining parts of the individual statements, separating them with commas. Ensure that you place a period (.) after the last part to inform the system where the chain ends.

Chaining is very often used in WRITE statements. WRITE accepts just one argument, so if for instance you wanted to display three fields from a structure called FLIGHTINFO, you would have to code:

WRITE FLIGHTINFO-CITYFROM.
WRITE FLIGHTINFO-CITYTO.
WRITE FLIGHTINFO-AIRPTO.

Chaining the statements results in a more readable and more intuitive form:

WRITE: FLIGHTINFO-CITYFROM, FLIGHTINFO-CITYTO, FLIGHTINFO-AIRPTO.

In the chain, a colon separates the beginning of the statement from the variable parts. After the colon or commas, you can insert any number of spaces.

You could, for example, write the same statement like this:

WRITE: FLIGHTINFO-CITYFROM,
  FLIGHTINFO-CITYTO,
  FLIGHTINFO-AIRPTO.

In a chain statement, the first part (before the colon) is not limited to the keyword of the statements. For example, the code

SUM = SUM + 1.
SUM = SUM + 2.
SUM = SUM + 3.
SUM = SUM + 4.

could be written in chained form:

SUM = SUM + : 1, 2, 3, 4.

[]Comments

ABAP has 2 ways of defining text as a comment.

An (*) in the leftmost column of a line makes that line a comment. A double quotation mark («”») anywhere on a line makes the rest of that line a comment.

[]Example

***************************************
** Program: BOOKINGS  **
** Author: Joe Byte, 07-Jul-2007 **
***************************************




REPORTBOOKINGS.




* Read flight bookings from the database
SELECT* FROM FLIGHTINFO
  WHERE CLASS = 'Y' "Y = economy
  OR CLASS = 'C'.  "C = business
(...)

Naming notation

ABAP has a large number of naming conventions for different language elements. These are conventions and not rules, so an ABAP programmer is free to abide by them or not. However ABAP code developed by SAP itself generally respects these naming rules. Below is a list.

  • ALV_*SAP List Viewer
  • AS_*Methods that perform type conversions
  • CHECK_*Check Methods
  • CH_*Changing Parameters
  • CT_*Changing Table
  • CL_*Class name
  • CO_*/C_* Constants
  • DR_*Data reference
  • G_*Global variables/data objects
  • GT_*Global table
  • GX_*Global boolean field (X or space)
  • IF_*Interface
  • INT_*/IT_ Internal Table
  • IS_*Methods that return a Boolean value
  • L_*Indicates the data object is local. Often, before underscore, put a ‘type letter’ in case of simple type (LC_,LF etc.)
  • LC_*Local Constant
  • LV_*Local Variable
  • LR_*Local Range
  • LT_*Local Table
  • LS_*Local Structure
  • LVC_*List Viewer Control
  • ON_*Event handler
  • PA_*Parameters
  • PE_*/EX_* Export parameter
  • PI_*/IM_* Input parameter
  • RA_*Ranges/Type Range Of
  • RE_*Result
  • RF_*Reference Variable
  • SET_*Accessors Methods
  • SO_*Select-Options
  • ST_*Structure
  • TA_*Internal Standard Table
  • TC_*Table Control
  • TH_*Internal Hashed Table
  • TP_*Other Variables
  • TS_*Internal Sorted Table
  • TT_*Table type
  • TY_*Types
  • T_*Variable is a table (T_MY_TABLE_VARIABLE)
  • X*Source/first data object (e.g. XVBAK)
  • Y*Destination/second data object (e.g. YVBAK)
  • WA_*Work Area
  • $*Static Variable
  • **Secondary working area (e.g. *VBAK in TABLES statement. Obsolete)

DATA and TYPES

It is a special strength of ABAP that you can define a great variety of data types and objects that span the spectrum from very elementary data types to very complex and dynamic types. Consequently, the subject of ABAP declarations is quite extensive.

ABAP accepts all data types defined in the SAP dictionary or in Type Pools. Types can also be defined inside the program itself. Object numeric (I for integer, F for floating point), packed decimal (P), character (C or N, where the N type is used for numeric strings that can be used in computation) or hexadecimal (X). Date fields (type D) and time fields (type T) have a “dual” nature; in an input/output context they behave like strings, but in a computational context they are numeric integers. There are no built-in functions or statements for dealing with dates and times; but, as in spreadsheets, arithmetic can be performed on a date-value to break it up. For example:

DATESENT = '20070901'.
VALIDTO = DATESENT + 60.
WRITE: 'Offer is valid until', VALIDTO DD/MM/YYYY.

In this example, a string literal representing September 1, 2007 is assigned to DATESENT. DATESENT is then used in a numeric calculation to produce another data field, VALIDTO, which is set to DATESENT plus 60 days. Finally, VALIDTO is output as a string. The optional “DD/MM/YYYY” modifier displays the date in a predefined format, here “31/10/2007”. Without the modifier the date would display as “20071031”.

Data and Types

All ABAP variables must be explicitly declared in order to be used. The convention is for all declarations to be at the top of the program, or subroutine. The declaration consists of the name, type, length (where applicable), additional modifiers (e.g. the number of implied decimals for a packed decimal field) and optionally an initial value:

* Primitive types:
DATA: COUNTER  TYPE I,
  VALIDITY TYPE I VALUE 60,
  TAXRATE(3) TYPE P DECIMALS 1,
  LASTNAME(20) TYPE C.




* Dictionary types:
DATA: ORIGIN TYPE COUNTRY.




* Internal table:
DATA: T_FLIGHTS TYPE TABLE OF FLIGHTINFO,
  T_LOOKUP TYPE HASHED TABLE OF FLT_LOOKUP.




* Objects:
DATA: BOOKING  TYPE REF TO CL_FLT_BOOKING.

Notice the use of the colon to chain together consecutive DATA statements.

ABAP Objects

The ABAP language supports object-oriented programming, through a feature known as “ABAP Objects”. This helps to simplify applications and make them more controllable.

ABAP Objects is fully compatible with the existing language, so one can use existing statements and modularization units in programs that use ABAP Objects, and can also use ABAP Objects in existing ABAP programs. Syntax checking is stronger in ABAP Objects programs, and some syntactical forms (usually older ones) of certain statements are not permitted.

Follow

About the Author

IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Alpha Nerd and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and in the words of the most interesting man in the world: Stay thirsty my friend.