Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Subroutine

Former Member
0 Kudos
160

Hi,

How to create a subroutine in the program. I had written the program and i had written perform statement. Now i want to create subroutine in the program. what is the command we use for that.

This is my program.

REPORT ZAC_TAB23.

TYPES:

BEGIN OF TY_KNA1,

KUNNR TYPE KNA1-KUNNR,

LAND1 TYPE KNA1-LAND1,

NAME1 TYPE KNA1-NAME1,

ORT01 TYPE KNA1-ORT01,

END OF TY_KNA1,

BEGIN OF TY_VBAK,

VBELN TYPE VBAK-VBELN,

AUDAT TYPE VBAK-AUDAT,

AUART TYPE VBAK-AUART,

NETWR TYPE VBAK-NETWR,

END OF TY_VBAK,

BEGIN OF TY_VBAP,

POSNR TYPE VBAP-POSNR,

MATNR TYPE VBAP-MATNR,

ARKTX TYPE VBAP-ARKTX,

NETPR TYPE VBAP-NETPR,

NETWR TYPE VBAP-NETWR,

END OF TY_VBAP.

DATA:

ST_KNA1 TYPE TY_KNA1,

IT_KNA1 TYPE TABLE OF TY_KNA1,

ST_VBAK TYPE TY_VBAK,

IT_VBAK TYPE TABLE OF TY_VBAK,

ST_VBAP TYPE TY_VBAP,

IT_VBAP TYPE TABLE OF TY_VBAP.

  • S E L E C T O P T I O N S

SELECT-OPTIONS:

SKUNNR FOR ST_KNA1-KUNNR.

  • S T A R T O F S E L E C T I O N.

START-OF-SELECTION.

PERFORM GET CUSTDATA.

ENDFORM. "

Now iam getting the error that custdat is not able to interpret.

what is the command we use to create a

FORM CUSTDATA (Subroutine) in the end.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
134

PERFORM GET_CUSTDATA(USE underscore)

Form get_custdata.

process.....

endform.

reward if helpfull.

6 REPLIES 6

Former Member
0 Kudos
134

Hi,

write the subroutine with

FORM ...ENDFORM.

or double click on cust data it will ask to create subroutine..then say yes...

Regards,

Omkar.

Former Member
0 Kudos
135

PERFORM GET_CUSTDATA(USE underscore)

Form get_custdata.

process.....

endform.

reward if helpfull.

Former Member
0 Kudos
134

just double click on the name of the subroutine.

And just specify where you would like to create it.

You're good to go!

Former Member
0 Kudos
134

hi,

U wrote Perform Getdata.

Double click on the Getdata.

It will ask you whether to create a form .

When u say yes it will create a Form and Endform.

In between this form and endform u need to write whatever code u want to write to get the data.

0 Kudos
134

Hi

PERFORM -> calls the subroutine

FORM

...

ENDFORM -> declares and contains the code of the subroutine.

according to me what you are saying is conflicting you have already defined subroutines as

1. PERFORM GETDATA..

2. PERFORM DISPLAY.

in SAP subroutines are

1. Perform form

2. Function Module

3. Macros which is now Obselete

that is y Your program are working

* T Y P E S
TYPES:
BEGIN OF TYVBAK,
VBELN TYPE VBAK-VBELN,
AUART TYPE VBAK-AUART,
AUDAT TYPE VBAK-AUDAT,
KUNNR TYPE VBAK-KUNNR,
NETWR TYPE VBAK-NETWR,
END OF TYVBAK.

* D A T A D E C L A R A T I O N S
DATA:
STVBAK TYPE TYVBAK,
ITVBAK TYPE TABLE OF TYVBAK.

* S E L E C T I O N S C R E E N
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:
SKUNNR FOR STVBAK-KUNNR.
SELECTION-SCREEN END OF BLOCK B1.

* I N I T I A L I Z A T I O N
INITIALIZATION.

* FILLING SELECT OPTIONS WITH DEFAULTS

SKUNNR-SIGN = 'I'.
SKUNNR-OPTION = 'BT'.
SKUNNR-LOW = '1'.
SKUNNR-HIGH = '4000000'.
APPEND SKUNNR.

* S T A R T O F S E L E C T I O N

START-OF-SELECTION.
PERFORM GETDATA.
*&---------------------------------------------------------------------*
*& Form GETDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GETDATA.
SELECT VBELN "SALES DOCUMENT NUMBER
AUART "DOCUMENT TYPE
AUDAT "SALES DOCUMENT DATE
KUNNR "SOLD TO PARTY
NETWR "NETWORTH
FROM VBAK
INTO TABLE ITVBAK
WHERE KUNNR IN SKUNNR.

IF SY-SUBRC EQ 0.
SORT ITVBAK BY KUNNR VBELN.
PERFORM DISPLAY.
ENDIF.
ENDFORM. "GETDATA
*&---------------------------------------------------------------------*
*& Form display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM DISPLAY.
LOOP AT ITVBAK INTO STVBAK.
WRITE:/1 STVBAK-VBELN,12 STVBAK-AUART,18 STVBAK-AUDAT,30 STVBAK-NETWR.
ENDLOOP.
ENDFORM. 

Reward all helpfull answers

Regards

Pavan

Former Member
0 Kudos
134

hi ram,

just double click on subroutine that u have declared using perform statement. then system will automatically creates a subroutine for u as

perform suresh_aluri -


> double click on suresh_aluri.

form suresh_aluri. ---> system automatically creates a subroutine with the name u had given to it at last.

endform.

or to write manually use keyword FORM ...... ENDFORM as

FORM [FORMNAME]

ENDFORM.

if helpful reward some points.

with regards,

Suresh.A