You are on page 1of 70

AlSafi Programs

1: SAP File Validation Process - Program code ZVPROI0110ASF


2: Prepare Delivery creation - Program code ZVPROI0210ASF
3: Maintain Billing Due List - VF04 - program ZVASFI0020
4: Payment Processing - Program ZVPROI0140ASF

1: SAP File Validation Process - Program code ZVPROI0110ASF


report zvposi0110 line-size 132
line-count 65.
*======================================================================*
* AUTHOR
: Matthew Pillay
*
* DATE WRITTEN : June 2001
*
* APPLICATION : SD-POS
*
* FUNCTION
: Validation Program for ASF Interface
* Modified By : Omer Farook for 12 Char Invoice 08/08/06
*
*======================================================================*
********************************************************************
* Change id : KA-001
* Author
: Kumar Ankit
* Date
: 24/05/2012
* CR
: FD9K900007
* Description: AFG Upgrade Syntax Check and Unicode adjustment
* Team
: IDC-UPGRADE
********************************************************************
************************************************************************
* Change ID : LS-001
* Author
: Laura Sorgiacomo
* Date
: 2012-07-09
* CR
: FD9K900048
* Description: UPG-CoE-W: SD_38 - ASD 17/07/2012
* Team
: CoE-UPGRADE
**********************************************************
************************************************************************
* Change ID : N/A
* Author
: Ravishankar.V
* Date
: 2013-02-02
* CR
: FD9K900719
* Description: Changes to length of Invoice number
**********************************************************
*======================================================================*
***************************** TABLES***********************************
*======================================================================*

tables:

zvposi01,
zvposi07,
zvposi08,
zvposi09,
ZVPROI10,
z1insr03,
knvv,
knb1,
t001w,
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
zvposi07_pro,
zvposi08_pro,
zvposi09_pro.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
Data:
temp(255) type c.
*
data: zvposi01_tab
like zvposi01 occurs 0 with header line,
zvposi07_tab
like zvposi07 occurs 0 with header line,
zvposi08_tab
like zvposi08 occurs 0 with header line,
zvposi09_tab
like zvposi09 occurs 0 with header line,
ZVPROI10_tab
like ZVPROI10 occurs 0 with header line,
z1insr03_tab
like z1insr03 occurs 0 with header line,
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
zvposi09_pro_tab
like zvposi09_pro occurs 0 with header line,
zvposi07_pro_tab
like zvposi07_pro occurs 0 with header line,
zvposi08_pro_tab
like zvposi08_pro occurs 0 with header line.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
*
data: begin of in_file_tab occurs 0,
prefix(3)
type c,
branch(4)
type c,
dot(1)
type c,
jdate(5)
type c,
fill(37)
type c,
end of in_file_tab.
*
* added by ssaikhan on 27.07.2002
data: begin of listfile_tab occurs 0,
line(100)
type c,
"data to be written in file
end of listfile_tab.
*
data: begin of file_tab occurs 0,
jdate(5)
type c,
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
*
branch(4)
type c,
branch(6)
type c,
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
filename(13)
type c,
end of file_tab.
*
data: begin of data_tab occurs 0,

rectype(1)
data(255)
end of data_tab.

type c,
type c,

*
data: begin of err_tab occurs 0,
errno(2)
type n,
end
of err_tab.
*
data: begin of sap_tab occurs 0,
fn(25)
type c,
vstel
like likp-vstel,
lifex
like likp-lifex,
lfart
like likp-lfart,
vkorg
like likp-vkorg,
vtweg
like rv50a-vtweg,
spart
like rv50a-spart,
route
like likp-route,
kunnr
like kuwev-kunnr,
wadat(8)
type c,
posnr
like lips-posnr,
matnr
like lips-matnr,
uom(3)
type c,
lfimg(10)
type c,
pstyv
like lips-pstyv,
lgort
like lips-lgort,
kschl
like komv-kschl,
kbetr(11)
type c,
kwert(11)
type c,
per(5)
type c,
linetyp(4)
type c,
end of sap_tab.
*
data: begin of kunnr_tab occurs 0,
kunnr
like knb1-kunnr,
vtweg
like knvv-vtweg,
end
of kunnr_tab.
*
data: begin of header_tab occurs 0,
branch(4)
type c,
***Changes RSV-Start
vbeln(16)
type c,
*
vbeln(12)
type c,
***Changes RSV-End
fkdat(8)
type c,
invtyp(1)
type c,
kunnr(10)
type c,
route(4)
type c,
salnum(10)
type c,
journey(11)
type c,
value(10)
type c,
fn(25)
type c,
end of header_tab.

"filename
"Shipping point = Branch
"Invoice no
"
"Sales org
"Distribution channel
"division
"Route
"Customer
"

"branch code
"invoice no
"invoice no
"Invoice date
"Invoice type
"Customer code
"SAP route code
"Salesman AR code
"Settlement number
"Value
"filename

data: begin of detail_tab occurs 0,


***Changes RSV-Start
*
vbeln(12)
type c,
vbeln(16)
type c,
***Changes RSV-End
linetyp(4)
type c,
item_cd(4)
type c,
qty(10)
type c,
meins(3)
type c,
price(10)
type c,
dis_amt(10)
type c,
reused(1)
type c,
value(10)
type c,
branch(4)
type c,
end of detail_tab.
*
data: begin of temp_header_tab occurs 0,
branch(4)
type c,
***Changes RSV-Start
*
vbeln(12)
type c,
vbeln(16)
type c,
***Changes RSV-End
fkdat(8)
type c,
invtyp(1)
type c,
kunnr(10)
type c,
route(4)
type c,
salnum(10)
type c,
journey(11)
type c,
value(10)
type c,
fn(25)
type c,
end of temp_header_tab.
data: begin of temp_detail_tab occurs 0,
***Changes RSV-Start
*
vbeln(12)
type c,
vbeln(16)
type c,
***Changes RSV-End
linetyp(4)
type c,
item_cd(4)
type c,
qty(10)
type c,
meins(3)
type c,
price(10)
type c,
dis_amt(10)
type c,
reused(1)
type c,
value(10)
type c,
branch(4)
type c,
end of temp_detail_tab.
*
data: begin of result_tab occurs 0,
result(255)
type c,
end
of result_tab.

"Invoice no
"Invoice no
"Item type
"Item code
"Quantity
"UOM
"Price
"Discount amount
"Returns indicator
"Value
"Branch

"branch code
"invoice no
"invoice no
"Invoice date
"Invoice type
"Customer code
"SAP route code
"Salesman AR code
"Settlement number
"Value
"filename

"Invoice no
"Invoice no
"Item type
"Item code
"Quantity
"UOM
"Price
"Discount amount
"Returns indicator
"Value
"Branch

*
data: paymnt_tab like header_tab occurs 0 with header line.
data: zvposi08_str
detail_str
sap_str

like zvposi08,
like detail_tab,
like sap_tab.

* added by Ahmad Al-Sharqi


data : begin of gift_tab
fn(25)
vstel
lifex
lfart
vkorg
vtweg
spart
route
kunnr
wadat(8)
posnr
matnr
uom(3)
lfimg(10)
pstyv
lgort
kschl
kbetr(11)
kwert(11)
per(5)
linetyp(4)

occurs 0 ,
type c,
like likp-vstel,
like likp-lifex,
like likp-lfart,
like likp-vkorg,
like rv50a-vtweg,
like rv50a-spart,
like likp-route,
like kuwev-kunnr,
type c,
like lips-posnr,
like lips-matnr,
type c,
type c,
like lips-pstyv,
like lips-lgort,
like komv-kschl,
type c,
type c,
type c,
type c,

"filename
"Shipping point = Branch
"Invoice no
"
"Sales org
"Distribution channel
"division
"Route
"Customer
"

end of gift_tab.
data: begin of FileError_tab occurs 0,
result(255)
type c,
end
of FileError_tab.
*======================================================================*
*************************RECORD LAYOUTS*********************************
*======================================================================*
* file header structure
"rectype 'H'
data: begin of file_hdr_str,
branch(4)
type c,
jdate(5)
type c,
end
of file_hdr_str.
* invoice header structure
"rectype '0'
data: begin of inv_hdr_str,
branch(4)
type c,
"branch code
***Changes RSV-Start
*
vbeln(12)
type c,
"invoice no

vbeln(16)
type c,
"invoice no
***Changes RSV-End
fkdat(8)
type c,
"Invoice date
invtyp(1)
type c,
"Invoice type
kunnr(10)
type c,
"Customer code
route(4)
type c,
"SAP route code
salnum(10)
type c,
"Salesman AR code
journey(11)
type c,
"Settlement number
value(10)
type c,
"Value
filler(25)
type c,
"filler
end
of inv_hdr_str.
* invoice detail structure
"rectype '1'
data: begin of inv_det_str,
***Changes RSV-Start
*
vbeln(12)
type c,
"Invoice no
vbeln(16)
type c,
"Invoice no
***Changes RSV-End
linetyp(4)
type c,
"Item type
item_cd(4)
type c,
"Item code
qty(10)
type c,
"Quantity
meins(3)
type c,
"UOM
price(10)
type c,
"Price
dis_amt(10)
type c,
"Discount amount
reused(1)
type c,
"Returns indicator
value(10)
type c,
"Value
end
of inv_det_str.
* file trailer structure
data: begin of file_trl_str,
reccount(10)
type c,
amt1(13)
type c,
end
of file_trl_str.
*======================================================================*
*****************************SWITCHES***********************************
*======================================================================*
data: sw_new_branch(1)
type c,
sw_file_status(1)
type c,
sw_file_trl_recvd(1)
type c,
sw_inv_hdr_recvd(1)
type c,
sw_inv_det_recvd(1)
type c,
sw_detail_valid(1)
type c,
sw_prev_inv_printed(1) type c,
sw_branch(6)
type c.
"Add MAHUSSAIN/FD9K911098/25-10-2015
*======================================================================*
**************************CONSTANTS*************************************
*======================================================================*
data:
c_132_asterisks(132) type c.
constants: c_yes(1)
type c value 'X',
c_no(1)
type c value ' ',
c_process(1)
type c value 'P',
c_ignore(1)
type c value 'I',
c_error(1)
type c value 'E',

c_period(1)
type c value '.',
c_numerics(10)
type c value '0123456789',
c_amt_numerics(13) type c value ' -0123456789.',
c_qty_numerics(13) type c value ' -0123456789.',
c_file_hdr(1)
type c value 'H',
c_inv_hdr(1)
type c value '0',
c_inv_det(1)
type c value '1',
c_file_trl(1)
type c value 'T',
*
c_invoice(9)
type c value '1*2*3*4*8',
c_invoice(13)
type c value '1*2*3*4*5*6*8',
c_payment(1)
type c value '9',
*Begin of Change AMHUSSAIN/ 16.12.2015 16:43:25 /
c_rental(1)
type c value '7',
*End of Change AMHUSSAIN / 16.12.2015 16:43:55 /
c_err01(50)
type c value 'Invalid branch code',
c_err02(50)
type c value 'Invalid invoice date',
c_err03(50)
type c value 'Invalid invoice type',
c_err04(50)
type c value 'Invalid customer',
c_err05(50)
type c value 'Invalid amount',
*
c_err06(50)
type c value 'Invalid invoice amount',
c_err07(50)
type c value 'Detail without header',
c_err08(50)
type c value 'Invalid invoice line type',
c_err09(50)
type c value 'Invalid quantity',
c_err10(50)
type c value 'Invalid price',
c_err11(50)
type c value 'Invalid price unit',
c_err12(50)
type c value 'Invalid discount amount',
c_err13(50)
type c value 'Invalid record count',
c_err14(50)
type c value 'Invalid total amount',
*Begin of Change AMHUSSAIN/ 16.12.2015 17:03:52 / FD9K911851
*
c_valid_head_types(15)
*
type c value '1*2*3*4*5*6*8*9',
c_valid_head_types(17)
type c value '1*2*3*4*5*6*7*8*9',
*End of Change AMHUSSAIN / 16.12.2015 17:04:11 / FD9K911851
c_cr_inv(1)
type c value '1', "Credit
c_cs_inv(1)
type c value '2', "Cash
c_tc_inv(1)
type c value '3', "Temp. Credit
c_gt_inv(1)
type c value '4', "Gift
c_re_inv(1)
type c value '5', "Exp. Returns Invoice
c_vr_inv(1)
type c value '6', "Valid Returns Invoice
c_rt_inv(1)
type c value '8', "Rental
c_valid_line_types(30) type c value
'1001*1002*1003*1004*1005*1901'.
* data : c_gift(1)
type c value 'g' .
"gift
*======================================================================*
**************************VARIABLES*************************************
*======================================================================*
field-symbols: <FS>.
data: v_sub(3)
type n,
v_rundate
like sy-datum,
v_runtime
like sy-uzeit,

v_curr_year(4)
v_prev_year(4)
v_begda
v_endda
v_curr_year_days(3)
v_prev_year_days(3)
v_file_date
v_day
v_day_name(10)
v_unix_command(255)

type
type
like
like
type
type
like
like
type
type

n,
n,
sy-datum,
sy-datum,
n,
n,
sy-datum,
scal-indicator,
c,
c,

v_line(80)
v_windows_com(255)
v_file_name
v_ctr

type
type
like
type

c,
c,
FILENAME-FILEEXTERN,
i,

*
v_file_prefix(3)
type c,
v_filename
like rlgrap-filename,
v_unix_filename
like filename-fileextern,
v_reccount(10)
type n,
v_count(10)
type n,
*changes done by mujeer on 12.11.2005
* description: changed decimals from 2 to 3 req from busi
*changes done by mderar 14/11/2005
* description: changed decimals from 3 Back 2 req from busines

*
*
*
*

*
*
*

v_temp_amt(13)
type p decimals 3,
v_tot_amt(13)
type p decimals 3,
v_tot_amt_2dec(13)
type p decimals 3,
v_amount(13)
type p decimals 3,
v_diff(9)
type p decimals 3,
end of change
v_lines(6)
type n,
v_error(7)
type c,
v_price(10)
type p decimals 3,
v_tmpprice(10)
type p decimals 2,
Added By Omer For changes to Dump Error if price is above 999.000
v_tmpprice1(10)
type p decimals 3,
End of Addition by Omer
end of change
v_qty(10)
type n,
v_peinh(5)
type n,
v_jdate(3)
type n,
v_julian_date(5)
type n,
v_tabix
like sy-tabix,
v_datum
like sy-datum,
IDC-UPGRADE - Begin of Modify - KA-001
v_mask(120)
type c,
v_mask
type string,
IDC-UPGRADE - End of Modify - KA-001
v_posnr(4).

TYPES : BEGIN OF TY_ZVPROI12,


MSALES TYPE ZVPSICT,
MATNR TYPE ZVPSIMT,
END OF TY_ZVPROI12.
DATA : ZVPROI12_TAB TYPE STANDARD TABLE OF TY_ZVPROI12,
WA_ZVPROI12 TYPE TY_ZVPROI12.
*======================================================================*
*************************SELECTION SCREEN*******************************
*======================================================================*
selection-screen: begin of block blk1 with frame title text-001.
parameters: p_vkorg
like knvv-vkorg default '1900'
obligatory,
x_ig0inv
as checkbox default 'X',
x_test
as checkbox default 'X'.
selection-screen: end of block blk1.
selection-screen: begin of block blk2 with frame title text-002.
selection-screen: begin of line.
selection-screen: position 1.
parameters: r_pserv
radiobutton group 1 default 'X'.
selection-screen: comment 3(30) text-003.
selection-screen: end of line.
selection-screen: begin of line.
selection-screen: comment 1(30) text-004.
selection-screen: position 31.
parameters: p_plist
like rlgrap-filename.
selection-screen: end of line.
selection-screen: uline.
selection-screen: begin of line.
selection-screen: position 1.
parameters: r_aserv
radiobutton group 1.
selection-screen: comment 3(30) text-005.
selection-screen: end of line.
selection-screen: begin of line.
selection-screen: comment 1(30) text-006.
selection-screen: position 31.
parameters: p_adir(60)
type c lower case default
'/home/abap/asf/receive/'.
selection-screen: end of line.
selection-screen end of block blk2.
*
*======================================================================*
**********************SELECTION SCREEN VALIDATION***********************
*======================================================================*
at selection-screen on value-request for p_plist.
* IDC-UPGRADE - Begin of Modify - KA-001
*
v_mask = ',Tab Delimited (*.txt),*.txt.'.
v_mask = '|Tab Delimited (*.txt)|*.txt.'.
*
CALL FUNCTION 'WS_FILENAME_GET'

*
EXPORTING
*
DEF_FILENAME
=
*
DEF_PATH
=
*
MASK
=
*
TITLE
=
*
IMPORTING
*
FILENAME
=
*
EXCEPTIONS
*
INV_WINSYS
=
*
NO_BATCH
=
*
SELECTION_CANCEL =
*
SELECTION_ERROR =
*
OTHERS
=
DATA:lt_files
TYPE filetable,
l_file
TYPE file_table,
l_title
TYPE string,
l_subrc
TYPE i,
l_usr_act TYPE i,
l_def_file TYPE string.

' '
' '
v_mask
' '
p_plist
1
2
3
4
5.

l_def_file = p_plist.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING
WINDOW_TITLE
= ' '
*
DEFAULT_EXTENSION
=
DEFAULT_FILENAME
= l_def_file
FILE_FILTER
= v_mask
*
WITH_ENCODING
=
*
INITIAL_DIRECTORY
=
*
MULTISELECTION
=
CHANGING
FILE_TABLE
RC
USER_ACTION
*
FILE_ENCODING
EXCEPTIONS
FILE_OPEN_DIALOG_FAILED
CNTL_ERROR
ERROR_NO_GUI
NOT_SUPPORTED_BY_GUI
others
.

= lt_files
= l_subrc
= l_usr_act
=
=
=
=
=
=

1
2
3
4
5

IF sy-subrc eq 0 AND
l_usr_act <> CL_GUI_FRONTEND_SERVICES=>ACTION_CANCEL.
LOOP AT lt_files INTO l_file.
MOVE l_file-filename to l_def_file.
MOVE l_def_file
to p_plist.
EXIT.

ENDLOOP.
ELSEIF SY-SUBRC <> 0.
clear p_plist.
ENDIF.
* IDC-UPGRADE - End of Modify - KA-001
*
at selection-screen.
* check background requirement
if sy-batch = c_yes and r_pserv = c_yes.
message e398(00) with 'Cannot run background with presentation '
'server input'.
endif.
* check file list/ directory
if r_pserv = c_yes and p_plist is initial.
message e398(00) with 'Please specify file list on presentation '
'server'.
elseif r_aserv = c_yes and p_adir is initial.
message e398(00) with 'Please specify application server '
'directory'.
endif.

*
*======================================================================*
********************* START-OF-SELECTION ******************************
*======================================================================*
start-of-selection.
*
perform initialize_process.
perform process_all_files.
perform create_delivery_data.
perform update_parameter_tables.
perform download_tables.
perform backup_input_files.
perform fileerror_list.

form fileerror_list.
loop at fileerror_tab.
write /01 fileerror_tab-result.
endloop.
endform.
*=====================================================================*
* Form: Initialise_Process
*
*=====================================================================*
form initialize_process.
* initialise variables
v_sub = 0.
while v_sub < 132.
c_132_asterisks+v_sub(1) = '*'.

*
*

*
*
*

add 1 to v_sub.
endwhile.
v_rundate = sy-datum.
v_runtime = sy-uzeit.
find days in years
v_curr_year = sy-datum+0(4).
concatenate v_curr_year '0101' into v_begda.
concatenate v_curr_year '1231' into v_endda.
v_curr_year_days = v_endda - v_begda + 1.
v_prev_year = v_curr_year - 1.
concatenate v_prev_year '0101' into v_begda.
concatenate v_prev_year '1231' into v_endda.
v_prev_year_days = v_endda - v_begda + 1.
load all parameter tables into internal memory
select * from zvposi01 into table zvposi01_tab.
select * from ZVPROI10 into table ZVPROI10_tab.
select * from zvposi07 into table zvposi07_tab.
select * from zvposi08 into table zvposi08_tab.
select * from zvposi09 into table zvposi09_tab.
select * from z1insr03 into table z1insr03_tab.
select kunnr vtweg into table kunnr_tab from knvv
where vkorg = p_vkorg.
Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
select * from zvposi07_pro into table zvposi07_pro_tab
where route = 'ASF'.
select * from zvposi09_pro into table zvposi09_pro_tab
where route = 'ASF'.
select * from zvposi08_pro into table zvposi08_pro_tab
where route = 'ASF'.
End of Change MAHUSSAIN/FD9K911098/25-10-2015.
get list of files to process
perform get_file_list.
reformat directory for later use
if r_pserv = c_yes.
v_sub = strlen( p_plist ) - 1.
while v_sub <> 0.
if p_plist+v_sub(1) = '\'.
exit.
else.
p_plist+v_sub(1) = ' '.
endif.
subtract 1 from v_sub.
endwhile.
else.
v_sub = strlen( p_adir ) - 1.
if p_adir+v_sub(1) <> '/'.
add 1 to v_sub.
p_adir+v_sub(1) = '/'.
endif.
endif.

*
endform.

*
*=====================================================================*
* Form: Process_All_Files
*
*=====================================================================*
form process_all_files.
*
sort file_tab by jdate branch.
loop at file_tab.
*
new julian date process
at new jdate.
perform convert_julian_date_to_date using file_tab-jdate.
format color col_heading.
write: /001 c_132_asterisks.
write: /001 'Julian Date ', file_tab-jdate, v_file_date,
v_day_name.
endat.
*
new branch process
at new branch.
sw_new_branch = c_yes.
endat.
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
sw_branch = file_tab-branch.
CLEAR : file_tab-branch.
file_tab-branch = sw_branch+2(4).
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
if sw_new_branch = c_yes.
sw_new_branch = c_no.
sw_file_status = c_process.
*
print branch name
read table z1insr03_tab with key werks = file_tab-branch.
if sy-subrc <> 0.
z1insr03_tab-name1 = 'UNKNWN'.
endif.
format color col_group.
uline.
write: /001 'Branch ', file_tab-branch, z1insr03_tab-name1.
*
validate files status
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
* Checking the first 3 letters of the file to identify the file whether it is
from
* Msale or RoutePro.
if sw_branch(2) = '88'.
read table zvposi09_pro_tab with key route = 'ASF'
branch = file_tab-branch
jdate = file_tab-jdate.
else.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
read table zvposi09_tab with key branch = file_tab-branch
jdate = file_tab-jdate.
endif.
" Add MAHUSSAIN/FD9K911098/25-10-2015.
if sy-subrc = 0.
write: 085 'File previously skipped, now being processed'.

new-line.
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if sw_branch(2) = '88'.
if zvposi09_pro_tab[] IS NOT INITIAL.
delete zvposi09_pro_tab index sy-tabix.
endif.
else.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
delete zvposi09_tab index sy-tabix.
endif.
" Add MAHUSSAIN/FD9K911098/25-10-2015.
else.
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if sw_branch(2) = '88'.
read table zvposi07_pro_tab with key route = 'ASF'
branch = file_tab-branch
jdate = file_tab-jdate.
else.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
read table zvposi07_tab with key branch = file_tab-branch
jdate = file_tab-jdate.
endif.
" Add MAHUSSAIN/FD9K911098/25-10-2015.
if sy-subrc = 0.
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if sw_branch(2) = '88'.
write: 085 'File previously processed on ',
zvposi07_pro_tab-datup, zvposi07_pro_tab-timup,
' - File ignored'.
else.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
write: 085 'File previously processed on ',
zvposi07_tab-datup, zvposi07_tab-timup,
' - File ignored'.
endif. " Add MAHUSSAIN/FD9K911098/25-10-2015.
sw_file_status = c_ignore.
else.
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if sw_branch(2) = '88'.
read table zvposi08_pro_tab with key
route = 'ASF'
branch = file_tab-branch.
if file_tab-jdate le zvposi08_pro_tab-jdate.
write: 085 'File prior to start date of branch',
' - File ignored'.
sw_file_status = c_ignore.
endif.
else.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
read table zvposi08_tab with key
branch = file_tab-branch.
if file_tab-jdate le zvposi08_tab-jdate.
write: 085 'File prior to start date of branch',
' - File ignored'.

sw_file_status = c_ignore.
endif.
endif.
" Add MAHUSSAIN/FD9K911098/25-10-2015.
endif.
endif.
format color col_normal.
validate file content
if sw_file_status = c_process.
perform process_file.
endif.
endif.

clear : sw_branch. " Add MAHUSSAIN/FD9K911098/25-10-2015.


endloop.
print files skipped this run
new-line.
write: /001 C_132_asterisks.
write: /001 'Files skipped this run'.
skip 1.
sort zvposi09_tab by datup branch jdate.
loop at zvposi09_tab where datup = v_rundate.
perform convert_julian_date_to_date using zvposi09_tab-jdate.
write: /001 zvposi09_tab-branch,
zvposi09_tab-jdate,
v_file_date,
v_day_name.
endloop.

*
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
skip 1.
sort zvposi09_pro_tab by datup branch jdate.
loop at zvposi09_pro_tab where datup = v_rundate.
perform convert_julian_date_to_date using zvposi09_pro_tab-jdate.
write: /001 zvposi09_pro_tab-branch,
zvposi09_pro_tab-jdate,
v_file_date,
v_day_name.
endloop.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
endform.
*
*=====================================================================*
* Form: Process_File
*
*=====================================================================*
form process_file.
*
perform load_file.
perform validate_file.
* update skipped files table (error file)
if sw_file_status <> c_process.
write: 085 'File ignored due to errors - please resubmit'.
new-line.

* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.


* Checking the first 3 degits of the file to update the RoutePro tables.
if sw_branch(2) = '88'.
zvposi09_pro_tab-route = 'ASF'.
zvposi09_pro_tab-branch = file_tab-branch.
zvposi09_pro_tab-jdate = file_tab-jdate.
zvposi09_pro_tab-datup = v_rundate.
zvposi09_pro_tab-timup = v_runtime.
zvposi09_pro_tab-type
= 'E'.
append zvposi09_pro_tab.
exit.
else.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
zvposi09_tab-branch = file_tab-branch.
zvposi09_tab-jdate = file_tab-jdate.
zvposi09_tab-datup = v_rundate.
zvposi09_tab-timup = v_runtime.
zvposi09_tab-type
= 'E'.
append zvposi09_tab.
exit.
endif.
"Add MAHUSSAIN/FD9K911098/25-10-2015.
else.
write: 085 'File processed successfully'.
new-line.
endif.
* update skipped files table (valid skips)
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if sw_branch(2) = '88'.
read table zvposi08_pro_tab with key route = 'ASF'
branch = file_tab-branch.
v_tabix = sy-tabix.
v_jdate = zvposi08_pro_tab-jdate+2(3) + 1.
*
catch up last years skipped files
if zvposi08_pro_tab-jdate+0(2) = v_prev_year+2(2) and
file_tab-jdate+0(2) = v_curr_year+2(2).
while v_jdate LE v_prev_year_days.
*
check if jdate already marked as skipped (error)
concatenate zvposi08_pro_tab-jdate+0(2) v_jdate into v_julian_date.
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if sw_branch(2) = '88'.
read table zvposi09_pro_tab with key route = 'ASF'
branch = file_tab-branch
jdate = v_julian_date.
else.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
read table zvposi09_tab with key branch = file_tab-branch
jdate = v_julian_date.
endif.
" Add MAHUSSAIN/FD9K911098/25-10-2015.
if sy-subrc = 0.
add 1 to v_jdate.
continue.
endif.

*
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if sw_branch(2) = '88'.
clear zvposi09_pro_tab.
zvposi09_pro_tab-route = 'ASF'.
zvposi09_pro_tab-branch = file_tab-branch.
concatenate zvposi08_tab-jdate+0(2) v_jdate into
zvposi09_pro_tab-jdate.
zvposi09_pro_tab-datup = v_rundate.
zvposi09_pro_tab-timup = v_runtime.
zvposi09_pro_tab-type
= 'S'.
append zvposi09_pro_tab.
else.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
clear zvposi09_tab.
zvposi09_tab-branch = file_tab-branch.
concatenate zvposi08_tab-jdate+0(2) v_jdate into
zvposi09_tab-jdate.
zvposi09_tab-datup = v_rundate.
zvposi09_tab-timup = v_runtime.
zvposi09_tab-type
= 'S'.
append zvposi09_tab.
endif.
" Add MAHUSSAIN/FD9K911098/25-10-2015.
add 1 to v_jdate.
endwhile.
v_jdate = '001'.
concatenate v_curr_year+2(2) '001' into zvposi08_pro_tab-jdate.
endif.
else.
* End f Change MAHUSSAIN/FD9K911098/25-10-2015.
read table zvposi08_tab with key branch = file_tab-branch.
v_tabix = sy-tabix.
v_jdate = zvposi08_tab-jdate+2(3) + 1.
*
catch up last years skipped files
if zvposi08_tab-jdate+0(2) = v_prev_year+2(2) and
file_tab-jdate+0(2) = v_curr_year+2(2).
while v_jdate LE v_prev_year_days.
*
check if jdate already marked as skipped (error)
concatenate zvposi08_tab-jdate+0(2) v_jdate into v_julian_date.
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if sw_branch(2) = '88'.
read table zvposi09_pro_tab with key route = 'ASF'
branch = file_tab-branch
jdate = v_julian_date.
else.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
read table zvposi09_tab with key branch = file_tab-branch
jdate = v_julian_date.
endif.
" Add MAHUSSAIN/FD9K911098/25-10-2015.
if sy-subrc = 0.
add 1 to v_jdate.
continue.

endif.
*
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if sw_branch(2) = '88'.
clear zvposi09_pro_tab.
zvposi09_pro_tab-route = 'ASF'.
zvposi09_pro_tab-branch = file_tab-branch.
concatenate zvposi08_tab-jdate+0(2) v_jdate into
zvposi09_pro_tab-jdate.
zvposi09_pro_tab-datup = v_rundate.
zvposi09_pro_tab-timup = v_runtime.
zvposi09_pro_tab-type
= 'S'.
append zvposi09_pro_tab.
else.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
clear zvposi09_tab.
zvposi09_tab-branch = file_tab-branch.
concatenate zvposi08_tab-jdate+0(2) v_jdate into
zvposi09_tab-jdate.
zvposi09_tab-datup = v_rundate.
zvposi09_tab-timup = v_runtime.
zvposi09_tab-type
= 'S'.
append zvposi09_tab.
endif.
" Add MAHUSSAIN/FD9K911098/25-10-2015.
add 1 to v_jdate.
endwhile.
v_jdate = '001'.
concatenate v_curr_year+2(2) '001' into zvposi08_tab-jdate.
endif.
endif. " Add MAHUSSAIN/FD9K911098/25-10-2015.
* update this years skipped files
while v_jdate < file_tab-jdate+2(3).
*
check if jdate already marked as skipped (error)
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if sw_branch(2) = '88'.
concatenate zvposi08_pro_tab-jdate+0(2) v_jdate into v_julian_date.
read table zvposi09_pro_tab with key route = 'ASF'
branch = file_tab-branch
jdate = v_julian_date.
else.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
concatenate zvposi08_tab-jdate+0(2) v_jdate into v_julian_date.
read table zvposi09_tab with key branch = file_tab-branch
jdate = v_julian_date.
endif. " Add MAHUSSAIN/FD9K911098/25-10-2015.
if sy-subrc = 0.
add 1 to v_jdate.
continue.
endif.
*
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if sw_branch(2) = '88'.

clear zvposi09_pro_tab.
zvposi09_pro_tab-route = 'ASF'.
zvposi09_pro_tab-branch = file_tab-branch.
concatenate zvposi08_pro_tab-jdate+0(2) v_jdate into
zvposi09_pro_tab-jdate.
zvposi09_pro_tab-datup = v_rundate.
zvposi09_pro_tab-timup = v_runtime.
zvposi09_pro_tab-type
= 'S'.
append zvposi09_pro_tab.
else.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
clear zvposi09_tab.
zvposi09_tab-branch = file_tab-branch.
concatenate zvposi08_tab-jdate+0(2) v_jdate into
zvposi09_tab-jdate.
zvposi09_tab-datup = v_rundate.
zvposi09_tab-timup = v_runtime.
zvposi09_tab-type
= 'S'.
append zvposi09_tab.
endif.
" Add MAHUSSAIN/FD9K911098/25-10-2015.
add 1 to v_jdate.
endwhile.
* update last processed table
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if sw_branch(2) = '88'.
if zvposi08_pro_tab-jdate < file_tab-jdate.
zvposi08_pro_tab-jdate = file_tab-jdate.
zvposi08_pro_tab-valid = v_rundate.
if not zvposi08_pro_tab[] is INITIAL.
modify zvposi08_pro_tab index v_tabix.
endif.
endif.
else.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
if zvposi08_tab-jdate < file_tab-jdate.
zvposi08_tab-jdate = file_tab-jdate.
zvposi08_tab-valid = v_rundate.
modify zvposi08_tab index v_tabix.
endif.
endif. " Add MAHUSSAIN/FD9K911098/25-10-2015.
* update processed files table
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if sw_branch(2) = '88'.
zvposi07_pro_tab-route = 'ASF'.
zvposi07_pro_tab-branch = file_tab-branch.
zvposi07_pro_tab-jdate = file_tab-jdate.
zvposi07_pro_tab-datup = v_rundate.
zvposi07_pro_tab-timup = v_runtime.
append zvposi07_pro_tab.
clear : zvposi07_pro_tab.
else.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.

zvposi07_tab-branch = file_tab-branch.
zvposi07_tab-jdate = file_tab-jdate.
zvposi07_tab-datup = v_rundate.
zvposi07_tab-timup = v_runtime.
append zvposi07_tab.
endif.
" Add MAHUSSAIN/FD9K911098/25-10-2015.
* save header and details
append lines of temp_header_tab to header_tab.
append lines of temp_detail_tab to detail_tab.
*
endform.
*
*======================================================================*
* Form: Get_File_List
*
*======================================================================*
form get_file_list.
* get list from presentation server
if r_pserv = c_yes.
* IDC-UPGRADE - Begin of Modify - KA-001
*
CALL FUNCTION 'WS_UPLOAD'
*
EXPORTING
*
FILENAME
= p_plist
*
FILETYPE
= 'ASC'
*
TABLES
*
DATA_TAB
= in_file_tab
*
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.
DATA L_P_FILE TYPE STRING.
TYPES: t_appoggio like LINE OF in_file_tab.
DATA: tb_appoggio1 TYPE STANDARD TABLE OF t_appoggio.
L_P_FILE = p_plist.

CALL METHOD cl_gui_frontend_services=>gui_upload


EXPORTING
filename = L_P_FILE
filetype = 'ASC'
* Begin of modification LS-001
* HAS_FIELD_SEPARATOR = 'X'
* End of modification la
CHANGING
data_tab = TB_APPOGGIO1
EXCEPTIONS

OTHERS = 1.
IF sy-subrc = 0.
in_file_tab[] = TB_APPOGGIO1[].
ELSEif sy-subrc <> 0.
message e398(00) with 'Unable to upload the file list from '
p_plist.
* IDC-UPGRADE - End of Modify - KA-001
endif.
else.
*
get list from application server
* specify the Operating System.
if sy-opsys = 'Windows NT'.
* changes by salim siraji (21/02/2007) for physical path changes
* req by appl. support manager
*
v_windows_com = 'dir v:\receive'.
v_windows_com = 'dir \\receive'.
CALL FUNCTION 'Z_EXECUTE_UNIX_COMMAND'
EXPORTING
COMMAND
= v_windows_com
TABLES
RESULT
= listfile_tab
EXCEPTIONS
COMMAND_NOT_SUCCESSFUL = 1
OTHERS
= 2.
if sy-subrc <> 0.
message e398(00) with 'Unable to get directory listing for '
v_windows_com.
else.
* Discard the unneccessary lines from the table
refresh in_file_tab.
clear in_file_tab.
loop at listfile_tab.
v_ctr = v_ctr + 1.
if v_ctr > 5.
if listfile_tab-line+17(8) = 'File(s)'.
exit.
endif.
if listfile_tab-line+24(5) <> '<DIR>'.
in_file_tab = listfile_tab-line+39(13).
append in_file_tab.
endif.
endif.
endloop.
endif.
else.
concatenate 'ls -1p ' p_adir into v_unix_command separated by ' '.
CALL FUNCTION 'Z_EXECUTE_UNIX_COMMAND'
EXPORTING
COMMAND
= v_unix_command

TABLES
RESULT
= in_file_tab
EXCEPTIONS
COMMAND_NOT_SUCCESSFUL = 1
OTHERS
= 2.
if sy-subrc <> 0.
message e398(00) with 'Unable to get directory listing for '
p_adir.
else.
delete in_file_tab where prefix cs '/' or
branch cs '/' or
dot cs '/' or
jdate cs '/' or
fill cs '/'.
endif.
endif.
endif.
* validate filenames
loop at in_file_tab.
v_file_prefix = in_file_tab-prefix.
translate v_file_prefix to lower case.
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
*
if v_file_prefix <> 'van'. "mss
**
message e398(00) with 'File list contains invalid file '
**in_file_tab '. Please check entire list/'
**
'directory'.
*
concatenate 'File list contains invalid file '
*
in_file_tab '. Please check entire list/'
*
'directory' into fileerror_tab-result.
*
append fileerror_Tab.
*
delete in_file_Tab.
*
continue.
*
*
else.
*
read table zvposi08_tab with key branch = in_file_tab-branch.
*
if sy-subrc <> 0.
**
message e398(00) with 'Invalid branch ' in_file_tab
**
'. Please maintain zvposi08 if you '
**
'require to process this branch'.
*
concatenate 'Invalid branch ' in_file_tab
*
'. Please maintain zvposi08 if you '
*
'require to process this branch'
*
into fileerror_tab-result.
*
append fileerror_Tab.
*
*
delete in_file_Tab.
*
continue.
*
elseif in_file_tab-dot <> c_period.
**
message e398(00) with 'Invalid filename ' in_file_tab
**
'. Period missing'.
*
concatenate 'Invalid filename ' in_file_tab
*
'. Period missing'

*
*
*
*
*
*
**
*
*
*
*
*
*
*
**
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
if

*
*
*

*
*

into fileerror_tab-result.
append fileerror_Tab.
delete in_file_Tab.
continue.
elseif not in_file_tab-jdate co c_numerics.
message e398(00) with 'Invalid julian date ' in_file_tab.
concatenate 'Invalid julian date ' in_file_tab
into fileerror_tab-result.
append fileerror_Tab.
delete in_file_Tab.
continue.
elseif not in_file_tab-fill is initial.
message e398(00) with 'Invalid filename ' in_file_tab
'. Characters after julian date'.
concatenate 'Invalid filename ' in_file_tab
'. Characters after julian date'
into fileerror_tab-result.
append fileerror_Tab.
delete in_file_Tab.
continue.
else.
file_tab-jdate
= in_file_tab-jdate.
file_tab-branch
= in_file_tab-branch.
file_tab-filename = in_file_tab.
append file_tab.
endif.
endif.
v_file_prefix = 'asf'. "mss
read table zvposi08_tab with key branch = in_file_tab-branch.
if sy-subrc <> 0.
message e398(00) with 'Invalid branch ' in_file_tab
'. Please maintain zvposi08 if you '
'require to process this branch'.
concatenate 'Invalid branch ' in_file_tab
'. Please maintain zvposi08 if you '
'require to process this branch'
into fileerror_tab-result.
append fileerror_Tab.
delete in_file_Tab.
continue.
elseif in_file_tab-dot <> c_period.
message e398(00) with 'Invalid filename ' in_file_tab
'. Period missing'.
concatenate 'Invalid filename ' in_file_tab
'. Period missing'
into fileerror_tab-result.
append fileerror_Tab.

*
*

delete in_file_Tab.
continue.
elseif not in_file_tab-jdate co c_numerics.
message e398(00) with 'Invalid julian date ' in_file_tab.
concatenate 'Invalid julian date ' in_file_tab
into fileerror_tab-result.
append fileerror_Tab.
delete in_file_Tab.
continue.
elseif not in_file_tab-fill is initial.
message e398(00) with 'Invalid filename ' in_file_tab
'. Characters after julian date'.
concatenate 'Invalid filename ' in_file_tab
'. Characters after julian date'
into fileerror_tab-result.
append fileerror_Tab.

delete in_file_Tab.
continue.
else.
file_tab-jdate
= in_file_tab-jdate.
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
* Here Checking the prefix of thee file name to concatenage the value with 99
or 88.
*
99 is to identify the file from 'VAN' (Msale)
*
88 is to identify the file from 'PRO' (RoutePro)
*
file_tab-branch
= in_file_tab-branch.
if v_file_prefix = 'van'.
CONCATENATE '99' in_file_tab-branch INTO file_tab-branch.
elseif v_file_prefix = 'asf'.
CONCATENATE '88' in_file_tab-branch INTO file_tab-branch.
endif.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
file_tab-filename = in_file_tab.
append file_tab.
endif.
else.
*
message e398(00) with 'File list contains invalid file '
*in_file_tab '. Please check entire list/'
*
'directory'.
concatenate 'File list contains invalid file '
in_file_tab '. Please check entire list/'
'directory' into fileerror_tab-result.
append fileerror_Tab.
delete in_file_Tab.
continue.
endif.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
endloop.

*
endform.
*
*======================================================================*
* Form: Load_File
*
*======================================================================*
form load_file.
* clear data table
refresh: data_tab.
clear: data_tab.
*
if r_pserv = c_yes.
concatenate p_plist file_tab-filename into v_filename.
* IDC-UPGRADE - Begin of Modify - KA-001
*
CALL FUNCTION 'WS_UPLOAD'
*
EXPORTING
*
FILENAME
= v_filename
*
FILETYPE
= 'ASC'
*
TABLES
*
DATA_TAB
= data_tab
*
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.
DATA L_P_FILE TYPE STRING.
TYPES: t_appoggio like LINE OF data_tab.
DATA: tb_appoggio1 TYPE STANDARD TABLE OF t_appoggio.
L_P_FILE = v_filename.

CALL METHOD cl_gui_frontend_services=>gui_upload


EXPORTING
filename = L_P_FILE
filetype = 'ASC'
* Begin of modification ls-001
* HAS_FIELD_SEPARATOR = 'X'
* End of modification LS-001
CHANGING
data_tab = TB_APPOGGIO1
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0.
data_tab[] = TB_APPOGGIO1[].

ELSEif sy-subrc <> 0.


message e398(00) with 'Unable to upload ' v_filename
' from presentation server'.
* IDC-UPGRADE - End of Modify - KA-001
endif.
else.
call function 'FILE_GET_NAME'
exporting
CLIENT
= SY-MANDT
logical_filename
= 'ASF_DATA_FILES_UPLOAD'
OPERATING_SYSTEM
= SY-OPSYS
PARAMETER_1
= file_tab-filename
IMPORTING
FILE_NAME
= v_file_name
EXCEPTIONS
FILE_NOT_FOUND
= 1
OTHERS
= 2
.
*

concatenate p_adir file_tab-filename into v_unix_filename.


CALL FUNCTION 'Z_UPLOAD_UNIX_FILE'
EXPORTING
FILENAME
= v_file_name
TABLES
FILETAB
= data_tab
EXCEPTIONS
FILE_NOT_FOUND = 1
FILE_CANT_OPEN = 2
OTHERS
= 3.
if sy-subrc <> 0.
message e398(00) with 'Unable to upload ' v_unix_filename
' from application server'.
endif.
endif.

*
endform.
*
*======================================================================*
* Form: Validate_File
*
*======================================================================*
form validate_file.
* initialise variables
refresh: temp_header_tab,
temp_detail_tab.
v_reccount = 0.
v_tot_amt = 0.
sw_file_trl_recvd = c_no.
loop at data_tab.
*
cater for extra records at end of file after file trailer received
if sw_file_trl_recvd = c_yes.
write: /001 data_tab-rectype, data_tab-data,

*
*

085 'Extra record after trailer'.


sw_file_status = c_error.
continue.
endif.
validate header record
if sy-tabix = 1.
if data_tab-rectype <> c_file_hdr.
write: 085 'Header record missing'.
new-line.
sw_file_status = c_ignore.
sw_file_trl_recvd = c_yes.
exit.
else.
file_hdr_str = data_tab-data.
if file_hdr_str-branch <> file_tab-branch or
file_hdr_str-jdate <> file_tab-jdate.
write: /001 file_hdr_str-branch, file_hdr_str-jdate,
085 'File header not matching Filename'.
new-line.
sw_file_status = c_ignore.
sw_file_trl_recvd = c_yes.
exit.
else.
sw_inv_hdr_recvd = c_no.
sw_inv_det_recvd = c_no.
clear: inv_hdr_str, inv_det_str.
add 1 to v_reccount.
endif.
continue.
endif.
endif.
validate invoice header
if data_tab-rectype = c_inv_hdr.
check for invoice with no detail
if inv_hdr_str-invtyp ca c_invoice and sw_inv_det_recvd = c_no.
if sw_prev_inv_printed = c_no.
write: /001 inv_hdr_str-branch,
inv_hdr_str-vbeln,
inv_hdr_str-fkdat,
inv_hdr_str-invtyp,
inv_hdr_str-kunnr,
inv_hdr_str-route,
inv_hdr_str-salnum,
inv_hdr_str-journey,
inv_hdr_str-value.
endif.
write: 085 'Invoice with no detail'.
new-line.
if x_ig0inv = c_no or inv_hdr_str-value <> ' 000000.00'.
sw_file_status = c_error.
endif.
endif.

sw_inv_hdr_recvd = c_yes.
sw_inv_det_recvd = c_no.
sw_prev_inv_printed = c_no.
inv_hdr_str = data_tab-data.
add 1 to v_reccount.
perform validate_invoice_header.
print errors
describe table err_tab lines v_lines.
if v_lines > 0.
loop at err_tab.
at first.
write: /001 inv_hdr_str-branch,
inv_hdr_str-vbeln,
inv_hdr_str-fkdat,
inv_hdr_str-invtyp,
inv_hdr_str-kunnr,
inv_hdr_str-route,
inv_hdr_str-salnum,
inv_hdr_str-journey,
inv_hdr_str-value.
sw_prev_inv_printed = c_yes.
endat.
concatenate 'c_err' err_tab-errno into v_error.
assign (v_error) to <FS>.
write: 085 <FS>.
new-line.
endloop.
sw_file_status = c_error.
else.
temp_header_tab = data_tab-data.
temp_header_tab-fn = file_tab-filename.
append temp_header_tab.
endif.
endif.
validate invoice detail
if data_tab-rectype = c_inv_det.
sw_inv_det_recvd = c_yes.
inv_det_str = data_tab-data.
add 1 to v_reccount.
perform validate_invoice_detail. " amjad
print errors
describe table err_tab lines v_lines.
if v_lines > 0.
loop at err_tab.
at first.
write: /001 inv_det_str-vbeln,
inv_det_str-linetyp,
inv_det_str-item_cd,
inv_det_str-qty,
inv_det_str-meins,
inv_det_str-price,

inv_det_str-dis_amt.
endat.
concatenate 'c_err' err_tab-errno into v_error.
assign (v_error) to <FS>.
write: 085 <FS>.
new-line.
endloop.
sw_file_status = c_error.
else.
temp_detail_tab = data_tab-data.
temp_detail_tab-branch = inv_hdr_str-branch.
append temp_detail_tab.
endif.
endif.
validate file trailer
if data_tab-rectype = c_file_trl.
sw_file_trl_recvd = c_yes.
add 1 to v_reccount.
file_trl_str = data_tab-data.
perform validate_file_trailer.
print errors
describe table err_tab lines v_lines.
if v_lines > 0.
loop at err_tab.
at first.
write: /001 file_trl_str-reccount,
file_trl_str-amt1,
'Accumulated ',
v_reccount,
v_tot_amt_2dec.
endat.
concatenate 'c_err' err_tab-errno into v_error.
assign (v_error) to <FS>.
write: 085 <FS>.
new-line.
endloop.
sw_file_status = c_error.
endif.
endif.

*
endloop.
if sw_file_trl_recvd = c_no.
write: 085 'Trailer record missing'.
new-line.
sw_file_status = c_ignore.
endif.
*
endform.
*
*======================================================================*
* Form: Validate_Invoice_Header
*
*======================================================================*

form validate_invoice_header.
*
refresh: err_tab.
clear:
err_tab.
* validate branch code
if inv_hdr_str-branch <> file_tab-branch.
err_tab-errno = 01.
append err_tab.
endif.
* check invoice date
v_datum = inv_hdr_str-fkdat.
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING
DATE
= v_datum
EXCEPTIONS
PLAUSIBILITY_CHECK_FAILED = 1
OTHERS
= 2.
if sy-subrc <> 0.
err_tab-errno = 02.
append err_tab.
endif.
* check invoice type
if c_valid_head_types ns inv_hdr_str-invtyp.
err_tab-errno = 03.
append err_tab.
endif.
* validate customer number
* if inv_hdr_str-invtyp <> c_payment.
*
read table kunnr_tab with key altkn = inv_hdr_str-altkn.
*
if sy-subrc <> 0.
*
err_tab-errno = 04.
*
append err_tab.
*
endif.
* endif.
* validate amount
* Changed By Mohammed Derar on 14/11/2005 From 6 to 7
if data_tab-rectype = '0'.
clear temp.
move data_tab-data to temp.
endif.
* Changes by Mohamed Omer Farook on 28.01.2007 for OMAN Branch 1181.
*If temp+0(4) = 1180 or temp+0(4) = 1182.
If temp+0(4) = 1180 or temp+0(4) = 1182 or temp+0(4) = 1181.
if inv_hdr_str-value cn c_amt_numerics or
inv_hdr_str-value+6(1) <> '.'.
err_tab-errno = 05.
append err_tab.
endif.
else.
if inv_hdr_str-value cn c_amt_numerics or
inv_hdr_str-value+7(1) <> '.'.
err_tab-errno = 05.

append err_tab.
endif.
endif..
*
endform.
*
*======================================================================*
* Form: Validate_Invoice_Detail
*
*======================================================================*
form validate_invoice_detail.
*
sw_detail_valid = c_yes.
refresh: err_tab.
clear:
err_tab.
* validate invoice number
if inv_det_str-vbeln <> inv_hdr_str-vbeln.
err_tab-errno = 07.
append err_tab.
endif.
* check line type
if c_valid_line_types ns inv_det_str-linetyp.
err_tab-errno = 08.
append err_tab.
endif.
* validate quantity
if inv_det_str-qty cn c_qty_numerics.
err_tab-errno = 09.
append err_tab.
sw_detail_valid = c_no.
endif.
* validate price
* Changed By Mohammed Derar On 14/11/2005 from 6 to 7
* Changes by Mohamed Omer Farook on 28.01.2007 for OMAN Branch 1181.
*If temp+0(4) = 1180 or temp+0(4) = 1182.
If temp+0(4) = 1180 or temp+0(4) = 1182 or temp+0(4) = 1181.
if inv_det_str-price cn c_amt_numerics or
inv_det_str-price+6(1) <> '.'.
err_tab-errno = 10.
append err_tab.
endif.
else.
if inv_det_str-price cn c_amt_numerics or
inv_det_str-price+7(1) <> '.'.
err_tab-errno = 10.
append err_tab.
endif.
endif.
** validate price unit
*
if inv_det_str-peinh cn c_qty_numerics.
*
err_tab-errno = 11.
*
append err_tab.

*
sw_detail_valid = c_no.
*
else.
*
v_peinh = inv_det_str-peinh.
*
if v_peinh = 0.
*
err_tab-errno = 11.
*
append err_tab.
*
sw_detail_valid = c_no.
*
endif.
*
endif.
* validate discount
* Changed By Mohammed Derar On 14/11/2005 from 6 to 7
* Changes by Mohamed Omer Farook on 28.01.2007 for OMAN Branch 1181.
*If temp+0(4) = 1180 or temp+0(4) = 1182.
If temp+0(4) = 1180 or temp+0(4) = 1182 or temp+0(4) = 1181.
if inv_det_str-dis_amt cn c_amt_numerics OR
inv_det_str-dis_amt+6(1) <> '.'.
err_tab-errno = 12.
append err_tab.
endif.
else.
if inv_det_str-dis_amt cn c_amt_numerics OR
inv_det_str-dis_amt+7(1) <> '.'.
err_tab-errno = 12.
append err_tab.
endif.
endif.
* calculate hash total
if sw_detail_valid = c_yes.
v_price = inv_det_str-price.
v_qty
= inv_det_str-qty.
*
v_peinh = inv_det_str-peinh.
compute v_tot_amt = v_tot_amt + ( v_price * v_qty ).
endif.
endform.
*
*======================================================================*
* Form: Validate_File_Trailer
*
*======================================================================*
form validate_file_trailer.
* check record count
if not file_trl_str-reccount co c_numerics.
err_tab-errno = 13.
append err_tab.
else.
v_count = file_trl_str-reccount.
if v_count <> v_reccount.
err_tab-errno = 13.
append err_tab.
endif.
endif.
* check total amount

if not file_trl_str-amt1 co c_amt_numerics.


err_tab-errno = 14.
append err_tab.
else.
v_amount = file_trl_str-amt1.
*changes done by mujeer on 12.11.2005
v_tot_amt_2dec = v_tot_amt.
v_temp_amt = 0.
v_temp_amt = v_amount - v_tot_amt .
if v_temp_amt > 1 or v_temp_amt < -1.
*
if v_amount <> v_tot_amt.
*end of chnages
err_tab-errno = 14.
append err_tab.
endif.
endif.
*
endform.
*
*======================================================================*
* Form: Convert_Julian_Date_to_Date
*
*======================================================================*
form convert_julian_date_to_date using j_date.
*
concatenate '20' j_date+0(2) '0101' into v_begda.
v_file_date = v_begda + j_date+2(3) - 1.
CALL FUNCTION 'DATE_COMPUTE_DAY'
EXPORTING
DATE
= v_file_date
IMPORTING
DAY
= v_day.
*
case v_day.
when 1.
v_day_name = 'Monday'.
when 2.
v_day_name = 'Tuesday'.
when 3.
v_day_name = 'Wednesday'.
when 4.
v_day_name = 'Thursday'.
when 5.
v_day_name = 'Friday'.
when 6.
v_day_name = 'Saturday'.
when 7.
v_day_name = 'Sunday'.
endcase.
*
endform.
*

*======================================================================*
* Form: Create_Delivery_Data
*
*======================================================================*
form create_delivery_data.
if detail_tab[] IS NOT INITIAL.
refresh : ZVPROI12_tab.
select MSALES
matnr
FROM ZVPROI12
into TABLE ZVPROI12_tab
FOR ALL ENTRIES IN detail_tab
WHERE msales = detail_tab-ITEM_CD.
endif.
data: v_kwert type f.
loop at header_tab.
clear: detail_str,
v_posnr.
*Begin of Change AMHUSSAIN/ 16.12.2015 16:45:41 /FD9K911851
*
if header_tab-invtyp = c_payment.
if header_tab-invtyp = c_payment." OR header_tab-invtyp = c_rental.
*End of Change AMHUSSAIN / 16.12.2015 16:49:28 / FD9K911851
paymnt_tab = header_tab.
append paymnt_tab.
continue.
endif.
*
check if customer on SAP
read table kunnr_tab with key kunnr = header_tab-kunnr.
if sy-subrc <> 0.
clear kunnr_tab.
kunnr_tab-kunnr = header_tab-kunnr.
kunnr_tab-kunnr+9(1) = '?'.
endif.
sap_tab-kunnr = kunnr_tab-kunnr.
*
set up shipping point/sales org/DC
sap_tab-vstel = header_tab-branch.
sap_tab-vkorg = p_vkorg.
sap_tab-vtweg = kunnr_tab-vtweg.
*
get division (using route)
read table zvposi01_tab with key route = header_tab-route.
if sy-s

c <> 0.

*
*
*

read table zvposi01_tab with key route = 'OTHERS'.


endif.
sap_tab-spart = zvposi01_tab-spart.
set up route/date/invoice date
sap_tab-route = header_tab-route.
sap_tab-wadat = header_tab-fkdat.
set up external delivery no
if header_tab-invtyp = c_cs_inv
or

*
*
*
*
*
*
*
*
*
*
*
*

( ( header_tab-invtyp = c_re_inv or
header_tab-invtyp = c_vr_inv ) and
header_tab-vbeln+0(1) = 'J' ).
if header_tab-vbeln+0(1) = 'J'.
concatenate 'CS'
header_tab-vbeln+1(10) into sap_tab-lifex.
else.
concatenate 'CS' header_tab-vbeln into sap_tab-lifex.
endif.
else.
sap_tab-lifex = header_tab-vbeln.
endif.

set up external delivery no


if header_tab-vbeln+0(1) = 'J'.
***Changes RSV-Start
*
concatenate 'CS' header_tab-vbeln+1(11) into sap_tab-lifex.
concatenate 'CS' header_tab-vbeln+1(15) into sap_tab-lifex.
***Changes RSV-End
else.
sap_tab-lifex = header_tab-vbeln.
endif.
*

*
*

"amjad

set up filename and invoice details


sap_tab-fn = header_tab-fn.
loop at detail_tab where vbeln = header_tab-vbeln and
branch = header_tab-branch.
clear: sap_tab-posnr, sap_tab-lfart, sap_tab-lgort,
sap_tab-lfimg, sap_tab-uom,
sap_tab-pstyv,
sap_tab-kschl, sap_tab-per,
sap_tab-kbetr,
sap_tab-kwert.
v_amount = detail_tab-price.
write v_amount to detail_tab-price.
v_amount = detail_tab-dis_amt.
move v_amount to detail_tab-dis_amt.
write v_amount to detail_tab-dis_amt.
v_posnr = v_posnr + 1.
set up del type/sloc/cond for this transaction type
loop at ZVPROI10_tab where invtype
= header_tab-invtyp and
transtype = detail_tab-linetyp.
sap_tab-posnr = v_posnr.

*
concatenate detail_tab-item_cd+0(2) '/'
*
detail_tab-item_cd+2(2) into sap_tab-matnr.
************ Material Code with Msale Material Code.
CLEAR : wa_ZVPROI12.
READ TABLE ZVPROI12_tab INTO wa_ZVPROI12
with key MSALES = detail_tab-item_cd.
if sy-subrc = 0.
sap_tab-matnr = wa_ZVPROI12-matnr.
endif.
sap_tab-lfart = ZVPROI10_tab-lfart.

sap_tab-lgort = ZVPROI10_tab-lgort.
sap_tab-lfimg = detail_tab-qty.
sap_tab-uom
= detail_tab-meins.
sap_tab-pstyv = ZVPROI10_tab-pstyv.
sap_tab-kschl = ZVPROI10_tab-kschl.
sap_tab-per
= 1.
if ZVPROI10_tab-koaid = 'B'.
* Changed By Mohammed Derar On 19/11/2005
* Changes made by Mohamed Omer Farook on 28.01.2007 for Oman Branch.
*
If detail_tab-branch = 1180 or detail_tab-branch = 1182.
If detail_tab-branch = 1180 or detail_tab-branch = 1182 or
detail_tab-branch = 1181.
Changes made by Omer as the price exceeds 999.000 it gives

*
*dump error.
*

sap_tab-kbetr = detail_tab-price.
REPLACE ALL OCCURRENCES OF ',' IN detail_tab-price WITH ''.
v_tmpprice1 = detail_tab-price.
sap_tab-kbetr = v_tmpprice1.
end of changes.
else.
v_tmpprice = detail_tab-price.
sap_tab-kbetr = v_tmpprice.
endif.
endif.
if ZVPROI10_tab-koaid = 'A' and ZVPROI10_tab-krech = 'C'.
clear sap_tab-kbetr.
sap_tab-kwert = detail_tab-dis_amt * -1.
if sap_tab-kwert = space.
sap_tab-kwert = 0.
endif.
endif.
if ZVPROI10_tab-koaid = 'A' and ZVPROI10_tab-krech = 'A'.
clear sap_tab-kbetr.
sap_tab-kbetr = detail_tab-dis_amt.
sap_tab-per
= 1.
if sap_tab-kbetr = space.
sap_tab-kbetr = 0.
endif.
endif.
sap_tab-linetyp = detail_tab-linetyp.
if sap_tab-kbetr <> 0.
append sap_tab.
endif.

*
*
*

v_kwert = sap_tab-kwert * -1.


PTMS 5700
if sap_tab-kwert <> '0.00'.
if v_kwert <> 0.0

append sap_tab.
endif.
if sap_tab-kschl = space.
append sap_tab.
endif.
endloop.
endloop.
clear header_tab.
clear detail_tab.
clear: sap_tab, kunnr_tab.
endloop.
sort sap_tab by fn vstel lifex lfart descending kunnr posnr linetyp.
*
endform.
*
*======================================================================*
* Form: Update_Parameter_Tables
*
*======================================================================*
form update_parameter_tables.
* check if test mode is on
if x_test = c_yes.
message i398(00) with 'Test mode - no updates to database tables.'
'. Please do NOT use MSSAP_TAB and MSPAY_TAB in'
' further updates'.
exit.
endif.
* update database tables with data from internal tables
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if zvposi07_pro_tab[] IS NOT INITIAL.
modify zvposi07_pro from table zvposi07_pro_tab.
if sy-subrc <> 0.
message e398(00) with 'Unable to update table zvposi07_pro'.
endif.
endif.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
*
modify zvposi07 from table zvposi07_tab.
*
if sy-subrc <> 0.
*
message e398(00) with 'Unable to update table zvposi07'.
*
endif.
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.
if zvposi08_pro_tab[] is NOT INITIAL.
modify zvposi08_pro from table zvposi08_pro_tab.
if sy-subrc <> 0.
message e398(00) with 'Unable to update table zvposi08_pro'.
endif.
endif.
* End of Change MAHUSSAIN/FD9K911098/25-10-2015.
*
modify zvposi08 from table zvposi08_tab.
*
if sy-subrc <> 0.
*
message e398(00) with 'Unable to update table zvposi08'.
*
endif.
* Begin of Change MAHUSSAIN/FD9K911098/25-10-2015.

delete from zvposi09_pro where branch <> '


'.
if zvposi09_pro_tab[] IS NOT INITIAL.
modify zvposi09_pro from table zvposi09_pro_tab.
if sy-subrc <> 0.
message e398(00) with 'Unable to update table zvposi09_pro'.
endif.
endif.
End of Change MAHUSSAIN/FD9K911098/25-10-2015.
delete from zvposi09 where branch <> '
'.
modify zvposi09 from table zvposi09_tab.
if sy-subrc <> 0.
message e398(00) with 'Unable to update table zvposi09'.
endif.

*
*
*
*
*
*
*
endform.
*
*======================================================================*
* Form: Download_Tables
*
*======================================================================*
form download_tables.
*
if r_pserv = c_yes.
concatenate p_plist 'MSSAP_TAB.TXT' into v_filename.
* IDC-UPGRADE - Begin of Modify - KA-001
*
CALL FUNCTION 'WS_DOWNLOAD'
*
EXPORTING
*
FILENAME
= v_filename
*
FILETYPE
= 'ASC'
*
TABLES
*
DATA_TAB
= sap_tab
*
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.
data: gd_file type string.
types: t_uctable like line of sap_tab.
data: it_uctable type standard table of t_uctable.
gd_file = v_filename.
it_uctable[] = sap_tab[].

CALL METHOD cl_gui_frontend_services=>gui_download


EXPORTING

filename = gd_file
filetype = 'ASC'
Append = ' '
CHANGING
data_tab = it_uctable
EXCEPTIONS
OTHERS = 1.
if sy-subrc <> 0.
message e398(00) with 'Unable to download MSSAP_TAB to '
v_filename.
* IDC-UPGRADE - End of Modify - KA-001

*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

endif.
concatenate p_plist 'MSPAY_TAB.TXT' into v_filename.
IDC-UPGRADE - Begin of Modify - KA-001
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME
= v_filename
FILETYPE
= 'ASC'
MODE
= 'A'
"Append Mode
TABLES
DATA_TAB
= paymnt_tab
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.

data: g_file type string.


types: t_paymnt like line of paymnt_tab.
data: it_paymnt type standard table of t_paymnt.
g_file = v_filename.
it_paymnt[] = paymnt_tab[].

CALL METHOD cl_gui_frontend_services=>gui_download


EXPORTING
filename = g_file
* Begin of modification ls-001
filetype = 'ASC'
append
= 'X'
* Append = 'x'
* End of modification ls-001

CHANGING
data_tab = it_paymnt
EXCEPTIONS
OTHERS = 1.
if sy-subrc <> 0.
message e398(00) with 'Unable to download MSPAY_TAB to '
v_filename.
* IDC-UPGRADE - End of Modify - KA-001
endif.
else.
call function 'FILE_GET_NAME'
exporting
CLIENT
= SY-MANDT
logical_filename
= 'ASF_DATA_FILES_DOWNLOAD' "amjad
OPERATING_SYSTEM
= SY-OPSYS
PARAMETER_1
= 'mssap_tab.txt'
IMPORTING
FILE_NAME
= v_file_name
EXCEPTIONS
FILE_NOT_FOUND
= 1
OTHERS
= 2
.
CALL FUNCTION 'Z_DOWNLOAD_UNIX_FILE'
EXPORTING
FILENAME
= v_file_name
TABLES
FILETAB
= sap_tab
EXCEPTIONS
FILE_NOT_FOUND = 1
FILE_CANT_OPEN = 2
OTHERS
= 3.
if sy-subrc <> 0.
message e398(00) with 'Unable to download MSSAP_TAB to '
'/home/abap/asf/input/mssap_tab.txt'.
endif.
call function 'FILE_GET_NAME'
exporting
CLIENT
= SY-MANDT
logical_filename
= 'ASF_DATA_FILES_DOWNLOAD'
OPERATING_SYSTEM
= SY-OPSYS
PARAMETER_1
= 'mspay_tab.txt'
IMPORTING
FILE_NAME
= v_file_name
EXCEPTIONS
FILE_NOT_FOUND
= 1
OTHERS
= 2
.
CALL FUNCTION 'Z_DOWNLOAD_UNIX_FILE'
EXPORTING
FILENAME
= v_file_name

TABLES
FILETAB
EXCEPTIONS
FILE_NOT_FOUND
FILE_CANT_OPEN
OTHERS
if sy-subrc <> 0.
message e398(00) with

= paymnt_tab
= 1
= 2
= 3.
'Unable to download MSPAY_TAB to '
'/home/abap/asf/input/mspay_tab.txt'.

endif.
endif.
*
endform.
*
*======================================================================*
* Form: Backup_Input_Files
*
*======================================================================*
form backup_input_files.
* only backup if NOT test mode and files on application server
check x_test = c_no and r_aserv = c_yes.
*
loop at file_tab.
if sy-opsys = 'Windows NT'.
* changes by salim siraji (21/02/2007) for physical path changes
* req by appl. support manager
*
v_windows_com = 'move v:\receive\'.
v_windows_com = 'move \\receive\'.
*
concatenate v_windows_com file_tab-filename ' v:\backup\'
*
file_tab-filename '.' sy-datum '.' sy-uzeit into
*
v_windows_com.
concatenate v_windows_com file_tab-filename ' \\backup\'
file_tab-filename '.' sy-datum '.' sy-uzeit into
v_windows_com.
call function 'Z_EXECUTE_UNIX_COMMAND'
exporting
command = v_windows_com
tables
result = result_tab
* IDC-UPGRADE - Begin of Insert
EXCEPTIONS
COMMAND_NOT_SUCCESSFUL
OTHERS
.
* IDC-UPGRADE - End of Insert -

- KA-001
= 1
= 2
KA-001

if sy-subrc <> 0.
message e398(00) with 'Unable to backup input files'.
endif.
else.
concatenate 'mv' p_adir into v_unix_command separated by ' '.

concatenate v_unix_command file_tab-filename into v_unix_command.


concatenate v_unix_command ' /home/abap/asf/backup/'
file_tab-filename '.' sy-datum '.' sy-uzeit into
v_unix_command.
call function 'Z_EXECUTE_UNIX_COMMAND'
exporting
command = v_unix_command
tables
result = result_tab
* IDC-UPGRADE - Begin of Insert - KA-001
EXCEPTIONS
COMMAND_NOT_SUCCESSFUL
= 1
OTHERS
= 2
.
* IDC-UPGRADE - End of Insert - KA-001
if sy-subrc <> 0.
message e398(00) with 'Unable to backup input files'.
endif.
endif.
endloop.
*
endform.

2: Prepare Delivery creation - Program code ZVPROI0210ASF


report zvposi0120.
*======================================================================*
* AUTHOR
: Abdullah Al-Shwaishi
*
* DATE WRITTEN : March 2004
*
* APPLICATION : SD-POS
*
* FUNCTION
: Creation of Delivery through upload from VANMAN system*
*======================================================================*
********************************************************************
* Change id : KA-001
* Author
: Kumar Ankit
* Date
: 24/05/2012
* CR
: FD9K900007
* Description: AFG Upgrade Syntax Check and Unicode adjustment
* Team
: IDC-UPGRADE
********************************************************************
********************************************************************
* Change id : GS-001
* Author
: Gisonna Salvatore
* Date
: 24/11/2012
* CR
: FD9K900104
* Description: AFG Upgrade Defect ADT*31 Schedule jobs in background
*
working correctly, but in foreground giving error.
* Team
: NDC-UPGRADE
********************************************************************
***************************** TABLES***********************************
*======================================================================*
*======================================================================*
*********************** SELECTION SCREEN *******************************
*======================================================================*
SELECTION-SCREEN BEGIN OF BLOCK NUM1
WITH FRAME TITLE TEXT-001.
PARAMETERS : P_TEST
P_ATPROC

AS CHECKBOX default 'X',


AS CHECKBOX default 'X'.

SELECTION-SCREEN END OF BLOCK NUM1.


selection-screen: begin of block blk2 with frame title text-009.
selection-screen: begin of line.
selection-screen: comment 1(25) text-010.
parameter: x_fixdat as checkbox default ' '.
selection-screen: position 29.
parameter: p_fixdat like likp-wadat_ist.
selection-screen: end of line.
selection-screen: end of block blk2.
selection-screen: begin of block blk3 with frame title text-012.
parameter: p_parvw
like vbpa-parvw,
p_parnr
like vbpa-parnr.
selection-screen: end of block blk3.
*======================================================================*

**************************INTERNAL TABLES*******************************
*======================================================================*
* Internal Table to store date required to create Delivery and Invoice
data: begin of sap_tab occurs 0,
fn(25)
type c,
"filename
vstel
like likp-vstel, "Shipping point = Branch
lifex
like likp-lifex, "Invoice no
lfart
like likp-lfart, "
vkorg
like likp-vkorg, "Sales org
vtweg
like rv50a-vtweg, "Distribution channel
spart
like rv50a-spart, "division
route
like likp-route, "Route
kunnr
like kuwev-kunnr, "Customer
wadat(8)
type c,
"
posnr
like lips-posnr,
matnr
like lips-matnr,
uom(3)
type c,
lfimg(10)
type c,
pstyv
like lips-pstyv,
lgort
like lips-lgort,
kschl
like komv-kschl,
kbetr(11)
type c,
kwert(11)
type c,
per(5)
type c,
linetyp(4)
type c,
end of sap_tab.
data : sap_str like sap_tab.
*Begin of Change AMHUSSAIN/ 20.04.2016 09:49:07/FD9K912927
data: begin of saptmp_tab occurs 0,
fn(25)
type c,
"filename
vstel
like likp-vstel, "Shipping point = Branch
lifex
like likp-lifex, "Invoice no
lfart
like likp-lfart, "
vkorg
like likp-vkorg, "Sales org
vtweg
like rv50a-vtweg, "Distribution channel
spart
like rv50a-spart, "division
route
like likp-route, "Route
kunnr
like kuwev-kunnr, "Customer
wadat(8)
type c,
"
posnr
like lips-posnr,
matnr
like lips-matnr,
uom(3)
type c,
lfimg(10)
type c,
pstyv
like lips-pstyv,
lgort
like lips-lgort,
kschl
like komv-kschl,
kbetr(11)
type c,
kwert(11)
type c,
per(5)
type c,
linetyp(4)
type c,
end of saptmp_tab.
TYPES : BEGIN OF TY_ZVPROI12,
MSALES
TYPE ZVPSICT,
MATNR
TYPE ZVPSIMT,
CHARG
TYPE CHARG_D,

END OF TY_ZVPROI12.
DATA : ZVPROI12_TAB TYPE STANDARD TABLE OF TY_ZVPROI12,
WA_ZVPROI12 TYPE TY_ZVPROI12.
*End of Change AMHUSSAIN / 20.04.2016 09:49:24/FD9K912927
data: begin of bdc_tab occurs 200.
include structure bdcdata.
data: end
of bdc_tab.
*======================================================================*
*************************** VARIABLES **********************************
*======================================================================*
data: v_vbeln like vbrk-vbeln,
v_fn like rlgrap-filename,
v_fp like rlgrap-filename value 'C:\van\',
v_i(2),
v_j(20),
v_datum like sy-datum,
v_invdat like sy-datum,
v_posnr(4),
v_kwert(12),
v_kbetr(12),
v_index,
v_flag,
v_count like sy-tabix,
v_group like apqi-groupid,
v_ref
like apqi-groupid,
v_qty(13),
v_jname(32),
v_jcount(8),
v_command(255),
* changed by ssaikhan on 15.07.2002
v_disp_date1(10),
v_disp_date2(10),
v_windows_com(255),
v_filename_mov(255),
v_filename
like FILENAME-FILEEXTERN.
at selection-screen.
if x_fixdat = 'X' and p_fixdat is initial.
message e398(00) with 'Please specify fixed reversal date'.
endif.

*======================================================================*
********************* START-OF-SELECTION *******************************
*======================================================================*
start-of-selection.
perform initialize_process.
perform terminate_process.

*---------------------------------------------------------------------*
*
FORM initialize_process
*
*---------------------------------------------------------------------*
form initialize_process.
if p_test = 'X'.
perform upload tables sap_tab.
else.
perform unix_upload tables sap_tab.
endif.
*Begin of Change AMHUSSAIN/ 20.04.2016 11:15:12*/FD9K912927
refresh : saptmp_tab.
saptmp_tab[] = sap_tab[].
sort : saptmp_tab by matnr.
delete ADJACENT DUPLICATES FROM saptmp_tab COMPARING matnr.
if saptmp_tab[] IS NOT INITIAL.
select MSALES
MATNR
CHARG
FROM ZVPROI12
INTO TABLE ZVPROI12_TAB
FOR ALL ENTRIES IN saptmp_tab
WHERE MATNR = saptmp_tab-MATNR.
IF SY-SUBRC = 0.
SORT : ZVPROI12_TAB BY MATNR.
ENDIF.
endif.
*End of Change AMHUSSAIN / 20.04.2016 11:15:28/FD9K912927
endform.
*---------------------------------------------------------------------*
*
FORM TERMINATE_PROCESS
*
*---------------------------------------------------------------------*
form terminate_process.
loop at sap_tab.
sap_str = sap_tab.
at new fn.
clear: v_group, v_ref, v_jname,v_jcount.
concatenate sap_str-fn+3(10) 'D' into v_group.
concatenate sap_str-fn+3(10)
sy-uzeit+3(3) into v_ref.
perform bdc_open.
endat.
sap_str = sap_tab.
* changed by ssaikhan on 15.07.2002
write sy-datum to v_disp_date1.
if x_fixdat = 'X'.
move p_fixdat to v_datum.
write v_datum to v_disp_date2.
else.
move sap_tab-wadat to v_datum.
write v_datum to v_disp_date2.
endif.

at new kunnr.
v_i = 1.
perform fill_bdc_tab using:

'X' 'SAPMV50A'
' ' 'LIKP-VSTEL'
' ' 'LIKP-LFART'
' ' 'LIKP-VKORG'
' ' 'RV50A-VTWEG'
' ' 'RV50A-SPART'
' ' 'BDC_OKCODE'
'X' 'SAPMV50A'
' ' 'KUWEV-KUNNR'
' ' 'LIKP-WADAT'
' ' 'LIKP-WADAT_IST'

'4002',
sap_tab-vstel,
sap_tab-lfart,
sap_tab-vkorg,
sap_tab-vtweg,
sap_tab-spart,
'=ENT2_T',
'1000',
sap_tab-kunnr,
v_disp_date1,
v_disp_date2.

endat.
at new posnr.
if v_i > 2.
v_i = 2.
endif.
perform fill_bdc_tab using 'X' 'SAPMV50A'
'1000'.
concatenate 'LIPS-MATNR(' v_i ')' into v_j.
perform fill_bdc_tab using ' ' v_j sap_str-matnr.
concatenate 'LIPSD-G_LFIMG(' v_i ')' into v_j.
perform fill_bdc_tab using ' ' v_j sap_str-lfimg.
concatenate 'LIPS-PSTYV(' v_i ')' into v_j.
perform fill_bdc_tab using ' ' v_j sap_str-pstyv.
*Begin of Change AMHUSSAIN/ 20.04.2016 09:33:55/FD9K912927
*** Adding the Batch Number at Item level.
concatenate 'LIPS-CHARG(' v_i ')' into v_j.
read table zvproi12_tab into wa_zvproi12
with key matnr = sap_str-matnr.
IF SY-SUBRC = 0.
perform fill_bdc_tab using ' ' v_j wa_zvproi12-charg.
ENDIF.
*End of Change AMHUSSAIN / 20.04.2016 09:34:24/PSTYV/FD9K912927
concatenate 'LIPS-VRKME(' v_i ')' into v_j.
perform fill_bdc_tab using: ' ' v_j sap_str-uom,
' ' 'BDC_OKCODE'
'=T\02',
'X' 'SAPMV50A'
'1000'.
perform fill_bdc_tab using: ' ' v_j sap_str-uom,
' ' 'BDC_OKCODE'
'=PIOV_T',
' ' 'BDC_CURSOR'
v_j.
concatenate 'LIPS-LGORT(' v_i ')' into v_j.
perform fill_bdc_tab using: 'X' 'SAPMV50A'
'1000',
' ' v_j
sap_str-lgort,
' ' 'BDC_CURSOR'
v_j.
concatenate 'RV50A-LIPS_SELKZ(' v_i ')' into v_j.
perform fill_bdc_tab using: 'X' 'SAPMV50A'
'1000',
' ' v_j
'X',
' ' 'BDC_OKCODE'
'IKON_T'.
v_i = v_i + 1.
endat.
write sap_tab-kbetr to v_kbetr.
write sap_tab-kwert to v_kwert.

if sap_tab-kschl <> space.


perform fill_bdc_tab using:'X'
' '
'X'
' '
' '
' '
' '
' '
endif.
at end of posnr.
perform fill_bdc_tab using:'X'
' '
'X'
' '

'SAPMV50A'
'3000',
'BDC_OKCODE' '=V69A_KOAN',
'SAPMV50A'
'3000',
'KOMV-KSCHL(02)' sap_tab-kschl,
'KOMV-KWERT(02)' v_kwert,
'KOMV-KBETR(02)' v_kbetr,
'KOMV-KPEIN(02)' sap_tab-per,
'KOMV-KMEIN(02)' sap_tab-uom.

'SAPMV50A'
'BDC_OKCODE'
'SAPMV50A'
'BDC_OKCODE'

'3000',
'=BACK',
'1000',
'=POAN_T'.

endat.
at end of kunnr.
perform fill_bdc_tab using:
' ' 'BDC_OKCODE'
'=HADM_T',
'X' 'SAPMV50A'
'2000',
' ' 'LIKP-LIFEX'
sap_tab-lifex,
' ' 'BDC_OKCODE'
'HPIC_T',
'X' 'SAPMV50A'
'2000',
' ' 'LIKP-BEROT'
v_ref,
' ' 'BDC_OKCODE'
'T\04',
'X' 'SAPMV50A'
'2000',
' ' 'LIKP-ROUTE'
sap_tab-route,
' ' 'BDC_OKCODE'
'=WABU_T',
'X' 'SAPMV50A'
'2000',
' ' 'BDC_OKCODE'
'=T\08',
'X' 'SAPMV50A'
'2000',
' ' 'GVS_TC_DATA-REC-PARVW(03)'
p_parvw,
' ' 'GVS_TC_DATA-REC-PARTNER(03)'
p_parnr,
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMV50A'
'2000',
' ' 'BDC_OKCODE' '=SICH_T'.

*
*
*
*
*
*
*
*
*
*

perform fill_bdc_tab using: ' ' 'BDC_OKCODE'


'X' 'SAPMV50A'
' ' 'LIKP-LIFEX'
' ' 'BDC_OKCODE'
'X' 'SAPMV50A'
' ' 'LIKP-BEROT'
' ' 'BDC_OKCODE'
'X' 'SAPMV50A'
' ' 'LIKP-ROUTE'
' ' 'BDC_OKCODE'
perform bdc_insert using 'VL01NO'.
endat.

'=HADM_T',
'2000',
sap_tab-lifex,
'HPIC_T',
'2000',
v_ref,
'T\04',
'2000',
sap_tab-route,
'=WABU_T'.

at end of fn.
perform bdc_close.
if P_ATPROC = 'X'.
perform process_session.
endif.
endat.
endloop.
endform.
*&---------------------------------------------------------------------*
*&
Form UPLOAD
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
form upload tables p_tab.
v_fn = 'C:\asf\MSSAP_TAB.TXT'.
* IDC-UPGRADE - Begin of Modify - KA-001
* CALL FUNCTION 'WS_UPLOAD'
*
EXPORTING
**
CODEPAGE
= ' '
*
FILENAME
= v_fn
*
FILETYPE
= 'ASC'
**
HEADLEN
= ' '
**
LINE_EXIT
= ' '
**
TRUNCLEN
= ' '
**
USER_FORM
= ' '
**
USER_PROG
= ' '
**
DAT_D_FORMAT
= ' '
**
IMPORTING
**
FILELENGTH
=
*
TABLES
*
DATA_TAB
= p_tab
*
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
*
.
DATA L_P_FILE TYPE STRING.
TYPES: t_appoggio like LINE OF sap_tab.
DATA: tb_appoggio1 TYPE STANDARD TABLE OF t_appoggio.
L_P_FILE = v_fn.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = L_P_FILE
filetype = 'ASC'
* NDC-UPGRADE - Begin of Delete - GS-001

* HAS_FIELD_SEPARATOR = 'X'
* NDC-UPGRADE - End of Delete - GS-00
CHANGING
data_tab = TB_APPOGGIO1
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0.
p_tab[] = TB_APPOGGIO1[].
elseif sy-subrc <> 0.
message e398(00) with 'Unable to Upload '
v_fn ' from the local PC'.
endif.
* IDC-UPGRADE - End of Modify - KA-001
endform.
"UPLOAD
*&---------------------------------------------------------------------*
*&
Form MATCH_MATNR
*&---------------------------------------------------------------------*
form match_matnr using
p_itemcode
p_matnr.
concatenate p_itemcode+0(2) '/'

p_itemcode+2(2) into p_matnr.

endform.

"MATCH_MATNR

*&---------------------------------------------------------------------*
*&
Form BDC_OPEN
*&---------------------------------------------------------------------*
form bdc_open.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT
= SY-MANDT
*
DEST
= FILLER8
GROUP
= v_group
*
HOLDDATE
= FILLER8
KEEP
= 'X'
USER
= sy-uname
*
RECORD
= FILLER1
*
IMPORTING
*
QID
=
EXCEPTIONS
CLIENT_INVALID
= 1
DESTINATION_INVALID = 2
GROUP_INVALID
= 3
GROUP_IS_LOCKED
= 4
HOLDDATE_INVALID
= 5
INTERNAL_ERROR
= 6
QUEUE_ERROR
= 7
RUNNING
= 8
SYSTEM_LOCK_ERROR
= 9
USER_INVALID
= 10
OTHERS
= 11
.

IF SY-SUBRC <> 0.
MESSAGE E398(00) WITH 'Unable to open group for BDC'.
ENDIF.
endform.

"BDC_OPEN

*&---------------------------------------------------------------------*
*&
Form FILL_BDC_TAB
*&---------------------------------------------------------------------*
form fill_bdc_tab using
p_dynbegin
p_name
p_value.
if p_dynbegin = 'X'.
clear bdc_tab.
move: p_name to bdc_tab-program,
p_value to bdc_tab-dynpro,
'X'
to bdc_tab-dynbegin.
append bdc_tab.
else.
clear bdc_tab.
move: p_name to bdc_tab-fnam,
p_value to bdc_tab-fval.
append bdc_tab.
endif.
endform.

"FILL_BDC_TAB

*&---------------------------------------------------------------------*
*&
Form BDC_INSERT
*&---------------------------------------------------------------------*
form bdc_insert using
value(p_0049).
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE
= p_0049
*
POST_LOCAL
= NOVBLOCAL
*
PRINTING
= NOPRINT
TABLES
DYNPROTAB
= bdc_tab
EXCEPTIONS
INTERNAL_ERROR
= 1
NOT_OPEN
= 2
QUEUE_ERROR
= 3
TCODE_INVALID
= 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS
= 7
.
IF SY-SUBRC <> 0.
MESSAGE E398(00) WITH 'Unable to Insert the BDC'.
ENDIF.
refresh bdc_tab.
clear bdc_tab.

endform.

"BDC_INSERT

*&---------------------------------------------------------------------*
*&
Form BDC_CLOSE
*&---------------------------------------------------------------------*
form bdc_close.
call function 'BDC_CLOSE_GROUP'.
endform.

"BDC_CLOSE

*&---------------------------------------------------------------------*
*&
Form PROCESS_SESSION
*&---------------------------------------------------------------------*
form process_session.
submit rsbdcsub exporting list to memory
with mappe eq v_group
with z_verarb eq 'X'
with logall
eq 'X'
and return.
endform.
*&---------------------------------------------------------------------*
*&
Form UNIX_UPLOAD
*&---------------------------------------------------------------------*
form unix_upload tables
p_sap_tab.
data : begin of result occurs 0,
result(100),
end of result.
call function 'FILE_GET_NAME'
exporting
CLIENT
= SY-MANDT
logical_filename
= 'ASF_DATA_FILES_DOWNLOAD'
OPERATING_SYSTEM
= SY-OPSYS
PARAMETER_1
= 'mssap_tab.txt'
IMPORTING
FILE_NAME
= v_filename
EXCEPTIONS
FILE_NOT_FOUND
= 1
OTHERS
= 2
.
CALL FUNCTION 'Z_UPLOAD_UNIX_FILE'
EXPORTING
FILENAME
= v_filename
*
IMPORTING
*
NORECS
=
TABLES
FILETAB
= p_sap_tab
EXCEPTIONS
FILE_NOT_FOUND = 1
FILE_CANT_OPEN = 2
OTHERS
= 3
.
*
if sy-subrc <> 0.

*
*
*
*

message e398(00) with 'Unable to Upload MSSAP_TAB from UNIX'.


endif.
if sy-opsys = 'Windows NT'.
changes by salim siraji (21/02/2007) for physical path changes
req by appl. support manager
concatenate 'move v:\input\mssap_tab.txt v:\backup\mssap_tab'
sy-datum '.' sy-uzeit '.txt' into v_windows_com.

* changes by salim siraji (28/02/2007) for rectification of physical


*path changes
*
concatenate 'move \\input\mssap_tab.txt \\backup\mssap_tab'
*
sy-datum '.' sy-uzeit '.txt' into v_windows_com.
v_filename_mov = v_filename .
*find 'input' in v_filename_mov .
search v_filename_mov for 'input' .
v_filename_mov+sy-fdpos = '' .
CONCATENATE 'move' v_filename v_filename_mov
into v_windows_com
separated by space.
concatenate v_windows_com 'backup\mssap_tab'
sy-datum '.' sy-uzeit '.txt' into v_windows_com.

*
*

CALL FUNCTION 'Z_EXECUTE_UNIX_COMMAND'


EXPORTING
COMMAND
= v_windows_com
IMPORTING
NORECS
=
TABLES
RESULT
= result
EXCEPTIONS
COMMAND_NOT_SUCCESSFUL = 1
OTHERS
= 2
.
if sy-subrc <> 0.
message e398(00) with 'Unable to Backup the file MSSAP_TAB in WINDOWS NT'

endif.
else.
concatenate 'mssap_tab' sy-datum '.' sy-uzeit '.txt'
into v_command.
concatenate 'mv /home/abap/asf/input/mssap_tab.txt'
' /home/abap/asf/backup/' v_command into v_command.
CALL FUNCTION 'Z_EXECUTE_UNIX_COMMAND'
EXPORTING
COMMAND
= v_command
*
IMPORTING
*
NORECS
=
TABLES
RESULT
= result
EXCEPTIONS
COMMAND_NOT_SUCCESSFUL = 1
OTHERS
= 2

if sy-subrc <> 0.
message e398(00) with 'Unable to Backup the file MSSAP_TAB in UNIX'.
endif.
endif.
endform.
" UNIX_UPLOAD

3: Maintain Billing Due List - VF04 - program ZVASFI0020


report zvasfi0020 .
*======================================================================*
* AUTHOR
: M N Srinivasan
* DATE WRITTEN : July 2000 Modified January 2001
* APPLICATION : SD-POS
* FUNCTION
: Creation of Delivery and Invoice through upload of
*
*
data from Telxon
*======================================================================*
*======================================================================*
***************************** TABLES ***********************************
*======================================================================*
tables: vbco7, rv60a.
data
data

: gt_fvkdfi like vkdfif occurs 50 with header line.


: zvposi08_pro like zvposi08_pro occurs 0 with header line.

data

: begin of bdc_tab occurs 200.


include structure bdcdata.
: end
of bdc_tab.

data

ranges : s_kunnr
s_lland
s_fkart
s_sortkri

for
for
for
for

vbco7-kunnr,
vbco7-lland,
vbco7-fkart,
vbco7-sortkri.

*======================================================================*
**************************** Variables *********************************
*======================================================================*
data: v_lin
like sy-tabix,
v_date like sy-datum,
v_group like apqi-groupid.
*======================================================================*
************************* Select Options *******************************
*======================================================================*
select-options: s_vtweg
s_spart
s_vstel
s_vbeln

for
for
for
for

vbco7-vtweg
vbco7-spart
vbco7-vstel
vbco7-vbeln

no-display,
no-display,
no-display,
no-display.

selection-screen begin of block num1


with frame title text-001.
parameters: p_atproc

as

checkbox default 'X'.

selection-screen end of block num1.


*======================================================================*
************************ Start Of Selection ****************************
*======================================================================*

start-of-selection.
select * from zvposi08_pro into table zvposi08_pro
where ROUTE = 'ASF'.
sort zvposi08_pro by BRANCH.
describe table zvposi08_pro lines v_lin.
read table zvposi08_pro index 1.
s_vstel-low = zvposi08_pro-BRANCH.
read table zvposi08_pro index v_lin.
s_vstel-high = zvposi08_pro-BRANCH.
s_vstel-sign = 'I'.
s_vstel-option = 'BT'.
append s_vstel.
vbco7-name_dazu = 'X'.
vbco7-allel
= 'X'.
call function 'RV_READ_INVOICE_INDEX'
exporting
comwa
= vbco7
no_billing_block
= vbco7-no_faksk
default_billing_type = rv60a-fkart
tables
lvkdfi
= gt_fvkdfi
s_kunnr
= s_kunnr
s_vbeln
= s_vbeln
s_lland
= s_lland
s_fkart
= s_fkart
s_sortkri
= s_sortkri
s_vtweg
= s_vtweg
s_spart
= s_spart
s_vstel
= s_vstel
exceptions
others
= 1.
perform bdc_open.
loop at gt_fvkdfi.
v_date = gt_fvkdfi-fkdat.
write v_date to gt_fvkdfi-fkdat.
perform fill_bdc_tab using: 'X' 'SAPMV60A' '0102',
' ' 'RV60A-FKDAT'
gt_fvkdfi-fkdat,
' ' 'KOMFK-VBELN(01)' gt_fvkdfi-vbeln,
' ' 'BDC_OKCODE'
'=FAKT',
'X' 'SAPMV60A'
'0104',
' ' 'BDC_OKCODE'
'=SICH'.
perform bdc_insert using 'VF01'.
endloop.
perform bdc_close.
if p_atproc eq 'X'.
perform submit_session.
if sy-subrc <> 0.

message e398(00) WITH 'Unable to process the session' v_group.


endif.
endif.
*======================================================================*
************************** End Of Selection ****************************
*======================================================================*
end-of-selection
.
*&---------------------------------------------------------------------*
*&
Form BDC_OPEN
*&---------------------------------------------------------------------*
form bdc_open.
concatenate 'BILL' sy-datum+4(4) sy-uzeit+0(4) into v_group.
skip.
write:/ 'SESSION NAME :',v_group.
skip.

*
*
*
*
*

CALL FUNCTION 'BDC_OPEN_GROUP'


EXPORTING
CLIENT
= SY-MANDT
DEST
= FILLER8
GROUP
= v_group
HOLDDATE
= FILLER8
KEEP
= 'X'
USER
= sy-uname
RECORD
= FILLER1
IMPORTING
QID
=
EXCEPTIONS
CLIENT_INVALID
= 1
DESTINATION_INVALID = 2
GROUP_INVALID
= 3
GROUP_IS_LOCKED
= 4
HOLDDATE_INVALID
= 5
INTERNAL_ERROR
= 6
QUEUE_ERROR
= 7
RUNNING
= 8
SYSTEM_LOCK_ERROR
= 9
USER_INVALID
= 10
OTHERS
= 11
.
IF SY-SUBRC <> 0.
MESSAGE E398(00) WITH 'Unable to open group for BDC'.
ENDIF.

endform.

"BDC_OPEN

*&---------------------------------------------------------------------*
*&
Form FILL_BDC_TAB
*&---------------------------------------------------------------------*
form fill_bdc_tab using
p_dynbegin
p_name
p_value.

if p_dynbegin = 'X'.
clear bdc_tab.
move: p_name to bdc_tab-program,
p_value to bdc_tab-dynpro,
'X'
to bdc_tab-dynbegin.
append bdc_tab.
else.
clear bdc_tab.
move: p_name to bdc_tab-fnam,
p_value to bdc_tab-fval.
append bdc_tab.
endif.
endform.

"FILL_BDC_TAB

*&---------------------------------------------------------------------*
*&
Form BDC_INSERT
*&---------------------------------------------------------------------*
form bdc_insert using
value(p_0049).
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE
= P_0049
*
POST_LOCAL
= NOVBLOCAL
*
PRINTING
= NOPRINT
TABLES
DYNPROTAB
= BDC_TAB
EXCEPTIONS
INTERNAL_ERROR
= 1
NOT_OPEN
= 2
QUEUE_ERROR
= 3
TCODE_INVALID
= 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS
= 7
.
IF SY-SUBRC <> 0.
MESSAGE E398(00) WITH 'Unable to Insert the BDC'.
ENDIF.
refresh bdc_tab.
clear bdc_tab.
endform.

"BDC_INSERT

*&---------------------------------------------------------------------*
*&
Form BDC_CLOSE
*&---------------------------------------------------------------------*
form bdc_close.
call function 'BDC_CLOSE_GROUP'.
endform.

"BDC_CLOSE

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

*
Form SUBMIT_SESSION
*
*---------------------------------------------------------------------*
form submit_session.
submit rsbdcsub exporting list to memory
with mappe eq v_group
with z_verarb eq 'X'
with logall
eq 'X'
and return.
endform.

Payment Processing - Program ZVPROI0140ASF


REPORT ZVPROI0140ASF.
*=====================================================================*
* AUTHOR
: AMHUSSAIN
*
* DATE WRITTEN : 28th Mar-16.
*
* APPLICATION : SD-POS
*
* FUNCTION
: Creation of Payments (Copy of ZVPOSI0140MS)
*
*=====================================================================*
********************************************************************
* Change id : KA-001
* Author
: Kumar Ankit
* Date
: 24/05/2012
* CR
: FD9K900007
* Description: AFG Upgrade Syntax Check and Unicode adjustment
* Team
: IDC-UPGRADE
********************************************************************
*=====================================================================*
***************************** TABLES **********************************
*======================================================================
TABLES: bkpf,
vbrk.
*
DATA: BEGIN OF bdc_tab OCCURS 0.
INCLUDE STRUCTURE bdcdata.
DATA: END
OF bdc_tab.
*
DATA: BEGIN OF pay_tab OCCURS 0,
branch(4)
TYPE c,
"branch code
* Remarked by MOF for 16 Characters
*
vbeln(12)
TYPE c,
"invoice no
vbeln(16)
TYPE c,
"invoice no
* End of Remark MOF for 16 Char
fkdat(8)
TYPE c,
"Invoice date
invtyp(1)
TYPE c,
"Invoice type
kunnr(10)
TYPE c,
"Customer code

route(4)
salnum(10)
journey(11)
value(10)
fn(25)
docref
END
OF pay_tab.

TYPE
TYPE
TYPE
TYPE
TYPE
LIKE

c,
c,
c,
c,
c,
bkpf-xblnr,

"SAP route code


"Salesman AR code
"Settlement number
"Value
"filename

*
DATA: BEGIN OF inv_tab OCCURS 0,
bukrs
LIKE vbrk-bukrs,
vbeln
LIKE vbrk-vbeln,
kunrg
LIKE vbrk-kunrg,
END
OF inv_tab.
*
DATA: BEGIN OF acc_tab OCCURS 0,
bukrs
LIKE bkpf-bukrs,
belnr
LIKE bkpf-belnr,
xblnr
LIKE bkpf-xblnr,
END
OF acc_tab.
*
DATA: BEGIN OF result OCCURS 0,
result(100)
TYPE c,
END
OF result.
*=====================================================================*
*************************** VARIABLES *********************************
*=====================================================================*
DATA: v_bldat(10)
TYPE c,
v_datum
LIKE sy-datum,
v_wrbtr(13)
TYPE c,
v_docno(10)
TYPE c,
v_sname
LIKE apqi-groupid,
v_line
LIKE sy-tabix,
v_ref(30)
TYPE c,
v_command(255)
TYPE c,
v_filename
LIKE filename-fileextern,
v_filename_mov(255),
v_windows_com(255),
v_waers
LIKE bkpf-waers.
*=====================================================================*
*********************** SELECTION SCREEN ******************************
*=====================================================================*
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
PARAMETERS: p_upload
AS CHECKBOX,
p_atproc
AS CHECKBOX,
p_fkart
LIKE vbrk-fkart DEFAULT 'ZF2B'
OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK blk1.
*=====================================================================*
********************* START-OF-SELECTION ******************************
*=====================================================================*
START-OF-SELECTION.
* upload payments

*
*
*
*

IF p_upload = 'X' .
PERFORM upload_pay_tab.
ELSE.
PERFORM unix_upload TABLES pay_tab.
ENDIF.
set reference
LOOP AT pay_tab.
Remarked by MOF for 16 Characters
CONCATENATE 'CS' pay_tab-vbeln+1(15) INTO pay_tab-docref.
CONCATENATE 'CS' pay_tab-vbeln+1(11) INTO pay_tab-docref.
end of Remark MOF for 16 char
MODIFY pay_tab.
ENDLOOP.
find invoices (using reference)
SELECT bukrs vbeln kunrg INTO CORRESPONDING FIELDS OF TABLE inv_tab
FROM vbrk
FOR ALL ENTRIES IN pay_tab
WHERE fkart = p_fkart AND
xblnr = pay_tab-docref.
IF sy-subrc <> 0.
MESSAGE i398(00) WITH 'No matching billing documents found '
'for all payments this run'.
PERFORM download_paytab_table.
PERFORM print_unposted_invoices.
EXIT.
ENDIF.
find accounting documents (released billing documents)
SELECT bukrs belnr xblnr INTO CORRESPONDING FIELDS OF TABLE acc_tab
FROM bkpf
FOR ALL ENTRIES IN inv_tab
WHERE bukrs = inv_tab-bukrs AND
belnr = inv_tab-vbeln.
IF sy-subrc <> 0.
MESSAGE i398(00) WITH 'No released accounting documents found '
'for all payments this run'.
PERFORM download_paytab_table.
PERFORM print_unposted_invoices.
EXIT.
ENDIF.
produce BDC session for incoming payment
PERFORM bdc_open.
LOOP AT pay_tab.
find accounting document
READ TABLE acc_tab WITH KEY xblnr = pay_tab-docref.
IF sy-subrc <> 0.
WRITE: / pay_tab-branch,
pay_tab-vbeln,
pay_tab-fkdat,
pay_tab-kunnr,
pay_tab-route,
pay_tab-salnum,
pay_tab-journey,

pay_tab-value,
pay_tab-fn,
pay_tab-docref.

CONTINUE.
ENDIF.
find billing document
READ TABLE inv_tab WITH KEY vbeln = acc_tab-belnr.
IF sy-subrc <> 0.
MESSAGE e398(00) WITH 'Unable to read INV_TAB with key '
acc_tab-belnr.
ENDIF.
set display variables
v_datum = pay_tab-fkdat.
WRITE v_datum TO v_bldat.
WRITE pay_tab-value TO v_wrbtr.
IF pay_tab-branch = '1190'.
v_waers = 'AED'.
ELSEIF pay_tab-branch = '1181'.
v_waers = 'OMR'.
ELSE.
v_waers = 'SAR'.
ENDIF.

fill BDC table


PERFORM fill_bdc_tab USING: 'X'
' '
' '
' '
' '
' '
' '
' '
' '
' '
' '
' '
' '
' '
' '
'X'
' '
' '
'X'
' '
'X'
' '
' '
PERFORM bdc_insert.
DELETE pay_tab.
ENDLOOP.

'SAPMF05A'
'0103',
'BKPF-BLDAT'
v_bldat,
'BKPF-BUDAT'
v_bldat,
'BKPF-BUKRS'
inv_tab-bukrs,
'BKPF-BLART'
'DZ',
'BKPF-WAERS'
v_waers,
'BKPF-XBLNR'
pay_tab-docref,
'RF05A-KONTO'
'102000',
'BSEG-WRBTR'
v_wrbtr,
'BSEG-VALUT'
' ',
'BSEG-SGTXT'
'X',
'BSEG-ZUONR'
pay_tab-branch,
'RF05A-AGKON'
inv_tab-kunrg,
'RF05A-XPOS1(03)' 'X',
'BDC_OKCODE'
'=PA',
'SAPMF05A'
'0731',
'RF05A-SEL01(01)' acc_tab-belnr,
'BDC_OKCODE'
'=PA',
'SAPDF05X'
'3100',
'BDC_OKCODE'
'=PART',
'SAPDF05X'
'3100',
'DF05B-PSZAH(01)' v_wrbtr,
'BDC_OKCODE'
'=BU'.

PERFORM bdc_close.
PERFORM download_paytab_table.
* submit BDC session
IF p_atproc = 'X'.
PERFORM submit_session.
ENDIF.
*
*
*
*=====================================================================*
* Form: Upload_Pay_Tab
*
*=====================================================================*
FORM upload_pay_tab.
*
* IDC-UPGRADE - Begin of Modify - KA-001
* CALL FUNCTION 'WS_UPLOAD'
*
EXPORTING
*
filename
= 'C:\van\MSPAY_TAB.TXT'
*
filetype
= 'ASC'
*
TABLES
*
data_tab
= pay_tab
*
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.
DATA L_P_FILE TYPE STRING.
TYPES: t_appoggio like LINE OF pay_tab.
DATA: tb_appoggio1 TYPE STANDARD TABLE OF t_appoggio.
L_P_FILE = 'C:\asf\MSPAY_TAB.TXT'.

CALL METHOD cl_gui_frontend_services=>gui_upload


EXPORTING
filename = L_P_FILE
filetype = 'ASC'
* HAS_FIELD_SEPARATOR = 'X' " Remarked by Mohamed Omer Farook for Upload fro
m workstation.
HAS_FIELD_SEPARATOR = ' '
CHANGING
data_tab = TB_APPOGGIO1
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0.

pay_tab[] = TB_APPOGGIO1[].
elseIF sy-subrc <> 0.
MESSAGE e398(00) WITH 'Unable to Upload the Payment file'
' from C:\van\MSPAY_TAB.TXT'.
ENDIF.
* IDC-UPGRADE - End of Modify - KA-001
*
ENDFORM.
"upload_pay_tab
*
*
*
*=====================================================================*
* Form: Unix_Upload
*
*=====================================================================*
FORM unix_upload TABLES pay_tab.
*
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
client
= sy-mandt
logical_filename = 'ASF_DATA_FILES_DOWNLOAD'
operating_system = sy-opsys
parameter_1
= 'mspay_tab.txt'
IMPORTING
file_name
= v_filename
EXCEPTIONS
file_not_found
= 1
OTHERS
= 2.
* recycle payment table
CALL FUNCTION 'Z_UPLOAD_UNIX_FILE'
EXPORTING
filename
= v_filename
TABLES
filetab
= pay_tab
EXCEPTIONS
file_not_found = 1
file_cant_open = 2.
IF sy-subrc <> 0.
MESSAGE e398(00) WITH 'Unable to Upload the Payment file'
' from /home/abap/asf/input/mspay_tab.txt'.
ENDIF.
IF sy-opsys = 'Windows NT'.
* changes by salim siraji (21/02/2007) for physical path changes
* req by appl. support manager
*
CONCATENATE 'move v:\input\mspay_tab.txt v:\backup\mspay_tab'
*
sy-datum '.' sy-uzeit '.txt' INTO v_windows_com.

* changes by salim siraji (28/02/2007) for rectification of physical


*path changes

*
*
*

CONCATENATE 'move \\input\mspay_tab.txt \\backup\mspay_tab'


sy-datum '.' sy-uzeit '.txt' INTO v_windows_com.

v_filename_mov = v_filename .
SEARCH v_filename_mov FOR 'input' .
v_filename_mov+sy-fdpos = '' .
CONCATENATE 'move' v_filename v_filename_mov
INTO v_windows_com
SEPARATED BY space.
CONCATENATE v_windows_com 'backup\mspay_tab'
sy-datum '.' sy-uzeit '.txt' INTO v_windows_com.
*
CALL FUNCTION 'Z_EXECUTE_UNIX_COMMAND'
EXPORTING
command
= v_windows_com
TABLES
RESULT
= RESULT
exceptions
command_not_successful = 1
OTHERS
= 2.
IF sy-subrc <> 0.
MESSAGE e398(00) WITH 'Unable to move the payment file to '
'/home/abap/van/backup/'.
ENDIF.
ELSE.
CONCATENATE 'mspay_tab' sy-datum '.' sy-uzeit '.txt'
INTO v_command.
CONCATENATE 'mv /home/abap/asf/input/mspay_tab.txt'
' /home/abap/asf/backup/' v_command INTO v_command.
* backup payment table
CALL FUNCTION 'Z_EXECUTE_UNIX_COMMAND'
EXPORTING
command
= v_command
TABLES
RESULT
= RESULT
exceptions
command_not_successful = 1
OTHERS
= 2.
IF sy-subrc <> 0.
MESSAGE e398(00) WITH 'Unable to move the payment file to '
'/home/abap/asf/backup/'.
ENDIF.
ENDIF.
*
ENDFORM.
"unix_upload
*

*
*
*=====================================================================*
* Form: BDC_Open
*
*=====================================================================*
FORM bdc_open.
*
CONCATENATE 'ASFPYMT' sy-datum+4(4) sy-uzeit+0(4) INTO v_sname.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client
= sy-mandt
group
= v_sname
keep
= 'X'
user
= sy-uname
EXCEPTIONS
client_invalid
= 1
destination_invalid = 2
group_invalid
= 3
group_is_locked
= 4
holddate_invalid
= 5
internal_error
= 6
queue_error
= 7
running
= 8
system_lock_error
= 9
user_invalid
= 10
OTHERS
= 11.
IF sy-subrc <> 0.
MESSAGE e398(00) WITH 'Unable to open group for BDC'.
ENDIF.
*
ENDFORM.
"bdc_open
*
*
*
*=====================================================================*
* Form: Fill_BDC_Tab
*
*=====================================================================*
FORM fill_bdc_tab USING
p_dynbegin
p_name
p_value.
*
IF p_dynbegin = 'X'.
CLEAR bdc_tab.
MOVE: p_name TO bdc_tab-program,
p_value TO bdc_tab-dynpro,
'X'
TO bdc_tab-dynbegin.
APPEND bdc_tab.
ELSE.
CLEAR bdc_tab.
MOVE: p_name TO bdc_tab-fnam,
p_value TO bdc_tab-fval.
APPEND bdc_tab.

ENDIF.
*
ENDFORM.
"fill_bdc_tab
*
*
*
*=====================================================================*
* Form: BDC_Insert
*
*=====================================================================*
FORM bdc_insert.
*
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode
= 'F-28'
TABLES
dynprotab
= bdc_tab
EXCEPTIONS
internal_error
= 1
not_open
= 2
queue_error
= 3
tcode_invalid
= 4
printing_invalid = 5
posting_invalid = 6
OTHERS
= 7.
IF sy-subrc <> 0.
MESSAGE e398(00) WITH 'Unable to Insert the BDC'.
ENDIF.
*
REFRESH bdc_tab.
CLEAR bdc_tab.
*
ENDFORM.
"bdc_insert
*
*
*
*=====================================================================*
* Form: BDC_Close
*
*=====================================================================*
FORM bdc_close.
*
CALL FUNCTION 'BDC_CLOSE_GROUP'.
*
ENDFORM.
"bdc_close
*
*
*
*=====================================================================*
* Form: Download_PayTab_Table
*
*=====================================================================*
FORM download_paytab_table.
*
IF p_upload = 'X'.

* IDC-UPGRADE - Begin of Modify - KA-001


*
CALL FUNCTION 'WS_DOWNLOAD'
*
EXPORTING
*
filename
= 'C:\van\MSPAY_TAB.TXT'
*
filetype
= 'ASC'
*
mode
= ' '
"Overwrite mode
*
TABLES
*
data_tab
= pay_tab
*
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.
data: gd_file type string.
types: t_uctable like line of pay_tab.
data: it_uctable type standard table of t_uctable.
gd_file = 'C:\asf\MSPAY_TAB.TXT'.
it_uctable[] = pay_tab[].

CALL METHOD cl_gui_frontend_services=>gui_download


EXPORTING
filename = gd_file
filetype = 'ASC'
Append = ' '
CHANGING
data_tab = it_uctable
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE e398(00) WITH 'Unable to download PAY_TAB to '
'C:\asf\MSPAY_TAB.TXT'.
ENDIF.
* IDC-UPGRADE - End of Modify - KA-001
ELSE.
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
client
= sy-mandt
logical_filename = 'ASF_DATA_FILES_DOWNLOAD'
operating_system = sy-opsys
parameter_1
= 'mspay_tab.txt'
IMPORTING

file_name
= v_filename
EXCEPTIONS
file_not_found
= 1
OTHERS
= 2.
CALL FUNCTION 'Z_DOWNLOAD_UNIX_FILE'
EXPORTING
filename
= v_filename
TABLES
filetab
= pay_tab
EXCEPTIONS
file_not_found = 1
file_cant_open = 2
OTHERS
= 3.
IF sy-subrc <> 0.
MESSAGE e398(00) WITH 'Unable to download the payment file to '
'/home/abap/asf/input/mspay_tab.txt'.
ENDIF.
ENDIF.
*
ENDFORM.
"download_paytab_table
*
*
*
*=====================================================================*
* Form: Print_Unposted_Invoices
*
*=====================================================================*
FORM print_unposted_invoices.
*
LOOP AT pay_tab.
WRITE: / pay_tab-branch,
pay_tab-vbeln,
pay_tab-fkdat,
pay_tab-kunnr,
pay_tab-route,
pay_tab-salnum,
pay_tab-journey,
pay_tab-value,
pay_tab-fn,
pay_tab-docref.
ENDLOOP.
*
ENDFORM.
"print_unposted_invoices
*
*
*
*=====================================================================*
* Form: Submit_Session
*
*=====================================================================*
FORM submit_session.
*
SUBMIT rsbdcsub EXPORTING LIST TO MEMORY
WITH mappe
= v_sname

WITH z_verarb = 'X'


WITH logall
= 'X'
AND RETURN.
*
ENDFORM.

"submit_session