Application Development 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: 

USING EXTENSION tables parameter in BAPI_ACC_DOCUMENT_POST

Former Member
0 Kudos

Hi,

I need to pass salesorder number when posting customers account in BAPI_ACC_DOCUMENT_POST.

In extension1 i delare like this

i_extension TYPE STANDARD TABLE OF BAPIACEXTC WITH HEADER LINE,

REFRESH i_extension.

CLEAR i_extension.

i_extension-field1 = '0000001364'.

append i_extension.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

documentheader = wa_documentheader

*IMPORTING

*obj_type = wa_documentheader-obj_type

*obj_key = wa_documentheader-obj_key

*obj_sys = wa_documentheader-obj_sys

TABLES

accountgl = i_accountgl

accountreceivable = i_accountreceivable

currencyamount = i_currencyamount

extension1 = i_extension

return = return.

but it's not posting the sales order number, here am i missing something. Appreciate your help?????????

1 ACCEPTED SOLUTION

former_member181962
Active Contributor
0 Kudos

I Think the extension parameter EXTENSION2 would be more relevant for you.

Here is an excerpt from the documentation:

<b> Reference Structure for BAPI Parameters EXTENSIONIN/EXTENSIO

Description

This enhancement structure can be used to transfer additional fields.

There are four fields available for each data record (VALUEPART1 - 4),

which each contain 240 characters. A defined ABAP dictionary structure

can be transferred in the field STRUCTURE, on the basis of which the

field contents are read.

The accounting document can be supplemented and changed in an

implemented BAdI (ACC_DOCUMENT) before the active accounting component

is called.

Default

The class CL_EXM_IM_ACC_DOCUMENT is available as example implementation.

Here, for each data record of the parameter that is transferred the ABAP

dictionary structure is checked and the content of the fields VALUEPART1

to -4 is set in the structure. If the structure that is transferred

contains a field POSNR, the associated lines of the accounting document

are updated using the contents of the enhancement. </b>

regards,

ravi

17 REPLIES 17

Former Member
0 Kudos

Hi,

You have to use BAdI ACC_DOCUMENT and copy the fields there. Just read the documentation for BAPI and the BAdI.

Hope this helps - please reward me if it does.

Regards, Joerg

former_member181962
Active Contributor
0 Kudos

I Think the extension parameter EXTENSION2 would be more relevant for you.

Here is an excerpt from the documentation:

<b> Reference Structure for BAPI Parameters EXTENSIONIN/EXTENSIO

Description

This enhancement structure can be used to transfer additional fields.

There are four fields available for each data record (VALUEPART1 - 4),

which each contain 240 characters. A defined ABAP dictionary structure

can be transferred in the field STRUCTURE, on the basis of which the

field contents are read.

The accounting document can be supplemented and changed in an

implemented BAdI (ACC_DOCUMENT) before the active accounting component

is called.

Default

The class CL_EXM_IM_ACC_DOCUMENT is available as example implementation.

Here, for each data record of the parameter that is transferred the ABAP

dictionary structure is checked and the content of the fields VALUEPART1

to -4 is set in the structure. If the structure that is transferred

contains a field POSNR, the associated lines of the accounting document

are updated using the contents of the enhancement. </b>

regards,

ravi

0 Kudos

How can i use this ACC_DOCUMENT BADI in my custom program. I posted my code here. Please guide me with this.

DATA: wa_documentheader TYPE bapiache09,

i_accountgl TYPE STANDARD TABLE OF bapiacgl09

WITH HEADER LINE,

i_accountreceivable TYPE STANDARD TABLE OF bapiacar09

WITH HEADER LINE,

i_currencyamount TYPE STANDARD TABLE OF bapiaccr09

WITH HEADER LINE,

i_ext2 TYPE STANDARD TABLE OF bapiparex WITH HEADER LINE,

return TYPE STANDARD TABLE OF bapiret2

WITH HEADER LINE.

*WA_DOCUMENTHEADER-OBJ_TYPE = 'BKPFF'.

*WA_DOCUMENTHEADER-OBJ_KEY = '$' .

*CONCATENATE SY-SYSID 'CLNT' SY-MANDT INTO WA_DOCUMENTHEADER-OBJ_SYS.

*

*wa_documentheader-header_txt = '0000000103'. '1001339'

wa_documentheader-header_txt = '0001001339'.

wa_documentheader-bus_act = 'RFBU' .

wa_documentheader-username = sy-uname.

wa_documentheader-comp_code = 'US10'.

wa_documentheader-doc_date = sy-datum.

wa_documentheader-pstng_date = sy-datum.

wa_documentheader-doc_type = 'Z2'.

REFRESH i_accountgl.

CLEAR i_accountgl.

i_accountgl-itemno_acc = 1.

i_accountgl-gl_account = '0000113014' .

i_accountgl-item_text = 'Test'.

i_accountgl-profit_ctr = '0000002000'.

APPEND i_accountgl.

*-- Account receivable

I_accountreceivable-itemno_acc = 2.

i_accountreceivable-customer = '0000116153'.

*i_accountreceivable-gl_account = '0000121000'.

i_accountreceivable-sp_gl_ind = 'A'.

DATA: ls_zzz type STANDARD TABLE OF ACCIT with header line.

CLEAR i_ext2.

  • i_ext2-structure = ACCIT.

ls_zzz-posnr = 2.

  • ls_zzz-awref_reb = '123654'.

  • ls_zzz-aworg_reb = '654654'.

  • ls_zzz-aubel = '0000001364'. "KDAUF

ls_zzz-kdauf = '0000001364'. "KDAUF

MOVE ls_zzz TO i_ext2-valuepart1.

APPEND i_ext2.

  • acc_document

*DATA: wa_extension TYPE bapiparex,

  • ext_value(960) TYPE c,

  • wa_accit TYPE accit,

  • l_ref TYPE REF TO data.

*

  • FIELD-SYMBOLS: <l_struc> TYPE ANY,

  • <l_field> TYPE ANY.

*

  • SORT i_ext2 BY structure.

*

  • LOOP AT i_ext2 INTO wa_extension.

    • AT NEW structure.

    • CREATE DATA l_ref TYPE (wa_extension-structure).

  • ASSIGN l_ref->* TO <l_struc>.

    • ENDAT.

  • CONCATENATE wa_extension-valuepart1 wa_extension-valuepart2

  • wa_extension-valuepart3 wa_extension-valuepart4

  • INTO ext_value.

  • MOVE ext_value TO <l_struc>.

  • ASSIGN COMPONENT 'POSNR' OF STRUCTURE <l_struc> TO <l_field>.

  • READ TABLE ls_zzz WITH KEY posnr = 2

  • INTO wa_accit.

  • IF sy-subrc IS INITIAL.

  • MOVE-CORRESPONDING <l_struc> TO wa_accit.

  • MODIFY ls_zzz FROM wa_accit INDEX sy-tabix.

  • ENDIF.

  • ENDLOOP.

*

  • CLEAR it_ext.

  • it_ext-field1

  • it_ext-field2

  • it_ext-field3

  • it_ext-field4

  • APPEND it_ext.

*DATA ZZZ_ACCIT LIKE ACCIT.

  • DATA: ls_zzz type ACCIT.

  • CLEAR i_ext2.

    • i_ext2-structure = ACCIT.

  • ls_zzz-posnr = 2.

    • ls_zzz-awref_reb = '123654'.

    • ls_zzz-aworg_reb = '654654'.

    • ls_zzz-aubel = '0000001364'. "KDAUF

  • ls_zzz-kdauf = '0000001364'. "KDAUF

  • MOVE ls_zzz TO i_ext2-valuepart1.

  • APPEND i_ext2.

*i_accountgl-itemno_acc = 2.

*i_accountgl-gl_account = '0000111010' .

*i_accountgl-item_text = 'Test'.

*APPEND i_accountgl.

*

*i_accountgl-itemno_acc = 3.

*i_accountgl-gl_account = '0000750070' .

*i_accountgl-item_text = 'Test'.

APPEND i_accountreceivable.

REFRESH i_currencyamount.

CLEAR i_currencyamount.

i_currencyamount-itemno_acc = 1.

i_currencyamount-currency = 'USD'.

i_currencyamount-amt_doccur = 100.

APPEND i_currencyamount.

CLEAR i_currencyamount.

i_currencyamount-itemno_acc = 2.

i_currencyamount-currency = 'USD'.

i_currencyamount-amt_doccur = 100 * -1 .

APPEND i_currencyamount.

*CLEAR i_currencyamount.

*i_currencyamount-itemno_acc = 3.

*i_currencyamount-currency = 'USD'.

*i_currencyamount-amt_doccur = 0.

*APPEND i_currencyamount.

*

*

REFRESH: return .

LOOP AT i_currencyamount.

IF i_currencyamount-amt_doccur > 0.

i_accountgl-acct_key = '40'.

ELSE.

i_accountgl-acct_key = '19'.

  • i_accountgl-sales_ord = '0000001364'.

i_currencyamount-amt_doccur = ABS( i_currencyamount-amt_doccur ).

ENDIF.

ENDLOOP.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'

EXPORTING

documentheader = wa_documentheader

  • CUSTOMERCPD =

  • CONTRACTHEADER =

TABLES

accountgl = i_accountgl

accountreceivable = i_accountreceivable

currencyamount = i_currencyamount

return = return

extension2 = i_ext2.

READ TABLE return WITH KEY type = 'E' TRANSPORTING NO FIELDS.

CHECK sy-subrc <> 0.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

documentheader = wa_documentheader

*IMPORTING

*obj_type = wa_documentheader-obj_type

*obj_key = wa_documentheader-obj_key

*obj_sys = wa_documentheader-obj_sys

TABLES

accountgl = i_accountgl

accountreceivable = i_accountreceivable

currencyamount = i_currencyamount

return = return

extension2 = i_ext2.

COMMIT WORK AND WAIT.

0 Kudos

Hello,

Unfortunately I don't have access to an SAP system right now, so I cannot check your sample program. But it seems ok to me.

So here's what you have to do according to documentation. I haven't actually done this myself for this particular BAPI, just for other accounting BAPIs, where the procedure is similar.

The general procedure is like this:

1) Supply the BAPI with the extension parameters. You have already done this and I think it is done correctly.

2) Using transaction <b>SE19</b> you have to create a BAdI implementation for the BAdI <b>ACC_DOCUMENT</b>.

3) In this extension you have to copy your extension fields from the extension structure to the accounting fields supplied in the BAdI interface parameters. Have a look at the sample implementation shown in <b>SE19</b> - this should give you an idea how it is done.

4) Activate the BAdI using transaction <b>SE19</b>. You can debug your coding e. g. by setting a breakpoint in the BAdI implementation coding.

Hope this helps - please reward me if it does.

Regards, Joerg

0 Kudos

Hi,

I did as you told, I took the values, but in BAPI giving me error as "Enter item number" Even though i give LINE ITEM NUMBER POSNR. Is anything i am missing?

0 Kudos

Hi!

Could you post the coding of your BAdI implementation, please?

Regards, Joerg

0 Kudos

DATA: wa_extension TYPE bapiparex ,

ext_value(960) TYPE c,

wa_accit TYPE accit,

l_ref TYPE REF TO data.

FIELD-SYMBOLS: <l_struc> TYPE ANY,

<l_field> TYPE ANY.

SORT c_extension2 BY structure.

LOOP AT c_extension2 INTO wa_extension.

AT NEW structure.

CREATE DATA l_ref TYPE (wa_extension-structure).

ASSIGN l_ref->* TO <l_struc>.

ENDAT.

CONCATENATE wa_extension-valuepart1 wa_extension-valuepart2

wa_extension-valuepart3 wa_extension-valuepart4

INTO ext_value.

MOVE ext_value TO <l_struc>.

  • ASSIGN COMPONENT 'POSNR' OF STRUCTURE <l_struc> TO

*<l_field>.

READ TABLE c_accit WITH KEY posnr = 2

INTO wa_accit.

IF sy-subrc IS INITIAL.

MOVE-CORRESPONDING <l_struc> TO wa_accit.

MODIFY c_accit FROM wa_accit INDEX sy-tabix.

ENDIF.

ENDLOOP.

this is BADI IMPLEMENTATION CODE...Will really appreciate your help.......

0 Kudos

I posted my BADI Code.

Thanks

0 Kudos

Hi Subha!

Now I have access to an SAP system

I have had a look at the way the extension is handled. If you look at the implementation of the BAdI you will find the following line:

create data l_ref type (wa_extension-structure).

This line requires that you supply the DDIC type you used to build up the extension parameters in the field <b>wa_extension-structure</b>. Since you use the structure ACCIT in you coding to supply the extension parameters:

DATA: ls_zzz type STANDARD TABLE OF ACCIT with header line.

My guess would be that you have to add a line before you append the extension line in your code which <i>calls</i> the BAPI like so (added line in <b>bold</b>):


...
DATA: ls_zzz type STANDARD TABLE OF ACCIT with header line.
CLEAR i_ext2.
* i_ext2-structure = ACCIT.
ls_zzz-posnr = 2.
* ls_zzz-awref_reb = '123654'.
* ls_zzz-aworg_reb = '654654'.
* ls_zzz-aubel = '0000001364'. "KDAUF
ls_zzz-kdauf = '0000001364'. "KDAUF
MOVE ls_zzz TO i_ext2-valuepart1.
<b>
*************************
* Please add this line: *
*************************
MOVE 'ACCIT' to i_ext2-structure.
*************************</b>
APPEND i_ext2.
...

I cannot test this coding atm, so please set a breakpint in your BAdI coding and have a look at what data you find there.

Hope this helps (please reward me if it does),

Joerg

0 Kudos

Hi,

That's Good you have access to SAP system....

I changed my code like below, created custom structure in se11 with two fields POSNR, KDAUF & gave that as extension parameter structure......

DATA: ls_zzz type yyy_ACCIT.

CLEAR i_ext2in.

  • MOVE 'ACCIT' to i_ext2in-structure.

<b>i_ext2in-structure = 'yyy_ACCIT'.</b>

ls_zzz-posnr = 2.

  • ls_zzz-KUNNR = '0000116153'.

  • ls_zzz-prctr = '0000002000'.

  • ls_zzz-UMSKZ = 'A'.

  • ls_zzz-awref_reb = '123654'.

  • ls_zzz-aworg_reb = '654654'.

  • ls_zzz-aubel = '0000001364'. "KDAUF

ls_zzz-kdauf = '0000001364'. "KDAUF

MOVE ls_zzz TO i_ext2in-valuepart1.

*MOVE 'yyy_ACCIT' to i_ext2in-structure.

APPEND i_ext2in.

But still getting error as <b>Enter item number</b> Don't know why i am getting this??????? Really appreciate your help & time in this........

0 Kudos

Hi,

You probaly have to type the structure name correctly and in uppercase since the sample coding from <b>SE19</b> dynamically creates an appropriate data field in its coding.

Have you put a breakpoint into the BAdI yet? I really think this would make the workings of this coding clear to you...

Otherwise, you can probably just type in your BAdI:


  DATA:
    ls_zzz TYPE yyy_accit,
    wa_extension type bapiarex,
    wa_accit TYPE accit.

  LOOP AT c_extension2 INTO wa_extension.
    ls_zzz = wa_extension-valuepart1.

    READ TABLE c_accit WITH KEY posnr = ls_zzz-posnr
          INTO wa_accit.

    IF sy-subrc IS INITIAL.
      wa_accit-kdauf = ls_zzz-kdauf.
      MODIFY c_accit FROM wa_accit INDEX sy-tabix.
    ENDIF.
  ENDLOOP.

This is probably a bit clearer than the (functionally equivalent) dynamic programming used by SAP in its sample implementation.

Regards, Joerg

0 Kudos

Yup I put a breakpoint & values are assinged as required, But when i check RETURN parameter in BAPI it's giving me "ENTER ITEM NUMBER" error? Still i couldn't findout why i am getting this ? Also I tried the code which you send in BADI implementation still give the same error..

Thanks a lot for your help.......

0 Kudos

Hi,

Thanks a lot for your Help. ENTER ITEM NUMBER means it's asked for ACCIT-KDPOS, when i give that value it's posted salesordernumber . I pasted code here.......

DATA:

ls_zzz TYPE YYY_ACCIT,

wa_extension type bapiparex,

wa_accit TYPE accit.

LOOP AT c_extension2 INTO wa_extension.

ls_zzz = wa_extension-valuepart1.

READ TABLE c_accit WITH KEY posnr = 2

  • "ls_zzz-posnr

INTO wa_accit.

IF sy-subrc IS INITIAL.

wa_accit-kdauf = ls_zzz-kdauf.

wa_accit-posnr = ls_zzz-itemno_acc.

wa_accit-kdpos = ls_zzz-posnr.

MODIFY c_accit FROM wa_accit INDEX sy-tabix.

ENDIF.

ENDLOOP.

message class v1 error 125. FM SD_ACCOUNT_DOCUMENT_ASSIGNMENT gives this error not passing of itemnumber........

0 Kudos

Hi!

Since this is an application error I guess you are using the extension properly.

Looking at the error code in transaction <b>SE91</b> and GoTo -> Longtext I see that the BAPI requires you to supply the order number (<b>KDAUF</b>) as well as the position number (<b>KDPOS</b>). I assume that you are either not supplying it correctly or you are using the wrong field.

In your coding you supply <b>wa_accit-kdpos</b> with the field <b>ls_zzz-posnr</b>. But the latter is - I think - the position number of the accounting document. This might have a different value than the customer order position. Also, it has a different data type, so probably you are just supplying the first few zeroes in this field. Looking at the data types I guess you <i>should</i> use the field <b>ls_zzz-kdpos</b>.

Maybe you should change the field <b>wa_accit-kdpos</b> in debug mode and try again. If this works, you should change your BAdI implementation as well as the calling routine. Supply field <b>KDPOS</b> instead of <b>POSNR</b>.

Hope this helps - please reward me if it does.

Regards, Joerg

0 Kudos

Yup thankyou for your help. I already rewarded points to you

0 Kudos

Thanks for your help it really worked out for me

0 Kudos

Hi Experts,

I am trying to update the Sales Order Number throguh BAPI BAPI_ACC_DOCUMENT_POST with out passing Sales order Line items thorgh Extension1 structure. So the BAPI is giving error as enter Line item.

But my requirement is to post the Document at Sales order level. So is it possible to Post the Document by just passing the Sales order number with out line items.