bapi for fb01
TRANSCRIPT
-
8/20/2019 Bapi for Fb01
1/9
INTRODUCTION:
The accounting documents record changes in values in a company code arising from accounting
transactions. They consist of one or more line items (postings), each of which represents an individual
transaction posted to an account. When posting an accounting document, the SAP system updates
the transaction figures in the accounts to which the document is posted.An accounting document is a
representation within the SAP System of the document (for example, an invoice) that triggered the
posting.
AP! "AP!#A$$#%&$'*T#P&ST+ acts as the interface etween your code and standard
transactions -/0-1.
This document explains the various steps involved to post a -! document using AP!
"AP!#A$$#%&$'*T#P&ST+ from an excel file.This is helpful to SAP Technical consultants as it
gives the details of all the re2uired parameters and data in document posting and validation to chec3 if
the 45 account in which we are posting amounts is present in SAP dataase. Transaction code for -!documents are -/0-1($reate), -6($hange) and -7(%isplay). !n one document, more than
888 line item cannot e posted ecause AP! can post up to 888 lines in one document. The file
should e alanced for the document to e posted i.e. credit amount and deit amount should e
e2ual. !n -!, header tale for document data is 9P- and line item tale is S4.
STEPS:
:arious steps involved in posting a document from a file are;
/. 'pload data from excel file into an internal tale using - "4'!#'P5&A%+ as explained in
suroutine 'P5&A%#-&
-
8/20/2019 Bapi for Fb01
2/9
-
8/20/2019 Bapi for Fb01
3/9
%ilena/e = l+_%ilena/e%iletype = >AS2> TAB4ESdata_tab = t_pload E2EPTIONS%ile_open_error = 0
%ile_read_error = 5no_batc- = ?,i_re%se_%iletrans%er = @inalid_type = 'no_at-ority = n$no+n_error = Cbad_data_%or/at = -eader_not_allo+ed = .separator_not_allo+ed = 0(-eader_too_lon, = 00n$no+n_dp_error = 05access_denied = 0?dp_ot_o%_/e/ory = 0@
dis$_%ll = 0'dp_ti/eot = 0 OT
-
8/20/2019 Bapi for Fb01
4/9
#
-
8/20/2019 Bapi for Fb01
5/9
+_postin,s7prodct_-ie+_postin,s7/eins+_postin,s7Hantity+_postin,s7as,/+_postin,s7as,c+_postin,s7billin,_type
l_csto/er l_cst_-ie5+_postin,s7order_reason+_postin,s7dsd_retrn_rsn +_postin,s7reson0+_postin,s7ite/_sales+_postin,s7sales_order+_postin,s7dist_c-annel+_postin,s7sales_or,+_postin,s7diision+_postin,s7s-ippin,_type+_postin,s7partner_pc+_postin,s7ite/_cate,ory
+_postin,s7tradin,_partner+_postin,s7/ar$et+_postin,s7sales_o%%ice+_postin,s7contry+_postin,s7resp+_postin,s7ale_date+_postin,s7trade_type+_postin,s7controllin,_area+_postin,s7cost_obect +_postin,s7cst_-ie0 +_postin,s7cst_-ie? +_postin,s7cst_-ie@ +_postin,s7cst_-ie'
+_postin,s7cst_-ie +_postin,s7cst_-ieC+_postin,s7s-ip_to_party+_postin,s7%in_plnin,_ll+_postin,s7e;t_ic_/od_std +_postin,s70(_intrprtation +_postin,s700_intrprtation+_postin,s7cr/_/ar$etin,+_d//y+_postin,s7a/ont = l_a/ont* END OF ((C IF NOT & +_postin,s7p$ey IS INITIA4 ) APPEND +_postin,s TO t_postin,ENDIF 24EA3: +_postin,s! l_a%nr!l_cst_-ie5! l_csto/er! l_prodct!l_plant! l_accont! l_a/ontEND4OOPIF t_b$rs IS NOT INITIA4 DE4ETE ADA2ENT D8P4I2ATES F3O9 t_b$rs 2O9PA3ING b$rs*Fect- t-e crrency %or co/pany codes SE4E2Tb$rs+aers F3O9 t((0 INTO TAB4E t_crr FO3 A44 ENT3IES IN t_b$rs #
-
8/20/2019 Bapi for Fb01
6/9
SO3T t_crr BY b$rsENDIFENDFO39" SP4IT_INTO_3E2O3DS*6777777777777777777777777777777777777777777777777777777777777777777777**6 For/ KA4IDATE_G4*6777777777777777777777777777777777777777777777777777777777777777777777*
FO39 alidate_,l TYPES: BEGIN OF ltype_,l!b$rs TYPE b$rs!sa$nr TYPE sa$nr!;intb TYPE ;intb! END OF ltype_,l DATA: lt_postin,s_te/p TYPE STANDA3D TAB4E OF type_ite/!lt_,l_%la, TYPE STANDA3D TAB4E OF ltype_,l!l+_,l_%la, TYPE ltype_,l!l_/s, TYPE c-ar0((!l+_/essa,e TYPE type_/essa,e!l_conter TYPE posnr_acc 3EF3ES
-
8/20/2019 Bapi for Fb01
7/9
* Else display t-e error /essa,e %or G4 accontl+_/essa,e7/es_type = c_el+_/essa,e7te;t = l_/s, APPEND l+_/essa,e TO t_/essa,e24EA3 l+_/essa,e,_error_%la, = c_;
ENDIFEND4OOPENDFO39" KA4IDATE_G4*6777777777777777777777777777777777777777777777777777777777777777777777**6 For/ POP84ATE_BAPI*6777777777777777777777777777777777777777777777777777777777777777777777*FO39 poplate_bapi 8SING rl_conter TYPE posnr_acc**Poplate line ite/ details IF +_postin,s7co/pany NE +_-eader7co/p_code,_cross_%la, = c_; ENDIF*Fill 2redit line ite/ data IF +_postin,s7p$ey='(
+_ite/_,l7ite/no_acc = rl_conter+_ite/_,l7co/p_code = +_postin,s7co/pany+_ite/_,l7,l_accont = +_postin,s7accont+_ite/_,l7pstn,_date = +_-eader7pstn,_date+_ite/_,l7cs_trans_t = +_postin,s7ttype+_ite/_,l7costcenter = +_postin,s7ccent+_ite/_,l7pro%it_ctr = +_postin,s7prcent+_ite/_,l7+bs_ele/ent = +_postin,s7+bs_ele/ent+_ite/_,l7orderid = +_postin,s7internal_order+_ite/_,l7ite/_te;t = +_postin,s7description+_ite/_,l7alloc_n/br = +_postin,s7assi,n/ent+_ite/_,l7ta;_code = +_postin,s7ta;_code+_ite/_,l7ta;rcode = +_postin,s7ridiction_code
+_ite/_,l7orderid = +_postin,s7internal_order+_ite/_,l7base_o/ = +_postin,s7/eins+_ite/_,l7Hantity = +_postin,s7Hantity+_ite/_,l7trade_id = +_postin,s7tradin,_partner+_ite/_,l7ale_date = +_postin,s7ale_date APPEND +_ite/_,l TO t_ite/_,l IF +_-eader57$rs% IS NOT INITIA4* To %etc- co/pany code crrency 3EAD TAB4E t_crr INTO +_crr #IT< LEY b$rs = +_postin,s7co/pany BINA3Y SEA32
-
8/20/2019 Bapi for Fb01
8/9
+_ite/_,l7ite/no_acc = rl_conter+_ite/_,l7co/p_code = +_postin,s7co/pany+_ite/_,l7,l_accont = +_postin,s7accont+_ite/_,l7pstn,_date = +_-eader7pstn,_date+_ite/_,l7cs_trans_t = +_postin,s7ttype+_ite/_,l7costcenter = +_postin,s7ccent
+_ite/_,l7pro%it_ctr = +_postin,s7prcent+_ite/_,l7+bs_ele/ent = +_postin,s7+bs_ele/ent+_ite/_,l7orderid = +_postin,s7internal_order+_ite/_,l7ite/_te;t = +_postin,s7description+_ite/_,l7alloc_n/br = +_postin,s7assi,n/ent+_ite/_,l7ta;_code = +_postin,s7ta;_code+_ite/_,l7ta;rcode = +_postin,s7ridiction_code+_ite/_,l7orderid = +_postin,s7internal_order+_ite/_,l7base_o/ = +_postin,s7/eins+_ite/_,l7Hantity = +_postin,s7Hantity+_ite/_,l7part_prctr = +_postin,s7partner_pc+_ite/_,l7trade_id = +_postin,s7tradin,_partner+_ite/_,l7ale_date = +_postin,s7ale_date
APPEND +_ite/_,l TO t_ite/_,l IF +_-eader57$rs% IS NOT INITIA4* To %etc- co/pany code crrency 3EAD TAB4E t_crr INTO +_crr #IT< LEY b$rs = +_postin,s7co/pany BINA3Y SEA32
-
8/20/2019 Bapi for Fb01
9/9
lt_b$p% TYPE STANDA3D TAB4E OF type_b$p%!l+_b$p% TYPE type_b$p%!l_bor, TYPE bor7bor,*2lear local +or$ area and ariables 24EA3: l+_/essa,e!l_/s,!
l+_retrn!l+_b$p% 24EA3: +_-eader7ob_type!+_-eader7ob_$ey!+_-eader7ob_sys IF ,_error_%la, NE c_; IF ,_credit_total ( AND ,_debit_total (2A44 F8N2TION >BAPI_A22_DO289ENT_2 EPO3TINGdoc/ent-eader= +_-eader TAB4ESaccont,l = t_ite/_,lcrrencya/ont = t_ite/_crr
retrn = t_retrnI% t_retrn is not initial* Postin, ornal entries 2A44 F8N2TION >BAPI_A22_DO289ENT_POST> EPO3TINGdoc/ent-eader = +_-eader I9PO3TINGob_type = ,_ob_typeob_$ey = ,_ob_$eyob_sys = ,_ob_sys TAB4ESaccont,l = t_ite/_,lcrrencya/ont = t_ite/_crr
retrn = t_retrnIF sy7sbrc ( 2A44 F8N2TION >BAPI_T3ANSA2TION_2O99IT> EPO3TING +ait = c_; ENDIFEndi%ENDIF