Posted: Thu Feb 10, 2011 6:11 pm Post subject: Financial Posting Interface (FIPI)
Author: Javier Meavilla Olivas
Code:
*=======================================================================
CONSTANTS:
*=======================================================================
c_typehead TYPE stype_pi VALUE 'K',
c_typepos TYPE stype_pi VALUE 'P',
c_waers TYPE waers VALUE 'EUR',
c_blart TYPE blart VALUE 'ZN',
c_debit TYPE bschl VALUE '40',
c_credit TYPE bschl VALUE '50',
c_inddebit TYPE shkzg VALUE 'S',
c_indcredit TYPE shkzg VALUE 'H'.
*===================================================================
FORM append_ftpost
*===================================================================
USING p_stype TYPE stype_pi
p_count TYPE count_pi
p_fnam TYPE bdc_fnam
p_fval TYPE any
CHANGING pt_ftpost TYPE tt_ftpost.
*===================================================================
FORM post_document
*===================================================================
USING p_bukrs TYPE bukrs
p_gjahr TYPE gjahr
p_monat TYPE monat
p_tip TYPE zga_nomtipcont
p_saknr TYPE saknr
p_bktxt TYPE bktxt
pt_pos TYPE tt_pos.
DATA: lt_blntab TYPE tt_blntab,
lt_ftpost TYPE tt_ftpost,
lt_fttax TYPE tt_fttax,
ls_blntab LIKE LINE OF lt_blntab.
IF sy-subrc IS NOT INITIAL.
MESSAGE i021(zga_nom).
ELSE.
* Grabación en tabla de log y mensaje
READ TABLE lt_blntab INTO ls_blntab INDEX 1.
IF sy-subrc IS INITIAL AND
ls_blntab-belnr IS NOT INITIAL.
PERFORM insert_log USING p_bukrs
p_gjahr
p_monat
p_tip
ls_blntab-belnr.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
CALL FUNCTION 'POSTING_INTERFACE_END'
EXCEPTIONS
session_not_processable = 1
OTHERS = 2.
*===================================================================
FORM insert_log
*===================================================================
USING p_bukrs TYPE bukrs
p_gjahr TYPE gjahr
p_monat TYPE monat
p_tip TYPE zga_nomtipcont
p_belnr TYPE belnr_d.
DATA: lv_belnr TYPE belnr_d,
ls_log TYPE zga_nomlog.
SELECT SINGLE belnr INTO lv_belnr
FROM zga_nomlog
WHERE bukrs = p_bukrs AND
gjahr = p_gjahr AND
monat = p_monat AND
tipcont = p_tip.
IF sy-subrc IS INITIAL.
UPDATE zga_nomlog FROM ls_log.
ELSE.
INSERT zga_nomlog FROM ls_log.
ENDIF.
ENDFORM. "insert_log
*===================================================================
FORM get_posting_date
*===================================================================
USING p_gjahr TYPE gjahr
p_monat TYPE monat
CHANGING p_date TYPE dats.
*======================================================================
FORM fill_bkpf
*======================================================================
USING p_bukrs TYPE bukrs
p_gjahr TYPE gjahr
p_monat TYPE monat
p_bktxt TYPE bktxt
CHANGING pt_ftpost TYPE tt_ftpost.
DATA: lv_posting_date TYPE dats,
lv_dats TYPE char10.
PERFORM get_posting_date USING p_gjahr p_monat
CHANGING lv_posting_date.
WRITE lv_posting_date TO lv_dats.
PERFORM append_ftpost USING c_typehead '1'
'BKPF-BUKRS' p_bukrs
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typehead '1'
'BKPF-MONAT' p_monat
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typehead '1'
'BKPF-BLART' c_blart
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typehead '1'
'BKPF-BUDAT' lv_dats
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typehead '1'
'BKPF-BLDAT' lv_dats
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typehead '1'
'BKPF-WAERS' c_waers
CHANGING pt_ftpost.
*PERFORM append_ftpost USING c_typehead '1'*
*'BKPF-XMWST' 'X'*
*CHANGING pt_ftpost.*
PERFORM append_ftpost USING c_typehead '1'
'BKPF-BKTXT' p_bktxt
CHANGING pt_ftpost.
*===================================================================
FORM fill_bseg
*===================================================================
USING p_saknr TYPE saknr
p_bktxt TYPE bktxt
CHANGING pt_pos TYPE tt_pos
pt_ftpost TYPE tt_ftpost.
DATA: ls_pos LIKE LINE OF pt_pos,
ls_ftpost LIKE LINE OF pt_ftpost,
lv_item TYPE buzei,
lv_wrbtr TYPE wrbtr,
lv_saknr TYPE saknr,
lv_bschl TYPE bschl,
lt_poscont TYPE TABLE OF zga_nompospost,
ls_poscont LIKE LINE OF lt_poscont,
ls_poscontaux LIKE LINE OF lt_poscont.
CLEAR: ls_pos, ls_ftpost.
REFRESH lt_poscont.
LOOP AT pt_pos INTO ls_pos.
MOVE-CORRESPONDING ls_pos TO ls_poscont.
APPEND ls_poscont TO lt_poscont.
ENDLOOP.
SORT lt_poscont BY saknr.
lv_item = '002'.
LOOP AT lt_poscont INTO ls_poscontaux.
ls_poscont = ls_poscontaux.
AT NEW saknr.
CLEAR: lv_wrbtr,
lv_saknr,
lv_bschl.
ENDAT.
CASE ls_poscont-shkzg.
WHEN c_inddebit.
lv_bschl = c_debit.
WHEN c_indcredit.
lv_bschl = c_credit.
ENDCASE.
IF ls_poscont-saknr IS INITIAL.
lv_saknr = p_saknr.
ELSE.
lv_saknr = ls_poscont-saknr.
ENDIF.
*===================================================================
FORM fill_bsegpos
*===================================================================
USING p_bschl TYPE bschl
p_saknr TYPE saknr
p_wrbtr TYPE wrbtr
p_bktxt TYPE bktxt
p_kostl TYPE kostl
p_prctr TYPE prctr
p_pos TYPE buzei
CHANGING pt_ftpost TYPE tt_ftpost.
DATA: lv_wrbtrstr TYPE char16.
WRITE p_wrbtr TO lv_wrbtrstr
CURRENCY c_waers NO-SIGN.
PERFORM append_ftpost USING c_typepos p_pos
'BSEG-BSCHL' p_bschl
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typepos p_pos
'BSEG-HKONT' p_saknr
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typepos p_pos
'BSEG-WRBTR' lv_wrbtrstr
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typepos p_pos
'BSEG-SGTXT' p_bktxt
CHANGING pt_ftpost.
IF p_kostl IS NOT INITIAL.
PERFORM append_ftpost USING c_typepos p_pos
'COBL-KOSTL' p_kostl
CHANGING pt_ftpost.
ENDIF.
IF p_prctr IS NOT INITIAL.
PERFORM append_ftpost USING c_typepos p_pos
'COBL-PRCTR' p_prctr
CHANGING pt_ftpost.
ENDIF.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.