Subscribe

RSS Feed (xml)



Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Friday, May 23, 2008

BDC program for Purchase Info Records

BDC program for Purchase Info Records

*&---------------------------------------------------------------------*
*& REPORT ZMM0069 *
*&---------------------------------------------------------------------*
*& Module : MM |
*& Application : The program loads the Purchasing Inforecords |
*& |
*----------------------------------------------------------------------*
*| Modification Log |
*| ---------------- |
*| Programmer Date CC# Chg.Ref Description of
*| Change |
*| ------------- ----------- ---- ----------- ----------------------|
*| Rajesh Singh 23-AUG-2005 Initial
*| development. |
*----------------------------------------------------------------------*

REPORT zmm0069 NO STANDARD PAGE HEADING
MESSAGE-ID z0
LINE-SIZE 132
LINE-COUNT 65(2).


*----------------------------------------------------------------------*
* Internal Tables *
*----------------------------------------------------------------------*

*Internal table for the purchasing info records fields.

DATA: BEGIN OF i_inforecord OCCURS 0,

matnr(18),
lifnr(10),
uom(3),
ekgrp(3),
planned_time(3),
under_tol(3),
over_tol(3),
qty(10),
price_cat(5),
inco(3),
designation(28),
netpr(13),
scale_qty1(10),
scale_pr1(13),
scale_qty2(10),
scale_pr2(13),
scale_qty3(13),
scale_pr3(10),
scale_qty4(13),
scale_pr4(10),
scale_qty5(13),
scale_pr5(10),
scale_qty6(13),
scale_pr6(10),
scale_qty7(13),
scale_pr7(10),
scale_qty8(13),
scale_pr8(10),
scale_qty9(13),
scale_pr9(10),
scale_qty10(13),
scale_pr10(10),

END OF i_inforecord.

** Internal table for Old and New Vendor number
DATA : BEGIN OF i_lfb1 OCCURS 1,

lifnr(10),
altkn(10),

END OF i_lfb1.

** Declare internal table for Call Transaction and BDC Session
DATA: i_bdc_table LIKE bdcdata OCCURS 0 WITH HEADER LINE.


*----------------------------------------------------------------------*
* Global Variables *
*----------------------------------------------------------------------*

DATA: g_counter(2) TYPE n,
g_field_name(18) TYPE c,
zc_yes TYPE syftype VALUE 'X'.


*----------------------------------------------------------------------*
* Selection Screen *
*----------------------------------------------------------------------*

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

PARAMETERS: p_fname1 TYPE localfile .

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.
PARAMETERS: p_rloc1 AS CHECKBOX DEFAULT 'X'.

SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE text-003.
PARAMETERS p_group(12) OBLIGATORY DEFAULT 'ZPURCHINFO'.

SELECTION-SCREEN END OF BLOCK c.
SELECTION-SCREEN END OF BLOCK b.
SELECTION-SCREEN END OF BLOCK a.


**WRITE the report header
TOP-OF-PAGE.
INCLUDE zheading.

*----------------------------------------------------------------------*
* Start of selection *
*----------------------------------------------------------------------*

START-OF-SELECTION.

* Load Input file
PERFORM f_load_input_file.

* Create BDC records.
PERFORM create_bdc_records .


*&---------------------------------------------------------------------*
*& Form Create_BDC_records
*&---------------------------------------------------------------------*
* Perform the BDC for the records in the internal table
*----------------------------------------------------------------------*

FORM create_bdc_records .

IF NOT i_inforecord[] IS INITIAL.

** Open BDC session

PERFORM open_bdc_session.

SELECT lifnr altkn FROM lfb1 INTO TABLE i_lfb1
FOR ALL ENTRIES IN i_inforecord
WHERE altkn = i_inforecord-lifnr.

* Sorting the Internal table for better performance

SORT i_lfb1 BY altkn.

LOOP AT i_inforecord.

***Mapping Old Vendor number to the new Vendor number

READ TABLE i_lfb1 WITH KEY altkn = i_inforecord-lifnr BINARY
SEARCH.

IF sy-subrc EQ 0.
i_inforecord-lifnr = i_lfb1-lifnr.
ENDIF.


CLEAR i_bdc_table[].
PERFORM insert_screen_header.
* call transaction 'ME11' using i_bdc_table
* mode 'A'.
* CLEAR i_bdc_table.


ENDLOOP.
CLEAR i_inforecord[].

PERFORM close_bdc_session.

** Release the BDC sessions created
PERFORM release_bdc.
ENDIF.


ENDFORM. " open_group


*&---------------------------------------------------------------------*
*& Form bdc_dynpro_start
*&---------------------------------------------------------------------*
* Start the screen for the transfer of fields
*----------------------------------------------------------------------*

FORM bdc_dynpro_start USING p_g_program_1
p_g_screen.

CLEAR i_bdc_table.
i_bdc_table-program = p_g_program_1.
i_bdc_table-dynpro = p_g_screen.
i_bdc_table-dynbegin = 'X'.
APPEND i_bdc_table.

ENDFORM. " bdc_dynpro_start_start

*&---------------------------------------------------------------------*
*& Form bdc_insert_field
*&---------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM bdc_insert_field USING f_name f_value.
IF f_value <> space.
CLEAR i_bdc_table.
i_bdc_table-fnam = f_name.
i_bdc_table-fval = f_value.
APPEND i_bdc_table.
ENDIF.
ENDFORM. "bdc_insert_field



*&--------------------------------------------------------------------*
*& Form open_bdc_session
*&--------------------------------------------------------------------*
* Open a BDC session
*---------------------------------------------------------------------*
FORM open_bdc_session .


** Open BDC session and create and update records

CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
* DEST = FILLER8
group = p_group
* HOLDDATE = FILLER8
keep = 'X'
user = sy-uname
* RECORD = FILLER1
* PROG = SY-CPROG
* IMPORTING
* QID =
EXCEPTIONS
client_invalid = 1
destination_invalid = 2
group_invalid = 3
group_is_locked = 4
holddate_invalid = 5
internal_error = 6
queue_error = 7
running = 8
system_lock_error = 9
user_invalid = 10
OTHERS = 11
.
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. " create_bdc_session
*&---------------------------------------------------------------------*
*& Form insert_screen_header
*&---------------------------------------------------------------------*
* Screen flow for the transfer of fields
*----------------------------------------------------------------------*

FORM insert_screen_header .


* First Screen 100

PERFORM bdc_dynpro_start USING 'SAPMM06I' '0100'.

PERFORM bdc_insert_field USING:'BDC_CURSOR' 'EINA-LIFNR',

'BDC_OKCODE' '/00',

'EINA-LIFNR' i_inforecord-lifnr,

'EINA-MATNR' i_inforecord-matnr,

'EINE-EKORG' '1000',

'RM06I-NORMB' zc_yes.

*****----------------------------------------********

* Next Screen 101

PERFORM bdc_dynpro_start USING 'SAPMM06I' '0101'.

PERFORM bdc_insert_field USING : 'BDC_CURSOR' 'EINA-MAHN1',

'BDC_OKCODE' '/00',

'EINA-MEINS' i_inforecord-uom.

*****----------------------------------------********
*Next Screen 102

PERFORM bdc_dynpro_start USING 'SAPMM06I' '0102'.

PERFORM bdc_insert_field USING : 'BDC_CURSOR' 'EINE-INCO2',

'EINE-APLFZ' i_inforecord-planned_time,

'EINE-EKGRP' i_inforecord-ekgrp,

'EINE-NORBM' i_inforecord-qty.

PERFORM bdc_insert USING 'EINE-UEBTK' ' '.

PERFORM bdc_insert_field USING:'EINE-PEINH' i_inforecord-scale_qty1,

'EINE-BPRME' i_inforecord-uom,

'EINE-UNTTO' '5',

'EINE-UEBTO' '25',

'EINE-MEPRF' i_inforecord-price_cat,

'EINE-NETPR' i_inforecord-netpr,

'EINE-INCO1' i_inforecord-inco,

'EINE-INCO2' i_inforecord-designation.

* Checking for Scale quantities

IF i_inforecord-scale_qty2 = space.

PERFORM bdc_insert_field USING 'BDC_OKCODE' '=BU'.

PERFORM insert_bdc_new.

ELSE.

PERFORM bdc_insert_field USING 'BDC_OKCODE' '=KO'.

*****----------------------------------------********
* Next Screen 201

PERFORM bdc_dynpro_start USING 'SAPMV13A' '0201'.

PERFORM bdc_insert_field USING : 'BDC_CURSOR' 'RV13A-DATAB',

'BDC_OKCODE' '=PSTF'.

*****----------------------------------------********
* Next Screen 201

PERFORM bdc_dynpro_start USING 'SAPMV13A' '0201'.

PERFORM bdc_insert_field USING : 'BDC_CURSOR' 'KONP-KSCHL(01)',

'BDC_OKCODE' '=PSTF',

'RV130-SELKZ(01)' zc_yes.

*****----------------------------------------********
* LAST SCREEN 303


PERFORM bdc_dynpro_start USING 'SAPMV13A' '0303'.

PERFORM bdc_insert_field USING : 'BDC_CURSOR' 'KONM-KBETR(03)',

'BDC_OKCODE' '=SICH'.

* Counter to Loop the Item level entry
g_counter = 0.

PERFORM scale_entry USING i_inforecord-scale_qty2
i_inforecord-scale_pr2.


PERFORM scale_entry USING i_inforecord-scale_qty3
i_inforecord-scale_pr3.

PERFORM scale_entry USING i_inforecord-scale_qty4
i_inforecord-scale_pr4.

PERFORM scale_entry USING i_inforecord-scale_qty5
i_inforecord-scale_pr5.


PERFORM scale_entry USING i_inforecord-scale_qty6
i_inforecord-scale_pr6.

PERFORM scale_entry USING i_inforecord-scale_qty7
i_inforecord-scale_pr7.

PERFORM scale_entry USING i_inforecord-scale_qty8
i_inforecord-scale_pr8.

PERFORM scale_entry USING i_inforecord-scale_qty9
i_inforecord-scale_pr9.

PERFORM scale_entry USING i_inforecord-scale_qty10
i_inforecord-scale_pr10.

PERFORM insert_bdc_new.


ENDIF.
ENDFORM. " insert_screen_header

*&---------------------------------------------------------------------*
*& Form insert_bdc
*&---------------------------------------------------------------------*
* Insert BDC
*----------------------------------------------------------------------*

FORM insert_bdc_new .

CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'ME11'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
TABLES
dynprotab = i_bdc_table
EXCEPTIONS
internal_error = 1
not_open = 2
queue_error = 3
tcode_invalid = 4
printing_invalid = 5
posting_invalid = 6
OTHERS = 7
.
IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CLEAR i_bdc_table[].

ENDFORM. " insert_bdc


*&---------------------------------------------------------------------*
*& Form close_bdc_session
*&---------------------------------------------------------------------*
* Close the BDC session
*----------------------------------------------------------------------*

FORM close_bdc_session .

CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
not_open = 1
queue_error = 2
OTHERS = 3.

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. " close_bdc_session

*&---------------------------------------------------------------------*
*& Form f_load_input_file
*&---------------------------------------------------------------------*
* Upload the file
*----------------------------------------------------------------------*

FORM f_load_input_file.

* Check always Local file for upload

IF p_rloc1 = zc_yes.

CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p_fname1
filetype = 'DAT'
TABLES
data_tab = i_inforecord
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
OTHERS = 10.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

STOP.

ENDIF.

ENDIF.
*
ENDFORM. " f_load_input_file
*&---------------------------------------------------------------------*
*& Form release_bdc
*&---------------------------------------------------------------------*
* Release the session
*----------------------------------------------------------------------*

FORM release_bdc.

SUBMIT rsbdcsub WITH mappe EQ p_group
WITH von EQ sy-datum
WITH bis EQ sy-datum
WITH fehler EQ '.'
EXPORTING LIST TO MEMORY
AND RETURN.


ENDFORM. " release_bdc

*&---------------------------------------------------------------------*
*& Form scale_entry
*&---------------------------------------------------------------------*
* Populate the Scale quantities
*----------------------------------------------------------------------*
* -->P_SCALE_QTY
* -->P_SCALE_PRICE
*----------------------------------------------------------------------*
FORM scale_entry USING p_scale_qty
p_scale_price.

* Increment the Counter

g_counter = g_counter + 1.

IF p_scale_qty <> space.

CONCATENATE 'KONM-KSTBM(' g_counter ')' INTO g_field_name.

PERFORM bdc_insert_field USING g_field_name p_scale_qty.

CONCATENATE 'KONM-KBETR(' g_counter ')' INTO g_field_name.

PERFORM bdc_insert_field USING g_field_name p_scale_price.

ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form bdc_insert
*&---------------------------------------------------------------------*
* To uncheck the Unlimited (UEBTK)
*----------------------------------------------------------------------*

FORM bdc_insert USING f_name f_value.
CLEAR i_bdc_table.
i_bdc_table-fnam = f_name.
i_bdc_table-fval = f_value.
APPEND i_bdc_table.
ENDFORM. " bdc_insert
ABAP Tips by : Rajasekhar

Schedule Agreement Data Uploading

Schedule Agreement Data Uploading

*& Report  ZMM_ME31L_UPLOAD
*& Developed by : HARI
*& Description : Schedule agreement data uploading

*&---------------------------------------------------------------------

REPORT ZMMA_ME31L_UPLOAD
NO STANDARD PAGE HEADING
LINE-SIZE 255.

*----------------------------------------------------------------------*
* Include for Types, WA, Itab, Constants, Global Variable declarations *
*----------------------------------------------------------------------*

include ZMMA_ME31L_UPLOAD_TOP.

*----------------------------------------------------------------------*
* At Selection-screen event
*----------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM f_get_filename USING p_file.

*----------------------------------------------------------------------*
* Start-of-Selection event
*----------------------------------------------------------------------*

START-OF-SELECTION.

* Subroutine to upload the data into Internal table I_Upload.

PERFORM get_data.

i_ctu_params-defsize = 'X'.
i_ctu_params-NOBINPT = ''.
*i_ctu_params-DISMODE = p_mode.
i_ctu_params-UPDMODE = p_upd.


LOOP AT i_upload where lifnr is not initial.

v_index = sy-tabix.

** Create Scheduling Agreement: Initial Screen

perform bdc_dynpro using 'SAPMM06E' '0200'.

perform bdc_field using 'BDC_CURSOR'
'RM06E-LGORT'.
perform bdc_field using 'BDC_OKCODE'
'=KOPF'.
perform bdc_field using 'EKKO-LIFNR'
I_Upload-Lifnr.
perform bdc_field using 'RM06E-EVART'
I_Upload-evart.
perform bdc_field using 'RM06E-VEDAT'
i_upload-vedat.
perform bdc_field using 'EKKO-EKORG'
i_upload-ekorg.
perform bdc_field using 'EKKO-EKGRP'
i_upload-ekgrp.
perform bdc_field using 'RM06E-WERKS'
i_upload-werks.
perform bdc_field using 'RM06E-LGORT'
i_upload-lgort.

* Create Scheduling Agreement: Header Data

perform bdc_dynpro using 'SAPMM06E' '0201'.

perform bdc_field using 'BDC_CURSOR'
'EKKO-KDATE'.
perform bdc_field using 'BDC_OKCODE'
'=AB'.
perform bdc_field using 'EKKO-KDATB'
i_upload-kdatb.
perform bdc_field using 'EKKO-KDATE'
i_upload-kdate.
cnt1 = 0.

j = 0.
i = 1.

DO.

* this loop for item values.
* cnt1 = cnt1 + 1.
* g_count1 = cnt1.
*
*
** filling the item details.
*
*** Begin of New changes

if j EQ 14.

v_ebelp = i - 1.

perform bdc_dynpro using 'SAPMM06E' '0220'.

perform bdc_field using 'BDC_CURSOR'
'RM06E-EBELP'.
perform bdc_field using 'BDC_OKCODE'
* '=P+'.
'/00'.
perform bdc_field using 'RM06E-EBELP'
v_ebelp.
j = 1.

cnt1 = 2.
* cnt1 = cnt1 + 1.
g_count1 = cnt1.

PERFORM f_fill_item_details.

else.

cnt1 = cnt1 + 1.
g_count1 = cnt1.

PERFORM f_fill_item_details.

endif.


* filling the item details.

i = i + 1.
j = j + 1.

*** Ended New changes
cnt2 = 0.
g_count2 = 0.

do.

* this loop for item condition condition values.
cnt2 = cnt2 + 1.
g_count2 = cnt2.

* filling the item conditions per each item value.

PERFORM f_fill_item_condns.

v_index = v_index + 1.
read table i_upload index v_index.
if sy-subrc eq 0.
if not i_upload-ematn is initial.
exit.
endif.
else.
exit.
endif.

enddo.

perform bdc_dynpro using 'SAPMV13A' '0201'.

perform bdc_field using 'BDC_CURSOR'
'RV13A-DATAB'.
perform bdc_field using 'BDC_OKCODE'
'=BACK '.
* perform bdc_dynpro using 'SAPMM06E' '0211'.

read table i_upload index v_index.
if sy-subrc eq 0.
if not i_upload-lifnr is initial.
exit.
endif.
else.
exit.
endif.

ENDDO.

** confirmation for each new vendor save yes/no.
perform bdc_dynpro using 'SAPMM06E' '0220'.

PERFORM f_get_field USING 'RM06E-EVRTP'
g_count1.
perform bdc_field using 'BDC_CURSOR'
g_field.
perform bdc_field using 'BDC_OKCODE'
* '=BACK'.
'=BU'.
* perform bdc_dynpro using 'SAPLSPO1' '0100'.
* perform bdc_field using 'BDC_OKCODE'
* '=YES'.

PERFORM bdc_transaction using 'ME31L'.

ENDLOOP.
clear i_upload.
refresh i_upload.
free i_upload.
PERFORM bdc_close_group.

*----------------------------------------------------------------------*
* End-of-Selection event
*----------------------------------------------------------------------*
*
END-OF-SELECTION.

SKIP 2.

write:/ 'Total Number of Transactions : ' color 6, g_tot.
SKIP 1.

write:/ 'Total Number of Success Transactions : ' color 5, g_success.
SKIP 1.

write:/ 'Total Number of Error Transactions : ' color 1, g_error.

SKIP 1.
if g_error <> 0.
format color 3.
write:/ 'Please go to Transaction SM35 to process the errors' hotspot.
endif.

*----------------------------------------------------------------------*
* At line-Selection event
*----------------------------------------------------------------------*
*
AT LINE-SELECTION.

if SY-LISEL = 'Please go to Transaction SM35 to process the errors'.
call transaction 'SM35'.
endif.
*
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*

form bdc_dynpro using program dynpro.
clear bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
append bdcdata.
endform.

*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*

form bdc_field using fnam fval.
clear bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
append bdcdata.
endform.

*----------------------------------------------------------------------*
* Start new transaction according to parameters *
*----------------------------------------------------------------------*

form bdc_transaction using tcode.

data: l_mstring(480).
data: l_subrc like sy-subrc.
refresh messtab.

CALL TRANSACTION TCODE USING BDCDATA
* MODE p_mode
* UPDATE p_upd
messages into messtab
OPTIONS FROM i_ctu_params.

** counting for success records.
IF sy-SUBRC <> 0.
g_error = g_error + 1.
IF E_GROUP_OPENED = ' '.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = p_sesion
USER = sy-uname
KEEP = 'X'.
E_GROUP_OPENED = 'X'.
ENDIF.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = TCODE
TABLES
DYNPROTAB = BDCDATA.
else.

** counting for error records
g_success = g_success + 1.
ENDIF.

g_tot = g_tot + 1.

REFRESH BDCDATA.
*
* l_subrc = sy-subrc.
* write: / 'CALL_TRANSACTION',
* tcode,
* 'returncode:'(i05),
* l_subrc,
* 'RECORD:',
* sy-index.
* loop at messtab.
* select single * from t100 where sprsl = messtab-msgspra
* and arbgb = messtab-msgid
* and msgnr = messtab-msgnr.
* if sy-subrc = 0.
* l_mstring = t100-text.
* if l_mstring cs '&1'.
* replace '&1' with messtab-msgv1 into l_mstring.
* replace '&2' with messtab-msgv2 into l_mstring.
* replace '&3' with messtab-msgv3 into l_mstring.
* replace '&4' with messtab-msgv4 into l_mstring.
* else.
* replace '&' with messtab-msgv1 into l_mstring.
* replace '&' with messtab-msgv2 into l_mstring.
* replace '&' with messtab-msgv3 into l_mstring.
* replace '&' with messtab-msgv4 into l_mstring.
* endif.
* condense l_mstring.
* write: / messtab-msgtyp, l_mstring(250).
* else.
* write: / messtab.
* endif.
* endloop.
* skip.
* refresh bdcdata.
endform.

*&---------------------------------------------------------------------*
*& Form Get_data
* write the code to upload the file data in internal table I_UPLOAD.
*----------------------------------------------------------------------*

form get_data .

clear i_upload.
refresh i_upload.

CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = p_file
FILETYPE = 'DAT'
TABLES
data_tab = i_upload
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
NO_AUTHORITY = 10
OTHERS = 11
.
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. " Get_data

*&---------------------------------------------------------------------*
*& Form f_fill_item_details
*----------------------------------------------------------------------*

form f_fill_item_details.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = g_count1
IMPORTING
output = g_count1.


** Create Scheduling Agreement: Item overview

perform bdc_dynpro using 'SAPMM06E' '0220'.

PERFORM f_get_field USING 'EKPO-KTMNG'
g_count1.
perform bdc_field using 'BDC_CURSOR'
g_field.
perform bdc_field using 'BDC_OKCODE'
* '=DETZ'.
'/00'.
* PERFORM f_get_field USING 'RM06E-TCSELFLAG'
* g_count1.
* perform bdc_field using g_field
* 'X'.

* Begin of changes on DEVK903540 Request by Hari.

PERFORM f_get_field USING 'EKPO-KNTTP'
g_count1.
perform bdc_field using g_field
i_upload-knttp.

* End of changes on DEVK903540 Request by Hari.

PERFORM f_get_field USING 'EKPO-EMATN'
g_count1.
perform bdc_field using g_field
i_upload-ematn.

PERFORM f_get_field USING 'EKPO-KTMNG'
g_count1.
perform bdc_field using g_field
i_upload-ktmng.

* PERFORM f_get_field USING 'EKPO-NETPR'
* g_count1.
* perform bdc_field using g_field
* ' 1'.

* Begin of changes on DEVK903540 Request by Hari.

IF i_upload-knttp NE SPACE.


** getting GL A/C Details.

perform bdc_dynpro using 'SAPMM06E' '0511'.

perform bdc_field using 'BDC_CURSOR'
'EKKN-SAKTO'.
perform bdc_field using 'BDC_OKCODE'
'=ENTE'.
perform bdc_field using 'EKKN-SAKTO'
i_upload-sakto.

** getting Cost Center value.

perform bdc_dynpro using 'SAPLKACB' '0002'.

perform bdc_field using 'BDC_CURSOR'
'COBL-KOSTL'.
perform bdc_field using 'BDC_OKCODE'
'=ENTE'.
perform bdc_field using 'COBL-KOSTL'
i_upload-kostl.

ENDIF.

** Create Scheduling Agreement: Item detials

perform bdc_dynpro using 'SAPMM06E' '0220'.

PERFORM f_get_field USING 'RM06E-EVRTP'
g_count1.
perform bdc_field using 'BDC_CURSOR'
g_field.
perform bdc_field using 'BDC_OKCODE'
'=DETA'.
* perform bdc_field using 'RM06E-EBELP'
* '1'.
PERFORM f_get_field USING 'RM06E-TCSELFLAG'
g_count1.
perform bdc_field using g_field
'X'.


perform bdc_dynpro using 'SAPMM06E' '0211'.

perform bdc_field using 'BDC_CURSOR'
'EKPO-MWSKZ'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'EKPO-BSTAE'
i_upload-bstae.

perform bdc_field using 'EKPO-MWSKZ'
i_upload-mwskz.


* End of changes on DEVK903540 Request by Hari.


*** Create Scheduling Agreement: Item overview
*
perform bdc_dynpro using 'SAPMM06E' '0220'.

PERFORM f_get_field USING 'RM06E-EVRTP'
g_count1.
perform bdc_field using 'BDC_CURSOR'
g_field.
perform bdc_field using 'BDC_OKCODE'
'=DETZ'.
* perform bdc_field using 'RM06E-EBELP'
* '1'.
PERFORM f_get_field USING 'RM06E-TCSELFLAG'
g_count1.
perform bdc_field using g_field
'X'.

** Create Scheduling Agreement: Additional data

perform bdc_dynpro using 'SAPMM06E' '0212'.

perform bdc_field using 'BDC_CURSOR'
'EKPO-ETFZ2'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'EKPO-ETFZ1'
i_upload-etfz1.
perform bdc_field using 'EKPO-ETFZ2'
i_upload-etfz2.

* Begin of Add DEVK903540 Request by Hari.

perform bdc_field using 'EKPO-KZSTU'
i_upload-kzstu.

* End of Add on DEVK903540 Request by Hari.

** Create Scheduling Agreement: Item overview

perform bdc_dynpro using 'SAPMM06E' '0220'.

PERFORM f_get_field USING 'RM06E-EVRTP'
g_count1.
perform bdc_field using 'BDC_CURSOR'
g_field.
perform bdc_field using 'BDC_OKCODE'
'=KO'.
* perform bdc_field using 'RM06E-EBELP'
* '1'.
PERFORM f_get_field USING 'RM06E-TCSELFLAG'
g_count1.
perform bdc_field using g_field
'X'.

perform bdc_dynpro using 'SAPMV13A' '0201'.

PERFORM f_get_field USING 'KONP-KBETR'
g_count1.
perform bdc_field using 'BDC_CURSOR'
g_field.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RV13A-DATAB'
i_upload-datab.
perform bdc_field using 'RV13A-DATBI'
i_upload-datbi.

endform. " f_fill_operation

*&---------------------------------------------------------------------*
*& Form f_get_field
*----------------------------------------------------------------------*

form f_get_field using p_name p_count1 .

CLEAR: g_field.

CONCATENATE p_name '(' p_count1 ')' INTO g_field.

endform. " f_get_field

*&---------------------------------------------------------------------*
*& Form f_fill_item_condns
*----------------------------------------------------------------------*

form f_fill_item_condns .


CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = g_count2
IMPORTING
output = g_count2.

PERFORM f_get_field2 USING 'KONP-KSCHL'
g_count2.
perform bdc_field using g_field2
i_upload-kschl.

PERFORM f_get_field2 USING 'KONP-KBETR'
g_count2.
perform bdc_field using g_field2
i_upload-kbetr.

* Begin of changes on DEVK903540 Request by Hari.

PERFORM f_get_field2 USING 'KONP-KPEIN'
g_count2.
perform bdc_field using g_field2
i_upload-kpein.

* End of changes on DEVK903540 Request by Hari.

endform. " f_fill_item_condns

*&---------------------------------------------------------------------*
*& Form f_get_field2
*----------------------------------------------------------------------*

form f_get_field2 using p_name2 p_count2.

clear: g_field2.

CONCATENATE p_name2 '(' p_count2 ')' INTO g_field2.


endform. " f_get_field2

*&---------------------------------------------------------------------*
*& Form f_get_filename
*----------------------------------------------------------------------*

form f_get_filename using p_file.

CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
* DEF_FILENAME = ' '
* DEF_PATH = ' '
mask = ',*.*,*.*.'
mode = 'O'
title = ' '
IMPORTING
filename = p_file
* RC =
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5 .

endform. " f_get_filename

*&---------------------------------------------------------------------*
*& Form bdc_close_group
*----------------------------------------------------------------------*

form bdc_close_group .

* close batchinput group

IF E_GROUP_OPENED = 'X'.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
ENDIF.

endform. " bdc_close_group
ABAP Tips by : Ravi

Upload Material Master - Finish Goods

Upload Material Master - Finish Goods

**********************************************************
* Prepare you excel file as per inter table RECORD
* and paste it in text file for uplaoding
**********************************************************

report ZSH_MATL_UP
no standard page heading line-size 255.

include bdcrecx1.

parameters: dataset(132) lower case.

parameters: Mfile like rlgrap-filename default
'h:\tape_lepage\UPLOAD\MATL.txt'.
PARAMETERS: CTY(2) OBLIGATORY.

data: begin of record occurs 0,
* data element: MATNR
MATNR_001(018),
* data element: MBRSH
MBRSH_002(001),
* data element: MTART
MTART_003(004),
* data element: XFELD
KZSEL_01_004(001),
* data element: XFELD
KZSEL_02_005(001),
* data element: XFELD
KZSEL_04_006(001),
* data element: XFELD
KZSEL_05_007(001),
* data element: XFELD
KZSEL_06_008(001),
********
* data element: XFELD
KZSEL_09_009(001),
*******
* data element: XFELD
KZSEL_12_009(001),
* data element: XFELD
KZSEL_13_010(001),
* data element: XFELD
KZSEL_14_011(001),
* data element: XFELD
KZSEL_15_012(001),
* data element: XFELD
KZSEL_17_013(001),
* data element: XFELD
KZSEL_18_014(001),

* data element: XFELD
KZSEL_11_001(001),
* data element: XFELD
KZSEL_11_005(001),
* data element: XFELD
KZSEL_11_006(001),
* data element: XFELD
KZSEL_11_007(001),
* data element: XFELD
KZSEL_11_008(001),



*** data element: XFELD
** KZSEL_11_013(001),
*** data element: XFELD
** KZSEL_12_014(001),
*** data element: XFELD
** KZSEL_13_015(001),
*** data element: XFELD
** KZSEL_17_016(001),
*** data element: XFELD
** KZSEL_18_017(001),
*** data element: XFELD
** KZSEL_13_018(001),
*** data element: XFELD
** KZSEL_14_019(001),



* data element: WERKS_D
WERKS_020(004),
* data element: LGORT_D
LGORT_021(004),
* data element: VKORG
VKORG_022(004),
* data element: VTWEG
VTWEG_023(002),
* data element: MAKTX
MAKTX_024(040),
* data element: MEINS
MEINS_025(003),
* data element: MATKL
MATKL_026(009),
* data element: SPART
SPART_027(002),
* data element: MTPOS_MARA
MTPOS_MARA_028(004),
* data element: BRGEW
BRGEW_029(017),
* data element: GEWEI
GEWEI_030(003),
* data element: NTGEW
NTGEW_031(017),
* data element: MAKTX
MAKTX_032(040),
* data element: MAKTX
MAKTX_033(040),
* data element: MEINS
MEINS_034(003),
* data element: SPART
SPART_035(002),
* data element: MATKL
MATKL_036(009),
* data element: SKTOF
SKTOF_037(001),
* data element: TAXKM
TAXKM_01_038(001),
* data element: TAXKM
TAXKM_02_039(001),
* data element: MAKTX
MAKTX_040(040),
* data element: TAXKM
TAXKM_03_041(001),
* data element: TAXKM
TAXKM_04_042(001),
* data element: MAKTX
MAKTX_043(040),
* data element: MEINS
MEINS_044(003),
* data element: SPART
SPART_045(002),
* data element: MATKL
MATKL_046(009),
* data element: SKTOF
SKTOF_047(001),
* data element: MAKTX
MAKTX_048(040),
* data element: STGMA
VERSG_049(001),
* data element: MTPOS_MARA
MTPOS_MARA_050(004),
* data element: MTPOS
MTPOS_051(004),
* data element: PROVG
PROVG_052(002),
* data element: MAKTX
MAKTX_053(040),
* data element: MEINS
MEINS_054(003),
* data element: BRGEW
BRGEW_055(017),
* data element: GEWEI
GEWEI_056(003),
* data element: NTGEW
NTGEW_057(017),
* data element: MTVFP
MTVFP_058(002),
* data element: TRAGR
TRAGR_059(004),
* data element: LADGR
LADGR_060(004),
* data element: PRCTR
PRCTR_061(010),


*ADDED
* data element: MAKTX
MAKTX_062_1(040),
* data element: MEINS
MEINS_063_1(003),
* data element: EKGRP
EKGRP_064_1(003),
******

* data element: MAKTX
MAKTX_062(040),
* data element: MEINS
MEINS_063(003),
* data element: EKGRP
EKGRP_064(003),
* data element: DISMM
DISMM_065(002),
* data element: DISPO
DISPO_066(003),
* data element: DISLS
DISLS_067(002),
* data element: BSTMI
BSTMI_068(017),
* data element: BSTMA
BSTMA_069(017),
* data element: MAKTX
MAKTX_070(040),
* data element: BESKZ
BESKZ_071(001),
* data element: LGPRO
LGPRO_072(004),
* data element: RGEKM
RGEKZ_073(001),
* data element: DZEIT
DZEIT_074(003),
* data element: FHORI
FHORI_075(003),
* data element: MAKTX
MAKTX_076(040),
* data element: PERKZ
PERKZ_077(001),
* data element: MTVFP
MTVFP_078(002),
* data element: MAKTX
MAKTX_079(040),
* data element: MAKTX
MAKTX_080(040),
* data element: MEINS
MEINS_081(003),
* data element: LGPRO
LGPRO_082(004),
* data element: DZEIT
DZEIT_083(003),
* data element: MAKTX
MAKTX_084(040),
* data element: MEINS
MEINS_085(003),
* data element: DATTP
IPRKZ_086(001),
* data element: MAKTX
MAKTX_087(040),
* data element: BRGEW
BRGEW_088(017),
* data element: GEWEI
GEWEI_089(003),
* data element: NTGEW
NTGEW_090(017),
* data element: PRCTR
PRCTR_091(010),
* data element: MAKTX
MAKTX_092(040),
* data element: MEINS
MEINS_093(003),
* data element: SPART
SPART_094(002),
* data element: BKLAS
BKLAS_095(004),
* data element: VPRSV
VPRSV_096(001),
* data element: PEINH
PEINH_097(006),
* data element: STPRS
STPRS_098(015),
* data element: MAKTX
MAKTX_099(040),
* data element: MAKTX
MAKTX_100(040),
* data element: MEINS
MEINS_101(003),
* data element: CK_EKALREL
EKALR_102(001),
* data element: HRKFT
HRKFT_103(004),
* data element: AWSLS
AWSLS_104(006),
* data element: PRCTR
PRCTR_105(010),
* data element: CK_LOSGR
LOSGR_106(017),
* data element: MAKTX
MAKTX_107(040),
* data element: BKLAS
BKLAS_108(004),
* data element: VPRSV
VPRSV_109(001),
* data element: PEINH
PEINH_110(006),
* data element: STPRS
STPRS_111(015),
end of record.

*** End generated data section ***

start-of-selection.


CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = MFILE
FILETYPE = 'DAT'
TABLES
DATA_TAB = record
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
OTHERS = 10.

IF SY-SUBRC <> 0.
WRITE:/ 'SY-SUBRC:', SY-SUBRC.
ENDIF.



LOOP AT RECORD.

*perform open_dataset using dataset.
*perform open_group.
*
*do.
*
*read dataset dataset into record.
*if sy-subrc <> 0. exit. endif.

perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RMMG1-MATNR'
record-MATNR_001.
perform bdc_field using 'RMMG1-MBRSH'
record-MBRSH_002.
perform bdc_field using 'RMMG1-MTART'
record-MTART_003.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(15)'.
perform bdc_field using 'BDC_OKCODE'
'=P+'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
record-KZSEL_01_004.
perform bdc_field using 'MSICHTAUSW-KZSEL(02)'
record-KZSEL_02_005.
perform bdc_field using 'MSICHTAUSW-KZSEL(04)'
record-KZSEL_04_006.
perform bdc_field using 'MSICHTAUSW-KZSEL(05)'
record-KZSEL_05_007.
perform bdc_field using 'MSICHTAUSW-KZSEL(06)'
record-KZSEL_06_008.
*****
perform bdc_field using 'MSICHTAUSW-KZSEL(09)'
record-KZSEL_09_009.
*****
perform bdc_field using 'MSICHTAUSW-KZSEL(12)'
record-KZSEL_12_009.
perform bdc_field using 'MSICHTAUSW-KZSEL(13)'
record-KZSEL_13_010.
perform bdc_field using 'MSICHTAUSW-KZSEL(14)'
record-KZSEL_14_011.
perform bdc_field using 'MSICHTAUSW-KZSEL(15)'
record-KZSEL_15_012.
perform bdc_field using 'MSICHTAUSW-KZSEL(17)'
record-KZSEL_17_013.
perform bdc_field using 'MSICHTAUSW-KZSEL(18)'
record-KZSEL_18_014.



perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.

perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
record-KZSEL_11_001.
perform bdc_field using 'MSICHTAUSW-KZSEL(05)'
record-KZSEL_11_005.
perform bdc_field using 'MSICHTAUSW-KZSEL(06)'
record-KZSEL_11_006.
perform bdc_field using 'MSICHTAUSW-KZSEL(07)'
record-KZSEL_11_007.
perform bdc_field using 'MSICHTAUSW-KZSEL(08)'
record-KZSEL_11_008.

*perform bdc_dynpro using 'SAPLMGMM' '0070'.
*perform bdc_field using 'BDC_CURSOR'
* 'MSICHTAUSW-DYTXT(01)'.
*perform bdc_field using 'BDC_OKCODE'
* '/00'.
*perform bdc_dynpro using 'SAPLMGMM' '0070'.
*perform bdc_field using 'BDC_CURSOR'
* 'MSICHTAUSW-DYTXT(14)'.
*perform bdc_field using 'BDC_OKCODE'
* '=ENTR'.
*perform bdc_field using 'MSICHTAUSW-KZSEL(13)'
* record-KZSEL_13_018.
*perform bdc_field using 'MSICHTAUSW-KZSEL(14)'
* record-KZSEL_14_019.


perform bdc_dynpro using 'SAPLMGMM' '0080'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-DISPR'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'RMMG1-WERKS'
record-WERKS_020.
perform bdc_field using 'RMMG1-LGORT'
record-LGORT_021.
perform bdc_field using 'RMMG1-VKORG'
record-VKORG_022.
perform bdc_field using 'RMMG1-VTWEG'
record-VTWEG_023.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_024.
perform bdc_field using 'MARA-MEINS'
record-MEINS_025.
perform bdc_field using 'MARA-MATKL'
record-MATKL_026.
perform bdc_field using 'MARA-SPART'
record-SPART_027.
perform bdc_field using 'MARA-MTPOS_MARA'
record-MTPOS_MARA_028.
perform bdc_field using 'BDC_CURSOR'
'MARA-NTGEW'.
perform bdc_field using 'MARA-BRGEW'
record-BRGEW_029.
perform bdc_field using 'MARA-GEWEI'
record-GEWEI_030.
perform bdc_field using 'MARA-NTGEW'
record-NTGEW_031.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MAKT-MAKTX'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_032.

perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_033.
perform bdc_field using 'MARA-MEINS'
record-MEINS_034.
perform bdc_field using 'MARA-SPART'
record-SPART_035.
perform bdc_field using 'MARA-MATKL'
record-MATKL_036.
perform bdc_field using 'MVKE-SKTOF'
record-SKTOF_037.
perform bdc_field using 'MG03STEUER-TAXKM(01)'
record-TAXKM_01_038.
perform bdc_field using 'MG03STEUER-TAXKM(02)'
record-TAXKM_02_039.
perform bdc_field using 'BDC_CURSOR'
'MVKE-AUMNG'.
perform bdc_dynpro using 'SAPLMGMM' '4200'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MAKT-MAKTX'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_040.
perform bdc_field using 'MG03STEUER-TAXKM(03)'
record-TAXKM_03_041.

IF CTY = 'CA'.
perform bdc_field using 'MG03STEUER-TAXKM(04)'
record-TAXKM_04_042.
ENDIF.

perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MAKT-MAKTX'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_043.
perform bdc_field using 'MARA-MEINS'
record-MEINS_044.
perform bdc_field using 'MARA-SPART'
record-SPART_045.
perform bdc_field using 'MARA-MATKL'
record-MATKL_046.
perform bdc_field using 'MVKE-SKTOF'
record-SKTOF_047.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_048.
perform bdc_field using 'MVKE-VERSG'
record-VERSG_049.
perform bdc_field using 'MARA-MTPOS_MARA'
record-MTPOS_MARA_050.
perform bdc_field using 'MVKE-MTPOS'
record-MTPOS_051.
perform bdc_field using 'MVKE-PROVG'
record-PROVG_052.
perform bdc_field using 'BDC_CURSOR'
'MVKE-PRAT1'.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_053.
perform bdc_field using 'MARA-MEINS'
record-MEINS_054.
perform bdc_field using 'MARA-BRGEW'
record-BRGEW_055.
perform bdc_field using 'MARA-GEWEI'
record-GEWEI_056.
perform bdc_field using 'MARA-NTGEW'
record-NTGEW_057.
perform bdc_field using 'MARC-MTVFP'
record-MTVFP_058.
perform bdc_field using 'MARA-TRAGR'
record-TRAGR_059.
perform bdc_field using 'MARC-LADGR'
record-LADGR_060.
perform bdc_field using 'BDC_CURSOR'
'MARC-PRCTR'.
perform bdc_field using 'MARC-PRCTR'
record-PRCTR_061.

perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_062_1.
perform bdc_field using 'MARA-MEINS'
record-MEINS_063_1.
perform bdc_field using 'MARC-EKGRP'

record-EKGRP_064_1.


perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_062.
perform bdc_field using 'MARA-MEINS'
record-MEINS_063.
perform bdc_field using 'MARC-EKGRP'
record-EKGRP_064.
perform bdc_field using 'BDC_CURSOR'
'MARC-DISPO'.
perform bdc_field using 'MARC-DISMM'
record-DISMM_065.
perform bdc_field using 'MARC-DISPO'
record-DISPO_066.
perform bdc_field using 'MARC-DISLS'
record-DISLS_067.
perform bdc_field using 'MARC-BSTMI'
record-BSTMI_068.
perform bdc_field using 'MARC-BSTMA'
record-BSTMA_069.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_070.
perform bdc_field using 'MARC-BESKZ'
record-BESKZ_071.
perform bdc_field using 'MARC-LGPRO'
record-LGPRO_072.
perform bdc_field using 'MARC-RGEKZ'
record-RGEKZ_073.
perform bdc_field using 'BDC_CURSOR'
'MARC-DZEIT'.
perform bdc_field using 'MARC-DZEIT'
record-DZEIT_074.
perform bdc_field using 'MARC-FHORI'
record-FHORI_075.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MAKT-MAKTX'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_076.
perform bdc_field using 'MARC-PERKZ'
record-PERKZ_077.
perform bdc_field using 'MARC-MTVFP'
record-MTVFP_078.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MAKT-MAKTX'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_079.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MAKT-MAKTX'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_080.
perform bdc_field using 'MARA-MEINS'
record-MEINS_081.
perform bdc_field using 'MARC-LGPRO'
record-LGPRO_082.
perform bdc_field using 'MARC-DZEIT'
record-DZEIT_083.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MAKT-MAKTX'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_084.
perform bdc_field using 'MARA-MEINS'
record-MEINS_085.
perform bdc_field using 'MARA-IPRKZ'
record-IPRKZ_086.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MAKT-MAKTX'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_087.
perform bdc_field using 'MARA-BRGEW'
record-BRGEW_088.
perform bdc_field using 'MARA-GEWEI'
record-GEWEI_089.
perform bdc_field using 'MARA-NTGEW'
record-NTGEW_090.
perform bdc_field using 'MARC-PRCTR'
record-PRCTR_091.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_092.
perform bdc_field using 'MARA-MEINS'
record-MEINS_093.
perform bdc_field using 'MARA-SPART'
record-SPART_094.
perform bdc_field using 'BDC_CURSOR'
'MBEW-STPRS'.
perform bdc_field using 'MBEW-BKLAS'
record-BKLAS_095.
perform bdc_field using 'MBEW-VPRSV'
record-VPRSV_096.
perform bdc_field using 'MBEW-PEINH'
record-PEINH_097.
perform bdc_field using 'MBEW-STPRS'
record-STPRS_098.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MAKT-MAKTX'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_099.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_100.
perform bdc_field using 'BDC_CURSOR'
'MARC-AWSLS'.
perform bdc_field using 'MARA-MEINS'
record-MEINS_101.
perform bdc_field using 'MBEW-EKALR'
record-EKALR_102.
perform bdc_field using 'MBEW-HRKFT'
record-HRKFT_103.
perform bdc_field using 'MARC-AWSLS'
record-AWSLS_104.
perform bdc_field using 'MARC-PRCTR'
record-PRCTR_105.
perform bdc_field using 'MARC-LOSGR'
record-LOSGR_106.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MAKT-MAKTX'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_107.
perform bdc_field using 'MBEW-BKLAS'
record-BKLAS_108.
perform bdc_field using 'MBEW-VPRSV'
record-VPRSV_109.
perform bdc_field using 'MBEW-PEINH'
record-PEINH_110.
perform bdc_field using 'MBEW-STPRS'
record-STPRS_111.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'MM01'.

**enddo.
**
**perform close_group.
**perform close_dataset using dataset.

ENDLOOP.

Upload the Pricing Condtion Records for Materials

Upload the Pricing Condtion Records for Materials

************************************************************************
* Report to Upload the pricing condtion records for materials. *
*----------------------------------------------------------------------*
* Program : ZSDR_PRICE_UPLOAD *
* Author : Sreenivasa Gautam.G - *
*----------------------------------------------------------------------*
* Description: *
* This report Creat pricing condition records for materials *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Tables Used : SELECT UPDATE INSERT DELETE *
* MVKE X *
* *
* Input/Output Files: *
* Transactions called: *
* Includes: *
* Run Frequency - *
************************************************************************
* Program History *
* ---------------------------------------------------------------------*
* Date Change No Change Request SAP Rel NSC Rel *
* Description *
* ---------------------------------------------------------------------*
* 4.6C *
* *
*----------------------------------------------------------------------*


REPORT zsdr_price_upload MESSAGE-ID zsdr_bdc_vk11 LINE-SIZE 150
LINE-COUNT 75 .


******Internal Table for Header Data.

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.



*************START-OF-SELECTION
START-OF-SELECTION.

******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.
* * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM. " get_filename
*&---------------------------------------------------------------------*
*& Form upload_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM upload_file.

DATA : frow VALUE 2 TYPE i,
fcol VALUE 1 TYPE i,
erow VALUE 10000 TYPE i,
ecol VALUE 7 TYPE i,
ecol1 VALUE 1 TYPE i,
c_col1 TYPE i VALUE '0001',
c_col2 TYPE i VALUE '0002',
c_col3 TYPE i VALUE '0003',
&nb! sp; c_col4 TYPE i VALUE '0004',
c_col5 TYPE i VALUE '0005',
c_col6 TYPE i VALUE '0006',
c_col7 TYPE i VALUE '0007'.

***FM used to UPLOAD data from Flat file

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_fname
i_begin_col = fcol
i_begin_row = frow
i_end_col = ecol
i_end_row = erow
TABLES
intern = t_xls_file
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.

IF sy-subrc <> 0.
MESSAGE e000.
ENDIF.


****T_XLS_FILE is initial, stop the process & throw message
IF t_xls_file[] IS INITIAL.
FORMAT COLOR 6 ON INTENSIFIED ON.
WRITE:/ 'No Data Exists '.
FORMAT COLOR OFF INTENSIFIED OFF.
STOP.
ELSE.


* Sort table by rows and colums
SORT t_xls_file BY row col.

* Get first row retrieved
READ TABLE t_xls_file INDEX 1.


* Set first row retrieved to current row
v_currentrow = t_xls_file-row.


**Loop to move data in internal Table
LOOP AT t_xls_file .
* Reset values for next row
IF t_xls_file-row NE v_currentrow.
APPEND wa_header TO t_header.
CLEAR wa_header.
v_currentrow = t_xls_file-row.
ENDIF.

CASE t_xls_file-col.
WHEN c_col1. "Kschl
wa_header-kschl = t_xls_file-value.
WHEN c_col2. "Vkorg
wa_header-vkorg = t_xls_file-value.
WHEN c_col3. "vtweg
wa_header-vtweg = t_xls_file-value.
WHEN c_col4. "Matnr
wa_header-matnr = t_xls_file-value.
WHEN c_col5. "Kbetr
wa_header-kbetr = t_xls_file-value.
WHEN c_col6. "FROm
wa_header-datab = t_xls_file-value.
WHEN c_col7. "TO
wa_header-datbi = t_xls_file-value.

ENDCASE.
ENDLOOP.
APPEND wa_header TO t_header.
CLEAR wa_header.
ENDIF.
****To process the data
PERFORM f_process.


ENDFORM. " upload_file
*&---------------------------------------------------------------------*
*& Form READ_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM read_data.

****To make Uniq Records in Header Level
SORT t_header BY kschl vkorg vtweg.
DELETE ADJACENT DUPLICATES FROM t_header COMPARING
kschl vkorg vtweg .
SORT t_item BY vkorg vtweg matnr.
DATA : wa1_item TYPE type_item.
DATA : l_cnt TYPE i.
DATA : flag(1) TYPE c. "to process the Line item.



***Looping Header Table.

LOOP AT t_header INTO wa_header.
***************************************

PERFORM bdc_dynpro US! ING 'SAPMV13A' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RV13A-KSCHL'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ANTA'.
PERFORM bdc_field USING 'RV13A-KSCHL'
wa_header-kschl.
PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RV130-SELKZ(03)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=WEIT'.
PERFORM bdc_field USING 'RV130-SELKZ(03)'
'X'.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.
PERFORM bdc_field USING 'BDC_CURSOR'
'KOMG-VKORG'.

PERFORM bdc_field USING 'KOMG-VKORG'
wa_header-vkorg.
PERFORM bdc_field USING 'KOMG-VTWEG'
wa_header-vtweg.

****To handle Line Items.
LOOP AT t_item INTO wa1_item WHERE vkorg = wa_header-vkorg AND
vtweg = wa_header-vtweg.
wa_item = wa1_item.



******Flag Set only After processing first 14 records .
IF flag = ' '.
v_lindx = v_lindx + 01.
SHIFT v_lindx LEFT DELETING LEADING '0'.
v_item = v_lindx .

CONCATENATE 'KOMG-MATNR(' v_item ')' INTO v_matnr.

PERFORM bdc_field USING v_matnr
wa_item-matnr.

CONCATENATE 'KONP-KBETR(' v_item ')' INTO v_kbetr.

PERFORM bdc_field USING v_kbetr
wa_item-kbetr.


CONCATENATE 'RV13A-DATAB(' v_item ')' INTO v_dat.

PERFORM bdc_field USING v_dat
wa_item-datab.


CONCATENATE 'RV13A-DATBI(' v_item ')' INTO v_dat1.

PERFORM bdc_field USING v_dat1
wa_item-datbi.


IF v_item = 14.
flag = 'X'.

PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.

PERFORM bdc_field USING 'BDC_OKCODE'
'=P+'.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.

CLEAR v_lindx.
CLEAR v_item.
CONTINUE.
ENDIF.
ENDIF.



***Flag is Set after Processing of 14 records.
****** TO process rest of Records
IF flag = 'X'.


v_pgedwn2 = v_pgedwn2 + 1.
v_lindx1 = v_lindx1 + 01.
SHIFT v_lindx1 LEFT DE! LETING LEADING '0'.
v_item = v_lindx1 .

CONCATENATE 'KOMG-MATNR(' v_it! em ')' INTO v_matnr.

PERFORM bdc_field USING v_matnr
wa_item-matnr.

CONCATENATE 'KONP-KBETR(' v_item ')' INTO v_kbetr.

PERFORM bdc_field USING v_kbetr
wa_item-kbetr.


CONCATENATE 'RV13A-DATAB(' v_item ')' INTO v_dat.

PERFORM bdc_field USING v_dat
wa_item-datab.


CONCATENATE 'RV13A-DATBI(' v_item ')' INTO v_dat1.

PERFORM bdc_field USING v_dat1
wa_item-datbi.

IF v_pgedwn2 = 13.



PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.


PERFORM bdc_field USING 'BDC_OKCODE'
'=P+'.

PERFORM bdc_dynpro USING 'SAPMV13A' '1004'.


v_pgedwn2 = 0.
v_lindx1 = 1.
CLEAR v_item.

CONTINUE.
ENDIF.
ENDIF.


ENDLOOP.

PERFORM bdc_field USING 'BDC_OKCODE'
'=SICH'.

****** Calling Transaction after Processing All items.

CALL TRANSACTION 'VK11' USING bdctab
OPTIONS FROM c_params MESSAGES INTO tmess_mtab.
*
REFRESH bdctab.
CLEAR : bdctab.
CLEAR : wa_item.
CLEAR : wa1_item.
CLEAR : wa_header.
CLEAR : l_cnt.
CLEAR : v_lindx1.
CLEAR: v_pgedwn2,v_lindx.



LOOP AT tmess_mtab .
l_cnt = l_cnt + 1.
READ TABLE t_item INTO wa_item INDEX l_cnt .
!

CALL FUNCTION 'MASS_MESSAGE_GET' "To get the Message Text
EXPORTING
arbgb = tmess_mtab-msgid
msgnr = tmess_mtab-msgnr
msgv1 = tmess_mtab-msgv1
msgv2 = tmess_mtab-msgv2
msgv3 = tmess_mtab-msgv3
msgv4 ! = tmess_mtab-msgv4
IMPORTING
msgtext = wa_mtab-text
EXCEPTIONS
message_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
wa_mtab-matnr = wa_item-matnr.
wa_mtab-msgtyp = tmess_mtab-msgtyp.
wa_mtab-msgid = tmess_mtab-msgid.
wa_mtab-msgn! r = tmess_mtab-msgnr.
APPEND wa_mtab TO t_mtab.
CLEAR wa_mtab-text.
CLEAR wa_item.
ENDLOOP.

ENDLOOP.

ENDFORM. " READ_DATA
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0300 text
* -->P_0301 text
!
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.

CLEAR bdctab.
bdctab-program = program.
bdctab-dynpro = dynpro.
bdctab-dynbegin = 'X'.
APPEND bdctab.

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.

CLEAR : t_xls_file,
wa_header,
wa_item,
wa_mvke,
wa_tvkov,
wa_error,
wa_mtab.


ENDFORM. " f_Refresh

Program Loads the Material Assignment of Routings

Program Loads the Material Assignment of Routings

Okay this is how it works:

When you try to create, you would find a pushbutton 'INSERT NEW LINES' or something simialr to enter your data in the next line. Say you're entering the Material inthe first row, its field position would be MARA-MATNR(01). Now when you click the Insert Pushbitton the cursor always is at positon 2. so you have to loop the remaining data to enter in MARA-MATNR(02). Yougenereally set a counter and pass that counter value (in this case the counter value is 2 always)

The other case when you don't have a push button to Insert. Enter all the rows and then do a Page down. Now your cursor would sit back at position 2 again. Say if there are 20 rows in the first screen. You would keep incrementing the counter and then when it is 21 you do a pagedown and then reset the counter to 2. You loop the pagedown and in it you loop the counter.

I have attached a BDC where I use the second case (no push button). Do a recording and then you would know all the answers by yourself.

*&---------------------------------------------------------------------*
*& REPORT ZPP0122 *
*&---------------------------------------------------------------------*
*& Module : PP |
*& Application : The program loads the Material Assignment of Routings |
*& |
*&---------------------------------------------------------------------*
REPORT zpp0122 NO STANDARD PAGE HEADING
MESSAGE-ID z0
LINE-SIZE 132
LINE-COUNT 65(2).



*----------------------------------------------------------------------*
* Internal Tables *
*----------------------------------------------------------------------*


*Internal table for the Routing fields.

DATA: BEGIN OF i_rout OCCURS 0,

plnnr(8),
plnal(2),
matnr(18),
werks(4),

END OF i_rout.


DATA:
g_my_rec_in LIKE i_rout.

** Declare internal table for Call Transaction and BDC Session

DATA: i_bdc_table LIKE bdcdata OCCURS 0 WITH HEADER LINE.


*----------------------------------------------------------------------*
* Global Variables *
*----------------------------------------------------------------------*

*
DATA: g_counter(2) TYPE n,
g_field_name(18) TYPE c,
zc_yes TYPE syftype VALUE 'X'.

*----------------------------------------------------------------------*
* Selection Screen *
*----------------------------------------------------------------------*

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

PARAMETERS: p_fname1 TYPE localfile .

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.
PARAMETERS: p_rloc1 AS CHECKBOX DEFAULT 'X'.


SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE text-005.
PARAMETERS p_group(12) OBLIGATORY DEFAULT 'ZROUTING'.

SELECTION-SCREEN END OF BLOCK c.
SELECTION-SCREEN END OF BLOCK b.
SELECTION-SCREEN END OF BLOCK a.

**WRITE the report header
TOP-OF-PAGE.
INCLUDE zheading.

*----------------------------------------------------------------------*
* Start of selection *
*----------------------------------------------------------------------*

START-OF-SELECTION.

* Load Input file
PERFORM f_load_input_file.

* Create BDC records.
PERFORM create_bdc_records .


*&---------------------------------------------------------------------*
*& Form Create_BDC_records
*&---------------------------------------------------------------------*
* perform the BDC for the records in the internal table
*----------------------------------------------------------------------*

FORM create_bdc_records .

IF NOT i_rout[] IS INITIAL.

** Open BDC session

PERFORM open_bdc_session.

LOOP AT i_rout.

g_my_rec_in = i_rout.


AT NEW plnnr.

CLEAR i_bdc_table[].

PERFORM insert_screen_header.

ENDAT.


CONCATENATE 'MAPL-PLNAL(' g_counter ')' INTO g_field_name.

PERFORM bdc_field USING g_field_name i_rout-plnal.

CONCATENATE 'MAPL-MATNR(' g_counter ')' INTO g_field_name.

PERFORM bdc_field USING g_field_name i_rout-matnr.

CONCATENATE 'MAPL-WERKS(' g_counter ')' INTO g_field_name.

PERFORM bdc_field USING g_field_name i_rout-werks.

PERFORM bdc_field USING 'BDC_OKCODE' '/00'.

g_counter = g_counter + 1.


* Page Down for further entries

IF g_counter = 19.

PERFORM bdc_field USING 'BDC_OKCODE' '=P+'.

PERFORM bdc_dynpro USING 'SAPLCZDI' '1010'.

g_counter = 2.

ENDIF.


AT END OF plnnr.

PERFORM bdc_field USING 'BDC_OKCODE' '=BACK'.

PERFORM bdc_dynpro USING 'SAPLCPDI' '1200'.

PERFORM bdc_field USING 'BDC_OKCODE' '=BU'.

PERFORM insert_bdc_new.

ENDAT.

ENDLOOP.

CLEAR i_rout[].

PERFORM close_bdc_session.

** Release the BDC sessions created
PERFORM release_bdc.

ENDIF.


ENDFORM. " open_group


*&---------------------------------------------------------------------*
*& Form bdc_dynpro_start
*&---------------------------------------------------------------------*
* Call the screen for the input of fields
*----------------------------------------------------------------------*
* -->P_G_PROGRAM_1
* -->P_G_SCREEN
*----------------------------------------------------------------------*
FORM bdc_dynpro USING p_g_program_1
p_g_screen.

CLEAR i_bdc_table.
i_bdc_table-program = p_g_program_1.
i_bdc_table-dynpro = p_g_screen.
i_bdc_table-dynbegin = 'X'.
APPEND i_bdc_table.

ENDFORM. " bdc_dynpro_start

*&---------------------------------------------------------------------*
*& Form bdc_field
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*

FORM bdc_field USING f_name f_value.
* IF f_value <> space.
CLEAR i_bdc_table.
i_bdc_table-fnam = f_name.
i_bdc_table-fval = f_value.
APPEND i_bdc_table.
* ENDIF.
ENDFORM. "bdc_insert_field


*&--------------------------------------------------------------------*
*& Form open_bdc_session
*&--------------------------------------------------------------------*
* Create the BDC session
*---------------------------------------------------------------------*
FORM open_bdc_session .


** Open BDC session and creat and update condition records

CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
* DEST = FILLER8
group = p_group
* HOLDDATE = FILLER8
keep = 'X'
user = sy-uname
* RECORD = FILLER1
* PROG = SY-CPROG
* IMPORTING
* QID =
EXCEPTIONS
client_invalid = 1
destination_invalid = 2
group_invalid = 3
group_is_locked = 4
holddate_invalid = 5
internal_error = 6
queue_error = 7
running = 8
system_lock_error = 9
user_invalid = 10
OTHERS = 11
.
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. " create_bdc_session

*&---------------------------------------------------------------------*
*& Form insert_screen_header
*&---------------------------------------------------------------------*
* Header Data inserted
*----------------------------------------------------------------------*

FORM insert_screen_header .

g_counter = 1.

* First screen

PERFORM bdc_dynpro USING 'SAPLCPDI' '1010'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RC271-PLNNR'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ALUE'.

PERFORM bdc_field USING 'RC271-PLNNR' g_my_rec_in-plnnr.

PERFORM bdc_field USING 'RC27M-MATNR' ' '.

PERFORM bdc_field USING 'RC27M-WERKS' ' '.

PERFORM bdc_field USING 'RC271-PLNAL' ' '.

*next screen

PERFORM bdc_dynpro USING 'SAPLCPDI' '1200'.

PERFORM bdc_field USING 'BDC_OKCODE' '=MTUE'.

*next screen

PERFORM bdc_dynpro USING 'SAPLCZDI' '1010'.

ENDFORM. " insert_screen_header

*&---------------------------------------------------------------------*
*& Form insert_bdc
*&---------------------------------------------------------------------*
* Insert the BDC for the transaction
*----------------------------------------------------------------------*

FORM insert_bdc_new .

CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'CA02'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
TABLES
dynprotab = i_bdc_table
EXCEPTIONS
internal_error = 1
not_open = 2
queue_error = 3
tcode_invalid = 4
printing_invalid = 5
posting_invalid = 6
OTHERS = 7
.
IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.


ENDIF.

CLEAR i_bdc_table[].


ENDFORM. " insert_bdc


*&---------------------------------------------------------------------*
*& Form close_bdc_session
*&---------------------------------------------------------------------*
* Close the session
*----------------------------------------------------------------------*

FORM close_bdc_session .

CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
not_open = 1
queue_error = 2
OTHERS = 3.

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. " close_bdc_session


*&---------------------------------------------------------------------*
*& Form f_load_input_file
*&---------------------------------------------------------------------*
* Load the data file
*----------------------------------------------------------------------*

FORM f_load_input_file.


* The data file is from Presentation server

IF p_rloc1 = zc_yes.

CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p_fname1
filetype = 'DAT'
TABLES
data_tab = i_rout
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
OTHERS = 10.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.

ENDIF.

ENDIF.

ENDFORM. " f_load_input_file

*&---------------------------------------------------------------------*
*& Form release_bdc
*&---------------------------------------------------------------------*
* Release BDC session
*----------------------------------------------------------------------*

FORM release_bdc.

SUBMIT rsbdcsub WITH mappe EQ p_group
WITH von EQ sy-datum
WITH bis EQ sy-datum
WITH fehler EQ '.'
EXPORTING LIST TO MEMORY
AND RETURN.

ENDFORM.
ABAP Tips by : Ravikumar

New Document

Blog Archive