2010 Apr 19 6:08 PM
Dear Experts,
my requirement is to extract the following fields from bseg table with BKPF (Header table).
1. Value Date,
2. Posting Date,
3. Company Code,
4.
5. Partner Profit Center,
6. Account Number,
7. Amt in Local currency.
sequence 4 Profit Center field should need to extract from CSKS Table (CSKS-PRCTR).
for this i need to check COST CENTER (BSEG-KOSTL) field in BSEG then extract Profit Center from CSKS table.
I got the CSKS-PRCTR value in IT_CSKS, But in read talbe the value is not moving to final internal table,
Can anyone help me what is correct mapping in Read table between BSEG and CSKS Table. (common field b/w two table)
kindly please advise.
Thanks in advance.
skumar.
Dear Experts,
my requirement is to extract the following fields from bseg table with BKPF (Header table).
1. Value Date,
2. Posting Date,
3. Company Code,
4.
5. Partner Profit Center,
6. Account Number,
7. Amt in Local currency.
sequence 4 Profit Center field should need to extract from CSKS Table (CSKS-PRCTR).
for this i need to check COST CENTER (BSEG-KOSTL) field in BSEG then extract Profit Center from CSKS table.
I got the CSKS-PRCTR value in IT_CSKS, But in read talbe the value is not moving to final internal table,
Can anyone help me what is correct mapping in Read table between BSEG and CSKS Table. (common field b/w two table)
kindly please advise.
Thanks in advance.
skumar.
2010 Apr 19 6:29 PM
read first the entries from BSEG based on your selection including the fields KOKRS and KOSTL into a internal table and then try to map both the fileds KOKRS and KOSTL into CSKS table. It should work
thanks
Abhi
2010 Apr 19 6:32 PM
below is my code:
Moderator message - Please respect the 2,500 character maximum when posting. Post only the relevant portions of code
Edited by: Rob Burbank on Apr 19, 2010 1:37 PM
2010 Apr 19 6:51 PM
Below is my code.
SELECT BUKRS BELNR GJAHR MONAT BUDAT FROM BKPF
INTO TABLE IT_BKPF
SELECT BUKRS BELNR GJAHR SHKZG DMBTR
HKONT KOSTL PRCTR PPRCT FROM BSEG
INTO CORRESPONDING FIELDS OF TABLE IT_BSEG FOR ALL ENTRIES IN IT_BKPF
WHERE BELNR = IT_BKPF-BELNR
SELECT KOKRS KOSTL BUKRS PRCTR FROM CSKS INTO TABLE IT_CSKS
FOR ALL ENTRIES IN IT_BSEG
WHERE KOKRS = IT_BSEG-KOKRS
AND KOSTL = IT_BSEG-KOSTL
AND BUKRS = IT_BSEG-BUKRS.
ENDIF.
LOOP AT IT_BSEG.
IT_FINAL-BUKRS = IT_BSEG-BUKRS.
READ TABLE IT_CSKS WITH KEY KOKRS = IT_BSEG-KOKRS
KOSTL = IT_BSEG-KOSTL
BUKRS = IT_BSEG-BUKRS.
IF SY-SUBRC = 0.
IT_FINAL-PRCTR = IT_CSKS-PRCTR2.
ENDIF.
APPEND IT_FINAL.
ENDLOOP.
please advise. Thanks.
Edited by: skumar.merp on Apr 19, 2010 7:52 PM
2010 Apr 19 7:00 PM
Well, you aren't checking sy-subrc after the SELECT on BSEG. You may not be returning any records there.
Rob
2010 Apr 19 7:37 PM
Hi Abhi & Rob
Thanks lot for reply. Sorry I am new to abap, itab mappings are quite confusing , I understand i need to use sy-subrc check. select from bkpf into it_bkpf(Header data)
select from bseg into it_bseg(Line Item)
if sy-subrc =0
select from csks into it_csks (Profit Center)
endif.
Loop at it_bseg.
move it_bseg field to it_final.
READ TABLE IT_CSKS WITH KEY KOKRS =IT_BSEG-KOKRS
KOSTL = IT_BSEG-KOSTL
IF SY-SUBRC = 0.
IT_FINAL-PRCTR = IT_CSKS-PRCTR2.
ENDIF.
endloop.
write statements...
please advice the above points are correct?
Thanks.
skumar
2010 Apr 19 7:47 PM
Move the ENDIF that is now after the SELECT FROM csks after the LOOP on bseg.
Rob
2010 Apr 19 7:49 PM
<use WHERE condition as the table would have lot of data otherwise to read from BKPF>
SELECT BUKRS BELNR GJAHR MONAT BUDAT FROM BKPF
INTO TABLE IT_BKPF WHERE <conditions>
if sy-subrc = 0.
SELECT BUKRS BELNR GJAHR SHKZG DMBTR
HKONT KOSTL PRCTR PPRCT FROM BSEG
INTO CORRESPONDING FIELDS OF TABLE IT_BSEG
FOR ALL ENTRIES IN IT_BKPF WHERE BELNR = IT_BKPF-BELNR
if sy-subrc = 0.
SELECT KOKRS KOSTL BUKRS PRCTR FROM CSKS INTO TABLE IT_CSKS
FOR ALL ENTRIES IN IT_BSEG
WHERE KOKRS = IT_BSEG-KOKRS
AND KOSTL = IT_BSEG-KOSTL
AND BUKRS = IT_BSEG-BUKRS.
if sy-subrc = 0.
SORT IT_CSKS BY KOKRS
KOSTL.
LOOP AT IT_BSEG.
IT_FINAL-BUKRS = IT_BSEG-BUKRS.
READ TABLE IT_CSKS WITH KEY KOKRS = IT_BSEG-KOKRS
KOSTL = IT_BSEG-KOSTL BINARY SEARCH.
IF SY-SUBRC = 0.
IT_FINAL-PRCTR = IT_CSKS-PRCTR2.
ENDIF.
APPEND IT_FINAL.
CLEAR IT_FINAL.
ENDLOOP.
endif.
endif.
endif.
Thanks
Abhi
2010 Apr 19 8:02 PM
Hi Abhi & Rob,
I have got better understading. Thank you very much for kind assistance.
Thanks
skumar.
2010 Apr 19 9:37 PM
When querying BSEG you should use all fields from BKPF primary key not just BELNR.
You can have the same doc number in different years or company codes.
2010 Apr 22 12:38 PM
Hi All my program is working now thank you for helpful source codes and ideas.
Thanks
Regards
Skumar
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |