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

Error in BAPI Coding

Former Member
0 Likes
578

Hi Experts,

I am new to interfaces like bapi, I tried a program for BAPI_ACC_DOCUMENT_POST to update AR, when i trying to execute it is displayng as "PROBLEM OCCURED".

Here i am giving program code, so please see the program and reslove my eror.

<removed by moderator>

DATA: obj_type LIKE bapiache09-obj_type,
      obj_key LIKE bapiache09-obj_key,
      obj_sys LIKE bapiache09-obj_sys,
      documentheader LIKE bapiache09,
      accountgl LIKE bapiacgl09 OCCURS 0 WITH HEADER LINE,
      accountpayable LIKE bapiacar09 OCCURS 0 WITH HEADER LINE,
      accountreceivable LIKE bapiacar09 OCCURS 0 WITH HEADER LINE,
      currencyamount LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE,
      return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
      extension1 LIKE bapiextc OCCURS 0 WITH HEADER LINE,
      t_edidd LIKE edidd OCCURS 0 WITH HEADER LINE,
      bapi_retn_info LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

DATA: error_flag.
documentheader-username = sy-uname.
documentheader-header_txt = 'Test BAPI'.
documentheader-comp_code = 'SERC'.
documentheader-doc_date = sy-datum.
documentheader-pstng_date = '10.09.2010'.
documentheader-doc_type = 'DR'.

CLEAR accountgl.
accountgl-itemno_acc = '1'.
accountgl-gl_account = '100100'.
accountgl-ref_key_1  = 'TEST'.
accountgl-comp_code = 'S150'.
accountgl-pstng_date = sy-datum.
accountgl-doc_type = 'DR'.
accountgl-customer = '2001'.
APPEND accountgl.
CLEAR accountgl.

CLEAR  accountreceivable.
accountreceivable-itemno_acc = '1'.
accountreceivable-customer = '2001'.
accountreceivable-gl_account = '100100'.
accountreceivable-comp_code = 'S150'.
APPEND accountreceivable.
CLEAR  accountreceivable.


APPEND currencyamount.
currencyamount-itemno_acc = '1'.
currencyamount-currency = 'INR'.
currencyamount-amt_doccur = '1000'.
APPEND currencyamount.


CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
  EXPORTING
    documentheader          = documentheader
*   CUSTOMERCPD             =
*   CONTRACTHEADER          =
 IMPORTING
   OBJ_TYPE                = obj_type
   OBJ_KEY                 = obj_key
   OBJ_SYS                 = obj_sys
  TABLES
   accountgl               = accountgl
   accountreceivable       = accountreceivable
*   ACCOUNTPAYABLE          =
*   ACCOUNTTAX              =
    currencyamount          = currencyamount
*   CRITERIA                =
*   VALUEFIELD              =
*   EXTENSION1              =
    return                  = return
*   PAYMENTCARD             =
*   CONTRACTITEM            =
*   EXTENSION2              =
*   REALESTATE              =
*   ACCOUNTWT               =
          .

IF sy-subrc <> 0.
  WRITE 'Problem occured'.
ELSE.
  *LOOP AT return.*
    *IF NOT return IS INITIAL.*
      *CLEAR bapi_retn_info.*
      *MOVE-CORRESPONDING return TO bapi_retn_info.*
      *IF return-type = 'A' OR return-type = 'E'.*
        *error_flag = 'X'.*
      *ENDIF.*
      *APPEND bapi_retn_info.*
    *ENDIF.*
  *ENDLOOP.*   (in this block i find error)
IF error_flag = 'X'.
    WRITE 'Problem occured'.
    ROLLBACK WORK.
  ELSE.
   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
          .
  ENDIF.

ENDIF.

Thanks in Advance,

gsreddy.

Edited by: Thomas Zloch on Jan 7, 2011 11:01 AM - please use code tags

4 REPLIES 4
Read only

Former Member
0 Likes
518

  *LOOP AT return.*
    *IF NOT return IS INITIAL.*
      *CLEAR bapi_retn_info.*
      *MOVE-CORRESPONDING return TO bapi_retn_info.*
      *IF return-type = 'A' OR return-type = 'E'.*
        *error_flag = 'X'.*
      *ENDIF.*
      *APPEND bapi_retn_info.*
    *ENDIF.*
  *ENDLOOP.*   (in this block i find error)

Uncomment the above code and check the errors in itab 'return' in debugging mode.

If are not able to resolve the error let us know what errors you are getting

Regards

Praveen

Read only

0 Likes
518

Hi Praveen,

Thanks for you reply, in the thread by mistake it was commented,

and i run the program in uncomment mode only, and error is displaying like "error occured"

(it displaying the write statement in 'IF 'block).

i did debug also, but i am not able to reslove the error.

<removed by moderator>

regards,

gsreddy.

Edited by: Thomas Zloch on Jan 7, 2011 1:52 PM - please no "needful" in these forums

Read only

0 Likes
518

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
  EXPORTING
    documentheader          = documentheader
*   CUSTOMERCPD             =
*   CONTRACTHEADER          =
 IMPORTING
   OBJ_TYPE                = obj_type
   OBJ_KEY                 = obj_key
   OBJ_SYS                 = obj_sys
  TABLES
   accountgl               = accountgl
   accountreceivable       = accountreceivable
*   ACCOUNTPAYABLE          =
*   ACCOUNTTAX              =
    currencyamount          = currencyamount
*   CRITERIA                =
*   VALUEFIELD              =
*   EXTENSION1              =
    return                  = return
*   PAYMENTCARD             =
*   CONTRACTITEM            =
*   EXTENSION2              =
*   REALESTATE              =
*   ACCOUNTWT               =
          .

In the BAPI tables parameter "return" what are the messages you are seeing in debugging mode???

Read only

brad_bohn
Active Contributor
0 Likes
518

SY-SUBRC is not relevant. Why do you check that and what is the condition? The 'NE' or 'EQ' is missing in your post. You've also hard-coded a customer account w/o leading zeros and hardcoded a date in the incorrect format - that's not correct. Otherwise, review some of that many examples in the forum or check the error messages as has already been suggested twice.