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: 

uploading

Former Member
0 Kudos

uplading material price from an external data set inot sapr/3 system using batch input method.

regards,

padma

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

See the sample code for Material price upload

report ZMMBDCP_MATERIAL_PRICE

no standard page heading

line-size 255.

----


  • Includes

----


include bdcrecx1.

----


  • Internal Tables

----


*--Internal Table To hold Material Price data from flat file.

Data: begin of it_mat_price occurs 0,

key(4),

f1(10), " date

f2(4), " Company Code

f3(4), " Plant

f4(18), " material

f5(15), " Price

end of it_mat_price.

*--Internal Table To hold Material Price header Data .

data : begin of it_header occurs 0,

key(4),

f1(10),

f2(4),

f3(4),

end of it_header.

*--Internal Table To hold Material Price details data .

data : begin of it_details occurs 0,

key(4),

f4(18),

f5(15),

end of it_details.

----


  • Variables

----


data : v_sno(2), " Serial Number

v_rows type i, " Number of Rows

v_fname(40). " To store Field Name

----


  • Start of Selection

----


start-of-selection.

clear it_mat_price.

refresh it_mat_price.

clear it_header.

refresh it_header.

clear it_details.

refresh it_details.

*--To Upload Material Price Data from Flat file.

CALL FUNCTION 'UPLOAD'

EXPORTING

FILENAME =

'C:\WINDOWS\Desktop\mat_price_change.txt'

FILETYPE = 'DAT'

TABLES

DATA_TAB = it_mat_price

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

GUI_REFUSE_FILETRANSFER = 6

OTHERS = 7.

*--Separating Header & Details Records

loop at it_mat_price.

At new key.

read table it_mat_price index sy-tabix.

move-corresponding it_mat_price to it_header. " Header

append it_header.

clear it_header.

endat.

move-corresponding it_mat_price to it_details. " Details

append it_details.

clear it_details.

endloop.

*--Perform to open Session

perform open_group.

*--To get Number of rows for Table Control

v_rows = sy-srows - 13.

*--Looping on Header record

loop at it_header.

perform bdc_dynpro using 'SAPRCKM_MR21' '0201'.

perform bdc_field using 'BDC_CURSOR'

'MR21HEAD-WERKS'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_field using 'MR21HEAD-BUDAT'

it_header-f1.

perform bdc_field using 'MR21HEAD-BUKRS'

it_header-f2.

perform bdc_field using 'MR21HEAD-WERKS'

it_header-f3.

perform bdc_field using 'MR21HEAD-SCREEN_VARIANT'

'MR21_LAGERMATERIAL_0250'.

v_sno = 0.

*--Looping On detials record.

loop at it_details where key eq it_header-key.

if v_sno ne v_rows.

v_sno = v_sno + 1.

endif.

perform bdc_dynpro using 'SAPRCKM_MR21' '0201'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

clear v_fname.

CONCATENATE 'CKI_MR21_0250-MATNR(' V_SNO ')' INTO V_FNAME.

perform bdc_field using v_fname

it_details-f4.

clear v_fname.

CONCATENATE 'CKI_MR21_0250-NEWVALPR(' V_SNO ')' INTO V_FNAME.

perform bdc_field using v_fname

it_details-f5.

endloop.

perform bdc_dynpro using 'SAPRCKM_MR21' '0201'.

perform bdc_field using 'BDC_OKCODE'

'=SAVE'.

perform bdc_field using 'BDC_CURSOR'

'MR21HEAD-SCREEN_VARIANT'.

perform bdc_field using 'MR21HEAD-SCREEN_VARIANT'

'MR21_LAGERMATERIAL_BWKEY_0250'.

*--Call Transaction to upadate New price

perform bdc_transaction using 'MR21'.

endloop.

perform close_group.

Reward points if useful

Regards

Anji

1 REPLY 1

Former Member
0 Kudos

Hi

See the sample code for Material price upload

report ZMMBDCP_MATERIAL_PRICE

no standard page heading

line-size 255.

----


  • Includes

----


include bdcrecx1.

----


  • Internal Tables

----


*--Internal Table To hold Material Price data from flat file.

Data: begin of it_mat_price occurs 0,

key(4),

f1(10), " date

f2(4), " Company Code

f3(4), " Plant

f4(18), " material

f5(15), " Price

end of it_mat_price.

*--Internal Table To hold Material Price header Data .

data : begin of it_header occurs 0,

key(4),

f1(10),

f2(4),

f3(4),

end of it_header.

*--Internal Table To hold Material Price details data .

data : begin of it_details occurs 0,

key(4),

f4(18),

f5(15),

end of it_details.

----


  • Variables

----


data : v_sno(2), " Serial Number

v_rows type i, " Number of Rows

v_fname(40). " To store Field Name

----


  • Start of Selection

----


start-of-selection.

clear it_mat_price.

refresh it_mat_price.

clear it_header.

refresh it_header.

clear it_details.

refresh it_details.

*--To Upload Material Price Data from Flat file.

CALL FUNCTION 'UPLOAD'

EXPORTING

FILENAME =

'C:\WINDOWS\Desktop\mat_price_change.txt'

FILETYPE = 'DAT'

TABLES

DATA_TAB = it_mat_price

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

GUI_REFUSE_FILETRANSFER = 6

OTHERS = 7.

*--Separating Header & Details Records

loop at it_mat_price.

At new key.

read table it_mat_price index sy-tabix.

move-corresponding it_mat_price to it_header. " Header

append it_header.

clear it_header.

endat.

move-corresponding it_mat_price to it_details. " Details

append it_details.

clear it_details.

endloop.

*--Perform to open Session

perform open_group.

*--To get Number of rows for Table Control

v_rows = sy-srows - 13.

*--Looping on Header record

loop at it_header.

perform bdc_dynpro using 'SAPRCKM_MR21' '0201'.

perform bdc_field using 'BDC_CURSOR'

'MR21HEAD-WERKS'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_field using 'MR21HEAD-BUDAT'

it_header-f1.

perform bdc_field using 'MR21HEAD-BUKRS'

it_header-f2.

perform bdc_field using 'MR21HEAD-WERKS'

it_header-f3.

perform bdc_field using 'MR21HEAD-SCREEN_VARIANT'

'MR21_LAGERMATERIAL_0250'.

v_sno = 0.

*--Looping On detials record.

loop at it_details where key eq it_header-key.

if v_sno ne v_rows.

v_sno = v_sno + 1.

endif.

perform bdc_dynpro using 'SAPRCKM_MR21' '0201'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

clear v_fname.

CONCATENATE 'CKI_MR21_0250-MATNR(' V_SNO ')' INTO V_FNAME.

perform bdc_field using v_fname

it_details-f4.

clear v_fname.

CONCATENATE 'CKI_MR21_0250-NEWVALPR(' V_SNO ')' INTO V_FNAME.

perform bdc_field using v_fname

it_details-f5.

endloop.

perform bdc_dynpro using 'SAPRCKM_MR21' '0201'.

perform bdc_field using 'BDC_OKCODE'

'=SAVE'.

perform bdc_field using 'BDC_CURSOR'

'MR21HEAD-SCREEN_VARIANT'.

perform bdc_field using 'MR21HEAD-SCREEN_VARIANT'

'MR21_LAGERMATERIAL_BWKEY_0250'.

*--Call Transaction to upadate New price

perform bdc_transaction using 'MR21'.

endloop.

perform close_group.

Reward points if useful

Regards

Anji