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


Steps

  • Go to transaction code SE24.
  • Enter the Object Type as class name which start's with YCL or ZCL< class name > and click on create,
  • Pop-up will appear.
  • Enter the Description and click on Save.
      

  • Enter the method name.
  • Select the level.
  • Select the visibility and description.

  • Click on Method name and click on Parameters Button.

  • Initial screen looks like,

  • Enter the import parameter name ,
  • Click on Type.
  • Click on F4 help and Select the Type.
  • Click on Associated Type.
  • Enter the associated type and press Enter.

  • Enter the parameter name.
  • Select the type using F4 help.
  • Enter the Associated type as Table Type and press Enter.



  • Click on Save and back button.

  • Double click on method (FETCH_DATA).


  • Screen looks like,

  • Write the logic.
  • Save it.
  • Click on back button.
  • Enter the method name.
  • Select the Level  and Visibility  .
  • Enter the description.
  • Select the method and click on Parameters button.


  • Screen looks like,
  • Enter the parameter name.
  • Enter the Type.
  • Enter the Associated Type and press Enter.
  • Save it and click on back button.

  • Double click on method.
  • Initial screen looks like,
  • Write the logic,
  • Logic,
method DISPLAY.
  
  DATA : WA TYPE MAKT.
  
  LOOP AT  IM_ITAB INTO WA.
    
    WRITE : / WA-MATNR , WA-SPRAS , WA-MAKTX.

  ENDLOOP.
endmethod.


  • Save  and click on back button.

  • Save -> Check -> Activate.

Usage of Class

  • 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


DATA : OBJ TYPE REF TO ZCL_PARAM_ITAB.

DATA : IT 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
    .

CALL METHOD OBJ->DISPLAY
  CHANGING
    IM_ITAB = IT
    .


  • Save -> Check -> Activate.
  • Click on execute (F8).

Input

  • Enter the Input.


  • Click on execute.

Output



Comments

Popular posts from this blog

FOR ALL ENTRIES (FAE) -4 TABLES USING ALV_GRID_DISPLAY

RADIO-BUTTONS IN BASIC REPORT