Go on link..

link us with ...

Friday, December 31, 2010

Down load WEIGHBRIDGE text file data to Ztable

*&---------------------------------------------------------------------*
*& Report ZVVF_MR025_WEIGHBRIDGE *
*& *
*&---------------------------------------------------------------------*
REPORT ZVVF_MR025_WEIGHBRIDGE no standard page heading line-size 110
MESSAGE-ID ZMM .

*----------------------------------------------------------------------
** Module Sales *
*----------------------------------------------------------------------
** Objective: Down load WEIGHBRIDGE text file data to Ztable
** Program : Updates tables (X) Download data (X)
** Output Lists () ALV
**
** Technical Spec No :
** Date Created :
** Author :
** Location :
**---------------------------------------------------------------------*
* External Dependencies
**---------------------------------------------------------------------*
*
**---------------------------------------------------------------------*
* Amendment History
**---------------------------------------------------------------------*
* Who Change ID Reason
*** ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*---------------------------------------------------------------------**
* Type-pools
*----------------------------------------------------------------------*

*---------------------------------------------------------------------*
**TABLES :
*---------------------------------------------------------------------*
TABLES : ZVVF_MT25_BRIDGE, "Weigh Bridge Down Loaded Details
ZVVF_MT25_BRIDG1, " Weigh Bridge Posted POs Details
EKPO, "Purchasing Document Item
EKBE, " History per Purchasing Document
MSEG, " Document Segment: Material
MKPF. " Header: Material Document

*---------------------------------------------------------------------*
**TYPES :
*---------------------------------------------------------------------*
DATA : BEGIN OF TY_DETAIL,
PO_NUMBER TYPE BAPI2017_GM_ITEM_CREATE-PO_NUMBER,
PO_ITEM TYPE BAPI2017_GM_ITEM_CREATE-PO_ITEM,
MATERIAL TYPE BAPI2017_GM_ITEM_CREATE-MATERIAL,
VENDOR TYPE BAPI2017_GM_ITEM_CREATE-VENDOR,
PLANT TYPE BAPI2017_GM_ITEM_CREATE-PLANT,
STGE_LOC TYPE BAPI2017_GM_ITEM_CREATE-STGE_LOC,
MOVE_TYPE TYPE BAPI2017_GM_ITEM_CREATE-MOVE_TYPE,
ENTRY_QNT TYPE BAPI2017_GM_ITEM_CREATE-ENTRY_QNT,
ENTRY_UOM TYPE BAPI2017_GM_ITEM_CREATE-ENTRY_UOM,
ENTRY_UOM_ISO TYPE BAPI2017_GM_ITEM_CREATE-ENTRY_UOM_ISO,
MVT_IND TYPE BAPI2017_GM_ITEM_CREATE-MVT_IND,
ITEM_TEXT TYPE BAPI2017_GM_ITEM_CREATE-ITEM_TEXT,
VENDRBATCH TYPE BAPI2017_GM_ITEM_CREATE-VENDRBATCH,
ST_UN_QTYY_1 TYPE BAPI2017_GM_ITEM_CREATE-ST_UN_QTYY_1,
QUANTITY TYPE BAPI2017_GM_ITEM_CREATE-QUANTITY,
PO_PR_QNT TYPE BAPI2017_GM_ITEM_CREATE-PO_PR_QNT,
IND_PROPOSE_QUANX TYPE BAPI2017_GM_ITEM_CREATE-IND_PROPOSE_QUANX,
BASE_UOM TYPE BAPI2017_GM_ITEM_CREATE-BASE_UOM.
DATA : END OF TY_DETAIL.
*---------------------------------------------------------------------*
**CONSTANTS :
*---------------------------------------------------------------------*
*CONSTANTS C_PATH TYPE STRING VALUE '/VVFuture/upload/fi/'.
*---------------------------------------------------------------------*
**INTERNAL TABLES :
*---------------------------------------------------------------------*

DATA : IT_BRIDGE TYPE TABLE OF ZVVF_MT25_BRIDGE WITH HEADER LINE.

DATA : IT_DETAIL LIKE STANDARD TABLE OF TY_DETAIL WITH HEADER LINE.

DATA : IT_BAPI_HEADER TYPE STANDARD TABLE OF BAPI2017_GM_HEAD_01 WITH
HEADER LINE.
DATA : IT_BAPI_DETAIL TYPE STANDARD TABLE OF BAPI2017_GM_ITEM_CREATE
WITH HEADER LINE.

DATA: BEGIN OF ITABRES OCCURS 0.
INCLUDE STRUCTURE BAPIRET2.
DATA: END OF ITABRES.

data : begin of it_ekbe occurs 0,
ebeln like ekbe-ebeln,
ebelp like ekbe-ebelp,
elikz like ekbe-elikz,
menge like ekbe-menge,
end of it_ekbe.
data : begin of it_ekbesum occurs 0,
ebeln like ekbe-ebeln,
ebelp like ekbe-ebelp,
elikz like ekbe-elikz,
menge like ekbe-menge,
end of it_ekbesum.

data : begin of it_mseg occurs 0,
ebeln like mseg-ebeln,
ebelp like mseg-ebelp,
mblnr like mkpf-mblnr,
xblnr like mkpf-xblnr,
end of it_mseg.

data : begin of it_block occurs 0,
ebeln like mseg-ebeln,
ebelp like mseg-ebelp,
ztext(35) type c,
end of it_block.

*---------------------------------------------------------------------*
**WORK AREA :
*---------------------------------------------------------------------*
DATA : WA_BRIDGE LIKE LINE OF IT_BRIDGE,
WA_ekbe LIKE LINE OF IT_ekbe,
WA_ekbesum LIKE LINE OF IT_ekbesum.
*---------------------------------------------------------------------*
**DATA :
*---------------------------------------------------------------------*
DATA: W_FILENAME TYPE STRING,
W_UNIXFN TYPE STRING,
w_lines type i.
DATA : MD_NUMBER TYPE MBLNR,
W_PSTYP LIKE EKPO-PSTYP,
W_input like mseg-matnr,
w_slip like ZVVF_MT25_BRIDGE-zfile.
data : w_block type i,
W_menge like ekpo-menge,
W_qty like ekpo-menge,
W_qty1 like ekpo-menge,
W_uebto like ekpo-uebto,
w_aedat like ekpo-aedat.
*---------------------------------------------------------------------*
**INITIALIZATION :
*---------------------------------------------------------------------*
INITIALIZATION.

*---------------------------------------------------------------------*
**SELECTION-SCREEN :
*---------------------------------------------------------------------*

SELECTION-SCREEN:BEGIN OF BLOCK BL1 WITH FRAME .

PARAMETER:
pr_file type ZFILE OBLIGATORY,
pr_path type ZFILE OBLIGATORY.
SELECTION-SCREEN END OF BLOCK BL1.
*---------------------------------------------------------------------*
**AT SELECTION-SCREEN :
*---------------------------------------------------------------------*
AT SELECTION-SCREEN.

perform check_data.

*---------------------------------------------------------------------*
**START-OF-SELECTION :
*---------------------------------------------------------------------*
START-OF-SELECTION.

***file from local drive saved to ztable
PERFORM SAVE_ON_UNIX_SERVE.

form check_data.
***check whether file already downloaded
select single zfile into w_slip from ZVVF_MT25_BRIDGE where
zfile = pr_file.
if sy-subrc = 0.
message e130 with pr_file.
else.
**check whether file already downloaded in table having all posted files
select single zfile into w_slip from ZVVF_MT25_BRIDG1 where
zfile = pr_file.
if sy-subrc = 0.
message e130 with pr_file.
endif.
endif.

endform.


*&---------------------------------------------------------------------*
*& Form SAVE_ON_UNIX_SERVE
*&---------------------------------------------------------------------*
FORM SAVE_ON_UNIX_SERVE .

DATA : W_UNIX_FILE TYPE RLGRAP-FILENAME.
DATA : ERRFLAG.
DATA : WA_DETAIL TYPE STRING.
DATA : DELIMITER(1) VALUE ','.

DATA : BEGIN OF IT_PO OCCURS 0,
W_PONO LIKE EKKO-EBELN ,
W_POITEM LIKE EKPO-EBELP,
w_slip(10) type c,
W_MATERIAL LIKE EKPO-MATNR ,
W_VENDOR LIKE EKKO-LIFNR,
W_PLANT LIKE EKPO-WERKS ,
W_STGE_LOC LIKE EKPO-LGORT,
w_frbnr LIKE mkpf-frbnr ,
w_xblnr LIKE mkpf-xblnr ,
W_bktxt LIKE mkpf-bktxt ,
W_ENTQTY(17) TYPE C ,
W_ITEM_TEXT1(17) TYPE C ,
W_ITEM_TEXT2(17) TYPE C ,
W_MENGE1(17) TYPE C ,
W_BASE_UOM LIKE EKPO-MEINS ,
W_VENDRBATCH LIKE EKPO-LGORT,
w_name type name1,
* W_MOVE_TYPE LIKE MSEG-BWART ,
* W_MVT_IND LIKE MSEG-KZBEW ,
END OF IT_PO.

DATA : WA_PO LIKE LINE OF IT_PO.

DATA :begin of itab occurs 0,

text(270) type c,

end of itab .
DATA : WA_LINE LIKE LINE OF itab.


CONCATENATE pr_PATH '/' pr_file '.txt' INTO W_UNIXFN .

****fn.module to download file
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = w_UNIXFN
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ' '
TABLES
DATA_TAB = ITAB..


IF SY-SUBRC NE 0.
ERRFLAG = 'X'.
MESSAGE I002(MG) WITH W_UNIXFN.
MESSAGE A099(MG).
ENDIF.

LOOP AT ITAB INTO WA_LINE.
**split data at ','
SPLIT WA_LINE AT DELIMITER INTO
WA_PO-W_PONO
WA_PO-W_POITEM
WA_PO-w_slip
WA_PO-W_MATERIAL
WA_PO-W_VENDOR
WA_PO-W_PLANT
WA_PO-W_STGE_LOC
WA_PO-W_frbnr
WA_PO-W_xblnr
WA_PO-W_bktxt
WA_PO-W_ENTQTY
WA_PO-W_ITEM_TEXT1
WA_PO-W_ITEM_TEXT2
WA_PO-W_MENGE1
WA_PO-W_BASE_UOM
WA_PO-W_VENDRBATCH
wa_po-w_name IN CHARACTER MODE .
***padding zeros
perform MATNR_FORMAT_INPUT using WA_PO-W_PONO.
perform MATNR_FORMAT_INPUT using WA_PO-W_POITEM.
perform MATNR_FORMAT_INPUT using WA_PO-W_MATERIAL.
perform MATNR_FORMAT_INPUT using WA_PO-W_VENDOR.

IF NOT WA_PO IS INITIAL.


***check whether PO is for STO and PO Existance
SELECT SINGLE PSTYP menge uebto aedat FROM EKPO INTO
(W_PSTYP,W_menge,W_uebto,w_aedat)
WHERE EBELN = WA_PO-W_PONO AND
EBELP = WA_PO-W_POITEM.
IF SY-SUBRC = 0.
IF W_PSTYP = 7.
WA_BRIDGE-BWART = '101'.
ELSE.
WA_BRIDGE-BWART = '103'.
ENDIF.

****check open PO qty exceeds the limit by received qty
w_qty = W_menge + ( ( W_uebto / 100 ) * W_menge ).

SELECT ebeln ebelp elikz menge FROM EKBE INTO corresponding
fields of table it_ekbe WHERE EBELN = WA_PO-W_PONO AND
EBELP = WA_PO-W_POITEM and
gjahr = w_aedat+0(4) and
( bwart = '101' or
bwart = '105' ).
if sy-subrc = 0.
loop at it_ekbe into wa_ekbe.
move-corresponding wa_ekbe to wa_ekbesum.
collect wa_ekbesum into it_ekbesum.
endloop.
***check delivery completed for PO
read table it_ekbesum into wa_ekbesum with key ebeln = WA_PO-W_PONO
ebelp = WA_PO-W_POITEM
elikz = ' '.
if sy-subrc = 0.

w_qty1 = wa_ekbesum-menge + WA_PO-W_MENGE1.

if w_qty1 gt w_qty.
WA_BRIDGE-zblck = 'X'.
WA_BRIDGE-ztext = 'No Open Quantity'.
it_block-ebeln = WA_PO-W_PONO.
it_block-ebelp = WA_PO-W_POITEM.
it_block-ztext = 'No Open Quantity'.
append it_block.
endif.

else.
WA_BRIDGE-zblck = 'X'.
WA_BRIDGE-ztext = 'Delivery Completed'.
it_block-ebeln = WA_PO-W_PONO.
it_block-ebelp = WA_PO-W_POITEM.
it_block-ztext = 'Delivery Completed'.
append it_block.

endif.

endif.
else.
WA_BRIDGE-zblck = 'X'.
WA_BRIDGE-ztext = 'PO Does Not Exists in Table EKKO'.

it_block-ebeln = WA_PO-W_PONO.
it_block-ebelp = WA_PO-W_POITEM.
it_block-ztext = 'PO Does Not Exists in Table EKKO'.
append it_block.
ENDIF.

if w_aedat is initial.
w_aedat = sy-datum.
endif.
***check delivery note exist or not
select distinct mseg~ebeln mseg~ebelp mkpf~mblnr mkpf~xblnr from mseg
inner join mkpf on mseg~mblnr = mkpf~mblnr and
mseg~mjahr = mkpf~mjahr into
corresponding fields of table it_mseg where
mseg~ebeln = WA_PO-W_PONO and
mseg~ebelp = WA_PO-W_POITEM and
mseg~mjahr = w_aedat+0(4) and
mkpf~xblnr = WA_PO-W_xblnr and
( bwart = '101' or
bwart = '103' OR
bwart = '105' ).
if sy-subrc = 0.
WA_BRIDGE-zblck = 'X'.
WA_BRIDGE-ztext = 'Duplicate Delivery Note'.
it_block-ebeln = WA_PO-W_PONO.
it_block-ebelp = WA_PO-W_POITEM.
it_block-ztext = 'Duplicate Delivery Note'.
append it_block.
endif.

APPEND WA_PO TO IT_PO.
WA_BRIDGE-EBELN = WA_PO-W_PONO.
WA_BRIDGE-EBELP = WA_PO-W_POITEM.
WA_BRIDGE-ZSLIPNO = WA_PO-W_SLIP.
WA_BRIDGE-MATNR = WA_PO-W_MATERIAL.
WA_BRIDGE-LIFNR = WA_PO-W_VENDOR.
WA_BRIDGE-WERKS = WA_PO-W_PLANT.
WA_BRIDGE-LGORT = WA_PO-W_STGE_LOC.
WA_BRIDGE-frbnr = WA_PO-W_frbnr.
WA_BRIDGE-xblnr = WA_PO-W_xblnr.
WA_BRIDGE-BKTXT = WA_PO-W_bktxt.
WA_BRIDGE-LSMNG = WA_PO-W_ENTQTY.
WA_BRIDGE-gmeins = WA_PO-W_ITEM_TEXT1.
WA_BRIDGE-tmeins = WA_PO-W_ITEM_TEXT2.
WA_BRIDGE-MENGE = WA_PO-W_MENGE1.
WA_BRIDGE-MEINS = WA_PO-W_BASE_UOM.
WA_BRIDGE-LCHARG = WA_PO-W_VENDRBATCH.
WA_BRIDGE-name1 = WA_PO-W_name.
WA_BRIDGE-KZBEW = 'B'.
WA_BRIDGE-budat = sy-datum.
WA_BRIDGE-yyear = sy-datum+0(4).
WA_BRIDGE-zfile = pr_file.

IF WA_BRIDGE-LSMNG NE WA_BRIDGE-MENGE.
IF WA_BRIDGE-BWART = '101'.
WA_BRIDGE-GRUND = '0001'.
ELSEIF WA_BRIDGE-BWART = '103'.
WA_BRIDGE-GRUND = '0003'.
ENDIF.
ENDIF.
**update ztable
MODIFY ZVVF_MT25_BRIDGE FROM WA_BRIDGE.

ENDIF.

clear : wa_bridge,w_qty,w_qty1,W_PSTYP,
W_menge,W_uebto,w_aedat,WA_PO,it_block.
ENDLOOP.

describe table IT_PO lines w_lines.
if w_lines ne 0.
clear ERRFLAG.
endif.

IF ERRFLAG = 'X'.
FORMAT COLOR = 6.
WRITE : /01 'File not saved on ZVVF_MT25_BRIDGE ' , 132 ''.
FORMAT COLOR OFF.
ELSE.
FORMAT COLOR = 5.
WRITE : /'File Successfuly Downloaded to Table',
'ZVVF_MT25_BRIDGE', 132 ''.
WRITE : / W_UNIXFN , 132 ''.
FORMAT COLOR OFF.

if not it_block[] is initial.
SKIP 2.
WRITE : /'Blocked POs are,'.
skip .
WRITE : /2 'Purchase order', 18 'PO Item', 35 'Reason'.
WRITE : /2 SY-ULINE(52) .
loop at it_block.
WRITE : /2 it_block-ebeln, 18 it_block-ebelp, 27 it_block-ztext.
endloop.
endif.

ENDIF.

ENDFORM. " SAVE_ON_UNIX_SERVE

*&--------------------------------------------------------------------*
*& Form MATNR_FORMAT_INPUT
*&--------------------------------------------------------------------*
* MATNR FORMAT INPUT
*---------------------------------------------------------------------*

FORM MATNR_FORMAT_INPUT using w_input.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = w_input
IMPORTING
OUTPUT = w_input.
ENDFORM.

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)