Skip to Content
1
Former Member
Jul 02, 2007 at 11:34 PM

BDC Errors

20 Views

I have to write a Session Method for the below program to UPLOAD the errors and process them at SM35, can anyone help me out with this please. Thanks heaps.

REPORT Z_SAMPLE_CONCUR_INTERFACE .

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.

PARAMETERS: p_fname LIKE rlgrap-filename VISIBLE LENGTH 100 DEFAULT

'C:\'.

PARAMETERS: p_chcgo LIKE rlgrap-filename VISIBLE LENGTH 100 DEFAULT

'C:\'.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002.

PARAMETERS: r_amex RADIOBUTTON GROUP rad1,

r_empaid RADIOBUTTON GROUP rad1,

r_copaid RADIOBUTTON GROUP rad1.

SELECTION-SCREEN END OF BLOCK b2.

DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE,

opt TYPE ctu_params,

messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

DATA: up_file TYPE STRING,

chicago_file TYPE STRING,

z_download TYPE STRING.

DATA: BEGIN OF inrec OCCURS 0,

data(999).

DATA: END OF inrec.

DATA: BEGIN OF temp OCCURS 0,

value(255).

DATA: END OF temp.

DATA: BEGIN OF chicago OCCURS 0,

value(999).

DATA: END OF chicago.

DATA: BEGIN OF header OCCURS 0,

batch_date(10),

rec_count(5),

hash_total(23).

DATA: END OF header.

TYPES: BEGIN OF struc,

batch_id(13), "batch ID

rep_key(48), "report key

rep_name(40), "report name

rep_stamp(32), "report ID

rep_rec_date(8), "report received date

rep_header2(48), "report header2

rep_header3(48), "report header3

rep_date(8), "report date

emp_fname(32), "employee first name

emp_min(1), "employee middle initial

emp_lname(32), "employee last name

emp_id(48), "employee ID

emp_info1(48), "employee info1

emp_info2(48), "employee info2

comp_name(48), "company name

emp_org4(48), "employee org 4

rep_amt_tot(23), "report amount total

rep_amt_apvd(23), "report amount approved

base_ccode(3), "base currency code

trans_date(8), "transaction date

trans_descrip(64), "transaction description

exp_type(64), "expense type

pers_exp(1), "personal expense (Y/N)

entry_amtc(23), "entry amount claimed

entry_amtd(23), "entry amount due

entry_amta(23), "entry amount approved

pay_type(64), "payment type

co_pay_type(80), "company payment type

cc_num(255), "credit card number

cc_ref_num(5), "credit card reference number

acct_num(20), "account number

fo_ccode(3), "foreign currency code

fo_amt(23), "foreign currency amount

fo_rate(23), "foregin currency rate

vendor(64), "vendor

bus_unit(48), "business unit

cost_center(48), "cost center

int_ord(48), "internal order

car_num_dtl(30), "car number detail

bus_mls_dtl(13), "business miles detail

mls_purp_dtl(13). "miles purpose detail

TYPES: END OF struc.

DATA: itab TYPE struc OCCURS 0 WITH HEADER LINE.

DATA: errors TYPE struc OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF doc OCCURS 0,

num(100) TYPE C.

DATA: END OF doc.

DATA: z1256(4) TYPE C value '1256',

zb34(3) TYPE C value ' 34',

z_datum(10),

z_xblnr(16),

z_bktxt(25),

z_hkont(10),

z_service(1), "TEMPORARY

z_file TYPE rlgrap-filename.

DATA: BEGIN OF dynp_value_tab OCCURS 0.

INCLUDE STRUCTURE dynpread.

DATA: END OF dynp_value_tab.

start-of-selection.

PERFORM upload_file.

PERFORM load_data.

PERFORM bdc_fb50.

PERFORM download_file.

----


  • At Selection Screen

----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

PERFORM get_filename.

p_fname = z_file.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_chcgo.

PERFORM get_filename.

p_chcgo = z_file.

&----


*& Form get_filename

&----


FORM get_filename.

MOVE: 'DS_NAME' TO dynp_value_tab-fieldname.

APPEND dynp_value_tab.

CALL FUNCTION 'DYNP_VALUES_READ'

EXPORTING

dyname = sy-repid

dynumb = sy-dynnr

TABLES

dynpfields = dynp_value_tab

EXCEPTIONS

invalid_abapworkarea = 04

invalid_dynprofield = 08

invalid_dynproname = 12

invalid_dynpronummer = 16

invalid_request = 20

no_fielddescription = 24

undefind_error = 28.

READ TABLE dynp_value_tab INDEX 1.

MOVE: dynp_value_tab-fieldvalue TO z_file.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

DEF_FILENAME = SPACE

DEF_PATH = z_file

MASK = ',.,.. '

MODE = 'O'

TITLE = ' '

IMPORTING

FILENAME = z_file

EXCEPTIONS

INV_WINSYS = 1

NO_BATCH = 2

SELECTION_CANCEL = 3

SELECTION_ERROR = 4

OTHERS = 5.

ENDFORM. " SUB_GET_FILENAME

&----


*& Form upload_file

&----


FORM upload_file .

up_file = p_fname.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = up_file

TABLES

DATA_TAB = inrec.

ENDFORM. " upload_file

&----


*& Form load_data

&----


FORM load_data.

*

  • Split data file into separate fields and load internal table

LOOP AT inrec.

SPLIT inrec-data AT 'DAT' INTO TABLE temp.

READ TABLE temp INDEX 1.

IF temp-value = 'EXTRACT'.

*

  • Extract header record

  • Batch Date

READ TABLE temp INDEX 2.

CHECK sy-subrc IS INITIAL.

CONCATENATE temp-value0(4) temp-value5(2) temp-value+8(2)

INTO header-batch_date.

*

  • Record Count

READ TABLE temp INDEX 3.

CHECK sy-subrc IS INITIAL.

MOVE temp-value TO header-rec_count.

*

  • Hash Total

READ TABLE temp INDEX 4.

CHECK sy-subrc IS INITIAL.

MOVE temp-value TO header-hash_total.

APPEND header.

ELSEIF temp-value = 'DETAIL'.

READ TABLE temp INDEX 10.

CHECK sy-subrc IS INITIAL.

IF temp-value = '12'.

LOOP AT temp.

IF sy-tabix = 1.

chicago-value = temp-value.

ELSE.

CONCATENATE chicago-value temp-value INTO chicago-value

SEPARATED BY '|'.

ENDIF.

ENDLOOP.

APPEND chicago.

ELSEIF temp-value = '11'. "TEMPORARY

z_service = 'Y'. "TEMPORARY

ELSE.

*

  • Extract detail record

  • Batch ID

READ TABLE temp INDEX 2.

CHECK sy-subrc IS INITIAL.

MOVE temp-value TO itab-batch_id.

  • Employee First Name

READ TABLE temp INDEX 7.

CHECK sy-subrc IS INITIAL.

MOVE temp-value TO itab-emp_fname.

*

  • Employee Middle Initial

READ TABLE temp INDEX 8.

CHECK sy-subrc IS INITIAL.

MOVE temp-value TO itab-emp_min.

*

  • Employee Last Name

READ TABLE temp INDEX 6.

CHECK sy-subrc IS INITIAL.

MOVE temp-value TO itab-emp_lname.

*

  • Report Key

READ TABLE temp INDEX 20.

CHECK sy-subrc IS INITIAL.

MOVE temp-value TO itab-rep_key.

*

  • Report Name

READ TABLE temp INDEX 27.

CHECK sy-subrc IS INITIAL.

MOVE temp-value TO itab-rep_name.

*

  • Report Stamp

READ TABLE temp INDEX 19.

CHECK sy-subrc IS INITIAL.

MOVE temp-value TO itab-rep_stamp.

*

  • Report Received Date

READ TABLE temp INDEX 24.

CHECK sy-subrc IS INITIAL.

CONCATENATE temp-value0(4) temp-value5(2) temp-value+8(2)

INTO itab-rep_rec_date.

*

  • Report Header2

READ TABLE temp INDEX 45.

CHECK sy-subrc IS INITIAL.

MOVE temp-value TO itab-rep_header2.

*

  • Report Header3

READ TABLE temp INDEX 46.

CHECK sy-subrc IS INITIAL.

MOVE temp-value TO itab-rep_header3.

*

  • Report Date

READ TABLE temp INDEX 25.

CHECK sy-subrc IS INITIAL.

CONCATENATE temp-value0(4) temp-value5(2) temp-value+8(2)

INTO itab-rep_date.

*

  • Employee First Name

  • READ TABLE temp INDEX 7.

  • CHECK sy-subrc IS INITIAL.

  • MOVE temp-value TO itab-emp_fname.

  • **

    • Employee Middle Initial

  • READ TABLE temp INDEX 8.

  • CHECK sy-subrc IS INITIAL.

  • MOVE temp-value TO itab-emp_min.

  • **

    • Employee Last Name

  • READ TABLE temp INDEX 6.

  • CHECK sy-subrc IS INITIAL.

  • MOVE temp-value TO itab-emp_lname.

  • *

    • Employee ID

    READ TABLE temp INDEX 5.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-emp_id.

    *

    • Employee Info1

    READ TABLE temp INDEX 37.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-emp_info1.

    *

    • Employee Info2

    READ TABLE temp INDEX 12.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-emp_info2.

    *

    • Company Name

    READ TABLE temp INDEX 11.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-comp_name.

    *

    • Emp Org4

    READ TABLE temp INDEX 13.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-emp_org4.

    *

    • Report Amount Total

    READ TABLE temp INDEX 31.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-rep_amt_tot.

    *

    • Report Amount Approved

    READ TABLE temp INDEX 32.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-rep_amt_apvd.

    *

    • Base Currency Code

    READ TABLE temp INDEX 22.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-base_ccode.

    *

    • Transaction Date

    READ TABLE temp INDEX 64.

    CHECK sy-subrc IS INITIAL.

    CONCATENATE temp-value0(4) temp-value5(2) temp-value+8(2)

    INTO itab-trans_date.

    *

    • Transaction Description

    READ TABLE temp INDEX 69.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-trans_descrip.

    *

    *Expense Type

    READ TABLE temp INDEX 63.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-exp_type.

    *

    • Personal Expense

    READ TABLE temp INDEX 68.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-pers_exp..

    *

    • Entry Amount Claimed

    READ TABLE temp INDEX 124.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-entry_amtc.

    *

    • Entry Amount Due

    READ TABLE temp INDEX 169.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-entry_amtd.

    *

    • Entry Amount Approved

    READ TABLE temp INDEX 125.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-entry_amta.

    *

    • Payment Type

    READ TABLE temp INDEX 165.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-pay_type.

    *

    • Company Payment Type

    READ TABLE temp INDEX 166.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-co_pay_type.

    *

    • Credit Card Number

    READ TABLE temp INDEX 130.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-cc_num.

    *

    • Credit Card Reference Number

    READ TABLE temp INDEX 133.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-cc_ref_num.

    *

    • Account Number

    READ TABLE temp INDEX 167.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-acct_num.

    *

    • Foreign Currency Code

    READ TABLE temp INDEX 178.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-fo_ccode.

    *

    • Foreign Currency Amount

    READ TABLE temp INDEX 123.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-fo_amt.

    *

    • Foregin Currency Rate

    READ TABLE temp INDEX 66.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-fo_rate.

    *

    • Vendor

    READ TABLE temp INDEX 70.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-vendor.

    *

    • Business Unit

    READ TABLE temp INDEX 79.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-bus_unit.

    *

    • Cost Center

    IF z_service = 'Y'. "TEMPORARY

    MOVE '51400' TO itab-cost_center. "TEMPORARY

    CLEAR z_service. "TEMPORARY

    ELSE. "TEMPORARY

    READ TABLE temp INDEX 80.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-cost_center.

    ENDIF. "TEMPORARY

    *

    • Internal Order

    READ TABLE temp INDEX 83.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-int_ord.

    *

    • Car Number Detail

    READ TABLE temp INDEX 174.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-car_num_dtl.

    *

    • Business Miles Detail

    READ TABLE temp INDEX 171.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-bus_mls_dtl.

    *

    • Miles Purpose Detail

    READ TABLE temp INDEX 69.

    CHECK sy-subrc IS INITIAL.

    MOVE temp-value TO itab-mls_purp_dtl.

    APPEND itab.

    ENDIF.

    ENDIF.

    ENDLOOP.

    ENDFORM. " load_data

    &----


    *& Form download_file

    &----


    FORM download_file .

    chicago_file = p_chcgo.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    FILENAME = chicago_file

    TABLES

    DATA_TAB = chicago.

    concatenate 'C:\' sy-datum 'docnums.txt' INTO z_download.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    FILENAME = z_download

    TABLES

    DATA_TAB = doc.

    IF NOT doc[] IS INITIAL.

    WRITE:/ text-003.

    LOOP AT doc.

    WRITE:/ doc-num.

    ENDLOOP.

    ENDIF.

    concatenate 'C:\' sy-datum 'errors.txt' INTO z_download.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    FILENAME = z_download

    • FILETYPE = 'ASC'

    • WRITE_FIELD_SEPARATOR = '|'

    TABLES

    DATA_TAB = errors.

    ENDFORM. " download_file

    &----


    *& Form bdc_fb50

    &----


    FORM bdc_fb50 .

    LOOP AT itab.

    PERFORM conversions.

    PERFORM bdc_dynpro USING 'SAPMF05A' '1001'.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '=BU'.

    PERFORM bdc_field USING 'ACGL_HEAD-BLDAT'

    z_datum.

    • '04/22/07'.

    PERFORM bdc_field USING 'ACGL_HEAD-WAERS'

    itab-base_ccode.

    • 'USD'.

    PERFORM bdc_field USING 'ACGL_HEAD-BUDAT'

    z_datum.

    • '04/27/07'.

    PERFORM bdc_field USING 'ACGL_HEAD-XBLNR'

    z_xblnr.

    • 'concur ref'.

    PERFORM bdc_field USING 'ACGL_HEAD-BKTXT'

    z_bktxt.

    • 'concur header txt'.

    PERFORM bdc_field USING 'BDC_CURSOR'

    'ACGL_ITEM-AUFNR(01)'.

    PERFORM bdc_field USING 'ACGL_ITEM-HKONT(01)'

    itab-acct_num.

    • '52250'.

    PERFORM bdc_field USING 'ACGL_ITEM-HKONT(02)'

    z_hkont.

    • '20100'.

    PERFORM bdc_field USING 'ACGL_ITEM-WRBTR(01)'

    itab-entry_amta.

    • ' 100'.

    PERFORM bdc_field USING 'ACGL_ITEM-WRBTR(02)'

    itab-entry_amta.

    • ' 100'.

    PERFORM bdc_field USING 'ACGL_ITEM-SGTXT(02)'

    itab-trans_descrip.

    • 'item text'.

    PERFORM bdc_field USING 'ACGL_ITEM-KOSTL(01)'

    itab-cost_center.

    • '50020'.

    PERFORM bdc_field USING 'ACGL_ITEM-AUFNR(01)'

    itab-int_ord.

    • '30020'.

    PERFORM bdc_dynpro USING 'SAPMF05A' '1001'.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '=BU'.

    PERFORM bdc_field USING 'ACGL_HEAD-XBLNR'

    z_xblnr.

    • 'CONCUR REF'.

    PERFORM bdc_field USING 'ACGL_HEAD-BKTXT'

    z_bktxt.

    • 'concur header txt'.

    PERFORM bdc_field USING 'BDC_CURSOR'

    'ACGL_ITEM-SHKZG(01)'.

    PERFORM bdc_field USING 'ACGL_ITEM-SHKZG(01)'

    'S'.

    CALL TRANSACTION 'FB50' USING bdcdata MESSAGES INTO messtab

    MODE 'N'.

    IF sy-subrc NE 0.

    SPLIT itab AT '|' INTO TABLE errors.

    MOVE-CORRESPONDING itab TO errors.

    • SPLIT itab-data AT '|' INTO TABLE errors.

    APPEND errors.

    ENDIF.

    REFRESH bdcdata. CLEAR bdcdata.

    ENDLOOP.

    LOOP AT messtab WHERE msgnr = '312'.

    MOVE messtab-msgv1 TO doc-num.

    APPEND doc.

    ENDLOOP.

    ENDFORM. " bdc_fb50

    *----


    *

    • Start new screen

    *

    *----


    *

    FORM bdc_dynpro USING program TYPE ANY dynpro TYPE ANY.

    CLEAR bdcdata.

    bdcdata-program = program.

    bdcdata-dynpro = dynpro.

    bdcdata-dynbegin = 'X'.

    APPEND bdcdata.

    ENDFORM. "BDC_DYNPRO

    *----


    *

    • Insert field

    *

    *----


    *

    FORM bdc_field USING fnam TYPE ANY fval TYPE ANY.

    CLEAR bdcdata.

    bdcdata-fnam = fnam.

    bdcdata-fval = fval.

    APPEND bdcdata.

    ENDFORM. "BDC_FIELD

    &----


    *& Form conversions

    &----


    FORM conversions .

    IF itab-int_ord+0(1) CA z1256.

    CLEAR itab-cost_center.

    itab-acct_num = '80001'.

    ELSEIF itab-int_ord+0(1) CA zb34. "statistical orders

    itab-acct_num = '52250'.

    ENDIF.

    IF r_amex = 'X'.

    z_hkont = '20100'.

    ELSEIF r_empaid = 'X'.

    ELSEIF r_copaid = 'X'.

    ENDIF.

    WRITE: sy-datum MM/DD/YYYY TO z_datum.

    CONCATENATE itab-emp_lname0(8) itab-emp_fname0(8)

    INTO z_xblnr SEPARATED BY SPACE.

    IF r_amex = 'X'.

    CONCATENATE 'CONCUR' 'CC' sy-datum

    INTO z_bktxt SEPARATED BY SPACE.

    ELSE.

    CONCATENATE 'CONCUR' 'Cash' sy-datum

    INTO z_bktxt SEPARATED BY SPACE.

    ENDIF.

    IF itab-trans_descrip IS INITIAL.

    CONCATENATE itab-emp_lname itab-emp_fname

    INTO itab-trans_descrip SEPARATED BY SPACE.

    ENDIF.

    endform.