2018 Feb 22 10:50 AM
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?
2018 Feb 22 6:52 PM
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.
2018 Feb 23 5:18 AM
can you please explain a little more? how can I add the cost center description to sapscript from material document (mseg table ) ?
2018 Feb 23 5:44 AM
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?
2018 Feb 23 11:31 AM
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
2018 Feb 24 7:21 AM
2018 Feb 24 7:37 AM
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?
2018 Feb 24 9:14 AM
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.
2018 Feb 24 7:41 PM
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.
2018 Feb 24 7:56 PM
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).
2018 Mar 12 11:46 AM
2018 Mar 12 12:16 PM
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.
2018 Mar 12 12:36 PM
2018 Mar 12 3:38 PM
2018 Mar 12 3:39 PM
By the way, I see a trailing dot in the line PERFORM, it shouldn't be there. Maybe the PERFORM fails.
2018 Feb 23 1:09 PM
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.
2018 Mar 12 6:51 PM
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.
2018 Mar 13 4:59 AM
as you said maybe this path is failure.
look at table CSKT : there are two value for cost center description (language EN and FA)

2018 Mar 13 6:58 PM
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.)