Wednesday, 13 July 2016

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






2 comments:

  1. Being healthy and fit isn’t a fad or a trend, it’s a lifestyle. Helping people lead healthy and happy lives through design.

    Source: BIOMANIX 2021
    More on: HEALTH

    ReplyDelete
  2. It’s my pleasure to read this blog post. This is amazing and very informative. I appreciate your efforts to write this and I am thankful to you for adding some value to my knowledge.
    I am excited to share this with my friends because they will also get something from it surely and will be thankful for yours. Keep sharing your thoughts.
    I am Stella Jones from AU and I am a part of a joint seal service provider team with a Caulkers Brisbane solution. We are the best joint sealing solution company in the AU.
    Feel free to contact us and get a permanent solution for joint sealing.

    ReplyDelete