on 03-03-2010 1:46 PM
Hi experts,
I want to print a form from a function.
I tried it (Open_Form, Write_Form, Close_Form...) - everyhting works.
Now I insert a few variables (declared in the function itself) into the function and print them...nothing!
In a programm I have to insert the variables in the TOP-Include - how to proceed with a function?
How do I have to declare the variables so that I can print them in my form?
regards
Michael
Hi Micheal,
After calling the function module Open_form, please call the FM start_form .
Cheers,
RK
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If I remember well, you have to attach the form to the program: in SE71, there is a non-intuitive menu (something like "texts") inside the left-most menu in which you have to enter the program name... (I don't have any SAP system to make sure)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just declare the variables globally.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Where should I declare them?
I only have a function called "z_print_apm_form" - I don't know nothing about the program which calles my function.
I got a table with data (my function imports data type table).
Now I make a loop over this generic table, get extra data and want to print them...do I have to declare the variables in the program? I don't want to...any other suggestions?
A little bit more information:
I calle the function this way:
CALL FUNCTION 'ZAPM_PRINT_FORM'
EXPORTING
data = lt_test.
Data is declared as Importing parameter, type table.
Function looks like this:
TYPES: BEGIN OF t_output,
matnr TYPE matnr.
TYPES: END OF t_output.
DATA: gs_output TYPE t_output.
DATA: gref TYPE REF TO data.
FIELD-SYMBOLS: <line> TYPE ANY,
<field> TYPE ANY.
CREATE DATA gref LIKE LINE OF data.
ASSIGN gref->* TO <line>.
LOOP AT data INTO <line>.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <line> TO <field>.
gs_output-matnr = <field>.
ENDLOOP.
[...]
CALL FUNCTION 'WRITE_FORM'
EXPORTING
window = 'MAIN'
element = 'POSITION'
EXCEPTIONS
OTHERS = 10.
[...]
In the Position element in windows MAIN there I want to print the variable gs_output-matnr
But it seems that this variable is empty - so I think I have to declare this variable global. But where I have to do this?
When I declare it in the program, I can't work with it in the function...
Hi,
Have you tried with the variable definition declared in the TOP include of the function group?
The option that I think Sandra is refering to would also be useful. If you're in the text editor of a window (old style editor, not the Word version) you have a menu path Insert -> Symbols -> Program Symbols. In this pop-up if you choose 'Append Print Program' you can specify the name of the print program (it will be the function group program SAPL....). Once this is assigned you can navigate through the variable that are recognised my the SAPscript and insert them directly into the editor.
Regards,
Nick
Hi,
I tried now the following:
1. Make a TOP-Inlude to the function - no output of the variable
2. Include the TOP-include of the function to the programm - interesting, but nothing.
3. Add program symbols in the Formular - I can choose a programm but then no variants appears to select
Maybe I can't print a form from a function?
> 3. Add program symbols in the Formular - I can choose a programm but then no variants appears to select
> Maybe I can't print a form from a function?
yes you can print from a function module. Which program is proposed in the list, does it start with SAPL followed by function group name? If your function group doesn't appear, you have to click "Create" to add SAPL.... When you select your program SAPL... and no variable appears, it means that you didn't declare the variables as global (the DATA statement must be outside FORM...ENDFORM and FUNCTION...ENDFUNCTION blocks)
Hi Michael,
I've done some prototyping and I'm reaching the same conclusion, I don't think you can call a SAPscript from a function module.
I've created a simple SAPscript and code to call it from a function module and have found, as you have that while the form is constructed the variables are not populated. I took the same calling code and put it in a report and it worked fine.
What I did get to work, however, was to call this report from the function module using SUBMIT and pass the variables to the report selection screen.
Regards,
Nick
Nick and Michael,
based on Nick idea, I did my prototype and could reproduce the issue.
In fact, SAPscript determines the calling program by using SY-CPROG which is the frame program, so it is the initial report called by SUBMIT or CALL TRANSACTION...
To use the function module, I found a workaround (I guess sapscript experts know that but they are probably dead 😞
In ITCPO structure (options parameter), there is TDPROGRAM component.
In your function module, do that and it works like a charm:
options-tdprogram = sy-repid. "SAPL...
CALL FUNCTION 'OPEN_FORM'
EXPORTING
...
OPTIONS = options
...
Hi Sandra,
I know this parameters and already use them:
lvs_itcpo-tdcopies = 1.
lvs_itcpo-tddest = 'ORG1'.
lvs_itcpo-tdpreview = 'X'.
lvs_itcpo-tdnoprint = ''.
lvs_itcpo-tdimmed = 'X'.
lvs_itcpo-tddelete = 'X'.
lvs_itcpo-tdprogram = 'ZTEST_PRINT_APM'.
lvs_itcpo-tdcovtitle = 'TEST APM'.
lvs_itcpo-tdreceiver = 'OPERATOR'.
lvs_itcpo-tdarmod = 1.
I tried different programs, functions, sy-repid...but it won't work for me
Edit: Sorry, forget to use the SUBMIT command...OK.
Forget it, this seems to be too much just for printing a form.
I will made a perfrom statement in the program itself, nothing with a function.
Much easier and it works without "tricks"...
Edited by: Michael Fallenbüchel on Mar 4, 2010 11:56 AM
It worked very well for me, you must have something very special in your code. Could you test this:
DATA gt_t005t TYPE STANDARD TABLE OF t005t WITH HEADER LINE.
FUNCTION z_zysrot005.
DATA form TYPE thead-tdform VALUE 'ZZYSROT005'.
DATA options TYPE itcpo.
DATA result TYPE itcpp.
SELECT * FROM t005t INTO TABLE gt_t005t WHERE spras = sy-langu.
* Open print job
PERFORM get_random_otf_printer CHANGING options-tddest.
options-tdpreview = 'X'.
options-tdnoprint = 'X'.
options-tdprogram = sy-repid.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
dialog = space
OPTIONS = options
form = form
EXCEPTIONS
OTHERS = 1.
* Set column headings into TOP area of main window for subsequent pages
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'HEADER'
function = 'SET'
type = 'TOP'
EXCEPTIONS OTHERS = 1.
LOOP AT gt_t005t.
* Print item
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'LINE'
EXCEPTIONS OTHERS = 1.
ENDLOOP.
* close print job
CALL FUNCTION 'CLOSE_FORM'
exceptions OTHERS = 1.
ENDFUNCTION.
FORM get_random_otf_printer CHANGING printer TYPE tsp03-padest.
DATA lt_tsp0a TYPE TABLE OF tsp0a.
DATA lt_padest TYPE TABLE OF tsp03-padest.
SELECT * FROM tsp0a INTO TABLE lt_tsp0a
WHERE driver NOT IN ('LIST','STN2','STND').
IF sy-subrc = 0.
SELECT padest FROM tsp03
INTO TABLE lt_padest
FOR ALL ENTRIES IN lt_tsp0a
WHERE patype = lt_tsp0a-patype.
ENDIF.
READ TABLE lt_padest INDEX 1 INTO printer.
ENDFORM. "get_random_otf_printer
and SAPscript ZZYSROT005 is (upload it using RSTXSCRP), here first part:
SFORMZZYSROT005
HFORMZZYSROT005
OLANE
HEADFORM ZZYSROT005 SAP DEF ECountries ZZYSROT005 00038SROSSI 700 20100104162730SROSSI 700 2010030414094213200017 E0 220
LINE/:FORM CPI 10; LPI 6; TAB-STOP 1 CM; START-PAGE FIRSTPAG; PARAGRAPH NO; RDI;
LINE/:FORM RDIDEV;
LINE/:PARAGRAPH ET LINE-SPACE 1 LN; FONT ARIAL_B; FONT-SIZE 5; ULINE ON;
LINE/:PARAGRAPH NO LINE-SPACE 1 LN; FONT ARIAL; FONT-SIZE 12;
LINE/:PARAGRAPH TI ALIGN CENTER; LINE-SPACE 1 LN; FONT ARIAL_B; FONT-SIZE 18;
LINE/:PARAGRAPH ET TAB 1 8 CM LEFT;
LINE/:PARAGRAPH NO TAB 1 8 CM LEFT;
LINE/:WINDOW MAIN
LINE/:WINDOW NUMPAGE TYPE VAR;
LINE/:WINDOW TITLE TYPE VAR;
LINE/:PAGE FIRSTPAG NEXT NEXTPAGE;
LINE/:PAGE NEXTPAGE NEXT NEXTPAGE;
LINE/:PAGE FIRSTPAG MAIN 0 19 MM 27 MM 176 MM 239 MM;
LINE/:PAGE FIRSTPAG WINDOW NUMPAGE 141 MM 282 MM 61 MM 15 MM;
LINE/:PAGE FIRSTPAG WINDOW TITLE 59 MM 5 MM 89 MM 19 MM;
LINE/:PAGE NEXTPAGE MAIN 0 19 MM 27 MM 176 MM 239 MM;
LINE/:PAGE NEXTPAGE WINDOW NUMPAGE 141 MM 282 MM 61 MM 15 MM;
END
Second part of sapscript file:
HEADFORM ZZYSROT005 SAP TXT ECountries ZZYSROT005 00038SROSSI 700 20100104162730SROSSI 700 2010030414094213200018 E0 220
LINE/:FORM TEXT 'Countries';
LINE/:PARAGRAPH ET TEXT 'Underlined';
LINE/:PARAGRAPH NO TEXT 'normal';
LINE/:PARAGRAPH TI TEXT 'Arial 18 pts,Bold,Center';
LINE/:WINDOW MAIN TEXT 'Main window';
LINE/:WINDOW NUMPAGE TEXT '';
LINE/:WINDOW TITLE TEXT '';
LINE/:PAGE FIRSTPAG TEXT '';
LINE/:PAGE NEXTPAGE TEXT '';
LINE/WNUMPAGE
LINE* Page &PAGE& / &SAPSCRIPT-FORMPAGES&
LINE/WMAIN
LINE/EHEADER
LINEETCountry code,,Country name
LINE/ELINE
LINENO>_T005T-LAND1&,,>_T005T-LANDX&
LINE/WTITLE
LINETITitle Arial 18 points, bold, centered
END
ACTVSAP
E
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.