Skip to Content
avatar image
Former Member

SAP Scripts

Ho we can use subroutines in SAP scripts

Can anyoine help with some examples

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Aug 20, 2007 at 09:35 AM

    Hi,

    You can use the PERFORM command to call an ABAP subroutine (form) from any program, subject to the normal ABAP runtime authorization checking. You can use such calls to subroutines for carrying out calculations, for obtaining data from the database that is needed at display or print time, for formatting data, and so on.

    PERFORM commands, like all control commands, are executed when a document is formatted for display or printing. Communication between a subroutine that you call and the document is by way of symbols whose values are set in the subroutine.

    Syntax in a form window:

    /: PERFORM <form> IN PROGRAM <prog>

    /: USING &INVAR1&

    /: USING &INVAR2&

    ......

    /: CHANGING &OUTVAR1&

    /: CHANGING &OUTVAR2&

    ......

    /: ENDPERFORM

    INVAR1 and INVAR2 are variable symbols and may be of any of the four SAPscript symbol types.

    OUTVAR1 and OUTVAR2 are local text symbols and must therefore be character strings.

    The ABAP subroutine called via the command line stated above must be defined in the ABAP report prog as follows:

    FORM <form> TABLES IN_TAB STRUCTURE ITCSY

    OUT_TAB STRUCTURE ITCSY.

    ...

    ENDFORM.

    Definition in the SAPscript form:

    /: PERFORM GET_BARCODE IN PROGRAM QCJPERFO

    /: USING &PAGE&

    /: USING &NEXTPAGE&

    /: CHANGING &BARCODE&

    /: ENDPERFORM

    /

    / &BARCODE&

    Coding of the calling ABAP program:

    REPORT QCJPERFO.

    FORM GET_BARCODE TABLES IN_PAR STUCTURE ITCSY

    OUT_PAR STRUCTURE ITCSY.

    DATA: PAGNUM LIKE SY-TABIX, "page number

    NEXTPAGE LIKE SY-TABIX. "number of next page

    READ TABLE IN_PAR WITH KEY ‘PAGE’.

    CHECK SY-SUBRC = 0.

    PAGNUM = IN_PAR-VALUE.

    READ TABLE IN_PAR WITH KEY ‘NEXTPAGE’.

    CHECK SY-SUBRC = 0.

    NEXTPAGE = IN_PAR-VALUE.

    READ TABLE OUT_PAR WITH KEY ‘BARCODE’.

    CHECK SY-SUBRC = 0.

    IF PAGNUM = 1.

    OUT_PAR-VALUE = ‘|’. "First page

    ELSE.

    OUT_PAR-VALUE = ‘||’. "Next page

    ENDIF.

    IF NEXTPAGE = 0.

    OUT_PAR-VALUE+2 = ‘L’. "Flag: last page

    ENDIF.

    MODIFY OUT_PAR INDEX SY-TABIX.

    ENDFORM.

    Reward if it helps..

    Regards,

    Omkar.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 20, 2007 at 09:37 AM

    Hi,

    for calling subroutines in script form by using PERFORM --- ENDPERFORM control commandS..

    /:PERFORM <name> IN PROGRAM <program_name>

    /:USING <parameter>

    /:CHANGING <parameter>

    /:ENDPERFORM

    while calling subroutine you must pass one parameter only for one line.

    you mus specifies the program name in which subroutine is available.

    while declaring subroutine, you must define subroutine formal parameters of type structure ITCSY, otherwise error will be raised..

    FORM <name> TABLES <input> STRUCTURE ITCSY

    <output> STRUCTURE ITCSY.

    here write the logic...

    ENDFORM.

    Refer this link

    http://aiokeh.wdf.sap.corp:50000/SAPIKS2/contentShow.sap?_SCLASS=IWB_STRUCT&_SLOIO=D2CB3D07455611D189710000E8322D00&IWB_INDUSTRY=SAP_BW&TMP_IWB_TASK=DISPLAY&RELEASE=710&LANGUAGE=EN&_SEQNUM=80&_LOIO=D180318F454211D189710000E8322D00&_CLASS=IWB_EXTHLP

    Regards,

    Priyanka.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 20, 2007 at 09:43 AM

    Calling ABAP Subroutines: PERFORM

    You can use the PERFORM command to call an ABAP subroutine (form) from any program, subject to the normal ABAP runtime authorization checking. You can use such calls to subroutines for carrying out calculations, for obtaining data from the database that is needed at display or print time, for formatting data, and so on.

    PERFORM commands, like all control commands, are executed when a document is formatted for display or printing. Communication between a subroutine that you call and the document is by way of symbols whose values are set in the subroutine.

    Syntax in a form window:

    /: PERFORM <form> IN PROGRAM <prog>

    /: USING &INVAR1&

    /: USING &INVAR2&

    ......

    /: CHANGING &OUTVAR1&

    /: CHANGING &OUTVAR2&

    ......

    /: ENDPERFORM

    Regards,

    Suruchi

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 20, 2007 at 09:49 AM

    Hi..

    Calling Subroutine from Layout set.

    Detailed procedure:

    1. IN THE LAYOUT SET MAIN WINDOW

    /: TOP

    /E ELE_TOP

    /: DEFINE &PAGE_TOTAL& = '0'

    /: ENDTOP

    /: MAIN

    /E E

    /: PERFORM GET_PAGE_TOTAL IN PROGRAM <YOUR PRINT PROGRAM>

    /: USING &STVBAK-NETWR&

    /: CHANGING &PAGE_TOTAL&

    /: ENDPERFORM

    /: BOTTOM

    • 'Page total for NETWR = ' , &PAGE_TOTAL&

    /: ENDBOTTOM

    CREATE THIS SUBROTINE IN YOUR PROGRAM

    FORM GET_PAGE_TOTAL

    TABLE INTAB STRUCTURE ITCSY

    OUTTAB STRUCTURE ITCSY.

    DATA : L_AMT TYPE P DECIMALS 2,

    L_TOTAL TYPE P DECIMALS 2.

    Read Table INTAB with KEY NAME = 'STVBAK-NETWR'.

    IF SY-SUBRC = 0.

    L_AMT = INTAB-VALUE.

    ENDIF.

    Read Table OUTTAB with KEY NAME = 'PAGE_TOTAL'.

    IF SY-SUBRC = 0.

    L_TOTAL = OUTTAB-VALUE.

    ADD L_AMT TO L_TOTAL.

    WRITE L_TOTAL TO OUTTAB-VALUE LEFT-JUSTIFIED.

    MODIFY OUTTAB INDEX SY-TABIX.

    ENDIF.

    ENDFORM.

    <b>Reward if Helpful</b>

    Add comment
    10|10000 characters needed characters exceeded