You are on page 1of 11

report zac00002 no standard page heading

line-size 80
message-id za.
************************************************************************
* Program : ZAI00002
Creation Dt: 12/15/01
* Title : Conversion Program for VAS to FA Lease
*
Transaction (Vehicle Auction)
*
* Author : Shaurya Agrawal (CGEY)
* Lead
: Derrica Dunn-Moody (Nissan)
*
Tammy Johnson (CGEY)
*
Donna Young (IBM)
* Type
: AA CONVERSION
Script Id : IT076
************************************************************************
* Description : This conversion program will transfer Lease and company
*
vehicles to be retired for the current month from VAS *
*
system to SAP AA system using BDC "Call Session Method"
*
*
************************************************************************
* Global Values : None
************************************************************************
* Input : File of data
* Output: List of errors and statistics
************************************************************************
* Modification History:
*
* YYYY/MM/DD
Author
* Correction# Description
* ----------- -------------------------------------------------------* 2002/05/02
Changed the logic to now retire the asset based on the
* DVCK908901
inventory number as opposed to the serial number
*
* 2002/05/20 Populate the reference field on the document header
* DVCK909342 Author: Luz Dinorah Barboza - IBM Technical support
*
Defect # 904
*
************************************************************************
*TABLES
tables: anla.
* INCLUDE PROGRAMS
*Include for standard header & trailer records
include zzifile3.
*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.
selection-screen end of line.

parameters: p_file1 like rlgrap-filename


obligatory
default 'C:\TEMP\TEST.TXT'.
parameters: p_file2 like rlgrap-filename
obligatory
default 'C:\TEMP\ERROR.TXT',
p_client like sy-mandt default sy-mandt,
p_group(12) obligatory,
p_user like sy-uname obligatory,
p_keep as checkbox default 'X',
p_hdate like sy-datum,
p_mailid like zb01-mailid default sy-repid. "mail id
selection-screen end of block blk1.
selection-screen begin of block blk2 with frame title text-002.
parameters: p_bukrs like anla-bukrs default '2177'.
selection-screen end of block blk2.
*INTERNAL TABLES
data: begin of t_file occurs 0,
invnr(10),
erlbt(9),
month(2),
year(4),
filler(50),
end of t_file.

" Serial Number


" Manual Value
" Month
" Year

data: begin of t_error occurs 0,


invnr(18),
erlbt(9),
month(2),
year(4),
filler(50),
end of t_error.

" Serial Number


" Manual Value
" Month
" Year

data: begin of i_msgs occurs 0.


include structure soli.
data: end of i_msgs.
data: begin of bdcdata occurs 0.
include structure bdcdata.
data: end of bdcdata.
data: begin of t_data occurs 0,
anln1 like raifp2-anln1,
bldat(10),
budat(10),
bzdat(10),
xmaer like raifp2-xmaer,
erlbt(13),
xblnr like raifp1-xblnr,
end of t_data.
data: begin of t_anla,
anln1 like anla-anln1,
invnr like anla-invnr,
end of t_anla.

"for email

" BDC Data Structure

"
"
"
"
"
"
"
"

Asset ID
Document Date
Posting Date
Asset Value Date
Manual Value (Radiobutton)
Manual value
Reference document number
Defect # 904

*DATA DECLARATION
data: count type i,
chk_continue,
chk_message,
d_len type i,
d_invnr(18),
d_date(10),
count_good type i,
count_bad type i,
header_id(4) type c value 'HDR ', "File Header Record Identifier
trailer_id(4) type c value 'TRLR'. "File Trailer Record Identifier
*INITIALIZATION.
refresh t_data.
refresh t_error.
refresh bdcdata.
* Includes used for report header and replaces fields with sy fields
include zziheadr.
*AT-SELECTION-SCREEN
at selection-screen on value-request for p_file1.
if p_source = space.
perform open_file using p_file1.
endif.
at selection-screen on value-request for p_file2.
if p_source = space.
perform open_file using p_file2.
endif.
at selection-screen.
if p_source <> space.
concatenate '/nmcfs1/' sy-sysid sy-mandt
'/in/zai00002.it076.err.' sy-datum '.' sy-uzeit into p_file2.
translate p_file2 to lower case.

*
*

call function 'Z_GET_FILES'


exporting
file_prefix
= p_file1
importing
first_file
= p_file1
TABLES
TAB_FILES
=
exceptions
not_found
= 1
invalid_length
= 2
others
= 3.
concatenate 'Input file ->' p_file1 into
separated by
append i_msgs.
concatenate 'Error file ->' p_file2 into
separated by
append i_msgs.
endif.

i_msgs-line
space.
i_msgs-line
space.

*START-OF-SELECTION.
start-of-selection.
* Standard lock function
call function 'Z_LOCK_PROGRAM'
exceptions
foreign_lock = 1
system_failure = 2
others
= 3.
if sy-subrc <> 0.
message e000 with 'Another copy of the program' sy-repid
'is currently running' space.
chk_message = 'A'.
perform write_summary.
endif.
if p_source = space.
perform get_file.
else.
perform read_data.
endif.
if chk_continue = 'X'.
perform get_data.
if count_good <> 0.
perform open_group.
perform build_session.
perform close_group.
endif.
perform write_summary.
endif.
*************************BEGIN OF FORM ROUTINES*************************
************************************************************************
*
PERFORM OPEN_FILE
*
************************************************************************
form open_file using p_file.
call function 'WS_FILENAME_GET'
exporting
def_filename
= p_file
def_path
= 'c:/temp'
mask
= ',*.*,*.*.'
mode
= 'O'
title
= 'File'
importing
filename
= p_file
exceptions
inv_winsys
= 1
no_batch
= 2
selection_cancel = 3
selection_error = 4
others
= 5.
endform.
************************************************************************

*
PERFORM GET_FILE
*
************************************************************************
form get_file.
call function 'WS_UPLOAD'
exporting
filename
= p_file1
filetype
= 'ASC'
tables
data_tab
= t_file
exceptions
conversion_error
= 1
file_open_error
= 2
file_read_error
= 3
invalid_type
= 4
no_batch
= 5
unknown_error
= 6
invalid_table_width
= 7
gui_refuse_filetransfer = 8
customer_error
= 9
others
= 10.
case sy-subrc.
when 0.
perform write_success using 'File '
p_file1
'Read Successfully'.
chk_continue = 'X'.
when others.
perform write_failure using 'Error Reading the file '
p_file1.
chk_continue = ' '.
endcase.
endform.
************************************************************************
*
PERFORM OPEN_GROUP
*
************************************************************************
form open_group.
call function 'BDC_OPEN_GROUP'
exporting
client = sy-mandt
group
= p_group
user
= p_user
keep
= p_keep
holddate = p_hdate.
case sy-subrc.
when 0.
perform write_success using 'BDC Session '
p_group
'Opened successfully'.
chk_continue = 'X'.
when others.
perform write_failure using 'Error! opening BDC Session '
p_group.
chk_continue = ' '.
endcase.
endform.
************************************************************************

*
FORM GET_DATA
*
************************************************************************
form get_data.
loop at t_file.
if t_file(4) = header_id. "MOVES HEADER RECORD TO THE ERROR FILE
move sy-datum to t_file+12(8).
move sy-uzeit to t_file+20(6).
move t_file to t_error.
append t_error.
clear t_error.
continue.
endif.
if t_file(4) = trailer_id.
move count_bad to t_file+26(8).
move sy-datum to t_file+12(8).
move sy-uzeit to t_file+20(6).
move t_file to t_error.
append t_error.
clear t_error.
continue.
endif.
count = count + 1.
move t_file-invnr to d_invnr.
select single anln1 invnr from anla into t_anla
where bukrs = p_bukrs and
invnr = d_invnr.
case sy-subrc.
when 0.
t_data-anln1 =
write sy-datum
t_data-bldat =
t_data-budat =
t_data-bzdat =
t_data-xmaer =
t_data-erlbt =
t_data-xblnr =

t_anla-anln1.
to d_date dd/mm/yyyy.
d_date.
d_date.
d_date.
'X'.
t_file-erlbt.
d_invnr. " Reference doc.# "Defect # 904

count_good = count_good + 1.
append t_data.
clear t_data.
when others.
t_error-invnr = d_invnr.
t_error-erlbt = t_file-erlbt.
t_error-month = t_file-month.
t_error-year = t_file-year.
count_bad = count_bad + 1.
append t_error.
clear t_error.
endcase.
endloop.
endform.

************************************************************************
*
FORM BUILD_SESSION
*
************************************************************************
form build_session.
loop at t_data.
*
SET PARAMETER ID 'BUK' FIELD P_BUKRS.
* Begin of Defect # 904
*
perform bdc_dynpro
using 'SAPLAMDP' '0100'.
*
perform bdc_field
using 'BDC_OKCODE'
*
'=SAVE'.
perform bdc_dynpro
using 'SAPLAMDP' '0100'.
perform bdc_field
using 'BDC_OKCODE'
'=TAB02'.
* End of Defect # 904
perform bdc_field
using 'BDC_CURSOR'
'RAIFP2-ANLN1'.
perform bdc_field
using 'RAIFP2-ANLN1'
t_data-anln1.
*
'10000087'.
perform bdc_field
using 'RAIFP2-ANLN2'
'0'.
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-XMAER'
'X'.
perform bdc_field
using 'RAIFP2-ERLBT'
t_data-erlbt.
* Begin of Defect # 904
perform bdc_dynpro
using 'SAPLAMDP' '0100'.
perform bdc_field
using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field

using 'RAIFP1-XBLNR'
t_data-xblnr.

* End of Defect # 904


perform bdc_transaction using 'ABAON'.
refresh bdcdata.
endloop.
endform.
************************************************************************
*
PERFORM CLOSE_GROUP
*
************************************************************************
form close_group.
call function 'BDC_CLOSE_GROUP'.
case sy-subrc.
when 0.
perform write_success using 'BDC Session ' p_group
'Closed successfully'.
if p_source <> space.
submit rsbdcsub and return with mappe = p_group.
if sy-subrc = 0.
concatenate 'BDC session submitted ->' p_group
into i_msgs-line separated by space.

append i_msgs.
delete dataset: p_file1.
else.
concatenate 'BDC session submit error ->' p_group
into i_msgs-line separated by space.
append i_msgs.
endif.
endif.
when others.
perform write_failure using 'Error! closing Session: '
p_group.
endcase.
endform.
************************************************************************
*
PERFORM BDC_TRANSACTION
*
************************************************************************
form bdc_transaction using tcode.
call function 'BDC_INSERT'
exporting
tcode
= tcode
tables
dynprotab = bdcdata.
endform.
************************************************************************
*
PERFORM BDC_DYNPRO
*
************************************************************************
form bdc_dynpro using program dynpro.
clear bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = '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
*
************************************************************************
form write_success using message1 message2 message3.
write:/ message1, message2, message3.
skip.
endform.
************************************************************************
*
PERFORM WRITE_FAILURE
*
************************************************************************
form write_failure using message1 message2.
write:/ message1, message2.
skip.

endform.
************************************************************************
*
PERFORM WRITE_SUMMARY
*
************************************************************************
form write_summary.
write:/ 'Total records uploaded from file:
', count.
skip.
write:/ 'Total records Submitted to Session:
', count_good.
skip.
write:/ 'Total records in Error due to Bad Asset Number:', count_bad.
skip.
if p_source = space.
write:/ 'Process the session using transaction SM35',
' and selecting the option Display Errors only'.
skip.
endif.
if chk_message = 'A'.
write:/ sy-repid, ' has concluded with errors.'.
skip.
endif.
if count_bad <> 0.
if p_source = space.
perform download_error.
else.
perform write_error_file.
endif.
endif.
endform.
************************************************************************
*
PERFORM DOWNLOAD_ERROR
*
************************************************************************
form download_error .
call function 'WS_DOWNLOAD'
exporting
filename
= p_file2
filetype
= 'ASC'
tables
data_tab
= t_error
exceptions
file_open_error
= 1
file_write_error
= 2
invalid_filesize
= 3
invalid_type
= 4
no_batch
= 5
unknown_error
= 6
invalid_table_width
= 7
gui_refuse_filetransfer = 8
customer_error
= 9
others
= 10.
case sy-subrc.
when 0.
perform write_success using 'Error file '
p_file2
'Written Successfully'.
when others.
perform write_failure using 'Error Writing the Error file '

p_file2.
endcase.
endform.
*&---------------------------------------------------------------------*
*&
Form read_data
*&---------------------------------------------------------------------*
*
Form which reads the UNIX file into the internal table
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form read_data.
open dataset p_file1 for input in text mode.
if sy-subrc ne 0.
write: / 'Cannot open inbound data file -> ', 35 p_file1.
concatenate 'Cannot open inbound data file -> ' p_file1
into i_msgs-line separated by space.
append i_msgs.
perform send_email.
stop.
endif.
do.
read dataset p_file1 into t_file.
if sy-subrc ne 0.
exit.
endif.
append t_file.
enddo.
close dataset p_file1.
describe table t_file lines sy-tfill.
if sy-tfill eq 0.
write: p_file1, 055 'File is empty.'.
concatenate p_file1 'File is empty.'
into i_msgs-line separated by space.
append i_msgs.
perform send_email.
stop.
endif.
chk_continue = 'X'.
endform.
" read_data
*&---------------------------------------------------------------------*
*&
Form send_email
*&---------------------------------------------------------------------*
*
Form which email the user an error report
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form send_email.
call function 'Z_SEND_MAIL'
exporting
mailid
= p_mailid
tables
msg_table = i_msgs
exceptions

invalid = 1
not_found = 2
others
= 3.
if sy-subrc <> 0.
write: / 'Was not able to send mail using mail ID -> ', p_mailid.
endif.
endform.
" send_email
*&---------------------------------------------------------------------*
*&
Form write_error_file
*&---------------------------------------------------------------------*
*
Form which outputs a dump to a desktop file
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form write_error_file.
* open outbound error file
open dataset p_file2 for output in text mode.
if sy-subrc ne 0.
write: / 'Cannot open outbound error file -> ', 35 p_file2.
concatenate 'Cannot open outbound error file ->' p_file2
into i_msgs-line separated by space.
append i_msgs.
perform send_email.
stop.
endif.
loop at t_error.
transfer t_error to p_file2.
endloop.
close dataset p_file2.
endform.

" write_error_file