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: 

BDC for test mode....

Former Member
0 Kudos

Hi,

i am writing BDC for VK11 transaction. i have a check box in selection screen for test run. if i click on check box BDC should execute(for validations i.e if a condition record exist and if i run the same it will be overlap, i need to handle that message) and database tables should not be updated.

thanks for advance.

Regards,

Srikanth.

2 REPLIES 2

Former Member
0 Kudos

Hi,

You can put a check in the program to call BDC_OPEN function module and the subsequent steps only when the check box value = ' ', this should be after uploading & validating the flat file contents to Internal table using GUI_UPLOAD,

Hope this helps,

Rgds,

Former Member
0 Kudos

Hello Srikanth,

This is report which I have did to change the condition record in the simulation as well as updation mode.

REPORT z08v_ra_d_condrecupd MESSAGE-ID z08v_d

NO STANDARD PAGE HEADING

LINE-SIZE 140.

*Data Declaration

TABLES: mara,

rv13a,

vbak,

t685a,

konv,

tcurr,

tcurf,

z08v_prd_struc_price,

a004,

a703, "#EC *

mvke,

konp.

TYPE-POOLS: kcde.

DATA: w_filen_tx LIKE rlgrap-filename.

DATA: lv_filepath TYPE draw-filep. "#EC *

DATA: lv_datab LIKE rv13a-datab.

DATA: lv_datbi LIKE rv13a-datbi.

DATA: lv_newrec, lv_singrec, lv_errmsg(100).

DATA: lv_datestr(8), lv_amnt(13).

DATA: lv_sydate(8), lv_tempdat1 LIKE rv13a-datbi,

lv_tempdat2 LIKE rv13a-datbi.

  • Internal table to hold the data input from a PC file.

DATA: it_input TYPE kcde_intern WITH HEADER LINE.

DATA: BEGIN OF wa_date,

tabix LIKE sy-tabix,

kschl LIKE rv13a-kschl,

start LIKE rv13a-datab,

end LIKE rv13a-datbi,

END OF wa_date.

DATA: it_date LIKE wa_date OCCURS 0 WITH HEADER LINE.

DATA : BEGIN OF it_tcurf OCCURS 0,

kurst LIKE tcurf-kurst,

fcurr LIKE tcurf-fcurr,

tcurr LIKE tcurf-tcurr,

gdatu LIKE tcurf-gdatu,

ffact LIKE tcurf-ffact,

tfact LIKE tcurf-tfact,

xdate TYPE d,

END OF it_tcurf.

DATA : v_date(10),

lv_filecheck,

lv_count TYPE i,

lv_tempdat(8).

DATA: w_filelength_pd TYPE p,

lv_repid LIKE sy-repid,

lv_matnr LIKE mara-matnr.

DATA: lv_data_cnt(4) TYPE n VALUE 0,

w_data_bdc_recs(4) TYPE n VALUE 0.

DATA: BEGIN OF wa_output,

  • vkorg LIKE vbak-vkorg,

  • vtweg LIKE vbak-vtweg,

  • spart LIKE vbak-spart,

  • land1 LIKE kna1-land1,

matnr LIKE mara-matnr,

condtab(4),

kschl1 LIKE t685a-kschl,

  • kbetr1 LIKE konv-kbetr,

kschl2 LIKE t685a-kschl,

  • kbetr2 LIKE konv-kbetr,

  • waers LIKE konv-waers,

datab(10),

datbi(10),

kurst LIKE tcurr-kurst,

ukurs LIKE tcurr-ukurs,

kbetr LIKE konv-kbetr,

  • kbetr4 LIKE konv-kbetr,

END OF wa_output.

DATA: it_output LIKE wa_output OCCURS 0 WITH HEADER LINE.

DATA: it_extract LIKE z08v_prd_struc_price OCCURS 0 WITH HEADER LINE.

  • Internal table to hold wrong materials.

DATA: BEGIN OF it_errmat OCCURS 0,

recno TYPE i,

kschl LIKE t685a-kschl,

matnr LIKE mara-matnr,

status(15),

bdcmsg(150),

END OF it_errmat.

DATA: wa_errmat LIKE it_errmat.

    • Internal table to hold data to be used in BDC session.

*DATA: BEGIN OF it_final OCCURS 0,

  • kurst LIKE tcurr-kurst, " Exc. Rate Type

  • vdate(10) TYPE c, " Valid from Date

  • ukurs LIKE tcurr-ukurs, " Indirect Quote rate

  • fcurr LIKE tcurr-fcurr, " From Currency

  • tcurr LIKE tcurr-tcurr, " To Currency

  • ffact LIKE tcurf-ffact, " From factor

  • tfact LIKE tcurf-tfact, " To Factor

  • END OF it_final.

  • Internal table to hold the BDC data.

DATA: BEGIN OF bdcdata OCCURS 1000.

INCLUDE STRUCTURE bdcdata.

DATA: END OF bdcdata.

DATA: it_msgtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

DATA: wa_msglog LIKE msg_log.

DATA: wa_msgtxt LIKE msg_text.

----


  • SELECTION SCREEN

----


SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-001.

PARAMETERS: p_fpath LIKE ibipparms-path OBLIGATORY,

p_sim AS CHECKBOX.

SELECTION-SCREEN END OF BLOCK bl1.

----


  • Initialization

----


INITIALIZATION.

lv_repid = sy-repid.

----


  • AT SELECTION-SCREEN

----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fpath.

CALL FUNCTION 'WS_FILENAME_GET' "#EC *

EXPORTING

def_filename = ' '

def_path = 'c:\'

mask = ',.,..'

mode = 'O'

title = text-016

IMPORTING

filename = p_fpath

EXCEPTIONS

OTHERS.

IF sy-subrc EQ 0. "Only if name has been changed,

w_filen_tx = p_fpath. "copy the new name

ENDIF. .

----


  • AT SELECTION-SCREEN ON field

----


AT SELECTION-SCREEN ON p_fpath.

CLEAR lv_filepath.

MOVE p_fpath TO lv_filepath.

CALL FUNCTION 'CV120_DOC_FILE_EXISTENCE_CHECK'

EXPORTING

  • PF_HOSTNAME =

  • PF_DTTRG =

pf_file = lv_filepath

IMPORTING

pfx_exist = lv_filecheck

EXCEPTIONS

error = 1

OTHERS = 2

.

IF lv_filecheck <> 'X'.

MESSAGE i003 WITH text-003.

EXIT.

ENDIF.

----


  • START OF SELECTION

----


START-OF-SELECTION.

  • Upload the input data.

PERFORM file_upload.

  • Check the uploaded data.

PERFORM check_data.

----


  • END OF SELECTION

----


END-OF-SELECTION.

IF p_sim <> 'X'.

FORMAT COLOR 3.

WRITE:/5 text-002, w_data_bdc_recs.

FORMAT COLOR OFF.

ENDIF.

ULINE.

TOP-OF-PAGE.

ULINE.

FORMAT COLOR 1.

WRITE:/ 'Program : ', lv_repid. "#EC NOTEXT

WRITE:/ 'Title : ', sy-title. "#EC NOTEXT

WRITE:/ 'User : ', sy-uname, 115 'Date : ', sy-datum."#EC NOTEXT

WRITE:/115 'Page : ', sy-pagno. "#EC NOTEXT

FORMAT COLOR OFF.

ULINE.

IF p_sim = 'X'.

FORMAT COLOR 2.

WRITE:/ text-005.

SKIP.

WRITE:/ text-006, 16 text-007, 30 text-008, 50 text-009, 74 text-010,

90 text-011, 102 text-012, 114 text-013.

FORMAT COLOR OFF.

ULINE.

ELSE.

FORMAT COLOR 2.

WRITE:/ text-022.

SKIP.

WRITE:/ text-023, 15 text-006, 31 text-008, 53 text-024,

65 text-025.

FORMAT COLOR OFF.

ULINE.

ENDIF.

END-OF-PAGE.

ULINE.

&----


*& Form FILE_UPLOAD

&----


  • Upload the file

----


FORM file_upload.

CLEAR it_extract.

REFRESH it_extract.

*download the excel data into an internal table

CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'

EXPORTING

filename = w_filen_tx

i_begin_col = 1

i_begin_row = 2

i_end_col = 13

i_end_row = 65536

TABLES

intern = it_input

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE e003 WITH text-004.

ENDIF.

LOOP AT it_input.

IF it_input-col = '1'.

it_extract-vkorg = it_input-value.

ENDIF.

IF it_input-col = '2'.

it_extract-vtweg = it_input-value.

ENDIF.

IF it_input-col = '3'.

it_extract-spart = it_input-value.

ENDIF.

IF it_input-col = '4'.

it_extract-land1 = it_input-value.

ENDIF.

IF it_input-col = '5'.

it_extract-matnr = it_input-value.

ENDIF.

IF it_input-col = '6'.

it_extract-kschl1 = it_input-value.

ENDIF.

IF it_input-col = '7'.

it_extract-kbetr1 = it_input-value.

ENDIF.

IF it_input-col = '8'.

it_extract-kschl2 = it_input-value.

ENDIF.

IF it_input-col = '9'.

it_extract-kbetr2 = it_input-value.

ENDIF.

IF it_input-col = '10'.

it_extract-waers = it_input-value.

ENDIF.

IF it_input-col = '11'.

REPLACE ALL OCCURRENCES OF '.' IN it_input-value WITH ''.

CONDENSE it_input-value NO-GAPS.

  • it_extract-datab+6(2) = it_input-value(2).

  • it_extract-datab4(2) = it_input-value2(2).

  • it_extract-datab(4) = it_input-value+4(4).

it_extract-datab = it_input-value.

ENDIF.

IF it_input-col = '12'.

REPLACE ALL OCCURRENCES OF '.' IN it_input-value WITH ''.

CONDENSE it_input-value NO-GAPS.

  • it_extract-datbi+6(2) = it_input-value(2).

  • it_extract-datbi4(2) = it_input-value2(2).

  • it_extract-datbi(4) = it_input-value+4(4).

it_extract-datbi = it_input-value.

ENDIF.

IF it_input-col = '13'.

it_extract-kurst = it_input-value.

ENDIF.

IF it_input-col = '14'.

it_extract-ukurs = it_input-value.

ENDIF.

IF it_input-col = '15'.

it_extract-kbetr3 = it_input-value.

ENDIF.

IF it_input-col = '16'.

it_extract-kbetr4 = it_input-value.

ENDIF.

AT END OF row.

APPEND it_extract.

CLEAR it_extract.

ENDAT.

ENDLOOP.

  • Count the valid records input.

CLEAR lv_data_cnt.

LOOP AT it_extract.

ADD 1 TO lv_data_cnt.

ENDLOOP.

  • Getting the condition value using table TCURR and TCURF

LOOP AT it_extract.

  • Condition value

IF it_extract-waers <> 'EUR'.

CLEAR lv_datestr.

lv_datestr = 99999999 - sy-datum.

SELECT SINGLE * FROM tcurr WHERE

kurst = it_extract-kurst AND

fcurr = it_extract-waers AND

tcurr = 'EUR' AND

gdatu <= lv_datestr. "#EC PORTABLE

IF sy-subrc = 0.

SELECT * INTO CORRESPONDING FIELDS OF TABLE it_tcurf

FROM tcurf

WHERE kurst = it_extract-kurst

AND ( fcurr = 'EUR' OR fcurr = it_extract-waers )

AND ( tcurr = it_extract-waers OR tcurr = 'EUR' ).

IF sy-subrc = 0.

LOOP AT it_tcurf.

CALL FUNCTION 'CONVERSION_EXIT_INVDT_OUTPUT'

EXPORTING

input = it_tcurf-gdatu

IMPORTING

output = v_date

EXCEPTIONS

OTHERS = 1.

it_tcurf-xdate0(4) = v_date6(4).

it_tcurf-xdate4(2) = v_date3(2).

it_tcurf-xdate6(2) = v_date0(2).

IF it_tcurf-gdatu <= lv_datestr. "#EC PORTABLE

MODIFY it_tcurf.

ELSE.

DELETE it_tcurf.

ENDIF.

ENDLOOP.

SORT it_tcurf BY kurst fcurr tcurr ASCENDING

xdate DESCENDING.

  • Get only the latest value for each currency conversion

DELETE ADJACENT DUPLICATES FROM it_tcurf

COMPARING kurst tcurr.

READ TABLE it_tcurf WITH KEY kurst = it_extract-kurst

fcurr = it_extract-waers

tcurr = 'EUR'.

IF sy-subrc NE 0. " If no conversion factor table exists

EXIT.

ENDIF.

it_extract-ukurs = tcurr-ukurs / it_tcurf-tfact.

it_extract-kbetr3 = it_extract-kbetr1 * it_extract-ukurs.

it_extract-kbetr4 = it_extract-kbetr2 * it_extract-ukurs.

MODIFY it_extract.

ENDIF.

ENDIF.

ELSE.

it_extract-kbetr3 = it_extract-kbetr1.

it_extract-kbetr4 = it_extract-kbetr2.

MODIFY it_extract.

ENDIF.

ENDLOOP.

ENDFORM. " FILE_UPLOAD

----


  • Form CHECK_DATA

----


  • Validate the input data

----


FORM check_data.

CLEAR: it_extract, it_errmat.

REFRESH: it_errmat.

IF p_sim <> 'X'.

CLEAR lv_count.

LOOP AT it_extract.

lv_count = lv_count + 1.

IF it_extract-land1 IS INITIAL.

PERFORM bdc_004.

ELSE.

PERFORM bdc_703.

ENDIF.

ENDLOOP.

CLEAR lv_count.

PERFORM upd_rec_output.

ELSE.

PERFORM sim_log.

ENDIF.

ENDFORM. " CHECK_DATA

&----


*& Form BDC_DYNPRO

&----


  • Text : Starts a new screen in the BDC table

  • This routine should be called for each new screen

  • encountered during the dialog processing.

  • All data relating to the screen should be entered using

  • BDC_FIELD immediately after this routine.

----


FORM bdc_dynpro

USING value(program)

value(dynpro).

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM. "BDC_DYNPRO

&----


*& Form BDC_FIELD

&----


  • Text : Adds screen data to the BDC table

  • Just nominate the field name, and data to populate the

  • field. You can also use BDC_CURSOR and BDC_OKCODE.

----


FORM bdc_field

USING value(fnam)

value(fval).

  • Exit if field value is blank

CHECK NOT fval IS INITIAL.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM. "BDC_FIELD

&----


*& Form bdc_004

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM bdc_004 .

*check whether record exists in A004.

IF NOT it_extract-kschl1 IS INITIAL.

SELECT SINGLE * FROM a004

WHERE kappl = 'V'

AND kschl = it_extract-kschl1

AND vkorg = it_extract-vkorg

AND vtweg = it_extract-vtweg

AND matnr = it_extract-matnr

AND datbi >= sy-datum

AND datab <= sy-datum.

IF sy-subrc = 0.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR: lv_tempdat1, lv_tempdat2.

lv_tempdat1+6(2) = it_extract-datab(2).

lv_tempdat14(2) = it_extract-datab2(2).

lv_tempdat1(4) = it_extract-datab+4(4).

lv_tempdat2+6(2) = it_extract-datbi(2).

lv_tempdat24(2) = it_extract-datbi2(2).

lv_tempdat2(4) = it_extract-datbi+4(4).

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

*Case 1

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

IF lv_tempdat1 > a004-datab AND

lv_tempdat1 < a004-datbi AND

lv_tempdat2 >= a004-datbi.

*changing the existing record wherein 'Valid to' date is changed to

*'From date - 1'. Here 'From date' is from input file.

CLEAR lv_datab.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

  • PERFORM bdc_field USING 'KONP-KBETR(01)' it_extract-kbetr3.

lv_datab = lv_tempdat1.

SUBTRACT 1 FROM lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATBI(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 1

PERFORM new_record_a004.

*case 2

*if validity period coincide, then just change the amount.

ELSEIF lv_tempdat1 = a004-datab AND

lv_tempdat2 = a004-datbi.

CLEAR lv_datab.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

CLEAR lv_amnt.

MOVE it_extract-kbetr3 TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

CLEAR lv_amnt.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

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

*Case 3 *

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

ELSEIF lv_tempdat1 > a004-datab AND

lv_tempdat1 < a004-datbi AND

lv_tempdat2 < a004-datbi.

CLEAR lv_datab.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

  • PERFORM bdc_field USING 'KONP-KBETR(01)' it_extract-kbetr3.

MOVE lv_tempdat1 TO lv_datab.

SUBTRACT 1 FROM lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATBI(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

  • second record in case 3

PERFORM new_record_a004.

  • third record in case 3

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F003-LOW'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_datab.

lv_datab = lv_tempdat2.

ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'SEL_DATE' lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM bdc_field USING 'KOMG-VKORG' it_extract-vkorg.

PERFORM bdc_field USING 'KOMG-VTWEG' it_extract-vtweg.

PERFORM bdc_field USING 'KOMG-MATNR(01)' it_extract-matnr.

CLEAR lv_amnt.

SELECT SINGLE * FROM konp WHERE

knumh = a004-knumh AND

kopos = '01'.

IF sy-subrc = 0.

MOVE konp-kbetr TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

ENDIF.

CLEAR lv_amnt.

PERFORM bdc_field USING 'KONP-KONWA(01)' 'EUR'.

IF NOT it_extract-datab IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

ELSE.

PERFORM bdc_field USING 'RV13A-DATAB(01)' sy-datum.

ENDIF.

IF NOT it_extract-datbi IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATBI(01)' a004-datbi.

ELSE.

PERFORM bdc_field USING 'RV13A-DATBI(01)' '31.12.9999'.

ENDIF.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

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

*case 4

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

ELSEIF lv_tempdat1 < a004-datab AND

lv_tempdat2 > a004-datab AND

lv_tempdat2 < a004-datbi.

CLEAR lv_datab.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

  • PERFORM bdc_field USING 'KONP-KBETR(01)' it_extract-kbetr3.

lv_datab = lv_tempdat2.

ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 4

PERFORM new_record_a004.

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

*case 5

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

ELSEIF lv_tempdat1 < a004-datab AND

lv_tempdat2 < a004-datab.

PERFORM new_record_a004.

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

*case 6

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

ELSEIF lv_tempdat1 > a004-datab AND

lv_tempdat2 > a004-datab.

PERFORM new_record_a004.

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

  • Case 7

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

ELSEIF lv_tempdat1 > a004-datab AND

lv_tempdat1 < a004-datbi.

*changing the existing record wherein 'Valid from' date is changed to

*'From date + 1'. Here 'To date' is from input file.

CLEAR lv_datab.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

  • PERFORM bdc_field USING 'KONP-KBETR(01)' it_extract-kbetr3.

lv_datab = lv_tempdat1.

ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 7

PERFORM new_record_a004.

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

  • Case 8

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

ELSEIF lv_tempdat1 < a004-datab AND

lv_tempdat2 = a004-datbi.

*changing the existing record wherein 'Valid from' date is changed to

*'From date + 1'. Here 'To date' is from input file.

CLEAR lv_datab.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM bdc_field USING 'KONP-KBETR(01)' it_extract-kbetr3.

lv_datab = lv_tempdat1.

  • ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 8

PERFORM new_record_a004.

ENDIF.

CLEAR: lv_tempdat1, lv_tempdat2.

ELSE.

*Totally new record as no record found in table A004.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F003-LOW'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM bdc_field USING 'KOMG-VKORG' it_extract-vkorg.

PERFORM bdc_field USING 'KOMG-VTWEG' it_extract-vtweg.

PERFORM bdc_field USING 'KOMG-MATNR(01)' it_extract-matnr.

CLEAR lv_amnt.

MOVE it_extract-kbetr3 TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

CLEAR lv_amnt.

PERFORM bdc_field USING 'KONP-KONWA(01)' 'EUR'.

IF NOT it_extract-datab IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATAB(01)' it_extract-datab.

ELSE.

PERFORM bdc_field USING 'RV13A-DATAB(01)' sy-datum.

ENDIF.

IF NOT it_extract-datbi IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATBI(01)' it_extract-datbi.

ELSE.

PERFORM bdc_field USING 'RV13A-DATBI(01)' '31.12.9999'.

ENDIF.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

ENDIF.

ENDIF.

IF NOT it_extract-kschl2 IS INITIAL.

*for the condition ZKDT

SELECT SINGLE * FROM a004

WHERE kappl = 'V'

AND kschl = it_extract-kschl2

AND vkorg = it_extract-vkorg

AND vtweg = it_extract-vtweg

AND matnr = it_extract-matnr

AND datbi >= sy-datum

AND datab <= sy-datum.

IF sy-subrc = 0.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR: lv_tempdat1, lv_tempdat2.

lv_tempdat1+6(2) = it_extract-datab(2).

lv_tempdat14(2) = it_extract-datab2(2).

lv_tempdat1(4) = it_extract-datab+4(4).

lv_tempdat2+6(2) = it_extract-datbi(2).

lv_tempdat24(2) = it_extract-datbi2(2).

lv_tempdat2(4) = it_extract-datbi+4(4).

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

*Case 1

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

IF lv_tempdat1 = a004-datab AND

lv_tempdat2 < a004-datbi AND

lv_tempdat2 >= a004-datbi.

*changing the existing record wherein 'Valid to' date is changed to

*'From date - 1'. Here 'From date' is from input file.

CLEAR lv_datab.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl2.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

  • PERFORM bdc_field USING 'KONP-KBETR(01)' it_extract-kbetr3.

lv_datab = lv_tempdat1.

SUBTRACT 1 FROM lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATBI(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 1

PERFORM new_record_a004_2.

*case 2

*if validity period coincide, then just change the amount.

ELSEIF lv_tempdat1 = a004-datab AND

lv_tempdat2 = a004-datbi.

CLEAR lv_datab.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl2.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

CLEAR lv_amnt.

MOVE it_extract-kbetr4 TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

CLEAR lv_amnt.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

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

*Case 3 *

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

ELSEIF lv_tempdat1 > a004-datab AND

lv_tempdat1 < a004-datbi AND

lv_tempdat2 < a004-datbi.

CLEAR lv_datab.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl2.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

  • PERFORM bdc_field USING 'KONP-KBETR(01)' it_extract-kbetr3.

lv_datab = lv_tempdat1.

SUBTRACT 1 FROM lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATBI(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

  • second record in case 3

PERFORM new_record_a004_2.

  • third record in case 3

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl2.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F003-LOW'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_datab.

lv_datab = lv_tempdat2.

ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'SEL_DATE' lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM bdc_field USING 'KOMG-VKORG' it_extract-vkorg.

PERFORM bdc_field USING 'KOMG-VTWEG' it_extract-vtweg.

PERFORM bdc_field USING 'KOMG-MATNR(01)' it_extract-matnr.

SELECT SINGLE * FROM konp WHERE

knumh = a004-knumh AND

kopos = '01'.

IF sy-subrc = 0.

CLEAR lv_amnt.

MOVE konp-kbetr TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

ENDIF.

CLEAR lv_amnt.

PERFORM bdc_field USING 'KONP-KONWA(01)' 'EUR'.

IF NOT it_extract-datab IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

ELSE.

PERFORM bdc_field USING 'RV13A-DATAB(01)' sy-datum.

ENDIF.

IF NOT it_extract-datbi IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATBI(01)' a004-datbi.

ELSE.

PERFORM bdc_field USING 'RV13A-DATBI(01)' '31.12.9999'.

ENDIF.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

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

*case 4

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

ELSEIF lv_tempdat1 < a004-datab AND

lv_tempdat2 > a004-datab AND

lv_tempdat2 < a004-datbi.

CLEAR lv_datab.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl2.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

  • PERFORM bdc_field USING 'KONP-KBETR(01)' it_extract-kbetr3.

lv_datab = lv_tempdat2.

ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 4

PERFORM new_record_a004_2.

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

*case 5

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

ELSEIF lv_tempdat1 < a004-datab AND

lv_tempdat2 < a004-datab.

PERFORM new_record_a004_2.

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

*case 6

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

ELSEIF lv_tempdat1 > a004-datab AND

lv_tempdat2 > a004-datab.

PERFORM new_record_a004_2.

  • ELSE.

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

  • Case 7

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

ELSEIF lv_tempdat1 > a004-datab AND

lv_tempdat1 < a004-datbi.

*changing the existing record wherein 'Valid from' date is changed to

*'From date + 1'. Here 'To date' is from input file.

CLEAR lv_datab.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

  • PERFORM bdc_field USING 'KONP-KBETR(01)' it_extract-kbetr3.

lv_datab = lv_tempdat1.

ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 7

PERFORM new_record_a004.

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

  • Case 8

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

ELSEIF lv_tempdat1 < a004-datab AND

lv_tempdat2 = a004-datbi.

*changing the existing record wherein 'Valid from' date is changed to

*'From date + 1'. Here 'To date' is from input file.

CLEAR lv_datab.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl2.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F001'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM bdc_field USING 'KONP-KBETR(01)' it_extract-kbetr4.

lv_datab = lv_tempdat1.

  • ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 8

PERFORM new_record_a004.

ENDIF.

ELSE.

CLEAR: lv_tempdat1, lv_tempdat2.

*Totally new record as no record found in table A004.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl2.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F003-LOW'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM bdc_field USING 'KOMG-VKORG' it_extract-vkorg.

PERFORM bdc_field USING 'KOMG-VTWEG' it_extract-vtweg.

PERFORM bdc_field USING 'KOMG-MATNR(01)' it_extract-matnr.

CLEAR lv_amnt.

MOVE it_extract-kbetr4 TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

CLEAR lv_amnt.

PERFORM bdc_field USING 'KONP-KONWA(01)' 'EUR'.

IF NOT it_extract-datab IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATAB(01)' it_extract-datab.

ELSE.

PERFORM bdc_field USING 'RV13A-DATAB(01)' sy-datum.

ENDIF.

IF NOT it_extract-datbi IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATBI(01)' it_extract-datbi.

ELSE.

PERFORM bdc_field USING 'RV13A-DATBI(01)' '31.12.9999'.

ENDIF.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

ENDIF.

ENDIF.

ENDFORM. " bdc_004

&----


*& Form bdc_703

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM bdc_703 .

*check whether record exists in A703.

IF NOT it_extract-kschl1 IS INITIAL.

SELECT SINGLE * FROM a703

WHERE kappl = 'V'

AND kschl = it_extract-kschl1

AND vkorg = it_extract-vkorg

AND vtweg = it_extract-vtweg

AND spart = it_extract-spart

AND land1 = it_extract-land1

AND matnr = it_extract-matnr

AND datbi >= sy-datum

AND datab <= sy-datum.

IF sy-subrc = 0.

CLEAR bdcdata.

CLEAR: lv_tempdat1, lv_tempdat2.

lv_tempdat1+6(2) = it_extract-datab(2).

lv_tempdat14(2) = it_extract-datab2(2).

lv_tempdat1(4) = it_extract-datab+4(4).

lv_tempdat2+6(2) = it_extract-datbi(2).

lv_tempdat24(2) = it_extract-datbi2(2).

lv_tempdat2(4) = it_extract-datbi+4(4).

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

*Case 1

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

IF lv_tempdat1 > a703-datab AND

lv_tempdat1 < a703-datbi AND

lv_tempdat2 >= a703-datbi.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

lv_datab = lv_tempdat1.

SUBTRACT 1 FROM lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATBI(01)' lv_datab.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 1

PERFORM new_record_a703.

*case 2

*if validity period coincide, then just change the amount.

ELSEIF lv_tempdat1 = a703-datab AND

lv_tempdat2 = a703-datbi.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

  • lv_datab = lv_tempdat1.

  • SUBTRACT 1 FROM lv_datab.

  • CLEAR lv_tempdat.

  • lv_tempdat(2) = lv_datab+6(2).

  • lv_tempdat2(2) = lv_datab4(2).

  • lv_tempdat+4(4) = lv_datab(4).

  • lv_datab = lv_tempdat.

  • CLEAR lv_tempdat.

  • PERFORM bdc_field USING 'RV13A-DATBI(01)' lv_datab.

CLEAR lv_amnt.

MOVE it_extract-kbetr3 TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

CLEAR lv_amnt.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

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

*Case 3 *

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

ELSEIF lv_tempdat1 > a703-datab AND

lv_tempdat1 < a703-datbi AND

lv_tempdat2 < a703-datbi.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

lv_datab = lv_tempdat1.

SUBTRACT 1 FROM lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATBI(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 3

PERFORM new_record_a703.

*third record in case 3

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_datab.

lv_datab = lv_tempdat2.

ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'SEL_DATE' lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM bdc_field USING 'KOMG-VKORG' it_extract-vkorg.

PERFORM bdc_field USING 'KOMG-VTWEG' it_extract-vtweg.

PERFORM bdc_field USING 'KOMG-SPART' it_extract-spart.

PERFORM bdc_field USING 'KOMG-LAND1' it_extract-land1.

PERFORM bdc_field USING 'KOMG-MATNR(01)' it_extract-matnr.

SELECT SINGLE * FROM konp WHERE

knumh = a703-knumh AND

kopos = '01'.

IF sy-subrc = 0.

CLEAR lv_amnt.

MOVE konp-kbetr TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

ENDIF.

CLEAR lv_amnt.

PERFORM bdc_field USING 'KONP-KONWA(01)' 'EUR'.

IF NOT it_extract-datab IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

ELSE.

PERFORM bdc_field USING 'RV13A-DATAB(01)' sy-datum.

ENDIF.

IF NOT it_extract-datbi IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATBI(01)' a703-datbi.

ELSE.

PERFORM bdc_field USING 'RV13A-DATBI(01)' '31.12.9999'.

ENDIF.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

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

*case 4

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

ELSEIF lv_tempdat1 < a703-datab AND

lv_tempdat2 > a703-datab AND

lv_tempdat2 < a703-datbi.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

lv_datab = lv_tempdat2.

ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 4

PERFORM new_record_a703.

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

*case 5

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

ELSEIF lv_tempdat1 < a703-datab AND

lv_tempdat2 < a703-datab.

PERFORM new_record_a703.

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

*case 6

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

ELSEIF lv_tempdat1 > a703-datab AND

lv_tempdat2 > a703-datab.

SELECT SINGLE * FROM a703

WHERE kappl = 'V'

AND kschl = it_extract-kschl1

AND vkorg = it_extract-vkorg

AND vtweg = it_extract-vtweg

AND spart = it_extract-spart

AND land1 = it_extract-land1

AND matnr = it_extract-matnr

AND datab <= lv_tempdat1

AND datbi >= lv_tempdat2.

IF sy-subrc = 0.

IF lv_tempdat1 = a703-datab AND

lv_tempdat2 = a703-datbi.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

  • lv_datab = lv_tempdat1.

  • SUBTRACT 1 FROM lv_datab.

  • CLEAR lv_tempdat.

  • lv_tempdat(2) = lv_datab+6(2).

  • lv_tempdat2(2) = lv_datab4(2).

  • lv_tempdat+4(4) = lv_datab(4).

  • lv_datab = lv_tempdat.

  • CLEAR lv_tempdat.

  • PERFORM bdc_field USING 'RV13A-DATBI(01)' lv_datab.

CLEAR lv_amnt.

MOVE it_extract-kbetr3 TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

CLEAR lv_amnt.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

ENDIF.

ELSE.

PERFORM new_record_a703.

ENDIF.

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

*Case 7

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

ELSEIF lv_tempdat1 = a703-datab AND

lv_tempdat2 < a703-datbi.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

lv_datab = lv_tempdat1.

ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 7

PERFORM new_record_a703.

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

*Case 8

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

ELSEIF lv_tempdat1 < a703-datab AND

lv_tempdat2 = a703-datbi.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

lv_datab = lv_tempdat1.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 8

PERFORM new_record_a703.

ENDIF.

ELSE.

CLEAR: lv_tempdat1, lv_tempdat2.

*Totally new record.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM bdc_field USING 'KOMG-VKORG' it_extract-vkorg.

PERFORM bdc_field USING 'KOMG-VTWEG' it_extract-vtweg.

PERFORM bdc_field USING 'KOMG-SPART' it_extract-spart.

PERFORM bdc_field USING 'KOMG-LAND1' it_extract-land1.

PERFORM bdc_field USING 'KOMG-MATNR(01)' it_extract-matnr.

CLEAR lv_amnt.

MOVE it_extract-kbetr3 TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

CLEAR lv_amnt.

PERFORM bdc_field USING 'KONP-KONWA(01)' 'EUR'.

IF NOT it_extract-datab IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATAB(01)' it_extract-datab.

ELSE.

PERFORM bdc_field USING 'RV13A-DATAB(01)' sy-datum.

ENDIF.

IF NOT it_extract-datbi IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATBI(01)' it_extract-datbi.

ELSE.

PERFORM bdc_field USING 'RV13A-DATBI(01)' '31.12.9999'.

ENDIF.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

ENDIF.

ENDIF.

IF NOT it_extract-kschl2 IS INITIAL.

  • For the condition ZKDT

SELECT SINGLE * FROM a703

WHERE kappl = 'V'

AND kschl = it_extract-kschl2

AND vkorg = it_extract-vkorg

AND vtweg = it_extract-vtweg

AND spart = it_extract-spart

AND land1 = it_extract-land1

AND matnr = it_extract-matnr

AND datbi >= sy-datum

AND datab <= sy-datum.

IF sy-subrc = 0.

CLEAR bdcdata.

CLEAR: lv_tempdat1, lv_tempdat2.

lv_tempdat1+6(2) = it_extract-datab(2).

lv_tempdat14(2) = it_extract-datab2(2).

lv_tempdat1(4) = it_extract-datab+4(4).

lv_tempdat2+6(2) = it_extract-datbi(2).

lv_tempdat24(2) = it_extract-datbi2(2).

lv_tempdat2(4) = it_extract-datbi+4(4).

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

*Case 1

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

IF lv_tempdat1 > a703-datab AND

lv_tempdat1 < a703-datbi AND

lv_tempdat2 >= a703-datbi.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl2.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

lv_datab = lv_tempdat1.

SUBTRACT 1 FROM lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATBI(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 1

PERFORM new_record_a703_2.

*case 2

*if validity period coincide, then just change the amount.

ELSEIF lv_tempdat1 = a703-datab AND

lv_tempdat2 = a703-datbi.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

  • lv_datab = lv_tempdat1.

  • SUBTRACT 1 FROM lv_datab.

  • CLEAR lv_tempdat.

  • lv_tempdat(2) = lv_datab+6(2).

  • lv_tempdat2(2) = lv_datab4(2).

  • lv_tempdat+4(4) = lv_datab(4).

  • lv_datab = lv_tempdat.

  • CLEAR lv_tempdat.

  • PERFORM bdc_field USING 'RV13A-DATBI(01)' lv_datab.

CLEAR lv_amnt.

MOVE it_extract-kbetr4 TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

CLEAR lv_amnt.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

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

*Case 3 *

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

ELSEIF lv_tempdat1 > a703-datab AND

lv_tempdat1 < a703-datbi AND

lv_tempdat2 < a703-datbi.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl2.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

lv_datab = lv_tempdat1.

SUBTRACT 1 FROM lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATBI(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 3

PERFORM new_record_a703_2.

*third record in case 3

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl2.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_datab.

lv_datab = lv_tempdat2.

ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'SEL_DATE' lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM bdc_field USING 'KOMG-VKORG' it_extract-vkorg.

PERFORM bdc_field USING 'KOMG-VTWEG' it_extract-vtweg.

PERFORM bdc_field USING 'KOMG-SPART' it_extract-spart.

PERFORM bdc_field USING 'KOMG-LAND1' it_extract-land1.

PERFORM bdc_field USING 'KOMG-MATNR(01)' it_extract-matnr.

SELECT SINGLE * FROM konp WHERE

knumh = a703-knumh AND

kopos = '01'.

IF sy-subrc = 0.

CLEAR lv_amnt.

MOVE konp-kbetr TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

ENDIF.

CLEAR lv_amnt.

PERFORM bdc_field USING 'KONP-KONWA(01)' 'EUR'.

IF NOT it_extract-datab IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

ELSE.

PERFORM bdc_field USING 'RV13A-DATAB(01)' sy-datum.

ENDIF.

IF NOT it_extract-datbi IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATBI(01)' a703-datbi.

ELSE.

PERFORM bdc_field USING 'RV13A-DATBI(01)' '31.12.9999'.

ENDIF.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

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

*case 4

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

ELSEIF lv_tempdat1 < a703-datab AND

lv_tempdat2 > a703-datab AND

lv_tempdat2 < a703-datbi.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl2.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

lv_datab = lv_tempdat2.

ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 4

PERFORM new_record_a703_2.

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

*case 5

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

ELSEIF lv_tempdat1 < a703-datab AND

lv_tempdat2 < a703-datab.

PERFORM new_record_a703_2.

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

*case 6

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

ELSEIF lv_tempdat1 > a703-datab AND

lv_tempdat2 > a703-datab.

PERFORM new_record_a703_2.

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

*Case 7

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

ELSEIF lv_tempdat1 = a703-datab AND

lv_tempdat2 < a703-datbi.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

lv_datab = lv_tempdat1.

ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 7

PERFORM new_record_a703.

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

*Case 8

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

ELSEIF lv_tempdat1 < a703-datab AND

lv_tempdat2 = a703-datbi.

REFRESH bdcdata.

CLEAR bdcdata.

CLEAR lv_datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

lv_datab = lv_tempdat1.

  • ADD 1 TO lv_datab.

CLEAR lv_tempdat.

lv_tempdat(2) = lv_datab+6(2).

lv_tempdat2(2) = lv_datab4(2).

lv_tempdat+4(4) = lv_datab(4).

lv_datab = lv_tempdat.

CLEAR lv_tempdat.

PERFORM bdc_field USING 'RV13A-DATAB(01)' lv_datab.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

*second record in case 8

PERFORM new_record_a703.

ENDIF.

ELSE.

CLEAR: lv_tempdat1, lv_tempdat2.

*Totally new record.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl2.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

CLEAR lv_sydate.

lv_sydate(2) = sy-datum+6(2).

lv_sydate2(2) = sy-datum4(2).

lv_sydate+4(4) = sy-datum(4).

PERFORM bdc_field USING 'SEL_DATE' lv_sydate.

CLEAR lv_sydate.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM bdc_field USING 'KOMG-VKORG' it_extract-vkorg.

PERFORM bdc_field USING 'KOMG-VTWEG' it_extract-vtweg.

PERFORM bdc_field USING 'KOMG-SPART' it_extract-spart.

PERFORM bdc_field USING 'KOMG-LAND1' it_extract-land1.

PERFORM bdc_field USING 'KOMG-MATNR(01)' it_extract-matnr.

CLEAR lv_amnt.

MOVE it_extract-kbetr4 TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

CLEAR lv_amnt.

PERFORM bdc_field USING 'KONP-KONWA(01)' 'EUR'.

IF NOT it_extract-datab IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATAB(01)' it_extract-datab.

ELSE.

PERFORM bdc_field USING 'RV13A-DATAB(01)' sy-datum.

ENDIF.

IF NOT it_extract-datbi IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATBI(01)' it_extract-datbi.

ELSE.

PERFORM bdc_field USING 'RV13A-DATBI(01)' '31.12.9999'.

ENDIF.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'A'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

ENDIF.

ENDIF.

ENDFORM. " bdc_703

&----


*& Form sim_log

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sim_log .

CLEAR lv_count.

LOOP AT it_extract.

CLEAR it_output.

CLEAR lv_newrec.

CLEAR lv_datab.

CLEAR lv_singrec.

CLEAR it_date.

REFRESH it_date.

lv_count = lv_count + 1.

*For condition ZKDK

IF NOT it_extract-kschl1 IS INITIAL.

it_output-kschl1 = it_extract-kschl1.

IF it_extract-land1 IS INITIAL.

it_output-condtab = 'A004'.

SELECT SINGLE * FROM a004

WHERE kappl = 'V'

AND kschl = it_extract-kschl1

AND vkorg = it_extract-vkorg

AND vtweg = it_extract-vtweg

AND matnr = it_extract-matnr

AND datbi >= sy-datum

AND datab <= sy-datum.

IF sy-subrc <> 0.

lv_newrec = 'X'.

ELSE.

CLEAR: lv_tempdat1, lv_tempdat2.

lv_tempdat1+6(2) = it_extract-datab(2).

lv_tempdat14(2) = it_extract-datab2(2).

lv_tempdat1(4) = it_extract-datab+4(4).

lv_tempdat2+6(2) = it_extract-datbi(2).

lv_tempdat24(2) = it_extract-datbi2(2).

lv_tempdat2(4) = it_extract-datbi+4(4).

  • case 1

IF a004-datab = lv_tempdat1 AND a004-datbi = lv_tempdat2.

lv_singrec = 'X'.

  • case 2

ELSEIF lv_tempdat1 > a004-datab AND

lv_tempdat1 < a004-datbi AND

lv_tempdat2 >= a004-datbi.

  • first record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl1.

it_date-start+4(4) = a004-datab(4).

it_date-start2(2) = a004-datab4(2).

it_date-start(2) = a004-datab+6(2).

lv_datbi = lv_tempdat1.

SUBTRACT 1 FROM lv_datbi.

it_date-end+4(4) = lv_datbi(4).

it_date-end2(2) = lv_datbi4(2).

it_date-end(2) = lv_datbi+6(2).

APPEND it_date.

  • second record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl1.

it_date-start = it_extract-datab.

it_date-end = it_extract-datbi.

APPEND it_date.

  • case 3

ELSEIF lv_tempdat1 > a004-datab AND

lv_tempdat1 < a004-datbi AND

lv_tempdat2 < a004-datbi.

  • first record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl1.

it_date-start+4(4) = a004-datab(4).

it_date-start2(2) = a004-datab4(2).

it_date-start(2) = a004-datab+6(2).

lv_datbi = lv_tempdat1.

SUBTRACT 1 FROM lv_datbi.

it_date-end+4(4) = lv_datbi(4).

it_date-end2(2) = lv_datbi4(2).

it_date-end(2) = lv_datbi+6(2).

APPEND it_date.

  • second record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl1.

it_date-start = it_extract-datab.

it_date-end = it_extract-datbi.

APPEND it_date.

  • third record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl1.

lv_datab = lv_tempdat1.

ADD 1 TO lv_datab.

it_date-start+4(4) = lv_datab(4).

it_date-start2(2) = lv_datab4(2).

it_date-start(2) = lv_datab+6(2).

it_date-end+4(4) = a004-datbi(4).

it_date-end2(2) = a004-datbi4(2).

it_date-end(2) = a004-datbi+6(2).

APPEND it_date.

  • case 4

ELSEIF lv_tempdat1 < a004-datab AND

lv_tempdat2 > a004-datab AND

lv_tempdat2 < a004-datbi.

  • first record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl1.

it_date-start+4(4) = lv_tempdat1(4).

it_date-start2(2) = lv_tempdat14(2).

it_date-start(2) = lv_tempdat1+6(2).

it_date-end+4(4) = lv_tempdat2(4).

it_date-end2(2) = lv_tempdat24(2).

it_date-end(2) = lv_tempdat2+6(2).

APPEND it_date.

  • second record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl1.

lv_datab = lv_tempdat2.

ADD 1 TO lv_datab.

it_date-start+4(4) = lv_datab(4).

it_date-start2(2) = lv_datab4(2).

it_date-start(2) = lv_datab+6(2).

it_date-end+4(4) = a004-datbi(4).

it_date-end2(2) = a004-datbi4(2).

it_date-end(2) = a004-datbi+6(2).

APPEND it_date.

  • case 5 & 6

ELSEIF lv_tempdat1 > a004-datbi OR

lv_tempdat2 < a004-datab.

lv_newrec = 'X'.

ENDIF.

CLEAR: lv_tempdat1, lv_tempdat2.

ENDIF.

ELSE.

it_output-condtab = 'A703'.

SELECT SINGLE * FROM a703

WHERE kappl = 'V'

AND kschl = it_extract-kschl1

AND vkorg = it_extract-vkorg

AND vtweg = it_extract-vtweg

AND spart = it_extract-spart

AND land1 = it_extract-land1

AND matnr = it_extract-matnr

AND datbi >= sy-datum

AND datab <= sy-datum.

IF sy-subrc <> 0.

lv_newrec = 'X'.

ELSE.

CLEAR: lv_tempdat1, lv_tempdat2.

lv_tempdat1+6(2) = it_extract-datab(2).

lv_tempdat14(2) = it_extract-datab2(2).

lv_tempdat1(4) = it_extract-datab+4(4).

lv_tempdat2+6(2) = it_extract-datbi(2).

lv_tempdat24(2) = it_extract-datbi2(2).

lv_tempdat2(4) = it_extract-datbi+4(4).

  • case 1

IF a703-datab = lv_tempdat1 AND a703-datbi = lv_tempdat2.

lv_singrec = 'X'.

  • case 2

ELSEIF lv_tempdat1 > a703-datab AND

lv_tempdat1 < a703-datbi AND

lv_tempdat2 >= a703-datbi.

  • first record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl1.

it_date-start+4(4) = a703-datab(4).

it_date-start2(2) = a703-datab4(2).

it_date-start(2) = a703-datab+6(2).

lv_datbi = lv_tempdat1.

SUBTRACT 1 FROM lv_datbi.

it_date-end+4(4) = lv_datbi(4).

it_date-end2(2) = lv_datbi4(2).

it_date-end(2) = lv_datbi+6(2).

APPEND it_date.

  • second record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl1.

it_date-start = it_extract-datab.

it_date-end = it_extract-datbi.

APPEND it_date.

  • case 3

ELSEIF lv_tempdat1 > a703-datab AND

lv_tempdat1 < a703-datbi AND

lv_tempdat2 < a703-datbi.

  • first record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl1.

it_date-start+4(4) = a703-datab(4).

it_date-start2(2) = a703-datab4(2).

it_date-start(2) = a703-datab+6(2).

lv_datbi = lv_tempdat1.

SUBTRACT 1 FROM lv_datbi.

it_date-end+4(4) = lv_datbi(4).

it_date-end2(2) = lv_datbi4(2).

it_date-end(2) = lv_datbi+6(2).

APPEND it_date.

  • second record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl1.

it_date-start = it_extract-datab.

it_date-end = it_extract-datbi.

APPEND it_date.

  • third record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl1.

lv_datab = lv_tempdat1.

ADD 1 TO lv_datab.

it_date-start+4(4) = lv_datab(4).

it_date-start2(2) = lv_datab4(2).

it_date-start(2) = lv_datab+6(2).

it_date-end+4(4) = a703-datbi(4).

it_date-end2(2) = a703-datbi4(2).

it_date-end(2) = a703-datbi+6(2).

APPEND it_date.

  • case 4

ELSEIF lv_tempdat1 < a703-datab AND

lv_tempdat2 > a703-datab AND

lv_tempdat2 < a703-datbi.

  • first record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl1.

it_date-start+4(4) = lv_tempdat1(4).

it_date-start2(2) = lv_tempdat14(2).

it_date-start(2) = lv_tempdat1+6(2).

it_date-end+4(4) = lv_tempdat2(4).

it_date-end2(2) = lv_tempdat24(2).

it_date-end(2) = lv_tempdat2+6(2).

APPEND it_date.

  • second record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl1.

lv_datab = lv_tempdat2.

ADD 1 TO lv_datab.

it_date-start+4(4) = lv_datab(4).

it_date-start2(2) = lv_datab4(2).

it_date-start(2) = lv_datab+6(2).

it_date-end+4(4) = a703-datbi(4).

it_date-end2(2) = a703-datbi4(2).

it_date-end(2) = a703-datbi+6(2).

APPEND it_date.

  • case 5 & 6

ELSEIF lv_tempdat1 > a703-datbi OR

lv_tempdat2 < a703-datab.

lv_newrec = 'X'.

ENDIF.

CLEAR: lv_tempdat1, lv_tempdat2.

ENDIF.

ENDIF.

  • Fill the output table

it_output-matnr = it_extract-matnr.

it_output-kbetr = it_extract-kbetr3.

it_output-kurst = it_extract-kurst.

it_output-ukurs = it_extract-ukurs.

it_output-datab(2) = it_extract-datab(2).

it_output-datab+2(1) = '.'.

it_output-datab3(2) = it_extract-datab2(2).

it_output-datab+5(1) = '.'.

it_output-datab6(4) = it_extract-datab4(4).

it_output-datbi(2) = it_extract-datbi(2).

it_output-datbi+2(1) = '.'.

it_output-datbi3(2) = it_extract-datbi2(2).

it_output-datbi+5(1) = '.'.

it_output-datbi6(4) = it_extract-datbi4(4).

  • it_output-datab = it_extract-datab.

  • it_output-datbi = it_extract-datbi.

IF lv_newrec = 'X'.

  • Checking for valid material

CLEAR lv_errmsg.

IF NOT it_extract-matnr IS INITIAL.

SELECT SINGLE * FROM mvke WHERE

matnr = it_extract-matnr AND

vkorg = it_extract-vkorg AND

vtweg = it_extract-vtweg.

IF sy-subrc <> 0.

CONCATENATE text-021 ':' text-018

it_extract-vkorg text-019

it_extract-vtweg INTO lv_errmsg.

FORMAT COLOR 4.

WRITE:/ lv_errmsg.

FORMAT COLOR OFF.

ELSE.

FORMAT COLOR 4.

WRITE:/ text-014.

FORMAT COLOR OFF.

ENDIF.

ENDIF.

FORMAT COLOR 7.

WRITE:/ it_output-kschl1, 16 it_output-condtab,

30 it_output-matnr, 50 it_output-kbetr, "#EC UOM_IN_MES

79 it_output-kurst CENTERED, 90 it_output-ukurs,

102 it_output-datab, 114 it_output-datbi.

FORMAT COLOR OFF.

SKIP.

ELSEIF lv_singrec <> 'X'.

CLEAR it_output.

REFRESH it_output.

LOOP AT it_date.

it_output-kschl1 = it_extract-kschl1.

IF it_extract-land1 IS INITIAL.

it_output-condtab = 'A004'.

ELSE.

it_output-condtab = 'A703'.

ENDIF.

it_output-matnr = it_extract-matnr.

it_output-kbetr = it_extract-kbetr3.

it_output-kurst = it_extract-kurst.

it_output-ukurs = it_extract-ukurs.

it_output-datab(2) = it_date-start(2).

it_output-datab+2(1) = '.'.

it_output-datab3(2) = it_date-start2(2).

it_output-datab+5(1) = '.'.

it_output-datab6(4) = it_date-start4(4).

it_output-datbi(2) = it_date-end(2).

it_output-datbi+2(1) = '.'.

it_output-datbi3(2) = it_date-end2(2).

it_output-datbi+5(1) = '.'.

it_output-datbi6(4) = it_date-end4(4).

APPEND it_output.

ENDLOOP.

FORMAT COLOR 4.

WRITE:/ text-015.

FORMAT COLOR OFF.

LOOP AT it_output.

FORMAT COLOR 7.

WRITE:/ it_output-kschl1, 16 it_output-condtab,

30 it_output-matnr, 50 it_output-kbetr,"#EC UOM_IN_MES

79 it_output-kurst CENTERED, 90 it_output-ukurs,

102 it_output-datab, 114 it_output-datbi.

  • WRITE:/ it_output-kschl1, 16 it_output-condtab,

  • 30 it_output-matnr, 50 it_output-kbetr,"#EC UOM_IN_MES

  • 79 it_output-kurst CENTERED, 90 it_output-ukurs,

  • 102 it_output-datab, 114 it_output-datbi.

FORMAT COLOR OFF.

SKIP.

ENDLOOP.

ELSE.

FORMAT COLOR 4.

WRITE:/ text-017.

FORMAT COLOR OFF.

FORMAT COLOR 7.

WRITE:/ it_output-kschl1, 16 it_output-condtab,

30 it_output-matnr, 50 it_output-kbetr, "#EC UOM_IN_MES

79 it_output-kurst CENTERED, 90 it_output-ukurs,

102 it_output-datab, 114 it_output-datbi.

FORMAT COLOR OFF.

SKIP.

ENDIF.

ENDIF.

*For condition ZKDT

CLEAR it_output.

IF NOT it_extract-kschl2 IS INITIAL.

it_output-kschl2 = it_extract-kschl2.

IF it_extract-land1 IS INITIAL.

it_output-condtab = 'A004'.

SELECT SINGLE * FROM a004

WHERE kappl = 'V'

AND kschl = it_extract-kschl2

AND vkorg = it_extract-vkorg

AND vtweg = it_extract-vtweg

AND matnr = it_extract-matnr

AND datbi >= sy-datum

AND datab <= sy-datum.

IF sy-subrc <> 0.

lv_newrec = 'X'.

ELSE.

CLEAR: lv_tempdat1, lv_tempdat2.

lv_tempdat1+6(2) = it_extract-datab(2).

lv_tempdat14(2) = it_extract-datab2(2).

lv_tempdat1(4) = it_extract-datab+4(4).

lv_tempdat2+6(2) = it_extract-datbi(2).

lv_tempdat24(2) = it_extract-datbi2(2).

lv_tempdat2(4) = it_extract-datbi+4(4).

  • case 1

IF a004-datab = lv_tempdat1 AND a004-datbi = lv_tempdat2.

lv_singrec = 'X'.

  • case 2

ELSEIF lv_tempdat1 > a004-datab AND

lv_tempdat1 < a004-datbi AND

lv_tempdat2 >= a004-datbi.

  • first record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl2.

it_date-start+4(4) = a004-datab(4).

it_date-start2(2) = a004-datab4(2).

it_date-start(2) = a004-datab+6(2).

lv_datbi = lv_tempdat1.

SUBTRACT 1 FROM lv_datbi.

it_date-end+4(4) = lv_datbi(4).

it_date-end2(2) = lv_datbi4(2).

it_date-end(2) = lv_datbi+6(2).

APPEND it_date.

  • second record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl2.

it_date-start = it_extract-datab.

it_date-end = it_extract-datbi.

APPEND it_date.

  • case 3

ELSEIF lv_tempdat1 > a004-datab AND

lv_tempdat1 < a004-datbi AND

lv_tempdat2 < a004-datbi.

  • first record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl2.

it_date-start+4(4) = a004-datab(4).

it_date-start2(2) = a004-datab4(2).

it_date-start(2) = a004-datab+6(2).

lv_datbi = lv_tempdat1.

SUBTRACT 1 FROM lv_datbi.

it_date-end+4(4) = lv_datbi(4).

it_date-end2(2) = lv_datbi4(2).

it_date-end(2) = lv_datbi+6(2).

APPEND it_date.

  • second record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl2.

it_date-start = it_extract-datab.

it_date-end = it_extract-datbi.

APPEND it_date.

  • third record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl2.

lv_datab = lv_tempdat1.

ADD 1 TO lv_datab.

it_date-start+4(4) = lv_datab(4).

it_date-start2(2) = lv_datab4(2).

it_date-start(2) = lv_datab+6(2).

it_date-end+4(4) = a004-datbi(4).

it_date-end2(2) = a004-datbi4(2).

it_date-end(2) = a004-datbi+6(2).

APPEND it_date.

  • case 4

ELSEIF lv_tempdat1 < a004-datab AND

lv_tempdat2 > a004-datab AND

lv_tempdat2 < a004-datbi.

  • first record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl2.

it_date-start+4(4) = lv_tempdat1(4).

it_date-start2(2) = lv_tempdat14(2).

it_date-start(2) = lv_tempdat1+6(2).

it_date-end+4(4) = lv_tempdat2(4).

it_date-end2(2) = lv_tempdat24(2).

it_date-end(2) = lv_tempdat2+6(2).

APPEND it_date.

  • second record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl2.

lv_datab = lv_tempdat2.

ADD 1 TO lv_datab.

it_date-start+4(4) = lv_datab(4).

it_date-start2(2) = lv_datab4(2).

it_date-start(2) = lv_datab+6(2).

it_date-end+4(4) = a004-datbi(4).

it_date-end2(2) = a004-datbi4(2).

it_date-end(2) = a004-datbi+6(2).

APPEND it_date.

  • case 5 & 6

ELSEIF lv_tempdat1 > a004-datbi OR

lv_tempdat2 < a004-datab.

lv_newrec = 'X'.

ENDIF.

CLEAR: lv_tempdat1, lv_tempdat2.

ENDIF.

ELSE.

it_output-condtab = 'A703'.

SELECT SINGLE * FROM a703

WHERE kappl = 'V'

AND kschl = it_extract-kschl2

AND vkorg = it_extract-vkorg

AND vtweg = it_extract-vtweg

AND spart = it_extract-spart

AND land1 = it_extract-land1

AND matnr = it_extract-matnr

AND datbi >= sy-datum

AND datab <= sy-datum.

IF sy-subrc <> 0.

lv_newrec = 'X'.

ELSE.

CLEAR: lv_tempdat1, lv_tempdat2.

lv_tempdat1+6(2) = it_extract-datab(2).

lv_tempdat14(2) = it_extract-datab2(2).

lv_tempdat1(4) = it_extract-datab+4(4).

lv_tempdat2+6(2) = it_extract-datbi(2).

lv_tempdat24(2) = it_extract-datbi2(2).

lv_tempdat2(4) = it_extract-datbi+4(4).

  • case 1

IF a703-datab = lv_tempdat1 AND a703-datbi = lv_tempdat2.

lv_singrec = 'X'.

  • case 2

ELSEIF lv_tempdat1 > a703-datab AND

lv_tempdat1 < a703-datbi AND

lv_tempdat2 >= a703-datbi.

  • first record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl2.

it_date-start+4(4) = a703-datab(4).

it_date-start2(2) = a703-datab4(2).

it_date-start(2) = a703-datab+6(2).

lv_datbi = lv_tempdat1.

SUBTRACT 1 FROM lv_datbi.

it_date-end+4(4) = lv_datbi(4).

it_date-end2(2) = lv_datbi4(2).

it_date-end(2) = lv_datbi+6(2).

APPEND it_date.

  • second record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl2.

it_date-start = it_extract-datab.

it_date-end = it_extract-datbi.

APPEND it_date.

  • case 3

ELSEIF lv_tempdat1 > a703-datab AND

lv_tempdat1 < a703-datbi AND

lv_tempdat2 < a703-datbi.

  • first record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl2.

it_date-start+4(4) = a703-datab(4).

it_date-start2(2) = a703-datab4(2).

it_date-start(2) = a703-datab+6(2).

lv_datbi = lv_tempdat1.

SUBTRACT 1 FROM lv_datbi.

it_date-end+4(4) = lv_datbi(4).

it_date-end2(2) = lv_datbi4(2).

it_date-end(2) = lv_datbi+6(2).

APPEND it_date.

  • second record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl2.

it_date-start = it_extract-datab.

it_date-end = it_extract-datbi.

APPEND it_date.

  • third record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl2.

lv_datab = lv_tempdat1.

ADD 1 TO lv_datab.

it_date-start+4(4) = lv_datab(4).

it_date-start2(2) = lv_datab4(2).

it_date-start(2) = lv_datab+6(2).

it_date-end+4(4) = a703-datbi(4).

it_date-end2(2) = a703-datbi4(2).

it_date-end(2) = a703-datbi+6(2).

APPEND it_date.

  • case 4

ELSEIF lv_tempdat1 < a703-datab AND

lv_tempdat2 > a703-datab AND

lv_tempdat2 < a703-datbi.

  • first record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl2.

it_date-start+4(4) = lv_tempdat1(4).

it_date-start2(2) = lv_tempdat14(2).

it_date-start(2) = lv_tempdat1+6(2).

it_date-end+4(4) = lv_tempdat2(4).

it_date-end2(2) = lv_tempdat24(2).

it_date-end(2) = lv_tempdat2+6(2).

APPEND it_date.

  • second record

it_date-tabix = sy-tabix.

it_date-kschl = it_extract-kschl2.

lv_datab = lv_tempdat2.

ADD 1 TO lv_datab.

it_date-start+4(4) = lv_datab(4).

it_date-start2(2) = lv_datab4(2).

it_date-start(2) = lv_datab+6(2).

it_date-end+4(4) = a703-datbi(4).

it_date-end2(2) = a703-datbi4(2).

it_date-end(2) = a703-datbi+6(2).

APPEND it_date.

  • case 5 & 6

ELSEIF lv_tempdat1 > a703-datbi OR

lv_tempdat2 < a703-datab.

lv_newrec = 'X'.

ENDIF.

CLEAR: lv_tempdat1, lv_tempdat2.

ENDIF.

ENDIF.

it_output-matnr = it_extract-matnr.

it_output-kbetr = it_extract-kbetr4.

it_output-kurst = it_extract-kurst.

it_output-ukurs = it_extract-ukurs.

it_output-datab(2) = it_extract-datab(2).

it_output-datab+2(1) = '.'.

it_output-datab3(2) = it_extract-datab2(2).

it_output-datab+5(1) = '.'.

it_output-datab6(4) = it_extract-datab4(4).

it_output-datbi(2) = it_extract-datbi(2).

it_output-datbi+2(1) = '.'.

it_output-datbi3(2) = it_extract-datbi2(2).

it_output-datbi+5(1) = '.'.

it_output-datbi6(4) = it_extract-datbi4(4).

  • it_output-datab = it_extract-datab.

  • it_output-datbi = it_extract-datbi.

IF lv_newrec = 'X'.

  • Checking for valid material

CLEAR lv_errmsg.

IF NOT it_extract-matnr IS INITIAL.

SELECT SINGLE * FROM mvke WHERE

matnr = it_extract-matnr AND

vkorg = it_extract-vkorg AND

vtweg = it_extract-vtweg.

IF sy-subrc <> 0.

CONCATENATE text-021 ':' text-018

it_extract-vkorg text-019

it_extract-vtweg INTO lv_errmsg.

FORMAT COLOR 4.

WRITE:/ lv_errmsg.

FORMAT COLOR OFF.

ELSE.

FORMAT COLOR 4.

WRITE:/ text-014.

FORMAT COLOR OFF.

ENDIF.

ENDIF.

FORMAT COLOR 7.

WRITE:/ it_output-kschl2, 16 it_output-condtab,

30 it_output-matnr, 50 it_output-kbetr, "#EC UOM_IN_MES

79 it_output-kurst CENTERED, 90 it_output-ukurs,

102 it_output-datab, 114 it_output-datbi.

FORMAT COLOR OFF.

SKIP.

ELSEIF lv_singrec <> 'X'.

CLEAR it_output.

REFRESH it_output.

LOOP AT it_date.

it_output-kschl1 = it_extract-kschl2.

IF it_extract-land1 IS INITIAL.

it_output-condtab = 'A004'.

ELSE.

it_output-condtab = 'A703'.

ENDIF.

it_output-matnr = it_extract-matnr.

it_output-kbetr = it_extract-kbetr4.

it_output-kurst = it_extract-kurst.

it_output-ukurs = it_extract-ukurs.

it_output-datab(2) = it_date-start(2).

it_output-datab+2(1) = '.'.

it_output-datab3(2) = it_date-start2(2).

it_output-datab+5(1) = '.'.

it_output-datab6(4) = it_date-start4(4).

it_output-datbi(2) = it_date-end(2).

it_output-datbi+2(1) = '.'.

it_output-datbi3(2) = it_date-end2(2).

it_output-datbi+5(1) = '.'.

it_output-datbi6(4) = it_date-end4(4).

APPEND it_output.

ENDLOOP.

FORMAT COLOR 4.

WRITE:/ text-015.

FORMAT COLOR OFF.

LOOP AT it_output.

FORMAT COLOR 7.

WRITE:/ it_output-kschl2, 16 it_output-condtab,

30 it_output-matnr, 50 it_output-kbetr,"#EC UOM_IN_MES

79 it_output-kurst CENTERED, 90 it_output-ukurs,

102 it_output-datab, 114 it_output-datbi.

  • WRITE:/ it_output-kschl2, 16 it_output-condtab,

  • 30 it_output-matnr, 50 it_output-kbetr,"#EC UOM_IN_MES

  • 79 it_output-kurst CENTERED, 90 it_output-ukurs,

  • 102 it_output-datab, 114 it_output-datbi.

FORMAT COLOR OFF.

SKIP.

ENDLOOP.

ELSE.

FORMAT COLOR 4.

WRITE:/ text-017.

FORMAT COLOR OFF.

FORMAT COLOR 7.

WRITE:/ it_output-kschl2, 16 it_output-condtab,

30 it_output-matnr, 50 it_output-kbetr, "#EC UOM_IN_MES

79 it_output-kurst CENTERED, 90 it_output-ukurs,

102 it_output-datab, 114 it_output-datbi.

FORMAT COLOR OFF.

SKIP.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. " sim_log

&----


*& Form upd_rec_output

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM upd_rec_output .

lv_count = 2.

LOOP AT it_errmat.

CLEAR wa_errmat.

wa_errmat = it_errmat.

AT FIRST.

IF lv_count = 2.

FORMAT COLOR 2.

ELSE.

FORMAT COLOR 4.

ENDIF.

WRITE:/ wa_errmat-recno CENTERED, 15 wa_errmat-kschl,

31 wa_errmat-matnr, 53 wa_errmat-status,

65 wa_errmat-bdcmsg.

FORMAT COLOR OFF.

CONTINUE.

ENDAT.

AT NEW recno.

IF lv_count = 2.

FORMAT COLOR 2.

ELSE.

FORMAT COLOR 4.

ENDIF.

WRITE:/ wa_errmat-recno CENTERED, 15 wa_errmat-kschl,

31 wa_errmat-matnr, 53 wa_errmat-status,

65 wa_errmat-bdcmsg.

FORMAT COLOR OFF.

CONTINUE.

ENDAT.

AT END OF recno.

IF lv_count = 2.

FORMAT COLOR 2.

ELSE.

FORMAT COLOR 4.

ENDIF.

WRITE:/15 wa_errmat-kschl, 31 wa_errmat-matnr, 53 wa_errmat-status,

65 wa_errmat-bdcmsg.

FORMAT COLOR OFF.

IF lv_count = 2.

lv_count = 4.

ELSE.

lv_count = 2.

ENDIF.

ULINE.

CONTINUE.

ENDAT.

IF lv_count = 2.

FORMAT COLOR 2.

ELSE.

FORMAT COLOR 4.

ENDIF.

WRITE:/15 wa_errmat-kschl, 31 wa_errmat-matnr, 53 wa_errmat-status,

65 wa_errmat-bdcmsg.

FORMAT COLOR OFF.

ENDLOOP.

ENDFORM. " upd_rec_output

&----


*& Form new_record_a004

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM new_record_a004 .

*creating a new record with specified validity period.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F003-LOW'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

PERFORM bdc_field USING 'SEL_DATE' it_extract-datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

  • PERFORM bdc_field USING 'KOMG-VKORG' it_extract-vkorg.

  • PERFORM bdc_field USING 'KOMG-VTWEG' it_extract-vtweg.

  • PERFORM bdc_field USING 'KOMG-MATNR(01)' it_extract-matnr.

CLEAR lv_amnt.

MOVE it_extract-kbetr3 TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

CLEAR lv_amnt.

  • PERFORM bdc_field USING 'KONP-KONWA(01)' 'EUR'.

IF NOT it_extract-datab IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATAB(01)' it_extract-datab.

ELSE.

PERFORM bdc_field USING 'RV13A-DATAB(01)' sy-datum.

ENDIF.

IF NOT it_extract-datbi IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATBI(01)' it_extract-datbi.

ELSE.

PERFORM bdc_field USING 'RV13A-DATBI(01)' '31.12.9999'.

ENDIF.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

ENDFORM. " new_record_a004

&----


*& Form new_record_a703

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM new_record_a703 .

*creating a new record with specified validity period.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl1.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

PERFORM bdc_field USING 'SEL_DATE' it_extract-datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM bdc_field USING 'KOMG-VKORG' it_extract-vkorg.

PERFORM bdc_field USING 'KOMG-VTWEG' it_extract-vtweg.

PERFORM bdc_field USING 'KOMG-SPART' it_extract-spart.

PERFORM bdc_field USING 'KOMG-LAND1' it_extract-land1.

PERFORM bdc_field USING 'KOMG-MATNR(01)' it_extract-matnr.

CLEAR lv_amnt.

MOVE it_extract-kbetr3 TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

CLEAR lv_amnt.

PERFORM bdc_field USING 'KONP-KONWA(01)' 'EUR'.

IF NOT it_extract-datab IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATAB(01)' it_extract-datab.

ELSE.

PERFORM bdc_field USING 'RV13A-DATAB(01)' sy-datum.

ENDIF.

IF NOT it_extract-datbi IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATBI(01)' it_extract-datbi.

ELSE.

PERFORM bdc_field USING 'RV13A-DATBI(01)' '31.12.9999'.

ENDIF.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl1.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

ENDFORM. " new_record_a703

&----


*& Form new_record_a703_2

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM new_record_a703_2 .

*creating a new record with specified validity period.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl2.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' 'X'.

PERFORM bdc_field USING 'RV130-SELKZ(02)' ''.

PERFORM bdc_dynpro USING 'RV13A703' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003' it_extract-spart.

PERFORM bdc_field USING 'F004' it_extract-land1.

PERFORM bdc_field USING 'F005-LOW' it_extract-matnr.

PERFORM bdc_field USING 'SEL_DATE' it_extract-datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '1703'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

PERFORM bdc_field USING 'KOMG-VKORG' it_extract-vkorg.

PERFORM bdc_field USING 'KOMG-VTWEG' it_extract-vtweg.

PERFORM bdc_field USING 'KOMG-SPART' it_extract-spart.

PERFORM bdc_field USING 'KOMG-LAND1' it_extract-land1.

PERFORM bdc_field USING 'KOMG-MATNR(01)' it_extract-matnr.

CLEAR lv_amnt.

MOVE it_extract-kbetr4 TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

CLEAR lv_amnt.

PERFORM bdc_field USING 'KONP-KONWA(01)' 'EUR'.

IF NOT it_extract-datab IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATAB(01)' it_extract-datab.

ELSE.

PERFORM bdc_field USING 'RV13A-DATAB(01)' sy-datum.

ENDIF.

IF NOT it_extract-datbi IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATBI(01)' it_extract-datbi.

ELSE.

PERFORM bdc_field USING 'RV13A-DATBI(01)' '31.12.9999'.

ENDIF.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

ENDFORM. " new_record_a703_2

&----


*& Form new_record_a004_2

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM new_record_a004_2 .

*creating a new record with specified validity period.

REFRESH bdcdata.

CLEAR bdcdata.

PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-KSCHL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ANTA'.

PERFORM bdc_field USING 'RV13A-KSCHL' it_extract-kschl2.

PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV130-SELKZ(02)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_field USING 'RV130-SELKZ(01)' ''.

PERFORM bdc_field USING 'RV130-SELKZ(02)' 'X'.

PERFORM bdc_dynpro USING 'RV13A004' '1000'.

PERFORM bdc_field USING 'BDC_CURSOR' 'F003-LOW'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.

PERFORM bdc_field USING 'F001' it_extract-vkorg.

PERFORM bdc_field USING 'F002' it_extract-vtweg.

PERFORM bdc_field USING 'F003-LOW' it_extract-matnr.

PERFORM bdc_field USING 'SEL_DATE' it_extract-datab.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RV13A-DATBI(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SICH'.

  • PERFORM bdc_field USING 'KOMG-VKORG' it_extract-vkorg.

  • PERFORM bdc_field USING 'KOMG-VTWEG' it_extract-vtweg.

  • PERFORM bdc_field USING 'KOMG-MATNR(01)' it_extract-matnr.

CLEAR lv_amnt.

MOVE it_extract-kbetr4 TO lv_amnt.

REPLACE '.' WITH ',' INTO lv_amnt.

CONDENSE lv_amnt NO-GAPS.

PERFORM bdc_field USING 'KONP-KBETR(01)' lv_amnt.

CLEAR lv_amnt.

  • PERFORM bdc_field USING 'KONP-KONWA(01)' 'EUR'.

IF NOT it_extract-datab IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATAB(01)' it_extract-datab.

ELSE.

PERFORM bdc_field USING 'RV13A-DATAB(01)' sy-datum.

ENDIF.

IF NOT it_extract-datbi IS INITIAL.

PERFORM bdc_field USING 'RV13A-DATBI(01)' it_extract-datbi.

ELSE.

PERFORM bdc_field USING 'RV13A-DATBI(01)' '31.12.9999'.

ENDIF.

REFRESH it_msgtab.

CALL TRANSACTION 'VK12'

USING bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO it_msgtab.

IF sy-subrc = 0.

ADD 1 TO w_data_bdc_recs.

DELETE ADJACENT DUPLICATES FROM it_msgtab.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-020.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT it_msgtab.

CLEAR wa_msglog.

wa_msglog-msgid = it_msgtab-msgid.

wa_msglog-msgno = it_msgtab-msgnr.

wa_msglog-msgty = it_msgtab-msgtyp.

wa_msglog-msgv1 = it_msgtab-msgv1.

wa_msglog-msgv2 = it_msgtab-msgv2.

wa_msglog-msgv3 = it_msgtab-msgv3.

wa_msglog-msgv4 = it_msgtab-msgv4.

CALL FUNCTION 'MESSAGE_TEXTS_READ'

EXPORTING

msg_log_imp = wa_msglog

IMPORTING

msg_text_exp = wa_msgtxt.

IF sy-subrc = 0.

CLEAR it_errmat.

it_errmat-recno = lv_count.

it_errmat-kschl = it_extract-kschl2.

it_errmat-matnr = it_extract-matnr.

it_errmat-status = text-021.

it_errmat-bdcmsg = wa_msgtxt-msgtx.

APPEND it_errmat.

ENDIF.

ENDLOOP.

ENDIF.

COMMIT WORK AND WAIT.

ENDFORM. " new_record_a004_2

Hope this is useful for U.

Reward points,

Regards,

Vasanth