You are on page 1of 15

*&---------------------------------------------------------------------*

*& Report ZVR_SUBROUTINES_MT_DEC


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zvr_subroutines_mt_dec NO STANDARD PAGE HEADING


LINE-SIZE 300.

************************************************************************
***SAMPLE APPLICATION USING SUBROUTINE WITH parameters
*declaration of types structure
TYPES: BEGIN OF ty_kna1,
kunnr TYPE kna1-kunnr,
name1 TYPE kna1-name1,
ort01 TYPE kna1-ort01,
regio TYPE kna1-regio,
stras TYPE kna1-stras,
pstlz TYPE kna1-pstlz,
telf1 TYPE kna1-telf1,
adrnr TYPE kna1-adrnr,
land1 TYPE kna1-land1,
ktokd TYPE kna1-ktokd,
END OF ty_kna1.

***declaration of work area & internal table


DATA : wa_kna1 TYPE ty_kna1,
it_kna1 TYPE TABLE OF ty_kna1,
lv_rec TYPE i,
r_kunnr TYPE RANGE OF kna1-kunnr.

***selection screen design


SELECT-OPTIONS s_kunnr FOR wa_kna1-kunnr.

***fetch data based on select option values


r_kunnr[] = s_kunnr[].

PERFORM fetch_kna1_data TABLES it_kna1


r_kunnr.

***check records in an internal table


DESCRIBE TABLE it_kna1 LINES lv_rec.

***display customer info


LOOP AT it_kna1 INTO wa_kna1.
WRITE :/ wa_kna1-kunnr,
wa_kna1-kunnr,
wa_kna1-name1,
wa_kna1-ort01,
wa_kna1-regio,
wa_kna1-stras,
wa_kna1-pstlz,
wa_kna1-telf1,
wa_kna1-adrnr,
wa_kna1-land1,
wa_kna1-ktokd.
CLEAR wa_kna1.
ENDLOOP.
SKIP 2.
ULINE.
WRITE :/ 'No. of records are:'COLOR 5, lv_rec COLOR 5.
*&---------------------------------------------------------------------*
*& Form FETCH_KNA1_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_S_KUNNR text
* -->P_IT_KNA1 text
*----------------------------------------------------------------------*
FORM fetch_kna1_data TABLES p_it_kna1 TYPE STANDARD TABLE
r_kunnr TYPE STANDARD TABLE.
"Insert correct name for <...>.
SELECT kunnr
name1
ort01
regio
stras
pstlz
telf1
adrnr
land1
ktokd FROM kna1
INTO TABLE it_kna1
WHERE kunnr IN r_kunnr.

ENDFORM. " FETCH_KNA1_DATA

*************************************************************************
****SAMPLE APPLICATION USING SUBROUTINE WITH parameters
**declaration of types structure
*TYPES: BEGIN OF ty_kna1,
* kunnr TYPE kna1-kunnr,
* name1 TYPE kna1-name1,
* ort01 TYPE kna1-ort01,
* regio TYPE kna1-regio,
* stras TYPE kna1-stras,
* pstlz TYPE kna1-pstlz,
* telf1 TYPE kna1-telf1,
* adrnr TYPE kna1-adrnr,
* land1 TYPE kna1-land1,
* ktokd TYPE kna1-ktokd,
* END OF ty_kna1.
*
****declaration of work area & internal table
*DATA : wa_kna1 TYPE ty_kna1,
* it_kna1 TYPE TABLE OF ty_kna1,
* lv_rec TYPE i.
*
****selection screen design
*SELECT-OPTIONS s_kunnr FOR wa_kna1-kunnr.
*
****fetch data based on select option values
*PERFORM fetch_kna1_data.
*
****check records in an internal table
*DESCRIBE TABLE it_kna1 LINES lv_rec.
*
****display customer info
*LOOP AT it_kna1 INTO wa_kna1.
* WRITE :/ wa_kna1-kunnr,
* wa_kna1-kunnr,
* wa_kna1-name1,
* wa_kna1-ort01,
* wa_kna1-regio,
* wa_kna1-stras,
* wa_kna1-pstlz,
* wa_kna1-telf1,
* wa_kna1-adrnr,
* wa_kna1-land1,
* wa_kna1-ktokd.
* CLEAR wa_kna1.
*ENDLOOP.
*SKIP 2.
*ULINE.
*WRITE :/ 'No. of records are:'COLOR 5, lv_rec COLOR 5.
*
**&---------------------------------------------------------------------*
**& Form FETCH_KNA1_DATA
**&---------------------------------------------------------------------*
** text
**----------------------------------------------------------------------*
** --> p1 text
** <-- p2 text
**----------------------------------------------------------------------*
*FORM fetch_kna1_data .
*
* SELECT kunnr
* name1
* ort01
* regio
* stras
* pstlz
* telf1
* adrnr
* land1
* ktokd FROM kna1
* INTO TABLE it_kna1
* WHERE kunnr IN s_kunnr.
*
*ENDFORM. " FETCH_KNA1_DATA

**************************************************************************
*****SAMPLE APPLICATION USING SUBROUTINE WITH parameters
***declaration of types structure
**TYPES: BEGIN OF ty_kna1,
** kunnr TYPE kna1-kunnr,
** name1 TYPE kna1-name1,
** ort01 TYPE kna1-ort01,
** regio TYPE kna1-regio,
** stras TYPE kna1-stras,
** pstlz TYPE kna1-pstlz,
** telf1 TYPE kna1-telf1,
** adrnr TYPE kna1-adrnr,
** land1 TYPE kna1-land1,
** ktokd TYPE kna1-ktokd,
** END OF ty_kna1.
**
*****declaration of work area & internal table
**DATA : wa_kna1 TYPE ty_kna1,
** it_kna1 TYPE TABLE OF ty_kna1.
**
*****fill data manually to internal table
**PERFORM fill_cust_data USING : '1000' 'JAHANGIR' 'HYD' 'TS' 'SR NAGAR' '500008'
'9876543210' '1111' 'IN' '0001',
** '2000' 'SHABBIR' 'MUM' 'MH' 'ANDHERI' '200008'
'888888888' '2222' 'IN' '0001',
** '3000' 'GANESH' 'CHE' 'TN' 'SHIVAJI' '400008'
'77777777' '3333' 'IN' '0001',
** '4000' 'BARKAT' 'DEL' 'UP' 'OKHLA' '100008'
'66666666' '4444' 'IN' '0001',
** '5000' 'SALMA' 'BAN' 'KA' 'MAJESTIC' '800008'
'555555' '5555' 'IN' '0001'.
**
*****display customer info
**LOOP AT it_kna1 INTO wa_kna1.
** WRITE :/ wa_kna1-kunnr,
** wa_kna1-kunnr,
** wa_kna1-name1,
** wa_kna1-ort01,
** wa_kna1-regio,
** wa_kna1-stras,
** wa_kna1-pstlz,
** wa_kna1-telf1,
** wa_kna1-adrnr,
** wa_kna1-land1,
** wa_kna1-ktokd.
** CLEAR wa_kna1.
**ENDLOOP.
***&---------------------------------------------------------------------*
***& Form FILL_CUST_DATA
***&---------------------------------------------------------------------*
*** text
***----------------------------------------------------------------------*
*** -->P_0064 text
*** -->P_0065 text
*** -->P_0066 text
*** -->P_0067 text
*** -->P_0068 text
*** -->P_0069 text
*** -->P_0070 text
*** -->P_0071 text
*** -->P_0072 text
*** -->P_0073 text
***----------------------------------------------------------------------*
**FORM fill_cust_data USING cust
** name
** city
** state
** sthno
** pstcd
** tele
** addr
** cntry
** acgrp.
**
** wa_kna1-kunnr = cust.
** wa_kna1-name1 = name.
** wa_kna1-ort01 = city.
** wa_kna1-regio = state.
** wa_kna1-stras = sthno.
** wa_kna1-pstlz = pstcd.
** wa_kna1-telf1 = tele.
** wa_kna1-adrnr = addr.
** wa_kna1-land1 = cntry.
** wa_kna1-ktokd = acgrp.
** APPEND wa_kna1 TO it_kna1.
** CLEAR wa_kna1.
**
**ENDFORM. " FILL_CUST_DATA
**********************************************************************
****sample application to perform addition using SUBROUTINE
*DATA : lv_var1 TYPE i VALUE '10',
* lv_var2 TYPE i VALUE '20',
* lv_res TYPE i.
*
****calculate result
*lv_res = lv_var1 + lv_var2.
*WRITE :/ lv_res.
****calling of subrotines
*PERFORM sub_add USING lv_var1
* lv_var2
* CHANGING lv_res.
****calculate result
*lv_res = lv_var1 + lv_var2.
*WRITE :/ lv_res.
**&---------------------------------------------------------------------*
**& Form SUB_ADD
**&---------------------------------------------------------------------*
** text
**----------------------------------------------------------------------*
** -->P_LV_VAR1 text
** -->P_LV_VAR2 text
** <--P_LV_RES text
**----------------------------------------------------------------------*
*FORM sub_add USING value(p_lv_var1) TYPE i
* value(p_lv_var2) TYPE i
* CHANGING value(p_lv_res) TYPE i.
*
* p_lv_var1 = 25.
* p_lv_var2 = 25.
* p_lv_res = p_lv_var1 + p_lv_var2.
* WRITE :/ p_lv_res.
*ENDFORM. " SUB_ADD
***********************************************************************
*****sample application to perform addition using SUBROUTINE
**DATA : lv_var1 TYPE i VALUE '10',
** lv_var2 TYPE i VALUE '20',
** lv_res TYPE i.
**
*****calculate result
**lv_res = lv_var1 + lv_var2.
**WRITE :/ lv_res.
*****calling of subrotines
**PERFORM sub_add USING lv_var1 lv_var2
** CHANGING lv_res.
*****calculate result
**lv_res = lv_var1 + lv_var2.
**WRITE :/ lv_res.
***&---------------------------------------------------------------------*
***& Form SUB_ADD
***&---------------------------------------------------------------------*
*** text
***----------------------------------------------------------------------*
*** -->P_LV_VAR1 text
*** -->P_LV_VAR2 text
*** <--P_LV_RES text
***----------------------------------------------------------------------*
**FORM sub_add USING value(p_lv_var1)
** value(p_lv_var2)
** CHANGING value(p_lv_res).
** p_lv_var1 = 25.
** p_lv_var2 = 25.
** p_lv_res = p_lv_var1 + p_lv_var2.
** WRITE :/ p_lv_res.
**ENDFORM. " SUB_ADD

**********************************************************************
****sample application to perform addition using SUBROUTINE
*DATA : lv_var1 TYPE i VALUE '10',
* lv_var2 TYPE i VALUE '20',
* lv_res TYPE i.
*
****calculate result
*lv_res = lv_var1 + lv_var2.
*WRITE :/ lv_res.
****calling of subrotines
*PERFORM sub_add USING lv_var1 lv_var2
* CHANGING lv_res.
****calculate result
*lv_res = lv_var1 + lv_var2.
*WRITE :/ lv_res.
**&---------------------------------------------------------------------*
**& Form SUB_ADD
**&---------------------------------------------------------------------*
** text
**----------------------------------------------------------------------*
** -->P_LV_VAR1 text
** -->P_LV_VAR2 text
** <--P_LV_RES text
**----------------------------------------------------------------------*
*FORM sub_add USING p_lv_var1
* p_lv_var2
* CHANGING p_lv_res.
* LOCAL : p_lv_var1, p_lv_var2, p_lv_res.
* p_lv_var1 = 25.
* p_lv_var2 = 25.
* p_lv_res = p_lv_var1 + p_lv_var2.
* WRITE :/ p_lv_res.
*ENDFORM. " SUB_ADD

***********************************************************************
*****sample application to perform addition using SUBROUTINE
**DATA : lv_var1 TYPE i VALUE '10',
** lv_var2 TYPE i VALUE '20',
** lv_res TYPE i.
**
*****calculate result
**lv_res = lv_var1 + lv_var2.
**WRITE :/ lv_res.
*****calling of subrotines
**PERFORM sub_add USING lv_var1 lv_var2
** CHANGING lv_res.
*****calculate result
**lv_res = lv_var1 + lv_var2.
**WRITE :/ lv_res.
**
***&---------------------------------------------------------------------*
***& Form SUB_ADD
***&---------------------------------------------------------------------*
*** text
***----------------------------------------------------------------------*
*** -->LV_VAR1 text
*** -->LV_VAR2 text
*** -->LV_RES text
***----------------------------------------------------------------------*
**FORM sub_add USING value(lv_var1)
** value(lv_var2)
** CHANGING value(lv_res).
** lv_var1 = 50.
** lv_var2 = 25.
** lv_res = lv_var1 + lv_var2.
** WRITE :/ lv_res.
**ENDFORM. "SUB_ADD

**********************************************************************
****sample application to perform addition using SUBROUTINE
*DATA : lv_var1 TYPE i VALUE '10',
* lv_var2 TYPE i VALUE '20',
* lv_res TYPE i.
*
****calculate result
*lv_res = lv_var1 + lv_var2.
*WRITE :/ lv_res.
****calling of subrotines
*PERFORM sub_add USING lv_var1 lv_var2
* CHANGING lv_res.
****calculate result
*lv_res = lv_var1 + lv_var2.
*WRITE :/ lv_res.
*
**&---------------------------------------------------------------------*
**& Form SUB_ADD
**&---------------------------------------------------------------------*
** text
**----------------------------------------------------------------------*
** -->LV_VAR1 text
** -->LV_VAR2 text
** -->LV_RES text
**----------------------------------------------------------------------*
*FORM sub_add USING lv_var1
* lv_var2
* CHANGING lv_res.
* LOCAL : lv_var1, lv_var2, lv_res.
* lv_var1 = 50.
* lv_var2 = 25.
* lv_res = lv_var1 + lv_var2.
* WRITE :/ lv_res.
*ENDFORM. "SUB_ADD

***********************************************************************
*****sample application to perform addition using SUBROUTINE
**DATA : lv_var1 TYPE i VALUE '10',
** lv_var2 TYPE i VALUE '20',
** lv_res TYPE i.
**
*****calculate result
**lv_res = lv_var1 + lv_var2.
**WRITE :/ lv_res.
*****calling of subrotines
**PERFORM sub_add USING lv_var1 lv_var2
** CHANGING lv_res.
*****calculate result
**lv_res = lv_var1 + lv_var2.
**WRITE :/ lv_res.
**
***&---------------------------------------------------------------------*
***& Form SUB_ADD
***&---------------------------------------------------------------------*
*** text
***----------------------------------------------------------------------*
*** -->LV_VAR1 text
*** -->LV_VAR2 text
*** -->LV_RES text
***----------------------------------------------------------------------*
**FORM sub_add USING lv_var1
** lv_var2
** CHANGING lv_res.
**
** lv_res = lv_var1 + lv_var2.
** WRITE :/ lv_res.
**ENDFORM. "SUB_ADD
**********************************************************************
****sample application to perform addition using SUBROUTINE
*DATA : lv_var1 TYPE i VALUE '10',
* lv_var2 TYPE i VALUE '20',
* lv_res TYPE i.
*
****calculate result
*lv_res = lv_var1 + lv_var2.
*WRITE :/ lv_res.
****calling of subrotines
*PERFORM sub_add.
****calculate result
*lv_res = lv_var1 + lv_var2.
*WRITE :/ lv_res.
**&---------------------------------------------------------------------*
**& Form SUB_ADD
**&---------------------------------------------------------------------*
** text
**----------------------------------------------------------------------*
** --> p1 text
** <-- p2 text
**----------------------------------------------------------------------*
*FORM sub_add .
* LOCAL : lv_var1, lv_var2.
* lv_var1 = 100.
* lv_var2 = 200.
* lv_res = lv_var1 + lv_var2.
* WRITE :/ lv_res.
*ENDFORM. " SUB_ADD
***********************************************************************
*****sample application to perform addition using SUBROUTINE
**DATA : lv_var1 TYPE i VALUE '10',
** lv_var2 TYPE i VALUE '20',
** lv_res TYPE i.
**
*****calculate result
**lv_res = lv_var1 + lv_var2.
**WRITE :/ lv_res.
*****calling of subrotines
**PERFORM sub_add.
*****calculate result
**lv_res = lv_var1 + lv_var2.
**WRITE :/ lv_res.
**
**
*****defintion of subroutines
**FORM sub_add.
**
** LOCAL : lv_var1, lv_var2.
** lv_var1 = 50.
** lv_var2 = 25.
** lv_res = lv_var1 + lv_var2.
** WRITE :/ lv_res.
**
**ENDFORM. "sub_calc

**********************************************************************
****sample application to perform addition using SUBROUTINE
*DATA : lv_var1 TYPE i VALUE '10',
* lv_var2 TYPE i VALUE '20',
* lv_res TYPE i.
*
****calculate result
*lv_res = lv_var1 + lv_var2.
*WRITE :/ lv_res.
****calling of subrotines
*PERFORM sub_add.
****calculate result
*lv_res = lv_var1 + lv_var2.
*WRITE :/ lv_res.
*
*
****defintion of subroutines
*FORM sub_add.
*
* lv_var1 = 50.
* lv_var2 = 25.
* lv_res = lv_var1 + lv_var2.
* WRITE :/ lv_res.
*
*ENDFORM. "sub_calc

***********************************************************************
*****sample application to perform addition using SUBROUTINE
**DATA : lv_var1 TYPE i VALUE '10',
** lv_var2 TYPE i VALUE '20',
** lv_res TYPE i.
**
*****calculate result
**lv_res = lv_var1 + lv_var2.
**WRITE :/ lv_res.
*****calling of subrotines
**PERFORM sub_add.
*****calculate result
**lv_res = lv_var1 + lv_var2.
**WRITE :/ lv_res.
**
**
*****defintion of subroutines
**FORM sub_add.
**
** lv_res = lv_var1 + lv_var2.
** WRITE :/ lv_res.
**
**ENDFORM. "sub_calc

**********************************************************************
****sample application to perform addition using SUBROUTINE
*DATA : lv_var1 TYPE i VALUE '10',
* lv_var2 TYPE i VALUE '20',
* lv_res TYPE i.
*
****calling of subrotines
*PERFORM sub_add.
*WRITE : lv_res.
*PERFORM sub_mul.
*WRITE :/ lv_res.
*
****defintion of subroutines
*FORM sub_add.
*
* lv_res = lv_var1 + lv_var2.
*
*ENDFORM. "sub_calc
****defintion of subroutines
*FORM sub_mul.
*
* lv_res = lv_var1 * lv_var2.
*
*ENDFORM. "sub_calc
***********************************************************************
*****sample application to perform addition using SUBROUTINE
**DATA : lv_var1 TYPE i VALUE '10',
** lv_var2 TYPE i VALUE '20',
** lv_res TYPE i.
**
*****calling of subrotines
**PERFORM sub_calc.
**WRITE :/ lv_res.
**
*****defintion of subroutines
**FORM sub_calc.
**
** lv_res = lv_var1 + lv_var2.
*** WRITE :/ lv_res.
**ENDFORM. "sub_calc
*******executable stmt not accepted after definition
****WRITE :/ 'end of subroutine'.