Thursday, February 10, 2011

SAP ABAP Scripts Question and Answers Part 3

61. Calling a form from SapScript (*****)

/:DEFINE &CUST& = '00000021'.
/: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.

Note that if you use more than one parameter you must use Using or Changing before every parameter !

/: PERFORM

IN PROGRAM
/: USING &INVAR1&
/: USING &INVAR2&
......
/: CHANGING &OUTVAR1&
/: CHANGING &OUTVAR2&
......
/: ENDPERFORM

62. Structure of a print program

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.

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

Must be ended with function module CLOSE 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 form
call funtion 'END_FORM'.....

Closes form printing
call function 'CLOSE_FORM'.
...

Examples of function calls

OPEN FORM

CALL FUNCTION 'OPEN_FORM'
EXPORTING
* APPLICATION = 'TX'
* ARCHIVE_INDEX =
* ARCHIVE_PARAMS =
DEVICE = 'PRINTER'
DIALOG = 'X'
* FORM = ' '
* LANGUAGE = SY-LANGU
OPTIONS = 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
OTHERS = 10
.


START_FORM

CALL FUNCTION 'START_FORM'
EXPORTING
* ARCHIVE_INDEX =
FORM = 'MY_FORM'

* LANGUAGE = ' '
* STARTPAGE = ' '
* PROGRAM = ' '
MAIL_APPL_OBJECT =
IMPORTING
* LANGUAGE =
EXCEPTIONS
FORM = 1
FORMAT = 2
UNENDED = 3
UNOPENED = 4
UNUSED = 5
OTHERS = 6

WRITE_FORM

See 'WRITE_FORM'

END_FORM

CALL FUNCTION 'END_FORM'

IMPORTING
* RESULT =
EXCEPTIONS
* UNOPENED = 1
BAD_PAGEFORMAT_FOR_PRINT = 2
OTHERS = 3

CLOSE_FORM

Structure for Print options (return values) - Pages selected for printing, Number of copies etc.
DATA BEGIN OF RESULT.
INCLUDE STRUCTURE ITCPP.
DATA END OF RESULT.

CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT = RESULT

* RDI_RESULT =
TABLES
* OTFDATA =
EXCEPTIONS
* UNOPENED = 1
BAD_PAGEFORMAT_FOR_PRINT = 2
* SEND_ERROR = 3
* OTHERS = 4.

63. CONTROL_FORM - Calling Commands Using a program

The function module CONTROL_FORM can be used to create SapScript control statements from within an ABAP program.

Example:

call function 'CONTROL_FORM'
EXPORTING
COMMAND = 'PROTECT'.

call function 'WRITE_FORM'.....................

call function 'CONTROL_FORM'
EXPORTING
COMMAND = 'ENDPROTECT'.

Styles

Styles are used to predefine paragraph and character formats for forms. SAP provides several standard styles e.g. for Address includes, on-line documentation and so on. You can define your own styles.

To find styles, create styles and maintaine styles, use transaction SE72.

You assign style to a text by using menu Format -> Style

You can make temporary style changes using the control command /: STYLE

Using graphics in SapScript

Use transaction SE78 to inmport graphics to SAP.

In the form painter, you can either include directly to the form using menu Edit->Graphic->Create or using the INCLUDE statement in a window.

To use an INCLUDE stanment, goto into the woindow script editor and use menu Include->Graphic. The include can look like this for a bitmap:

/: BITMAP MYLOGO OBJECT GRAPHICS ID BMAP TYPE BMON

Modifications
Considerations in connection with modifications

The standard SAP print program should only be changed when it is absolutely necessary. If additional data is needed, these can in many cases be retrieved using a a PERFORM statement in the form instead of changing the print program..

There can be the following reasons to change the print program:

Structureal changes
New text eloements are needed
Print program to be used to print additional forms

Determine/change which forms and printprograms that are used for printing

The forms and print programs for a given output type and application can be found in table TNAPR Processing programs for output

Use view V_TNAPR in (Transaction SE30) to change entries

.

No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive

goodsites