Application Development and Automation 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: 
Read only

Error Handling in BDC...Review code..

Former Member
0 Likes
1,127

Hi Gurus,

I have made a BDC program to do call transaction for FV50...i AM NOT SURE ON HOW TO DO ERROR HANDLING IN THAT...TRIED TO DO SOMETHING BUT IT NEEDS LOT OF IMPROVEMENT...

CAN ONE YOU EXPERTS HELP ME IN THAT...I AM ATTACHING THE ENTIRE CODE..

REPORT zbdc_park_fv50.

DATA:

t_document_line_item_main LIKE bapiacgl09 OCCURS 100,

t_document_line_item_enhn LIKE bapiacextc OCCURS 100,

t_document_line_item_amnt LIKE bapiaccr09 OCCURS 100,

wa_document_header LIKE bapiache09,

wa_document_line_item_main LIKE bapiacgl09,

wa_document_line_item_enhn LIKE bapiacextc,

wa_document_line_item_amnt LIKE bapiaccr09.

DATA: BEGIN OF s_bdc_document_item_main,

v_HKONT LIKE ACGL_ITEM-HKONT,

v_SHKZG LIKE ACGL_ITEM-SHKZG,

v_SGTXT LIKE ACGL_ITEM-SGTXT,

v_WRBTR LIKE ACGL_ITEM-WRBTR,

v_WAERS LIKE ACGL_HEAD-WAERS,

v_PRCTR LIKE ACGL_ITEM-PRCTR,

v_YYLOB LIKE ACGL_ITEM-YYLOB,

v_YYCSG LIKE ACGL_ITEM-YYCSG,

END OF s_bdc_document_item_main.

DATA: t_bdc_document_item_main LIKE s_bdc_document_item_main OCCURS 0,

wa_bdc_document_item_main LIKE s_bdc_document_item_main.

DATA: t_bdcdata LIKE bdcdata OCCURS 0 with header line,

t_messages LIKE bdcmsgcoll OCCURS 0 with header line.

DATA: idx TYPE i,

ch3(2) TYPE n,

fname(40) TYPE c,

options TYPE ctu_params.

DATA: indate TYPE d,

intdate TYPE d,

var_SHKZG LIKE BSEG-SHKZG,

amount(13) type c.

DATA: w_textout LIKE t100-text.

*DATA: gd_update TYPE i,

  • gd_lines TYPE i.

CLEAR wa_document_header.

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

***FILL DOCUMENT HEADER***********

wa_document_header-obj_type = space. "

wa_document_header-obj_key = space.

wa_document_header-obj_sys = space.

wa_document_header-bus_act = 'RFBU'.

wa_document_header-username = 'samwil'.

wa_document_header-header_txt = 'TEST_BDC_PARK123'.

wa_document_header-comp_code = '1001'.

wa_document_header-doc_date = '20070817'.

wa_document_header-pstng_date = '20070817'.

CLEAR wa_document_header-trans_date.

CLEAR wa_document_header-fisc_year.

CLEAR wa_document_header-fis_period.

wa_document_header-doc_type = 'SY'.

wa_document_header-ref_doc_no = 'AAR1213'.

wa_document_header-ac_doc_no = space.

wa_document_header-obj_key_r = space.

wa_document_header-reason_rev = space.

wa_document_header-compo_acc = space.

wa_document_header-ref_doc_no_long = space.

wa_document_header-acc_principle = 'LGAP'.

wa_document_header-neg_postng = space.

wa_document_header-obj_key_inv = space.

wa_document_header-bill_category = space.

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

      • FILL LINE ITEMS *******************

CLEAR: wa_document_line_item_main, wa_document_line_item_enhn, wa_document_line_item_amnt.

      • Fill Main Portion Of Accounting Line Item

wa_document_line_item_main-itemno_acc = '1'. "Accounting Document Line Item Number

wa_document_line_item_main-gl_account = '2480001067'."HKONT - Account

wa_document_line_item_main-item_text = 'ITEM 2'. "SGTXT - Item Text

wa_document_line_item_main-doc_type = space. "BLART - Document Type

wa_document_line_item_main-comp_code = space. "BUKRS - Company Code

wa_document_line_item_main-pstng_date = '20080817'. "BUDAT - Posting Date

wa_document_line_item_main-alloc_nmbr = space. "ZUONR - Allocation Number

wa_document_line_item_main-costcenter = space. "KOSTL - Cost Center

wa_document_line_item_main-profit_ctr = '1999999'. "PRCTR - Profit Center

wa_document_line_item_main-de_cre_ind = 'D'. "NEWBS - Posting Key / Debit Credit Indicator

wa_document_line_item_main-trade_id = space. "RASSC - Company ID Of Trading Partner

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

      • Fill Amount Portion Of Accounting Line Item

wa_document_line_item_amnt-itemno_acc = '1'. "Accounting Document Line Item Number

wa_document_line_item_amnt-curr_type = '00'. "Currency Type

wa_document_line_item_amnt-currency = 'USD'. "WAERS - Currency Key

wa_document_line_item_amnt-amt_doccur = '100'. "WRBTR - Amount In Document Currency Type

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

      • Create Enhancement Portion Of Accounting Line Item

wa_document_line_item_enhn-field1+0(3) = '001'. "Line of Bus YYLOB

wa_document_line_item_enhn-field1+3(3) = '008'. "Customer Segm YYCSG

wa_document_line_item_enhn-field1+6(5) = space. "Product Group

wa_document_line_item_enhn-field1+11(2) = space. "Distribution Ch

wa_document_line_item_enhn-field1+13(4) = space. "Maturity Year

wa_document_line_item_enhn-field1+17(3) = space. "Insurance Type

wa_document_line_item_enhn-field1+20(4) = space. "Accident Year

wa_document_line_item_enhn-field1+24(6) = space. "Product

wa_document_line_item_enhn-field1+30(3) = space. "Source

wa_document_line_item_enhn-field1+33(22) = space. "DI Run Name

wa_document_line_item_enhn-field1+55(1) = space. "DI Run Type

wa_document_line_item_enhn-field1+56(5) = space. "DI Run Number

wa_document_line_item_enhn-field1+61(16) = space. "DI Journal ID

wa_document_line_item_enhn-field1+77(5) = space. "DI Journal Link

wa_document_line_item_enhn-field1+82(22) = space. "DI File Name

APPEND: wa_document_line_item_main TO t_document_line_item_main,

wa_document_line_item_enhn TO t_document_line_item_enhn,

wa_document_line_item_amnt TO t_document_line_item_amnt.

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

      • Fill Next Line Item #2

CLEAR: wa_document_line_item_main, wa_document_line_item_enhn, wa_document_line_item_amnt.

      • Fill Main Portion Of Accounting Line Item

wa_document_line_item_main-itemno_acc = '2'. "Accounting Document Line Item Number

wa_document_line_item_main-gl_account = '2480001067'."HKONT - Account

wa_document_line_item_main-item_text = 'ITEM 3'. "SGTXT - Item Text

wa_document_line_item_main-doc_type = space. "BLART - Document Type

wa_document_line_item_main-comp_code = space. "BUKRS - Company Code

wa_document_line_item_main-pstng_date = '20080817'. "BUDAT - Posting Date

wa_document_line_item_main-alloc_nmbr = space. "ZUONR - Allocation Number

wa_document_line_item_main-costcenter = space. "KOSTL - Cost Center

wa_document_line_item_main-profit_ctr = '1999999'. "PRCTR - Profit Center

wa_document_line_item_main-de_cre_ind = 'C'. "NEWBS - Posting Key / Debit Credit Indicator

wa_document_line_item_main-trade_id = space. "RASSC - Company ID Of Trading Partner

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

      • Fill Enhancement Portion Of Accounting Line Item

      • Fill Amount Portion Of Accounting Line Item

wa_document_line_item_amnt-itemno_acc = '2'. "Accounting Document Line Item Number

wa_document_line_item_amnt-curr_type = '00'. "Currency Type

wa_document_line_item_amnt-currency = 'USD'. "WAERS - Currency Key

wa_document_line_item_amnt-amt_doccur = '100'. "WRBTR - Amount In Document Currency Type

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

      • Create Enhancement Portion Of Accounting Line Item

wa_document_line_item_enhn-field1+0(3) = '001'. "Line of Bus YYLOB.

wa_document_line_item_enhn-field1+3(3) = '008'. "Customer Segm YYCSG

wa_document_line_item_enhn-field1+6(5) = space. "Product Group

wa_document_line_item_enhn-field1+11(2) = space. "Distribution Ch

wa_document_line_item_enhn-field1+13(4) = space. "Maturity Year

wa_document_line_item_enhn-field1+17(3) = space. "Insurance Type

wa_document_line_item_enhn-field1+20(4) = space. "Accident Year

wa_document_line_item_enhn-field1+24(6) = space. "Product

wa_document_line_item_enhn-field1+30(3) = space. "Source

wa_document_line_item_enhn-field1+33(22) = space. "DI Run Name

wa_document_line_item_enhn-field1+55(1) = space. "DI Run Type

wa_document_line_item_enhn-field1+56(5) = space. "DI Run Number

wa_document_line_item_enhn-field1+61(16) = space. "DI Journal ID

wa_document_line_item_enhn-field1+77(5) = space. "DI Journal Link

wa_document_line_item_enhn-field1+82(22) = space. "DI File Name

APPEND: wa_document_line_item_main TO t_document_line_item_main,

wa_document_line_item_enhn TO t_document_line_item_enhn,

wa_document_line_item_amnt TO t_document_line_item_amnt.

****FILL THE BDC TABLE*******************************************************

LOOP AT t_document_line_item_main INTO wa_document_line_item_main.

Move: wa_document_line_item_main-gl_account TO wa_bdc_document_item_main-v_HKONT,

wa_document_line_item_main-item_text TO wa_bdc_document_item_main-v_SGTXT,

wa_document_line_item_main-profit_ctr TO wa_bdc_document_item_main-v_PRCTR,

wa_document_line_item_main-de_cre_ind TO wa_bdc_document_item_main-v_SHKZG.

Read table t_document_line_item_amnt index sy-tabix into wa_document_line_item_amnt.

IF sy-subrc = 0.

Move : wa_document_line_item_amnt-currency TO wa_bdc_document_item_main-v_WAERS,

wa_document_line_item_amnt-amt_doccur TO wa_bdc_document_item_main-v_WRBTR.

ENDIF.

Read table t_document_line_item_enhn index sy-tabix into wa_document_line_item_enhn.

IF sy-subrc = 0.

Move : wa_document_line_item_enhn-field1+0(3) TO wa_bdc_document_item_main-v_YYLOB,

wa_document_line_item_enhn-field1+3(3) TO wa_bdc_document_item_main-v_YYCSG.

ENDIF.

APPEND wa_bdc_document_item_main TO t_bdc_document_item_main.

CLEAR: wa_bdc_document_item_main.

ENDLOOP. " BDC Table.

************************BDC PROGRAM**************************************************************

perform bdc_dynpro TABLES t_bdcdata using 'SAPLACHD' '1000'.

perform bdc_field TABLES t_bdcdata using 'BDC_CURSOR'

'BKPF-BUKRS'.

perform bdc_field TABLES t_bdcdata using 'BDC_OKCODE'

'=ENTR'.

perform bdc_field TABLES t_bdcdata using 'BKPF-BUKRS'

wa_document_header-comp_code.

perform bdc_dynpro TABLES t_bdcdata using 'SAPMF05A' '1001'.

perform bdc_field TABLES t_bdcdata using 'BDC_OKCODE'

'=PBBP'.

perform bdc_field TABLES t_bdcdata using 'ACGL_HEAD-BLDAT'

wa_document_header-doc_date.

perform bdc_field TABLES t_bdcdata using 'ACGL_HEAD-WAERS'

'USD'.

perform bdc_field TABLES t_bdcdata using 'ACGL_HEAD-BUDAT'

wa_document_header-pstng_date.

perform bdc_field TABLES t_bdcdata using 'ACGL_HEAD-XBLNR'

wa_document_header-ref_doc_no.

perform bdc_field TABLES t_bdcdata using 'ACGL_HEAD-BKTXT'

wa_document_header-header_txt.

perform bdc_field TABLES t_bdcdata using 'ACGL_HEAD-BLART'

wa_document_header-doc_type.

perform bdc_field TABLES t_bdcdata using 'BDC_CURSOR'

'ACGL_ITEM_GEN-GEN_CHAR2(02)'.

LOOP AT t_bdc_document_item_main INTO wa_bdc_document_item_main.

idx = idx + 1.

ch3 = idx.

CONCATENATE 'ACGL_ITEM-HKONT('ch3')' INTO FNAME.

perform bdc_field TABLES t_bdcdata using fname

wa_bdc_document_item_main-v_HKONT.

CONCATENATE 'ACGL_ITEM-SHKZG('ch3')' INTO FNAME.

IF wa_bdc_document_item_main-v_SHKZG = 'C'.

var_SHKZG = 'H'.

ELSEIF wa_bdc_document_item_main-v_SHKZG = 'D'.

var_SHKZG = 'S'.

ENDIF.

perform bdc_field TABLES t_bdcdata using fname

var_SHKZG.

CONCATENATE 'ACGL_ITEM-WRBTR('ch3')' INTO FNAME.

WRITE: wa_bdc_document_item_main-v_WRBTR to amount.

perform bdc_field TABLES t_bdcdata using FNAME

  • wa_bdc_document_item_main-v_WRBTR.

amount.

CONCATENATE 'ACGL_ITEM-SGTXT('ch3')' INTO FNAME.

perform bdc_field TABLES t_bdcdata using FNAME

wa_bdc_document_item_main-v_SGTXT.

CONCATENATE 'ACGL_ITEM-PRCTR('ch3')' INTO FNAME.

perform bdc_field TABLES t_bdcdata using FNAME

wa_bdc_document_item_main-v_PRCTR.

CONCATENATE 'ACGL_ITEM_GEN-GEN_CHAR1('ch3')' INTO FNAME.

perform bdc_field TABLES t_bdcdata using FNAME

wa_bdc_document_item_main-v_YYLOB.

CONCATENATE 'ACGL_ITEM_GEN-GEN_CHAR2('ch3')' INTO FNAME.

perform bdc_field TABLES t_bdcdata using FNAME

wa_bdc_document_item_main-v_YYCSG.

options-dismode = 'A'.

options-nobinpt = 'X'.

endloop.

CALL TRANSACTION 'FV50' USING t_bdcdata MESSAGES INTO

t_messages OPTIONS FROM options.

*if sy-subrc = 0.

  • Retrieve error messages

LOOP AT t_messages WHERE msgtyp = 'E'.

  • Builds actual message based on info returned from Call transaction

CALL FUNCTION 'MESSAGE_TEXT_BUILD'

EXPORTING

msgid = t_messages-msgid

msgnr = t_messages-msgnr

msgv1 = t_messages-msgv1

msgv2 = t_messages-msgv2

msgv3 = t_messages-msgv3

msgv4 = t_messages-msgv4

IMPORTING

message_text_output = w_textout.

ENDLOOP.

*----


*

  • Start new screen

*

*----


*

FORM bdc_dynpro TABLES it_bdcdata STRUCTURE bdcdata USING program

dynpro.

DATA: wa_bdcdata TYPE bdcdata.

wa_bdcdata-program = program.

wa_bdcdata-dynpro = dynpro.

wa_bdcdata-dynbegin = 'X'.

APPEND wa_bdcdata TO it_bdcdata.

ENDFORM. "BDC_DYNPRO

*----


*

  • Insert field

*

*----


*

FORM bdc_field TABLES it_bdcdata STRUCTURE bdcdata USING fnam fval.

DATA: wa_bdcdata TYPE bdcdata.

IF fval <> space.

CLEAR wa_bdcdata.

wa_bdcdata-fnam = fnam.

wa_bdcdata-fval = fval.

APPEND wa_bdcdata TO it_bdcdata.

ENDIF.

ENDFORM. "BDC_FIELD

Title was edited by:

Alvaro Tejada Galindo

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,067

HI,

The code looks ok...

take a internal table for messages.

data : begin of itab occurs 0,

message(100) type c,

end of itab.

put this after

  • Retrieve error messages

LOOP AT t_messages WHERE msgtyp = 'E'.

  • Builds actual message based on info returned from Call transaction

CALL FUNCTION 'MESSAGE_TEXT_BUILD'

EXPORTING

msgid = t_messages-msgid

msgnr = t_messages-msgnr

msgv1 = t_messages-msgv1

msgv2 = t_messages-msgv2

msgv3 = t_messages-msgv3

msgv4 = t_messages-msgv4

IMPORTING

message_text_output = w_textout.

<b>itab-message = w_textout.

append itab</b>.

ENDLOOP.

7 REPLIES 7
Read only

Former Member
0 Likes
1,068

HI,

The code looks ok...

take a internal table for messages.

data : begin of itab occurs 0,

message(100) type c,

end of itab.

put this after

  • Retrieve error messages

LOOP AT t_messages WHERE msgtyp = 'E'.

  • Builds actual message based on info returned from Call transaction

CALL FUNCTION 'MESSAGE_TEXT_BUILD'

EXPORTING

msgid = t_messages-msgid

msgnr = t_messages-msgnr

msgv1 = t_messages-msgv1

msgv2 = t_messages-msgv2

msgv3 = t_messages-msgv3

msgv4 = t_messages-msgv4

IMPORTING

message_text_output = w_textout.

<b>itab-message = w_textout.

append itab</b>.

ENDLOOP.

Read only

Former Member
0 Likes
1,067

A couple of things:

FV50 is an EnjoySAP transaction and not well suited to batch input. FBV1 as far am I am aware, is still supported. (See note 310485.)

You will run into problems if the index (ch3) becomes larger than the number of lines on the screen.

Rob

Read only

0 Likes
1,067

Thanks for the reply Rob...

How shud i do this then...please give some suggestions...

Read only

0 Likes
1,067

I don't think I would go in this direction at all. Have you thought about using standard SAP program RFBIBL00?

Rob

Read only

0 Likes
1,067

Hey Rob,

Yaa I did...but i am new to ABAP so was not sure how to use it...can u provide some inputs on how can iuse RFBIBL00 and get this done...Please suggest...

Read only

0 Likes
1,067

The first thing to do is check the documentation. It's pretty thorough.

Rob

Read only

Former Member
0 Likes
1,067

Hi Sam,

For every record you are uploading try to print or add a breakpoint in debugger at w_textout. In w_textout you will find if the record has any error. If the record is succesfully upload you will find the succesfully message.

<b><REMOVED BY MODERATOR></b>

Message was edited by:

Alvaro Tejada Galindo