Skip to Content
-1

code for add the cost center description in sapscript ?

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)
Add comment
10|10000 characters needed 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.

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

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


  • Get RSS Feed

3 Answers

  • Feb 23 at 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

    Add comment
    10|10000 characters needed characters exceeded

  • 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?

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 12 at 06: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.

    Add comment
    10|10000 characters needed characters exceeded

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