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

Calling a sapscript form from a function module issues

Former Member
0 Likes
3,311

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!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,623

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.

14 REPLIES 14
Read only

Former Member
0 Likes
2,623

hI JENNIFER

HAVE YOU EXPORTED ALL THE VALUES USED IN THE SAP SCRIPT TO THE FUNCTIONAL MODULE.

REGARDS

KISHORE

Read only

0 Likes
2,623

Jennifer, welcome to SDN! I don't know if this will help, but in the function module, click "Edit", "Interfaces", "Globalize Parameters".

Regards,

Rich Heilman

Read only

0 Likes
2,623

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.

Read only

0 Likes
2,623

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.

Read only

0 Likes
2,623

Have you tried delcaring the DATA statements inside the source of the function instead of the TOP include?

FUNCTION ZTEST.

Data:.....

Call function 'OPEN_FORM'
....

ENDFUNCTION.

Regards,

Rich Heilman

Read only

0 Likes
2,623

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

Read only

Former Member
0 Likes
2,624

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.

Read only

0 Likes
2,623

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?

Read only

0 Likes
2,623

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

Read only

0 Likes
2,623

Max... You are the BEST!! You are totally My HERO!!! Thank you SO SO much!! Yeah!!

Read only

0 Likes
2,623

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

Read only

0 Likes
2,623

Max my Man! you solved my problem as well! U tha best man!

Read only

0 Likes
2,623

Max, thank you!

Miguel

Edited by: Javier Rodrigo on Aug 5, 2010 9:15 AM

Read only

0 Likes
2,623

this is a new way. let me have a try.