You are on page 1of 328

A AB BA AP P

IIB BM MA AP PD DE EV VT Te ea am m

Table of Contents
2.3.10 CHAPTER 1 USEFUL TRANSACTIONS 3 CHAPTER 3 1.1 EDI SPECIFIC TRANSACTIONS---------------3 1.1.1 SCHEDULING AGREEMENTS........................ 3 1.2 MESSAGE CONTROL ----------------------------3 1.2.1 DELIVERY ................................................. 3 1.2.2 INVOICE .................................................... 3 1.2.3 ORDER RESPONSE .................................... 3 1.2.4 IDOC ADMINISTRATION .............................. 3 1.2.5 IDOC DEVELOPMENT ................................. 4 1.2.6 REQUIREMENTS CODING ............................ 4 CHAPTER 2 USEFUL PROGRAMS AND FUNCTION 5 3.1 GENERAL PROGRAMMING 186 STEP LOOP........................................... 180

BAPIS ---------------------------------------------- 186

3.2 DIALOG PROGRAMMING ------------------- 186 3.2.1 PROCESS ON VALUE REQUEST F4 ....... 186 3.3 REPORTS----------------------------------------- 187 3.3.1 REFRESHING DATA ON REPORTS ........... 187 3.3.2 TREE REPORTS .................................... 188 3.3.3 INITIALIZING DATE RANGES ON SELECTIONOPTIONS 191 3.3.4 REPORT HEADINGS ............................... 191 3.3.5 POPUP SELECTION GET FILENAME ...... 192 3.3.6 CHECKBOXES IN REPORTS ..................... 192 3.3.7 LIST BOXES ON SELECTION SCREENS .... 192 3.3.8 AT LINE SELECTION ............................... 193 3.3.9 TABSTRIPS ON A SELECTION SCREEN ..... 193 3.3.10 DYNAMIC SELECTION SCREENS .............. 194 3.4 FILE PROCESSING ---------------------------- 195 3.4.1 DOWNLOADING TO EXCEL...................... 195 3.4.2 FTP A FILE TO ANOTHER SERVER ........... 196 3.4.3 DATASET ........................................... 197 3.4.4 WS_DOWNLOAD............................... 198 3.4.5 GUI_DOWNLOAD WITH POPUP FILENAME REQUEST 199 3.5 MACROS ------------------------------------------ 200

2.1 FUNCTION MODULES ---------------------------5 2.1.1 STANDARD FUNCTION MODULE .................. 5 2.1.2 CUSTOM FUNCTION MODULE .................... 12 2.2 PROGRAMS --------------------------------------- 18 2.2.1 RHSOBJCH FIXES PD CONTROL TABLES MISSING IN TX SWU3............................................. 18 2.2.2 RV80HGEN........................................... 18 2.2.3 SCHEDULING OF SYSTEM MAINTENANCE JOBS 19 2.2.4 G/L ACCOUNT LINE ITEM DISPLAY ........... 20 2.2.5 FI-SL: REVERSAL OF ACTUAL DOCUMENTS20 2.2.6 SET DOCUMENT SELECT PATH .................. 20 2.2.7 CHECK IF ALL THE CHARACTER IN A STRING ARE NUMERIC 20 2.2.8 BACKGROUND JOB SET BY PROGRAM ....... 21 2.2.9 DYNAMIC INTERNAL TABLE DEFINE ............ 22 2.2.10 INTERNAL TABLE OPTIMIZATION ................ 23 2.2.11 DOWNLOAD OR UPLOAD FORM ................ 24 2.2.12 FIND ENHANCEMENT ............................... 24 2.2.13 FIND IMG TCODE .................................... 28 2.2.14 DYNAMIC REFURBISH REPORT .................. 31 2.2.15 SMW0 --WEB REPOSITORY .................... 34 2.2.16 ALV GROUP ........................................... 34 2.2.17 SAP SCRIPT ........................................... 57 2.3 INTEGRATED TRANSACTION------------- 100 2.3.1 CREATE INFO TYPE ............................... 100 2.3.2 LSMW ................................................. 112 2.3.3 BADI.................................................... 130 2.3.4 REPORT TREE ...................................... 150 2.3.5 DIS-ACTIVE STANDARD BUTTON ............. 152 2.3.6 SCREEN ENHANCEMENT ON MM01........ 153 2.3.7 QUERY ................................................. 154 2.3.8 BTE ..................................................... 170 2.3.9 .............................................. 176

3.6 SELECT STATEMENTS ---------------------- 201 3.6.1 JOINS ................................................... 201 3.6.2 FOR ALL ENTRIES .................................. 202 3.7 GENERAL----------------------------------------- 203 3.7.1 RETRIEVING THE EMAIL ADDRESS OF AN SAP 203 USER 3.7.2 EXECUTING A PROGRAM ........................ 204 3.7.3 CHANGING \ CREATING REQUIREMENTS . 204 3.7.4 DISPLAYING TRANSACTION .................... 204 3.7.5 GUI-STATUS ........................................ 204 3.7.6 DOCUMENT FLOW ................................. 204 3.7.7 MAINTAINING TRAILING SPACES WHEN DOWNLOADING TO PC ......................................... 205 3.7.8 HIDING ABAP SOURCE CODE ............... 205 3.7.9 WHERE IN IMG IS A TABLE CONFIGURED. 205 3.7.10 EDITOR TIPS (*EJECT AND *$*$) .......... 205 3.7.11 LIST OF WAYS TO TRANSPORT VARIANTS 206 3.7.12 CHECKING FOR BACKGROUND PROCESSING 206 CHAPTER 4
2008-09

WORKFLOW PROGRAMS

207
Page 1 of 328

Dong.Ping

4.1

VIEWING PARTICULAR USERS INBOX 207 OBJECT PROGRAMMING 209

CHAPTER 5 5.1 5.2

SAP DEMO REPORTS ----------------------- 209 TREE REPORTS ------------------------------- 209

5.3 ALV GRID CONTROL------------------------- 219 5.3.1 ADDING CUSTOM BUTTONS ON ALV GRID CONTROLS .......................................................... 219 5.3.2 HIGHLIGHT LINES................................... 223 5.3.3 FIRST LINE VISIBLE ................................ 223 5.3.4 READ ONLY TEXT BOX ............................ 223 5.3.5 ENTERING TEXT .................................... 224 CHAPTER 6 6.1 6.2 6.3 6.4 IDOC PROGRAMMING 226

CREATING AN IDOC-------------------------- 226 SENDING AN IDOC---------------------------- 226 CHANGING AN IDOC ------------------------- 226 CHANGING AN IDOCS STATUS --------- 227

BDC PROCESSING & IDOC STATUS UPDATE 232 6.10.3 MAILING IN SAP.................................... 234 6.10.4 PROGRAM EXAMPLE REPORT TO SHOW EDI STATUS 239 6.10.5 EXAMPLE UPLOAD FILE TO IDOC ............ 252 6.10.6 IDOC CREATION FROM INBOUND FILE ...... 259 6.10.7 LIST TRANSACTIONS .............................. 271 6.10.8 REPORT WITH JOINS AND MACROS ......... 273 6.10.9 GRAPHICAL POPUP PROGRESS DISPLAY279 6.10.10 CHANGE IDOC STATUS TO ERROR STATUS AND SEND TO WORKFLOW ........................................... 280 6.10.11 REPORT TO DOWNLOAD PROGRAMS ....... 287 6.10.12 DISPLAY TABLE IN HTML....................... 296 6.10.13 TREE REPORTS ..................................... 299 6.10.14 SHELL LIST REPORT OFF A TABLE - NAST302 6.10.15 ALV REPORT ........................................ 307 6.10.16 SAP GENERATED REPORT \ DIALOG PROGRAM 311 6.10.17 LIST OF TRANSACTIONS REPORT ............ 322 CHAPTER 7 BASIS ERRORS AND RESOLUTIONS 325

6.10.2

6.5 READING AN IDOC --------------------------- 227 6.5.1 EXAMPLE OPEN DOCUMENT FOR READ 227 6.6 6.7 6.8 DISPLAYING AN IDOC ----------------------- 228 IDOC TYPE POOL ----------------------------- 228 LAUNCHING AN ERROR WORKFLOW - 228

7.1

CANNOT ACTIVATE A TABLE ------------- 325 TEAM CONTRIBUTE 327

CHAPTER 8 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8

GL --------------------------------------------------- 327 OF --------------------------------------------------- 327 CRM ------------------------------------------------ 327 I2 ECOMMERCE -------------------------------- 327 I2 PLANNING ------------------------------------ 327 PE --------------------------------------------------- 327 FI----------------------------------------------------- 328 GPDP----------------------------------------------- 328

6.9 RETURNING IDOCS LINKED TO DOCUMENTS -------------------------------------------- 230 6.9.1 * RETURN THE LIST OF IDOCS LINKED TO THE DELIVERY230 6.9.2 * RETURN THE LIST OF IDOCS LINKED TO THE INVOICE 230 6.9.3 VERSION 4.6X ...................................... 230 6.10 EXAMPLES -------------------------------------- 232 6.10.1 WRITE IDOC STATUS ............................. 232

2008-09

Page 2 of 328

Dong.Ping

CHAPTER 1 USEFUL TRANSACTIONS


IDoc Development class: SED.

1.1
VOE1 VOE2 VOE3 VOE4 OVAI

EDI SPECIFIC TRANSACTIONS


Translation between EDI categories and SD item categories Table EDSC view. Customer link to sales area detail. Table view EDPVW. Add partner types that will be transferred to the IDoc. Table view EDPAR. Link external partner number with our internal number. Create entries for each Vendor / Partner description combination. (Vendors must match sold-to Acct. at Cust., and Partner descriptions must match ship-to Partner descriptions.) This transaction updates table T661W. SAP uses this table to determine the schedule agreement sold-to partner.

1.1.1 Scheduling agreements


OVA9 Create entries for each sold-to customer for which you will receive EDI schedule releases. At implementation, the only field that needs to be maintained is "Check PO number," which causes SAP to make sure that the PO number sent on the release matches the PO number on the schedule agreement. This transaction updates table T663A. SAP will not post an EDI schedule release, if this record is missing. If you would like SAP to post schedule requirements using discrete dates only, instead of weekly and/or monthly buckets, you can indicate the days of the week that you deliver to this customer. SAP will divide the customer's quantity for a week or month evenly into the days of the week specified by the distribution function code. This code must be sent in the DELINS IDoc in field E1EDP16-ETVTF.

OVAJ

1.2
NACE

MESSAGE CONTROL
Links to all the message control transactions via the application area

1.2.1 Delivery
V/36 Maintain output determination for deliveries (Output determination procedures) V10000 (Header output) has condition type LAVA (usually with requirement 1 NB: Use V/84 V7ALLE SHAD for grouped ASNs. I.e. Group deliveries into shipments Create output condition records for shipping. LAVA WE (Partner function) - We must add each new partner with VV21 Reissue output for deliveries

VV21 VL71

1.2.2 Invoice
V/54 VV31 VF31 Maintain access sequence for billing documents Create condition records for billing documents. (RD00 RE Billing party) Reissue output for billing documents

1.2.3 Order response


V/30 V/48, V/32, V/43 VV11 Sales document output types (BA00) Maintain access sequence for sales documents Create condition records for sales documents. (BA00 SP Sold to party)

1.2.4 IDoc Administration



2008-09 Page 3 of 328

Dong.Ping

WE09 / WE02 WE05 WE60 WE20

IDoc lists according to content. View IDocs via specific IDoc number or business application detail contained within the contents of a segment. View IDocs IDoc type documentation tool Partner profile configuration. Add partner detail together with inbound and outbound relationships. We also incorporate message control on the outbound IDocs. Utilize the organizational units to trap functional errors for further processing. Reprocess IDocs in error or waiting for action. (Both inbound and outbound in 4.6. Use BD88 in prior versions)

BD87

1.2.5 IDoc Development


BD55 WE19 WE31 WE30 WE82 WE57 Conversion rule user exit. Link conversion rule user exit to the different system \ partner combinations. EDI test tool. Use to test inbound Function module changes. Segment create Create IDoc extension type Link Release detail to Extension IDoc Type Assign function module to logical message and IDoc type

1.2.6 Requirements coding


V/27 Create code to check requirements for output control. Used to check ZBA0 against BA00 output.

2008-09

Page 4 of 328

CHAPTER 2 USEFUL PROGRAMS AND FUNCTI ON


2.1 FUNCTION MODULES

SD_VBAP_READ_WITH_VBELN EDIT_LINES VIEW_MAINTENANCE_CALL DY_GET_FOCUS DY_GET_SET_FIELD_VALUE F4IF_INT_TABLE_VALUE_REQUEST READ_TEXT CONVERSION_EXIT_CUNIT_OUTPUT SJIS_DBC_TO_SBC SJIS_SBC_TO_DBC CO_R0_CHECK_DECIMAL_POINT POSTAL_CODE_CHECK CONVERSION_EXIT_ALPHA_INPUT GET_JOB_RUNTIME_INFO TERMINAL_ID_GET DATE_CONVERT_TO_FACTORYDATE MESSAGE_TEXT_BUILD POPUP_TO_CONFIRM CONVERSION_EXIT_MATN1_INPUT CONVERSION_EXIT_MATN1_OUTPUT SSF_FUNCTION_MODULE_NAME DATE_CHECK_PLAUSIBILITY cl_gui_frontend_services=>gui_upload cl_gui_frontend_services=>gui_download SSF_FUNCTION_MODULE_NAME SMARTFORMS POPUP_TO_DECIDE_LIST ABAP_DOCU_DOWNLOAD BAL_* BP_EVENT_RAISE BP_JOBLOG_READ CLOI_PUT_SIGN_IN_FRONT CLPB_EXPORT CLPB_IMPORT COMMIT_TEXT CONVERSION_EXIT_ALPHA_INPUT CONVERSION_EXIT_ALPHA_OUTPUT CONVERT_OTF

2.1.1 Standard Function module

vbap READ_TEXT LINES TDFORMAT=* help 0 job id form (SmartForm) CHECK CALL HTML ABAP SAP ABAP/4 job log SAP SAP 0 0 SAP (SAP Script)
2008-09

Example

Transfer SAP Script.txt

Page 5 of 328

DATE_GET_WEEK DATE_CHECK_PLAUSIBILITY DYNP_VALUES_READ DYNP_VALUES_UPDATE ENQUE_SLEEP ENQUEUE_ESFUNCTION EPS_GET_FILE_ATTRIBUTES EPS_GET_DIRECTORY_LISTING F4_DATE F4IF_SHLP_EXIT_EXAMPLE FILENAME_GET FTP_CONNECT FTP_COMMAND FTP_DISCONNECT GET_GLOBAL_SYMBOLS GET_INCLUDETAB WS_FILE_DELETE GUI_CREATE_DIRECTORY GUI_REMOVE_DIRECTORY cl_gui_frontend_services=>file_delete GUI_DELETE_FILE GUI_DOWNLOAD GUI_EXEC GUI_GET_DESKTOP_INFO GUI_RUN GUI_UPLOAD

SAP SCREEN SELECTION SCREEN ABAP F4 FTP FTP FTP tables, select options, texts, etc selection screen INCLUDES
Delete.txt

WS_EXECUTE WS_QUERY WS_UPLOAD (Useful for doing AT SELECTION SCREEN ON VALUE REQUEST for those fields that do not provide F4 help at the DDIC level) Factory Calendar&/ Holiday Calendar SAP INI INI
2008-09
Download.txt

HELP_START

HOLIDAY_GET INIT_TEXT POPUP_TO* PRICING PROFILE_GET PROFILE_SET READ_TEXT REGISTRY_GET REGISTRY_SET RP_CALC_DATE_IN_INTERVAL

Last Day of Month.txt

Page 6 of 328

Last Day of Calendar.txt

RP_LAST_DAY_OF_MONTHS LAST_DAY_IN_PERIOD_GET RPY_DYNPRO_READ SXPG_COMMAND_CHECK TH_DELETE_USER TH_POPUP UNIT_CONVERSION_SIMPLE WS_DOWNLOAD WS_EXCEL WS_EXECUTE WS_MSG WWW_LIST_TO_HTML SD_VBAP_READ_WITH_VBELN EDIT_LINES VIEW_MAINTENANCE_CALL DY_GET_SET_FIELD_VALUE F4IF_INT_TABLE_VALUE_REQUEST CONVERSION_EXIT_CUNIT_OUTPUT SJIS_DBC_TO_SBC SJIS_SBC_TO_DBC CO_R0_CHECK_DECIMAL_POINT POSTAL_CODE_CHECK TERMINAL_ID_GET idDATE_CONVERT_TO_FACTORYDATE MESSAGE_TEXT_BUILD CONVERT_TO_LOCAL_CURRENCY SSF_FUNCTION_MODULE_NAME DATE_CHECK_PLAUSIBILITY CHECKcl_gui_frontend_services=>gui_upload cl_gui_frontend_services=>gui_download SSF_FUNCTION_MODULE_NAME DAY_IN_WEEK RP_CALC_DATE_IN_INTERVAL BKK_ADD_MONTH_TO_DATE GUI_CREATE_DIRECTORY GUI_DELETE_FILE GUI_DOWNLOAD GUI_EXEC GUI_GET_DESKTOP_INFO GUI_RUN GUI_UPLOAD GET_CURRENT_YEAR GET_SF_DUNN_DATA

SM04 EXCEL HTML vbap READ_TEXT LINES TDFORMAT=* help GET_JOB_RUNTIME_INFO job , form (SmartForm) SMARTFORMS CALL / PC PC PC PC PC ShellExecute PC fiscal year
dunning

ReadMess.txt

letter
Page 7 of 328

2008-09

SAPGUI_PROGRESS_INDICATOR QSS0_FLTP_TO_CHAR_CONVERSION RV_DELIVERY_PRINT_VIEW HU_CREATE_ITEM

Progress Indicator.txt

delivery Handling unit


USEREXIT_KOMKBV1_FILL,User exit to update communication structure at header level. In function module KOMKBV1_FILL called from SAPMV45A Application interface to the ALE layer on outbound processing side CA-EDI: IDoc documentation tools API(Reads full IDoc structure and field documentation. Offsets, types, etc..) Download ABAP documentation in HTML format will return the IP address of the terminal in hex All function modules used for SAP's application logging can be found here Trigger an event from ABAP/4 program Fetch job log executions Place the negative sign after a number. SAP default is place the negative sign after the number. Export a text table to the clipboard (on presentation server) Import a Text Table from the Clipboard (on presentation server) To load long text into SAP converts any number into a string fill with zeroes-right converts any number with zeroes-right into a simple integer Convert SAP documents (SAPScript) to other types will return the week that a date is in Check to see if a date is in a valid format for SAP. Works well when validating dates being passed in from other systems download a file to the presentation server (PC) Read the values from a dynpro. This function can be used to read the values from a report's selection screen too Similar to DYNP_VALUES_READ, this function will allow the updating of fields on a dynpro. Very useful when you want to change a field based on the value entered for another field. Wait a specified period of time before continuing processing Lock an abap program so that it cannot be executed. Set the parameters as follows: Pass in a filename and a path, and will return attributes for the file return a list of filenames from a local or network drive displays a calendar in a popup window and allows user to choose a date, or it can be displayed read only.

.txt

Read Delivery.txt

KOMKBV1_FILL

MASTER_IDOC_DISTRIBUTE IDOC_TYPE_COMPLETE_READ ABAP_DOCU_DOWNLOAD ARFC_GET_TID BAL_* BP_EVENT_RAISE BP_JOBLOG_READ CLOI_PUT_SIGN_IN_FRONT CLPB_EXPORT CLPB_IMPORT COMMIT_TEXT CONVERSION_EXIT_ALPHA_INPUT CONVERSION_EXIT_ALPHA_OUTPUT CONVERT_OTF DATE_GET_WEEK DATE_CHECK_PLAUSIBILITY DOWNLOAD DYNP_VALUES_READ

DYNP_VALUES_UPDATE

ENQUE_SLEEP ENQUEUE_ESFUNCTION EPS_GET_FILE_ATTRIBUTES EPS_GET_DIRECTORY_LISTING

F4_DATE

2008-09

Page 8 of 328

F4IF_SHLP_EXIT_EXAMPLE FILENAME_GET FTP_CONNECT FTP_COMMAND FTP_DISCONNECT

documents the different reasons to use a search help exit, and shows how it is done. popup to get a filename from a user, returns blank filename if user selects cancel Open a connection (and log in) to an FTP server Execute a command on the FTP server Close the connection (and log off) the FTP server Takes a message id and number, and puts it into a variable. Works better than WRITE_MESSAGE, since some messages use $ as a place holder, and WRITE_MESSAGE does not accommadate that, it only replaces the ampersands (&) in the message. Returns a list of all tables, select options, texts, etc for a program. Even includes the text definitions for the selection screen Returns a list of all INCLUDES in a program Fetch values from a set Function Group GRAP is now obsolete. SAP recommends using functions in function group SFES instead. Below is an overview of the changes Create a directory on the presentation server Replaces WS_FILE_DELETE. Delete a file on the presentation server Replaces WS_DOWNLOAD. Download table from the app server to presentation server Replaces WS_EXECUTE. Start a File or Program Asynchronously with WinExec Replaces WS_QUERY. Delivers Information About the Desktop (client) Delete a directory on the presentation server Start a File or Program Asynchronously with ShellExecute Replaces WS_UPLOAD. Upoad file from presentation server to the app server Display help for a field. Useful for doing AT SELECTION SCREEN ON VALUE REQUEST for those fields that do not provide F4 help at the DDIC level. Provides a table of all the holidays based upon a Factory Calendar &/ Holiday Calendar. is an HR function, but can be used for any data. You pass it data, and column headers, and it provides a table control with the ability to manipulate the data, and send it to Word or Excel. Also see the additional documentation here. Get all leave information (includes leave entitlement, used holidays/paid out holidays) To load long text into SAP Return a list of all plants for a given company code convert an ABAP report (displayed on screen) from OTF to ASCII format Retrieves the output of a report from memory when the report was executed using SUBMIT... EXPORTING LIST TO MEMORY. See also WRITE_LIST. 2008-09 Page 9 of 328

FORMAT_MESSAGE

GET_GLOBAL_SYMBOLS GET_INCLUDETAB

G_SET_GET_ALL_VALUES

GUI_CREATE_DIRECTORY GUI_DELETE_FILE GUI_DOWNLOAD GUI_EXEC GUI_GET_DESKTOP_INFO GUI_REMOVE_DIRECTORY GUI_RUN GUI_UPLOAD

HELP_START

HOLIDAY_GET

HR_DISPLAY_BASIC_LIST

HR_GET_LEAVE_DATA INIT_TEXT K_WERKS_OF_BUKRS_FIND LIST_TO_ASCII

LIST_FROM_MEMORY

MONTH_NAMES_GET MS_EXCEL_OLE_STANDARD_OLE OTF_CONVERT CONVERT_OTFSPOOLJOB_2_PDF CONVERT_ABAPSPOOLJOB_2_PDF POPUP_TO_CONFIRM_LOSS_OF_DATA

It returns all the month and names in repective language. will build a file, and automatically start Excel wraps several other function modules. Will convert OTF to ASCII or PDF converts a OTF spool to PDF (i.e. Sapscript document) convert abap spool output to PDF Create a dialog box in which you make a question whether the user wishes to perform a processing step with loss of data. Create a dialog box in which you make a question whether the user wishes to perform the step. Create a dialog box in which you inform the user about a specific decision point during an action. Create a dialog box in which you make a question whether the user wishes to perform a processing step with a particular object Provide user with several choices as radio buttons Create a dialog box in which you inform the user about a specific decision point via a diagnosis text. Create a dialog box in which you display a two-line message Popup to choose a month Provide a display of a table for user to select one, with the value of the table line returned when selected. Return pricing conditions in an internal table. Use structure TCOMK for parameter COMM_HEAD_1, and structure TCOMP for parameter COMM_ITEM_1, and set CALCULATION_TYPE to B. The pricing conditions will be returned in XOMV. You must fill TCOMP, and TCOMK with the appropriate values before callling the function in order for it to work. Read an Entry in an INI File on the frontend Write an Entry in an INI File on the frontend To load long text into SAP Read an Entry from the Registry Set an entry in the Registry Runs an ABAP program that is stored in the table PROGRAM when the MODE = 'F'. Table WRITES contains the ouput of the program. Allows you to run a program without having the source code in the target system. Return the active HR Plan return the day based on the date provied starts Excel with the contents of an internal table. This function finds Excel in the desktop registry. It also uses a local PC working directory to save the file (that's what the "W" value for data path flag does). Very transparent to user! Returns all related org info 2008-09 Page 10 of 328

POPUP_TO_CONFIRM_STEP

POPUP_TO_CONFIRM_WITH_MESSAGE

POPUP_TO_CONFIRM_WITH_VALUE POPUP_TO_DECIDE POPUP_TO_DECIDE_WITH_MESSAGE POPUP_TO_DISPLAY_TEXT POPUP_TO_SELECT_MONTH POPUP_WITH_TABLE_DISPLAY

PRICING

PROFILE_GET PROFILE_SET READ_TEXT REGISTRY_GET REGISTRY_SET

RFC_ABAP_INSTALL_AND_RUN

RH_GET_ACTIVE_WF_PLVAR RH_GET_DATE_DAYNAME

RH_START_EXCEL_WITH_DATA

RH_STRUC_GET

RP_CALC_DATE_IN_INTERVAL RP_LAST_DAY_OF_MONTHS RPY_DYNPRO_READ

Add/subtract years/months/days from a date Determine last day of month Read dynpro, including screen flow Given a transaction, return the program and screen or given a program and screen, return the transactions that use the program and screen. Returns an internal table that contains a formatted list of all the selection parameters entered for a report. Table is ready to print out. Get the current contents of selection screen Send message from ABAP/4 program to SAPoffice. Returns the contents of the specified variant in a table. Hang the current application from 1 to 5 seconds. Submit a remote report. Read a directory on the Application Server If the server name is left blank, it reads a directory from local presentation server, otherwise it reads the directory of the remote server Read a file from the presentation server if no server name is given, or read file from remote server. Very useful to avoid authority checks that occur doing an OPEN DATASET. This function using a SAP C program to read the data. Saves table to the presentation server (not PC). Does not use OPEN DATASET, so it

RPY_TRANSACTION_READ

RS_COVERPAGE_SELECTIONS RS_REFRESH_FROM_SELECTOPTIONS RS_SEND_MAIL_FOR_SPOOLLIST RS_VARIANT_CONTENTS RZL_SLEEP RZL_SUBMIT RZL_READ_DIR_LOCAL

RZL_READ_DIR

RZL_READ_FILE

RZL_WRITE_FILE_LOCAL

does not suffer from authority checks!


Display a progress bar on the SAP GUI, and give the user some idea of what is happening To load long text into SAP If you are coding a module pool and using a table-control, you can use this function SCROLLING_IN_TABLE to handle any scrolling. (provided by Paul Kjaer) Give the difference in Days and Time for 2 dates Send a document as part of an email. The documentation is better than normal for this function, so please read it. Split a fully pathed filename into a filename and a path. Fetch printer spool according to the spool number informed Browse printer spool numbers according to user informed. Conversion From OTF to PDF (SAPScript conversion) Conversion From OTF to Printer Format (SAPScript conversion) Conversion From OTF to ASCII (SAPScript conversion)

SAPGUI_PROGRESS_INDICATOR SAVE_TEXT

SCROLLING_IN_TABLE

SD_DATETIME_DIFFERENCE SO_NEW_DOCUMENT_ATT_SEND_API1 SO_SPLIT_FILE_AND_PATH SO_SPOOL_READ SO_WIND_SPOOL_LIST SX_OBJECT_CONVERT_OTF_PDF SX_OBJECT_CONVERT_OTF_PRT SX_OBJECT_CONVERT_OTF_RAW

2008-09

Page 11 of 328

SXPG_CALL_SYSTEM

you can check the user's authorization for the specified command and run the command. The command runs on the host system on which the function module is executed. The function module is RFC-capable. It can therefore be run on the host system at which a user happens to be active or on another designated host system at which an R/3 server is active. Select a list of external OS command definitions. Read the definition of a single external OS command from the R/3 System's database. Check whether the user is authorized to execute the specified command on the target host system with the specified arguments. Check a user's authorization to use a command, as in SXPG_COMMAND_CHECK. If the authorization check is successful, then execute the command on the target host system. Return the terminal id Logoff a user. Similar results to using SM04. Get the UNIX environment Display a popup system message on a specific users screen. Run a transaction on a remote server. Optionally provide BDC data to be used in the transaction Give information about the current user (sessions, workstation logged in from, etc) Show which users are logged into an app server convert weights from one UOM to another. upload a file to the presentation server (PC) Will load one or more files from app or presentation server Useful for writing out the list contents that result from the function Save Internal Table as File on the Presentation Server Start EXCEL on the PC execute a program on a windows PC Delete File at the Frontend Call File Selector Create a dialog box in which you display an one-line message. Load Files from the Presentation Server to Internal ABAP Tables Get the label from a frontend device After running a report, call this function to convert the list output to HTML.

SXPG_COMMAND_LIST_GET SXPG_COMMAND_DEFINITION_GET SXPG_COMMAND_CHECK

SXPG_COMMAND_EXECUTE

TERMINAL_ID_GET TH_DELETE_USER TH_ENVIRONMENT TH_POPUP TH_REMOTE_TRANSACTION TH_USER_INFO TH_USER_LIST UNIT_CONVERSION_SIMPLE UPLOAD UPLOAD_FILES WRITE_LIST WS_DOWNLOAD WS_EXCEL WS_EXECUTE WS_FILE_DELETE WS_FILENAME_GET WS_MSG WS_UPLOAD WS_VOLUME_GET WWW_LIST_TO_HTML

2.1.2 Custom function module


2.1.2.1 DOWNLOAD_WEB_OBJECT
( Description: Download a Web Template) Sample: Download Excel module from server

2008-09

Page 12 of 328

DATA: w_temp_file(65), "Temp file path for excel template file. w_formkey LIKE wwwdatatab, w_ftemplate LIKE rlgrap-filename, w_fdata LIKE rlgrap-filename. w_formkey = 'MIZARR00414B'. w_ftemplate = 'C:\TEMP\ZARR00414B.XLT'. w_fdata = 'C:\TEMP\ZARR00414B.TXT'. CALL FUNCTION 'DOWNLOAD_WEB_OBJECT' EXPORTING key = w_formkey destination = w_ftemplate CHANGING temp = w_temp_file.

2.1.2.2 SO_DOCUMENT_SEND_API1 SAPoffice: Send new document with attachments using RFC Sample: DATA: it_user TYPE TABLE OF zdepot_mail WITH HEADER LINE, t_time TYPE char8, t_date TYPE char10. * mail DATA: doc TYPE sodocchgi1, pack TYPE TABLE OF sopcklsti1 WITH HEADER LINE, "package cont TYPE TABLE OF solisti1 WITH HEADER LINE, "content recv TYPE TABLE OF somlreci1 WITH HEADER LINE. "user
* user SELECT * INTO TABLE it_user FROM zdepot_mail. IF it_user[] IS INITIAL. EXIT. ENDIF. LOOP AT it_user . recv-receiver = it_user-bname. recv-rec_type = 'B'. "U-INTERNET APPEND recv. ENDLOOP. * content WRITE: sy-datum TO t_date, sy-uzeit TO t_time.

2008-09 Page 13 of 328

CONCATENATE 'Global link has interfaced to SAP system at ' t_time t_date text-011 INTO cont-line SEPARATED BY space. APPEND cont. CLEAR cont-line. cont-line = 'Thank you.'. APPEND cont. * package pack-transf_bin = space. pack-head_start = 1. pack-head_num = 0. pack-body_start = 1. pack-doc_type = 'RAW'. DESCRIBE TABLE cont LINES pack-body_num. APPEND pack. * document header doc-obj_descr = 'Interface Notification'. * mail function CALL FUNCTION 'SO_DOCUMENT_SEND_API1' EXPORTING document_data = doc TABLES packing_list = pack contents_txt = cont receivers = recv EXCEPTIONS too_many_receivers =1 document_not_sent =2 document_type_not_exist = 3 operation_no_authorization = 4 parameter_error =5 x_error =6 enqueue_error =7 OTHERS = 8. IF sy-subrc <> 0. ENDIF.

2008-09 Page 14 of 328

2.1.2.3 ALSM_EXCEL_TO_INTERNAL_TABLE
Upload data from Excel directly Sample: DATA: t1(255). DATA: i_begin_col TYPE i VALUE '1', i_begin_row TYPE i VALUE '2', i_end_col TYPE i VALUE '90', i_end_row TYPE i VALUE '60000'.

DATA: i_intern LIKE alsmex_tabline OCCURS 10 WITH HEADER LINE. DATA: i_return LIKE bapireturn1 OCCURS 10 WITH HEADER LINE.
CLEAR: txline. WRITE 'Upload Excel file from PC,Please wait...' TO txline. write_screen: txline.

DEFINE ins_msg. add 1 to c_err_no. check_msg-no = c_err_no. append check_msg. clear check_msg. c_l_error = 'X'. END-OF-DEFINITION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING filename = p_file i_begin_col = i_begin_col i_begin_row = i_begin_row i_end_col = i_end_col i_end_row = i_end_row TABLES intern = i_intern EXCEPTIONS inconsistent_parameters = 1 upload_ole =2 OTHERS = 3. IF sy-subrc <> 0. CALL FUNCTION 'MESSAGE_TEXT_BUILD' EXPORTING msgid = sy-msgid msgnr = sy-msgno msgv1 = sy-msgv1 msgv2 = sy-msgv2 msgv3 = sy-msgv3 msgv4 = sy-msgv4 IMPORTING message_text_output = t1. check_msg-line = t1. ins_msg. ENDIF.

2008-09

Page 15 of 328

2.1.2.4 G_PERIOD_ALLOWED_CHECK
( Description: Check open posting periods,) SamPle: Spro *All

call function 'G_PERIOD_ALLOWED_CHECK' EXPORTING account_type = + company = bukrs company code period = P_POPER period periv_company = 'Z1' record_type = '0' to_account = ZZZZZZZZZZ default value year = P_GJAHR fiscal year EXCEPTIONS period_not_allowed = 1 not_authorized = 2 others = 3. *Customer call function 'G_PERIOD_ALLOWED_CHECK' EXPORTING account_type = D customer company = bukrs company code period = P_POPER period periv_company = 'Z1' record_type = '0' to_account = ZZZZZZZZZZ default value year = P_GJAHR fiscal year EXCEPTIONS period_not_allowed = 1 not_authorized = 2 others = 3.

2.1.2.5 Transfer money to capital RMB


function z_convert_numeric_to_chinese. *"---------------------------------------------------------------------*"*"Local interface: *" IMPORTING *" VALUE(PI_MONEY) LIKE BSEG-DMBTR *" EXPORTING *" REFERENCE(PO_CHINESE) *" EXCEPTIONS *" WRONG_MONEY

2008-09

Page 16 of 328

*"---------------------------------------------------------------------if pi_money = 0. po_chinese = ''. exit. endif. data:money_str(13). money_str = pi_money. if money_str cn '0123456789. '. raise wrong_money. endif. data:i type i. if money_str cs '.'. i = sy-fdpos + 1. money_str+sy-fdpos = money_str+i. endif. condense money_str no-gaps. data:units_off type i, curnt_off type i. data:lastd type n,curntd type n. data:cword(2),weight(2). data:units(30) value '', digts(20) value ''. * clear:po_chinese,units_off. lastd = 0. curnt_off = strlen( money_str ) - 1. while curnt_off >= 0. curntd = money_str+curnt_off(1). i = curntd * 2. cword = digts+i(2). weight = units+units_off(2). i = units_off / 2. if curntd = 0. "Current digit is 0 if i = 2 or i = 6 or i = 10. clear:cword. if curnt_off = 0. clear:weight. endif. elseif lastd = 0. clear:cword,weight. else. clear:weight. endif. endif. concatenate cword weight po_chinese into po_chinese. lastd = curntd. subtract 1 from curnt_off. add 2 to units_off.

2008-09

Page 17 of 328

endwhile. if po_chinese ns ''. concatenate po_chinese '' into po_chinese. else. cword = po_chinese. if cword = ''. shift po_chinese by 2 places. endif. endif. endfunction.

2.1.2.6 Standard function list


.xls

2.2

PROGRAMS

2.2.1 RHSOBJCH Fixes PD Control Tables missing in tx SWU3 2.2.2 RV80HGEN


Run this program to generate custom code in to standard SAP code when you have created your own conditions using transaction V/27.

RPR_ABAP_SOURCE_SCAN - Search ABAP code for a string. Has many more options for selecting the ABAPs to search than RSRSCAN1 or RKCTSEAR. RSBDCDRU - Prints the contents of a Batch Input session. No options for error transactions only. RSBDCOS0 - Execute UNIX commands. Looks similar to the old SAPMSOS0 program that disappeared in 3.0 RSWBO060 - put objects into a request and transport it to any other system RPUAUD00 - HR Report to list all logged changes for an employee. Uses the PCL4 Audit Cluster. RPUAUDDL - HR Report to delete audit data from the PCL4 Audit Cluster. RPDTRA00 - List all HR transactions. RHGRENZ0 - Delimit IT1000 and related 1001s. Program will delete any 1001 infotypes whose start date is after the delimit date. RHGRENZ2 - Delimit IT1001 only. RHGRENZ1 - Extend the end date on delimited records. Very useful when you delimit a bunch of records incorrectly, and need to change the end date.
Notes on HRGRENZ0/HRBRENZ2: RHGRENZ0/2 will abend if there are any inconsistencies between PD and PA (i.e. people in a different controlling area than the position they belong to). Controlling area of a person is determined by the cost centre that a person's position is assigned to. When assigning a person to a position, SAP checks to make sure that the Controlling area of the company that the person belongs to is the same as that of the Cost centre that their position belongs to.

2008-09

Page 18 of 328

RKCTSEAR - Search source code for up to two strings. Also see RSRSCAN1 and RPR_ABAP_SOURCE_SCAN. RPUP1D00/10 - View/Delete data from PCL1 Cluster RPUP2D00/10 - View/Delete data from PCL2 Cluster RPUP3D00/10 - View/Delete data from PCL3 Cluster RPUP4D00/10 - View/Delete data from PCL4 Cluster RSTXSCRP Save a SAPScript layout set to disk, and load it back into SAP. RPUDELPN Delete all info for an employee number, including cluster data and infotypes. RSABAPIV Mass print/display of ABAP/4 help text RSBDCSUB Release batch-input sessions automatically RSBDCBTC - Submit a BDC job with an internal batch number and wait for the end of the batch-input session. RSCLTCOP Copy tables across clients RSAVGL00 Table adjustment across clients RSINCL00 Extended program list RSTXSCRP Transport SAPscript files across systems RSORAREL Get the Oracle Release RSRSCAN1 Search source code for a given string. Will also search includes. Also see RKCTSEAR and RPR_ABAP_SOURCE_SCAN. RSTBSERV Compare a contents of a table between clients RGUGBR00 Substitution/Validation utility RSPARAM Display all instance parameters RSUSR003 Check the passwords of users SAP* and DDIC in all clients RSUSR006 List users last login RSWBO052 Change development class of a sapscript (provided by Alan Cecchini)

2.2.3 Scheduling of system maintenance jobs


RSBTCDEL Clean the old background job records RSDBCREO Clean batch input session log RSPO0041 Removing old spooling objects RSSNAPDL Clean the old ABAP error dumps

2008-09

Page 19 of 328

2.2.4 G/L Account Line Item Display


TCDDE: FBL3N

2.2.5 FI-SL: Reversal of Actual Documents


Program name: RGUREP13

2.2.6 Set document select path


call method cl_gui_frontend_services=>file_open_dialog Sample: report

**--- SELECT SCREEN selection-screen begin of block b1 with frame title text-000 . parameters:p_file type file_table-filename . "File name selection-screen end of block b1. **---- at selection-screen. data: t_file type string, t_rt type boolean. t_file = p_file. t_rt = cl_gui_frontend_services=>file_exist( t_file ). * Get file name at selection-screen on value-request for p_file.
data: t_rc type i, "For class--return code t_it_file type filetable, "For class--internal table t_wa_file type file_table. "For class--work area * Pop-up the dialog call method cl_gui_frontend_services=>file_open_dialog exporting window_title = 'Select file' file_filter = '*.TXT|*.TXT|*.*|*.*|' initial_directory = 'C:' multiselection = c_false changing file_table = t_it_file rc = t_rc exceptions file_open_dialog_failed = 1 cntl_error =2 error_no_gui =3 not_supported_by_gui = 4. * Get single file read table t_it_file into t_wa_file index 1. p_file = t_wa_file-filename.

2.2.7 Check if all the character in a string are numeric


Sample:

2008-09

Page 20 of 328

DATA: num TYPE p value 3124141, ex TYPE REF TO cx_root. TRY. num = text. CATCH cx_root INTO ex. flag = c_true. ENDTRY.

2.2.8 Background Job set by program


Sample: DATA: t_jobname TYPE tbtcjob-jobname, t_jobcount TYPE tbtcjob-jobcount. * open one job t_jobname = sy-repid. CALL FUNCTION 'JOB_OPEN' EXPORTING jobname = t_jobname IMPORTING jobcount = t_jobcount EXCEPTIONS cant_create_job = 1 invalid_job_data = 2 jobname_missing = 3 OTHERS = 4.

"#EC *

* backgroud execute SUBMIT ZARI014 AND RETURN WITH p_back = c_true WITH p_sap = c_true WITH p_srv = c_false USER sy-uname VIA JOB t_jobname NUMBER t_jobcount TO SAP-SPOOL DESTINATION 'TNT_CHINA_FRONTEND' IMMEDIATELY ' ' KEEP IN SPOOL 'X' WITHOUT SPOOL DYNPRO. * close job CALL FUNCTION 'JOB_CLOSE' EXPORTING jobcount = t_jobcount jobname = t_jobname strtimmed = 'X'

"#EC *

2008-09

Page 21 of 328

EXCEPTIONS cant_start_immediate = 1 invalid_startdate = 2 jobname_missing =3 job_close_failed = 4 job_nosteps =5 job_notex =6 lock_failed =7 invalid_target =8 OTHERS = 9. * send message MESSAGE i208(00) WITH text-005. LEAVE PROGRAM.

2.2.9 Dynamic internal table define


*&---------------------------------------------------------------------* *& Report Zdynamic * *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* REPORT ZPLATO3 . parameters: table type c length 30 . data: data_ref type ref to data.

field-symbols: <tab> type any table.

start-of-selection. create data data_ref type table of (table). assign:data_ref->* to <tab>.

select * from (table) into table <tab> up to 20 rows.

perform write_table using <tab>. *&---------------------------------------------------------------------* *& Form write_table *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_<TAB> text

2008-09 Page 22 of 328

*----------------------------------------------------------------------* FORM write_table USING p_table type any table. field-symbols: <line> type data, <field> type data. loop at p_table assigning <line>. do. assign component sy-index of structure <line> to <field>. if sy-subrc <> 0. exit. endif. write:<field>. enddo. write:/. endloop. ENDFORM. " write_table

2.2.10

Internal table optimization

*&---------------------------------------------------------------------* *& Report ZPLATO2 * *&---------------------------------------------------------------------* REPORT ZPLATO2 . types: begin of my_line_type, name type string, birth_date type d, salary type p decimals 2, end of my_line_type, my_table_type type hashed table of my_line_type with unique key name birth_date. data: my_wa type my_line_type, my_table type my_table_type. start-of-selection. my_wa-name = 'plato'. my_wa-birth_date = '19800506'. my_wa-salary = '200000.00'. insert my_wa into table my_table. my_wa-name = 'April may june'.

2008-09 Page 23 of 328

my_wa-birth_date = '18904343'. my_wa-salary = '100000.00'. insert my_wa into table my_table. my_wa-name = 'mark tan'. my_wa-birth_date = '181204343'. my_wa-salary = '100.00'. insert my_wa into table my_table. perform write_table using my_table. *&---------------------------------------------------------------------* *& Form write_table *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM write_table using p_table type any table. field-symbols: <line> type data, <field> type data. write / '{'. loop at p_table assigning <line>. write /4 '('. do. assign component sy-index of structure <line> to <field>. if sy-subrc <> 0. exit. endif. write /8 <field>. enddo. "loop at component write /4 ')'. endloop. "loop at table write / '}'. ENDFORM. " write_table

2.2.11 2.2.12

Download or Upload Form Find Enhancement


2008-09 Page 24 of 328

Program name : RSTXSCRP

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

*& Report Z_FIND_ENHANCEMENT *&--------------------------------------------------------* REPORT zbadi . TABLES : tstc, tadir, modsapt, modact, trdir, tfdir, enlfdir, sxs_attrt , tstct. DATA : jtab LIKE tadir OCCURS 0 WITH HEADER LINE. DATA : field1(30). DATA : v_devclass LIKE tadir-devclass. PARAMETERS : p_tcode LIKE tstc-tcode, p_pgmna LIKE tstc-pgmna . DATA wa_tadir TYPE tadir. START-OF-SELECTION. IF NOT p_tcode IS INITIAL. SELECT SINGLE * FROM tstc WHERE tcode EQ p_tcode. ELSEIF NOT p_pgmna IS INITIAL. tstc-pgmna = p_pgmna. ENDIF. IF sy-subrc EQ 0. SELECT SINGLE * FROM tadir WHERE pgmid = 'R3TR' AND object = 'PROG' AND obj_name = tstc-pgmna. MOVE : tadir-devclass TO v_devclass. IF sy-subrc NE 0. SELECT SINGLE * FROM trdir WHERE name = tstc-pgmna. IF trdir-subc EQ 'F'. SELECT SINGLE * FROM tfdir WHERE pname = tstc-pgmna. SELECT SINGLE * FROM enlfdir WHERE funcname = tfdir-funcname. SELECT SINGLE * FROM tadir

2008-09

Page 25 of 328

WHERE pgmid = 'R3TR' AND object = 'FUGR' AND obj_name EQ enlfdir-area. MOVE : tadir-devclass TO v_devclass. ENDIF. ENDIF. SELECT * FROM tadir INTO TABLE jtab WHERE pgmid = 'R3TR' AND object IN ('SMOD', 'SXSD') AND devclass = v_devclass. SELECT SINGLE * FROM tstct WHERE sprsl EQ sy-langu AND tcode EQ p_tcode. FORMAT COLOR COL_POSITIVE INTENSIFIED OFF. WRITE:/(19) 'Transaction Code - ', 20(20) p_tcode, 45(50) tstct-ttext. SKIP. IF NOT jtab[] IS INITIAL. WRITE:/(105) sy-uline. FORMAT COLOR COL_HEADING INTENSIFIED ON.

Sorting the internal Table SORT jtab BY object. DATA : wf_txt(60) TYPE c, wf_smod TYPE i , wf_badi TYPE i , wf_object2(30) TYPE c. CLEAR : wf_smod, wf_badi , wf_object2.

Get the total SMOD. LOOP AT jtab INTO wa_tadir. AT FIRST. FORMAT COLOR COL_HEADING INTENSIFIED ON.

WRITE:/1 sy-vline, 2 'Enhancement/ Business Add-in', 41 sy-vline , 42 'Description', 105 sy-vline. WRITE:/(105) sy-uline. ENDAT. CLEAR wf_txt.

2008-09

Page 26 of 328

AT NEW object. IF wa_tadir-object = 'SMOD'. wf_object2 = 'Enhancement' . ELSEIF wa_tadir-object = 'SXSD'. wf_object2 = ' Business Add-in'. ENDIF. FORMAT COLOR COL_GROUP INTENSIFIED ON. WRITE:/1 sy-vline, 2 wf_object2, 105 sy-vline. ENDAT. CASE wa_tadir-object. WHEN 'SMOD'. wf_smod = wf_smod + 1. SELECT SINGLE modtext INTO wf_txt FROM modsapt WHERE sprsl = sy-langu AND name = wa_tadir-obj_name. FORMAT COLOR COL_NORMAL INTENSIFIED OFF. WHEN 'SXSD'. * For BADIs wf_badi = wf_badi + 1 . SELECT SINGLE text INTO wf_txt FROM sxs_attrt WHERE sprsl = sy-langu AND exit_name = wa_tadir-obj_name. FORMAT COLOR COL_NORMAL INTENSIFIED ON. ENDCASE. WRITE:/1 sy-vline, 2 wa_tadir-obj_name HOTSPOT ON, 41 sy-vline , 42 wf_txt, 105 sy-vline. AT END OF object. WRITE : /(105) sy-uline. ENDAT. ENDLOOP. WRITE:/(105) sy-uline. SKIP.

2008-09

Page 27 of 328

FORMAT COLOR COL_TOTAL INTENSIFIED ON. WRITE:/ 'No.of Exits:' , wf_smod. WRITE:/ 'No.of BADis:' , wf_badi. ELSE. FORMAT COLOR COL_NEGATIVE INTENSIFIED ON. WRITE:/(105) 'No userexits or BADis exist'. ENDIF. ELSE. FORMAT COLOR COL_NEGATIVE INTENSIFIED ON. WRITE:/(105) 'Transaction does not exist'. ENDIF. AT LINE-SELECTION. DATA : wf_object TYPE tadir-object. CLEAR wf_object.

GET CURSOR FIELD field1. CHECK field1(8) EQ 'WA_TADIR'. READ TABLE jtab WITH KEY obj_name = sy-lisel+1(20). MOVE jtab-object TO wf_object. CASE wf_object. WHEN 'SMOD'. SET PARAMETER ID 'MON' FIELD sy-lisel+1(10). CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN. WHEN 'SXSD'. SET PARAMETER ID 'EXN' FIELD sy-lisel+1(20). CALL TRANSACTION 'SE18' AND SKIP FIRST SCREEN. ENDCASE.

2.2.13

Find IMG Tcode

REPORT zimgcode_find . TYPES: BEGIN OF typ_param, param TYPE tstcp-param, END OF typ_param. DATA: tab_dd26s TYPE TABLE OF dd26s, rec_dd26s TYPE dd26s, tab_param TYPE TABLE OF typ_param, rec_param TYPE typ_param, tab_tstcp TYPE TABLE OF tstcp, rec_tstcp TYPE tstcp, tab_tstct TYPE TABLE OF tstct, rec_tstct TYPE tstct, rec_dd02t TYPE dd02t, tab_vclstruc TYPE TABLE OF vclstruc, rec_vclstruc TYPE vclstruc.
2008-09 Page 28 of 328

DATA: l_tcode LIKE tstct-tcode, l_tabname TYPE dd25l-roottab. PARAMETERS: p_root TYPE dd25l-roottab OBLIGATORY. AT LINE-SELECTION. GET CURSOR FIELD l_tcode. CHECK l_tcode EQ 'REC_TSTCT-TCODE'. CALL TRANSACTION sy-lisel+1(10). EXIT. AT SELECTION-SCREEN. SELECT SINGLE * FROM dd02t INTO rec_dd02t WHERE ddlanguage = sy-langu AND tabname = p_root. START-OF-SELECTION. PERFORM frm_get_maintanceview. PERFORM frm_get_tcode. PERFORM frm_output_tcode. *&-----------------------------------------------------------* *& Form FRM_GET_MAINTANCEVIEW *&-----------------------------------------------------------* * *------------------------------------------------------------* FORM frm_get_maintanceview. " SELECT * FROM dd26s INTO TABLE tab_dd26s WHERE tabname = p_root. SELECT * FROM dd26s APPENDING TABLE tab_dd26s WHERE viewname = p_root. " SELECT * FROM vclstruc INTO TABLE tab_vclstruc WHERE predobject = p_root.

VIEW

IF NOT tab_dd26s[] IS INITIAL. " SELECT * FROM vclstruc APPENDING TABLE tab_vclstruc FOR ALL ENTRIES IN tab_dd26s WHERE predobject = tab_dd26s-viewname. ENDIF. ENDFORM. " FRM_GET_MAINTANCEVIEW *&-----------------------------------------------------------* *& Form FRM_GET_TCODE *&-----------------------------------------------------------*
2008-09

Page 29 of 328

* *------------------------------------------------------------* FORM frm_get_tcode. CHECK NOT tab_dd26s[] IS INITIAL OR NOT tab_vclstruc[] IS INITIAL. LOOP AT tab_dd26s INTO rec_dd26s. CONCATENATE '%' rec_dd26s-viewname '%' INTO rec_param-param. CONDENSE rec_param-param NO-GAPS. APPEND rec_param TO tab_param. ENDLOOP. LOOP AT tab_vclstruc INTO rec_vclstruc. CONCATENATE '%' rec_vclstruc-vclname '%' INTO rec_param-param. CONDENSE rec_param-param NO-GAPS. APPEND rec_param TO tab_param. ENDLOOP. LOOP AT tab_param INTO rec_param. SELECT * FROM tstcp APPENDING TABLE tab_tstcp WHERE param LIKE rec_param-param. ENDLOOP. IF NOT tab_tstcp[] IS INITIAL. SELECT * FROM tstct INTO TABLE tab_tstct FOR ALL ENTRIES IN tab_tstcp WHERE sprsl = sy-langu AND tcode = tab_tstcp-tcode. ENDIF.

TCODE

ENDFORM. " FRM_GET_TCODE *&-----------------------------------------------------------* *& Form FRM_OUTPUT_TCODE *&-----------------------------------------------------------* * *------------------------------------------------------------* FORM frm_output_tcode. IF tab_tstct[] IS INITIAL. FORMAT COLOR COL_NEGATIVE INTENSIFIED ON. WRITE:/(95) 'Not found any tcode!'. EXIT. ELSE. FORMAT COLOR COL_POSITIVE INTENSIFIED OFF. WRITE:/(19) 'Table : ', 20(20) p_root, 45(50) rec_dd02t-ddtext. SKIP. IF NOT tab_tstct[] IS INITIAL.
2008-09

TCODE

Page 30 of 328

Listekopf WRITE:/(95) sy-uline. FORMAT COLOR COL_HEADING INTENSIFIED ON. WRITE:/1 sy-vline, 2 'T-code', 21 sy-vline , 22 'Description', 95 sy-vline. WRITE:/(95) sy-uline. LOOP AT tab_tstct INTO rec_tstct. READ TABLE tab_tstcp INTO rec_tstcp WITH KEY tcode = rec_tstct-tcode. IF rec_tstcp-param+0(6) = '/*SM34'. FORMAT COLOR COL_KEY INTENSIFIED OFF. ELSE. FORMAT COLOR COL_NORMAL INTENSIFIED OFF. ENDIF. WRITE:/1 sy-vline, 2 rec_tstct-tcode HOTSPOT ON, 21 sy-vline , 22 rec_tstct-ttext, 95 sy-vline. ENDLOOP. WRITE:/(95) sy-uline. DESCRIBE TABLE tab_tstct. SKIP. FORMAT COLOR COL_TOTAL INTENSIFIED ON. WRITE:/ 'T-code founded:' , sy-tfill.

ENDIF. ENDIF. ENDFORM.

" FRM_OUTPUT_TCODE

2.2.14

Dynamic refurbish report

REPORT zauto_refresh . DATA: g_init_once, ok_code(20), g_ref_from_timer.

TYPES: BEGIN OF t_ekko, ebeln TYPE ekpo-ebeln, ebelp TYPE ekpo-ebelp,


2008-09 Page 31 of 328

statu TYPE ekpo-statu, aedat TYPE ekpo-aedat, matnr TYPE ekpo-matnr, menge TYPE ekpo-menge, meins TYPE ekpo-meins, netpr TYPE ekpo-netpr, peinh TYPE ekpo-peinh, END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0, wa_ekko TYPE t_ekko. IF g_init_once <> 'X'. g_init_once = 'X'. CALL FUNCTION 'Z_ENQUE_SLEEP' STARTING NEW TASK 'WAIT' PERFORMING when_finished ON END OF TASK. ENDIF.

WRITE:/ 'wait for 10 sec....'. AT USER-COMMAND. CASE ok_code. WHEN 'FCT_R'. SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh UP TO 10 ROWS FROM ekpo INTO TABLE it_ekko. WRITE:/ sy-uzeit. "Time LOOP AT it_ekko INTO wa_ekko. WRITE:/ wa_ekko-ebeln, wa_ekko-ebelp.
2008-09 Page 32 of 328

ENDLOOP. sy-lsind = 0. IF g_ref_from_timer = 'X'. CALL FUNCTION 'Z_ENQUE_SLEEP' STARTING NEW TASK 'INFO' PERFORMING when_finished ON END OF TASK. g_ref_from_timer = ''. ENDIF. ENDCASE. *---------------------------------------------------------------------* * FORM WHEN_FINISHED *

*---------------------------------------------------------------------* * --> TASKNAME *

*---------------------------------------------------------------------* FORM when_finished USING taskname. RECEIVE RESULTS FROM FUNCTION 'Z_ENQUE_SLEEP'. g_ref_from_timer = 'X'.

* Trigger an event to run the at user-command SET USER-COMMAND 'FCT_R'. ok_code = 'FCT_R'. sy-ucomm = 'FCT_R'. ENDFORM. " WHEN_FINISHED

FUNCTION Z_ENQUE_SLEEP. *"---------------------------------------------------------------------*"Local interface: *"---------------------------------------------------------------------wait up to 10 seconds. *CALL FUNCTION 'ENQUE_SLEEP'


2008-09 Page 33 of 328

* *

EXPORTING SECONDS = 1.

ENDFUNCTION.

2.2.15

SMW0 --Web Repository

Tcode SMW0 ,upload Excel or Word template to SAP server Use Function download the template CALL FUNCTION 'DOWNLOAD_WEB_OBJECT' EXPORTING KEY = OBJDATA DESTINATION = L_DESTINATION.

2.2.16
2.2.16.1.1

ALV Group
What is ALV

2.2.16.1 Standard ALV


The ALV Grid Control (ALV = SAP List Viewer),, ,. SAP : SAP ,ALV GRID ,, ,. ALV GRID :

3 ,,,.. ALV 3 ALV :, ALV, ALV. 2.2.16.1.2 ALV GRID CONTROL (ALV )

ALV GRID CONTROL ,ALV GRID CONTROL ,. ABAP , ALV (INSTANCE), ABAP .

2008-09

Page 34 of 328

2.2.16.1.3

ALV GRID CONTROL

ALV GRID , CL_GUI_ALV_GRID data ALV_GRID1 type ref to cl_gui_alv_grid. ALV GRID :

2.2.16.1.4 2.2.16.1.4.1

ALV GRID [Field catalog]

ALV ,,,,,. : (, STRUCTURE LVC_S_FCAT)


2ROW_POS 3COL_POS 4FIELDNAME 5TABNAME 6CURRENCY 7CFIELDNAME 8QUANTITY 9QFIELDNAME 10IFIELDNAME 11ROUND 12EXPONENT 13KEY 14KEY_SEL 15ICON 16SYMBOL 17CHECKBOX 18JUST 19LZERO 20NO_SIGN 21NO_ZERO 22NO_CONVEXT 23EDIT_MASK 24EMPHASIZE 25FIX_COLUMN ALV : () ALV : ALV : LVC ALV : ALV : ALV : ALV : ALV : ALV : ROUND ALV ALV : ALV : ALV : ALV : ALV : ALV : ALV : ALV ALV : ALV : ALV : ALV : ALV :
2008-09 Page 35 of 328

,, 1,2,.. 1

, : 'R': right justified 'L': left justified 'C': centered X' X', X', 0

26DO_SUM 27NO_SUM 28NO_OUT 29TECH 30OUTPUTLEN 31CONVEXIT 32SELTEXT 33TOOLTIP 34ROLLNAME 35DATATYPE 36INTTYPE 37INTLEN 38LOWERCASE 39REPTEXT 40HIER_LEVEL 41REPREP 42DOMNAME 43SP_GROUP 44HOTSPOT 45DFIELDNAME 46COL_ID 47F4AVAILABL 48AUTO_VALUE 49CHECKTABLE 50VALEXI 51WEB_FIELD 52HREF_HNDL 53STYLE 54STYLE2 55STYLE3 56STYLE4 57DRDN_HNDL 58DRDN_FIELD 59NO_MERGING 60H_FTYPE 61COL_OPT 62NO_INIT_CH 63DRDN_ALIAS 64REF_FIELD 65REF_TABLE 66TXT_FIELD 67ROUNDFIELD 68DECIMALS_O

ALV : ALV : ALV : ALV : ALV : ALV : ALV : ALV : F1 ABAP ABAP (C,D,N,...) / ALV : ALV : / ALV : ALV : ALV : ID ALV : ALV : ALV : ALV : ALV : ALV : ALV : 1 ALV : (,,. , ...) 1 1 ALV : ALV : ALV : ALV : ROUND ALV :
2008-09

X', X' , X' , X'.

ABAP ABAP (C,D,N,...) X'

X',,

X'.

, PUSHBUTTION

Page 36 of 328

69DECMLFIELD 70DD_OUTLEN 71DECIMALS 72COLTEXT 73SCRTEXT_L 74SCRTEXT_M 75SCRTEXT_S 76COLDDICTXT 77SELDDICTXT 78TIPDDICTXT 79EDIT 80TECH_COL 81TECH_FORM 82TECH_COMP 83HIER_CPOS 84H_COL_KEY 85H_SELECT 86DD_ROLL 87DRAGDROPID 88MAC 89INDX_FIELD 90INDX_CFIEL 91INDX_QFIEL 92INDX_IFIEL 93INDX_ROUND 94INDX_DECML 95GET_STYLE 96MARK

ALV : DECIMALS ALV : ALV : ALV : DDIC ALV : DDIC ALV : DDIC ALV : ALV : ALV : ALV : ALV : : / () ALV : & 1 1 1 .'X'

2.2.16.1.4.2

[ layout ]

ALV ALV ,,,. ALV [LVC_S_LAYO],.


CWIDTH_OPT SMALLTITLE GRID_TITLE NO_HEADERS NO_HGRIDLN NO_MERGING NO_ROWMARK NO_TOOLBAR NO_VGRIDLN , , , , D A
2008-09

Value range SPACE, 'X' SPACE, 'X' 70 SPACE, 'X' SPACE, 'X' SPACE, 'X' SPACE, 'X' SPACE, 'X' SPACE, 'X'
Page 37 of 328

SEL_MODE EXCP_CONDS EXCP_FNAME EXCP_LED EXCP_ROLLN CTAB_FNAME INFO_FNAME ZEBRA NO_TOTLINE NUMC_TOTAL TOTALS_BEF STYLEFNAME

LED , NUMC , , PUSHBUTTON

SPACE, 'A', 'B', 'C', 'D' SPACE, 'X' 30 SPACE, 'X' SPACE, 'X' 30 30 SPACE, 'X' SPACE, 'X' SPACE, 'X' SPACE, 'X' 30

2.2.16.1.4.3

[ Print, Sort, Filter ]

[LVC_S_PRNT] [LVC_S_SORT] [LVC_S_FILT]

2.2.16.2 Special ALV


2.2.16.2.1
: :

get_frontend_fieldcatalog set_frontend_fieldcatalog get_frontend_layout set_frontend_layout

,,..

,,,. DATA ls_fcat TYPE lvc_s_fcat . DATA lt_fcat TYPE lvc_t_fcat . DATA ls_layout TYPE lvc_s_layo . CALL METHOD gr_alvgrid->get_frontend_fieldcatalog IMPORTING et_fieldcatalog = lt_fcat[] . LOOP AT lt_fcat INTO ls_fcat . IF ls_fcat-fieldname = 'PAYMENTSUM' . ls_fcat-no_out = space . MODIFY lt_fcat FROM ls_fcat . ENDIF . ENDLOOP . CALL METHOD gr_alvgrid->set_frontend_fieldcatalog EXPORTING it_fieldcatalog = lt_fcat[] . CALL METHOD gr_alvgrid->get_frontend_layout IMPORTING es_layout = ls_layout . ls_layout-grid_title = 'Flights (with Payment Sums)' . CALL METHOD gr_alvgrid->set_frontend_layout EXPORTING is_layout = ls_layout .

2008-09

Page 38 of 328

2.2.16.2.2

. LVC_T_SORT . set_table_for_first_display IT_SORT . FORM prepare_sort_table CHANGING pt_sort TYPE lvc_t_sort . DATA ls_sort TYPE lvc_s_sort . ls_sort-spos = '1' . ls_sort-fieldname = 'CARRID' . ls_sort-up = 'X' . "A to Z ls_sort-down = space . APPEND ls_sort TO pt_sort . ls_sort-spos = '2' . ls_sort-fieldname = 'SEATSOCC' . ls_sort-up = space . ls_sort-down = 'X' . "Z to A APPEND ls_sort TO pt_sort . ENDFORM. " prepare_sort_table 2 : 1. DUMP. 2.,,,"no_merging""X" . get_sort_criteria set_sort_criteria.

2.2.16.2.3

()

ALV ,."LVC_T_FILT" . RANGES ."SET_TABLE_FOR_FIRST_DISPLAY" "IT_FILTER" FORM prepare_filter_table CHANGING pt_filt TYPE lvc_t_filt . DATA ls_filt TYPE lvc_s_filt . ls_filt-fieldname = 'FLDATE' . ls_filt-sign = 'E' . ls_filt-option = 'BT' . ls_filt-low = '20030101' . ls_filt-high = '20031231' . APPEND ls_filt TO pt_filt . ENDFORM. " preparefiltertable "get_filter_criteria" "set_filter_criteria".

2.2.16.2.4

,,"SEL_MODE".. . SPACE 'A' 'B' 'C' 'D' : 1. ALV ,. 2.,. "GET_SELECTED_CELLS","GET_SELECTED_CELLS_ID","GET_SELECTED_ROWS","GET_SELECTED_COLUMNS" B , ,, ,, , B ,

2008-09

Page 39 of 328

3. PAI ,,. PBO , SET . 2.2.16.2.5


, ALV .,. ,,. ALV .,4 CHAR . Cx y z--Color | | | | 1/0: / 1/0: / C ,(1 7),,,,, . : x 1Gray-blue 2Light gray 3yellow 4Blue-green 5green 6red 7orange headers List bodies totals Key columns Positive threshold value Negative threshold value Control levels

A.
"emphasize". 4 CHAR ,.: LS_FCAT-EMPHASIZE = 'C701'. , . LS_FCAT-KEY = 'X' ,.,KEY

B.
,,,., 4 CHAR ,. : DATA BEGIN OF gt_list OCCURS 0 . INCLUDE STRUCTURE SFLIGHT . DATA rowcolor(4) TYPE c . DATA END OF gt_list . ,ALV ,"INFO_FNAME", ALV,. ps_layout-info_fname = 'ROWCOLOR'. ,,,., ,,

C.
,, 2 . DEEP , ALV .. "LVC_T_SCOL". 3 :

2008-09

Page 40 of 328

FNAME , COLOR ,. ,. COLOR . NOKEYCOL .,.,. ,ALV "CTAB_FNAME",. DATA BEGIN OF gt_list OCCURS 0 . INCLUDE STRUCTURE SFLIGHT . DATA rowcolor(4) TYPE c . DATA cellcolors TYPE lvc_t_scol . DATA END OF gt_list . DATA ls_cellcolor TYPE lvc_s_scol . ... READ TABLE gt_list INDEX 5 . ls_cellcolor-fname = 'SEATSOCC' . ls_cellcolor-color-col = '7' . ls_cellcolor-color-int = '1' . APPEND ls_cellcolor TO gt_list-cellcolors . MODIFY gt_list INDEX 5 . : ,--->--->.

2.2.16.2.6

."LVC_T_HYPE" , INT4 , ALV,,.,WEB_FIELD . , CARRID,CONNID : , 2 : DATA BEGIN OF gt_list OCCURS 0 . INCLUDE STRUCTURE SFLIGHT . DATA rowcolor(4) TYPE c . DATA cellcolors TYPE lvc_t_scol . DATA carrid_handle TYPE int4 . DATA connid_handle TYPE int4 . DATA END OF gt_list . : ,.,,"LVC_T_HYPE". FORM prepare_hyperlinks_table CHANGING pt_hype TYPE lvc_t_hype . DATA ls_hype TYPE lvc_s_hype . ls_hype-handle = '1' . ls_hype-href = 'http://www.company.com/carrids/car1' . APPEND ls_hype TO pt_hype . ls_hype-handle = '2' . ls_hype-href = 'http://www.company.com/carrids/car1' . APPEND ls_hype TO pt_hype . ls_hype-handle = '3' . ls_hype-href = 'http://www.company.com/carrids/car1' . APPEND ls_hype TO pt_hype . ls_hype-handle = '4' . ls_hype-href = 'http://www.company.com/connids/con11' . APPEND ls_hype TO pt_hype . ls_hype-handle = '5' . ls_hype-href = 'http://www.company.com/connids/con12' APPEND ls_hype TO pt_hype .

2008-09

Page 41 of 328

.. .. ENDFORM . . FIELDCATLOG . CARRID field catalog Ls_fieldcat-web_field = CARRID_HANDLE. CONNID field catalog Ls_fieldcat-web_field = CONNID_HANDLE. "SET_TABLE_FOR_FIRST_DISPLAY" it_hyperlink :: LOOP AT gt_list. IF gt_list-carrid = XX. Gt_list-carrid_handle = 1. IF gt_list-connid = 01. Gt_list-connid_handle = 4. ENDIF. ENDIF. ENDLOOP.

2.2.16.2.7

,,, . ,,,"LVC_T_DROP". ALV ."SET_TABLE_FOR_FIRST_DISPLAY", "SET_DROP_DOWN_TABLE". ,"DRDN_HNDL".: ps_fcat-drdn_hndl = '1' . (, ),"DRDN_FIELD".: ps_fcat-drdn_field = 'PTYP_DD_HNDL' . : DATA BEGIN OF gt_list OCCURS 0 . INCLUDE STRUCTURE SFLIGHT . DATA rowcolor(4) TYPE c . DATA cellcolors TYPE lvc_t_scol . DATA carrid_handle TYPE int4 . DATA connid_handle TYPE int4 . DATA ptype_dd_hndl TYPE int4 . DATA END OF gt_list . : FORM prepare_drilldown_values. DATA lt_ddval TYPE lvc_t_drop . DATA ls_ddval TYPE lvc_s_drop . ls_ddval-handle = '1' . ls_ddval-value = 'JFK-12' . APPEND ls_ddval TO lt_ddval . ls_ddval-handle = '1' . ls_ddval-value = 'JSF-44' . APPEND ls_ddval TO lt_ddval . ls_ddval-handle = '1' . ls_ddval-value = 'KMDA-53' .

2008-09

Page 42 of 328

APPEND ls_ddval TO lt_ddval . ls_ddval-handle = '1' . ls_ddval-value = 'SS3O/N' . APPEND ls_ddval TO lt_ddval . CALL METHOD gr_alvgrid->set_drop_down_table EXPORTING it_drop_down = lt_ddval . ENDFORM. " prepare_drilldown_values , set_drop_down_table ALV.

2.2.16.2.8

,ALV GRID .. ALV GRID . ALV GRID , HTML HTML SAP GUI . : Event Print_end_of_list Print_top_of_list Print_top_of_page Print_end_of_page Subtotal_text ALV GRID Event Button_click Double_click Hotspot_click Application Query click on a push button in the ALV GRID control Query a double click on a cell of the ALV GRID Query a hotspot click on columns defined for this purpose in advance Collect information when elements of the ALV GRID Control are dragged Process information when elements of the ALV GRID Control are dropped Perform final actions after successful drag&drop Distinguish between options for drag&drop behavior HTML Application Define output text to be printed at the end of the entire list Define output text to be printed at begin of the entire list Define output text to be printed at begin of each page Define output text to be printed at the end of each page Define self-defined subtotal texts HTML

Ondrag

Ondrop

ondropComplete ondropGetFlavor

Event Before_user_command User_command Application Query self-defined and standard functions Query self-defined function HTML
2008-09 Page 43 of 328

codes After_user_command Query self-defined and standard functions codes

(,) Event Tool bar Menu_button Context_menu_request Onf1 Application Change,delete or add gui elements on alv grid Define menus for menu buttons in the toolbar Change context menu Define self-defined f1 help HTML

,. CLAS lcl_event_handler DEFINITION. PUBLIC SECTION. METHODS: *-- ALV Handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object e_interactive, *-- Handle_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm. *-- Handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid IMPORTING e_row_id e_column_id es_row_no. *-- Handle_before_user_command FOR EVENT before_user_command OF cl_gui_alv_grid IMPORTING e_ucomm. *-- Handle_after_user_command FOR EVENT after_user_command OF cl_gui_alv_grid IMPORTING e_ucomm. *-- ALV , Handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed. *-- Handle_data_changed_finished FOR EVENT data_changed_finished OF cl_gui_alv_grid IMPORTING e_modified. *-- Handle_menu_button FOR EVENT menu_button OF cl_gui_alv_grid IMPORTING e_object e_ucomm. *--

2008-09

Page 44 of 328

Handle_button_click FOR EVENT button_click OF cl_gui_alv_grid IMPORTING e_objec e_ucomm. PRIVATE SECTION. ENDCLASS. , ALV : CLASS lcl_event_handler IMPLEMENTATION. *-- Handle toolbar METHOD handle_toolbar. PERFORM handle_toolbar USIGN e_object e_interactive. ENDMETHOD. *-- Handle hotspot click METHOD handle_hotspot_click. PERFORM handle_hotspot_click USING e_row_id e_column_id es_row_no. ENDMETHOD. *-- Handle double click METHOD handle_double_click. PERFORM handle_double_click USING e_row e_column es_row_no. ENDMETHOD. *-- Handle after user command METHOD handle _after_user_command. PERFORM handle_after_user_command USING e_object. ENDFORM. *-- Handle before user command METHOD handle_before_user_command. PERFORM handle_before_user_command. ENDMETHOD. *--Handle data changed METHOD handle_data_changed. PERFORM handle_data_changed USING er_data_changed. ENDMEHTOD. METHOD handle_data_changed_finished. PERFORM handle_data_chaged USING e_modified. ENDMETHOD. METHOD handle_menu_button. PERFORM handle_menu_button USING e_object e_ucomm. ENDMEHTOD. MEHTOD handle_button_click. PERFORM handle_button_click USING e_objcet e_ucomm. ENDMETHOD. ENDCALSS. , ALV GRID . DATA gr_event_handler TYPE REF TO lcl_event_handler . .. .. *--Creating an instance for the event handler CREATE OBJECT gr_event_handler . *--Registering handler methods to handle ALV Grid events SET HANDLER gr_event_handler->handle_user_command FOR gr_alvgrid . SET HANDLER gr_event_handler->handle_toolbar FOR gr_alvgrid . SET HANDLER gr_event_handler->handle_menu_button FOR gr_alvgrid .

2008-09

Page 45 of 328

SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid . SET HANDLER gr_event_handler->handle_hotspot_click FOR gr_alvgrid . SET HANDLER gr_event_handler->handle_button_click FOR gr_alvgrid . SET HANDLER gr_event_handler->handle_before_user_command FOR gr_alvgrid . SET HANDLER gr_event_handler->handle_context_menu_request FOR gr_alvgrid . SET HANDLER gr_event_handler->handle_data_changed FOR gr_alvgrid . SET HANDLER gr_event_handler->handle_data_changed_finished FOR gr_alvgrid .

2.2.16.2.8.1

HotPost

,,"HOTSPOT""X", HOTSPOT_CLICK. HOTSPOT_CLICK ,"E_ROW_ID", 2 : LVC_S_COL "E_COLUMN_ID", E_COLUMN_ID-FIELDNAME . LVC_S_ROID "ES_ROW_NO", ES_ROW_NO-ROW_ID ,. : FORM handle_hotspot_click USING i_row_id TYPE lvc_s_row I_column_id TYPE lvc_s_col Is_row_no TYPE lvc_s_roid. READ TABLE gt_list INDEX is_row_no-rowid. IF sy-subrc = 0 AND i_column_id-fieldname = SEATSOCC. CALL SCREEN 200. ENDIF. ENDFORM. SEATSOCC, 200. 2.2.16.2.8.2 Double click

, 3 ..
:

FORM handle_double_click USING i_row TYPE lvc_s_row I_column TYPE lvc_s_col Is_row_no TYPE lvc_s_rowid. READ TABLE gt_list INDEX is_row_no-row_id. IF sy-subrc = 0 AND i_column-fieldname = SEATSOCC. CALL SCREEN 200. ENDIF. ENDFORM. SEATSOCC 200. 2.2.16.2.8.3 User-defined button and command

ALV , GUI ,2 . toolbar , user_command . TOOLBAR ,"e_object""mt_toolbar".:

FORM handle_toolbar USING i_object TYPE REF TO cl_alv_event_toolbar_set. 2008-09

Page 46 of 328

DATA: ls_toolbar TYPE stb_button. CLEAR ls_toolbar. MOVE 3 TO ls_toolbar-butn_type. APPEND ls_toolbar TO i_object->mt_toolbar. CLEAR ls_toolbar. MOVE 'PER' TO ls_toolbar-function. MOVE icon_display_text TO ls_toolbar-icon. MOVE 'Passenger Info'(201) TO ls_toolbar-quickinfo. MOVE 'Passenger Info'(201) TO ls_toolbar-text. MOVE ' ' TO ls_toolbar-disabled. APPEND ls_toolbar TO i_object->mt_toolbar. CLEAR ls_toolbar. MOVE 'EXCH' TO ls_toolbar-function. MOVE 2 TO ls_toolbar-butn_type. MOVE icon_calculation TO ls_toolbar-icon. MOVE 'Payment in other Curencies'(202) TO ls_toolbar-quickinfo. MOVE ' ' TO ls_toolbar-text. MOVE ' ' TO ls_toolbar-disapbled. APPEND ls_toolbar TO i_object->mt_toolbar. ENDFORM. :
Field FUNCTION BUTN_TYPE Description : Button(normal) Menu and default button Menu Radio button Checkbox Menu entry ICON TEXT QUICKINFO DISABLED () () ()

. 1 2, , menu_button :

FORM handle_menu_button USING i_object TYPE REF TO cl_ctmenu I_ucomm TYPE syucomm.. CASE i_ucomm. WHEN EXCH. CALL METHOD i_object->add_function EXPORTING Fcode = EU

2008-09

Page 47 of 328

Text = Euro. CALL METHOD i_object->add_function EXPORTING Fcode = TRL Text = Turkish Lira. ENDCASE. ENDFORM. , USER_COMMAND . FORM handle_user_command USING i_ucomm TYPE sy-ucomm. DATA lt_selected_rows TYPE lvc_t_rowid. DATA ls_selected_row TYPE lvc_s_roid. CALL METHOD gr_alvgrid->get_selected_rows IMPORTING Et_row_no = lt_selected_rows. READ TABLE lt_selected_rows INTO ls_selected_row INDEX 1. If sy-subrc ne 0. MESSAGE S000(su) WITH 'Select a row'(203). ENDIF. CASE i_ucomm. WHEN 'CAR'. READ TABLE gt_list INDEX ls_selected_row-row_id. IF sy-subrc = 0. CALL FUNCTION 'ZDISPLAY_CARRIER_INFO' EXPORTING carrid = gt_list-carrid EXCEPTIONS carrier_not_found = 1 Oters = 2. ENDIF. WHEN 'EU'. READ TABLE gt_list INDEX ls_selected_row-row_id. IF sy-subrc = 0. CALL FUNCTION 'ZPOPUP_CONV_CURR_ADD_DISPLAY' EXPORTING monun = 'EU' Quant = gt_list-paymentsum. ENDIF. ENDCASE. ENDFORM.
get_selected_rows . EXCH 2 ,. ALV , ALV set_toolbar_interactive .

2.2.16.2.8.4

Change standard ALV function

ALV .,"before_user_command", "set_user_command",. :

FORM handle_before_user_command USING i_ucomm TYPE syucomm . CASE e_ucomm . WHEN '&INFO' .

2008-09

Page 48 of 328

CALL FUNCTION 'ZSFLIGHT_PROG_INFO' . CALL METHOD gr_alvgrid->set_user_command EXPORTING i_ucomm = space. ENDCASE . ENDFORM . 2.2.16.2.8.5
(style , style CL_GUI_ALV_GRID , MC_STYLE4_LINK,MC_STYLE4_LINK_NO,MC_STYLE_BUTTON,MC_STYLE_DISABLED,....),/, F4,,,......

2.2.16.2.8.5.1

PUSHBUTTON

,"LVC_T_STYL". : DATA: BEGIN OF gt_list OCCURS 0. INCLUDE STRUCTURE sflight. DATA rowcolor(4) TYPE c. DATA cellcolors TYPE lvc_t_scol. DATA carrid_handle TYPE int4. DATA connid_handle TYPE int4. DATA cellstyles TYPE lvc_t_styl. DATA END OF gt_list. : 7 SEATSMAX . DATA ls_style TYPE lvc_s_styl. READ TABLE gt_list INDEX 7. Ls_style-fieldname = 'SEATSMAX'. Ls_style-style = cl_gui_alv_grid=>mc_style_button. APPEND ls_style TO gt_list-cellstyles. MODIFY gt_list INDEX 7. STYLE ,: gs_layout-stylefname = 'CELLSTYLES'.
, 2 .

2.2.16.2.8.5.2

, SAP . ,, A,, B,. , EDIT "X".,ALV ,, ,.,. 5.1 ,,"LVC_T_STYL". style CL_GUI_ALV_GRID=>MC_STYLE_ENABLED CL_GUI_ALV_GRID=>MC_STYLE_DISABLED. .CL_GUI_ALV_GRID=>MC_STYLE_ENABLED , CL_GUI_ALV_GRID=>MC_STYLE_DISABLED .: FORM adjust_edittables USING pt_list LIKE gt_list[]. DATA ls_listrow LIKE LINE OF pt_list.

2008-09

Page 49 of 328

DATA ls_stylerow TYPE lvc_s_styl. DATA lt_styletab TYPE lvc_t_styl. LOOP AT pt_list INTO ls_listrow. IF ls_listrow-carrid = 'XY'. Ls_stylerow-fieldname = 'SEATSMAX'. Ls_stylerow-style = cl_alv_grid=>mc_style_disabled. APPEND ls_stylerow TO lt_styletab. ENDIF. IF ls_listrow-connid = '02'. Ls_stylerow-fieldname = 'PLANETYPE' Ls_stylerow-style = cl_alv_grid=>mc_style_enabled. APPEND ls_Pstylerow TO lt_styletab. ENDIF. INSERT LINES OF lt_styletab INTO ls_listrow-cellstyles. MODIFY pt_list FROM ls_listrow. ENDLOOP. ENDFORM. ALV STYLE . gs_layout-stylefname = 'CELLSTYLES'. , STYLE . set_ready_for_input i_ready_for_input = 1 ALV ALV i_ready_for_input 0 2.2.16.2.8.6
alv ALV Alv grid :data_changed data_changed_finished. REGISTER_EDIT_EVENT ,.2 : 1.: i_event_id = cl_gui_alv_grid=>mc_event_enter 2.: i_event_id = cl_gui_alv_grid=>mc_event_modifies ,. ALV ,DATA_CHANGED CL_ALV_CHANGED_DATA_PROTOCOL ER_DATA_CHANGED ALV.. CL_ALV_CHANGED_DATA_PROTOCOL : Get_cell_value Modify_cell Add_protocol_entry Protocol_is_visible Refresh_protocol : MT_MOD_CELLS Contains address of modified cells with rowed and
2008-09 Page 50 of 328

field name MT_MOD_ROWS MT_GOOD_CELLS MT_DELETED_ROWS MT_INSERTED_ROWS Contain modified rows Its type is genric Contain cells have proper values Contain rows deleted from the list Contain rows deleted from the list

,.

: FORM handle_data_changed USING ir_data_changed TYPE REF TO cl_alv_changed_data_protocol. DATA: ls_mod_cell TYPE lvc_s_modi, Lv_value TYPE lvc_value. SORT ir_data_changed->mt_mod_cells BY row_id. LOOP AT ir_data_changed->mt_mod_cells INTO ls_mod_cell WHERE fieldname = 'SEATSMAX'. CALL METHOD ir_data_changed->get_cell_value EXPORTING i_row_id = ls_mod_cell-row_id I_fieldname = 'CARRID' IMPORTING e_value = lv_value. IF lv_value = 'THY' AND ls_mod_cell-value > '500'. CALL METHOD ir_data_changed->add_protocol_entry EXPORTING I_msgid = 'SU' I_msgno = '000' I_msgty = 'E' I_msgv1 = 'This number can not exceed 500 for ' I_msgv2 = lv_value I_msgv3 = 'The value is et to ''500''' I_fieldname = ls_mod_cell-fieldname I_row_id = ls_mod_cell-rowid. CALL METHOD ir_data_changed->modify_cell EXPORTING i_row_id = ls_mod_cell-row_id I_fieldname = ls_mod_cell-fieldname I_value = '500'. ENDIF. ENDLOOP. ENDFORM.

2.2.16.2.9 2.2.16.2.9.1

Special Sample programs Show user-defined Logo On ALV

(ALV) Upload Logo for REUSE_ALV_COMMENTARY_WRITE For those who wish to upload and use a picture in your ALV ABAP reports. Steps for uploading Logo :-: . Goto the transaction OAER . Enter the class name as 'PICTURES' . Enter the class type as 'OT'

2008-09

Page 51 of 328

. Enter the object key as the name of the logo you wish to give . Execute . Then in the new screen select Standard doc. types in bottom window. Click on the Screen icon. Now, it will ask for the file path where you have to upload the logo . Now you can use this logo in REUSE_ALV_COMMENTARY_WRITE

2008-09

Page 52 of 328

2.2.16.2.9.2

2.2.16.2.9.3

.doc

2.2.16.2.9.4

.doc

2.2.16.2.9.5

.doc

2.2.16.2.9.6

.do c

2008-09

Page 53 of 328

2.2.16.2.9.7

ALV

ALV.doc

2.2.16.2.9.8

ALV .doc

2.2.16.2.9.9

ALV .doc

2.2.16.2.9.10

.doc

2.2.16.3 How To Write ALV


2.2.16.3.1 SCREEN, (CONTAINER),.
DATA:WCL_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER, WCL_ALV TYPE REF TO CL_GUI_ALV_GRID . DATA gt_fieldcat TYPE lvc_t_fcat . *--- DATA gs_layout TYPE lvc_s_layo . *--- DATA BEGIN OF gt_list OCCURS 0 . *----( SFLIGHT ) INCLUDE STRUCTURE SFLIGHT . DATA END OF gt_list .

2.2.16.3.2

ALV

PBO : PROCESS BEFORE OUTPUT . MODULE display_alv . DISPLAY_ALV MODULE ,: MODULE display_alv OUTPUT . PERFORM display_alv . ENDMODULE . FORM DISPLAY_ALV , ALV ,,: IF WCL_ALV IS INITIAL . CREATE OBJECT: WCL_CONTAINER EXPORTING CONTAINER_NAME = 'ALV_CON'. CREATE OBJECT WCL_ALV EXPORTING I_PARENT = WCL_CONTAINER. *----- PERFORM prepare_field_catalog CHANGING gt_fieldcat . *----- PERFORM prepare_layout CHANGING gs_layout .

2008-09

Page 54 of 328

*----- ALV CALL METHOD gr_alvgrid->set_table_for_first_display EXPORTING * I_BUFFER_ACTIVE = * I_CONSISTENCY_CHECK = * I_STRUCTURE_NAME = * IS_VARIANT = * I_SAVE = * I_DEFAULT = 'X' is_layout = gs_layout * IS_PRINT = * IT_SPECIAL_GROUPS = * IT_TOOLBAR_EXCLUDING = * IT_HYPERLINK = CHANGING it_outtab = gt_list[] it_fieldcatalog = gt_fieldcat * IT_SORT = * IT_FILTER = EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4 . ELSE . *---- ALV CALL METHOD gr_alvgrid->refresh_table_display * EXPORTING * IS_STABLE = * I_SOFT_REFRESH = EXCEPTIONS finished = 1 OTHERS = 2 . IF sy-subrc <> 0. *-- ENDIF. ENDIF . "set_table_for_first_display" I_BUFFER_ACTIVE ,,, ALV ., ALV ,'SFLIGHT'., , IT_FIELDCATALOG . : 'X' 'U' 'A' SPACE : 'X' , SPACE ,
2008-09 Page 55 of 328

I_STRUCTURE_NAME IS_VARIANT

I_SAVE

I_DEFAULT IS_LAYOUT IS_PRINT

IT_SPECIAL_GROUPS IT_TOOLBAR_EXCLUDING IT_HYPERLINK IT_ALV_GRAPHICS IT_OUTTAB IT_FIELDCATALOG IT_SORT IT_FILTER

SP_GROUP . ,LVC_S_HYPE HREF , HANDLE , GRID , ALV. ,

"REFRESH_TABLE_DISPLAY" IS_STABLE 2 ., ,. ,,, ,. .: ALV, .

I_SOFT_REFRESH

2.2.16.3.3

Two way: 1. FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat . DATA ls_fcat type lvc_s_fcat . ls_fcat-fieldname = 'CARRID' . ls_fcat-inttype = 'C' . ls_fcat-outputlen = '3' . ls_fcat-coltext = 'Carrier ID' . ls_fcat-seltext = 'Carrier ID' . APPEND ls_fcat to pt_fieldcat . CLEAR ls_fcat . ls_fcat-fieldname = 'CONNID' . ls_fcat-ref_table = 'SFLIGHT' . ls_fcat-ref_table = 'CONNID' . ls_fcat-outputlen = '3' . ls_fcat-coltext = 'Connection ID' . ls_fcat-seltext = 'Connection ID' . APPEND ls_fcat to pt_fieldcat . ENDFORM . 2. FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat . DATA ls_fcat type lvc_s_fcat . CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING i_structure_name = 'SFLIGHT' CHANGING ct_fieldcat = pt_fieldcat[] EXCEPTIONS inconsistent_interface = 1 program_error = 2 2008-09

Page 56 of 328

OTHERS = 3. IF sy-subrc <> 0. *--Exception handling ENDIF. LOOP AT pt_fieldcat INTO ls_fcat . CASE pt_fieldcat-fieldname . WHEN 'CARRID' . ls_fcat-outpulen = '10' . ls_fcat-coltext = 'Airline Carrier ID' . MODIFY pt_fieldcat FROM ls_fcat . WHEN 'PAYMENTSUM' . ls_fcat-no_out = 'X' . MODIFY pt_fieldcat FROM ls_fcat . ENDCASE . ENDLOOP . ENDFORM 2.2.16.3.4

FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo. ps_layout-zebra = 'X' . ps_layout-grid_title = 'Flights' . ps_layout-smalltitle = 'X' . ENDFORM. " prepare_layout 2.2.16.3.5

(,,)
ALV , UI_FUNCTIONS , set_table_for_first_display "IT_TOOLBAR_EXCLUDING". cl_gui_alv_grid , after_user_command . , layout no_toolbar "X". FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions . DATA ls_exclude TYPE ui_func. ls_exclude = cl_gui_alv_grid=>mc_fc_maximum . APPEND ls_exclude TO pt_exclude. ls_exclude = cl_gui_alv_grid=>mc_fc_minimum . APPEND ls_exclude TO pt_exclude. ls_exclude = cl_gui_alv_grid=>mc_fc_subtot . APPEND ls_exclude TO pt_exclude. ls_exclude = cl_gui_alv_grid=>mc_fc_sum . APPEND ls_exclude TO pt_exclude. ls_exclude = cl_gui_alv_grid=>mc_fc_average . APPEND ls_exclude TO pt_exclude. ls_exclude = cl_gui_alv_grid=>mc_mb_sum . APPEND ls_exclude TO pt_exclude. ls_exclude = cl_gui_alv_grid=>mc_mb_subtot . ENDFORM . , ALV DEMO ..

2.2.17
2.2.17.1.1

SAP Script
SAPscript

2.2.17.1 SAPscript Forms


SAPscript 1) 2)styles forms layout

2008-09

Page 57 of 328

3) style forms 4) SAPscript form 5)stylesforms

2.2.17.1.2 2.2.17.1.2.1

Forms:

SAP Forms SAP Forms SAP Forms Y Z SAP Forms SAP IMG Forms layout Form Form SAP Forms layout Forms item Forms SAPscript (Tools Word processing Standard text) Form Form Main Form Main SAP Form Forms Styles Form Styles

Forms Styles Forms Styles SAP Forms Styles Client 000 SAPscript client000 Forms Styles Forms Styles SAPscript client000 Forms Styles client000 SAP Forms Styles client000 Forms Styles YXXX ZXXX Language rules: SAPscript uses the following rules to manage versions of forms and styles in different languages: The in using whichSAPs a form or style is created is its "original language." You can translate a form or style into otherlanguage languages translation tools. If a language form or style is needed only in its data. original language and need be translated, then you can this in the attributes in the header The form or style then not does not appear in work lists in indicate the translation tools. In versions other than the original changes to a form or style are limited only to translation of texts. No changes to definitions andlanguage attributesversion, are permitted.
2008-09 Page 58 of 328

2.2.17.1.2.2
2.2.17.1.2.2.1

Header Data

Header Data page page Header Data Basic settings Header Data form Header Data

SAPscript Form form start page subsequent pages start page subsequent page subsequent SAPscript form main window.

2008-09

Page 59 of 328

2.2.17.1.2.2.2 Tabs Outline

Paragraph Formats and Attributes

SAPscript Paragraph()

Description

2008-09

Page 60 of 328

1 (Description) (Left margin, Right margin) (indent 1st line) (Space before, Space after) (Alignment) (Line spacing) (No blank lines) (Page protection) (Next paragraph same page) 2 Font // 3 Tabs in Paragraph Formats tabs pc editor ,,symbol tabs tabs CH () CM () MM() PT() TW(1/20 ) 4 Outline

2008-09

Page 61 of 328

2.2.17.1.2.2.3

Character Formats and Attributes

Character formats and Attributes Standard Font Standard marker()BarcodeProtectedHiddenSuperscript Font Font
2.2.17.1.2.2.4 Windows

Windows Form Page Window Form window SAPscript window Form Main window Form Window Main Window Form MAIN Main Window SAPscript 1 2 pages 3 page window main window main window

page main window page window subsequent page SAPscript subsequent pages
header line totals main window (output area) page main window Main window TOP Area BOTTOM Area BODY AreaTOP Area BOTTOM Area BODY Area

2008-09

Page 62 of 328

Form SAPscript main windwo Form WRITE_FORM WRITE_FORM_LINES TYPE TYPE BODY

VAR Window
2008-09 Page 63 of 328

page CONST Windowpage window VAR Window Form pages

CONST Window VAR Window Form


CONST window 4.0 CONST Window VAR Window window VAR
Pages

2.2.17.1.2.2.5

Form page Form header first page page page page pages layouts page SAPscript page SE71 page WIN32 Form Painter

2.2.17.1.2.2.6

Pages window

Pages window ,, pages window 2008-09 Page 64 of 328

pages windows page page 1) pages main window pages 2) page main window main window windows pages page window page window page window window window

2.2.17.1.2.2.7

Text Elements

SAPscript form Text Elements() form Text Elements Text Elements Text Elements window main window HEADING FLIGHTIST Text Elements

2008-09

Page 65 of 328

Text Elements ABAP TEXT-001Text Elements ABAP TEXT-001 Text Elements Text Elements Text Elements Text Elements SAPscript window Text Elements Text Elements Text Elements 1 Text Elements /E Text Elements

<NAME> Text Elements 30 Text Elements Text Elements Text Elements

Text Elements LOCAL Text Elements


Text Elements(ABAP) WRITE_FORM Text Elements

2008-09

Page 66 of 328

2 Text Elements Text Elements window contents /E/E /E window Text Elements Text Elements Text Elements WRITE_FORM Text Elements Main window Text Elements main window form subsequent page window main window Text Elements form ADDRESS window Text Elements Text Elements ADRS_SENDER IF AND CASE

3 Text Elements WRITE_FORM FUNCTION Text Elements FUNCTION

2008-09

Page 67 of 328

SET window APPEND Text Elements Text Elements DELETE Text Elements Text Elements

Text Elements page window Text Elements


main window BODY APPEND SET DELETE TOP BOTTOM 2.2.17.1.2.3
2.2.17.1.2.3.1

Form

form form logo 1) form logo logo form PCL-5 TIF6.0 logo logo PCL-5 PCL-5 logo form logo form

logo logo logo TIF6.0 SAP


form logo

2008-09

Page 68 of 328

2.2.17.1.2.3.2

FORM logo

Step-by-Step Guide Task 1 Convert your company logo into a SAPscript standard text.

1. Create your company logo with a graphic program and save it in the Baseline TIFF 6.0 format. In this guide, the filename is LOGO.TIF. 2. From the SAP main menu, choose Tools ABAP Workbench. 3. On the ABAP Workbench screen, choose ABAP Editor.

4. In the Program field, enter RSTXLDMC. 5. Choose Execute.

4 5

2008-09

Page 69 of 328

6. Determine the location of LOGO.TIF. 7. In the File name field, enter the file name with its location. 10 Note: UNIX file names are case sensitive. 8. In the Type field, enter the appropriate type for the raster image. BMON stands for a black and white raster image. Use BMON for monochrome printers because these printers normally do not perform a graylevel conversion. BCOL stands for a color raster image with up to 256 colors. For this example, use BMON. 9. In the Text name field, enter ZHEXMACRO-LOGO. 10. Choose Execute.
The upload may take a while. The result should be a protocol as shown.

7 8

11. At the end of the protocol, a Standard text ZHEX-MACRO-LOGO ID ST Language EN saved successfully message indicates that the standard text was created. 12. Choose Back four times to return to the SAP main menu.

12

11

You can easily display the created standard text. 1. Choose Tools Word processing Standard text. 2. In the Text name field, enter ZHEX-MACRO-LOGO. 3. Choose Display.

2008-09

Page 70 of 328

For additional information about report RSTXLDMC, access the report documentation: 1. 2. 3. 4. 5. Choose Tools ABAP Workbench. Choose ABAP Editor. In the Program field, enter RSTXLDMC. Select Documentation. Choose Display.

Step-by-Step Guide Task 2 Include the standard text ZHEX-MACRO_LOGO in the sales order confirmation form Z_9H_RVORDER01.

1. From the SAP main menu, choose Tools Word processing Form. 2. In the Form field, enter Z_9H_RVORDER01, and in the Language field, enter EN. 3. In the Sub-objects section, select Page layout. 4. Choose Change. The synchronized screens of the Form Painter appear. 3 2

2008-09

Page 71 of 328

5. In the Design window, create a new window by choosing Create window form the form layout manipulation menu. The new window is automatically named Window1. 5

6. Activate Window1 and choose Rename window from the form layout manipulation menu.

7. Rename Window1 as LOGO. 8. Choose Execute. 7 8

2008-09

Page 72 of 328

9. Define the position of the window LOGO using the graphical Form Painter.

With graphics or macros the system considers only the window position but not the size. The Left margin must be specified in CH (characters) and the Upper margin must be specified in LN (line).

10. Activate the LOGO window and choose Edit window text from the form layout manipulation window. The PC Editor for the LOGO window appears.

10

2008-09

Page 73 of 328

11. In the PC Editor choose the Insert command button. The Insert Additional Information screen appears. 11

12. Select Command. 13. Enter INCLUDE ZHEX-MACROLOGO OBJECT TEXT ID ST in the command line. 14. Choose Continue.

12

13

14

2008-09

Page 74 of 328

The new command line (gray highlighted) appears in the PC Editor. 15. Choose Back. The window text is automatically saved by the system. 16. Confirm the information. 15

17. Activate the changed form.

17

Your company logo appears on the first page of form Z_9H_RVORDER01 using the standard text ZHEX-MACRO-LOGO and the window LOGO for the print output. If the company logo should be displayed on the subsequent pages, you must copy the window LOGO to page NEXT. You have to repeat the following procedure for all defined pages: 1. In the administrative screen, choose the window LOGO. 2. Copy the window.

2008-09 Page 75 of 328

3. Choose page NEXT. 4. Insert the window. The position and size of the window LOGO defined for page FIRST apply to the other pages. 5. Activate the form.
PCL-5 logo
2.2.17.1.2.3.3

form

Step-by-Step Guide Task Define the material numbers on the sales order confirmation Z_9H_RVORDER01 as a 3 of 9 bar code with a check digit.

1. From the SAP main menu, choose Tools Word processing Form. 2. In the Form field, enter Z_9H_RVORDER01, and in the Language field, enter EN. 3. Select Character formats. 4. Choose Change. 2

2008-09

Page 76 of 328

5. In the String field, enter B3. 6. In the Description field, enter Bar code 3 of 9 w/check. 7. Choose Enter. The new character format appears in the character formats frame. 8. In the Bar code field, press the F4 help key and choose the appropriate bar code from the list of available bar codes. Choose BC_CD39C. 9. Save the new character format. The bar code is now defined and can be used. Next, we have to adjust the output of the Main window. 10. Choose Layout. 5 6 7 9 10

11. In the Design Window activate the Main window and choose Edit window text.

11

2008-09

Page 77 of 328

12. In the text editor, scroll down until you see /E ITEM_LINE. 13. Place the cursor at the end of the first line under /E ITEM_LINE. 14. Choose Enter to create a new line. 12

13

15. In the new line, enter ,,<B3>&VBDPA-MATNR&</>. 16. Choose Back. 17. Confirm all the subsequent popup windows. 15 16

The two commas, for the first tab, position the bar code under the material number. <B3> changes the current character string to B3, which defines the bar code. </> ends the character string and returns to IL. Some of the bar codes are higher than one line, which may cause the previous lines to overlap. To avoid overlapping, add blank lines before the line with the bar code. Use an appropriate paragraph for this blank line, so that the blank lines are not compressed. To check the paragraph settings, go to standard attributes and ensure that the No blank lines checkbox is deselected.

2008-09 Page 78 of 328

In our example, notice the bar code, which reserves space for the entire material number field (this field is 18 characters long). If you do not use all 18 characters and do not want to waste space, delimit the field length by using the output length formatting option. The text editor line is ,,<B3>&VBDPA-MATNR(8)&</> In a numerical bar code, some scanners cannot read special characters. For these scanners, omit the special characters inserted by SAPscript during formatting. An example of a special character is the delimiter for Thousands that is used for some numerical fields. See appendix A for more information on formatting options. 18. Activate the form.

18

2.2.17.1.2.3.4

Using Boxes, Lines, and Shading

SAPscript Boxes, frames, lines, shading BOX POSITION SIZE 1 BOX /: BOX [XPOS] [YPOS] [WIDTH] [HEIGHT] [FRAME] [INTENSITY] XPOSYPOSWIDTHHEIGHTFRAME INTENSITY 0-100 20 XPOSYPOS POSITION POSITION page X(abs) = XORIGIN + XPOS Y(abs) = YORIGIN + YPOS WIDTH

2008-09

Page 79 of 328

SIZE HEIGHT SIZE FRAME 0 INTENSITY 100

TW (twip) PT (point) IN (inch) MM (millimeter) CM (centimeter) LN (line) CH (character).

/: BOX WIDTH '17.5' CM HEIGHT 1 /: BOX WIDTH '17.5' CM HEIGHT /: BOX XPOS '10.0' CM WIDTH 0 TW /: BOX XPOS '13.5' CM WIDTH 0 TW HEIGHT '13.5' CM FRAME 10 TW

CM

FRAME 10 TW INTENSITY '13.5' CM FRAME 10 HEIGHT '13.5' CM FRAME 10

15 TW TW

'' '17.5'

2 POSTION /: POSITION [XORIGIN] [YORIGIN] [WINDOW] [PAGE] BOX XPOS, YPOS window POSITION window /: POSITION WINDOW Sets the origin for the coordinate system to the upper left corner of the window. /: POSITION XORIGIN 2 CM YORIGIN '2.5 CM' Sets the origin for the coordinate system to a point 2 cm from the left edge and 2.5 cm from the upper edge of the output page. /: POSITION XORIGIN '-1.5' CM YORIGIN -1 CM Shifts the origin for the coordinates 1.5 cm to the left and 1 cm up 3 SIZE /: SIZE [WIDTH] [HEIGHT] [WINDOW] [PAGE] BOX WIDTHHEIGHT window SIZE window XORIGINYORIGIN WINDOW window PAGE page(XORIGIN = 0 cm, YORIGIN = 0 cm)

WIDTHWIDTH

WINDOW window
2008-09 Page 80 of 328

PAGE page

/: SIZE WINDOW Sets WIDTH and HEIGHT to the current window dimensions. /: SIZE WIDTH '3.5' CM HEIGHT '7.6' CM Sets WIDTH to 3.5 cm and HEIGHT to 7.6 cm. /: POSITION WINDOW /: POSITION XORIGIN -20 TW YORIGIN -20 TW /: SIZE WIDTH +40 TW HEIGHT +40 TW /: BOX FRAME 10 TW A frame is added to the current window. The edges of the frame extend beyond the edges of the window itself, so as to avoid obscuring the leading and trailing text characters.

2.2.17.2 SAPscript Control Commands


2.2.17.2.1 Control Commands
SAPscript Control Commands / Control Commands Control Commands Control Commands Control Commands Control Commands

2.2.17.2.2 2.2.17.2.2.1

Control Commands NEW-PAGE

main window SAPscript NEW-PAGE () NEW-PAGE NEW-PAGE form page next page form pages pages next page /: NEW-PAGE [page_name] /: NEW-PAGE form page /: NEW-PAGE S1 S1 next page

2.2.17.2.2.2

PROTECT

SAPscript PROTECT ENDPROTECT PROTECT PROTECT NEW-PAGE page PROTECT/ENDPROTECT NEW-PAGE main window PROTECT/ENDPROTECT /: : : /: ENDPROTECT PROTECT ENDPROTECT ENDPROTECT SAPscript PROTECT/ENDPROTECT ENDPROTECT PROTECT PROTECT/ENDPROTECT 2008-09 Page 81 of 328 PROTECT

PROTECT/ENDPROTECT page

2.2.17.2.2.3

main window NEW-WINDOW

page 99 main windows main window 0 98 windows SAPscript labels main window main window main window NEW-WINDOW main window main window /: NEW-WINDOW

2.2.17.2.2.4

symbol DEFINE

/: DEFINE &symbol_name& = 'value' symbol DEFINE /: DEFINE &subject& = 'Your letter of 7/3/95' symbol 60 symbol /: /: /: &symbol2& -> SAPscript /: DEFINE &symbol1& = 'mail' /: DEFINE &symbol2& := 'SAP&symbol1&' /: DEFINE &symbol1& = 'script' &symbol2& -> SAPmail &symbol2& symbol symbol symbol = symbol= symbol == symbol:= symbol := DEFINE DEFINE DEFINE &symbol1& &symbol2& &symbol1& = = = 'mail' 'SAP&symbol1&' 'script'

2.2.17.2.2.5

SET DATE MASK

SET DATE MASK /: SET DATE MASK = 'date_mask' MASK DD: day (two digits) DDD: day name - abbreviated DDDD: day name - written out in full MM: month (two digits) MMM: month name abbreviated MMMM: month name - written out in full YY: year (two digits) YYYY: year (four digits) LD: day (formatted as for the L option) LM: month (formatted as for the L option) LY: year (formatted as for the L option) MASK March 1 1997 /: SET DATE MASK = 'Foster City, MM/DD/YY' &DATE& -> Foster City, 03/01/97 () /: SET DATE MASK = 'MMMM DD, YYYY' &DATE& -> March 01, 1997 ()
st

2008-09

Page 82 of 328

MASK /: SET DATE MASK = ' ' SAP TTDTG MASK

2.2.17.2.2.6

Time SET TIME MASK

Time SET TIME MASK /: SET TIME MASK = 'time_mask' TIME MASK HH hours (two digits) MM minutes (two digits) SS seconds (two digits) MASK 100812 /: SET TIME MASK = 'HH:MM' &TIME& -> 10:08() /: SET TIME MASK = 'HH hours MM minutes' &TIME& -> 10 hours 08 minutes() MASK /: SET TIME MASK = ' '

2.2.17.2.2.7

SET COUNTRY

/: SET COUNTRY country_key country_key T005X country_key. Country SET COUNTRY /: SET COUNTRY 'CAN' /: SET COUNTRY &country_key& symbol

2.2.17.2.2.8
: /: SET SIGN LEFT symbol /: SET SIGN RIGHT symbol

symbol SET SIGN

2.2.17.2.2.9

Initializing Numbered ParagraphsRESET

RESET RESET RESET /: RESET paragraph_format N1 * Proceed as follows if you want to work with the SAP R/3 system: N1 Ensure that you have a PC N1 Switch the PC on N1 Click on the SAP icon using the mouse. * You will then enter the SAP logon screen. In order to log

2008-09

Page 83 of 328

on here, you must carry out the following actions: /: RESET N1 N1 Enter your user name N1 Enter your password N1 Select the application you want to use /: RESET N1 Proceed as follows if you want to work with the SAP R/3 system: 1. Ensure that you have a PC 2. Switch the PC on 3. Click on the SAP icon using the mouse. You will then enter the SAP logon screen. In order to log on here, you must carry out the following actions: 1. Enter your user name 2. Enter your password 3. Select the application you want to use /: RESET N1 Proceed as follows if you want to work with the SAP R/3 system: 1. Ensure that you have a PC 2. Switch the PC on 3. Click on the SAP icon using the mouse. You will then enter the SAP logon screen. In order to log on here, you must carry out the following actions: 4. Enter your user name 5. Enter your password 6. Select the application you want to use

2.2.17.2.2.10

INCLUDE

INCLUDE SAPscript include include INCLUDE /: INCLUDE name [OBJECT o] [ID i] [LANGUAGE l] [PARAGRAPH p] [NEW-PARAGRAPH np] name /: INCLUDE MYTEXT MYTEXT /: INCLUDE MYTEXT LANGUAGE 'E' PARAGRAPH 'A1' MYTEXT INCLUDE 'A1' INCLUDE SAPSCRIPT-SUBRC 0INCLUDE 1 2 SAPscript form 4

2.2.17.2.2.11

STYLE

STYLE STYLE * /: STYLE style [DOMINANT] /: STYLE * 1)STYLE INCLUDE INCLUDE DOMINANT 2) INCLUDE STYLE DOMINANT INCLUDE STYLE

2.2.17.2.2.12

ADDRESS

2008-09

Page 84 of 328

/: ADDRESS [DELIVERY] [TYPE t] [PARAGRAPH a] [PRIORITY p] [LINES l] /: TITLE title /: NAME name1[,name2[,name3[,name4]]] /: PERSON name of natural person [TITLE form of address] /: PERSONNUMBER number of the personen /: DEPARTMENT department /: STREET street name HOUSE house number /: LOCATION additional location information /: POBOX po box [CODE post code / zip code] [CITY city] /: POSTCODE post code / zip_code /: CITY city1[,city2] /: NO_UPPERCASE_FOR_CITY /: REGION county / state /: COUNTRY recipient country [LANGUAGE language code] /: COUNTRY_IN_REC_LANG /: LANG_FOR_COUNTRY language key /: FROMCOUNTRY sender country /: ADDRESSNUMBER address number /: ENDADDRESS ADDRESS-ENDADDRESS COUNTRY ADRS1, ADRS2, ADRS3 ADDRESS-ENDADDRESS SAP online help /: ADDRESS /: TITLE 'Firma' /: NAME 'Schneider & Co', 'Finanzberatung' /: STREET 'Kapitalgasse 33' /: POBOX '12345' CODE '68499' /: POSTCODE '68309' /: CITY 'Mannheim' /: COUNTRY 'DE' /: FROMCOUNTRY 'DE' /: ENDADDRESS Firma Schneider & Co Finanzberatung Postfach 12345 68499 Mannheim

2.2.17.2.2.13

main window Header TextTOP

main window TOP/ENDTOP main window Header Text /: TOP : : /: ENDTOP main window TOP/ENDTOP Header Text TOP/ENDTOP /: TOP /: ENDTOP main window Header Text Header Text

2008-09

Page 85 of 328

2.2.17.2.2.14
/: BOTTOM : : /: ENDBOTTOM

main window Footer TextBOTTOM

main window Header Text main window Footer TextFooter Text main window

Header Text BOTTOM/ENDBOTTOM /: BOTTOM /: END BOTTOM

2.2.17.2.2.15
1 /: IF condition : : /: ENDIF 2 /: IF condition : /:ELSEIF condition : /:ELSE /: ENDIF 3 /: IF condition : /:ELSE : /: ENDIF

IF

IF

2.2.17.2.2.16
/: CASE symbol /: WHEN value1 : /: WHEN value2 : /: WHEN valuen : /: WHEN OTHERS. : /: ENDCASE

CASE

CASE IF

1)CASE ENDCASE 2) WHEN OTHERS

2.2.17.2.2.17

ABAP PERFORM

PERFORM ABAP (FORM) PERFORM symbol

2008-09

Page 86 of 328

/: PERFORM <form> IN PROGRAM <prog> /: USING &INVAR1& /: USING &INVAR2& ...... /: CHANGING &OUTVAR1& /: CHANGING &OUTVAR2& ...... /: ENDPERFORM INVAR1 INVAR2 SAPscript Symbol OUTVAR1 OUTVAR2 symbol ABAP FORM <form> TABLES IN_TAB STRUCTURE ITCSY OUT_TAB STRUCTURE ITCSY. ... ENDFORM. SAPscript from ABAP QCJPERFO GET_BARCODE SAPscript form /: PERFORM GET_BARCODE IN PROGRAM QCJPERFO /: USING &PAGE& /: USING &NEXTPAGE& /: CHANGING &BARCODE& /: ENDPERFORM / / &BARCODE& ABAP REPORT QCJPERFO. FORM GET_BARCODE TABLES IN_PAR STUCTURE ITCSY OUT_PAR STRUCTURE ITCSY. DATA: PAGNUM LIKE SY-TABIX, "page number NEXTPAGE LIKE SY-TABIX. "number of next page. READ TABLE IN_PAR WITH KEY PAGE. CHECK SY-SUBRC = 0. PAGNUM = IN_PAR-VALUE. READ TABLE IN_PAR WITH KEY NEXTPAGE. CHECK SY-SUBRC = 0. NEXTPAGE = IN_PAR-VALUE. READ TABLE IN_PAR WITH KEY BARCODE. CHECK SY-SUBRC = 0. IF PAGNUM = 1. OUT_PAR-VALUE = |. "First page ELSE. OUT_PAR-VALUE = ||. "Next page ENDIF.

2008-09

Page 87 of 328

IF NEXTPAGE = 0. OUT_PAR-VALUE+2 = L. "Flag: last page ENDIF. MODIFY OUT_PAR INDEX SY-TABIX. ENDFORM.

2.2.17.2.2.18

SUMMING

SUMMING /: SUMMING program_symbol INTO total_symbol SAPscript program_symbol TABLES

2.2.17.3 SAPscript Symbols


2.2.17.3.1 Syntax of Symbols
symbol symbol & symbol '+() SAPscript Editor symbol long line long line = or /= & symbol symbol symbol &symbol& &MY_symbol& &KNA1-NAME1& &DATE& &KNA1-UMSAT(I)& symbol &mysymbol &my symbol& &mysymbol)& &symbol(Z& &KNA1-UMSAT(i)&

symbol symbol SAPscript symbol &mysymbol& &Mysymbol& &MYSYMBOL&

2.2.17.3.2

System Symbols

SAPscript system symbols symbols SAPscript system symbols sap online help Current Date Current Day Number Current Month Number Current Year Number Local Date &DATE& &DAY& &MONTH& &YEAR& &LDATE& COUNTRY = JAPAN Monday 1 2008-09 Page 88 of 328

Current Day Name Current Month Name

&NAME_OF_DAY& &NAME_OF_MONTH&

Current Time Hours Component of Current Time Minutes Component of Current Time Seconds Component of Current Time Current Page Number Page Number of the Next Page Selected Device Type Spaces Underline Vertical Line

&TIME& &HOURS& &MINUTES& &SECONDS& &PAGE& &NEXTPAGE& &DEVICE& &SAPCE& &ULINE& &VLINE&

2.2.17.3.3

Program Symbols

symblos symbols program symbolsprogram symbols 255 TABLES program symbols &KNA1-NAME1&, &KNA1-ORT01&, &KNA1-PFACH& program symbols &MYCOUNTRY& symbol form symbol Form/text .... /: DEFINE &mysymbol& = abc * &mysymbol& .... .... Data: mysymbol(5) value xyz. .... abc Form/text .... * &mysymbol& .... .... Data: mysymbol(5) value xyz. .... xyz * &mysymbol&xyzabc /: DEFINE &mysymbol& = abc

2.2.17.3.4

Standard Symbols

Standard symbols TTDTG Standard symbols 60 SAP Standard symbols Standard symbols

2.2.17.3.5

Text Symbols

Symbols Symbols Text Symbols, Text Symbols Include Symbols Text DEFINE /: DEFINE &mysymbol& = 'xxx xxx xxxxx xxxx'

2008-09

Page 89 of 328

&mysymbol& /: DEFINE &mysymbol& = 'yyyyy yyy yyyy' / &mysymbol& : xxx xxx xxxxx xxxx yyyyy yyy yyyy

Text Symbols ' '

2.2.17.4 Formatting Options


symbols program symbolsURR, DEC, QUAN, INT1 INT2, INT4, PREC, FLTP program symbols SAP Dictionary Formatting Options symbols Formatting Options symbol Formatting Options SAPscript 20 Formatting

Options.

2.2.17.4.1

Offset()

&symbol+offset& symbol symbol offset offset symbol

If < symbol> has the value 123456789, the following will be displayed: &symbol& -> 123456789 &symbol+3& -> 456789 &symbol+7& -> 89 &symbol+12& -> &symbol+0& -> 123456789

2.2.17.4.2

Output Length

symbol Output Length &symbol(length)& If < symbol> has the value 123456789. &symbol(3)& -> 123 &symbol(7)& -> 1234567 offset Output Length &symbol+4(3)& -> 567 symbol symbol * program symbol ABAP Dictionary &symbol(*)&

2.2.17.4.3

Omitting the Leading Sign

program symbols S &symbol(S)&

2008-09

Page 90 of 328

The ITCDP-TDULPOS field contains the value -100.00. The ABAP Dictionary definition for this field includes a leading sign. &ITCDP-TDULPOS& -> 100.00&ITCDP-TDULPOS(S)& -> 100.00 &symbol(<)& Leading Sign to the Left &ITCDP-TDULPOS& -> 100.00&ITCDP-TDULPOS(<)& -> -100.00 &symbol(>)& Leading Sign to the Right &ITCDP-TDULPOS& -> 100.00&ITCDP-TDULPOS(<)& -> -100.00 &ITCDP-TDULPOS(>)& -> 100.00

2.2.17.4.4

Omitting Leading Zeros

symbol values 0 01 Omitting Leading Zeros &symbol(Z)& : Assuming the current date is 1.1.1994, &DAY& -> 01 &DAY(Z)& -> 1

2.2.17.4.5

Space Compression

symbol value Space Compression symbol value Space Compression ABAP CONDENSE &symbol(C)& Assuming ' Albert Einstein ' is the symbol value, &symbol& -> Albert Einstein &symbol(C)& ->Albert Einstein

2.2.17.4.6

Number of Decimal Places

program symbol DEC, QUAN FLTP Number of Decimal Places SAP Dictionary &symbol(.N)& The EKPO-MENGE field contains the value 1234.56. The Dictionary definition specifies 3 decimal places and an output length of 17. &EKPO-MENGE& -> 1,234.560 &EKPO-MENGE(.1) -> 1,234.6 &EKPO-MENGE&(.4) -> 1,234.5600 &EKPO-MENGE&(.0) -> 1,235

2008-09

Page 91 of 328

2.2.17.4.7

Omitting the Separator for Thousands

DEC, CURR, INT QUAN Symbols Omitting the Separator for Thousands &symbol(T)& The EKPO-MENGE field contains the value 1234.56. The Dictionary definition specifies 3 decimal places and an output length of 17. &EKPO-MENGE& -> 1,234.560 &EKPO-MENGE(T)& -> 1234.560

2.2.17.4.8

Specifying an Exponent for Floating Point Numbers

&symbol(EN)& N = 0&symbol(E0)&&symbol(E)& In this example, the PLMK-SOLLWERT field is assumed to have the value 123456.78 and to be of data type FLTP. &PLMK-SOLLWERT& -> +1.23456780000000E+05 &PLMK-SOLLWERT(E3)& -> +123.456780000000E+03 &PLMK-SOLLWERT(E6)& -> +0.12345678000000E+06 &PLMK-SOLLWERT(E0)& -> +123456.780000000 &PLMK-SOLLWERT(E)& -> +123456.780000000

2.2.17.4.9

Right-Justified Output

Symbol values Formatting Optios &symbol(R)& If symbol has the value 1234. &symbol& -> 1234 &symbol(8R) -> 1234 program symbols SAP Dictionary

2.2.17.4.10

Fill Characters

symbols value &symbol(F f )& f = The figure for customer sales in the KNA1-UMSAT field is $700. The Dictionary description of the field specifies an output length 8. &KNA1-UMSAT& -> 700.00 &KNA1-UMSAT(F*)& -> **700.00 &KNA1-UMSAT(F0)& -> 00700.00

2.2.17.4.11
&symbol(I)&

Suppressing Output of Initial Values

symbols symbols

2008-09

Page 92 of 328

Assuming KNA1-UMSAT contains the value 0 and the currency is DEM. &KNA1-UMSAT& -> 0,00 &KNA1-UMSAT(I)& -> If the field contains an amount other than 0, this value is printed in the normal way. &KNA1-UMSAT& -> 700,00 &KNA1-UMSAT(I)& -> 700,00

2.2.17.4.12 &symbol(L)& 2.2.17.4.13

Local Dates(Currently Only for Japan)

mask JPDA R/3

Changing the Value of a Counter

SAPSCRIPT-COUNTER_x(x = 0 9) 1 SAPSCRIPTCOUNTER_x &SAPSCRIPT-COUNTER_x(+)& Increases by 1 the contents of the counter variable x (x=0.. 9) &SAPSCRIPT-COUNTER_x(-)& Decreases by 1 the contents of the counter variable x (x=0.. 9) 1) SAPSCRIPT-COUNTER_x Formatting Options() 2) DEFINE Assume that &SAPSCRIPT-COUNTER_1& initially has the value 2.
&SAPSCRIPT-COUNTER_1& -> 2 &SAPSCRIPT-COUNTER_1(+)& -> 3 &SAPSCRIPT-COUNTER_1(-)& -> 2 &SAPSCRIPT-COUNTER_1(-)& -> 1 &SAPSCRIPT-COUNTER_1(+0)& -> &SAPSCRIPT-COUNTER_1(+)& -> 3

2.2.17.4.14

Preceding and Subsequent Texts(Pre-Text/Post-Text)

symbols symbols symbols symbols symbols (Pre-Text) symbols (Post-Text) symbols &'pre-text'symbol'post-text'& =/= The KNA1-PFACH field contains a customer P.O. Box number. Since the text "P.O. Box" is not stored in the field along with the value, you would normally write the following for the P.O. Box line of an address: P.O. Box &KNA1-PFACH&

2008-09

Page 93 of 328

However, if no P.O. Box has been specified, the text "P.O. Box" would still appear on its own in the address. To prevent this, use pre-text or post-text (in this case, pre-text). P.O. Box &KNA1-PFACH& -> P.O. Box &'P.O. Box 'KNA1-PFACH& -> If a P.O. Box has been specified, then this will be displayed together with the appropriate text in the normal way. &'P.O. Box 'KNA1-PFACH& -> P.O. Box 123456

2.2.17.5 SAPscript Function Dodules


ABAP FORM SAPscript Function Modules SAPscript Function Modules Function Modules OPEN_FORM CLOSE_FORM WRITE_FORM Function Modules sap online help READ_TEXT READ_TEXT_INLINE READ_REFERENCE_LINES SAVE_TEXT DELETE_TEXT COPY_TEXTS SELECT_TEXT REFER_TEXT RENAME_TEXT COMMIT_TEXT INIT_TEXT EDIT_TEXT EDIT_TEXT_INLINE CHECK_TEXT_AUTHORITY CHECK_TEXT_ID CHECK_TEXT_LANGUAGE CHECK_TEXT_OBJECT Checks the authorization for standard texts. Checks whether the specified text ID is valid. Checks whether the specified text language is valid. Checks whether the specified text object is valid. Calls the text editor. Merges the inline lines with the other text lines and calls the text editor. Creates a reference to another text. Renames the text in the text memory. Creates for all texts in the text memory the call of an appropriate update module. Initializes the internal work areas for a text. Reads a text module and passes it to the specified work areas. Like READ_TEXT. In addition, it passes the first few text lines to a second lines table. Reads the text lines of a reference text and passes them to the specified lines table. Saves a text. Deletes a text. Copies a text. Finds the texts for an application object.

2008-09

Page 94 of 328

CHECK_TEXT_NAME TEXT_SYMBOL_COLLECT TEXT_SYMBOL_PARSE TEXT_SYMBOL_REPLACE TEXT_SYMBOL_SETVALUE TEXT_CONTROL_REPLACE TEXT_INCLUDE_REPLACE PRINT_TEXT PRINT_TEXT_ITF Form OPEN_FORM CLOSE_FORM START_FORM WRITE_FORM WRITE_FORM_LINES END_FORM CONTROL_FORM READ_FORM_ELEMENTS READ_FORM_LINES CONVERT_TEXT CONVERT_TEXT_R2 CONVERT_OTF_MEMORY EXCHANGE_ITF IMPORT_TEXT EXPORT_TEXT TRANSFER_TEXT

Checks whether the specified text name is valid.

Finds the variable symbols that occur in a text. Checks whether a character string is a SAPscript symbol. Replaces symbols in a text with their values. Defines the value of a text symbol. Replaces control statements in a text (IF, CASE...). Replaces INCLUDE control statements by the text lines of the corresponding text.

Formats a text for output. Prints a text in the internal ITF format.

Opens the form output. Ends the form output. Starts a new form. Calls a form element. Writes text lines into a form. Ends the current form. Sends a control statement to the form. Finds the elements of a form. Passes the lines of a form elements into an internal lines table.

Converts texts between different formats. Converts texts between R/3 format (SAPscript) and R/2 format. Converts the formatted text (OTF format). Exchanges the paragraph and character formats of a text with those of another style or form.

Imports texts. Exports texts. Uploads/Downloads texts.

2008-09

Page 95 of 328

2.2.17.5.1

Open Form

OPEN_FORM function module form form function WRITE_FORM, START_FORM, CONTROL_FORM... function module CLOSE_FORM function module form ABAP OPEN_FORMCLOSE_FORM (ABAP ) CALL FUNCTION 'OPEN_FORM' EXPORTING FORM = SPACE LANGUAGE = SY-LANGU DEVICE = 'PRINTER' DIALOG = 'X' OPTIONS = SPACE APPLICATION = 'TX' ARCHIVE_INDEX = SPACE ARCHIVE_PARAMS = SPACE IMPORTING LANGUAGE = RESULT = NEW_ARCHIVE_PARAMS = EXCEPTIONS CANCELED = DEVICE = FORM = OPTIONS = UNCLOSED = 1) Exporting FORM------ form OPEN_FORM Function Modules form output functions START_FORM formSPACE LANGUAGE------form SY-LANGU DEVICE------ form PRINTER DIALOG------' ','X''X' OPTIONS------ ITCOP SPACE APPLICATION------ DEVICE SCREEN menu menu SCREEN SAPscript TTXOB 'TX' ARCHIVE_INDEX------ TOA_DATASPACE ARCHIVE_PARAMS------ ABAP Dictionary ARC_PARAMSSPACE 2) Importing LANGUAGE------ form THEAD-TDSPRAS RESULT------ ITCPP NEW_ARCHIVE_PARAMS------ ARC_PARAMS 3) Exceptions CANCELED------ form DEVICE------ FORM------ form OPTIONS------ formatting options UNCLOSED------ from form form

2008-09

Page 96 of 328

2.2.17.5.2

CLOSE_FORM

OPEN_FORM form CALL FUNCTION 'CLOSE_FORM' IMPORTING RESULT = TABLES OTFDATA = ?... EXCEPTIONS UNOPENED = RESULT------CLOSE_FORM ITCPP OTFDATA------ OPTIONS TDGETOTF 'X' OTFDATA OTF UNOPENED------ form

2.2.17.5.3

WRITE_FORM

ELEMENT element form CALL FUNCTION 'WRITE_FORM' EXPORTING ELEMENT = SPACE WINDOW = 'MAIN' FUNCTION = 'SET' TYPE = 'BODY' IMPORTING PENDING_LINES = EXCEPTIONS ELEMENT = FUNCTION = TYPE = UNOPENED = UNSTARTED = WINDOW = 1) Exporting ELEMENT----- windowWINDOW form window SPACE WINDOW----- windowMAIN FUNCTION----- window sap online help TYPE----- main window main window TOP, BODY, BOTTOMBODY 2) Importing PENDING_LINES----- main window BOTTOM main window BOTTOM PENDING PENDING PENDING_LINES X NEW-PAGE PENDING BOTTOM Exceptions ELEMENT----- FUNCTION-----FUNCTION SET, APPEND, DELETE TYPE----- window TYPE BODY, TOP, BOTTOM

3)

2008-09

Page 97 of 328

UNOPENED----- form UNSTARTED----- form WINDOW----- form window

2.2.17.6 Sample program


REPORT Z_TEST . TABLES: EKKO,EKPO,NAST,THEAD,ITCPO,EKET,MAKT. PARAMETERS: ZEBELN LIKE EKKO-EBELN. *ALL SCREEN 200. CALL FUNCTION 'OPEN_FORM' EXPORTING FORM = 'Z_TEST' LANGUAGE = SY-LANGU. SELECT SINGLE * FROM EKKO WHERE EBELN = ZEBELN. SELECT * FROM EKPO WHERE EBELN = ZEBELN. SELECT SINGLE * FROM EKET WHERE EBELN = ZEBELN AND EBELP = EKPO-EBELP. SELECT SINGLE * FROM MAKT WHERE MATNR = EKPO-MATNR AND SPRAS = SY-LANGU. * SHIFT ekpo-matnr LEFT DELETING LEADING '0'. SHIFT EKPO-EBELP LEFT DELETING LEADING '0'. CALL FUNCTION 'WRITE_FORM' EXPORTING ELEMENT = 'TEST' TYPE = 'BODY' WINDOW = 'MAIN' EXCEPTIONS OTHERS = 01. ENDSELECT. CALL FUNCTION 'CLOSE_FORM'. REPORT ZBC400_04_020 NO STANDARD PAGE HEADING.

TABLES:SPFLI,SFLIGHT. TYPES:BEGIN OF REC1, CARRID LIKE SPFLI-CARRID, CONNID LIKE SPFLI-CONNID, CITYFROM LIKE SPFLI-CITYFROM, CITYTO LIKE SPFLI-CITYTO, DISTANCE LIKE SPFLI-DISTANCE, END OF REC1. DATA: ITAB1 TYPE TABLE OF REC1 WITH HEADER LINE. DATA: I,J TYPE I. DATA: Z_FREE LIKE SFLIGHT-SEATSMAX.

START-OF-SELECTION. SELECT CARRID CONNID CITYFROM CITYTO DISTANCE FROM SPFLI INTO TABLE ITAB1. LOOP AT ITAB1. I = I + 1. J = I MOD 2.

2008-09

Page 98 of 328

IF J = 0 . FORMAT COLOR 3. ELSE. FORMAT COLOR 2. ENDIF. WRITE:/1 ITAB1-CARRID, 15 ITAB1-CONNID, 30 ITAB1-CITYFROM, 45 ITAB1-CITYTO, 60 ITAB1-DISTANCE. ENDLOOP.

END-OF-SELECTION. SET PF-STATUS 'Z_YZH'. AT USER-COMMAND. CASE SY-UCOMM. WHEN 'EXIT'. LEAVE PROGRAM. WHEN 'DETAIL'. PERFORM DETAIL. ENDCASE.

TOP-OF-PAGE. WRITE:/30 ''. WRITE:/ ':',SY-DATUM, 50 ':',SY-UNAME. ULINE. FORMAT COLOR 1. WRITE:/1 '', 15 '', 30 '', 45 '', 60 ''. ULINE. *&---------------------------------------------------------------------* *& * Form DETAIL text text text *&---------------------------------------------------------------------* *----------------------------------------------------------------------* * --> p1 * <-- p2

*----------------------------------------------------------------------* FORM DETAIL. CALL FUNCTION 'OPEN_FORM' EXPORTING FORM = 'Z_04_04' LANGUAGE = SY-LANGU. CALL FUNCTION 'WRITE_FORM' EXPORTING ELEMENT = 'TITLE' TYPE = 'BODY' WINDOW = 'MAIN' EXCEPTIONS OTHERS = 01.

2008-09

Page 99 of 328

SELECT * FROM SPFLI INTO SPFLI. SELECT * FROM SFLIGHT INTO SFLIGHT WHERE CARRID = SPFLI-CARRID AND CONNID = SPFLI-CONNID. CLEAR Z_FREE. Z_FREE = SFLIGHT-SEATSMAX - SFLIGHT-SEATSOCC. CALL FUNCTION 'WRITE_FORM' EXPORTING ELEMENT = 'INFORMATION' TYPE = 'BODY' WINDOW = 'MAIN' EXCEPTIONS OTHERS = 01. CLEAR SFLIGHT. ENDSELECT. CLEAR SPFLI. ENDSELECT. CALL FUNCTION 'CLOSE_FORM'. ENDFORM. " DETAIL

2.3

INTEGRATED TRANSACTION

2.3.1 Create Info type


2.3.1.1 / 2.3.1.1.1 PM01

2008-09

Page 100 of 328

2.3.1.1.2

conponent, zzyjszwqfsdm,zzfzdw

2.3.1.1.3

9024 Se11 1Delivery Class,Data Browser/Table view maint.

2008-09

Page 101 of 328

APPL0 APPL2 USER1

APPL1 USER

2008-09

Page 102 of 328

5elementary type Field label field label

6se11

2008-09

Page 103 of 328

8 pm019024ps

2008-09

Page 104 of 328

2.3.1.1.4

2008-09

Page 105 of 328

2.3.1.1.5

2008-09

Page 106 of 328

2.3.1.2 1). SPRO

2008-09

Page 107 of 328

2). MP902400

MP902400 3).

2008-09

Page 108 of 328

4). PM01

9024

2008-09

Page 109 of 328

5). ZZYJSZWQDFSZZYJSZWQDFS 2008-09

Page 110 of 328

6). INFOTYPE9024

2008-09

Page 111 of 328

INFOTYPE9024, 2.3.1.3 ///

2.3.2 LSMW
Legacy System Migration Workbench 1 TCODE LSMW

2 Create entry

2008-09

Page 112 of 328

. 3

2008-09

Page 113 of 328

2008-09

Page 114 of 328

Personal menu,

2008-09

Page 115 of 328

Numbers on/off Doubleclick=Display/Edit Object overview Object Action Log

2008-09

Page 116 of 328

8 Ctrl+F8

9 Ctrl+F1

10

2008-09

Page 117 of 328

Object description Owner Standard Batch/Import technique(/) object Method ()

11&

12

2008-09

Page 118 of 328

13 Create structure

14 Z

2008-09

Page 119 of 328

15

16

2008-09

Page 120 of 328

17 create field

18 field name and field description field name and field description 2008-09 Page 121 of 328

19

2008-09

Page 122 of 328

20 DISPLAY&CHANGE Ctrl+F1

21.must be selected

2008-09

Page 123 of 328

BGR00

22

2008-09

Page 124 of 328

23

24Ctrl+F1

2008-09

Page 125 of 328

25 Source field

26 TCODE Edit Constant , Source field Edit Initial


2008-09 Page 126 of 328

27

28Ctrl+F1

2008-09

Page 127 of 328

29 Legacy data Create entry

30 Delimiter Tabulator

2008-09

Page 128 of 328

31 Ctrl+F8

32 Ctrl+F1

2008-09

Page 129 of 328

then read data

2.3.3 BADI

2008-09 Page 130 of 328

2.3.3.1 How to Find BADI 1. : ST05 table buffer trace"SQL trace" 2. Activate trace 3BP 4 BP 5deactivate trace 6 display trace objects V_EXT_IMP V_EXT_ACT operations OPEN 7 Introduction There are multiple ways of searching for BAdIs. My favorite one is using the Performance Trace (formerly known as SQL trace) transaction code ST05. This analyzing technique is based on the fact that all BAdIs are registrated in SAP database tables. So for each BAdI call these database tables will be accessed. The BAdI database tables are SXS_INTER, SXC_EXIT, SXC_CLASS and SXC_ATTR. These tables are always accessed by the views V_EXT_IMP and V_EXT_ACT. So these two ABAP views (T: SE11) will be the basis for the trace. This blog will not describe how to implement BAdIs. See http://help.sap.com/ for more information on implementing a BAdI. The procedure to discover BAdIs by a Performance Trace will be explained by using the example used below. Example case I want to know which BAdIs are called in the transaction "Maintain Business Partners" transaction code BP. Pre checks Check if no other users (T:SM04) or batch jobs (T: SM50) are using the same user as you do. Trace Actions Start the Performance trace Start transaction ST05 (Performance Analysis) Set flag field "Buffer trace" Remark: We need to trace also the buffer calls, because BAdI database tables are buffered. (especially view V_EXT_IMP and V_EXT_ACT) Push button "Activate Trace" Execute the Business transaction Start transaction BP in a new GUI session Push button "Organization" Fill in your test data Name NL4B

2008-09

Page 131 of 328

Street

Olympia

House number 1a/1b Postal code City Country 1213 NS Hilversum NL

Push button Save Performance trace Go back to the Performance trace session Push button "Deactivate Trace" Analyzing the Trace List Showing the Trace List Push button "Display Trace" The popup screen "Set Restrictions for Displaying Trace" appears Now we are going to filter the trace on Objects: V_EXT_IMP and V_EXT_ACT. Push button "Multiple selections" button behind field Objects Fill: V_EXT_IMP and V_EXT_ACT

Push button "Copy (F8)" Fill Operations: OPEN Push button Enter See the result:

2008-09

Page 132 of 328

Interpreting the Trace list All the interface class names of view V_EXT_IMP start with IF_EX_. This is the standard SAP prefix for BAdI class interfaces. The BAdI name is after the IF_EX_. So the BAdI name of IF_EX_ADDR_LANGU_TO_VERS is ADDR_LANGU_TO_VERS. In transaction SE18 you can see the BAdI definition.

(If you cant find the BAdI definition name, search in table SXS_INTER.) Exporting the Trace list If youd like to keep your analysis, you can export it to Excel file format. Actually the file will be saved in tab separated file format, but giving the file the extension .xls it will automatically be opened by Excel.

2008-09

Page 133 of 328

Start menu: List > Save > Local File Select Spreadsheet Push Enter Fill your preferred file location and file name

Push button "Generate" Open the file (in Excel)

Delete the columns and rows you dont need and the result looks like:

2008-09

Page 134 of 328

View V_EXT_IMP and V_EXT_ACT The reason for filtering the result not only on the view V_EXT_IMP but also on V_EXT_ACT is necessary, because not all BAdIs are implemented in the same way. For example: V_EXT_IMP catches BAdI BPTIME_BP001. V_EXT_ACT catches BAdI ADDRESS_SEARCH Tips Make a full test entry in the Business transaction before starting the Performance analysis. So during the Performance trace you wont make mistakes. Making mistakes during the recording will cause extra trace lines in your trace list. Try to start with an empty Business transaction screen. This tip is best explained by an example. When I restart transaction BP after I have created, displayed or changed a business partner, the last opened business partner will be displayed automatically. This means also I will get extra trace lines in my trace list. To start again with an empty business partner screen you have to close all GUI sessions and login again. In the Business transaction you need to fill all required fields so all BAdIs will be called. Appendix BP analysis View Call BAdI ADDR_LANGU_TO_VERS ADDR_LANGU_TO_VERS

V_EXT_ACT R 20 ADDR_LANGU_TO_VERS V_EXT_IMP R 30 IF_EX_ADDR_LANGU_TO_VERS

2008-09

Page 135 of 328

V_EXT_ACT R 20 BUPR_FILTER_RELTYP V_EXT_IMP R 30 IF_EX_BUPR_FILTER_RELTYP V_EXT_ACT R 20 BUPR_FILTER_RELTYP V_EXT_IMP R 30 IF_EX_BUPR_FILTER_RELTYP V_EXT_ACT R 20 BUPR_FILTER_RELSHP V_EXT_ACT R 20 BUPA_AUGRP V_EXT_IMP R 30 IF_EX_BUPA_AUGRP V_EXT_IMP R 30 IF_EX_BPTIME_BP001 V_EXT_ACT R 20 ADDRESS_SUBSCREEN V_EXT_ACT R 20 ADDRESS_SEARCH V_EXT_IMP R 30 IF_EX_ADDRESS_SUBSCREEN V_EXT_IMP R 30 IF_EX_ADDRESS_SUBSCREEN V_EXT_IMP R 30 IF_EX_ADDRESS_SUBSCREEN V_EXT_IMP R 30 IF_EX_ADDRESS_SUBSCREEN V_EXT_ACT R 20 ADDRESS_SEARCH V_EXT_ACT R 20 ADDRESS_CHECK V_EXT_ACT R 20 ADDRESS_CHECK V_EXT_ACT R 20 ADDR_TXJCD_CHECK V_EXT_ACT R 20 ADDRESS_CHECK V_EXT_ACT R 20 ADDR_PRINTFORM_SHORT

BUPR_FILTER_RELTYP BUPR_FILTER_RELTYP BUPR_FILTER_RELTYP BUPR_FILTER_RELTYP BUPR_FILTER_RELSHP BUPA_AUGRP BUPA_AUGRP BPTIME_BP001 ADDRESS_SUBSCREEN ADDRESS_SEARCH ADDRESS_SUBSCREEN ADDRESS_SUBSCREEN ADDRESS_SUBSCREEN ADDRESS_SUBSCREEN ADDRESS_SEARCH ADDRESS_CHECK ADDRESS_CHECK ADDR_TXJCD_CHECK ADDRESS_CHECK ADDR_PRINTFORM_SHORT

V_EXT_IMP R 30 IF_EX_ADDR_PRINTFORM_SHORT ADDR_PRINTFORM_SHORT V_EXT_ACT R 20 BUPA_ROLE_EXPORT V_EXT_IMP R 30 IF_EX_BUPA_ROLE_EXPORT V_EXT_ACT R 20 BUPA_BANK_EXPORT V_EXT_IMP R 30 IF_EX_BUPA_BANK_EXPORT V_EXT_ACT R 20 BUPA_CCARD_EXPORT V_EXT_IMP R 30 IF_EX_BUPA_CCARD_EXPORT V_EXT_ACT R 20 BUPA_INDSEC_EXPORT V_EXT_IMP R 30 IF_EX_BUPA_INDSEC_EXPORT V_EXT_ACT R 20 BUPA_ADDR_EXPORT V_EXT_IMP R 30 IF_EX_BUPA_ADDR_EXPORT V_EXT_ACT R 20 BUPA_GENERAL_EXPORT V_EXT_IMP R 30 IF_EX_BUPA_GENERAL_EXPORT V_EXT_ACT R 20 BUPA_GENERAL_UPDATE BUPA_ROLE_EXPORT BUPA_ROLE_EXPORT BUPA_BANK_EXPORT BUPA_BANK_EXPORT BUPA_CCARD_EXPORT BUPA_CCARD_EXPORT BUPA_INDSEC_EXPORT BUPA_INDSEC_EXPORT BUPA_ADDR_EXPORT BUPA_ADDR_EXPORT BUPA_GENERAL_EXPORT BUPA_GENERAL_EXPORT BUPA_GENERAL_UPDATE
2008-09 Page 136 of 328

V_EXT_IMP R 110 IF_EX_BUPA_GENERAL_UPDATE BUPA_GENERAL_UPDATE V_EXT_ACT R 20 BUPA_BANK_UPDATE V_EXT_IMP R 110 IF_EX_BUPA_BANK_UPDATE V_EXT_ACT R 20 BUPA_CARDS_UPDATE V_EXT_IMP R 30 IF_EX_BUPA_CARDS_UPDATE V_EXT_ACT R 20 BUPA_ROLES_UPDATE V_EXT_IMP R 30 IF_EX_BUPA_ROLES_UPDATE V_EXT_ACT R 20 BUPA_INDSEC_UPDATE V_EXT_IMP R 30 IF_EX_BUPA_INDSEC_UPDATE V_EXT_ACT R 20 BUPA_IDENT_UPDATE V_EXT_IMP R 30 IF_EX_BUPA_IDENT_UPDATE V_EXT_ACT R 20 ADDRESS_UPDATE V_EXT_IMP R 30 IF_EX_ADDRESS_UPDATE V_EXT_IMP R 30 IF_EX_ADDRESS_UPDATE V_EXT_ACT R 20 BUPA_ADDR_UPDATE V_EXT_IMP R 110 IF_EX_BUPA_ADDR_UPDATE V_EXT_ACT R 20 BUPA_TAX_UPDATE V_EXT_IMP R 110 IF_EX_BUPA_TAX_UPDATE V_EXT_ACT R 20 FSBP_BPID_UPDATE V_EXT_IMP R 30 IF_EX_FSBP_BPID_UPDATE V_EXT_IMP R 30 IF_EX_BPTIME_BP001 V_EXT_ACT R 20 FSBP_BP001_UPDATE V_EXT_IMP R 30 IF_EX_FSBP_BP001_UPDATE V_EXT_IMP R 30 IF_EX_BPTIME_BUT021_FS V_EXT_ACT R 20 FSBP_BUT021_UPDATE V_EXT_IMP R 30 IF_EX_FSBP_BUT021_UPDATE V_EXT_ACT R 20 ADDRESS_SEARCH V_EXT_ACT R 20 PARTNER_UPDATE V_EXT_IMP R 30 IF_EX_PARTNER_UPDATE V_EXT_IMP R 30 IF_EX_PARTNER_UPDATE V_EXT_IMP R 30 IF_EX_BPTIME_BP001 V_EXT_IMP R 30 IF_EX_BPTIME_BUT021_FS V_EXT_ACT R 20 GOS_SRV_SELECT V_EXT_IMP R 30 IF_EX_GOS_SRV_SELECT BUPA_BANK_UPDATE BUPA_BANK_UPDATE BUPA_CARDS_UPDATE BUPA_CARDS_UPDATE BUPA_ROLES_UPDATE BUPA_ROLES_UPDATE BUPA_INDSEC_UPDATE BUPA_INDSEC_UPDATE BUPA_IDENT_UPDATE BUPA_IDENT_UPDATE ADDRESS_UPDATE ADDRESS_UPDATE ADDRESS_UPDATE BUPA_ADDR_UPDATE BUPA_ADDR_UPDATE BUPA_TAX_UPDATE BUPA_TAX_UPDATE FSBP_BPID_UPDATE FSBP_BPID_UPDATE BPTIME_BP001 FSBP_BP001_UPDATE FSBP_BP001_UPDATE BPTIME_BUT021_FS FSBP_BUT021_UPDATE FSBP_BUT021_UPDATE ADDRESS_SEARCH PARTNER_UPDATE PARTNER_UPDATE PARTNER_UPDATE BPTIME_BP001 BPTIME_BUT021_FS GOS_SRV_SELECT GOS_SRV_SELECT
2008-09 Page 137 of 328

V_EXT_ACT R 20 ADDRESS_SEARCH

ADDRESS_SEARCH

Keywords: BAdI BAdIs BAdIs Businesses Add In Business Add-In Business Add-Ins how to find BAdIs 2.3.3.2 How to create BADI Implementing Business Add-Ins (BADI) The use of object orientated code within SAP has lead to new method of enhancing standard SAP code called Business Add-Ins or BADI's for short. Although the implementation concept is based on classes, methods and inheritance you do not really have to understand this fully to implement a BADI. Simply think of methods as a function module with the same import and export parameters and follow the simple instructions below. Steps: 1. Execute Business Add-In(BADI) transaction SE18 2. Enter BADI name i.e. HRPBSGB_HESA_NISR and press the display button 3. Select menu option Implementation->Create 4. Give implementation a name such as Z_HRPBSGB_HESA_NISR 5. You can now make any changes you require to the BADI within this implementation, for example choose the Interface tab 6. Double click on the method you want to change, you can now enter any code you require. 7. Please note to find out what import and export parameters a method has got return the original BADI definition (i.e. HRPBSGB_HESA_NISR) and double click on the method name for example within HRPBSGB_HESA_NISR contract is a method 8. When changes have been made activate the implementation

2.3.3.3 ECC 6.0 BADI sample ECC6 BAdi . 1. BADI

2008-09

Page 138 of 328

. BAdI migrates to enhancement spot MB_GOODSMOVEMENT" , implementation enhancement implementation

2008-09

Page 139 of 328

. Enhancement Implementation: ZTEST_EI ZTEST_EI. . ,.

..

2008-09

Page 140 of 328

: ZTEST_EI SE19 . ZTEST_EI .

2008-09

Page 141 of 328

Enhancement Implementation , Create Implementation .

2.3.3.4 MB1A BADI sample


Create BADI for material document-- MB1A

2008-09

Page 142 of 328

SE18 BUDI ( ) ** budi

2008-09

Page 143 of 328

BADI: MB_DOCUMENT_BADI

2008-09

Page 144 of 328

BADI SE19 SE18

2008-09

Page 145 of 328

ZXXXX se19

2008-09

Page 146 of 328

MB_DOCUMENT_BEFORE_UPDATE

signature

2008-09

Page 147 of 328

2008-09

Page 148 of 328

2.3.3.5 SE18/SE19/SE24 Se18: Enhancement Spot budi name/BAdI Definition implementation SLL_PI_SD0C_TRANSFER badi Enhancement SLL_PI_SD0C_R3 badi name

SLL_PI_SD0C_TRANSFER Enhancement implementation badi implementation /SAPSLL/PI_SD0C_TRANSFER ZSAPSLL_PI_SD0C_TRANSFER se19 New Badi Enhancement Implementation se18 . ZSAPSLL_PI_SD0C_TRANSFER 3 Interface Implementing Class Method IF_EX_SLL_PI_SD0C_TRANSFER ZSAPSLL_CL_EX_PI_SD0C_TRANSFER (sap ) /SAPSLL/PI_SD0C_TRANSFER /SAPSLL/PI_SD0C_TRANSFER

/SAPSLL/PI_SD0C_TRANSFER 3

2008-09

Page 149 of 328

Interface Implementing Class Method Classic Badi

IF_EX_SLL_PI_SD0C_TRANSFER /SAPSLL/CL_EX_PI_SD0C_TRANSFER (sap )

Implementation r3 4.7 badi .

se24 Object type ZSAPSLL_CL_EX_PI_SD0C_TRANSFER / /SAPSLL/CL_EX_PI_SD0C_TRANSFER se19 Implementing Class 1. badi 2. badi badi badi

2.3.4 Report Tree


b. SE43N: Area menu maintenance c. SERP: Report tree initial

2.3.4.1 Sample:: SERP

2008-09

Page 150 of 328

2.3.4.2 Double click ZTS_RT_OEM_U_LOGISTICS

2.3.4.3 Choose Other type to add a transaction

2008-09

Page 151 of 328

Choose Other type to add a transaction

2.3.5 Dis-active Standard button


TCode: SHD0 1. , Transaction variants and screen variants ,

2008-09

Page 152 of 328

2. Variant groups can control the screen for partial user 3. Which transaction variants belong to the groups?
The name of a transaction variant that is to belong to a group meets the following naming conventions: <Name of variant group><name of transaction code>. Example: A transaction variant is to be created for the XYZ transaction that belongs to GROUP1. The name of the transaction variant is then GROUP1XYZ. Due to this naming convention, the group name must be in the "correct" namespace. Transaction variants that (randomly) meet this naming convention do not necessarily belong to a group. The group assignment is activated by 1. Creating a group 2. Assigning users to this group A transaction variant that belongs to a group can also be used this way, like a transaction variant without a group.

2.3.6 Screen Enhancement on MM01


: Screen Enhancement, FM Extis, MM01, MM02 FM Exits enhancement a screen, 1. Find relevant enhancement thru program name.

2008-09

Page 153 of 328

2. T-code: CMOD, create an enhancement project, then assign the enhancement to the enhancement project 3. Create a subscreen in corresponding X function group 4. Implement the FM exits for transporting data to subscreen and retrieving data from subscreen. 5. Active the enhancement project. main screen flow logic PBO CALL CUSTOMER-SUBSCREEN area INCLUDING x-function-poolscreen_number. " Transporting data to subscreen MODULE ... CALL CUSTOMER-FUNCTION 'xxx' EXPORTING i_vars = gl_field. PAI CALL CUSTOMER-SUBSCREEN area . " Transporting data from subscreen MODULE... CALL CUSTOMER-FUNCTION 'xxx' IMPORTING o_vars = gl_field. FM exits parameter interface screen enhancemnet X Function Group screen number enhance MM01 screen , 1. T-code: OMT3C, create a function group 2. Create/copy a subscreen to the function group 3. Build subscreen layout 4. Add some necessary code to PBO and PAI event block 5. T-code: OMT3B, create/copy a screen sequence, make sure that the program name = "SAPL"+created function group name, and the subscreen number = created subscreen number 6. T-code: OMT3E, change the screen sequence. MM01 Screen MM01 Screen subscreen component subscreen customer namespace Modification subscreen screen sequence sequence screen determination procedure

2.3.7 Query
TCD CODE: SQ03. :

2008-09

Page 154 of 328

,,,.

2008-09

Page 155 of 328

,,. TCD SQ02,

2008-09

Page 156 of 328

,: ,,,.

, Insert table,..

2008-09

Page 157 of 328

, 02 :;03 .

2008-09

Page 158 of 328

01 : ,.

,,:

2008-09

Page 159 of 328

2008-09

Page 160 of 328

, TCD SQ01, ,.

2008-09

Page 161 of 328

2008-09

Page 162 of 328

,,.

,,.

2008-09

Page 163 of 328

(), ,

2008-09

Page 164 of 328

. ,. ,.

2008-09

Page 165 of 328

,.

2008-09

Page 166 of 328

:------ ------.

TCD: SE93

2008-09

Page 167 of 328

(),.

(),.

2008-09

Page 168 of 328

2008-09

Page 169 of 328

, , ,,,!

2.3.8 BTE
BTE , BT ERP, E Business Transaction Event, , (Tcode:SMOD|CMOD) ABAP,BTE RFC (Tcode:FIBF), BTE ,. :(Tcode:BF24)

1, ZMM01-2, 1-[2]. :(Tcode:BF34).

2008-09

Page 170 of 328

,00001250 , BTE, ZMM01_2_CHECK. :(Tcode:SE37).

00001250* SAMPLE_INTERFACE+EVENT ,Copy , 3. . DATA: I_MSG1(60) TYPE C, I_MSG2(50) TYPE C. * Never let user change profit center of material . if ( I_MARC_NEW-PRCTR <> I_MARC_OLD-PRCTR ) and ( I_MARC_OLD-PRCTR <> '' ) . CALL FUNCTION 'READ_CUSTOMIZED_MESSAGE' EXPORTING I_ARBGB = 'ZFI' I_DTYPE = '' I_MSGNR = '003' IMPORTING E_MSGTY = SY-MSGTY.

CHECK E_MSGTY <> '-' .


MESSAGE ID ' ZFI ' TYPE SY-MSGTY NUMBER '003' with 'Change Material profit center not allowed!' . ENDIF. IF ( I_MBEW_NEW-BWKEY = 'FRA1' AND I_MARC_NEW-PRCTR <> '9233110000' ). CALL FUNCTION 'READ_CUSTOMIZED_MESSAGE' EXPORTING I_ARBGB = 'ZFI' I_DTYPE = '' I_MSGNR = '002' IMPORTING E_MSGTY = SY-MSGTY.

CHECK E_MSGTY <> '-' .


I_MSG1 = 'FRA1 profit center should be 9233110000!'. CONCATENATE 'However,Your input is :' I_MBEW_NEW-BWKEY '&' I_MARC_NEWPRCTR into I_MSG2 . MESSAGE ID ' ZFI ' TYPE SY-MSGTY NUMBER '002' with I_MSG1 I_MSG2. ENDIF.

2008-09

Page 171 of 328

case ,-,ZFI. - PO,SO output message,, try..catch..finally .

,. :(Tcode:SE91).
Tcode SE91 ,

1 ZFI,,&,.

:(Tcode:SE38). .

(1).TitleMESSAGE-ID. REPORT ZMSGTEST1 MESSAGE-ID ZFI . MESSAGE I001.


(2)..

REPORT ZMSGTEST2 . MESSAGE I001(ZFI).


(3). .

REPORT ZMSGTEST3 . MESSAGE I002(ZFI) with 1 2 . MESSAGE ID ' ZFI ' TYPE 'I' NUMBER '002' with 1 2 . I: W: E: S: A:. (4).

2008-09 Page 172 of 328

PROGRAM ZMSGTEST4 EXPORTING

CALL FUNCTION 'READ_CUSTOMIZED_MESSAGE' I_ARBGB = 'ZFI' I_DTYPE = '' I_MSGNR = '0002' IMPORTING E_MSGTY = SY-MSGTY. CHECK E_MSGTY <> '-' . MESSAGE ID ' ZFI ' TYPE SY-MSGTY NUMBER '002' 3Tcode. ,Application AreaSE91Message Class.
:(Tcode:OBA5|OMRM).

with 1 2 .

(1).. Table,
T100: . T160M :MM,.,MMSE16. T100C: FI,OBA5, OFMG,CO. T100S: ,,KI 005Tcode:OBA5 . .T160M,SE16T100S T100U: ,. ,Client.

2008-09

Page 173 of 328

2,ZFI,T100S,2-[1] T100S 2-[3]ZFI-002|003,2-[4]. Tcode:OBA5 ZFI 002 ZFI 003 , READ_CUSTOMIZED_MESSAGE.


(2).Tcode FI: OBA5|OFMG|OFPM MM: OMRM|OKZZ|OMT4|OMCQ |O04C| SD: OVAH CO: OPR4_ACT|OPR4_CK|OPR4_CKML|OPR4_CKPF|OPR4_KKA|OPR4_KKP|OPR4_KKS| OPR4_KKS1|OPR4_PPCOPP : OPR5|OPR1|OPR3|OPR6|OPR7|OPR8|OPR9|OPRCMFE|MSW1|MSW2

2008-09

Page 174 of 328

3OMRM, ->PO-> M8 504|M8 081,.

Example Business Scenario for Business Transaction Events Company A would like to copy the group key field from the vendor master into the allocation field on all the line items within a vendor invoice and payments, including the vendor lines. This requirement assumes only one vendor is posted to in a document.

To accomplish this requirement, Company A will use the Business Transaction Event 1130, Post Document: SAP Internal Field Substitution.

1. IMG Menu Path: Financial Accounting Financial Accounting Global Settings Use Business Transaction Events Environment Infosystem (Processes). 2. Find the correct Business Event. You are updating a field, so you select the Processes Info System instead of the Publish and Subscribe Info System. 3. Execute the search with the defaults. 4. Find the correct interface for updating a document: Post Document: SAP- Internal Field Substitution
5. Put your cursor on the event and click on the Sample Function Module button. 6. You are now in transaction SE37 Function Builder. This is the function module (sample_process_00001130) you will need to copy into a "Z" name function module for your coding 7. Click on the Copy button. 8. Enter the "Z" function module name in the To Function Module field 9. Enter a Function Group. If you need to create a "Z" function group, go to transaction code SE37 and follow menu path: Go to Function Groups Create Group. A function group is a logical grouping of function modules, and the ABAP code is generated for function groups. You will be prompted for a development class and transport when creating the function group. 10. In Function Builder (transaction SE37), enter the new "Z" function module. Click on the Change button. 11. The system will default into the source code screen where you may enter your ABAP code. 12. Notice the tables available for the code. Additional tables may be declared if necessary. 13. Enter the following source code

tables: lfa1. data: z_groupkey like lfa1-konzs. z_groupkey = ' '. loop at t_bseg. * check for vendor lines. If one is found, read the vendor master and * retrieve the group key field. if t_bseg-koart eq 'K'. select single konzs from lfa1 into z_groupkey

2008-09

Page 175 of 328

where lifnr = t_bseg-lifnr. endif. * Move the group key field into all line items allocation field. loop at t_bsegsub. t_bsegsub-zuonr = z_groupkey. modify t_bsegsub index sy-tabix. endloop. "t_bsegsub endloop. "t_bseg 14. Save the function module. 15. Back out to the main Function Builder screen by clicking on the green arrow button. 16. Activate the function module by clicking on the Activate button 17. Assign the function module to the event in the IMG: Financial Accounting Financial Accounting Global Settings Business Transaction Events Settings Process Function Modules of an SAP Appl. 18. Hit enter past the warning messages that this is SAP data. 19. Click on the New Entries button. 20. Enter the process for your interface. In your example it is 00001130. 21. Enter the country the interface is valid for. If it is valid for all countries, leave this field blank. 22. Enter the application the interface should be called for. If it should be called for all applications, leave this field blank. Please note that not all integrated transactions are programmed to go through these interfaces! You will need to test to find out! 23. Enter the new "Z" function module 24. Save the settings. At this point you will be prompted for a CTS number for the configuration change. 25. The Business Transaction Event is complete! You are ready for testing

2.3.9
.

2008-09

Page 176 of 328

2008-09

Page 177 of 328

bapi

2008-09

Page 178 of 328

,.

2008-09

Page 179 of 328

C:\Documents and Settings\gaohj\

2.3.10

Step Loop

2008-09

Page 180 of 328

Screen 100 program PROCESS BEFORE OUTPUT. * MODULE STATUS_0100. LOOP.

2008-09

Page 181 of 328

MODULE ITAB_TO_SCREEN. ENDLOOP. * PROCESS AFTER INPUT. LOOP. CHAIN. FIELD:MARA-MATNR,MARA-MTART. MODULE SCREEN_TO_ITAB. ENDCHAIN. ENDLOOP. MODULE USER_COMMAND_0100. PROGRAM ZJHTEST09 TABLES: MARA. DATA:BEGIN OF ITAB OCCURS 0, MATNR LIKE MARA-MATNR, MTART LIKE MARA-MATNR, END OF ITAB. DATA:LINE IDX FILL TYPE I, .

LINES TYPE I, TYPE I, TYPE I,

LIMIT TYPE I. DATA OKCODE(40). *&---------------------------------------------------------------------* *& * Module ITAB_TO_SCREEN OUTPUT text *&---------------------------------------------------------------------* *----------------------------------------------------------------------* MODULE ITAB_TO_SCREEN OUTPUT. IDX = SY-STEPL + LINE. READ TABLE ITAB INDEX IDX. IF SY-SUBRC = 0. MOVE:ITAB-MATNR TO MARA-MATNR, ITAB-MTART TO MARA-MTART.

2008-09

Page 182 of 328

ENDIF. ENDMODULE. *& * " ITAB_TO_SCREEN OUTPUT *&---------------------------------------------------------------------* Module SCREEN_TO_ITAB INPUT text *&---------------------------------------------------------------------* *----------------------------------------------------------------------* MODULE SCREEN_TO_ITAB INPUT. LINES = SY-LOOPC. IDX = SY-STEPL + LINE. MOVE:MARA-MATNR TO ITAB-MATNR, MARA-MTART TO ITAB-MTART. MODIFY ITAB INDEX IDX. IF SY-SUBRC <> 0. APPEND ITAB. ENDIF. ENDMODULE. *& * " SCREEN_TO_ITAB INPUT *&---------------------------------------------------------------------* Module USER_COMMAND_0100 INPUT text *&---------------------------------------------------------------------* *----------------------------------------------------------------------* MODULE USER_COMMAND_0100 INPUT. CASE OKCODE. WHEN 'NEXT_LINE'. line = line + 1. limit = fill - lines. IF line > limit. line = limit. ENDIF. WHEN 'PREV_LINE'. line = line - 1. IF line < 0. line = 0. ENDIF. WHEN 'NEXT_PAGE'. line = line + lines. limit = fill - lines. IF line > limit. line = limit. ENDIF.

2008-09

Page 183 of 328

WHEN 'PREV_PAGE'. line = line - lines. IF line < 0. line = 0. ENDIF. WHEN 'LAST_PAGE'. line = fill - lines. WHEN 'FIRST_PAGE'. line = 0. WHEN 'FIND'. REFRESH ITAB. CLEAR ITAB. SELECT MATNR MTART INTO TABLE ITAB FROM MARA. DESCRIBE TABLE itab LINES fill. SORT ITAB BY MATNR. WHEN 'CREA'. REFRESH ITAB.CLEAR ITAB. ENDCASE. CLEAR OKCODE. ENDMODULE. " USER_COMMAND_0100 INPUT important

2008-09

Page 184 of 328

ABAPDOCU

2008-09

Page 185 of 328

CHAPTER 3 GENERAL PROGRAMMING


3.1 3.2 BAPIS DIALOG PROGRAMMING
http://ifr.sap.com - SAPs Interface Repository

3.2.1 Process on value request F4


PROCESS ON VALUE-REQUEST. FIELD zpcr-source MODULE source_help. MODULE source_help INPUT. DATA: BEGIN OF ivalue_source OCCURS 0, source LIKE zsource-source, source_desc LIKE zsource-source_desc, END OF ivalue_source. DATA: BEGIN OF ivalue_category OCCURS 0, Data: w_progname LIKE sy-repid, w_scr_num LIKE sy-dynnr . DATA: return_values LIKE ddshretval OCCURS 0 WITH HEADER LINE. DATA: itab_dynpfields LIKE dynpread OCCURS 0 with header line, t_dynpfields LIKE dynpread. DATA: t_dyname LIKE d020s-prog, t_dynumb LIKE d020s-dnum. SELECT source source_desc FROM zsource INTO TABLE ivalue_source. IF sy-subrc = 0. CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING retfield = 'SOURCE' dynpprog = w_progname dynpnr = w_scr_num dynprofield = 'ZPCR-SOURCE' value_org = 'S' TABLES value_tab = ivalue_source return_tab = return_values EXCEPTIONS parameter_error = 1 no_values_found = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE . zpcr-source = return_values-fieldval. SELECT SINGLE source_desc INTO zsource-source_desc FROM zsource WHERE source = zpcr-source. ENDIF. ELSE. MESSAGE i999(b1) WITH 'No values in ZSOURCE table'. ENDIF. REFRESH itab_dynpfields. CLEAR: itab_dynpfields. t_dynpfields-fieldname = 'ZSOURCE-SOURCE_DESC'. APPEND t_dynpfields TO itab_dynpfields. t_dynumb = sy-dynnr. t_dyname = sy-repid.

2008-09

Page 186 of 328

* This function module must have the values added to * the internal table that you need t oread. CALL FUNCTION 'DYNP_VALUES_READ' EXPORTING dyname = t_dyname dynumb = t_dynumb TABLES dynpfields = itab_dynpfields EXCEPTIONS invalid_abapworkarea = 1 invalid_dynprofield = 2 invalid_dynproname = 3 invalid_dynpronummer = 4 invalid_request =5 no_fielddescription = 6 invalid_parameter = 7 undefind_error =8 double_conversion = 9 stepl_not_found = 10 OTHERS = 11. IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. LOOP AT itab_dynpfields. CASE itab_dynpfields-fieldname. WHEN 'ZSOURCE-SOURCE_DESC'. itab_dynpfields-fieldvalue = zsource-source_desc. MODIFY itab_dynpfields. ENDCASE. ENDLOOP. CALL FUNCTION 'DYNP_VALUES_UPDATE' EXPORTING dyname = t_dyname dynumb = t_dynumb TABLES dynpfields = itab_dynpfields EXCEPTIONS invalid_abapworkarea = 1 invalid_dynprofield = 2 invalid_dynproname = 3 invalid_dynpronummer = 4 invalid_request =5 no_fielddescription = 6 undefind_error =7 OTHERS = 8. IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDMODULE. " source_help INPUT

3.3

REPORTS

3.3.1 Refreshing Data on reports


DATA: LO_REPID LIKE SY-REPID, LO_SELTAB LIKE RSPARAMS OCCURS 0 WITH HEADER LINE. LO_REPID = SY-REPID. CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS' EXPORTING CURR_REPORT = LO_REPID

2008-09

Page 187 of 328

TABLES SELECTION_TABLE = LO_SELTAB EXCEPTIONS NOT_FOUND =1 NO_REPORT =2 OTHERS =3 . IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. SUBMIT (SY-REPID) WITH SELECTION-TABLE LO_SELTAB.

3.3.2 Tree Reports


STEP ONE ADD THESE LINES OF CODE IN THE DECLARATION AREA **** DECLARATION
DATA: BEGIN OF items OCCURS 100, id type sy-tabix, parent_id type sy-tabix, text(1000), symbol, END OF items, tabix_stack LIKE sy-tabix OCCURS 10 WITH HEADER LINE, items_show LIKE items OCCURS 100 WITH HEADER LINE. DATA: parent_stack LIKE sy-tabix OCCURS 10 WITH HEADER LINE, t_parent LIKE sy-tabix, current LIKE sy-tabix. INCLUDE <symbol>. INCLUDE ZTREE_REPORT_INCLUDES.

STEP TWO ADD THESE LINES OF CODE TO POPULATE THE INTERNAL TABLE **** POPULATE DATA
REFRESH parent_stack. current = 0. parent_stack = 0. APPEND parent_stack. LOOP AT itab_data. CASE itab_data-qualf. WHEN 1. New parent current = current + 1. PERFORM read_from_parent_stack CHANGING t_parent. parent_stack = current. APPEND parent_stack. PERFORM append_item USING current t_parent itab_xml_data. WHEN 2. End of current leg current = current + 1. PERFORM append_item USING current t_parent itab_xml_data. perform delete_parent_stack. WHEN 3. Same level current = current + 1. PERFORM read_from_parent_stack CHANGING t_parent. PERFORM append_item USING current t_parent itab_xml_data. ENDCASE. ENDLOOP.

STEP THREE ADD THESE LINES OF CODE TO PRINT THE REPORT


LOOP AT items WHERE parent_id = 0. MOVE-CORRESPONDING items TO items_show. items_show-symbol = '+'. APPEND items_show. ENDLOOP. PERFORM print_tree TABLES items_show.

STEP FOUR ADD THESE LINES OF CODE TO EXPAND \ COLLAPSE THE TREE

2008-09

Page 188 of 328

* at line-selection - when the node is opened/closed or item double-clk


AT LINE-SELECTION. READ TABLE items WITH KEY parent_id = items_show-id. "see 'hide' IF sy-subrc = 0. "item has children - expand or collapse sy-lsind = 0. PERFORM expand_collapse USING items_show-id. PERFORM print_tree TABLES items_show. ELSE. "item has NO children - perform some action READ TABLE items WITH KEY id = items_show-id. WRITE: 'Action performed on item "' NO-GAP, items-text NO-GAP, '", id.', items-id. ENDIF.

STEP FIVE ADD THIS INCLUDE CODE


*----------------------------------------------------------------------* * INCLUDE ZTREE_REPORT_INCLUDES *----------------------------------------------------------------------* * form append_item
FORM append_item USING value(id) value(parent_id) value(text). items-id = id. items-parent_id = parent_id. items-text = text. APPEND items. ENDFORM. " APPEND_ITEM

* form read_from_stack
FORM read_from_stack CHANGING tabix LIKE sy-tabix. DESCRIBE TABLE tabix_stack. CHECK sy-tfill NE 0. READ TABLE tabix_stack INDEX sy-tfill. tabix = tabix_stack. DELETE tabix_stack INDEX sy-tfill. ENDFORM.

* form print tree


FORM print_tree TABLES items STRUCTURE items. DATA: v_tabix LIKE sy-tabix, start_tabix LIKE sy-tabix, v_level LIKE sy-tfill, v_offset TYPE i, v_id LIKE items-id, v_parent_id LIKE items-parent_id, v_parent_id_for_vline LIKE items-parent_id, v_prev_level TYPE i, v_items_count LIKE sy-tfill, v_vlines_string(200). CHECK NOT items[] IS INITIAL. SORT items BY parent_id id. READ TABLE items INDEX 1. v_parent_id = items-parent_id. start_tabix = 1. REFRESH tabix_stack. DO. LOOP AT items FROM start_tabix. v_tabix = start_tabix = sy-tabix. "remember current index v_id = items-id. v_parent_id_for_vline = items-parent_id.

decrease level and exit loop if parent not the same as previous
IF items-parent_id NE v_parent_id. PERFORM read_from_stack CHANGING start_tabix. "level = NoOfRecs READ TABLE items INDEX start_tabix. v_parent_id = items-parent_id. ADD 1 TO start_tabix. "next loop starts from parent index + 1

clear vline
IF v_level > 1. v_offset = 2 + ( v_level - 2 ) * 3. IF v_level = 1. v_offset = 1. ENDIF. v_vlines_string+v_offset = ' '. ENDIF. EXIT. ENDIF. v_parent_id = items-parent_id.

write item
2008-09 Page 189 of 328

FORMAT COLOR OFF. DESCRIBE TABLE tabix_stack LINES v_level."level is no of StackRecs WRITE: / v_vlines_string. v_offset = v_level * 3. IF v_level NE 0. IF v_prev_level < v_level. WRITE: AT v_offset '|', / ''. WRITE: / v_vlines_string. ENDIF. v_offset = v_level * 3. WRITE AT v_offset '|--'. ENDIF. v_offset = v_offset + 3. CASE items-symbol. WHEN '+'. WRITE AT v_offset sym_plus_folder AS SYMBOL COLOR 4 INTENSIFIED HOTSPOT. WHEN '-'. WRITE AT v_offset sym_minus_folder AS SYMBOL COLOR 4 INTENSIFIED HOTSPOT. WHEN OTHERS. FORMAT COLOR 5. ENDCASE. WRITE: items-text. v_prev_level = v_level. HIDE: items-id. ADD 1 TO v_items_count. READ TABLE items WITH KEY parent_id = items-id.

increase level and exit loop if item has children


IF sy-subrc = 0. start_tabix = sy-tabix. APPEND v_tabix TO tabix_stack. "level is no of recs in stack v_parent_id = items-parent_id.

set vline
v_tabix = v_tabix + 1. READ TABLE items INDEX v_tabix. v_offset = 2 + ( v_level - 1 ) * 3. IF v_level > 0. IF items-parent_id = v_parent_id_for_vline AND sy-subrc = 0. v_vlines_string+v_offset = '|'. ELSE. v_vlines_string+v_offset = ' '. ENDIF. ENDIF. EXIT. ENDIF.

* *

at last - decrease level


AT LAST.

clear vline

IF v_level > 1. v_offset = 2 + ( v_level - 2 ) * 3. IF v_level = 1. v_offset = 1. ENDIF. v_vlines_string+v_offset = ' '. ENDIF. " next loop starts from parent index, not parent index + 1 " because of different parents level will decrease anyway PERFORM read_from_stack CHANGING start_tabix. APPEND start_tabix TO tabix_stack. "must return index to stack ENDAT. ENDLOOP. DESCRIBE TABLE items. IF start_tabix > sy-tfill OR v_items_count >= sy-tfill. EXIT. ENDIF. ENDDO. ENDFORM.

* form expand_collapse
FORM expand_collapse USING value(v_id). DATA: v_no_more_orphans, items_temp LIKE items OCCURS 100 WITH HEADER LINE. DELETE items_show WHERE parent_id = v_id. "try to collapse IF sy-subrc = 0. "succesfull first collapse DO. "cascade collapse - delete 'orphans' that are left REFRESH items_temp. MOVE items_show[] TO items_temp[].

2008-09

Page 190 of 328

SORT items_temp BY id. v_no_more_orphans = 'X'. LOOP AT items_show WHERE parent_id NE ''. READ TABLE items_temp WITH KEY id = items_show-parent_id BINARY SEARCH TRANSPORTING NO FIELDS. IF sy-subrc NE 0. "no parent - it's an orphan CLEAR v_no_more_orphans. DELETE items_show. ENDIF. ENDLOOP. IF v_no_more_orphans = 'X'. EXIT. ENDIF. ENDDO. items_show-symbol = '+'. MODIFY items_show TRANSPORTING symbol WHERE id = v_id. ELSE. "unsuccessfull collapse - expand items_show-symbol = '-'. MODIFY items_show TRANSPORTING symbol WHERE id = v_id. LOOP AT items WHERE parent_id = v_id. "show children APPEND items TO items_show. ENDLOOP. LOOP AT items_show WHERE parent_id = v_id. "check grandchildren READ TABLE items WITH KEY parent_id = items_show-id. IF sy-subrc = 0. items_show-symbol = '+'. ELSE. items_show-symbol = ''. ENDIF. MODIFY items_show. ENDLOOP. ENDIF. ENDFORM.

* form read_from_parent_stack
FORM read_from_parent_stack CHANGING tabix LIKE sy-tabix. DESCRIBE TABLE parent_stack. CHECK sy-tfill NE 0. READ TABLE parent_stack INDEX sy-tfill. tabix = parent_stack.

* DELETE tabix_stack INDEX sy-tfill.


ENDFORM.

*& Form delete_parent_stack *&---------------------------------------------------------------------*


form delete_parent_stack. DESCRIBE TABLE parent_stack. CHECK sy-tfill NE 0. DELETE parent_stack INDEX sy-tfill. endform. " delete_parent_stack

3.3.3 Initializing date ranges on selection-options


selection-screen begin of block g1 with frame title text-000. select-options: s_docdat for vbak-erdat. "Document date selection-screen end of block g1. * Initialization * *----------------------------------------------------------------------* initialization. * Default dates to dsel screen move 'I' to s_docdat-sign. move 'BT' to s_docdat-option. move sy-datum to s_docdat-high. subtract 7 from sy-datum. move sy-datum to s_docdat-low. append s_docdat.

SELECT-OPTIONS T1 FOR MBEW-MATNR MEMORY ID MAT.

3.3.4 Report headings


top-of-page. perform top. form top. uline.

2008-09

Page 191 of 328

write: / sy-vline no-gap, (79) text-001 color col_heading intensified, 80 sy-vline, / sy-vline no-gap, (79) text-002 color col_heading intensified off, 80 sy-vline, / sy-vline no-gap, (79) text-003 color col_heading intensified off, 80 sy-vline. uline. endform.

3.3.5 Popup selection Get Filename


* See program RSSPO410 for examples of this FM DATA: returncode LIKE sy-subrc, filestring TYPE string. DATA: BEGIN OF fields OCCURS 2. INCLUDE STRUCTURE sval. DATA: END OF fields. CLEAR fields. fields-tabname = 'RLGRAP'. fields-fieldname = 'FILENAME'. fields-value = 'C:\TEST.XLS'. fields-field_attr = '00'. APPEND fields. CALL FUNCTION 'POPUP_GET_VALUES' EXPORTING POPUP_TITLE = TEXT-026 IMPORTING RETURNCODE = RETURNCODE TABLES FIELDS = fields EXCEPTIONS ERROR_IN_FIELDS = 1 OTHERS = 2. CHECK RETURNCODE EQ SPACE.

filestring = fields-value.

3.3.6 Checkboxes in reports


To put a delete button on the screen (Fcode = DELETE) with a checkbox on each line.
at user-command. case sy-ucomm. when 'DELETE'. do counter times. read line sy-index. if sy-lisel(1) = 'X'. Holds line content and sy-lisel(1) will be X when checked select single * from endif. enddo. perform write_report. sy-lsind = 0. endcase. form write_report. select * from . write: / pick as checkbox, hide: . endselect. counter = sy-dbcnt + 7. Cater for header lines endform. " WRITE_REPORT start-of-selection. set pf-status 'STD'. perform write_report.

3.3.7 List Boxes on Selection Screens


Here is a short example of using list boxes on selection screens:

2008-09 Page 192 of 328

PROGRAM ztest.
TYPE-POOLS: vrm. DATA: name TYPE vrm_id, list TYPE vrm_values, value LIKE LINE OF list. PARAMETERS: ps_parm(10) AS LISTBOX VISIBLE LENGTH 10. AT SELECTION-SCREEN OUTPUT. name = 'PS_PARM'. value-key = '1'. value-text = 'Line 1'. APPEND value TO list. value-key = '2'. value-text = 'Line 2'. APPEND value TO list. CALL FUNCTION 'VRM_SET_VALUES' EXPORTING id = name values = list. START-OF-SELECTION. WRITE: / 'Parameter:', ps_parm.

3.3.8 At line selection


DATA: FIELD_NAME(30), "Check for line selection on field T_IDOC LIKE EDIDC-DOCNUM. "Store IDoc number for line selectn * --- EVENT : AT LINE SELECTION --AT LINE-SELECTION. * Return the field that the user clicked on GET CURSOR FIELD FIELD_NAME. CASE FIELD_NAME. * Clicked on Invoice number WHEN 'ITAB_SO-INVOIC_NO'. SET PARAMETER ID 'VF' FIELD ITAB_SO-INVOIC_NO. CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN. "View Invoice * Clicked on delivery number WHEN 'ITAB_SO-DELIVERY'. SET PARAMETER ID 'VL' FIELD ITAB_SO-DELIVERY. CALL TRANSACTION 'VL03' AND SKIP FIRST SCREEN. "View delivery * Clicked on Sales Order number WHEN 'ITAB_SO-VBELN'. SET PARAMETER ID 'AUN' FIELD ITAB_SO-VBELN. CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN. "View Sales Order * Idoc # clicked WHEN 'ITAB_SO-DOCNUM'. IF ITAB_SO-DOCNUM <> ''. MOVE ITAB_SO-DOCNUM TO T_IDOC. CALL FUNCTION 'EDI_DOCUMENT_DATA_DISPLAY' "Display Idoc EXPORTING DOCNUM = T_IDOC TREE_DISPLAY = 'Y' EXCEPTIONS NO_DATA_RECORD_FOUND = 1 OTHERS = 2. IF SY-SUBRC <> 0. MESSAGE I999(B1) WITH Click on IDoc.. ENDIF. ELSE. MESSAGE I999(B1) WITH Click on IDoc.. ENDIF. ENDCASE.

3.3.9 Tabstrips on a selection screen


*&---------------------------------------------------------------------* *& Report ZTABSTRIP * *& Author: Kevin Wilson * *& HTTP://www.sapgenie.com - Portal for SAP consultants * *&---------------------------------------------------------------------* REPORT ztabstrip LINE-SIZE 120 NO STANDARD PAGE HEADING. TABLES: mara, lfa1, ekpo. *---------------------------------------------------------------------* * selection screen * *---------------------------------------------------------------------* * Define screen 101 as subscreen SELECTION-SCREEN BEGIN OF SCREEN 101 AS SUBSCREEN. SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t00. SELECT-OPTIONS matnr FOR mara-matnr. SELECTION-SCREEN END OF BLOCK b1. SELECTION-SCREEN END OF SCREEN 101.

2008-09

Page 193 of 328

* Define screen 102 as subscreen SELECTION-SCREEN BEGIN OF SCREEN 102 AS SUBSCREEN. SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t02. SELECT-OPTIONS: kunnr FOR lfa1-kunnr. SELECTION-SCREEN END OF BLOCK b2. SELECTION-SCREEN END OF SCREEN 102. * Define screen 103 as subscreen SELECTION-SCREEN BEGIN OF SCREEN 103 AS SUBSCREEN. SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-t03. PARAMETERS werks LIKE ekpo-werks. SELECTION-SCREEN END OF BLOCK b3. SELECTION-SCREEN END OF SCREEN 103. * Define tab screen SELECTION-SCREEN BEGIN OF TABBED BLOCK t1 FOR 20 LINES. SELECTION-SCREEN TAB (10) name1 USER-COMMAND ucomm1 DEFAULT SCREEN 101. SELECTION-SCREEN TAB (20) name2 USER-COMMAND ucomm2 DEFAULT SCREEN 102. SELECTION-SCREEN TAB (30) name3 USER-COMMAND ucomm3 DEFAULT SCREEN 103. SELECTION-SCREEN END OF BLOCK t1. INITIALIZATION. name1 = text-n01. "Material name2 = text-n02. "Vendor name3 = text-n03. "Plant

3.3.10

Dynamic selection screens

*--- SELECTION OPTIONS --------------------------------------SELECTION-SCREEN BEGIN OF BLOCK SO WITH FRAME TITLE TEXT-001. SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN,"Sales order number S_VBELND FOR LIKP-VBELN,"Delivery number S_VBELNI FOR VBRK-VBELN,"Invoice number S_VBELNP FOR VBKD-BSTKD."PO number SELECTION-SCREEN END OF BLOCK SO.

*--- EVENT AT SCREEN OUTPUT ------------------------------AT SELECTION-SCREEN OUTPUT. CASE SY-TCODE. WHEN 'ZEDI6'. LOOP AT SCREEN. CASE SCREEN-GROUP4. WHEN '001'. "Sales order select SCREEN-ACTIVE = '1'. "1=Active, 0=Don't display MODIFY SCREEN. WHEN '002'. "Delivery select SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display MODIFY SCREEN. WHEN '003'. "Invoice select SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display MODIFY SCREEN. WHEN '004'. "PO Select SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display MODIFY SCREEN. ENDCASE. ENDLOOP. WHEN 'ZEDI6D'. "Delivery select LOOP AT SCREEN. CASE SCREEN-GROUP4. WHEN '001'. "Sales order select SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display MODIFY SCREEN. WHEN '002'. "Delivery select SCREEN-ACTIVE = '1'. "1=Active, 0=Don't display MODIFY SCREEN. WHEN '003'. "Invoice select SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display MODIFY SCREEN. WHEN '004'. "PO Select

2008-09

Page 194 of 328

SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display MODIFY SCREEN. ENDCASE. ENDLOOP. WHEN 'ZEDI6I'. "Invoice select LOOP AT SCREEN. CASE SCREEN-GROUP4. WHEN '001'. "Sales order select SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display MODIFY SCREEN. WHEN '002'. "Delivery select SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display MODIFY SCREEN. WHEN '003'. "Invoice select SCREEN-ACTIVE = '1'. "1=Active, 0=Don't display MODIFY SCREEN. WHEN '004'. "PO Select SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display MODIFY SCREEN. ENDCASE. ENDLOOP. WHEN 'ZEDI6P'. "PO select LOOP AT SCREEN. CASE SCREEN-GROUP4. WHEN '001'. "Sales order select SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display MODIFY SCREEN. WHEN '002'. "Delivery select SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display MODIFY SCREEN. WHEN '003'. "Invoice select SCREEN-ACTIVE = '0'. "1=Active, 0=Don't display MODIFY SCREEN. WHEN '004'. "PO Select SCREEN-ACTIVE = '1'. "1=Active, 0=Don't display MODIFY SCREEN. ENDCASE. ENDLOOP. ENDCASE.

3.4

FILE PROCESSING

3.4.1 Downloading to Excel


REPORT ztablexls. ******************************************************************** * Developer : S.Srini. * Location : Chennai, * : Tamil Nadu, * : India. * Date : 3/10/2001. ******************************************************************** * TESTED - MS EXCEL 97 * NOT RECOMMENDED FOR LENGTHY OUTPUT AND LARGE DATA TABLE BROWSING ******************************************************************** TABLES: USR03,DD02L. DATA: ZX030L LIKE X030L. DATA BEGIN OF ZDFIES OCCURS 0. INCLUDE STRUCTURE DFIES. DATA END OF ZDFIES. DATA: BEGIN OF FLDITAB OCCURS 0, FLDNAME(11) TYPE C, END OF FLDITAB. DATA ITABUSR03 LIKE USR03 OCCURS 0 WITH HEADER LINE. DATA TNAME LIKE DD02L-TABNAME. SELECT * FROM USR03 INTO TABLE ITABUSR03. TNAME = 'USR03'. PERFORM GETFIELEDS. PERFORM SHOW123. 2008-09

Page 195 of 328

******************************************** FORM GETFIELEDS. CALL FUNCTION 'GET_FIELDTAB' EXPORTING LANGU = SY-LANGU ONLY = SPACE TABNAME = TNAME WITHTEXT = 'X' IMPORTING HEADER = ZX030L TABLES FIELDTAB = ZDFIES EXCEPTIONS INTERNAL_ERROR = 01 NO_TEXTS_FOUND = 02 TABLE_HAS_NO_FIELDS = 03 TABLE_NOT_ACTIV = 04. CASE SY-SUBRC. WHEN 0. LOOP AT ZDFIES. FLDITAB-FLDNAME = ZDFIES-FIELDNAME. APPEND FLDITAB. ENDLOOP. WHEN OTHERS. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO with SY-SUBRC. ENDCASE. ENDFORM. *********************************** FORM SHOW123. CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT' EXPORTING FILE_NAME = 'C:\USR03.XLS' DATA_SHEET_NAME = 'USER LIST' TABLES DATA_TAB = ITABUSR03 FIELDNAMES = FLDITAB EXCEPTIONS FILE_NOT_EXIST =1 FILENAME_EXPECTED =2 COMMUNICATION_ERROR =3 OLE_OBJECT_METHOD_ERROR = 4 OLE_OBJECT_PROPERTY_ERROR = 5 INVALID_FILENAME =6 INVALID_PIVOT_FIELDS =7 DOWNLOAD_PROBLEM =8 OTHERS = 9. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDFORM.

3.4.2 FTP a file to another server


Here is an example of how to FTP a file from the Application server to a remote server using standard SAP functions.
%&%& RDIRZKBTST32 ZKBTST32 1S 19990728 19990728 731H 001EX 1999072815590400000000000000 %&%& REPOZKBTST32 REPORT ZKBTST32 LINE-SIZE 132. *----------------------------------------------------------------------* Test SAP FTP functions

2008-09

Page 196 of 328

*----------------------------------------------------------------------DATA: BEGIN OF MTAB_DATA OCCURS 0, LINE(132) TYPE C, END OF MTAB_DATA. DATA: MC_PASSWORD(20) TYPE C, MI_KEY TYPE I VALUE 26101957, MI_PWD_LEN TYPE I, MI_HANDLE TYPE I. START-OF-SELECTION. MC_PASSWORD = 'password'. DESCRIBE FIELD MC_PASSWORD LENGTH MI_PWD_LEN. *-- FTP_CONNECT requires an encrypted password to work CALL 'AB_RFC_X_SCRAMBLE_STRING' ID 'SOURCE' FIELD MC_PASSWORD ID 'KEY' FIELD MI_KEY ID 'SCR' FIELD 'X' ID 'DESTINATION' FIELD MC_PASSWORD ID 'DSTLEN' FIELD MI_PWD_LEN. CALL FUNCTION 'FTP_CONNECT' EXPORTING USER = 'userid' PASSWORD = MC_PASSWORD HOST = 'servername' RFC_DESTINATION = 'SAPFTP' IMPORTING HANDLE = MI_HANDLE EXCEPTIONS NOT_CONNECTED = 1 OTHERS = 2. CHECK SY-SUBRC = 0. CALL FUNCTION 'FTP_COMMAND' EXPORTING HANDLE = MI_HANDLE COMMAND = 'dir' TABLES DATA = MTAB_DATA EXCEPTIONS TCPIP_ERROR = 1 COMMAND_ERROR = 2 DATA_ERROR = 3 OTHERS = 4. IF SY-SUBRC = 0. LOOP AT MTAB_DATA. WRITE: / MTAB_DATA. ENDLOOP. ELSE. * do some error checking. ENDIF. CALL FUNCTION 'FTP_DISCONNECT' EXPORTING HANDLE = MI_HANDLE EXCEPTIONS OTHERS = 1. %&%& TEXPZKBTST32 R FTP from SAP {{{ %&%& HEADZKBTST32 00000 00000000000000 0000000000000000000000 0 %&%& DOKLZKBTST32

3.4.3 DATASET
3.4.3.1 Example 1
*&---------------------------------------------------------------------* *& Form SENDTO_UNIX *&---------------------------------------------------------------------* FORM SENDTO_UNIX.

2008-09

Page 197 of 328

* open data set to transfer extract data OPEN DATASET Z_FILE_NAME FOR OUTPUT IN TEXT MODE. IF SY-SUBRC NE 0. * File could not be opened for writing WRITE: / TEXT-006. LI_WRITE_ERROR = 1. EXIT. ENDIF. LOOP AT IT_PAYR. TRANSFER IT_PAYR TO Z_FILE_NAME. ENDLOOP. * close dataset CLOSE DATASET Z_FILE_NAME. ENDFORM. " SENDTO_UNIX *&---------------------------------------------------------------------*

3.4.3.2 Example 2
OPEN DATASET OUTFILE FOR OUTPUT IN TEXT MODE. * if the timestamped file cannot be created, do not process the * input file, because the input file is deleted after processing, * and there would be no record of the data. if not sy-subrc is initial. *'ERROR opening file & for output' close dataset infile. message i033 with outfile. continue. "process next vendor's file endif. do. read dataset infile into izss7b20. case sy-subrc. when 0. transfer izss7b20 to outfile. if izss7b20-datacode = 'T'. "trailer rec perform process_one_vendor using infile. exit. "process next vendor's file endif. check izss7b20-datacode = 'D'. "data rec move-corresponding uty_vendors to ie020. move-corresponding izss7b20 to ie020. when 4. "EOF perform process_one_vendor using infile. exit. "process next vendor's file when others. *ERROR reading dataset & on & message w015 with infile sy-datum. exit. "discontinue file reads endcase. enddo. close dataset: infile, outfile. delete dataset infile.

3.4.4 WS_DOWNLOAD
*** Internal table to be downloaded data: begin of z_sales occurs 10000, kunnr like kna1-kunnr, "Customer number name1 like kna1-name1, "Name end of z_sales. data: begin of t_colnames occurs 10, name(15), "Column names for download end of t_colnames. selection-screen begin of block g2 with frame title text-001. parameters: p_print radiobutton group l1, View p_down radiobutton group l1, Download p_file like rlgrap-filename default 'C:\'. selection-screen end of block g2. *----------------------------------------------------------------------* * Selection Screen processing * *----------------------------------------------------------------------* at selection-screen on p_file.

2008-09

Page 198 of 328

* If download is checked, but no file name is entered, error if p_down eq 'X' and p_file eq space. message e000 with 'Please enter file name for download.'. endif. *** Populate Itabs for download * Column names move 'Sold-to' to t_colnames-name. append t_colnames. move 'Name' to t_colnames-name. append t_colnames. * Data move vbak-kunnr to zsales-kunnr. move kna1-name1 to zsales-name1. append zsales. * Call function module to download file call function 'WS_DOWNLOAD' exporting filename = p_file filetype = 'DAT' * col_select = 'X' tables data_tab = z_sales fieldnames = t_colnames * EXCEPTIONS * FILE_OPEN_ERROR =1 * FILE_WRITE_ERROR =2 * INVALID_FILESIZE =3 * INVALID_TABLE_WIDTH = 4 * INVALID_TYPE =5 * NO_BATCH =6 * UNKNOWN_ERROR =7 * GUI_REFUSE_FILETRANSFER = 8 * OTHERS =9 . if sy-subrc <> 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif.

3.4.5 GUI_DOWNLOAD with POPUP filename request


DATA: filestring TYPE string. DATA: BEGIN OF fields OCCURS 2. INCLUDE STRUCTURE sval. DATA: END OF fields. CLEAR fields. fields-tabname = 'RLGRAP'. fields-fieldname = 'FILENAME'. fields-value = p_file. fields-field_attr = '00'. APPEND fields. CALL FUNCTION 'POPUP_GET_VALUES' EXPORTING popup_title = text-003 IMPORTING returncode = returncode TABLES fields = fields EXCEPTIONS error_in_fields = 1 OTHERS = 2. CHECK returncode EQ space. filestring = fields-value. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = filestring write_field_separator = ','

2008-09

Page 199 of 328

TABLES data_tab = itab_data EXCEPTIONS file_write_error =1 no_batch =2 gui_refuse_filetransfer = 3 invalid_type =4 no_authority =5 unknown_error =6 header_not_allowed =7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22. IF sy-subrc <> 0. MESSAGE s999(b1) WITH 'File ' filestring ' NOT created!'. ELSE. MESSAGE s999(b1) WITH 'File ' filestring ' Created successfully!'. ENDIF. "Check on download success

3.5

MACROS

See section 6.10.8 for an example. DEFINE:


define add_comma. * add comma for selection criteria output string if offset > 0. &1_string_&2+offset(1) = ','. offset = offset + 2. endif. END-of-definition. " add_comma USAGE: add_comma &1 &2.

DEFINE:
DEFINE create_string. * loop for inclusions loop at s_&1. offset = strlen( &1_string_&2 ). c_low = s_&1-low. c_high = s_&1-high. shift c_low left deleting leading '0'. shift c_high left deleting leading '0'. shift c_low left deleting leading space. shift c_high left deleting leading space. if '&1' = 'date'. concatenate c_low+4(2) '/' c_low+6(2) '/' c_low+2(2) into c_low. if not c_high is initial. concatenate c_high+4(2) '/' c_high+6(2) '/' c_high+2(2) into c_high. endif. endif. case s_&1-option. when 'EQ'. check s_&1-sign = '&2'. add_comma &1 &2. &1_string_&2+offset = c_low. when 'NE'.

2008-09

Page 200 of 328

check s_&1-sign = '&3'. add_comma &1 &2. &1_string_&2+offset = c_low. when 'GT'. check s_&1-sign = '&2'. add_comma &1 &2. &1_string_&2+offset = 'Greater than'. offset = offset + 13. &1_string_&2+offset = c_low. when 'LE'. check s_&1-sign = '&2'. add_comma &1 &2. &1_string_&2+offset = 'Less than or equal to'. offset = offset + 22. &1_string_&2+offset = c_low. when 'LT'. check s_&1-sign = '&2'. add_comma &1 &2. &1_string_&2+offset = 'Less than'. offset = offset + 10. &1_string_&2+offset = c_low. when 'BT'. check s_&1-sign = '&2'. add_comma &1 &2. concatenate &1_string_&2 c_low '-' c_high into &1_string_&2 separated by space. when 'NB'. check s_&1-sign = '&3'. add_comma &1 &2. concatenate &1_string_&2 c_low '-' c_high into &1_string_&2 separated by space. endcase. endloop. END-OF-DEFINITION. " create_string USAGE: create_string date I E.

DEFINE:
DEFINE WRITE_STRING. if ( &1_string_I is initial and &1_string_E is initial ). &1_string_I = 'All'. endif. if not &1_string_I is initial. write: /05 h_tag, 22 'include:', 31 &1_string_I. if not &1_string_E is initial. write: /22 'exclude:', 31 &1_string_E. endif. elseif not &1_string_E is initial. write: /05 h_tag, 22 'exclude:', 31 &1_string_E. endif. END-OF-DEFINITION. USAGE: write_string date.

" write_string

3.6

SELECT STATEMENTS

3.6.1 Joins
See section 6.10.8 for an example.
START-OF-SELECTION. * ASSUMPTION: All quantities are in sales units. Since quantities * are summed to the material group level, it is assumed that all * materials within a material group have the same sales unit of * measure. select a~kunag a~vbeln a~fkdat a~bukrs a~vbtyp b~matkl b~matnr b~arktx b~fkimg b~kzwi2 b~wavwr c~name1 d~kunn2

2008-09

Page 201 of 328

into corresponding fields of table replines from vbrk as a inner join vbrp as b on a~vbeln = b~vbeln inner join kna1 as c on a~kunag = c~kunnr left outer join knvp as d on a~kunag = d~kunnr and a~vkorg = d~vkorg and a~vtweg = d~vtweg and d~spart = '71' and d~parvw = 'CO' and d~parza = '000' where a~vkorg = '7100' and a~vbtyp in r_vtyp and a~fkdat in s_date and a~kunag in s_cust and b~matkl in s_mgrp and b~autyp in r_atyp. END-OF-SELECTION.

3.6.2 For all entries

SELECT FOR ALL ENTRIES (1)


LOOP AT g_itab_vvbak INTO g_wa_vvbak. SELECT kunnr adrnr FROM kkna1 SELECT APPENDING TABLE g_itab_kkna1 WHERE kunnr = g_wa_vvbak-kunnr. ENDLOOP.

SELECT inside LOOP


Check whether driver table is empty

DESCRIBE TABLE g_itab_vvbak LINES lin. IF lin EQ 0. MESSAGE I051(bc490). EXIT. ENDIF. SORT g_itab_vvbak BY kunnr. DELETE ADJACENT DUPLICATES FROM g_itab_vvbak. SELECT kunnr adrnr FROM kkna1 INTO TABLE g_itab_kkna1 FOR ALL ENTRIES IN g_itab_vvbak WHERE kunnr = g_itab_vvbak-kunnr.

Eliminate duplicates

SAP AG 1999

SELECT FOR ALL ENTRIES

Use SELECT FOR ALL ENTRIES in order to divide SELECT statements into loops. This variant enables you to create a

JOIN between an internal table and a database table. In the example above, only the records from table KKNA1 are read that have customer numbers in the internal table g_itab_vvbak. In connection with SELECT ... FOR ALL ENTRIES the following problems occur: You cannot have an empty internal driver table. If the driver table is empty, selection is not limited. In particular, WHERE clause conditions are not evaluated if they do not refer to the internal driver table. Duplicate table entries should be deleted from the internal table before executing the SELECT... FOR ALL ENTRIES. If they are not deleted, identical data is read unnecessarily from the database.

2008-09

Page 202 of 328

The parameter rsdb/max_blocking_factor must be implemented according to SAP's database-specific


recommendations.

SELECT FOR ALL ENTRIES (2)


Object VVBAK VVBAK KKNA1 KKNA1 KKNA1 KKNA1 KKNA1 KKNA1 Oper REOPEN FETCH REOPEN FETCH REOPEN FETCH REOPEN FETCH Rec 0 100000 0 149 0 149 0 149 SELECT "KUNNR" , "ADRNR" FROM "KKNA1" WHERE "MANDT" = :A0 AND "KUNNR" = :A1 OR "MANDT" = :A2 AND "KUNNR" = :A3 OR "MANDT" = :A4 AND "KUNNR" = :A5 OR "MANDT" = :A6 AND "KUNNR" = :A7 ....

... ... ... rsdb/max_blocking_factor gives the maximum number of statements SELECT STATEMENT concatenated with OR

(Estimated Costs = ....

CONCATENATION TABLE ACESS BY INDEX ROWID KKNA1

INDEX UNIQUE SCAN KKNA1~0 TABLE ACESS BY INDEX ROWID INDEX UNIQUE SCAN
SAP AG 1999

KKNA1

KKNA1~0

The SELECT ... SELECT FOR ALL ENTRIES addition ensures that SQL statements are divided into several SELECT statements by the database interface. The individual SELECT statements are processed on the database and the results are buffered in the database interface. The database interface eliminates duplicate data records from the results set and transfers the results set to the ABAP program. Each SELECT statement processed on the database is executed as a concatenation of individual accesses (for example, index range scans or index unique scans). Concatenation is performed over the entries in the internal driver table. Since the SELECT ... FOR ALL ENTRIES may be very complex, it should not be combined with RANGES tables. The implementation of the WHERE clause for individual SELECT statements depends on the database and is realized by the database interface. The profile parameter rsdb/max_blocking_factor controls the maximum number of individual WHERE conditions that can be concatenated. SAP pre-configures this parameter according to the database. For Oracle the setting is 15.

3.7

GENERAL

3.7.1 Retrieving the email address of an SAP user


call function 'SUSR_USER_ADDRESS_READ' exporting user_name = sy-uname read_db_directly ='' importing user_address = addr3_val user_usr03 = usr03 exceptions

2008-09

Page 203 of 328

user_address_not_found = 1 others = 2. if sy-subrc = 0. call function 'ADDR_PERS_COMP_COMM_GET' exporting address_number = addr3_val-addrnumber language = sy-langu person_number = addr3_val-persnumber table_type = 'ADSMTP' tables comm_table = in_email exceptions others = 1. if sy-subrc = 0. describe table in_email lines l_tfill. if l_tfill = 0. message i140(qm). raise action_stopped. Else. ***** HERES EMAIL ADDRESS in_email-smtp endif. endif. endif.

3.7.2 Executing a program


**************************************************************** FORM downloadhtml. CALL FUNCTION 'WS_DOWNLOAD' EXPORTING filename = 'C:\TABLEVIEW.HTM' TABLES data_tab = htmlview. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDFORM. *************************************************************** FORM showhtml. CALL FUNCTION 'WS_EXECUTE' EXPORTING commandline = 'c:\tableview.htm' program = 'C:\PROGRA~1\INTERN~1\IEXPLORE.EXE'. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDFORM. ************************************************************************

3.7.3 Changing \ Creating Requirements


Use transaction V/27

3.7.4 Displaying Transaction


Set parameter ID AUN field vbak-vbeln. Call transaction VA03 and skip first screen.

3.7.5 GUI-Status
BACK %EX RW PRI %SC %SC+ P-PP+ P++

3.7.6 Document Flow


REPORT ZWSBDOCFLOW

2008-09

Page 204 of 328

LINE-SIZE 170 LINE-COUNT 65 MESSAGE-ID ZO NO STANDARD PAGE HEADING. TABLES: VBAK, VBCO6, LIKP, VBDPR. DATA: XVBFA LIKE VBFA OCCURS 1 WITH HEADER LINE. DATA: XLIKP LIKE LIKP OCCURS 1 WITH HEADER LINE. SELECT-OPTIONS: VBELN FOR VBAK-VBELN DEFAULT '0000185996' TO '0000186003'. SELECT * FROM VBAK WHERE VBELN IN VBELN. MOVE-CORRESPONDING VBAK TO VBCO6. CLEAR XVBFA. REFRESH XVBFA. CLEAR XLIKP. REFRESH XLIKP. CALL FUNCTION 'RV_ORDER_FLOW_INFORMATION' EXPORTING COMWA = VBCO6 TABLES VBFA_TAB = XVBFA. LOOP AT XVBFA WHERE ( VBTYP_N = 'J' ) AND ( VBTYP_V = 'C' ) . MOVE: XVBFA-VBELN TO XLIKP-VBELN. COLLECT XLIKP. ENDLOOP. CHECK NOT XLIKP[] IS INITIAL. CLEAR VBDPR-TDNAME. "70 chars WRITE: / VBAK-VBELN. LOOP AT XLIKP. WRITE: /5 XLIKP-VBELN. SELECT SINGLE * FROM LIKP WHERE VBELN EQ XLIKP-VBELN. CHECK SY-SUBRC IS INITIAL. WRITE: 'found'. ENDLOOP. ENDSELECT.

3.7.7 Maintaining Trailing spaces when downloading to PC


Before calling DOWNLOAD or WS_DOWNLOAD, do a perform SET_TRAIL_BLANKS(saplgrap) using 'X' To set the length of each record including your blanks add this code: perform SET_FIXLEN(saplgrap) using '0' '100'

3.7.8 Hiding ABAP Source Code


It is very easy to hide your source code in ABAP. Simply enter *@#@@[SAP] on the very first line of your program. This text should be the only text on the line. There is no easy way to get your source code back, so make sure you make a backup and save it to a local drive!

3.7.9 Where in IMG is a table configured


Use SM31, enter the table name. Click on Customizing. Enter an IMG project, or click w/o proj button. Click enter. Gives you IMG path(s) which lead to updating given table.

3.7.10

Editor Tips (*EJECT and *$*$)

2008-09

Page 205 of 328

*EJECT - If you put *EJECT at the start of a line, it will force a new page when you print your source code. This comes in real handy when you would like to have subroutines start at the top of a new page. *$*$* - By placing *$*$ at the beginning of a comment line will lock the line for editing. You are able to edit the line until you hit the enter key.

3.7.11

List of ways to transport variants

There are at least three ways that I know of that you can transport a variant for a program. When you first transport a program, all elements of a program are transported along with the source code. This includes any variants that have been created at this time After the first time a program has been transported, there are two ways to move a variant. The first method is to manually add an entry to the transport for the variant you want to move. The format of the entry is LIMU VARX xxxxxxxxName_of_the_variant where xxxxxxxx is the program name. The last method is the easiest, in that you do not have to remember any arcane codes. Go to the ABAP editor, and go to the variant screen. Under the Utilitles menu is Transport Variant. This allows you to choose the variants to transport, and the transport to put them in.

3.7.12

Checking for background processing

If you want to see if the user is running the program in the foreground: sy-subty = 4. Call type for submit otherwise it is a background submit:

3.7.12.1 Example
* Display the GUI status if run in foreground otherwise dont if sy-subty = 4. set pf-status 'GH'. endif.

2008-09

Page 206 of 328

CHAPTER 4 WORKFLOW PROGRAMS


4.1 VIEWING PARTICULAR USERS INBOX
REPORT z_view_workflow_inbox. DATA itab_list LIKE swkwlhead OCCURS 0 WITH HEADER LINE. DATA: field_name(30), "Check for line selection on field t_wi_id like SWWWIHEAD-WI_ID, t_uname like sy-uname. * 'Select User ID and execute to view inbox' SELECTION-SCREEN COMMENT 5(50) text-001 MODIF ID sc1. * 'User ID Selection' SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-002. PARAMETERS: p_uname LIKE USR02-BNAME DEFAULT sy-uname OBLIGATORY. SELECTION-SCREEN END OF BLOCK b1. * Sort Criteria SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-003. PARAMETERS: p_sort1 RADIOBUTTON GROUP sor1, p_sort2 RADIOBUTTON GROUP sor1, p_sort3 RADIOBUTTON GROUP sor1, p_sort4 RADIOBUTTON GROUP sor1, p_sort5 RADIOBUTTON GROUP sor1, p_sort6 RADIOBUTTON GROUP sor1. SELECTION-SCREEN END OF BLOCK b2. *----------------------------------------------------------------------* * Initialization *----------------------------------------------------------------------* INITIALIZATION. PERFORM update_sel_screen_attributes. TOP-OF-PAGE. FORMAT COLOR COL_HEADING. WRITE 'Woritem ID'. WRITE AT 15 'Description'. WRITE AT 135 'Date'. WRITE AT 146 'Time'. WRITE AT 155 'Parent ID'. WRITE AT 168 'Task'. WRITE AT 183 'Status'. FORMAT COLOR OFF. *----------------------------------------------------------------------* * Start of Selection *----------------------------------------------------------------------* START-OF-SELECTION. REFRESH itab_list. t_uname = p_uname. CALL FUNCTION 'SWK_LOCAL_INBOX_GET' EXPORTING user_id = t_uname user_langu = 'E' TABLES wi_list = itab_list. READ TABLE itab_list INDEX 1. IF sy-subrc = 0. IF p_sort1 = 'X'. SORT itab_list BY wi_id. ELSEIF p_sort2 = 'X'. SORT itab_list BY wi_text. ELSEIF p_sort3 = 'X'. SORT itab_list BY wi_cd wi_ct. ELSEIF p_sort4 = 'X'. SORT itab_list BY wi_chckwi.

2008-09

Page 207 of 328

ELSEIF p_sort5 = 'X'. SORT itab_list BY wi_rh_task. ELSEIF p_sort6 = 'X'. SORT itab_list BY wi_stat. ENDIF. ENDIF. LOOP AT itab_list. WRITE: / itab_list-wi_id, itab_list-wi_text, itab_list-wi_cd, itab_list-wi_ct, itab_list-wi_chckwi, itab_list-wi_rh_task, itab_list-wi_stat. HIDE itab_list-wi_id. HIDE itab_list-wi_rh_task. ENDLOOP. IF sy-subrc <> 0. MESSAGE i999(b1) WITH 'No Workflow items found in the inbox of ' p_uname. ELSE. WRITE: / '***', sy-tfill, 'entries ***'. ENDIF. END-OF-SELECTION. AT LINE-SELECTION. * Return the field that the user clicked on GET CURSOR FIELD field_name. CASE field_name. WHEN 'ITAB_LIST-WI_ID'. IF itab_list-wi_id IS INITIAL. MESSAGE i999(b1) WITH 'Please double click a line on the report!'. ELSE. t_wi_id = itab_list-wi_id. CALL FUNCTION 'SWL_WI_DISPLAY' EXPORTING wi_id = t_wi_id extended_display ='X' EXCEPTIONS read_failed = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDIF. WHEN 'ITAB_LIST-WI_RH_TASK'. IF itab_list-wi_rh_task IS INITIAL. MESSAGE i999(b1) WITH 'Please double click a line on the report!'. ELSE. CALL FUNCTION 'SWL_WI_DISPLAY_TASK' EXPORTING wi_id = itab_list-wi_id. CLEAR itab_list-wi_rh_task. ENDIF. WHEN OTHERS. MESSAGE i999(b1) WITH 'Field not selectable!'. ENDCASE. CLEAR: itab_list-wi_id, itab_list-wi_rh_task. *&---------------------------------------------------------------------* *& Form update_sel_screen_attributes *&---------------------------------------------------------------------* FORM update_sel_screen_attributes. LOOP AT SCREEN. IF screen-group1 = 'SC1'. screen-intensified = '1'. MODIFY SCREEN. ENDIF. ENDLOOP. ENDFORM. " update_sel_screen_attributes

2008-09

Page 208 of 328

CHAPTER 5 OBJECT PROGRAMMING


5.1 5.2 SAP DEMO REPORTS TREE REPORTS
Go to SE80 -> Environment > Reuse Library

CLASS DEFINITION
CLASS lcl_application DEFINITION. PUBLIC SECTION. METHODS: handle_node_double_click FOR EVENT node_double_click OF cl_gui_list_tree IMPORTING node_key, handle_expand_no_children FOR EVENT expand_no_children OF cl_gui_list_tree IMPORTING node_key, handle_item_double_click FOR EVENT item_double_click OF cl_gui_list_tree IMPORTING node_key item_name, handle_button_click FOR EVENT button_click OF cl_gui_list_tree IMPORTING node_key item_name, handle_link_click FOR EVENT link_click OF cl_gui_list_tree IMPORTING node_key item_name, handle_checkbox_change FOR EVENT checkbox_change OF cl_gui_list_tree IMPORTING node_key item_name checked. ENDCLASS.

CLASS IMPLEMENTATION
CLASS lcl_application IMPLEMENTATION. METHOD handle_node_double_click. " this method handles the node double click event of the tree " control instance " show the key of the double clicked node in a dynpro field READ TABLE itab_data WITH KEY node_key = node_key INTO wa_data. * You now have the data to do anything you wish * . ENDMETHOD. METHOD handle_item_double_click. " this method handles the item double click event of the tree " control instance. You have variables node_key and item_name " show the key of the node and the name of the item " of the double clicked item in a dynpro field READ TABLE itab_data WITH KEY node_key = node_key INTO wa_data. * You now have the data to do anything you wish * . ENDMETHOD. METHOD handle_link_click. " this method handles the link click event of the tree

2008-09

Page 209 of 328

" control instance " show the key of the node and the name of the item " of the clicked link in a dynpro field g_node_key = node_key. g_item_name = item_name. ENDMETHOD. METHOD handle_button_click. " this method handles the button click event of the tree " control instance " show the key of the node and the name of the item " of the clicked button in a dynpro field g_node_key = node_key. g_item_name = item_name. ENDMETHOD. METHOD handle_checkbox_change. " this method handles the checkbox_change event of the tree " control instance " show the key of the node and the name of the item " of the clicked checkbox in a dynpro field g_node_key = node_key. g_item_name = item_name. ENDMETHOD. METHOD handle_expand_no_children. DATA: node_table TYPE treev_ntab, node TYPE treev_node, item_table TYPE item_table_type, item TYPE mtreeitm. * show the key of the expanded node in a dynpro field g_node_key = node_key. IF node_key = 'Child2'. "#EC NOTEXT * add the children for node with key 'Child2' * Node with key 'New3' CLEAR node. node-node_key = 'New3'. "#EC NOTEXT node-relatkey = 'Child2'. node-relatship = cl_gui_list_tree=>relat_last_child. APPEND node TO node_table. * Node with key 'New4' CLEAR node. node-node_key = 'New4'. "#EC NOTEXT node-relatkey = 'Child2'. node-relatship = cl_gui_list_tree=>relat_last_child. APPEND node TO node_table. * Items of node with key 'New3' CLEAR item. item-node_key = 'New3'. item-item_name = '1'. item-class = cl_gui_list_tree=>item_class_text. item-length = 11. item-usebgcolor = 'X'. " item-text = 'SAPTROX1'. APPEND item TO item_table. CLEAR item. item-node_key = 'New3'. item-item_name = '2'.

2008-09

Page 210 of 328

item-class = cl_gui_list_tree=>item_class_text. item-alignment = cl_gui_list_tree=>align_auto. item-font = cl_gui_list_tree=>item_font_prop. item-text = 'Comment to SAPTROX1'. APPEND item TO item_table. * Items of node with key 'New4' CLEAR item. item-node_key = 'New4'. item-item_name = '1'. item-class = cl_gui_list_tree=>item_class_text. item-length = 11. item-usebgcolor = 'X'. " item-text = 'SAPTRIXTROX'. APPEND item TO item_table. CLEAR item. item-node_key = 'New4'. item-item_name = '2'. item-class = cl_gui_list_tree=>item_class_text. item-alignment = cl_gui_list_tree=>align_auto. item-font = cl_gui_list_tree=>item_font_prop. item-text = 'Comment to SAPTRIXTROX'. APPEND item TO item_table. ENDIF. CALL METHOD g_tree->add_nodes_and_items EXPORTING node_table = node_table item_table = item_table item_table_structure_name = 'MTREEITM' EXCEPTIONS failed = 1 cntl_system_error = 3 error_in_tables = 4 dp_error = 5 table_structure_name_not_found = 6. IF sy-subrc <> 0. MESSAGE a000(tree_control_msg). ENDIF. ENDMETHOD. ENDCLASS.

"#EC NOTEXT

"#EC NOTEXT

DATA DEFINITIONS
* Type definitions types: begin of itab_type, folder type flag, node_key type mtreeitm, relatkey type tv_nodekey, type like qmel-QMART, qmnum like qmel-qmnum, qwrnum like qmel-qwrnum, end of itab_type. * Data Definitions data: okcode like sy-ucomm, itab_data type itab_type occurs 0, wa_data type itab_type. * Tree list definitions class lcl_application definition deferred. class cl_gui_cfw definition load. * CAUTION: MTREEITM is the name of the item structure which must * be defined by the programmer. DO NOT USE MTREEITM! types: item_table_type like standard table of mtreeitm with default key.

2008-09

Page 211 of 328

SELECTION SCREEN
*----------------------------------------------------------------------* * Start of Selection *----------------------------------------------------------------------* START-OF-SELECTION. REFRESH: itab_data. PERFORM create_input_table TABLES itab_data. * create the application object * this object is needed to handle the ABAP Objects Events of Controls CREATE OBJECT g_application. CALL SCREEN 2000. "Tree Report END-OF-SELECTION.

SUBROUTINES
*&---------------------------------------------------------------------* *& Form update_sel_screen_attributes *&---------------------------------------------------------------------* FORM update_sel_screen_attributes. LOOP AT SCREEN. IF screen-group1 = 'SC1'. screen-intensified = '1'. MODIFY SCREEN. ENDIF. ENDLOOP. ENDFORM. " update_sel_screen_attributes *&---------------------------------------------------------------------* *& Form create_and_init_tree *&---------------------------------------------------------------------* FORM create_and_init_tree. DATA: node_table TYPE treev_ntab, item_table TYPE item_table_type, events TYPE cntl_simple_events, event TYPE cntl_simple_event. * create a container for the tree control CREATE OBJECT g_custom_container EXPORTING " the container is linked to the custom control with the " name 'TREE_CONTAINER' on the dynpro container_name = 'TREE_CONTAINER' EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5. IF sy-subrc <> 0. MESSAGE a000(tree_control_msg). ENDIF. * create a list tree control CREATE OBJECT g_tree EXPORTING parent = g_custom_container node_selection_mode = cl_gui_list_tree=>node_sel_mode_single item_selection = 'X' with_headers ='' EXCEPTIONS cntl_system_error =1 create_error =2 failed =3 illegal_node_selection_mode = 4

2008-09

Page 212 of 328

lifetime_error = 5. IF sy-subrc <> 0. MESSAGE a000(tree_control_msg). ENDIF. * define the events which will be passed to the backend " node double click event-eventid = cl_gui_list_tree=>eventid_node_double_click. event-appl_event = 'X'. " APPEND event TO events. " item double click event-eventid = cl_gui_list_tree=>eventid_item_double_click. event-appl_event = 'X'. APPEND event TO events. " expand no children event-eventid = cl_gui_list_tree=>eventid_expand_no_children. event-appl_event = 'X'. APPEND event TO events. " link click event-eventid = cl_gui_list_tree=>eventid_link_click. event-appl_event = 'X'. APPEND event TO events. " button click event-eventid = cl_gui_list_tree=>eventid_button_click. event-appl_event = 'X'. APPEND event TO events. " checkbox change event-eventid = cl_gui_list_tree=>eventid_checkbox_change. event-appl_event = 'X'. APPEND event TO events. CALL METHOD g_tree->set_registered_events EXPORTING events = events EXCEPTIONS cntl_error =1 cntl_system_error =2 illegal_event_combination = 3. IF sy-subrc <> 0. MESSAGE a000(tree_control_msg). ENDIF. * assign event handlers in the application class to each desired event SET HANDLER g_application->handle_node_double_click FOR g_tree. SET HANDLER g_application->handle_item_double_click FOR g_tree. SET HANDLER g_application->handle_expand_no_children FOR g_tree. SET HANDLER g_application->handle_link_click FOR g_tree. SET HANDLER g_application->handle_button_click FOR g_tree. SET HANDLER g_application->handle_checkbox_change FOR g_tree. * add some nodes to the tree control * NOTE: the tree control does not store data at the backend. If an * application wants to access tree data later, it must store the * tree data itself. PERFORM build_node_and_item_table USING node_table item_table. CALL METHOD g_tree->add_nodes_and_items EXPORTING node_table = node_table item_table = item_table item_table_structure_name = 'MTREEITM'

2008-09

Page 213 of 328

EXCEPTIONS failed = 1 cntl_system_error = 3 error_in_tables = 4 dp_error = 5 table_structure_name_not_found = 6. IF sy-subrc <> 0. MESSAGE a000(tree_control_msg). ENDIF. ENDFORM. " create_and_init_tree *&---------------------------------------------------------------------* *& Form build_node_and_item_table *&---------------------------------------------------------------------* FORM build_node_and_item_table USING node_table TYPE treev_ntab item_table TYPE item_table_type. DATA: node TYPE treev_node, item TYPE mtreeitm. * Build the node and item table. LOOP AT itab_data INTO wa_data. CLEAR node. node-node_key = wa_data-node_key. node-relatkey = wa_data-relatkey. node-isfolder = 'X'. IF wa_data-relatkey IS INITIAL. CLEAR: node-relatship, node-exp_image, node-expander. node-hidden = ' '. node-disabled = ' '. ELSE. node-relatship = cl_gui_list_tree=>relat_last_child. ENDIF. APPEND node TO node_table. * Update Items CLEAR item. item-node_key = wa_data-node_key. item-item_name = '1'. item-length = 4. item-class = cl_gui_list_tree=>item_class_text. " Text Item item-alignment = cl_gui_list_tree=>align_auto. item-font = cl_gui_list_tree=>item_font_prop. item-usebgcolor = 'X'. item-text = wa_data-type. APPEND item TO item_table. CLEAR item. item-node_key = wa_data-node_key. item-item_name = '2'. item-length = 20. item-class = cl_gui_list_tree=>item_class_text. " Text Item item-alignment = cl_gui_list_tree=>align_auto. item-font = cl_gui_list_tree=>item_font_prop. item-text = wa_data-qmnum. APPEND item TO item_table. ENDLOOP. ENDFORM. " build_node_and_item_table *&---------------------------------------------------------------------* *& Form create_input_table *&---------------------------------------------------------------------*

2008-09

Page 214 of 328

FORM create_input_table TABLES p_itab_data LIKE itab_data. DATA: t_counter(4) TYPE n, t_parent(4) TYPE c, t_parent1(4) TYPE c, t_qmnum LIKE qmel-qmnum, t_qmnum1 LIKE qmel-qmnum. t_counter = 1. CLEAR: t_parent, t_parent1. IF NOT s_ecr IS INITIAL. SELECT qmnum qmart qwrnum INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum) FROM qmel WHERE qmnum IN s_ecr AND qmart = 'C3'. CLEAR: wa_data. wa_data-folder = 'X'. wa_data-node_key = t_counter. wa_data-relatkey = t_parent. wa_data-type = qmel-qmart. wa_data-qmnum = qmel-qmnum. wa_data-qwrnum = qmel-qwrnum. APPEND wa_data TO p_itab_data. t_parent = t_counter. ADD 1 TO t_counter. * Check for ECNs attached to this ECR SELECT qmnum qmart qwrnum INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum) FROM qmel WHERE qwrnum = qmel-qmnum AND qmart = 'C4'. CLEAR: wa_data. wa_data-folder = 'X'. wa_data-node_key = t_counter. wa_data-relatkey = t_parent. wa_data-type = qmel-qmart. wa_data-qmnum = qmel-qmnum. wa_data-qwrnum = qmel-qwrnum. APPEND wa_data TO p_itab_data. t_parent1 = t_counter. ADD 1 TO t_counter. * Check for ECOs attached to this ECN SELECT qmnum qmart qwrnum INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum) FROM qmel WHERE qwrnum = qmel-qmnum AND qmart = 'C5'. CLEAR: wa_data. wa_data-folder = 'X'. wa_data-node_key = t_counter. wa_data-relatkey = t_parent1. wa_data-type = qmel-qmart. wa_data-qmnum = qmel-qmnum. wa_data-qwrnum = qmel-qwrnum. APPEND wa_data TO p_itab_data. ADD 1 TO t_counter. ENDSELECT. CLEAR: t_parent1.

2008-09

Page 215 of 328

ENDSELECT. CLEAR: t_parent. ENDSELECT. CLEAR: t_parent, t_parent1. ENDIF. IF NOT s_ecn IS INITIAL. SELECT qmnum qmart qwrnum INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum) FROM qmel WHERE qmnum IN s_ecn AND qmart = 'C4'. CLEAR: wa_data. wa_data-folder = 'X'. wa_data-node_key = t_counter. wa_data-relatkey = t_parent1. wa_data-type = qmel-qmart. wa_data-qmnum = qmel-qmnum. wa_data-qwrnum = qmel-qwrnum. APPEND wa_data TO p_itab_data. t_parent1 = t_counter. ADD 1 TO t_counter. t_qmnum = qmel-qmnum. * Is an ECR attached? IF NOT qmel-qwrnum IS INITIAL. SELECT SINGLE qmnum qmart qwrnum INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum) FROM qmel WHERE qmnum = qmel-qwrnum. IF sy-subrc = 0. CLEAR: wa_data. wa_data-folder = 'X'. wa_data-node_key = t_counter. wa_data-relatkey = t_parent1. wa_data-type = qmel-qmart. wa_data-qmnum = qmel-qmnum. wa_data-qwrnum = qmel-qwrnum. APPEND wa_data TO p_itab_data. ADD 1 TO t_counter. ENDIF. ENDIF. qmel-qmnum = t_qmnum. * Check for ECOs attached to this ECN SELECT qmnum qmart qwrnum INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum) FROM qmel WHERE qwrnum = qmel-qmnum AND qmart = 'C5'. CLEAR: wa_data. wa_data-folder = 'X'. wa_data-node_key = t_counter. wa_data-relatkey = t_parent1. wa_data-type = qmel-qmart. wa_data-qmnum = qmel-qmnum. wa_data-qwrnum = qmel-qwrnum. APPEND wa_data TO p_itab_data. ADD 1 TO t_counter. ENDSELECT. CLEAR: t_parent1. ENDSELECT.

2008-09

Page 216 of 328

CLEAR: t_parent, t_parent1. ENDIF. IF NOT s_eco IS INITIAL. SELECT qmnum qmart qwrnum INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum) FROM qmel WHERE qmnum IN s_eco AND qmart = 'C5'. CLEAR: wa_data. wa_data-folder = 'X'. wa_data-node_key = t_counter. wa_data-relatkey = t_parent. wa_data-type = qmel-qmart. wa_data-qmnum = qmel-qmnum. wa_data-qwrnum = qmel-qwrnum. APPEND wa_data TO p_itab_data. t_parent = t_counter. ADD 1 TO t_counter. t_qmnum = qmel-qmnum. IF NOT qmel-qwrnum IS INITIAL. * Check for ECNs attached to this ECO SELECT qmnum qmart qwrnum INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum) FROM qmel WHERE qmnum = qmel-qwrnum AND qmart = 'C4'. CLEAR: wa_data. wa_data-folder = 'X'. wa_data-node_key = t_counter. wa_data-relatkey = t_parent. wa_data-type = qmel-qmart. wa_data-qmnum = qmel-qmnum. wa_data-qwrnum = qmel-qwrnum. APPEND wa_data TO p_itab_data. t_parent1 = t_counter. ADD 1 TO t_counter. t_qmnum1 = qmel-qmnum. IF NOT qmel-qwrnum IS INITIAL. * Check for ECRs attached to this ECN SELECT qmnum qmart qwrnum INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum) FROM qmel WHERE qmnum = qmel-qwrnum AND qmart = 'C3'. CLEAR: wa_data. wa_data-folder = 'X'. wa_data-node_key = t_counter. wa_data-relatkey = t_parent1. wa_data-type = qmel-qmart. wa_data-qmnum = qmel-qmnum. wa_data-qwrnum = qmel-qwrnum. APPEND wa_data TO p_itab_data. ADD 1 TO t_counter. ENDSELECT. qmel-qmnum = t_qmnum1. CLEAR: t_parent1. ENDIF. ENDSELECT. qmel-qmnum = t_qmnum.

2008-09

Page 217 of 328

CLEAR: t_parent1. ENDIF. ENDSELECT. CLEAR: t_parent, t_parent1. ENDIF. ENDFORM. " create_input_table

PBO Screen 2000


*&---------------------------------------------------------------------* *& Module STATUS_2000 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module STATUS_2000 output. SET PF-STATUS 'ZCM_2000'. SET TITLEBAR 'ZCM_2000'. endmodule. " STATUS_2000 OUTPUT *&---------------------------------------------------------------------* *& Module init_data_2000 OUTPUT *&---------------------------------------------------------------------* module init_data_2000 output. if g_tree is initial. " The Tree Control has not been created yet. " Create a Tree Control and insert nodes into it. perform create_and_init_tree. endif. endmodule. " init_data_2000 OUTPUT

PAI Screen 2000


*&---------------------------------------------------------------------* *& Module USER_COMMAND_2000 INPUT *&---------------------------------------------------------------------* module user_command_2000 input. data: return_code type i. * CL_GUI_CFW=>DISPATCH must be called if events are registered * that trigger PAI * this method calls the event handler method of an event call method cl_gui_cfw=>dispatch importing return_code = return_code. if return_code <> cl_gui_cfw=>rc_noevent. " a control event occured => exit PAI clear okcode. exit. endif. case okcode. when 'RETURN'. " Finish program if not g_custom_container is initial. " destroy tree container (detroys contained tree control, too) call method g_custom_container->free exceptions cntl_system_error = 1 cntl_error = 2. if sy-subrc <> 0. message a000(TREE_CONTROL_MSG). endif. clear g_custom_container. clear g_tree. endif. leave to screen 0. endcase. clear okcode.

2008-09

Page 218 of 328

endmodule.

" USER_COMMAND_2000 INPUT

SCREEN 2000

5.3

ALV GRID CONTROL

See Development Class SLIS for example programs including drag and drop functionality.

5.3.1 Adding custom buttons on ALV grid controls


DATA
* Predefine a local class for event handling to allow the * declaration of a reference variable before the class is defined. CLASS lcl_event_receiver DEFINITION DEFERRED. DATA: custom_container1 TYPE REF TO cl_gui_custom_container, cont_on_main TYPE scrfname VALUE 'ALV_GRID', grid1 TYPE REF TO cl_gui_alv_grid, event_receiver TYPE REF TO lcl_event_receiver, okcode LIKE sy-ucomm. DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, gt_fieldcat1 TYPE lvc_t_fcat, gs_layout TYPE slis_layout_alv, gs_layout1 TYPE lvc_s_layo, gs_layout2 type disvariant, gs_print TYPE slis_print_alv, gt_sort TYPE slis_t_sortinfo_alv,

2008-09

Page 219 of 328

gt_sp_group TYPE slis_t_sp_group_alv, gt_events TYPE slis_t_event, gt_list_top_of_page TYPE slis_t_listheader. DATA:t_out TYPE TABLE OF zstruct, t_out_wa LIKE zstruct. **************************************************************** * LOCAL CLASSES: Definition **************************************************************** *=============================================================== * class lcl_event_receiver: local class to * define and handle own functions. * * Definition: * ~~~~~~~~~~~ CLASS lcl_event_receiver DEFINITION. PUBLIC SECTION. METHODS: handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object e_interactive, handle_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm. PRIVATE SECTION. ENDCLASS. **************************************************************** * LOCAL CLASSES: Implementation **************************************************************** *=============================================================== * class lcl_event_receiver (Implementation) * * CLASS lcl_event_receiver IMPLEMENTATION. METHOD handle_toolbar. * 2.In event handler method for event TOOLBAR: Append own functions * by using event parameter E_OBJECT. DATA: ls_toolbar TYPE stb_button. *.................................................................... * E_OBJECT of event TOOLBAR is of type REF TO CL_ALV_EVENT_TOOLBAR_SET. * This class has got one attribute, namly MT_TOOLBAR, which * is a table of type TTB_BUTTON. One line of this table is * defined by the Structure STB_BUTTON (see data deklaration above). * * A remark to the flag E_INTERACTIVE: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * 'e_interactive' is set, if this event is raised due to * the call of 'set_toolbar_interactive' by the user. * You can distinguish this way if the event was raised * by yourself or by ALV * (e.g. in method 'refresh_table_display'). * An application of this feature is still unknown... :-) * append a separator to normal toolbar CLEAR ls_toolbar. MOVE 3 TO ls_toolbar-butn_type. APPEND ls_toolbar TO e_object->mt_toolbar. * append an icon to show booking table

2008-09

Page 220 of 328

CLEAR ls_toolbar. MOVE 'COMMENT' TO ls_toolbar-function. MOVE icon_annotation TO ls_toolbar-icon. MOVE 'Insert Comment'(001) TO ls_toolbar-quickinfo. MOVE 'Notes'(004) TO ls_toolbar-text. MOVE ' ' TO ls_toolbar-disabled. APPEND ls_toolbar TO e_object->mt_toolbar. MOVE 'MATNR' TO ls_toolbar-function. MOVE icon_material TO ls_toolbar-icon. MOVE 'View Material'(002) TO ls_toolbar-quickinfo. MOVE 'Material'(003) TO ls_toolbar-text. MOVE ' ' TO ls_toolbar-disabled. APPEND ls_toolbar TO e_object->mt_toolbar. ENDMETHOD. *------------------------------------------------------------------METHOD handle_user_command. * 3.In event handler method for event USER_COMMAND: Query your * function codes defined in step 2 and react accordingly. DATA: lt_rows TYPE lvc_t_row. CASE e_ucomm. WHEN 'COMMENT'. CALL METHOD grid1->get_selected_rows IMPORTING et_index_rows = lt_rows. CALL METHOD cl_gui_cfw=>flush. IF sy-subrc NE 0. * add your handling, for example CALL FUNCTION 'POPUP_TO_INFORM' EXPORTING titel = g_repid txt2 = sy-subrc txt1 = 'Error in Flush'(500). ELSE. PERFORM get_comment TABLES lt_rows. Perform action ENDIF. WHEN 'MATNR'. CALL METHOD grid1->get_selected_rows IMPORTING et_index_rows = lt_rows. CALL METHOD cl_gui_cfw=>flush. IF sy-subrc NE 0. * add your handling, for example CALL FUNCTION 'POPUP_TO_INFORM' EXPORTING titel = g_repid txt2 = sy-subrc txt1 = 'Error in Flush'(500). ELSE. READ TABLE lt_rows INDEX 1. IF sy-subrc = 0. READ TABLE t_out INTO t_out_wa INDEX lt_rows-index. IF sy-subrc = 0. SET PARAMETER ID 'MAT' FIELD t_out_wa-matnr. CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN. "View Material ELSE. MESSAGE i999(b1) WITH 'Entry not found!'. ENDIF. ELSE. MESSAGE i999(b1) WITH 'Please select a line first!'. ENDIF.

2008-09

Page 221 of 328

ENDIF. ENDCASE. ENDMETHOD. "handle_user_command *----------------------------------------------------------------ENDCLASS. * * lcl_event_receiver (Implementation) *===================================================================

PBO
process before output. MODULE STATUS_2000. module init_data. module create_container. *&---------------------------------------------------------------------* *& Module create_container OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module create_container output. if custom_container1 is initial. * create a custom container control for our ALV Control create object custom_container1 exporting container_name = cont_on_main exceptions cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5. if sy-subrc ne 0. * add your handling, for example call function 'POPUP_TO_INFORM' exporting titel = g_repid txt2 = sy-subrc txt1 = 'The control could not be created'(001). endif. * create an instance of alv control create object grid1 exporting i_parent = custom_container1. * allow to select single lines - Multilines = A gs_layout1-sel_mode = 'B'. t_out[] = t_out_mat[]. gt_fieldcat1[] = gt_fieldcat[]. gs_layout2-report = sy-repid. * IS_VARIANT, I_SAVE and I_DEFAULT are used for maintaining variants * for the users. The setting 'U' allows a user to create their own * variant and save it. The setting 'X' enables the ZBOM report to fire * up the report with the default setting for that user. * IS_VARIANT just needs to contain the report name. * ZSTRUCT needs to be a structure or table in the data dictionary. * The data elements are used for the column headings of your table control. * T_OUT is your table for data. call method grid1->set_table_for_first_display exporting i_structure_name = 'ZSTRUCT' is_variant = gs_layout2 i_save = 'U' "User may save variant i_default = 'X' "Load variant automatically

2008-09

Page 222 of 328

is_layout = gs_layout1 changing it_outtab = t_out. * ->Create Object to receive events and link them to handler methods. * When the ALV Control raises the event for the specified instance * the corresponding method is automatically called. * create object event_receiver. set handler event_receiver->handle_user_command for grid1. set handler event_receiver->handle_toolbar for grid1. * 4.Call method 'set_toolbar_interactive' to raise event TOOLBAR. call method grid1->set_toolbar_interactive. endif. call method cl_gui_control=>set_focus exporting control = grid1. endmodule. " create_container OUTPUT

5.3.2 Highlight lines


* Highlight lines declarations types: begin of highlight_line, from type i, to type i, end of highlight_line. data: itab_highlight type table of highlight_line, wa_highlight type highlight_line. data: t_true type i value 1. * Highlight the name line loop at itab_highlight into wa_highlight. call method editor2->highlight_lines exporting from_line = wa_highlight-from highlight_mode = t_true to_line = wa_highlight-to exceptions has_no_effect =1 error_cntl_call_method = 2 invalid_parameter =3 others =4 . if sy-subrc <> 0. message i003 with 'EDITOR2' 'highlight_lines' sy-subrc. endif. endloop.

5.3.3 First line visible


* Sets the top line of the table as the first visible line * otherwise only the last line is displayed and you need to * scroll up to see the other comments. call method editor2->set_first_visible_line exporting line =1 exceptions error_cntl_call_method = 1 others = 2. if sy-subrc <> 0. message i003 with 'EDITOR2' 'set_first_visible_line' sy-subrc. endif.

5.3.4 Read only text box


* Set the history area as read only call method editor2->set_readonly_mode exporting readonly_mode = t_true

2008-09

Page 223 of 328

exceptions error_cntl_call_method = 1 others = 2. if sy-subrc <> 0. message i003 with 'EDITOR2' 'set_readonly_mode' sy-subrc. endif.

5.3.5 Entering text


PBO
if editor1 is initial * create control container create object textedit_custom_container1 exporting container_name = 'TEXTEDITOR1' exceptions cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5. if sy-subrc ne 0. * add your handling endif. * create calls constructor, which initializes, creats and links * a TextEdit Control create object editor1 exporting parent = textedit_custom_container1 wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position wordwrap_position = line_length wordwrap_to_linebreak_mode = cl_gui_textedit=>true exceptions others = 1. endif. End of EDITOR1 is initial SELECT * FROM znotes INTO CORRESPONDING FIELDS OF wa_mytable where qmnum = zpcr-qmnum. append wa_mytable to mytable1. ENDSELECT. CALL METHOD editor1->set_selected_text_as_r3table EXPORTING table = mytable1 EXCEPTIONS error_dp =1 error_dp_create =2 OTHERS = 3. IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.

PAI on SAVE
refresh: mytable1. CALL METHOD editor1->get_text_as_r3table IMPORTING table = mytable1 EXCEPTIONS OTHERS = 1.

DATA
constants: line_length type i value 52. *** Variables

2008-09

Page 224 of 328

data: editor1 type ref to cl_gui_textedit, * reference to custom container: necessary to bind TextEdit Control textedit_custom_container1 type ref to cl_gui_custom_container. * define table type for data exchange types: begin of mytable_line, line(line_length) type c, end of mytable_line. * table to exchange text types: mytable type standard table of mytable_line initial size 0. data: mytable1 type mytable, wa_mytable type mytable_line. Screen

Box with custom control texteditor1 in it.

2008-09

Page 225 of 328

CHAPTER 6 IDOC PROGRAMMING


6.1 CREATING AN IDOC
* Creating records clear e1edp20. idocdata-segnam = 'E1EDP20'. e1edp20-edatu = ie020-sched_deliv_date. e1edp20-wmeng = ie020-sched_qty. idocdata-sdata = e1edp20. idocdata-tabnam = idocdata-segnam. seg_num = seg_num + 1. idocdata-segnum = seg_num. shift idocdata-segnum left deleting leading space. append idocdata. clear idocdata. * Once IDoc detail is created

CALL FUNCTION 'INBOUND_IDOC_PROCESS' TABLES IDOC_CONTROL = iedidc IDOC_DATA = idocdata. commit work.

6.2

SENDING AN IDOC

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' EXPORTING master_idoc_control = s_zordrsp_edidc obj_type = 'BUS2032' TABLES communication_idoc_control = itab_zordrsp_edidc master_idoc_data = itab_zordrsp_edidd EXCEPTIONS error_in_idoc_control =1 error_writing_idoc_status =2 error_in_idoc_data =3 sending_logical_system_unknown = 4 OTHERS = 5. IF sy-subrc <> 0. return_code = 2. WRITE: /1 'ZORDRSP IDoc not created'. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. WRITE: /1 'IDoc: ', itab_zordrsp_edidc-docnum, ' created'. HIDE itab_zordrsp_edidc-docnum. ENDIF.

6.3

CHANGING AN IDOC

CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_EDIT' EXPORTING DOCUMENT_NUMBER = iedidc-docnum IMPORTING IDOC_CONTROL = IEDIDC TABLES IDOC_DATA = idocdata EXCEPTIONS DOCUMENT_FOREIGN_LOCK = 01 DOCUMENT_NOT_EXIST = 02 DOCUMENT_NUMBER_INVALID = 03 ERROR_MESSAGE = 04 OTHERS = 05. CALL FUNCTION 'EDI_DOCUMENT_STATUS_SET' EXPORTING DOCUMENT_NUMBER = iedidc-DOCNUM

2008-09

Page 226 of 328

IDOC_STATUS = edi_ds IMPORTING IDOC_CONTROL = iedidc EXCEPTIONS DOCUMENT_NUMBER_INVALID =1 OTHER_FIELDS_INVALID =2 STATUS_INVALID =3 OTHERS =4 . CALL FUNCTION 'EDI_DOCUMENT_CLOSE_EDIT' EXPORTING DOCUMENT_NUMBER = iedidc-DOCNUM.

6.4

CHANGING AN IDOCS STATUS

CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_PROCESS' EXPORTING DOCUMENT_NUMBER = iedidc-docnum IMPORTING IDOC_CONTROL = IEDIDC EXCEPTIONS DOCUMENT_FOREIGN_LOCK = 01 DOCUMENT_NOT_EXIST = 02 DOCUMENT_NUMBER_INVALID = 03 ERROR_MESSAGE = 04 OTHERS = 05. CALL FUNCTION 'EDI_DOCUMENT_STATUS_SET' EXPORTING DOCUMENT_NUMBER = iedidc-DOCNUM IDOC_STATUS = edi_ds IMPORTING IDOC_CONTROL = iedidc EXCEPTIONS DOCUMENT_NUMBER_INVALID =1 OTHER_FIELDS_INVALID =2 STATUS_INVALID =3 OTHERS =4 . CALL FUNCTION 'EDI_DOCUMENT_CLOSE_PROCESS' EXPORTING DOCUMENT_NUMBER = iedidc-DOCNUM.

6.5

READING AN IDOC

CALL FUNCTION 'IDOC_READ_COMPLETELY' EXPORTING document_number = p_docnum IMPORTING idoc_control = s_ordchg_edidc TABLES int_edidd = itab_ordchg_edidd EXCEPTIONS document_not_exist =1 document_number_invalid = 2 OTHERS = 3.

6.5.1 Example Open document for read


CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_READ' EXPORTING DOCUMENT_NUMBER = iedidc-docnum IMPORTING IDOC_CONTROL = IEDIDC EXCEPTIONS DOCUMENT_FOREIGN_LOCK = 01 DOCUMENT_NOT_EXIST = 02 DOCUMENT_NUMBER_INVALID = 03 ERROR_MESSAGE = 04 OTHERS = 05. call function 'EDI_SEGMENTS_GET_ALL' exporting document_number = iedidc-docnum

2008-09

Page 227 of 328

tables idoc_containers = data_rec exceptions document_number_invalid = 1 end_of_document =2 others = 3. if not sy-subrc is initial. CALL FUNCTION 'EDI_DOCUMENT_CLOSE_READ' EXPORTING DOCUMENT_NUMBER = iedidc-docnum IMPORTING IDOC_CONTROL = iedidc

6.6

DISPLAYING AN IDOC

CALL FUNCTION 'EDI_DOCUMENT_DATA_DISPLAY' "Display Idoc EXPORTING docnum = t_idoc tree_display = 'Y' EXCEPTIONS no_data_record_found = 1 OTHERS = 2.

6.7

IDOC TYPE POOL

TYPE-POOLS: * general idoc type pool TIDOC.

6.8

LAUNCHING AN ERROR WORKFLOW

* include for workflow programming INCLUDE <CNTN01>. PERFORM analyzing_event_create TABLES t_couple_to_process USING l_commit_counter inbsync. if sy-subrc is initial. MESS-MSGID = 'ZS7'. MESS-MSGTY = 'E'. MESS-MSGNO = i_msgno. MESS-MSGV1 = i_msgv1. MESS-MSGV2 = i_msgv2. CALL FUNCTION 'IDOC_ERROR_WORKFLOW_START' EXPORTING DOCNUM =0 EVENTCODE = 'EDIM' MESS = mess STATUSMESS = mess EXCEPTIONS NO_ENTRY_IN_TEDE5 =1 ERROR_IN_START_WORKFLOW =2 OTHERS = 3. COMMIT WORK. endif. "link created FORM analyzing_event_create TABLES t_couple_to_process_in STRUCTURE ediinbound USING commit_counter_in LIKE ediglodata-comcount start_recfb_synchron_in LIKE ediglodata-inbsync. * local variables DATA: * instance that is created l_object TYPE swc_object, * object key, e.g IDoc number l_object_key LIKE swotobjid-objkey, * id of wf event

2008-09

Page 228 of 328

l_event_id LIKE swedumevid-evtid, * status record for case of error l_status_record TYPE tidoc_status_record_ext, * flag indicating whether subscribed task is started synchronously l_start_recfb_synchron LIKE sweflags-syncflag VALUE ' ', * idoc number (needed because of type checking) l_idoc_number LIKE edidc-docnum. * local constants CONSTANTS: * object type 'IDOC' c_object_type LIKE swetypecou-objtype VALUE 'IDOCINVOIC', * name of event to be created c_idc_evt LIKE swetypecou-event VALUE 'INPUTERROROCCURREDMM' . if t_couple_to_process_in[] is initial. COMMIT WORK. CALL FUNCTION 'DEQUEUE_ALL'. CLEAR commit_counter_in. exit. endif. * cast l_start_recfb_synchron = start_recfb_synchron_in. * declaration of container swc_container l_t_ev_container. * initialize container swc_clear_container l_t_ev_container. * dequeue all idocs at the same time LOOP AT t_couple_to_process_in. * cast l_idoc_number = t_couple_to_process_in(16). CALL FUNCTION 'EDI_DOCUMENT_DEQUEUE_LATER' EXPORTING docnum = l_idoc_number EXCEPTIONS OTHERS = 0. ENDLOOP. * get first idoc number in table in order to create an object READ TABLE t_couple_to_process_in INDEX 1. * set object key in variable of correct type (casting) l_object_key = t_couple_to_process_in(16). * create an object, i.e. an IDoc swc_create_object l_object c_object_type l_object_key. * fill container: work item object id (idoc) swc_set_element l_t_ev_container "EC * c_element_wi_obj_id "EC * l_object. "EC * * fill container: NumberPlusEventcode (table of couples) swc_set_table l_t_ev_container c_element_no_plus_info t_couple_to_process_in. * fire event that will trigger the idoc inbound processing CALL FUNCTION 'SWE_EVENT_CREATE' EXPORTING objtype = c_object_type objkey = l_object_key event = c_idc_evt * CREATOR ='' * START_WITH_DELAY = ' ' start_recfb_synchron = l_start_recfb_synchron IMPORTING event_id = l_event_id TABLES event_container = l_t_ev_container EXCEPTIONS objtype_not_found = 1 OTHERS = 2. IF ( sy-subrc <> 0 ) * event was not created => error handling for this idoc (EDIM)

2008-09

Page 229 of 328

OR ( l_event_id = 0 ). * stop processing, no commit MESSAGE ID 'E0' TYPE 'A' NUMBER '374' WITH l_status_record-docnum c_idc_evt RAISING event_create_failed. ELSE. * do commit and reset counter * the commit will get the idocs to the database and at the same time * activate the event that was created COMMIT WORK. * dequeue all unprocessed IDocs to avoid log-overflow CALL FUNCTION 'DEQUEUE_ALL'. CLEAR commit_counter_in. * reset table of idocs that need to be processed CLEAR t_couple_to_process_in. REFRESH t_couple_to_process_in. ENDIF. ENDFORM. " ANALYZING_EVENT_CREATE

6.9

RETURNING IDOCS LINKED TO DOCUMENTS


CALL FUNCTION 'EDI_GET_LINKED_IDOCS' EXPORTING OBJTYPE = 'LIKP' OBJKEY = ITAB_SO-O856NO TABLES LINKED_IDOCS = ITAB_LINKED_IDOCS EXCEPTIONS OBJECT_NOT_FOUND = 1 NO_IDOCS_LINKED = 2 OBJECT_TYPE_UNKNOWN = 3 INTERNAL_ERROR =4 OTHERS = 5. IF SY-SUBRC = 0. CLEAR: T_VBELN_DOCNUM, T_824_DOCNUM. CLEAR: T_VBELN_DATE, T_824_DATE.

6.9.1 * Return the list of IDocs linked to the delivery

6.9.2 * Return the list of IDocs linked to the invoice


CALL FUNCTION 'EDI_GET_LINKED_IDOCS' EXPORTING OBJTYPE = 'VBRK' OBJKEY = ITAB_SO-O810NO TABLES LINKED_IDOCS = ITAB_LINKED_IDOCS EXCEPTIONS OBJECT_NOT_FOUND = 1 NO_IDOCS_LINKED = 2 OBJECT_TYPE_UNKNOWN = 3 INTERNAL_ERROR =4 OTHERS = 5.

6.9.3 Version 4.6X


DATA: DATA: t_roles LIKE relroles OCCURS 5 WITH HEADER LINE. t_object LIKE borident. t_object-objkey = itab_data-objky. t_object-objtype = 'BUS2035'. Scheduling Agreements CALL FUNCTION 'SREL_GET_NEXT_RELATIONS' EXPORTING object = t_object TABLES roles = t_roles EXCEPTIONS internal_error = 1 no_logsys =2

2008-09

Page 230 of 328

OTHERS

= 3.

6.9.3.1 R/3 note no. 317864


In Release 4.6, the IDoc base does not use the Workflow container with type C to save links but the system was changed to the generic object services. This note describes in which relations the objects in the IDoc processing are saved. This know-how is a prerequisite in order to effectively find a special object whose link was saved during the IDoc processing. All relationships types defined in the SAP System can be found in table VRBRELTYP. From the IDoc base, the following essential relationships have been defined: IDC0 - Application document and outbound IDoc are related IDC1 - Inbound IDoc and application document are related IDC3 - Inbound IDoc and its original IDoc are related (while editing) IDC4 - Inbound IDoc and outbound IDoc of the sending system are related (for R/3 - R/3 link) IDC7 - Outbound IDoc and its original IDoc are related (while editing) IDC8 - Inbound IDoc and transaction ID (of tRFC) are related IDCA - Outbound IDoc and transaction ID (of tRFC) are related In order to read relationships use SREL_GET_NEXT_RELATIONS. Generally, you need to transfer the BOR object (triple: object key, object type an logical system) for which you want to read the relationships to this function module. In order to find a special link you should know in which relationship the link was saved and whether the BOR object was saved into role A or into role B. For individual relationship types you can find this information also in table VRBRELTYP. For the relationship types described above, the object named first is always in role A and the second object is always in role B. Example: Searching the outbound IDoc of the sending system for an inbound IDoc which was generated via an R/3 - R/3 communication. The example source code represents the correction. The internal table will then contain an entry from which you can read the following information: The fields OBJKEY_A, OBJTYPE_A and LOGSYS_A contain all transferred values of the object for whose link you are searching - this object occurs in role A. The field RELTYPE contains the value 'IDC4' - since we only searched for this. The fields OBJKEY_B, OBJTYPE_B and LOGSYS_B contain all values of the searched linked object - this searched object occurs in role B. That is: the field OBJKEY_B contains the IDoc number of the sending system, the field OBJTYPE_B should contain the value 'IDOC' and the field LOGSYS_B should contain the sending logical system. Example * find the outbound-IDoc of the sending system for an inbound-IDoc, * which was created during R/3 - R/3 - communication report test. data: object1 like borident. data: begin of links occurs 0. include structure relgraphlk. data: end of links. object1-objkey = '0000000000004711'."IDOC-Nummer of the inbound-IDoc object1-objtype = 'IDOC'. object1-logsys = 'TTTCLNT999'. " << own logical system CALL FUNCTION 'SREL_GET_NEXT_RELATIONS' EXPORTING OBJECT = object1 * ROLETYPE = RELATIONTYPE = 'IDC4' * MAX_HOPS =1 * INCL_APPLRELS ='' * EXCL_ROLES = * EXCL_RELATIONS = TABLES LINKS = links * ROLES = * APPLLINKS =

2008-09

Page 231 of 328

EXCEPTIONS OTHERS

= 4.

* in table links we can find one entry with following informations: * in fields OBJKEY_A, OBJTYPE_A und LOGSYS_A are all values of * object1 - to this object we looked for the special link * object1 appears in role A * in field RELTYPE is the value 'IDC4' - we looked only for this kind * in fields OBJKEY_B, OBJTYPE_B and LOGSYS_B are all values of the * linked object - this linked object appears in role B * this means: in field OBJKEY_B is the IDoc-number of the sending Page 4 * system, in field OBJTYPE_B should be 'IDOC' and in LOGSYS_B is the * name of the sending logical system.

6.10 EXAMPLES 6.10.1 Write Idoc Status


FORM write_idoc_status USING p_statxt p_stapa1 p_stapa2 p_stapa3 p_stapa4 p_stamno p_stamid CHANGING t_status. TABLES: t100. CONDENSE p_stapa1 NO-GAPS. CONDENSE p_stapa2 NO-GAPS. CONDENSE p_stapa3 NO-GAPS. CONDENSE p_stapa4 NO-GAPS. IF p_statxt IS INITIAL. SELECT SINGLE text FROM t100 INTO t_status WHERE sprsl = 'EN' AND arbgb = p_stamid AND msgnr = p_stamno. ELSE. MOVE p_statxt TO t_status. ENDIF. IF t_status CS '&1' OR t_status CS '&2' OR t_status CS '&3' OR t_status CS '&4'. REPLACE '&1' WITH p_stapa1 INTO t_status. REPLACE '&2' WITH p_stapa2 INTO t_status. REPLACE '&3' WITH p_stapa3 INTO t_status. REPLACE '&4' WITH p_stapa4 INTO t_status. CONDENSE t_status. ELSE. REPLACE '&' WITH p_stapa1 INTO t_status. REPLACE '&' WITH p_stapa2 INTO t_status. REPLACE '&' WITH p_stapa3 INTO t_status. REPLACE '&' WITH p_stapa4 INTO t_status. CONDENSE t_status. ENDIF. ENDFORM. " WRITE_IDOC_STATUS

6.10.2

BDC Processing & Idoc status update

**********************************************************************
*---- Data definition ------------------------------------------------DATA: BEGIN OF BDCDATA OCCURS 5. INCLUDE STRUCTURE BDCDATA. DATA: END OF BDCDATA. DATA: C_TCODE LIKE BKPF-TCODE VALUE 'FB01'. DATA BEGIN OF MESSTAB OCCURS 10.

2008-09

Page 232 of 328

INCLUDE STRUCTURE BDCMSGCOLL. DATA END OF MESSTAB. ********************************************************************** *---- Call transaction -----------------------------------------------FORM Main_Program REFRESH BDCDATA. PERFORM APPEND_BDC USING 'SAPMF05A' '0100' ' '' '. PERFORM APPEND_BDC USING ' ' ' ' 'BKPF-BLDAT' '09031998'. PERFORM APPEND_BDC USING ' ' ' ' 'BDC_OKCODE' '/00'. PERFORM APPEND_BDC USING 'SAPMF05A' '0300' ' ' ' '. PERFORM APPEND_BDC USING ' ' ' ' 'BSEG-WRBTR' '*'. PERFORM APPEND_BDC USING ' ' ' ' 'BDC_OKCODE' 'BU'. CALL TRANSACTION 'FB01' USING BDCDATA MODE 'N' UPDATE 'S'. PERFORM UPDATE_IDOC_STATUS. ENDFORM. ********************************************************************** *--- Call transaction with errors to BDC ----------------------------REFRESH MESSTAB. CALL TRANSACTION C_TCODE 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. SY-MSGID = 'B1'. SY-MSGNO = 999. SY-MSGV1 = 'Error: Check BDC'. 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 TABLES DYNPROTAB = BDCDATA. CALL FUNCTION 'BDC_CLOSE_GROUP' EXCEPTIONS NOT_OPEN = 1 QUEUE_ERROR = 2 OTHERS = 3. ENDIF. ********************************************************************** *--- Append BDCDATA internal table -----------------------------------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.

2008-09

Page 233 of 328

APPEND BDCDATA. ENDFORM. *&---------------------------------------------------------------------* *& Form UPDATE_IDOC_STATUS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM UPDATE_IDOC_STATUS. *--- Now we check the CALL TRANSACTION return code and set IDOC status CLEAR IDOC_STATUS. IF RETURN_CODE = 0. WORKFLOW_RESULT = '0'. IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM. IDOC_STATUS-STATUS = '53'. IDOC_STATUS-UNAME = SY-UNAME. IDOC_STATUS-REPID = SY-REPID. IDOC_STATUS-MSGTY = SY-MSGTY. IDOC_STATUS-MSGID = SY-MSGID. IDOC_STATUS-MSGNO = SY-MSGNO. IDOC_STATUS-MSGV1 = SY-MSGV1. IDOC_STATUS-MSGV2 = SY-MSGV2. IDOC_STATUS-MSGV3 = SY-MSGV3. IDOC_STATUS-MSGV4 = SY-MSGV4. RETURN_VARIABLES-WF_PARAM = 'Processed_IDOCs'. RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM. APPEND RETURN_VARIABLES. ELSE. WORKFLOW_RESULT = '99999'. IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM. IDOC_STATUS-STATUS = '51'. IDOC_STATUS-UNAME = SY-UNAME. IDOC_STATUS-REPID = SY-REPID. IDOC_STATUS-MSGTY = SY-MSGTY. IDOC_STATUS-MSGID = SY-MSGID. IDOC_STATUS-MSGNO = SY-MSGNO. IDOC_STATUS-MSGV1 = SY-MSGV1. IDOC_STATUS-MSGV2 = SY-MSGV2. IDOC_STATUS-MSGV3 = SY-MSGV3. IDOC_STATUS-MSGV4 = SY-MSGV4. RETURN_VARIABLES-WF_PARAM = 'Error_IDOCs'. RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM. APPEND RETURN_VARIABLES. ENDIF. APPEND IDOC_STATUS. ENDFORM. " UPDATE_IDOC_STATUS

6.10.3

Mailing in SAP

6.10.3.1 Z_IDOC_INPUT_ALEAUD Code


FUNCTION Z_IDOC_INPUT_ALEAUD. *"---------------------------------------------------------------------*"*"Local interface: *" IMPORTING *" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD *" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC *" EXPORTING *" VALUE(WORKFLOW_RESULT) LIKE BDWF_PARAM-RESULT *" VALUE(APPLICATION_VARIABLE) LIKE BDWF_PARAM-APPL_VAR *" VALUE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK *" VALUE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS *" TABLES *" IDOC_CONTRL STRUCTURE EDIDC *" IDOC_DATA STRUCTURE EDIDD *" IDOC_STATUS STRUCTURE BDIDOCSTAT *" RETURN_VARIABLES STRUCTURE BDWFRETVAR *" SERIALIZATION_INFO STRUCTURE BDI_SER *" EXCEPTIONS *" WRONG_FUNCTION_CALLED

2008-09

Page 234 of 328

*"---------------------------------------------------------------------DATA: T_IDOC_CONTROL LIKE EDIDC OCCURS 0 WITH HEADER LINE, T_IDOC_DATA LIKE EDIDD OCCURS 0 WITH HEADER LINE, T_ALE_ERR LIKE ALE_ERR_MESSAGE OCCURS 0 WITH HEADER LINE, X_OBJCONT LIKE SOLI OCCURS 0 WITH HEADER LINE, X_OBJHEAD LIKE SOLI OCCURS 0 WITH HEADER LINE, RAW_HEAD LIKE SORH OCCURS 0 WITH HEADER LINE, X_RECEIVERS LIKE SOOS1 OCCURS 0 WITH HEADER LINE. DATA: W_E1ADHDR LIKE E1ADHDR, W_E1STATE LIKE E1STATE, W_E1PRTOB LIKE E1PRTOB, X_OBJECT_HD_CHANGE LIKE SOOD1, RECEIVING_SYSTEM LIKE EDIDC-SNDPRN, SENDING_SYSTEM LIKE EDIDC-RCVPRN, H_TEXT LIKE SOOD1-OBJDES, FOLDER_NAME LIKE SOS06-S_FOLNAM, SUBRC LIKE SY-SUBRC, GLOBAL_SUBRC LIKE SY-SUBRC, X_OBJECT_TYPE LIKE SOOD-OBJTP. T_IDOC_CONTROL[] = IDOC_CONTRL[]. T_IDOC_DATA[] = IDOC_DATA[]. READ TABLE T_IDOC_CONTROL INDEX 1. RECEIVING_SYSTEM = T_IDOC_CONTROL-SNDPRN. SENDING_SYSTEM = T_IDOC_CONTROL-RCVPRN. GLOBAL_SUBRC = 0. LOOP AT T_IDOC_DATA. CASE T_IDOC_DATA-SEGNAM. WHEN 'E1ADHDR'. IF ZTAUD-MESTYP <> SPACE AND NOT T_ALE_ERR[] IS INITIAL. * send SAP mail CLEAR SUBRC. PERFORM SEND_SAP_MAIL TABLES T_ALE_ERR USING RECEIVING_SYSTEM SENDING_SYSTEM ZTAUD SUBRC. IF SUBRC <> 0. GLOBAL_SUBRC = SUBRC. IDOC_STATUS-DOCNUM = T_IDOC_CONTROL-DOCNUM. IDOC_STATUS-STATUS = '51'. IDOC_STATUS-MSGTY = 'E'. IDOC_STATUS-MSGID = 'B1'. IDOC_STATUS-MSGNO = '999'. IDOC_STATUS-MSGV1 = TEXT-013. IDOC_STATUS-MSGV2 = ZTAUD-MESTYP. IDOC_STATUS-MSGV3 = 'SO_OBJECT_SEND RC ='. IDOC_STATUS-MSGV4 = SUBRC. APPEND IDOC_STATUS. ENDIF. CLEAR T_ALE_ERR. REFRESH T_ALE_ERR. ENDIF. W_E1ADHDR = T_IDOC_DATA-SDATA. CLEAR ZTAUD. SELECT SINGLE * FROM ZTAUD WHERE MESTYP = W_E1ADHDR-MESTYP. WHEN 'E1STATE'. IF ZTAUD-MESTYP = SPACE. CONTINUE. ELSE. W_E1STATE = T_IDOC_DATA-SDATA. CLEAR T_ALE_ERR. IF W_E1STATE-STATUS = '51' OR W_E1STATE-STATUS = '56' OR W_E1STATE-STATUS = '61' OR W_E1STATE-STATUS = '63' OR W_E1STATE-STATUS = '65' OR W_E1STATE-STATUS = '60'. T_ALE_ERR-STATUS = W_E1STATE-STATUS.

2008-09

Page 235 of 328

T_ALE_ERR-DOCNUMSND = W_E1STATE-DOCNUM. ENDIF. ENDIF. WHEN 'E1PRTOB'. IF ZTAUD-MESTYP = SPACE. CONTINUE. ELSE. IF T_ALE_ERR-STATUS = SPACE. CONTINUE. ELSE. W_E1PRTOB = T_IDOC_DATA-SDATA. T_ALE_ERR-DOCNUMRCV = W_E1PRTOB-DOCNUM. APPEND T_ALE_ERR. CLEAR T_ALE_ERR. ENDIF. ENDIF. ENDCASE. ENDLOOP. IF ZTAUD-MESTYP <> SPACE AND NOT T_ALE_ERR[] IS INITIAL. * send SAP mail CLEAR SUBRC. PERFORM SEND_SAP_MAIL TABLES T_ALE_ERR USING RECEIVING_SYSTEM SENDING_SYSTEM ZTAUD SUBRC. IF SUBRC <> 0. GLOBAL_SUBRC = SUBRC. IDOC_STATUS-DOCNUM = T_IDOC_CONTROL-DOCNUM. IDOC_STATUS-STATUS = '51'. IDOC_STATUS-MSGTY = 'E'. IDOC_STATUS-MSGID = 'B1'. IDOC_STATUS-MSGNO = '999'. IDOC_STATUS-MSGV1 = TEXT-013. IDOC_STATUS-MSGV2 = ZTAUD-MESTYP. IDOC_STATUS-MSGV3 = 'SO_OBJECT_SEND RC ='. IDOC_STATUS-MSGV4 = SUBRC. APPEND IDOC_STATUS. ENDIF. CLEAR T_ALE_ERR. REFRESH T_ALE_ERR. ENDIF. IF GLOBAL_SUBRC <> 0. WORKFLOW_RESULT = 99999. RETURN_VARIABLES-DOC_NUMBER = T_IDOC_CONTROL-DOCNUM. RETURN_VARIABLES-WF_PARAM = 'Error_IDOCs'. APPEND RETURN_VARIABLES. ELSE. WORKFLOW_RESULT = 0. CLEAR IDOC_STATUS. IDOC_STATUS-DOCNUM = T_IDOC_CONTROL-DOCNUM. IDOC_STATUS-STATUS = '53'. IDOC_STATUS-MSGTY = 'E'. IDOC_STATUS-MSGID = 'B1'. IDOC_STATUS-MSGNO = '999'. IDOC_STATUS-MSGV1 = TEXT-014. APPEND IDOC_STATUS. CLEAR RETURN_VARIABLES. RETURN_VARIABLES-WF_PARAM = 'Processed_IDOCs'. RETURN_VARIABLES-DOC_NUMBER = T_IDOC_CONTROL-DOCNUM. APPEND RETURN_VARIABLES. ENDIF. ENDFUNCTION.

6.10.3.2 Appendix II (LZALAF01 Code)


*------------------------------------------------------------------***INCLUDE LZALAF01 . *------------------------------------------------------------------*&---------------------------------------------------------------------*

2008-09

Page 236 of 328

*& Form SEND_SAP_MAIL *&---------------------------------------------------------------------*


FORM SEND_SAP_MAIL TABLES T_ALE_ERR STRUCTURE ALE_ERR_MESSAGE USING RECEIVING_SYSTEM LIKE EDIDC-SNDPRN SENDING_SYSTEM LIKE EDIDC-RCVPRN ZTAUD STRUCTURE ZTAUD SUBRC LIKE SY-SUBRC. DATA: T_ALE_ERR_WA LIKE ALE_ERR_MESSAGE OCCURS 0 WITH HEADER LINE, X_OBJCONT LIKE SOLI OCCURS 0 WITH HEADER LINE, * x_objhead like soli occurs 0 with header line, X_RECEIVERS LIKE SOOS1 OCCURS 0 WITH HEADER LINE. DATA: X_OBJECT_HD_CHANGE LIKE SOOD1, H_TEXT LIKE SOLI-LINE, H_STATUS LIKE EDIDC-STATUS, X_OBJECT_TYPE LIKE SOOD-OBJTP. MOVE 'RAW' TO X_OBJECT_TYPE. H_TEXT = TEXT-002. REPLACE '&' WITH ZTAUD-MESTYP INTO H_TEXT. REPLACE '&' WITH RECEIVING_SYSTEM INTO H_TEXT. CONDENSE H_TEXT. MOVE: SY-LANGU TO X_OBJECT_HD_CHANGE-OBJLA, TEXT-001 TO X_OBJECT_HD_CHANGE-OBJSRT, TEXT-001 TO X_OBJECT_HD_CHANGE-OBJNAM, H_TEXT TO X_OBJECT_HD_CHANGE-OBJDES, 'F' TO X_OBJECT_HD_CHANGE-OBJSNS. " Functional * clear x_objhead. * refresh x_objhead. * move 6 to raw_head-rawsiz. * move raw_head to x_objhead. * append x_objhead. REFRESH X_OBJCONT. CLEAR X_OBJCONT. MOVE H_TEXT TO X_OBJCONT. APPEND X_OBJCONT. CLEAR X_OBJCONT. APPEND X_OBJCONT. SORT T_ALE_ERR. LOOP AT T_ALE_ERR. IF H_STATUS <> T_ALE_ERR-STATUS. IF H_STATUS <> SPACE. PERFORM ERROR_REPORT TABLES X_OBJCONT T_ALE_ERR_WA USING H_STATUS RECEIVING_SYSTEM SENDING_SYSTEM. CLEAR T_ALE_ERR_WA. REFRESH T_ALE_ERR_WA. ENDIF. H_STATUS = T_ALE_ERR-STATUS. ENDIF. T_ALE_ERR_WA = T_ALE_ERR. APPEND T_ALE_ERR_WA. ENDLOOP. IF SY-SUBRC = 0. PERFORM ERROR_REPORT TABLES X_OBJCONT T_ALE_ERR_WA USING H_STATUS RECEIVING_SYSTEM SENDING_SYSTEM. CLEAR T_ALE_ERR_WA. REFRESH T_ALE_ERR_WA. ENDIF. CLEAR X_RECEIVERS.

2008-09

Page 237 of 328

REFRESH X_RECEIVERS. MOVE ZTAUD-DLINAM TO X_RECEIVERS-RECNAM. " Distribution list MOVE 'X' TO X_RECEIVERS-SNDEX. MOVE 'C' TO X_RECEIVERS-RECESC. APPEND X_RECEIVERS. CLEAR: SY-MSGID. CALL FUNCTION 'SO_OBJECT_SEND' EXPORTING OBJECT_HD_CHANGE = X_OBJECT_HD_CHANGE OBJECT_TYPE = X_OBJECT_TYPE TABLES OBJCONT = X_OBJCONT * objhead = x_objhead RECEIVERS = X_RECEIVERS EXCEPTIONS ACTIVE_USER_NOT_EXIST =1 COMMUNICATION_FAILURE =2 COMPONENT_NOT_AVAILABLE = 3 FOLDER_NOT_EXIST =4 FOLDER_NO_AUTHORIZATION = 5 FORWARDER_NOT_EXIST =6 NOTE_NOT_EXIST =7 OBJECT_NOT_EXIST =8 OBJECT_NOT_SENT =9 OBJECT_NO_AUTHORIZATION = 10 OBJECT_TYPE_NOT_EXIST = 11 OPERATION_NO_AUTHORIZATION = 12 OWNER_NOT_EXIST = 13 PARAMETER_ERROR = 14 SUBSTITUTE_NOT_ACTIVE = 15 SUBSTITUTE_NOT_DEFINED = 16 SYSTEM_FAILURE = 17 TOO_MUCH_RECEIVERS = 18 USER_NOT_EXIST = 19 X_ERROR = 20 OTHERS = 21. SUBRC = SY-SUBRC. ENDFORM. " SEND_SAP_MAIL

*&---------------------------------------------------------------------* *& Form ERROR_REPORT *&---------------------------------------------------------------------* FORM ERROR_REPORT TABLES X_OBJCONT STRUCTURE SOLI T_ALE_ERR_WA STRUCTURE ALE_ERR_MESSAGE USING H_STATUS LIKE EDIDC-STATUS RECEIVING_SYSTEM LIKE EDIDC-SNDPRN SENDING_SYSTEM LIKE EDIDC-RCVPRN. DATA: H_TEXT LIKE SOLI-LINE, H_LINES(5) TYPE C. CLEAR X_OBJCONT. APPEND X_OBJCONT. CLEAR H_TEXT. CASE H_STATUS. WHEN '51'. H_TEXT = TEXT-004. WHEN '56'. H_TEXT = TEXT-005. WHEN '61'. H_TEXT = TEXT-006. WHEN '63'. H_TEXT = TEXT-007. WHEN '65'. H_TEXT = TEXT-008. WHEN '60'. H_TEXT = TEXT-009. WHEN OTHERS. H_TEXT = H_STATUS.

2008-09

Page 238 of 328

ENDCASE. CLEAR X_OBJCONT. X_OBJCONT = H_TEXT. APPEND X_OBJCONT. DESCRIBE TABLE T_ALE_ERR_WA LINES H_LINES. H_TEXT = TEXT-010. REPLACE '&' WITH H_LINES INTO H_TEXT. X_OBJCONT = H_TEXT. APPEND X_OBJCONT. H_TEXT = TEXT-011. REPLACE '&' WITH RECEIVING_SYSTEM INTO H_TEXT. REPLACE '&' WITH SENDING_SYSTEM INTO H_TEXT. X_OBJCONT = H_TEXT. APPEND X_OBJCONT. LOOP AT T_ALE_ERR_WA. H_TEXT = TEXT-012. REPLACE '&' WITH T_ALE_ERR_WA-DOCNUMRCV INTO H_TEXT. REPLACE '&' WITH T_ALE_ERR_WA-DOCNUMSND INTO H_TEXT. X_OBJCONT = H_TEXT. APPEND X_OBJCONT. ENDLOOP. ENDFORM. " ERROR_REPORT

6.10.4

Program example Report to show EDI status

Includes: ZFORMS
*&---------------------------------------------------------------------* *& Report Z_REPORT_ZTABLE * *&---------------------------------------------------------------------* * Author: Kevin Wilson Date: 15th September, 2000 * Detail: This program loops through the sales order table, taking * relevant data and storing it in the ZTABLE table. The * ZTABLE table stores the status of an order in the EDI * process. *&---------------------------------------------------------------------* REPORT Z_REPORT_ZTABLE LINE-SIZE 160. *--- TABLE DEFINITIONS ------------------------------------------------TABLES: VBAK, VBAP, VBFA, VBPA, ZTABLE, EDIDC, EDIDD, EDID4, Z1824HD. *--- INTERNAL TABLE DEFINITIONS ---------------------------------------* ITAB_SO_EXTRA stores the key of ITAB_SO as well as additional fields * that may be required down the line. eg. Material number and billing * block. TYPES: BEGIN OF ITAB_SO_EXTRA_TYPE, VBELN LIKE VBAK-VBELN, "Sales Order # BSTNK LIKE VBAK-BSTNK, "PO # POSNR LIKE VBAP-POSNR, "Sales Order Line # FAKSP LIKE VBAP-FAKSP, "Line Item Billing block MATNR LIKE VBAP-MATNR, "Material number END OF ITAB_SO_EXTRA_TYPE. * Create an internal table to store the invoice numbers * of those invoices that do not have INVOIC Idocs attached to them. * i.e. The ZD01 output was not created for some reason. TYPES: BEGIN OF TITAB_TYPE, O810 LIKE ZTABLE-O810NO, END OF TITAB_TYPE. * Internal table definitions containing the data entries for ZTABLE DATA: ITAB_SO LIKE ZTABLE OCCURS 20000 WITH HEADER LINE, ITAB_SO_EXTRA TYPE ITAB_SO_EXTRA_TYPE OCCURS 20000 WITH HEADER LINE. * Internal table definitions containing invoice numbers that need to be * saved in order to generate the ZD01 output. DATA: TITAB TYPE TITAB_TYPE OCCURS 100 WITH HEADER LINE. * Column names required for file download. DATA: BEGIN OF T_COLNAMES OCCURS 10,

2008-09

Page 239 of 328

NAME(15), "Column names for download END OF T_COLNAMES. *--- DATA DEFINITIONS -------------------------------------------------DATA: E1EDP26 TYPE E1EDP26, E1EDP01 TYPE E1EDP01, "Line item segment T_POSNR LIKE VBAP-POSNR, "Line item number INVOICE_FLAG(1), "Is there an invoice? Y/N DELIVERY_FLAG(1), "Is there a delivery? Y/N FIELD_NAME(30), "Check for line selection on field T_IDOC LIKE EDIDC-DOCNUM, "Store IDoc number for line selectn T_STAT LIKE ZTABLE-I824856STAT."Temporary 824 status *--- CONSTANT DEFINITIONS --- FOR CO. A ------------------------------CONSTANTS: C_SPART_12 LIKE VBAK-SPART VALUE '12', "Division 12 C_AUART_ZEDI LIKE VBAK-AUART VALUE 'ZEDI'. "Doc type ZEDI *--- SELECTION OPTIONS ------------------------------------------------SELECTION-SCREEN BEGIN OF BLOCK SO WITH FRAME TITLE TEXT-001. SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN,"Sales order number S_ERDAT FOR VBAK-ERDAT,"Sales order date S_KUNNR FOR VBPA-KUNNR."Ship to partner SELECTION-SCREEN END OF BLOCK SO. SELECTION-SCREEN BEGIN OF BLOCK UP WITH FRAME TITLE TEXT-002. PARAMETERS: P_UPD_Y RADIOBUTTON GROUP UPD, "Update table P_UPD_N RADIOBUTTON GROUP UPD. "Don't update table SELECTION-SCREEN END OF BLOCK UP. SELECTION-SCREEN BEGIN OF BLOCK G2 WITH FRAME TITLE TEXT-011. PARAMETERS: P_VIEW RADIOBUTTON GROUP L1, "View P_DOWN RADIOBUTTON GROUP L1, "Download P_FILE LIKE RLGRAP-FILENAME DEFAULT 'C:\ZTABLE.XLS'. SELECTION-SCREEN END OF BLOCK G2. AT SELECTION-SCREEN ON P_FILE. * If download is checked, but no file name is entered, error IF P_DOWN EQ 'X' AND P_FILE EQ SPACE. MESSAGE E999(B1) WITH TEXT-014. ENDIF. *--- INCLUDES ---------------------------------------------------------INCLUDE Z_FORMS. *--- INITIALIZATION ---------------------------------------------------INITIALIZATION. REFRESH: ITAB_SO, ITAB_SO_EXTRA, TITAB. CLEAR: ITAB_SO, ITAB_SO_EXTRA, TITAB. *--- SELECTION --------------------------------------------------------START-OF-SELECTION. IF P_UPD_Y EQ 'X'. "Update ZTABLE table SELECT VBELN ERDAT BSTNK FROM VBAK INTO (VBAK-VBELN, VBAK-ERDAT, VBAK-BSTNK) WHERE VBELN IN S_VBELN AND ERDAT IN S_ERDAT AND SPART = C_SPART_12 AND AUART = C_AUART_ZEDI. * Populate the internal table with the relevant data PERFORM UPDATE_ITAB_SO USING VBAK-VBELN VBAK-ERDAT VBAK-BSTNK. ENDSELECT. "Loop through selected orders for updating itab IF SY-SUBRC NE 0. MESSAGE I999(B1) WITH TEXT-003. "No sales orders found in range ELSE. * Perform an update on the database table ZTABLE using ITAB_SO PERFORM UPDATE_ZTABLE TABLES ITAB_SO. * Print ITAB_SO and ITAB_SO_EXTRA contents to the screen filtering out * customers not selected via the selection screen PERFORM PRINT_ITAB

2008-09

Page 240 of 328

TABLES ITAB_SO ITAB_SO_EXTRA. ENDIF. "sy-subrc check on sales order selection ELSE. "The user has requested to view the table and not do update REFRESH: ITAB_SO_EXTRA, ITAB_SO. CLEAR: ITAB_SO_EXTRA, ITAB_SO. SELECT * INTO TABLE ITAB_SO FROM ZTABLE WHERE VBELN IN S_VBELN AND DATUM IN S_ERDAT. IF SY-SUBRC = 0. LOOP AT ITAB_SO. * We need to see if the order we have is a CO. A order. A CO. A order * is uniquely identified with Division = 12 and Order type = ZEDI SELECT SINGLE SPART AUART FROM VBAK INTO (VBAK-SPART, VBAK-AUART) WHERE VBELN = ITAB_SO-VBELN. IF SY-SUBRC = 0. * Check for CO. A order IF VBAK-SPART = C_SPART_12 AND VBAK-AUART = C_AUART_ZEDI. T_POSNR = ITAB_SO-POSNR DIV 10. SELECT MATNR FAKSP FROM VBAP INTO (ITAB_SO_EXTRA-MATNR, ITAB_SO_EXTRA-FAKSP) WHERE VBELN = ITAB_SO-VBELN AND POSNR = T_POSNR. ITAB_SO_EXTRA-VBELN = ITAB_SO-VBELN. ITAB_SO_EXTRA-POSNR = ITAB_SO-POSNR. ITAB_SO_EXTRA-BSTNK = ITAB_SO-BSTKD. APPEND ITAB_SO_EXTRA. ENDSELECT. "Update extra details ENDIF. "Check for CO. A orders with DIV=12 & Ord Type=ZEDI ENDIF. "Sy-subrc check on lookup for DIV and Ord Type ENDLOOP. "ITAB_SO internal table loop * Print ITAB_SO and ITAB_SO_EXTRA contents to the screen filtering out * customers not selected via the selection screen PERFORM PRINT_ITAB TABLES ITAB_SO ITAB_SO_EXTRA. ELSE. "No entries were found in ITAB_SO MESSAGE I999(B1) WITH TEXT-005. "No entries in ITAB_SO! ENDIF. ENDIF. * Loop through the internal table set up to store the invoice numbers * of those invoices that do not have INVOIC Idocs attached to them. PERFORM SAVE_BILLING_DOC TABLES TITAB. END-OF-SELECTION. * --- EVENT : AT LINE SELECTION --AT LINE-SELECTION. * Return the field that the user clicked on GET CURSOR FIELD FIELD_NAME. CASE FIELD_NAME. * Clicked on message from 824 WHEN 'ITAB_SO-I824810NOTE' OR 'ITAB_SO-I824856NOTE'. IF T_IDOC <> ''. IF T_STAT = 'R'. * Return the full detail of the error using report Z_LIST_IDOC_824 SUBMIT Z_LIST_IDOC_824 WITH I_DOCN = T_IDOC AND RETURN. ELSE. MESSAGE I999(B1) WITH TEXT-013."IDoc not rejected ENDIF. ELSE. MESSAGE I999(B1) WITH TEXT-012."No IDoc ENDIF. * Clicked on Invoice number WHEN 'ITAB_SO-O810NO'. IF ITAB_SO-O810NO <> ''. SET PARAMETER ID 'VF' FIELD ITAB_SO-O810NO. CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN. "View Invoice ELSE. MESSAGE I999(B1) WITH TEXT-008."Click on invoice ENDIF. * Clicked on delivery number

2008-09

Page 241 of 328

WHEN 'ITAB_SO-O856NO'. IF ITAB_SO-O856NO <> ''. SET PARAMETER ID 'VL' FIELD ITAB_SO-O856NO. CALL TRANSACTION 'VL03' AND SKIP FIRST SCREEN. "View delivery ELSE. MESSAGE I999(B1) WITH TEXT-010."Click on Delivery ENDIF. * Clicked on Sales Order number WHEN 'ITAB_SO-VBELN'. SET PARAMETER ID 'AUN' FIELD ITAB_SO-VBELN. CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN. "View Sales Order * DESADV Idoc # clicked WHEN 'ITAB_SO-O856DOCNUM'. IF ITAB_SO-O856DOCNUM <> ''. MOVE ITAB_SO-O856DOCNUM TO T_IDOC. CALL FUNCTION 'EDI_DOCUMENT_DATA_DISPLAY' "Dsiplay Idoc EXPORTING DOCNUM = T_IDOC TREE_DISPLAY = 'Y' EXCEPTIONS NO_DATA_RECORD_FOUND = 1 OTHERS = 2. IF SY-SUBRC <> 0. MESSAGE I999(B1) WITH TEXT-007. "Click on IDoc. ENDIF. ELSE. MESSAGE I999(B1) WITH TEXT-007."Click on IDoc. ENDIF. * INVOIC Idoc # clicked WHEN 'ITAB_SO-O810DOCNUM'. IF ITAB_SO-O810DOCNUM <> ''. MOVE ITAB_SO-O810DOCNUM TO T_IDOC. CALL FUNCTION 'EDI_DOCUMENT_DATA_DISPLAY' "Display an IDoc. EXPORTING DOCNUM = T_IDOC TREE_DISPLAY = 'Y' EXCEPTIONS NO_DATA_RECORD_FOUND = 1 OTHERS = 2. IF SY-SUBRC <> 0. MESSAGE I999(B1) WITH TEXT-007. "Click on IDoc. ENDIF. ELSE. MESSAGE I999(B1) WITH TEXT-007."Click on IDoc. ENDIF. * ZAPPADV810 IDoc # clicked WHEN 'ITAB_SO-I824810DOCNUM'. IF ITAB_SO-I824810DOCNUM <> ''. MOVE ITAB_SO-I824810DOCNUM TO T_IDOC. CALL FUNCTION 'EDI_DOCUMENT_DATA_DISPLAY' "Display IDoc EXPORTING DOCNUM = T_IDOC TREE_DISPLAY = 'Y' EXCEPTIONS NO_DATA_RECORD_FOUND = 1 OTHERS = 2. IF SY-SUBRC <> 0. MESSAGE I999(B1) WITH TEXT-007. "Click on IDoc. ENDIF. ELSE. MESSAGE I999(B1) WITH TEXT-007."Click on IDoc. ENDIF. * ZAPPADV856 IDoc # clicked WHEN 'ITAB_SO-I824856DOCNUM'. IF ITAB_SO-I824856DOCNUM <> ''. MOVE ITAB_SO-I824856DOCNUM TO T_IDOC. CALL FUNCTION 'EDI_DOCUMENT_DATA_DISPLAY' "Display IDoc EXPORTING DOCNUM = T_IDOC TREE_DISPLAY = 'Y' EXCEPTIONS NO_DATA_RECORD_FOUND = 1 OTHERS = 2. IF SY-SUBRC <> 0. MESSAGE I999(B1) WITH TEXT-007. "Click on IDoc. ENDIF.

2008-09

Page 242 of 328

ELSE. MESSAGE I999(B1) WITH TEXT-007."Click on IDoc. ENDIF. ENDCASE. "Evaluation of field names

Include: ZFORMS
*----------------------------------------------------------------------* ***INCLUDE Z_FORMS . *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form UPDATE_ITAB_SO *&---------------------------------------------------------------------* * Loop through VBAP and update the table ZTABLE *----------------------------------------------------------------------* * -->VBAK_VBELN Sales Order Number * -->VBAK_ERDAT Sales Order Date * -->VBAK_BSTNK Purchase Order Number *----------------------------------------------------------------------* FORM UPDATE_ITAB_SO USING VBAK_VBELN VBAK_ERDAT VBAK_BSTNK. * --- LOCAL VARIABLES --DATA: T_POSNR LIKE VBAP-POSNR, T_VBELN_DOCNUM LIKE EDIDC-DOCNUM, T_VBELN_DATE LIKE EDIDC-CREDAT, T_PRICE LIKE ZTABLE-O810PRICE, T_SEGNUM LIKE EDID4-SEGNUM, T_824_DOCNUM LIKE EDIDC-DOCNUM, T_824_NOTE LIKE ZTABLE-I824856NOTE, T_824_STAT LIKE ZTABLE-I824856STAT, T_824_DATE LIKE EDIDC-CREDAT, N1 TYPE I. * --- LOCAL INTERNAL TABLES --DATA: ITAB_LINKED_IDOCS LIKE SWW_CONTOB OCCURS 5 WITH HEADER LINE. * Initialization CLEAR: ITAB_SO, ITAB_SO_EXTRA. * Store Sales Order Header Data MOVE: VBAK_VBELN TO ITAB_SO-VBELN, VBAK_ERDAT TO ITAB_SO-DATUM, VBAK_BSTNK TO ITAB_SO-BSTKD. MOVE: VBAK_VBELN TO ITAB_SO_EXTRA-VBELN, VBAK_BSTNK TO ITAB_SO_EXTRA-BSTNK. * Get ship to customer number from VBPA SELECT SINGLE KUNNR FROM VBPA INTO ITAB_SO-KUNNR WHERE VBELN = VBAK_VBELN AND POSNR = '000000' AND PARVW = 'WE'. "Ship to partner function * Loop through the sales order line items. SELECT * FROM VBAP WHERE VBELN = VBAK_VBELN. T_POSNR = VBAP-POSNR * 10. MOVE: T_POSNR TO ITAB_SO-POSNR. MOVE: T_POSNR TO ITAB_SO_EXTRA-POSNR, VBAP-FAKSP TO ITAB_SO_EXTRA-FAKSP, "Billing block VBAP-MATNR TO ITAB_SO_EXTRA-MATNR. "Material # * Get delivery and invoice number CLEAR: ITAB_SO-O856NO, ITAB_SO-O856DATE, ITAB_SO-O856DOCNUM. CLEAR: ITAB_SO-O810NO, ITAB_SO-O810DATE, ITAB_SO-O810PRICE, ITAB_SO-O810DOCNUM. INVOICE_FLAG = ''. DELIVERY_FLAG = ''. SELECT VBELN VBTYP_N FROM VBFA INTO (VBFA-VBELN, VBFA-VBTYP_N) WHERE VBELV = VBAK_VBELN AND POSNV = VBAP-POSNR.

2008-09

Page 243 of 328

CASE VBFA-VBTYP_N. WHEN 'J'. "Delivery DELIVERY_FLAG = 'X'. MOVE VBFA-VBELN TO ITAB_SO-O856NO. IF ITAB_SO-O856NO <> ''. * Return the list of IDocs linked to the delivery CALL FUNCTION 'EDI_GET_LINKED_IDOCS' EXPORTING OBJTYPE = 'LIKP' OBJKEY = ITAB_SO-O856NO TABLES LINKED_IDOCS = ITAB_LINKED_IDOCS EXCEPTIONS OBJECT_NOT_FOUND = 1 NO_IDOCS_LINKED = 2 OBJECT_TYPE_UNKNOWN = 3 INTERNAL_ERROR =4 OTHERS = 5. IF SY-SUBRC = 0. CLEAR: T_VBELN_DOCNUM, T_824_DOCNUM. CLEAR: T_VBELN_DATE, T_824_DATE. * FILTER OUT ALL BUT THE LATEST IDOCS PERFORM GET_IDOC_MESTYP TABLES ITAB_LINKED_IDOCS USING 'LIKP' T_POSNR CHANGING T_VBELN_DOCNUM T_VBELN_DATE T_824_STAT T_824_NOTE T_824_DATE T_824_DOCNUM. MOVE T_VBELN_DOCNUM TO ITAB_SO-O856DOCNUM. MOVE T_VBELN_DATE TO ITAB_SO-O856DATE. MOVE T_824_DOCNUM TO ITAB_SO-I824856DOCNUM. MOVE T_824_STAT TO ITAB_SO-I824856STAT. MOVE T_824_NOTE TO ITAB_SO-I824856NOTE. MOVE T_824_DATE TO ITAB_SO-I824856DATE. REFRESH: ITAB_LINKED_IDOCS[], ITAB_LINKED_IDOCS. CLEAR: ITAB_LINKED_IDOCS. ELSE. "No IDocs were linked to Delivery MOVE '' TO ITAB_SO-O856DOCNUM. MOVE '' TO ITAB_SO-O856DATE. MOVE '' TO ITAB_SO-I824856DOCNUM. MOVE 'N' TO ITAB_SO-I824856STAT. MOVE 'No 824 received' TO ITAB_SO-I824856NOTE. MOVE '' TO ITAB_SO-I824856DATE. ENDIF. ELSE. "In case the delivery is not there... MOVE '' TO ITAB_SO-O856DOCNUM. MOVE '' TO ITAB_SO-O856DATE. MOVE '' TO ITAB_SO-I824856DOCNUM. MOVE 'N' TO ITAB_SO-I824856STAT. MOVE 'No 824 received' TO ITAB_SO-I824856NOTE. MOVE '' TO ITAB_SO-I824856DATE. ENDIF. WHEN 'M'. "Invoice INVOICE_FLAG = 'X'. MOVE VBFA-VBELN TO ITAB_SO-O810NO. IF ITAB_SO-O810NO <> ''. * Return the list of IDocs linked to the invoice CALL FUNCTION 'EDI_GET_LINKED_IDOCS' EXPORTING OBJTYPE = 'VBRK' OBJKEY = ITAB_SO-O810NO TABLES LINKED_IDOCS = ITAB_LINKED_IDOCS EXCEPTIONS OBJECT_NOT_FOUND = 1 NO_IDOCS_LINKED = 2 OBJECT_TYPE_UNKNOWN = 3 INTERNAL_ERROR =4 OTHERS = 5. IF SY-SUBRC = 0. CLEAR: T_VBELN_DOCNUM, T_824_DOCNUM, T_824_NOTE, T_824_STAT.

2008-09

Page 244 of 328

CLEAR: T_VBELN_DATE, T_824_DATE. * FILTER OUT ALL BUT THE LATEST IDOCS PERFORM GET_IDOC_MESTYP TABLES ITAB_LINKED_IDOCS USING 'VBRK' T_POSNR CHANGING T_VBELN_DOCNUM T_VBELN_DATE T_824_STAT T_824_NOTE T_824_DATE T_824_DOCNUM. MOVE T_VBELN_DOCNUM TO ITAB_SO-O810DOCNUM. MOVE T_VBELN_DATE TO ITAB_SO-O810DATE. MOVE T_824_DOCNUM TO ITAB_SO-I824810DOCNUM. MOVE T_824_STAT TO ITAB_SO-I824810STAT. MOVE T_824_NOTE TO ITAB_SO-I824810NOTE. MOVE T_824_DATE TO ITAB_SO-I824810DATE. * Get invoice price IF T_VBELN_DOCNUM IS INITIAL. CLEAR T_PRICE. ELSE. SELECT * FROM EDID4 WHERE DOCNUM = T_VBELN_DOCNUM AND SEGNAM = 'E1EDP01'. MOVE EDID4-SDATA TO E1EDP01. IF E1EDP01-POSEX = VBAP-POSNR. T_SEGNUM = EDID4-SEGNUM. SELECT * FROM EDID4 WHERE DOCNUM = T_VBELN_DOCNUM AND SEGNAM = 'E1EDP26' AND PSGNUM = T_SEGNUM. MOVE EDID4-SDATA TO E1EDP26. IF E1EDP26-QUALF = '010'. "Price qualifier T_PRICE = E1EDP26-BETRG. EXIT. ENDIF. ENDSELECT. MOVE T_PRICE TO ITAB_SO-O810PRICE. EXIT. ENDIF. ENDSELECT. ENDIF. REFRESH: ITAB_LINKED_IDOCS[], ITAB_LINKED_IDOCS. CLEAR: ITAB_LINKED_IDOCS. ELSE. "Didn't find any linked IDocs to the invoice * Save invoice number for those invoices without IDocs. Later we will * submit these numbers for saving. TITAB-O810 = ITAB_SO-O810NO. APPEND TITAB. * SUBMIT ZVF02SAVE WITH BILLING = ITAB_SO-O810NO AND RETURN. MOVE '' TO ITAB_SO-O810DOCNUM. MOVE '' TO ITAB_SO-O810DATE. MOVE '' TO ITAB_SO-I824810DOCNUM. MOVE 'N' TO ITAB_SO-I824810STAT. MOVE 'No 824 received' TO ITAB_SO-I824810NOTE. MOVE '' TO ITAB_SO-I824810DATE. MOVE '' TO ITAB_SO-O810PRICE. ENDIF. ELSE. MOVE '' TO ITAB_SO-O810DOCNUM. MOVE '' TO ITAB_SO-O810DATE. MOVE '' TO ITAB_SO-I824810DOCNUM. MOVE 'N' TO ITAB_SO-I824810STAT. MOVE 'No 824 received' TO ITAB_SO-I824810NOTE. MOVE '' TO ITAB_SO-I824810DATE. MOVE '' TO ITAB_SO-O810PRICE. MOVE '' TO ITAB_SO-O810NO. ENDIF. ENDCASE. ENDSELECT. IF SY-SUBRC = 0. ELSE. MOVE '' TO ITAB_SO-O856DOCNUM. MOVE '' TO ITAB_SO-O856DATE. MOVE '' TO ITAB_SO-O856NO. MOVE '' TO ITAB_SO-I824856DOCNUM.

2008-09

Page 245 of 328

MOVE 'N' TO ITAB_SO-I824856STAT. MOVE 'No 824 received' TO ITAB_SO-I824856NOTE. MOVE '' TO ITAB_SO-I824856DATE. MOVE '' TO ITAB_SO-O810DOCNUM. MOVE '' TO ITAB_SO-O810DATE. MOVE '' TO ITAB_SO-O810PRICE. MOVE '' TO ITAB_SO-O810NO. MOVE '' TO ITAB_SO-I824810DOCNUM. MOVE 'N' TO ITAB_SO-I824810STAT. MOVE 'No 824 received' TO ITAB_SO-I824810NOTE. MOVE '' TO ITAB_SO-I824810DATE. ENDIF. "Subsequent documents IF DELIVERY_FLAG <> 'X'. MOVE '' TO ITAB_SO-I824856DOCNUM. MOVE 'N' TO ITAB_SO-I824856STAT. MOVE 'No 824 received' TO ITAB_SO-I824856NOTE. MOVE '' TO ITAB_SO-I824856DATE. ELSE. "Delivery was found. DELIVERY_FLAG = ''. ENDIF. IF INVOICE_FLAG <> 'X'. MOVE '' TO ITAB_SO-I824810DOCNUM. MOVE 'N' TO ITAB_SO-I824810STAT. MOVE 'No 824 received' TO ITAB_SO-I824810NOTE. MOVE '' TO ITAB_SO-I824810DATE. ELSE. "Invoice was found. INVOICE_FLAG = ''. ENDIF. APPEND: ITAB_SO, ITAB_SO_EXTRA. ENDSELECT. IF SY-SUBRC NE 0. "Sales Order has no line items CLEAR ITAB_SO-POSNR. ENDIF. ENDFORM. " UPDATE_ITAB_SO *&---------------------------------------------------------------------* *& Form UPDATE_ZTABLE *&---------------------------------------------------------------------* * Update ZTABLE table with internal table data *----------------------------------------------------------------------* * -->P_ITAB_SO Internal table text containing data to be updated *----------------------------------------------------------------------* FORM UPDATE_ZTABLE TABLES P_ITAB_SO STRUCTURE ITAB_SO. MODIFY ZTABLE FROM TABLE P_ITAB_SO. IF SY-SUBRC NE 0. "Some items not updated MESSAGE I999(B1) WITH SY-DBCNT TEXT-004. ELSE. IF SY-DBCNT EQ 0. "No entries in itab_so MESSAGE I999(B1) WITH TEXT-005. ELSE. "& entries added to ZTABLE MESSAGE I999(B1) WITH SY-DBCNT TEXT-006. ENDIF. ENDIF. ENDFORM. " UPDATE_ZTABLE *&---------------------------------------------------------------------* *& Form PRINT_ITAB *&---------------------------------------------------------------------* * Print out the 2 internal tables *----------------------------------------------------------------------* * -->P_ITAB_SO ZTABLE information * -->P_ITAB_SO_EXTRA Additional information with the same key *----------------------------------------------------------------------* FORM PRINT_ITAB TABLES ITAB_SO STRUCTURE ITAB_SO ITAB_SO_EXTRA STRUCTURE ITAB_SO_EXTRA. SORT ITAB_SO BY VBELN POSNR. LOOP AT ITAB_SO. IF ITAB_SO-KUNNR IN S_KUNNR. "Only print out Customers in range SELECT SINGLE SPART AUART FROM VBAK INTO (VBAK-SPART, VBAK-AUART) WHERE VBELN = ITAB_SO-VBELN. IF SY-SUBRC = 0. IF VBAK-SPART = C_SPART_12 AND VBAK-AUART = C_AUART_ZEDI.

2008-09

Page 246 of 328

READ TABLE ITAB_SO_EXTRA WITH KEY VBELN = ITAB_SO-VBELN POSNR = ITAB_SO-POSNR BSTNK = ITAB_SO-BSTKD. IF ITAB_SO-POSNR = '000010'. FORMAT COLOR COL_KEY. IF SY-TABIX <> 1. ULINE. ENDIF. * Sales Order number WRITE:/1 ITAB_SO-VBELN. HIDE ITAB_SO-VBELN. * PO Number WRITE: ITAB_SO-BSTKD, * PO Date ITAB_SO-DATUM, * Customer Number ITAB_SO-KUNNR. * Sales order header billing block SELECT SINGLE FAKSK FROM VBAK INTO VBAK-FAKSK WHERE VBELN = ITAB_SO-VBELN. IF SY-SUBRC = 0. WRITE: VBAK-FAKSK. ENDIF. FORMAT COLOR OFF. ENDIF. * Line item number IF ITAB_SO-POSNR <> '000010'. SKIP 1. ENDIF. FORMAT COLOR COL_GROUP. WRITE:/5 ITAB_SO-POSNR, * Material Number ITAB_SO_EXTRA-MATNR, * Billing block at the line item level ITAB_SO_EXTRA-FAKSP. FORMAT COLOR COL_NORMAL. * Delivery Number WRITE:/5 'Delivery:', ITAB_SO-O856NO. HIDE ITAB_SO-O856NO. * DESADV IDoc number WRITE: ITAB_SO-O856DOCNUM. HIDE ITAB_SO-O856DOCNUM. * DESADV Date WRITE: ITAB_SO-O856DATE. IF ITAB_SO-I824856STAT = 'R' OR ITAB_SO-I824856STAT = 'X'. FORMAT COLOR COL_NEGATIVE. ELSEIF ITAB_SO-I824856STAT = 'N'. FORMAT COLOR COL_NEGATIVE. ELSEIF ITAB_SO-I824856STAT = 'A'. FORMAT COLOR COL_POSITIVE. ELSE. FORMAT COLOR COL_TOTAL. ENDIF. * 824 for 856 Status WRITE:/10 '824 for 856:', ITAB_SO-I824856STAT. MOVE ITAB_SO-I824856STAT TO T_STAT. HIDE T_STAT. * 824 for 856 IDoc Number WRITE: ITAB_SO-I824856DOCNUM. HIDE ITAB_SO-I824856DOCNUM. * 824 for 856 IDoc Date WRITE: ITAB_SO-I824856DATE, * 824 for 856 Error Text Detail ITAB_SO-I824856NOTE. MOVE ITAB_SO-I824856DOCNUM TO T_IDOC. HIDE T_IDOC. FORMAT COLOR COL_NORMAL. * Invoice number WRITE:/5 'Invoice: ', ITAB_SO-O810NO. HIDE ITAB_SO-O810NO. * INVOIC IDoc Number * If there is an invoice number but no IDoc number then highlight IF ITAB_SO-O810DOCNUM = '' AND ITAB_SO-O810NO <> ''. FORMAT COLOR COL_TOTAL. WRITE: 'NO INVOIC IDoc!'. FORMAT COLOR OFF. ELSE.

2008-09

Page 247 of 328

WRITE: ITAB_SO-O810DOCNUM. ENDIF. HIDE ITAB_SO-O810DOCNUM. * INVOIC IDoc Date WRITE: ITAB_SO-O810DATE, * INVOIC IDoc Price ITAB_SO-O810PRICE. IF ITAB_SO-I824810STAT = 'R' OR ITAB_SO-I824810STAT = 'X'. FORMAT COLOR COL_NEGATIVE. ELSEIF ITAB_SO-I824810STAT = 'N'. FORMAT COLOR COL_NEGATIVE. ELSEIF ITAB_SO-I824810STAT = 'A'. FORMAT COLOR COL_POSITIVE. ELSE. FORMAT COLOR COL_TOTAL. ENDIF. * 824 for 810 Status WRITE:/10 '824 for 810:', ITAB_SO-I824810STAT. MOVE ITAB_SO-I824856STAT TO T_STAT. HIDE T_STAT. * 824 for 810 IDoc Number WRITE: ITAB_SO-I824810DOCNUM. HIDE ITAB_SO-I824810DOCNUM. * 824 for 810 IDoc Date WRITE: ITAB_SO-I824810DATE, * 824 for 810 Error Text ITAB_SO-I824810NOTE. MOVE ITAB_SO-I824810DOCNUM TO T_IDOC. HIDE T_IDOC. FORMAT COLOR OFF. ENDIF. ENDIF. CLEAR ITAB_SO. ENDIF. ENDLOOP. ULINE. * Perform the download of the file IF P_DOWN = 'X'. PERFORM DOWNLOAD_FILE TABLES ITAB_SO USING P_FILE. ENDIF. ENDFORM. " PRINT_ITAB *&---------------------------------------------------------------------* *& Form GET_IDOC_MESTYP *&---------------------------------------------------------------------* * Loop through the internal table and check the message type * returning only the latest ones. *----------------------------------------------------------------------* * -->ITAB_LINKED_IDOCS List of IDocs linked to Document *----------------------------------------------------------------------* FORM GET_IDOC_MESTYP TABLES ITAB_LINKED_IDOCS STRUCTURE SWW_CONTOB USING VALUE(OBJECT_TYPE) T_LINE LIKE VBAP-POSNR CHANGING T_VBELN_DOCNUM T_VBELN_DATE T_824_STAT T_824_NOTE T_824_DATE T_824_DOCNUM. * Temporary local data DATA: T_DOCNUM LIKE EDIDC-DOCNUM, Z1824HD TYPE Z1824HD, Z1824TH TYPE Z1824TH, Z1824DT TYPE Z1824DT, Z1824TD TYPE Z1824TD, T_SEGNUM LIKE EDID4-SEGNUM, H_MESSAGE LIKE ZTABLE-I824856NOTE, "Header text L_MESSAGE LIKE ZTABLE-I824856NOTE, "Line item text T_MESSAGE LIKE ZTABLE-I824856NOTE, T_STATUS LIKE ZTABLE-I824856STAT, N1 TYPE I. DESCRIBE TABLE ITAB_LINKED_IDOCS LINES N1. IF N1 > 1. SORT ITAB_LINKED_IDOCS BY OBJKEY. ENDIF. CASE OBJECT_TYPE.

2008-09

Page 248 of 328

WHEN 'LIKP'. "Delivery LOOP AT ITAB_LINKED_IDOCS WHERE OBJTYPE = 'IDOC'. T_DOCNUM = ITAB_LINKED_IDOCS-OBJKEY. SELECT SINGLE DOCNUM CREDAT MESTYP FROM EDIDC INTO (EDIDC-DOCNUM, EDIDC-CREDAT, EDIDC-MESTYP) WHERE DOCNUM = T_DOCNUM. IF SY-SUBRC = 0. CASE EDIDC-MESTYP. WHEN 'DESADV'. "Outbound delivery T_VBELN_DOCNUM = EDIDC-DOCNUM. T_VBELN_DATE = EDIDC-CREDAT. WHEN 'ZAPPADV856' OR 'ZAPPADV'. "824 Signal repsonse to 856 SELECT * FROM EDID4 WHERE DOCNUM = EDIDC-DOCNUM AND SEGNAM = 'Z1824DT'. MOVE EDID4-SDATA TO Z1824DT. IF Z1824DT-POLINE <> T_LINE. "Not relevant for this line CONTINUE. ELSE. "Found 824 for this line item T_824_DOCNUM = EDIDC-DOCNUM. T_824_DATE = EDIDC-CREDAT. ENDIF. ENDSELECT. ENDCASE. ENDIF. ENDLOOP. WHEN 'VBRK'. "Invoice LOOP AT ITAB_LINKED_IDOCS WHERE OBJTYPE = 'IDOC'. T_DOCNUM = ITAB_LINKED_IDOCS-OBJKEY. SELECT SINGLE DOCNUM CREDAT MESTYP FROM EDIDC INTO (EDIDC-DOCNUM, EDIDC-CREDAT, EDIDC-MESTYP) WHERE DOCNUM = T_DOCNUM. IF SY-SUBRC = 0. CASE EDIDC-MESTYP. WHEN 'INVOIC'. "Outbound delivery T_VBELN_DOCNUM = EDIDC-DOCNUM. T_VBELN_DATE = EDIDC-CREDAT. WHEN 'ZAPPADV810' OR 'ZAPPADV'. "824 Signal repsonse to 810 SELECT * FROM EDID4 WHERE DOCNUM = EDIDC-DOCNUM AND SEGNAM = 'Z1824DT'. MOVE EDID4-SDATA TO Z1824DT. IF Z1824DT-POLINE <> T_LINE. "Not relevant for this line CONTINUE. ELSE. "Found 824 for this line item T_824_DOCNUM = EDIDC-DOCNUM. T_824_DATE = EDIDC-CREDAT. ENDIF. ENDSELECT. ENDCASE. ENDIF. ENDLOOP. ENDCASE. * Check status of the 824 IDocs IF T_824_DOCNUM IS INITIAL. "No 824 linked to Document T_824_NOTE = 'No 824 received'. T_824_STAT = 'N'. ELSE. SELECT SINGLE * FROM EDID4 WHERE DOCNUM = T_824_DOCNUM AND SEGNAM = 'Z1824HD'. IF SY-SUBRC = 0. MOVE EDID4-SDATA TO Z1824HD. CASE Z1824HD-ACKCODE. WHEN 'TA'. "Transaction accepted H_MESSAGE = 'OK'. L_MESSAGE = 'OK'. T_STATUS = 'A'. WHEN 'TR'. "Transaction rejected * Header text SELECT SINGLE * FROM EDID4 WHERE DOCNUM = T_824_DOCNUM AND SEGNAM = 'Z1824TH'. IF SY-SUBRC = 0.

2008-09

Page 249 of 328

MOVE EDID4-SDATA TO Z1824TH. H_MESSAGE = Z1824TH-LINE. ELSE. H_MESSAGE = 'No header error text segment Z1824TH'. ENDIF. "Search for Text header SELECT * FROM EDID4 WHERE DOCNUM = T_824_DOCNUM AND SEGNAM = 'Z1824DT'. MOVE EDID4-SDATA TO Z1824DT. IF Z1824DT-POLINE = T_LINE. T_SEGNUM = EDID4-SEGNUM. IF Z1824DT-ACKCODE = 'IA'. "Item accepted L_MESSAGE = 'OK'. T_STATUS = 'A'. EXIT. ELSEIF Z1824DT-ACKCODE = 'IC'. "Item accepted but changed T_STATUS = 'C'. * Line item text for that line item number SELECT SINGLE * FROM EDID4 WHERE DOCNUM = T_824_DOCNUM AND PSGNUM = T_SEGNUM AND SEGNAM = 'Z1824TD'. IF SY-SUBRC = 0. MOVE EDID4-SDATA TO Z1824TD. L_MESSAGE = Z1824TD-LINE. ELSE. L_MESSAGE = 'No error text for line item in Z1824TD'. ENDIF. EXIT. ELSE. T_STATUS = 'R'. * Line item text for that line item number SELECT SINGLE * FROM EDID4 WHERE DOCNUM = T_824_DOCNUM AND PSGNUM = T_SEGNUM AND SEGNAM = 'Z1824TD'. IF SY-SUBRC = 0. MOVE EDID4-SDATA TO Z1824TD. L_MESSAGE = Z1824TD-LINE. ELSE. L_MESSAGE = 'No error text for line item in Z1824TD'. ENDIF. EXIT. ENDIF. "Item accepted ELSE. "Wrong line item CONTINUE. ENDIF. ENDSELECT. "Select on Z1824TD IF SY-SUBRC <> 0. L_MESSAGE = 'No item details in 824!'. * Header text SELECT SINGLE * FROM EDID4 WHERE DOCNUM = T_824_DOCNUM AND SEGNAM = 'Z1824TH'. IF SY-SUBRC = 0. MOVE EDID4-SDATA TO Z1824TH. H_MESSAGE = Z1824TH-LINE. ELSE. H_MESSAGE = 'No header error text'. ENDIF. ENDIF. * T_STATUS = 'R'. ENDCASE. CONCATENATE H_MESSAGE '|' L_MESSAGE INTO T_MESSAGE. T_824_NOTE = T_MESSAGE. T_824_STAT = T_STATUS. ELSE. T_824_NOTE = 'No Line item detail segment in 824'. T_STATUS = 'X'. ENDIF. ENDIF. ENDFORM. " GET_IDOC_MESTYP *&---------------------------------------------------------------------* *& Form DOWNLOAD_FILE *&---------------------------------------------------------------------* * Update column headings and perform download to file. *----------------------------------------------------------------------*

2008-09

Page 250 of 328

* -->ITAB_SO ZTABLE table * -->P_FILE File name for download *----------------------------------------------------------------------* FORM DOWNLOAD_FILE TABLES ITAB_SO STRUCTURE ITAB_SO USING P_FILE. *** Populate Itabs for download * Column names MOVE 'Client' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE 'PO Number' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE 'PO Line Number' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE 'SO Number' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE 'PO Date' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE 'Customer' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE 'Delivery Date' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE 'Delivery IDoc Number' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE 'Delivery Number' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE '824 Status for 856' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE '824 Date for 856' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE '824 IDoc for 856' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE '824 Note for 856' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE 'Invoice Date' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE 'Invoice IDoc Number' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE 'Invoice Number' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE 'Invoice Price' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE '824 Status for 810' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE '824 Date for 810' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE '824 IDoc for 810' TO T_COLNAMES-NAME. APPEND T_COLNAMES. MOVE '824 Note for 810' TO T_COLNAMES-NAME. APPEND T_COLNAMES. * Write data in internal table ITAB_SO to file specified in parameters CALL FUNCTION 'WS_DOWNLOAD' EXPORTING FILENAME = P_FILE FILETYPE = 'DAT' TABLES DATA_TAB = ITAB_SO FIELDNAMES = T_COLNAMES EXCEPTIONS FILE_OPEN_ERROR =1 FILE_WRITE_ERROR =2 INVALID_FILESIZE =3 INVALID_TABLE_WIDTH = 4 INVALID_TYPE =5 NO_BATCH =6 UNKNOWN_ERROR =7 GUI_REFUSE_FILETRANSFER = 8 OTHERS = 9. IF SY-SUBRC = 0. ELSEIF SY-SUBRC = 1. MESSAGE I027(Z3) WITH P_FILE. ELSEIF SY-SUBRC = 2. MESSAGE I028(Z3) WITH P_FILE. ELSEIF SY-SUBRC = 3. MESSAGE I001(Z4) WITH P_FILE.

2008-09

Page 251 of 328

ELSEIF SY-SUBRC = 4. MESSAGE I002(Z4) WITH P_FILE. ELSEIF SY-SUBRC = 5. MESSAGE I003(Z4) WITH P_FILE. ELSEIF SY-SUBRC = 6. MESSAGE I004(Z4) WITH P_FILE. ELSEIF SY-SUBRC = 7. MESSAGE I005(Z4) WITH P_FILE. ELSEIF SY-SUBRC = 8. MESSAGE I006(Z4) WITH P_FILE. ELSE. MESSAGE I007(Z4) WITH P_FILE. ENDIF. ENDFORM. " DOWNLOAD_FILE *&---------------------------------------------------------------------* *& Form SAVE_BILLING_DOC *&---------------------------------------------------------------------* * Loop through the internal table set up to store the invoice numbers * of those invoices that do not have INVOIC Idocs attached to them. * i.e. The ZD01 output was not created for some reason. * By saving the invoice (which is what this program does) the output * should be generated. *----------------------------------------------------------------------* * -->TITAB Stores invoice numbers of those invoices that do not * have INVOIC IDocs linked to them. *----------------------------------------------------------------------* FORM SAVE_BILLING_DOC TABLES TITAB STRUCTURE TITAB. DATA: N TYPE I. LOOP AT TITAB. SUBMIT ZVF02SAVE WITH BILLING = TITAB-O810 AND RETURN. MESSAGE I009(Z4) WITH TITAB-O810. ENDLOOP. IF SY-SUBRC = 0. DESCRIBE TABLE TITAB LINES N. MESSAGE I008(Z4) WITH N. ENDIF. ENDFORM. " SAVE_BILLING_DOC

6.10.5

Example upload file to IDoc

REPORT ZS7BM000005 message-id ZS7. *______________________________________________________________________ */ Program Name: Creation of ORDRSP IDocs from file E020 */ Description : This program reads in external file E020 containing * order confirmation data from internal vendors and * creates one ORDRSP IDoc per PO. */ Transaction : n/a - run from job Z_ccc_S7B_Dnnnnn, * where 'ccc' = 3-digit client and 'nnnnn' = zero-filled * sequence number. *______________________________________________________________________ tables: lfa1, e1edk01, e1edk02, e1edp01, e1edp19, e1edp20, e1edp02, e1eds01, zst7f_ty_vendors. parameters: p_path like PATH-PATHEXTERN default '/ftp/atac/in/'. data: INFILE LIKE PATH-PATHEXTERN, back_path(7) type c value 'backup/', info_no like ekpo-infnr, offset like sy-fdpos, p01_ctr like sy-index, seg_num like sy-index. data: OUTFILE LIKE PATH-PATHEXTERN, today(8) type c, outfile_err(1) type c.

2008-09

Page 252 of 328

data: begin of uty_vendors occurs 10, lifnr like lfa1-lifnr, name_abbr like zst7f_ty_vendors-name_abbr, site_code like zst7f_ty_vendors-site_code, ship_days like zst7f_ty_vendors-ship_days, end of uty_vendors. data: iZSS7B20 like ZSS7B20. data: idocdata like edi_dd occurs 5 with header line. data: iedidc like edi_dc occurs 1 with header line. data: begin of ie020 occurs 10, lifnr like lfa1-lifnr, ship_days like zst7f_ty_vendors-ship_days, po_number(10) type n, po_lineno(5) type n, slip_number like e1edp02-belnr, sched_date like e1edp02-datum, "char 8 sched_qty like e1edp20-wmeng, cust_partno like e1edp19-idtnr, vendor_partno like e1edp19-mfrpn, sched_deliv_date like e1edp20-edatu, "format OK - ccyymmdd uom like e1edp01-menee, qty_ordered like e1edp01-menge, end of ie020. data: save_po like ie020-po_number, save_line like ie020-po_lineno, save_vend_part like ie020-vendor_partno, save_cust_part like ie020-cust_partno. *-----------------------------------------------------------------* MAIN PROCESSING LOOP *-----------------------------------------------------------------START-OF-SELECTION. today = sy-datlo. * find all internal vendors select a~lifnr b~name_abbr b~site_code b~ship_days into corresponding fields of table uty_vendors from lfa1 as a inner join zst7f_ty_vendors as b on a~lifnr = b~lifnr where a~ktokk = 'ZZTY' and b~ship_code = ' '. concatenate 'SAP' sy-sysid(3) into iedidc-sndpor. * initialize control record: move: '2' to iedidc-direct, 'ORDERS01' to iedidc-doctyp, 'ORDRSP' to iedidc-mestyp, 'F' to iedidc-std, 'E020' to iedidc-stdmes, 'LS' to iedidc-sndprt, 'TY_VENDORS' to iedidc-sndprn, sy-datlo to iedidc-credat, sy-timlo to iedidc-cretim. append iedidc. e1edk01-action = '000'. loop at uty_vendors. clear ie020. refresh ie020. if not uty_vendors-name_abbr is initial. * datafiles are received with naming convention: * E020_<customer name abbreviation>_UTY concatenate p_path 'E020_' uty_vendors-name_abbr '_UTY'

2008-09

Page 253 of 328

into infile. if not sy-subrc is initial. "pathname too long * Filename too long: & message w016 with infile. continue. endif. condense infile. OPEN DATASET INFILE FOR INPUT IN TEXT MODE. if not sy-subrc is initial. *'Cannot open dataset & on &' message i013 with infile sy-datum. else. "successful file open concatenate p_path back_path 'E020_' uty_vendors-name_abbr '_UTY' today into outfile. if not sy-subrc is initial. "pathname too long * Filename too long: & message w016 with outfile. continue. endif. condense outfile. OPEN DATASET OUTFILE FOR OUTPUT IN TEXT MODE. * if the timestamped file cannot be created, do not process the * input file, because the input file is deleted after processing, * and there would be no record of the data. if not sy-subrc is initial. *'ERROR opening file & for output' close dataset infile. message i033 with outfile. continue. "process next vendor's file endif. do. read dataset infile into izss7b20. case sy-subrc. when 0. transfer izss7b20 to outfile. if izss7b20-datacode = 'T'. "trailer rec perform process_one_vendor using infile. exit. "process next vendor's file endif. check izss7b20-datacode = 'D'. "data rec move-corresponding uty_vendors to ie020. move-corresponding izss7b20 to ie020. perform convert_po_no using izss7b20-pono_poline changing ie020-po_number ie020-po_lineno. perform convert_date using izss7b20-sched_date izss7b20-sched_type izss7b20-ship_method changing ie020-sched_date ie020-ship_days ie020-sched_deliv_date. perform convert_quantities using izss7b20-uom izss7b20-sched_qty izss7b20-qty_ordered changing ie020-uom ie020-sched_qty ie020-qty_ordered. append ie020. when 4. "EOF perform process_one_vendor using infile. exit. "process next vendor's file when others. *ERROR reading dataset & on & message w015 with infile sy-datum. exit. "discontinue file reads endcase. enddo. close dataset: infile, outfile. delete dataset infile. endif. endif. endloop. "UTY_VENDORS *&---------------------------------------------------------------------*

2008-09

Page 254 of 328

*& Form process_one_vendor *&---------------------------------------------------------------------* * Records from one vendor file are now in the internal table * ie020. *----------------------------------------------------------------------* FORM process_one_vendor using value(infile). sort ie020 by po_number po_lineno. loop at ie020. if sy-tabix > 1. if ( ie020-po_number <> save_po or ie020-po_lineno <> save_line ). perform idoc_mat_seg. endif. endif. if ie020-po_number <> save_po. if sy-tabix > 1. perform post_prev_idoc. endif. perform idoc_header_segs. endif. if ( ie020-po_number <> save_po or ie020-po_lineno <> save_line ). if sy-tabix > 1. perform idoc_item_segs. endif. endif. perform idoc_sched_segs. save_po = ie020-po_number. save_line = ie020-po_lineno. save_vend_part = ie020-vendor_partno. save_cust_part = ie020-cust_partno. endloop. perform idoc_mat_seg. perform post_prev_idoc. * File successfully processed: & message s035 with infile. ENDFORM. " process_one_vendor

*&---------------------------------------------------------------------* *& Form convert_po_no *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM convert_po_no using value(infield) changing po_number like ie020-po_number po_line like ie020-po_lineno. data: cpos like sy-fdpos, lpos like sy-fdpos, cline(6) type c. * if the infield contains a hyphen, assume that the preceding characters * represent the po number, if they are numeric. The po line number is * assumed to be all numeric characters after the hyphen. if infield ca '-'. if infield(sy-fdpos) co ' 0123456789'. "numeric po_number = infield(sy-fdpos). cpos = sy-fdpos + 1. endif. else. "no hyphen - PTY if infield(2) = '71'. "SAP number range cpos = 10. else. "SyteLine number cpos = 6. endif. if infield(cpos) co ' 0123456789'. "numeric po_number = infield(cpos). endif. endif. if not po_number is initial. while infield+cpos(1) co '0123456789'. cline+lpos(1) = infield+cpos(1). lpos = lpos + 1. cpos = cpos + 1.

2008-09

Page 255 of 328

endwhile. shift cline left deleting leading '0'. if not cline is initial. po_line = cline. endif. endif. * Put out a warning in the job log, but create the IDoc to save the data if ( po_number is initial or po_line is initial ). * PO number - line item conversion failed: & message w016 with infield. endif. ENDFORM. " convert_po_no

*&---------------------------------------------------------------------* *& Form convert_date *&---------------------------------------------------------------------* * Convert yymmdd to ccyymmdd for SAP and * convert ship date to delivery date *----------------------------------------------------------------------* FORM convert_date USING value(DATE6) value(DATE_TYPE) value(i_ship_code) CHANGING DATE8 like IE020-SCHED_DATE SHIP_DAYS like ie020-ship_days DELIVERY_DATE like ie020-sched_deliv_date. data: cent(2) type c, d_date type d. * add century to schedule date check date6 cn ' /0'. if date6(2) < '90'. cent = '20'. else. cent = '19'. endif. concatenate cent date6 into date8. * convert ship date to delivery date (if necessary) if date_type <> 'ETA'. " delivery date not sent if not i_ship_code is initial. "ship method sent select single ship_days from zst7f_ty_vendors into ship_days where lifnr = ie020-lifnr and ship_code = i_ship_code. endif. * defaut ship_days are passed in and will be changed only * if a number specific to the shipping method is found in * the select above if ( ship_days > 0 and not delivery_date is initial ). * put the date into a date field, so SAP will do date math d_date = delivery_date. d_date = d_date + ship_days. delivery_date = d_date. shift delivery_date left deleting leading ' '. endif. endif. ENDFORM. " convert_date

*&---------------------------------------------------------------------* *& Form quantity_conversion *&---------------------------------------------------------------------* * The quantities in the input file are implied 3-decimal, * so need to be converted into a "real" number. * Also, the unit of measure may be 'KP' indicating that the qty * is given in thousands. *----------------------------------------------------------------------* FORM convert_quantities USING value(i_UOM) value(i_confirm_qty)

2008-09

Page 256 of 328

value(i_QTY_ORDERED) CHANGING o_uom like iE020-UOM o_confirm_qty like IE020-SCHED_QTY o_qty_ordered like IE020-QTY_ORDERED. constants: thou type p decimals 3 value '1000'. data: n_confirm_qty like ekpo-menge, n_qty_ordered like ekpo-menge. if ( i_confirm_qty co ' 0123456789' and i_confirm_qty cn ' 0' ). n_confirm_qty = i_confirm_qty. n_confirm_qty = n_confirm_qty / thou. endif. if ( i_qty_ordered co ' 0123456789' and i_qty_ordered cn ' 0' ). n_qty_ordered = i_qty_ordered. n_qty_ordered = n_qty_ordered / thou. endif. if i_uom = 'KP'. n_confirm_qty = n_confirm_qty / thou. n_qty_ordered = n_qty_ordered / thou. endif. o_uom = 'PCE'. if not n_confirm_qty is initial. o_confirm_qty = n_confirm_qty. shift o_confirm_qty left deleting leading space. else. clear o_confirm_qty. endif. if not n_qty_ordered is initial. o_qty_ordered = n_qty_ordered. shift o_qty_ordered left deleting leading space. else. clear o_qty_ordered. endif. ENDFORM. " convert_quantities

*&---------------------------------------------------------------------* *& Form idoc_header_segs *&---------------------------------------------------------------------* * create internal table entries for PO header segments: * E1EDK01 * E1EDK02 *----------------------------------------------------------------------* FORM idoc_header_segs. clear seg_num. idocdata-segnam = 'E1EDK01'. idocdata-sdata = e1edk01. perform append_idoc_rec. clear e1edk02. idocdata-segnam = 'E1EDK02'. e1edk02-qualf = '001'. e1edk02-belnr = ie020-po_number. idocdata-sdata = e1edk02. perform append_idoc_rec. ENDFORM. " idoc_header_segs

*&---------------------------------------------------------------------* *& Form idoc_item_segs *&---------------------------------------------------------------------* * create internal table entries for PO item header segments: * E1EDP01 * E1EDP02 *----------------------------------------------------------------------* FORM idoc_item_segs. clear e1edp01. idocdata-segnam = 'E1EDP01'.

2008-09

Page 257 of 328

e1edp01-menee = ie020-uom. e1edp01-menge = ie020-qty_ordered. idocdata-sdata = e1edp01. perform append_idoc_rec. clear e1edp02. idocdata-segnam = 'E1EDP02'. e1edp02-qualf = '001'. e1edp02-belnr = ie020-po_number. e1edp02-zeile = ie020-po_lineno. idocdata-sdata = e1edp02. perform append_idoc_rec. idocdata-segnam = 'E1EDP02'. clear e1edp02. e1edp02-qualf = '002'. e1edp02-belnr = ie020-slip_number. e1edp02-datum = ie020-sched_date. idocdata-sdata = e1edp02. perform append_idoc_rec. p01_ctr = p01_ctr + 1. ENDFORM. " idoc_item_segs *&---------------------------------------------------------------------* *& Form idoc_sched_segs *&---------------------------------------------------------------------* * create internal table entries for PO item schedule segments: * E1EDP20 *----------------------------------------------------------------------* FORM idoc_sched_segs. clear e1edp20. idocdata-segnam = 'E1EDP20'. e1edp20-edatu = ie020-sched_deliv_date. e1edp20-wmeng = ie020-sched_qty. idocdata-sdata = e1edp20. perform append_idoc_rec. ENDFORM. " idoc_sched_segs

*&---------------------------------------------------------------------* *& Form idoc_mat_seg *&---------------------------------------------------------------------* * create internal table entries for PO item material no. segments: * E1EDP19 *----------------------------------------------------------------------* FORM idoc_mat_seg. tables: ekpo. clear e1edp19. idocdata-segnam = 'E1EDP19'. e1edp19-qualf = '002'. e1edp19-idtnr = save_vend_part. e1edp19-mfrpn = save_cust_part. idocdata-sdata = e1edp19. perform append_idoc_rec. clear e1edp19. select single matnr from ekpo into e1edp19-idtnr where ebeln = save_po and ebelp = save_line. if not e1edp19-idtnr is initial. idocdata-segnam = 'E1EDP19'. e1edp19-qualf = '001'. idocdata-sdata = e1edp19. perform append_idoc_rec. endif. ENDFORM. " idoc_mat_seg

*********************************************************************** *& Form post_prev_idoc *&---------------------------------------------------------------------* * create a database idoc from the idocdata table and clear table.

2008-09

Page 258 of 328

*----------------------------------------------------------------------* FORM post_prev_idoc. clear e1eds01. idocdata-segnam = 'E1EDS01'. e1eds01-sumid = '001'. e1eds01-summe = p01_ctr. shift e1eds01-summe left deleting leading space. idocdata-sdata = e1eds01. perform append_idoc_rec. CALL FUNCTION 'INBOUND_IDOC_PROCESS' TABLES IDOC_CONTROL = iedidc IDOC_DATA = idocdata. commit work. refresh idocdata. clear: idocdata, p01_ctr, save_po, save_line, save_vend_part, save_cust_part. ENDFORM. " post_prev_idoc

*&---------------------------------------------------------------------* *& Form append_idoc_rec *&---------------------------------------------------------------------* * add a data record to the IDoc internal table *----------------------------------------------------------------------* FORM append_idoc_rec. idocdata-tabnam = idocdata-segnam. seg_num = seg_num + 1. idocdata-segnum = seg_num. shift idocdata-segnum left deleting leading space. append idocdata. clear idocdata. ENDFORM. " append_idoc_rec

6.10.6

IDoc creation from inbound file

REPORT ZS7BM000006 message-id ZS7. *______________________________________________________________________ */ Program Name: Creation of DESADV & INVOIC IDocs from file E021 */ Description : This program reads in external file E021 containing * shipping and invoice data from internal vendors and * creates one DESADV and one INVOIC IDoc per invoice. */ Transaction : n/a - run from job Z_ccc_S7B_Annnnn, where * 'ccc' = 3-digit client and 'nnnnn' = zero-filled * sequence number matching the scheduled job for E020. *______________________________________________________________________ tables: lfa1, lfm1, ekpo, eine, e1edk01, e1edk02, e1edk07, e1edk08, e1edk06, e1edk03, e1edka1, e1edka2, e1edp07, e1edp09, e1edp19, e1edp01, e1edp02, e1edp26,

2008-09

Page 259 of 328

e1edp04, e1eds01, e1eds02, zst7f_ty_vendors. parameters: p_path like PATH-PATHEXTERN default '/ftp/atac/in/'. data: INFILE LIKE PATH-PATHEXTERN, back_path(7) type c value 'backup/', offset like sy-fdpos, p07_ctr like sy-index, invoice_total type p decimals 3, d_seg_num like sy-index, i_seg_num like sy-index. data: OUTFILE LIKE PATH-PATHEXTERN, today(8) type c. data: begin of uty_vendors occurs 10, lifnr like lfa1-lifnr, waers like lfm1-waers, name_abbr like zst7f_ty_vendors-name_abbr, ship_days like zst7f_ty_vendors-ship_days, end of uty_vendors. data: iZSS7B21 like ZSS7B21. data: data: data: data: desadvdata like edi_dd occurs 5 with header line. invoicdata like edi_dd occurs 5 with header line. dedidc like edi_dc occurs 1 with header line. iedidc like edi_dc occurs 1 with header line.

data: begin of ie021 occurs 10, lifnr like lfa1-lifnr, ship_days like zst7f_ty_vendors-ship_days, invoice_no like e1edk08-vbeln, stat like e1edk01-action, po_number(10) type n, po_lineno(5) type n, slip_number like e1edp09-vbeln, shipto_id like e1edka1-partn, vendor_id like e1edka1-partn, endcust_name like e1edka1-name1, cust_partno like e1edp09-kdmat, "char 35 vendor_partno like e1edp09-matnr, "char 35 invoice_qty like e1edp09-lfimg, qty_uom like e1edp01-menee, unit_price like e1edp01-vprei, price_uom like e1edp01-pmene, price_qty like e1edp01-peinh, line_amount like e1edp26-betrg, currency like e1edk01-curcy, etd like e1edk06-datum, "ship date eta like e1edk06-datum, "delivery date ship_id like e1edk08-traid, ship_method like e1edk08-traty, create_date like e1edk03-datum, plant like ekpo-werks, end of ie021. data: save_po like ie021-po_number, save_line like ie021-po_lineno, save_stat like ie021-stat, save_invoice like ie021-invoice_no. constants: hun_thou type p decimals 5 value '100000', thou type p decimals 3 value '1000'. *&---------------------------------------------------------------------* *& DEFINITION: append_idoc_rec *&---------------------------------------------------------------------* * add a data record to the IDoc internal table *----------------------------------------------------------------------* define append_idoc_rec.

2008-09

Page 260 of 328

&1-tabnam = &1-segnam. &2_seg_num = &2_seg_num + 1. &1-segnum = &2_seg_num. shift &1-segnum left deleting leading space. append &1. clear &1. end-of-definition. " append_idoc_rec

*-----------------------------------------------------------------* MAIN PROCESSING LOOP *-----------------------------------------------------------------START-OF-SELECTION. today = sy-datum. * find all internal vendors select a~lifnr b~waers c~name_abbr c~ship_days into corresponding fields of table uty_vendors from lfa1 as a inner join lfm1 as b on a~lifnr = b~lifnr inner join zst7f_ty_vendors as c on a~lifnr = c~lifnr where a~ktokk = 'ZZTY' and b~ekorg = '7100' and c~ship_code = ' '. perform init_desadv. perform init_invoic. concatenate 'SAP' sy-sysid(3) into: iedidc-sndpor, dedidc-sndpor. loop at uty_vendors. clear ie021. refresh ie021. if not uty_vendors-name_abbr is initial. * datafiles are received with naming convention: * E020_<customer name abbreviation>_UTY concatenate p_path 'E021_' uty_vendors-name_abbr '_UTY' into infile. if not sy-subrc is initial. "pathname too long * Filename too long: & message i016 with infile. continue. endif. condense infile. OPEN DATASET INFILE FOR INPUT IN TEXT MODE. if not sy-subrc is initial. *'Cannot open dataset & on &' message i013 with infile sy-datum. continue. else. concatenate p_path back_path 'E021_' uty_vendors-name_abbr '_UTY' today into outfile. if not sy-subrc is initial. "pathname too long * Filename too long: & message i016 with outfile. continue. endif. condense outfile. OPEN DATASET OUTFILE FOR OUTPUT IN TEXT MODE. * if the datestamped file cannot be created, do not process the * input file, because the input file is deleted after processing, * and there would be no record of the data. if not sy-subrc is initial. *'ERROR opening file & for output' close dataset infile. message i033 with outfile. continue. "process next vendor's file

2008-09

Page 261 of 328

endif. do. read dataset infile into izss7b21. case sy-subrc. when 0. transfer izss7b21 to outfile. if izss7b21-datacode = 'T'. "trailer rec perform process_one_vendor using infile. exit. "process next vendor's file endif. check: izss7b21-datacode = 'A'. "data rec case izss7b21-status. when ' '. "new ie021-stat = '000'. when 'M'. "modification ie021-stat = '002'. when 'D'. "deletion ie021-stat = '003'. endcase. move-corresponding uty_vendors to ie021. move-corresponding izss7b21 to ie021. perform convert_po_no using izss7b21-pono_poline changing ie021-po_number ie021-po_lineno. perform convert_dates using ie021-lifnr izss7b21-etd izss7b21-eta izss7b21-ship_method izss7b21-create_date changing ie021-eta ie021-ship_days. perform quantity_conversion using izss7b21-qty_uom izss7b21-invoice_qty izss7b21-unit_price changing ie021-qty_uom ie021-invoice_qty izss7b21-line_amount. perform money_conversion using izss7b21-currency izss7b21-unit_price izss7b21-price_uom izss7b21-line_amount changing ie021-currency ie021-price_uom ie021-price_qty ie021-unit_price ie021-line_amount. perform SAP_vendor_partno changing ie021-cust_partno. append ie021. when 4. "EOF perform process_one_vendor using infile. exit. "process next vendor's file when others. *ERROR reading dataset & - & message i015 with infile sy-datum. exit. endcase. enddo. close dataset: infile, outfile. delete dataset infile. endif. endif. endloop. "UTY_VENDORS *&---------------------------------------------------------------------* *& Form process_one_vendor *&---------------------------------------------------------------------* * Pre-processed records from one vendor file are now in the * internal table ie021 - ready to create IDocs *----------------------------------------------------------------------* FORM process_one_vendor using value(infile). sort ie021 by invoice_no stat po_number po_lineno. loop at ie021.

2008-09

Page 262 of 328

if ( ie021-invoice_no <> save_invoice or ie021-stat <> save_stat ). if sy-tabix > 1. perform post_idocs using ie021-stat. endif. perform idoc_header_segs using ie021-stat. endif. if ( ie021-stat <> save_stat or ie021-po_number <> save_po or ie021-po_lineno <> save_line or ie021-invoice_no <> save_invoice ). if ( sy-tabix > 1 and ie021-stat = '000' ). perform idoc_poheader_segs. endif. endif. perform idoc_item_segs using ie021-stat. save_po = ie021-po_number. save_line = ie021-po_lineno. save_invoice = ie021-invoice_no. save_stat = ie021-stat. endloop. perform post_idocs using ie021-stat. * File successfully processed: & message s035 with infile. ENDFORM. " process_one_vendor

*&---------------------------------------------------------------------* *& Form convert_po_no *&---------------------------------------------------------------------* * Break the PO number & line field into separate fields *----------------------------------------------------------------------* FORM convert_po_no using value(infield) changing po_number like ie021-po_number po_line like ie021-po_lineno. data: cpos like sy-fdpos, lpos like sy-fdpos, cline(6) type c. * if the infield contains a hyphen, assume that the preceding characters * represent the po number, if they are numeric. The po line number is * assumed to be all numeric characters after the hyphen. if infield ca '-'. if infield(sy-fdpos) co ' 0123456789'. "numeric po_number = infield(sy-fdpos). cpos = sy-fdpos + 1. endif. else. "no hyphen - PTY if infield(2) = '71'. "SAP number range cpos = 10. else. "SyteLine number cpos = 6. endif. if infield(cpos) co ' 0123456789'. "numeric po_number = infield(cpos). endif. endif. if not po_number is initial. while infield+cpos(1) co '0123456789'. cline+lpos(1) = infield+cpos(1). lpos = lpos + 1. cpos = cpos + 1. endwhile. shift cline left deleting leading '0'. if not cline is initial. po_line = cline. endif. endif. * Put out a warning in the job log, but create the IDoc to save the data if ( po_number is initial or po_line is initial ). * PO number - line item conversion failed: & message i034 with infield.

2008-09

Page 263 of 328

endif. ENDFORM.

" convert_po_no

*&---------------------------------------------------------------------* *& Form convert_dates *&---------------------------------------------------------------------* * Convert ship date to delivery date, if necessary *----------------------------------------------------------------------* FORM convert_dates using value(vendor_no) value(i_ship_date) value(i_delivery_date) value(i_ship_code) value(i_create_date) changing o_delivery_date ship_days. data: ship_date type d. * if delivery date not sent, calculate it from ship date plus * ship days. * Note that this logic could leave delivery date blank, * if ship date is not numeric. if ( i_delivery_date is initial or i_delivery_date co ' 0' ). "no delivery date sent if ( i_ship_date co ' 0123456789' and i_ship_date cn ' 0' ). "ship date sent * move the ship date into a date field to add days ship_date = i_ship_date. elseif ( i_create_date co ' 0123456789' and i_create_date cn ' 0' ). ship_date = i_create_date. endif. if not i_ship_code is initial. select single ship_days from zst7f_ty_vendors into ship_days where lifnr = vendor_no and ship_code = i_ship_code. endif. if not ship_date is initial. if ship_days > 0. ship_date = ship_date + ship_days. o_delivery_date = ship_date. shift o_delivery_date left deleting leading ' '. endif. endif. else. "delivery date sent o_delivery_date = i_delivery_date. endif. ENDFORM. " convert_dates

*&---------------------------------------------------------------------* *& Form quantity_conversion *&---------------------------------------------------------------------* * The quantities in the input file are implied 3-decimal, * so need to be converted into a "real" number. * Also, the unit of measure may be 'KP' indicating that the qty * is given in thousands. *----------------------------------------------------------------------* FORM quantity_conversion USING value(i_UOM) value(i_invoice_qty) value(i_unit_price) CHANGING o_uom like iE021-qty_UOM o_invoice_qty like IE021-INVOICE_QTY c_LINE_AMOUNT like izss7b21-line_amount. data: data: data: data: data: f_invoice_qty type f. n_invoice_qty like lips-kcmeng. f_unit_price type f. f_line_amt type f. n_line_amt0 type p decimals 0.

if ( i_invoice_qty co ' 0123456789' and i_invoice_qty cn ' 0' ). f_invoice_qty = i_invoice_qty. * if no extended price is sent, calculate it

2008-09

Page 264 of 328

if c_line_amount is initial. * the qty is implied 3-dec, the price is still implied * 5-dec, and line amount should be implied 3-dec. f_unit_price = i_unit_price. f_line_amt = ( f_invoice_qty * f_unit_price ) / 100000. n_line_amt0 = f_line_amt. c_line_amount = n_line_amt0. shift c_line_amount left deleting leading space. endif. * if the invoice qty is per 1000, the implied 3-dec times 1000 equals * the unconverted value. Otherwise, divide by 1000 to get the PCE qty if i_uom = 'KP'. n_invoice_qty = f_invoice_qty. else. n_invoice_qty = f_invoice_qty / thou. endif. endif. o_uom = 'PCE'. if not n_invoice_qty is initial. o_invoice_qty = n_invoice_qty. shift o_invoice_qty left deleting leading space. else. clear o_invoice_qty. endif. ENDFORM. " quantity_conversion

*&---------------------------------------------------------------------* *& Form money_conversion *&---------------------------------------------------------------------* * Add the implied decimals and store price-per qty, if * price per 1,000 is sent. *----------------------------------------------------------------------* FORM money_conversion USING value(I_CURR) value(i_UNIT_PRICE) value(i_UOM) value(i_LINE_AMOUNT) CHANGING o_CURRENCY like ie021-currency o_PRICE_UOM like ie021-price_uom o_PRICE_QTY like ie021-price_qty o_UNIT_PRICE like ie021-unit_price o_LINE_AMOUNT like ie021-line_amount. data: n_unit_price type p decimals 5, n_line_amount type p decimals 3. * not all of the vendors send the currency code, so use the vendor * master default case i_curr(2). when 'US'. o_currency = 'USD'. when 'JP'. o_currency = 'JPY'. when others. o_currency = uty_vendors-waers. endcase. * unit price is implied 5-dec if ( i_unit_price cn ' 0' and i_unit_price co ' 0123456789' ). n_unit_price = i_unit_price. n_unit_price = n_unit_price / hun_thou. endif. * line price is implied 3-dec if ( i_line_amount co ' 0123456789' and i_line_amount cn ' 0' ). n_line_amount = i_line_amount. n_line_amount = n_line_amount / thou. endif. * 'KP' = price per thousand if i_uom = 'KP'. o_price_qty = '1000'.

2008-09

Page 265 of 328

else. o_price_qty = '1'. endif. o_price_uom = 'PCE'. if not n_unit_price is initial. o_unit_price = n_unit_price. shift o_unit_price left deleting leading space. else. clear o_unit_price. endif. if not n_line_amount is initial. o_line_amount = n_line_amount. shift o_line_amount left deleting leading space. else. clear o_line_amount. endif. ENDFORM. " money_conversion

*&---------------------------------------------------------------------* *& Form SAP_vendor_partno *&---------------------------------------------------------------------* * replace UTY part number sent by vendor with SAP material no. * from PO line item. *----------------------------------------------------------------------* FORM SAP_vendor_partno changing cust_partno like ie021-cust_partno. tables: makt. data: partno_sent like makt-maktx. partno_sent = cust_partno. clear: makt, cust_partno. select single matnr from ekpo into cust_partno where ebeln = ie021-po_number and ebelp = ie021-po_lineno. if sy-subrc is initial. *compare material description to part number sent by vendor select single maktx from makt into makt-maktx where matnr = cust_partno. if partno_sent <> makt-maktx. * 'Part No. Mismatch: PO & - &, Part sent &, SAP mat.no. &' message i031 with ie021-po_number ie021-po_lineno partno_sent makt-maktx. endif. else. "PO line not found *try to find SAP material number using 20-char catalog no. sent select single matnr from makt into cust_partno where maktx = partno_sent. if not sy-subrc is initial. * 'SAP material no. not found for & - PO & - &' message i032 with partno_sent ie021-po_number ie021-po_lineno. endif. endif. *if not found, IDoc will go to workflow for missing material no. ENDFORM. " SAP_vendor_partno

*&---------------------------------------------------------------------* *& Form idoc_header_segs *&---------------------------------------------------------------------* * create internal table entries for header segments. * DESADV: * E1EDK07 * E1EDKA1 * E1EDK03 * E1EDK08 * E1EDKA2 * E1EDK06 * INVOIC: * E1EDK01 * E1EDKA1(s) * E1EDK02 * E1EDK03(s)

2008-09

Page 266 of 328

*----------------------------------------------------------------------* FORM idoc_header_segs using value(desadv_ok). * INVOIC clear i_seg_num. invoicdata-segnam = 'E1EDK01'. e1edk01-action = ie021-stat. if ie021-currency(2) = 'US'. e1edk01-curcy = 'USD'. else. e1edk01-curcy = 'JPY'. endif. invoicdata-sdata = e1edk01. append_idoc_rec invoicdata i. clear e1edka1. invoicdata-segnam = 'E1EDKA1'. e1edka1-parvw = 'RE'. e1edka1-partn = ie021-shipto_id. invoicdata-sdata = e1edka1. append_idoc_rec invoicdata i. clear e1edka1. invoicdata-segnam = 'E1EDKA1'. e1edka1-parvw = 'LF'. e1edka1-partn = ie021-lifnr. e1edka1-lifnr = ie021-shipto_id. invoicdata-sdata = e1edka1. append_idoc_rec invoicdata i. if not ie021-endcust_name is initial. clear e1edka1. invoicdata-segnam = 'E1EDKA1'. e1edka1-parvw = 'WE'. e1edka1-name1 = ie021-endcust_name. invoicdata-sdata = e1edka1. append_idoc_rec invoicdata i. endif. clear e1edk02. invoicdata-segnam = 'E1EDK02'. e1edk02-qualf = '009'. e1edk02-belnr = ie021-invoice_no. invoicdata-sdata = e1edk02. append_idoc_rec invoicdata i. clear e1edk03. invoicdata-segnam = 'E1EDK03'. e1edk03-iddat = '012'. e1edk03-datum = ie021-create_date. invoicdata-sdata = e1edk03. append_idoc_rec invoicdata i. invoicdata-segnam = 'E1EDK03'. e1edk03-iddat = '024'. invoicdata-sdata = e1edk03. append_idoc_rec invoicdata i. check desadv_ok = '000'. * DESADV clear d_seg_num. desadvdata-segnam = 'E1EDK07'. e1edk07-action = ie021-stat. e1edk07-bolnr = ie021-invoice_no. desadvdata-sdata = e1edk07. append_idoc_rec desadvdata d. clear e1edka1. desadvdata-segnam = 'E1EDKA1'. desadvdata-sdata = e1edka1. append_idoc_rec desadvdata d. clear e1edk03. desadvdata-segnam = 'E1EDK03'. desadvdata-sdata = e1edk03. append_idoc_rec desadvdata d.

2008-09

Page 267 of 328

clear e1edk08. desadvdata-segnam = 'E1EDK08'. e1edk08-vbeln = ie021-invoice_no. e1edk08-traid = ie021-ship_id. e1edk08-traty = ie021-ship_method. desadvdata-sdata = e1edk08. append_idoc_rec desadvdata d. clear e1edka2. desadvdata-segnam = 'E1EDKA2'. desadvdata-sdata = e1edka2. append_idoc_rec desadvdata d. clear e1edk06. desadvdata-segnam = 'E1EDK06'. e1edk06-iddat = '025'. "document date e1edk06-datum = ie021-create_date. desadvdata-sdata = e1edk06. append_idoc_rec desadvdata d. if not ie021-eta is initial. clear e1edk06. desadvdata-segnam = 'E1EDK06'. e1edk06-iddat = '001'. "delivery date e1edk06-datum = ie021-eta. desadvdata-sdata = e1edk06. append_idoc_rec desadvdata d. endif. if not ie021-etd is initial. clear e1edk06. desadvdata-segnam = 'E1EDK06'. e1edk06-iddat = '010'. "ship date e1edk06-datum = ie021-etd. desadvdata-sdata = e1edk06. append_idoc_rec desadvdata d. endif. ENDFORM. " idoc_header_segs

*&---------------------------------------------------------------------* *& Form idoc_poheader_segs *&---------------------------------------------------------------------* * create internal table entries for DESADV PO/item segments * E1EDP07 *----------------------------------------------------------------------* FORM idoc_poheader_segs. *DESADV clear e1edp07. desadvdata-segnam = 'E1EDP07'. e1edp07-bstnk = ie021-po_number. e1edp07-posex = ie021-po_lineno. desadvdata-sdata = e1edp07. append_idoc_rec desadvdata d. p07_ctr = p07_ctr + 1. ENDFORM. " idoc_poheader_segs

*&---------------------------------------------------------------------* *& Form idoc_item_segs *&---------------------------------------------------------------------* * create internal table entries for PO item segments: * DESADV: E1EDP09 * INVOIC: E1EDP01 Qtys * E1EDP02 ref nos. (PO number / line) * E1EDP19 part numbers * E1EDP26 amounts * E1EDP04 taxes *----------------------------------------------------------------------* FORM idoc_item_segs using value(desadv_ok). data: n_line_amt type p decimals 3.

2008-09

Page 268 of 328

*INVOIC clear e1edp01. invoicdata-segnam = 'E1EDP01'. e1edp01-menee = ie021-qty_uom. e1edp01-menge = ie021-invoice_qty. e1edp01-vprei = ie021-unit_price. e1edp01-pmene = ie021-price_uom. e1edp01-peinh = ie021-price_qty. e1edp01-netwr = ie021-line_amount. invoicdata-sdata = e1edp01. append_idoc_rec invoicdata i. clear e1edp02. invoicdata-segnam = 'E1EDP02'. e1edp02-qualf = '001'. e1edp02-belnr = ie021-po_number. e1edp02-zeile = ie021-po_lineno. invoicdata-sdata = e1edp02. append_idoc_rec invoicdata i. clear e1edp19. invoicdata-segnam = 'E1EDP19'. e1edp19-qualf = '001'. e1edp19-idtnr = ie021-cust_partno. invoicdata-sdata = e1edp19. append_idoc_rec invoicdata i. clear e1edp19. invoicdata-segnam = 'E1EDP19'. e1edp19-qualf = '002'. e1edp19-idtnr = ie021-vendor_partno. invoicdata-sdata = e1edp19. append_idoc_rec invoicdata i. clear e1edp26. invoicdata-segnam = 'E1EDP26'. e1edp26-qualf = '003'. e1edp26-betrg = ie021-line_amount. invoicdata-sdata = e1edp26. append_idoc_rec invoicdata i. * dummy tax seg clear e1edp04. invoicdata-segnam = 'E1EDP04'. e1edp04-msatz = '0.00'. invoicdata-sdata = e1edp04. append_idoc_rec invoicdata i. n_line_amt = ie021-line_amount. invoice_total = invoice_total + n_line_amt. check desadv_ok = '000'. *DESADV clear e1edp09. desadvdata-segnam = 'E1EDP09'. e1edp09-vbeln = ie021-slip_number. e1edp09-matnr = ie021-vendor_partno. e1edp09-vrkme = ie021-qty_uom. e1edp09-lfimg = ie021-invoice_qty. desadvdata-sdata = e1edp09. append_idoc_rec desadvdata d. ENDFORM. " idoc_item_segs

*********************************************************************** *& Form post_idocs *&---------------------------------------------------------------------* * create database IDocs from the idocdata tables and clear tables. *----------------------------------------------------------------------* FORM post_idocs using value(desadv_ok). *INVOIC clear e1eds01. invoicdata-segnam = 'E1EDS01'.

2008-09

Page 269 of 328

e1eds01-sumid = '010'. e1eds01-summe = invoice_total. e1eds01-waerq = ie021-currency. shift e1eds01-summe left deleting leading space. invoicdata-sdata = e1eds01. append_idoc_rec invoicdata i. CALL FUNCTION 'INBOUND_IDOC_PROCESS' TABLES IDOC_CONTROL = iedidc IDOC_DATA = invoicdata. commit work. *DESADV if desadv_ok = '000'. clear e1eds02. desadvdata-segnam = 'E1EDS02'. e1eds02-sumid = '001'. e1eds02-summe = p07_ctr. shift e1eds02-summe left deleting leading space. desadvdata-sdata = e1eds02. append_idoc_rec desadvdata d. CALL FUNCTION 'INBOUND_IDOC_PROCESS' TABLES IDOC_CONTROL = dedidc IDOC_DATA = desadvdata. commit work. endif. refresh: desadvdata, invoicdata. clear: desadvdata, invoicdata, p07_ctr, invoice_total, save_stat, save_po, save_line, save_invoice. ENDFORM. " post_idocs

*&---------------------------------------------------------------------* *& Form init_desadv *&---------------------------------------------------------------------* * add a DESDAV control record and initialize fields *----------------------------------------------------------------------* FORM init_desadv. clear dedidc. refresh dedidc. * initialize control record: move: '2' to dedidc-direct, 'DESADV01' to dedidc-doctyp, 'DESADV' to dedidc-mestyp, 'F' to dedidc-std, 'E021' to dedidc-stdmes, 'LS' to dedidc-sndprt, 'TY_VENDORS' to dedidc-sndprn, sy-datlo to dedidc-credat, sy-timlo to dedidc-cretim. append dedidc. ENDFORM. " init_desadv

*&---------------------------------------------------------------------* *& Form init_invoic *&---------------------------------------------------------------------* * add a INVOIC control record and initialize fields *----------------------------------------------------------------------*

2008-09

Page 270 of 328

FORM init_invoic. clear iedidc. refresh iedidc. * initialize control record: move: '2' to iedidc-direct, 'INVOIC01' to iedidc-doctyp, 'INVOIC' to iedidc-mestyp, 'MM' to iedidc-mescod, 'F' to iedidc-std, 'E021' to iedidc-stdmes, 'LS' to iedidc-sndprt, 'TY_VENDORS' to iedidc-sndprn, sy-datlo to iedidc-credat, sy-timlo to iedidc-cretim. append iedidc. ENDFORM. " init_invoic

6.10.7

List transactions
*

*----------------------------------------------------------------------* * REPORT Z_TRANSACTIONS *----------------------------------------------------------------------* * TEXT ELEMENTS * ------------* Heading * Transaction code Text * * Selection texts * P_DNLD Download? * P_FILE Filename: * S_SPRSL Language: * S_TCODE Transaction Code: * * Text Symbols * 001 Transaction Selection * 002 Download Option * 003 Filename *----------------------------------------------------------------------* REPORT z_transactions. TABLES: tstct. TYPES: BEGIN OF itab_tx, tcode LIKE tstct-tcode, ttext LIKE tstct-ttext, END OF itab_tx.

DATA: itab_tx TYPE itab_tx OCCURS 0 WITH HEADER LINE, tx TYPE itab_tx, itab_file LIKE sval OCCURS 0 WITH HEADER LINE, p_file LIKE rlgrap-filename, returncode LIKE sy-subrc, filestring TYPE string. DATA: BEGIN OF fields OCCURS 2. INCLUDE STRUCTURE sval. DATA: END OF fields. * text-001 = Transaction Selection SELECTION-SCREEN BEGIN OF BLOCK transx WITH FRAME TITLE text-001. SELECT-OPTIONS: s_tcode FOR tstct-tcode, s_sprsl FOR tstct-sprsl. SELECTION-SCREEN END OF BLOCK transx. * text-002 = Download Option SELECTION-SCREEN BEGIN OF BLOCK dld WITH FRAME TITLE text-002. PARAMETERS: p_dnld TYPE c AS CHECKBOX. SELECTION-SCREEN END OF BLOCK dld. AT SELECTION-SCREEN OUTPUT. p_file = 'C:\SAPTXlist.xls'. p_dnld = 'X'. MOVE 'I' TO s_sprsl-sign.

2008-09

Page 271 of 328

MOVE 'EQ' TO s_sprsl-option. MOVE 'EN' TO s_sprsl-low. APPEND s_sprsl. START-OF-SELECTION. REFRESH itab_tx. SELECT * FROM tstct INTO CORRESPONDING FIELDS OF TABLE itab_tx WHERE tcode IN s_tcode AND sprsl IN s_sprsl. IF sy-subrc <> 0. MESSAGE s265(sf). ELSE. SORT itab_tx BY tcode. LOOP AT itab_tx. WRITE: /1 itab_tx-tcode(20), AT 20 itab_tx-ttext. ENDLOOP. IF p_dnld = 'X'. CLEAR fields. fields-tabname = 'RLGRAP'. fields-fieldname = 'FILENAME'. fields-value = p_file. fields-field_attr = '00'. APPEND fields. CALL FUNCTION 'POPUP_GET_VALUES' EXPORTING popup_title = text-003 IMPORTING returncode = returncode TABLES fields = fields EXCEPTIONS error_in_fields = 1 OTHERS = 2. CHECK returncode EQ space. filestring = fields-value. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = filestring write_field_separator = ',' TABLES data_tab = itab_tx EXCEPTIONS file_write_error =1 no_batch =2 gui_refuse_filetransfer = 3 invalid_type =4 no_authority =5 unknown_error =6 header_not_allowed =7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22. IF sy-subrc <> 0. MESSAGE s999(b1) WITH 'File ' filestring ' NOT created!'. ELSE. MESSAGE s999(b1) WITH 'File ' filestring

2008-09

Page 272 of 328

' Created successfully!'. ENDIF. "Check on download success ENDIF. "Download ENDIF. "Check on selection

6.10.8

Report with joins and macros

REPORT ZREPORT message-id z11 LINE-SIZE 180 LINE-COUNT 65 NO STANDARD PAGE HEADING. tables: vbrk, vbrp, knvp, kna1, T100, BHDGD. data: gpct type p decimals 1. SELECT-OPTIONS: S_DATE FOR vbrk-fkdat. SELECT-OPTIONS: S_cust FOR vbrk-kunag. SELECT-OPTIONS: S_srep FOR KNVP-kunn2. SELECT-OPTIONS: S_MGRP FOR VBRP-MATKL. SELECT-OPTIONS: S_GPCT FOR gpct. DATA: BEGIN OF REPLINES OCCURS 100, MATKL LIKE VBRP-MATKL, "material group ARKTX LIKE VBRP-ARKTX, "old material no. MATNR LIKE VBRP-MATNR, "ATAC material no. KUNAG LIKE vbrk-kunag, "customer no. NAME1 like kna1-name1, "customer name BUKRS like VBRK-BUKRS, "company code VBELN like vbrk-vbeln, "invoice no. FKDAT like vbrk-fkdat, "invoice date (ccyymmdd) FKIMG like VBRP-FKIMG, "inv. qty (3-dec) KZWI2 like VBRP-KZWI2, "line price (2-dec) WAVWR like VBRP-WAVWR, "line cost (2-dec) KUNN2 like KNVP-KUNN2, "Sales rep VBTYP like VBRK-VBTYP, "document type END OF REPLINES. DATA: FKIMG_SUM_GRP like vbrp-fkimg, KZWI2_SUM_GRP like vbrp-KZWI2, WAVWR_SUM_GRP like vbrp-WAVWR, FKIMG_SUM_MAT like vbrp-fkimg, KZWI2_SUM_MAT like vbrp-KZWI2, WAVWR_SUM_MAT like vbrp-WAVWR. DATA: save_matnr like vbrp-matnr, save_matkl like vbrp-matkl, save_arktx like vbrp-arktx, lin like sy-tabix, offset type i, hun type p decimals 2 value 100, c_low(20), c_high(20), h_tag(15). data:: date_string_I(150) type c, cust_string_I(150) type c, srep_string_I(150) type c, mgrp_string_I(150) type c, gpct_string_I(150) type c, date_string_E(150) type c, cust_string_E(150) type c, srep_string_E(150) type c, mgrp_string_E(150) type c, gpct_string_E(150) type c. ranges: r_atyp for vbrp-autyp, r_vtyp for vbrk-vbtyp. *________________________________________________________ * DEFINITIONS

2008-09

Page 273 of 328

*________________________________________________________ define add_comma. * add comma for selection criteria output string if offset > 0. &1_string_&2+offset(1) = ','. offset = offset + 2. endif. END-of-definition. " add_comma

DEFINE create_string. * loop for inclusions loop at s_&1. offset = strlen( &1_string_&2 ). c_low = s_&1-low. c_high = s_&1-high. shift c_low left deleting leading '0'. shift c_high left deleting leading '0'. shift c_low left deleting leading space. shift c_high left deleting leading space. if '&1' = 'date'. concatenate c_low+4(2) '/' c_low+6(2) '/' c_low+2(2) into c_low. if not c_high is initial. concatenate c_high+4(2) '/' c_high+6(2) '/' c_high+2(2) into c_high. endif. endif. case s_&1-option. when 'EQ'. check s_&1-sign = '&2'. add_comma &1 &2. &1_string_&2+offset = c_low. when 'NE'. check s_&1-sign = '&3'. add_comma &1 &2. &1_string_&2+offset = c_low. when 'GT'. check s_&1-sign = '&2'. add_comma &1 &2. &1_string_&2+offset = 'Greater than'. offset = offset + 13. &1_string_&2+offset = c_low. when 'LE'. check s_&1-sign = '&2'. add_comma &1 &2. &1_string_&2+offset = 'Less than or equal to'. offset = offset + 22. &1_string_&2+offset = c_low. when 'LT'. check s_&1-sign = '&2'. add_comma &1 &2. &1_string_&2+offset = 'Less than'. offset = offset + 10. &1_string_&2+offset = c_low. when 'BT'. check s_&1-sign = '&2'. add_comma &1 &2. concatenate &1_string_&2 c_low '-' c_high into &1_string_&2 separated by space. when 'NB'. check s_&1-sign = '&3'. add_comma &1 &2. concatenate &1_string_&2 c_low '-' c_high into &1_string_&2 separated by space. endcase. endloop. END-OF-DEFINITION. DEFINE WRITE_STRING. if ( &1_string_I is initial and &1_string_E is initial ). &1_string_I = 'All'. " create_string

2008-09

Page 274 of 328

endif. if not &1_string_I is initial. write: /05 h_tag, 22 'include:', 31 &1_string_I. if not &1_string_E is initial. write: /22 'exclude:', 31 &1_string_E. endif. elseif not &1_string_E is initial. write: /05 h_tag, 22 'exclude:', 31 &1_string_E. endif. END-OF-DEFINITION. INITIALIZATION. * load selection tables for invoice types CLEAR: r_atyp, r_vtyp. REFRESH: r_atyp, r_vtyp. r_atyp-SIGN = 'I'. r_atyp-OPTION = 'EQ'. r_atyp-LOW = 'C'. "order APPEND r_atyp. r_atyp-LOW = 'E'. "sched. agree. APPEND r_atyp. r_atyp-LOW = 'F'. "sched. agree. w/ext.agent APPEND r_atyp. r_atyp-LOW = 'H'. "returns APPEND r_atyp. r_vtyp-SIGN = 'I'. r_vtyp-OPTION = 'EQ'. r_vtyp-LOW = 'M'. "invoice APPEND r_vtyp. r_vtyp-LOW = 'N'. "invoice cancellation APPEND r_vtyp. r_vtyp-LOW = 'O'. "credit memo APPEND r_vtyp. r_vtyp-LOW = 'S'. "credit memo cancellation APPEND r_vtyp. AT SELECTION-SCREEN. * store selection criteria for header output. clear: date_string_I, cust_string_I, srep_string_I, mgrp_string_I, gpct_string_I, date_string_E, cust_string_E, srep_string_E, mgrp_string_E, gpct_string_E. create_string date I E. create_string date E I. create_string cust I E. create_string cust E I. create_string srep I E. create_string srep E I. create_string mgrp I E. create_string mgrp E I. create_string gpct I E. create_string gpct E I. START-OF-SELECTION. * ASSUMPTION: All quantities are in sales units. Since quantities * are summed to the material group level, it is assumed that all * materials within a material group have the same sales unit of * measure. " write_string

2008-09

Page 275 of 328

select a~kunag a~vbeln a~fkdat a~bukrs a~vbtyp b~matkl b~matnr b~arktx b~fkimg b~kzwi2 b~wavwr c~name1 d~kunn2 into corresponding fields of table replines from vbrk as a inner join vbrp as b on a~vbeln = b~vbeln inner join kna1 as c on a~kunag = c~kunnr left outer join knvp as d on a~kunag = d~kunnr and a~vkorg = d~vkorg and a~vtweg = d~vtweg and d~spart = '71' and d~parvw = 'CO' and d~parza = '000' where a~vkorg = '7100' and a~vbtyp in r_vtyp and a~fkdat in s_date and a~kunag in s_cust and b~matkl in s_mgrp and b~autyp in r_atyp. END-OF-SELECTION. PERFORM INIT_BATCH_HEADING. SORT REPLINES BY MATKL MATNR KUNAG FKDAT. PERFORM LIST_DISPLAY. AT LINE-SELECTION. * run transaction to display invoice document * passing parameter values via memory SET PARAMETER ID 'VF' FIELD REPLINES-VBELN. CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN. ******************************************* TOP-OF-PAGE DURING LINE-SELECTION. PERFORM HEADING_DISPLAY. ******************************************* TOP-OF-PAGE. PERFORM HEADING_DISPLAY. ************************************************************************ * FORMS ************************************************************************ *----------------------------------------------------------------------* FORM LIST_DISPLAY * Output internal table, REPLINES *----------------------------------------------------------------------FORM LIST_DISPLAY. data: gross_profit like vbrp-kzwi2, gp_percent type p decimals 1, uprice type p decimals 5, ucost type p decimals 5, hun type p decimals 2 value 100, neg type p decimals 2 value -1. data: invoice_no(10). LOOP AT REPLINES. FORMAT COLOR COL_NORMAL INTENSIFIED ON INVERSE OFF. check ( replines-fkimg > 0 or replines-KZWI2 > 0 or replines-WAVWR > 0 ). * change sign on cancellations if ( replines-vbtyp = 'N' or replines-vbtyp = 'S' ). replines-fkimg = replines-fkimg * neg. replines-KZWI2 = replines-KZWI2 * neg. replines-WAVWR = replines-WAVWR * neg.

2008-09

Page 276 of 328

endif. * calculate gross profit percent and apply selection value range gross_profit = replines-kzwi2 - replines-wavwr. gp_percent = ( gross_profit / replines-kzwi2 ) * hun. check: gp_percent in s_gpct, replines-kunn2 in s_srep. * calculate unit price uprice = replines-kzwi2 / replines-fkimg. * calculate unit cost ucost = replines-wavwr / replines-fkimg. * begin output if ( save_matnr <> replines-matnr and not save_matnr is initial ). perform material_footer. endif. if ( save_matkl <> replines-matkl and not save_matkl is initial ). perform material_group_footer. endif. save_matkl = replines-matkl. save_matnr = replines-matnr. save_arktx = replines-arktx. invoice_no = replines-vbeln. shift: invoice_no left deleting leading '0', replines-kunag left deleting leading '0', replines-matnr left deleting leading '0'. WRITE: /01(3) REPLINES-MATKL, 05(20) REPLINES-ARKTX, 26(7) REPLINES-MATNR, 34(8) REPLINES-KUNAG, 42(14) REPLINES-NAME1, 57(10) INVOICE_NO, 68 REPLINES-FKDAT MM/DD/YY, 79(12) REPLINES-FKIMG decimals 0, 92(15) REPLINES-KZWI2, 108(12) UPRICE, 121(15) REPLINES-WAVWR, 137(12) UCOST, 150(15) gross_profit, 166(8) gp_percent, 175 '%'. HIDE: REPLINES-BUKRS, REPLINES-VBELN. FKIMG_SUM_GRP = FKIMG_SUM_GRP + replines-fkimg. KZWI2_SUM_GRP = KZWI2_SUM_GRP + replines-KZWI2. WAVWR_SUM_GRP = WAVWR_SUM_GRP + replines-WAVWR. FKIMG_SUM_MAT = FKIMG_SUM_MAT + replines-fkimg. KZWI2_SUM_MAT = KZWI2_SUM_MAT + replines-KZWI2. WAVWR_SUM_MAT = WAVWR_SUM_MAT + replines-WAVWR. FORMAT COLOR COL_NORMAL INTENSIFIED OFF INVERSE OFF. ENDLOOP. * output last totals perform material_footer. perform material_group_footer. * Report footer IF NOT SY-SUBRC IS INITIAL. SKIP. SKIP. WRITE: /50 '*** NO RECORDS SELECTED ***'. EXIT. ELSE. FORMAT COLOR COL_KEY ON INTENSIFIED OFF INVERSE OFF. WRITE: /55 '*** END OF REPORT ***'. ENDIF. SY-LSIND = 0. "replaces basic list ENDFORM. *---------------------------------------------------------------------FORM INIT_BATCH_HEADING. * BHDGD-LINES = SY-LINSZ. "number of characters per line BHDGD-LINES = 177. "number of characters per line BHDGD-UNAME = SY-UNAME. "user name creating report BHDGD-REPID = SY-REPID. "abap name BHDGD-LINE1 = SY-TITLE. "report title from attributes

2008-09

Page 277 of 328

BHDGD-BUKRS = '7100'. "company BHDGD-INIFL = '0'. "says you are initializing the heading ENDFORM. *---------------------------------------------------------------------FORM HEADING_DISPLAY. PERFORM BATCH-HEADING(RSBTCHH0). SKIP. h_tag = 'Invoice Dates'. write_string date. h_tag = 'Customers'. write_string cust. h_tag = 'Sales Reps'. write_string srep. h_tag = 'Material Groups'. write_string mgrp. h_tag = 'Gr.Profit Pct'. write_string gpct. skip 2. FORMAT COLOR COL_KEY ON INTENSIFIED OFF INVERSE OFF. WRITE: /01 'Mat', 26 'ATAC', 34 'Customer', 57 'Invoice', 68 'Invoice', 79(12) 'Invoice' right-justified, 92(15) 'Extended' right-justified, 108(12) 'Unit or Avg' right-justified, 121(15) 'Extended' right-justified, 137(12) 'Unit or Avg' right-justified, 150(15) 'Gross' right-justified, /01 'Grp', 05 'Item Nbr', 26 'Nbr', 34 'Nbr', 42 'Name', 57 'Nbr', 68 'Date', 79(12) 'Quantity' right-justified, 92(15) 'Price' right-justified, 108(12) 'Price' right-justified, 121(15) 'Cost' right-justified, 137(12) 'Cost' right-justified, 150(15) 'Profit' right-justified, 171 'GP%'. FORMAT COLOR COL_POSITIVE ON INVERSE OFF. ULINE. ENDFORM. *&---------------------------------------------------------------------* *& Form product_group_footer *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM material_group_footer. data: gross_profit like vbrp-kzwi2, gp_percent type p decimals 1, uprice type p decimals 5, ucost type p decimals 5. * calculate gross profit percent gross_profit = kzwi2_sum_grp - wavwr_sum_grp. gp_percent = ( gross_profit / kzwi2_sum_grp ) * hun. * calculate unit price uprice = kzwi2_sum_grp / fkimg_sum_grp. * calculate unit cost ucost = wavwr_sum_grp / fkimg_sum_grp. write: /79 '============', 92 '===============', 108 '============', 121 '===============', 137 '============',

2008-09

Page 278 of 328

150 '===============', 168 '======'. write: /01 'Total for Material Group', 26 save_matkl, 79(12) FKIMG_SUM_GRP decimals 0, 92(15) KZWI2_SUM_GRP, 108(12) UPRICE, 121(15) WAVWR_SUM_GRP, 137(12) UCOST, 150(15) gross_profit, 166(8) gp_percent, 175 '%'. uline. clear: FKIMG_SUM_GRP, KZWI2_SUM_GRP, WAVWR_SUM_GRP. ENDFORM. " material_group_footer

*&---------------------------------------------------------------------* *& Form invoice_footer *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM material_footer. data: gross_profit like vbrp-kzwi2, gp_percent type p decimals 1, uprice type p decimals 5, ucost type p decimals 5. * calculate gross profit percent gross_profit = kzwi2_sum_mat - wavwr_sum_mat. gp_percent = ( gross_profit / kzwi2_sum_mat ) * hun. * calculate unit price uprice = kzwi2_sum_mat / fkimg_sum_mat. * calculate unit cost ucost = wavwr_sum_mat / fkimg_sum_mat. write: /79 '------------', 92 '---------------', 108 '------------', 121 '---------------', 137 '------------', 150 '---------------', 168 '------'. write: /01 'Subtotal for material', 23 save_matnr, 79(12) FKIMG_SUM_MAT decimals 0, 92(15) KZWI2_SUM_MAT, 108(12) UPRICE, 121(15) WAVWR_SUM_MAT, 137(12) UCOST, 150(15) gross_profit, 166(8) gp_percent, 175 '%'. clear: FKIMG_SUM_MAT, KZWI2_SUM_MAT, WAVWR_SUM_MAT. ENDFORM. " material_footer

6.10.9

Graphical POPUP progress display

REPORT ZEPS_PROGRESS_POP . *********************************************************** * Developer : S.Srini. * Location : Chennai, * : Tamil Nadu, * : India. * Date : 03/09/2001. *********************************************************** data: val type i. data event(6) type c.

2008-09

Page 279 of 328

val = 0. do 4 times. val = val + 25. CALL FUNCTION 'EPS_PROGRESS_POPUP' EXPORTING BTN_TXT = 'CANCEL' CURVAL_G2 = VAL LAYOUT = '1' MAXVAL_G2 = '100' POPUP_LINK = 'ASYNC' POPUP_STAT = '1' POPUP_TITLE = 'SAP' TEXT_1 = 'TEXT 1' TEXT_2 = 'TEXT 2' TEXT_3 = 'TEXT 3' TEXT_4 = 'TEXT 4' TEXT_G1 = 'TEXT G1' TEXT_G2 = 'TEXT G2' TITLE_G2 = 'TITLE G2 ' WINID = 100. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDDO. PERFORM CLOSEGRAPH. ************************************************************ FORM CLOSEGRAPH. CALL FUNCTION 'PROGRESS_POPUP' EXPORTING STAT = '2' WINID = 100. CALL FUNCTION 'GRAPH_DIALOG' EXPORTING CLOSE = 'X'. ENDFORM. ***********************************************************

6.10.10 Change IDoc status to error status and send to workflow


REPORT ZS7BM000007 message-id ZS7 . *______________________________________________________________________ */ Program Name: Process invoice IDocs with Goods Receipt */ Description : This program checks all INVOIC MM IDocs in status 64 * and 66 to determine if they have been received. Those * IDocs older than 10 days that have still not been * goods receipted are given error status 51. */ Transaction : N/A - run via scheduled job *______________________________________________________________________ tables: edidc, mkpf, ekpo, rbkp, e1edk01, e1edka1, e1edk02, e1edp02. data: iedidc like edidc occurs 1 with header line, data_rec like edidd occurs 1 with header line. data: c_docnum(16) type c, c_mblnr(10) type c, c_invoic(10) type c, rc(1) type c, lead_time like lfm1-plifz, gr_qty like mseg-erfmg, test_date like sy-datum,

2008-09

Page 280 of 328

gr_required like ekpo-webre, po_number(10) type n, po_lineno like ekpo-ebelp, n_vend(10) type n, vendor_id like lfa1-lifnr. data: begin of itab_gr occurs 0, mblnr like mkpf-mblnr, bwart like mseg-bwart, erfmg like mseg-erfmg, end of itab_gr. constants: * name of container element (workitem object id) C_ELEMENT_WI_OBJ_ID LIKE SWCONT-ELEMENT VALUE '_WI_OBJECT_ID', * name of container element (NumberPlusEventcode) C_ELEMENT_NO_PLUS_INFO LIKE SWCONT-ELEMENT VALUE 'NumberPlusEventcode'. ranges: r_status for edidc-status. TYPE-POOLS: * general idoc type pool TIDOC. ************************************************************************ * INCLUDES * ************************************************************************ * include for workflow programming INCLUDE <CNTN01>. ************************************************************************ * INNITIALIZATION * ************************************************************************ initialization. * create IDoc status selection table. clear r_status. refresh r_status. MOVE: 'EQ' TO r_status-OPTION, "equals 'I' TO r_status-SIGN, "include '64' TO r_status-LOW. APPEND r_status. MOVE: '66' TO r_status-LOW. APPEND r_status. ************************************************************************ * START-OF-SELECTION ************************************************************************ start-of-selection. select * from edidc into table iedidc where status in r_status and direct = '2' and "inbound mestyp = 'INVOIC' and mescod = 'MM'. loop at iedidc. clear rc. CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_READ' EXPORTING DOCUMENT_NUMBER = iedidc-docnum IMPORTING IDOC_CONTROL = IEDIDC EXCEPTIONS DOCUMENT_FOREIGN_LOCK = 01 DOCUMENT_NOT_EXIST = 02 DOCUMENT_NUMBER_INVALID = 03 ERROR_MESSAGE = 04 OTHERS = 05. IF NOT SY-SUBRC IS INITIAL. c_docnum = iedidc-docnum. shift c_docnum left deleting leading '0'. * 'Cannot open INVOIC IDoc & for Goods Receipt processing' message w025 with c_docnum.

2008-09

Page 281 of 328

continue. ENDIF. call function 'EDI_SEGMENTS_GET_ALL' exporting document_number = iedidc-docnum tables idoc_containers = data_rec exceptions document_number_invalid = 1 end_of_document =2 others = 3. if not sy-subrc is initial. CALL FUNCTION 'EDI_DOCUMENT_CLOSE_READ' EXPORTING DOCUMENT_NUMBER = iedidc-docnum IMPORTING IDOC_CONTROL = iedidc c_docnum = iedidc-docnum. shift c_docnum left deleting leading '0'. * 'Cannot retrieve data for INVOIC IDoc & (Goods Receipt processing)' message w030 with c_docnum. continue. else. CALL FUNCTION 'EDI_DOCUMENT_CLOSE_READ' EXPORTING DOCUMENT_NUMBER = iedidc-docnum IMPORTING IDOC_CONTROL = iedidc. * If this is a change or modify IDoc, change status to 51 (error). * One & only one K01 segment should exist read table data_rec with key segnam = 'E1EDK01'. if sy-subrc is initial. move data_rec-sdata to e1edk01. case e1edk01-action. when '000'. "original data * OK - do nothing when '002'. "modified data * 'Invoice & - IDoc for Review Only' perform idoc_status_update using '51' '028' 'Modification' ' '. when '002'. "modified data * 'Invoice & - IDoc for Review Only' perform idoc_status_update using '51' '028' 'Cancellation' ' '. endcase. endif. check rc is initial. * get the vendor no. clear vendor_id. loop at data_rec where segnam = 'E1EDKA1'. move data_rec-sdata to e1edka1. check: e1edka1-parvw = 'LF', e1edka1-partn co ' 0123456789', e1edka1-partn <> ' '. n_vend = e1edka1-partn. vendor_id = n_vend. endloop. * if this is a new IDoc, check to make sure it even needs the GR test clear gr_required. loop at data_rec where segnam = 'E1EDP02'. move data_rec-sdata to e1edp02. check: e1edp02-qualf = '001', e1edp02-belnr <> ' ', e1edp02-zeile <> ' '. * Note that a missing PO number / line number is NOT an error here * the IDoc will error in the standard SAP processing in RBDAPP01 shift e1edp02-belnr left deleting leading '0'. clear: po_number, po_lineno. if e1edp02-belnr co ' 0123456789'. po_number = e1edp02-belnr. endif. if e1edp02-zeile co ' 0123456789'. po_lineno = e1edp02-zeile.

2008-09

Page 282 of 328

endif. select single webre from ekpo into gr_required where ebeln = po_number and ebelp = po_lineno. if ( sy-subrc is initial and gr_required = 'X' ). exit. endif. endloop. "E1EDP02 segments * if any line item on this invoice requires a goods receipt, continue * receipt evaluation. Otherwise, status the IDoc to go to standard SAP * processing. (Assumption is made that if an IDoc has status 66, the GR * flag was turned "on" at some point and has since been removed.) if gr_required is initial. "no goods receipt required if iedidc-status = '66'. * 'Goods Receipt no longer required' perform idoc_status_update using '64' '026' ' ' ' '. endif. continue. "next IDoc endif. * Should be only one K02, but loop just in case... loop at data_rec where segnam = 'E1EDK02'. move data_rec-sdata to e1edk02. if e1edk02-qualf = '009'. * if an invoice already exists for this ref. no., give the IDoc * an error status select single belnr from rbkp into rbkp-belnr where xblnr = e1edk02-belnr(16) and blart = 'KR' "invoice and stblg = ' '. "no reversal if sy-subrc is initial. *'Invoice & already exists for ref.no. &' c_invoic = rbkp-belnr. shift c_invoic left deleting leading '0'. perform idoc_status_update using '51' '027' c_invoic e1edk02-belnr(16). exit. "exit loop on data recs for this IDoc endif. clear: itab_gr, gr_qty. refresh: itab_gr. select a~mblnr b~bwart b~erfmg into corresponding fields of table itab_gr from mkpf as a inner join mseg as b on a~mblnr = b~mblnr where a~vgart = 'WE' "goods receipt for PO and a~blart = 'WE' "goods receipt and a~xblnr = e1edk02-belnr(16). loop at itab_gr. case itab_gr-bwart. when '101'. "receipt gr_qty = gr_qty + itab_gr-erfmg. when '102'. "reversal gr_qty = gr_qty - itab_gr-erfmg. endcase. endloop. * if no goods receipt if gr_qty <= 0. case iedidc-status. * if new IDoc, status to '66' when '64'. * 'Waiting for Goods Receipt' perform idoc_status_update using '66' '022' ' ' ' '. * if reprocessed IDoc, check length of delay and status to 51 * (late receipt) if > 10 days. when '66'. clear lead_time. select single plifz from lfm1 into lead_time where lifnr = vendor_id and ekorg = '7100'. if lead_time is initial. lead_time = 10. endif. test_date = iedidc-credat + lead_time. **TEST

2008-09

Page 283 of 328

** **TEST

if test_date > sy-datum. if test_date <= sy-datum.

* 'Goods Receipt Overdue' perform idoc_status_update using '51' '024' ' ' ' '. else. * do nothing - IDoc stays in status 66 and gets tested for GR in next * job run endif. endcase. else. "goods receipt exists * if this is a reprocess of an IDoc for which a goods receipt now * exists, give the IDoc status 64, so it is processed by RBDAPP01 * in the next job step. if iedidc-status = '66'. c_mblnr = mkpf-mblnr. shift c_mblnr left deleting leading '0'. * 'Goods Receipt found for ref.no. &' perform idoc_status_update using '64' '023' e1edk02-belnr(16) ' '. endif. endif. else. "wrong K02 qualifier * do nothing - IDoc will try to post and be handled manually endif. "QUALF='009' endloop. "data_rec endif. "successful retrieval of IDoc data segments > data_rec endloop. "iedidc end-of-selection. *----------------------------------------------------------------------* FORM IDOC_STATUS_UPDATE * Creates status records for the selected IDocs. *----------------------------------------------------------------------FORM IDOC_STATUS_UPDATE using value(i_stat) value(i_msgno) value(i_msgv1) value(i_msgv2). tables: edi_ds, tede2. DATA: MESS like EDIMESSAGE. data: l_commit_counter LIKE ediglodata-comcount value '00000001', inbsync LIKE ediglodata-inbsync, t_couple_to_process LIKE ediinbound OCCURS 0 WITH HEADER LINE. CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_PROCESS' EXPORTING DOCUMENT_NUMBER = iedidc-docnum IMPORTING IDOC_CONTROL = IEDIDC EXCEPTIONS DOCUMENT_FOREIGN_LOCK = 01 DOCUMENT_NOT_EXIST = 02 DOCUMENT_NUMBER_INVALID = 03 ERROR_MESSAGE = 04 OTHERS = 05. IF NOT SY-SUBRC IS INITIAL. c_docnum = iedidc-docnum. shift c_docnum left deleting leading '0'. * 'Cannot open INVOIC IDoc & for Goods Receipt processing' message w025 with c_docnum. rc = 'X'. exit. ENDIF. CLEAR EDI_DS. EDI_DS-DOCNUM = iedidc-DOCNUM. EDI_DS-STATUS = i_stat. EDI_DS-REPID = 'ZS7BM000007'. EDI_DS-TABNAM = 'EDI_DS'.

2008-09

Page 284 of 328

EDI_DS-MANDT EDI_DS-STAMQU EDI_DS-STAMID EDI_DS-STAMNO EDI_DS-STAPA1 EDI_DS-STAPA2 GET TIME. EDI_DS-LOGDAT EDI_DS-LOGTIM

= SY-MANDT. = 'SAP'. = 'ZS7'. = i_msgno. = i_msgv1. = i_msgv2. = SY-DATUM. = SY-UZEIT.

CALL FUNCTION 'EDI_DOCUMENT_STATUS_SET' EXPORTING DOCUMENT_NUMBER = iedidc-DOCNUM IDOC_STATUS = edi_ds IMPORTING IDOC_CONTROL = iedidc EXCEPTIONS DOCUMENT_NUMBER_INVALID =1 OTHER_FIELDS_INVALID =2 STATUS_INVALID =3 OTHERS =4 . IF NOT SY-SUBRC IS INITIAL. c_docnum = iedidc-docnum. shift c_docnum left deleting leading '0'. * IDoc no. & failed status update to & message w021 with c_docnum i_stat. ENDIF. CALL FUNCTION 'EDI_DOCUMENT_CLOSE_PROCESS' EXPORTING DOCUMENT_NUMBER = iedidc-DOCNUM. if i_stat = '51'. clear: t_couple_to_process. refresh: t_couple_to_process. select single * from tede2 into tede2 where evcode = 'INVL'. if sy-subrc is initial. t_couple_to_process(16) = iedidc-docnum. t_couple_to_process+16(138) = tede2. append t_couple_to_process. PERFORM analyzing_event_create TABLES t_couple_to_process USING l_commit_counter inbsync. if sy-subrc is initial. MESS-MSGID = 'ZS7'. MESS-MSGTY = 'E'. MESS-MSGNO = i_msgno. MESS-MSGV1 = i_msgv1. MESS-MSGV2 = i_msgv2. CALL FUNCTION 'IDOC_ERROR_WORKFLOW_START' EXPORTING DOCNUM =0 EVENTCODE = 'EDIM' MESS = mess STATUSMESS = mess EXCEPTIONS NO_ENTRY_IN_TEDE5 =1 ERROR_IN_START_WORKFLOW =2 OTHERS = 3. COMMIT WORK. endif. "link created endif. "tede2 found endif. * Set return code to stop further processing of this IDoc

2008-09

Page 285 of 328

rc = 'X'. ENDFORM. *----------------------------------------------------------------------* FORM ANALYZING_EVENT_CREATE * Creates link between IDoc and workflow container. * SAP code stolen from LEDINF01 *----------------------------------------------------------------------FORM analyzing_event_create TABLES t_couple_to_process_in STRUCTURE ediinbound USING commit_counter_in LIKE ediglodata-comcount start_recfb_synchron_in LIKE ediglodata-inbsync. * local variables DATA: * instance that is created l_object TYPE swc_object, * object key, e.g IDoc number l_object_key LIKE swotobjid-objkey, * id of wf event l_event_id LIKE swedumevid-evtid, * status record for case of error l_status_record TYPE tidoc_status_record_ext, * flag indicating whether subscribed task is started synchronously l_start_recfb_synchron LIKE sweflags-syncflag VALUE ' ', * idoc number (needed because of type checking) l_idoc_number LIKE edidc-docnum. * local constants CONSTANTS: * object type 'IDOC' c_object_type LIKE swetypecou-objtype VALUE 'IDOCINVOIC', * name of event to be created c_idc_evt LIKE swetypecou-event VALUE 'INPUTERROROCCURREDMM' . if t_couple_to_process_in[] is initial. COMMIT WORK. CALL FUNCTION 'DEQUEUE_ALL'. CLEAR commit_counter_in. exit. endif. * cast l_start_recfb_synchron = start_recfb_synchron_in. * declaration of container swc_container l_t_ev_container. * initialize container swc_clear_container l_t_ev_container. * dequeue all idocs at the same time LOOP AT t_couple_to_process_in. * cast l_idoc_number = t_couple_to_process_in(16). CALL FUNCTION 'EDI_DOCUMENT_DEQUEUE_LATER' EXPORTING docnum = l_idoc_number EXCEPTIONS OTHERS = 0. ENDLOOP. * get first idoc number in table in order to create an object READ TABLE t_couple_to_process_in INDEX 1. * set object key in variable of correct type (casting) l_object_key = t_couple_to_process_in(16). * create an object, i.e. an IDoc swc_create_object l_object c_object_type l_object_key. * fill container: work item object id (idoc) swc_set_element l_t_ev_container "EC * c_element_wi_obj_id "EC * l_object. "EC * * fill container: NumberPlusEventcode (table of couples)

2008-09

Page 286 of 328

swc_set_table l_t_ev_container c_element_no_plus_info t_couple_to_process_in. * fire event that will trigger the idoc inbound processing CALL FUNCTION 'SWE_EVENT_CREATE' EXPORTING objtype = c_object_type objkey = l_object_key event = c_idc_evt * CREATOR ='' * START_WITH_DELAY = ' ' start_recfb_synchron = l_start_recfb_synchron IMPORTING event_id = l_event_id TABLES event_container = l_t_ev_container EXCEPTIONS objtype_not_found = 1 OTHERS = 2. IF ( sy-subrc <> 0 ) * event was not created => error handling for this idoc (EDIM) OR ( l_event_id = 0 ). * stop processing, no commit MESSAGE ID 'E0' TYPE 'A' NUMBER '374' WITH l_status_record-docnum c_idc_evt RAISING event_create_failed. ELSE. * do commit and reset counter * the commit will get the idocs to the database and at the same time * activate the event that was created COMMIT WORK. * dequeue all unprocessed IDocs to avoid log-overflow CALL FUNCTION 'DEQUEUE_ALL'. CLEAR commit_counter_in. * reset table of idocs that need to be processed CLEAR t_couple_to_process_in. REFRESH t_couple_to_process_in. ENDIF. ENDFORM. " ANALYZING_EVENT_CREATE

6.10.11 Report to download programs


%&%& RDIRZKBPROGS ZKBPROGS 1S ABAPER1 19990702ABAPER1 %&%& REPOZKBPROGS *----------------------------------------------------------------------* * Report: ZKBPROGS * *----------------------------------------------------------------------* * Function : Up/Download ABAP reports complete with texts * *----------------------------------------------------------------------* * Change Log : * * July 5, 1999 * * - Combined existing programs that did the upload and download into* * - one program. * * - Changed format that the reports are saved in to be compatible * * with Wolfgang Morgenthaler's upload/download program(YSTRASN00 * * at www.antarcon.de). Major differences between this program and* * Wolfgang's are: * - this program does not update TRDIR with the * * TRDIR entries that are in the program uploaded. Instead, * * current users stats are used. * * - this program allows selection of reports from a list or * * a single report can be tuped in and uploaded * * - this program also updates TADIR so that a development class* * is assigned to the program * * - this program checks to see if the program already has a * * TRDIR entry, and if it does, warns the user * * - this program will save/restore the program documenation too* * * * * 19990719 12531H 001EX 1999071911024200000000000000

2008-09

Page 287 of 328

* * *----------------------------------------------------------------------* REPORT ZKBPROGS NO STANDARD PAGE HEADING LINE-SIZE 255. *----------------------------------------------------------------------* * Declare Database Objects * *----------------------------------------------------------------------* tables: DOKIL, TRDIR. *----------------------------------------------------------------------* * Constants * CONSTANTS: MC_TRDIR_IDENTIFIER(72) TYPE C VALUE '%&%& RDIR', MC_REPORT_IDENTIFIER(72) TYPE C VALUE '%&%& REPO', MC_TEXT_IDENTIFIER(72) TYPE C VALUE '%&%& TEXP', MC_THEAD_IDENTIFIER(72) TYPE C VALUE '%&%& HEAD', MC_DOC_IDENTIFIER(72) TYPE C VALUE '%&%& DOKL', MC_TRDIR_SHORT(4) TYPE C VALUE 'RDIR', MC_REPORT_SHORT(4) TYPE C VALUE 'REPO', MC_TEXT_SHORT(4) TYPE C VALUE 'TEXP', MC_THEAD_SHORT(4) TYPE C VALUE 'HEAD', MC_DOC_SHORT(4) TYPE C VALUE 'DOKP'. *----------------------------------------------------------------------* *----------------------------------------------------------------------* * Declare Module level data structures * *----------------------------------------------------------------------* DATA: BEGIN OF MTAB_PROGRAM_SOURCE OCCURS 0, LINE(72) TYPE C, END OF MTAB_PROGRAM_SOURCE. DATA: MTAB_PROGRAM_TRDIR LIKE TRDIR OCCURS 0 WITH HEADER LINE. DATA: MTAB_PROGRAM_TEXTS LIKE TEXTPOOL OCCURS 0 WITH HEADER LINE. DATA: MSTR_THEAD LIKE THEAD. DATA: BEGIN OF MTAB_PROGRAM_FILE OCCURS 0, LINE(275) TYPE C, END OF MTAB_PROGRAM_FILE. DATA: BEGIN OF MTAB_DIRECTORY OCCURS 0, NAME LIKE TRDIR-NAME, DESC(72) TYPE C, SAVENAME LIKE RLGRAP-FILENAME, END OF MTAB_DIRECTORY. DATA: BEGIN OF MTAB_PROGRAM_DOCUMENTATION OCCURS 0, LINE(255) TYPE C, END OF MTAB_PROGRAM_DOCUMENTATION. *----------------------------------------------------------------------* * Selection Screen * *----------------------------------------------------------------------* *-- Options for upload/download of programs SELECTION-SCREEN BEGIN OF BLOCK FRM_OPTIONS WITH FRAME TITLE TEXT-UDL. PARAMETERS: RB_DOWN RADIOBUTTON GROUP UDL DEFAULT 'X'. " Download reports SELECTION-SCREEN BEGIN OF BLOCK FRM_TRDIR WITH FRAME TITLE TEXT-DIR. SELECT-OPTIONS: S_NAME FOR TRDIR-NAME, " Program Name S_SUBC FOR TRDIR-SUBC " Program Type DEFAULT 'F' OPTION EQ SIGN E," Exclude Functions by default S_CNAM FOR TRDIR-CNAM " Created by DEFAULT SY-UNAME, S_UNAM FOR TRDIR-UNAM, " Last Changed by S_CDAT FOR TRDIR-CDAT, " Creation date S_UDAT FOR TRDIR-UDAT. " Last update date SELECTION-SCREEN END OF BLOCK FRM_TRDIR. *-- Options for uploading programs PARAMETERS: RB_UP RADIOBUTTON GROUP UDL. " Upload reports SELECTION-SCREEN BEGIN OF BLOCK FRM_UPLOAD WITH FRAME TITLE TEXT-UPL. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 1(29) TEXT-SNG. PARAMETERS: RB_FILE RADIOBUTTON GROUP HOW DEFAULT 'X'. SELECTION-SCREEN COMMENT 33(42) TEXT-FNA. SELECTION-SCREEN END OF LINE. PARAMETERS: RB_LIST RADIOBUTTON GROUP HOW. SELECTION-SCREEN END OF BLOCK FRM_UPLOAD.

2008-09

Page 288 of 328

SELECTION-SCREEN END OF BLOCK FRM_OPTIONS. *-- Options for up/downloading programs SELECTION-SCREEN BEGIN OF BLOCK FRM_FILEN WITH FRAME TITLE TEXT-FIL. PARAMETERS: RB_DOS RADIOBUTTON GROUP FIL DEFAULT 'X', " Save to local RB_UNIX RADIOBUTTON GROUP FIL, " Save to UNIX P_PATH LIKE RLGRAP-FILENAME " Path to save files to DEFAULT 'c:\temp\'. SELECTION-SCREEN END OF BLOCK FRM_FILEN. AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_NAME-LOW. CALL FUNCTION 'F4_PROGRAM' EXPORTING OBJECT = S_NAME-LOW SUPPRESS_SELECTION = 'X' IMPORTING RESULT = S_NAME-LOW EXCEPTIONS OTHERS = 1. AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_NAME-HIGH. CALL FUNCTION 'F4_PROGRAM' EXPORTING OBJECT = S_NAME-HIGH SUPPRESS_SELECTION = 'X' IMPORTING RESULT = S_NAME-HIGH EXCEPTIONS OTHERS = 1. AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_UNAM-LOW. PERFORM GET_NAME USING 'S_UNAM-LOW' CHANGING S_UNAM-LOW. AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_UNAM-HIGH. PERFORM GET_NAME USING 'S_UNAM-HIGH' CHANGING S_UNAM-HIGH. AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_CNAM-LOW. PERFORM GET_NAME USING 'S_CNAM-LOW' CHANGING S_CNAM-LOW. AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_CNAM-HIGH. PERFORM GET_NAME USING 'S_CNAM-HIGH' CHANGING S_CNAM-HIGH. TOP-OF-PAGE. IF RB_LIST = 'X'. FORMAT COLOR COL_HEADING. NEW-LINE. WRITE: AT 3 TEXT-H01, AT 15 TEXT-H03. FORMAT COLOR OFF. ENDIF. AT LINE-SELECTION. CHECK RB_LIST = 'X'. " only do in list mode READ LINE SY-CUROW FIELD VALUE MTAB_DIRECTORY-SAVENAME. *-- Read file into an internal table PERFORM READ_REPORT_FROM_DISK TABLES MTAB_PROGRAM_FILE USING MTAB_DIRECTORY-SAVENAME. *-- Split table into TADIR entry, report lines, and report text PERFORM SPLIT_INCOMING_FILE TABLES MTAB_PROGRAM_FILE MTAB_PROGRAM_SOURCE MTAB_PROGRAM_TEXTS MTAB_PROGRAM_DOCUMENTATION CHANGING TRDIR MSTR_THEAD. *-- Save all of the data PERFORM INSERT_NEW_REPORT TABLES MTAB_PROGRAM_SOURCE MTAB_PROGRAM_TEXTS MTAB_PROGRAM_DOCUMENTATION USING TRDIR MSTR_THEAD. *----------------------------------------------------------------------* * Start of processing * *----------------------------------------------------------------------* START-OF-SELECTION. FORMAT COLOR COL_NORMAL. IF RB_DOWN = 'X'. PERFORM DOWNLOAD_REPORTS. ELSEIF RB_UP = 'X'. PERFORM UPLOAD_REPORTS. ENDIF.

2008-09

Page 289 of 328

END-OF-SELECTION. IF RB_DOWN = 'X'. CONCATENATE P_PATH 'directory.txt' INTO P_PATH. PERFORM SAVE_TABLE_TO_FILE TABLES MTAB_DIRECTORY USING P_PATH. ENDIF. *---------------------------------------------------------------------* * FORM UPLOAD_REPORTS * *---------------------------------------------------------------------* FORM UPLOAD_REPORTS. *-- Can upload a reports entered in selection criteria or *-- select from a list. List can be from index.txt in same directory *-- (created by the download) or by reading the first line of each file *-- in the directory. IF RB_FILE = 'X'. " Upload single program from a file *-- Read file into an internal table PERFORM READ_REPORT_FROM_DISK TABLES MTAB_PROGRAM_FILE USING P_PATH. *-- Split table into TADIR entry, report lines, and report text PERFORM SPLIT_INCOMING_FILE TABLES MTAB_PROGRAM_FILE MTAB_PROGRAM_SOURCE MTAB_PROGRAM_TEXTS MTAB_PROGRAM_DOCUMENTATION CHANGING TRDIR MSTR_THEAD. *-- Save all of the data PERFORM INSERT_NEW_REPORT TABLES MTAB_PROGRAM_SOURCE MTAB_PROGRAM_TEXTS MTAB_PROGRAM_DOCUMENTATION USING TRDIR MSTR_THEAD. ELSEIF RB_LIST = 'X'. " Show list for user to choose from *-- get list of report names/descriptions from directory text CONCATENATE P_PATH 'directory.txt' INTO P_PATH. PERFORM READ_REPORT_FROM_DISK TABLES MTAB_DIRECTORY USING P_PATH. SORT MTAB_DIRECTORY. *-- Write out list of report names/descriptions LOOP AT MTAB_DIRECTORY. WRITE: / MTAB_DIRECTORY-NAME UNDER TEXT-H01, MTAB_DIRECTORY-DESC UNDER TEXT-H03, MTAB_DIRECTORY-SAVENAME. ENDLOOP. *-- Process user selections for reports to upload. ENDIF. ENDFORM. " upload_reports *---------------------------------------------------------------------* * FORM DOWNLOAD_REPORTS * *---------------------------------------------------------------------* * From the user selections, get all programs that meet the * * criteria, and save them in ftab_program_directory. * * Also save the report to disk. * *---------------------------------------------------------------------* FORM DOWNLOAD_REPORTS. DATA: LC_FULL_FILENAME LIKE RLGRAP-FILENAME. *-- The table is put into an internal table because the program will *-- abend if multiple transfers to a dataset occur within a SELECT/ *-- ENDSELCT (tested on 3.1H) SELECT * FROM TRDIR INTO TABLE MTAB_PROGRAM_TRDIR WHERE NAME IN S_NAME AND SUBC IN S_SUBC AND CNAM IN S_CNAM AND UNAM IN S_UNAM AND CDAT IN S_CDAT AND UDAT IN S_UDAT. LOOP AT MTAB_PROGRAM_TRDIR. *-- Clear out text and source code tables CLEAR: MTAB_PROGRAM_FILE,

2008-09

Page 290 of 328

MTAB_PROGRAM_SOURCE, MTAB_PROGRAM_TEXTS, MTAB_PROGRAM_DOCUMENTATION. REFRESH: MTAB_PROGRAM_FILE, MTAB_PROGRAM_SOURCE, MTAB_PROGRAM_TEXTS, MTAB_PROGRAM_DOCUMENTATION. *-- Get the report READ REPORT MTAB_PROGRAM_TRDIR-NAME INTO MTAB_PROGRAM_SOURCE. *-- Get the text for the report READ TEXTPOOL MTAB_PROGRAM_TRDIR-NAME INTO MTAB_PROGRAM_TEXTS. *-- Get the documentation for the report CLEAR DOKIL. SELECT * UP TO 1 ROWS FROM DOKIL WHERE ID = 'RE' AND OBJECT = MTAB_PROGRAM_TRDIR-NAME AND LANGU = SY-LANGU AND TYP = 'E' ORDER BY VERSION DESCENDING. ENDSELECT. *-- Documentation exists for this object IF SY-SUBRC = 0. CALL FUNCTION 'DOCU_READ' EXPORTING ID = DOKIL-ID LANGU = DOKIL-LANGU OBJECT = DOKIL-OBJECT TYP = DOKIL-TYP VERSION = DOKIL-VERSION IMPORTING HEAD = MSTR_THEAD TABLES LINE = MTAB_PROGRAM_DOCUMENTATION EXCEPTIONS OTHERS = 1. ENDIF. *-- Put the report code and texts into a single file *-- Put the identifier line in so that the start of the TRDIR line *-- is marked CONCATENATE MC_TRDIR_IDENTIFIER MTAB_PROGRAM_TRDIR-NAME INTO MTAB_PROGRAM_FILE-LINE. APPEND MTAB_PROGRAM_FILE. *-- Add the TRDIR line MTAB_PROGRAM_FILE-LINE = MTAB_PROGRAM_TRDIR. APPEND MTAB_PROGRAM_FILE. *-- Put the identifier line in so that the start of the report code *-- is marked CONCATENATE MC_REPORT_IDENTIFIER MTAB_PROGRAM_TRDIR-NAME INTO MTAB_PROGRAM_FILE-LINE. APPEND MTAB_PROGRAM_FILE. *-- Add the report code LOOP AT MTAB_PROGRAM_SOURCE. MTAB_PROGRAM_FILE = MTAB_PROGRAM_SOURCE. APPEND MTAB_PROGRAM_FILE. ENDLOOP. *-- Put the identifier line in so that the start of the report text *-- is marked CONCATENATE MC_TEXT_IDENTIFIER MTAB_PROGRAM_TRDIR-NAME INTO MTAB_PROGRAM_FILE-LINE. APPEND MTAB_PROGRAM_FILE. *-- Add the report texts LOOP AT MTAB_PROGRAM_TEXTS. MTAB_PROGRAM_FILE = MTAB_PROGRAM_TEXTS. APPEND MTAB_PROGRAM_FILE. ENDLOOP. *-- Put the identifier line in so that the start of the THEAD record *-- is marked CONCATENATE MC_THEAD_IDENTIFIER MTAB_PROGRAM_TRDIR-NAME INTO MTAB_PROGRAM_FILE-LINE. APPEND MTAB_PROGRAM_FILE. MTAB_PROGRAM_FILE = MSTR_THEAD.

2008-09

Page 291 of 328

APPEND MTAB_PROGRAM_FILE. *-- Put the identifier line in so that the start of the report *-- documentation is marked CONCATENATE MC_DOC_IDENTIFIER MTAB_PROGRAM_TRDIR-NAME INTO MTAB_PROGRAM_FILE-LINE. APPEND MTAB_PROGRAM_FILE. *-- Add the report documentation LOOP AT MTAB_PROGRAM_DOCUMENTATION. MTAB_PROGRAM_FILE = MTAB_PROGRAM_DOCUMENTATION. APPEND MTAB_PROGRAM_FILE. ENDLOOP. *-- Make the fully pathed filename that report will be saved to CONCATENATE P_PATH MTAB_PROGRAM_TRDIR-NAME '.txt' INTO LC_FULL_FILENAME. PERFORM SAVE_TABLE_TO_FILE TABLES MTAB_PROGRAM_FILE USING LC_FULL_FILENAME. *-- Write out message with Program Name/Description READ TABLE MTAB_PROGRAM_TEXTS WITH KEY ID = 'R'. IF SY-SUBRC = 0. MTAB_DIRECTORY-NAME = MTAB_PROGRAM_TRDIR-NAME. MTAB_DIRECTORY-DESC = MTAB_PROGRAM_TEXTS-ENTRY. MTAB_DIRECTORY-SAVENAME = LC_FULL_FILENAME. APPEND MTAB_DIRECTORY. WRITE: / MTAB_PROGRAM_TRDIR-NAME, MTAB_PROGRAM_TEXTS-ENTRY(65) COLOR COL_HEADING. ELSE. MTAB_DIRECTORY-NAME = MTAB_PROGRAM_TRDIR-NAME. MTAB_DIRECTORY-DESC = 'No description available'. MTAB_DIRECTORY-SAVENAME = LC_FULL_FILENAME. APPEND MTAB_DIRECTORY. WRITE: / MTAB_PROGRAM_TRDIR-NAME. ENDIF. ENDLOOP. ENDFORM. " BUILD_PROGRAM_DIRECTORY *---------------------------------------------------------------------* * FORM SAVE_TABLE_TO_FILE * *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* * --> FTAB_TABLE * * --> F_FILENAME * *---------------------------------------------------------------------* FORM SAVE_TABLE_TO_FILE TABLES FTAB_TABLE USING F_FILENAME. IF RB_DOS = 'X'. " Save file to presentation server CALL FUNCTION 'WS_DOWNLOAD' EXPORTING FILENAME = F_FILENAME FILETYPE = 'ASC' TABLES DATA_TAB = FTAB_TABLE EXCEPTIONS OTHERS = 4. IF SY-SUBRC NE 0. WRITE: / 'Error opening dataset' COLOR COL_NEGATIVE, F_FILENAME COLOR COL_NEGATIVE. ENDIF. ELSE. " Save file to application server OPEN DATASET F_FILENAME FOR OUTPUT IN TEXT MODE. IF SY-SUBRC = 0. LOOP AT FTAB_TABLE. TRANSFER FTAB_TABLE TO F_FILENAME. IF SY-SUBRC NE 0. WRITE: / 'Error writing record to file;' COLOR COL_NEGATIVE, F_FILENAME COLOR COL_NEGATIVE. ENDIF. ENDLOOP. ELSE. WRITE: / 'Error opening dataset' COLOR COL_NEGATIVE, F_FILENAME COLOR COL_NEGATIVE. ENDIF. ENDIF. " End RB_DOS ENDFORM. " SAVE_PROGRAM

2008-09

Page 292 of 328

*---------------------------------------------------------------------* * FORM READ_REPORT_FROM_DISK * *---------------------------------------------------------------------* * Read report into internal table. Can read from local or * * remote computer * *---------------------------------------------------------------------* FORM READ_REPORT_FROM_DISK TABLES FTAB_TABLE USING F_FILENAME. DATA: LC_MESSAGE(128) TYPE C. CLEAR FTAB_TABLE. REFRESH FTAB_TABLE. IF RB_DOS = 'X'. TRANSLATE F_FILENAME USING '/\'. " correct slash for Dos PC file CALL FUNCTION 'WS_UPLOAD' EXPORTING FILENAME = F_FILENAME FILETYPE = 'ASC' TABLES DATA_TAB = FTAB_TABLE EXCEPTIONS CONVERSION_ERROR = 1 FILE_OPEN_ERROR = 2 FILE_READ_ERROR = 3 INVALID_TABLE_WIDTH = 4 INVALID_TYPE =5 NO_BATCH =6 UNKNOWN_ERROR =7 OTHERS = 8. IF SY-SUBRC >< 0. WRITE: / 'Error reading file from local PC' COLOR COL_NEGATIVE. ENDIF. ELSEIF RB_UNIX = 'X'. TRANSLATE F_FILENAME USING '\/'. " correct slash for unix OPEN DATASET F_FILENAME FOR INPUT MESSAGE LC_MESSAGE IN TEXT MODE. IF SY-SUBRC = 0. DO. READ DATASET F_FILENAME INTO FTAB_TABLE. IF SY-SUBRC = 0. APPEND FTAB_TABLE. ELSE. EXIT. ENDIF. ENDDO. CLOSE DATASET F_FILENAME. ELSE. WRITE: / 'Error reading file from remote computer' COLOR COL_NEGATIVE, / LC_MESSAGE, / F_FILENAME. SY-SUBRC = 4. ENDIF. ENDIF. ENDFORM. " READ_REPORT_FROM_DISK *---------------------------------------------------------------------* * FORM SPLIT_INCOMING_FILE * *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* * --> FTAB_PROGRAM_FILE * * --> FTAB_PROGRAM_SOURCE * * --> ` * * --> FTAB_PROGRAM_TEXTS * *---------------------------------------------------------------------* FORM SPLIT_INCOMING_FILE TABLES FTAB_PROGRAM_FILE STRUCTURE MTAB_PROGRAM_FILE FTAB_PROGRAM_SOURCE STRUCTURE MTAB_PROGRAM_SOURCE FTAB_PROGRAM_TEXTS STRUCTURE MTAB_PROGRAM_TEXTS FTAB_PROGRAM_DOCUMENTATION STRUCTURE MTAB_PROGRAM_DOCUMENTATION CHANGING FSTR_TRDIR FSTR_THEAD. DATA:

2008-09

Page 293 of 328

LC_DATATYPE(4) TYPE C, " Type of data, REPO, TEXP, RDIR LC_PROGRAM_FILE LIKE MTAB_PROGRAM_FILE. LOOP AT FTAB_PROGRAM_FILE. LC_PROGRAM_FILE = FTAB_PROGRAM_FILE. CASE LC_PROGRAM_FILE(9). WHEN MC_TRDIR_IDENTIFIER. LC_DATATYPE = MC_TRDIR_SHORT. WHEN MC_REPORT_IDENTIFIER. LC_DATATYPE = MC_REPORT_SHORT. WHEN MC_TEXT_IDENTIFIER. LC_DATATYPE = MC_TEXT_SHORT. WHEN MC_DOC_IDENTIFIER. LC_DATATYPE = MC_DOC_SHORT. WHEN MC_THEAD_IDENTIFIER. LC_DATATYPE = MC_THEAD_SHORT. WHEN OTHERS. " Actual contents of report, trdir, or text CASE LC_DATATYPE. WHEN MC_TRDIR_SHORT. FSTR_TRDIR = FTAB_PROGRAM_FILE. WHEN MC_REPORT_SHORT. FTAB_PROGRAM_SOURCE = FTAB_PROGRAM_FILE. APPEND FTAB_PROGRAM_SOURCE. WHEN MC_TEXT_SHORT. FTAB_PROGRAM_TEXTS = FTAB_PROGRAM_FILE. APPEND FTAB_PROGRAM_TEXTS. WHEN MC_THEAD_SHORT. FSTR_THEAD = FTAB_PROGRAM_FILE. WHEN MC_DOC_SHORT. FTAB_PROGRAM_DOCUMENTATION = FTAB_PROGRAM_FILE. APPEND FTAB_PROGRAM_DOCUMENTATION. ENDCASE. ENDCASE. ENDLOOP. ENDFORM. " SPLIT_INCOMING_FILE *---------------------------------------------------------------------* * FORM INSERT_NEW_REPORT * *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* * --> FTAB_PROGRAM_SOURCE * * --> FTAB_PROGRAM_TEXTS * * --> F_TRDIR * *---------------------------------------------------------------------* FORM INSERT_NEW_REPORT TABLES FTAB_PROGRAM_SOURCE STRUCTURE MTAB_PROGRAM_SOURCE FTAB_PROGRAM_TEXTS STRUCTURE MTAB_PROGRAM_TEXTS FTAB_PROGRAM_DOCUMENTATION STRUCTURE MTAB_PROGRAM_DOCUMENTATION USING FSTR_TRDIR LIKE TRDIR FSTR_THEAD LIKE MSTR_THEAD. DATA: LC_OBJ_NAME LIKE E071-OBJ_NAME, LC_LINE2(40) TYPE C, LC_ANSWER(1) TYPE C. *-- read trdir to see if the report already exists, if it does, prompt *-- user to overwrite or abort. SELECT SINGLE * FROM TRDIR WHERE NAME = FSTR_TRDIR-NAME. IF SY-SUBRC = 0. " Already exists CONCATENATE 'want to overwrite report' FSTR_TRDIR-NAME INTO LC_LINE2 SEPARATED BY SPACE. CONCATENATE LC_LINE2 '?' INTO LC_LINE2. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING DEFAULTOPTION = 'N' TEXTLINE1 = 'The selected report already exists, do you' TEXTLINE2 = LC_LINE2 TITEL = 'Report already exists' CANCEL_DISPLAY = SPACE IMPORTING ANSWER = LC_ANSWER EXCEPTIONS OTHERS = 1.

2008-09

Page 294 of 328

ELSE. LC_ANSWER = 'J'. ENDIF. IF LC_ANSWER = 'J'. *-- Create the TADIR entry. (TRDIR entry created by INSERT REPORT) LC_OBJ_NAME = TRDIR-NAME. CALL FUNCTION 'TR_TADIR_POPUP_ENTRY_E071' EXPORTING WI_E071_PGMID = 'R3TR' WI_E071_OBJECT = 'PROG' WI_E071_OBJ_NAME = LC_OBJ_NAME WI_TADIR_DEVCLASS = '$TMP' EXCEPTIONS EXIT =3 OTHERS = 4. IF SY-SUBRC = 0. *-- Create Report INSERT REPORT FSTR_TRDIR-NAME FROM FTAB_PROGRAM_SOURCE. *-- Create Texts INSERT TEXTPOOL FSTR_TRDIR-NAME FROM FTAB_PROGRAM_TEXTS LANGUAGE SY-LANGU. *-- Save Documentation CALL FUNCTION 'DOCU_UPDATE' EXPORTING HEAD = FSTR_THEAD STATE = 'A' TYP = 'E' VERSION = '1' TABLES LINE = FTAB_PROGRAM_DOCUMENTATION EXCEPTIONS OTHERS = 1. ELSE. WRITE: / 'Error updating the TADIR entry' COLOR COL_NEGATIVE, 'Program' COLOR COL_NEGATIVE INTENSIFIED OFF, FSTR_TRDIR-NAME, 'was not loaded into SAP.' COLOR COL_NEGATIVE INTENSIFIED OFF. ENDIF. ELSE. WRITE: / FSTR_TRDIR-NAME COLOR COL_NEGATIVE, 'was not uploaded into SAP. Action cancelled by user' COLOR COL_NEGATIVE INTENSIFIED OFF. ENDIF. ENDFORM. " INSERT_NEW_REPORT *---------------------------------------------------------------------* * FORM GET_NAME * *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* * --> VALUE(F_FIELD) * * --> F_NAME * *---------------------------------------------------------------------* FORM GET_NAME USING VALUE(F_FIELD) CHANGING F_NAME. DATA: LTAB_FIELDS LIKE DYNPREAD OCCURS 0 WITH HEADER LINE, LC_PROG LIKE D020S-PROG, LC_DNUM LIKE D020S-DNUM. TRANSLATE F_FIELD TO UPPER CASE. refresh ltab_fields. LTAB_FIELDS-FIELDNAME = F_FIELD. append ltab_fields. LC_PROG = SY-REPID . LC_DNUM = SY-DYNNR . CALL FUNCTION 'DYNP_VALUES_READ' EXPORTING DYNAME = LC_PROG DYNUMB = LC_DNUM TABLES dynpfields = ltab_fields EXCEPTIONS OTHERS = 01. read table ltab_fields index 1. IF SY-SUBRC EQ 0. F_NAME = LTAB_FIELDS-FIELDVALUE. refresh ltab_fields. ENDIF.

2008-09

Page 295 of 328

CALL FUNCTION 'F4_USER' EXPORTING OBJECT = F_NAME IMPORTING RESULT = F_NAME. ENDFORM. " GET_NAME %&%& TEXPZKBPROGS IDIR File Download Options (File Selection) {{{ IFIL File Options {{{ IFNA Enter filename below (under File Options) *{{{ IH01 Prog Name {{{ IH03 Program Description {{{ ISNG Upload a single file #{{{ IUDL Upload to SAP/Download from SAP {{{ IUPL File Upload Options {{{ R Backup/Restore program source code with texts -{{{ SP_PATH Path to save programs to {{{ SRB_DOS Files on local computer #{{{ SRB_DOWN Download Programs {{{ SRB_FILE Upload a single file {{{ SRB_LIST Select program(s) from a list %{{{ SRB_UNIX Files on remote computer "{{{ SRB_UP Upload Programs to SAP SS_CDAT Date Created {{{ SS_CNAM Created by UserID {{{ SS_NAME Program Name {{{ SS_SUBC Program Type {{{ SS_UDAT Date Changed {{{ SS_UNAM Last Changed by UserID %&%& HEADZKBPROGS DOKU ZHRBDC54 RE E 31H 19990707151635ABAPER1 31H 1999070715193207200000 0 %&%& DOKLZKBPROGS

-{{{

-{{{ S_DOCU_SHOW S_DOCUS100002ABAPER1

6.10.12 Display table in HTML


REPORT zhtmltable. *********************************************************** * Column type P not supported. *********************************************************** TABLES dd02l. DATA: zx030l LIKE x030l, p_number TYPE i, tablefound TYPE i. DATA: colorval TYPE i. DATA: packval TYPE p, totalrows TYPE n. DATA: w_area1(5000) TYPE c,charval(20) TYPE c. DATA: tablen TYPE i VALUE 255. DATA: BEGIN OF htmlview OCCURS 0, htmlcode(500) TYPE c, END OF htmlview. DATA BEGIN OF zdfies OCCURS 1000. INCLUDE STRUCTURE dfies. DATA END OF zdfies.

2008-09

Page 296 of 328

DATA: BEGIN OF flditab OCCURS 0, fldname(11) TYPE c, END OF flditab. ************** PARAMETERS: tabname LIKE dd02l-tabname OBLIGATORY. ************** htmlview-htmlcode = '<HTML><HEAD><TITLE>Table Browser</TITLE>'. APPEND htmlview. htmlview-htmlcode = '<BODY BGCOLOR="#404040"><FONT COLOR="#00FFFF" face="Arial Black"> Table View : '. APPEND htmlview. htmlview-htmlcode = tabname. APPEND htmlview. htmlview-htmlcode = '</FONT> <p>&nbsp;</p>'. APPEND htmlview. *********************************************** PERFORM check-table-class. PERFORM read-direct-table. PERFORM downloadhtml. PERFORM showhtml. ******************************************** FORM check-table-class. tablefound = -1. SELECT * FROM dd02l WHERE tabname EQ tabname. IF dd02l-tabclass CS 'TRANSP' OR dd02l-tabclass CS 'POOL' OR dd02l-tabclass CS 'CLUSTER '. tablefound = 1. EXIT. ENDIF. ENDSELECT. IF tablefound < 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH 'Table Not Found.... or Table Class Not in "TRANSP","POOL", "CLUSTER"'. STOP. ENDIF. ENDFORM. ************************************************************************ FORM read-direct-table. DATA: offs TYPE i. DATA: len2(5) TYPE n. DATA: anz_numb TYPE i. PERFORM gettableinfo USING tabname. htmlview-htmlcode = '<table border="0" width="100%">'. APPEND htmlview. htmlview-htmlcode = '<tr valign="middle" BGCOLOR="#5F5F5F">'. APPEND htmlview. htmlview-htmlcode = '<FONT SIZE="3" COLOR="#FFBF18" FACE= "Courier new">'. APPEND htmlview. LOOP AT zdfies. PERFORM htmlheader USING zdfies-fieldname. flditab-fldname = zdfies-fieldname. APPEND flditab. ENDLOOP. htmlview-htmlcode = '</B></tr>'. APPEND htmlview. colorval = 1. SELECT COUNT(*) FROM (tabname) INTO totalrows. WRITE :/ totalrows. anz_numb = 0. SELECT * FROM (tabname) INTO w_area1. ADD 1 TO anz_numb. IF anz_numb GT 100. " U can alter the Hits, now Max. is 100 EXIT. ENDIF. IF colorval > 0 . htmlview-htmlcode = '<tr valign="middle" BGCOLOR="#F7F7F7"><FONT size="1" COLOR="#008080" FACE="Arial Narrow">'. APPEND htmlview. ELSE. htmlview-htmlcode = '<tr valign="middle" bgcolor="#D2D2D2"><FONT SIZE="1" COLOR="#9F000F" FACE="Arial Narrow">'. APPEND htmlview. ENDIF. colorval = colorval * -1 . *************

2008-09

Page 297 of 328

LOOP AT zdfies. charval = w_area1+zdfies-offset(zdfies-intlen). CASE zdfies-inttype. WHEN 'P'. * PACKVAL = W_AREA1+ZDFIES-OFFSET(ZDFIES-INTLEN). * CHARVAL = PACKVAL. ENDCASE. PERFORM htmlfield USING w_area1+zdfies-offset(zdfies-intlen). ENDLOOP. ************* htmlview-htmlcode = '</FONT></tr>'. APPEND htmlview. CLEAR: w_area1. ENDSELECT. htmlview-htmlcode = '</body></html>'. APPEND htmlview. ENDFORM. **************************************************************** FORM downloadhtml. CALL FUNCTION 'WS_DOWNLOAD' EXPORTING filename = 'C:\TABLEVIEW.HTM' TABLES data_tab = htmlview. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDFORM. *************************************************************** FORM showhtml. CALL FUNCTION 'WS_EXECUTE' EXPORTING commandline = 'c:\tableview.htm' program = 'C:\PROGRA~1\INTERN~1\IEXPLORE.EXE'. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDFORM. ************************************************************************ FORM gettableinfo USING tname. CALL FUNCTION 'GET_FIELDTAB' EXPORTING langu = sy-langu only = space tabname = tname withtext = 'X' IMPORTING header = zx030l TABLES fieldtab = zdfies EXCEPTIONS internal_error = 01 no_texts_found = 02 table_has_no_fields = 03 table_not_activ = 04. CASE sy-subrc. WHEN 0. LOOP AT zdfies. ENDLOOP. WHEN OTHERS. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-subrc. ENDCASE. ENDFORM. ******************************************************** FORM htmlfield USING name TYPE c. htmlview-htmlcode = '<td >'. APPEND htmlview. htmlview-htmlcode = name. APPEND htmlview. htmlview-htmlcode = '</td>'. APPEND htmlview. ENDFORM. ******************************************************** FORM htmlheader USING name TYPE c. htmlview-htmlcode = '<td >'. APPEND htmlview. htmlview-htmlcode = name. APPEND htmlview. htmlview-htmlcode = '</td>'. APPEND htmlview.

2008-09

Page 298 of 328

ENDFORM.

6.10.13 Tree reports


REPORT ZIB_EXP_TREE_REP_SAMPLE LINE-COUNT 65 LINE-SIZE 80 NO STANDARD PAGE HEADING. ************************************************************************ * Author: Igor Barbaric * Expandable hierarchy tree report sample - very easy to build an * include program for universal usage! Consists of two main forms and * a sample tree. * Forms: * - "print_tree" prints the tree to the list out of * the given internal table; items may be mixed in any order * - "expand_collapse" - maintains the internal table in such way that * the selected branch is expanded or collapsed ********************************************************************* DATA: BEGIN OF ITEMS OCCURS 100, ID(10), PARENT_ID(10), TEXT(20), SYMBOL, END OF ITEMS, TABIX_STACK LIKE SY-TABIX OCCURS 10 WITH HEADER LINE, ITEMS_SHOW LIKE ITEMS OCCURS 100 WITH HEADER LINE. INCLUDE <SYMBOL>. * append sample items (mixed order) PERFORM APPEND_ITEM USING: "no. par. no. title '1' '' 'Food', '2' '' 'Drinks', '12' '9' 'Jack Daniels', '17' '11' 'Bosch', '3' '' 'Tools', '4' '1' 'Meat', '16' '11' 'Metabo', '5' '1' 'Chocolate', '6' '2' 'Alcoholic', '8' '4' 'Pork', '10' '5' 'Milka', '11' '3' 'Drills', '13' '9' 'Jim Beam', '7' '4' 'Beef', '14' '2' 'Non-alcoholic', '35' '31' 'Teran', '9' '6' 'Whiskey', '15' '14' 'Coca-cola', '18' '6' 'Wine', '28' '18' 'Croatia', '33' '28' 'Slavonia', '34' '28' 'Istria', '29' '18' 'Hungary', '30' '29' 'Tokaj', '19' '33' 'Enjingi', '20' '33' 'Zdjelarevic', '22' '19' 'Riesling', '23' '19' 'Chardonnay', '24' '20' 'Riesling', '32' '31' 'Malvazija', '25' '20' 'Merlot', '31' '34' 'Tomasevic'. * show initial list (items with level 0 - parentless items) LOOP AT ITEMS WHERE PARENT_ID = ''. MOVE-CORRESPONDING ITEMS TO ITEMS_SHOW. ITEMS_SHOW-SYMBOL = '+'. APPEND ITEMS_SHOW. ENDLOOP. PERFORM PRINT_TREE TABLES ITEMS_SHOW. * at line-selection - when the node is opened/closed or item double-clk AT LINE-SELECTION. READ TABLE ITEMS WITH KEY PARENT_ID = ITEMS_SHOW-ID. "see 'hide' IF SY-SUBRC = 0. "item has children - expand or collapse SY-LSIND = 0. PERFORM EXPAND_COLLAPSE USING ITEMS_SHOW-ID.

2008-09

Page 299 of 328

PERFORM PRINT_TREE TABLES ITEMS_SHOW. ELSE. "item has NO children - perform some action READ TABLE ITEMS WITH KEY ID = ITEMS_SHOW-ID. WRITE: 'Action performed on item "' NO-GAP, ITEMS-TEXT NO-GAP, '", id.', ITEMS-ID. ENDIF. * form print_tree FORM PRINT_TREE TABLES ITEMS STRUCTURE ITEMS. DATA: V_TABIX LIKE SY-TABIX, START_TABIX LIKE SY-TABIX, V_LEVEL LIKE SY-TFILL, V_OFFSET TYPE I, V_ID LIKE ITEMS-ID, V_PARENT_ID LIKE ITEMS-PARENT_ID, V_PARENT_ID_FOR_VLINE LIKE ITEMS-PARENT_ID, V_PREV_LEVEL TYPE I, V_ITEMS_COUNT LIKE SY-TFILL, V_VLINES_STRING(200). CHECK NOT ITEMS[] IS INITIAL. SORT ITEMS BY PARENT_ID ID. READ TABLE ITEMS INDEX 1. V_PARENT_ID = ITEMS-PARENT_ID. START_TABIX = 1. REFRESH TABIX_STACK. DO. LOOP AT ITEMS FROM START_TABIX. V_TABIX = START_TABIX = SY-TABIX. "remember current index V_ID = ITEMS-ID. V_PARENT_ID_FOR_VLINE = ITEMS-PARENT_ID. * decrease level and exit loop if parent not the same as previous IF ITEMS-PARENT_ID NE V_PARENT_ID. PERFORM READ_FROM_STACK CHANGING START_TABIX. "level = NoOfRecs READ TABLE ITEMS INDEX START_TABIX. V_PARENT_ID = ITEMS-PARENT_ID. ADD 1 TO START_TABIX. "next loop starts from parent index + 1 * clear vline IF V_LEVEL > 1. V_OFFSET = 2 + ( V_LEVEL - 2 ) * 3. IF V_LEVEL = 1. V_OFFSET = 1. ENDIF. V_VLINES_STRING+V_OFFSET = ' '. ENDIF. EXIT. ENDIF. V_PARENT_ID = ITEMS-PARENT_ID. * write item FORMAT COLOR OFF. DESCRIBE TABLE TABIX_STACK LINES V_LEVEL."level is no of StackRecs WRITE: / V_VLINES_STRING. V_OFFSET = V_LEVEL * 3. IF V_LEVEL NE 0. IF V_PREV_LEVEL < V_LEVEL. WRITE: AT V_OFFSET '|', / ''. WRITE: / V_VLINES_STRING. ENDIF. V_OFFSET = V_LEVEL * 3. WRITE AT V_OFFSET '|--'. ENDIF. V_OFFSET = V_OFFSET + 3. CASE ITEMS-SYMBOL. WHEN '+'. WRITE AT V_OFFSET SYM_PLUS_FOLDER AS SYMBOL COLOR 4 INTENSIFIED HOTSPOT. WHEN '-'. WRITE AT V_OFFSET SYM_MINUS_FOLDER AS SYMBOL COLOR 4 INTENSIFIED HOTSPOT. WHEN OTHERS. FORMAT COLOR 5. ENDCASE. WRITE: ITEMS-TEXT. V_PREV_LEVEL = V_LEVEL. HIDE: ITEMS-ID. ADD 1 TO V_ITEMS_COUNT. READ TABLE ITEMS WITH KEY PARENT_ID = ITEMS-ID. * increase level and exit loop if item has children IF SY-SUBRC = 0. START_TABIX = SY-TABIX. APPEND V_TABIX TO TABIX_STACK. "level is no of recs in stack V_PARENT_ID = ITEMS-PARENT_ID.

2008-09

Page 300 of 328

set vline V_TABIX = V_TABIX + 1. READ TABLE ITEMS INDEX V_TABIX. V_OFFSET = 2 + ( V_LEVEL - 1 ) * 3. IF V_LEVEL > 0. IF ITEMS-PARENT_ID = V_PARENT_ID_FOR_VLINE AND SY-SUBRC = 0. V_VLINES_STRING+V_OFFSET = '|'. ELSE. V_VLINES_STRING+V_OFFSET = ' '. ENDIF. ENDIF. EXIT. ENDIF. * at last - decrease level AT LAST. * clear vline IF V_LEVEL > 1. V_OFFSET = 2 + ( V_LEVEL - 2 ) * 3. IF V_LEVEL = 1. V_OFFSET = 1. ENDIF. V_VLINES_STRING+V_OFFSET = ' '. ENDIF. " next loop starts from parent index, not parent index + 1 " because of different parents level will decrease anyway PERFORM READ_FROM_STACK CHANGING START_TABIX. APPEND START_TABIX TO TABIX_STACK. "must return index to stack ENDAT. ENDLOOP. DESCRIBE TABLE ITEMS. IF START_TABIX > SY-TFILL OR V_ITEMS_COUNT >= SY-TFILL. EXIT. ENDIF. ENDDO. ENDFORM. * form expand_collapse FORM EXPAND_COLLAPSE USING VALUE(V_ID). DATA: V_NO_MORE_ORPHANS, ITEMS_TEMP LIKE ITEMS OCCURS 100 WITH HEADER LINE. DELETE ITEMS_SHOW WHERE PARENT_ID = V_ID. "try to collapse IF SY-SUBRC = 0. "succesfull first collapse DO. "cascade collapse - delete 'orphans' that are left REFRESH ITEMS_TEMP. MOVE ITEMS_SHOW[] TO ITEMS_TEMP[]. SORT ITEMS_TEMP BY ID. V_NO_MORE_ORPHANS = 'X'. LOOP AT ITEMS_SHOW WHERE PARENT_ID NE ''. READ TABLE ITEMS_TEMP WITH KEY ID = ITEMS_SHOW-PARENT_ID BINARY SEARCH TRANSPORTING NO FIELDS. IF SY-SUBRC NE 0. "no parent - it's an orphan CLEAR V_NO_MORE_ORPHANS. DELETE ITEMS_SHOW. ENDIF. ENDLOOP. IF V_NO_MORE_ORPHANS = 'X'. EXIT. ENDIF. ENDDO. ITEMS_SHOW-SYMBOL = '+'. MODIFY ITEMS_SHOW TRANSPORTING SYMBOL WHERE ID = V_ID. ELSE. "unsuccessfull collapse - expand ITEMS_SHOW-SYMBOL = '-'. MODIFY ITEMS_SHOW TRANSPORTING SYMBOL WHERE ID = V_ID. LOOP AT ITEMS WHERE PARENT_ID = V_ID. "show children APPEND ITEMS TO ITEMS_SHOW. ENDLOOP. LOOP AT ITEMS_SHOW WHERE PARENT_ID = V_ID. "check grandchildren READ TABLE ITEMS WITH KEY PARENT_ID = ITEMS_SHOW-ID. IF SY-SUBRC = 0. ITEMS_SHOW-SYMBOL = '+'. ELSE. ITEMS_SHOW-SYMBOL = ''. ENDIF. MODIFY ITEMS_SHOW. ENDLOOP. ENDIF. ENDFORM. * form append_item

2008-09

Page 301 of 328

FORM APPEND_ITEM USING VALUE(ID) VALUE(PARENT_ID) VALUE(TEXT). ITEMS-ID = ID. ITEMS-PARENT_ID = PARENT_ID. ITEMS-TEXT = TEXT. APPEND ITEMS. ENDFORM. * form read_from_stack FORM READ_FROM_STACK CHANGING TABIX LIKE SY-TABIX. DESCRIBE TABLE TABIX_STACK. CHECK SY-TFILL NE 0. READ TABLE TABIX_STACK INDEX SY-TFILL. TABIX = TABIX_STACK. DELETE TABIX_STACK INDEX SY-TFILL. ENDFORM.

6.10.14 Shell List Report off a table - NAST


REPORT znast. *** Table Definitions *** TABLES: nast. *** TYPE DEFINITIONS *** TYPES: BEGIN OF itab_data_structure, kappl LIKE nast-kappl, "Application objky LIKE nast-objky, "Key kschl LIKE nast-kschl, "Output type parnr LIKE nast-parnr, "Partner erdat LIKE nast-erdat, "Creation date usnam LIKE nast-usnam, "User name vstat LIKE nast-vstat. "Status TYPES: END OF itab_data_structure. TYPES: BEGIN OF itab_data_structure2, objky LIKE nast-objky, "Key docnum LIKE edidc-docnum, "Idoc Number mestyp LIKE edidc-mestyp. "Message type TYPES: END OF itab_data_structure2. *** INTERNAL TABLE DEFINITIONS *** DATA: itab_data TYPE itab_data_structure OCCURS 0 WITH HEADER LINE, itab_data2 TYPE itab_data_structure2 OCCURS 0 WITH HEADER LINE, itab_linked_idocs LIKE sww_contob OCCURS 5 WITH HEADER LINE, t_roles LIKE relroles OCCURS 5 WITH HEADER LINE. *** DATA DEFINITIONS DATA: field_name(30), "Check for line selection on field t_kschl(4), "Output type t_kunnr(10), "Customer number t_object LIKE borident. *** Selection screen *** SELECTION-SCREEN BEGIN OF BLOCK g1 WITH FRAME TITLE text-000. SELECT-OPTIONS: s_kappl FOR nast-kappl, "Application s_objky FOR nast-objky, "Key s_kschl FOR nast-kschl, "Output type s_parnr FOR nast-parnr, "Partner s_erdat FOR nast-erdat, "Creation date s_usnam FOR nast-usnam, "User name s_vstat FOR nast-vstat. "Status SELECTION-SCREEN END OF BLOCK g1. SELECTION-SCREEN BEGIN OF BLOCK g2 WITH FRAME TITLE text-001. PARAMETERS: r_kappl RADIOBUTTON GROUP r1, r_objky RADIOBUTTON GROUP r1, r_kschl RADIOBUTTON GROUP r1, r_parnr RADIOBUTTON GROUP r1, r_erdat RADIOBUTTON GROUP r1, r_usnam RADIOBUTTON GROUP r1, r_vstat RADIOBUTTON GROUP r1. SELECTION-SCREEN END OF BLOCK g2. SELECTION-SCREEN BEGIN OF BLOCK g3 WITH FRAME TITLE text-002.

2008-09

Page 302 of 328

PARAMETERS: c_idoc AS CHECKBOX DEFAULT 'X'. SELECTION-SCREEN END OF BLOCK g3. *** Initialization *** INITIALIZATION. * Default dates MOVE 'I' TO s_erdat-sign. MOVE 'BT' TO s_erdat-option. MOVE sy-datum TO s_erdat-high. SUBTRACT 7 FROM sy-datum. MOVE sy-datum TO s_erdat-low. APPEND s_erdat. * Default Status MOVE 'I' TO s_vstat-sign. MOVE 'NE' TO s_vstat-option. MOVE '1' TO s_vstat-low. APPEND s_vstat. * Default Output MOVE 'I' TO s_kschl-sign. MOVE 'EQ' TO s_kschl-option. MOVE 'ZBA0' TO s_kschl-low. APPEND s_kschl. MOVE 'ZBA1' TO s_kschl-low. APPEND s_kschl. MOVE 'ZBA2' TO s_kschl-low. APPEND s_kschl. MOVE 'ZP00' TO s_kschl-low. APPEND s_kschl. MOVE 'ZAVA' TO s_kschl-low. APPEND s_kschl. MOVE 'ZD00' TO s_kschl-low. APPEND s_kschl. START-OF-SELECTION. REFRESH: itab_data, itab_data2. SELECT * FROM nast WHERE kappl IN s_kappl AND objky IN s_objky AND kschl IN s_kschl AND parnr IN s_parnr AND erdat IN s_erdat AND usnam IN s_usnam AND vstat IN s_vstat. itab_data-kappl = nast-kappl. itab_data-objky = nast-objky. itab_data-kschl = nast-kschl. itab_data-parnr = nast-parnr. itab_data-erdat = nast-erdat. itab_data-usnam = nast-usnam. itab_data-vstat = nast-vstat. APPEND itab_data. ENDSELECT. IF sy-subrc <> 0. MESSAGE i999(b1) WITH 'No records in that range!'. ELSE. IF c_idoc = 'X'. CLEAR: itab_data2. LOOP AT itab_data. itab_data2-objky = itab_data-objky. CASE itab_data-kschl. WHEN 'ZD00'. "Invoice READ TABLE itab_data2 WITH KEY objky = itab_data-objky. CHECK sy-subrc <> 0. REFRESH: t_roles. t_object-objkey = itab_data-objky. t_object-objtype = 'VBRK'. CALL FUNCTION 'SREL_GET_NEXT_RELATIONS' EXPORTING

2008-09

Page 303 of 328

object = t_object TABLES roles = t_roles EXCEPTIONS internal_error = 1 no_logsys =2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE i999(b1) WITH 'Could not execute linked docs FM:' itab_data-objky. ELSE. LOOP AT t_roles WHERE objtype = 'IDOC'. itab_data2-docnum = t_roles-objkey. SELECT SINGLE mestyp FROM edidc INTO itab_data2-mestyp WHERE docnum = t_roles-objkey. APPEND itab_data2. ENDLOOP. ENDIF. WHEN 'ZAVA'. "Delivery READ TABLE itab_data2 WITH KEY objky = itab_data-objky. CHECK sy-subrc <> 0. REFRESH: t_roles. t_object-objkey = itab_data-objky. t_object-objtype = 'LIKP'. CALL FUNCTION 'SREL_GET_NEXT_RELATIONS' EXPORTING object = t_object TABLES roles = t_roles EXCEPTIONS internal_error = 1 no_logsys =2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE i999(b1) WITH 'Could not execute linked docs FM:' itab_data-objky. ELSE. LOOP AT t_roles WHERE objtype = 'IDOC'. itab_data2-docnum = t_roles-objkey. SELECT SINGLE mestyp FROM edidc INTO itab_data2-mestyp WHERE docnum = t_roles-objkey. APPEND itab_data2. ENDLOOP. ENDIF. WHEN 'ZBA0' OR 'ZBA1' OR 'ZBA2'. "Orders READ TABLE itab_data2 WITH KEY objky = itab_data-objky. CHECK sy-subrc <> 0. REFRESH: t_roles. t_object-objkey = itab_data-objky. t_object-objtype = 'BUS2032'. CALL FUNCTION 'SREL_GET_NEXT_RELATIONS' EXPORTING object = t_object TABLES roles = t_roles EXCEPTIONS internal_error = 1 no_logsys =2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE i999(b1) WITH 'Could not execute linked docs FM:' itab_data-objky. ELSE. LOOP AT t_roles WHERE objtype = 'IDOC'. itab_data2-docnum = t_roles-objkey. SELECT SINGLE mestyp FROM edidc INTO itab_data2-mestyp

2008-09

Page 304 of 328

WHERE docnum = t_roles-objkey. COLLECT itab_data2. ENDLOOP. ENDIF. WHEN 'ZP00'. "Scheduling Agreement READ TABLE itab_data2 WITH KEY objky = itab_data-objky. CHECK sy-subrc <> 0. REFRESH: t_roles. t_object-objkey = itab_data-objky. t_object-objtype = 'BUS2035'. CALL FUNCTION 'SREL_GET_NEXT_RELATIONS' EXPORTING object = t_object TABLES roles = t_roles EXCEPTIONS internal_error = 1 no_logsys =2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE i999(b1) WITH 'Could not execute linked docs FM:' itab_data-objky. ELSE. LOOP AT t_roles WHERE objtype = 'IDOC'. itab_data2-docnum = t_roles-objkey. SELECT SINGLE mestyp FROM edidc INTO itab_data2-mestyp WHERE docnum = t_roles-objkey. APPEND itab_data2. ENDLOOP. ENDIF. ENDCASE. ENDLOOP. ENDIF. ENDIF. END-OF-SELECTION. DESCRIBE TABLE itab_data. IF sy-tfill > 0. IF r_kappl = 'X'. SORT itab_data BY kappl. ELSEIF r_objky = 'X'. SORT itab_data BY objky. ELSEIF r_kschl = 'X'. SORT itab_data BY kschl. ELSEIF r_parnr = 'X'. SORT itab_data BY parnr. ELSEIF r_erdat = 'X'. SORT itab_data BY erdat. ELSEIF r_usnam = 'X'. SORT itab_data BY usnam. ELSEIF r_vstat = 'X'. SORT itab_data BY vstat. ENDIF. PERFORM print_itab_data TABLES itab_data itab_data2. ENDIF. AT LINE-SELECTION. GET CURSOR FIELD field_name. CASE field_name. WHEN 'ITAB_DATA2-DOCNUM' OR 'ITAB_DATA2-MESTYP'. "IDoc number CALL FUNCTION 'EDI_DOCUMENT_DATA_DISPLAY' EXPORTING docnum = itab_data2-docnum EXCEPTIONS no_data_record_found = 1 OTHERS = 2.

2008-09

Page 305 of 328

IF sy-subrc <> 0. MESSAGE i999(b1) WITH 'Could not display IDoc:' itab_data2-docnum. ENDIF. CLEAR: itab_data2-docnum. WHEN 'ITAB_DATA-OBJKY'. "Order number t_kschl = sy-lisel+34(4). CASE t_kschl. WHEN 'ZAVA'. "Delivery SET PARAMETER ID 'VL' FIELD itab_data-objky. CALL TRANSACTION 'VL03' AND SKIP FIRST SCREEN. WHEN 'ZBA0' OR 'ZBA1' OR 'ZBA2'. "Sales Order SET PARAMETER ID 'AUN' FIELD itab_data-objky. CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN. WHEN 'ZP00'. "Scheduling Agreement SET PARAMETER ID 'LPN' FIELD itab_data-objky. CALL TRANSACTION 'VA33' AND SKIP FIRST SCREEN. WHEN 'ZD00'. "Invoice SET PARAMETER ID 'VF' FIELD itab_data-objky. CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN. WHEN OTHERS. MESSAGE i999(b1) WITH 'Unrecognized Output Type!'. ENDCASE. WHEN 'ITAB_DATA-PARNR'. "Customer number t_kunnr = sy-lisel+39(10). SET PARAMETER ID 'KUN' FIELD itab_data-parnr. CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN. WHEN OTHERS. MESSAGE i999(b1) WITH 'Please click the Doc or Partner #.'. ENDCASE. CLEAR: t_kunnr, t_kschl, field_name. *&---------------------------------------------------------------------* *& Form print_itab_data *&---------------------------------------------------------------------* * Print out ITAB_DATA *----------------------------------------------------------------------* * -->T_ITAB_DATA Internal Table Data *----------------------------------------------------------------------* FORM print_itab_data TABLES t_itab_data STRUCTURE itab_data t_itab_data2 STRUCTURE itab_data2. FORMAT COLOR COL_HEADING. WRITE: / 'App', 5 'Document Number', 35 'Type', 40 'Partner', 51 'Created on', 62 'Created by', 75 'Status'. FORMAT COLOR OFF. LOOP AT t_itab_data. FORMAT COLOR COL_NORMAL. WRITE: /1 t_itab_data-kappl, t_itab_data-objky, t_itab_data-kschl, t_itab_data-parnr, t_itab_data-erdat, t_itab_data-usnam. HIDE: t_itab_data-objky, t_itab_data-parnr.

2008-09

Page 306 of 328

IF t_itab_data-vstat = '0'. "Not processed FORMAT COLOR COL_TOTAL. WRITE: t_itab_data-vstat, 'Not processed'. FORMAT COLOR OFF. ELSEIF t_itab_data-vstat = '1'. "Processed FORMAT COLOR COL_POSITIVE. WRITE: t_itab_data-vstat, 'Processed'. FORMAT COLOR OFF. ELSE. "Incorrectly Processed FORMAT COLOR COL_NEGATIVE. WRITE: t_itab_data-vstat, 'Incorrectly processed'. FORMAT COLOR OFF. ENDIF. IF c_idoc = 'X'. LOOP AT t_itab_data2 WHERE objky = t_itab_data-objky. WRITE:/ t_itab_data2-docnum, t_itab_data2-mestyp. HIDE t_itab_data2-docnum. ENDLOOP. ENDIF. ENDLOOP. ENDFORM. " print_itab_data

6.10.15 ALV Report


REPORT sy-repid. *----------------------------------------------------------------------*/ Description :This program creates an ALV report for Daily Cash * Receipts for a selected date range. *----------------------------------------------------------------------* Global data declaration TYPE-POOLS: slis. * Global structure of list TYPES: BEGIN OF i_cust_invoices, "This is a temp-table where SELECT "data is to be stored. bkpf LIKE bkpf, "Acct Doc Header structure bseg LIKE bseg, "Acct Doc Segment struc kna1 LIKE kna1, "Customer Master struc skat LIKE skat, "Chart of Accts struc END OF i_cust_invoices. TABLES: bkpf, bseg, kna1, skat. "TABLES: def of Database tables.

*/ Selection and Input Parameters SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME. SELECT-OPTIONS: s_belnr FOR bseg-belnr, "Acct Doc number s_budat FOR bkpf-budat, "Doc Posting Date s_blart FOR bkpf-blart DEFAULT 'DZ'. "Document Type SELECTION-SCREEN END OF BLOCK block1.

DATA: gt_fieldcat TYPE slis_t_fieldcat_alv.


DATA: gt_outtab TYPE i_cust_invoices OCCURS 0 WITH HEADER LINE. DATA: g_repid LIKE sy-repid. DATA: i_bkpf TYPE bkpf OCCURS 0 WITH HEADER LINE. * Initialization fieldcatalog INITIALIZATION. g_repid = sy-repid. PERFORM fieldcat_init USING gt_fieldcat[]. * Start of Selection START-OF-SELECTION. * Data selection PERFORM select_data TABLES gt_outtab.

2008-09

Page 307 of 328

* Display list END-OF-SELECTION.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' EXPORTING i_callback_program = g_repid it_fieldcat = gt_fieldcat[] TABLES t_outtab = gt_outtab.
*----------------------------------------------------------------------* Forms *----------------------------------------------------------------------* Initialization fieldcatalog DEFINITION OF HEADING. * Fieldnames and ref_fieldnames MUST be UPPER CASE !! FORM fieldcat_init USING rt_fieldcat TYPE slis_t_fieldcat_alv. DATA: ls_fieldcat TYPE slis_fieldcat_alv. DATA: pos TYPE i VALUE 1. CLEAR ls_fieldcat. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BKPF-BUDAT'. ls_fieldcat-ref_fieldname = 'BUDAT'. ls_fieldcat-ref_tabname = 'BKPF'. ls_fieldcat-key = 'X'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BSEG-BELNR'. ls_fieldcat-ref_fieldname = 'BELNR'. ls_fieldcat-ref_tabname = 'BSEG'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BSEG-HKONT'. ls_fieldcat-ref_fieldname = 'HKONT'. ls_fieldcat-ref_tabname = 'BSEG'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BSEG-KOSTL'. ls_fieldcat-ref_fieldname = 'KOSTL'. ls_fieldcat-ref_tabname = 'BSEG'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'SKAT-TXT20'. ls_fieldcat-ref_fieldname = 'TXT20'. ls_fieldcat-ref_tabname = 'SKAT'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'SKAT-TXT50'. ls_fieldcat-ref_fieldname = 'TXT50'. ls_fieldcat-ref_tabname = 'SKAT'. LS_FIELDCAT-NO_OUT = 'X'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. "Posting Date

"Acct Doc Number

"Acct number

"Cost Center

"Acct Description

"Acct Description

2008-09

Page 308 of 328

* * * * * * *

ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BSEG-AUGBL'. ls_fieldcat-ref_fieldname = 'AUGBL'. ls_fieldcat-ref_tabname = 'BSEG'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BSEG-KUNNR'. ls_fieldcat-ref_fieldname = 'KUNNR'. ls_fieldcat-ref_tabname = 'BSEG'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'KNA1-NAME1'. ls_fieldcat-ref_fieldname = 'NAME1'. ls_fieldcat-ref_tabname = 'KNA1'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BKPF-XBLNR'. ls_fieldcat-ref_fieldname = 'XBLNR'. ls_fieldcat-ref_tabname = 'BKPF'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BSEG-SHKZG'. ls_fieldcat-ref_fieldname = 'SHKZG'. ls_fieldcat-ref_tabname = 'BSEG'. LS_FIELDCAT-NO_OUT = 'X'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BSEG-WRBTR'. ls_fieldcat-ref_fieldname = 'WRBTR'. ls_fieldcat-ref_tabname = 'BSEG'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BKPF-WAERS'. ls_fieldcat-ref_fieldname = 'WAERS'. ls_fieldcat-ref_tabname = 'BKPF'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BKPF-KURSF'. ls_fieldcat-ref_fieldname = 'KURSF'. ls_fieldcat-ref_tabname = 'BKPF'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BSEG-DMBTR'. ls_fieldcat-ref_fieldname = 'DMBTR'. ls_fieldcat-ref_tabname = 'BSEG'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos.

"Clearing Doc

"Cust number

"Customer name

"Ref Doc (Check) Number

"DR/CR ind.

"Amt in Doc Currency

"Currency Key

"Exchange Rate

"Amt in Local Currency

2008-09

Page 309 of 328

ls_fieldcat-fieldname = 'BSEG-GJAHR'. ls_fieldcat-ref_fieldname = 'GJAHR'. ls_fieldcat-ref_tabname = 'BSEG'. LS_FIELDCAT-NO_OUT = 'X'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BSEG-BUZEI'. ls_fieldcat-ref_fieldname = 'BUZEI'. ls_fieldcat-ref_tabname = 'BSEG'. LS_FIELDCAT-NO_OUT = 'X'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BSEG-BSCHL'. ls_fieldcat-ref_fieldname = 'BSCHL'. ls_fieldcat-ref_tabname = 'BSEG'. LS_FIELDCAT-NO_OUT = 'X'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. * * * * * * * * *

"Fiscal Year

"Doc Line #

"Posting Key

Cost Center is not needed for cash posting - only expenses. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BSEG-KOSTL'. ls_fieldcat-ref_fieldname = 'KOSTL'. ls_fieldcat-ref_tabname = 'BSEG'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BKPF-BUKRS'. ls_fieldcat-ref_fieldname = 'BUKRS'. ls_fieldcat-ref_tabname = 'BKPF'. LS_FIELDCAT-NO_OUT = 'X'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BKPF-BLART'. ls_fieldcat-ref_fieldname = 'BLART'. ls_fieldcat-ref_tabname = 'BKPF'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BSEG-SGTXT'. ls_fieldcat-ref_fieldname = 'SGTXT'. ls_fieldcat-ref_tabname = 'BSEG'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. pos = pos + 1. ls_fieldcat-col_pos = pos. ls_fieldcat-fieldname = 'BKPF-USNAM'. ls_fieldcat-ref_fieldname = 'USNAM'. ls_fieldcat-ref_tabname = 'BKPF'. LS_FIELDCAT-NO_OUT = 'X'. APPEND ls_fieldcat TO rt_fieldcat. CLEAR ls_fieldcat. "Cost Center

"Company Code

"Document Type

"Item Text

"User name

ENDFORM. "fieldcat_init

2008-09

Page 310 of 328

* Data selection FORM select_data TABLES rt_outtab LIKE gt_outtab[]. DATA: l_name LIKE tline-tdline. * IF s_hkont IS INITIAL. SELECT bukrs belnr blart budat usnam xblnr waers kursf INTO CORRESPONDING FIELDS OF TABLE i_bkpf FROM bkpf WHERE belnr IN s_belnr AND blart IN s_blart AND budat IN s_budat. LOOP AT i_bkpf. SELECT hkont kostl belnr gjahr buzei bschl shkzg dmbtr wrbtr sgtxt kunnr INTO (bseg-hkont, bseg-kostl, bseg-belnr, bseg-gjahr, bseg-buzei, bseg-bschl, bseg-shkzg, bseg-dmbtr, bseg-wrbtr, bseg-sgtxt, bseg-kunnr) FROM bseg WHERE belnr EQ i_bkpf-belnr. CLEAR: KNA1, skat. SELECT SINGLE * FROM skat WHERE SPRAS EQ SY-LANGU AND KTOPL EQ '7100' AND SAKNR = bseg-hkont. "ska1, skb1 account # stored in SAKNR. "in BSEG, account # stored in HKONT. if bseg-SHKZG eq 'H'. multiply : bseg-wrbtr by -1, bseg-dmbtr by -1. endif. MOVE-CORRESPONDING: i_bkpf TO rt_outtab-bkpf, bseg TO rt_outtab-bseg, skat TO rt_outtab-skat. SELECT SINGLE name1 INTO rt_outtab-kna1-name1 FROM KNA1 WHERE kunnr = rt_outtab-bseg-kunnr. APPEND rt_outtab. CLEAR: rt_outtab. ENDSELECT. ENDLOOP. ENDFORM. " select_data

6.10.16 SAP Generated report \ Dialog Program


REPORT AQA0SYSTQV000005ZMATCOST====== LINE-SIZE 253 NO STANDARD PAGE HEADING LINE-COUNT 000(001). INCLUDE <SYMBOL>. INCLUDE <ICON>. SELECTION-SCREEN: BEGIN OF BLOCK PROG WITH FRAME TITLE TEXT-F58. TABLES MAKT. TABLES T001. TABLES MBEW. DATA %COUNT-MBEW(4) TYPE X. DATA %LINR-MBEW(2). DATA: BEGIN OF %JOINWA, MBEW LIKE MBEW, MAKT LIKE MAKT, END OF %JOINWA. TABLES AQLDB. INCLUDE RSAQEXCD.

2008-09

Page 311 of 328

DATA: BEGIN OF %ST_LISTE OCCURS 100, HEAD(1), TAB(3), LINE(6) TYPE N, CONT(1) TYPE N, FINT(1), FINV(1), FCOL(1) TYPE N, TEXT(0253), END OF %ST_LISTE. DATA %DATA_SELECTED(1). DATA %GLFRAME(1) VALUE 'X' . DATA %UFLAG(1). DATA %USTFLAG(1). DATA %GRST_TEXT(255). DATA %GLLINE TYPE I. DATA %TABIX LIKE SY-TABIX. DATA %PRFLAG(1) TYPE X VALUE '02'. DATA %PERC(4) TYPE P DECIMALS 3. DATA %P100(4) TYPE P DECIMALS 3 VALUE '100.000'. DATA %RANGCT TYPE I. DATA %RANGCC(8). SELECT-OPTIONS SP$00001 FOR MBEW-MATNR MEMORY ID MAT. SELECT-OPTIONS SP$00003 FOR MAKT-MAKTX. SELECTION-SCREEN SKIP 1. SELECTION-SCREEN: BEGIN OF BLOCK DIRECT WITH FRAME TITLE TEXT-F59. SELECTION-SCREEN: BEGIN OF LINE. PARAMETERS: %ALV RADIOBUTTON GROUP FUNC USER-COMMAND OUTBUT DEFAULT 'X' . SELECTION-SCREEN: COMMENT 4(26) TEXT-F72 FOR FIELD %ALV. PARAMETERS: %ALVL TYPE SLIS_VARI. SELECTION-SCREEN: PUSHBUTTON 72(4) PB%EXCO USER-COMMAND EXPCOL. SELECTION-SCREEN: END OF LINE. SELECTION-SCREEN: BEGIN OF LINE. PARAMETERS: %NOFUNC RADIOBUTTON GROUP FUNC MODIF ID OLD. SELECTION-SCREEN: COMMENT 4(26) TEXT-F66 FOR FIELD %NOFUNC MODIF ID OLD. PARAMETERS: %TVIEW RADIOBUTTON GROUP FUNC MODIF ID OLD. SELECTION-SCREEN: COMMENT 34(26) TEXT-F68 FOR FIELD %TVIEW MODIF ID OLD, END OF LINE. SELECTION-SCREEN: BEGIN OF LINE. PARAMETERS: %GRAPH RADIOBUTTON GROUP FUNC MODIF ID OLD. SELECTION-SCREEN: COMMENT 4(26) TEXT-F61 FOR FIELD %GRAPH MODIF ID OLD. PARAMETERS: %TEXT RADIOBUTTON GROUP FUNC MODIF ID OLD. SELECTION-SCREEN: COMMENT 34(26) TEXT-F69 FOR FIELD %TEXT MODIF ID OLD, END OF LINE. SELECTION-SCREEN: BEGIN OF LINE. PARAMETERS: %ABC RADIOBUTTON GROUP FUNC MODIF ID OLD. SELECTION-SCREEN: COMMENT 4(26) TEXT-F70 FOR FIELD %ABC MODIF ID OLD. PARAMETERS: %EXCEL RADIOBUTTON GROUP FUNC MODIF ID OLD. SELECTION-SCREEN: COMMENT 34(26) TEXT-F60 FOR FIELD %EXCEL MODIF ID OLD, END OF LINE. SELECTION-SCREEN: BEGIN OF LINE. PARAMETERS: %EIS RADIOBUTTON GROUP FUNC MODIF ID OLD. SELECTION-SCREEN: COMMENT 4(26) TEXT-F63 FOR FIELD %EIS MODIF ID OLD. SELECTION-SCREEN: END OF LINE. SELECTION-SCREEN: BEGIN OF LINE. PARAMETERS: %XINT RADIOBUTTON GROUP FUNC MODIF ID XIN. SELECTION-SCREEN: COMMENT 4(26) TEXT-F73 FOR FIELD %XINT MODIF ID XIN. PARAMETERS: %XINTK(30) LOWER CASE MODIF ID XIN. SELECTION-SCREEN: END OF LINE. SELECTION-SCREEN: BEGIN OF LINE. PARAMETERS: %DOWN RADIOBUTTON GROUP FUNC MODIF ID OLD. SELECTION-SCREEN: COMMENT 4(26) TEXT-F64 FOR FIELD %DOWN MODIF ID OLD.

2008-09

Page 312 of 328

PARAMETERS: %PATH(132) LOWER CASE MODIF ID OLD. SELECTION-SCREEN: END OF LINE. SELECTION-SCREEN: BEGIN OF LINE. PARAMETERS: %SAVE RADIOBUTTON GROUP FUNC MODIF ID OLD. SELECTION-SCREEN: COMMENT 4(26) TEXT-F62 FOR FIELD %SAVE MODIF ID OLD. PARAMETERS: %LISTID(40) LOWER CASE MODIF ID OLD. SELECTION-SCREEN: END OF LINE. SELECTION-SCREEN: END OF BLOCK DIRECT. SELECTION-SCREEN: END OF BLOCK PROG. DATA: BEGIN OF %G00 OCCURS 100, MBEW-MATNR LIKE MBEW-MATNR, MAKT-MAKTX LIKE MAKT-MAKTX, MBEW-VERPR LIKE MBEW-VERPR, T001-WAERS-0103 LIKE T001-WAERS, MBEW-PEINH LIKE MBEW-PEINH, END OF %G00. DATA: BEGIN OF %%G00, MBEW-MATNR(018), MAKT-MAKTX(040), MBEW-VERPR(015), T001-WAERS-0103 LIKE T001-WAERS, MBEW-PEINH(006), END OF %%G00. DATA %ZNR TYPE I. DATA %LZNR TYPE I VALUE 99999. FIELD-GROUPS HEADER. DATA %GROUP01. DATA %%MAKT-MAKTX LIKE MAKT-MAKTX. DATA %%%MAKT-MAKTX(1). DATA %GROUP0101. FIELD-GROUPS %FG01. DATA %ANY-01. CONTROLS TVIEW100 TYPE TABLEVIEW USING SCREEN 100. AT SELECTION-SCREEN . PERFORM ALVL_CHECK(RSAQEXCE) USING %ALVL 'G00'. PERFORM TESTMODE(RSAQEXCE). PERFORM CHECK_EXPCOL(RSAQEXCE) USING %ALV. AT SELECTION-SCREEN ON VALUE-REQUEST FOR %ALVL . PERFORM ALVL_VALUE_REQUEST(RSAQEXCE) USING %ALVL 'G00'. AT SELECTION-SCREEN ON VALUE-REQUEST FOR %XINTK . PERFORM XINT_VALUE_REQUEST(RSAQEXCE). AT SELECTION-SCREEN OUTPUT . PERFORM RINIT(RSAQBRST). PERFORM SET_EXPCOL(RSAQEXCE) USING %ALV PB%EXCO. PERFORM ALVL_SET_INVISIBLE(RSAQEXCE). PERFORM SET_XINT_PARAMS(RSAQEXCE). INITIALIZATION. PERFORM INIT_XINT(RSAQEXCE). PERFORM SET_WWW_FLAGS(RSAQEXCE). START-OF-SELECTION. INSERT MAKT-MAKTX INTO HEADER. INSERT %COUNT-MBEW INTO HEADER. INSERT %LINR-MBEW INTO HEADER. INSERT MBEW-MATNR INTO %FG01. INSERT MBEW-VERPR INTO %FG01. INSERT T001-WAERS INTO %FG01. INSERT MBEW-PEINH INTO %FG01. PERFORM INIT_TEXTHANDLING(RSAQEXCE) USING 'CL_TEXT_IDENTIFIER' ' ' 'SYSTQV000000000000000002'. PERFORM AUTHORITY_BEGIN(RSAQEXCE). PERFORM AUTHORITY(RSAQEXCE) USING 'MBEW'. PERFORM AUTHORITY(RSAQEXCE) USING 'MAKT'. PERFORM AUTHORITY_END(RSAQEXCE). PERFORM %COMP_LDESC. SELECT MBEW~MATNR MBEW~BWKEY MBEW~BWTAR MBEW~LVORM MBEW~LBKUM

2008-09

Page 313 of 328

MBEW~SALK3 MBEW~VPRSV MBEW~VERPR MBEW~STPRS MBEW~PEINH MBEW~BKLAS MBEW~SALKV MBEW~VMKUM MBEW~VMSAL MBEW~VMVPR MBEW~VMVER MBEW~VMSTP MBEW~VMPEI MBEW~VMBKL MBEW~VMSAV MBEW~VJKUM MBEW~VJSAL MBEW~VJVPR MBEW~VJVER MBEW~VJSTP MBEW~VJPEI MBEW~VJBKL MBEW~VJSAV MBEW~LFGJA MBEW~LFMON MBEW~BWTTY MBEW~STPRV MBEW~LAEPR MBEW~ZKPRS MBEW~ZKDAT MBEW~BWPRS MBEW~BWPRH MBEW~VJBWS MBEW~VJBWH MBEW~VVJSL MBEW~VVJLB MBEW~VVMLB MBEW~VVSAL MBEW~ZPLPR MBEW~ZPLP1 MBEW~ZPLP2 MBEW~ZPLP3 MBEW~ZPLD1 MBEW~ZPLD2 MBEW~ZPLD3 MBEW~PPERZ MBEW~PPERL MBEW~PPERV MBEW~KALKZ MBEW~KALKL MBEW~KALKV MBEW~KALSC MBEW~XLIFO MBEW~MYPOL MBEW~BWPH1 MBEW~BWPS1 MBEW~ABWKZ MBEW~PSTAT MBEW~KALN1 MBEW~KALNR MBEW~BWVA1 MBEW~BWVA2 MBEW~BWVA3 MBEW~VERS1 MBEW~VERS2 MBEW~VERS3 MBEW~HRKFT MBEW~KOSGR MBEW~PPRDZ MBEW~PPRDL MBEW~PPRDV MBEW~PDATZ MBEW~PDATL MBEW~PDATV MBEW~EKALR MBEW~VPLPR MBEW~MLMAA MBEW~MLAST MBEW~LPLPR MBEW~VKSAL MBEW~HKMAT MBEW~SPERW MBEW~KZIWL MBEW~WLINL MBEW~ABCIW MBEW~BWSPA MBEW~LPLPX MBEW~VPLPX MBEW~FPLPX MBEW~LBWST MBEW~VBWST MBEW~FBWST MBEW~EKLAS MBEW~QKLAS MBEW~MTUSE MBEW~MTORG MBEW~OWNPR MBEW~XBEWM MBEW~BWPEI MBEW~MBRUE MBEW~OKLAS MAKT~MATNR MAKT~SPRAS MAKT~MAKTX MAKT~MAKTG INTO (MBEW-MATNR , MBEW-BWKEY , MBEW-BWTAR , MBEW-LVORM , MBEW-LBKUM , MBEW-SALK3 , MBEW-VPRSV , MBEW-VERPR , MBEW-STPRS , MBEW-PEINH , MBEW-BKLAS , MBEW-SALKV , MBEW-VMKUM , MBEW-VMSAL , MBEW-VMVPR , MBEW-VMVER , MBEW-VMSTP , MBEW-VMPEI , MBEW-VMBKL , MBEW-VMSAV , MBEW-VJKUM , MBEW-VJSAL , MBEW-VJVPR , MBEW-VJVER , MBEW-VJSTP , MBEW-VJPEI , MBEW-VJBKL , MBEW-VJSAV , MBEW-LFGJA , MBEW-LFMON , MBEW-BWTTY , MBEW-STPRV , MBEW-LAEPR , MBEW-ZKPRS , MBEW-ZKDAT , MBEW-BWPRS , MBEW-BWPRH , MBEW-VJBWS , MBEW-VJBWH , MBEW-VVJSL , MBEW-VVJLB , MBEW-VVMLB , MBEW-VVSAL , MBEW-ZPLPR , MBEW-ZPLP1 , MBEW-ZPLP2 , MBEW-ZPLP3 , MBEW-ZPLD1 , MBEW-ZPLD2 , MBEW-ZPLD3 , MBEW-PPERZ , MBEW-PPERL , MBEW-PPERV , MBEW-KALKZ , MBEW-KALKL , MBEW-KALKV , MBEW-KALSC , MBEW-XLIFO , MBEW-MYPOL , MBEW-BWPH1 , MBEW-BWPS1 , MBEW-ABWKZ , MBEW-PSTAT , MBEW-KALN1 , MBEW-KALNR , MBEW-BWVA1 , MBEW-BWVA2 , MBEW-BWVA3 , MBEW-VERS1 , MBEW-VERS2 , MBEW-VERS3 , MBEW-HRKFT , MBEW-KOSGR , MBEW-PPRDZ , MBEW-PPRDL , MBEW-PPRDV , MBEW-PDATZ , MBEW-PDATL , MBEW-PDATV , MBEW-EKALR , MBEW-VPLPR , MBEW-MLMAA , MBEW-MLAST , MBEW-LPLPR , MBEW-VKSAL , MBEW-HKMAT , MBEW-SPERW , MBEW-KZIWL , MBEW-WLINL , MBEW-ABCIW , MBEW-BWSPA , MBEW-LPLPX , MBEW-VPLPX , MBEW-FPLPX , MBEW-LBWST , MBEW-VBWST , MBEW-FBWST , MBEW-EKLAS , MBEW-QKLAS , MBEW-MTUSE , MBEW-MTORG , MBEW-OWNPR , MBEW-XBEWM , MBEW-BWPEI , MBEW-MBRUE , MBEW-OKLAS , MAKT-MATNR , MAKT-SPRAS , MAKT-MAKTX , MAKT-MAKTG ) FROM ( MBEW INNER JOIN MAKT ON MAKT~MATNR = MBEW~MATNR ) WHERE MBEW~MATNR IN SP$00001 AND MAKT~MAKTX IN SP$00003. %DBACC = %DBACC - 1. IF %DBACC = 0. STOP. ENDIF. CHECK SP$00003. CHECK SP$00001. ADD 1 TO %COUNT-MBEW. %LINR-MBEW = '01'. EXTRACT %FG01. ENDSELECT. END-OF-SELECTION. SORT AS TEXT BY MAKT-MAKTX %COUNT-MBEW %LINR-MBEW. %DIACT = SPACE. %BATCH = SY-BATCH. IF %BATCH <> SPACE. IF %EIS <> SPACE. %DIACT = 'E'. NEW-PAGE PRINT ON DESTINATION 'NULL' NO DIALOG LINE-SIZE 0253 LINE-COUNT 0065. ENDIF. IF %ALV <> SPACE. %DIACT = 'V'. %ALV_LAYOUT = %ALVL. NEW-PAGE PRINT ON DESTINATION 'NULL' NO DIALOG

2008-09

Page 314 of 328

LINE-SIZE 0253 LINE-COUNT 0065. ENDIF. IF %SAVE <> SPACE. %DIACT = 'S'. NEW-PAGE PRINT ON DESTINATION 'NULL' NO DIALOG LINE-SIZE 0253 LINE-COUNT 0065. ENDIF. ELSEIF %CALLED_BY_WWW <> SPACE. %DIACT = SPACE. ELSEIF %CALLED_BY_WWW_ALV <> SPACE. %DIACT = 'V'. ELSE. IF %SAVE <> SPACE. %DIACT = 'S'. ENDIF. IF %XINT <> SPACE. %DIACT = 'I'. ENDIF. IF %TVIEW <> SPACE. %DIACT = 'T'. ENDIF. IF %ALV <> SPACE. %DIACT = 'V'. ENDIF. IF %DOWN <> SPACE. %DIACT = 'D'. ENDIF. IF %EIS <> SPACE. %DIACT = 'E'. ENDIF. IF %GRAPH <> SPACE. %DIACT = 'G'. ENDIF. IF %EXCEL <> SPACE. %DIACT = 'X'. ENDIF. IF %TEXT <> SPACE. %DIACT = 'W'. ENDIF. IF %ABC <> SPACE. %DIACT = 'A'. ENDIF. IF %DIACT <> SPACE AND %DIACT <> 'S' AND %DIACT <> 'W'. NEW-PAGE PRINT ON DESTINATION 'NULL' NO DIALOG LINE-SIZE 0253 LINE-COUNT 0065. ENDIF. %PATHNAME = %PATH. IF %DIACT = 'I'. %FUNCTIONKEY = %XINTK. ENDIF. IF %DIACT = 'V'. %ALV_LAYOUT = %ALVL. ENDIF. ENDIF. FREE MEMORY ID 'AQLISTDATA'. IF %MEMMODE <> SPACE. IF %BATCH <> SPACE. NEW-PAGE PRINT ON DESTINATION 'NULL' NO DIALOG LINE-SIZE 0253 LINE-COUNT 0065. ENDIF. %DIACT = '1'. ENDIF. %TITEL = ' '. IF SY-SUBTY O %PRFLAG AND %TITEL = SPACE. NEW-PAGE WITH-TITLE. ENDIF. %TVSIZE = 0200. %PLINE = 1. %PZGR = 1. %FIRST = 'X'. PERFORM %OUTPUT. %FIRST = SPACE. IF %DIACT <> SPACE AND %DIACT <> 'S'. NEW-PAGE PRINT OFF. NEW-PAGE NO-HEADING NO-TITLE. WRITE SPACE. ELSE. PERFORM PF-STATUS(RSAQEXCE) USING 'XXX '. ENDIF. CLEAR: %TAB, %LINE, %CONT. IF %DATA_SELECTED = SPACE. IF %DIACT = '1'. EXPORT EMPTY FROM %EMPTY TO MEMORY ID 'AQLISTDATA'. LEAVE. ELSE. IF %BATCH = SPACE AND %CALLED_BY_WWW = SPACE AND %CALLED_BY_WWW_ALV = SPACE. MESSAGE S260(AQ). LEAVE LIST-PROCESSING. ELSE. IF %CALLED_BY_WWW_ALV = SPACE. %DIACT = SPACE. ENDIF. ENDIF. ENDIF.

2008-09

Page 315 of 328

ENDIF. IF %DIACT = 'S'. PERFORM %SAVE_LIST. LEAVE LIST-PROCESSING. ENDIF. IF %DIACT = 'V' AND %BATCH <> SPACE. NEW-PAGE PRINT ON. PERFORM %DOWNLOAD USING 'ALV'. LEAVE. ENDIF. IF %DIACT = 'V' AND %CALLED_BY_WWW_ALV <> SPACE. PERFORM %DOWNLOAD USING 'ALV'. LEAVE. ENDIF. IF %DIACT = 'P' AND %BATCH <> SPACE. PERFORM %DOWNLOAD USING '+DAT'. LEAVE LIST-PROCESSING. ENDIF. IF %DIACT = 'E' AND %BATCH <> SPACE. PERFORM %DOWNLOAD USING 'EIS'. LEAVE LIST-PROCESSING. ENDIF. IF %DIACT = '1'. PERFORM %DOWNLOAD USING '+MEM'. LEAVE. ENDIF. IF %DIACT = 'X'. SET USER-COMMAND 'XXL'. ELSEIF %DIACT = 'W'. SET USER-COMMAND 'TEXT'. ELSEIF %DIACT = 'V'. SET USER-COMMAND 'ALV'. ELSEIF %DIACT = 'T'. SET USER-COMMAND 'VIEW'. ELSEIF %DIACT = 'G'. SET USER-COMMAND 'GRAF'. ELSEIF %DIACT = 'A'. SET USER-COMMAND 'ABCA'. ELSEIF %DIACT = 'E'. SET USER-COMMAND 'EIS'. ELSEIF %DIACT = 'D'. SET USER-COMMAND 'DOWN'. ELSEIF %DIACT = 'I'. SET USER-COMMAND 'XINT'. ELSEIF %DIACT = 'P'. SET USER-COMMAND '+DAT'. ENDIF. TOP-OF-PAGE. PERFORM %TOP-OF-PAGE. END-OF-PAGE. PERFORM PAGE_FOOT(RSAQEXCE). PERFORM %SAVE_PAGE. TOP-OF-PAGE DURING LINE-SELECTION. PERFORM %TOP-OF-PAGE. AT USER-COMMAND. CASE SY-UCOMM. WHEN 'EXIT'. LEAVE. WHEN 'RETN'. PERFORM RETURN(RSAQEXCE). WHEN 'CANC'. PERFORM RETURN(RSAQEXCE). WHEN 'WEIT'. PERFORM RETURN(RSAQEXCE). WHEN 'INHA'. PERFORM CATALOGUE(RSAQEXCE). WHEN 'AUSL'. PERFORM PICKUP(RSAQEXCE). WHEN 'AUSW'. PERFORM PICKUP(RSAQEXCE). WHEN 'RCAA'. PERFORM RCHAIN(RSAQBRST).

2008-09

Page 316 of 328

WHEN 'RCAL'. PERFORM RCALL(RSAQBRST). WHEN 'VGLI'. PERFORM CHANGE(RSAQEXCE). WHEN 'VGLE'. PERFORM CHANGE(RSAQEXCE). WHEN 'TOTO'. PERFORM CHANGE(RSAQEXCE). WHEN 'VSTA'. PERFORM CHANGE(RSAQEXCE). WHEN 'VSTE'. PERFORM RETURN(RSAQEXCE). WHEN 'SAVL'. PERFORM %SAVE_LIST. WHEN 'ODRU'. PERFORM PRINT_LIST(RSAQEXCE). WHEN 'COPA'. PERFORM PRINT_COVER_PAGE(RSAQEXCE). WHEN 'TEXT'. PERFORM %DOWNLOAD USING 'TEXT'. WHEN 'ALV'. PERFORM %DOWNLOAD USING 'ALV'. WHEN 'VIEW'. PERFORM %VIEW. WHEN 'XXL'. PERFORM %DOWNLOAD USING 'XXL'. WHEN 'GRAF'. PERFORM %DOWNLOAD USING 'GRAF'. WHEN 'ABCA'. PERFORM %DOWNLOAD USING 'ABCA'. WHEN 'EIS'. PERFORM %DOWNLOAD USING 'EIS'. WHEN 'DOWN'. PERFORM %DOWNLOAD USING 'DOWN'. WHEN 'XINT'. PERFORM %DOWNLOAD USING 'XINT'. ENDCASE. CLEAR: %CLINE, %ZGR. CLEAR: %TAB, %LINE, %CONT. IF %DIACT <> SPACE. LEAVE LIST-PROCESSING. ENDIF. FORM %COMP_LDESC. REFRESH %LDESC. REFRESH %GDESC. PERFORM LDESC(RSAQEXCE) USING 'G00010000X018 00 98' TEXT-A00 TEXT-B00 TEXT-H00 'MBEW-MATNR' MBEW-MATNR 'MBEW-MATNR'. PERFORM LDESC(RSAQEXCE) USING 'G00020000X040 01 98' TEXT-A01 TEXT-B01 TEXT-H00 'MAKT-MAKTX' MAKT-MAKTX 'MAKT-MAKTX'. PERFORM LDESC(RSAQEXCE) USING 'G00030062 015F 00 98' TEXT-A02 TEXT-B02 TEXT-H00 'MBEW-VERPR' MBEW-VERPR 'MBEW-VERPR'. PERFORM LDESC(RSAQEXCE) USING 'G00040000 005W 00 98' TEXT-A03 TEXT-B03 TEXT-H00 'T001-WAERS' T001-WAERS 'T001-WAERS-0103'. PERFORM LDESC(RSAQEXCE) USING 'G00050084 006 00 98' TEXT-A04 TEXT-B04 TEXT-H00 'MBEW-PEINH' MBEW-PEINH 'MBEW-PEINH'. PERFORM GDESC(RSAQEXCE) USING 'G00' 5 20 ' ' ' ' 'X'. ENDFORM. FORM %OUTPUT. DESCRIBE TABLE %PRLIST LINES %MAX_PRLIST. %HEAD = 'AAA'. %KEYEMPTY = SPACE. NEW-PAGE. PERFORM %OUTPUT_GL. PERFORM COMPLETE_PAGE(RSAQEXCE). %HEAD = 'ZZZ'. PERFORM LAST_PTAB_ENTRY(RSAQEXCE). NEW-PAGE. IF %KEYEMPTY <> SPACE. MESSAGE S894(AQ).

2008-09

Page 317 of 328

ENDIF. ENDFORM. FORM %TOP-OF-PAGE. IF SY-UCOMM = 'INHA'. EXIT. ENDIF. IF SY-UCOMM = 'COPA'. EXIT. ENDIF. IF %HEAD = SPACE. EXIT. ENDIF. IF %HEAD = 'DDD'. PERFORM TVIEWPAGE(RSAQEXCE). EXIT. ENDIF. IF %HEAD = 'GGG'. PERFORM PAGE(RSAQEXCE) USING 'G00' TEXT-GRL 252 %GLFRAME 001. SET LEFT SCROLL-BOUNDARY COLUMN 002. PERFORM SET_SCROLL_BOUNDARY(RSAQEXCE) USING 002. IF %TOTO <> SPACE. EXIT. ENDIF. ELSE. CASE %HEAD. ENDCASE. ENDIF. ENDFORM. FORM %NEWLINE. %UFLAG = SPACE. NEW-LINE. WRITE: '|', 252 '|'. POSITION 2. ENDFORM. FORM %SKIP USING COUNT. IF SY-LINNO > 1. %UFLAG = SPACE. DO COUNT TIMES. NEW-LINE. FORMAT RESET. WRITE: '|', 252 '|'. ENDDO. ENDIF. ENDFORM. FORM %ULINE. IF %UFLAG = SPACE. IF SY-LINNO > 1. ULINE /1(252). ENDIF. %UFLAG = 'X'. ENDIF. ENDFORM. FORM %HIDE. IF %BATCH <> SPACE AND %DIACT = 'S'. PERFORM HIDE(RSAQEXCE). ELSE. HIDE: %TAB, %LINE, %CONT. ENDIF. ENDFORM. FORM %HIDE_COLOR. IF %BATCH <> SPACE AND %DIACT = 'S'. PERFORM HIDE_COLOR(RSAQEXCE). ELSE. HIDE: %FINT, %FCOL.

2008-09

Page 318 of 328

ENDIF. ENDFORM. FORM %RCALL USING NAME VALUE. FIELD-SYMBOLS <FIELD>. ASSIGN (NAME) TO <FIELD>. READ CURRENT LINE FIELD VALUE <FIELD> INTO VALUE. IF SY-SUBRC <> 0. VALUE = SPACE. EXIT. ENDIF. IF VALUE = SPACE AND %TAB = 'G00' AND %LDESC-FCUR NA 'FM'. READ TABLE %G00 INDEX %LINE. IF SY-SUBRC = 0. ASSIGN COMPONENT %LDESC-FNAMEINT OF STRUCTURE %G00 TO <FIELD>. IF SY-SUBRC = 0. WRITE <FIELD> TO VALUE(%LDESC-FOLEN). ENDIF. ENDIF. ENDIF. ENDFORM. FORM %SAVE_PAGE. IF %BATCH <> SPACE AND %DIACT = 'S'. PERFORM SAVE_PAGE(RSAQEXCE) TABLES %ST_LISTE. ENDIF. ENDFORM. FORM %REPLACE_VAR USING TEXT. FIELD-SYMBOLS <VAR>. ASSIGN TEXT+1(*) TO <VAR>. ENDFORM. FORM %SAVE_LIST. DATA: %SFLAG, QREPORT LIKE SY-REPID. IF %DIACT = 'S'. %SFLAG = 'X'. ENDIF. QREPORT = SY-REPID. PERFORM SAVE_LIST(RSAQEXCE) TABLES %ST_LISTE USING QREPORT %SFLAG %LISTID. IF %QL_ID <> SPACE. %DLFLAG = 'X'. %LISTSIZE = 0253. PERFORM COMP_SELECTION_SCREEN(RSAQEXCE). EXPORT %ST_LISTE %PTAB %LDESC %GDESC %DLFLAG %LISTSIZE %SELECTIONS %G00 TO DATABASE AQLDB(AQ) ID %QL_ID. ENDIF. ENDFORM. FORM %REFRESH. CASE %TAB. WHEN 'G00'. IMPORT %G00 FROM DATABASE AQLDB(AQ) ID %QL_ID. ENDCASE. ENDFORM. FORM %DOWNLOAD USING CODE. DATA: QREPORT LIKE SY-REPID.

2008-09

Page 319 of 328

PERFORM INIT_DOWNLOAD(RSAQEXCE). QREPORT = SY-REPID. CASE %TAB. WHEN 'G00'. PERFORM DOWNLOAD(RSAQEXCE) TABLES %G00 USING CODE QREPORT TEXT-GRL. WHEN OTHERS. MESSAGE S860(AQ). ENDCASE. ENDFORM. FORM %SET_DATA CHANGING L_LINES TYPE I. IMPORT LDATA TO %G00 FROM MEMORY ID 'AQLISTDATA'. DESCRIBE TABLE %G00 LINES L_LINES. FREE MEMORY ID 'AQLISTDATA'. ENDFORM. FORM %GET_DATA TABLES DATATAB STRUCTURE %G00 USING FIRST TYPE I LAST TYPE I. APPEND LINES OF %G00 FROM FIRST TO LAST TO DATATAB. ENDFORM. FORM %GET_REF_TO_TABLE USING LID LIKE RSAQLDESC-LID REF_TO_ITAB TYPE REF TO DATA SUBRC LIKE SY-SUBRC. SUBRC = 0. CASE LID. WHEN 'G00'. CREATE DATA REF_TO_ITAB LIKE %G00[]. WHEN OTHERS. SUBRC = 4. MESSAGE S860(AQ). ENDCASE. ENDFORM. FORM %VIEW. DATA: ANZ TYPE I, PROG LIKE SY-REPID. PROG = SY-REPID. PERFORM INIT_DOWNLOAD(RSAQEXCE). CASE %TAB. WHEN 'G00'. PERFORM GENERATE_VIEW_DYNPRO(RSAQEXCE) USING PROG TEXT-GRL. DESCRIBE TABLE %G00 LINES ANZ. TVIEW100-LINES = ANZ. PERFORM INIT_VIEW(RSAQEXCE) TABLES %G00 USING TVIEW100. CALL SCREEN 100. PERFORM RESET_VIEW_DYNPRO(RSAQEXCE). WHEN OTHERS. MESSAGE S860(AQ). ENDCASE. ENDFORM. FORM %OUTPUT_GL. IF %MAX_PRLIST <> 0. READ TABLE %PRLIST WITH KEY TAB = 'GGG'. IF SY-SUBRC <> 0. EXIT. ENDIF. ENDIF. SET MARGIN 00.

2008-09

Page 320 of 328

PERFORM COMPLETE_PAGE(RSAQEXCE). %NOCHANGE = SPACE. NEW-PAGE. %GLLINE = 0. %TAB = 'G00'. %LINE = 0. %CONT = '0'. %FINT = SPACE. %FCOL = '0'. %HEAD = 'GGG'. %CLINE = 0. %OUTFLAG = SPACE. %OUTCOMP = SPACE. %OUTTOTAL = SPACE. %RFLAG = 'AA'. IF %DIACT <> SPACE AND %DIACT NA 'SW'. WRITE SPACE. ENDIF. FORMAT RESET. LOOP. %DATA_SELECTED = 'X'. AT %FG01. %ZNR = '01'. %ZGR = '01'. %CLINE = %CLINE + 1. %G00-MBEW-MATNR = MBEW-MATNR. %G00-MAKT-MAKTX = MAKT-MAKTX. %G00-MBEW-VERPR = MBEW-VERPR. %G00-T001-WAERS-0103 = T001-WAERS. %G00-MBEW-PEINH = MBEW-PEINH. IF %FIRST <> SPACE. APPEND %G00. ENDIF. %GLLINE = %GLLINE + 1. %LZNR = %ZNR. IF %DIACT <> SPACE AND %DIACT NA 'SW'. CONTINUE. ENDIF. PERFORM CHECK(RSAQEXCE) USING ' '. IF %RFLAG = 'E'. EXIT. ENDIF. IF MAKT-MAKTX <> %%MAKT-MAKTX OR %%%MAKT-MAKTX = SPACE. %%MAKT-MAKTX = MAKT-MAKTX. %%%MAKT-MAKTX ='X'. ENDIF. IF %RFLAG(1) = 'A'. FORMAT RESET. %FINT = 'F'. %FCOL = '0'. FORMAT COLOR 2. %FCOL = '2'. PERFORM %NEWLINE. WRITE 002(018) MBEW-MATNR. %LINE = %GLLINE. PERFORM %HIDE. %LINE = 0. PERFORM %HIDE_COLOR. WRITE 021(040) MAKT-MAKTX. WRITE 062(015) MBEW-VERPR CURRENCY T001-WAERS. WRITE 078(005) T001-WAERS. WRITE 084(006) MBEW-PEINH. ENDIF. ENDAT. AT END OF MAKT-MAKTX. %ZGR = '01'. PERFORM CHECK(RSAQEXCE) USING 'X'. IF %RFLAG = 'E'. EXIT. ENDIF. ENDAT. ENDLOOP. %RFLAG = 'AA'. PERFORM %ULINE. CLEAR: %CLINE, %ZGR. ENDFORM.

MODULE %INIT_VIEW OUTPUT. CASE %TAB. WHEN 'G00'. PERFORM INIT_PBO(RSAQEXCE) TABLES %G00 USING TVIEW100 'X'. WHEN OTHERS. MESSAGE S860(AQ).

2008-09

Page 321 of 328

ENDCASE. ENDMODULE. MODULE %PBO_VIEW OUTPUT. CASE %TAB. WHEN 'G00'. PERFORM LOOP_PBO(RSAQEXCE) TABLES %G00 USING %%G00 TVIEW100. ENDCASE. ENDMODULE. MODULE %PAI_VIEW INPUT. CASE %TAB. WHEN 'G00'. PERFORM LOOP_PAI(RSAQEXCE) TABLES %G00 USING %%G00 TVIEW100. ENDCASE. ENDMODULE. MODULE %OKCODE_VIEW INPUT. CASE %TAB. WHEN 'G00'. PERFORM OKCODE(RSAQEXCE) TABLES %G00 USING TVIEW100. ENDCASE. ENDMODULE.

6.10.17 List of transactions report


*----------------------------------------------------------------------* * REPORT Z_TRANSACTIONS *----------------------------------------------------------------------* * TEXT ELEMENTS * ------------* Heading * Transaction code Text * * Selection texts * P_DNLD Download? * P_FILE Filename: * S_SPRSL Language: * S_TCODE Transaction Code: * * Text Symbols * 001 Transaction Selection * 002 Download Option * 003 Filename *----------------------------------------------------------------------* REPORT z_transactions. TABLES: tstct. TYPES: BEGIN OF itab_tx, tcode LIKE tstct-tcode, ttext LIKE tstct-ttext, END OF itab_tx. DATA: itab_tx TYPE itab_tx OCCURS 0 WITH HEADER LINE, tx TYPE itab_tx, itab_file LIKE sval OCCURS 0 WITH HEADER LINE, p_file LIKE rlgrap-filename, returncode LIKE sy-subrc, filestring TYPE string. DATA: BEGIN OF fields OCCURS 2. INCLUDE STRUCTURE sval. DATA: END OF fields. * text-001 = Transaction Selection SELECTION-SCREEN BEGIN OF BLOCK transx WITH FRAME TITLE text-001. SELECT-OPTIONS: s_tcode FOR tstct-tcode, s_sprsl FOR tstct-sprsl. *

2008-09

Page 322 of 328

SELECTION-SCREEN END OF BLOCK transx. * text-002 = Download Option SELECTION-SCREEN BEGIN OF BLOCK dld WITH FRAME TITLE text-002. PARAMETERS: p_dnld TYPE c AS CHECKBOX. SELECTION-SCREEN END OF BLOCK dld. AT SELECTION-SCREEN OUTPUT. p_file = 'C:\SAPTXlist.xls'. p_dnld = 'X'. MOVE 'I' TO s_sprsl-sign. MOVE 'EQ' TO s_sprsl-option. MOVE 'EN' TO s_sprsl-low. APPEND s_sprsl. START-OF-SELECTION. REFRESH itab_tx. SELECT * FROM tstct INTO CORRESPONDING FIELDS OF TABLE itab_tx WHERE tcode IN s_tcode AND sprsl IN s_sprsl. IF sy-subrc <> 0. MESSAGE s265(sf). ELSE. SORT itab_tx BY tcode. LOOP AT itab_tx. WRITE: /1 itab_tx-tcode(20), AT 20 itab_tx-ttext. ENDLOOP. IF p_dnld = 'X'. CLEAR fields. fields-tabname = 'RLGRAP'. fields-fieldname = 'FILENAME'. fields-value = p_file. fields-field_attr = '00'. APPEND fields. CALL FUNCTION 'POPUP_GET_VALUES' EXPORTING popup_title = text-003 IMPORTING returncode = returncode TABLES fields = fields EXCEPTIONS error_in_fields = 1 OTHERS = 2. CHECK returncode EQ space. filestring = fields-value. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = filestring write_field_separator = ',' TABLES data_tab = itab_tx EXCEPTIONS file_write_error =1 no_batch =2 gui_refuse_filetransfer = 3 invalid_type =4 no_authority =5 unknown_error =6 header_not_allowed =7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16

2008-09

Page 323 of 328

disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22. IF sy-subrc <> 0. MESSAGE s999(b1) WITH 'File ' filestring ' NOT created!'. ELSE. MESSAGE s999(b1) WITH 'File ' filestring ' Created successfully!'. ENDIF. "Check on download success ENDIF. "Download ENDIF. "Check on selection

2008-09

Page 324 of 328

CHAPTER 7 BASIS ERRORS AND RESOLUTIONS


7.1 CANNOT ACTIVATE A TABLE
Syntax error in SDCC, table inconsistency between ABAP Dictionary and the database, transport error 8 during the generation of ABAP Dictionary. When you call Transaction SDCC, a termination occurs due to a putative syntax error because a table is not known or active.When you check this with the ABAP dictionary (SE11), you notice, that the table is active or inactive, however it is not possible to activate it.The activation might terminate with the error message 'Inconsistency between ABAP Dictionary and database'.A check of the affected object also delivers this error. Proceed as follows:

Log on as user DDIC Call Transaction SE14 Enter the affected table name and select EDIT In the following screen, choose Table -> Reconstruct Confirm the execution Call Transaction SE11 Enter the affected table name Display Activate

If - after you chose EDIT -, the error message occurs that the table only exists on the database, you need to activate the source and the runtime object.

Call Transaction SE37: -> Function module 'DD_TABL_ACTM' -> Single test Under import parameter MODE, enter the number 12 and under TABNAME the corresponding table name -> Execute (F8) -> Export parameter ACT_RESULT must be 0 Call Transaction SE14 again as described above. -> Extras -> Database object -> Check, as well as -> Extras -> Runtime object -> Check inconsistencies should no longer be contained.
2008-09 Page 325 of 328

If you cannot switch to the EDIT mode in Transaction SE14, which means no modifications are allowed in the customer system, then proceed as follows:

Call function module 'DD_TABL_ACTM' as described above. Then call Transaction SE14 again and verify that the table has been activated. As a result, this ensures that the SDCC can be executed. The menu options in Transaction SE14 are -> Extras -> Database object -> Check, as well as -> Extras -> Runtime object -> Check inconsistencies should no longer be contained. If this is not the case, open a CSN message under the BC-DWB-DIC-ED component.

2008-09

Page 326 of 328

CHAPTER 8 TEAM CONTRIBUTE


8.1 GL
Program name
ZSFGLTMF011 ZTME20N ZTMR_AP_GL_006 /SAPSLL/IF_BADI_IFMAP_CUS_CDOC SAPLZPACKING_STATIONAP ZGTSE_AP_GL_010

RICEF ID
ABA-GL-TM-F011 ABA-GL-TM-E011 ABA-GL-TM-R006 ZGL_GTS_E007 ABA-TS-GL-TME006 ABA-GL-GTS-E010

Owner
Hu Lin WangJin Du Jin MaoZhen YanYin HongShuang

Description System Special Comment


UPS Barcode Sap Control Ocean Manual Shipping Instruction GTS BADI Packing station enhancement Load tariff code ECD301 ECD301 ECD301 GCD301 ECD301 GCD301 UPS Sap Control GTS BADI XML conversion

.txt .doc

.txt

8.2 8.3 8.4 8.5

OF CRM I2 ECOMMERCE I2 PLANNING


Program name
ZRFC_XI_VMI_SA_INPUT

RICEF ID
AP-GP-VMII002 AP-GP-VMII002 AP-GP-VMII002 AP-GP-VMII009 AP-GP-PLI031 AP-GP-PLI030 AP-GP-PLI003

Owner
chenmin

Description
Dwonload Scheduling Agreement Dwonload Scheduling Agreement Dwonload Scheduling Agreement Write back Dispatch list to ECC Download OEM CTO BOM Download order bom for shipped SO download normal bom

System
ECD301

Special Comment
( XI ) ECC RFC ( XI ) ECC RFC ( XI ) ECC RFC BAPI_GOODSMVT_CREATE IM WM BOM BOM , BOM ( )

ZRFC_XI_VMI_SA

chenmin

ECD301

ZRFC_XI_VMI_SA_OUTPUT ZRFC_XI_VMI_DISPATCH_V4 ZRFC_OEM_CTO_BOM ZRFC_TS_SCM_SHIPPED_FPBOM ZRFC_TS_SCM_BOM_NB

chenmin chenmin chenmin chenmin sunkai

ECD301 ECD301 ECD301 ECD301 ECD301

8.6

PE

2008-09

Page 327 of 328

8.7

FI
Program name Owner Description System Special Comment
'BAPI_ACC_DOCUMENT_POST' 'BAPI_ACC_DOCUMENT_POST' tables EXTENSION1 Sap BTE tcode,FIBF ; script from

RICEF ID

AP-SOH-GLF002

ZFII067

CONGAOHJ

Upload FI data from SAP

ECD301

AP-SOH-GLF001 AP-S&D-ARF004

ZFIF001

wangyinghua

Invoice Form

ECD301

ZF150_DUNN_01_1,ZAPF004

con-malh

Dunning letter

ECD301

BTE- -.d _.doc ABAP - .txt .doc oc .txt .txt .tx

8.8

GPDP

2008-09

Page 328 of 328

You might also like