0% found this document useful (0 votes)
6 views3 pages

Sub Routines

The document discusses different ways to pass parameters between programs and subroutines in ABAP, including passing by reference vs value and how to pass internal tables with or without header lines defined.

Uploaded by

Tejas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Sub Routines

The document discusses different ways to pass parameters between programs and subroutines in ABAP, including passing by reference vs value and how to pass internal tables with or without header lines defined.

Uploaded by

Tejas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

DATA NUM1 TYPE I VALUE 10.

DATA NUM2 TYPE I VALUE 20.

DATA RES TYPE I.

PERFORM ADDNUM USING NUM1 NUM2 CHANGING RES.

FORM ADDNUM USING VALUE(N1) VALUE(N2) CHANGING R.

R = N1 + N2.

ENDFORM.

By Reference: (changed value is sent to the calling function)

Using and Changing can be used interchangeably and with each other also. Same output.

PERFORM S1 USING F1. OR PERFORM S1 CHANGING F1 [ F1 is actual parameter]

FORM S1 USING P1.[P1 is formal parameter]

----

ENDFORM.

OR

PERFORM S1 CHANGING F1. OR PERFORM S1 USING F1

FORM S1 CHANGING P1.

ENDFORM.

By Value: (changed value is not sent back to calling function)

PERFORM S1 USING F1.

FORM S1 USING VALUE(P1).

ENDFORM.

Here when u use them interchangeably it behaves differently.

USING with USING VALUE() – behaves as pass by value. i.e changed value is not sent back.

USING with CHANGING VALUE()—behaves as pass by reference.

CHANGING with CHANGING VALUE()—behaves as pass by reference.

CHANGING with USING VALUE()—behaves as pass by value.


Passing an Internal Table without Header Line
and automatically creating a header line in Subroutine

 PERFORM S1 TABLES itab.


o FORM S1 TABLES PT STRUCTURE FS. *FS is previously defined structure(not in SE11 but
in same program)…. ENDFORM
o FORM S1 TABLES PT STRUCTURE ZStructname…ENDFORM.
o FORM S1 TABLES PT LIKE ITDEPT……. ENDFORM.
 GENERAL SYNTAX:

FORM <Formname> TABLES<subroutine tablename>


STRUCTURE <structname> /LIKE internal tablename.

The following does not work.


o FORM S1 TABLES PT. "does not work bcz PT does not have structure
o FORM S1 TABLES ITDEPT. "does not work bcz ITDEPT does not have
Structure.
o FORM S1 TABLES PT STRUCTURE ITDEPT. “ITDEPT is not structure.

 Passing Internal table without a header line and


Header line is not automatically created in subroutine.

PERFORM S1 USING ITDEPT.

PERFORM S1 CHANGING ITDEPT.

 form s1 using PT like itdept. “Pass by reference

 form s1 using value(PT) LIKE itdept. “Pass by value

 form s1 changing PT like itdept.

 form s1 changing value(PT) LIKE itdept.

GENERAL SYNTAX:

FORM <Formname> USING/CHANGING [VALUE]<subroutine tablename> LIKE


internal tablename.

 Passing body of an Internal table that has a header line.


PERFORM S1 TABLES itab.
o FORM S1 TABLES PT STRUCTURE FS. *FS is previously defined structure(not in SE11 but
in same program)…. ENDFORM
o FORM S1 TABLES PT STRUCTURE ZStructname…ENDFORM.
o FORM s1 TABLES pt STRUCTURE itdept.
o FORM S1 TABLES PT LIKE ITDEPT[].
GENERAL SYNTAX:
FORM <Formname> TABLES<subroutine tablename>
STRUCTURE <structname> /STRUCTURE internal tablename/LIKE internal
tablename[].
Following does not work.
o FORM S1 TABLES PT. "does not work
o FORM S1 TABLES PT LIKE ITDEPT. "does not work bcz no body

You might also like