Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Read Table mapping between BSEG and CSKS table

Former Member
0 Likes
2,056

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.

10 REPLIES 10
Read only

Former Member
0 Likes
1,556

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

Read only

Former Member
0 Likes
1,556

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

Read only

0 Likes
1,556

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

Read only

0 Likes
1,556

Well, you aren't checking sy-subrc after the SELECT on BSEG. You may not be returning any records there.

Rob

Read only

0 Likes
1,556

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

Read only

0 Likes
1,556

Move the ENDIF that is now after the SELECT FROM csks after the LOOP on bseg.

Rob

Read only

Former Member
0 Likes
1,556

<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

Read only

0 Likes
1,556

Hi Abhi & Rob,

I have got better understading. Thank you very much for kind assistance.

Thanks

skumar.

Read only

0 Likes
1,556

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.

Read only

0 Likes
1,556

Hi All my program is working now thank you for helpful source codes and ideas.

Thanks

Regards

Skumar