Purchase Order SAP Script

Developing Purchase order SAPScript with totals, subtotals, terms in SAP ABAP programming

+ -
Requirement: Develop a purchase order with Logo, Address and page no.

A Real Time Scenario on  Purchase Order SAP Script Form

Business Req : Create a PO form with the below layout.

Please  follow the below steps

Step 1 :  Create a Page by name PAGE1

Step 2 :  Create Required no of Window as per the layout given

Step 3:  Create  Page Windows and specify height/width

Step 4 :  Create Paragraph Formats

Step 5 :  Create a TABS for Paragraph Formats

Step 6 :  Create a Character Format

Step 7 :  Write the code for  Printing Headings, Line item information, Grand total in 

  Mainwindow

Step 8 :  Write the code for Printing Vendor address in Address window

Step 9 :  Write the code for Printing  Footer information in Footer window

Step 10 : Write the code for Printing  Logo in Logo window

Step 11 : Similarly, Write the code for Printing  PO Details/PageNo/Title

Step 12 : Print the standard text using SO10 Tcode

Step13 : Arrange all the windows as per the given Layout.

Step14 : Create a Driver Program

Step15 : EXECUTE THE driver program

Step16 : Create a Second Page Layout

Step17 : Increase the height of MAIN window

Step18 : Printing Terms&Conditions using STARTFORM AND END FORM

Step19 : Change the Driver Program for using STARTFORM AND END FORM

Detailed Steps:

1. Se71->Give formname ->ZV_PO ->create.

2. give Meaning->click on BASIC settings.

3. Select page format /landscape

Step 1 :  Create a Page by name PAGE1

4. Click on PAGES->EDIT->CRATE ELEMENT->give page as page1 and meaning as page1->>Give Next Page as Page1

5. click on WINDOWS(by default, main window will be added)

Step 2 :  Create Required no of Window as per the layout given

6.  click on EDIT->create element->give window name as TITLE and meaning as title.

Repeat the same step  and  add  the below  windows.

 

Step 3:  Create  Page Windows and specify height/width

7. Click on Page windows-> EDIT->CRATE ELEMENT->Double click on each window so that the window would be added to the page. Give the appropriate  height, width, left/right margin  as below for each window

Step 4 :  Create Paragraph Formats

Create the 4 paragraph Formats as below.

Step 5 :  Create a TABS for Paragraph Formats

Give Tabs for HEADER paragraph format  as below .

And the 4th tab as 55 chars right justified .

Give font family as COURIER AND size as 12  for all paragraph formats, except for TITLE paragraph. Give 16 for this TITLE paragraph.

Step 6 :  Create a Character Format

Create character format as below .

Step 7 :  Write the code for Headings, Line item information, Grand total in  Mainwindow

Goto->Pagewindows->Double click on main window and click on texteditor-

CLICK ON GOTO CHANGE EDITOR--->write the below code.

Here…

/:TOP…ENDTOP is used to print header information in the main window so that the it flows on to every page .

/EBODY----this is used to print body. All the line item values .

/E-Total----used to print total at the end of main window ..

This element is called after the loop..endloop..so that Grand total is printed immediately

After the main window .

Step 8 :  Write the code for Printing Vendor address in Address window

Goto->Pagewindows->Double click on ADDRESS  window and click on texteditor->write the below code.

Step 9 :  Write the code for Printing  Footer information in Footer window

Goto->Pagewindows->Double click on FOOTER  window and click on  texteditor->write the below code.

FT--&ULINE(60)&

FT--ALL RIGHTS RESERVED TO IBM INDIA PVT.LTD

Here FT is paragraph format  And

C1 is char format  with bold.

Step 10 : Write the code for Printing  Logo in Logo window

Goto->Pagewindows->Double click on LOGO  window and click on texteditor->write the below code or Click on  INSERT->GRAPHICS->Select Stored on Document

Server->Give Name 'IBM'(Image name Uploaded through SE78)->

Give object : GRAPHICS

ID : BMAP

Select  color Bitmap Image->Press Continue->the Below syntax will come

automatically

BITMAP 'IBM' OBJECT GRAPHICS ID BMAP TYPE BCOL

Step 11 : Similarly, Write the code for Printing  PO Details/PageNo/Title

Similarly,  for all windows write the below code in the text editor

Goto->Pagewindows->Double click on PO_NO  window and click on texteditor->write the below code

DF-- PO No  : &wa_ekko-ebeln&

DF-- PO Date : &wa_ekko-aedat&

Goto->Pagewindows->Double click on PAGE_NO  window and click on texteditor->write the below code

DF--Page.No : &PAGE&/&SAPSCRIPT-FORMPAGES(C)&

Goto->Pagewindows->Double click on TITLE  window and click on texteditor->write the below code

TL----Purchase Order

Step 12 : Print the standard text using SO10 Tcode

Goto->Pagewindows->Double click on TEXT window and click on texteditor->write the below text.

We can write the text directly  in the window. But in the real time we use a concept called standard Text.

So Lets use the standard Text now.

Goto SO10->give text name->click on Create->

CLICK ON GOTO->CHANGE EDITOR

Write the below text->click on save->go back and click on print preview.

Go back to script

Goto->Pagewindows->Double click on TEXT window and click on texteditor->write the below text.

/: INCLUDE ZV_PO_TEXT OBJECT TEXT ID ST

THIS IS STD TEXT THRU SO10 TXN.

Or

CLick on Insert->Text->Standard->a pop will appear->give text name as ZV_PO_TEXT->press enter->

The code will be displayed automatically.

Step13 : Arrange all the windows as per the given Layout

Finally, Lets  Re-arrange all the window positions again by going to Graphical Form Painer.

Click on SETTINGS->FORM PAINTER->Select checkbox  Graphical Form Painter

And press enter 

The form should look as below.

If not arrange all the windows as below by dragging and dropping.

Now goback to PC EDITOR .

Save and activate script

Specify default paragraph and first page

Save and activate script

Step14 : Create a Driver Program

And the driver prg is :

REPORT  ZV_PO_DRIVER.

TABLES : ADRC,LFA1,EKKO.

PARAMETERS : P_EBELN TYPE EKKO-EBELN .

*DATA DECLARATIONS

DATA : WA_EKKO TYPE EKKO .

DATA : WA_EKPO TYPE EKPO .

DATA : IT_EKPO TYPE TABLE OF EKPO .

DATA : WA_LFA1 TYPE LFA1 .

DATA : WA_ADRC TYPE ADRC .

DATA : V_TOT TYPE EKPO-NETWR .

*READ  PO HEADER DETAILS

SELECT SINGLE * FROM EKKO

  INTO  WA_EKKO

  WHERE EBELN = P_EBELN .

*READ  PO ITEM  DETAILS

SELECT  * FROM EKPO

  INTO TABLE IT_EKPO

  WHERE EBELN = P_EBELN .

READ TABLE IT_EKPO INTO WA_EKPO INDEX 1.

DO 100 TIMES .

  APPEND WA_EKPO TO IT_EKPO .

ENDDO.

*READ  VENDOR MASTER DATA TO FIND THE ADDRESS NUMBER

SELECT SINGLE * FROM LFA1 INTO WA_LFA1 WHERE LIFNR = WA_EKKO-LIFNR .

SELECT SINGLE * FROM ADRC INTO WA_ADRC WHERE ADDRNUMBER = WA_LFA1-ADRNR .

*OPEN THE FORM

CALL FUNCTION 'OPEN_FORM'

  EXPORTING

  FORM  = 'ZV_PO'

  LANGUAGE = SY-LANGU.

*PRINT EACH ITEM IN MAIN WINDOW

LOOP AT IT_EKPO INTO WA_EKPO .

*CALCLUATE GRAND TOTAL

  V_TOT = V_TOT + WA_EKPO-NETWR .

  WA_EKPO-MATNR = 'APACHE-160' .

  CALL FUNCTION 'WRITE_FORM'

  EXPORTING

  ELEMENT = 'BODY'

  WINDOW  = 'MAIN'.

*PRIINT THETOTAL AFETR ANIN WINDOW BODY PAGE

  AT LAST .

  CALL FUNCTION 'WRITE_FORM'

  EXPORTING

  ELEMENT = 'TOTAL'

  WINDOW  = 'MAIN'.

  ENDAT.

ENDLOOP .

CALL FUNCTION 'CLOSE_FORM'.

Step15 : EXECUTE THE driver program

EXECUTE THE driver program->Give PO number as 4151508223

and execute->Below is the output .

Step16 : Create a Second Page Layout

Now Create a second Page PAGE2 and copy the Main Window, Page No Window, Footer Window.

Click on PAGES->EDIT->CRATE ELEMENT->give page as page2 and meaning as page2->>Give Next Page as Page2

Double click on Page1->give next page as Page2.

Double click on Page2->give next page as Page2.

 

7. Click on Page windows-> Give Page as Page2->Click on EDIT->CRATE ELEMENT->Double click on Main Window, Page No Window, Footer Window  so that the windows would be added to the page2.

Step17 : Increase the height of MAIN window

Now Lets Re-arrange  the  MAIN window  position  i.e. Just Increase the height of MAIN window  as below  by going to Graphical Form Painer.

Click on SETTINGS->FORM PAINTER->Select checkbox  Graphical Form Painter

 

The form should look as below.

Save->activate the form and again test it from Driver Prg.

The Page1 Should look as below.

And the Page2 Should look as below.

USING STARTFORM AND END FORM

Step18 : Printing Terms&Conditions using STARTFORM AND END FORM

Crate another Sap Script by name ZV_PO_TERMS  with below attributes.

Page :  Page1

Windows :  Main Window, Create a new window by name TERMS.

Page Windows : Copy MAIN window and TERMS windows onto page1 .

Double click on the Main Window->Write the below text.

Double click on the TERMS Window->Write the below text.

Create a title paragraph format and write the below text with font size 22 points

Also create defuakt paragraph format with font size 16 points

Save , Activate the program.

Define irst page and default paragraph

Step19 : Change the Driver Program for using STARTFORM AND END FORM

Write the below code in the  above driver program i.e. just add the below code to the above code  CALL FUNCTION 'CLOSE_FORM'.

CALL FUNCTION 'END_FORM' .

*The start form is used to call a different form for printing TREMS&CONDITIONS.

*This  for is reusable as it is only for printing

* TREMS&CONDITIONS

CALL FUNCTION 'START_FORM'

EXPORTING

*  ARCHIVE_INDEX  = ARCHIVE_INDEX

  form  = 'ZV_PO_TERMS'

  language  = sy-langu

  .

  CALL FUNCTION 'WRITE_FORM'

  EXPORTING

  element = 'TERMS'

  window  = 'MAIN'.

CALL FUNCTION 'END_FORM' .

CALL FUNCTION 'CLOSE_FORM'.

The Terms  and conditions  will be printed on the Last Page .

*&---------------------------------------------------------------------*

*& Report  ZV_PO_DRIVER

*&

*&---------------------------------------------------------------------*

REPORT  ZV_PO_DRIVER.

TABLES : ADRC,LFA1,EKKO.

PARAMETERS : P_EBELN TYPE EKKO-EBELN .

*DATA DECLARATIONS

DATA : WA_EKKO TYPE EKKO .

DATA : WA_EKPO TYPE EKPO .

DATA : IT_EKPO TYPE TABLE OF EKPO .

DATA : WA_LFA1 TYPE LFA1 .

DATA : WA_ADRC TYPE ADRC .

DATA : V_TOT TYPE EKPO-NETWR .

*READ  PO HEADER DETAILS

SELECT SINGLE * FROM EKKO

  INTO  WA_EKKO

  WHERE EBELN = P_EBELN .

*READ  PO ITEM  DETAILS

SELECT  * FROM EKPO

  INTO TABLE IT_EKPO

  WHERE EBELN = P_EBELN .

READ TABLE IT_EKPO INTO WA_EKPO INDEX 1.

DO 100 TIMES .

  APPEND WA_EKPO TO IT_EKPO .

ENDDO.

*READ  VENDOR MASTER DATA TO FIND THE ADDRESS NUMBER

SELECT SINGLE * FROM LFA1 INTO WA_LFA1 WHERE LIFNR = WA_EKKO-LIFNR .

SELECT SINGLE * FROM ADRC INTO WA_ADRC WHERE ADDRNUMBER = WA_LFA1-ADRNR .

*OPEN THE FORM

CALL FUNCTION 'OPEN_FORM'

  EXPORTING

  FORM  = 'ZV_PO'

  LANGUAGE = SY-LANGU.

*PRINT EACH ITEM IN MAIN WINDOW

LOOP AT IT_EKPO INTO WA_EKPO .

*CALCLUATE GRAND TOTAL

  V_TOT = V_TOT + WA_EKPO-NETWR .

  WA_EKPO-MATNR = 'APACHE-160' .

  CALL FUNCTION 'WRITE_FORM'

  EXPORTING

  ELEMENT = 'BODY'

  WINDOW  = 'MAIN'.

*PRIINT THETOTAL AFETR ANIN WINDOW BODY PAGE

  AT LAST .

  CALL FUNCTION 'WRITE_FORM'

  EXPORTING

  ELEMENT = 'TOTAL'

  WINDOW  = 'MAIN'.

  ENDAT.

ENDLOOP .

CALL FUNCTION 'END_FORM' .

*The start form is used to call  another SAP SCRIPT  form for printing TERMS&CONDITIONS.

*This  form  can be  reusable by al  forms as it is only for printing TREMS&CONDITIONS

CALL FUNCTION 'START_FORM'

EXPORTING

*  ARCHIVE_INDEX  = ARCHIVE_INDEX

  FORM  = 'ZV_PO_TERMS'

  LANGUAGE  = SY-LANGU

  .

CALL FUNCTION 'WRITE_FORM'

  EXPORTING

  ELEMENT = 'TERMS'

  WINDOW  = 'MAIN'.

CALL FUNCTION 'END_FORM' .

CALL FUNCTION 'CLOSE_FORM'

  .

Please Sign in to ask a question

Was this lesson helpful to you? Yes No 17 People out of 23 think this lesson helpful


Lesson Navigation

←Previous Chapter
Next Lesson → Smartforms