Monday, June 2, 2008

SAP ABAP Decimal Places in Currency

SAP ABAP Decimal Places in Currency

If you wish to find the decimal places in the currency you can use the following function module.

G_DECIMAL_PLACES_GET

The table that stores the Currencies in SAP system (Currency Codes) is TCURC. The code below shows the decimal places for a particular currency.

REPORT ZEX_CURRENCY .

Parameters: p_curr(10).

Data: d_decpl like TCURX-CURRDEC.

CALL FUNCTION 'G_DECIMAL_PLACES_GET'
  EXPORTING
    CURRENCY            = p_curr
 IMPORTING
   DECIMAL_PLACES       = d_decpl .

Write: 'Decimal Places ', d_decpl.


SAP ABAP Select Options

SAP ABAP Select Options Basics

For any ABAP Report or an executable giving the selection criterion is important. Presenting the user with selection screen is very easy using Select-Options and Parameters in SAP ABAP.

The basic for of Select-Options in SAP ABAP is as follows.

Select-options: s_vbeln for vbak-vbeln.


In the above statement s_vbeln is defined as an internal table. And it has the following fields.

           'SIGN:',         s_vbeln-sign,
           'OPTION:',    s_vbeln-option,
           'LOW:',         s_vbeln-low,
           'HIGH:',        s_vbeln-high.
__________________________________________________________

Valid data types of f include all elementary ABAP types except data type f. You cannot use data type f, references, or aggregate types.

We will explore Select Options with the help of a small program shown below.
__________________________________________________________

REPORT ZEX_SELECTOPTIONS.

Tables: VBAK,
             VBAP.

Data: int_vbak type vbak occurs 0 with header line.

Select-options: s_vbeln for vbak-vbeln.

Select * INTO int_VBAK from VBAK where
              VBELN in s_vbeln.
APPEND int_VBAK.
CLEAR int_VBAK.
ENDSELECT.

Loop at s_vbeln.
WRITE: /   'SIGN:',   s_vbeln-sign,
                 'OPTION:', s_vbeln-option,
                 'LOW:',    s_vbeln-low,
                 'HIGH:',   s_vbeln-high.
Endloop.

loop at int_vbak.
Write:/ int_vbak-vbeln, int_vbak-AUART.
endloop.

_______________________________________________________

Once the above program is executed, then the user is presented with a selection screen as shown below.


Sales Order No.                  ___________|          to     ___________        >>

Basically here you can enter the Sales Order Number as follows.

1) Single Entry
2) Range
3) Selected Sales Order Numbers

In case the user enters only a single Sales Order number then only one order gets selected and the output of the code,

Loop at s_vbeln.
WRITE: /   'SIGN:',   s_vbeln-sign,
                 'OPTION:', s_vbeln-option,
                 'LOW:',    s_vbeln-low,
                 'HIGH:',   s_vbeln-high.
Endloop.


is as Follows

SIGN: I OPTION: EQ LOW: 4969 HIGH:
_________________________________________


In case the user enters a range from 4969 to 4977 then the output of the above code is


SIGN: I OPTION: BT LOW: 4969  HIGH: 4977
_______________________________________________

In case the user enters only selected values as 4969, 4970, 4971, 4972 the the output will be as follows.

                                        
SIGN: I OPTION: EQ LOW: 4969       HIGH:
SIGN: I OPTION: EQ LOW: 4970       HIGH:
SIGN: I OPTION: EQ LOW: 4971       HIGH:
SIGN: I OPTION: EQ LOW: 4972       HIGH:
SIGN: I OPTION: EQ LOW: 4973       HIGH:
______________________________________________

Note: The output shown above is for the internal table of select options. The result of the selected Sales Order will be different. You can run the code given above and see the output.





SAP ABAP Views

SAP ABAP Views

Many a times it is required to extract data from several tables this can be a time consuming process. To simplify the process and to increase the efficiency of the code, you can define a VIEW. Data is not stored in a VIEW physically. Here data is combined from several tables, but the data is stored in their respective tables. As the name goes a VIEW is just a VIEW of the selected/desired fields from a number of tables. Fields that are not required are hidden. For example if data needs to be extracted from 5 tables with desired fields, then you can create a VIEW of the required fields.




In SAP ABAP a VIEW can be defined in the following ways.

1) By masking one or more fields from a Table.
2) By Linking tables with a Rational Join Operation
3)
By defining join condition from a foreign key defined between the tables

There are 4 types of view in ABAP

1) Database Views
2) Projection Views
3) Help Views
4) Maintenance Views






SAP ABAP Creating a Material using a BAPI Part 2

SAP ABAP Creating a Material using a BAPI Part 2

In part 1
SAP ABAP Creating a Material using a BAPI Part 1 we have seen how to get the next Material Number. In this Part we will see the parameters that need to be passed for creating the actual Material. For simplicity let us keep the number of parameters to minimum. We will just pass the mandatory fields as per the system that I am using. Please note that you need to pass the Material Number Obtained in the previous Part. Also make sure that you run the following BAPIs in the Order shown below.

To create a Material in SAP using a BAPI you need to use the following 2 BAPIs

BAPI_MATERIAL_GETINTNUMBER
_______________________________________________
Pass the Material Number obtained
from the above BAPI to the following BAPI

_______________________________________________
BAPI_MATERIAL_SAVEDATA
_______________________________________________


Find the code below.

REPORT ZEX_SAVEMATERIAL .

Parameters: p_matype like BAPIMATDOA-MATL_TYPE,
            p_indsr like BAPIMATDOA-IND_SECTOR,
            p_reqnum like BAPIMATALL-REQ_NUMBERS.

Data: d_ret like BAPIRETURN1,
      d_ret2 like BAPIRET2.

Data: int_matnum type BAPIMATINR occurs 0 with header line,
      int_matdesc type BAPI_MAKT occurs 0 with header line.

Data: st_headdata like BAPIMATHEAD,
      st_clientdata like BAPI_MARA,
      st_clientx like BAPI_MARAX.

CALL FUNCTION 'BAPI_MATERIAL_GETINTNUMBER'
     EXPORTING
          MATERIAL_TYPE    = p_matype
          INDUSTRY_SECTOR  = p_indsr
          REQUIRED_NUMBERS = p_reqnum
     IMPORTING
          RETURN           = d_ret
     TABLES
          MATERIAL_NUMBER  = int_matnum.

if sy-subrc = 0.
endif.

loop at int_matnum.
  st_headdata-MATERIAL = int_matnum-MATERIAL.
endloop.

int_matdesc-langu ='E'.
int_matdesc-langu_iso = 'E'.
int_matdesc-matl_desc = 'Material 1'.
append int_matdesc.
clear int_matdesc.

st_headdata-ind_sector = 'C'.
st_headdata-matl_type = 'HAWA'.

st_clientdata-MATL_GROUP = '001'.
st_clientdata-BASE_UOM = 'BT'.
st_clientdata-BASE_UOM_ISO = 'BT'.

st_clientx-MATL_GROUP ='X'.
st_clientx-BASE_UOM = 'X'.
st_clientx-BASE_UOM_ISO = 'X'.


CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
  EXPORTING
    HEADDATA                   = st_headdata
   CLIENTDATA                  = st_clientdata
   CLIENTDATAX                 = st_clientx
*             PLANTDATA                  =
*             PLANTDATAX                 =
*             FORECASTPARAMETERS         =
*             FORECASTPARAMETERSX        =
*             PLANNINGDATA               =
*             PLANNINGDATAX              =
*             STORAGELOCATIONDATA        =
*             STORAGELOCATIONDATAX       =
*             VALUATIONDATA              =
*             VALUATIONDATAX             =
*             WAREHOUSENUMBERDATA        =
*             WAREHOUSENUMBERDATAX       =
*             SALESDATA                  =
*             SALESDATAX                 =
*             STORAGETYPEDATA            =
*             STORAGETYPEDATAX           =
*             FLAG_ONLINE                = ' '
*             FLAG_CAD_CALL              = ' '
*             NO_DEQUEUE                 = ' '
 IMPORTING
   RETURN                     = d_ret2
 TABLES
   MATERIALDESCRIPTION        = int_matdesc
*             UNITSOFMEASURE             =
*             UNITSOFMEASUREX            =
*             INTERNATIONALARTNOS        =
*             MATERIALLONGTEXT           =
*             TAXCLASSIFICATIONS         =
*             RETURNMESSAGES             =
*             PRTDATA                    =
*             PRTDATAX                   =
*             EXTENSIONIN                =
*             EXTENSIONINX               =
          .

If sy-subrc = 0.
Endif.





SAP ABAP Creating a Material using a BAPI Part 1

SAP ABAP Creating a Material using a BAPI

In SAP ABAP you can create a Material using a BAPI. To do so you first need to get the Next Material Number. This can be obtained by using the following BAPI.

To create a Material in SAP using a BAPI you need to use the following 2 BAPIs

BAPI_MATERIAL_GETINTNUMBER
BAPI_MATERIAL_SAVEDATA

If you are suing the transaction MM01 to create a Material, you can see the Material Number being assigned automatically. If you have not noticed this please run the transaction MM01 and enter the values in the initial screen. After hitting enter you will see the Material Number appear in the next screen automatically.

Let us now see the parameters that need to be passed to the BAPI BAPI_MATERIAL_GETINTNUMBER.

The Mandatory Parameters that need to be passed to the BAPI are as follows.

Material Type
Industry Sector
Required Numbers

Enter the desired values and generate the Next Material Number. Once you obtain the Material Number, you then need to pass this number to the following BAPI.

BAPI to create Material in SAP

BAPI_MATERIAL_SAVEDATA

The following program demonstrates the BAPI BAPI_MATERIAL_GETINTNUMBER

REPORT ZEX_GETMATNUM .

Parameters: p_matype like BAPIMATDOA-MATL_TYPE,
            p_indsr like BAPIMATDOA-IND_SECTOR,
            p_reqnum like BAPIMATALL-REQ_NUMBERS.

Data: d_ret like BAPIRETURN1.

Data: int_matnum type BAPIMATINR occurs 0.

CALL FUNCTION 'BAPI_MATERIAL_GETINTNUMBER'
  EXPORTING
    MATERIAL_TYPE          = p_matype
   INDUSTRY_SECTOR         = p_indsr
   REQUIRED_NUMBERS        = p_reqnum
 IMPORTING
   RETURN                  = d_ret
  TABLES
    MATERIAL_NUMBER        = int_matnum
          .

          if sy-subrc = 0.

          endif.

I have used the following Parameters:

Material Type            HAWA
Industry Sector         C
Required Numbers     1

See Also: SAP ABAP Creating a Material using a BAPI Part 2
____________________________________________________________________________________________________________________________________________________________________