10-18-2008 7:38 AM
hi all,
i am getting a flat file from application server .i have to do some validations and i am passing these values to bapi structure to create Purchase requisition(PR).but it is not creating any PR.
i am sending my code to u pls go through that .and tell me where i have to change it
report zlpr_inb_str_create
no standard page heading
line-size 250
message-id zl_msg.
************************************************************************
TYPES DECLARATION *
************************************************************************
types:begin of ty_data,
sc_code type t001l-lgort, "School Code
course type ltext, "Course
stock_item type matnr, "Stocked Item Number
quantity type char5, "Requisition Quantity
ac_info type char20, "Accounting Information
fincode type bp_geber, "Fund
fkber type fkber , "Functional Area
kostl type kostl , "Cost Center
saknr type saknr , "G/L Account Number
gsber type gsber , "Business Area
end of ty_data.
types:begin of ty_log ,
sc_code type t001l-lgort, "School Code
course type ltext, "Course
stock_item type matnr, "Stocked Item Number
quantity type char5, "Requisition Quantity
ac_info type char20, "Accounting Information
s_date type sy-datum, "System Date
s_time type sy-uzeit, "System Time
err_msg type char100, "Error Message
end of ty_log.
types:begin of ty_mara,
matnr type mara-matnr, "Material code
ac_info(20) type c,
end of ty_mara.
types:begin of ty_lgort,
lgort type t001l-lgort, "Storage Location
ac_info(20) type c,
end of ty_lgort.
types:begin of ty_fincode,
fincode type fmfincode-fincode, "SAP Fund
end of ty_fincode .
types:begin of ty_fkber,
fkber type tfkb-fkber, "SAP Function Area
end of ty_fkber .
types:begin of ty_kostl,
kostl type csks-kostl, "SAP Cost Center
end of ty_kostl .
types:begin of ty_saknr,
saknr type ska1-saknr, "SAP GL Account
end of ty_saknr .
types:begin of ty_gsber,
gsber type tgsb-gsber, "SAP Business Area
end of ty_gsber .
************************************************************************
VARIABLES DECLARATION *
************************************************************************
data: g_fincode type bp_geber, "Fund
g_fkber type fkber , "Functional Area
g_kostl type kostl , "Cost Center
g_saknr type saknr , "G/L Account Number
g_gsber type gsber , "Business Area
g_itmcnt type i , "Count for item lines
g_err type c . "For error messages
************************************************************************
INTERNAL TABLES DECLARATION *
************************************************************************
data:it_data type standard table of ty_data with header line,
it_dynsel type table of dselc with header line,
it_dynval type table of dval,
it_log type standard table of ty_log, "Error log
it_mara type standard table of ty_mara, "Material Number
it_lgort type standard table of ty_lgort, "Storage Location
it_fincode type standard table of ty_fincode, "Fund
it_fkber type standard table of ty_fkber, "Functional Area
it_kostl type standard table of ty_kostl, "Cost Center
it_saknr type standard table of ty_saknr, "G/L Account Number
it_gsber type standard table of ty_gsber. "Bussiness Area
************************************************************************
WORK AREA DECLARATION *
************************************************************************
data: wa_data type ty_data,
wa_string type string,
wa_log type ty_log, "Error Log
wa_mara type ty_mara, "Material Number
wa_lgort type ty_lgort, "Storage Location
wa_fincode type ty_fincode, "Fund
wa_fkber type ty_fkber, "Functional Area
wa_kostl type ty_kostl, "Cost Center
wa_saknr type ty_saknr, "G/L Account Number
wa_gsber type ty_gsber, "Bussiness Area
wa_helpinf type help_info.
************************************************************************
INTERNAL TABLES DECLARATION FOR PASSING VALUES IN BAPI *
************************************************************************
data : it_item type standard table of bapiebanc, "Item Data
it_atasg type standard table of bapiebkn, "Account Assignment Data for Item
it_ittxt type standard table of bapiebantx, "Text for Item
it_return type standard table of bapireturn, "Return Messages
g_reqstno type bapiebanc-preq_no. "Purchase Requisition Number
data : wa_bapiebanc type bapiebanc,
wa_bapiebkn type bapiebkn ,
wa_bapiebantx type bapiebantx,
wa_return type bapireturn.
************************************************************************
CONSTANTS *
************************************************************************
constants: c_program type ztcca_pgmconst value 'ZLPR_INB_STR_CREATE', "program Name
c_field1 type ztcca_pgmconst value 'Z_STR_CREATE',
c_msg type char41 value 'No Valid Records to Process in the file',
c_module type char2 value 'PR',
c_dev_type type zcca_dev_type value 'INT',
c_movement type zcca_movement value 'I',
c_object_id type char25 value 'PR_INB_0001',
c_dlmtr type c value '|', "For Deliminator
c_fldname(10) type c value 'FILEINTERN', "For File name FM
c_dyflname(19) type c value 'FILENAME-FILEINTERN', "For File name FM
c_fname(8) type c value 'FILENAME', "For file name FM
c_prog(8) type c value 'RSSYSTDB', "For file name FM
c_chktable(10) type c value 'FILENAMECI', "For file name FM
c_dynpro(4) type c value '1000', "For File name FM
c_dynprofld(6) type c value 'P_FILE', "For File name FM
c_call(1) type c value 'T', "For File name FM
c_spras type c value 'E', "For File name FM
c_obj(1) type c value 'F', "For File name FM
c_pov(1) type c value 'N', "For File name FM
c_currow(1) type c value '3', "For File name FM
c_curcol(2) type c value '35', "For File name FM
c_sydyn(1) type c value 'S', "For File name FM
c_pr_type(4) type c value 'ZUB', "For PR Type
c_item_cat(1) type c value 'U', "For Item Category
c_ac_asign(1) type c value 'K', "For Cost Center
c_pur_grp(1) type c value 'H', "For Purchasing Group
c_pur_org(4) type c value 'DCPS', "For Purchasing Organisation
c_gl_ac(4) type c value 'CABE',
c_unit(2) type c value 'EA', "For Unit Of Measure
c_r_plant(4) type c value '1000' , "For Requesting Plant
c_10(2) type c value '10',
c_3000(4) type c value '3000', "For Supplying Plant
c_90(2) type c value '90',
c_ok(1) type c value 'X',
c_i(1) type c value 'I',
c_eq(2) type c value 'EQ',
c_flag(1) type c value 'X' ,
c_x(1) type c value 'X' ,
c_coma(1) type c value ',' ,
c_00(2) type c value '00' ,
c_0000(4) type c value '0000' ,
c_one type i value 1 ,
c_98 type i value 98 .
***********************************************************************
AT SELECTION-SCREEN *
***********************************************************************
*-- selection screen declarations
selection-screen begin of block b_source with frame title text-008.
parameters: p_file type localfile . "Source file name
parameters:rb_phy radiobutton group path user-command ucmd default 'X', "Physical path
rb_logic radiobutton group path . "Logical path
selection-screen end of block b_source.
***********************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST *
***********************************************************************
at selection-screen on value-request for p_file.
*--Get the value help for the application server .
perform get_value_help.
***********************************************************************
AT SELECTION-SCREEN ON INPUT FILE *
***********************************************************************
at selection-screen on p_file.
*--Validate the physical file path of application server
perform validate_file_path using p_file.
***********************************************************************
START-OF-SELECTION EVENT *
***********************************************************************
start-of-selection.
*--To get source file data from application server
perform get_file_data.
*-- Validate input file data
perform validate_data.
*-- Post STR / PR in SAP
perform create_str.
*--To display the processing log
PERFORM display_log.
*--- Display Default Application server file path on selection screen
perform default_app_server_file.
&----
*& Form VALIDATE_FILE_PATH
&----
Validate physical file path for application server
----
form validate_file_path using p_app_file.
data: l_app_fname type sldstring, "APPLICATION FILE NAME
l_test type sldagtst. "TEST INDICATOR
move p_app_file to l_app_fname.
if rb_phy = 'X'.
if p_file ne space.
*CHECK WHETHER FILE EXIST IN THE APPLICATION SERVER
call function 'SLDAG_CHECK_FILE_EXISTENCE'
exporting
fq_file_name = l_app_fname
importing
exists = l_test.
if l_test is initial.
message i023. "File not found.
endif.
endif.
endif.
clear l_test.
endform. " VALIDATE_FILE_PATH
&----
&----
*& Form GET_VALUE_HELP
&----
Get the help for the file name
----
form get_value_help .
if rb_phy = 'X'.
call function '/SAPDMC/LSM_F4_SERVER_FILE'
exporting
directory = '.'
importing
serverfile = p_file
exceptions
canceled_by_user = 1
others = 2.
if sy-subrc <> 0.
message i023. "File not found
endif.
elseif rb_logic = c_ok.
clear: wa_helpinf,
it_dynsel,
it_dynval.
refresh: it_dynsel,
it_dynval.
Set the parameters before invoking the FM
for browsing the logical filename
wa_helpinf-call = c_call.
wa_helpinf-object = c_obj.
wa_helpinf-program = c_prog.
wa_helpinf-dynpro = c_dynpro.
wa_helpinf-tabname = c_fname.
wa_helpinf-fieldname = c_fldname.
wa_helpinf-spras = sy-langu.
wa_helpinf-title = sy-title.
wa_helpinf-dynprofld = c_dynprofld.
wa_helpinf-checktable = c_chktable.
wa_helpinf-checkfield = c_fldname.
wa_helpinf-report = sy-cprog.
wa_helpinf-pov = c_pov.
wa_helpinf-curow = c_currow.
wa_helpinf-cucol = c_curcol.
wa_helpinf-sy_dyn = c_sydyn.
wa_helpinf-dynpprog = sy-cprog.
it_dynsel-fldname = c_fldname.
it_dynsel-dyfldname = c_dyflname.
append it_dynsel.
Call the FM to display the help for the logical filenames
call function 'HELP_START'
exporting
help_infos = wa_helpinf
tables
dynpselect = it_dynsel
dynpvaluetab = it_dynval.
endif.
endform. " GET_VALUE_HELP
&----
*& Form get_file_data
&----
text
----
form get_file_data .
*--Open the file and move data into table it_data
open dataset p_file for input in text mode encoding default.
if ( sy-subrc ne 0 ).
message e002 with c_msg.
endif.
while sy-subrc = 0.
read dataset p_file into wa_string.
if sy-subrc = 0.
split the string into table structure
split wa_string at '|' into: wa_data-sc_code "School Code
wa_data-course "Course
wa_data-stock_item "Stock Item Number
wa_data-quantity "Quantity
wa_data-ac_info. "Accounting Information
Convert Stock Item number ( Material number )
call function 'CONVERSION_EXIT_MATN1_INPUT'
exporting
input = wa_data-stock_item "Stock Item Number
importing
output = wa_data-stock_item "Stock Item Number
exceptions
length_error = 1
others = 2.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
Get SAP fields from accounting information string
wa_data-gsber = wa_data-ac_info+12(4). " validate to sap bussiness area
concatenate wa_data-ac_info+1(3) c_00 into wa_data-fincode. "validate to Sap fund
concatenate wa_data-ac_info4(4) c_00 wa_data-ac_info8(4) c_0000
into wa_data-fkber. "Validate Functional Area
concatenate wa_data-ac_info+12(4) c_00 into wa_data-kostl. "Validate Cost Center
concatenate wa_data-ac_info+16(4) c_00 into wa_data-saknr. "validate to Sap GL Account
*-- Convert Cost center into internal format
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = wa_data-kostl
importing
output = wa_data-kostl.
*-- Convert G/L Account into internal format
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = wa_data-saknr
importing
output = wa_data-saknr.
append wa_data to it_data.
endif.
endwhile.
close dataset p_file.
if ( sy-subrc ne 0 ).
message e005.
endif.
sort it_data ascending by sc_code .
endform. " GET_FILE_DATA
&----
*& Form validate_data *
&----
text *
----
form validate_data .
*-- If input file contains data, create STR in SAP
if ( it_data[] is initial ).
Error message
message e002.
endif.
Extract material data for validation
select matnr "Material Number
from mara
into table it_mara
for all entries in it_data
where matnr = it_data-stock_item.
Extract Storage location data for validation
select lgort "Storage Location
from t001l
into table it_lgort
for all entries in it_data
where werks = c_3000 and
lgort = it_data-sc_code.
Extract SAP Fund IDs
select fincode "Fund
from fmfincode
into table it_fincode
for all entries in it_data
where fikrs = c_pur_org
and fincode = it_data-fincode.
Extract SAP Function Area
select fkber "Functional Area
from tfkb
into table it_fkber
for all entries in it_data
where fkber = it_data-fkber.
Extract SAP Cost Center
select kostl "Cost Center
from csks
into table it_kostl
for all entries in it_data
where kokrs = c_pur_org
and kostl = it_data-kostl
and datbi >= sy-datum
and datab <= sy-datum.
Extract SAP G/L Account
select saknr "G/L Account Number
from ska1
into table it_saknr
for all entries in it_data
where ktopl = c_gl_ac
and saknr = it_data-saknr.
Extract SAP Business Area
select gsber "Bussiness Area
from tgsb
into table it_gsber
for all entries in it_data
where gsber = it_data-gsber.
Validate uploaded material and storage location data
sort it_mara by matnr. "Material Number
sort it_lgort by lgort. "Storage Location
sort it_fincode by fincode. "Fund
sort it_fkber by fkber. "Functional Area
sort it_kostl by kostl. "Cost Center
sort it_saknr by saknr. "G/L Account Number
sort it_gsber by gsber. "Bussiness Area
loop at it_data into wa_data.
Validate Material number
read table it_mara into wa_mara with key matnr = wa_data-stock_item
binary search.
if sy-subrc ne 0.
perform update_error_log using wa_data
text-001.
endif.
Validate Storage location ( School Code )
read table it_lgort into wa_lgort with key lgort = wa_data-sc_code.
if sy-subrc ne 0.
perform update_error_log using wa_data
text-002.
endif.
Validate Sap fund
read table it_fincode into wa_fincode with key fincode = it_data-fincode
binary search.
if sy-subrc ne 0.
perform update_error_log using wa_data
text-003.
endif.
Validate Functional Area
read table it_fkber into wa_fkber with key fkber = it_data-fkber
binary search.
if sy-subrc ne 0.
perform update_error_log using wa_data
text-004.
endif.
Validate Cost Center
read table it_kostl into wa_kostl with key kostl = it_data-kostl
binary search.
if sy-subrc ne 0.
perform update_error_log using wa_data
text-005.
endif.
Validate G/L Account Number
read table it_saknr into wa_saknr with key saknr = it_data-saknr
binary search.
if sy-subrc ne 0.
perform update_error_log using wa_data
text-006.
endif.
Validate to Bussiness Area
read table it_gsber into wa_gsber with key gsber = it_data-gsber
binary search.
if sy-subrc ne 0.
perform update_error_log using wa_data
text-007.
endif.
endloop.
endform. " VALIDATE_DATA
&----
*& Form REQUISITION_CREATE
&----
text
----
--> p1 text
<-- p2 text
----
form requisition_create .
if c_flag ne c_x.
call function 'BAPI_REQUISITION_CREATE'
exporting
SKIP_ITEMS_WITH_ERROR =
automatic_source = c_x
importing
number = g_reqstno
tables
requisition_items = it_item
requisition_account_assignment = it_atasg
requisition_item_text = it_ittxt
REQUISITION_LIMITS =
REQUISITION_CONTRACT_LIMITS =
REQUISITION_SERVICES =
REQUISITION_SRV_ACCASS_VALUES =
return = it_return.
REQUISITION_SERVICES_TEXT =
REQUISITION_ADDRDELIVERY =
EXTENSIONIN =
if g_reqstno is not initial.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = c_x
IMPORTING
RETURN =
.
endif.
read table it_return into wa_return with key type = 'E'.
if sy-subrc eq 0.
write: / wa_return-message.
else.
write: / g_reqstno.
endif.
endif.
endform. " REQUISITION_CREATE
&----
*& Form display_log
&----
text
----
*
WRITE: text-011,p_file.
*
LOOP AT it_log INTO wa_log.
WRITE : / wa_log-sc_code, wa_log-stock_item, wa_log-quantity, sy-datum, sy-uzeit, wa_log-err_msg.
ENDLOOP.
*
*ENDFORM. " DISPLAY_LOG
&----
&----
*& Form UPDATE_ERROR_LOG
&----
text
----
-->P_WA_DATA text
-->P_TEXT_001 text
----
To display Error Message
form update_error_log using p_data type ty_data
p_errmsg.
clear : wa_log.
*CONCATENATE wa_log-sc_code wa_log-course wa_log-stock_item wa_log-quantity wa_log-ac_info into g_err SEPARATED BY c_coma.
wa_log-sc_code = p_data-sc_code. "School Code
wa_log-course = p_data-course. "Course
wa_log-stock_item = p_data-stock_item. "Stock Item Number
wa_log-quantity = p_data-quantity. "Quantity
wa_log-ac_info = p_data-ac_info. "Account Information
wa_log-err_msg = p_errmsg. "Error Message
concatenate wa_log-sc_code wa_log-course wa_log-stock_item wa_log-quantity
wa_log-ac_info into g_err separated by c_coma.
append wa_log to it_log.
endform. " UPDATE_ERROR_LOG
&----
*& Form CREATE_STR
&----
text
----
--> p1 text
<-- p2 text
----
form create_str .
sort it_data by sc_code.
loop at it_data into wa_data.
clear : wa_bapiebanc, wa_bapiebkn, wa_bapiebantx.
at new sc_code.
refresh : it_item,it_atasg,it_ittxt.
clear : g_itmcnt.
endat.
*-- Count of Item lines per school code
g_itmcnt = g_itmcnt + c_one.
wa_bapiebanc-doc_type = c_pr_type. "purchase requisition documentation type
wa_bapiebanc-item_cat = c_item_cat. "ITEM CATEGORY
wa_bapiebanc-acctasscat = c_ac_asign. "Account Assignment Category
wa_bapiebanc-material = wa_data-stock_item. "Material number
wa_bapiebanc-suppl_plnt = c_3000. "supplying plant
wa_bapiebanc-pur_group = c_pur_grp. "purchase Group
wa_bapiebanc-purch_org = c_pur_org. "Purchase Organisation
wa_bapiebanc-unit = c_unit. "Unit of measure
wa_bapiebanc-plant = c_r_plant. "receiving plant
wa_bapiebanc-deliv_date = sy-datum + 7. "Delivary date
append wa_bapiebanc to it_item.
wa_bapiebkn-fund = it_data-fincode. "SAP Fund
wa_bapiebkn-func_area = it_data-fkber. "Functional Area
wa_bapiebkn-bus_area = it_data-gsber . "Business Area
wa_bapiebkn-cost_ctr = it_data-kostl. "Cost Center
wa_bapiebkn-g_l_acct = it_data-saknr . "G/L Account
append wa_bapiebkn to it_atasg .
wa_bapiebantx-text_line = wa_data-course.
append wa_bapiebantx to it_ittxt.
*-- If item line count per school code is 98, call BAPI to create STR/PR
if ( g_itmcnt = c_98 ).
perform requisition_create.
refresh : it_item,it_atasg,it_ittxt.
clear : g_itmcnt.
continue.
endif.
*-- At end of school code, call BAPI to create STR/PR
at end of sc_code.
perform requisition_create.
endat.
endloop.
endform. " CREATE_STR
&----
*& Form DEFAULT_APP_SERVER_FILE
&----
text
----
--> p1 text
<-- p2 text
----
form default_app_server_file .
call function 'ZCCA_DEFAULT_APP_SERVER_FILE'
exporting
module = c_module
dev_type = c_dev_type
movement = c_movement
object_id = c_object_id
FILE_EXTENSION = 'TXT'
importing
serverfile = p_file .
concatenate p_file c_object_id '_' sy-datum sy-uzeit into
p_file.
endform. " DEFAULT_APP_SERVER_FILE
10-18-2008 7:58 AM
wa_bapiebanc-doc_type = c_pr_type. "purchase requisition documentation type
wa_bapiebanc-item_cat = c_item_cat. "ITEM CATEGORY
wa_bapiebanc-acctasscat = c_ac_asign. "Account Assignment Category
wa_bapiebanc-material = wa_data-stock_item. "Material number
wa_bapiebanc-suppl_plnt = c_3000. "supplying plant
wa_bapiebanc-pur_group = c_pur_grp. "purchase Group
wa_bapiebanc-purch_org = c_pur_org. "Purchase Organisation
wa_bapiebanc-unit = c_unit. "Unit of measure
wa_bapiebanc-plant = c_r_plant. "receiving plant
wa_bapiebanc-deliv_date = sy-datum + 7. "Delivary date
***************************************************8
here pass wa_bapiebanc-CREATE_IND= '1'.
*************************************************
append wa_bapiebanc to it_item.
note
Short Text
Creation Indicator (Purchase Requisition/Schedule Lines)
Definition
Shows whether the purchase requisition or delivery schedule line was
created manually or automatically (e.g. as a result of the requirements
planning process).
In the case of delivery schedules created under scheduling agreements,
if schedule lines with different creation indicators are consolidated to
form a release schedule line, the creation indicator remains "blank".
05-15-2009 7:59 AM