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: 

bapi

Former Member
0 Kudos

Hi all,

How to create report using BAPI_ACC_GL_POSTING_POST bapi.

and how to collect the log messages into the application server.

Please send me the code.

regards,

rakesh

2 REPLIES 2

Former Member
0 Kudos

Hi

Refer to this code :

include <icon>.

*/ =================================================================== *

CONSTANTS: on VALUE 'X',

off VALUE ' ',

tabx TYPE X VALUE '09',

c_e1bpache08 TYPE edilsegtyp VALUE 'E1BPACHE08',

c_e1bpacgl08 TYPE edilsegtyp VALUE 'E1BPACGL08',

c_e1bpaccr08 TYPE edilsegtyp VALUE 'E1BPACCR08'.

TYPES: BEGIN OF t_tab_index,

from TYPE i,

to TYPE i,

END OF t_tab_index.

data : tab type c.

DATA:

e1bpache08 LIKE e1bpache08,

e1bpacgl08 LIKE e1bpacgl08,

e1bpaccr08 LIKE e1bpaccr08.

DATA: g_subrc TYPE subrc.

DATA: g_file TYPE string.

DATA: g_segname TYPE edilsegtyp.

DATA: g_sdata TYPE edi_sdata.

DATA: g_first_doc.

DATA: i_dataf TYPE char2000 OCCURS 900 WITH HEADER LINE,

i_dataf_doc TYPE char2000 OCCURS 50 WITH HEADER LINE.

DATA: g_tab_index TYPE t_tab_index OCCURS 100 WITH HEADER LINE.

DATA: i_accountgl TYPE bapiacgl08 OCCURS 100 WITH HEADER LINE,

i_curramnt TYPE bapiaccr08 OCCURS 100 WITH HEADER LINE,

i_return TYPE bapiret2 OCCURS 10 WITH HEADER LINE,

g_docheader TYPE bapiache08.

*/ ======================== SELECTION ================================ *

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-010.

PARAMETERS: excelf TYPE file_name LOWER CASE

DEFAULT 'C:\my_excel_file.txt'.

SELECTION-SCREEN END OF BLOCK b1.

*/ =========================== CORE ================================== *

START-OF-SELECTION.

*/ Call text File with GUI_UPLOAD

g_file = excelf.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = g_file

  • FILETYPE = 'ASC'

  • HAS_FIELD_SEPARATOR = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

data_tab = i_dataf

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17

.

IF sy-subrc <> 0.

write: / Text-032.

stop.

ENDIF.

*/ Initialisation

write tabx to tab. " required as of ABAP 610 split cannot

*/ have mixed char and byte types

CLEAR g_tab_index.

REFRESH g_tab_index.

*/ how to process several doc : detecting docs in i_dataf

g_first_doc = on.

LOOP AT i_dataf.

CLEAR: g_segname, g_sdata.

SPLIT i_dataf AT tab INTO g_segname g_sdata.

CHECK: g_segname = c_e1bpache08,

sy-tabix > 1.

*/ 1st document

IF g_first_doc = on.

g_tab_index-from = 1.

g_tab_index-to = sy-tabix - 1.

APPEND g_tab_index.

*/ Next Documents

ELSE.

g_tab_index-from = g_tab_index-to + 1.

g_tab_index-to = sy-tabix - 1.

APPEND g_tab_index.

ENDIF.

g_first_doc = off.

ENDLOOP.

*/ Last doc.

g_tab_index-from = g_tab_index-to + 1.

g_tab_index-to = sy-tfill.

APPEND g_tab_index.

*/ Process documents.

loop at g_tab_index.

clear i_dataf_doc.

refresh i_dataf_doc.

append lines of i_dataf from g_tab_index-from

to g_tab_index-to

to i_dataf_doc.

perform process_document.

endloop.

END-OF-SELECTION.

*/ =========================== ROUTINES ============================== *

----


  • FORM process_document *

----


  • ........ *

----


FORM process_document.

*/ Clearing Memory

CLEAR: g_docheader, i_accountgl, i_curramnt, i_return, g_subrc.

REFRESH: i_accountgl, i_curramnt, i_return.

*/ Checking i_dataf_doc

*/ Mapping dataf => Bapi structures & internal tables

CLEAR g_subrc.

CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.

LOOP AT i_dataf_doc.

CLEAR g_sdata.

SPLIT i_dataf_doc AT tab INTO g_segname g_sdata.

CASE g_segname.

*/ HEADER

WHEN c_e1bpache08.

PERFORM do_split_ache08.

MOVE-CORRESPONDING e1bpache08 TO g_docheader.

IF e1bpache08-doc_date IS INITIAL.

CLEAR g_docheader-doc_date.

ENDIF.

IF e1bpache08-pstng_date IS INITIAL.

CLEAR g_docheader-pstng_date.

ENDIF.

IF e1bpache08-trans_date IS INITIAL.

CLEAR g_docheader-trans_date.

ENDIF.

*/ Account GL

WHEN c_e1bpacgl08.

PERFORM do_split_acgl08.

MOVE-CORRESPONDING e1bpacgl08 TO i_accountgl.

IF e1bpacgl08-pstng_date IS INITIAL.

CLEAR i_accountgl-pstng_date.

ENDIF.

APPEND i_accountgl.

*/ Account Currency & Amounts

WHEN c_e1bpaccr08.

PERFORM do_split_accr08.

MOVE-CORRESPONDING e1bpaccr08 TO i_curramnt.

APPEND i_curramnt.

*/ kick the line if segment name not filled

WHEN space.

*/ Other names => Bad file structure !

WHEN OTHERS.

g_subrc = 2.

ENDCASE.

ENDLOOP. " i_dataf_doc

ENDCATCH.

*/ erreur d'affectation

IF sy-subrc = 1 OR

NOT g_subrc IS INITIAL.

perform message_output using on.

exit.

ENDIF.

*/ Calling the BAPI

CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'

EXPORTING

documentheader = g_docheader

  • IMPORTING

  • OBJ_TYPE =

  • OBJ_KEY =

  • OBJ_SYS =

TABLES

accountgl = i_accountgl

currencyamount = i_curramnt

return = i_return

  • EXTENSION1 =

.

LOOP AT i_return WHERE type CA 'AE'.

g_subrc = 1.

EXIT.

ENDLOOP.

IF NOT g_subrc IS INITIAL.

perform message_output using on.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT =

  • IMPORTING

  • RETURN =

.

perform message_output using off.

ENDIF.

ENDFORM.

&----


*& Form do_split_ACHE08

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM do_split_ache08.

CLEAR e1bpache08.

SPLIT g_sdata AT tab INTO

e1bpache08-obj_type

e1bpache08-obj_key

e1bpache08-obj_sys

e1bpache08-username

e1bpache08-header_txt

e1bpache08-obj_key_r

e1bpache08-comp_code

e1bpache08-ac_doc_no

e1bpache08-fisc_year

e1bpache08-doc_date

e1bpache08-pstng_date

e1bpache08-trans_date

e1bpache08-fis_period

e1bpache08-doc_type

e1bpache08-ref_doc_no

e1bpache08-compo_acc

e1bpache08-reason_rev

.

ENDFORM. " do_split_ACHE08

&----


*& Form do_split_ACGL08

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM do_split_acgl08.

CLEAR e1bpacgl08.

SPLIT g_sdata AT tab INTO

e1bpacgl08-itemno_acc

e1bpacgl08-gl_account

e1bpacgl08-comp_code

e1bpacgl08-pstng_date

e1bpacgl08-doc_type

e1bpacgl08-ac_doc_no

e1bpacgl08-fisc_year

e1bpacgl08-fis_period

e1bpacgl08-stat_con

e1bpacgl08-ref_key_1

e1bpacgl08-ref_key_2

e1bpacgl08-ref_key_3

e1bpacgl08-customer

e1bpacgl08-vendor_no

e1bpacgl08-alloc_nmbr

e1bpacgl08-item_text

e1bpacgl08-bus_area

e1bpacgl08-costcenter

e1bpacgl08-acttype

e1bpacgl08-orderid

e1bpacgl08-orig_group

e1bpacgl08-cost_obj

e1bpacgl08-profit_ctr

e1bpacgl08-part_prctr

e1bpacgl08-wbs_element

e1bpacgl08-network

e1bpacgl08-routing_no

e1bpacgl08-order_itno

.

ENDFORM. " do_split_ACGL08

&----


*& Form do_split_ACCR08

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM do_split_accr08.

data: l_filler(100).

CLEAR e1bpaccr08.

SPLIT g_sdata AT tab INTO

e1bpaccr08-itemno_acc

e1bpaccr08-curr_type

e1bpaccr08-currency

e1bpaccr08-currency_iso

e1bpaccr08-amt_doccur

e1bpaccr08-exch_rate

e1bpaccr08-exch_rate_v

l_filler

.

ENDFORM. " do_split_ACCR08

&----


*& Form message_output

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM message_output using if_error.

data: l_message(200),

l_return type i.

format color 1.

skip.

write: / text-020, g_tab_index-from,

text-021, g_tab_index-to.

skip.

if if_error = on.

write: / icon_red_light as icon, text-030 color 6.

else.

write: / icon_green_light as icon, text-031 color 5.

endif.

describe table i_return lines l_return.

if l_return is initial.

write: / text-032.

endif.

loop at i_return.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = i_return-id

LANG = sy-langu

NO = i_return-number

V1 = i_return-MESSAGE_V1

V2 = i_return-MESSAGE_V2

V3 = i_return-MESSAGE_V3

V4 = i_return-MESSAGE_V4

IMPORTING

MSG = l_message

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

check sy-subrc = 0.

write: / l_message.

endloop.

ENDFORM. " message_output

Thanks

Vasudha

Former Member
0 Kudos

Hi Ram,

Please check the below link,

Best Regards.

    • Reward points if it is helpful.