当前位置:文档之家› 批量执行库存转移 abap程序

批量执行库存转移 abap程序

**************************************************************
* PROGRAM NAME:ZBDC_MB1B *
* PROGRAM DESC: MB1B Batch Input *
* VERSION HISTORY: *
*============================================================*
* *
* *
*============================================================*
**************************************************************
report ZTEST1
no standard page heading line-size 255.

type-pools: slis,abap,truxs.

include bdcrecx1.

data: begin of itab occurs 0,
** data element: BLDAT
* BLDAT_001(010),
** data element: BUDAT
* BUDAT_002(010),
** data element: BWARTWA
* BWARTWA_003(003),
** data element: WERKS_D
WERKS_004(004),
* data element: LGORT_D
LGORT_005(004),
* data element:
* XFULL_006(001),
* data element: WVERS3
* WVERS3_007(001),
* data element: UMLGO
UMLGO_008(004),
* data element: MATNR
MATNR_01_009(018),
* data element: ERFMG
ERFMG_01_010(017),
* data element: FMORE
* FMORE_011(001),
end of itab.

DATA: NUM(5) TYPE C.


data: message_table like bdcmsgcoll occurs 0 with header line.

parameters: dataset(132) lower case default 'c:\upload.xls'.
*** 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 ***

*** End generated data section ***

AT SELECTION-SCREEN ON VALUE-REQUEST FOR dataset.
DATA: GET_FILE LIKE RLGRAP-FILENAME.

PERFORM GET_FILE CHANGING GET_FILE.

dataset = GET_FILE.

start-of-selection.
perform frm_gropress_indicator.

*perform open_dataset using dataset.
perform open_group.
perform upload_file.

DATA: v_LINE TYPE I,
LINE1 TYPE I,
LINE2 TYPE I,
TMPBWART(03) VALUE '311'.

DESCRIBE TABLE ITAB lines v_line.

LOOP AT ITAB.
NUM = NUM + 1.
IF ( NUM > 999 or num = 1 ).
perform heardform.
num = 1.
ENDIF.

perform bdc_dynpro using 'SAPMM07M' '0410'.
perform bdc_field using 'BDC_CURSOR'
'MSEG-UMLGO'.
IF ( NUM =

v_LINE OR NUM = 999 or line1 = 1 ).
perform bdc_field using 'BDC_OKCODE'
'=BU'.
ELSE.
PERFORM bdc_field USING 'BDC_OKCODE'
'=NPE'.
ENDIF.

perform bdc_field using 'mseg-MATNR'
ITAB-MATNR_01_009.
perform bdc_field using 'MSEG-ERFMG'
ITAB-ERFMG_01_010.
perform bdc_field using 'MSEG-WERKS'
ITAB-WERKS_004.
perform bdc_field using 'MSEG-LGORT'
ITAB-LGORT_005.
perform bdc_field using 'MSEG-WEMPF'
ITAB-ERFMG_01_010.
perform bdc_field using 'MSEG-UMLGO'
ITAB-UMLGO_008.
perform bdc_field using 'DKACB-FMORE'
'X'.
perform bdc_dynpro using 'SAPLKACB' '0002'.
perform bdc_field using 'BDC_OKCODE'
'=ENTE'.
DELETE ITAB INDEX 1.
DESCRIBE TABLE ITAB lines line1.
if ( num = 999 or line1 = 0 ).
perform bdc_transaction using 'MB1B'.
endif.
ENDLOOP.

perform close_group.

*&---------------------------------------------------------------------*
*& Form upload_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM upload_file.
data: l_file type string,
rawtab(4096) type c occurs 0,
p_filename type rlgrap-filename,
ws_ext(3) type c,
length type i.


condense dataset.
length = strlen( dataset ).
length = length - 3.
ws_ext = dataset+length(3).
translate ws_ext to upper case.

if ws_ext = 'XLS'.
** For input files with format XLS

p_filename = dataset.

call function 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_field_seperator = 'X'
i_line_header = 'X'
i_tab_raw_data = rawtab
i_filename = p_filename
TABLES
i_tab_converted_data = itab[]
EXCEPTIONS
conversion_failed = 1
others = 2.

if sy-subrc <> 0.
case sy-subrc.
when 1.
message e017(z99) with
'CONVERSION_ERROR when uploading input file' '' '' ''.
when others.
message e017(z99) with
'Error when uploading input file' '' '' ''.
endcase.
endif.

elseif ws_ext = 'TXT'.
p_filename = dataset.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = P_FILENAME
FILETYPE =

'DAT'
TABLES
DATA_TAB = itab[]
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.


else.

message e017(z99) with
'File format must be XLS OR TXT!' '' '' ''.

endif.

if itab[] is initial.
message e017(z99) with
'Input file is empty!' '' '' ''.
else.
sort itab by werks_004 lgort_005 umlgo_008 matnr_01_009 erfmg_01_010
.
delete adjacent duplicates from itab.
delete itab where erfmg_01_010 ca sy-abcde.
endif.
ENDFORM. " upload_file
*&---------------------------------------------------------------------*
*& Form GET_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GET_FILE text
*----------------------------------------------------------------------*
FORM GET_FILE CHANGING GET_FILE.
DATA: FILETAB TYPE FILETABLE,
FILETAB_LN LIKE LINE OF FILETAB,
RC TYPE I.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
CHANGING
FILE_TABLE = FILETAB
RC = RC
EXCEPTIONS
FILE_OPEN_DIALOG_FAILED = 1
CNTL_ERROR = 2
ERROR_NO_GUI = 3.

LOOP AT FILETAB INTO FILETAB_LN.
GET_FILE = FILETAB_LN-FILENAME.
ENDLOOP.

ENDFORM. " GET_FILE

*&---------------------------------------------------------------------*
*& Form frm_gropress_indicator
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_gropress_indicator.
call function 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = 0
text = 'Program is starting,Please wait... '.


ENDFORM. " frm_gropress_indicator
*&---------------------------------------------------------------------*
*& Form heardform
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM heardform.
READ TABLE ITAB INDEX 1.
perform bdc_dynpro using 'SAPMM07M' '0400'.
perform bdc_field using 'BDC_CURSOR'
'RM07M-WERKS'.
perform bdc_field u

sing 'BDC_OKCODE'
'=NPE'.
perform bdc_field using 'MKPF-BLDAT'
SY-DATUM.
perform bdc_field using 'MKPF-BUDAT'
SY-DATUM.
perform bdc_field using 'RM07M-BWARTWA'
TMPBWART.
perform bdc_field using 'RM07M-WERKS'
ITAB-WERKS_004.
perform bdc_field using 'RM07M-LGORT'
ITAB-LGORT_005.
PERFORM bdc_field USING 'XFULL'
'X'.
PERFORM bdc_field USING 'RM07M-WVERS2'
'X'.
ENDFORM. " heardform

相关主题
文本预览
相关文档 最新文档