Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

catching error in bapi_po_create1

sergio_cifuentes
Participant
0 Likes
763

i'm calling the bapi_po_create1 from an rfc, it contains some errors, that i can see it in the return table, but i've tried to catch wether is an error ocurred or not, but the sy-subrc it's always 0, why??

here's my code:



CALL FUNCTION 'BAPI_PO_CREATE1'
    EXPORTING
      poheader          = v_header
      poheaderx         = v_headerx
    IMPORTING
      exppurchaseorder  = v_purch
    TABLES
      poitem            = v_item
      poitemx           = v_itemx
      return            = v_return.

  IF sy-subrc = 0.    "always = 0
    PERFORM pr_commit TABLES v_return
                      USING  'X'.
    WRITE: / v_purch.
  ELSE.
    LOOP AT v_return.
      WRITE:  / v_return-type,
                v_return-message.
    ENDLOOP.
  ENDIF.

1 ACCEPTED SOLUTION
Read only

jens_becher
Explorer
0 Likes
679

hi,

the call of 'BAPI_PO_CREATE1' will never set the sy-subrc, because there's no exception for it. The only chance you have is to check the return table for error messages, like

 
loop at v_return where msgty = 'E'.
      WRITE:  / v_return-type,
                v_return-message.
endloop.
if sy-subrc <> 0.
* everyting seems ok
    PERFORM pr_commit TABLES v_return
                      USING  'X'.
    WRITE: / v_purch.
endif.

hope it helps.

i'm calling the bapi_po_create1 from an rfc, it contains some errors, that i can see it in the return table, but i've tried to catch wether is an error ocurred or not, but the sy-subrc it's always 0, why??

here's my code:



CALL FUNCTION 'BAPI_PO_CREATE1'
    EXPORTING
      poheader          = v_header
      poheaderx         = v_headerx
    IMPORTING
      exppurchaseorder  = v_purch
    TABLES
      poitem            = v_item
      poitemx           = v_itemx
      return            = v_return.

  IF sy-subrc = 0.    "always = 0
    PERFORM pr_commit TABLES v_return
                      USING  'X'.
    WRITE: / v_purch.
  ELSE.
    LOOP AT v_return.
      WRITE:  / v_return-type,
                v_return-message.
    ENDLOOP.
  ENDIF.

3 REPLIES 3
Read only

Former Member
0 Likes
679

Hi,

Define an internal table or type BAPIRET2 for holding the error messages and pass it to function module as RETURN table for catching errors.

loop at it_return.

commit if there are no errors.

endloop.

Regards,

Srilatha.

Read only

jens_becher
Explorer
0 Likes
680

hi,

the call of 'BAPI_PO_CREATE1' will never set the sy-subrc, because there's no exception for it. The only chance you have is to check the return table for error messages, like

 
loop at v_return where msgty = 'E'.
      WRITE:  / v_return-type,
                v_return-message.
endloop.
if sy-subrc <> 0.
* everyting seems ok
    PERFORM pr_commit TABLES v_return
                      USING  'X'.
    WRITE: / v_purch.
endif.

hope it helps.

Read only

Former Member
0 Likes
679

Instead of using sy-subrc use:

IF v_return[] IS INITIAL.

then check for message type E

ENDIF.