Friday, 29 July 2016

Calling BAPIs from SAP-ABAP ( Ex : BAPI Message GetDetail )


  • This report uses the service BAPI BapiService.MessageGetDetail , to display the messages from message class ( SE91 ).
  • Go to SE91.
  • Enter the Meassage Class , Message ID  and click on display.
  • Messages are,

Steps

  • Go to Transaction code SE38.
  • Enter the Program name start's with Z or Y<program name>.

  • Enter the Title.
  • Select Attribute Type as Executable Program.
  • Click on Save.

  • Enter the source code.
DATA : ID LIKE  BAPIRET2-ID,
       NUMBER LIKE  BAPIRET2-NUMBER,
       TEXTFORMAT LIKE  BAPITGA-TEXTFORMAT,
       MESSAGE_V1 LIKE  BAPIRET2-MESSAGE_V1,
       MESSAGE LIKE  BAPIRET2-MESSAGE,
       RETURN LIKE  BAPIRET2 .


DATA:  BEGIN OF MY_TEXT OCCURS 1.
       INCLUDE STRUCTURE  BAPITGB.

 DATA: END OF MY_TEXT.


MOVE 'FI' TO ID.   "MESSAGE CLASS

MOVE '024' TO NUMBER. "MESSAGE ID

MOVE 'ASC' TO TEXTFORMAT.

MOVE '0001' TO MESSAGE_V1.


CALL FUNCTION 'BAPI_MESSAGE_GETDETAIL'
  EXPORTING
    ID                =   ID
    NUMBER            =   NUMBER
   LANGUAGE          = SY-LANGU
    TEXTFORMAT        =   TEXTFORMAT
*   LINKPATTERN       =
   MESSAGE_V1        = MESSAGE_V1
*   MESSAGE_V2        =
*   MESSAGE_V3        =
*   MESSAGE_V4        =
 IMPORTING
   MESSAGE           = MESSAGE
   RETURN            =  RETURN
 TABLES
   TEXT              = MY_TEXT
          .

IF RETURN IS INITIAL.
  WRITE : / 'VARIABLE MESSAGE  :' ,  MESSAGE_V1.
  SKIP 2.

 WRITE : / 'OUTPUT' COLOR 4.

 WRITE : / MESSAGE.

 SKIP 4.
 LOOP AT MY_TEXT.



    WRITE : / MY_TEXT. "SUCCESSFULL MESSAGE

   ENDLOOP.
   ELSE.

     WRITE : / RETURN-MESSAGE. "UNSUCCESSFULL MESSAGE


ENDIF.

  • Save-> Check -> Activate.
  • Execute.

No comments:

Post a Comment