Show TOC

Procedure documentationEnhancing the BAPI Wrappers Locate this document in the navigation structure

 

You need to make adjustments in the code of the generated BAPI wrappers to enable them to retrieve data from the database tables ZTR_ORDER_HDR and ZTR_ORDER_ITM.

Procedure

  1. In the NetWeaver Application Server ABAP, start the Function Builder (transaction SE37).

  2. For Function Module, enter ZTR_ORDER_GETLIST and choose Change.

  3. In the source code view, edit the function module code so that it is identical to the example below. You can copy and paste the example code.

    FUNCTION ZTR_ORDER_GETLIST.

    *"--------------------------------------------------------------------

    *"*"Local Interface:

    *" TABLES

    *" ORDERHEADER STRUCTURE ZTR_ORDER_HDR

    *" RETURN STRUCTURE BAPIRET2

    *"--------------------------------------------------------------------

    select * from ZTR_ORDER_HDR

    into corresponding fields of table orderheader.

    ENDFUNCTION.

  4. Choose Check to check the syntax and then activate the module.

  5. After activation, test the BAPI Wrapper functionality by choosing Test/Execute (or by pressing F8).

    The BAPI returns the order data present in the ZTR_ORDER_HDR table.

  6. Leave the Function Builder.

  7. Start the Function Builder (transaction SE37), enter ZTR_ORDER_GETDETAIL and choose Change.

  8. In the source code view, edit the function module code so that it is identical to the example below. You can copy and paste the example code into the editor.

    FUNCTION ZTR_ORDER_GETDETAIL.

    *"--------------------------------------------------------------------

    *"*"Local Interface:

    *" IMPORTING

    *" VALUE(ORDERID) TYPE ZTR_ORDER_HDR-ORDERID

    *" EXPORTING

    *" VALUE(ORDERHEADER) TYPE ZTR_ORDER_HDR

    *" TABLES

    *" RETURN STRUCTURE BAPIRET2

    *" ORDERITEM STRUCTURE ZTR_ORDER_ITM

    *"--------------------------------------------------------------------

    DATA : wa_bapiret TYPE bapiret2.

    SELECT SINGLE * FROM ZTR_ORDER_HDR

    INTO CORRESPONDING FIELDS OF orderheader

    WHERE orderid EQ orderid.

    IF sy-subrc NE 0.

    CALL FUNCTION 'BALW_BAPIRETURN_GET2'

    EXPORTING

    type = 'E'

    cl = 'BGMSG'

    number = 000

    par1 = 'No records exist'

    IMPORTING

    return = wa_bapiret.

    APPEND wa_bapiret TO return.

    ROLLBACK WORK.

    EXIT.

    ELSE.

    SELECT * FROM ZTR_ORDER_ITM

    INTO CORRESPONDING FIELDS OF table orderitem

    WHERE orderid EQ orderid.

    ENDIF.

    ENDFUNCTION.

  9. Choose Check to check the syntax and then activate the module.

  10. After activation, test the BAPI wrapper functionality by choosing Test/Execute (or by pressing F8).

  11. Enter a valid ORDERID and choose Execute.

    The BAPI returns the order items corresponding to this ORDERID.

  12. Leave the Function Builder.

  13. Start the Function Builder (transaction SE37), enter ZTR_ORDER_MODIFY and choose Change.

  14. In the source code view, edit the function module code so that it is identical to the example below. You can copy and paste the example code.

    FUNCTION ZTR_ORDER_MODIFY.

    *"--------------------------------------------------------------------

    *"*"Local Interface:

    *" IMPORTING

    *" VALUE(ORDERHEADER) TYPE ZTR_ORDER_HDR

    *" TABLES

    *" RETURN STRUCTURE BAPIRET2

    *" ORDERITEM STRUCTURE ZTR_ORDER_ITM

    *"--------------------------------------------------------------------

    DATA: it_return TYPE STANDARD TABLE OF bapiret2,

    tmpreturn TYPE bapiret2,

    tmp_ord TYPE ZTR_ORDER_HDR,

    wa_bapiret TYPE bapiret2,

    it_orditem TYPE STANDARD TABLE OF ZTR_ORDER_ITM,

    tmp_orditem TYPE ZTR_ORDER_ITM.

    REFRESH it_return.

    CLEAR tmp_ord. tmp_ord = orderheader.

    it_orditem[] = orderitem[].

    SELECT SINGLE orderid INTO tmp_ord-orderid

    FROM ZTR_ORDER_HDR

    WHERE orderid = tmp_ord-orderid

    .

    IF sy-subrc <> 0.

    CALL FUNCTION 'BALW_BAPIRETURN_GET2'

    EXPORTING

    type = 'E'

    cl = '00'

    number = 001

    par1 = 'Order not found'

    IMPORTING

    return = wa_bapiret.

    APPEND wa_bapiret TO return.

    ROLLBACK WORK.

    return.

    ENDIF.

    MODIFY ZTR_ORDER_HDR FROM tmp_ord.

    LOOP AT it_orditem INTO tmp_orditem

    WHERE orderid = tmp_ord-orderid.

    IF NOT tmp_orditem IS INITIAL.

    DELETE FROM ZTR_ORDER_ITM

    WHERE orderid = tmp_ord-orderid.

    exit.

    ENDIF.

    ENDLOOP.

    INSERT ZTR_ORDER_ITM FROM TABLE it_orditem.

    IF sy-subrc = 0.

    CALL FUNCTION 'BALW_BAPIRETURN_GET2'

    EXPORTING

    type = 'S'

    cl = '00'

    number = '001'

    par1 = 'Update Successful'

    IMPORTING

    return = wa_bapiret.

    APPEND wa_bapiret TO return.

    COMMIT WORK.

    ELSEIF sy-subrc <> 0.

    CALL FUNCTION 'BALW_BAPIRETURN_GET2'

    EXPORTING

    type = 'E'

    cl = '00'

    number = '001'

    par1 = 'NOT UPDATED'

    IMPORTING

    return = wa_bapiret.

    APPEND wa_bapiret TO return.

    ROLLBACK WORK.

    ENDIF.

    ENDFUNCTION.

  15. Choose Check to check the syntax and then activate the module.

  16. After activation, test the BAPI wrapper functionality by choosing Test/Execute (or by pressing F8).

  17. Enter a valid ORDERHEADER and table of ORDERITEM. Choose Execute. The BAPI returns the updated results in the RETURN table.

  18. Open the Data Browser (transaction SE16) and check the contents of the table ZTR_ORDER_ITM for the ORDERID entered in the previous step. The result should be identical to the table specified as the table ORDERITEM in the previous step.