‎2007 May 03 2:48 PM
AS per the requirement i need to fetch the Address details of employees from PA0006.
we have a field ADDRESS TYPE (ANSSA).
1) First need to check whether employee has "PERMANENT ADDRESS or not, if it is there display it. (ANSSA = 1)
2) If any employee doesn't contain "Permanent Address" then check for his TEMPORARY ADDRESS. if it is there display it. (ANSSA = 9001)
3) if "Temporary address" is not there then Display EMERGENCY ADDRESS.
(ANSSA = 4).
I have written the code for this. but Eventhough the Employee has Permanent Address(ANSSA =1) it is taking Emergency Address(ANSSA = 4) for some of the records.
i'm attaching the code.
Please verify and suggest me the right way.
Reading Personal No. from Flat file and storing into Internal table t_txt_upload.
using FOR ALL ENTRIES fetching corresponding the records associated with that personal numbers from PA0006 and storing into IT_p0006.
Read table it_p0006 with key pernr = t_txt_upload-pernr binary search.
if sy-subrc eq 0.
it_final-pernr = it_p0006-pernr. "Employee No
it_final-begda = it_p0006-begda. "Date From
it_final-endda = it_p0006-endda. "Date To
if it_p0006-anssa = 4.
it_final-anssa = 'E'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
elseif it_p0006-anssa = '9001'.
it_final-anssa = 'T'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
elseIF.
it_p0006-anssa = '1'.
it_final-anssa = 'P'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
endif.
‎2007 May 03 2:56 PM
Hi Vamsi,
I guess what is happening here is all records belonging to all types are selected.
But if you check the order in which you are comparing first you are checking if any
emergency record is present, then temporary address and then permanent address. But to get your result you should check in the reverse order i.e. first
permanent address, then temporary, then emergency.
if it_p0006-anssa = 1.
it_final-anssa = 'E'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
elseif it_p0006-anssa = '9001'.
it_final-anssa = 'T'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
elseIF.
it_p0006-anssa = '9001'.
it_final-anssa = 'P'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
endif.
Regards,
Aravind
‎2007 May 03 2:55 PM
Might be just a typo... At least if you copied and pasted the code.
Check if the 4 is also like '4'. With single quotes.
Like (I prefer CASE...):
CASE it_p0006-anssa.
WHEN '4'.
it_final-anssa = 'E'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
WHEN '9001'.
it_final-anssa = 'T'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
WHEN '1'.
it_final-anssa = 'P'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
ENDCASE.
‎2007 May 03 2:56 PM
Hi Vamsi,
I guess what is happening here is all records belonging to all types are selected.
But if you check the order in which you are comparing first you are checking if any
emergency record is present, then temporary address and then permanent address. But to get your result you should check in the reverse order i.e. first
permanent address, then temporary, then emergency.
if it_p0006-anssa = 1.
it_final-anssa = 'E'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
elseif it_p0006-anssa = '9001'.
it_final-anssa = 'T'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
elseIF.
it_p0006-anssa = '9001'.
it_final-anssa = 'P'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
endif.
Regards,
Aravind
‎2007 May 03 3:18 PM
HI earlier i have tried like that itself. it always going to 4. so have given first condition as 4.
Thanks for your help.
i will give you the record pattern in DB. it will give clarity on my problem.
Personal No. BeginDate EndDate AddressType
01 01.03.1998 25.07.2006 1
01 26.07.2006 31.12.9999 1
01 12.09.2004 31.12.9999 4
For each personal No. there are two to three records in the DB.
I'm sorting based on Personal Number.
and Deleting Adjacent Duplicates.
This will make you very clear and please give the Reply.
Thanks in advance.
if not t_txt_upload[] is initial.
Get the data from table PA0006.
select pernr
begda
endda
anssa
stras
locat
ort01
ort02
pstlz
land1
telnr
com01
num01
com02
num02
from pa0006
into table it_p0006
for all entries in t_txt_upload
where pernr eq t_txt_upload-pernr.
if sy-subrc eQ 0.
append it_p0006.
else.
MESSAGE I030 WITH IT_P0006-PERNR.
endif.
sort it_p0006 by pernr.
delete adjacent duplicates from it_p0006 comparing pernr.
endif.
loop at t_txt_upload.
Read table it_p0006 with key pernr = t_txt_upload-pernr binary search.
if sy-subrc eq 0.
it_final-pernr = it_p0006-pernr. "Employee No
it_final-begda = it_p0006-begda. "Date From
it_final-endda = it_p0006-endda. "Date To
if it_p0006-anssa = 1.
it_final-anssa = 'P'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
elseif it_p0006-anssa = 9001.
it_final-anssa = 'T'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
else .
it_p0006-anssa = 4.
it_final-anssa = 'E'.
it_final-stras = it_p0006-stras.
it_final-locat = it_p0006-locat.
it_final-ort01 = it_p0006-ort01.
it_final-ort02 = it_p0006-ort02.
it_final-pstlz = it_p0006-pstlz.
it_final-telnr = it_p0006-telnr.
it_final-land1 = it_p0006-land1.
endif.
‎2007 May 03 3:48 PM
Hi Vamsi,
The problem is with below two statements.
sort it_p0006 by pernr.
delete adjacent duplicates from it_p0006 comparing pernr.
If you are deleting comparing pernr, then what might be happening is that records with address type 1 and 9001 might be getting deleted.
Why are you sorting and deleting adjacent duplicates based on pernr? If you want only the current records you can add that in the selection criteria like below, no need to sort and delete.
select pernr
begda
endda
anssa
stras
locat
ort01
ort02
pstlz
land1
telnr
com01
num01
com02
num02
from pa0006
into table it_p0006
for all entries in t_txt_upload
where pernr eq t_txt_upload-pernr and
<u> begda le sy-datum and
endda ge sy-datum.</u>
Regards,
Aravind
‎2007 May 03 5:06 PM
Hi Vamsi,
Also check the following portion of code.
loop at t_txt_upload.
Read table it_p0006 with key pernr = t_txt_upload-pernr binary search.
You are reading record belonging to pernr only. I feel the approach should be
try and read record using both pernr and anssa. There should be three reads. In the
first read use anssa eq '1'. If you donot get any record in that read try using anssa eq '9001'. If that also fails try using anssa equals '4'. The code i have given below.
loop at t_txt_upload.
Read table it_p0006 with key pernr = t_txt_upload-pernr anssa = '1' binary search.
if sy-subrc eq 0.
-
else.
Read table it_p0006 with key pernr = t_txt_upload-pernr anssa = '9001' binary search.
if sy-subrc eq 0.
else.
Read table it_p0006 with key pernr = t_txt_upload-pernr anssa = '4' binary search.
if sy-subrc eq 0.
else.
endif.
endif.
endif.
Regards,
Aravind
‎2007 May 04 8:40 AM
Thanks alot for your suggestion. i get rid of tht problem.
I'm Printing the output in flat file(notepad) using GUI_DOWNLOAD.
Data is populating fine.
I need add pipe dilimiter (|) for all the fields.
like
Personal No.| BEGDA | ENDDA | ANSSA | TELNR|
can you guide me the way.
‎2007 May 04 3:12 PM
Hi Vamsi,
I guess the only possible way is concatenate all fields i.e. personnel number, begda, endda separated by '|' using concatenate statement as shown below.
concatenate pernr '|' begda '|' endda '|' into result or
concatenate pernr '|' begda '|' endda '|' into result separated by '|' and then download.
I would also suggest you to create a separate thread for the new question so that it
has higher visibility among viewers.
Regards,
Aravind