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: 

How can I do it for change FB01 to BAPI_ACC_DOCUMENT_POST or POSTING_INTERFACE_DOCUMENT, IN MY FUNCTION?

former_member185067
Participant
0 Kudos

Hi all,

Someone can me help me? I need change my fuction module this have a call transaction FB01 and I need change the TCODE for other method. I readed some forums and people say that I can use:

BAPI_ACC_DOCUMENT_POST or POSTING_INTERFACE_DOCUMENT instead transaction FB01.

My source code of my function module is the following:

FUNCTION Z_HSP_WF_DOCUMENT_POST.

*"----------------------------------------------------------------------

*"*"Interfase local

*"  IMPORTING

*"     VALUE(DATA1) LIKE  ZHSP_WF_ST_DOC_POST STRUCTURE

*"        ZHSP_WF_ST_DOC_POST

*"     VALUE(PAY_DATA) LIKE  ZHSP_WF_ST_PAYMENT_DATA STRUCTURE

*"        ZHSP_WF_ST_PAYMENT_DATA

*"     VALUE(CUSTOMERCPD) LIKE  ZHSP_WF_ST_CUSTOMERCPD STRUCTURE

*"        ZHSP_WF_ST_CUSTOMERCPD OPTIONAL

*"  EXPORTING

*"     VALUE(SUBRC) LIKE  SYST-SUBRC

*"  TABLES

*"      MESSTAB STRUCTURE  BDCMSGCOLL OPTIONAL

*"      MESSTABTEXT STRUCTURE  BAPIRET2 OPTIONAL

*"  EXCEPTIONS

*"      NO_POSTING

*"----------------------------------------------------------------------

************************************************************************

DATA: tp_mode LIKE apqi-putactive,

       tp_stras type stras_gp,

       tp_date_cont(8).

* Initialize variables and parameters

  subrc = 0.

  tp_mode = 'N'.

  subrc = 0.

  concatenate sy-datum+6(2) sy-datum+4(2) sy-datum(4) into tp_date_cont.

* Dynpros

perform bdc_dynpro      using 'SAPMF05A' '0100'.

perform bdc_field       using 'BDC_CURSOR'

                              'BKPF-BKTXT'.

perform bdc_field       using 'BDC_OKCODE'

                              '/00'.

perform bdc_field       using 'BKPF-BLDAT'

                              DATA1-BLDAT.

perform bdc_field       using 'BKPF-BLART'

                              DATA1-BLART.

perform bdc_field       using 'BKPF-BUKRS'

                              DATA1-BUKRS.

perform bdc_field       using 'BKPF-BUDAT'

                              tp_date_cont.

perform bdc_field       using 'BKPF-MONAT'

                              sy-datum+4(2).

perform bdc_field       using 'BKPF-WAERS'

                              PAY_DATA-CURRENCY.

perform bdc_field       using 'BKPF-XBLNR'

                              DATA1-XBLNR.

*perform bdc_field       using 'BKPF-BKTXT'

*                              'TEXTO CABECERA'.

perform bdc_field       using 'FS006-DOCID'

                              '*'.

perform bdc_field       using 'RF05A-NEWBS'

                              DATA1-NEWBS.

perform bdc_field       using 'RF05A-NEWKO'

                              DATA1-CUSTOMER.

IF NOT CUSTOMERCPD IS INITIAL.

   concatenate CUSTOMERCPD-STREET ', ' CUSTOMERCPD-HOUSE_NUM1

   into TP_STRAS.

    perform bdc_dynpro      using 'SAPLFCPD' '0100'.

    perform bdc_field       using 'BDC_CURSOR'

                                  'BSEC-STCD1'.

*    perform bdc_field       using 'BDC_OKCODE'    "DELCALA

*                                  '/00'.          "DELCALA

*    perform bdc_field       using 'BSEC-SPRAS'

*                                  'ES'.

    perform bdc_field       using 'BSEC-NAME1'

                                  CUSTOMERCPD-NAME1.

    perform bdc_field       using 'BSEC-NAME2'

                                  CUSTOMERCPD-NAME2.

    perform bdc_field       using 'BSEC-STRAS'

                                  tp_stras.

    perform bdc_field       using 'BSEC-PFACH'

                                  CUSTOMERCPD-PO_BOX.

    perform bdc_field       using 'BSEC-PSTL2'

                                  CUSTOMERCPD-POBX_PCD.

    perform bdc_field       using 'BSEC-ORT01'

                                  CUSTOMERCPD-CITY.

    perform bdc_field       using 'BSEC-PSTLZ'

                                  CUSTOMERCPD-POSTL_CODE.

    perform bdc_field       using 'BSEC-LAND1'

                                  CUSTOMERCPD-COUNTRY.

    perform bdc_field       using 'BSEC-BANKL'

                                  PAY_DATA-BANKL_02.

    perform bdc_field       using 'BSEC-BANKS'

                                  'ES'.

    perform bdc_field       using 'BSEC-BANKN'

                                  PAY_DATA-BANKN_02.

    perform bdc_field       using 'BSEC-BKONT'

                                  PAY_DATA-BKONT_02.

    perform bdc_field       using 'BSEC-STCD1'

                                  CUSTOMERCPD-STCD1.

    perform bdc_field       using 'BSEC-STKZU'

                                  'X'.

    if pay_data-iban is not initial.

      perform bdc_field       using 'BDC_OKCODE'

                                    '=IBAN'.

      perform bdc_dynpro      using 'SAPLIBMA' '0100'.

      perform bdc_field       using 'BDC_OKCODE'

                                    '=SWITCH'.

      perform bdc_dynpro      using 'SAPLIBMA' '0100'.

      perform bdc_field       using 'IBAN00'

                                    PAY_DATA-IBAN.

      perform bdc_field       using 'BDC_OKCODE'

                                    '=ENTR'.

      perform bdc_dynpro      using 'SAPLFCPD' '0100'.

      perform bdc_field       using 'BDC_CURSOR'

                                    'BSEC-STCD1'.

    endif.

    perform bdc_field       using 'BDC_OKCODE'

                                  '/00'.

ENDIF.

perform bdc_dynpro      using 'SAPMF05A' '0302'.

perform bdc_field       using 'BDC_CURSOR'

                              'RF05A-NEWKO'.

perform bdc_field       using 'BDC_OKCODE'

                              '=ZK'.

perform bdc_field       using 'BSEG-WRBTR'

                              PAY_DATA-WRBTR.

perform bdc_field       using 'BKPF-XMWST'

                              'X'.

if PAY_DATA-W_TAX_CODE <> ' '.

   perform bdc_field       using 'BSEG-QSSKZ'

                                 PAY_DATA-W_TAX_CODE.

endif.

if not customercpd is initial.

   perform bdc_field       using 'BSEG-ZUONR'

                                  CUSTOMERCPD-STCD1.

endif.

perform bdc_field       using 'BSEG-SGTXT'

                               DATA1-SGTXT.

*Nuevo campo crespj01 23.11.2011

if DATA1-ZTERM is not initial.

   perform bdc_field       using 'BSEG-ZTERM'

                                  DATA1-ZTERM.

endif.

if DATA1-ZFBDT is not initial.

   perform bdc_field       using 'BSEG-ZFBDT'

                                  DATA1-ZFBDT.

endif.

perform bdc_field       using 'BSEG-ZLSCH'

                              PAY_DATA-ZLSCH.

perform bdc_field       using 'RF05A-NEWBS'

                              '40'.

perform bdc_field       using 'RF05A-NEWKO'

                              PAY_DATA-GL_ACCOUNT.

perform bdc_dynpro      using 'SAPMF05A' '0332'.

perform bdc_field       using 'BDC_OKCODE'

                              '/00'.

perform bdc_field       using 'BSEG-HBKID'

                              PAY_DATA-HBKID.

if data1-newbs ne '34' and data1-newbs ne '24'.

  perform bdc_field       using 'BSEG-XREF1'

                                PAY_DATA-XREF1.

endif.

perform bdc_dynpro      using 'SAPMF05A' '0300'.

perform bdc_field       using 'BDC_CURSOR'

                              'BSEG-SGTXT'.

****************************************

*perform bdc_field       using 'BDC_OKCODE'

*                              '=BU'.

*DEL CALALJ01 26.02.2008 FIN    ****************************************

perform bdc_field       using 'BSEG-WRBTR'

                              '*'.

if  PAY_DATA-TAX_CODE <> space.

  perform bdc_field       using 'BSEG-MWSKZ'

                                PAY_DATA-TAX_CODE.

endif.

perform bdc_field       using 'BSEG-SGTXT'

                               DATA1-SGTXT.

*INC CALALJ01 26.02.2008 INICIO ****************************************

if data1-newbs eq '34' or data1-newbs eq '24'.

  perform bdc_field       using 'BDC_OKCODE'

                                '=ZK'.

ELSE.

  perform bdc_field       using 'BDC_OKCODE'

                                '=BU'.

endif.

   ****************************************

perform bdc_dynpro      using 'SAPLKACB' '0002'.

*DEL DOMINM05 08.03.2007 INICIO ****************************************

*perform bdc_field       using 'BDC_CURSOR'

*                              'COBL-KOSTL'.

*DEL DOMINM05 08.03.2007 INICIO ****************************************

perform bdc_field       using 'BDC_OKCODE'

                              '=ENTE'.

if not PAY_DATA-COSTCENTER is initial.

perform bdc_field       using 'COBL-KOSTL'

                              PAY_DATA-COSTCENTER.

endif.

if not PAY_DATA-AUFNR is initial.

perform bdc_field       using 'COBL-AUFNR'

                              PAY_DATA-AUFNR.

endif.

if not PAY_DATA-PS_POSID is initial.

    perform bdc_field       using 'COBL-PS_POSID'

                                  PAY_DATA-PS_POSID.

endif.

****************************************

if data1-newbs eq '34' or data1-newbs eq '24'.

  perform bdc_dynpro      using 'SAPMF05A' '0330'.

  perform bdc_field       using 'BSEG-XREF1'

                              PAY_DATA-XREF1.

  perform bdc_field       using 'BDC_OKCODE'

                                '=BU'.

endif.

****************************************

* RFC Call Transaction

PERFORM bdc_transaction TABLES messtab

                        USING 'FB01' tp_mode subrc 'DEST_H1'.

* Message Texts

  CHECK NOT messtab[] IS INITIAL.

  LOOP AT messtab.

    CLEAR messtabtext.

    CALL FUNCTION 'BAPI_MESSAGE_GETDETAIL' DESTINATION 'DEST_H1'

      EXPORTING

        id         = messtab-msgid

        number     = messtab-msgnr

        language   = 'S'

        textformat = 'RTF'

        message_v1 = messtab-msgv1

        message_v2 = messtab-msgv2

        message_v3 = messtab-msgv3

        message_v4 = messtab-msgv4

      IMPORTING

        message    = messtabtext-message.

    messtabtext-id         = messtab-msgid.

*INS DOMINM05 25.01.2007 INICIO ******************************

    messtabtext-type       = messtab-msgtyp.

*INS DOMINM05 25.01.2007 FIN    ******************************

    messtabtext-number     = messtab-msgnr.

    messtabtext-message_v1 = messtab-msgv1.

    messtabtext-message_v2 = messtab-msgv2.

    messtabtext-message_v3 = messtab-msgv3.

    messtabtext-message_v4 = messtab-msgv4.

    APPEND messtabtext.

  ENDLOOP.

*  if subrc <> 0.

*     raise no_posting.

*  endif.

5 REPLIES 5

Former Member
0 Kudos

Hi,

if you want to use BAPI you mentioned you need to fill all the BAPI's structures and pass them to FM. I'm sorry but I think you can't just change from BDC to BAPI. BAPI structures have good descriptions so I suggest you to go there and check. You don't need to know the screens and so on as you need for Transaction Call. BAPI also determine by itself a lot od data you need to pass manually in t-code.

You need to pass for sure this structures:

DOCUMENTHEADER

ACCOUNTGL

ACCOUNTPAYABLE - I think you posting AP doc. from your current FM

CURRENCYAMOUNT

RETURN


You can make a few runs and check what you have in RETURN. It's really usefull becasue it's usually gives idea what you need to correct or pass.

0 Kudos

Hi Michal,

Thank you for your quicky answer, but I don't understand some things:

How can I fill the BAPI'S structures?

Why can't use BDC to BAPI?

You don't need to know the screens and so on as you need for Transaction Call? Sorry what do you refer?

Thank you very again Michal,

Regards, Carlos Castillo

0 Kudos

For FB01 screen was change dynamically based on posting key (different for vendor,customer,etc).

So use BAPI_ACC_DOCUMENT_POST fm and it can take care of dynamic screen changes and structures like BBSEG,BBKPF.

0 Kudos

Hi Carlos,

See SAP Note 306504 - Collective note: BAPIs for the AC interface and related notes. With this note you will find enough keywords for a further research.

Why is better BAPI than BDC? Because, for instance, if your FI consultant changes the field status group your BDC will begin to fail and you will need to waste a lot of effort to identify the bug, while with BAPI, in BAPIRET2 you will have the error message. After any upgrade, you can find a lot of errors, depends of sequence of screens.

I hope this helps you

Regards

Eduardo

0 Kudos

Hola Eduardo,

I must read the note 306504 and let you know. But I don't understand how affected the BDC in my FM.

I only need adapter the BAPI_ACC_DOCUMENT_POST or BAPID_ACC_DOCUMENT_POST2 or  FM instead the call transaction FB01.

I would be of great help the main steps for do it:

Thank you very,

Carlos