cancel
Showing results for 
Search instead for 
Did you mean: 

Printing from a function

michael_fallenbchel
Active Participant
0 Kudos

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

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Micheal,

After calling the function module Open_form, please call the FM start_form .

Cheers,

RK

Sandra_Rossi
Active Contributor
0 Kudos

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)

kesavadas_thekkillath
Active Contributor
0 Kudos

Just declare the variables globally.

michael_fallenbchel
Active Participant
0 Kudos

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?

michael_fallenbchel
Active Participant
0 Kudos

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

Former Member
0 Kudos

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

michael_fallenbchel
Active Participant
0 Kudos

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?

Sandra_Rossi
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

michael_fallenbchel
Active Participant
0 Kudos

Hi at all,

I tested so much different things now...the easiest way would be to make a program with a "normal" TOP include...

Then it works without any problems!

Thanks everybody for your input...

Sandra_Rossi
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Sandra, I'm seriously impressed.

Regards,

Nick

michael_fallenbchel
Active Participant
0 Kudos

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

Sandra_Rossi
Active Contributor
0 Kudos

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

Sandra_Rossi
Active Contributor
0 Kudos

and SAPscript ZZYSROT005 is (upload it using RSTXSCRP), here first part:

SFORMZZYSROT005

HFORMZZYSROT005

&nbsp;OLANE

&nbsp;HEADFORM &nbsp; &nbsp; &nbsp;ZZYSROT005 &nbsp; &nbsp; &nbsp;SAP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DEF ECountries &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ZZYSROT005 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;00038SROSSI &nbsp; &nbsp; &nbsp;700 20100104162730SROSSI &nbsp; &nbsp; &nbsp;700 2010030414094213200017 E0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 220

&nbsp;LINE/:FORM CPI 10; LPI 6; TAB-STOP 1 CM; START-PAGE FIRSTPAG; PARAGRAPH NO; RDI;

&nbsp;LINE/:FORM RDIDEV;

&nbsp;LINE/:PARAGRAPH ET LINE-SPACE 1 LN; FONT ARIAL_B; FONT-SIZE 5; ULINE ON;

&nbsp;LINE/:PARAGRAPH NO LINE-SPACE 1 LN; FONT ARIAL; FONT-SIZE 12;

&nbsp;LINE/:PARAGRAPH TI ALIGN CENTER; LINE-SPACE 1 LN; FONT ARIAL_B; FONT-SIZE 18;

&nbsp;LINE/:PARAGRAPH ET TAB 1 8 CM LEFT;

&nbsp;LINE/:PARAGRAPH NO TAB 1 8 CM LEFT;

&nbsp;LINE/:WINDOW MAIN

&nbsp;LINE/:WINDOW NUMPAGE TYPE VAR;

&nbsp;LINE/:WINDOW TITLE TYPE VAR;

&nbsp;LINE/:PAGE FIRSTPAG NEXT NEXTPAGE;

&nbsp;LINE/:PAGE NEXTPAGE NEXT NEXTPAGE;

&nbsp;LINE/:PAGE FIRSTPAG MAIN 0 19 MM 27 MM 176 MM 239 MM;

&nbsp;LINE/:PAGE FIRSTPAG WINDOW NUMPAGE 141 MM 282 MM 61 MM 15 MM;

&nbsp;LINE/:PAGE FIRSTPAG WINDOW TITLE 59 MM 5 MM 89 MM 19 MM;

&nbsp;LINE/:PAGE NEXTPAGE MAIN 0 19 MM 27 MM 176 MM 239 MM;

&nbsp;LINE/:PAGE NEXTPAGE WINDOW NUMPAGE 141 MM 282 MM 61 MM 15 MM;

&nbsp;END

Sandra_Rossi
Active Contributor
0 Kudos

Second part of sapscript file:

&nbsp;HEADFORM &nbsp; &nbsp; &nbsp;ZZYSROT005 &nbsp; &nbsp; &nbsp;SAP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TXT ECountries &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ZZYSROT005 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;00038SROSSI &nbsp; &nbsp; &nbsp;700 20100104162730SROSSI &nbsp; &nbsp; &nbsp;700 2010030414094213200018 E0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 220

&nbsp;LINE/:FORM TEXT 'Countries';

&nbsp;LINE/:PARAGRAPH ET TEXT 'Underlined';

&nbsp;LINE/:PARAGRAPH NO TEXT 'normal';

&nbsp;LINE/:PARAGRAPH TI TEXT 'Arial 18 pts,Bold,Center';

&nbsp;LINE/:WINDOW MAIN TEXT 'Main window';

&nbsp;LINE/:WINDOW NUMPAGE TEXT '';

&nbsp;LINE/:WINDOW TITLE TEXT '';

&nbsp;LINE/:PAGE FIRSTPAG TEXT '';

&nbsp;LINE/:PAGE NEXTPAGE TEXT '';

&nbsp;LINE/WNUMPAGE

&nbsp;LINE* Page &PAGE& / &SAPSCRIPT-FORMPAGES&

&nbsp;LINE/WMAIN

&nbsp;LINE/EHEADER

&nbsp;LINEETCountry code,,Country name

&nbsp;LINE/ELINE

&nbsp;LINENO&GT_T005T-LAND1&,,&GT_T005T-LANDX&

&nbsp;LINE/WTITLE

&nbsp;LINETITitle Arial 18 points, bold, centered

&nbsp;END

&nbsp;ACTVSAP

E