Ex : -
Steps
- Go to Transaction code SE38.
- Enter the program name start's with Y or Z < program name > and click on Create.
- Pop-up will appear.
- Enter the Title.
- Select the Attribute type as Executable program.
- Click on SAVE.
- Source Code.
CLASS C1 DEFINITION.
PUBLIC SECTION.
EVENTS : NO_RECORD .
METHODS : FETCH_DATA IMPORTING IM_VBELN TYPE VBAP-VBELN
CHANGING CH_ITAB TYPE VBAP_T,
DISPLAY IMPORTING IM_ITAB TYPE VBAP_T,
EVENT_HANDLER FOR EVENT NO_RECORD OF C1.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS C1 IMPLEMENTATION.
METHOD FETCH_DATA.
SELECT * FROM VBAP INTO TABLE CH_ITAB WHERE VBELN = IM_VBELN.
IF SY-SUBRC NE 0.
RAISE EVENT NO_RECORD.
ENDIF.
ENDMETHOD.
METHOD DISPLAY.
DATA : WA_VBAP TYPE VBAP.
LOOP AT IM_ITAB INTO WA_VBAP.
WRITE : / WA_VBAP-VBELN , WA_VBAP-POSNR , WA_VBAP-MATNR ,
WA_VBAP-ARKTX , WA_VBAP-NETWR.
ENDLOOP.
ENDMETHOD.
METHOD EVENT_HANDLER.
MESSAGE 'RECORD NOT FOUND' TYPE 'I'.
ENDMETHOD.
ENDCLASS.
DATA : OBJ TYPE REF TO C1.
DATA : IT_VBAP TYPE TABLE OF VBAP.
PARAMETERS : P_VBELN TYPE VBAP-VBELN.
START-OF-SELECTION.
CREATE OBJECT OBJ.
SET HANDLER OBJ->EVENT_HANDLER FOR OBJ.
CALL METHOD OBJ->FETCH_DATA
EXPORTING
IM_VBELN = P_VBELN
CHANGING
CH_ITAB = IT_VBAP.
CALL METHOD OBJ->DISPLAY
EXPORTING
IM_ITAB = IT_VBAP.
No comments:
Post a Comment