Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

help regarding SAP SCRIPT

Former Member
0 Likes
713

Hi!

can any one help me regarding SAP SCRIPT. i unable to write a print program for sap script . can any one can send me sample code using ITCSY structure.

Thanks in advance.

Thanks & Regads,

DurgaPrasad.k

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
667

Hi durgaprasad,

1. something like this.

2.

FORM REDUCE_LEADING_ZERO TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

DATA XBLNR LIKE VBRK-XBLNR.

  • Read IN_TAB and save in local variables.

READ TABLE IN_TAB WITH KEY 'XBLNR'.

XBLNR = IN_TAB-VALUE.

  • Delete leading zero

SHIFT XBLNR LEFT DELETING LEADING '0'.

  • Update OUT_TAB table

READ TABLE OUT_TAB WITH KEY 'REFER'.

IF SY-SUBRC EQ 0.

MOVE XBLNR TO OUT_TAB-VALUE.

MODIFY OUT_TAB INDEX SY-TABIX.

ENDIF.

ENDFORM.

regards,

amit m.

5 REPLIES 5
Read only

Former Member
0 Likes
668

Hi durgaprasad,

1. something like this.

2.

FORM REDUCE_LEADING_ZERO TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

DATA XBLNR LIKE VBRK-XBLNR.

  • Read IN_TAB and save in local variables.

READ TABLE IN_TAB WITH KEY 'XBLNR'.

XBLNR = IN_TAB-VALUE.

  • Delete leading zero

SHIFT XBLNR LEFT DELETING LEADING '0'.

  • Update OUT_TAB table

READ TABLE OUT_TAB WITH KEY 'REFER'.

IF SY-SUBRC EQ 0.

MOVE XBLNR TO OUT_TAB-VALUE.

MODIFY OUT_TAB INDEX SY-TABIX.

ENDIF.

ENDFORM.

regards,

amit m.

Read only

Former Member
0 Likes
667

Hi,

refer this to write print program:

<b>The Print Program</b>

Structure of a print program

OPEN_FORM function

CLOSE_FORM function

WRITE_FORM

START_FORM function

END_FORM function

CONTROL_FORM function

The print program is used to print forms. The program retieves the necesary data from datbase

tables, defines the order of in which text elements are printed, chooses a form for printing and

selects an output device and print options.

<b>Function modules in a printprogram:</b>

When you print a form you must used the staments OPEN_FORM and CLOSE_FORM. To combine

forms into a single spool request use START_FORM and END_FORM.

To print textelements in a form use WRITE_FORM. The order in which the textelements are printed,

is determined by the order of the WRITE_FORM statements. Note: for printing lines in the body, you

can also use the WRITE_FORM_LINES function module.

To transfer control command to a form use CONTROL_FORM.

<b>Structure of a print program</b>

  • Read data

Tables: xxx.

SELECT *

FROM xxx.

  • Open form printing - Must be called before working with any of the other form function modules.

  • Must be ended with function module CLOSE FORM

call function 'OPEN_FORM'.....

  • To begin several indentical forms containing different data within a single spool request, begin each

form using START_FORM, and end it using END_FORM

call funtion 'START_FORM'.....

  • Write text elements to a window of the form

call function 'WRITE_FORM'.....

  • Ends spool request started with START_FORM

call funtion 'END_FORM'.....

  • Closes form printing

call function 'CLOSE_FORM'...

OPEN_FORM function

Syntax:

CALL FUNCTION 'OPEN_FORM'

  • EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

  • DEVICE = 'PRINTER'

  • DIALOG = 'X'

  • FORM = ' '

  • LANGUAGE = SY-LANGU

  • OPTIONS =

  • MAIL_SENDER =

  • MAIL_RECIPIENT =

  • MAIL_APPL_OBJECT =

  • RAW_DATA_INTERFACE = '*'

  • IMPORTING

  • LANGUAGE =

  • NEW_ARCHIVE_PARAMS =

  • RESULT =

  • EXCEPTIONS

  • CANCELED = 1

  • DEVICE = 2

  • FORM = 3

  • OPTIONS = 4

  • UNCLOSED = 5

  • MAIL_OPTIONS = 6

  • ARCHIVE_ERROR = 7

  • INVALID_FAX_NUMBER = 8

  • MORE_PARAMS_NEEDED_IN_BATCH = 9

  • SPOOL_ERROR = 10

  • OTHERS = 11

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

<b>Some important parameters:</b>

FORM Name of the form

DEVICE PRINTER : Print output using spool

TELEFAX: Fax output

SCREEN: Output to screen

OPTIONS Used to control attrubutes for printing or faxing (Number of copies, immediate output....

The input for the parameter is structure ITCPO.

CLOSE_FORM function

CALL FUNCTION 'CLOSE_FORM'

  • IMPORTING

  • RESULT =

  • RDI_RESULT =

  • TABLES

  • OTFDATA =

  • EXCEPTIONS

  • UNOPENED = 1

  • BAD_PAGEFORMAT_FOR_PRINT = 2

  • SEND_ERROR = 3

  • SPOOL_ERROR = 4

  • OTHERS = 5

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Paramerters:

RESULT Returns status information and print/fax parameters after the form has been printed.

RESULT is of structure ITCPP.

WRITE_FORM function

CALL FUNCTION 'WRITE_FORM'

  • EXPORTING

  • ELEMENT = ' '

  • FUNCTION = 'SET'

  • TYPE = 'BODY'

  • WINDOW = 'MAIN'

  • IMPORTING

  • PENDING_LINES =

  • EXCEPTIONS

  • ELEMENT = 1

  • FUNCTION = 2

  • TYPE = 3

  • UNOPENED = 4

  • UNSTARTED = 5

  • WINDOW = 6

  • BAD_PAGEFORMAT_FOR_PRINT = 7

  • SPOOL_ERROR = 8

  • OTHERS = 9

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Some important parameters:

ELEMENT Specifies which textelement is printed

WINDOW Specifies which window is printed

TYPE Specifies the output area of the main window. This can be:

TOP - Used for headers

BODY

BOTTOM - Used for footers

FUNCTION Specifies whether text is to be appended, replaced or added

Example of how to use the WRITE_FORM function module together with a script.

Form layout of the MAIN window

/E INTRODUCTION

  • Dear Customer

...........................

/E ITEM_HEADER

IH Carrier, Departure

/E ITEM_LINE

IL &SBOOK-CARRID&, &SPFLI-DEPTIME&

/E CLOSING_REMARK

<b>The print program</b>

  • Writing INTRODUCTION

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'INTRODUCTION'

FUNCTION = 'SET'

TYPE = 'BODY'

WINDOW = 'MAIN'

EXCEPTIONS

OTHERS = 8

.

  • Writing ITEM_HEADER

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'ITEM_HEADER'

FUNCTION = 'SET'

TYPE = 'BODY'

WINDOW = 'MAIN'

EXCEPTIONS

OTHERS = 8

.

  • Set ITEM_HEADER into TOP area of main window for subsequent pages

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'ITEM_HEADER'

FUNCTION = 'SET'

TYPE = 'TOP'

WINDOW = 'MAIN'

EXCEPTIONS

OTHERS = 8

  • Write ITEM_LINE

LOOP AT .....

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'ITEM_LINE'

FUNCTION = 'SET'

TYPE = 'BODY'

WINDOW = 'MAIN'

EXCEPTIONS

OTHERS = 8.

ENDLOOP.

  • Delete ITEM_HEADER from TOP area of main window

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'ITEM_HEADER'

FUNCTION = 'DELETE'

TYPE = 'TOP'

WINDOW = 'MAIN'

EXCEPTIONS

OTHERS = 8

  • Print CLOSING_REMARK

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'CLOSING_REMARK'

FUNCTION = 'SET'

TYPE = 'BODY'

WINDOW = 'MAIN'

EXCEPTIONS

OTHERS = 8

START_FORM function

CALL FUNCTION 'START_FORM'

  • EXPORTING

  • ARCHIVE_INDEX =

  • FORM = ' '

  • LANGUAGE = ' '

  • STARTPAGE = ' '

  • PROGRAM = ' '

  • MAIL_APPL_OBJECT =

  • IMPORTING

  • LANGUAGE =

  • EXCEPTIONS

  • FORM = 1

  • FORMAT = 2

  • UNENDED = 3

  • UNOPENED = 4

  • UNUSED = 5

  • SPOOL_ERROR = 6

  • OTHERS = 7

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

END_FORM function

CALL FUNCTION 'END_FORM'

  • RESULT =

  • EXCEPTIONS

  • UNOPENED = 1

  • BAD_PAGEFORMAT_FOR_PRINT = 2

  • SPOOL_ERROR = 3

  • OTHERS = 4

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CONTROL_FORM function

The CONTROL_FORM function module alows you to create SapScript control statements from within

an APAB program.

Syntax:

CALL FUNCTION 'CONTROL_FORM'

EXPORTING

command =

  • EXCEPTIONS

  • UNOPENED = 1

  • UNSTARTED = 2

  • OTHERS = 3

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Example:

Protecting the text element ITEM_LINE

CALL FUNCTION 'CONTROL_FORM'

EXPORTING

COMMAND = 'PROTECT'.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

TEXELEMENT = 'ITEM_LINE'.

CALL FUNCTION 'CONTROL_FORM'

EXPORTING

COMMAND = 'ENDPROTECT'.

rgds,

latheesh

Message was edited by: Latheesh Kaduthara

Read only

Former Member
0 Likes
667

Hi DurgaPrasad,

You can use, basically 3 Function Modules like OPEN_FORM, WRITE_FORM and CLOSE_FORM for SAPScript, though u can also use other FMs like START_FORM & END_FORM.

You can also call subroutines of programs in SAPScript.

In SAPScript, subroutines are called as follows:

/: PERFORM <subroutine_name> IN PROGRAM <program_name>

/: USING <Variable_name1>

/: USING <Variable_name2>

.

.

.

/: CHANGING <Variable_name>

/:ENDPERFORM

In the definition part in the program, it is coded like this.

FORM <subroutine_name> TABLES <in_name> STRUCTURE ITCSY <out_name> STRUCTURE ITCSY.

ENDFORM.

Whatever variables you have used in the USING part will be stored in the table <b>in_name</b> and varibles defined in CHANGING part will be in table <b>out_name</b>.

EG: for adding values in internal table

In SAPScript,

/: PERFORM ADD_INCOME IN PROGRAM ZSHAIL_BASIC

/: USING &VAR&

/: USING &ITAB-MY_INCOME&

/: CHANGING &VAR&

/: ENDPERFORM

In the main program,

FORM ADD_INCOME TABLES IN_TAB STRUCTURE ITCSY OUT_TAB STRUCTURE ITCSY.

DATA: INPUT1(10) TYPE N,

INPUT2(10) TYPE N.

LOOP AT IN_TAB .

IF IN_TAB-NAME = 'VAR'.

INPUT1 = IN_TAB-VALUE.

ELSE.

INPUT2 = IN_TAB-VALUE.

INPUT1 = INPUT1 + INPUT2.

ENDIF.

ENDLOOP.

READ TABLE OUT_TAB INDEX 1.

OUT_TAB-VALUE = INPUT1.

MODIFY OUT_TAB INDEX 1.

ENDFORM.

You can also go through these docs...

http://www.esnips.com/doc/7dd71921-a71f-4163-a4e0-c7e6e867d737/sap-script.pdf

http://www.esnips.com/doc/b57e8989-ccf0-40d0-8992-8183be831030/sapscript-how-to-calculate-totals-and...

http://www.esnips.com/doc/1ff9f8e8-0a4c-42a7-8819-6e3ff9e7ab44/sapscripts.pdf

Hope your query will be solved.

Regards,

SP.

Message was edited by: Sylendra Prasad

Read only

Former Member
0 Likes
667

hii

check this

/:PERFORM GET_NAME IN PROGRAM Z_BC460_EX4_HF

/: USING &CUST&

/: CHANGING &NAME&

/:ENDPERFORM.

Dear &NAME&

The ABAP routine could be defined as follows:

IMPORTANT: The structure itcsy must be used for the parameters.

REPORT Z_HENRIKF_SCRIPT_FORM .

tables scustom.

form get_name tables in_tab structure itcsy

out_tab structure itcsy.

read table in_tab index 1.

select single * from scustom

where id = in_tab-value.

if sy-subrc = 0.

read table out_tab index 1.

move scustom-name to out_tab-value.

modify out_tab index sy-tabix.

else.

read table out_tab index 1.

move 'No name' to out_tab-value.

modify out_tab index sy-tabix.

endif.

    • You could also fill the ouput parameter table this way

  • READ TABLE out_par WITH KEY 'NAME1'.

  • out_par-value = l_name1.

  • MODIFY out_par INDEX sy-tabix.

endform.

Regards

Naresh

Read only

Former Member
0 Likes
667

HI

GOOD

Retrieving data without modifying the original called program

*

  • Retrieving data without modifying the original called program

*

  • Put this script code in your sapscripts

  • /: PERFORM GET_BARCODE IN PROGRAM ZSCRIPTPERFORM

  • /: USING &PAGE&

  • /: USING &NEXTPAGE&

  • /: CHANGING &BARCODE&

  • /: ENDPERFORM

  • / &BARCODE&

*

*

REPORT ZSCRIPTPERFORM.

FORM GET_BARCODE TABLES IN_PAR STRUCTURE 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.

*-- End of Program

THANKS

MRUTYUN