Thursday 14 July 2016

Global Class : Passing parameters ( Select-Options 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 short description and click on save button.
  • Class Interface looks like,



  • Enter the method name.
  • Select the Level and Visibility.
  • Click on method name and click Parameters button.
  • Screen looks like,
  • Enter the Parameter name and select the type of it.


Creating custom select-options

  • Go to transaction code SE11.
  • Click on Data Type radio button.
  • Enter the standard SELECT-OPTIONS structure name i.e RSDSELOPT.
  • Click on Copy .


  • Pop-up will appear.
  • Customize select-options name and click on continue.

  • Assign the package name , either Local package or Package.
  • Check the status bar.

  • Click on Change button.
  • Pop-up will appear.
  • Click on "Main,in Orginal Lang" .
  • Structure looks like,
  • Choose the Component Type for LOW and HIGH as per requirements and press ENTER.
  • Save -> Check -> Activate.

  • Copy the structure name.
  • Go back to SE24.



  • Enter the Associated Type as :  customized Select-options name and press ENTER.

  • For Internal table as parameter :Enter Parameter name.
  • Select the Type.
  • Enter the associated Type as : Table Type and press ENTER.
  • Click on Save and Click on back button.
  • To implement the method.
  • Double click on method name.

  • Screen looks like,


  • Enter the logic.

  
  SELECT * FROM MAKT INTO TABLE CH_ITAB WHERE MATNR BETWEEN IM_MATNR-LOW AND IM_MATNR-HIGH.


  • Save it and click on BACK button.
  • Define one more method.
  • Enter the method name.
  • Select the Level and Visibility of the method.
  • Enter the description.

  • To add parameters to method.
  • Click on method name and click on Parameters button.
  • Enter the parameter name , its Type and Associated Type as Table Type and press ENTER.
  • Save it and click on BACK button.
  • To implement the method.
  • Double click on method name.
  • Screen looks like,
  • Enter the Logic.
DATA : WA_MAKT TYPE MAKT.
  
  LOOP AT IM_ITAB INTO WA_MAKT.
    
    WRITE : / WA_MAKT-MATNR , WA_MAKT-SPRAS , WA_MAKT-MAKTX.

  ENDLOOP.






  • Save and click on back button.
  • Save -> Check -> Activate.

Main Program

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

Source Code


  • To call  global class method.
  • Click on Pattern.
  • Pop-up will appear.
  • Select "ABAP Objects Patterns"  radio button and click on continue.
  • Pop-up will appear.
  • Enter the instance name , class name.

  • Select the method using F4  help.
  • Select the method.

  • Double click on method.
  • Click on Continue.
  • Similarly, we call other global methods.




Source code

TABLES : MAKT.

DATA : OBJ TYPE REF TO   ZCL_SELECT_OPT_ITAB.

DATA : IT_MAKT TYPE TABLE OF MAKT.

SELECT-OPTIONS : S_MATNR FOR MAKT-MATNR.

CREATE OBJECT OBJ.
CALL METHOD OBJ->FETCH_DATA
  EXPORTING
    IM_MATNR = S_MATNR
  CHANGING
    CH_ITAB  = IT_MAKT
    .
CALL METHOD OBJ->DISPLAY
  EXPORTING
    IM_ITAB = IT_MAKT
    .


  • Save -> Check -> Activate.
  • Execute ( F8).

Input


  • Enter the input.
  • Execute (F8).

Output




No comments:

Post a Comment