SAP AND ABAP TIPS AND FACTS

Monday, March 17, 2008

SAP ABAP Tutorial: Module Pool Programming. Part 3

SAP ABAP Tutorial: Module Pool Programming. Part 3

We will now proceed further and see the code that needs to be put in place to actually create the sales order.

Code for the PBO Module

*&---------------------------------------------------------------------*
*& Module pool       ZSALESORDSCREEN                                   *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*


INCLUDE ZSALESORDERTOP                          .                      "

* INCLUDE ZSALESORDERO01                          .                    *
* INCLUDE ZSALESORDERI01                          .                    *
* INCLUDE ZSALESORDERF01                          .                    *

*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_9000 OUTPUT.
  SET PF-STATUS 'ZSALES'.
  SET TITLEBAR 'ZSL'.

ENDMODULE.                 " STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9000 INPUT.

CASE OK_CODE.

When 'BACK'.
leave to screen 0.

When 'ORDE'.

Perform Create_Salesord.
leave to screen 0.

endcase.

ENDMODULE.                 " USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*&      Form  Create_Salesord
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM Create_Salesord.

*-------------------------Data Declaration-----------------------------*
Data: st_BAPISDHEAD like BAPISDHEAD, " Sales Order Header Data
      ta_BAPIITEMIN like BAPIITEMIN occurs 0 with header line, " Ln item
      ta_BAPIPARTNR like BAPIPARTNR occurs 0 with header line, " Partner
      d_BAPIRETURN1 like BAPIRETURN1,          " Bapi return msg
      d_vbeln like bapivbeln-VBELN.            " Sales Order Number


* Move the data to create sales order in the repective parameters------*
move: txtordtype    to st_BAPISDHEAD-DOC_TYPE,     " Sales document type
      txtpurchord   to st_BAPISDHEAD-PURCH_NO_C,
*      '00010'     to ta_BAPIITEMIN-ITM_NUMBER,
      txtmatno     to ta_BAPIITEMIN-MATERIAL,
*      '1100'      to ta_BAPIITEMIN-PLANT,
      txtqty         to ta_BAPIITEMIN-REQ_QTY,
      'AG'        to ta_BAPIPARTNR-PARTN_ROLE,  " Sold to Party
      txtsoldto   to ta_BAPIPARTNR-PARTN_NUMB.
* Append the internal tables-------------------------------------------*
       append ta_BAPIPARTNR.
       clear ta_BAPIPARTNR.
       append ta_BAPIITEMIN.
       clear ta_BAPIITEMIN.
* Move ship to party---------------------------------------------------*
       move: 'RG'    to ta_BAPIPARTNR-PARTN_ROLE, " Ship to party
             txtshipto   to ta_BAPIPARTNR-PARTN_NUMB.
* Append the internal tables-------------------------------------------*
       append ta_BAPIPARTNR.
       clear ta_BAPIPARTNR.


* Call the Bapi to create the sales order

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
  EXPORTING
    ORDER_HEADER_IN           = st_BAPISDHEAD
*   WITHOUT_COMMIT            = ' '
*   CONVERT_PARVW_AUART        = 'X'
 IMPORTING
   SALESDOCUMENT              = d_vbeln
*   SOLD_TO_PARTY             =
*   SHIP_TO_PARTY             =
*   BILLING_PARTY             =
   RETURN                    = d_BAPIRETURN1
  TABLES
    ORDER_ITEMS_IN            = ta_BAPIITEMIN
    ORDER_PARTNERS            = ta_BAPIPARTNR
*   ORDER_ITEMS_OUT           =
*   ORDER_CFGS_REF            =
*   ORDER_CFGS_INST           =
*   ORDER_CFGS_PART_OF        =
*   ORDER_CFGS_VALUE          =
*   ORDER_CCARD               =
*   ORDER_CFGS_BLOB           =
*   ORDER_SCHEDULE_EX         =
          .

if d_vbeln <> space.
*          Message I001.
*          Message I002 with D_vbeln.
          Message ID 'ZEXERCISE2' TYPE 'S' Number '000'.
*          write: 'Sales order No. ', d_vbeln.
endif.

ENDFORM.                    " Create_Salesord



*&---------------------------------------------------------------------*
*& Include ZSALESORDERTOP                                              *
*&                                                                     *
*&---------------------------------------------------------------------*

PROGRAM  ZSALESORDSCREEN               .

Data: ok_code(4),
      txtordtype(2),
      txtsoldto(10),
      txtshipto(10),
      txtpurchord(10),
      txtmatno(18),
      txtqty(13).

SAP ABAP Tutorial: Module Pool Programming. Part 2

SAP ABAP Tutorial: Module Pool Programming. Part 2

Once the program
'ZSALESORDSCREEN' is created Saved and Activated, run Transaction SE51.

Enter screen number '9000'

Screen numbers can be up to 4 characters long, all of which must be digits. Screen numbers from 9000 are reserved for customer-specific screens.
In the Screen Painter enter a short Description and Activate the screen.

Once this is done you will be presented with a screen that will have three tabs, namely Attributes/Element List/Flow Logic

Click on Element List and type Ok_Code and Activate.

Now click on Flow Logic.

You should see the following code in the Flow Logic.

PROCESS BEFORE OUTPUT.
 MODULE STATUS_9000.

PROCESS AFTER INPUT.
 MODULE USER_COMMAND_9000.

Create
MODULE STATUS_9000 by double clicking on it.  The following code will be automatically created.


INCLUDE ZSALESORDERTOP                          .                      "

* INCLUDE ZSALESORDERO01                        .                    *
* INCLUDE ZSALESORDERI01                          .                    *
* INCLUDE ZSALESORDERF01                          .                    *

*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_9000 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_9000  OUTPUT


Uncomment the following code.

  SET PF-STATUS 'ZSALES'. ------------------ Menu Bar for the custom Sales Order Screen.
  SET TITLEBAR 'ZSL'.       -------------------- Title.


Give appropriate names to PF-STATUS and TITLE BAR. Once the code is uncommented and the appropriate names are given. Double click on the name
ZSALES. Once you see the prompt click on create object.

You will see the following three options in the resulting screen.
                                                                                                           
Menu bar                                     Status for Sales Order Screen                                          
Application toolbar                      Status for Sales Order Screen                                          
Function keys                              Status for Sales Order Screen


Click on the Function Keys Drop Down Box. You will see the Standard Tool Bar with Icons that you normally see in the SAP Screen.
Enter the following values in the empty fields.

Standard Toolbar                                                                                                                             
Ente     SAVE     BACK     EXIT     CANCEL    PRINT     FIND     FINDNEXT   FIRSTPAGE  PREVP     NEXT    LAST

Activate the PF-STATUS.

You will be prompted to enter the Function Text and Info Text for the button Enter.
Please enter the following values.

Function Text   'Ente'
Info Text          'Enter'

Execute Transaction SE80 and Activate the complete program by right clicking on it.

We will now create a transaction code for our program. To create a transaction code right click on the main program and from the pop-up menu select Create-----Transaction.

In the dialog box enter the following values.

Transaction Code     'ZSALESORD'
Short Description     'Create Sales Order'


And Click on Save.
You will now be asked to enter Program name and Screen Number. Enter the following values.

Program         ZSALESORDSCREEN
Screen            9000  

Save and Activate the Program

Now we need to enter code to create the Sales order. We also need to create the Screen Elements.

In transaction SE80 in the left pane click on Screens and then double click on 9000.
Now from the menu click on LAYOUT button.

We need to create Labels and Text Boxes for the following fields.

Filed  (Label Display)          Label Name              TextBox Name         Def Length
Order Type                           lblordtyp                     txtordtyp                               2
Sales Org                             lblsalesorg                  txtsalesorg                            4
Distribution Channel            lbldistchnl                   txtdistchnl                             2
Division                                lbldiv                           txtdiv                                    2
Sold-to Party                        lblsoldto                     txtsoldto                            10
Ship-to Party                        lblshipto                      txtshipto                            10
Purchase Ord                       lblpurchord                 txtpurchord                        10
Material                                lblmat                          txtmat                                18
Quantity                               lblqty                           txtqty                                 13

We also need to create a command button as follows

Label                                 Name
Create Order                     lblcreateord


We will now look at the property box which is displayed after double clicking on each screen element.

Order Type (Label)
                   Name                  lblordtyp
                   Text                    Order_Type
                 

Order Type (Text Box)
                   Name                  txtordtyp
                   Text                   
                   Def. Length         2


Similarly fill the Property box for other fileds

Important

Property Box for Command Button in this case the Function Code is important

Create Order  
                           Name                  cmdord
                           Text                    Create Order           
                           Fct Code             ORDE
        

SAP ABAP Tutorial: Module Pool Programming. Part 3                                                                                        

SAP ABAP Module Pool Programming Tutorial Part 1

SAP ABAP Tutorial: Module Pool Programming. Part 1

Related Transaction Codes:

SE51: Screen Painter Initial Screen
SE41: Menu Painter Initial Screen
SE38: ABAP Editor Initial Screen
SE80: Object Navigator


In this tutorial we will explore module pool programming. We will create a sales order.
We will combine the Initial screen and the Overview Screen of Transaction VA01 Create Standard Order into one screen.

We will use the following BAPI to create the Sales Order

BAPI_SALESORDER_CREATEFROMDAT1

The following fields will be updated.

Order Type                              OR
Sales Org                                1000
Dsitribution Channel                10
Division                                    00


Sold-to Party                               7777
Ship-to Party                               7777
Purch Ord No                              15493
Material                                       y-351
Order Quantity                             10

We will now proceed and create the main program.
Run Transaction SE80 and create a program 'ZSALESORDSCREEN'. First just create this program save and activate.

To do so in the dropdown box select Program and type the name
'ZSALESORDSCREEN' in the filed below and hit enter.
You will see a prompt that says 'Program does not exist' do you want to create a new object?

Say yes.
Create a program with TOPINCLUDE, give an appropriate name to the TOPINCLUDE and save the program.

See
SAP ABAP Tutorial: Module Pool Programming. Part 2



ABAP TIPS

PREVIOUS                  NEXT                    RANDOM

 ABAP TIPS


Since your web browser does not support JavaScript, here is a non-JavaScript version of the image slideshow:

 ABAP TIPS
Always specify your conditions in the Where-clause instead of checking them yourself with check statements. The database system can then use an index (if possible) and the network load is considerably less.


 ABAP TIPS
For all frequently used Select statements, try to use an index. You always use an index if you specify (a generic part of) the index fields concatenated with logical Ands in the Select statement's Where clause. Note that complex Where clauses are poison for the statement optimizer in any database system.


 ABAP TIPS
If there exists at least one row of a database table or view with a certain condition, use the Select Single statement instead of a Select-Endselect-loop. Select Single requires one communication with the database system, whereas Select-Endselect needs two.


 ABAP TIPS
It is always faster to use the Into Table version of a Select statement than to use Append statements.


 ABAP TIPS
To read data from several logically connected tables use a join instead of nested Select statements. Network load is considerably less.


 ABAP TIPS
If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself. Network load is considerably less.


 ABAP TIPS
If you process your data only once, use a Select-Endselect-loop instead of collecting data in an internal table with Select Into Table. Internal table handling takes up much more space.


 ABAP TIPS
Use a select list or a view instead of Select * , if you are only interested in specific columns of the table. Network load is considerably less.


 ABAP TIPS
For all frequently used, read-only tables, try to use SAP buffering. Network load is considerably less.


 ABAP TIPS
Whenever possible, use array operations instead of single-row operations to modify your database tables. Frequent communication between the application program and database system produces considerable overhead.


 ABAP TIPS
Whenever possible, use column updates instead of single-row updates to update your database tables. Network load is considerably less.


 ABAP TIPS
Instead of using nested Select loops or FOR ALL ENTRIES it is often possible to use subqueries. Network load is considerably less.


 ABAP TIPS
Use the special operators CO, CA, CS, instead of programming the operations yourself. If ABAP/4 statements are executed per character on long strings, CPU consumption can rise substantially.


 ABAP TIPS
Some function modules for string manipulation have become obsolete and should be replaced by ABAP/4 statements or functions: STRING_CONCATENATE... -> CONCATENATE, STRING_SPLIT... -> SPLIT, STRING_LENGTH -> strlen(), STRING_CENTER -> WRITE...TO...CENTERED, STRING_MOVE_RIGHT -> WRITE...TO...RIGHT-JUSTIFIED


 ABAP TIPS
Use the CONCATENATE statement instead of programming a string concatenation of your own.


 ABAP TIPS
If you want to delete the leading spaces in a string, use the ABAP/4 statement SHIFT...LEFT DELETING LEADING... .Other constructions (with CN and SHIFT...BY SY-FDPOS PLACES, with CONDENSE if possible, with CN and ASSIGN CLA+SY-FDPOS(LEN) ...) are not as fast. In any case, avoid using SHIFT inside a WHILE-loop!


 ABAP TIPS
Use the SPLIT statement instead of programming a string split yourself.


 ABAP TIPS
Use the strlen( ) function to restrict the DO loop to the relevant part of the field, e.g. when determinating a check-sum.


 ABAP TIPS
Use "CLEAR f WITH val" whenever you want to initialize a field with a value different from the field's type-specific initial value.


 ABAP TIPS
Try to keep the table ordered and use binary search or used a table of type SORTED TABLE. If TAB has n entries, linear search runs in O( n ) time, whereas binary search takes only O( log2( n ) ).


 ABAP TIPS
A dynamic key access is slower than a static one, since the key specification must be evaluated at runtime. However, for large tables the costs are dominated by number of comparison needed to locate the entry.


 ABAP TIPS
If you need to access an internal table with different keys repeatedly, keep your own secondary indices.With a secondary index, you can replace a linear search with a binary search plus an index access.


 ABAP TIPS
LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE evaluates the specified condition internally. As with any logical expressions, the performance is better if the operands of a comparison share a common type. The performance can be further enhanced if LOOP ... WHERE is combined with FROM i1 and/or TO i2, if possible.


Always use Pretty Printer and Extended Program Check before releasing the code. Do not leave unused code in the program. Comment the code thoroughly. Align the comments and the Code. Follow the SAP Standards and SAP Best Practices guidelines. It’s a good practice to take a dump of the code on your local drive.

Ole Automation Part1
Ole Automation Part 2
Processing Blocks in ABAP
Simple ABAP Report
ALV Grid - Changing Colors
ALV Report Example
Creating Variants For ABAP Reports
Recording BDC using Transaction
Sales Document Flow in ABAP
User Exits in SAP SD
SAP ABAP Naming Standards
SAP SD Tables
SAP ABAP Data Dictionary Tables
MM Important Transaction Codes in SAP
Passing g Data From One ABAP Program to Another
ABAP Compute Add Collect and Append
SAP ABAP Determining Attributes of Data
SAP ABAP Editor Icons
BAPI for Displaying Material Data
BAPI to get customer bank details
EDI Outbound Process
SAP EDI Process Overview
Function Module for Vendor Bank details
SAP IDOC
Creating a Valid Password in SAP
SAP BADIs Introduction
SAP ABAP MACROS
POP UP function Module to Confirm and Save Data
Select Options
BAPI for availability check
String to Numerical
SAP Goods Movement Process
Getting a List of Plants for a Material
SAP R3 Clients Concept
ABAP Adobe Forms
Authorization Object Tables
SAP Industry Specific Solutions

Sap Scripts and SmartForms Bar Codes
Standard Reports and Sap Scripts
Important Standard Reports in SAP
Abap Tricks and Tips
Bapi Sales Order
BAPI Purchase Order
Creating Function Modules in SAP
Creating Tables in SAP
Finding User Exits in SAP
Function Module Create Text and Read Text
Important Transaction Codes in SAP
ABAP Function Module for Submitting a Program
ABAP Game Tic Tac Toe
ABAP Internal Table To Excel Sheet
ABAP Function Module to create Directory
Different Types of Menus in SAP
Function Modules in SAP to check Loged in Users
ABAP Function Module for Adding Days to Dates
Call a Transaction From a Remote System
SAP MM simple Procurement Cycle
BAPI Material EDIT
Finding Decimal Places in Currency
Getting negative sign before a number in ABAP
Program Editor Lock Unlock
Restricting Select Options
List of BAPIs in the system
SAP Function Module Scramble a String
LSMW
POP up table contents on the screen
SAP R3 Bookmarking Websites
Stock Requirements List Function Module
Retail Transaction Codes
ABAP Debugger Break Points
ABAP Debugger WatchPoints
Drill Down Reports Concept
Creating a HOT SPOT
Interactive Programs and Hide Technique
String Concatenate
Get Week of the Year
SAP ABAP to Add Days to a Date
Add Months to a Date
Get Month in the Year
Display Clock

ABAP Code For Progress BAR
ABAP Function Module For Caluclator
ABAP Function Module For Calender
Displaying Messages in ABAP
Function Module Pop Up To Confirm
Conversion Routines in SAP
SAP ABAP Authorization
SAP ABAP Module Pool Tutorial
SAP ABAP RFC

Finding Path to SAP Transaction in Menu
SAP Purchasing Documents
SAP and ABAP Shortcuts
Logical Databases
Advantages of Logical Databases
Copy to Clipboard
BAPI Create Material
Finding and Running Programs in ABAP
Program Syntax Check and Extended Syntax Check
Select Options upper lower case
BAPI Sales Order Simulate
Get PLANT and Description for a Material
MRP List Function Module
Production Planning and Controlling
Applications in SAP R3
Tool Based Reports
Important Transaction Codes in SAP
SAP Stock per Bin
Pop Up a Calender
Module to Read a File
Module to Reverse A String
Run an Executable Program with Parameters
Program for POP up Screen
Printing Selection Parameters for a Report
Uploading and DownLoading a Report
SAP ABAP Version Management
SAP ABAP Short Cuts
List of Important System Variables

ABAP MACROS
ABAP Calling a File Selector
Some Important Function Modules
ABAP String Operations

ABAP Function Module to Check Validity of Date
Transfer Internal Table Contents to a File

SAP ABAP Program Types
BAPI to Read Customer Data
Checking Validity of Date
Download to Application Server
ABAP Debugger Breakpoint and Watchpoint
BAPI to get Company Code Details
Creating Material Using BAPI part 2
Generating a Valid Password
Logical Databases Structure
Making Fields OBligatory in Selection Screen
ABAP Views
Getting a Company Code for a Plant
Importing contents of Clipboard in SAP
Getting a Plant for a Material
Plant Material and Storage Location
SAP Production Planning Standard Reports
NetWeaver Components
Supported Databases and Operating Systems