TYPES : BEGIN OF type_header,
kschl LIKE konv-kschl,
vkorg LIKE vbak-vkorg,
vtweg LIKE komg-spart,
matnr LIKE mvke-matnr,
kbetr(11) TYPE c,
datab(10) TYPE c,
datbi(10) TYPE c,
END OF type_header.
****Internal Table for Item Level.
TYPES : BEGIN OF type_item,
kschl LIKE konv-kschl,
vkorg LIKE vbak-vkorg,
vtweg LIKE komg-spart,
matnr LIKE mvke-matnr,
kbetr(11) TYPE c,
datab(10) TYPE c,
datbi(10) TYPE c,
END OF type_item.
******Error Table For not found in MVKE.
TYPES : BEGIN OF type_error ,
kschl LIKE konv-kschl,
vkorg LIKE vbak-vkorg,
vtweg LIKE komg-spart,
matnr LIKE mvke-matnr,
kbetr LIKE konp-kbetr,
datab(10) TYPE c,
datbi(10) TYPE c,
text(100) TYPE c,
END OF type_error.
****For error Messages
TYPES : BEGIN OF type_mtab,
matnr LIKE mara-matnr,
msgtyp LIKE bdcmsgcoll-msgtyp,
msgid LIKE bdcmsgcoll-msgid,
msgnr LIKE bdcmsgcoll-msgnr,
text(100) TYPE c,
END OF type_mtab.
****Internal Table
TYPES: BEGIN OF type_mvke,
matnr LIKE mvke-matnr,
vkorg LIKE mvke-vkorg,
vtweg LIKE mvke-vtweg,
END OF type_mvke.
****Internal Table
TYPES : BEGIN OF type_tvkov,
vkorg LIKE tvkov-vkorg,
vtweg LIKE tvkov-vtweg,
END OF type_tvkov.
** Declaring Internal Tables
DATA : t_header TYPE STANDARD TABLE OF type_header,
t_item TYPE STANDARD TABLE OF type_item,
t_mvke TYPE STANDARD TABLE OF type_mvke,
t_tvkov TYPE STANDARD TABLE OF type_tvkov,
t_error TYPE STANDARD TABLE OF type_error,
t_mtab TYPE STANDARD TABLE OF type_mtab.
** Work Area Declaration.
DATA : wa_header LIKE LINE OF t_header,
wa_item LIKE LINE OF t_item,
wa_error LIKE LINE OF t_error,
wa_mtab LIKE LINE OF t_mtab,
wa_tvkov LIKE LINE OF t_tvkov,
wa_mvke LIKE LINE OF t_mvke.
**Rows for Table with Excel Data********
DATA: t_xls_file LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.
***Constant.
DATA : c_params LIKE ctu_params.
DATA : c_ans(1) TYPE c.
DATA : v_count(4) TYPE c. " To show No.of records
DATA : bdctab LIKE bdcdata OCCURS 10 WITH HEADER LINE. " BDCDATA
DATA : tmess_mtab LIKE bdcmsgcoll OCCURS 10 WITH HEADER LINE.
************************************************************************
**
** SELECTION SCREEN
************************************************************************
**
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_fname LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN : END OF BLOCK b1.
**********************************************************************
* END OF SELECTION SCREEN.
**********************************************************************
DATA : repid LIKE sy-repid.
DATA : v_matnr(50) TYPE c, "used for line items
v_kbetr(50) TYPE c, "used for line items
v_dat1(50) TYPE c, "used for line items
v_dat(50) TYPE c. "used for line items
DATA : v_lindx(5) TYPE n ,"index counter for first 14 records.
v_lindx1(5) TYPE n VALUE '01', "index counter for 13 records.
v_item(5) TYPE c, "To increment the line index
v_pgedwn2 TYPE i . "For Pagedown Counter
DATA: v_currentrow TYPE i. "For Current Row
DATA v_bdc(50) TYPE c." Text to apper in Confrim POPUP Window.
************AT SELECTION-SCREEN
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
PERFORM get_filename USING p_fname.
******Values for Ctu_params to Transaction
c_params-defsize = 'X'.
c_params-dismode = 'N'.
c_params-updmode = 'S'.
******Refresh
PERFORM f_refresh.
*********To upload File.
PERFORM upload_file.
****User Confrimation only BDC will Process
IF c_ans = '1'.
** *** BDC Process.
PERFORM read_data.
ELSE.
FORMAT COLOR 3 INTENSIFIED .
WRITE:/ 'Selected not to Process the Upload'.
EXIT.
ENDIF.
******On completion of Process Refresh the Internal Table
REFRESH : t_xls_file,
t_header,
t_item,
t_mvke,
t_tvkov.
CLEAR : t_xls_file,
wa_header,
wa_item,
wa_mvke,
wa_tvkov.
***************************************
***********Display Messages
WRITE : /01 'Status',19 'Status Text'.
WRITE AT 0(150) sy-uline.
LOOP AT t_mtab INTO wa_mtab.
WRITE :/01 wa_mtab-msgtyp,19 wa_mtab-text.
ENDLOOP.
SKIP 2.
SORT t_error BY matnr.
WRITE AT 0(150) sy-uline.
WRITE 'ERROR MESSAGES'.
WRITE AT 0(150) sy-uline.
WRITE :/01 'Material.No',20 'Status Text'.
WRITE AT 0(150) sy-uline.
LOOP AT t_error INTO wa_error WHERE matnr NE ' '.
!
WRITE:/01 wa_error-matnr,20 wa_error-text.
ENDLOOP.
*---------------------------------------------------------------------*
*& Form get_filename
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FILENAME text
*----------------------------------------------------------------------*
FORM get_filename USING p_fname.
*****To read the file from Presentation Server
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
program_name = repid
dynpro_number ! ; = syst-dynnr
field_name = p_fname
* STATIC = ' '
mask = '*.XLS'
CHANGING
file_name = p_fname
EXCEPTIONS
mask_too_long = 1
OTHERS = 2
.
IF sy-subrc <0>P_0300 text
* -->P_0301 text
!
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
ENDFORM. " BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0305 text
* -->P_WA_HEADER_KSCHL text
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
CLEAR bdctab.
bdctab-fnam = fnam.
bdctab-fval = fval.
APPEND bdctab.
ENDFORM. " BDC_FIELD
*&---------------------------------------------------------------------*
*& Form bdc_trc_ansaction
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0527 text
*----------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Form f_Process
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*!
FORM f_process.
DATA : l_todate(12) TYPE c,
l_frdate(12) TYPE c.
***Select for all entries of material in Header "Flat File Materials".
IF NOT t_header[] IS INITIAL.
SELECT matnr vkorg vtweg FROM mvke INTO TABLE t_mvke FOR ALL ENTRIES
IN t_header WHERE matnr = t_header-matnr AND
vkorg = t_header-vkorg AND
vtweg = t_header-vtweg.
ENDIF.
*********select Sales.org & Dist.channel.
IF NOT t_header[] IS INITIAL.
SELECT vkorg vtweg FROM tvkov INTO TABLE t_tvkov FOR ALL ENTRIES IN
t_header WHERE vkorg = t_header-vkorg
AND vtweg = t_header-vtweg.
ENDIF.
***Checking for material in Sales Master Table
SORT t_mvke BY matnr vkorg vtweg.
SORT t_tvkov BY vkorg vtweg.
LOOP AT t_header INTO wa_header.
READ TABLE t_mvke INTO wa_mvke WITH KEY matnr = wa_header-matnr
vkorg = wa_header-vkorg
! ; vtweg = wa_header-vtweg BINARY SEARCH.
IF sy-subrc <> 0.
wa_error = wa_header.
&nb! sp; MOVE text-011 TO wa_error-text.
APPEND wa_error TO t_error.
DELETE TABLE t_header FROM wa_header.
ELSE.
********Date Validations
IF ( wa_header-datab NE ' ! ; ' AND wa_header-datbi NE ' ' ) .
l_todate = wa_header-datab.
l_frdate = wa_header-datbi.
REPLACE '.' INTO l_toda! te WITH ''.
REPLACE '.' INTO l_todate WITH ''.
CONDENSE l_todate NO-GAPS.
REPLACE '.' INTO l_frdate WITH ''.
REPLACE '.' INTO l_frdate WITH ''.
CONDENSE l_frdate NO-GAPS.
IF l_frdate < l_todate.
wa_error = wa_header .
MOVE text-012 TO wa_error-text.
APPEND wa_error TO t_error.
DELETE TABLE t_header FROM wa_header.
ENDIF.
ELSE.
wa_error = wa_header .
MOVE text-016 TO wa_error-text.
APPEND wa_error TO t_error.
DELETE TABLE t_header FROM wa_header.
ENDIF.
ENDIF.
********Rate Validation.
IF wa_header-kbetr = ' '.
wa_error = wa_header .
MOVE text-017 TO wa_error-text.
APPEND wa_error TO t_error.
DELETE TABLE t_header FROM wa_header.
ENDIF.
************************************************************************
READ TABLE t_tvkov INTO wa_tvkov WITH KEY vkorg = wa_header-vkorg
BINARY SEARCH.
IF sy-subrc = 0.
READ TABLE t_tvkov INTO wa_tvkov WITH KEY vtweg = wa_header-vtweg
BINARY SEARCH.
IF sy-subrc <> 0.
wa_error = wa_header.
MOVE text-015 TO wa_error-text.
WRITE wa_header-vtweg TO wa_error-text+13(4).
APPEND wa_error TO t_error.
ENDIF.
ELSE.
wa_error = wa_header.
MOVE text-013 TO wa_error-text.
WRITE wa_header-vkorg TO wa_error-text+9(4).
APPEND wa_error TO t_error.
ENDIF.
CLEAR wa_header.
ENDLOOP.
*****Deleting Duplicate Material Form Header "Flat File Data".
SORT t_header BY kschl vkorg vtweg matnr.
DELETE ADJACENT DUPLICATES FROM t_header COMPARING
kschl! vkorg vtweg matnr .
* ****Data Moving from Header to Item Level.
t_item[] = t_header[].
*To count No.of records in Item Table.
DESCRIBE TABLE t_item LINES v_count.
CONCATENATE text-014 ' ' v_count INTO v_bdc.
****Popup to get Confirmation from user to process BDC
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = 'Confirmation of File Data'
text_question = v_bdc
text_button_1 = 'Confirm'
text_button_2 = 'Cancel Run'
default_button = '1'
IMPORTING
answer = c_ans.
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-! MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " f_Process
*
*&---------------------------------------------------------------------*
*& Form f_Refresh
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_refresh.
REFRESH : t_xls_file,
t_header,
t_item,
t_mvke,
t_tvkov,
t_error,
t_mtab.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.