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

return value after call bapi

Former Member
0 Likes
1,374

Please read my code as below. My problem always exit even when call bapi successfully. I debug this code, find RETURN is null.

I'm a newbie at ABAP. please help me.

CALL FUNCTION 'BAPI_PO_GETITEMS'
EXPORTING
...
TABLES
...
RETURN = RETURN.


if RETURN-TYPE  u300Au300B 'S'.
  OUTPUT-RETCODE = RETURN-TYPE.
  exit.
endif.

1 ACCEPTED SOLUTION
Read only

SureshRa
Active Participant
0 Likes
720

Hi,

There are two things you should note.

1. RETURN is a table parameter. So you need to loop through it. You seem to be reading only the header of the table.

2. This BAPI returns an EMPTY table RETURN if it is successful in reading the PO items. In this case your code will exit whenever PO items are read successfully.

You change your code like below:


DATA: v_failure TYPE c.
.....
....
CLEAR v_failure.
LOOP AT return.
  IF return-type IN ('E', 'A'). "Error or Abend - both un-successful
    v_failure = 'X'.
    EXIT.  "This EXIT is to exit the loop if any error is found
  ENDIF.
ENDLOOP.
IF v_failure = 'X'.
  EXIT.  "This EXIT is to exit your routine.
ENDIF.

Cheers,

Suresh

2 REPLIES 2
Read only

Former Member
0 Likes
720

Hello,

If you provide a valid PO number, then the RETURN parameter will be empty. If you give an invalid PO, you will get RETURN with TYPE NE 'S'.

Thanks,

Venu

Read only

SureshRa
Active Participant
0 Likes
721

Hi,

There are two things you should note.

1. RETURN is a table parameter. So you need to loop through it. You seem to be reading only the header of the table.

2. This BAPI returns an EMPTY table RETURN if it is successful in reading the PO items. In this case your code will exit whenever PO items are read successfully.

You change your code like below:


DATA: v_failure TYPE c.
.....
....
CLEAR v_failure.
LOOP AT return.
  IF return-type IN ('E', 'A'). "Error or Abend - both un-successful
    v_failure = 'X'.
    EXIT.  "This EXIT is to exit the loop if any error is found
  ENDIF.
ENDLOOP.
IF v_failure = 'X'.
  EXIT.  "This EXIT is to exit your routine.
ENDIF.

Cheers,

Suresh