Login Form
Main Menu
ERPGenie Websites
ERP Software Corner
Developing a new ITS IAC
- Details
- Category: WAS / ITS
- Published on Wednesday, 25 July 2007 21:56
- Written by Kevin Wilson
- Hits: 22021
1 Introduction
To program a new IAC you need to perform the following steps:
1. Develop a dialog transaction that performs the required task.
This is a special dialog transaction that does not contain any screen
controls. Ie. No GUI-STATUS, help. All flow must be controlled from the
screen itself.
2. Generate a service file linking to the above-mentioned transaction
3. Generate a language resource file for the service
4. Generate a HTML template per dialog screen. This template should be
modified to represent a friendlier interface. Standard HTML and JAVA
can be used so long as when you refer to SAP objects and syntax you
used the SAP HTML Business format. For details of the SAP HTML
Business syntax, refer to the help files in the SAP@Studio.
Our aim is to develop a 1-screen application that updates a purchase
order with a reference number (waybill number) as well as a custom table
call ZWAYBILL. It also calls 2 reports that list current waybill numbers and
generates a list of waybill numbers, in ZWAYBILL, to work with.
2 SAP Portion
2.1 Creating the program and transaction
Create a dialog program called ZWAYBILL_ENTRY
2.2 Create screen
Create screen 100 which will capture the waybill, PO combination.
2.2.1 Screen attributes
2.2.3 Element List
WAYBILL Text 6 24 15 15 1 0
WAYBILL I/O 6 41 12 12 1 CHAR 0
BSTNR Text 7 24 15 15 1 0
BSTNR I/O 7 41 10 10 1 CHAR 0
BUTTON_SAVE Push 9 22 4 4 1 0
BUTTON_LIST Push 9 29 4 4 1 0
BUTTON_QUIT Push 9 35 4 4 1 0
BUTTON_GENE Push 9 41 24 24 1 0
OKCODE OK 0 0 20 20 1 OK 0
2.2.4 Screen Flow
process before output.
module init_0100.
*
process after input.
chain.
field: waybill, bstnr.
module check_0100.
endchain.
module user_command_0100.
2.3 SAP Programs
The following are example programs of the dialog and report kind, used in the
example.
2.3.1 Dialog entry program
*&---------------------------------------------------------------------*
*& Report ZWAYBILL_ENTRY *
*&---------------------------------------------------------------------*
INCLUDE ZWAYBTOP . "
* INCLUDE ZWAYBO01 . *
* INCLUDE ZWAYBI01 . *
* INCLUDE ZWAYBF01 . *
*&---------------------------------------------------------------------*
*& Module INIT_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE INIT_0100 OUTPUT.
CLEAR: WAYBILL, BSTNR.
ENDMODULE. " INIT_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module CHECK_0100 INPUT
*&---------------------------------------------------------------------*
MODULE CHECK_0100 INPUT.
CHECK OKCODE <> 'QUIT'.
CHECK OKCODE <> 'LIST'.
CHECK OKCODE <> 'GENE'.
IF WAYBILL = ' '.
MESSAGE E999(B1) WITH 'Waybill is a required field, please enter!'.
ENDIF.
IF BSTNR = ' '.
MESSAGE E999(B1) WITH 'PO # is a required field, please enter!'.
ENDIF.
PERFORM ADD_LEADING_ZEROS CHANGING WAYBILL.
PERFORM ADD_LEADING_ZEROS10 CHANGING BSTNR.
SELECT SINGLE * FROM ZWAYBILL WHERE
WAYBILL = WAYBILL.
IF SY-SUBRC = 0.
IF ZWAYBILL-BSTNR <> ' '.
MESSAGE E999(B1) WITH
WAYBILL ':Waybill already assigned to PO:' ZWAYBILL-BSTNR.
EXIT.
ENDIF.
ELSE. "No waybill
MESSAGE E999(B1) WITH
'Waybill # has not yet been generated:' WAYBILL.
ENDIF.
SELECT SINGLE * FROM ZWAYBILL WHERE
BSTNR = BSTNR.
IF SY-SUBRC = 0.
MESSAGE E999(B1) WITH
BSTNR ': PO already has waybill:' ZWAYBILL-WAYBILL.
EXIT.
ENDIF.
SELECT SINGLE * FROM EKKO WHERE
EBELN = BSTNR.
IF SY-SUBRC <> 0.
MESSAGE E999(B1) WITH
'PO does not exist:' BSTNR.
EXIT.
ENDIF.
ENDMODULE. " CHECK_0100 INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE OKCODE.
WHEN 'SAVE'.
REFRESH ZWAYITAB.
MOVE: SY-UNAME TO ZWAYITAB-UNAME,
SY-DATUM TO ZWAYITAB-DATUM,
SY-UZEIT TO ZWAYITAB-UZEIT,
WAYBILL TO ZWAYITAB-WAYBILL,
SY-MANDT TO ZWAYITAB-MANDT,
BSTNR TO ZWAYITAB-BSTNR.
APPEND ZWAYITAB.
SELECT SINGLE * FROM ZWAYBILL WHERE
WAYBILL = WAYBILL.
IF SY-SUBRC = 0.
IF ZWAYBILL-BSTNR = ' '.
PERFORM UPDATE_PO USING WAYBILL BSTNR.
IF RETURN_CODE = 0.
UPDATE ZWAYBILL FROM TABLE ZWAYITAB.
MESSAGE I999(B1) WITH BSTNR 'saved with waybill:' WAYBILL.
ELSE.
MESSAGE I999(B1) WITH BSTNR 'NOT saved for waybill:' WAYBILL.
ENDIF.
ELSE.
MESSAGE I999(B1) WITH 'Waybill assigned to PO:' ZWAYBILL-BSTNR.
ENDIF.
ELSE.
MESSAGE I999(B1) WITH 'That waybill has not been generated:'
WAYBILL.
EXIT.
ENDIF.
WHEN 'LIST'.
SUBMIT Z_LIST_WAYBILL VIA SELECTION-SCREEN AND RETURN.
WHEN 'GENE'.
SUBMIT Z_GEN_WAYBILL VIA SELECTION-SCREEN AND RETURN.
WHEN 'QUIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form ADD_LEADING_ZEROS
*&---------------------------------------------------------------------*
FORM ADD_LEADING_ZEROS CHANGING P_NUMBER.
DATA: T_NUMBER(12) TYPE N.
MOVE P_NUMBER TO T_NUMBER.
MOVE T_NUMBER TO P_NUMBER.
ENDFORM. " ADD_LEADING_ZEROS
*&---------------------------------------------------------------------*
*& Form ADD_LEADING_ZEROS10
*&---------------------------------------------------------------------*
FORM ADD_LEADING_ZEROS10 CHANGING P_NUMBER.
DATA: T_NUMBER(10) TYPE N.
MOVE P_NUMBER TO T_NUMBER.
MOVE T_NUMBER TO P_NUMBER.
ENDFORM. " ADD_LEADING_ZEROS10
*&---------------------------------------------------------------------*
*& Form UPDATE_PO
*&---------------------------------------------------------------------*
FORM UPDATE_PO USING P_WAYBILL
P_BSTNR.
*** Declarations for BDC update
DATA: C_TCODE_ME22 LIKE SY-TCODE VALUE 'ME22'.
DATA BEGIN OF MESSTAB OCCURS 10.
INCLUDE STRUCTURE BDCMSGCOLL.
DATA END OF MESSTAB.
REFRESH BDCDATA.
PERFORM APPEND_BDC USING 'SAPMM06E' '0105' ' ' ' '.
PERFORM APPEND_BDC USING ' ' ' ' 'RM06E-BSTNR' P_BSTNR.
PERFORM APPEND_BDC USING ' ' ' ' 'BDC_OKCODE' '/00'.
PERFORM APPEND_BDC USING 'SAPMM06E' '0120' ' ' ' '.
PERFORM APPEND_BDC USING ' ' ' ' 'BDC_OKCODE' '=KOPF'.
PERFORM APPEND_BDC USING 'SAPMM06E' '0101' ' ' ' '.
PERFORM APPEND_BDC USING ' ' ' ' 'EKKO-IHREZ' P_WAYBILL.
PERFORM APPEND_BDC USING ' ' ' ' 'BDC_OKCODE' '=DR'.
PERFORM APPEND_BDC USING 'SAPDV70A' '0100' ' ' ' '.
PERFORM APPEND_BDC USING ' ' ' ' 'BDC_OKCODE' '=V70S'.
*--- Call transaction with errors to BDC -----------------------------
REFRESH MESSTAB.
CALL TRANSACTION C_TCODE_ME22 USING BDCDATA MODE 'N' UPDATE 'S'
MESSAGES INTO MESSTAB.
RETURN_CODE = SY-SUBRC.
IF RETURN_CODE = 0.
LOOP AT MESSTAB.
IF MESSTAB-MSGTYP = 'E'.
RETURN_CODE = MESSTAB-MSGNR.
MESSAGE ID MESSTAB-MSGID TYPE 'E' NUMBER MESSTAB-MSGNR.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
*--- Here we check the return code, if there was an error, we put the
* transaction in a BDC session for the user to review and correct.
IF RETURN_CODE NE 0.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = 'ZKJW'
USER = SY-UNAME
KEEP = 'X'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = C_TCODE_ME22
TABLES
DYNPROTAB = BDCDATA.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
ENDIF.
ENDFORM. " UPDATE_PO
*&---------------------------------------------------------------------*
*& Form APPEND_BDC
*&---------------------------------------------------------------------*
FORM APPEND_BDC USING VALUE(P_PROG)
VALUE(P_SCREEN)
VALUE(P_NAM)
VALUE(P_VAL).
CLEAR BDCDATA.
IF P_PROG NE SPACE.
BDCDATA-PROGRAM = P_PROG.
BDCDATA-DYNPRO = P_SCREEN.
BDCDATA-DYNBEGIN = 'X'.
BDCDATA-FNAM = P_NAM.
BDCDATA-FVAL = P_VAL.
ELSE.
BDCDATA-FNAM = P_NAM.
BDCDATA-FVAL = P_VAL.
ENDIF.
APPEND BDCDATA.
ENDFORM. " APPEND_BDC
2.3.2 Report programs
2 Reports were written to:
· display a list of waybill numbers against Pos (Z_LIST_WAYBILL)
· generate a list of waybill numbers for use with the dialog program
(Z_LIST_WAYBILL)
These 2 reports are linked to in the web page template. They need the
following characteristics before they can be run, via the web, using WEBRFC:
· They need authorization groups assigned to their program attributes. The
ITS user that runs the report, via the WEBRFC, needs to have the rights to
run reports from this authorization group. (SE38)
· The reports need to be released for the Internet. Use transaction SMW0 to
release the program.
· The report can be added to a report tree in order to access the report via
the standard reporting tree structure available through the standard web
interface. Go to the IMG and search for ‘Reporting Tree’ in order to find the
place to update the tree.
Note: You can transport the tree but the reports need to be released for the
internet in each client that it is required in.
2.3.2.1 Example of Z_GEN_WAYBILL
REPORT Z_GEN_WAYBILL NO STANDARD PAGE HEADING.
* DATA DECLARATION *
***** TABLE DECLARATIONS
TABLES: ZWAYBILL.
***** DATA DECLARATIONS
DATA: TEMP_VAL LIKE SY-TABIX.
DATA: BEGIN OF ZWAYITAB OCCURS 1000,
MANDT LIKE SY-MANDT,
WAYBILL LIKE ZWAYBILL-WAYBILL,
BSTNR LIKE ZWAYBILL-BSTNR,
UNAME LIKE ZWAYBILL-UNAME,
DATUM LIKE ZWAYBILL-DATUM,
UZEIT LIKE ZWAYBILL-UZEIT.
DATA END OF ZWAYITAB.
DATA: T_WAYB1(12) TYPE N,
T_WAYB2(12) TYPE N.
* SELECTION SCREEN *
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: WAYB1 LIKE ZWAYBILL-WAYBILL,
WAYB2 LIKE ZWAYBILL-WAYBILL.
SELECTION-SCREEN END OF BLOCK B1.
* MAIN LOGIC *
***** START-OF-SELECTION
START-OF-SELECTION.
DATA: CNT1(1000) TYPE I.
IF WAYB2 =' ' AND WAYB1 = ' '.
MESSAGE E999(B1) WITH 'You have to make a selection.'.
EXIT.
ENDIF.
IF WAYB1 <> ' ' AND WAYB2 = ' '. WAYB2 = WAYB1. ENDIF.
IF WAYB1 =' ' AND WAYB2 <> ' '. WAYB1 = 0. ENDIF.
MOVE WAYB1 TO T_WAYB1.
MOVE WAYB2 TO T_WAYB2.
MOVE T_WAYB1 TO WAYB1.
MOVE T_WAYB2 TO WAYB2.
CNT1 = 0.
WHILE WAYB1 <= WAYB2.
MOVE: SY-UNAME TO ZWAYITAB-UNAME,
SY-DATUM TO ZWAYITAB-DATUM,
SY-UZEIT TO ZWAYITAB-UZEIT,
WAYB1 TO ZWAYITAB-WAYBILL,
SY-MANDT TO ZWAYITAB-MANDT,
' ' TO ZWAYITAB-BSTNR.
INSERT INTO ZWAYBILL VALUES ZWAYITAB.
IF SY-SUBRC = 0.
ADD 1 TO CNT1.
ENDIF.
ADD 1 TO WAYB1.
MOVE WAYB1 TO T_WAYB1.
MOVE T_WAYB1 TO WAYB1.
ENDWHILE.
IF SY-SUBRC <> 0.
WRITE: /1 'No records added'.
ELSE.
WRITE: /1 CNT1, ' records added.'.
ENDIF.
END-OF-SELECTION.
2.3.2.2 Example of Z_LIST_WAYBILL
REPORT Z_LIST_WAYBILL NO STANDARD PAGE HEADING.
* DATA DECLARATION *
***** TABLE DECLARATIONS
TABLES: ZWAYBILL.
***** DATA DECLARATIONS
DATA: TEMP_VAL LIKE SY-TABIX.
DATA: T_WAYB1(12) TYPE N,
T_WAYB2(12) TYPE N,
T_BSTN1(10) TYPE N,
T_BSTN2(10) TYPE N.
* SELECTION SCREEN *
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: WAYB1 LIKE ZWAYBILL-WAYBILL,
WAYB2 LIKE ZWAYBILL-WAYBILL,
BSTN1 LIKE ZWAYBILL-BSTNR,
BSTN2 LIKE ZWAYBILL-BSTNR.
SELECTION-SCREEN END OF BLOCK B1.
* EVENTS *
***** TOP-OF-PAGE
TOP-OF-PAGE.
FORMAT COLOR COL_HEADING.
WRITE: /1 'Waybill #',
15 'PO #',
30 'Name',
45 'Date',
60 'Time'.
ULINE.
* MAIN LOGIC *
***** START-OF-SELECTION
START-OF-SELECTION.
IF WAYB2 =' ' AND WAYB1 = ' '. WAYB1 = 0. WAYB2 = 999999999999. ENDIF.
IF WAYB1 <> ' ' AND WAYB2 = ' '. WAYB2 = WAYB1. ENDIF.
IF WAYB1 =' ' AND WAYB2 <> ' '. WAYB1 = 0. ENDIF.
IF BSTN2 =' ' AND BSTN1 = ' '. BSTN1 = ' '. BSTN2 = 9999999999. ENDIF.
IF BSTN1 <> ' ' AND BSTN2 = ' '. BSTN2 = BSTN1. ENDIF.
MOVE WAYB1 TO T_WAYB1.
MOVE WAYB2 TO T_WAYB2.
MOVE T_WAYB1 TO WAYB1.
MOVE T_WAYB2 TO WAYB2.
MOVE BSTN1 TO T_BSTN1.
MOVE BSTN2 TO T_BSTN2.
MOVE T_BSTN1 TO BSTN1.
MOVE T_BSTN2 TO BSTN2.
IF BSTN1 = '0000000000'. CLEAR BSTN1. ENDIF.
SELECT * FROM ZWAYBILL WHERE
( WAYBILL >= WAYB1 AND WAYBILL <= WAYB2 ) AND
( BSTNR >= BSTN1 AND BSTNR <= BSTN2 ).
TEMP_VAL = ( SY-DBCNT ) MOD 2.
IF TEMP_VAL = 0.
FORMAT COLOR 2.
ELSE.
FORMAT COLOR 4.
ENDIF.
WRITE: /1 ZWAYBILL-WAYBILL,
15 ZWAYBILL-BSTNR,
30 ZWAYBILL-UNAME,
45 ZWAYBILL-DATUM,
60 ZWAYBILL-UZEIT.
ENDSELECT.
IF SY-SUBRC <> 0.
MESSAGE I999(B1) WITH 'No values in that range, try again.'.
ELSE.
FORMAT COLOR COL_TOTAL.
WRITE: /1 'Total Records = ', SY-DBCNT.
FORMAT COLOR OFF.
ENDIF.
END-OF-SELECTION.
3 SAP@Web Studio portion
To maintain the interface with the internet application components, it is best to
use the SAP tool SAP@Web Studio. It allows you to create a project, where you
can manage all the development and changes that you are currently working on
from 1 area. It provides the following functionality to you:
· You can publish your web pages to the webserver, once a webserver site
definition has been successfully completed
· In order to make changes to templates, services or resource files, you need
to check them out to your personal directory. This marks them as unavailable
on the SAP system for working on by other team members. On completion,
you simply check them back into SAP
· Studio also allows you to easily pull templates from SAP as well as to put
templates in SAP for storing.
· Use transaction SIAC, in SAP, to link a service to a transport. You cannot
check out files if they are not linked to an open transport.
Follow the steps mentioned below to create the files necessary for displaying
our web enabled transaction.
3.1 Creating a service file
The service file keeps the parameters used by the transaction. E.g. Userid,
password, systemid
Start WEB@STUDIO and goto File->New -> Service Wizards. Add to a project
that will keep track of your work.
· Choose a service name (E.g. ZWAY)
· The R/3 system is best left as <use global settings> unless you want to
specifically limit it a particular system.
· Select <Use global service spec> to specify the user unless you want to
specifically limit it to a user other than the global ITS user.
· Enter a timeout period in minutes. This is the time taken before the session
becomes invalid when there has been no activity.
· Use the web transaction that you created in step 1.
· Click finish
Example service file
~transaction ZWAY
~timeout 20
3.2 Creating a resource file
Resource files enable you to separate language dependent content from the
logic of your SAP application. If you want to publish the application in French and
English then you will need 2 resource files.
Start WEB@STUDIO and goto File->New -> Resource Wizards. Add to a
project that will keep track of your work.
· Enter service name
· Theme (default = 99)
· Language = en
3.3 Developing the web page
Start WEB@STUDIO and goto File->New -> Template Wizards. Add to a project
that will keep track of your work.
· Choose the SAP system with the custom SAP transaction on it
· Enter user details on how to log into the system
· Enter the program name; screen numbers, service and theme
· If it is language dependent then you would point to the applicable resource
and theme and separate templates would be created for you
· Finish
Example web page
<html><head><title>Program ZWAYBILL_ENTRY</title></head>
<script language="javascript">
function goBack(){
parent.location = "http://testweb/scripts/wgate?~service=webrfc&_FUNCTION=
WWW_GET_SELSCREEN&_REPORT=Z_LIST_WAYBILL";
}
function goGen(){
parent.location = "http://testweb/scripts/wgate?~service=webrfc&_FUNCTION=
WWW_GET_SELSCREEN&_REPORT=Z_GEN_WAYBILL";
}
</script>
<body><center>
<h2>Waybill Processing</h2><hr>
<form action="`wgateURL()`" method="post">
<h4>Update Purchase Order with Waybill number</h4>
<table>
<tr><td>`WAYBILL.label`</td><td><input type="text" name="WAYBILL" value="`WAYBILL`" maxlength="12" size="12" ></td></tr>
<tr><td>`BSTNR.label`</td><td><input type="text" name="BSTNR" value="`BSTNR`" maxlength="10" size="10" ></td></tr>
</table>
<p><input type="submit" name="~OkCode(SAVE)" value="`BUTTON_SAVE.label`">
<input type="submit" name="~OkCode(QUIT)" value="`BUTTON_QUIT.label`"></p>
</form>
<HR><h4>List or Generate Waybill numbers</h4>
Press the List Button below to see a list of Waybills used<br><img src ="/images/BUTTONS/List.jpg" alt = "List" onclick = "javascript:goBack();"><br>
Press the Generate Button below to generate new waybill numbers<br><img src ="/images/BUTTONS/Generate.jpg" alt = "List" onclick = "javascript:goGen();">
<hr><h5><font color="#FF4500">`~messageLine`</font></h5></center></body></html>
4 Finished product


