Saturday 2 July 2016

Passing parameter and internal table as parameters in Normal Function Module

Steps

To create function module
  • Go to transaction code SE38.
  • Enter the function module name start's with Y or Z<function module name> and click on create button.



  • Enter the function group name.
  • Enter the short description.
  • Click on SAVE button.

  • Pop-up will appear. Click on continue.

  • In import tab , enter the import variable and it's type.
  • Click on Tables Tab and enter the  internal table name as well as its type and press ENTER.

  • Click on Exception tab and enter the exception.


  • Click on Source code tab and enter the source code.
  TABLES makt.

SELECT SINGLE MATNR FROM MAKT INTO MAKT-MATNR WHERE MATNR P_MATNR.
  IF SY-SUBRC NE 0.
   RAISE RECORD_NOT_FOUND.
  ELSE.

   SELECT FROM MAKT INTO TABLE IT_MAKT WHERE MATNR P_MATNR.
  ENDIF.





  • Save->Check ->Activate.

Usage of function module

  • 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

TABLES MAKT.

DATA IT_MAKT TYPE TABLE OF MAKT.

PARAMETERS P_MATNR TYPE MAKT-MATNR.

call function 'ZPASS_PARAM_INT_TAB'
  exporting
    p_matnr                p_matnr
  tables
    it_makt                it_makt
 EXCEPTIONS
   RECORD_NOT_FOUND       1
   OTHERS                 2
          .
if sy-subrc 0.
LOOP AT it_makt INTO makt.

WRITE / makt-matnr makt-spras makt-maktx.
ENDLOOP.
endif.

IF sy-subrc 1.
  "RECORD_NOT_FOUND
  MESSAGE 'Material number not found ' TYPE 'E'.

ENDIF.



  • Save ->Check->Activate.


  • Execute (F8).

Input-1

  • Enter the material number which does not exit in MAKT table.



  • Click on execute.

Output



Input-2



  • Enter the material Number.

  • Execute.

Output



No comments:

Post a Comment