‎2008 Dec 08 5:37 AM
Hi all,
The requirement is to pull the data placed in the flat file on the application server.
I am able to pull the data using Read Dataset and Open dataset commands
and then using Split command I am separating the coloumn data into a internal table.
I have debugged and this internal table is holding my data from flat file properly.
I need to insert the data into the the infotype PA0006-- Address Infotype.
I have enqued the PERNR--Employee Number
Then called the BAPI HR_INFOTYPE_OPERATION
Data is coming inside the parameter "Record". I debugged the BAPI and checked it.
But the BAPI is not inserting the record.
Please,
have a look at my code.
Thanking you all in advance,
Warm regards,
Hari Kiran
1909,99991231,20081204,1,NAGI,2ND,522006,HYDERABAD,INDIA,236795
1908,99991231,20081205,1,JOHN,3RD,522106,HYDERABAD,INDIA,236798
Above is my flat file.
REPORT zhr_pull_commu_data LINE-SIZE 200.
*data ls_data like p0006.
*
DATA: BEGIN OF ls_data OCCURS 1,
pernr LIKE p0006-pernr,
endda LIKE p0006-endda,
begda LIKE p0006-begda,
subty LIKE p0006-subty,
name2(15) TYPE c, " LIKE p0006-name2,
stras(15) TYPE c, " LIKE p0006-stras,
pstlz LIKE p0006-pstlz,
ort01 LIKE p0006-ort01,
land1 LIKE p0006-land1,
telnr LIKE p0006-telnr,
END OF ls_data.
DATA: BEGIN OF flatfile OCCURS 0,
data(500) TYPE c,
END OF flatfile.
DATA return LIKE bapireturn1.
PARAMETERS: file1 TYPE localfile DEFAULT 'D:\usr\sap\trans\data\COMM.txt'.
OPEN DATASET file1 FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
DO.
READ DATASET file1 INTO flatfile.
IF sy-subrc NE 0.
EXIT.
ENDIF.
APPEND flatfile.
CLEAR flatfile.
ENDDO.
ENDIF.
CLOSE DATASET file1.
LOOP AT flatfile.
SPLIT flatfile-data AT ',' INTO ls_data-pernr
ls_data-endda
ls_data-begda
ls_data-subty
ls_data-name2
ls_data-stras
ls_data-pstlz
ls_data-ort01
ls_data-land1
ls_data-telnr.
APPEND ls_data.
CLEAR ls_data.
LOOP AT ls_data.
CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE'
EXPORTING
number = ls_data-pernr
IMPORTING
return = return.
IF NOT return IS INITIAL.
WRITE: / ls_data-pernr, (70) return-message.
REJECT.
ENDIF.
CALL FUNCTION 'HR_INFOTYPE_OPERATION'
EXPORTING
infty = '0006'
number = ls_data-pernr
subtype = ls_data-subty
OBJECTID =
LOCKINDICATOR =
validityend = ls_data-endda
validitybegin = ls_data-begda
RECORDNUMBER =
record = ls_data
operation = 'INS'
tclas = 'A'
DIALOG_MODE = '0'
NOCOMMIT =
VIEW_IDENTIFIER =
SECONDARY_RECORD =
IMPORTING
return = ls_return
KEY =
.
ENDIF.
IF sy-subrc EQ 0.
.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN = return
.
CALL FUNCTION 'BAPI_EMPLOYEE_DEQUEUE'
EXPORTING
number = ls_data-pernr
IMPORTING
RETURN = return
.
‎2008 Dec 08 5:42 AM
‎2008 Dec 08 5:42 AM
‎2008 Dec 08 5:49 AM
Hi Amit,
Thank you for the input.
I want you to know that I have gone through searching SDN
before placing the question.
All the threads talk about Enquing the PERNR , then calling the BAPI and
then Dequeing it-- Which I am doing.
Data is even coming inside the BAPI- HR_INFOTYPE_OPERATION....
But, it's not inserting.
Is there anything wrong in the way I have declared my internal tables.
???
Warmr regards,
Hari Kiran
‎2008 Dec 08 5:56 AM
Hi,
While inserting the record are you giving the perfect key which is existing in the record ?.
check the data which your sending is input enable or not?. or might be check table entry missing
‎2008 Dec 08 6:00 AM
Ok... I will go through that..
thank you...
Regards,
Hari Kiran
‎2008 Dec 08 6:23 AM
here is a sample program that creates initial records in infotype 0759.. this should give you an idea how the function module is used in a program..
report zp_pa_ecm_conv_0759
no standard page heading.
tables
tables:
pernr. "Standard Selections for HR Master Data
infotypes
infotypes:
0001, "Org Assignment
0008, "Basic Pay
0758, "Compensation Program
0759. "Compensation Process
data declarations
Types
type-pools : slis. "Global data for ALV
alv field catalog
data: t_fieldcat type slis_t_fieldcat_alv with header line.
*constants
constants:
c_usd type waers value 'USD', "Currency
c_pernr(5) value 'PERNR', "Pers no
c_sname(5) value 'SNAME', "Emp Name
c_werks(5) value 'WERKS', "Pers Area
c_btrtl(5) value 'BTRTL', "Pers Subarea
c_persg(5) value 'PERSG', "Emp Grp
c_persk(5) value 'PERSK', "Emp Subgrp
c_orgeh(5) value 'ORGEH', "Org Unit
c_citem(5) value 'CITEM', "Comp Review Item
c_effdt(5) value 'EFFDT', "Effective date
c_0759 type infty value '0759', "Comp Process
c_tclas type pspar-tclas value 'A', "Transaction class for data storage
c_actio type pspar-actio value 'INS', "Infotype operation
c_10 type ecm_carea value '10', "Comp Area
c_background_id type bds_typeid value 'PMMN_BACKGROUND'. "ALV background
work fields
data:
w_title type lvc_title,
w_count type i. "no of recs
field strings
return structure
data: rec_return type bapiret1. "return code
internal tables
data:
begin of t_out occurs 0,
pernr type pernr_d, "Pers. No
sname type smnam, "Employee name
werks type persa, "Pers Area
btrtl type btrtl, "Pers Subarea
persg type persg, "Emp Group
persk type persk, "Emp Subgrp
orgeh type orgeh, "Org. Unit
citem type ecm_citem, "Compensation Review Item
effdt type ecm_effdt, "Effective date
bssal type ecm_bssal, "Caluclation Base
curre type waers, "Currency
end of t_out.
error table
data:
begin of t_error occurs 0,
pernr type pernr_d, "Pers no
sname type sname, "Emp Name
citem type ecm_citem, "Review item
effdt type ecm_effdt, "effective date
end of t_error.
data t_events type slis_t_event. "ALV top of page
temp table to store comp data
data:
begin of t_citem occurs 0,
cplan type ecm_cplan, "Comp Plan
citem type ecm_citem, "Review Item
effdt type ecm_effdt, "Effective date
cpgr1 type ecm_cpgr1, "1st Program grouping
cpgr2 type ecm_cpgr2, "2nd Program grouping
end of t_citem.
selection screen
selection-screen begin of block abc with frame title text-001.
parameters:
p_crevi like t71adm08-crevi. "Comp Review
select-options:
s_trfst for p0008-trfst. "Pay Scale Level
parameters:
p_test as checkbox. "Test option
selection-screen end of block abc.
************************************************************************
PROCESSING
************************************************************************
initialization.
initialization.
perform eventtab_build using t_events[].
start of selection
start-of-selection.
get all the relevant Comp Review items for the comp review entered on
the selection screen
perform fill_citem.
get pernr.
clear: p0001,p0758,p0008.
Validate Pay Scale level with selection screen values
rp-provide-from-last p0008 space pn-begda pn-endda.
check p0008-trfst in s_trfst.
Obtain Org Info from infotype 0001
rp-provide-from-last p0001 space pn-begda pn-endda.
check pnp-sw-found eq 1.
Obtain Compensation Program details from infotype 0758
rp-provide-from-last p0758 space pn-begda pn-endda.
check pnp-sw-found eq 1.
fill the output table with info from 0001 , 0758 & the
temp table t_citem
loop at t_citem where cpgr1 = p0758-cpgr1
and cpgr2 = p0758-cpgr2.
t_out-pernr = pernr-pernr.
t_out-sname = p0001-sname.
t_out-werks = p0001-werks.
t_out-btrtl = p0001-btrtl.
t_out-persg = p0001-persg.
t_out-persk = p0001-persk.
t_out-orgeh = p0001-orgeh.
t_out-citem = t_citem-citem.
t_out-effdt = t_citem-effdt.
rp-provide-from-last p0008 space t_citem-effdt t_citem-effdt.
t_out-bssal = p0008-ansal.
t_out-curre = c_usd.
append t_out.
clear t_out.
endloop.
end-of-selection.
check if any data selected for processing
if t_out[] is initial.
no data found.
write:/ 'No data found'(004).
else.
if p_test eq space.
If test option is not selected, create infotype 0759 records
using standard function module.
perform create_0759.
if not t_error[] is initial.
display errors
perform write_error.
endif.
if w_count eq 1.
message s016(rp) with w_count 'record was updated'(002).
ALV display of records that will be updated
perform list_display.
else.
message s016(rp) with w_count 'records were updated'(003).
ALV display of records that will be updated
perform list_display.
endif.
else.
ALV display of records that will be updated
perform list_display.
endif.
endif.
&----
*& Form EVENTTAB_BUILD
&----
form eventtab_build using t_lt_events type slis_t_event.
data: rec_event type slis_alv_event.
constants: c_top_of_page(11) value 'TOP_OF_PAGE'.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = t_lt_events.
read table t_lt_events with key name = slis_ev_top_of_page
into rec_event.
if sy-subrc = 0.
move c_top_of_page to rec_event-form.
append rec_event to t_lt_events.
endif.
endform. "EVENTTAB_BUILD
&----
*& Form fill_citem
&----
form fill_citem .
select acplan acitem beffdt ccpgr1 c~cpgr2 into table t_citem
from t71adm09 as a
inner join t71adm10 as b on acitem = bcitem
inner join t71adm07 as c on acplan = ccplan
and bcarea = ccarea
where a~crevi = p_crevi
and b~carea = c_10.
if sy-subrc ne 0.
clear t_citem[].
else.
sort t_citem.
endif.
endform. " fill_citem
&----
*& Form list_display
&----
form list_display .
fill ALV filed catalog ( column names )
perform fill_fieldcat using c_pernr 9 'Pers. No'(005).
perform fill_fieldcat using c_sname 40 'Employee Name'(006).
perform fill_fieldcat using c_werks 10 'Pers. Area'(007).
perform fill_fieldcat using c_btrtl 13 'Pers. Subarea'(008).
perform fill_fieldcat using c_persg 14 'Employee Group'(009).
perform fill_fieldcat using c_persk 17 'Employee Subgroup'(010).
perform fill_fieldcat using c_orgeh 9 'Org. Unit'(011).
perform fill_fieldcat using c_citem 9 'Comp Review Item'(012).
perform fill_fieldcat using c_effdt 10 'Effectiev Date'(013).
w_title = sy-title.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_background_id = c_background_id
i_callback_program = sy-repid
i_grid_title = w_title
it_fieldcat = t_fieldcat[]
it_events = t_events[]
tables
t_outtab = t_out
exceptions
program_error = 1
others = 2.
if sy-subrc ne 0.
message e208(00) with 'Error in FM REUSE_ALV_GRID_DISPLAY'(014).
endif.
endform. " list_display
&----
*& Form fill_fieldcat
&----
form fill_fieldcat using p_fieldname type c
p_length type i
p_header type c.
t_fieldcat-fieldname = p_fieldname.
t_fieldcat-outputlen = p_length.
t_fieldcat-seltext_m = p_header.
t_fieldcat-seltext_l = p_header.
t_fieldcat-reptext_ddic = p_header.
append t_fieldcat.
clear t_fieldcat.
endform. " fill_fieldcat
&----
*& Form top_of_page
&----
form top_of_page .
data: t_list_top_of_page type slis_t_listheader.
data: ls_line type slis_listheader.
*
constants: c_h value 'H'.
List Type
clear ls_line.
ls_line-typ = c_h.
LS_LINE-KEY: not used for this type
ls_line-info = sy-title.
append ls_line to t_list_top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_list_top_of_page.
endform. " top_of_page
&----
*& Form create_0759
&----
form create_0759 .
refresh p0759.
clear p0759.
loop at t_out.
Enqueue personnel number
call function 'BAPI_EMPLOYEE_ENQUEUE'
exporting
number = t_out-pernr
importing
return = rec_return.
if not rec_return is initial.
fill the error tab & continue with the next loop pass
t_error-pernr = t_out-pernr.
t_error-sname = t_out-sname.
t_error-citem = t_out-citem.
t_error-effdt = t_out-effdt.
append t_error.
clear t_error.
else.
fill the p0759 record structure
p0759-pernr = t_out-pernr.
p0759-infty = c_0759.
p0759-citem = t_out-citem.
p0759-begda = t_out-effdt.
p0759-endda = t_out-effdt.
p0759-cstat = 1.
p0759-carea = c_10.
p0759-cpamt = 0.
p0759-bssal = t_out-bssal.
p0759-curre = t_out-curre.
update infotype 0759 using std function module
call function 'HR_INFOTYPE_OPERATION'
exporting
infty = c_0759
number = t_out-pernr
record = p0759
validityend = p0759-endda
validitybegin = p0759-begda
operation = c_actio
tclas = c_tclas
importing
return = rec_return.
if the update is successful increment the count, else
pass the record to error table for display in the end
if rec_return is initial.
w_count = w_count + 1.
else.
t_error-pernr = t_out-pernr.
t_error-sname = t_out-sname.
t_error-citem = t_out-citem.
t_error-effdt = t_out-effdt.
append t_error.
clear t_error.
endif.
endif.
endloop.
endform. " create_0759
&----
*& Form write_error
&----
form write_error .
skip.
write:/3 'List of records that were not updated'(015).
loop at t_error.
if sy-tabix eq 1.
uline /(80).
write:/ sy-vline, 'Pers. No'(016),
12 sy-vline, 13 'Emp. Name'(017),
47 sy-vline, 48 'Comp Review Item'(018),
58 sy-vline, 59 'Effective Date'(019),
80 sy-vline.
uline /(80).
endif.
write:/ sy-vline, t_error-pernr under text-016,
12 sy-vline, t_error-sname under text-017,
47 sy-vline, t_error-citem under text-018,
58 sy-vline, t_error-effdt under text-019 mm/dd/yyyy,
80 sy-vline.
uline /(80).
endloop.
endform. " write_error
‎2008 Dec 08 7:53 AM
Hi Hrupa,
That was a very helpful answer.
I had changed my code and it's executing but data is not getting inserted.
I have one doubt. Since time constraint is 1 i.e. Only one record for PERNR can exit
for 0006 infotype.
So, am I supposed to use 'UPD' instead of 'INS'
as I have records in 0006 and I am testing my code using an existing PERNR which has a
record in 0006.
Any inputs are welcome....
Warm regards,
Hari Kiran
Here's my code now- It's executing. It's writing out the messages 'Employee locked'
'Employee committed' and 'Employee unlocked' but data is not getting placed.
&----
*& Report ZTP_HR_PULL_COMMU_DATA
*&
&----
*&
*&
&----
REPORT ztp_hr_pull_commu_data LINE-SIZE 200.
TABLES: pa0006.
INFOTYPES: 0006.
DATA ls_data1 LIKE p0006.
*
DATA: BEGIN OF ls_data OCCURS 1,
pernr LIKE p0006-pernr,
endda LIKE p0006-endda,
begda LIKE p0006-begda,
subty LIKE p0006-subty,
name2(15) TYPE c, " LIKE p0006-name2,
stras(15) TYPE c, " LIKE p0006-stras,
pstlz LIKE p0006-pstlz,
ort01 LIKE p0006-ort01,
ort02 LIKE p0006-ort02,
land1 LIKE p0006-land1,
telnr LIKE p0006-telnr,
END OF ls_data.
DATA: BEGIN OF flatfile OCCURS 0,
data(500) TYPE c,
END OF flatfile.
DATA: return LIKE bapireturn1,
i_key TYPE bapipakey.
PARAMETERS: file1 TYPE localfile DEFAULT 'D:\usr\sap\trans\data\COMM.txt'.
OPEN DATASET file1 FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
DO.
READ DATASET file1 INTO flatfile.
IF sy-subrc NE 0.
EXIT.
ENDIF.
APPEND flatfile.
CLEAR flatfile.
ENDDO.
ENDIF.
CLOSE DATASET file1.
LOOP AT flatfile.
SPLIT flatfile-data AT ',' INTO ls_data-pernr
ls_data-endda
ls_data-begda
ls_data-subty
ls_data-name2
ls_data-stras
ls_data-pstlz
ls_data-ort01
ls_data-land1
ls_data-telnr.
APPEND ls_data.
CLEAR ls_data.
ENDLOOP.
LOOP AT ls_data.
ls_data1-pernr = ls_data-pernr.
ls_data1-endda = ls_data-endda.
ls_data1-begda = ls_data-begda.
ls_data1-subty = ls_data-subty.
ls_data1-name2 = ls_data-name2.
ls_data1-stras = ls_data-stras.
ls_data1-pstlz = ls_data-pstlz.
ls_data1-ort01 = ls_data-ort01.
ls_data1-land1 = ls_data-land1.
ls_data1-telnr = ls_data-telnr.
CALL FUNCTION 'DEQUEUE_ALL'
EXPORTING
_SYNCHRON = ' '
.
CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE'
EXPORTING
number = ls_data1-pernr
IMPORTING
return = return.
IF sy-subrc EQ 0.
WRITE:/ 'EMPLOYEE LOCKED'.
ENDIF.
CALL FUNCTION 'HR_INFOTYPE_OPERATION'
EXPORTING
infty = '0006'
number = ls_data1-pernr
subtype = ls_data1-subty
OBJECTID =
LOCKINDICATOR =
validityend = ls_data1-endda
validitybegin = ls_data1-begda
RECORDNUMBER =
record = ls_data1
operation = 'INS'
tclas = 'A'
dialog_mode = '0'
nocommit = ' '
VIEW_IDENTIFIER =
SECONDARY_RECORD =
IMPORTING
return = return
key = i_key
.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
return = return
.
IF sy-subrc EQ 0.
WRITE:/ 'EMPLOYEE COMMITED'.
ENDIF.
**
CALL FUNCTION 'BAPI_EMPLOYEE_DEQUEUE'
EXPORTING
number = ls_data1-pernr
IMPORTING
RETURN = ls_return
.
IF sy-subrc EQ 0.
WRITE:/ 'EMPLOYEE UNLOCKED'.
ENDIF.
WRITE:/ ' DONE'.
ENDLOOP.
‎2008 Dec 09 9:42 AM
Hi all,
The code is working properly.
The BAPIRETURN is giving the message, "Personnel NO. Not yet assigned".
I have realised that the PERNR or the employee number I am taking is not assigned yet.
But, I have taken these PERNR from the Org. Assignment table - PA0001.
The employee is having org. assignment done for him in this infotype.
I don't know what type of PERNR I need to take.??
Any inputs are welcome - Functional/ technical.
Thanking you all in advance,
Hari Kiran
‎2008 Dec 10 11:41 AM
Hi all,
I was able to insert records using BDC session method.
I had no issues.
Guess something is wrong with the BAPI...
Warm regards,
Hari Kiran
‎2008 Dec 11 10:39 AM
The BAPI is now giving the return message as " Invalid Date".
I have checked t-code -SU3.
My date is in the format- DD.MM.YYYY
Data in my flat file for date is like '05122008'
Its coming inside the BAPI but not getting placed.
Inputs please.
Regards,
Hari Kiran
‎2008 Dec 24 9:23 AM
The issue was solved.
I gave the date in the format yyyymmdd in the flat file.
There was nothing wrong with the code.
Regards,
Hari Kiran