Application Development 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: 

How to use the next 'initial' cost center in infotype 0027

Former Member
0 Kudos

Hello experts!

I need some help in posting in infotype 0027 which should be fairly easy to most of you. As you guys know, there are a total of 25 cost centers available (KST01-KST25) for this infotype. What I want to do is check from KST01 if it exists with a valid entry at a specific date (BEGDA and ENDDA will be provided as well) all the way up to KST25 and choose the first cost center field that is INITIAL. This is used before 'BAPI_COSTCENTER_CREATEMULTIPLE' so that if KST01 up to KST05 all have values on the same BEGDA & ENDDA, how can I have KST06 chosen? Thanks in advance for your help!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Write as below.

data : p_0027 like pa0027 occurs 0 with header line.

data : lv_KOSTL type KOSTL.

data : lv_index(2) type n.

data : lv_cost(12).

field-symbols : <lv_kostl> type any.

select single * from pa0027 into p_0027.

do 25 times

varying lv_KOSTL from p_0027-KST01 next p_0027-KST02.

lv_index = lv_index + 1.

IF lv_KOSTL is initial.

concatenate 'KST' lv_index into lv_cost.

exit.

endif.

enddo.

assign component lv_cost of structure p_0027 to <lv_kostl>.

IF sy-subrc = 0.

<lv_kostl> = '100'. " <-- Assign any value here

ENDIF.

Regards,

Srini.

4 REPLIES 4

Former Member
0 Kudos

Hi,

Write as below.

data : p_0027 like pa0027 occurs 0 with header line.

data : lv_KOSTL type KOSTL.

data : lv_index(2) type n.

data : lv_cost(12).

field-symbols : <lv_kostl> type any.

select single * from pa0027 into p_0027.

do 25 times

varying lv_KOSTL from p_0027-KST01 next p_0027-KST02.

lv_index = lv_index + 1.

IF lv_KOSTL is initial.

concatenate 'KST' lv_index into lv_cost.

exit.

endif.

enddo.

assign component lv_cost of structure p_0027 to <lv_kostl>.

IF sy-subrc = 0.

<lv_kostl> = '100'. " <-- Assign any value here

ENDIF.

Regards,

Srini.

0 Kudos

Hi Srini.

Thanks for your reply. However, when I try to check for syntax errors, I get the error "The addition OCCURS is no longer supported in the OO context. use "TABLE OF ..... INITIAL SIZE instead"" I am currently coding this in a method in se24 but I don't have an idea how "TABLE OF.. INITIAL SIZE" will be used, can you please help me with this one? Thank you very much.

0 Kudos

Hi,

Instead you can just declare a work area ..

data : p_0027 type pa0027.

data : lv_KOSTL type KOSTL.

data : lv_index(2) type n.

data : lv_cost(12).

field-symbols : <lv_kostl> type any.

select single * from pa0027 into p_0027.

do 25 times

varying lv_KOSTL from p_0027-KST01 next p_0027-KST02.

lv_index = lv_index + 1.

IF lv_KOSTL is initial.

concatenate 'KST' lv_index into lv_cost.

exit.

endif.

enddo.

assign component lv_cost of structure p_0027 to <lv_kostl>.

IF sy-subrc = 0.

<lv_kostl> = '100'. " <-- Assign any value here

ENDIF.

Regards,

Srini.

0 Kudos

Thank you very much this has solved my problem thanks a lot