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 to change a current BDC that trigger FB60 from park account to post account?

siongchao_ng
Contributor
0 Kudos

Hi all,

Below is the BDC code that is currently parking document.

How to change the code to enable it to post instead of park?

DATA : cnt(2)  TYPE n,
cnt1 TYPE i,
fld(25) TYPE c.
DATA : opt TYPE ctu_params . "#EC NEEDED
DATA: i_monat TYPE bapi0002_4-fiscal_period. "monat.
DATA: i_bktxt TYPE bktxt, i_budat TYPE budat.
DATA: lw_podate TYPE bapi0002_4-posting_date.
DATA: lc_mode TYPE c LENGTH 1.
DATA: lv_year TYPE bkpf-gjahr.
DATA: lv_bukrs TYPE bkpf-bukrs.



CLEAR gwa_inv_up.
LOOP AT gt_inv_up INTO gwa_inv_up WHERE indic = 'H'.



REFRESH : gt_bdcdata,gt_bdc_messages.
CLEAR :gt_bdcdata,gt_bdc_messages, gwa_bdc_messages,
i_monat, i_bktxt, i_budat.

********** FOR T-CODE FB60

PERFORM bdc_dynpro USING 'SAPLACHD' '1000'.
PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.
PERFORM bdc_field USING 'BKPF-BUKRS' gwa_inv_up-bukrs.


CONCATENATE gwa_inv_up-budat+6(2) gwa_inv_up-budat+4(2)
gwa_inv_up-budat+(4) INTO i_budat.

lw_podate = gwa_inv_up-budat.

CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
companycodeid = gwa_inv_up-bukrs
posting_date = lw_podate
IMPORTING
* FISCAL_YEAR =
fiscal_period = i_monat.
* RETURN =

PERFORM bdc_dynpro USING 'SAPMF05A' '1100'.
PERFORM bdc_field USING 'BDC_OKCODE' '=MORE'.
* To change the transaction to Credit memo.
IF gwa_inv_up-blart = 'KC'.
PERFORM bdc_field USING 'RF05A-BUSCS' 'G'."Credit memo
ELSE.
PERFORM bdc_field USING 'RF05A-BUSCS' 'R'. "Invoice
ENDIF.

PERFORM bdc_field USING 'INVFO-ACCNT' gwa_inv_up-lifnr.
PERFORM bdc_field USING 'INVFO-BLDAT' gwa_inv_up-bldat.
PERFORM bdc_field USING 'INVFO-XBLNR' gwa_inv_up-xblnr.
PERFORM bdc_field USING 'INVFO-BUDAT' i_budat.
"gwa_inv_up-budat.
PERFORM bdc_field USING 'INVFO-MONAT' i_monat. "'9'.
PERFORM bdc_field USING 'INVFO-BLART' gwa_inv_up-blart.
PERFORM bdc_field USING 'INVFO-WRBTR' gwa_inv_up-dmbtr.
PERFORM bdc_field USING 'INVFO-WAERS' gwa_inv_up-waers.
PERFORM bdc_field USING 'INVFO-XMWST' gwa_inv_up-xmwst.
PERFORM bdc_field USING 'INVFO-MWSKZ' gwa_inv_up-mwskz.
"'P0'.
PERFORM bdc_field USING 'INVFO-SGTXT' gwa_inv_up-sgtxt.

PERFORM bdc_dynpro USING 'SAPMF05A' '1100'.
PERFORM bdc_field USING 'BDC_OKCODE' '=PAYM'.
* PERFORM bdc_field USING 'BDC_CURSOR' 'INVFO-GSBER'.
* PERFORM bdc_field USING 'BDC_OKCODE' '=BS'.
CONCATENATE 'IGRANT' gwa_inv_up-bktxt INTO i_bktxt.
PERFORM bdc_field USING 'INVFO-BKTXT' i_bktxt. "Add

PERFORM bdc_field USING 'INVFO-GSBER' gwa_inv_up-gsber.
PERFORM bdc_dynpro USING 'SAPMF05A' '1100'.
PERFORM bdc_field USING 'INVFO-ZLSCH' gwa_inv_up-zlsch.
PERFORM bdc_field USING 'BDC_OKCODE' '/00'.

* PERFORM bdc_dynpro USING 'SAPMF05A' '1100'.
* PERFORM bdc_field USING 'BDC_OKCODE' '=BS'.
* PERFORM bdc_field USING 'INVFO-ZLSCH' gwa_inv_up-zlsch.

cnt = 1.
cnt1 = 1.
CLEAR gwa_inv_line.
LOOP AT gt_inv_up INTO gwa_inv_line
WHERE indic = 'D'
AND count = gwa_inv_up-count.


CONCATENATE 'ACGL_ITEM-MARKSP(' cnt ')' INTO fld.
PERFORM bdc_field USING fld 'X'.
PERFORM bdc_dynpro USING 'SAPMF05A' '1100'.
PERFORM bdc_field USING 'BDC_OKCODE' '=0005'.


CONCATENATE 'ACGL_ITEM-HKONT(' cnt ')' INTO fld.
PERFORM bdc_field USING fld gwa_inv_line-lifnr.
CONCATENATE 'ACGL_ITEM-SHKZG(' cnt ')' INTO fld.
PERFORM bdc_field USING fld gwa_inv_line-shkzg.
CONCATENATE 'ACGL_ITEM-WRBTR(' cnt ')' INTO fld.
PERFORM bdc_field USING fld gwa_inv_line-dmbtr.
CONCATENATE 'ACGL_ITEM-MWSKZ(' cnt ')' INTO fld.
PERFORM bdc_field USING fld gwa_inv_line-mwskz.
CONCATENATE 'ACGL_ITEM-SGTXT(' cnt ')' INTO fld.
PERFORM bdc_field USING fld gwa_inv_line-sgtxt.
CONCATENATE 'ACGL_ITEM-GSBER(' cnt ')' INTO fld.
PERFORM bdc_field USING fld gwa_inv_line-gsber.
CONCATENATE 'ACGL_ITEM-KOSTL(' cnt ')' INTO fld.
PERFORM bdc_field USING fld gwa_inv_line-kostl.
CONCATENATE 'ACGL_ITEM-PROJK(' cnt ')' INTO fld.
PERFORM bdc_field USING fld gwa_inv_line-posid.
CONCATENATE 'ACGL_ITEM-FISTL(' cnt ')' INTO fld.
PERFORM bdc_field USING fld gwa_inv_line-fistl.
CONCATENATE 'ACGL_ITEM-FIPOS(' cnt ')' INTO fld.
PERFORM bdc_field USING fld gwa_inv_line-fipos.
CONCATENATE 'ACGL_ITEM-GEBER(' cnt ')' INTO fld.
PERFORM bdc_field USING fld gwa_inv_line-geber.
PERFORM bdc_field USING 'BDC_CURSOR' fld.


ENDLOOP.

PERFORM bdc_dynpro USING 'SAPMF05A' '1100'.
PERFORM bdc_field USING 'BDC_OKCODE' '=BP'.

PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'.
PERFORM bdc_field USING 'BDC_OKCODE' '=BU'.
*&---------------------------------------------------------------------*
*& calling transaction fb60
*&---------------------------------------------------------------------*
lc_mode = 'N'.
CALL TRANSACTION 'FB60' USING gt_bdcdata
MODE lc_mode "'N' "A.N
UPDATE 'S'
MESSAGES INTO gt_bdc_messages.

IF NOT gt_bdc_messages IS INITIAL.

LOOP AT gt_bdc_messages INTO gwa_bdc_messages.
CLEAR gv_messg.

CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = gwa_bdc_messages-msgid
lang = gwa_bdc_messages-msgspra
no = gwa_bdc_messages-msgnr
v1 = gwa_bdc_messages-msgv1
v2 = gwa_bdc_messages-msgv2
v3 = gwa_bdc_messages-msgv3
v4 = gwa_bdc_messages-msgv4
IMPORTING
msg = gv_messg.

IF ( gwa_bdc_messages-msgtyp = 'S' ) OR
( gwa_bdc_messages-msgtyp = 'E' ).

CLEAR gwa_errorlog .
gwa_errorlog-bktxt = gwa_inv_up-bktxt .
gwa_errorlog-budat = gwa_inv_up-budat .

IF gwa_bdc_messages-msgtyp EQ 'S' AND
gwa_bdc_messages-msgnr EQ '001'.

gwa_errorlog-xblnr = gv_messg+9(11) .
gwa_errorlog-msgty = gc_msgty_s.
gwa_errorlog-status = 'S'.

gwa_errorlog-message = gv_messg .
APPEND gwa_errorlog TO gt_errorlog .
CLEAR gwa_errorlog.

ELSEIF gwa_bdc_messages-msgtyp EQ 'E'.

gwa_errorlog-xblnr = gwa_inv_up-xblnr .
gwa_errorlog-msgty = gc_msgty_e.
gwa_errorlog-status = 'E'.

gwa_errorlog-message = gv_messg .
APPEND gwa_errorlog TO gt_errorlog .
CLEAR gwa_errorlog.
ENDIF.

ENDIF.
CLEAR gwa_bdc_messages.
ENDLOOP.

ENDIF.


ENDLOOP.



IF NOT gt_inv_up[] IS INITIAL.
CLEAR :lv_year, lv_bukrs,gv_uname.

COMMIT WORK AND WAIT.
gv_uname = 'BATCH'.
lv_bukrs = 'HQ'.


* CALL FUNCTION 'FKK_FM_GET_FISCAL_YEAR'
* EXPORTING
* i_bukrs = lv_bukrs
* i_budat = sy-datum
* IMPORTING
* e_gjahr = lv_year.

CALL FUNCTION 'GET_CURRENT_YEAR'
EXPORTING
bukrs = lv_bukrs
date = sy-datum
IMPORTING
curry = lv_year.


REFRESH gt_bkpf.
SELECT bukrs belnr gjahr cputm bktxt FROM bkpf INTO TABLE gt_bkpf
WHERE bukrs EQ lv_bukrs
AND gjahr EQ lv_year
* AND budat EQ sy-datum
AND cpudt EQ sy-datum
AND usnam EQ gv_uname
AND bktxt LIKE 'IGRANT%'.

SORT gt_bkpf BY bukrs belnr gjahr cputm bktxt.
ENDIF.
DELETE ADJACENT DUPLICATES FROM gt_errorlog COMPARING ALL FIELDS.

CLEAR gwa_inv_up.
LOOP AT gt_inv_up INTO gwa_inv_up WHERE indic = 'H'.

CLEAR gwa_errorlog.
READ TABLE gt_errorlog INTO gwa_errorlog WITH KEY
bktxt = gwa_inv_up-bktxt.
IF sy-subrc EQ 0. " gwa_errorlog IS INITIAL.
ELSE.
CLEAR gw_bkpf.
IF NOT gt_bkpf[] IS INITIAL.
CLEAR i_bktxt.
CONCATENATE 'IGRANT' gwa_inv_up-bktxt INTO i_bktxt.
CLEAR gw_bkpf.
READ TABLE gt_bkpf INTO gw_bkpf WITH KEY bukrs = lv_bukrs
bktxt = i_bktxt.
ENDIF.
IF NOT gw_bkpf IS INITIAL.
CLEAR gwa_errorlog .
gwa_errorlog-bktxt = gwa_inv_up-bktxt .
gwa_errorlog-budat = gwa_inv_up-budat .
gwa_errorlog-xblnr = gw_bkpf-belnr .
gwa_errorlog-msgty = gc_msgty_s.
gwa_errorlog-status = 'S'.
CONCATENATE 'Document' gw_bkpf-belnr 'HQ was parked' INTO
gwa_errorlog-message SEPARATED BY space.
APPEND gwa_errorlog TO gt_errorlog .
CLEAR gwa_errorlog.
ELSE.
gwa_errorlog-bktxt = gwa_inv_up-bktxt .
gwa_errorlog-budat = gwa_inv_up-budat .
gwa_errorlog-xblnr = gwa_inv_up-xblnr .
gwa_errorlog-msgty = gc_msgty_e.
gwa_errorlog-status = 'E'.
gwa_errorlog-message = 'Error while Park the document'.
APPEND gwa_errorlog TO gt_errorlog .
CLEAR gwa_errorlog.

CLEAR gwa_inv_up.
ENDIF.
ENDIF.
ENDLOOP.
1 ACCEPTED SOLUTION

Jeansy
Active Contributor
0 Kudos

Hi,

the following coding lines are responsible for the parking of the document:

    PERFORM bdc_dynpro      USING 'SAPMF05A' '1100'.
PERFORM bdc_field USING 'BDC_OKCODE' '=BP'.

I verified this in the GUI-status of FB60, see below:

  • User Command BP: Park Document
  • User-Command BU: Post Document

So I would suggest to deactivate the coding lines mentioned below that are responsible for the parking of the document.

I hope this helps you.

Kind regards
Jens

2 REPLIES 2

siongchao_ng
Contributor
0 Kudos

Hi all,

which part of the BDC is clicking the park button? which bdc_okcode? unable to identify it. I want the bdc_okcode for post button click instead.

Jeansy
Active Contributor
0 Kudos

Hi,

the following coding lines are responsible for the parking of the document:

    PERFORM bdc_dynpro      USING 'SAPMF05A' '1100'.
PERFORM bdc_field USING 'BDC_OKCODE' '=BP'.

I verified this in the GUI-status of FB60, see below:

  • User Command BP: Park Document
  • User-Command BU: Post Document

So I would suggest to deactivate the coding lines mentioned below that are responsible for the parking of the document.

I hope this helps you.

Kind regards
Jens