on 2009 Sep 10 9:04 AM
Hi,
I am really new in sapscript and I followed tutorials, manuals ecc in this morning I tried to write my first helloworld sapscript; really simple:
1) i made a form z_test with a text in main window where i wrote: Hi &user&
2) i wrote a z_report where i set variable user = sy-uname and then, open / write / close form ..
But when launching program, output is open, but I can see only "Hi" and no name following.
What am I missing ?
thanks
gabriele
Use UPPER CASE between &'s.
&USER&
You may check [this|http://www.erpgenie.com/sap-technical/sapscript-smartforms/sapscript-commands] also.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
No It has to define in z_report, but as global data, so don't define it in a routine (perform).
REPORT Z_REPORT.
DATA: USER TYPE SY-UNAME. " <-------- This is a global data
REPORT Z_REPORT.
FORM MY_FORM.
DATA: USER TYPE SY-UNAME. " <-------- This is a local data
ENDFORM.
Anyawy u can check your sapscript by trx SE71: Form->Check->Text
Max
update:
if I check text in form, it tells me that symbol SY-UNAME is not recognized (finally!!), so where do I have to declare it for form?
I think I am missing the element, ... how should I put it? just with backslash and E ?
.. I think also I am using an editor more advance then the one I see in tutorial .. for me it's like MS word instead a sort of old abap editor..
Edited by: Gabriele Montori on Sep 10, 2009 11:11 AM
Hi
U don't need to define SY-UNAME because it's a system symbol, so your form can automatically see it.
U see the editor based on MS, so it could be the variable to be printed are not correctly written in the window, u should move to old editor.
When u're in the editor: Goto->Cnange Editor
Now check how the variables are written: they have to have the format &variable&
If you use the new editor you don't write &variable&, but u should use the commands of toolbar in order to get the system o program variable .
Max
I think it's incredible .. I cannot understand the reason why it's not working .. I did exactly what you said and what I found on example on internet ... in 'new' editor, I used the toolbar to add symbol and in the old (on which I switched) I put & surrounding symbol name .. but nothing happens ... the only thing that seems does not work is this: in 'old-style' editor, there is a button for symbols .. I pressed it ad it asked me for a appending program or add global data ... I choose append and put the name of my report .. then clicking on global data I can see the ones I declared in report and it adds directly in text if I double click on them .. but still not showing ...
My drive program is here:
REPORT z_sapscript.
CLEAR usr01.
SELECT SINGLE * FROM usr01 WHERE bname = sy-uname.
zoption-tddest = usr01-spld. "Output device (printer)
zoption-tdimmed = 'X'. "Print immediately
zoption-tddelete = 'X'. "Delete after printing
zoption-tdprogram = 'ZPQRPRNT'. "Program Name
DATA TEST_NAME(20) TYPE c.
test_name = sy-uname.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
application = 'TX'
device = 'PRINTER'
dialog = ' '
form = 'Z_TEST_SAPSCRIPT'
language = sy-langu
OPTIONS = zoption
IMPORTING
language = sy-langu
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
LEAVE PROGRAM.
ENDIF.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
window = 'MAIN'
EXCEPTIONS
element = 1.
CALL FUNCTION 'CLOSE_FORM'
EXCEPTIONS
unopened = 1
OTHERS = 2.
Main windows has only &TEST_NAME&
Edited by: Gabriele Montori on Sep 10, 2009 11:42 AM
Hi
Something is strange in your code:
REPORT z_sapscript. "<--------- Z_SAPSCRIPT
zoption-tdprogram = 'ZPQRPRNT'. "<------???????
Can u try this updating?
REPORT z_sapscript.
DATA TEST_NAME(20) TYPE c.
CLEAR usr01.
SELECT SINGLE * FROM usr01 WHERE bname = sy-uname.
*zoption-tddest = usr01-spld. "Output device (printer)
*zoption-tdimmed = 'X'. "Print immediately
*zoption-tddelete = 'X'. "Delete after printing
*zoption-tdprogram = 'ZPQRPRNT'. "Program Name
test_name = sy-uname.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
application = 'TX'
device = 'PRINTER'
dialog = ' X'
form = 'Z_TEST_SAPSCRIPT'
* language = sy-langu
* OPTIONS = zoption
IMPORTING
language = sy-langu
EXCEPTIONS
OTHERS = 1.
IF sy-subrc 0.
LEAVE PROGRAM.
ENDIF.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
window = 'MAIN'
EXCEPTIONS
element = 1.
CALL FUNCTION 'CLOSE_FORM'
EXCEPTIONS
unopened = 1
OTHERS = 2.
Max
Hi
That doesn't possible, so don't worry
what U need to consider is zoption-tdprogram has to have the name of main program, so the program where the variable are defined.
This field isn't usually filled, because the main program is the driver program (i.e the program where the sapscript is called), it need to fill it only if the program where the variable are defined is not the driver program.
So i believe this (your) code:
REPORT z_sapscript.
DATA TEST_NAME(20) TYPE c.
CLEAR usr01.
SELECT SINGLE * FROM usr01 WHERE bname = sy-uname.
zoption-tddest = usr01-spld. "Output device (printer)
zoption-tdimmed = 'X'. "Print immediately
zoption-tddelete = 'X'. "Delete after printing
test_name = sy-uname.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
application = 'TX'
device = 'PRINTER'
dialog = 'space
form = 'Z_TEST_SAPSCRIPT'
language = sy-langu
OPTIONS = zoption
IMPORTING
language = sy-langu
EXCEPTIONS
OTHERS = 1.
IF sy-subrc 0.
LEAVE PROGRAM.
ENDIF.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
window = 'MAIN'
EXCEPTIONS
element = 1.
CALL FUNCTION 'CLOSE_FORM'
EXCEPTIONS
unopened = 1
OTHERS = 2.
.
It should work now
Max
Hi,
Try Hi &SY-UNAME& directly in script.
Or in the driver program use
data user type sy-uname.
user = sy-uname.
and then in script use in editor
Hi &USER&
See if the format is default paragraph '*' as above.
Case doesnot matter.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
thanks for hint: it does not work, so my error is not in transferring data from report to form (as I was thinking), but I'm missing something else. For adding text the procedure I followed is this:
1) righr click on layout window
2) click on 'edit text' in context menu
3) write 'Hi' in editor
4) click on '+' (insert command) button to add data
5) select 'Symbols' radio button
6) entered '&SY-UNAME&'
Am I doing some mistake?
regards
gabriele
Hi
I did this and it works:
Report:
REPORT ZPROVAMAX5.
DATA: USER LIKE SY-UNAME.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
FORM = 'Z_TEST'
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
CODEPAGE = 11
OTHERS = 12.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
USER = SY-UNAME.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'INTRO'
WINDOW = 'MAIN'.
CALL FUNCTION 'CLOSE_FORM'.
ENDIF.
Sapscript (MAIN window):
/E INTRO
* Hi &USER&
Max
User | Count |
---|---|
79 | |
11 | |
10 | |
8 | |
7 | |
6 | |
5 | |
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.