From: shambavi.asuri on
Hi al,
I have been trying to work with the transaction ME21.
i tried to batch of data using the transaction but i wasnt able to
figure the correct login for the same. i have also pasted the code
that i used .
Can anyone help?
report ZPROJECT
no standard page heading line-size 255.

include bdcrecx1.

*parameters: dataset(132) lower case.
*** DO NOT CHANGE - the generated data section - DO NOT CHANGE
***
*
* If it is nessesary to change the data section use the rules:
* 1.) Each definition of a field exists of two lines
* 2.) The first line shows exactly the comment
* '* data element: ' followed with the data element
* which describes the field.
* If you don't have a data element use the
* comment without a data element name
* 3.) The second line shows the fieldname of the
* structure, the fieldname must consist of
* a fieldname and optional the character '_' and
* three numbers and the field length in brackets
* 4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE
***

DATA : BEGIN OF IT_DUMMY OCCURS 0,
DUMMY(300) TYPE C,
END OF IT_DUMMY.
data: begin of record1 OCCURS 0,
* data element: ELIFN
LIFNR_001(010),
* data element: BSART
BSART_002(004),
* data element: BEDAT
BEDAT_003(010),
* data element: EKORG
EKORG_004(004),
* data element: BKGRP
EKGRP_005(003),
* data element: LPEIN
LPEIN_006(001),
END OF RECORD1.

DATA:BEGIN OF RECORD2 OCCURS 0,
* data element: EMATNR
EMATN_01_007(018),
* data element: BSTMG
MENGE_01_008(017),
* data element: BSTME
MEINS_01_009(003),
* data element: EEIND
EEIND_01_010(010),
* data element: BPREI
NETPR_01_011(014),
* data element: EPEIN
PEINH_01_012(006),
* data element: BBPRM
BPRME_01_013(003),
* data element: MATKL
MATKL_01_014(009),
* data element: EWERK
WERKS_01_015(004),
* data element: LGORT_D
LGORT_01_016(004),
* data element: AUFEP
EBELP_017(005),
end of record2.

*** End generated data section ***

start-of-selection.

* perform open_dataset using dataset.
perform open_group.


CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME ='C:\Documents and Settings
\146914\Desktop\PROJECT.TXT'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = IT_DUMMY
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* NO_AUTHORITY = 6
* UNKNOWN_ERROR = 7
* BAD_DATA_FORMAT = 8
* HEADER_NOT_ALLOWED = 9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
* ACCESS_DENIED = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* OTHERS = 17
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT IT_DUMMY.
IF IT_DUMMY-DUMMY+0(1) = '*'.
record1-lifnr_001 = IT_DUMMY-DUMMY+1(10).
record1-bsart_002 = IT_DUMMY-DUMMY+11(4).
record1-bedat_003 = IT_DUMMY-DUMMY+15(10).
record1-ekorg_004 = it_dummy-dummy+25(4).
record1-ekgrp_005 = it_dummy-dummy+29(3).
record1-lpein_006 = IT_DUMMY-DUMMY+32(1).
APPEND RECORD1.
ELSE.
RECORD2-EMATN_01_007 = IT_DUMMY-DUMMY+1(18).
RECORD2-MENGE_01_008 = IT_DUMMY-DUMMY+19(17).
RECORD2-MEINS_01_009 = IT_DUMMY-DUMMY+36(3).
RECORD2-EEIND_01_010 = IT_DUMMY-DUMMY+39(10).
RECORD2-NETPR_01_011 = IT_DUMMY-DUMMY+49(14).
RECORD2-PEINH_01_012 = IT_DUMMY-DUMMY+63(6).
RECORD2-BPRME_01_013 = IT_DUMMY-DUMMY+69(3).
RECORD2-MATKL_01_014 = IT_DUMMY-DUMMY+72(9).
RECORD2-WERKS_01_015 = IT_DUMMY-DUMMY+81(4).
RECORD2-LGORT_01_016 = IT_DUMMY-DUMMY+85(4).
* record2-ebelp_017 = IT_DUMMY-DUMMY+86(5).
APPEND RECORD2.
ENDIF.
ENDLOOP.

LOOP AT RECORD1.
* read dataset dataset into record.
if sy-subrc <> 0. exit.
endif.

perform bdc_dynpro using 'SAPMM06E' '0100'.
perform bdc_field using 'BDC_CURSOR'
'EKKO-EKGRP'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'EKKO-LIFNR'
record1-LIFNR_001.
perform bdc_field using 'RM06E-BSART'
record1-BSART_002.
perform bdc_field using 'RM06E-BEDAT'
record1-BEDAT_003.
perform bdc_field using 'EKKO-EKORG'
record1-EKORG_004.
perform bdc_field using 'EKKO-EKGRP'
record1-EKGRP_005.
perform bdc_field using 'RM06E-LPEIN'
record1-LPEIN_006.
perform bdc_dynpro using 'SAPMM06E' '0120'.
perform bdc_field using 'BDC_CURSOR'
'EKPO-LGORT(01)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
DATA : FNAM(20) TYPE C,
IDX TYPE C.

MOVE 1 TO IDX.

LOOP AT RECORD2 .
CONCATENATE 'EKPO-EMATN(' IDX ')' INTO FNAM.
perform bdc_field using FNAM
RECORD2-EMATN_01_007.

CONCATENATE 'EKPO-MENGE(' IDX ')' INTO FNAM.
perform bdc_field using FNAM
record2-MENGE_01_008.

CONCATENATE 'EKPO-MEINS(' IDX ')' INTO FNAM.
perform bdc_field using FNAM
record2-MEINS_01_009.

CONCATENATE 'RM06E-EEIND(' IDX ')' INTO FNAM.
perform bdc_field using FNAM
record2-EEIND_01_010.


CONCATENATE 'EKPO-NETPR(' IDX ')' INTO FNAM.
perform bdc_field using FNAM
record2-NETPR_01_011.


CONCATENATE 'EKPO-PEINH(' IDX ')' INTO FNAM.
perform bdc_field using FNAM
record2-PEINH_01_012.

CONCATENATE 'EKPO-BPRME(' IDX ')' INTO FNAM.
perform bdc_field using FNAM
record2-BPRME_01_013.

CONCATENATE 'EKPO-MATKL(' IDX ')' INTO FNAM.
perform bdc_field using FNAM
record2-MATKL_01_014.

CONCATENATE 'EKPO-WERKS(' IDX ')' INTO FNAM.
perform bdc_field using FNAM
record2-WERKS_01_015.

CONCATENATE 'EKPO-LGORT(' IDX ')' INTO FNAM.
perform bdc_field using FNAM
record2-LGORT_01_016.

IDX = IDX + 1.
ENDLOOP.


perform bdc_dynpro using 'SAPMM06E' '0120'.
perform bdc_field using 'BDC_CURSOR'
'RM06E-EBELP'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'RM06E-EBELP'
record2-EBELP_017.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'ME21'.
REFRESH BDCDATA.
ENDLOOP.


perform close_group.
* perform close_dataset using dataset.