zai00003 ganesh

25
7/29/2019 Zai00003 Ganesh http://slidepdf.com/reader/full/zai00003-ganesh 1/25 ************************************************************************ * Program : ZAI00003 Creation Dt: 06/25/04 * Title : Company Vehicle Interfaces for Additions * Transaction (ABZON) * * Author : Beatriz Alvarez * Lead : Kay Ramsey * Type : AA interface Script Id : IL050 ************************************************************************ * Description : This program is feed with a CV file which contains Lease * and company vehicles to be added to SAP through Asset * Acquisition transaction which creates the Asset * Accounting document. ************************************************************************ * Input : File of data * Output: List/Mail of errors and statistics ************************************************************************ * Modification History: * * YYYY/MM/DD Author * Correction# Description * ----------- -------------------------------------------------------- * 2004/06/25 Beatriz Alvarez * DV5K919249 Initial Version ************************************************************************ *2009/12/20 Rambabu K *DV5K951285 EWO#1001 to pass person department to the additional * asset description field of asset master record ************************************************************************ report ZAI00003 no standard page heading line-size 255 message-id zf. *----------------------------------------------------------------------- *TABLES *----------------------------------------------------------------------- tables: anla. *Mail structures data: doc_chng LIKE sodocchgi1, objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE, reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE. *----------------------------------------------------------------------- *PARAMETERS *----------------------------------------------------------------------- selection-screen skip. selection-screen begin of block blk1 with frame title text-001. selection-screen begin of line. selection-screen comment 1(31) text-003. parameters: p_source as checkbox DEFAULT 'X'. "default from server selection-screen end of line. selection-screen begin of line. selection-screen comment 1(31) text-004. parameters p_test as checkbox default 'X'. selection-screen end of line. parameters: p_file1 like rlgrap-filename obligatory " Uplaod File default '/nmcfs1/<sysid>/in/ccv1120.cvadds'.

Upload: balakrishna-vegi

Post on 04-Apr-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 1/25

************************************************************************* Program : ZAI00003 Creation Dt: 06/25/04* Title : Company Vehicle Interfaces for Additions* Transaction (ABZON)** Author : Beatriz Alvarez* Lead : Kay Ramsey* Type : AA interface Script Id : IL050************************************************************************* Description : This program is feed with a CV file which contains Lease* and company vehicles to be added to SAP through Asset* Acquisition transaction which creates the Asset* Accounting document.************************************************************************* Input : File of data* Output: List/Mail of errors and statistics************************************************************************* Modification History:** YYYY/MM/DD Author* Correction# Description* ----------- --------------------------------------------------------* 2004/06/25 Beatriz Alvarez* DV5K919249 Initial Version

*************************************************************************2009/12/20 Rambabu K*DV5K951285 EWO#1001 to pass person department to the additional* asset description field of asset master record************************************************************************report ZAI00003 no standard page heading

line-size 255message-id zf.

*-----------------------------------------------------------------------*TABLES*-----------------------------------------------------------------------tables: anla.

*Mail structuresdata: doc_chng LIKE sodocchgi1,objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE.

*-----------------------------------------------------------------------*PARAMETERS*-----------------------------------------------------------------------selection-screen skip.

selection-screen begin of block blk1 with frame title text-001.selection-screen begin of line.selection-screen comment 1(31) text-003.

parameters: p_source as checkbox DEFAULT 'X'. "default from serverselection-screen end of line.

selection-screen begin of line.selection-screen comment 1(31) text-004.parameters p_test as checkbox default 'X'.selection-screen end of line.

parameters: p_file1 like rlgrap-filename obligatory " Uplaod Filedefault '/nmcfs1/<sysid>/in/ccv1120.cvadds'.

Page 2: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 2/25

parameters: p_file2 like rlgrap-filename obligatory " Download Filedefault '/nmcfs1/<sysid>/in/ccv1120.cvadds_error.<datetime>'.

PARAMETERS: P_FDATA LIKE RLGRAP-FILETYPE default 'DAT'.

selection-screen skip.parameters: p_group(12) obligatory default sy-repid,

p_user like sy-uname obligatory default 'BDC_AA',p_keep as checkbox default 'X',p_holddt like sy-datum.

select-options s_erec for reclist-receiver DEFAULT'[email protected]'obligatory NO INTERVALS.

selection-screen end of block blk1.selection-screen skip.

selection-screen begin of block blk2 with frame title text-002.parameters p_bukrs like anla-bukrs obligatory default '2177'.parameters p_bldat like raifp1-bldat obligatory default sy-datum.parameters p_budat like raifp1-budat obligatory default sy-datum.parameters p_GKONT like raifp2-gkont obligatory default '0249999081'.parameters p_anlkl like raifp4-anlkl obligatory default '65190000'.parameters p_meins like anla-meins obligatory default 'EA'.

parameters p_blart like RAIFP1-blart obligatory default 'AA'.parameters p_bwasl like RAIFP1-bwasl obligatory default '100'.parameters p_menge(3) type n obligatory default '1'.parameters p_stort like anlz-stort obligatory default 'HCAR'.parameters p_ord44 like anla-ord44 obligatory default '10'.parameters p_eigkz like anla-eigkz obligatory default 'A'.selection-screen end of block blk2.

*-----------------------------------------------------------------------* INCLUDE PROGRAMS*-----------------------------------------------------------------------* Includes for standard report header & replaces fields with sy fieldsinclude zziheadr.

*Include for standard header & trailer recordsinclude ZZIFILE1.include zzifile3.include <icon>.

*-----------------------------------------------------------------------*INTERNAL TABLES*-----------------------------------------------------------------------data: begin of t_file occurs 0,

ccode(4), " Company Owner Group IDplant(4), " Plantcity(4), " Citycounty(4), " County

state(2), " Statecountry(2), " Countryvin(17), " VIN numbermodel_num(5), " Model Codesernr(6), " Serial numberdesc(50), " Asset Descriptioncost(12), " Costdate(8), " Document Date (DD/MM/YYYY)model_year(2), " Model Yearveh_type(1), " Vehicle Type

Page 3: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 3/25

lease_flag(1), " Lease Company Flagcolor(3), " Vehicle Colorperson(27), " Person DepartmentCCENTER(10), " Cost Centerprocess_Date(8), " Process Date

end of t_file.

* ERROR DATAdata begin of t_error occurs 0.

include structure t_file.data MSG(50).DATA TYPE(1).data end of t_error.

* VALID DATAdata: begin of t_data occurs 0,

bukrs like anla-bukrs, " Company Codetxt50 like raifp4-txt50, " Asset Descriptionkostl like anlz-kostl, " Cost Centeranbtr(13), " Amount Postedbldat(10), " Document Datebudat(10), " Posting DateBZDAT(10), " In service datesgtxt like raifp2-sgtxt, " Free text for other details

xblnr like raifp1-xblnr, " Reference document numberzuonr like raifp2-zuonr, " Assignmentwerks like anlz-werks, " Plantsernr like anla-sernr, " Serial Numberkfzkz like anlz-kfzkz, " Model codegdlgrp like anla-gdlgrp, " Product Linezzord46 like anla-zzord46, " Countryzzord47 like anla-zzord47, " Regionzzord48 like anla-zzord48, " Countyzzord49 like anla-zzord49, " Citytypbz like anla-typbz, " Type Nameend of t_data.

* INPUT RECORDDATA: BEGIN OF in_rec,recbody(460) TYPE c,

END OF in_rec.* MESSAGES TO BE MAILEDdata: begin of i_msgs occurs 0.

include structure soli.data: end of i_msgs.

* Detail in maildata begin of i_msg_det occurs 0.

include structure soli.data end of i_msg_det.

* BDC STRUCTUREdata: begin of bdcdata occurs 0.

include structure bdcdata.data: end of bdcdata.

*DATA DECLARATIONdata: count_good type i, "Correct records counter

count_bad type i, "Error records countercount_rej type i, "Error records rejected counter

Page 4: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 4/25

count type i, "Total records counter (good+bad)chk_continue, "Error flagchk_message, "Message typeheader_id(4) value 'HDR ', "File Header Record Identifiertrailer_id(4) value 'TRLR',"File Trailer Record Identifiermsgs_lin type i, "Message linestotal_recs(6) type n, "Total records read from filebukrs like anla-bukrs, "Company Codeanlkl like raifp4-anlkl, "Asset classmeins like anla-meins, "UMblart like RAIFP1-blart, "doc typebwasl like RAIFP1-bwasl, "Asset transaction typegkont like raifp2-gkont, "Offseting accountstort like anlz-stort, "Asset locationord44 like anla-ord44, "Operating Planteigkz like anla-eigkz, "Property indicatorkostl like anlz-kostl, "cost centerBKZKP LIKE CSKS-BKZKP, "Lock Indicator for

"Actual Primary Postingswerks like anlz-werks, "planttmp_date like sy-datum. "date

CONSTANTS: C_X VALUE 'X',C_E VALUE 'E',

C_L VALUE 'L',C_C VALUE 'C',C_S VALUE 'S',C_R VALUE 'R',C_N VALUE 'N',C_PERIV(2) VALUE 'V3',C_11(2) VALUE '11',C_A VALUE 'A',C_DOT VALUE '.',c_raw(3) VALUE 'RAW',C_NUMBERS(11) VALUE '0123456789 ',T_CODE(5) VALUE 'ABZON'.

*-----------------------------------------------------------------------

* INITIALIZATION*-----------------------------------------------------------------------INITIALIZATION.refresh t_data.refresh t_error.refresh bdcdata.refresh i_msgs.

*----------------------------------------------------------------------** AT-SELECTION-SCREEN*----------------------------------------------------------------------** PC INPUT FILEat selection-screen on value-request for p_file1.if p_source = space. "desktop

perform open_file using p_file1.endif.

* PC OUTPUT FILEat selection-screen on value-request for p_file2.if p_source = space. "desktop

perform open_file using p_file2.endif.

* COMP CODEat selection-screen on p_bukrs.select single bukrs into bukrs from t093c where bukrs = p_bukrs.

Page 5: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 5/25

if sy-subrc <> 0.message e000 with 'Company Code'(005) p_bukrs 'not valid'(006).

endif.* OFFSETING ACCOUNTat selection-screen on p_GKONT.SELECT SINGLE SAKNR FROM SKB1

INTO GKONTWHERE BUKRS = P_BUKRSAND SAKNR = P_GKONT.

if sy-subrc <> 0.message e000 with 'Account'(051) p_gkont 'not valid'(006).

endif.

* ASSET CLASSat selection-screen on p_anlkl.select single anlkl into anlkl from ANKA where ANLKL = p_ANLKL.if sy-subrc <> 0.

message e000 with 'Asset Class'(007) p_ANLKL 'not valid'(006).endif.

* UofMat selection-screen on p_meins.select single MSEHI into meins from t006 where MSEHI = p_meins.if sy-subrc <> 0.

message e000 with 'Unit of Measure'(008) p_meins 'not valid'(006).

endif.* DOC TYPEat selection-screen on p_blart.select single blart into blart from t003 where blart = p_blart.if sy-subrc <> 0.

message e000 with 'Doc. Asset Type'(009) p_blart 'not valid'(006).endif.

* ASSET TX TYPEat selection-screen on p_BWASL.select single bwasl into bwasl from tabw where BWASL = p_BWASL.if sy-subrc <> 0.

message e000 with 'Asset transaction type'(010) p_BWASL'not valid'(006).

endif.* ASSET LOCATIONat selection-screen on p_STORT.select STAND up to 1 rows from T499S into STORTwhere STAND = p_STORT.

endselect.if sy-subrc <> 0.

message e000 with 'Asset location'(011) p_STORT 'not valid'(006).endif.

* EVALUATION GRP #at selection-screen on p_ORD44.select ORDNR up to 1 rows from T087 into ORD44where ORDNR = p_ORD44.

endselect.if sy-subrc <> 0.

message e000 with 'Evaluation group number'(012) p_ORD44'not valid'(006).

endif.* PROPERTY INDICATORat selection-screen on p_EIGKZ.select single EIGKZ from T097 into EIGKZ where EIGKZ = p_EIGKZ.if sy-subrc <> 0.

message e000 with 'Property indicator'(013) p_EIGKZ

Page 6: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 6/25

'not valid'(006).endif.

* FILE TYPE INVISIBLE IF INPUT FILE FROM SERVER (HARD CODE)at selection-screen OUTPUT.LOOP AT SCREEN.

IF SCREEN-NAME = 'P_FDATA'.IF P_SOURCE = 'X'.

screen-INVISIBLE = '1'.SCREEN-ACTIVE = '0'.screen-OUTPUT = '0'.

ELSE.screen-INVISIBLE = '0'.SCREEN-ACTIVE = '1'.screen-OUTPUT = '1'.

ENDIF.MODIFY SCREEN.

ENDIF.IF SCREEN-NAME = '%_P_FDATA_%_APP_%-TEXT'.IF P_SOURCE = 'X'.

screen-INVISIBLE = '1'.SCREEN-ACTIVE = '0'.screen-OUTPUT = '0'.MODIFY SCREEN.

ENDIF.

ENDIF.ENDLOOP.*-----------------------------------------------------------------------*START-OF-SELECTION.*-----------------------------------------------------------------------start-of-selection.* Performing function module Z_GET_VARIANT_CONTENTS.include ZZIGETVAR.

* LOCK PROGRAMperform lock_program.

if p_source = space.

* GET FILE FROM PCperform get_file.else.

* GET FILE FROM SERVERperform read_data.

endif.if chk_continue = C_X.

* VALIDATE DATAperform get_data.

* CONTROL REPORTperform write_summary.

* EMAIL THE RESULTSperform set_mail.

perform send_mail.endif.

*-----------------------------------------------------------------------*END-OF-SELECTION*-----------------------------------------------------------------------end-of-selection.* Performing include for additional processing at the end.include ZZIFINPROC.

*************************BEGIN OF FORM ROUTINES*************************

Page 7: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 7/25

*-----------------------------------------------------------------------* PERFORM OPEN_FILE **-----------------------------------------------------------------------* Display the window to choose the path where the PC file will be gotten*-----------------------------------------------------------------------form open_file using p_file.call function 'WS_FILENAME_GET'

EXPORTINGdef_filename = p_filedef_path = 'c:/temp'mask = ',*.*,*.*.'mode = 'O'title = 'Open File'(014)

IMPORTINGfilename = p_file.

* no sy-subrc checking is necessary here.endform.

*-----------------------------------------------------------------------* PERFORM GET_FILE **-----------------------------------------------------------------------* Get file from PC*-----------------------------------------------------------------------form get_file.

call function 'WS_UPLOAD'EXPORTINGfilename = p_file1filetype = p_fdata

TABLESdata_tab = t_file

EXCEPTIONSconversion_error = 1file_open_error = 2file_read_error = 3invalid_type = 4no_batch = 5unknown_error = 6

invalid_table_width = 7gui_refuse_filetransfer = 8customer_error = 9others = 10.

case sy-subrc.when 0.perform write_success using 'File'(015)

p_file1'Read Successfully'(016).

chk_continue = C_X.when others.perform write_failure using 'Error Reading the file'(017)

p_file1.chk_continue = SPACE.

endcase.endform.

*-----------------------------------------------------------------------* PERFORM OPEN_GROUP **-----------------------------------------------------------------------* Open BDC session*-----------------------------------------------------------------------

Page 8: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 8/25

form open_group.call function 'BDC_OPEN_GROUP'

EXPORTINGclient = sy-mandt "p_clientgroup = p_groupuser = p_userkeep = p_keepholddate = p_holddt

EXCEPTIONSCLIENT_INVALID = 1DESTINATION_INVALID = 2GROUP_INVALID = 3GROUP_IS_LOCKED = 4HOLDDATE_INVALID = 5INTERNAL_ERROR = 6QUEUE_ERROR = 7RUNNING = 8SYSTEM_LOCK_ERROR = 9USER_INVALID = 10.

case sy-subrc.when 0.chk_continue = C_X.concatenate 'BDC session Opened ->'(020) p_group

into i_msgs-line separated by space.append i_msgs.when others.perform write_failure using 'Error! opening BDC Session'(021)

p_group.chk_continue = SPACE.concatenate 'BDC session open error ->'(022) p_group

into i_msgs-line separated by space.append i_msgs.

endcase.endform.

*-----------------------------------------------------------------------

* FORM GET_DATA **-----------------------------------------------------------------------* Validate data from file. if any error exist in record, this one will* go to an error log.*-----------------------------------------------------------------------form get_data.data: int(10),

decimal(2),lenght type i,match type c.

loop at t_file.count = count + 1.clear anla.

TRANSLATE t_file-vin TO UPPER CASE.* Get only one record

select anln1 sernr up to 1 rows from anla into anlawhere bukrs = p_bukrs andinvnr = t_file-vin.

endselect.case sy-subrc.

when 0.perform store_error_record USING 'VIN #'(023) t_file-vin

Page 9: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 9/25

TEXT-T01 space C_R.when others.

* Check VIN lengh.lenght = strlen( t_file-vin ).if lenght <> 17.perform store_error_record USING 'VIN #'(023) t_file-vin

'is not 17 alphanumeric'(024) space C_R.continue.

endif.* Check Cost Center

IF t_file-ccenter CO C_NUMBERS.unpack t_file-ccenter to t_file-ccenter.

ENDIF.clear: kostl, BKZKP.select kostl BKZKP up to 1 rows into (kostl,BKZKP) from cskswhere kostl = t_file-ccenter.endselect.IF SY-SUBRC <> 0.perform store_error_record USING 'Cost Center'(025)

t_file-ccenter 'not valid'(006) space C_E.continue.

elseif BKZKP = c_X.perform store_error_record USING 'Cost Center'(025)

t_file-ccenter 'blocked for posting'(056) space C_E.

continue.ENDIF.t_data-kostl = t_file-ccenter.

* Check Plantclear werks.select single werks into werks from t001wwhere werks = t_file-plant.IF SY-SUBRC <> 0.perform store_error_record USING 'Plant'(026) t_file-plant

'not valid'(006) space C_E.continue.

endif.t_data-werks = t_file-plant.

* Check Locationclear stort.select single stand into stort from t499swhere werks = t_data-werks and

stand = p_stort.IF SY-SUBRC <> 0.perform store_error_record USING 'Location'(027) p_stort

'does not exist in plant'(028) t_data-werks C_E.continue.

endif.

t_data-txt50 = t_file-desc.* COST

IF t_file-cost CO C_NUMBERS.unpack t_file-cost to t_file-cost.

ENDIF.int = t_file-cost(10).decimal = t_file-cost+10(2).concatenate int decimal into t_data-anbtr separated by C_DOT.

* FORMAT DATEclear tmp_date.if t_file-date is initial.

Page 10: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 10/25

tmp_date = sy-datum.else.

move t_file-date to tmp_date.endif.write tmp_date to t_data-BZDAT dd/mm/yyyy. " Asset Date

write p_budat to t_data-budat dd/mm/yyyy.

* check if dates in the same fiscal year - TMP_DATE contains asset date* at this moment

perform check_dates using tmp_date p_budatchanging match.

if match = C_N.perform store_error_record USING 'Asset val date'(057)

'& posting date are not in same FY'(058)space space C_R.

continue.endif.

clear tmp_date.tmp_date = P_BLDAT.write tmp_date to t_data-bldat dd/mm/yyyy.

* take out the marks '"' from the person name filed.do.search t_file-person for '"'.if sy-subrc <> 0.

exit.else.

replace '"' with space into t_file-person.endif.

enddo.* Format short text - SGTXT

if t_file-model_year co c_numbers.unpack t_file-model_year to t_file-model_year.

endif.

concatenate t_file-vin text-t00t_file-model_year+1(1) text-t00t_file-veh_type text-t00t_file-color text-t00t_file-personinto t_data-sgtxt.

search t_file-person for ','.if sy-subrc = 0.CONDENSE t_data-sgtxt no-gaps.endif.concatenate t_file-model_num t_file-sernr into t_data-xblnr.t_data-zuonr = t_file-vin.

t_data-sernr = t_data-xblnr. "model code + serial #t_data-kfzkz = t_file-model_num.if t_file-lease_flag = C_L.t_data-gdlgrp = space.

elseif t_file-lease_flag = C_C.t_data-gdlgrp = C_11.

endif.t_data-zzord46 = t_file-country.t_data-zzord47 = t_file-STATE.t_data-zzord48 = t_file-county.

Page 11: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 11/25

t_data-zzord49 = t_file-city.t_data-typbz = t_file-veh_type.

if p_test = C_X.perform store_error_record USING 'CORRECT'(029) '' '' '' C_S.count_good = count_good + 1.

else.perform build_session.

endif.clear t_data.

endcase.endloop.

if p_source = C_X and p_test = space.delete dataset: p_file1.

endif.endform.

*-----------------------------------------------------------------------* FORM BUILD_SESSION **-----------------------------------------------------------------------* Build the BDC when the update mode has been chosen, BDC will contain* only the records evaluated as good after the validation*-----------------------------------------------------------------------

form build_session.set parameter id 'BUK' field p_bukrs.PERFORM FILL_BDC_STRUCTURE.call transaction t_code USING BDCDATA mode 'N' UPDATE 'S'.if sy-subrc = 0.

commit work.count_good = count_good + 1.perform store_error_record USING 'CORRECT'(029) '' '' '' C_S.

else.move t_file to t_error.t_error-type = 'E'.t_error-msg = 'Call transaction failed'(037).append t_error.

count_bad = count_bad + 1.endif.refresh bdcdata.

endform.

*-----------------------------------------------------------------------* PERFORM CLOSE_GROUP **-----------------------------------------------------------------------* Close BDC session & submit it (the one that contains correct records)*-----------------------------------------------------------------------form close_group.call function 'BDC_CLOSE_GROUP'

EXCEPTIONS

NOT_OPEN = 1QUEUE_ERROR = 2.

case sy-subrc.when 0.when others.perform write_failure using 'Error! closing Session: '(031)

p_group.endcase.

Page 12: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 12/25

endform.

*-----------------------------------------------------------------------* PERFORM BDC_TRANSACTION **-----------------------------------------------------------------------* insert the BDC data structure to the batch input session.*-----------------------------------------------------------------------form bdc_transaction using VALUE(t_code).DATA TCODE LIKE TSTC-TCODE.TCODE = T_CODE.call function 'BDC_INSERT'

EXPORTINGtcode = tcode

TABLESdynprotab = bdcdata.

* Since no exceptions are being evaluated, sy-subrc does not need to be* checked.endform.

*-----------------------------------------------------------------------* PERFORM BDC_DYNPRO **-----------------------------------------------------------------------form bdc_dynpro using program dynpro.clear bdcdata.

bdcdata-program = program.bdcdata-dynpro = dynpro.bdcdata-dynbegin = C_X.append bdcdata.

endform.

*-----------------------------------------------------------------------* PERFORM BDC_FIELD **-----------------------------------------------------------------------form bdc_field using fnam fval.clear bdcdata.bdcdata-fnam = fnam.bdcdata-fval = fval.

append bdcdata.endform.

*-----------------------------------------------------------------------* PERFORM WRITE_SUCCESS **-----------------------------------------------------------------------* write a success message*-----------------------------------------------------------------------form write_success using message1 message2 message3.write:/ message1, message2, message3.skip.

endform.

*-----------------------------------------------------------------------* PERFORM WRITE_FAILURE **-----------------------------------------------------------------------* write an error message*-----------------------------------------------------------------------form write_failure using message1 message2.write:/ message1, message2.skip.

endform.

Page 13: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 13/25

*-----------------------------------------------------------------------* PERFORM WRITE_SUMMARY **-----------------------------------------------------------------------* Control report and download error file.*-----------------------------------------------------------------------form write_summary.write:/ 'No. of records uploaded from file: '(032), count.skip.write:/ 'No. of records processed (new assets): '(033), count_good.SKIP.write:/ 'No. of recs Submitted to ERROR Session:'(055), count_bad.skip.write:/ 'No. of recs Rejected: '(036), count_rej.skip.

if p_test = space.if count_bad > 0.ULINE AT 20(64).FORMAT color col_heading intensified off.write: /20 SY-VLINE,

'BDC'(035), p_group,'has been created. It contains error records'(030),SY-VLINE,

/ SPACE.

FORMAT COLOR OFF INTENSIFIED ON.ULINE AT 20(64).endif.

elseif p_test = 'X'.ULINE AT 20(68).FORMAT color col_heading intensified off.write: /20 SY-VLINE,

'BDC'(035), p_group, 'and Assets'(019),'were NOT created. This is a test run'(018),SY-VLINE,/ SPACE.

FORMAT COLOR OFF INTENSIFIED ON.ULINE AT 20(68).

endif.format color off intensified on.* DISPLAY REJECTED RECORDS AND SEND ERROR RECORDS TO ERROR BDCperform display_error_records.

* MESSAGES TO BE MAILEDif p_test = space.

if count_bad > 0.concatenate 'BDC'(035) p_group

'has been created. It contains error records'(030)into i_msgs-line separated by SPACE.

append i_msgs.clear i_msgs.

append i_msgs.endif.

else.concatenate 'BDC'(035) p_group 'and Assets'(019)

'were NOT created. This is a test run'(018)into i_msgs-line separated by SPACE.

append i_msgs.clear i_msgs.append i_msgs.

endif.

Page 14: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 14/25

i_msgs-line = count.condense i_msgs-line.concatenate 'No. of records uploaded from file: '(032) i_msgs-line

into i_msgs-line separated by space.append i_msgs.i_msgs-line = count_good.condense i_msgs-line.concatenate 'No. of records processed (new assets): '(033)

i_msgs-line into i_msgs-line separated by space.append i_msgs.i_msgs-line = count_bad.condense i_msgs-line.concatenate 'No. of recs Submitted to ERROR Session:'(055) i_msgs-line

into i_msgs-line separated by space.append i_msgs.

i_msgs-line = count_rej.condense i_msgs-line.concatenate 'No. of recs Rejected: '(036)

i_msgs-line into i_msgs-line separated by space.append i_msgs.

if chk_message = 'A'.write:/ sy-repid, 'has concluded with errors.'(039).

skip.concatenate sy-repid 'has concluded with errors.'(039)into i_msgs-line separated by space.

append i_msgs.endif.

skip.ULINE.

* DOWONLOAD ERROR LOG TO A FILE (EITHER IN PC OR UNIX)if count_bad <> 0.

if p_source = space.perform download_error.

else.

perform write_error_file.endif.endif.

endform.

*-----------------------------------------------------------------------* PERFORM DOWNLOAD_ERROR **-----------------------------------------------------------------------* Download file to PC*-----------------------------------------------------------------------form download_error.

PERFORM add_sysid_to_file_name USING p_file2.

call function 'WS_DOWNLOAD'EXPORTING

filename = p_file2filetype = p_fdata

TABLESdata_tab = t_error

EXCEPTIONSfile_open_error = 1

Page 15: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 15/25

file_write_error = 2invalid_filesize = 3invalid_type = 4no_batch = 5unknown_error = 6invalid_table_width = 7gui_refuse_filetransfer = 8customer_error = 9others = 10.

case sy-subrc.when 0.perform write_success using 'Error file'(040)

p_file2(50)'Written Successfully'(041).

when others.perform write_failure using 'Error Writing the Error file'(042)

p_file2(50).endcase.

endform.*&---------------------------------------------------------------------**& Form read_data*&---------------------------------------------------------------------** Routine to read input data file

*----------------------------------------------------------------------*form read_data.

PERFORM add_sysid_to_file_name USING p_file1.PERFORM add_sysid_to_file_name USING p_file2.

call function 'Z_GET_FILES'EXPORTING

file_prefix = p_file1IMPORTING

first_file = p_file1EXCEPTIONS

not_found = 1invalid_length = 2.* Validation to SY-SUBRC is not necessary here, even if it returns a* value different to 0, the file name won't be changed.

concatenate 'Input file ->'(043) p_file1 into i_msgs-lineseparated by space.

append i_msgs.concatenate 'Error file ->'(044) p_file2 into i_msgs-line

separated by space.append i_msgs.

* open inbound text file

open dataset p_file1 for input in text mode.if sy-subrc ne 0.

write: / 'Cannot open inbound data file ->'(045), 35 p_file1.concatenate 'Cannot open inbound data file ->'(045) p_file1

into i_msgs-line separated by space.append i_msgs.perform set_mail.perform send_mail.stop.

endif.

Page 16: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 16/25

do.read dataset p_file1 into in_rec.if sy-subrc ne 0.exit.

endif.total_recs = total_recs + 1.

* check headerIF in_rec(3) = header_id.MOVE in_rec TO std_header.CONTINUE.

ENDIF.

* check trailerIF in_rec(4) = trailer_id.MOVE in_rec TO std_trailer.CONTINUE.

ENDIF.

MOVE in_rec TO t_file.APPEND t_file.

enddo.

close dataset p_file1.

IF std_trailer-num_recs NE total_recs.CONCATENATE 'File trailer record count'(053) std_trailer-num_recs

'does not match total records'(054) total_recsINTO i_msgs.

APPEND i_msgs.perform set_mail.perform send_mail.MESSAGE e000 WITH 'File trailer record count'(053)

std_trailer-num_recs'does not match total records'(054)

total_recs.ENDIF.

describe table t_file lines sy-tfill.if sy-tfill eq 0.

write: p_file1, 055 'File is empty.'(052).concatenate p_file1 'File is empty.'(052)

into i_msgs-line separated by space.append i_msgs.perform set_mail.perform send_mail.stop.

endif.

chk_continue = 'X'.

endform. " read_data*&---------------------------------------------------------------------**& Form write_error_file*&---------------------------------------------------------------------** Routine to write error file*----------------------------------------------------------------------*form write_error_file.

Page 17: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 17/25

* open outbound error fileopen dataset p_file2 for output in text mode.if sy-subrc ne 0.

write: / 'Cannot open outbound error file ->'(046), 35 p_file2.concatenate 'Cannot open outbound error file ->'(046) p_file2

into i_msgs-line separated by space.append i_msgs.perform set_mail.perform send_mail.stop.

endif.

TRANSFER STD_HEADER TO P_FILE2.loop at t_error.

transfer t_error to p_file2.endloop.TRANSFER STD_TRAILER TO P_FILE2.close dataset p_file2.

endform. " write_error_file*&---------------------------------------------------------------------**& Form lock_program*&---------------------------------------------------------------------*

* Standard lock function call*----------------------------------------------------------------------*FORM lock_program.call function 'Z_LOCK_PROGRAM'

EXCEPTIONSforeign_lock = 1system_failure = 2others = 3.

if sy-subrc <> 0.message e000 with 'Another copy of the program'(048) sy-repid

'is currently running'(049) space.concatenate 'Another copy of the program'(048) sy-repid

'is currently running'(049) into i_msgs-lineseparated by space.append i_msgs.chk_message = C_A.perform write_summary.

endif.ENDFORM. " lock_program*&---------------------------------------------------------------------**& Form store_error_record*&---------------------------------------------------------------------** Save record in error log*----------------------------------------------------------------------*FORM store_error_record USING VALUE(MSG) VALUE(MSG1)

VALUE(MSG2) value(msg3) value(type).T_ERROR = T_FILE.concatenate msg msg1 msg2 msg3 into T_ERROR-MSG separated by space.

t_error-type = type.if t_error-type = C_E.

count_bad = count_bad + 1.elseif t_error-type = C_R.

count_rej = count_rej + 1.endif.

Page 18: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 18/25

append t_error.clear t_error.

ENDFORM. " store_error_record*&---------------------------------------------------------------------**& Form display_error_records*&---------------------------------------------------------------------** Display detail of either what was correctly processed or not.* Build ERROR BDC*----------------------------------------------------------------------*FORM display_error_records.skip.WRITE:/ TEXT-999.CLEAR chk_continue.IF P_TEST = SPACE.IF COUNT_BAD > 0.

* OPEN ERROR SESSIONREAD TABLE T_ERROR WITH KEY TYPE = C_E.IF SY-SUBRC = 0.perform open_group.ENDIF.

ENDIF.endif.

write:/ ICON_INCOMPLETE as icon, 'REJECTED RECORDS',

ICON_CHECKED as icon, 'CORRECT RECORDS',ICON_FAILURE as icon, 'RECS SENT TO BDC'.WRITE:/ TEXT-999.skip.

* move header columns to filemove text-d01 to i_msg_Det.move text-d02 to i_msg_Det+118(66).append i_msg_det.clear i_msg_det.

loop at t_error.IF T_ERROR-TYPE = C_R. "REJECTEDwrite / ICON_INCOMPLETE as icon.

ELSEIF T_ERROR-TYPE = 'E'. "ERROR sent to BDCWRITE / ICON_FAILURE as icon.if p_test = space.

perform format_error_data.PERFORM FILL_BDC_STRUCTURE.perform bdc_transaction using T_CODE.refresh bdcdata.

endif.ELSE.WRITE / ICON_CHECKED as icon.

ENDIF.write: t_error-ccode, " Company Owner Group ID

t_error-plant, " Plant

t_error-city, " Cityt_error-county, " Countyt_error-state, " Statet_error-country, " Countryt_error-vin, " VIN numbert_error-model_num, " Model Codet_error-sernr, " Serial numbert_error-desc, " Asset Descriptiont_error-cost, " Costt_error-date, " Document Date (DD/MM/YYYY)

Page 19: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 19/25

t_error-model_year, " Model Yeart_error-veh_type, " Vehicle Typet_error-lease_flag, " Lease Company Flagt_error-color, " Vehicle Colort_error-person, " Person Departmentt_error-CCENTER, " Cost Centert_error-process_Date, " Process Datet_error-msg. " Message

clear t_error-type. "don't pass the error type to the filemove t_error to i_msg_det.append i_msg_det.clear i_msg_det.

endloop.FORMAT COLOR OFF.IF chk_continue = C_X.

perform close_group.ENDIF.

ENDFORM. " display_error_records*&---------------------------------------------------------------------**& Form FILL_BDC_STRUCTURE*&---------------------------------------------------------------------** Fill BDC structure (BDCDATA) to be inserted to BCC*----------------------------------------------------------------------*FORM FILL_BDC_STRUCTURE.

*------------------------------------------------------perform bdc_dynpro using 'SAPLAMDP' '0100'.perform bdc_field using 'BDC_OKCODE'

'=NEWA'.perform bdc_field using 'RAIFP3-XBANL'

' '.perform bdc_field using 'RAIFP3-XNANL'

'X'.perform bdc_field using 'RAIFP1-BUDAT'

t_data-budat.*------------------------------------------------------perform bdc_dynpro using 'SAPLAMDP' '0100'.perform bdc_field using 'BDC_OKCODE'

'=TAB02'.perform bdc_field using 'RAIFP3-XNANL''X'.

perform bdc_field using 'RAIFP4-TXT50't_data-txt50.

perform bdc_field using 'RAIFP4-ANLKL'P_anlkl.

perform bdc_field using 'RAIFP4-KOSTL't_data-kostl.

perform bdc_field using 'RAIFP2-ANBTR't_data-anbtr.

perform bdc_field using 'RAIFP2-MENGE'P_menge.

perform bdc_field using 'RAIFP2-MEINS'P_meins.

perform bdc_field using 'RAIFP1-BLDAT't_data-bldat.

perform bdc_field using 'RAIFP1-BUDAT't_data-budat.

perform bdc_field using 'RAIFP1-BZDAT't_data-bZdat.

perform bdc_field using 'RAIFP2-SGTXT'

Page 20: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 20/25

t_data-sgtxt.*---------------------------------------------------perform bdc_dynpro using 'SAPLAMDP' '0100'.perform bdc_field using 'BDC_OKCODE'

'=MAST'.perform bdc_field using 'RAIFP3-XNANL'

'X'.perform bdc_field using 'RAIFP4-TXT50'

t_data-txt50.perform bdc_field using 'RAIFP4-ANLKL'

P_anlkl.perform bdc_field using 'RAIFP4-KOSTL'

t_data-kostl.perform bdc_field using 'RAIFP1-BLART'

P_blart.perform bdc_field using 'RAIFP2-GKONT'

P_gkont.perform bdc_field using 'RAIFP1-BWASL'

P_bwasl.perform bdc_field using 'RAIFP1-XBLNR'

t_data-xblnr.perform bdc_field using 'RAIFP2-ZUONR'

t_data-ZUONR.*------------------------------------------------------

perform bdc_dynpro using 'SAPLAIST' '2110'.perform bdc_field using 'BDC_OKCODE''=DETA'.

perform bdc_field using 'ANLA-ANLKL'P_ANLKL.

perform bdc_field using 'RAIST05-XVLNIX''X'.

perform bdc_field using 'ANLA-TXT50't_data-txt50.

*Begin of modification | DV5K951285perform bdc_field using 'ANLA-TXA50'

t_file-person.*End of modification | DV5K951285

perform bdc_field using 'ANLA-INVNR't_data-zuonr.

perform bdc_field using 'ANLZ-KOSTL't_data-kostl.

perform bdc_field using 'ANLZ-WERKS't_data-werks.

perform bdc_field using 'ANLZ-STORT'P_stort.

*------------------------------------------------------perform bdc_dynpro using 'SAPLAIST' '1000'.perform bdc_field using 'BDC_OKCODE'

'=TAB02'.

perform bdc_field using 'ANLA-TXT50't_data-txt50.

perform bdc_field using 'ANLA-SERNR't_data-sernr.

perform bdc_field using 'ANLA-INVNR't_data-zuonr.

perform bdc_field using 'ANLA-MEINS'P_meins.

perform bdc_field using 'RA02S-XHIST''X'.

Page 21: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 21/25

perform bdc_field using 'ANLA-INKEN''X'.

*------------------------------------------------------perform bdc_dynpro using 'SAPLAIST' '1000'.perform bdc_field using 'BDC_OKCODE'

'=TAB03'.PERFORM bdc_field USING 'ANLZ-KOSTL'

T_DATA-KOSTL.PERFORM bdc_field USING 'ANLZ-WERKS' T_DATA-WERKS.PERFORM bdc_field USING 'ANLZ-STORT' P_STORT.PERFORM bdc_field USING 'ANLZ-KFZKZ' T_DATA-KFZKZ.

*------------------------------------------------------perform bdc_dynpro using 'SAPLAIST' '1000'.perform bdc_field using 'BDC_OKCODE'

'=TAB04'.PERFORM bdc_field USING 'ANLA-ORD44'

P_ORD44.PERFORM bdc_field USING 'ANLA-GDLGRP'

T_DATA-gdlgrp.

PERFORM bdc_field USING 'ANLA-ZZORD46'T_DATA-zzord46.

PERFORM bdc_field USING 'ANLA-ZZORD47'T_DATA-zzord47.

PERFORM bdc_field USING 'ANLA-ZZORD48'T_DATA-zzord48.PERFORM bdc_field USING 'ANLA-ZZORD49'

T_DATA-zzord49.*------------------------------------------------------perform bdc_dynpro using 'SAPLAIST' '1000'.perform bdc_field using 'BDC_OKCODE'

'=TAB05'.perform bdc_field using 'RA02S-XNEU_AM'

'X'.perform bdc_field using 'ANLA-TYPBZ'

T_DATA-typbz.*------------------------------------------------------

perform bdc_dynpro using 'SAPLAIST' '1000'.perform bdc_field using 'BDC_OKCODE''=RW'.

perform bdc_field using 'ANLA-EIGKZ'P_EIGKZ.

*------------------------------------------------------perform bdc_dynpro using 'SAPLAIST' '2110'.perform bdc_field using 'BDC_OKCODE'

'=CREA'.

perform bdc_dynpro using 'SAPLAMDP' '0100'.perform bdc_field using 'BDC_OKCODE'

'=SAVE'.

perform bdc_field using 'RAIFP3-XNANL''X'.

ENDFORM. " FILL_BDC_STRUCTURE*&---------------------------------------------------------------------**& Form format_error_data*&---------------------------------------------------------------------** Format error data to be sent to BDC.*----------------------------------------------------------------------*FORM format_error_data.data: int(10),

Page 22: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 22/25

decimal(2).* count = count + 1.* Check Cost Center

IF t_error-ccenter CO C_NUMBERS.unpack t_error-ccenter to t_error-ccenter.

ENDIF.t_data-kostl = t_error-ccenter.

* Check Plantt_data-werks = t_error-plant.

* Check Locationt_data-txt50 = t_error-desc.

* COSTIF t_error-cost CO C_NUMBERS.unpack t_ERROR-cost to t_error-cost.

ENDIF.int = t_error-cost(10).decimal = t_error-cost+10(2).concatenate int decimal into t_data-anbtr separated by C_DOT.

* FORMAT DATEclear tmp_date.if t_error-date is initial.tmp_date = sy-datum.

else.

move t_error-date to tmp_date.endif.write tmp_date to t_data-BZDAT dd/mm/yyyy.

clear tmp_date.tmp_date = P_BLDAT.

write tmp_date to t_data-bldat dd/mm/yyyy.

clear tmp_date.write p_budat to t_data-budat dd/mm/yyyy.

* enter the name without mark '"'do.

search t_error-person for '"'.if sy-subrc <> 0.exit.

else.replace '"' with space into t_error-person.

endif.enddo.

* Format short text - SGTXTif t_error-model_year co c_numbers.unpack t_error-model_year to t_error-model_year.

endif.concatenate t_error-vin text-t00

t_error-model_year+1(1) text-t00t_error-veh_type text-t00t_error-color text-t00t_error-personinto t_data-sgtxt.

CONDENSE t_data-sgtxt no-gaps.

concatenate t_error-model_num t_error-sernr into t_data-xblnr.t_data-zuonr = t_error-vin.t_data-sernr = t_data-xblnr. "model code + serial #

Page 23: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 23/25

t_data-kfzkz = t_error-model_num.if t_error-lease_flag = C_L.t_data-gdlgrp = space.

elseif t_ERROR-lease_flag = C_C.t_data-gdlgrp = C_11.

endif.

t_data-zzord46 = t_error-country.t_data-zzord47 = t_error-STATE.t_data-zzord48 = t_error-county.t_data-zzord49 = t_error-city.t_data-typbz = t_error-veh_type.

ENDFORM. " format_error_data

*&---------------------------------------------------------------------**& Form send_mail*&---------------------------------------------------------------------** This form Send the e-mail to the users*----------------------------------------------------------------------*FORM send_mail.write SY-DATUM TO tmp_date mmddyy. " Run date

* E-MAIL SUBJECT LINECLEAR doc_chng.

CONCATENATE sy-cprog '(' sy-sysid(03) ')' 'Additions_'(038) tmp_dateINTO doc_chng-obj_descr SEPARATED BY ' '.

* ATTACHMENT attributesCLEAR objpack.

concatenate 'Additions_'(038) tmp_date '.TXT'(050)into objpack-obj_descr.

msgs_lin = msgs_lin + 1.objpack-body_start = msgs_lin.

****append lines of i_msg_Det to i_msgs.

describe table i_msgs lines msgs_lin.***objpack-body_num = msgs_lin. " for ? linesobjpack-doc_type = c_raw. " TXT FILE

READ TABLE i_msgs INDEX msgs_lin. " read the last partial line

objpack-doc_size = ( msgs_lin - 1 ) * 255 + STRLEN( i_msgs ).APPEND objpack.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'EXPORTING

document_data = doc_chng

put_in_outbox = c_xTABLES

packing_list = objpackcontents_txt = i_msgsreceivers = reclist

EXCEPTIONStoo_many_receivers = 1document_not_sent = 2document_type_not_exist = 3operation_no_authorization = 4

Page 24: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 24/25

parameter_error = 5x_error = 6enqueue_error = 7OTHERS = 8.

IF sy-subrc EQ 0. " if successful* The Log should display the SAP ID

MESSAGE i000 WITH 'E-mail attaching Additions sent to Users'(034).ELSE. " error

* * The Log should display the SAP IDMESSAGE i000 WITH 'Error in sending e-mail to Users'(059)

'RC ='(060) sy-subrc.ENDIF.

ENDFORM. " send_mail

*&---------------------------------------------------------------------**& Form set_mail*&---------------------------------------------------------------------** Assign the corresponding e-mail address depending of the SAP user,*----------------------------------------------------------------------*FORM set_mail.* E-MAIL BODY** attributes

REFRESH objpack.CLEAR objpack.objpack-body_start = 1.describe table i_msgs lines msgs_lin.objpack-body_num = msgs_lin. "objpack-doc_type = c_raw.APPEND objpack.

* RECEIVERREFRESH reclist.CLEAR reclist.loop at s_erec.

reclist-receiver = s_erec-low.

* The mail will be sent to the Internet addresses specified in the inputreclist-rec_type = 'U'.reclist-express = c_x.APPEND reclist.

endloop.ENDFORM. " set_mail*&---------------------------------------------------------------------**& Form check_dates*&---------------------------------------------------------------------** Check if Asset date and Posting date are in the same fiscal year*----------------------------------------------------------------------*FORM check_dates USING asset_date like sy-datum

post_date like sy-datum

CHANGING P_MATCH.data: asset_fy like T009B-BDATJ,

post_fy like T009B-BDATJ,period like T009B-POPER.

CLEAR: ASSET_FY, POST_FY, PERIOD.*ASSET DATECALL FUNCTION 'DATE_TO_PERIOD_CONVERT'

EXPORTINGI_DATE = asset_date

Page 25: Zai00003 Ganesh

7/29/2019 Zai00003 Ganesh

http://slidepdf.com/reader/full/zai00003-ganesh 25/25

I_PERIV = C_PERIV "V3IMPORTING

E_BUPER = periodE_GJAHR = asset_fy.

*no sy-subrc evaluation needed* POSTING DATECALL FUNCTION 'DATE_TO_PERIOD_CONVERT'

EXPORTINGI_DATE = post_dateI_PERIV = C_PERIV "V3

IMPORTINGE_BUPER = periodE_GJAHR = post_fy.

*no sy-subrc evaluation neededIF asset_fy ne post_fy.

p_match = C_N.ELSE.

p_match = C_S.ENDIF.

ENDFORM. " check_dates