Вы находитесь на странице: 1из 6

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

*& Report ZMM_MB1B_BDC


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT

zmm_mb1b_bdc.

DATA: it_exload LIKE alsmex_tabline

OCCURS 0 WITH HEADER LINE.

DATA:

messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE,


msg_txt(150) TYPE c.
DATA: wa_serial TYPE char5,
count TYPE i.
DATA: it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
TYPES: BEGIN OF ts_final,
serial TYPE i,
bldat TYPE mkpf-bldat,
budat TYPE mkpf-budat,
bwartwa TYPE rm07m-bwartwa,
werks TYPE rm07m-werks,
lgort TYPE rm07m-lgort,
lifnr TYPE msegk-lifnr,
matnr TYPE mseg-matnr,
erfmg TYPE char17,
END OF ts_final.
DATA: it_final TYPE STANDARD TABLE OF ts_final WITH HEADER LINE,
it_final_new TYPE STANDARD TABLE OF ts_final WITH HEADER LINE,
wa_final TYPE ts_final.
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETER: pfile LIKE rlgrap-filename OBLIGATORY ,
w_begin TYPE i OBLIGATORY,
w_end TYPE i OBLIGATORY.
SELECTION-SCREEN:END OF BLOCK b1.
SELECTION-SCREEN : BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS : p_back RADIOBUTTON GROUP g1 DEFAULT 'X' USER-COMMAND g1,
p_fwd RADIOBUTTON GROUP g1.
SELECTION-SCREEN: END OF BLOCK b2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pfile.
PERFORM sub_browse_file.
START-OF-SELECTION.
PERFORM sub_data_load.
PERFORM sub_data_transform.
PERFORM sub_post_data.
*&---------------------------------------------------------------------*
*&
Form SUB_BROWSE_FILE
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text

* <-- p2
text
*----------------------------------------------------------------------*
FORM sub_browse_file .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name
= syst-cprog
dynpro_number
= syst-dynnr
*
FIELD_NAME
= ' '
IMPORTING
file_name
= pfile
.
ENDFORM.
" SUB_BROWSE_FILE
*&---------------------------------------------------------------------*
*&
Form SUB_DATA_LOAD
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM sub_data_load .
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename
= pfile
i_begin_col
= '0001'
i_begin_row
= w_begin
i_end_col
= '0009'
i_end_row
= w_end
TABLES
intern
= it_exload
EXCEPTIONS
inconsistent_parameters = 1
upload_ole
= 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.
" SUB_DATA_LOAD
*&---------------------------------------------------------------------*
*&
Form SUB_DATA_TRANSFORM
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM sub_data_transform .
LOOP AT it_exload.
CASE it_exload-col.
WHEN '0001'.
it_final-serial = it_exload-value.
WHEN '0002'.

it_final-bldat = it_exload-value.
WHEN '0003'.
it_final-budat = it_exload-value.
WHEN '0004'.
it_final-bwartwa = it_exload-value.
WHEN '0005'.
it_final-werks = it_exload-value.
WHEN '0006'.
it_final-lgort = it_exload-value.
WHEN '0007'.
it_final-lifnr = it_exload-value.
WHEN '0008'.
it_final-matnr = it_exload-value.
WHEN '0009'.
it_final-erfmg = it_exload-value.
ENDCASE.
AT END OF row.
APPEND it_final.
CLEAR it_final.
ENDAT.
ENDLOOP.
ENDFORM.
" SUB_DATA_TRANSFORM
*&---------------------------------------------------------------------*
*&
Form SUB_POST_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM sub_post_data .

SORT it_final BY serial.


LOOP AT it_final.
AT NEW serial.
REFRESH it_final_new[].
wa_serial = it_final-serial.
ENDAT.
IF it_final-serial = wa_serial.
it_final_new = it_final.

APPEND it_final_new.
ENDIF.
AT END OF serial.
CLEAR wa_final.
READ TABLE it_final_new INDEX 1.
wa_final = it_final_new.
PERFORM upload_data.
ENDAT.
ENDLOOP.
ENDFORM.
" SUB_POST_DATA
*&---------------------------------------------------------------------*
*&
Form UPLOAD_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM upload_data .
DATA: wd_serial TYPE char2,
we_char1 TYPE char15,
we_char2 TYPE char15,
we_char3 TYPE char15,
day TYPE char2,
month TYPE char2,
year TYPE char4,
date TYPE char10.
day = sy-datum+6(2).
month = sy-datum+4(2).
year = sy-datum(4).
CONCATENATE day '.' month '.' year INTO date.
PERFORM sub_populate_data USING:
'1'
' '
' '
' '
' '
' '
' '
' '
' '
' '

'SAPMM07M'
'BDC_CURSOR'
'BDC_OKCODE'
'MKPF-BLDAT'
'MKPF-BUDAT'
'RM07M-BWARTWA'
'RM07M-WERKS'
'RM07M-LGORT'
'XFULL'
'RM07M-WVERS2'

'1' 'SAPMM07M'
' ' 'BDC_CURSOR'
' ' 'BDC_OKCODE'
' ' 'MSEGK-LIFNR'
' ' 'MSEG-MATNR'
' ' 'MSEG-ERFMG'
' ' 'DKACB-FMORE'

*
*

'0400',
'RM07M-LGORT',
'/00',
wa_final-bldat,
wa_final-budat,
wa_final-bwartwa,
wa_final-werks,
wa_final-lgort,
'X',
'X',
'0421',
'MSEG-ERFMG(01)',
'/00',
wa_final-lifnr,
wa_final-matnr,
wa_final-erfmg,
'X'.

LOOP AT it_final_new.
wd_serial = wd_serial + 1.
UNPACK wd_serial TO wd_serial.
CONCATENATE 'MSEG-MATNR' '(' wd_serial ')' INTO we_char1.

CONCATENATE 'MSEG-ERFMG' '(' wd_serial ')' INTO we_char2.


PERFORM sub_populate_data USING:
' '
' '

we_char1
we_char2

it_final_new-matnr,
it_final_new-erfmg.

ENDLOOP.
PERFORM sub_populate_data USING:
'1' 'SAPLKACB'
' ' 'BDC_OKCODE'

'0002',
'=ENTE'.

PERFORM sub_populate_data USING:


'1'
' '
' '
' '

'SAPMM07M'
'BDC_CURSOR'
'BDC_OKCODE'
'DKACB-FMORE'

'1' 'SAPLKACB'
' ' 'BDC_OKCODE'

'0421',
'MSEG-ERFMG(01)',
'=BU',
'X',
'0002',
'=ENTE'.

IF p_fwd = 'X'.
CALL TRANSACTION 'MB1B' USING it_bdcdata MESSAGES INTO messtab
UPDATE 'S'
MODE 'A'.
ELSEIF p_back = 'X'.
CALL TRANSACTION 'MB1B' USING it_bdcdata MESSAGES INTO messtab
UPDATE 'S'
MODE 'E'.
ENDIF.
LOOP AT messtab.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id
= messtab-msgid
lang
= sy-langu
no
= messtab-msgnr
v1
= messtab-msgv1
v2
= messtab-msgv2
v3
= messtab-msgv3
v4
= messtab-msgv4
IMPORTING
msg
= msg_txt
EXCEPTIONS
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.
IF messtab-msgtyp EQ 'E'.
CONDENSE wa_serial.
WRITE: 5 wa_serial COLOR 6.
WRITE: 10 msg_txt COLOR 6.
ELSEIF messtab-msgtyp EQ 'S'.
CONDENSE wa_serial.
WRITE: 5 wa_serial COLOR 5.
WRITE: 10 msg_txt COLOR 5.
ELSEIF messtab-msgtyp EQ 'W'.

CONDENSE wa_serial.
WRITE: 5 wa_serial COLOR 3.
WRITE: 10 msg_txt COLOR 3.
ELSE.
WRITE:/10 msg_txt COLOR 4.
ENDIF.
CLEAR msg_txt.
ENDLOOP.
ULINE.
REFRESH:it_bdcdata,messtab.

ENDFORM.
" UPLOAD_DATA
*&---------------------------------------------------------------------*
*&
Form SUB_POPULATE_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_ENDFORM text
*----------------------------------------------------------------------*
FORM sub_populate_data USING flag var1 var2.
IF flag = '1'.
it_bdcdata-program = var1.
it_bdcdata-dynpro = var2.
it_bdcdata-dynbegin = 'X'.
ELSE.
it_bdcdata-fnam = var1.
it_bdcdata-fval = var2.
ENDIF.
APPEND it_bdcdata.
CLEAR it_bdcdata.
ENDFORM.

" SUB_POPULATE_DATA