You are on page 1of 4

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

*& Report ZAVM_BDC_CT_INBO_MM01


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
*A-0102 F
COUP
FOOD
G
*A-0103 F
COUP
FOOD
G
*A-0104 F
COUP
FOOD
G
*A-0105 F
COUP
FOOD
G
REPORT ZAVM_BDC_SS_INBO_MM01.
*&---------------------------------------------------------------------*
*&
SOURCE STRUCTURE DECLATION
*&---------------------------------------------------------------------*
TYPES: BEGIN OF TY_UPLOAD,
MATNR TYPE RMMG1-MATNR, "MATERAIL
MBRSH TYPE RMMG1-MBRSH, "INDUSRY SECTOR
MTART TYPE RMMG1-MTART, "MATERAIL TYPE
MAKTX TYPE MAKT-MAKTX, "MATERAIL DISCRIPTION
MEINS TYPE MARA-MEINS, "UOM
END OF TY_UPLOAD.
*&---------------------------------------------------------------------*
*& TRAGET AND SOURCE INTERNAL TABLES DECLATION
*&---------------------------------------------------------------------*
* FOR SOURCE INTERNAL TABLE
DATA: T_UPLOAD TYPE STANDARD TABLE OF TY_UPLOAD WITH HEADER LINE INITIAL SIZE 0,
* FOR TARGET INTERNAL TABLE
T_BDCDATA TYPE STANDARD TABLE OF BDCDATA WITH HEADER LINE INITIAL SIZE 0,
*&---------------------------------------------------------------------*
*& TRAGET AND SOURCE WORKAREA DECLATION
*&---------------------------------------------------------------------*
*SOURCE TABLE WORKAREA DECALATION
W_UPLOAD TYPE TY_UPLOAD,
*TARGET TABLE WORKAREA DECALTION
W_BDCDATA TYPE BDCDATA.
*&---------------------------------------------------------------------*
*& SELECTION-SCREEN DECLARATION
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: P_FINAME TYPE FILENAME-FILEINTERN,
P_SS TYPE APQI-GROUPID.
.
SELECTION-SCREEN END OF BLOCK B1.
*&---------------------------------------------------------------------*
*& INITIALIAZATION DECLARATION
*&---------------------------------------------------------------------*
INITIALIZATION.
*CLEAR WORKAREA

CLEAR: W_UPLOAD,
W_BDCDATA.
*REFRESH INTERNAL TABLE
REFRESH: T_UPLOAD,
T_BDCDATA.
CONCATENATE 'MMA_' SY-DATUM INTO P_SS.

*&---------------------------------------------------------------------*
*& TOP-OF-PAGE DECLARATION
*&---------------------------------------------------------------------*
TOP-OF-PAGE.
WRITE: /20 'UPLOADING OF MATERAIL DATA'.
ULINE.
*&---------------------------------------------------------------------*
*& START OF SELECTION DECLARATION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*TO UPLOAD THE FLAT DATA TO SOUREC TABLE
PERFORM SUB_UPLOAD_DATA_AS.
*POULATE THE TRAGET TABLE FROM SOURCE TABLE
PERFORM SUB_POP_SS.
*&---------------------------------------------------------------------*
*&
Form SUB_UPLOAD_DATA_PS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM SUB_UPLOAD_DATA_AS .
DATA: L_FINAME TYPE STRING.
OPEN DATASET P_FINAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.
CHECK SY-SUBRC = 0.
DO.
READ DATASET P_FINAME INTO L_FINAME.
IF SY-SUBRC <> 0.
EXIT.
ELSE.
SPLIT L_FINAME AT ',' INTO W_UPLOAD-MATNR
W_UPLOAD-MBRSH
W_UPLOAD-MTART
W_UPLOAD-MAKTX
W_UPLOAD-MEINS.
APPEND W_UPLOAD TO T_UPLOAD.
CLEAR W_UPLOAD.
ENDIF.
ENDDO.
ENDFORM.

" SUB_UPLOAD_DATA_PS

*&---------------------------------------------------------------------*
*&
Form SUB_POP_CALLTRANS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM SUB_POP_SS.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT
= SY-MANDT
GROUP
= P_SS
*
HOLDDATE
= '20110902'
*
KEEP
= 'X'
USER
= SY-UNAME
PROG
= SY-CPROG
.
LOOP AT T_UPLOAD INTO W_UPLOAD.
REFRESH T_BDCDATA.
******************************************,
PERFORM BDC_DYNPRO
USING 'SAPLMGMM' '0060'.
PERFORM BDC_FIELD
USING 'BDC_CURSOR'
'RMMG1-MATNR'.
PERFORM BDC_FIELD
USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD
USING 'RMMG1-MATNR'
W_UPLOAD-MATNR.
PERFORM BDC_FIELD
USING 'RMMG1-MBRSH'
W_UPLOAD-MBRSH.
PERFORM BDC_FIELD
USING 'RMMG1-MTART'
W_UPLOAD-MTART.
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)'
'X'.
PERFORM BDC_DYNPRO
USING 'SAPLMGMM' '4004'.
PERFORM BDC_FIELD
USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD
USING 'MAKT-MAKTX'
W_UPLOAD-MAKTX.
PERFORM BDC_FIELD
USING 'BDC_CURSOR'
'MARA-MEINS'.
PERFORM BDC_FIELD
USING 'MARA-MEINS'
W_UPLOAD-MEINS.
PERFORM BDC_FIELD
USING 'MARA-MTPOS_MARA'
'NORM'.
PERFORM BDC_DYNPRO
USING 'SAPLSPO1' '0300'.
PERFORM BDC_FIELD
USING 'BDC_OKCODE'
'=YES'.
*******************************************************
*TO INSERT THE TO SESSION.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE
= 'MM01'
TABLES

DYNPROTAB = T_BDCDATA.
ENDLOOP.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
IF SY-SUBRC = 0.
WRITE: / 'SESSION CREATED CHECK SM35',P_SS.
ENDIF.

ENDFORM.

"SUB_POP_ss

*----------------------------------------------------------------------*
*
Start new screen
*
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR W_BDCDATA.
W_BDCDATA-PROGRAM = PROGRAM.
W_BDCDATA-DYNPRO = DYNPRO.
W_BDCDATA-DYNBEGIN = 'X'.
APPEND W_BDCDATA TO T_BDCDATA.
ENDFORM.
"BDC_DYNPRO
*----------------------------------------------------------------------*
*
Insert field
*
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR W_BDCDATA.
W_BDCDATA-FNAM = FNAM.
W_BDCDATA-FVAL = FVAL.
APPEND W_BDCDATA TO T_BDCDATA.
ENDFORM.
"BDC_FIELD