‎2006 Mar 18 2:24 AM
I created a FM to print a form using open_form, start_form, write_form, end_form and close_form. When I put this code in a report program...it works great. When I try to call the SAPscript from the FM all the variables are blank in the SAPScript....but populated in the FM. I do have the variables defined in the top include of the Function group. I have also even tried moving for example itab_matnr to mara-matnr ...thinking it was something about 'global' definition.... still no luck. Any help would be greatly appreciated.
Thanks!!
‎2006 Mar 18 5:17 AM
Hi jennifer,
1. The reason is
all the FMs for writing to sapscript (write_form,etc)
search for VARIABLES
in the TOP MOST PARENT PROGRAM.
2. Hence, look at this code
report abc.
*----
Data - will get pritned
data : var2 type matnr.
var2 = '1233456789'.
*----
Var1 in FM WILL NOT GET PRINTED
CALL FUNCTION 'ZAM_F06'
EXPORTING
var1 = 'pppppppppp'
.
3. Here var1 WILL NOT GET PRINTED
whereas,
VAR2 will get printed.
4. Hence, do not pass any value to the FM,
just use the global variables of the program,
and simply call the FM without passing
data for printing.
5. The write_form
will DETECT the MOST PARENT/TOP PROGRAM
(ie your z program)
and get variable values from there.
regards,
amit m.
‎2006 Mar 18 2:30 AM
hI JENNIFER
HAVE YOU EXPORTED ALL THE VALUES USED IN THE SAP SCRIPT TO THE FUNCTIONAL MODULE.
REGARDS
KISHORE
‎2006 Mar 18 2:58 AM
‎2006 Mar 18 3:11 AM
I am using a table ... I defined a structure and I am passing the values via the table to the FM. I am not exporting anything... Is that what I am missing? I am basically just writing this FM for several programs to call so that we do not have to have the big piece of code for the open, write, start, end, close...etc.
‎2006 Mar 18 3:13 AM
Hi there. Thanks for the fast reply Rich. I did try your suggestion.... but it didn't fix this issue. I was looking for that earlier though.. as I too thought that might be the issue. Thanks SO much.
‎2006 Mar 18 3:35 AM
‎2006 Mar 18 4:52 AM
Hi Jennifer,
SAP follows a similar approach for printing the Benefits enrollments forms.. Pl take a look at the function module HR_BEN_FORM_PRINT_SAPSCR.. may be you can get an idea of what else you need to do.. One thing I noticed is before calling the WRITE_FORM, there is a function call to 'READ_FORM_ELEMENTS' (inside the function HR_BEN_FORM_GENERATE).. may be you should do that too, instead of passing the text elements as parameters/tables.
Regards,
Suresh Datti
‎2006 Mar 18 5:17 AM
Hi jennifer,
1. The reason is
all the FMs for writing to sapscript (write_form,etc)
search for VARIABLES
in the TOP MOST PARENT PROGRAM.
2. Hence, look at this code
report abc.
*----
Data - will get pritned
data : var2 type matnr.
var2 = '1233456789'.
*----
Var1 in FM WILL NOT GET PRINTED
CALL FUNCTION 'ZAM_F06'
EXPORTING
var1 = 'pppppppppp'
.
3. Here var1 WILL NOT GET PRINTED
whereas,
VAR2 will get printed.
4. Hence, do not pass any value to the FM,
just use the global variables of the program,
and simply call the FM without passing
data for printing.
5. The write_form
will DETECT the MOST PARENT/TOP PROGRAM
(ie your z program)
and get variable values from there.
regards,
amit m.
‎2006 Mar 19 7:23 PM
Amit...thank you for your response... The problem is, I am writing this FM so that the calling programs do not have to do anything but pass the table with the values to print. I am writing this FM to print a label. The label gets printed out of many custom txns. I was hoping that all we would have to do was to call this FM to print and not have to worry about what all the developers define their fields...they just have to put them in the table and call the FM... I am thinking this is just not possible....do you agree?
‎2006 Mar 19 8:32 PM
Hi Jennifer
I tried to run a sapscript by fm and report and I got your problem: it did work only using the report.
So I saw the code of fm ME_PRINT_PO and noted that before calling the FM OPEN_FORM the report name is setted in the structure ITCPO for the option.
So I used this code:
FUNCTION Z_MAX_PRINT.
*"----
""Interfaccia locale:
*" IMPORTING
*" REFERENCE(MATNR) TYPE MATNR
*"----
ITCPO-TDPROGRAM = SY-REPID.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
FORM = 'ZMAX'
OPTIONS = ITCPO
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.
EXIT.
ENDIF.
MARA-MATNR = MATNR.
TEXT = 'TEST TEST'.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'PROVA'
WINDOW = 'MAIN'.
CALL FUNCTION 'CLOSE_FORM'.
ENDFUNCTION.
The variables MARA and TEXT are defined in TOP include.
Now it works.
So I believe the system can't know the name of the main program where the variables are defined, so it needs to indicate explicitly the name of program.
Max
‎2006 Mar 19 9:04 PM
Max... You are the BEST!! You are totally My HERO!!! Thank you SO SO much!! Yeah!!
‎2006 Mar 19 9:18 PM
Uhm!!!!
You're too kind to me...I've just only used all suggestions of guys.
Anyway I'm happy I was helpfull for your.
Max
‎2009 Apr 27 7:49 AM
‎2010 Aug 05 8:15 AM
Max, thank you!
Miguel
Edited by: Javier Rodrigo on Aug 5, 2010 9:15 AM
‎2011 Jun 10 8:13 AM