‎2008 Jul 10 5:33 AM
Hi folks,
I have to validate the entris in my flat file before passing it to the BDC.I have a RATE field as 5th field. How to check whther the 5th field contains valid RATE values.We cannot check the entries from the table. Becaus we can give even new entries here. I think we have to check the data type. Could any body let me know, how to check this..Thansk in advance..
Ram.
‎2008 Jul 10 5:40 AM
Hi Ram,
Design a Selection screen which has a table control, Put the fields onto it. And also place some buttons like INSERT , DELETE EXIT on the selection screen.
Where INSERT is to INSERT the records into the database.
DELETE is to DELETE the record which has wrong entry.
EXIT is to exit from the screen.
Use the Call transaction method with MODE as 'A' and check the records. and then insert into the database. This solves the issue.
Regards,
Swapna.
‎2008 Jul 10 5:46 AM
hi when you get the records from flat file and split and put into ur internal table structure... validate that 5th field before appending into the internal table..
split wa_flat into
wa_f1 wa_f2 wa_f3...
at '|'.
validate 5th record here...
append wa to itab.
‎2008 Jul 10 5:49 AM
hi
i have same done for FB60.(validating the flat file)
check these code
report ZZFB60 no standard page heading
line-size 550.
&----
*& Database Tables Declaration
&----
tables: t100, "Messages
lfa1, "Vendor Master (General Section)
lfb1, "Vendor Master (Company Code)
skb1, "G/L account master (company code)
lfbw, "Vendor master record (withholding tax types) X
csks, "Cost Center Master Data
bkpf, "Accounting Document Header
bseg, "Accounting Document Segment
usr02, "Logon data
bsip. "Index for Vendor Validation of Double Documents
&----
*& Selection Screen
&----
selection-screen begin of block b1 with frame.
parameters : p_file1 like rlgrap-filename obligatory,
p_doctyp like invfo-blart obligatory,
p_invdat like invfo-bldat obligatory,
p_posdat like invfo-budat obligatory.
selection-screen end of block b1.
skip 2.
selection-screen begin of block b2 with frame.
parameters :ZTEST RADIOBUTTON GROUP radi default 'X' user-command chang,
ZRUN RADIOBUTTON GROUP radi.
selection-screen end of block b2.
skip 2.
selection-screen begin of block b3 with frame title text-002.
parameters : SUCCREC RADIOBUTTON GROUP rad1 modif id Z1,
ERRORLOG RADIOBUTTON GROUP rad1 modif id Z1.
selection-screen end of block b3.
&----
*& Constants Declaration
&----
CONSTANTS : C_TRANS_FB60(4) VALUE 'FB60'.
&----
*& Variables Declaration
&----
data : v_name like lfa1-name1,
v_belnr like bseg-belnr,
v_username type char12,
v_kostl like csks-kostl.
data : day type char2,
month type char2,
year type char4,
date1 type char10,
date2 type char10.
data : c1(8) type c value '.txt',
cnt(2) TYPE n,
cnt1 type i,
fld(25) TYPE c,
fld2(67) type c,
flag type c.
data : v_belnr1 like bseg-belnr,
amount like bseg-wrbtr,
totalamount like bseg-wrbtr.
data : MESSG TYPE STRING.
&----
*& Internal Tables Declaration
&----
data : begin of t_record occurs 0,
BUKRS(004),
ACCNT(010),
XBLNR(016),
WRBTR1(016),
WAERS(005),
SECCO(004) ,
SGTXT(050),
HKONT(010),
WRBTR2(017),
MWSKZ(002),
GSBER(004),
KOSTL(010),
end of t_record.
data : begin of error_record occurs 0,
ROWNO type i,
BUKRS(004),
ACCNT(010),
XBLNR(016),
WRBTR1(016),
WAERS(005),
SECCO(004) ,
SGTXT(020),
HKONT(010),
WRBTR2(017),
MWSKZ(002),
GSBER(004),
KOSTL(010),
text1(50),
text2(55),
text3(50),
text4(50),
text5(70),
text6(50),
flag,
end of error_record.
data : n_record like error_record occurs 0 with header line,
f_record like error_record occurs 0 with header line.
data : WA_BDCMSGCOLL TYPE BDCMSGCOLL.
data : begin of t_head occurs 0,
BUKRS(004), "Company Code
ACCNT(010), "Account or Vendor
XBLNR(016), "Reference
WRBTR1(017), "Amount in document currency
WAERS(005), "Currency
SECCO(004), "Section Code
SGTXT(050), "Text
end of t_head.
data : begin of error_head1 occurs 0,
BUKRS(004), "Company Code
ACCNT(010), "Account or Vendor
XBLNR(016), "Reference
WRBTR1(017), "Amount in document currency
WAERS(005), "Currency
SECCO(004), "Section Code
SGTXT(050), "Text
messtyp type char1,
MESSG type char256,
end of error_head1.
data : succ_head like t_head occurs 0 with header line,
error_head like t_head occurs 0 with header line.
data : begin of t_item occurs 0,
ACCNT(010), "Account
XBLNR(016), "Reference
WRBTR1(017), "Amount in document currency
HKONT(010), "GL Account
WRBTR2(017), "Line item Amount in document currency
MWSKZ(002), "Tax Code
GSBER(004), " Business Area
KOSTL(010), "Cost centre
end of t_item.
data : IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,
IT_BDC_MESSAGES LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
&----
*& At Selection-Screen
&----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.
PERFORM file_selection.
AT SELECTION-SCREEN ON p_file1.
if p_file1 CS c1.
PERFORM data_upload.
else.
message e303(ME) with 'File is not with .TXT extension'.
endif.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'Z1'.
IF zrun = 'X'.
SCREEN-INPUT = 1.
ELSE.
SCREEN-INPUT = 0.
ENDIF.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
&----
*& Start-of-Selection
&----
start-of-selection.
PERFORM date.
PERFORM validate.
if ZTEST = 'X'.
PERFORM header.
PERFORM disperrortestrun.
endif.
if ZRUN = 'X'.
PERFORM head_item.
PERFORM form_bdcbenerate.
if SUCCREC = 'X'.
PERFORM dispsuccrec.
endif.
if ERRORLOG = 'X'.
PERFORM disperrorrec.
endif.
endif.
End-of-selection.
----
Mappping *
----
form form_bdcbenerate.
refresh error_head.
refresh succ_head.
loop at t_head.
REFRESH : IT_BDCDATA,IT_BDC_MESSAGES.
CLEAR :IT_BDCDATA, IT_BDC_MESSAGES, WA_BDCMSGCOLL..
perform bdc_dynpro using 'SAPLACHD' '1000'.
perform bdc_field using 'BDC_OKCODE' '=ENTR'.
perform bdc_field using 'BKPF-BUKRS' t_head-bukrs.
perform bdc_dynpro using 'SAPMF05A' '1100'.
perform bdc_field using 'BDC_OKCODE' '/00'.
perform bdc_field using 'INVFO-ACCNT' t_head-accnt.
perform bdc_field using 'INVFO-BLDAT' date1.
perform bdc_field using 'INVFO-BUDAT' date2.
perform bdC_field using 'INVFO-BLART' p_doctyp.
perform bdc_field using 'INVFO-XBLNR' t_head-xblnr.
perform bdc_field using 'INVFO-WRBTR' t_head-wrbtr1.
perform bdc_field using 'INVFO-WAERS' t_head-waers.
perform bdc_field using 'INVFO-SECCO' t_head-secco.
perform bdc_field using 'INVFO-SGTXT' t_head-sgtxt.
cnt = 1.
cnt1 = 1.
loop at t_item where accnt = t_head-accnt
and xblnr = t_head-xblnr
and wrbtr1 = t_head-wrbtr1.
if cnt1 gt 1.
CONCATENATE 'ACGL_ITEM-MARKSP(' cnt ')' INTO fld.
perform bdc_field using fld 'X'.
perform bdc_dynpro using 'SAPMF05A' '1100'.
perform bdc_field using 'BDC_OKCODE' '=0005'.
endif.
perform bdc_dynpro using 'SAPMF05A' '1100'.
perform bdc_field using 'BDC_OKCODE' '/00'.
CONCATENATE 'ACGL_ITEM-HKONT(' cnt ')' INTO fld.
perform bdc_field using fld t_item-hkont.
CONCATENATE 'ACGL_ITEM-WRBTR(' cnt ')' INTO fld.
perform bdc_field using fld t_item-wrbtr2.
CONCATENATE 'ACGL_ITEM-MWSKZ(' cnt ')' INTO fld.
perform bdc_field using fld t_item-mwskz.
CONCATENATE 'ACGL_ITEM-GSBER(' cnt ')' INTO fld.
perform bdc_field using fld t_item-gsber.
CONCATENATE 'ACGL_ITEM-KOSTL(' cnt ')' INTO fld.
perform bdc_field using fld t_item-kostl.
perform bdc_field using 'BDC_CURSOR' fld.
cnt1 = cnt1 + 1.
endloop.
perform bdc_dynpro using 'SAPMF05A' '1100'.
perform bdc_field using 'BDC_OKCODE'
'=BS'.
perform bdc_dynpro using 'SAPMSSY0' '0120'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
&----
*& Calling Transaction FB60
&----
CALL TRANSACTION C_TRANS_FB60 USING IT_BDCDATA mode 'N'
update 'S'
MESSAGES INTO IT_BDC_MESSAGES.
if sy-subrc <> 0.
MOVE-CORRESPONDING t_head TO error_head.
append error_head.
clear error_head.
*
loop at IT_BDC_MESSAGES into WA_BDCMSGCOLL.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = WA_BDCMSGCOLL-MSGID
LANG = WA_BDCMSGCOLL-MSGSPRA
NO = WA_BDCMSGCOLL-MSGNR
V1 = WA_BDCMSGCOLL-MSGV1
V2 = WA_BDCMSGCOLL-MSGV2
V3 = WA_BDCMSGCOLL-MSGV3
V4 = WA_BDCMSGCOLL-MSGV4
IMPORTING
MSG = MESSG.
IF ( WA_BDCMSGCOLL-MSGTYP = 'S' ) OR ( WA_BDCMSGCOLL-MSGTYP = 'E' )
OR ( WA_BDCMSGCOLL-MSGTYP = 'W' ) .
move-corresponding error_head to error_head1.
move-corresponding t_head to error_head1.
error_head1-messg = MESSG. "ERROR MESSAGE
error_head1-messtyp = WA_BDCMSGCOLL-MSGTYP.
APPEND error_head1.
ENDIF.
endloop.
else.
MOVE-CORRESPONDING t_head TO succ_head.
append succ_head.
clear succ_head.
endif.
endloop.
endform.
&----
*& Form data_upload
&----
FORM data_upload .
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = p_file1
FILETYPE = 'DAT'
TABLES
DATA_TAB = t_record.
ENDFORM. " data_upload
&----
*& Form file_selection
&----
FORM file_selection .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'p_file1'
IMPORTING
file_name = p_file1.
ENDFORM. " file_selection
&----
*& Form BDC_DYNPRO
&----
FORM BDC_DYNPRO using program dynpro.
CLEAR IT_BDCDATA.
IT_BDCDATA-PROGRAM = PROGRAM.
IT_BDCDATA-DYNPRO = DYNPRO.
IT_BDCDATA-DYNBEGIN = 'X'.
APPEND IT_BDCDATA.
endform.
&----
*& Form BDC_FIELD
&----
FORM bdc_field using fnam fval.
CLEAR IT_BDCDATA.
IT_BDCDATA-FNAM = FNAM.
IT_BDCDATA-FVAL = FVAL.
APPEND IT_BDCDATA.
ENDFORM.
----
FORM validate *
----
FORM validate.
delete t_record index 1.
loop at t_record.
delete t_record where accnt = ' '.
translate t_record-bukrs to upper case.
translate t_record-accnt to upper case.
translate t_record-waers to upper case.
translate t_record-xblnr to upper case.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = t_record-accnt
IMPORTING
OUTPUT = t_record-accnt.
move-corresponding t_record to n_record.
append n_record.
clear n_record.
endloop.
loop at t_record.
clear flag.
delete t_record where accnt = ' '.
vendor and company code checking.
translate t_record-accnt to upper case.
translate t_record-bukrs to upper case.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = t_record-accnt
IMPORTING
OUTPUT = t_record-accnt.
select single * from lfb1 where bukrs = t_record-bukrs
and lifnr = t_record-accnt.
if sy-subrc <> 0.
flag = 'X'.
error_record-rowno = sy-tabix + 1.
move-corresponding t_record to error_record.
error_record-text1 = 'The Vendor not Under this company Code'.
endif.
With holding liability.
select single * from lfbw where bukrs = t_record-bukrs
and lifnr = t_record-accnt
and WT_SUBJCT = 'X'.
if sy-subrc <> 0.
flag = 'X'.
error_record-rowno = sy-tabix + 1.
move-corresponding t_record to error_record.
error_record-text2 = 'The Vendor doesnt have Withholding Tax Liability'.
endif.
G/L account check with company code*
select single * from skb1 where bukrs = t_record-bukrs
and saknr = t_record-hkont.
if sy-subrc <> 0.
flag = 'X'.
error_record-rowno = sy-tabix + 1.
move-corresponding t_record to error_record.
error_record-text3 = 'The G/L acc not under the given company code'.
endif.
*cost centre checking
this FM for leading zeros
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = t_record-kostl
IMPORTING
OUTPUT = v_kostl.
select single kostl from csks into v_kostl where bukrs = t_record-bukrs
and kostl = v_kostl.
if sy-subrc <> 0.
flag = 'X'.
error_record-rowno = sy-tabix + 1.
move-corresponding t_record to error_record.
error_record-text4 = 'The costcentre not under the given company code'.
endif.
it check the invioce alredy posted or not.
translate t_record-waers to upper case.
translate t_record-xblnr to upper case.
select single belnr into v_belnr1 from bsip where bukrs = t_record-bukrs
and lifnr = t_record-accnt
and waers = t_record-waers
and bldat = p_invdat
and xblnr = t_record-xblnr.
if sy-subrc = 0.
day = p_invdat+6(2).
month = p_invdat+4(2).
year = p_invdat+0(4).
concatenate day month year into date1 SEPARATED BY '.'.
error_record-rowno = sy-tabix + 1.
move-corresponding t_record to error_record.
concatenate 'This document under number' v_belnr1 'already posted on '
date1 into fld2 separated by space.
error_record-text5 = fld2.
flag = 'X'.
endif.
*zero balance
on change of t_record-accnt or t_record-xblnr.
amount = 0.
totalamount = 0.
amount = t_record-wrbtr1.
loop at n_record where bukrs = t_record-bukrs
and accnt = t_record-accnt
and xblnr = t_record-xblnr
and wrbtr1 = t_record-wrbtr1
and waers = t_record-waers.
totalamount = totalamount + n_record-wrbtr2.
endloop.
endon.
if amount ne totalamount.
error_record-rowno = sy-tabix + 1.
move-corresponding t_record to error_record.
error_record-text6 = 'Posting only possible with zero balance'.
flag = 'X'.
endif.
if flag = 'X'.
error_record-flag = 'X'.
append error_record.
endif.
if flag <> 'X'.
move-corresponding t_record to f_record.
append f_record.
endif.
clear f_record.
clear error_record.
endloop.
endform.
&----
*& Form Table Control
&----
FORM head_item .
clear t_record.
LOOP AT t_record.
delete t_record where accnt = ' '.
translate t_record-bukrs to upper case.
translate t_record-accnt to upper case.
translate t_record-waers to upper case.
translate t_record-xblnr to upper case.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = t_record-accnt
IMPORTING
OUTPUT = t_record-accnt.
on change of t_record-accnt or t_record-xblnr or t_record-wrbtr1.
MOVE-CORRESPONDING t_record TO t_head.
APPEND t_head.
endon.
MOVE-CORRESPONDING t_record TO t_item.
APPEND t_item.
clear : t_item,t_head.
ENDLOOP.
ENDFORM.
&----
*& Download the Internal Table to Local File.
&----
form disperrorrec.
perform top-of-page1.
PERFORM diserrorrecpostrun.
endform.
&----
*& Date form
&----
FORM date.
day = p_invdat+6(2).
month = p_invdat+4(2).
year = p_invdat+0(4).
concatenate day month year into date1 SEPARATED BY '.'.
day = p_posdat+6(2).
month = p_posdat+4(2).
year = p_posdat+0(4).
concatenate day month year into date2 SEPARATED BY '.'.
ENDFORM.
&----
*& Display the errors in flat file test run
&----
form disperrortestrun.
loop at error_record.
format color 2 intensified on.
set left scroll-boundary column 70.
write : /'|',
(6) error_record-rowno, '|' no-gap,
(14) error_record-bukrs, '|' no-gap,
(12) error_record-accnt, '|' no-gap,
(16) error_record-xblnr, '|' no-gap,
(16) error_record-wrbtr1, '|' no-gap,
(8) error_record-waers, '|' no-gap,
(13) error_record-secco, '|' no-gap,
(20) error_record-sgtxt, '|' no-gap,
(14) error_record-hkont, '|' no-gap,
(15) error_record-wrbtr2, '|' no-gap,
(10) error_record-mwskz, '|' no-gap,
(20) error_record-gsber, '|' no-gap,
(12) error_record-kostl, '|' no-gap,
(5) error_record-flag, '|' no-gap,
(50) error_record-text1, '|' no-gap,
(53) error_record-text2, '|' no-gap,
(50) error_record-text3, '|' no-gap,
(50) error_record-text4, '|' no-gap,
(67) error_record-text5, '|' no-gap,
(45) error_record-text6, '|' .
endloop.
uline at /1(538).
format color off.
endform.
----
Report Header for Test Run *
----
form header.
set left scroll-boundary column 70.
format color 5 .
write: 'REPORT :', sy-repid,
38 'ERROR RECORDS DETAILS OF TEST RUN OF FB60(VENDOR INVIOCE POSTING)'
,123 'DATE :', sy-datum .
format color off.
skip 3.
format color 1 intensified on.
uline at 1(538).
write : /'|',
(6) 'Row No', '|' no-gap,
(14) 'Company Code', '|' no-gap,
(12) 'Vendor No', '|' no-gap,
(16) 'Reference', '|' no-gap,
(16) 'Invioce Amount', '|' no-gap,
(8) 'Currency', '|' no-gap,
(13) 'Section Code', '|' no-gap,
(20) 'text', '|' no-gap,
(14) 'G/L Account', '|' no-gap,
(15) 'Item Amount', '|' no-gap,
(10) 'Tax Code', '|' no-gap,
(20) 'Business Area', '|' no-gap,
(12) 'Cost Centre', '|' no-gap,
(5) 'Error record Status', '|' no-gap,
(50) 'Company Code/Vendor', '|' no-gap,
(53) 'Vendor/With holding tax Liability', '|' no-gap,
(50) 'Company Code/ G/L Account', '|' no-gap,
(50) 'Company Code / Cost Centre', '|' no-gap,
(67) 'Invioce Status', '|' no-gap,
(45) 'Invalid Balance',
'|'.
uline at /1(538).
format color off.
endform.
----
Report Header for Uploaded records of post run *
----
form top-of-page.
format color 5 .
write: 'REPORT :', sy-repid,60 'UPLOADED RECORDS DETAILS',
123 'DATE :', sy-datum .
format color off.
skip 3.
format color 1 intensified on.
uline at 1(140).
write : /'|',
(14) 'Company Code', '|' no-gap,
(17) 'Vendor Code', '|' no-gap,
(32) 'Vendor Name', '|' no-gap,
(13) 'Document No', '|' no-gap,
(12) 'Posting Date', '|' no-gap,
(24) 'Invioce Amount', '|' no-gap,
(12) 'UserName',
'|'.
uline at /1(140).
format color off.
endform.
----
Display the upload records of post run *
----
form dispsuccrec.
PERFORM top-of-page.
format color 2 intensified on.
loop at succ_head.
select single bname into (v_username) from usr02
where bname = sy-uname.
Translate succ_head-accnt to upper case.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = succ_head-accnt
IMPORTING
OUTPUT = succ_head-accnt.
select single name1 into (v_name) from lfa1
where lifnr = succ_head-accnt.
translate succ_head-waers to upper case.
translate succ_head-xblnr to upper case.
select single belnr into v_belnr from bsip where
bukrs = succ_head-bukrs
and lifnr = succ_head-accnt
and waers = succ_head-waers
and bldat = p_invdat
and xblnr = succ_head-xblnr
.
write : /'|',
(14) succ_head-bukrs, '|' no-gap,
(17) succ_head-accnt, '|' no-gap,
(32) v_name, '|' no-gap,
(13) v_belnr, '|' no-gap,
(12) date2, '|' no-gap,
(24) succ_head-wrbtr1, '|' no-gap,
(12) v_username, '|' .
endloop.
uline at /1(140).
format color off.
endform.
----
Report for error records of post run *
----
form diserrorrecpostrun.
format color 2 intensified on.
set left scroll-boundary column 70.
loop at error_head1.
write : /'|',
(14) error_head1-bukrs, '|' no-gap,
(17) error_head1-accnt, '|' no-gap,
(15) error_head1-xblnr, '|' no-gap,
(10) error_head1-waers, '|' no-gap,
(20) error_head1-wrbtr1, '|' no-gap,
(12) error_head1-secco, '|' no-gap,
(30) error_head1-sgtxt, '|' no-gap,
(14) error_head1-messtyp , '|' no-gap,
(82) error_head1-messg , '|'.
endloop.
uline at /1(234).
format color off.
endform.
----
Report Header for error records of post run *
----
form top-of-page1.
format color 5 .
write: 'REPORT :', sy-repid,60 'ERROR RECORDS DETAILS',
123 'DATE :', sy-datum .
set left scroll-boundary column 70.
format color off.
skip 3.
format color 1 intensified on.
uline at 1(234).
write : /'|',
(14) 'Company Code', '|' no-gap,
(17) 'Vendor Code', '|' no-gap,
(15) 'Reference ', '|' no-gap,
(10) 'Currency', '|' no-gap,
(20) 'Amount in Document', '|' no-gap,
(12) 'Section Code', '|' no-gap,
(30) 'Item text', '|' no-gap,
(14) 'Message Type', '|' no-gap,
(82) 'Message Text',
'|'.
uline at /1(234).
format color off.
endform.
thanks
sitaram
‎2008 Jul 10 5:54 AM
Hi,
After uploading ur flat file into ur itab,
then do this..
LOOP AT ITAB.
IF ITAB-RATE LT 0.
---- PRINT ERROR MESSAGE
ENDIF.
ENDLOOP. reply back
With Rgds,
S.Bharani
‎2008 Jul 10 6:49 AM
Hi,
U have to check at flat file level only.... that is down by functional consultants.. As an abaper we need to use that flat file only.. and one more thing if yo uwant to check whether the field holds the data/value that can be down at internal table level...
Reward Points if useful
Raghunath.S
9986076729
‎2008 Jul 10 7:25 AM
Hi,
Validating rate means wat do u mean?
If ur trying to check whether it is decimal or not u can use this piece of code...
REPORT ztest2 . "IDES Textpool
DATA rate(11) TYPE c ."p DECIMALS 4.
DATA rate1(12) TYPE c." p DECIMALS 4.
rate1 = '.0123456789'.
rate = '10.90'.
IF rate CO
rate1.
WRITE rate.
ELSE.
WRITE 'error'.
ENDIF.
replace rate with some..'a123h' & check result...
Hope this will be useful