Friday, 27 June 2014

Creating Class Interface in SAP Classes

Creating Class Interface in SAP Classes

+ -
As per SAP Standard documentation all the standard interfaces in SAP starts with IF_ and all the custom interfaces starts with ZIF_ , in the below example we will be learning how to create a use interfaces in SAP.
All the custom classes is SAP starts with ZCL_ and all the custom interfaces will start with ZIF_, based on the provided name (at the time of creation), SAP will automatically determine and creates (interface or class).
Go to SE24, provide name as ZIF_SAPN_MATERIAL_EXAMPL, create.
Creating interfaces in SAP Classes
Provide description, save, save it in a local object.
Creating interfaces in SAP Classes
Go to methods tab, add method name as GET_MATERIAL_DETAILS-INSTANCE, click on parameters button and add below parameters.
Creating interfaces in SAP Classes
Save, Go back to methods and add one more method GET_MATERIAL_DESCRIPTIONS.
Creating interfaces in SAP Classes
Click on parameters and provide parameters as below.
Creating interfaces in SAP Classes
Save and activate.
We have created an interface with two methods (which dosen`t have implementation).
No Go to SE24 and create a class ZCL_SAPN_CLASS_EX
Creating interfaces in SAP Classes
Provide description, save it in a local object.
Creating interfaces in SAP Classes
Go to interfaces tab and add interface name asCreating interfaces in SAP ClassesZIF_SAPN_MATERIAL_EXAMPLE, enter
Creating interfaces in SAP Classes
Now go to methods tab, you can see all the methods in the interface are automatically copied.
Creating interfaces in SAP Classes
Save, double click on each method and create your own implementation.
Double click on ZIF_SAPN_MATERIAL_EXAMPLE~GET_MATERIAL_DETAILS, and add below code.
    SELECT SINGLE * FROM MARA
      INTO EX_MARA
      WHERE MATNR = IM_MATNR.
Double click on ZIF_SAPN_MATERIAL_EXAMPLE~GET_MATERIAL_DESCRIPTIONS, add below code
    SELECT * FROM MAKT INTO EX_MAKT
      WHERE MATNR = IM_MATNR
       AND SPRAS = 'E'. "English description only
    ENDSELECT.
Save and activate the class.

Using class in program

Create a SE38 program and follow the steps below. The interface method will be clalled by using INTERFACENAME~METHODNAME.
REPORT ZSAPN_CLASS_INTERFACE.
DATA : LO_CLASS TYPE REF TO ZCL_SAPN_CLASS_EX. "declare class

DATA : WA_MARA TYPE MARA. "mara decleration
DATA : WA_MAKT TYPE MAKT. "makt decleration

PARAMETERS P_MATNR TYPE MARA-MATNR.

CREATE OBJECT LO_CLASS. "create object for the class

START-OF-SELECTION.
  CALL METHOD LO_CLASS->ZIF_SAPN_MATERIAL_EXAMPLE~GET_MATERIAL_DETAILS
    EXPORTING
      IM_MATNR = P_MATNR
    IMPORTING
      EX_MARA  = WA_MARA.
  CALL METHOD LO_CLASS->ZIF_SAPN_MATERIAL_EXAMPLE~GET_MATERIAL_DESCRIPTIONS
    EXPORTING
      IM_MATNR = P_MATNR
    IMPORTING
      EX_MAKT  = WA_MAKT.
  WRITE :/ 'Material Details - ' COLOR 5, WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MBRSH, WA_MARA-MATKL.
  WRITE :/ 'Material Descriptions - 'COLOR 6, WA_MAKT-MATNR, WA_MAKT-MAKTX, WA_MAKT-SPRAS.

Wednesday, 25 June 2014

Select with Joins in SAP ABAP

Select with Joins in SAP ABAP

+ -
SELECT WITH JOINS statement is used to read data simultaneously from multiple database tables .
As per performance standards, SELECT WITH JOINS for more than 3 tables is not advisable, as it puts heavy load on database
Syntax :

 SELECT T1~FIELD1
        T1~FIELD2
        T2~FIELD1
        T2~FIELD2
        INTO TABLE <ITAB>
 FROM T1 INNER JOIN T2 ON ( T1~FIELD1 = T2~FIELD )
 WHERE T1~FIELD = <SOME VALUE> .

** Here T1 and T2 are database tables, FIELD1 and FIELD2 are fields in respective tables

Example of using SELECT JOINS in SAP ABAP

**DATA DECLERATIONS
TYPES: BEGIN OF T_MARA,
  MATNR LIKE MARA-MATNR,  "FIELD1 FROM MARA TABLE
  MTART TYPE MARA-MTART,  "FIELD2 FROM MARA TABLE
  MAKTX TYPE MAKT-MAKTX,  "FIELD1 FROM MAKT TABLE
  SPRAS TYPE MAKT-SPRAS,  "FIELD2 FROM MAKT TABLE
END OF T_MARA.

DATA: IT_MARA TYPE  TABLE OF T_MARA .
DATA : WA_MARA TYPE T_MARA.
SELECT MARA~MATNR
       MARA~MTART
       MAKT~MAKTX
       MAKT~SPRAS
  INTO  TABLE IT_MARA
  FROM MARA INNER JOIN MAKT ON ( MARA~MATNR = MAKT~MATNR )
  UP TO 50 ROWS.


LOOP AT IT_MARA INTO WA_MARA.
  WRITE : / WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MAKTX, WA_MARA-SPRAS .
ENDLOOP.

Creating Domain and Data Element

Creating Domain and Data Element

+ -

Creating a Domain in SAP

Go to SE11 T-code, select domain radio button, provide a name (ZSAPN_DOMAIN) and create.
Create domain in SAP
Provide short description, no of characters and save (Ctrl S ).
 Domain in SAP
Select local object ( non transportable object ).
How to create domain in SAP
Activate.
 Create dataelement
Domain is created.

Creating data element in SAP

Go to SE11, select data type radio button, provide a name (ZSAPN_DATAELEMENT) and create.
 Create dataelement
A popup will open, select data element radio button
Creating dataelement
Enter short description and domain name (ZSAPN_DOMAIN) and select field label tab.
dataelement in SAP
Select field label tab and maintain field labels.
SAP dataelement

Creating Table in SAP

Creating Table in SAP

+ -
A table can be created in two ways one is top to bottom approach and another one is bottom to top approach.
1.Top to Bottom : In this approach, first table fields are defined and later domain and data element are defined.
2.Bottom to Top : In this approach, first domain and data element are defined and later table will be created .
In this example we are going to learn creating a SAP transparent table using top to bottom approach ( I suggest simplest way ).
Go to SE11 T-code, provide table name to be created ZSTUDENT_TABLE and create.
Creating a table in SAP
Provide short description, delivery class (A), Display Maintenance Allowed and select fields tab.
Creating a table in SAP
Select Fields tab, add a field STUDENT_NO, data element as ZSTUDENT_NO and check Key and Initial Value check boxes.
A table must contain at least one key field, without a key field we can not create a table.
Creating a table in SAP
Double click on data element ZSTUDENT_NO (Not yet created), a pop up will open click yes and one more information message will come press enter.
Now a pop up will come asking to create date element, click yes.
Creating a table in SAP
Provide short description, domain and label
Creating a table in SAP
Creating a table in SAP
Save, double click on domain name ZSTUDENT_NO, click on yes.
Provide short description, data type, no. characters, save and activate.
Creating a table in SAP
Similarly create remaining fields with data elements and domains as below
Creating a table in SAP
Once all fields are created click on technical settings button.
Creating a table in SAP
Provide data class and size category, save and activate.
Creating a table in SAP
You will get a warning message just click on No, table is created.
Now add entries to table.
Add entries to SAP custom table
Adding entries to SAP custom table

Tuesday, 24 June 2014

What is SAP and why SAP ?

What is SAP and why SAP ?

+ -
SAP Software is a ERP( Enterprise Resource Planing) solution, through which large and medium scale companies can manage their business.SAP Software is produced by a German based company SAP.
SAP Company: SAP Company founded in 1972 in Germany by five former employes of IBM and they released standard versions called R1 and R2 in early days, and they released 3-tier architecture R3 in 1990`s which was very successful.
In 2000 SAP released ECC (Enterprise Core Component), latest version in market is ECC 6.0 and they are adding additions to this in the form of enhancement packs.
Why SAP?
Through SAP software a company can plan their business in different aspects like Supply Chain Solutions, Material Management, Sales and Distribution, Finance controlling, Human Resource planing, etc.
The total SAP Software is built using ABAP Programing Language, which is a standard programing language developed by SAP it self, we call ABAP as 4th Generation Programing Language (ABAP/4) 
Some of Modules in SAP are :
  • SAP FI module: FI stands for Financial Accounting.
  • SAP CO module: CO stands for Controlling.
  • SAP CRM module: CRM stands for Customer Relationship Management.
  • SAP CS module: CS stands for Customer Service.
  • SAP EC module: EC stands for Enterprise Controlling.
  • SAP EHS module: EHS stands for Environment, Health and Safety.
  • SAP FM module: FM stands for Fleet Management.
  • SAP FSCM module: FSCM stands for Financial Supply Chain Management.
  • SAP HR module: HR stands for Human Resources.
  • SAP IM module: IM stands for Investment Management.
  • SAP MM module: MM stands for Materials Management .
  • SAP PLM module: PLM stands for Product Life Cycle Management.
  • SAP PM module: PM stands for Plant Maintenance.
  • SAP PP module: PP stands for Production Planning.
  • SAP Product Costing: Product Costing deals with Plan Costing Actual Costing of Finish products.
  • SAP PS module: PS stands for Project Systems.
  • SAP QM module: QM stands for Quality Management.
  • SAP RE module: RE stands for Real Estate.
  • SAP SD module: SD stands for Sales and Distribution.
  • SAP SM module: SM stands for Service Management.
  • SAP TR module: TR stands for Treasury.
  • SAP WM module: WM stands for Warehouse Management.
  • SAP LO module: LO stands for Logistics General.
  • SAP ABAP module: ABAP stands for Advanced Business Application Programming.
  • SAP Basis module: Basis also known as Basis Admin is typically the administration of SAP.
  • SAP BI module: BI stands for Business Intelligence.
  • SAP BPC module: BPC stands for Business Planning and Consolidation.
  • SAP BODI module: BODI stands for Business Objects Data Integrator.
  • SAP EP module: EP stands for Enterprise Portal.
  • SAP GRC module: GRC stands for Group Risk Compliance.
  • SAP MDM module: MDM stands for Master Data Management.
  • SAP Netweaver module: Netweaver provides technical foundation for SAP applications.
  • SAP Security module: Security ensures security of enterprise operations.
  • SAP Solution Manager module: Solution Manager facilitates technical support for distributed systems.
  • SAP XI module: SAP Exchange Infrastructure (SAP XI) enables you to implement cross-system processes on services.
  • SAP PI module: SAP Process Integration (SAP PI) is enterprise application integration (EAI)software.

Interactivereports and it`s events

Interactivereports and it`s events

+ -
  • Displaying the basic information on the basic list and the detailed information in the secondary list is called as interactive reports.
  • In SAP, there are 21 lists, out of which first list is called basic list with list number 0 and remaining lists are called as secondary lists with list numbers 1,2,3,4...to...20.
  • The Syatem Variable SY-LSIND will give the list index no.
Example: Display material basic details in first screen(basic list), when ever user clicks on any material number it displays materials plant details in second screen.
Interactive Reports Events

At Line-Selection

This event will trigger when ever user double click on any list line.
Syntax: AT LINE-SELECTION . "Triggers line selection 

At User Command

This event will trigger when ever user clicks on any custom buttons of GUI.
Syntax: AT USER-COMMAND . "Triggers user command 

At PF Status

This event will trigger when ever user clicks on any function buttons.
Syntax: AT PF <function key> . "Triggers user command 

Top Of Page During line selection

This is used to print heading for secondary lists in interactive reports .
Syntax: TOP-OF-PAGE DURING LINE-SELECTION . "Prints secondary list header 
Techniques used in interactive reporting

Hide area

It is a key word which is used to store the data into a temporary memory call as HIDE area.
Functionality of HIDE is
  • When ever the user uses the HIDE statement, the data will be stored in HIDE area along with line numbers.
  • When ever user double clicks on any list line the system takes the line number and checks the HIDE area for the corresponding data in that particular line, then the data will be return to the HIDE variables.
Syntax: HIDE <WA>. "store total work area in hide area
         OR
        HIDE <WA-FIELD>. "store work area field in hide area
GET CURSOR
This key word is used to read the field name and field value where the mouse cursor is placed or double click action is raised. It dosen`t use hide area.
Syntax : GET CURSOR FIELD <V_FIELDNAME>,
                    FIELDVALUE <V_FIELDVALUE>.

Friday, 20 June 2014

Formatting output in write statement of SAP ABAP

Formatting output in write statement of SAP ABAP

You can position the output of a WRITE statement on the screen by making a format specification before the field name as follows:

Syntax:

WRITE AT [/][][()] ,
Where

• ‘the slash’/‘ denotes a new line,
• is a number or variable denoting the position on the screen,
• is a number or variable long denoting the output length.

For variables you need to mention the AT, for direct values it is notnecessary.

DATA: LEN TYPE I VALUE 10,
POS TYPE I VALUE 11,
TEXT (10) VALUE ‘1234567890’
WRITE AT POS (LEN) TEXT.

This produces the following output on the screen;
The text – 1234567890 – appears in the text.

If the output length is too short, fewer characters are displayed. Numeric fields are truncated on the left and prefixed with an asterisk (*). All other fields are truncated on the right, but no indication is given that the field is shorter.

DATA: NUMBER TYPE I VALUE 1234567890,
TEXT (10) VALUE ‘abcdefghij’.

WRITE: (5) NUMBER, /(5) TEXT.

This produces the following output:
7890
abcde

In the default setting, you cannot create empty lines with the WRITE statement.
WRITE: ‘One’,
/‘ ’,
/ ‘Two’

The output looks as follows:
One
Two

The system suppresses lines that contain nothing but empty spaces.

You can use various formatting options with the WRITE statement.

SAP ABAP - Data Types & Data Objects.

SAP ABAP - Data Types & Data Objects.

• Data objects are units created during runtime.
• Data object cannot exist without data type.
• Occupies memory space.

Kinds of Data Objects

1. INTERNAL DATA OBJECTS

• Literal

A literal has a fixed value.
Ex WRITE: “WORK HARD”

• Variables

DATA statement is used to create variables
Ex DATA: NUM TYPE I
NUM is a variable declared by DATA statement. Any variable, which you use in program, need to be declared before you use it and can be done by DATA statement.

Here variable is declared by referring to existing data type.

Variable can also be declared by referring existing data object.
Ex. We have already declared NUM by DATA statement.
DATA: PRICE LIKE NUM.
Here variable is declared by using LIKE parameter, which tells system that price has all the attributes of data object NUM i.e., PRICE is also of type I.

The main difference between TYPE and LIKE parameter when defining or declaring the object is that TYPE is used to refer existing DATA TYPE (elementary or structured or user defined) while LIKE is used to declare data objects with reference to existing DATA OBJECTS.

• Constant

Constant is a data object, which contains fixed value through out the program. Constant can be declared in program by using CONSTANTstatement.

Ex. CONSTANT: INT TYPE I VALUE 15.

In program value of INT cannot be changed. If you give a statement like INT = 20.
In this case system will give error.

2. EXTERNAL DATA OBJECTS

Are defined in tables i.e., in ABAP/4 dictionary. You can access this data from table.

TABLES: SFLIGHT
DATA: SEATS LIKE SFLIGHT-SEATSMAX.

3. SYSTEM-DEFINED DATA OBJECTS

SPACE & SYSTEM VARIABLES like sy-uname, sy-datum, & sy-repid.

4. SPECIAL DATA OBJECTS

PARAMETERS: are variable, which can accept value from user.

SELECTIONS CRITERIA: are special internal tables to accept value range from user.


Need for Data types:

Consider the following example.

DATA: fname(20),
mname(20),
lname(20),
add1(20),
add2(20),
add3(20).

If you have DATA statement like above, and if you need to change the length of all the fields say from 20 to 25, then you need to change all the fields i.e., going through each and every statement.

But consider the following case where TYPES has been used.

TYPES:str(20)
DATA:fname type str,
Mname type str,
Lname type str,
Add1 type str,
Add2 type str,
Add3 type str.

In this case if you need to change the length of all fields from 20 to 25. Then just change the length of STR and change will be reflected for all the fields.

If you define all the types in TYPE-POOL i.e., global definition of all the types, you can use these types anywhere and in any program.

Thursday, 19 June 2014

about subroutines

SUBROUTINES

In order to modularize the program Subroutines are used. Generally Subroutines are called by using PERFORM keyword and defined within FORM and ENDFORM block. There are three ways of passing the data from the calling part to the called part -1. pass by value  2. pass by reference  3 . pass by value and return .
**********Subroutine - pass by value method-> using - using value( ) **********

TYPES : BEGIN OF LINE,
               NAME(10),
              ADD(10),
             END OF LINE.

DATA : PER1 TYPE LINE.
PER1-NAME = 'AAAA'.
PER1-ADD = 'BBBB'.

PERFORM DISPLAY USING PER1. " calling the subroutine - Display

WRITE :/ PER1-NAME, PER1-ADD.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_PER1  text
*----------------------------------------------------------------------*
FORM DISPLAY  USING VALUE(P_PER1) TYPE LINE.
  WRITE :/ P_PER1-NAME, P_PER1-ADD.
       P_PER1-NAME = 'CCCC'.
       P_PER1-ADD = 'DDDD'.
  WRITE :/ PER1-NAME, PER1-ADD.
ENDFORM.                    " DISPLAY

****************OUTPUT*****************************

AAAA       BBBB
AAAA       BBBB
AAAA       BBBB
**********Subroutine - pass by reference method-> using - using **********

TYPES : BEGIN OF LINE,
               NAME(10),
              ADD(10),
            END OF LINE.

DATA : PER1 TYPE LINE.
PER1-NAME = 'AAAA'.
PER1-ADD = 'BBBB'.

PERFORM DISPLAY USING PER1.
WRITE :/ PER1-NAME, PER1-ADD.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_PER1  text
*----------------------------------------------------------------------*
FORM DISPLAY  USING P_PER1 TYPE LINE.
  WRITE :/ P_PER1-NAME, P_PER1-ADD.
         P_PER1-NAME = 'CCCC'.
        P_PER1-ADD = 'DDDD'.
  WRITE :/ PER1-NAME, PER1-ADD.
ENDFORM.                    " DISPLAY

****************OUTPUT******************************
AAAA       BBBB
CCCC       DDDD
CCCC       DDDD
**********Subroutine - pass by reference method-> using - changing  **********

TYPES : BEGIN OF LINE,
              NAME(10),
              ADD(10),
             END OF LINE.

DATA : PER1 TYPE LINE.
PER1-NAME = 'AAAA'.
PER1-ADD = 'BBBB'.
PERFORM DISPLAY USING PER1.
WRITE :/ PER1-NAME, PER1-ADD.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_PER1  text
*----------------------------------------------------------------------*
FORM DISPLAY  CHANGING P_PER1 TYPE LINE.
  WRITE :/ P_PER1-NAME, P_PER1-ADD.
P_PER1-NAME = 'CCCC'.
P_PER1-ADD = 'DDDD'.
  WRITE :/ PER1-NAME, PER1-ADD.
ENDFORM.                    " DISPLAY

****************OUTPUT********************************
AAAA       BBBB
CCCC       DDDD
CCCC       DDDD

**********Subroutine - pass by value and return  method-> using - changing  value( )**********

TYPES : BEGIN OF LINE,
              NAME(10),
             ADD(10),
             END OF LINE.

DATA : PER1 TYPE LINE.
PER1-NAME = 'AAAA'.
PER1-ADD = 'BBBB'.
PERFORM DISPLAY USING PER1.
WRITE :/ PER1-NAME, PER1-ADD.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_PER1  text
*----------------------------------------------------------------------*
FORM DISPLAY  CHANGING VALUE(P_PER1) TYPE LINE.
  WRITE :/ P_PER1-NAME, P_PER1-ADD.
P_PER1-NAME = 'CCCC'.
P_PER1-ADD = 'DDDD'.
  WRITE :/ PER1-NAME, PER1-ADD.
ENDFORM.                    " DISPLAY

****************OUTPUT********************************
AAAA       BBBB
AAAA       BBBB
CCCC       DDDD

**********Subroutine - pass by reference method-> changing - using  **********

TYPES : BEGIN OF LINE,
               NAME(10),
              ADD(10),
              END OF LINE.

DATA : PER1 TYPE LINE.
PER1-NAME = 'AAAA'.
PER1-ADD = 'BBBB'.
PERFORM DISPLAY CHANGING PER1.
WRITE :/ PER1-NAME, PER1-ADD.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_PER1  text
*----------------------------------------------------------------------*
FORM DISPLAY  USING P_PER1 TYPE LINE.
  WRITE :/ P_PER1-NAME, P_PER1-ADD.
P_PER1-NAME = 'CCCC'.
P_PER1-ADD = 'DDDD'.
  WRITE :/ PER1-NAME, PER1-ADD.
ENDFORM.                    " DISPLAY

****************OUTPUT*******************************
AAAA       BBBB
CCCC       DDDD
CCCC       DDDD

**********Subroutine - pass by value method-> changing - using  value( ) **********

TYPES : BEGIN OF LINE,
              NAME(10),
             ADD(10),
            END OF LINE.

DATA : PER1 TYPE LINE.
PER1-NAME = 'AAAA'.
PER1-ADD = 'BBBB'.
PERFORM DISPLAY CHANGING PER1.
WRITE :/ PER1-NAME, PER1-ADD.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_PER1  text
*----------------------------------------------------------------------*
FORM DISPLAY  USING VALUE(P_PER1) TYPE LINE.
  WRITE :/ P_PER1-NAME, P_PER1-ADD.
P_PER1-NAME = 'CCCC'.
P_PER1-ADD = 'DDDD'.
  WRITE :/ PER1-NAME, PER1-ADD.
ENDFORM.                    " DISPLAY

****************OUTPUT********************************
AAAA       BBBB
AAAA       BBBB
AAAA       BBBB

**********Subroutine - pass by reference method-> changing - changing **********

TYPES : BEGIN OF LINE,
              NAME(10),
             ADD(10),
             END OF LINE.

DATA : PER1 TYPE LINE.
PER1-NAME = 'AAAA'.
PER1-ADD = 'BBBB'.
PERFORM DISPLAY CHANGING PER1.
WRITE :/ PER1-NAME, PER1-ADD.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_PER1  text
*----------------------------------------------------------------------*
FORM DISPLAY  CHANGING P_PER1 TYPE LINE.
  WRITE :/ P_PER1-NAME, P_PER1-ADD.
P_PER1-NAME = 'CCCC'.
P_PER1-ADD = 'DDDD'.
  WRITE :/ PER1-NAME, PER1-ADD.
ENDFORM.                    " DISPLAY

****************OUTPUT*********************************
AAAA       BBBB
CCCC       DDDD
CCCC       DDDD

**********Subroutine - pass by value and return  method-> changing - changing value( ) **********

TYPES : BEGIN OF LINE,
              NAME(10),
             ADD(10),
            END OF LINE.

DATA : PER1 TYPE LINE.
PER1-NAME = 'AAAA'.
PER1-ADD = 'BBBB'.
PERFORM DISPLAY CHANGING PER1.
WRITE :/ PER1-NAME, PER1-ADD.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_PER1  text
*----------------------------------------------------------------------*
FORM DISPLAY  CHANGING VALUE(P_PER1) TYPE LINE.
  WRITE :/ P_PER1-NAME, P_PER1-ADD.
P_PER1-NAME = 'CCCC'.
P_PER1-ADD = 'DDDD'.
  WRITE :/ PER1-NAME, PER1-ADD.
ENDFORM.                    " DISPLAY

****************OUTPUT********************************
AAAA       BBBB
AAAA       BBBB
CCCC       DDDD

**********Subroutine - both type of parameters in subroutine **********
data : num1 type I,
         NUM2 TYPE I,
         RES TYPE I.
NUM1 = 5.
NUM2 = 8.

PERFORM MUL_DSIP USING NUM1 NUM2 CHANGING RES.
WRITE :/ 'VALUE OF RES = ' , RES.
*&---------------------------------------------------------------------*
*&      Form  MUL_DSIP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_NUM1  text
*      -->P_NUM2  text
*      <--P_RES  text
*----------------------------------------------------------------------*
FORM MUL_DSIP  USING    VALUE(P_NUM1)
                                                 VALUE(P_NUM2)
                                                  CHANGING VALUE(P_RES).

  P_RES = P_NUM1 * P_NUM2.

  WRITE :/ 'VALUE OF P_RES = ', P_RES.
  WRITE :/ 'VALUE OF RES = ', RES.

ENDFORM.                    " MUL_DSIP

***********************OUTPUT***********************
VALUE OF P_RES =          40
VALUE OF RES =           0
VALUE OF RES =          40

**********Subroutine -factorial of a number  **********

PARAMETERS NUM TYPE I.
DATA FACT TYPE I VALUE 0.
PERFORM FACTORIAL USING NUM
                                         CHANGING FACT.
WRITE :/ 'FACTORIAL OF ', NUM,'=', FACT.
*&---------------------------------------------------------------------*
*&      Form  FACTORIAL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_NUM  text
*      <--P_FACT  text
*----------------------------------------------------------------------*
FORM FACTORIAL  USING   VALUE(P_NUM)
                                                  CHANGING P_FACT.
P_FACT = 1.
WHILE P_NUM > 1.
  P_FACT = P_FACT * P_NUM.
  P_NUM = P_NUM - 1.
  ENDWHILE.
ENDFORM.                    " FACTORIAL

******************OUTPUT******************************
FACTORIAL OF           5  =        120

**********Subroutine -local and global data  **********

DATA TEXT(5) TYPE C VALUE 'ABCDE'.
WRITE :/ TEXT.
PERFORM DISPLAY.
WRITE :/ TEXT.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY .
  DATA TEXT TYPE CHAR5 VALUE 'EDCBA'.
  WRITE :/ TEXT.
ENDFORM.                    " DISPLAY

******************OUTPUT*****************************
ABCDE
EDCBA
ABCDE

**********Subroutine - with exit statement **********

perform exit_unconditionally.
write :/ 'Get back control again after uncoditionally stop nby exit'.

*&---------------------------------------------------------------------*
*&      Form  EXIT_UNCONDITIONALLY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM EXIT_UNCONDITIONALLY .
write :/ 'one'.
write :/ 'two'.
write :/ 'three'.
write :/ 'four'.
exit.
write :/ 'five'.

ENDFORM.                    " EXIT_UNCONDITIONALLY

****************** OUTPUT *****************************
one
two
three
four
Get back control again after uncoditionally stop nby exit

**********Subroutine - with check statement **********
DATA : NUM1 TYPE I,
            NUM2 TYPE I,
            RES TYPE P DECIMALS 2.

NUM1 = 10. NUM2 = 3.
perform CHECK_DISPALY USING NUM1 NUM2 CHANGING RES.

NUM1 = 10. NUM2 = 0.
perform CHECK_DISPALY USING NUM1 NUM2 CHANGING RES.


NUM1 = 20. NUM2 = 8.
perform CHECK_DISPALY USING NUM1 NUM2 CHANGING RES.
*&---------------------------------------------------------------------*
*&      Form  CHECK_DISPALY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_NUM1  text
*      -->P_NUM2  text
*      <--P_RES  text
*----------------------------------------------------------------------*
FORM CHECK_DISPALY  USING    P_NUM1
                                                             P_NUM2
                                            CHANGING P_RES.
CHECK P_NUM2 NE 0.

P_RES = P_NUM1 / P_NUM2.
WRITE :/ 'DIVISION = ', P_RES.
ENDFORM.                    " CHECK_DISPALY

*********************OUTPUT**************************
DIVISION =              3,33
DIVISION =              2,50

**********Subroutine - multiple call of subroutine in a single line **********
DO 2 TIMES.
PERFORM SY-INDEX OF SUBROUT1 SUBROUT2.
ENDDO.

*&---------------------------------------------------------------------*
*&      Form  SUBROUT1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUBROUT1 .
WRITE :/ 'SUBROUTINE 1 OF PROGRAM ZPGM'.
ENDFORM.                    " SUBROUT1
*&---------------------------------------------------------------------*
*&      Form  SUBROUT2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUBROUT2 .
WRITE :/ 'SUBROUTINE 2 OF PROGRAM ZPGM'.
ENDFORM.                    " SUBROUT2

*******************OUTOUT****************************
SUBROUTINE 1 OF PROGRAM ZPGM
SUBROUTINE 2 OF PROGRAM ZPGM

**********Subroutine - nested  subroutine  **********
DATA : NUM1 TYPE I,
             NUM2 TYPE I,
             RES TYPE I.

 NUM1 = 10.
 NUM2 = 3.
perform ADDITION.
*&---------------------------------------------------------------------*
*&      Form  ADDITION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM ADDITION .
RES = NUM1 + NUM2.
PERFORM DISPLAY.
ENDFORM.                    " ADDITION
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY .
WRITE :/ NUM1 , '+', NUM2 , '=', RES.
ENDFORM.                    " DISPLAY

*********************OUTPUT***************************
        10  +          3  =         13

**********Subroutine - uses of data and static data in subroutine  **********

PERFORM FUNCTION1.
PERFORM FUNCTION1.
SKIP 2.
ULINE.
PERFORM FUNCTION2.
PERFORM FUNCTION2.
*&---------------------------------------------------------------------*
*&      Form  FUNCTION1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FUNCTION1 .
DATA : TEXT1 TYPE C LENGTH 5 VALUE 'ABCDE'.
WRITE :/ TEXT1.
TEXT1 = '12345'.
WRITE :/ TEXT1.
ENDFORM.                    " FUNCTION1
*&---------------------------------------------------------------------*
*&      Form  FUNCTION2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FUNCTION2 .
STATICS TEXT2 TYPE C LENGTH 5 VALUE 'PQRST'.
WRITE :/ TEXT2.
TEXT2 = '54321'.
WRITE :/ TEXT2.
ENDFORM.                    " FUNCTION2

******************OUTPUT**********************************

ABCDE
12345
ABCDE
12345

PQRST
54321
54321
54321
**********Subroutine - uses of  global and local work area in subroutine  **********
TABLES : SFLIGHT.

PERFORM ASSIGN1.
WRITE :/ SFLIGHT-CARRID, SFLIGHT-CONNID.
PERFORM ASSIGN2.
WRITE :/ SFLIGHT-CARRID, SFLIGHT-CONNID.
*&---------------------------------------------------------------------*
*&      Form  ASSIGN1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM ASSIGN1 .
*TABLES : SFLIGHT. " DECLARATION NOT POSSIBLE ALREDAY EXISTS
  SFLIGHT-CARRID = 'SSS'.
  SFLIGHT-CONNID = '1234'.
  WRITE :/ SFLIGHT-CARRID , SFLIGHT-CONNID.
ENDFORM.                    " ASSIGN1
*&---------------------------------------------------------------------*
*&      Form  ASSIGN2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM ASSIGN2 .
  LOCAL SFLIGHT.
SFLIGHT-CARRID = 'PPP'.
  SFLIGHT-CONNID = '4321'.
  WRITE :/ SFLIGHT-CARRID , SFLIGHT-CONNID.
ENDFORM.                    " ASSIGN2

******************OUTPUT*****************************
SSS 1234
SSS 1234
PPP 4321
SSS 1234

**********Subroutine - calling a subroutine of other program  **********
REPORT ZPGM.

PERFORM DISPLAY.
*&---------------------------------------------------------------------*
*&      Form  DISPALY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY .
WRITE :/ 'SUBROUTINE OF THE PROGRAM = ', SY-CPROG.
ENDFORM.                    " DISPALY


********CALLING THIS SUBROUTINE FROM ZPGM1 **********

REPORT ZPGM1.
PERFORM DISPLAY(ZPGM) IF FOUND.
*********************OUTPUT OF ZPGM1******************

SUBROUTINE OF THE PROGRAM =  ZPGM1

**********Subroutine - dynamic calling a subroutine from  other program  **********
REPORT ZPGM.
PERFORM SUBROUT1.
PERFORM SUBROUT2.

*&---------------------------------------------------------------------*
*&      Form  SUBROUT1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUBROUT1 .
WRITE :/ 'SUBROUTINE 1 OF PROGRAM ZPGM'.
ENDFORM.                    " SUBROUT1
*&---------------------------------------------------------------------*
*&      Form  SUBROUT2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUBROUT2 .
WRITE :/ 'SUBROUTINE 2 OF PROGRAM ZPGM'.
ENDFORM.                    " SUBROUT2

*******************************************************
REPORT ZPGM1.
DATA : PROGRAM_NAME TYPE C LENGTH 5 VALUE 'ZPGM'.
DATA : SUB_NAME TYPE C LENGTH 8 VALUE 'SUBROUT1'.

PERFORM (SUB_NAME) IN PROGRAM (PROGRAM_NAME) IF FOUND.
  SUB_NAME = 'SUBROUT2'.
PERFORM (SUB_NAME) IN PROGRAM (PROGRAM_NAME) IF FOUND.

********************OUTPUT *****************************
SUBROUTINE 1 OF PROGRAM ZPGM
SUBROUTINE 2 OF PROGRAM ZPGM
**********Subroutine - passing work area to a subroutine and handled by field symbol  **********
DATA : BEGIN OF LINE,
           COL1 TYPE C VALUE 'A',
           COL2 TYPE C VALUE 'B',
           END OF LINE.

DATA : COL(4) TYPE C VALUE 'COL1'.

PERFORM DISPLAY USING LINE.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LINE  text
*----------------------------------------------------------------------*
FORM DISPLAY  USING    P_LINE . " P_line type any
FIELD-SYMBOLS <FS>.
assign component col of structure p_line to <FS>.
write :/ <FS>.
assign component 2 of structure p_line to <FS>.
write :/ <FS>.
ENDFORM.                    " DISPLAY

******************OUTPUT**********************************
A
B
**********Subroutine - passing work area to a subroutine and handled by field symbol  **********
data : begin of line,
          col1 value 'x',
          col2 value 'y',
         end of line.
data : comp(4) type c value 'COL2'.
perform display using line.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LINE  text
*----------------------------------------------------------------------*
FORM DISPLAY  USING    P_LINE type any.
field-symbols : <fs>.
assign component 1 of structure p_line to <fs>.
write :/ <fs>.
ASSIGN COMPONENT COMP OF STRUCTURE P_LINE TO <FS>.
WRITE /  <FS>.
ENDFORM.                    " DISPLAY

****************** OUTPUT *****************************
x
y