Application Development and Automation 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: 
Read only

query regarding subroutines.........

Former Member
0 Likes
645

Can u please explain regarding passing internal table in subroutines??

explain it with some example code !!!!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
620

Hi

see this

PERFORM - parameter_list

Syntax

... [TABLES itab1 itab2 ...]

[USING a1 a2 ...]

[CHANGING a1 a2 ...].

Extras:

1. ... TABLES itab1 itab2 ...

2. ... USING a1 a2 ...

3. ... CHANGING a1 a2 ...

Effect

These additions assign actual parameters to the formal parameters from the parameter interface for the subroutine subr. You can specify all data objects whose data type matches the typing of the corresponding formal parameter (see Check Typing) as actual parameters. Each formal parameter assumes all the properties of the actual parameter assigned to it when it is called.

Addition 1

... TABLES itab1 itab2 ...

Effect

If you specify the addition TABLES, each table parameter t1 t2 ... for the subroutine called that is defined with the addition TABLES to the FORM statement must be assigned an internal table itab as the actual parameter. The assignment of the actual parameters to the formal parameters takes place using their positions in the lists t1 t2 ... and itab1 itab2 ... .

You can only specify standard tables for itab. Transfer takes place by means of a reference. If a specified table itab has a header line, this is also transferred; otherwise, the header line in the corresponding table parameter t is blank when it is called.

Note

Use of table parameters in the interface for subroutines is obsolete but a large number of subroutines have not yet been converted to appropriately typed USING or CHANGING parameters, so that they must still be supplied with data by the TABLES addition to the PERFORM statement.

Example

Static call of the internal subroutine select_sflight transferring a table parameter.

<b>

PARAMETERS: p_carr TYPE sflight-carrid,

p_conn TYPE sflight-connid.

DATA sflight_tab TYPE STANDARD TABLE OF sflight.

...

PERFORM select_sflight TABLES sflight_tab

USING p_carr p_conn.

...

FORM select_sflight TABLES flight_tab LIKE sflight_tab

USING f_carr TYPE sflight-carrid

f_conn TYPE sflight-connid.

SELECT *

FROM sflight

INTO TABLE flight_tab

WHERE carrid = f_carr AND

connid = f_conn.

ENDFORM.</b>

Addition 2

... USING a1 a2 ...

Addition 3

... CHANGING a1 a2 ...

Effect

If you specify the additions USING and CHANGING, an actual parameter a1 a2 ... of the appropriate type must be assigned to each of the formal parameters u1 u2 ... and c1 c2 ... defined with the same additions to the FORM statement. The actual parameters specified after USING and CHANGING form one shared list. They are assigned to the formal parameters after the position in the shared list. The type of parameter transfer is defined with the additions USING and CHANGING to the FORM statement. The addition USING must be before CHANGING. Otherwise, the assignment of the actual parameters to the additions USING and CHANGING is irrelevant to the PERFORM statement. It is also irrelevant whether only one or both of the additions is specified.

Notes

For the sake of program documentation, we advise that you specify the additions USING and CHANGING in the FORM statement according to the definition of the parameter interface.

In non-Unicode programs, you can address memory area outside an actual parameter if an actual parameter a1 a2 ... is assigned offset or length specifications. In non-Unicode programs, the length is set to the length of the current parameter if an offset is specified without a length. Both of these lead to warnings in the syntax check and to syntax errors in Unicode programs. The rules for the ASSIGN statement apply to the addressable memory area in non-Unicode programs as well.

Example

The following five PERFORM statements mean the same but only the fourth is recommended, since it is the only one that documents the interface of the subroutine called.

DATA: a1 TYPE string,

a2 TYPE string,

a3 TYPE string,

a4 TYPE string.

PERFORM test USING a1 a2 a3 a4.

PERFORM test CHANGING a1 a2 a3 a4.

PERFORM test USING a1 CHANGING a2 a3 a4.

PERFORM test USING a1 a2 CHANGING a3 a4.

PERFORM test USING a1 a2 a3 CHANGING a4.

...

FORM test USING p1 TYPE string

p2 TYPE string

CHANGING value(p3) TYPE string

value(p4) TYPE string.

...

ENDFORM.

<b>Reward points for useful Answers</b>

Regards

Anji

4 REPLIES 4
Read only

Former Member
0 Likes
620

Hi,

PROGRAM FORM_TEST.

TYPES: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE I,

END OF LINE.

DATA: ITAB TYPE STANDARD TABLE OF LINE WITH HEADER LINE,

JTAB TYPE STANDARD TABLE OF LINE.

PERFORM FILL TABLES ITAB.

MOVE ITAB[] TO JTAB.

PERFORM OUT TABLES JTAB.

FORM FILL TABLES F_ITAB LIKE ITAB[].

DO 3 TIMES.

F_ITAB-COL1 = SY-INDEX.

F_ITAB-COL2 = SY-INDEX ** 2.

APPEND F_ITAB.

ENDDO.

ENDFORM.

FORM OUT TABLES F_ITAB LIKE JTAB.

LOOP AT F_ITAB.

WRITE: / F_ITAB-COL1, F_ITAB-COL2.

ENDLOOP.

ENDFORM.

The produces the following output:

1 1

2 4

3 9

Reward if useful!

Read only

Former Member
0 Likes
620

Hi,

Check this sample code:

TABLES: KNA1,LFA1.

SELECT-OPTIONS : CUST FOR KNA1-KUNNR,

VENDOR FOR LFA1-LIFNR.

DATA : BEGIN OF ITAB OCCURS 0,

LIFNR LIKE LFA1-LIFNR,

LAND1 LIKE LFA1-LAND1,

NAME1 LIKE LFA1-NAME1,

END OF ITAB.

DATA : BEGIN OF JTAB OCCURS 0,

KUNNR LIKE KNA1-KUNNR,

LAND1 LIKE KNA1-LAND1,

NAME1 LIKE KNA1-NAME1,

END OF JTAB.

TYPE-POOLS : SLIS.

DATA : KNA1_B TYPE SLIS_T_FIELDCAT_ALV,

LAYOUT TYPE SLIS_LAYOUT_ALV,

EVENTS_B TYPE SLIS_T_EVENT.

DATA : REPID LIKE SY-REPID.

REPID = SY-REPID.

SELECT KUNNR

LAND1

NAME1

FROM KNA1

INTO TABLE ITAB

WHERE KUNNR IN CUST.

SELECT LIFNR

LAND1

NAME1 FROM LFA1

INTO

TABLE JTAB

WHERE LIFNR IN VENDOR.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

EXPORTING

I_CALLBACK_PROGRAM = REPID.

<b>PERFORM APPENDBLOCK TABLES ITAB USING 'ITAB'.

PERFORM APPENDBLOCK TABLES JTAB USING 'JTAB'.</b>

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'.

FORM APPENDBLOCK TABLES JTAB USING ITAB.

REFRESH KNA1_B.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = SY-REPID

I_INTERNAL_TABNAME = ITAB

I_INCLNAME = REPID

CHANGING

CT_FIELDCAT = KNA1_B.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

IS_LAYOUT = LAYOUT

IT_FIELDCAT = KNA1_B

I_TABNAME = ITAB

IT_EVENTS = EVENTS_B

TABLES

T_OUTTAB = JTAB.

ENDFORM.

Read only

Former Member
0 Likes
620
Report ychatest.

data: it001 type table of t001 with header line.

start-of-selection.
   perform get_company_codes tables it001.
 
 loop at it001. 
    write:/ it001-bukrs, it001-butxt.
  endloop.
 

form get_company_codes tables itab.
  select * into table itab from t001.
endform.
Read only

Former Member
0 Likes
621

Hi

see this

PERFORM - parameter_list

Syntax

... [TABLES itab1 itab2 ...]

[USING a1 a2 ...]

[CHANGING a1 a2 ...].

Extras:

1. ... TABLES itab1 itab2 ...

2. ... USING a1 a2 ...

3. ... CHANGING a1 a2 ...

Effect

These additions assign actual parameters to the formal parameters from the parameter interface for the subroutine subr. You can specify all data objects whose data type matches the typing of the corresponding formal parameter (see Check Typing) as actual parameters. Each formal parameter assumes all the properties of the actual parameter assigned to it when it is called.

Addition 1

... TABLES itab1 itab2 ...

Effect

If you specify the addition TABLES, each table parameter t1 t2 ... for the subroutine called that is defined with the addition TABLES to the FORM statement must be assigned an internal table itab as the actual parameter. The assignment of the actual parameters to the formal parameters takes place using their positions in the lists t1 t2 ... and itab1 itab2 ... .

You can only specify standard tables for itab. Transfer takes place by means of a reference. If a specified table itab has a header line, this is also transferred; otherwise, the header line in the corresponding table parameter t is blank when it is called.

Note

Use of table parameters in the interface for subroutines is obsolete but a large number of subroutines have not yet been converted to appropriately typed USING or CHANGING parameters, so that they must still be supplied with data by the TABLES addition to the PERFORM statement.

Example

Static call of the internal subroutine select_sflight transferring a table parameter.

<b>

PARAMETERS: p_carr TYPE sflight-carrid,

p_conn TYPE sflight-connid.

DATA sflight_tab TYPE STANDARD TABLE OF sflight.

...

PERFORM select_sflight TABLES sflight_tab

USING p_carr p_conn.

...

FORM select_sflight TABLES flight_tab LIKE sflight_tab

USING f_carr TYPE sflight-carrid

f_conn TYPE sflight-connid.

SELECT *

FROM sflight

INTO TABLE flight_tab

WHERE carrid = f_carr AND

connid = f_conn.

ENDFORM.</b>

Addition 2

... USING a1 a2 ...

Addition 3

... CHANGING a1 a2 ...

Effect

If you specify the additions USING and CHANGING, an actual parameter a1 a2 ... of the appropriate type must be assigned to each of the formal parameters u1 u2 ... and c1 c2 ... defined with the same additions to the FORM statement. The actual parameters specified after USING and CHANGING form one shared list. They are assigned to the formal parameters after the position in the shared list. The type of parameter transfer is defined with the additions USING and CHANGING to the FORM statement. The addition USING must be before CHANGING. Otherwise, the assignment of the actual parameters to the additions USING and CHANGING is irrelevant to the PERFORM statement. It is also irrelevant whether only one or both of the additions is specified.

Notes

For the sake of program documentation, we advise that you specify the additions USING and CHANGING in the FORM statement according to the definition of the parameter interface.

In non-Unicode programs, you can address memory area outside an actual parameter if an actual parameter a1 a2 ... is assigned offset or length specifications. In non-Unicode programs, the length is set to the length of the current parameter if an offset is specified without a length. Both of these lead to warnings in the syntax check and to syntax errors in Unicode programs. The rules for the ASSIGN statement apply to the addressable memory area in non-Unicode programs as well.

Example

The following five PERFORM statements mean the same but only the fourth is recommended, since it is the only one that documents the interface of the subroutine called.

DATA: a1 TYPE string,

a2 TYPE string,

a3 TYPE string,

a4 TYPE string.

PERFORM test USING a1 a2 a3 a4.

PERFORM test CHANGING a1 a2 a3 a4.

PERFORM test USING a1 CHANGING a2 a3 a4.

PERFORM test USING a1 a2 CHANGING a3 a4.

PERFORM test USING a1 a2 a3 CHANGING a4.

...

FORM test USING p1 TYPE string

p2 TYPE string

CHANGING value(p3) TYPE string

value(p4) TYPE string.

...

ENDFORM.

<b>Reward points for useful Answers</b>

Regards

Anji