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.
- In import tab , enter the import variable and it's type.
- 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.
Usage of function module
- 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.
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.
- Execute (F8).
Input-1
- Click on execute.
Output
Input-2
- Execute.
No comments:
Post a Comment