Wednesday, 13 July 2016

Local Class : Passing parameters ( Parameter and Internal table ) to methods




Steps:

  • Go to Transaction code : SE38.
  • Enter the program name which start's with Y or Z<program name > and click Create button.
  • Enter the Title.
  • Select Attribute Type as : Executable program.
  • Click on Save.


Source Code



CLASS C1 DEFINITION.

  PUBLIC SECTION.

  METHODS : FETCH_DATA IMPORTING IM_MATNR TYPE MAKT-MATNR
                       CHANGING CH_ITAB TYPE MAKT_ITAB,
            DISPLAY IMPORTING IM_ITAB TYPE MAKT_ITAB.



  PROTECTED SECTION.


  PRIVATE SECTION.


ENDCLASS.


CLASS C1 IMPLEMENTATION.

  METHOD FETCH_DATA.

    SELECT * FROM MAKT INTO TABLE CH_ITAB WHERE MATNR = IM_MATNR.

  ENDMETHOD.

  METHOD DISPLAY.

    DATA : WA_MAKT TYPE MAKT.

    LOOP AT IM_ITAB INTO WA_MAKT.


      WRITE : / WA_MAKT-MATNR , WA_MAKT-SPRAS , WA_MAKT-MAKTX.

    ENDLOOP.


  ENDMETHOD.


ENDCLASS.


DATA : OBJ TYPE REF TO C1.

DATA : IT_MAKT TYPE TABLE OF MAKT.

PARAMETERS : P_MATNR TYPE MAKT-MATNR.

START-OF-SELECTION.
CREATE OBJECT OBJ.


CALL METHOD OBJ->FETCH_DATA
EXPORTING
  IM_MATNR = P_MATNR
CHANGING
  CH_ITAB  = IT_MAKT.

CALL METHOD OBJ->DISPLAY
EXPORTING
  IM_ITAB = IT_MAKT.

  • Class definition




  • Class Implementation.
  • Main Program.
  • Save ->Check -> Activate.
  • Execute (F8).

Input

  • Execute ( F8 ).

Output


No comments:

Post a Comment