Saturday, 16 July 2016

Local Class : Passing parameters ( Select-Options and Internal table ) to methods




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 the Attribute Type as : Executable Program.
  • Click on SAVE button.



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 SE38.


Source Code


CLASS C1 DEFINITION.

  PUBLIC SECTION.

  METHODS FETCH_DATA IMPORTING IM_MATNR TYPE  ZSEL
                       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 BETWEEN
IM_MATNR-LOW AND IM_MATNR-HIGH.

  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.

TABLES MAKT.
DATA OBJ TYPE REF TO C1.

DATA IT_MAKT TYPE TABLE OF MAKT.

SELECT-OPTIONS S_MATNR FOR MAKT-MATNR.

START-OF-SELECTION.

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.


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




Input

  • Enter the input.

  • Execute ( F8).

Output






No comments:

Post a Comment