‎2006 Sep 27 3:34 AM
The read statement is giving return code 4(sy-subrc) although the data is there. The data elements used are the same as well.
Data: Begin of I_a901 occurs 0,
raufnr like catsdb-raufnr,
pernr like catsdb-pernr,
kunnr like a901-kunnr,
matnr like a901-matnr,
knumh like a901-knumh,
end of i_a901.
Data: Begin of I_CATSDB_30 Occurs 0,
WORKDATE Type CATSDATE,
PERNR LIKE CATSDB-PERNR,
RAUFNR Type EAUFNR,
RKOSTL Type EKOSTL,
AWART Type AWART,
STATUS Type CATSSTATUS,
COUNTER Type CATSREFCOU,
REFCOUNTER tYPE CATSREFCOU,
CATSHOURS type CATSHOURS,
ZZDESCRIPTION Type ZZDESCRIPTION,
ERSDA Type CATS_ERSDA,
ERSTM Type CATS_CPUTM,
ERNAM Type CATS_ERNAM,
LAEDA Type CATS_LAEDA,
LAETM Type CATS_LAETM,
AENAM Type AENAM,
End of I_CATSDB_30.
Read table i_a901 with key pernr = i_catsdb-pernr
raufnr = i_catsdb-raufnr.
What could be the reason?
‎2006 Sep 27 3:40 AM
‎2006 Sep 27 3:41 AM
change the itab definition & try it ie
Data: Begin of I_a901 occurs 0,
pernr like catsdb-pernr,
raufnr like catsdb-raufnr,
kunnr like a901-kunnr,
matnr like a901-matnr,
knumh like a901-knumh,
end of i_a901.
sort i_a901.
Read table i_a901 with key pernr = i_catsdb-pernr
raufnr = i_catsdb-raufnr
binary search.
~Suresh
‎2006 Sep 27 3:46 AM
REPORT ZSD_AUDITLOG.
Tables: CATSDB, PA0001, VBAK, CSKS, T554T.
Type pools that we use for ALV are defined below.
TYPE-POOLS SLIS.
Data: Begin of I_VBAK Occurs 0,
vbeln type vbak-vbeln,
raufnr type catsdb-raufnr,
vkorg type vbak-vkorg,
VKGRP type VBAK-VKGRP,
knumv type vbak-knumv,
End of I_VBAK.
Data: Begin of I_CATSDB_30 Occurs 0,
WORKDATE Type CATSDATE,
PERNR LIKE CATSDB-PERNR,
RAUFNR Type EAUFNR,
RKOSTL Type EKOSTL,
AWART Type AWART,
STATUS Type CATSSTATUS,
COUNTER Type CATSREFCOU,
REFCOUNTER tYPE CATSREFCOU,
CATSHOURS type CATSHOURS,
ZZDESCRIPTION Type ZZDESCRIPTION,
ERSDA Type CATS_ERSDA,
ERSTM Type CATS_CPUTM,
ERNAM Type CATS_ERNAM,
LAEDA Type CATS_LAEDA,
LAETM Type CATS_LAETM,
AENAM Type AENAM,
End of I_CATSDB_30.
Data: I_CATSDB Like I_CATSDB_30 Occurs 0 with header line,
I_CATSDB_TMP like I_CATSDB_30 Occurs 0 with header line.
Data : Begin of I_REGION occurs 0,
vkgrp like vbak-vkgrp,
bezei like tvgrt-bezei,
End of I_REGION.
Data: Begin of I_OUTPUT Occurs 0,
BEZEI LIKE TVGRT-BEZEI,
PROJCC Type EAUFNR,
ATEXT Type ABWTXT ,
WORKDATE Type CATSDATE,
PERNR Type PERNR_D,
ENAME Type EMNAM,
INITHRS TYPE CATSHOURS,
FINHRS TYPE CATSHOURS,
DELTA TYPE CATSHOURS,
RATE TYPE NETWR_AP,
AMOUNT TYPE P DECIMALS 2,
End of I_OUTPUT.
Data: Begin of I_PERNR Occurs 0,
PERNR Type PERNR_D,
End of I_PERNR.
Data: Begin of I_RAUFNR Occurs 0,
RAUFNR LIKE VBAK-VBELN,
End of I_RAUFNR.
Data: Begin of I_VBAP Occurs 0,
VBELN like VBAP-VBELN,
RAUFNR like CATSDB-RAUFNR,
POSNR like vbap-posnr,
MATNR like vbap-matnr,
PERNR LIKE pa0001-pernr,
end of i_vbap.
Data: Begin of I_a901 occurs 0,
raufnr like catsdb-raufnr,
pernr like catsdb-pernr,
kunnr like a901-kunnr,
matnr like a901-matnr,
knumh like a901-knumh,
end of i_a901.
Data: Begin of I_KONP occurs 0,
knumh like KONP-knumh,
kbetr like konp-kbetr,
end of i_KONP.
Data: Begin of I_EMPNAME Occurs 0,
PERNR Type PERNR_D,
ENAME Type EMNAM,
End of I_EMPNAME.
Data: Begin of I_ACTIVITY Occurs 0,
AWART LIKE T554T-AWART,
ATEXT LIKE T554T-ATEXT,
End of I_ACTIVITY.
Data: ITAB_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
I_LAYOUT TYPE SLIS_LAYOUT_ALV,
I_SORT TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE,
I_EVENTS TYPE SLIS_T_EVENT WITH HEADER LINE,
ITAB_HEADING TYPE SLIS_T_LISTHEADER WITH HEADER LINE,
ITAB_FORMNAME TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',
SYREPID LIKE SY-REPID.
Selection screen declaration.
SELECTION-SCREEN BEGIN OF BLOCK A1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_WERKS LIKE CATSDB-WERKS OBLIGATORY.
SELECT-OPTIONS :S_TSDATE FOR CATSDB-WORKDATE OBLIGATORY,
S_REGIO FOR VBAK-VKGRP,
S_EMPNO FOR PA0001-PERNR,
S_PCODE FOR VBAK-VBELN MATCHCODE OBJECT VMVA,
S_COCENT FOR CSKS-KOSTL,
S_ACTYP FOR T554T-AWART.
SELECTION-SCREEN END OF BLOCK A1.
TOP-OF-PAGE.
PERFORM TOP_OF_PAGE.
START-OF-SELECTION.
Perform Get_Region_Proj.
Perform Get_Timesheet_30.
Perform Get_Timesheet.
Perform Get_Ename_and_Rate.
Perform Build_Output.
Perform Build_Alv.
Perform Display_Output.
FORM Get_Timesheet_30 .
loop at i_vbak.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = i_vbak-vbeln
IMPORTING
OUTPUT = i_vbak-raufnr.
modify i_vbak.
clear i_vbak.
endloop.
Getting the active records for a particular employee, based on the
reference counter which does not indicates that its the active record
with and initial record.
Select WORKDATE PERNR RAUFNR RKOSTL AWART STATUS COUNTER REFCOUNTER
CATSHOURS ZZDESCRIPTION ERSDA ERSTM ERNAM LAEDA LAETM AENAM
Into Table I_CATSDB_30
From CATSDB
For all entries in I_VBAK
Where WORKDATE IN S_TSDATE
AND RAUFNR EQ I_VBAK-raufnr
AND PERNR IN S_EMPNO
AND RKOSTL IN S_COCENT
AND AWART IN S_ACTYP
AND STATUS = '30'
AND REFCOUNTER IS NOT NULL
AND WERKS = P_WERKS.
SORT I_CATSDB_30.
ENDFORM. " Get_Timesheet_60
&----
*& Form Get_Timesheet
&----
text
----
--> p1 text
<-- p2 text
----
FORM Get_Timesheet .
*Getting all records for the active records in I_CATSDB_30.
If I_CATSDB_30[] IS NOT INITIAL.
Select WORKDATE PERNR RAUFNR RKOSTL AWART
STATUS COUNTER REFCOUNTER CATSHOURS ZZDESCRIPTION
ERSDA ERSTM ERNAM LAEDA LAETM AENAM
Into Table I_CATSDB
From CATSDB
FOR ALL ENTRIES IN I_CATSDB_30
Where WORKDATE = I_CATSDB_30-WORKDATE
AND PERNR = I_CATSDB_30-PERNR
AND RAUFNR = I_CATSDB_30-RAUFNR
AND RKOSTL = I_CATSDB_30-RKOSTL
AND WERKS = P_WERKS.
Sort I_CATSDB ASCENDING BY WORKDATE PERNR RAUFNR RKOSTL
DESCENDING ERSDA ERSTM.
EndIf.
ENDFORM. " Get_Timesheet
&----
*& Form TOP_OF_PAGE
&----
text
----
FORM TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = ITAB_HEADING[]
EXCEPTIONS
OTHERS = 1.
ENDFORM. " TOP_OF_PAGE
&----
*& Form Display_Output
&----
text
----
--> p1 text
<-- p2 text
----
FORM Display_Output .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SYREPID
IS_LAYOUT = I_LAYOUT
IT_FIELDCAT = ITAB_FIELDCAT[]
IT_SORT = I_SORT[]
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
I_SAVE = 'A'
IT_EVENTS = I_EVENTS[]
TABLES
T_OUTTAB = I_OUTPUT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " Display_Output
&----
*& Form Get_Emp_Name
&----
text
----
--> p1 text
<-- p2 text
----
FORM Get_Ename_and_Rate .
Getting the individual employee and projects so that
we can get the names of the employees and the rates for the projects
For every IF & IN project we get the respective intercompany project
as well.
DATA : LEN TYPE i.
Loop at I_CATSDB.
At New PERNR.
Move I_CATSDB-PERNR to I_PERNR-PERNR.
Append I_PERNR.
Clear I_PERNR.
EndAt.
At New Raufnr.
LEN = STRLEN( I_CATSDB-RAUFNR ).
if len eq 8.
Move I_CATSDB-RAUFNR(6) to I_RAUFNR-RAUFNR.
Append I_RAUFNR.
Clear I_Raufnr.
endif.
Move I_CATSDB-RAUFNR to I_RAUFNR-RAUFNR.
Append I_RAUFNR.
Clear I_Raufnr.
EndAt.
Clear I_Raufnr.
EndLoop.
Sort : I_PERNR, I_RAUFNR.
DELETE ADJACENT DUPLICATES FROM I_PERNR.
DELETE ADJACENT DUPLICATES FROM I_RAUFNR.
Select PERNR ENAME
into table I_EMPNAME
From PA0001
For all entries in I_PERNR
Where PERNR = I_PERNR-PERNR
And BEGDA <= Sy-Datum
And ENDDA >= Sy-Datum.
SELECT AWART ATEXT FROM T554T
INTO TABLE I_ACTIVITY
WHERE SPRSL = 'EN'
AND MOABW = '40'.
SELECT KUNNR MATNR KNUMH FROM A901
INTO CORRESPONDING FIELDS OF TABLE I_A901
FOR ALL ENTRIES IN I_RAUFNR
WHERE KUNNR = I_RAUFNR-RAUFNR
AND DATBI GE S_TSDATE-HIGH
AND DATAB LE S_TSDATE-LOW.
SELECT KNUMH KBETR FROM KONP INTO TABLE I_KONP
FOR ALL ENTRIES IN I_A901
WHERE KNUMH = I_A901-KNUMH.
LOOP AT I_A901.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = i_a901-matnr
IMPORTING
OUTPUT = i_a901-pernr.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = i_a901-kunnr
IMPORTING
OUTPUT = i_a901-raufnr.
modify i_a901.clear i_a901.
ENDLOOP.
sort i_a901 by raufnr pernr.
ENDFORM. " Get_Emp_Name
&----
*& Form Build_Output
&----
text
----
--> p1 text
<-- p2 text
----
FORM Build_Output .
I_CATSDB_TMP[] = I_CATSDB[].
Loop at I_CATSDB.
If I_CATSDB-STATUS = '30'.
Read table I_VBAK with key raufnr = i_catsdb-raufnr.
if sy-subrc eq 0.
Read table I_Region with key vkgrp = i_vbak-vkgrp.
if sy-subrc = 0.
I_output-Bezei = I_Region-Bezei.
endif.
endif.
i_output-projcc = i_catsdb-raufnr.
Read table I_ACTIVITY with key awart = I_CATSDB-Awart.
if sy-subrc = 0.
i_output-atext = i_activity-atext.
endif.
i_output-workdate = i_catsdb-workdate.
i_output-pernr = i_catsdb-pernr.
Read table I_EMPNAME with key pernr = I_CATSDB-pernr.
if sy-subrc = 0.
i_output-pernr = i_empname-pernr.
i_output-ename = i_empname-ename.
endif.
data : tmp_refc like catsdb-refcounter.
tmp_refc = i_catsdb-refcounter.
while not tmp_refc is initial .
read table i_catsdb_tmp with key counter = tmp_refc.
if sy-subrc = 0.
tmp_refc = i_catsdb_tmp-refcounter.
endif.
endwhile.
i_output-inithrs = i_catsdb_tmp-catshours.
read table i_catsdb_tmp with key pernr = i_catsdb-pernr
awart = i_catsdb-awart
workdate = i_catsdb-workdate
raufnr = i_catsdb-raufnr
rkostl = i_catsdb-rkostl
refcounter = ''.
if sy-subrc = 0.
i_output-inithrs = i_catsdb_tmp-catshours.
endif.
i_output-finhrs = i_catsdb-catshours.
i_output-delta = i_output-finhrs - i_output-inithrs.
Read table i_vbak with key raufnr = i_catsdb-raufnr.
If the sales org is 0030, then we take the rate from the respective
intercompany project.
If sy-subrc = 0.
if i_vbak-vkorg = '0030'.
Read table i_a901 with key pernr = i_catsdb-pernr
raufnr = i_catsdb-raufnr(6).
if sy-subrc = 0.
Read table i_konp with key knumh = i_a901-knumh.
if sy-subrc = 0.
i_output-rate = i_konp-kbetr.
endif.
endif.
else.
Read table i_a901 with key pernr = i_catsdb-pernr
raufnr = i_catsdb-raufnr.
if sy-subrc = 0.
Read table i_konp with key knumh = i_a901-knumh.
if sy-subrc = 0.
i_output-rate = i_konp-kbetr.
endif.
endif.
endif.
endif.
i_output-amount = i_output-rate * i_output-delta.
append i_output.
clear : i_output, i_vbap, i_catsdb_tmp, i_empname,
i_activity, i_vbak, i_catsdb, i_a901,i_konp.
endif.
EndLoop.
sort i_output by bezei atext projcc workdate pernr.
ENDFORM. " Build_Output
&----
*& Form Fill_FieldCat
&----
text
----
--> p1 text
<-- p2 text
----
FORM Fill_FieldCat .
CLEAR ITAB_FIELDCAT.
ITAB_FIELDCAT-TABNAME = 'I_OUTPUT'.
ITAB_FIELDCAT-FIELDNAME = 'BEZEI'.
ITAB_FIELDCAT-COL_POS = 1.
ITAB_FIELDCAT-OUTPUTLEN = 20.
ITAB_FIELDCAT-JUST = 'C'.
ITAB_FIELDCAT-SELTEXT_M = 'REGION'.
APPEND ITAB_FIELDCAT.CLEAR ITAB_FIELDCAT.
ITAB_FIELDCAT-TABNAME = 'I_OUTPUT'.
ITAB_FIELDCAT-FIELDNAME = 'ATEXT'.
ITAB_FIELDCAT-COL_POS = 2.
ITAB_FIELDCAT-OUTPUTLEN = 25.
ITAB_FIELDCAT-SELTEXT_M = 'ACTIVITY TYPE'.
APPEND ITAB_FIELDCAT.CLEAR ITAB_FIELDCAT.
ITAB_FIELDCAT-TABNAME = 'I_OUTPUT'.
ITAB_FIELDCAT-FIELDNAME = 'PROJCC'.
ITAB_FIELDCAT-COL_POS = 3.
ITAB_FIELDCAT-OUTPUTLEN = 10.
ITAB_FIELDCAT-SELTEXT_M = 'PROJECT'.
APPEND ITAB_FIELDCAT.CLEAR ITAB_FIELDCAT.
ITAB_FIELDCAT-TABNAME = 'I_OUTPUT'.
ITAB_FIELDCAT-FIELDNAME = 'WORKDATE'.
ITAB_FIELDCAT-COL_POS = 4.
ITAB_FIELDCAT-OUTPUTLEN = 16.
ITAB_FIELDCAT-SELTEXT_L = 'TIME SHEET DATE'.
APPEND ITAB_FIELDCAT.CLEAR ITAB_FIELDCAT.
ITAB_FIELDCAT-TABNAME = 'I_OUTPUT'.
ITAB_FIELDCAT-FIELDNAME = 'ENAME'.
ITAB_FIELDCAT-COL_POS = 5.
ITAB_FIELDCAT-OUTPUTLEN = 25.
ITAB_FIELDCAT-SELTEXT_L = 'EMPLOYEE'.
APPEND ITAB_FIELDCAT.CLEAR ITAB_FIELDCAT.
ITAB_FIELDCAT-TABNAME = 'I_OUTPUT'.
ITAB_FIELDCAT-FIELDNAME = 'INITHRS'.
ITAB_FIELDCAT-COL_POS = 6.
ITAB_FIELDCAT-OUTPUTLEN = 12.
ITAB_FIELDCAT-SELTEXT_L = 'INITIAL HRS'.
APPEND ITAB_FIELDCAT.CLEAR ITAB_FIELDCAT.
ITAB_FIELDCAT-TABNAME = 'I_OUTPUT'.
ITAB_FIELDCAT-FIELDNAME = 'FINHRS'.
ITAB_FIELDCAT-COL_POS = 7.
ITAB_FIELDCAT-OUTPUTLEN = 12.
ITAB_FIELDCAT-SELTEXT_M = 'FINAL HRS'.
APPEND ITAB_FIELDCAT.CLEAR ITAB_FIELDCAT.
ITAB_FIELDCAT-TABNAME = 'I_OUTPUT'.
ITAB_FIELDCAT-FIELDNAME = 'DELTA'.
ITAB_FIELDCAT-COL_POS = 8.
ITAB_FIELDCAT-OUTPUTLEN = 10.
ITAB_FIELDCAT-SELTEXT_M = 'VARIANCE'.
APPEND ITAB_FIELDCAT.CLEAR ITAB_FIELDCAT.
ITAB_FIELDCAT-TABNAME = 'I_OUTPUT'.
ITAB_FIELDCAT-FIELDNAME = 'RATE'.
ITAB_FIELDCAT-COL_POS = 9.
ITAB_FIELDCAT-OUTPUTLEN = 10.
ITAB_FIELDCAT-SELTEXT_M = 'RATE'.
APPEND ITAB_FIELDCAT.CLEAR ITAB_FIELDCAT.
ITAB_FIELDCAT-TABNAME = 'I_OUTPUT'.
ITAB_FIELDCAT-FIELDNAME = 'AMOUNT'.
ITAB_FIELDCAT-COL_POS = 10.
ITAB_FIELDCAT-OUTPUTLEN = 10.
ITAB_FIELDCAT-SELTEXT_M = 'Amount'.
APPEND ITAB_FIELDCAT.CLEAR ITAB_FIELDCAT.
ENDFORM. " Fill_FieldCat
&----
*& Form Fill_Layout
&----
text
----
--> p1 text
<-- p2 text
----
FORM Fill_Layout .
I_LAYOUT-ZEBRA = 'X'.
I_LAYOUT-WINDOW_TITLEBAR = TEXT-001.
I_LAYOUT-TOTALS_TEXT = 'Grand Total'.
ENDFORM. " Fill_Layout
&----
*& Form Get_Region_Proj
&----
text
----
--> p1 text
<-- p2 text
----
FORM Get_Region_Proj .
Getting the Sales Org & Region for a project.
Select VBELN VKORG VKGRP KNUMV from VBAK
into corresponding fields of table I_VBAK
where vkgrp in S_REGIO and
vbeln in S_PCODE and
vbtyp eq 'G'.
Getting the Region & its resp. Description.
Select vkgrp bezei from tvgrt
into table i_region
where spras = 'EN'.
ENDFORM. " Get_Region_Proj
&----
*& Form Build_Sort
&----
text
----
--> p1 text
<-- p2 text
----
FORM Build_Sort .
I_SORT-SPOS = 1.
I_SORT-TABNAME = 'I_output'.
I_SORT-FIELDNAME = 'BEZEI'.
I_SORT-UP = 'X'.
I_SORT-SUBTOT = 'X'.
I_SORT-GROUP = 'UL'.
APPEND I_SORT. CLEAR I_SORT.
I_SORT-SPOS = 2.
I_SORT-TABNAME = 'I_output'.
I_SORT-FIELDNAME = 'ATEXT'.
I_SORT-UP = 'X'.
I_SORT-SUBTOT = 'X'.
I_SORT-GROUP = 'UL'.
APPEND I_SORT. CLEAR I_SORT.
I_SORT-SPOS = 3.
I_SORT-TABNAME = 'I_output'.
I_SORT-FIELDNAME = 'PROJCC'.
I_SORT-UP = 'X'.
I_SORT-SUBTOT = 'X'.
I_SORT-GROUP = 'UL'.
APPEND I_SORT. CLEAR I_SORT.
ENDFORM. " Build_Sort
&----
*& Form Build_Alv
&----
text
----
--> p1 text
<-- p2 text
----
FORM Build_Alv .
Perform Fill_FieldCat.
Perform Build_Sort.
Perform Fill_Layout.
ENDFORM. " Build_Alv
‎2006 Sep 27 3:49 AM
‎2006 Sep 27 4:03 AM
I notice that the i_a901 pernr is populated via a conversion exit fm, maybe the formats of the two pernrs are different and this causes the read table to fail?
‎2006 Sep 27 4:11 AM
‎2006 Sep 27 4:13 AM
try using the statement like this
Read table i_a901 with key raufnr = i_catsdb-raufnr
pernr = i_catsdb-pernr
binary search.
Regards
Gopi
‎2006 Sep 27 4:42 AM
when I say formats I mean you have reformatted the i_a901 pernr via the fm but maybe the other one is still in the other format??
‎2006 Sep 27 4:44 AM
Hi Thiru,
Could u check the values populated in the interenal tables i_a901 and i_catsdb for pernr and raufnr while debugging this statement ..
And one more thing .. Check ur form "Get_Ename_and_Rate"
the place where u have looped at "i_a901"
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = i_a901-kunnr
IMPORTING
OUTPUT = i_a901-raufnr.
U have tried to convert customer number to a project ... (just check is this the problem? as i guess CATSDB-RAUFNR stores the projects and not the customer numbers)
Cheers
Kripa Rangachari .......
‎2006 Sep 27 3:12 PM
hi kripa,
Kunnr in i_a901 stores the project codes, and i_catsdb-raufnr the project codes as well, therefore i have used exit alpha to convert the types and make it same so that it can be read from the table.
Cheers,
Thiru
‎2006 Sep 27 3:14 PM
Hi Neil,
Both pernrs are in the same format. I checked that out.