Skip to Content
-1

code for add the cost center description in sapscript ?

Feb 22 at 10:50 AM

113

avatar image

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?

capture1.jpg (90.1 kB)
capture.jpg (82.1 kB)
capture.jpg (19.8 kB)
10 |10000 characters needed characters left characters exceeded

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.

0

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

0

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.


0
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Hedvig Rohonyi
Feb 23 at 11:31 AM
1

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

Show 10 Share
10 |10000 characters needed characters left characters exceeded

no it dosen't display anything

capture2.jpg (53.9 kB)
0

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?

0

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.

0

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.

1

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).

0

hi

result of debug: it doesn't display anything.

1

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.

0
Show more comments

The same way as you did for *MKPF-CPUDT

0

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

0
ali khojaloo Feb 23 at 05:44 AM
-1

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?


capture.jpg (42.2 kB)
Share
10 |10000 characters needed characters left characters exceeded
Jelena Perfiljeva
Mar 12 at 06:51 PM
0
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.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

as you said maybe this path is failure.

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

2.jpg (33.8 kB)
0

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.)

0