Go on link..

link us with ...

Thursday, December 30, 2010

STOCK UPLOAD in MM Module

*&---------------------------------------------------------------------*
*& Report ZMB001_RM07MMBL_STOCK_UPLOAD *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZMB001_RM07MMBL_STOCK_UPLOAD NO STANDARD PAGE HEADING
LINE-SIZE 80.
*--------------------------sgp-----------------------------------------*
* MODULE : MM
*---------------------------------------------------------------------*
* Objective :..........................................

* Program : Updates Tables ( X ) Downloads data ( )
* Outputs List ( )
*
* Technical Spec No : ...............
* Functional Specifications :
* Date Created :
* Author :
* Location :
* Company :
*---------------------------------------------------------------------*
* External Dependencies *
*---------------------------------------------------------------------*
* Using Transaction : MB1C
*---------------------------------------------------------------------*
* Amendment History
*---------------------------------------------------------------------*
* Who Change ID Reason *
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ *
* XXXXXXXXX AADDMMYYYY Where XXXX = Developers Name................. *
* AA- Developers Initial ................................. *
* ........................................................ *
* ........................................................ *
*---------------------------------------------------------------------*

*---------------------------------------------------------------------*
* Includes *
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
TABLES : T001W,
T148,
T157H,
LFA1,
MARA,
MBEW,
TGSB,
T030,
T134G,
T006,
MCH1,
SKAT,
MARD,
T001L,
MARC .
*---------------------------------------------------------------------*
* Types Begin with TY_
*---------------------------------------------------------------------*
*TYPES :
*---------------------------------------------------------------------*
* Constants Begin with C_
*---------------------------------------------------------------------*
*CONSTANTS:
*---------------------------------------------------------------------*
* Data Begin with W_
*---------------------------------------------------------------------*
DATA : WF_TOTAL_ERRORS TYPE I,
WF_ERFMG(13),
WF_EXWRT(13).
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* Infotypes ( HR Module Specific)
*---------------------------------------------------------------------*
*INFOTYPES :
*---------------------------------------------------------------------*
* Internal tables Begin with IT_
*---------------------------------------------------------------------*
DATA : BEGIN OF IT_TAB OCCURS 0 ,
BLDAT(10),
BUDAT(10),
BWART LIKE RM07M-BWART,
WERKS LIKE RM07M-WERKS,
LGORT LIKE RM07M-LGORT,
SOBKZ LIKE RM07M-SOBKZ,
LIFNR LIKE LFA1-LIFNR,
GSBER LIKE COBL-GSBER,
MATNR LIKE MSEG-MATNR,
ERFMG LIKE MSEG-ERFMG,
ERFME LIKE MSEG-ERFME,
CHARG LIKE MSEG-CHARG,
EXWRT LIKE BMSEG-EXWRT,
BKTXT LIKE MKPF-BKTXT,
SGTXT LIKE MSEG-SGTXT.
* kdauf LIKE mseg-kdauf,
* kdpos LIKE mseg-kdpos.
DATA : END OF IT_TAB.

DATA : BEGIN OF IT_ACC OCCURS 0,
GSBER LIKE BSEG-GSBER,
WERKS LIKE BSEG-WERKS,
KONTS LIKE T030-KONTS,
EXWRT LIKE BSEG-WRBTR.
DATA : END OF IT_ACC.

DATA : BEGIN OF IT_BMSEG OCCURS 0 .
INCLUDE STRUCTURE BMSEG.
DATA : END OF IT_BMSEG.
*---------------------------------------------------------------------*
* Field Symbols Begin with FS_
*---------------------------------------------------------------------*
*FIELD-SYMBOLS:
*---------------------------------------------------------------------*
* Field Groups Begin with FG_
*---------------------------------------------------------------------*
*FIELD-GROUPS :
*---------------------------------------------------------------------*
* Insert
*---------------------------------------------------------------------*
*INSERT :
*---------------------------------------------------------------------*
* Controls Begin with TC_ for table controls
*---------------------------------------------------------------------*
*CONTROLS :
*---------------------------------------------------------------------*
* Select Options Begin with SO_
*---------------------------------------------------------------------*
*SELECT-OPTIONS :
*---------------------------------------------------------------------*
* Parameters Begin with PR_
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK MBLK0 WITH FRAME TITLE TEXT-001.
PARAMETERS : P_GROUP LIKE BGR00-GROUP OBLIGATORY DEFAULT 'OPENSTOCK',
P_XPROT LIKE BGR00-XKEEP DEFAULT 'X',
P_XSELK LIKE AM07M-XSELK.
SELECTION-SCREEN END OF BLOCK MBLK0.

SELECTION-SCREEN BEGIN OF BLOCK MBLK1 WITH FRAME TITLE TEXT-002.
PARAMETER P_FILE LIKE RLGRAP-FILENAME DEFAULT 'C:\mb1c.txt'.
SELECTION-SCREEN END OF BLOCK MBLK1.

SELECTION-SCREEN BEGIN OF BLOCK MBLKX WITH FRAME TITLE TEXT-006.
PARAMETERS : P_LOCAL RADIOBUTTON GROUP GRP1.
PARAMETER P_LOCLFN LIKE RLGRAP-FILENAME
DEFAULT 'C:\mmdata\openstock.txt'.
PARAMETERS : P_UNIX RADIOBUTTON GROUP GRP1.
PARAMETER P_UNIXFN LIKE RLGRAP-FILENAME
DEFAULT '/VVFuture/upload/mm/openstock.txt'.
PARAMETERS : P_RM07MM AS CHECKBOX.
PARAMETERS : P_LOGFIL LIKE FILENAME-FILEINTERN DEFAULT
'ZMM_OPEN_STOCK'.
*parameters: callmode like rfpdo-rfbifunct obligatory default 'B'.
SELECTION-SCREEN END OF BLOCK MBLKX.
PARAMETERS : P_QTYTOT AS CHECKBOX.
PARAMETERS : P_BUDAT LIKE BKPF-BUDAT OBLIGATORY DEFAULT '20040229'.
DATA : WF_TOTAL_QTY LIKE MSEG-MENGE,
WF_TOTAL_REC TYPE I,
WF_TOTAL_AMOUNT LIKE MSEG-DMBTR.
*---------------------------------------------------------------------*
* Initialisation
*---------------------------------------------------------------------*
*INITIALISATION :
*---------------------------------------------------------------------**
* At selection-screen
*---------------------------------------------------------------------*
*AT SELECTION-SCREEN.
************************************************************************
* S T A R T O F S E L E C T I O N
************************************************************************
START-OF-SELECTION.

PERFORM UPLOAD_DATA.
PERFORM CHECK_DATA.
* perform check_batch.
PERFORM DISPLAY_ACCOUNTING_INFORMATION.

IF WF_TOTAL_ERRORS = 0.
SKIP 2.
PERFORM FILL_RM07MMBL_FORMAT.
FORMAT COLOR = 7.
FORMAT COLOR OFF.
ELSE.
FORMAT COLOR = 6.
SKIP 2.
WRITE : /01 'Total Errors ', WF_TOTAL_ERRORS,
'File Not Generated for RM07MMBL', 132 ''.
FORMAT COLOR OFF.
ENDIF.
IF WF_TOTAL_ERRORS = 0.
IF P_LOCAL = 'X'.
PERFORM DOWNLOAD_DATA.
ELSE.
PERFORM SAVE_ON_UNIX_SERVE.
ENDIF.
ENDIF.
IF P_RM07MM = 'X' AND P_UNIX = 'X'.
IF WF_TOTAL_ERRORS = 0.
PERFORM CALLL_RM07MMBL.
ELSE.
SKIP 2.
WRITE : /01 'Session not created for RM07MMBL' COLOR COL_NEGATIVE.
ENDIF.
ENDIF.

END-OF-SELECTION.
************************************************************************
* E N D O F S E L E C T I O N
************************************************************************
*eject
*-----------------------------------------------------------------
* At line selection
*---------------------------------------------------------------------*
*AT LINE-SELECTION.
*---------------------------------------------------------------------*
* PF Key Processing
*---------------------------------------------------------------------*
*AT PFXX.
*---------------------------------------------------------------------*
* User Command Processing
*---------------------------------------------------------------------*
*AT USER-COMMAND.
*---------------------------------------------------------------------*
* Top Of Page
*---------------------------------------------------------------------*
*TOP-OF-PAGE.
*---------------------------------------------------------------------*
* End Of Page
*---------------------------------------------------------------------*
*END-OF-PAGE.*eject.
*----------------------------------------------------------------------*
* FORM Fnnn-xxxxxxxxxx.
*----------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
*FORM FNNN-XXXXXXXX.
*----------------------------------------------------------------------*
* Local variables must begin with L, followed by the naming convention
* for the corresponding variable type eg. LW_, LIT_
*----------------------------------------------------------------------
*ENDFORM.*eject.*Any declarations for classes, methods and interfaces.

***********************---------------------****************************
* E N D O F A B A P
***********************---------------------****************************
*&---------------------------------------------------------------------*
*& Form check_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_DATA.
LOOP AT IT_TAB.

PERFORM CHECK_BWART. "Movement Type
PERFORM CHECK_WERKS. "Plant.
PERFORM CHECK_PLANT_FOR_MATERIAL.
PERFORM CHECK_LGORT. "Storage Location.
PERFORM CHECK_SOBKZ. "Special Stock Type
PERFORM CHECK_LIFNR. "Vendor Code
PERFORM CHECK_AND_GSBER. "Business Area
PERFORM CHECK_MATNR. "Material Code
PERFORM CHECK_ERFMG. "Quantity
PERFORM CHECK_ERFME. "Unit of Measurement
* PERFORM check_charg. "Batch No
PERFORM CHECK_EXWRT. "Amount.
PERFORM CHECK_SGTXT. "Text
PERFORM CHECK_BUDAT. "Posting Date
* PERFORM check_sales_order.
PERFORM FILL_ACCOUNTING_INFORMATION.
WF_TOTAL_QTY = WF_TOTAL_QTY + IT_TAB-ERFMG.
WF_TOTAL_AMOUNT = WF_TOTAL_AMOUNT + IT_TAB-EXWRT.
ADD 1 TO WF_TOTAL_REC.
ENDLOOP.
IF P_QTYTOT = 'X'.
WRITE : /01 'Total Records',15(10) WF_TOTAL_REC,
30 'Quantity ',41(13) WF_TOTAL_QTY DECIMALS 3,
55 'Amount :', 65(13) WF_TOTAL_AMOUNT DECIMALS 2.
ENDIF.
ENDFORM. " check_data
*&---------------------------------------------------------------------*
*& Form check_bwart
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_BWART.

IF NOT (
IT_TAB-BWART = '561' OR
IT_TAB-BWART = '563' OR
IT_TAB-BWART = '565' ).

PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-BWART
'Movement Type Should be 561'.
ENDIF.
ENDFORM. " check_bwart
*&---------------------------------------------------------------------*
*& Form write_error
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_TAB_MATNR text
* -->P_0099 text
*----------------------------------------------------------------------*
FORM WRITE_ERROR USING P_MATNR
P_FIELD
P_ERROR.
ADD 1 TO WF_TOTAL_ERRORS.
WRITE : /01 P_MATNR,
20 P_FIELD,
40 P_ERROR.
ENDFORM. " write_error
*&---------------------------------------------------------------------*
*& Form check_WERKS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_WERKS.
SELECT SINGLE * FROM T001W CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND WERKS = IT_TAB-WERKS.
IF SY-SUBRC <> 0.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-WERKS
'Invalid Plant'.
ENDIF.
ENDFORM. " check_WERKS
*&---------------------------------------------------------------------*
*& Form check_LGORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_LGORT.

IF NOT
( IT_TAB-BWART EQ '561' AND IT_TAB-SOBKZ EQ 'O' ) .
SELECT SINGLE * FROM T001L CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND WERKS = IT_TAB-WERKS
AND LGORT = IT_TAB-LGORT.

IF SY-SUBRC <> 0 .
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-LGORT
'Invalid storage Location for plant'.
ENDIF.
SELECT SINGLE * FROM MARD CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND MATNR = IT_TAB-MATNR
AND WERKS = IT_TAB-WERKS
AND LGORT = IT_TAB-LGORT.
IF SY-SUBRC <> 0.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-LGORT
'Invalid storage Location Material'.
ENDIF.
ENDIF.

ENDFORM. " check_LGORT
*&---------------------------------------------------------------------*
*& Form check_SOBKZ
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_SOBKZ.
IF NOT IT_TAB-SOBKZ IS INITIAL.
SELECT SINGLE * FROM T148 CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND SOBKZ = IT_TAB-SOBKZ.
IF SY-SUBRC <> 0.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-SOBKZ
'Special Stock Indicator'.
ENDIF.
SELECT SINGLE * FROM T157H CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND SPRAS = SY-LANGU
AND TCODE = 'MB1C'
AND BWART = IT_TAB-BWART
AND SOBKZ = IT_TAB-SOBKZ.
IF SY-SUBRC <> 0.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-SOBKZ
'Special Stock Indicator for Movement Type'.
ENDIF.

ENDIF.
ENDFORM. " check_SOBKZ
*&---------------------------------------------------------------------*
*& Form check_lifnr
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_LIFNR.
IF NOT IT_TAB-SOBKZ IS INITIAL.
CHECK IT_TAB-SOBKZ NE 'E'.
SELECT SINGLE * FROM LFA1 CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND LIFNR = IT_TAB-LIFNR.
IF SY-SUBRC <> 0.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-LIFNR
'Invalid Vendor Code'.
ENDIF.
ENDIF.
ENDFORM. " check_lifnr
*&---------------------------------------------------------------------*
*& Form check_gsber
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_AND_GSBER.
SELECT SINGLE * FROM MARA CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND MATNR = IT_TAB-MATNR.

SELECT SINGLE * FROM T134G CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND WERKS = IT_TAB-WERKS
AND SPART = MARA-SPART.
IF SY-SUBRC <> 0.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-GSBER
'Check Business Area detarmination for Plant'.
ELSE.
IT_TAB-GSBER = T134G-GSBER.
modify it_tab.
ENDIF.
ENDFORM. " check_gsber
*&---------------------------------------------------------------------*
*& Form check_matnr
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_MATNR.
SELECT SINGLE * FROM MARA CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND MATNR = IT_TAB-MATNR.
IF SY-SUBRC <> 0.
PERFORM WRITE_ERROR USING IT_TAB-MATNR ' '
'Invalid Material Code'.
ENDIF.
ENDFORM. " check_matnr
*&---------------------------------------------------------------------*
*& Form check_ERFMG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_ERFMG.
IF IT_TAB-ERFMG IS INITIAL OR
IT_TAB-ERFMG < 0.
IF SY-SUBRC <> 0.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-ERFMG
'Quantity is zero or < zero'.
ENDIF.
ENDIF.
ENDFORM. " check_ERFMG
*&---------------------------------------------------------------------*
*& Form check_ERFME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_ERFME.

IF MARA-MEINS <> IT_TAB-ERFME.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-ERFME
'Invalid UOM for Material'.
ENDIF.

CHECK IT_TAB-ERFME NE 'CRT' OR IT_TAB-ERFME NE 'KI'.

SELECT SINGLE * FROM T006 CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND MSEHI = IT_TAB-ERFME.
IF SY-SUBRC <> 0.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-ERFME
'Invalid UOM'.
ENDIF.
ENDFORM. " check_ERFME
*&---------------------------------------------------------------------*
*& Form check_CHARG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_CHARG.
IF NOT IT_TAB-CHARG IS INITIAL.
SELECT SINGLE * FROM MCH1 CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND MATNR = IT_TAB-MATNR
AND CHARG = IT_TAB-CHARG.
* as batches are already created in case of BFL,
IF SY-SUBRC NE 0.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-CHARG
'Batch no does not exist for this material'.
ENDIF.


ENDIF.
ENDFORM. " check_CHARG
*&---------------------------------------------------------------------*
*& Form check_exwrt
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_EXWRT.
DATA : WF_DMBTR LIKE MSEG-DMBTR.

WF_DMBTR = IT_TAB-EXWRT.

IF IT_TAB-EXWRT < 0.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-EXWRT
'Amount can not be zero'.
ENDIF.

* IF it_tab-exwrt = 0.

IF WF_DMBTR = 0.
SELECT SINGLE * FROM MBEW CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND MATNR = IT_TAB-MATNR
AND BWKEY = IT_TAB-WERKS.
IF SY-SUBRC = 0 AND NOT MBEW-VERPR IS INITIAL.
PERFORM WRITE_ERROR USING IT_TAB-MATNR MBEW-VERPR
'Please reset Moving average price for material'.
ENDIF.
ENDIF.
ENDFORM. " check_exwrt
*&---------------------------------------------------------------------*
*& Form check_sgtxt
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_SGTXT.
IF IT_TAB-SGTXT IS INITIAL.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-SGTXT
'Text can not be blank'.
ENDIF.
ENDFORM. " check_sgtxt
*&---------------------------------------------------------------------*
*& Form check_batch
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_BATCH.
DATA : BEGIN OF IT_BATCH OCCURS 0 ,
MATNR LIKE MSEG-MATNR,
CHARG LIKE MSEG-CHARG,
CTR TYPE I.
DATA : END OF IT_BATCH.
LOOP AT IT_TAB WHERE CHARG <> SPACE.
IT_BATCH-MATNR = IT_TAB-MATNR.
IT_BATCH-CHARG = IT_TAB-CHARG.
IT_BATCH-CTR = 1.
COLLECT IT_BATCH.
ENDLOOP.

LOOP AT IT_BATCH WHERE CTR > 1.
PERFORM WRITE_ERROR USING IT_BATCH-MATNR IT_BATCH-CHARG
'Duplicate batch no for This Material'.
ENDLOOP.
ENDFORM. " check_batch
*&---------------------------------------------------------------------*
*& Form display_accounting_information
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_ACCOUNTING_INFORMATION.

WRITE : /01 'Account wise Stock'.
FORMAT COLOR = 3.
WRITE : /01 SY-ULINE(132).
SORT IT_ACC BY GSBER WERKS KONTS.
LOOP AT IT_ACC.
SELECT SINGLE * FROM SKAT CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND SPRAS = SY-LANGU
AND KTOPL = 'BFL'
AND SAKNR = IT_ACC-KONTS.

WRITE : /01 IT_ACC-GSBER,
06 IT_ACC-WERKS,
11 IT_ACC-KONTS ,
22 SKAT-TXT20,
65(15) IT_ACC-EXWRT DECIMALS 2.
ENDLOOP.
FORMAT COLOR OFF.
WRITE : /01 SY-ULINE(132).
ENDFORM. " display_accounting_information
*&---------------------------------------------------------------------*
*& Form fill_accounting_information
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_ACCOUNTING_INFORMATION.
IF IT_TAB-EXWRT > 0.
SELECT SINGLE * FROM MBEW CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND MATNR = IT_TAB-MATNR
AND BWKEY = IT_TAB-WERKS.
SELECT SINGLE * FROM T030 CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND KTOPL = 'VCOA'
AND KTOSL = 'BSX'
* AND BWMOD = ___
* AND KOMOK = ___
AND BKLAS = MBEW-BKLAS.

IF SY-SUBRC <> 0.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-WERKS
'Standard Accounts Table not maintain for plant'.
ELSE.
IT_ACC-GSBER = IT_TAB-GSBER.
IT_ACC-WERKS = IT_TAB-WERKS.
IT_ACC-KONTS = T030-KONTS.
IT_ACC-EXWRT = IT_TAB-EXWRT.
COLLECT IT_ACC.
ENDIF.
ENDIF.
ENDFORM. " fill_accounting_information
*&---------------------------------------------------------------------*
*& Form upload_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM UPLOAD_DATA.
DATA : FNAME TYPE STRING.
FNAME = P_FILE.
CONSTANTS: CON_TAB TYPE CHAR01 VALUE 'X'.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = FNAME
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = CON_TAB
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = IT_TAB
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.



* CALL FUNCTION 'WS_UPLOAD'
* EXPORTING
* FILENAME = p_FILE
* FILETYPE = 'DAT'
* TABLES
* DATA_TAB = it_tab.
ENDFORM. " upload_data
*&---------------------------------------------------------------------*
*& Form fill_RM07MMBL_format
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_RM07MMBL_FORMAT.
LOOP AT IT_TAB.
IT_BMSEG-MAPPE = P_GROUP.
IT_BMSEG-TCODE = 'MB1C'.
IT_BMSEG-BWART = IT_TAB-BWART.
IT_BMSEG-BLDAT = IT_TAB-BLDAT.
IT_BMSEG-BUDAT = IT_TAB-BUDAT.
IT_BMSEG-BKTXT = IT_TAB-BKTXT.
IT_BMSEG-MATNR = IT_TAB-MATNR.
IT_BMSEG-WERKS = IT_TAB-WERKS.
IT_BMSEG-LGORT = IT_TAB-LGORT.
IT_BMSEG-CHARG = IT_TAB-CHARG.
IT_BMSEG-LIFNR = IT_TAB-LIFNR.
IT_BMSEG-SOBKZ = IT_TAB-SOBKZ.
IT_BMSEG-GSBER = IT_TAB-GSBER.
IT_BMSEG-ERFMG = IT_TAB-ERFMG.
IT_BMSEG-ERFME = IT_TAB-ERFME.
IT_BMSEG-EXWRT = IT_TAB-EXWRT.
IT_BMSEG-SGTXT = IT_TAB-SGTXT.
* it_bmseg-kdauf = it_tab-kdauf.
* it_bmseg-kdpos = it_tab-kdpos.
APPEND IT_BMSEG.
ENDLOOP.
ENDFORM. " fill_RM07MMBL_format
*&---------------------------------------------------------------------*
*& Form download_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DOWNLOAD_DATA.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = P_LOCLFN
FILETYPE = 'ASC'
TABLES
DATA_TAB = IT_BMSEG.
IF SY-SUBRC <> 0.
FORMAT COLOR = 6.
WRITE : /01 'Error occurs at time of download file',132 ''.
ELSE.
FORMAT COLOR = 5.
WRITE : /01 'Fill Successfully Generated into ',132 ''.
WRITE : /01 P_LOCLFN, 132 ''.
WRITE : /'Copy this file to unix server and run program RM07MMBL',
132 ''.
ENDIF.

ENDFORM. " download_data
*&---------------------------------------------------------------------*
*& Form save_on_unix_serve
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SAVE_ON_UNIX_SERVE.
DATA : ERRFLAG.
* CONCATENATE p_unixfn INTO p_unixfn.
OPEN DATASET P_UNIXFN FOR OUTPUT IN TEXT MODE ENCODING DEFAULT .
IF SY-SUBRC NE 0.
ERRFLAG = 'X'.
MESSAGE I002(MG) WITH P_UNIXFN.
MESSAGE A099(MG).
ENDIF.
LOOP AT IT_BMSEG.
TRANSFER IT_BMSEG TO P_UNIXFN.
IF SY-SUBRC NE 0.
ERRFLAG = 'X'.
MESSAGE I001(MG) WITH P_UNIXFN.
MESSAGE A099(MG).
ENDIF.
ENDLOOP.
CLOSE DATASET P_UNIXFN .

IF ERRFLAG = 'X'.
FORMAT COLOR = 6.
WRITE : /01 'File not save on unix Server' , 132 ''.
FORMAT COLOR OFF.
ELSE.
FORMAT COLOR = 5.
WRITE : /'File Successfuly Save on Unix Server', 132 ''.
WRITE : / P_UNIXFN , 132 ''.
IF P_RM07MM IS INITIAL.
WRITE : /'Run program RM07MMBL' , 132 ''.
ENDIF.
FORMAT COLOR OFF.
ENDIF.

ENDFORM. " save_on_unix_serve
*&---------------------------------------------------------------------*
*& Form calll_rm07mmbl
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALLL_RM07MMBL.
* change max no of line to 475
SUBMIT RM07MMBL WITH DS_NAME = P_LOGFIL
* with MAXPO = 1
WITH MAXPO = 475
WITH P_UNAME = SY-UNAME
WITH XPROT = 'X'
AND RETURN.
SKIP 2.
FORMAT COLOR = 5.
WRITE : /01 'Run Session',P_GROUP ,132 ''.
FORMAT COLOR OFF.

ENDFORM. " calll_rm07mmbl
*&---------------------------------------------------------------------*
*& Form check_budat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_BUDAT.
IF IT_TAB-BUDAT <> P_BUDAT.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-BUDAT
'Invalid Posting Date'.
ENDIF.

ENDFORM. " check_budat
*&---------------------------------------------------------------------*
*& Form check_plant_for_material
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_PLANT_FOR_MATERIAL .
SELECT SINGLE * FROM MARC CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND MATNR = IT_TAB-MATNR
AND WERKS = IT_TAB-WERKS .


IF SY-SUBRC <> 0.
PERFORM WRITE_ERROR USING IT_TAB-MATNR IT_TAB-WERKS
'Material not maintained for Plant'.
ENDIF.

ENDFORM. " check_plant_for_material
*&---------------------------------------------------------------------*
*& Form check_sales_order
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_SALES_ORDER .

* CHECK it_tab-bwart EQ '561' .
* CHECK it_tab-sobkz EQ 'E' .
*
* IF it_tab-kdauf IS INITIAL OR
* it_tab-kdpos IS INITIAL.
*
* PERFORM write_error USING it_tab-matnr it_tab-werks
* 'Sales order/item missing ' .
* ENDIF.

ENDFORM. " check_sales_order

No comments:

link us...

For Visitors

if you want to publish or Add something on ERP, SAP , SAP FUNCTIONAL, SAP ABAP then mail us along with your email-id. contain must be yours

email-id :- avinashkr_raj@yahoo.com(any email)

email-id :- avinaskr_raj.abap@blogger.com ( use only gmail)