Tuesday, 24 June 2014

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