2018年9月28日 星期五

How to modify and extend SAP applications – Different approaches + Transaction codes

如何修改及延伸 SAP 應用系統
How to modify and extend SAP applications – Different approaches + Transaction codes

This part of series is focused on transactions that allow an ABAP developer enhance the original SAP reports with his own modifications. You will find here the list of transactions – possibilities how to extend SAP reports, internal logic within function modules, classes or dictionary objects.

This post is part of series about SAP transaction codes for ABAP Developers:
  1. Basic SAP transactions for ABAP developers
  2. How to modify and extend SAP applications
  3. Transaction codes for database and table handling
  4. How to analyse, debug and optimize your SAP programs with standard tools

Introduction

There are following options how to modify SAP’s standard code. Recommended approaches are BADI implementations and enhancement points.
  • BADI implementations – SE18, SE19
  • Enhancement points – implicit or explicit enhancements points – SE80
  • User exits – CMOD, SMOD
  • Modifications – SE95, SPAU, SPDD

1. Business Add Ins (BADI)

SE18 – BADI Builder – Definitions

BADI stands for Business Add Ins which is an advanced way of implementing modifications. Developer can use BADI builder definition for creating or searching for possible places where he or his customers can modify ABAP logic using BADI or enhancement spots.

SE19 – BADI Builder – Implementations


When the developer knows which BADI or enhancement spot he wants to modify, he can manage BADI implementations and enhancement spots in se19.




2. Enhancements

SMOD – SAP Enhancements


SAP Enhancements transactions is a former type of SAP’s way to modify programs using user exits. Anyway, it can still be handful for developer to know this transaction, since he may come across old solutions which used this technique. SMOD includes more type of user exits – menu, screen and function module exits.




CMOD – Project Management of SAP Enhancements


CMOD transaction is used for managing attributes, enhancement assignments, components and documentation of SAP Enhancement. Developer manages here Enhancement projects which are formed by Enhancements from SMOD.





3. Enhancement points

SE80 – ABAP Development Workbench

SE80 transaction was already mentioned in the first article about essential transaction codes for ABAP development. The reason why it is included here is the fact, that the developer can manage enhancement points through this transaction. When the developer clicks on a highlighted icon, enhancement implementation tools will be available for him. He can choose either from explicit or implicit enhancement points in the source code where he can insert his own code or modify already implemented enhancement points.


4. Modifications

SE95 – Modification Browser

When there is no other option, the developer can also create modifications in the source code using transaction se80. First he needs to obtain repair registration key from SAP OSS, then the modification will be possible. Be aware that this is the most painful way because the developer will have to take care about merging the changes after every service pack upgrade or note implementation using transactions SPAU and SPDD. Modification browser is the used by developer to manage all recent modifications in the system.

SPAU – Modification Adjustment

After every upgrade, modifications has to be rechecked. When there is a change in the standard code in the same place where is the modification, developer needs to adjust this modification.

SPDD – Modification Adjustment for Dictionary

The same approach must be used for dictionary objects. Whenever the dictionary object is changed, developer have to repeat the modification.









SAP 資料庫 Transaction codes for Database and Table handling

Transaction codes for Database and Table handling
In this part of series, I am going to describe several original SAP transaction codes (reports and utilities) for handling tables and database.

This post is part of series about SAP transaction codes for ABAP Developers:
  1. Basic SAP transactions for ABAP developers
  2. How to modify and extend SAP applications
  3. Transaction codes for database and table handling
  4. How to analyse, debug and optimize your SAP programs with standard tools

Basic transactions for table management SE11 – ABAP DictionarySE16 – Data BrowserSE54 – Generate Table Maintenance are described in the first post of the series. Just to remind you, se11 is used for managing dictionary objects including database tables, se16 is used for browsing the data in a database table and finally se54 is used creating maintenance views where you can manage that data.
Apart from these basic transaction codes, there are several more advanced utilities which are used for specific database operations. Those transaction codes(t-codes) are as following.

SE14 – Database utility

Whenever you change the structure of a table which is derived from ABAP dictionary object (transparent table, physical table pool, table cluster, indexes or database views) , you also need to run the database utility in order to synchronize changes between ABAP Dictionary and database layer. Moreover, this utility allows you to maintain terminated conversions, administer modification requests and manage incremental conversions.

SE16n – Table display

Transaction SE16N is actually an improved and more user-friendly data browser SE16 with ALV data grid. Until EHP5, it was possible to enter code &SAP_EDIT and edit data inside of tables, but due to security risk, this option is not available anymore. Anyway, there is still an option to turn on edit mode using debugger.




SM30, SM31 – Generate table maintenance dialog

Transaction SM30 allows you to run generated dialog where it is possible to view and change data in database tables and views. Those database objects must have set up the option Display/Maintenance allowed in ABAP Dictionary table management and have already generated table maintenance via SE54.

Transaction SM31 refers to the same program which SM30 does, so there is no difference between this transaction. The old SM31 transaction is available as transaction SM31_OLD.

DB02 – Database analysis


DB02 is a database analysis tools which displays various statistics of database and database objects. The purpose of this tool is to check whether there are missing indexes in database tables and check consistency of database objects.  Moreover, this tool can give you overview of data area occupancy (available/occupied space) of the whole database.







How to analyse, debug and optimize your SAP programs with standard tools
There is a phase in development cycle when the programmer needs to optimize his final product. This post focuses on those transactions which help developers to analyse, debug and optimize already finished reports and programs.

This post is part of series about SAP transaction codes for ABAP Developers:
  1. Basic SAP transactions for ABAP developers
  2. How to modify and extend SAP applications
  3. Transaction codes for database and table handling
  4. How to analyse, debug and optimize your SAP programs with standard tools

SAP system offers several options how to analyze our programs. Let’s start with the debugger.

Developer tools

Debugger

There are basically two options how to use a debugger. You can either start the debugger when you set a session break point in your code while using se80 or se38. When you run the program additional window with (new) debugger will show up.
The other method to is enter one of these following codes into command field just before you run the report:

  • /h – basic and most used command which will run the debugger
  • /hs – start debugger and allow system debugging
  • /ha – start debugger, skip screen handling and start directly debugging ABAP code
  • /hmusa – start debugger and create memory snapshot which can be analysed in transaction S_MEMORY_INSPECTOR

2018年9月27日 星期四

Skip to end of metadata
Go to start of metadata
BAPIs can you find in SE37 when searching with:
BAPI
Operative Object
BAPI_BUS2172*Project
BAPI_BUS2173*Phase
BAPI_BUS2175*Task
BAPI_BUS2176*Checklist Header
BAPI_BUS2174*Checklist Item
BAPI_BUS2177*Role


BAPI
Templates
BAPI_BUS2170*Project Template
BAPI_BUS2167*Phase in Template
BAPI_BUS2169*Task in Template
BAPI_BUS2171*Checklist Template
BAPI_BUS2168*ChkLst Itm in Temp
BAPI_BUS2178*
Role in Template
New BAPIs for resource management in Detail:
BAPI name
BAPI Role/ function
BAPI_BUS2177_ROLE_DIST_GET
Determine Demand Distribution
BAPI_BUS2177_ROLE_DIST_SET
Change Demand Distribution
BAPI_BUS2177_STAFF_DIST_GET
Determine Demand Distribution
BAPI_BUS2177_STAFF_DIST_SET
Change Demand Distribution


BAPI_BUS2177_ROLE_DIST_SET SAP Function module - BAPI Role: Change Demand Distribution

 Hierarchy

  CPRXRPM (Software Component) SAP Portfolio and Project Management 6.0
     PPM-PRO-EXT-API (Application Component) BAPI Interface for cProjects
       DEVELOPMENT_PROJECTS_BAPI (Package) Project Management - BAPI

 Basic Data

Function ModuleBAPI_BUS2177_ROLE_DIST_GETBAPI Role: Determine Demand Distribution  
Function GroupDPR_BUS2177  Development Projects: Role  
Program NameSAPLDPR_BUS2177   
INCLUDE NameLDPR_BUS2177U40   

 Parameters

TypeParameter NameTypingAssociated TypeDefault valueOptionalPass ValueShort text
 ExportingES_DIST_ADMIN_DATATYPEBAPI_TS_DIST_ADMIN_DATADistribution administration data
 ExportingEV_DIST_GUIDTYPEDPR_TV_GUIDApplication Object GUID
 ExportingEV_ENTITY_GUIDTYPEDPR_TV_GUIDApplication Object GUID
 ImportingPROJECTROLE_GUIDTYPEBAPI_TS_GUID-ROLE_GUIDGUID for Project Role
 TablesET_DISTRIBUTIONTYPEBAPI_TS_DIST_DATADistribution data
 TablesRETURNTYPEBAPIRET2Return Parameters
        

 Processing Type

 Normal Function Module 
 Remote-Enabled Module BaseXML supported
 Update Module Start immediately
 Immediate Start, No Restart
 Start Delayed
 Coll.run
 JAVA Module Callable from ABAP 
 Remote-Enabled JAVA Module 
 Module Callable from JAVA 

 History

Last changed by/onSAP 20141109 
SAP Release Created in310  

讀出功能模組文件 SAP Function Module Documentation


Get SAP function module documentation



Step 1 - Execute transaction SE37 
First, execute sap transaction SE37 and enter the function module name. Then press the display button 
 

Alternatively, choose menu option Goto->Documentation->Function Module Documentation. The only problem I find with this option is that the documentation popup box appears underneath the current SAP window so you don't actually see it without moving the window 
 

Step 2 - Display documentation 
If you selected display you will be taken to the FM details, now simply choose the menu option goto->Documentation. 
 

The Function module documentation will now be displayed 
 

Step 3 - Alternate way using tcodevSE80 
You also get the same options to view Function Module documentation within SAP transaction SE80 

2018年9月26日 星期三

ABAP/4 讀取 Database table, store procedure
  1. data:
  2. PAR1(30) type C,
  3. PAR2(30) type C,
  4. OUT1 type I,
  5. OUT2(30) type C,
  6. OUT3(30) type C.
  7.  
  8. exec sql performig sp_return.
  9. select * from $PROC$sp_dummy
  10. where ( :par1, :par2 )
  11. into :out1, :out2, : out3
  12. endexec.
  13.  
  14. form sp_return.
  15. * some coding
  16. endform

General Types
Predefined data types without special semantic attributes.
Numeric Types
TypeValid Places mInitial ValueMeaningABAP Type
INT1301-byte integer, 0 to 255b
INT2502-byte integer, -32,768 to 32,767s
INT41004-byte integer, -2,147,483,648 to +2,147,483,647i
INT81908-byte integer, -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807int8
DEC1-310Packed number BCD formatp, length DIV 2 + 1
DF16_DEC1-150Decimal floating point number stored in BCD formatdecfloat16
DF16_RAW160Decimal floating point number stored in binary formatdecfloat16
DF34_DEC1-310Decimal floating point number stored in BCD formatdecfloat34
DF34_RAW340Decimal floating point number stored in binary formatdecfloat34
FLTP160Floating point numberf

Character-Like Types
TypeValid Places mInitial ValueMeaningABAP Type
CHAR1-30000, maximum of 1333 for table fieldsm blanksCharacter stringc, length m
LCHR256-32000Nonelong character stringc, length m
SSTRING1-1333Empty stringCharacter stringstring
STRING256-...Empty stringCharacter string (CLOB)string

Byte-like types
TypeValid Places mInitial ValueMeaningABAP Type
RAW1-32000 maximum of 255 for table fieldsNoneByte stringx, length m
LRAW256-32000NoneLong byte stringx, length m
RAWSTRING256-...Empty stringByte string (BLOB)xstring

Special Types
Predefined data types with special semantic attributes.
Date Types/Time Types
TypeValid Places mInitial ValueMeaningABAP Type
DATS800000000Date in the format YYYYMMDDd
TIMS6000000Time in the format HHMMSSt
ACCP66 blanksPosting period in the format YYYYMMn, length 6

Character-Like Types with Special Semantics
TypeValid Places mInitial ValueMeaningABAP Type
NUMC1-255m zeroesNumeric textn, length m
CLNT3000Clientc, length 3
LANG1BlankLanguage keyc, length 1

Currency Fields and Quantity Fields
TypeValid Places mInitial ValueMeaningABAP Type
CURR1-310Currency field in BCD formatp, length DIV 2 + 1
CUKY55 blanksCurrency key for currency fieldsc, length 5
QUAN1-310Quantity field in BCD formatp, length DIV 2 + 1
UNIT2-32 or 3 blanksUnit key of a quantity fieldc, length m

Obsolete Types
TypeValid Places mInitial ValueMeaningABAP Type
DF16_SCL160Decimal floating point number stored in binary format with scaling specified (obsolete)decfloat16
DF34_SCL340Decimal floating point number stored in binary format with scaling specified (obsolete)decfloat34
PREC20Obsolete data types
VARC1-...NoneObsolete data typec, length m



Character-Like Types and Byte-Like Types
Character Strings
The following predefined data types in ABAP Dictionary are available for general character strings:
  • CHAR for text fields
The predefined type CHAR, mapped to the ABAP type c, is used to describe general text fields with a maximum length of 30000 characters (only 1333 characters for table fields).
  • LCHR for long text fields
The predefined type LCHR, also mapped to the ABAP type c, is used to describe general text fields with lengths between 256 and 32000 characters. In database tables, the maximum length must be specified as the value of a preceding INT2 or INT4 field. Table fields of this type cannot be used as key fields of database tables or in any positions in Open SQL statements.
The predefined type SSTRING is mapped to the ABAP type string, but handled like the type CHAR or VARCHAR in ABAP Dictionary and by database tables. The length is restricted to a maximum of 1333, but table fields of this type can also be used as key fields by database tables and used by Open SQL statements in almost all positions where text fields are possible.
The predefined type STRING is mapped to the ABAP type string and also handled like a text string (CLOB) in ABAP Dictionary and by database tables. Table fields of this type cannot be used as key fields or index fields in database tables or in any positions in Open SQL statements.
Notes
  • In general structures, the length of a component of type CHAR is not restricted to 1333.
  • In database tables, there can be only one table field of the type LCHR and it must be the last table field. This means that the type LRAW cannot be used simultaneously in the same database table. If the statement SELECT is used to read an LCHR field, the preceding length field must also be read. In writes using Open SQL, the length field must be given the correct value or data may be lost.
  • LCHR is no longer recommended for new developments. The type STRING is recommended instead, however it is also not suitable for key fields of database tables or for unrestricted use in Open SQL. Where possible, SSTRING can be used here instead.
  • Switching existing dictionary objects from LCHR to STRING or SSTRING, on the other hand, can be critical, since all ABAP types and ABAP objects that reference dictionary objects like this are then given a deep data type. A switch from a flat data type to a deep data type usually constitutes an incompatible change and can produce syntax errors in ABAP programs.

Example
Like the example for literals; the row to be read is here also specified using host variables. The addition STRUCTURE is specified after INTO. However, this is not necessary since wa can be identified statically as a structure. The structure wa is handled in the INTO clause as if all substrings were specified separately: INTO :wa-cityfrom, :wa-cityto.
PARAMETERS: p_carrid TYPE spfli-carrid,
            p_connid TYPE spfli-connid.

DATA: BEGIN OF wa,
        cityfrom TYPE spfli-cityfrom,
        cityto   TYPE spfli-cityto,
      END OF wa.

EXEC SQL.
  SELECT cityfrom, cityto
         INTO STRUCTURE :wa
         FROM spfli
         WHERE mandt  = :sy-mandt AND
               carrid = :p_carrid AND connid = :p_connid
ENDEXEC. 



Example
Reads multiple rows from the database table SPFLI using cursor handling and host variables in static Native SQL. If rows are found, sy-subrc is set to 0 and sy-dbcnt is increased by one for each row read.
PARAMETERS p_carrid TYPE spfli-carrid.

DATA:  connid   TYPE spfli-connid,
       cityfrom TYPE spfli-cityfrom,
       cityto   TYPE spfli-cityto.

EXEC SQL.
  OPEN dbcur FOR
    SELECT connid, cityfrom, cityto
           FROM spfli
           WHERE mandt  = :sy-mandt AND
                 carrid = :p_carrid
ENDEXEC.

DO.
  EXEC SQL.
    FETCH NEXT dbcur INTO :connid, :cityfrom, :cityto
  ENDEXEC.
  IF sy-subrc <> 0.
    EXIT.
  ELSE.
    ...
  ENDIF.
ENDDO.

EXEC SQL.
  CLOSE dbcur
ENDEXEC. 

Bad Example
Reads multiple rows from the database table SCARR and calls the subroutine evaluate for each row read.
DATA wa TYPE spfli-carrid.

EXEC SQL PERFORMING evaluate.
  SELECT carrid FROM spfli INTO :wa WHERE mandt = :sy-mandt
ENDEXEC.
cl_demo_output=>display( ).

FORM evaluate.
  cl_demo_output=>write( |{ wa } | ).
ENDFORM.
Good Example
Explicit cursor processing.
DATA wa TYPE spfli-carrid.

EXEC SQL.
  OPEN CUR FOR
  SELECT carrid FROM spfli WHERE mandt = :sy-mandt
ENDEXEC.

DO.
  EXEC SQL.
    FETCH NEXT CUR INTO :wa
  ENDEXEC.
  IF sy-subrc <> 0.
    EXIT.
  ENDIF.
  cl_demo_output=>write( |{ wa } | ).
ENDDO.
cl_demo_output=>display( ).