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

Print Programs

Former Member
0 Likes
2,754

Hi everyone!!

I've just created a PR Form using sapscript and i wish to test it. From what i can gather, i need to create a print program first before i can proceed.

I've been looking at several standard sapscript forms like MEDRUCK, and i would like to know if any of you knew the print program for it. Perhaps it could give me an idea on what to do next.

Are print programs like your regular ABAP programs?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,722

Hi again,

1. EBAN consists of many line item records

for one purchase requisiion number BANFN

2. So write your code as below :

3. Moreover, in sapscript layout,

define a new element with name 'LINEITEM'

4. Inside this element write your fields as :

&ITAB-EBAN& &ITAB-TXZ01&

(write the full field name along with table name)

5.

REPORT abc.

PARAMETERS : i_banfn LIKE eban-banfn.

DATA : BEGIN OF itab OCCURS 0,

eban LIKE eban-badat,

txz01 LIKE eban-txz01,

menge LIKE eban-menge,

meins LIKE eban-meins,

werks LIKE eban-werks,

knttp LIKE eban-knttp,

afnam LIKE eban-afnam,

END OF itab.

SELECT badat txz01 menge meins werks knttp afnam

INTO CORRESPONDING FIELDS OF TABLE itab

FROM eban

WHERE banfn = i_banfn.

LOOP AT itab.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = 'LINEITEM'

  • FUNCTION = 'SET'

  • TYPE = 'BODY'

window = 'MAIN'

.

ENDLOOP.

regards,

amit m.

36 REPLIES 36
Read only

Former Member
0 Likes
2,722

I've managed to find out the print program for MEDRUCK...was browsing through the earlier forum thread when i can accross this way:

From SAPscript form -> Go to Check -> Text -> Press "Enter"

Still, from SE38, when i looked at the print program SAPLMEDRUCK...all i see are INCLUDE statements...it's not really helping me much in giving me an idea on what to write in the print program for my form...

Any hints on how i should continue?

Read only

Former Member
0 Likes
2,722

Hi Bernard,

1. Yes

Print programs are just like normal abap programs

2. For using sapscript, u need 2 things.

a) Sapscript layout built from SE71

b) program (called as driver program)

built from se38.

3. 3 - 4 FMs are VERY IMPORTANT.

They control the output/print of sapsciript.

They are for sapscript purpose only.

4.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

FORM = 'ZAM_TEMPSS1'

EXCEPTIONS

CANCELED = 1

.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'DETAIL'

  • FUNCTION = 'SET'

  • TYPE = 'BODY'

WINDOW = 'MAIN'

EXCEPTIONS

ELEMENT = 1

.

CALL FUNCTION 'CLOSE_FORM'

EXCEPTIONS

UNOPENED = 1

.

5. please see the documentation F1 help

on these FM and u will understand

how to use them.

USING THEM IS VERY SIMPLE.

Regards,

Amit M.

Read only

Former Member
0 Likes
2,722

Hi again,

1. Sample program.

2. ZAM_TEMPSS1 = sapscript layout (se71)

u can replace your name also in the code

3. MYELEMENT = some element name in layout

u can write the name of your own element in the code

4.

REPORT abc.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

form = 'ZAM_TEMPSS1'

EXCEPTIONS

canceled = 1.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'MYELEMENT'

WINDOW = 'MAIN'

EXCEPTIONS

ELEMENT = 1

.

CALL FUNCTION 'CLOSE_FORM'

EXCEPTIONS

unopened = 1.

regards,

amit m.

Read only

0 Likes
2,722

Thanks for the quick reply...could you please elaborate more on the ELEMENTs part?

Read only

0 Likes
2,722

Hi again,

1. Elements are nothing but INDEPENDENT BLOCKS

which may be printed thru program

using WRITE_FORM fm.

2. In se71 sapscript layout,

we write :

/E MYELEMENT

/ hi, this is line

/ hi, this is another line

/E ABC

/ hi, this is line

/ hi, this is another line

3. /E

This defines the begingging of new ELEMENt (ie. Block)

it contains 2 lines (as u can see above)

The element name is MYELEMENT.

4. In above there are 2 elements namely

MYELEMENT

ABC

5. Now these element (block) can be printed / written

in the layout using FM

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'MYELEMENT'

WINDOW = 'MAIN'

EXCEPTIONS

ELEMENT = 1

.

6. U can use this FM in a loop to

print the element (with 2 lines)

more than once

(This technique is used to print say Purchase

Order Line items)

Also see the help of sapscript layout.

I hope it helps.

regards,

amit m.

Read only

0 Likes
2,722

For the print program, i was asked by the consultant to provide a SELECTION-SCREEN so that the user can key in the PR Number (EBAN-BANFN). In doing so, the appropriate PR No. and its details will be retrieved and displayed as part of the form. The following fields are to be retrieved and displayed:


EBAN-BADAT
EBAN-TXZ01
EBAN-MENGE
EBAN-MEINS
EBAN-WERKS
EBAN-KNTTP
EBAN-AFNAM

I have done the SELECTION-SCREEN as follows:


*&---------------------------------------------------------------------*
*&    SELECTION-SCREEN                                                 *
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE TEXT-001.
PARAMETERS: I_BANFN LIKE EBAN-BANFN,       "PR No.
SELECTION-SCREEN END OF BLOCK 1.

So how do i make sure that the earlier mentioned fields are retrieved based on the PR No. that the user has keyed in and would later appear in the form? Would a SELECT statement be required to accomplish this?

Read only

0 Likes
2,722

Hi,

1. First populate the 7 fields

using SELECT statment.

(This is a must)

2. In your sapscript layout,

to print the value of the fields,

write like this :

&EBAN-BADAT& &EBAN-TXZ01&

(& means value of this variable)

(In fact any variable in the driver program

can be printed in sapscript like this :

&VariableName&

3. Then using the 3 FMS,

print your sapscript.

regards,

amit m.

Read only

0 Likes
2,722

Would the followig SELECT statement suffice?


SELECT BADAT TXZ01 MENGE MEINS WERKS KNTTP AFNAM
  FROM EBAN
  WHERE BANFN = I_BANFN.

I would also like to know how am i going to test to see whether i am getting the form layout as i wanted it to be?

Read only

Former Member
0 Likes
2,723

Hi again,

1. EBAN consists of many line item records

for one purchase requisiion number BANFN

2. So write your code as below :

3. Moreover, in sapscript layout,

define a new element with name 'LINEITEM'

4. Inside this element write your fields as :

&ITAB-EBAN& &ITAB-TXZ01&

(write the full field name along with table name)

5.

REPORT abc.

PARAMETERS : i_banfn LIKE eban-banfn.

DATA : BEGIN OF itab OCCURS 0,

eban LIKE eban-badat,

txz01 LIKE eban-txz01,

menge LIKE eban-menge,

meins LIKE eban-meins,

werks LIKE eban-werks,

knttp LIKE eban-knttp,

afnam LIKE eban-afnam,

END OF itab.

SELECT badat txz01 menge meins werks knttp afnam

INTO CORRESPONDING FIELDS OF TABLE itab

FROM eban

WHERE banfn = i_banfn.

LOOP AT itab.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = 'LINEITEM'

  • FUNCTION = 'SET'

  • TYPE = 'BODY'

window = 'MAIN'

.

ENDLOOP.

regards,

amit m.

Read only

0 Likes
2,722

So does it mean i would have to put the element (/E) <b>LINEITEM</b> in the sapscript layout on the line above the variable? For example:


/E ITEM_LINE
*  Purchase Request No. (SAP) : <U>&EBAN-BANFN&</>  Date         : <U>&EBAN-BADAT&</>
*  Item Description           : <U>&EBAN-TXZ01&</>
*  Quantity to Order          : <U>&EBAN-MENGE(.2)&</><U> &EBAN-MEINS&</>

Should it loop something like this?

Read only

0 Likes
2,722

I meant "look"...not "loop"...ah, since i started doing ABAP i tend to write ABAP statements and in capital letters when writing a normal letter or message, if not, it won't look right

Read only

0 Likes
2,722

Hi again,

1. Exactly.

The layout u mentioned is perfectly corrrect.

*----


PS :

What is your Internal Table name :

If EBAN then it is correct.

If ITAB then

&ITAB-BANFN& . . .ETC.

*----


2. Should it loop something like this?

Do not Loop (REPEAT) the same in Layout.

3. It has to be written only ONCE.

4. Instead, we have to loop in the driver program.

LOOP AT ITAB.

CALL FUNCTION WRITE_FORM

ENDLOOP.

5. What will happen,

the program will loop at itab , say 5 times.

6. Hence, in the first loop, when call function is there,

it will write the ELEMENT,

WITH THE CURRENT VALUES OF ITAB.

7. In second passs,

it will AGAIN write the ELEMENT,

WITH THE CURRENT VALUES OF ITAB. (ie. 2nd record)

8. . .

. .

and so on.

9. Hence, in your layout, the element

ITEM_LINE WILL BE WRITTEN 5 TIMES,

WITH 5 DIFFEREENT VALUES.

regards,

amit m.

Message was edited by: Amit Mittal

Read only

0 Likes
2,722

Hi Bernard,

It looks good.

you did it correctly.

Regards

vijay

Read only

0 Likes
2,722

So what comes next? How do i test whether everything in my layout is in order?

Read only

0 Likes
2,722

hi,

1. U should write your driver program (se38 program)

using the 3 FMs mentioned in the previous post.

2. Run the program.

3. The layout will appear on screen in print-preview mode.

regards,

amit m.

Read only

0 Likes
2,722

Hi Bernard,

Implement your driver Program in SE38, using

standard functions open_form, write_form, close_form.

check the output, every thing fine or not.

Regards

vijay

Read only

0 Likes
2,722

Erm...for some reason, only 2 of my 3 windows are displayed: 'LOGO' and 'HEADER'

But my 'MAIN' window is not being displayed...perhaps you guys could double check my print program...did i leave out anything?


*&---------------------------------------------------------------------*
*& Report  ZLPUPR006                                                   *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZLPUPR006 NO STANDARD PAGE HEADING.

TABLES: EBAN.

*&---------------------------------------------------------------------*
*&    DATA DECLARATION                                                 *
*&---------------------------------------------------------------------*
DATA : BEGIN OF ITAB OCCURS 0,
       BANFN LIKE EBAN-BANFN,      "Purchase requisition number
       BADAT LIKE EBAN-BADAT,      "Requisition (request) date
       TXZ01 LIKE EBAN-TXZ01,      "Short text
       MENGE LIKE EBAN-MENGE,      "Purchase requisition quantity
       MEINS LIKE EBAN-MEINS,      "Purchase requisition unit of measure
       WERKS LIKE EBAN-WERKS,      "Plant
       KNTTP LIKE EBAN-KNTTP,      "Account assignment category
       AFNAM LIKE EBAN-AFNAM,      "Name of requisitioner/requester
       END OF ITAB.

*&---------------------------------------------------------------------*
*&    SELECTION-SCREEN                                                 *
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE TEXT-001.
PARAMETERS: I_BANFN LIKE EBAN-BANFN.       "PR No.
SELECTION-SCREEN END OF BLOCK 1.

SELECT BANFN BADAT TXZ01 MENGE MEINS WERKS KNTTP AFNAM
  INTO CORRESPONDING FIELDS OF TABLE ITAB
  FROM EBAN
  WHERE BANFN = I_BANFN.

LOOP AT ITAB.
  CALL FUNCTION 'OPEN_FORM'
    EXPORTING
      FORM                        = 'ZLPUPR005'
    EXCEPTIONS
      CANCELED                    = 1.

  CALL FUNCTION 'WRITE_FORM'
    EXPORTING
      ELEMENT                     = 'LINE_ITEM'
      WINDOW                      = 'MAIN'
    EXCEPTIONS
      ELEMENT                     = 1.

  CALL FUNCTION 'CLOSE_FORM'
      UNOPENED                    = 1.

ENDLOOP.

Read only

0 Likes
2,722

<b>open_form.

loop ai itab.

write_form.

endloop.

close_form.</b>

take out the open and close form inside the loop.

vijay

Read only

0 Likes
2,722

it should be like this...

  CALL FUNCTION 'OPEN_FORM'
    EXPORTING
      form     = 'ZLPUPR005'
    EXCEPTIONS
      canceled = 1.

LOOP AT itab.


  CALL FUNCTION 'WRITE_FORM'
    EXPORTING
      element = 'LINE_ITEM'
      window  = 'MAIN'
    EXCEPTIONS
      element = 1.

ENDLOOP.

  CALL FUNCTION 'CLOSE_FORM'
    unopened = 1.

Read only

0 Likes
2,722

Hi again,

1. 'OPEN_FORM'

'CLOSE_FORM'

These FM should be used only once.

(not in a loop)

2. WRITE_FORM

write this in aloop.

Loop at Itab.

write_form

endloop.

regards,

amit m.

Read only

0 Likes
2,722

Hmmm...its still not appearing...i've made sure that i activated the sapscript before i tried running the program...i've already removed OPEN_FORM and CLOSE_FORM FM from the loop like you mentioned...could it be the sapscript layout itself? Maybe i misunderstood what you explained on the ELEMENT part? Here's the sapscript i did:


/E ITEM_LINE
*  Purchase Request No. (SAP) : <U>&ITAB-BANFN&</>  Date         : <U>
=  &ITAB-BADAT&</>
*
*  Purchase Request Header    : _________________________________________
*
*  Item Description           : <U>&ITAB-TXZ01&</>
*
*  Unit Price                 : __________
*
*  Quantity to Order          : <U>&ITAB-MENGE(.2)&</><U> &ITAB-MEINS&</>
*
*  Total Amount               : __________     <B>RM Equivalent</> :
   __________
*
*  Reasons for this request (if any) : __________________________________
*
*                                      __________________________________
*
*  &ULINE(100%)&
*
*  Plant/Company               :
/: IF &ITAB-WERKS& = '6001'.
=  Plant 1
/: ELESIF &ITAB-WERKS& = '6002'.
=  Plant 2
/: ENDIF.
*
*  Budgeted/Non-Budgeted       :
/: IF &ITAB-KNTTP& = 'A'.
=  Budgeted CAPEX
/: ELSEIF &ITAB-KNTTP& = 'Z'.
=  Non-Budgeted CAPEX
/: ELSEIF &ITAB-KNTTP& = 'K'.
=  OPEX
/: ENDIF.
*
*
*  For information only
*
*  <B>Total amount seeking for</>    : ____________________
*  <B>approval</>
*  
*  &ULINE(100%)&
*  
*  <B>AUTHORISATION</>
*  
*  Requested By : ___________________  Verified By : ____________________
*                 Name: &ITAB-AFNAM&                 (Head of Department)
*  
*  
*  Approve By   : ___________________  Approve By  : ____________________
*  
*  
*  
*  Approve By   : ___________________
*  
*                               <B><S>Please refer to PR Authorisation
   Matrix</></>
*  
*  &ULINE(100%)&

Read only

0 Likes
2,722

Hi,

it seems ok to me, did you check the data is coming or not. check it in debug mode.

thanks

vijay

Read only

0 Likes
2,722

Hi,

<b>/E ITEM_LINE</b> change to

/E LINE_ITEM

Read only

0 Likes
2,722

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = <b>'LINE_ITEM'</b>

window = 'MAIN'

EXCEPTIONS

element = 1.

either do

/E ITEM_LINE change to

/E LINE_ITEM

Read only

0 Likes
2,722

Sorry for the late reply...in the middle Go Live...so kinda busy with other stuff, had no time to follow up on this...

Anyway, thanks for the tip...typo error...points rewarded for you...

Okay, its now appearing in the print preview...

I've got 1 last thing to ask right now...my statement to draw a line doesn't seem to work...in the print preview, the syntax is appearing rather than the line:


&ULINE(100%)&

Read only

0 Likes
2,722

Oh and another thing, in my sapscript layout, i have an IF...ELSE...ENDIF statement. By right, if ITAB-WERKS should be of a certain value, the appropriate plant should appear during the print preview...

It's not...have a look:


*  Plant/Company               :
/: IF &ITAB-WERKS& = '6001'.
/: Company 1                      <-company name #1 should appear
/: ELESIF &ITAB-WERKS& = '6002'.
/: Company 2		          <-company name #2 should appear
/: ENDIF.

Read only

0 Likes
2,722

hi all, just wanna ask your opinion on whether what i want to do is possible.

In my form, i have a line that is suppose to appear in the form like this:


Quantity to Order: __________

Note that the fields that are suppose to appear are ITAB-MENGE and ITAB-MEINS and the values that are displayed need to be underlined, so i did as follows:


<U>&ITAB-MENGE& &ITAB-MEINS&</>

from that statement, the following is the output i got:


Example current output:         6.000 pcs
                        -----------------        <-treat this as underline

The problem is that the values need to be output within 10 character spaces, underlined (even the line has to be the length of 10 characters) and right justified. I would like to know how to combine several formatting options together, so that i get the output that i want like this:


Wanted output:      6 pcs
               ----------

I know that the following formatting options are available, the question is how to join them?


for right justified    -> &ITAB-MENGE(R)&
for 2 decimals         -> &ITAB-MENGE(.2)&
for omit leading 0     -> &ITAB-MENGE(Z)&
for thousand seperator -> &ITAB-MENGE(T)&

Any hints you guys can provide?

Message was edited by: Bernard Loh

Read only

0 Likes
2,722

Put them all in the parenthesis.



&ITAB-MENGE(6.2RZT)&

REgards,

Rich Heilman

Read only

0 Likes
2,722

so simple like that?!?!

thanks Rich, you're real good in this

BTW, i managed to solved the &ULINE& thingy myself

But i'm still figuring out the IF...ENDIF part...could you help me on that?

Read only

0 Likes
2,722

Well, at first look it seems that your paragraph format is not assigned. You have /: instead of a paragraph format. This could be the reason.



*  Plant/Company               :
/: IF &ITAB-WERKS& = '6001'.
<b>Z1</b> Company 1                      <-company name #1 should appear
/: ELESIF &ITAB-WERKS& = '6002'.
<b>Z1</b> Company 2		          <-company name #2 should appear
/: ENDIF.



Regards,

Rich Heilman

Read only

0 Likes
2,722

Ok thanks...it working now...now i'm figuring out how to display a box like the following:


---------------------------------------------------------------------------------------
| Original Budget | Amount Utilized | Balance Before |     Current      |  Balance /  |
|                 |       YTD       |  this request  | Acquisition Cost | (Variation) |
---------------------------------------------------------------------------------------
|                 |                 |                |                  |             |
|                 |                 |                |                  |             |
---------------------------------------------------------------------------------------
|                 |                 |                |                  |             |
|                 |                 |                |                  |             |
---------------------------------------------------------------------------------------

I'll try reading the earlier threads on this

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,722

Has this thread been answered? If so, please make sure to award appropriate points and mark it as solved. Thanks.

Regards,

Rich Heilman

Read only

0 Likes
2,722

its almost done...i have 1 final question about creating boxes, then its done:


/: BOX YPOS '9.4'CM WIDTH '3.0'CM HEIGHT '0.7'CM FRAME 1 TW INTENSITY 10

I would like to know how to draw the box on a certain position to the right, lets say in the middle of the page. Based on what i've read, i only manage to understand how to draw it on the higher or lower position of the page...

Read only

0 Likes
2,722

Ok, i managed to figure it out...i had to use XPOS...

thread is closed...thanks to everyone who helped

Read only

0 Likes
2,722

Hi Bernard Loh

Is it possible give the completed working code in this thread and definetly will be helpfull for all including me. I am also looking for a solution to print PR.

Thanks in advance

Read only

Former Member
0 Likes
2,722

Hi All

Can any one give the completed code for the benefit of everyone. Presently I am looking at the ways to print

Please help