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

code for add the cost center description in sapscript ?

Former Member
0 Kudos
4,647

Hi every body

I wrote this program for read the cost center description from CSKT Table:

REPORT ZRED_RES_COSTCENTER.
FORM get_coster TABLES IN_PAR STRUCTURE ITCSY
OUT_PAR STRUCTURE ITCSY.
DATA: Coster TYPE CSKT-LTEXT .
READ TABLE IN_PAR WITH KEY NAME = 'MSEG-KOSTL'.
IF SY-SUBRC IS INITIAL.
READ TABLE OUT_PAR WITH KEY NAME = 'COSTERNAME'.
IF SY-SUBRC IS INITIAL.
SELECT SINGLE LTEXT INTO coster FROM CSKT WHERE KOSTL EQ IN_PAR-VALUE .
OUT_PAR-VALUE = Coster .
MODIFY OUT_PAR INDEX SY-TABIX.
ENDIF.
ENDIF.

ENDFORM.

but when I use this program in the sapscript , it dosen't work.

cost center in CSKT table like this:

in MSEG table :

can u help me please?

18 REPLIES 18
Read only

mmcisme1
Active Contributor
0 Kudos
4,232

You may get a better answer for you. Because what I suggest could be time consuming. I try to never write my code in a SapScript. I copy the SAP program that call the SAPScript and then make the changes there. If your SAPscript has the same fields as your program, it always works. If it doesn't work it's very easy to debug.

Read only

Former Member
0 Kudos
4,232

can you please explain a little more? how can I add the cost center description to sapscript from material document (mseg table ) ?

Read only

Former Member
0 Kudos
4,232

in the MB51 cost center format different with the tables:

here cost center XXXXX but in the CSKT like this 00000XXXXX

when the program read the cost center number which format comes?maybe problem is it. can anyone guide me?

Read only

hedvig_rohonyi
Product and Topic Expert
Product and Topic Expert
4,232

Hi,

I checked your code and if I understand it correctly the description is stored in field &costername&.

But instead it the field &costcenter& is displayed in the form. Is it right?

Best regards,

Hedvig

Read only

0 Kudos
4,232

no it dosen't display anything

Read only

0 Kudos
4,232

when I used the MSEG-KOSTL directly in the main window of form , cost center displayed like this : XXXXX

zeros dose not display.but CSKT-LTEXT format is 00000XXXXX

I don't know when the read this section of the program "

SELECT SINGLE LTEXT INTO coster FROM CSKT WHERE KOSTL EQ IN_PAR-VALUE .
OUT_PAR-VALUE = Coster ."

it's true or not?

Read only

0 Kudos
4,232

I don't understand if you're talking about the description of the cost center or about its number.

As far as I understand, your question is answered (solved for the description), and you should mark Hedvig's answer as correct.

Now your question is about the cost center number? Although it's a continuation for you, it should be posted as a new question in the forum.

Read only

4,232

My question about the cost center description. I give you more information for solve the my problem. In the sapcript form there is the cost center number. I want to display cost center description. I told you maybe formt of cost center number that com from MSEG table diffrent with CSKT then program dosen't work maybe. I didn't say my question about descrption is solved.

Read only

0 Kudos
4,232

Thanks. I understand now. The values of the cost center number are stored with leading zeroes in the database (stored in so-called internal values), but output without these zeroes (external values). So, you should better debug your code to make sure what's going on (in debug you always see the internal value, i.e. with leading zeroes).

Read only

4,232

hi

result of debug: it doesn't display anything.

Read only

0 Kudos
4,232

But what is the value of MSEG-KOSTL, and did you debug the subroutine GET_COSTER? You'll find out what's going on, for sure.

Read only

0 Kudos
4,232

how can i see the MSEG-KOSTL vlaues ?

Read only

0 Kudos
4,232

The same way as you did for *MKPF-CPUDT

Read only

0 Kudos
4,232

By the way, I see a trailing dot in the line PERFORM, it shouldn't be there. Maybe the PERFORM fails.

Read only

mmcisme1
Active Contributor
0 Kudos
4,232

What happens when the SAPScript runs? Does it give you a short dump?

It looks like:

perform get_coster in program zreadres_costcenter using &mseg-kostl&
                                                   changing &costername&.

Doesn't match your parameters in the form:

FORM get_coster TABLES IN_PAR STRUCTURE ITCSYOUT_PAR STRUCTURE ITCSY
                       OUT_PAR STRUCTURE ITCSY.
                          

So when the code runs is there a short dump? Look at your perform

perform get_coster in program zreadres_costcenter TABLES IN_PAR STRUCTURE ITCSYOUT_PAR STRUCTURE ITCSY
                                                         OUT_PAR STRUCTURE ITCSY.

That should work - I think. Also look at Hedvig's answer.


Read only

Jelena_Perfiljeva
Active Contributor
0 Kudos
4,232
SELECT SINGLE LTEXT INTO coster FROM CSKT WHERE KOSTL EQ IN_PAR-VALUE .

Don't use the parameter (here IN_PAR-VALUE) like that in the SAPScript routines, it's a straight path to failure. Declare another variable with the same type as CSKT-KOSTL and use that. Don't forget to call the conversion routine to make sure leading zeroes are added.

Also SPRAS and KOKRS should be in SELECT since they're key fields, otherwise you'll be in for an unpleasant surprise down the line.

And +1 to Sandra's comments.

Read only

0 Kudos
4,232

as you said maybe this path is failure.

look at table CSKT : there are two value for cost center description (language EN and FA)

Read only

0 Kudos
4,232

This was not mentioned before. Obviously, with this data you must use language as well.

And this screenshot also clearly shows leading zeroes in the cost center, so that's clearly a problem here. (Thought we've established that already though.)