Friday 1 July 2016

Passing Internal Tables as Parameters



  • We can use one of two methods to pass an internal table to a subroutine:
  1. Pass with header line.
  2. Pass body only 
  • Summarizes the effect of each of these methods on internal tables with and without header lines.
  • The syntax for each method of passing an internal table to a subroutine.
  • Syntax for Describing the Internal Table to the Subroutine.
Ex:



Steps

  • Go to Transaction Code SE38.
  • Enter the program name start's with Y or Z<program name > and click on create button.
  • Enter the Title.
  • Select Attribute Type as Executable Program.
  • Click on save button.

Source Code




REPORT  ZPASS_INTER_TAB_SUB.
DATA IT_MAKT TYPE TABLE OF MAKT WITH HEADER LINE.

SELECT-OPTIONS S_MATNR FOR IT_MAKT-MATNR.

PERFORM FETCH_DATA USING S_MATNR[]  CHANGING IT_MAKT[].
 PERFORM DISPLAY TABLES IT_MAKT.

*&---------------------------------------------------------------------*
*&      Form  FETCH_DATA
*&---------------------------------------------------------------------*
    Internal Table passed without header Line
*----------------------------------------------------------------------*
*      -->P_S_MATNR  text
*      <--P_IT_MAKT  text
*----------------------------------------------------------------------*
form FETCH_DATA  using    p_s_matnr LIKE s_matnr[]
                 changing p_it_makt LIKE it_makt[].

  SELECT FROM MAKT INTO TABLE p_it_makt[] WHERE MATNR IN p_s_matnr.

endform.                    " FETCH_DATA
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
Internal Table passed with header Line



*----------------------------------------------------------------------*
*      -->P_IT_MAKT  text
*----------------------------------------------------------------------*
form DISPLAY  tables   p_it_makt structure MAKT.
                         "Insert correct name for <...>.

LOOP AT   p_it_makt.

 WRITE /   p_it_makt-MATNR ,   p_it_makt-SPRAS ,   p_it_makt-MAKTX.
ENDLOOP.

endform.                    " DISPLAY

  • Save ->Check ->Activate.
  • Execute

Input

Output



No comments:

Post a Comment