Sunday, 29 July 2012

Using Perform in a SAP Script

The purpose of this post is to demonstrate how to call a subroutine from an SAP Script.

There might be a requirement where you may have to call a form from within the window of a SAP Script.It can be used for formatting of the output or performing some calculations.

Example : We will call a subroutine from the script to format the output. Suppose the variable coming from the print program contains a date and the requirement is to insert a blank space between each digit.

IN SCRIPT:

We use a DEFINE statement in SAP Script to declare local variables. These are of character type by default.

/* define a local variable variable2 in sap script to hold value of zdate coming from print program.
/: DEFINE &VARIABLE2& := &ZDATE&.
/* call the subroutine in report ztest
/: SET DATE MASK = 'DDMMYYYY'
/: PERFORM CHANGE_FORMAT IN PROGRAM ZTEST
/: USING &ZDATE&
/: CHANGING &VARIABLE2&
/: ENDPERFORM
/* display the  changed value
* &VARIABLE2&


IN PROGRAM:

The form definition can be given in any report and not necessarily in print program.

DATA  : LD TYPE C LENGTH 15.

FORM CHANGE_FORMAT TABLES L_DATA_IN STRUCTURE ITCSY L_DATA_OUT STRUCTURE ITCSY.
CLEAR : LD.
READ TABLE L_DATA_IN INDEX 1.
MOVE L_DATA_IN-VALUE TO LD.

CONCATENATE  LD+0(1)
                               LD+1(1)
                               LD+2(1)
                               LD+3(1)
                               LD+4(1)
                               LD+5(1)
                               LD+6(1)
                               LD+7(1)
INTO LD SEPARATED BY SPACE.

READ TABLE L_DATA_OUT INDEX 1.
MOVE LD TO L_DATA_OUT-VALUE.
MODIFY L_DATA_OUT INDEX 1.

ENDFORM.


RESULT:

INPUT VALUE IN ZDATE : 29072012

OUTPUT VALUE IN VARIABLE2 : 2 9 0 7 2 0 1 2


3 comments:

  1. how can i enable sgtxt in credit to show irrespective of the document type.

    ReplyDelete
  2. how can i enable sgtxt in credit to show irrespective of the document type.

    ReplyDelete
  3. I need the text in field BSED-SGTXT to appear in my sap script print out. I do not want any condition(i.e. document types) to be placed. Please help!! Thank you

    ReplyDelete