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: 

Automating FB50 in BADI of MIGO

YayatiEkbote
Contributor
0 Kudos

Hello experts,

I have a scenario in which i need to automate FB50 in BADI of MIGO. The BADI i found is

MB_CHECK_LINE_BADI in which there is only one method. In this BADI i get the data from I_MKPF and I_MSEG. And i have selected BAPI- BAPI_ACC_DOCUMENT_POST.

My question is the debit credit indicator has field name SHKZG on FB50 screen. But in the BAPI i don't have that field. Rest all fields are matching.

Also in MIGO i am unable to understand from where do the G/L account information come into tables MSEG and MKPF.

Am i missing anything?

11 REPLIES 11

Former Member
0 Kudos

hi

I think field DE_CRE_IND in the structure ACCOUNTGL of Table parameter of BAPI_ACC_DOCUMENT_POST should be helpfull.

Thanks,

Ravi

eduardo_hinojosa
Active Contributor
0 Kudos

Hi,

It is solved by the BAPI. If I am right, it is solved in the subroutine PROCESS_ACCCR in include LACC4F20 (for instance fo BAPI_ACC_BILLING_POST) in function of values of FI account and sign of amount.

Other suggestion. If you don't know it, see SAP Note 306504 - Collective note: BAPIs for the AC interface.

I hope this helps you

Regards

Eduardo

0 Kudos

Thanks to all. I solved the problem by adding the select query to retireve g/l account information from another table. And the BAPI which i have mentioned above is working fine for my requirement in the BADI i have chosen. The BADI triggers at the time of posting MIGO. Thanks all.

0 Kudos

I am sorry i posted this thread as 'answered' but there is error in using BAPI_ACC_DOCUMENT_POST for FB50.

The RETURN table is giving the following info-

Return-type = E, Return-Number = 609

I have done the follwing code in MIGO's BADI-MB_CHECK_LINE_BADI, method - CHECK_LINE.

DATA: HEADERDATA TYPE BAPIACHE09,

ACCOUNTGL TYPE TABLE OF BAPIACGL09 INITIAL SIZE 0,

WA_ACCOUNTGL TYPE BAPIACGL09,

CURRENCYAMOUNT TYPE TABLE OF BAPIACCR09 INITIAL SIZE 0,

FINAL_CURRENCYAMOUNT TYPE TABLE OF BAPIACCR09 INITIAL SIZE 0,

WA_CURRENCYAMOUNT TYPE BAPIACCR09,

RETURN TYPE TABLE OF BAPIRET2 INITIAL SIZE 0,

WA_RETURN TYPE BAPIRET2.

TYPES: BEGIN OF PURCH_ORD_DATA_I,

EBELN TYPE EKPO-EBELN,

EBELP TYPE EKPO-EBELP,

MATNR TYPE EKPO-MATNR,

MTART TYPE EKPO-MTART,

NETPR TYPE EKPO-NETPR,

END OF PURCH_ORD_DATA_I.

DATA: T_PURCH_ORD_DATA_I TYPE STANDARD TABLE OF PURCH_ORD_DATA_I,

WA_PURCH_ORD_DATA_I TYPE PURCH_ORD_DATA_I.

TYPES:BEGIN OF PURCH_ORD_DATA_H,

EBELN TYPE EKKO-EBELN,

WAERS TYPE EKKO-WAERS,

WKURS TYPE EKKO-WKURS,

END OF PURCH_ORD_DATA_H.

DATA: T_PURCH_ORD_DATA_H TYPE STANDARD TABLE OF PURCH_ORD_DATA_H,

WA_PURCH_ORD_DATA_H TYPE PURCH_ORD_DATA_H.

DATA: FINAL_AMT TYPE BAPIWRBTR,

TXT1 TYPE BKTXT,

TXT2 TYPE BKTXT.

IF SY-UCOMM = 'OK_POST1' OR SY-UCOMM = 'OK_POST'.

IF SY-TCODE = 'MIGO'.

SELECT * FROM EKKO INTO CORRESPONDING FIELDS OF TABLE T_PURCH_ORD_DATA_H

WHERE EBELN = IS_MSEG-EBELN.

SELECT * FROM EKPO INTO CORRESPONDING FIELDS OF TABLE T_PURCH_ORD_DATA_I

FOR ALL ENTRIES IN T_PURCH_ORD_DATA_H

WHERE EBELN = T_PURCH_ORD_DATA_H-EBELN

AND MTART = 'HAWA'.

IF SY-SUBRC = 0.

HEADERDATA-DOC_DATE = IS_MKPF-BLDAT.

HEADERDATA-PSTNG_DATE = IS_MKPF-BUDAT.

TXT = 'FB50 FOR PO'.

CONCATENATE TXT '-' IS_MSEG-EBELN INTO TXT2.

HEADERDATA-HEADER_TXT = TXT2.

WA_ACCOUNTGL-GL_ACCOUNT = '0053010100'.

WA_ACCOUNTGL-DE_CRE_IND = 'S'.

WA_ACCOUNTGL-COSTCENTER = '2027468093'.

APPEND WA_ACCOUNTGL TO ACCOUNTGL.

WA_ACCOUNTGL-GL_ACCOUNT = '0050220000'.

WA_ACCOUNTGL-DE_CRE_IND = 'H'.

WA_ACCOUNTGL-COSTCENTER = '2027468093'.

APPEND WA_ACCOUNTGL TO ACCOUNTGL.

LOOP AT T_PURCH_ORD_DATA_I INTO WA_PURCH_ORD_DATA_I.

FINAL_AMT = FINAL_AMT + ( IS_MSEG-MENGE * WA_PURCH_ORD_DATA_I-NETPR ).

ENDLOOP.

READ TABLE T_PURCH_ORD_DATA_H INTO WA_PURCH_ORD_DATA_H WITH KEY EBELN = IS_MSEG-EBELN.

IF SY-SUBRC = 0 AND WA_PURCH_ORD_DATA_H-WAERS NE 'INR'.

FINAL_AMT = FINAL_AMT * WA_PURCH_ORD_DATA_H-WKURS.

ENDIF.

WA_CURRENCYAMOUNT-AMT_DOCCUR = FINAL_AMT.

WA_CURRENCYAMOUNT-CURRENCY = 'INR'.

APPEND WA_CURRENCYAMOUNT TO CURRENCYAMOUNT.

CLEAR: WA_CURRENCYAMOUNT, FINAL_AMT.

ENDIF.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

documentheader = HEADERDATA

tables

ACCOUNTGL = ACCOUNTGL[]

currencyamount = CURRENCYAMOUNT[]

return = RETURN[]

.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT .

LOOP AT RETURN INTO WA_RETURN.

WRITE:/ WA_RETURN-TYPE, WA_RETURN-ID, WA_RETURN-NUMBER, WA_RETURN-MESSAGE.

ENDLOOP.

ENDIF.

Am i using correct BAPI for automating FB50 while posting MIGO?

In FB50 screen. There is mandatory field Currency in which 'INR' is to be entered.

But in the BAPI DOCUMENTHEADER there is no field for currency.

Is that the problem?

If it is which BAPI should be used? or what is the solution?

YayatiEkbote
Contributor
0 Kudos

I marked this post as answered but faced problem after posting this.

0 Kudos

Hi,

What value do you set for OBJ_TYPE?

See Note 938165 - Incorrect document number for OBJ_TYPE= 'BKPFF' for further information.

I hope this helps you

Regards

Eduardo

0 Kudos

I am not setting any value for OBJ_TYPE.

The values for Return structure are:

Return-type = E

Return-ID = RW

Return-Number = 609

Return-Message = Error in document: BKPFF $ 100CLNT

I read the documentation of BAPI_ACC_DOCUMENT_POST. But i don't know what values should be passed to the export parameters. I am unable to understand how can we set values to export parameters. Pardon me i am asking wrong and basic questions.

Can you please elaborate your answer?

0 Kudos

Hi Yayati,

Declare a parameter like below and pass it to importing parameter " obj_key "of BAPI.

This will give you some values in output, which can be used further.

DATA: l_objkey TYPE bapiache09-obj_key.

I hope that helps.

Cheers.

0 Kudos

Thanks Ravi. I solved the problem using BDC in background mode inside the BADI because the work had to be finished fast. But the question is still open. Plz can you tell me how those objects OBJ_KEY work?

0 Kudos

Hi

See SAP Note 306504 - Collective note: BAPIs for the AC interface for further information related with this kind of fields, as 'Use of OBJ_TYPE (reference transaction)' and 'Source document or reference to sender document'.

Regards

Eduardo

YayatiEkbote
Contributor
0 Kudos

Thanks, problem solved.