Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all 935 articles
Browse latest View live

Document to demonstrate only one instance of active job is running for a single Job

$
0
0

Hi,

 

Please go through below to know how to keep only one instance of batch job active.

 

Requirement :

Keep only one instance of active job is running for a single Job

 

Solution:

SAP  provided a standard program to handle this scenario. The program name is RSBTONEJOB2.


Please find the below steps :-


1. Create a variant for the program which you want to schedule the batch job.


2. Create a variant for  RSBTONEJOB2 with job name , report name and variant. I create the variant 'DEMO_VARIANT'.

   

   

 

   

 

3. Go to SM36, create a job with same name give in variant of RSBTONEJOB2 .

 

    

 

4. Click on step, enter abap program name RSBTONEJOB2 and variant DEMO_VARIANT. Start the job immediately and save.

 

   

 

5. Go to SM37 and you can see the job ZDEMO_KEEP_ONE_ACTIVE_INSTANCE will be in active status.

 

6. Copy the job and release it. The second job will be finished with below job log.

 

   

 

7. The log of first job

 

   

 

This scenario is been asked number of times in SCN. Hope this helps to fellow SCN member.

Therefore I request all SAP folks to share there comments and add something i missed here.

 

Thanks

-Always Learner


Create confirmations entries with a Badi / me21n / me22n / me23n

$
0
0

Create confirmations entries with a Badi

I got the problem that I have to add a line for confirmation to migrated purchase order. So if you want to try this, you need a PO. Let us assume you got a PO (EL00000001) with one position (0010). As you can see there is no confirmation. We used material 990003038 and the standard plant 1000.

 

po1.png

 

Now, lets have a look into transaction MD04, using material 990003038 and the plant 1000. You should see something like this.

po2.png

Now we want to add the confirmation. If you add it by hand:

po3.png

 

ATTENTION: In this tutorial a table will be updated with the MODIFY command. Please stop here if the command is not clear and read this. You may damage the system if you do something wrong.

 

First of all I’ll present you the tables we need.

EKKO – EinKauf KOpf – Header PO (yes, German is my mother tongue)

EKPO – EinKauf POsition – Position PO

EKES - Vendor Confirmations

EKET - Scheduling Agreement Schedule Lines

 

First I’ll create another PO (EL00000002) with the same position (0010).

 

 

So here is the program I used:

  1. DATA:  lt_uekes    TYPETABLE OF uekes,
  2.       ls_uekes    LIKELINE OF  lt_uekes,
  3.       lt_uekes_out TYPETABLE OF uekes,
  4.       lv_etens    TYPE          etens.
  5. DATA: lv_date TYPE eindt.
  6. DATA: lv_ebelp TYPE ebelp VALUE'10'.
  7. DATA: lv_ebeln TYPE ebeln VALUE'EL00000002'.
  8. DATA: lv_xblnr TYPE ekes-xblnr VALUE'REFERENCE'.
  9. DATA: lv_data_char10 TYPE char10 VALUE'01.07.2015'.
  10. DATA: lv_menge TYPE bbmng VALUE'5'.
  11. DATA: lv_ekpomeins TYPE bstme VALUE'PC'.
  12. DATA: ls_return TYPE bapiret2.
  13. DATA: ls_eket TYPE eket.
  14. DATA: lt_eket TYPESTANDARD TABLE OF eket.
  15. "Just make sure the the format is right.
  16. CALL FUNCTION'CONVERSION_EXIT_ALPHA_INPUT'
  17.   EXPORTING
  18.     input  = lv_ebeln
  19.   IMPORTING
  20.     output= lv_ebeln.
  21. CALL FUNCTION'CONVERSION_EXIT_ALPHA_INPUT'
  22.   EXPORTING
  23.     input  = lv_ebelp
  24.   IMPORTING
  25.     output= lv_ebelp.
  26. "Change the date to internal format
  27. CALL FUNCTION'CONVERT_DATE_TO_INTERNAL'
  28.   EXPORTING
  29.     date_external            = lv_data_char10
  30.   IMPORTING
  31.     date_internal            = lv_date
  32.   EXCEPTIONS
  33.     date_external_is_invalid =1
  34.     OTHERS                  =2.
  35. IF sy-subrc <>0.
  36. * Implement suitable error handling here
  37. ENDIF.
  38. "Check if there is already a ekes entry. If so you have to increase ETENS by one.
  39. "ETENS is an incremental counter in the table.
  40. SELECTMAX( etens )INTO lv_etens
  41.   FROM ekes
  42.   WHERE ebeln = lv_ebeln
  43.     AND ebelp = lv_ebelp.
  44. IF sy-subrc =0AND lv_etens <>0.
  45.   ADD1TO lv_etens.
  46. ENDIF.
  47. ls_uekes-ebeln    = lv_ebeln.        "Purchase order number you want to update 'EL00000002'
  48. ls_uekes-ebelp    = lv_ebelp.        "Position you want to update '00010' --> beware 5 digits
  49. ls_uekes-etens    = lv_etens.        "Counter in EKES
  50. ls_uekes-ebtyp    ='AB'.            "Short form of the confirm category
  51. ls_uekes-xblnr    = lv_xblnr.        "The referenc sting
  52. ls_uekes-eindt    = lv_date.        "Delivery date of the confirmation
  53. ls_uekes-menge    = lv_menge.        "Quantety of the confirmation
  54. ls_uekes-ekpomeins = lv_ekpomeins.    "ISO UNIT
  55. ls_uekes-lpein    ='1'.
  56. ls_uekes-erdat    = sy-datum.        "Date when it was added
  57. ls_uekes-ezeit    = sy-uzeit.        "time when it was added
  58. ls_uekes-estkz    ='1'.
  59. ls_uekes-kzdis    = abap_true.
  60. ls_uekes-kz        ='I'.            "I is for Insert, U for Update
  61. APPEND ls_uekes TO lt_uekes.
  62. CALL FUNCTION'ME_CONFIRMATION_UPDATE'
  63.   EXPORTING
  64.     i_ebeln = lv_ebeln                "Purchase order number is the key for the FuMo(FUBA)
  65.   TABLES
  66.     xekes  = lt_uekes.
  67. IF sy-subrc =0.
  68.   "You have to call the commit, because you want to find an EKET entry
  69.   "I you don't do this the next select will fail
  70.   CALL FUNCTION'BAPI_TRANSACTION_COMMIT'
  71.     EXPORTING
  72.       wait  ='X'
  73.     IMPORTING
  74.       return= ls_return.
  75. ENDIF.
  76. "Okay now EKES is ready, but the will be no update to md04 if you dont update EKET.
  77. "I couldn't find a FuMo(FUBA) which will do the update for me.
  78. "If somebody got a better solution please mail me nikolaus.harrich@cnt-online.at
  79. "But beware and think about what you do here.
  80. SELECTSINGLE*
  81.   FROM eket
  82.   INTO ls_eket
  83.   WHERE ebeln  = lv_ebeln AND
  84.         ebelp  = lv_ebelp.
  85. ls_eket-dabmg = lv_menge.
  86. APPEND ls_eket TO lt_eket.
  87. MODIFY eket FROM TABLE lt_eket.
  88. IF sy-subrc =0.
  89.   CALL FUNCTION'BAPI_TRANSACTION_COMMIT'
  90.     EXPORTING
  91.       wait  ='X'
  92.     IMPORTING
  93.       return= ls_return.
  94. ENDIF.

Add line items automatically in VA01 - Sales Order Create

$
0
0

Add a line item automatically when a user clicks on save to sales order in VA01

 

 

Limitations:

 

There is a long list of user-exits present in SD module that facilitate customization to the standard process. However, no User exits , Customer Exits or BADI's have been provided which can add an item automatically to Sales Order.

 

 

Expectations:

 

To add an item manually in a SO the only input required from the user is the material number and quantity. Rest all the information is determined automatically by the standard code.The automatic addition of item should take care of below points.

 

      • The only required input should be material number and quantity.
      • Item number ( VBAP-POSNR ) should be auto determined.
      • Item category and other item details should be read from master data / configuration tables.
      • Schedule line data to be determined as for a normal manually added item.
      • Pricing should be determined automatically.
      • Any code written in user exits should be triggered for this item as well.

 

Approach Followed:


We will be using  USEREXIT_MOVE_FIELD_TO_VBAK to write our code. This userexit is present in include MV45AFZZ of program SAPMV45A.

 

This user exit is used to transfer some fields to the sales order header.However , we will write our code in this exit to add an item during save.

 

Code:

 

*--Check if the user has pressed SAVE button

IF sy-ucomm EQ 'SICH'.

 

*--Read table XVBAP to check if the material is not already added

 

           READ TABLE xvbap INTO ls_xvbap WITH KEY matnr = 000000000000240000

                                                     updkz = 'I'.

           IF sy-subrc NE 0.

 

             CLEAR: vbap.

 

*--Initialize workareas for VBAP and VBEP


             PERFORM vbap_unterlegen(sapfv45p).

 

             PERFORM vbep_unterlegen(sapfv45e).

 

*--Populate material number and quantity

 

             vbap-matnr     = ‘000000000000240000’.

             rv45a-kwmeng   = 1000.

 

*--Call standard performs to populate material details.

*--Perform for material validations and details

             PERFORM vbap-matnr_pruefen(sapfv45p) USING charx sy-subrc.

 

*--Perform for item category determination. This will take care of substitution items if any for this material.

             PERFORM vbap-pstyv_pruefen(sapfv45p).

 

*--Perform for filling VBAP with default values from configuration and master tables

             PERFORM vbap_fuellen(sapfv45p).

 

             PERFORM vbap-matnr_null_pruefen(sapfv45p).

             PERFORM vbep-wmeng_setzen(sapfv45e).

 

*--Perform to check sales unit

             PERFORM vbap-vrkme_pruefen(sapfv45p) USING charx

                   CHANGING sy-subrc sy-msgid sy-msgty sy-msgno

                            sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

 

*--Perform to update VBAP values

             PERFORM vbap_bearbeiten(sapfv45p).

 

*--Perform for filling VBEP with default values. This will take care of schedule lines of the item

             PERFORM vbep_fuellen(sapfv45e).

 

*--Perform to check quantity

             PERFORM vbep-wmeng_pruefen(sapfv45e) USING charx

                   CHANGING sy-subrc sy-msgid sy-msgty sy-msgno

                            sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

 

*--Perform to update VBEP values

             PERFORM vbep_bearbeiten(sapfv45e).

 

*--Perform to fill conditions and pricing data

             PERFORM vbap_bearbeiten_ende(sapfv45p).

 

           ENDIF.

         ENDIF.

 

 

 

Execution Snapshots:

 

 

Go to VA01 to create a sales order. Enter sold to party and other details. Add 1 item manually.

 

1.png

 

Click on save, item 240000 should be item as next item ( POSNR 20 ).


2.png

Check the SO in VA03. Here the item 20 is added successfully.


3.png



Check line item schedule line data:


4.png

 

Check Pricing data:

 

5.png

 

Thus , we see in this way a line item can be added automatically in the sales order.

 

Advantages:

 

  • The item addition can be done on the basis of certain conditions and multiple items can be added by placing this code in a loop.
  • Since all standard performs are called to fill the data , even the different user-exits for item will be triggered if implemented for the item.
  • By adding a check for call_bapi equal to 'X' and TRTYP eq 'H' , this code can be executed from Create Sales Order BAPI also.
  • Item number is determined automatically.
  • Item category , item substitution, scheduling , availability check and pricing is done by standard performs.
  • If the requirement is to add items just as the user enters the header details, that can be done with minimum code changes.

 

Use Cases:

 

This can be used in certain business scenarios like:

 

  • Suppose based on the customer some free items need to be added to sales order. In such case the item ( material ) and customer combination can be stored in a custom table. It can be then read from and populated automatically.

 

  • It can also be used if some default material has to be added to all sales orders being created.

 

Note:

 

Sensitive data has been blurred in the snapshots.

 

Feel free to provide feedback and valuable comments.

 

~ Tanmay

Deriving the Translation Date from Document Date – Step by Step

$
0
0

The SAP folks working in SAP FI must be familiar with this concept. Just to give a brief introduction, Translation date is a date which is used to convert the foreign currency to local currency. Since the exchange rate is picked based on the translation date, it is a very critical date component. In standard SAP, translation date is automatically derived from posting date.

 

This document will walk you through the step by step procedure of deriving the translation date automatically from document date.

 

Before going any further, let us make a few terminologies clear:

BUDAT: Posting Date (date when document is posted)

BLDAT: Document Date/Invoice Date (date when document is entered/parked)

WWERT: Translation Date (date used to pick the exchange rates)

 

This change of date can be realized by implementation of a BADI FI_TRANS_DRIVE_WWERT. This BADI is called by function module FI_DERIVE_WWERT. Following is the step by step procedure for the same.

 

  1. Go to T-Code SE19, in the “create implementation” part and give the BADI’s name:-

Pic1.jpg

 

     2. Then, the following dialog box appears, enter the implementation name:-

pic2.jpg

     3. In the next screen, give the short description.

pic3.jpg

         4. Go to the interface tab and enter the name of the implementing class. (ZCL_IM_DERIVE_WWERT_BUDAT in this case). This will be a Z class that                will implement that interface IF_EX_FI_TRANS_DATE_DERIVE which has one method: DERIVE_WWERT.

pic4.jpg

Here, double click on the DERIVE_WWERT method and the following editor will open where you can write your piece of code.

pic5.jpg

As per this case, the code can be like the following:-

METHOD if_ex_fi_trans_date_derive~derive_wwert.
e_wwert
= i_bldat.
ENDMETHOD.

 

     5. Save the code and activate it. Save and activate the BADI implementation as well.

     6. Now is the time to test this. For this go to FV60/65 and enter an invoice. After enter the header details, go to the “Local Currency” tab and check the                  translation date. It should be same as the document date.

             pic6.jpgpic7.jpg

Hope it was useful. Please feel free to share your questions or comments if any.

Thanks,

Arashdeep

Abap 7.40 improvements example code compilation

$
0
0

You can check abap changes that comes with 7.40 release from Horst Keller 's blog ABAP Language News for Release 7.40

 

And below you can find example code compilation for your own try.

 

***********************************

 

REPORT zabap740.


***************
* Expressions *
***************

************************************
* Expressions->Inline Declarations *
************************************

**Data declaration
**Before 7.40
*DATA text TYPE string.
*text = 'Example Text'.
*cl_demo_output=>display( text ).
*
**With 7.40
*DATA(text740) = 'Example Text 740'.
*cl_demo_output=>display( text740 ).



**Declaration of table
*TYPES: BEGIN OF t_struct1,
*         col1 TYPE i,
*         col2 TYPE string,
*       END OF t_struct1,
*       t_itab TYPE TABLE OF t_struct1 WITH EMPTY KEY.
*
**Before 7.40
*DATA: itab TYPE t_itab,
*      wa   LIKE LINE OF itab.
*wa-col1 = 1. wa-col2 = 'B1'.
*APPEND wa TO itab.
*wa-col1 = 2. wa-col2 = 'B2'.
*APPEND wa TO itab.
*cl_demo_output=>display( itab ).
*
**With 7.40
*DATA(itab740) =
*  NEW t_itab( ( col1 = 1 col2 = 'B1' )
*              ( col1 = 2 col2 = 'B2' ) ).
*cl_demo_output=>display( itab ).
*
*TYPES typ_itab TYPE TABLE OF i WITH EMPTY KEY.
*DATA(itabt) = VALUE typ_itab( ( 1 ) ( 2 ) ( 3 ) ).
*cl_demo_output=>display( itabt ).

**Declaration of table work areas
*DATA: itab TYPE TABLE OF mara.
*SELECT *
*UP TO 1 ROWS
*INTO TABLE itab
*FROM mara.
*
**Before 7.40
*DATA wa LIKE LINE OF itab.
*LOOP AT itab INTO wa.
*  cl_demo_output=>display( wa ).
*ENDLOOP.
*
**With 7.40
*LOOP AT itab INTO DATA(wa740).
*  cl_demo_output=>display( wa740-matnr ).
*ENDLOOP.


**Declaration of a helper variable
**Before 7.40
*DATA cnt TYPE i.
*FIND 'O' IN 'OZGUR' MATCH COUNT cnt.
*cl_demo_output=>display( cnt ).
*
**With 7.40
*FIND 'O' IN 'OZGUR' MATCH COUNT DATA(cnt740).
*cl_demo_output=>display( cnt740 ).


**Declaration of a result
**Before 7.40
*DATA res TYPE numc4.
*CALL METHOD cl_lib_string_tab=>version
*  RECEIVING
*    rv_version = res.
*cl_demo_output=>display( res ).
*
**With 7.40
*CALL METHOD cl_lib_string_tab=>version
*  RECEIVING
*    rv_version = DATA(res740).
*cl_demo_output=>display( res740 ).

**Declaration of actual parameters
**Before 7.40
*DATA vers TYPE numc4.
*cl_lib_string_tab=>version( RECEIVING rv_version = vers ).
*cl_demo_output=>display( vers ).
*
**With 7.40
*cl_lib_string_tab=>version( RECEIVING rv_version = DATA(vers740) ).
*cl_demo_output=>display( vers740 ).




**Declaration of reference variables for factory methods
**Before 7.40
*DATA ixml           TYPE REF TO if_ixml.
*DATA stream_factory TYPE REF TO if_ixml_stream_factory.
*DATA document       TYPE REF TO if_ixml_document.
*ixml           = cl_ixml=>create( ).
*stream_factory = ixml->create_stream_factory( ).
*document       = ixml->create_document( ).
*cl_demo_output=>display( document ).
*
**With 7.40
*DATA(ixml740)           = cl_ixml=>create( ).
*DATA(stream_factory740) = ixml740->create_stream_factory( ).
*DATA(document740)       = ixml740->create_document( ).
*cl_demo_output=>display( document740 ).

**Field Symbols
*DATA: lv_value TYPE string VALUE 'TEST VALUE'.
*ASSIGN lv_value TO FIELD-SYMBOL(<fs>).
*cl_demo_output=>display( <fs> ).
*
*
*SELECT matnr, mtart
*UP TO 1 ROWS
*INTO TABLE @DATA(itab)
*FROM mara.
*LOOP AT itab ASSIGNING FIELD-SYMBOL(<line>).
*  cl_demo_output=>display( <line> ).
*ENDLOOP.
*
*READ TABLE itab ASSIGNING FIELD-SYMBOL(<wa>) INDEX 1.
*cl_demo_output=>display( <wa> ).



****************************************
* Expressions->Constructor Expressions *
****************************************

*************************
* Instance operator NEW *
*************************

**Example for data objects
**Before Release 7.40
*FIELD-SYMBOLS <fs> TYPE data.
*DATA dref TYPE REF TO data.
*CREATE DATA dref TYPE i.
*ASSIGN dref->* TO <fs>.
*<fs> = 555.
*cl_demo_output=>display( <fs> ).
*
**With Release 7.40
*DATA dref740 TYPE REF TO data.
*dref740 = NEW i( 740 ).
*ASSIGN dref740->* TO FIELD-SYMBOL(<fs740>).
*cl_demo_output=>display( <fs740> ).


**Example for instances of classes
**Before Release 7.40
*DATA: cstr   TYPE REF TO cl_bcs_string,
*      lv_str TYPE string.
*CREATE OBJECT cstr.
*CALL METHOD cstr->add_text
*  EXPORTING
*    iv_string = 'ABAP 7.40'.
*CALL METHOD cstr->get_string
*  RECEIVING
*    rv_result = lv_str.
*cl_demo_output=>display( lv_str ).
*
**With Release 7.40
**Either
*DATA cstr740 TYPE REF TO cl_bcs_string.
*cstr740 = NEW #( ).
**or with an inline declaration
*DATA(cstr7402) = NEW cl_bcs_string( ).
**cstr740->get_string(RECEIVING rv_result = data(lv_str)).
*cl_demo_output=>display( cstr7402 ).


** Internal table
*TYPES: BEGIN OF t_struct1,
*         col1 TYPE i,
*         col2 TYPE i,
*       END OF t_struct1,
*       BEGIN OF t_struct2,
*         col1 TYPE i,
*         col2 TYPE t_struct1,
*         col3 TYPE TABLE OF t_struct1 WITH EMPTY KEY,
*       END OF t_struct2,
*       t_itab TYPE TABLE OF t_struct2 WITH EMPTY KEY.
*
*DATA(dref) =
*  NEW t_itab( ( col1 = 1
*                col2-col1 = 1
*                col2-col2 = 2
*                col3 = VALUE #( ( col1 = 1 col2 = 2 )
*                                ( col1 = 3 col2 = 4 ) ) )
*              ( col1 = 2
*                col2-col1 = 2
*                col2-col2 = 4
*                col3 = VALUE #( ( col1 = 2 col2 = 4 )
*                                ( col1 = 6 col2 = 8 ) ) ) ).
*cl_demo_output=>display( dref ).



************************
* Value Operator VALUE *
************************

**Example for initial values
*CLASS c1 DEFINITION.
*  PUBLIC SECTION.
*    TYPES: BEGIN OF t_struct,
*             col1 TYPE i,
*             col2 TYPE i,
*           END OF t_struct.
*    CLASS-DATA: wa TYPE t_struct.
*    CLASS-METHODS m1 IMPORTING p TYPE t_struct.
*ENDCLASS.
*CLASS c1 IMPLEMENTATION.
*  METHOD m1.
*    wa = p.
*  ENDMETHOD.
*ENDCLASS.
*
*START-OF-SELECTION.
*
*  c1=>m1( VALUE #( col1 = 1 col2 = 2 ) ).
*  cl_demo_output=>display( c1=>wa ).


**Example for structures
*TYPES:  BEGIN OF t_col2,
*           col1 TYPE i,
*           col2 TYPE i,
*        END OF t_col2.
*
*TYPES: BEGIN OF t_struct,
*         col1 TYPE i,
*         col2 TYPE t_col2,
*       END OF t_struct.
*
*DATA: struct TYPE t_struct,
*      col2 TYPE t_col2.
*"1
*struct = VALUE t_struct( col1 = 1
*                         col2-col1 = 1
*                         col2-col2 = 2 ).
*cl_demo_output=>display( struct ).
*"2
*col2   = VALUE t_col2( col1 = 1
*                         col2 = 2 ).
*struct = VALUE t_struct( col1 = 1
*                         col2 = col2 ).
*cl_demo_output=>display( struct ).
*"3
*struct = VALUE t_struct( col1 = 1
*                         col2 = VALUE #( col1 = 1
*                                         col2 = 2 ) ).
*cl_demo_output=>display( struct ).


**Examples for internal tables
*TYPES t_itab TYPE TABLE OF i WITH EMPTY KEY.
*DATA itab TYPE t_itab.
*
*itab = VALUE #( ( ) ( 1 ) ( 2 ) ).
*cl_demo_output=>display( itab ).
*
**Structured line type (RANGES table):
*DATA itab2 TYPE RANGE OF i.
*
*itab2 = VALUE #( sign = 'I'  option = 'BT' ( low = 1  high = 10 )
*                                          ( low = 21 high = 30 )
*                                          ( low = 41 high = 50 )
*                            option = 'GE' ( low = 61 )  ).
*cl_demo_output=>display( itab2 ).


**Other expressions in VALUE operator
*TYPES t_date_tab TYPE TABLE OF string  WITH EMPTY KEY.
*
*DATA(date_tab) = VALUE t_date_tab(
*  ( |{ CONV d( sy-datlo - 1 ) DATE = ENVIRONMENT }| )
*  ( |{         sy-datlo       DATE = ENVIRONMENT }| )
*  ( |{ CONV d( sy-datlo + 1 ) DATE = ENVIRONMENT }| )
*  ( |{ 'CMA' && ' DANISMANLIK' }| ) ).
*cl_demo_output=>display( date_tab ).


**************************
* Reference Operator REF *
**************************
**Example for dynamic method call
*CLASS class DEFINITION.
*  PUBLIC SECTION.
*    METHODS meth
*      IMPORTING p1 TYPE string
*                p2 TYPE i.
*ENDCLASS.
*CLASS class IMPLEMENTATION.
*  METHOD meth.
*   cl_demo_output=>display( p1 ).
*  ENDMETHOD.
*ENDCLASS.
*
*START-OF-SELECTION.
*
*  DATA(arg1) = `blah`.
*  DATA(arg2) = 111.
*
*  DATA(ptab) = VALUE abap_parmbind_tab(
*    ( name = 'P1' kind = cl_abap_objectdescr=>exporting value = REF #( arg1 ) )
*    ( name = 'P2' kind = cl_abap_objectdescr=>exporting value = REF #( arg2 ) ) ).
*
*  DATA(oref) = NEW class( ).
*  CALL METHOD oref->('METH')
*    PARAMETER-TABLE ptab.

**Example for ADBC
*DATA(key) = '000000000000017036'.
*data(lv_spras) = sy-langu.
*
*DATA(sql) = NEW cl_sql_statement( ).
*sql->set_param( REF #( sy-mandt ) ).
**sql->set_param( REF #( key ) ).
*sql->set_param( REF #( lv_spras ) ).
*
*DATA(result) = sql->execute_query(
*      `SELECT maktx ` &&
*      `FROM makt ` &&
**      `WHERE mandt  = ? AND matnr = ?` ).
*      `WHERE mandt  = ? AND spras = ?` ).
*
*DATA maktx TYPE makt-maktx.
*result->set_param( REF #( maktx ) ).
*cl_demo_output=>display( result->next( ) ).


*****************************
* Conversion Operator CONV  *
*****************************

**Example for parameter passing
**Method cl_abap_codepage=>convert_to expects a string but you want to convert a text field.
**Before release 7.40
*DATA text TYPE c LENGTH 255 value 'TEXT 255 CHAR'.
*
*DATA helper TYPE string.
*DATA xstr   TYPE xstring.
*helper = text.
*xstr = cl_abap_codepage=>convert_to( source = helper ).
*cl_demo_output=>display( xstr ).
*
**With release 7.40
*DATA text740 TYPE c LENGTH 255 value 'TEXT 255 CHAR 740'.
*DATA(xstr740) = cl_abap_codepage=>convert_to( source = CONV string( text740 ) ).
*cl_demo_output=>display( xstr740 ).
*
**In such cases it is even simpler to write
*DATA text7402 TYPE c LENGTH 255 value 'TEXT 255 CHAR 7402'.
*DATA(xstr7402) = cl_abap_codepage=>convert_to( source = CONV #( text7402 ) ).
*cl_demo_output=>display( xstr7402 ).

**Example for influencing a calculation
*IF 1 / 3 > 0.
*  cl_demo_output=>display( 'true' ).
*ELSE.
*  cl_demo_output=>display( 'false' ).
*ENDIF.
*
*
*IF CONV decfloat34( 1 / 3 ) > 0.
*  cl_demo_output=>display( 'true' ).
*ELSE.
*  cl_demo_output=>display( 'false' ).
*ENDIF.
*
**Example for influencing a comparison
*IF ' ' = ` `.
*  cl_demo_output=>display( 'true' ).
*ELSE.
*  cl_demo_output=>display( 'false' ).
*ENDIF.
*
*IF ' ' = CONV char1( ` ` ).
*  cl_demo_output=>display( 'true' ).
*ELSE.
*  cl_demo_output=>display( 'false' ).
*ENDIF.


*************************
* Casting Operator CAST *
*************************

**Example from RTTI
**Common example where a down cast is needed.
**Before release 7.40
*DATA structdescr TYPE REF TO cl_abap_structdescr.
*structdescr ?= cl_abap_typedescr=>describe_by_name( 'VBAK' ).
*
*DATA components  TYPE abap_compdescr_tab.
*components = structdescr->components.
*cl_demo_output=>display( components ).
*
**With release 7.40
*DATA(components740) = CAST cl_abap_structdescr(
*  cl_abap_typedescr=>describe_by_name( 'VBAP' ) )->components.
*cl_demo_output=>display( components740 ).

**Example with up cast
**The static type of the reference variable iref declared inline should be the interface not the class.
*INTERFACE if.
*
*ENDINTERFACE.
*CLASS cl DEFINITION CREATE PRIVATE.
*  PUBLIC SECTION.
*    INTERFACES if.
*    CLASS-METHODS factory RETURNING VALUE(ref) TYPE REF TO cl.
*ENDCLASS.
*CLASS cl IMPLEMENTATION.
*  METHOD factory.
*    ref = NEW #( ).
*  ENDMETHOD.
*ENDCLASS.
*
*START-OF-SELECTION.
*  DATA(iref) = CAST if( cl=>factory( ) ).
*  DATA(iref_cl) = CAST if( cl=>factory( ) ).
*  BREAK-POINT.

***Example with data objects
**A constructor expression with CAST followed by -> is an LHS-expression,
**you can assign values to it.
*TYPES: BEGIN OF t_struc,
*         col1 TYPE i,
*         col2 TYPE i,
*       END OF t_struc.
*
*DATA dref  TYPE REF TO data.
*DATA struc TYPE t_struc.
*
*dref = NEW t_struc( ).
*CAST t_struc( dref )->col1 = struc-col1.
*ASSIGN dref->* TO FIELD-SYMBOL(<fs>).
*cl_demo_output=>display( <fs> ).


***************************
* Lossless operator EXACT *
***************************

**Lossless calculations
**A lossless calculation must not perform any roundings. If it does, an exception occurrs.
*TRY.
*    DATA(r1) = EXACT decfloat34( 3 / 2 ).
*    cl_demo_output=>write( |Exact: { r1 }| ).
*  CATCH cx_sy_conversion_rounding INTO DATA(e1).
*    cl_demo_output=>write( |Not exact: { e1->value }| ).
*ENDTRY.
*
*TRY.
*    DATA(r2) = EXACT decfloat34( 3 / 7 ).
*    cl_demo_output=>write( |Exact: { r2 }| ).
*  CATCH cx_sy_conversion_rounding INTO DATA(e2).
*    cl_demo_output=>write( |Not exact: { e2->value }| ).
*ENDTRY.
*
*cl_demo_output=>display( ).


*Lossless assignments
**A lossless assignment is an assignment where
**the value of the source is valid for its type
**there are no data losses during the assignment
**the converted value of the target is valid for its type
*TYPES numtext TYPE n LENGTH 10.
*
*cl_demo_output=>write( CONV numtext( '4 Apples + 2 Oranges' ) ).
*
*TRY.
*    DATA(number) = EXACT numtext( '4 Apples + 2 Oranges' ).
*  CATCH cx_sy_conversion_error INTO DATA(exc).
*    cl_demo_output=>write( exc->get_text( ) ).
*ENDTRY.
*cl_demo_output=>display( ).


*****************************************
* Conditional operators COND and SWITCH *
*****************************************

**Example for COND
*CLASS cx_cant_be DEFINITION INHERITING FROM cx_static_check.
*ENDCLASS.
*DATA(settedtime) = sy-timlo.
*settedtime = '110000'.
*DATA(time) =
*  COND string(
*    WHEN settedtime < '120000' THEN
*      |{ settedtime TIME = ISO } AM|
*    WHEN settedtime > '120000' THEN
*      |{ CONV t( settedtime - 12 * 3600 )
*         TIME = ISO } PM|
*    WHEN settedtime = '120000' THEN
*      |High Noon|
*    ELSE
*      THROW cx_cant_be( )
*  ).
*cl_demo_output=>display( time ).


**Example for SWITCH
*CLASS cx_langu_not_supported DEFINITION INHERITING FROM cx_static_check.
*ENDCLASS.
*CLASS class DEFINITION.
*  PUBLIC SECTION.
*    METHODS meth IMPORTING iso_langu   TYPE string
*                 RETURNING VALUE(text) TYPE string.
*ENDCLASS.
*CLASS class IMPLEMENTATION.
*  METHOD meth.
*    text = 'Returning text from class' && iso_langu.
*  ENDMETHOD.
*ENDCLASS.
*
*START-OF-SELECTION.
*  DATA(text) =
*    NEW class(
*      )->meth(
*          SWITCH #( sy-langu
*                    WHEN 'D' THEN `DE`
*                    WHEN 'E' THEN `EN`
*                    WHEN 'T' THEN `TR`
*                    ELSE THROW cx_langu_not_supported( ) ) ).
*  cl_demo_output=>display( text ).






****************
* ABAP Objects *
****************

**Before Release 7.40 a functional method could have only importing parameters besides its returning parameter.
**A functional method can now have exporting and changing parameters besides its returning parameter.
**In functional method calls you can use the additions EXPORTING, IMPORTING, and CHANGING to pass parameters.
*CLASS class DEFINITION.
*  PUBLIC SECTION.
*    CLASS-METHODS do_something IMPORTING p1       TYPE i
*                                         p2       TYPE i
*                               EXPORTING p3       TYPE i
*                                         p4       TYPE i
*                               RETURNING VALUE(r) TYPE i.
*ENDCLASS.
*CLASS class IMPLEMENTATION.
*  METHOD do_something.
*    r = p2 - p1 - 111.
*    p3 = 3.
*    p4 = 4.
*  ENDMETHOD.
*ENDCLASS.
*
*START-OF-SELECTION.
*  DATA: a1 TYPE i,
*        a2 TYPE i.
*  IF  class=>do_something( EXPORTING p1 = 333
*                                     p2 = 444
*                           IMPORTING p3 = a1
*                                     p4 = a2 ) = 0.
*    cl_demo_output=>display( 'Result = 0' ).
*  ELSE.
*    cl_demo_output=>display( 'Result <> 0' ).
*  ENDIF.


**Interfaces in Test Classes
**Before Release 7.40
*CLASS mock_request DEFINITION FOR TESTING FINAL.
*  PUBLIC SECTION.
*    INTERFACES if_http_request.
*ENDCLASS.
*CLASS mock_request IMPLEMENTATION.
*  METHOD if_http_request~get_form_field.
*    value = SWITCH spfli-carrid( name WHEN 'carrid' THEN 'LH'
*                                      ELSE space ).
*  ENDMETHOD.
*
*  METHOD if_http_entity~set_cdata.     ENDMETHOD.     "##needed
*  METHOD if_http_entity~set_data.      ENDMETHOD.     "##needed
*  METHOD if_http_entity~add_multipart. ENDMETHOD.     "##needed
*  METHOD if_http_entity~append_cdate.  ENDMETHOD.     "##needed
*ENDCLASS.
*
**Release 7.40
*CLASS mock_request740 DEFINITION FOR TESTING FINAL.
*  PUBLIC SECTION.
*    INTERFACES if_http_request PARTIALLY IMPLEMENTED.
*ENDCLASS.
*CLASS mock_request740 IMPLEMENTATION.
*  METHOD if_http_request~get_form_field.
*    value = SWITCH spfli-carrid( name WHEN 'carrid' THEN 'LH'
*                                      ELSE space ).
*  ENDMETHOD.
*ENDCLASS.


*******************
* Internal Tables *
*******************

***************************************
* Internal Tables->Table expressions  *
***************************************

**Index access using the primary index
*SELECT *
*UP TO 10 ROWS
*INTO TABLE @DATA(itab)
*FROM mara.
*
*READ TABLE itab INDEX 3 INTO DATA(wa).
*cl_demo_output=>display( wa-matnr ).
*
*READ TABLE itab WITH KEY matnr = '00582AA' INTO wa.
*DATA output TYPE string.
*CONCATENATE 'Matnr:' wa-matnr 'Mtart:' wa-mtart INTO output SEPARATED BY space.
*cl_demo_output=>display( output ).
*
*DATA(wa740) = itab[ 3 ].
*cl_demo_output=>display( wa740-matnr ).
*
*READ TABLE itab WITH KEY matnr = '00582AA' INTO DATA(wa7402).
*cl_demo_output=>display( |Matnr: { wa7402-matnr } Mtart: { wa7402-mtart }| ).
*
*cl_demo_output=>display( |Mtart: { itab[ matnr = '00582AA' ]-mtart }| ).


**Access using a free key
*SELECT *
*UP TO 10 ROWS
*INTO TABLE @DATA(itab)
*FROM mara.
*
*DATA: wa TYPE mara.
*READ TABLE itab WITH KEY matnr = '' mtart = ''  INTO wa.
*cl_demo_output=>display( wa-matnr ).
*
*DATA(wa740) = itab[ matnr = '' mtart = '' ].
*cl_demo_output=>display( wa740-matnr ).

**Fun example
*TYPES:
*  BEGIN OF struc1,
*    col1 TYPE i,
*    col2 TYPE i,
*  END OF struc1,
*  itab1 TYPE TABLE OF struc1 WITH EMPTY KEY,
*  itab2 TYPE TABLE OF itab1 WITH EMPTY KEY,
*  BEGIN OF struc2,
*    col1 TYPE i,
*    col2 TYPE itab2,
*  END OF struc2,
*  itab3 TYPE TABLE OF struc2 WITH EMPTY KEY.
*
*DATA(itab) = VALUE itab3(
*   ( col1 = 1  col2 = VALUE itab2(
*                       ( VALUE itab1(
*                           ( col1 = 2 col2 = 3 )
*                           ( col1 = 4 col2 = 5 ) ) )
*                       ( VALUE itab1(
*                           ( col1 = 6 col2 = 7 )
*                           ( col1 = 8 col2 = 9 ) ) ) ) )
*   ( col1 = 10 col2 = VALUE itab2(
*                       ( VALUE itab1(
*                           ( col1 = 11 col2 = 12 )
*                           ( col1 = 13 col2 = 14 ) ) )
*                       ( VALUE itab1(
*                           ( col1 = 15 col2 = 16 )
*                           ( col1 = 17 col2 = 18 ) ) ) ) ) ).
*
** Reading the column with value 13 with READ TABLE statements
*READ TABLE itab     INTO DATA(wa1) INDEX 2.
*READ TABLE wa1-col2 INTO DATA(wa2) INDEX 1.
*READ TABLE wa2      INTO DATA(wa3) INDEX 2.
*DATA(num1) = wa3-col1.
*
** Reading the column with value 13 with chained table expressions
*DATA(num2) = itab[ 2 ]-col2[ 1 ][ 2 ]-col1.
**cl_demo_output=>write( wa1 ).
*cl_demo_output=>write( wa2 ).
*cl_demo_output=>write( wa3 ).
*cl_demo_output=>write( num1 ).
*cl_demo_output=>write( num2 ).
*cl_demo_output=>display( ).



*********************************************
* Internal Tables->Internal table functions *
*********************************************

**Line existence
**Note that we have already some other predicate functions in ABAP: matches
**and the contains-variants in the context of string processing
*SELECT *
*UP TO 10 ROWS
*INTO TABLE @DATA(itab)
*FROM mara.
*IF line_exists( itab[ matnr = '00582AA' ] ).
*  cl_demo_output=>display( 'true' ).
*ELSE.
*  cl_demo_output=>display( 'false' ).
*ENDIF.


**Line index
*SELECT *
*UP TO 10 ROWS
*INTO TABLE @DATA(itab)
*FROM mara.
*DATA(idx) = line_index( itab[ matnr = '00582AA' ] ).
*cl_demo_output=>display( idx ).


***************************************************
* Internal Tables->Internal tables with empty key *
***************************************************
*http://scn.sap.com/community/abap/blog/2013/06/27/abap-news-for-release-740--internal-tables-with-empty-key
*DATA: BEGIN OF struct,
*        col1 TYPE i,
*        col2 TYPE i,
*      END OF struct.
*
*DATA itab LIKE TABLE OF struct.
*
*struct-col1 = 3. struct-col2 = 1.
*APPEND struct TO itab.
*struct-col1 = 2. struct-col2 = 2.
*APPEND struct TO itab.
*struct-col1 = 1. struct-col2 = 1.
*APPEND struct TO itab.
*
*DATA jtab LIKE itab.
*jtab = itab.
*
*SORT jtab."not working
*
*IF jtab = itab.
*  MESSAGE 'nop!' TYPE 'I'.
*ENDIF.

*TYPES: BEGIN OF struct,
*         col1 TYPE i,
*         col2 TYPE i,
*       END OF struct.
*
*TYPES itab TYPE STANDARD TABLE OF struct.
*FIELD-SYMBOLS <itab> TYPE itab.
*DATA jtab like <itab>.

*TYPES itab TYPE STANDARD TABLE OF string WITH EMPTY KEY.
*
*DATA(itab) = VALUE itab(
*  ( `I'm going slightly mad` )
*  ( `I'm going slightly mad` )
*  ( `It finally happened - happened` )
*  ( `It finally happened - ooh woh` ) ).
*
*cl_demo_output=>display( itab ).


*********************************************
* ABAP Language News for Release 7.40, SP05 *
*********************************************

**Internal Tables
*SELECT *
*UP TO 10 ROWS
*INTO TABLE @DATA(itab)
*FROM mara.
*data: itab2 type TABLE OF marc.
*
*MOVE-CORRESPONDING itab TO itab2.
*cl_demo_output=>display( itab2 ).
*
*MOVE-CORRESPONDING itab TO itab2 EXPANDING NESTED TABLES.
*cl_demo_output=>display( itab2 ).
*
*MOVE-CORRESPONDING itab TO itab2 KEEPING TARGET LINES."Append
*cl_demo_output=>display( itab2 ).

**LET Expressions in Constructor Expressions
*defines variables var1, var2, ... or field symbols <fs1>, <fs2>, ...
*as local auxiliary fields in an expression
*TYPES:
*   BEGIN OF struc,
*     col1 TYPE i,
*     col2 TYPE i,
*   END OF struc.
*
*DATA(rnd) = cl_abap_random_int=>create(
*  seed = CONV i( sy-uzeit ) min = 1 max = 10 ).
*
*DO 5 TIMES.
*  DATA(struc) = VALUE struc(
*    LET x = rnd->get_next( )
*        y = x * x
*        z = sy-index * 1000 IN col1 = x + z
*                               col2 = y + z ).
*  cl_demo_output=>write( struc ).
*ENDDO.
*cl_demo_output=>display( ).

**CORRESPONDING Operator
**allows to execute  a "MOVE-CORRESPONDING" for structures or internal tables at operand positions
*SELECT *
*UP TO 10 ROWS
*INTO TABLE @DATA(itab)
*FROM mara.
*DATA: itab2 TYPE TABLE OF marc.
*itab2 = CORRESPONDING #( itab ).
*cl_demo_output=>display( itab2 ).

**Table Comprehensions
*CLASS demo DEFINITION.
*  PUBLIC SECTION.
*    CLASS-METHODS main.
*    TYPES:
*      BEGIN OF line1,
*        col1 TYPE i,
*        col2 TYPE i,
*        col3 TYPE i,
*        col4 TYPE i,
*      END OF line1,
*      itab1 TYPE TABLE OF line1 WITH EMPTY KEY
*                                WITH UNIQUE SORTED KEY
*                                     key COMPONENTS col1,
*      BEGIN OF line2,
*        col1 TYPE i,
*        col2 TYPE i,
*      END OF line2,
*      itab2 TYPE TABLE OF line1 WITH EMPTY KEY,
*      itab3 TYPE TABLE OF line1 WITH EMPTY KEY,
*      itab4 TYPE TABLE OF line2 WITH EMPTY KEY,
*      itab5 TYPE TABLE OF i     WITH EMPTY KEY.
*ENDCLASS.
*
*CLASS demo IMPLEMENTATION.
*  METHOD main.
*
*    DATA(out) = cl_demo_output=>new( ).
*
*    DATA(itab1) = VALUE itab1(
*      FOR j = 41 THEN j - 10 UNTIL j < 10
*      ( col1 = j col2 = j + 1 col3 = j + 2 col4 = j + 3 ) ).
*    out->write( itab1 ).
*
*    DATA(itab2) = VALUE itab2(
*      FOR wa IN itab1 WHERE ( col1 < 30 )
*        ( wa ) ).
*    out->write( itab2 ).
*
*    DATA(itab3) = VALUE itab3(
*      FOR wa IN itab1 INDEX INTO idx WHERE ( col1 = 21 ) ##PRIMKEY[key]
*        ( LINES OF itab1 from idx ) ).
*    out->write( itab3 ).
*
*    DATA(itab4) = VALUE itab4(
*       FOR wa IN itab1 FROM 2 TO 3
*         ( col1 = wa-col2 col2 = wa-col3 ) ).
*    out->write( itab4 ).
*
*    DATA(base)  = VALUE itab5( ( 1 ) ( 2 ) ( 3 ) ).
*    DATA(itab5) = VALUE itab5(
*       BASE base
*       FOR wa IN itab1 USING KEY key
*          ( wa-col1 ) ).
*    out->write( itab5 ).
*
*    out->display( ).
*  ENDMETHOD.
*ENDCLASS.
*START-OF-SELECTION.
*  demo=>main( ).

************
* Open SQL *
************
**Lists in Open SQL statements can and should be separated by a comma.
**Host variables in Open SQL statements can and should be escaped by a @.
*DATA: lv_matnr TYPE makt-matnr,
*      lv_langu TYPE sy-langu.
*lv_matnr = '0004001A'.
*lv_langu = sy-langu.
*SELECT matnr, maktx
*UP TO 10 ROWS
*FROM makt
*INTO TABLE @DATA(itab)
*WHERE matnr = @lv_matnr AND
*      spras = @lv_langu
*ORDER BY matnr, maktx.
*cl_demo_output=>display( itab ).

**SQL Expressions
**elementary values
**arithmetic expressions
**arithmetic functions abs, ceil, floor, div, mod
**castings with cast
**string concatenations with &&
**coalesce
**case
*DATA: lv_else TYPE makt-maktx VALUE 'DEFAULT MAKTX'.
*SELECT matnr, CASE maktx
*      WHEN 'AMBALAJ SETİ' THEN ( 'when 1-' && spras && '-' && maktx )
*      WHEN 'CMS 040 MAMUL JANT' THEN ( 'when 2-' && maktx && '-' && spras )
*      "else maktx
*      ELSE @lv_else
*    END AS text
*UP TO 10 ROWS
*FROM makt
*INTO  TABLE @DATA(itab).
*cl_demo_output=>display( itab ).


*ABAP Managed Database Procedures
*http://scn.sap.com/community/abap/blog/2014/02/06/abap-news-for-release-740-sp05


*********************************************
* ABAP Language News for Release 7.40, SP08 *
*********************************************
**Predicative Method Calls
*IF cl_abap_demo_services=>is_production_system( ).
*  cl_demo_output=>display(
*     'This demo cannot be executed in a production system' ).
*  LEAVE PROGRAM.
*ELSE.
*  cl_demo_output=>display('false' ).
*ENDIF.

**New Boolean Function
*IF boolc( 1 = 2 ) = abap_false."returns string so wrong
*  cl_demo_output=>display_text( 'yes' ).
*ELSE.
*  cl_demo_output=>display_text( 'no' ).
*ENDIF.
*
*IF xsdbool( 1 = 2 ) = abap_false.
*  cl_demo_output=>display_text( 'yes' ).
*ELSE.
*  cl_demo_output=>display_text( 'no' ).
*ENDIF.

** REDUCE in FOR Expressions
* Cast result
*DATA(result) =
*  REDUCE string( INIT text = `Count up:`
*                 FOR n = 1 UNTIL n > 10
*                 NEXT text = text && | { n }| ).
*cl_demo_output=>display_text( result ).
*
*TYPES outref TYPE REF TO if_demo_output.
*DATA(output) =
*  REDUCE outref( INIT out  = cl_demo_output=>new( )
*                      text = `Count up:`
*                 FOR n = 1 UNTIL n > 11
*                 NEXT out = out->write( text )
*                      text = |{ n }| ).
*output->display( ).

**BASE for start values of constructor expressions
**Appending lines
*DATA itab TYPE TABLE OF i.
*itab = VALUE #( ( 1 ) ( 2 ) ( 3 ) ).
*itab = VALUE #( ( 4 ) ( 5 ) ( 6 ) ).
*cl_demo_output=>display( itab ).
*
*itab = VALUE #( ( 1 ) ( 2 ) ( 3 ) ).
*itab = VALUE #( BASE itab ( 4 ) ( 5 ) ( 6 ) ).
*cl_demo_output=>display( itab ).

*******************
* Internal Tables *
*******************
** GROUP BY for Internal Tables
*DATA flights TYPE TABLE OF spfli WITH EMPTY KEY.
*SELECT *
*UP TO 10 ROWS
*INTO TABLE @flights
*FROM  spfli.
*
*DATA members LIKE flights.
*LOOP AT flights INTO DATA(flight)
*     GROUP BY ( carrier = flight-carrid
*                cityfr = flight-cityfrom )
*              ASCENDING
*              ASSIGNING FIELD-SYMBOL(<group>).
*  CLEAR members.
*  LOOP AT GROUP <group> ASSIGNING FIELD-SYMBOL(<flight>).
*    members = VALUE #( BASE members ( <flight> ) ).
*  ENDLOOP.
*  cl_demo_output=>write( members ).
*ENDLOOP.
*cl_demo_output=>display( ).
*
*TYPES t_flights LIKE flights.
*DATA out TYPE REF TO if_demo_output.
*out = REDUCE #( INIT o = cl_demo_output=>new( )
*                FOR GROUPS <group2> OF wa_flight IN flights
*                GROUP BY ( carrier = wa_flight-carrid cityfr = wa_flight-cityfrom )
*                  ASCENDING
*                LET members2 = VALUE t_flights( FOR m IN GROUP <group2> ( m ) ) IN
*                NEXT o = o->write( members2 ) ).
*out->display( ).

**FILTER expressions
*CLASS demo DEFINITION.
*  PUBLIC SECTION.
*    CLASS-METHODS main.
*ENDCLASS.
*CLASS demo IMPLEMENTATION.
*  METHOD main.
*    DATA carrid TYPE spfli-carrid VALUE 'LH'.
*    cl_demo_input=>add_field( CHANGING field = carrid ).
*    DATA cityfrom TYPE spfli-cityfrom VALUE 'Frankfurt'.
*    cl_demo_input=>request( CHANGING field = cityfrom ).
*
*    DATA spfli_tab TYPE STANDARD TABLE OF spfli
*                   WITH EMPTY KEY
*                   WITH NON-UNIQUE SORTED KEY carr_city
*                        COMPONENTS carrid cityfrom.
*
*    SELECT *
*    FROM spfli
*    INTO TABLE @spfli_tab.
*
*    DATA(extract) =
*      FILTER #( spfli_tab USING KEY carr_city
*                  WHERE carrid   = CONV #( to_upper( carrid ) ) AND
*                        cityfrom = CONV #( to_upper( cityfrom ) ) ).
*
*    cl_demo_output=>display( extract ).
*
*    DATA(rest) =
*      FILTER #( spfli_tab EXCEPT USING KEY carr_city
*                  WHERE carrid   = CONV #( to_upper( carrid ) ) AND
*                        cityfrom = CONV #( to_upper( cityfrom ) ) ).
*
*    ASSERT lines( extract ) + lines( rest ) = lines( spfli_tab ).
*  ENDMETHOD.
*ENDCLASS.
*
*START-OF-SELECTION.
*  demo=>main( ).

************
* Open SQL *
************

* Inline Declarations behind INTO
*DATA id TYPE scarr-carrid VALUE 'LH'.
*cl_demo_input=>request( CHANGING field = id ).
*SELECT SINGLE carrname AS name, carrid AS id
*INTO @DATA(result)
*FROM   scarr
*WHERE  carrid = @id.
*cl_demo_output=>display( result ).
*
*SELECT carrname AS name, carrid AS id
*FROM   scarr
*INTO TABLE @DATA(result2).
*cl_demo_output=>display( result2 ).

** Column Specification
*SELECT scarr~carrname, spfli~*, scarr~url
*FROM scarr
*INNER JOIN spfli
*        ON scarr~carrid = spfli~carrid
*INTO TABLE @DATA(result).
*cl_demo_output=>display( result ).

Compare the repository objects between several SAP systems of one domain

$
0
0

This program can help you to analyze versions of repository objects in several systems of one domain. The program allows you to check the correctness of versions in the transport request by comparing it to the versions of the same objects in other systems. This prevents errors related with the transport of irrelevant versions of repository objects on your production system. This program has a common idea with RSSYSCOMP, but unlike it this program allows you to see the versions of the repository objects in all systems of domain and check the correctness of versions.

 

TMS must be active, request must be released. Before transferring the request, run the program. The input data are the number of the request and the name of the target system. The output data are the versions of the objects from the transport request. The green objects are the objects with the right chronology. Otherwise the objects will be red.

image002.png

Excel worksheet reading from SAP application server

$
0
0

Issue Faced:

Excel worksheet reading from SAP application server  will  not work, file should be either  .xml  based excel file or .csv based excel or .dat type excel file  to be read from application server

Normal Excel-File  reading from the application server is not possible because, the Excel format before Office 2007 where a binary format (Suffix: .xls). The newer Office file format (Suffix: xlsx) is a zipped XML Format. To read the binary Excel-Format you need an OLE Connection between SAP GUI and MS: Office. But at the application server in background you doesn't have this OLE Connection.

Usually the payment details through third parties  are returned as  Excel files  and getting stored in Server location. So reading of these excel file is required for storing the  details in SAP tables.

 

Solution:

 

There are many possible solutions. We have evaluated 3 solutions for our purpose as it’s difficult to track presentation layer files each time. So reading from Server location is easier.

 

1) Upload the files from the presentation server in foreground. There are some function modules in the standard which can read the xls format.

2) Write an Excel-macro based solution which converts all Excel Files in the CSV-Format so that the same could be read from applications server directly.

3) Creating a temporary excel  file in presentation server based on the application server file using Sap function module :ARCHIVFILE_SERVER_TO_CLIENT,

    and reading it as normal presentation server- excel file and storing in the data in SAP table and deleting  the temp file in the end.

How to handle DUMP : DYNPRO_SEND_IN_BACKGROUND

$
0
0

BACKGROUND

 

DUMP : DYNPRO_SEND_IN_BACKGROUND

 

We may get the above mentioned DUMP in case of Inbound IDOC / RFC Call / Background Job.

 

These inbound IDOC / RFC Call / Background Job may be used for creation of some documents like Invoice, Sales Order or Purchase Order.

 

Now we might have made some extra Z enhancement in user exits or BADIs where you have used a POP-UP screen for some sort of user confirmation. For Example, we frequently use FM "POPUP_TO_CONFIRM" for this. Or may be we have called a screen which requires some user actions(inputs).

 

When a screen which requires an input is called in background, the system gives the above mentioned DUMP. This happens because  there is no user connection in case of inbound IDOC / RFC Call / Background Job. The inbound IDOC was may be triggered from a 3rd Party Non-SAP System or the RFC Call was made from a different System.

 

You will get a DUMP like this:

dump screen.png

 

 

HOW TO HANDLE THIS SITUATION

 

While providing any POP-UP screen, we need to check the User Type.


We may follow the steps below:


1) We will get the user ID in this variable sy-uname.

2) There is a table USR02 where we will find logon details of any user.

3) There is a field USTYP, which will tell us what kind of user it is.


Below are the possible type of users.

type of users.png

 

We can put a simple code to check what kind of user it is. If it is a Dialog User(A), then only provide the POP-UP screen or else don't. We can handle the action automatically with some logic according to the requirement.

 

table.png

 

 

We can also create a function module which you can just call when needed. Refer below Picture.

FM.png


Useful tips regarding ABAP code inspector that you may not know

$
0
0

ABAP code inspector ( tcode SCI ) is not just a tool to ensure the correctness of your code. It is a powerful toolset for an ABAPer to make his life easier. This document is written based on Netweaver 7.40, unveiling some simple but useful tips about code inspector.

 

How to use ABAP code inspector

 

You could find the basic steps how to leverage code inspector from this blog: A Small tip to get all transparent tables used in ABAP code

 

How to read the inspection result


  • There are three columns Error, Warnings and Information. The result with error would probably need your high attention as most of the time it means the bad design or wrong usage about the features checked by inspection variant. The warnings and Information result are just suggestions or calculation result raised by code inspector. If you are 100% sure about your code behavior in all scenarios and runtime context, it is ok that you keep your current code unchanged. For example, in your code you do have some nested LOOP, however the two internal tables being looped are just configuration tables and would not have more than 10 entries for each in your application. In this dedicated case the nested loop will not lead to a great performance loss.

 

  • The documentation icon contains the corresponding help document for each check variant. The document contains quite a good demonstration about:

 

          1. DOs and NOT TO DOs regarding given feature. By reading the document, you can learn how to write a correct, efficient, and robust ABAP code.

 

          2. If you would like to suppress some waringing or information result, assuming if you are 100% sure about your code behavior in all scenarios and runtime context as mentioned before, you could achieve this by adding pseduo comment. The necessary pseduo comment could be found in each documentation.

 

  • By clicking the arrow button, you will navigate to variant customizing window. You could fine-tune the check variant there to perform the code inspection specifically for your project requirement.

 

result.png

Useful tips

 

 

The following parts are organized based on the original hierarchy in code inspection variant maintenance view, as displayed in the picture below:

 

clipboard1.png

General checks - Table Attribute Statistics

 

In the Technical Settings on database table in SE11, You can maintain "Buffering" and "Buffering Type" for a table. Code inspector will find out all combinations of these two settings which do not make sense, for example below:

clipboard2.png

Performance Check

Select-Statement can be transformed. X% of fields used

 

Suppose you have used a SELECT * FROM TABLE A in your method, after this SELECT statement, only number of B fields of table A are used in your method code, and the table A has totally number of C fields. Then code inspector will check whether the utilization rate of table fields ( B / C ) >= default value 20%. If the rate is less than 20%, it give you a hint that you should SELECT only those fields which are really needed in your code instead of SELECT *. You are able to change the default value 20% to any other value which suits your project requirement.

 

clipboard3.png

Search DB Operations in loops across modularization units

 

See one example below. Code inspector will find out all scenarios that a DB operation ( read or write ) is done within LOOP ( or even worse, within nested LOOP ) for you. In this example the table CRMD_DPP_HI_BLCK is read within the nested loop which leads to bad performance in application. Normally we will not directly access DB table in application code due to layer isolation design strategy, in this case we need to re-consider our code design: is there any other function module existing which supports the mass-read onm table CRMD_DPP_HI_BLCK?

clipboard4.png

Nested Loops

 

Nested loops can produce non-linear runtime behavior. In SAP delivered code there did exist many nested loops but the internal tables that the loop are operated on are mostly configuration tables, which means normally the internal table would not have too many entries. However you should think twice in your application code if you need to write nested loop on an application table which would potentially have lots of entries.


This variant will not only identify all nested "LOOP" statement but also other ABAP keyword which leads to loop behavior, like WHILE, DO etc.


Copy current table row for LOOP AT


nowadays it is well known to us all that it is better to use LOOP AT itab ASSIGNING <fs>.  (using a Field Symbol) or  LOOP AT itab REFERENCE INTO dref. (using a reference variable). This check variant gives you a very convenient way to identify all LOOP AT ... INTO WA usage.


Low-Perform. Parameter Transfers


When we are designing the signature of class method or function module, we can decide whether a parameter should have "pass-value" or "pass-reference", according to their dedicated use case. The general rule is that pass by value is always slower than pass by reference. The loss in performance is always a minimum of 40 % and can rise to several 1000 %, depending on the data type and data volume.


This check variant will provide you all potential in-efficient "pass-by-value" use cases. You could also customize the check variant to make the scan is done based on specific Type and Kind of Parameter that you are interested with.

clipboard5.png

Table Attribute Check

 

In the Technical Settings for a database table in tcode SE11, we can maintain Buffering setting for it. There is one option "The option "Buffering allowed, but switched off", which is dedicated used for tables whose size category in the customer system cannot be predicted by the developer. Here, table in the customer system might be very large (in which case it should not be buffered) or relatively small (in which case it can be buffered).

 

So if one developer has marked this option on a table which has table size category 0 or 1, it become not valid since by selecting size category size to be 0 or 1, it indicates that the number of table entries has toplimit ( <= 11000 entries defined for size 1 ). In this case, "Buffering Activated" must be selected instead.

 

This check variant will identify all such incorrect table settings which may lead to potential performance loss for you.

 

Security Check - Dynamic and Client-Specific accesses in SELECT


As a developer in SAP, we are required to avoid any potential SQL injection in our code. The first step to achieve it is to find out all codes where the dynamic SELECT occurs. This check variant will scan all the following behaviors in your code:

 

  • Dynamic table accesses: SELECT * FROM (dbtab) WHERE ...
  • Dynamic WHERE conditions: SELECT * FROM dbtab WHERE (where_cond)
  • Accesses to certain tables: SELECT * FROM dbtab WHERE ...
  • Client-specific accesses: SELECT * FROM dbtab FROM WA ... CLIENT SPECIFIED ...

 

The variant "Dynamic and Client-Specific Accesses with INSERT, UPDATE, MODIFY, DELETE" does the similar logic.


Syntax Check/Generation - Extended Program Check


Return code(SY_SUBRC) for the EXCEPTION will not be processed after CALL FUNCTION

 

 

For example, if you call a function module which has declared several kinds of exceptions, however you didn't evaluate them by checking sy-subrc after function module call, this behavior will be complained by code inspector.

 

  CALL FUNCTION 'XXXX'          EXPORTING             iv_para1                                = YYYY          EXCEPTIONS            exception1_occurred             = 1            exception2_occurred             = 2            OTHERS                               = 3.

* an IF SY-SUBRC evaluation is missing here!!!

 

 

Function module ... is flagged as obsolete

 

This is a good variant if you need to find out all obsolete function module usage in your code.

 

Robust Programming


Search for APPEND and INSERT ... INDEX in SORTED Tables

 

To make things easier I use a small piece of code to demonstrate:

 

data: lt_table TYPE SORTED TABLE OF int4 WITH UNIQUE KEY table_line.
INSERT 2 INTO TABLE lt_table. " lt_table content: 2
INSERT 1 INTO TABLE lt_table. " lt_table ordered content: 1, 2
APPEND 4 TO lt_table. " lt_table ordered content: 1,2,4. No trouble here since fortunately 4 is the bigger than any value currently in lt_table
APPEND 3 TO lt_table. " DUMP!!!

 

This check variant will find out all use cases about APPEND or INSERT ... INDEX done on a sorted table. Although not all of those will lead to runtime DUMP, a robust code should not count on those uncertainties but try to avoid them from beginning.

 

Empty Unused Procedures

 

This check variant returns all Identification of the function modules & class methods which are empty  not yet been called in the current system. For methods and function modules which are not remote-enabled ones, they are good candidates to be deleted during your code-refacting.


Check of SY-SUBRC Handing


Most executable ABAP keywords will set the value of system variable SY-SUBRC accordingly. A robust code should always evaluate its value every time an ABAP statement containing those keywords are executed and react correspondingly.


You can customize the check variant to fine-tune your own SY-SUBRC handling check behavior.

customize.png

Suspect Conversions

 

For example, the conversion from a Literal variable to another variable with ABAP type is regarded as "Suspect conversion".   Assignment from a structure variable to a character-like variable is also considered to be suspect conversions. Basically the help document from "F1->ABAP Programming Guidelines->Robust ABAP->Assignments, Calculations, and Other Types of Data->Using Conversion Rules" is dedicatedly for conversion and worth reading.

conversion.png

 

Missing table content check before calling SELECT ... FOR ALL ENTRIES IN

 

 

In case the internal table used in FOR ALL ENTRIES statement is empty, the DB table would unexpectedly be read completely.

The guideline is always try to check the internal table content first, that is, to embrace FAE statement with an IF <internal table> IS NOT  INITIAL prerequisite check.

 

Programming Conventions

Naming conventions


You could define naming convention currently used in your team or reuse the default setting below. Any violation on the convention will be reported by code inspector.



convention1.png

convention2.png

 

Metrics and Statistics


This check variant collection is mainly checked against some concept from software engineering point of view.

 

Number of Executable Statements Metrics

 

This variant will calculate the number of executable statement for each method of a given ABAP class ( or other ABAP artifact such as function module, report etc ). You could also define the "comment rate", for example there is an input field in variant configuration:

 

warn if < ... comments per 100: 10 ( default value, could be changed )

 

Then you could see the following inspection result for example:

 

Number of comments is 3 per 39 executable

Statements => falls below limit of 10% ( calculated by the variant configuration: 10 ( default value, could be changed ) / 100

 

FAN-OUT Structural Metrics

 

This terminology comes originally from Semiconductor Industry: "Fan-in is the number of inputs a gate can handle." ( from wikipedia )

 

In software engineering, the concept fan-in and fan-out are used to monitor and measure the interaction among modules in the application. According to structured programming idea, an application consists of modules which is responsible to implement a relatively independent functionality.

 

Fan-in: the number of modules which calls the current module being discussed. The larger fan-in is, the better reusability the current module gains.

 

Fan-out: The number of modules that the current module calls in its code. The larger fan-out is, the more complex the module is. A module with fan-out = 1 usually indicates that it is just a wrapper which delegates the call to the module within it. A large fan-out means the module has many dependencies on other modules. In this case, you may think twice about your current design: Is it possible to introduce some new intermediate module to reduce fan-out value?

 

To get a better understanding on fan-out, please refer to attachment "example - why fan-out of method GET_OPPORTUNITY_RESULT is calculated as 7.txt".

 

This check variant will calculate the fan-out value of each ABAP class method and also a cumulative fan-out value of the ABAP class by summing up all fan-out values of its method.

 

Comment Language Metrics


There is argument that in code-refacting topic, suppose a piece of code is not needed any more, should we comment it out or just directly remove it? Back to ABAP, if you have requirement to identify all location where some ABAP code are commented out, this check variant is your best choice. Besides comment identification functionality, this variant also provides the following features:


  • Number of German comment lines
  • Number of English comment lines
  • Number of comment lines in unknown language
  • Number of lines of commented out ABAP
  • Number of pseudo-comments


OO Size Metrics


The following statistics could be displayed for a given ABAP class.


  • Number of methods

     In variant configuration, you can also set further filter like: number of private, protected, and public methods, number of re-defined methods .


  • Number of attributes

     In variant configuration, you can also set further filter like: number of private, protected, and public methods .


  • Number  of interfaces
  • Number of events


Program Complexity Test - cyclomatic complexity


From wikipedia, the cyclomatic complexity of a program is defined with reference to the control flow graph of the program, a directed graph containing the basic blocks of the program, with an edge between two basic blocks if control may pass from the first to the second. The complexity M is then defined as:

 

M = E − N + 2, where

 

E = the number of edges of the graph.

N = the number of nodes of the graph.

 

Take this very simple report for example, it has cyclomatic complexity calculated as 3 by code inspector.

 

DATA: lv_value TYPE i VALUE 1.
IF lv_value = 1.  WRITE: / 'always happend'.
ELSEIF lv_value = 2.  WRITE: / 'not possible'.
ELSE.  WRITE: / 'even not possible'.
ENDIF.

Why calculated as 3? See the directed graph for this simple report below:

graph.png

E: 3 ( black, red and green edgs )

N: 2 ( two blue diamond blocks )

As a result M = 3 - 2 + 2 = 3.


Search functions


Search based on various criterias could be performed according to your variant configuration.

 

Search DB Operations

 

The following operations on database table could be identified:

 

  • SELECT
  • DELETE
  • UPDATE
  • MODIFY
  • INSERT
  • OPEN CURSOR
  • FETCH
  • CLOSE CURSOR
  • EXEC SQL

 

Find Unwanted Language Elements

 

Some ABAP keyword should be forbidden under certain programming contenxt, for example all List processing keywords like WRITE, FORMAT, ULINE etc should not be used in Enterprise service development environment. Of course in variant configuration you could add any other keywords which are unwanted in your project.

 

Search ABAP Statement Patterns

 

Compare with another very useful source code scan report RS_ABAP_SOURCE_SCAN, it also supports source code scan based on statement pattern, not statement itself. For example if you need to identify all use cases of "Read table with key", you only need to specify the following search pattern in variant configuration: ( * stands for any characters in the given position )

 

READ TABLE * WITH KEY * =  *

 

And it works like a charm:

search.png

So if you would not like to spend time to prepare the complex regular search string for

RS_ABAP_SOURCE_SCAN, you can try this approach.


More to be added soon...

Purchase Order Statistical Delivery Date

$
0
0

Hi,

 

Here is BADI document to not change the purchase order statistical delivery date.

Trigger outbound idocs by linking change document object with business object events

$
0
0

Scenario


To transfer master data (For example: vendor master, material master, customer master) changes instantly through idocs from SAP to legacy systems, we do not have automated mechanism like message control technique which is used to transfer transaction data (For example: purchase orders, sales orders). To overcome this problem we can use concept of linking business object events and change document objects to transfer master data idocs.

Below, I will explain with an example how material master price changes are communicated instantly to legacy systems.

 

  1. Change Document Objects
  2. Link change document object with business object event
  3. Assign business object event to receiver function module
  4. Convert XML data in receiver function module.

 

1.    Change Document Objects


      Transaction code: SCDO


  • Change document object contains the tables in which the data of the business object is stored. Function modules that are called in the corresponding application programs and that log the changes at runtime can be generated from the change document object.
  • Logging only takes place if the fields whose contents were changed refer to a data element that was flagged as relevant for the change document.
  • Below screen shots depicts the list of tables contained in change document object ‘MATERIAL’. Our material price field ‘VERPR’ is stored in table ‘MBEW’. Whenever change is made to material price, function modules associated to change document object logs the change in CDHDR and CDPOS tables.

       Change document object.jpg

  • Below screen shot shows list of function modules, DDIC objects and programs generated for change document object ‘MATERIAL’.

chg_gen.png

 

2.    Link change document object with business object event


Transaction code: SWEC


  • After suitable change document object is selected we need to assign change document object to business object.
  • Both change document object and business object which we link should have same key. So the business object should be relevant to change document object. In this example, I am using BOR ‘ZUS1001006’ (copied from ‘BUS1001006’) and new event ‘changed’ is created.
  • Below screen shot shows our custom BOR ‘ZUS1001006’ with event changed. SWO1 is the transaction code for business objects.

obj_typ.png

 

Step 1: Go to transaction SWEC. Click on new entries.

cd1.jpg

 

Step 2: Fill the necessary inputs and save.

 

Since our business object event needs to be triggered only when there is a change in material, I have selected the radio button on change.

 

cd2.jpg

 

 

We can limit the event to trigger only for few fields. This can be achieved by maintaining the fields and their corresponding table name in the node field restrictions.

 

cd3.png

 

3.Assign business object event to receiver function module


Transaction code:  SWETYPV


Create a custom receiver function module and it should have interface parameters same as standard FM ‘SWW_WI_CREATE_VIA_EVENT_IBF’.

 

Step 1: Go to transaction code SWETYPV, click on new entries and fill input fields as below and save. Make sure to check Linkage Activated check box.

 

cd4.png

 

 

4. Convert XML data in receiver function module


Transaction code:  SE37


  • Function module ‘Z_IDOC_CREATE_MAT_PRICE_CHANGE’, receives the data regarding change in XML format.
  • Event_container is the internal table which holds the xml data. This needs to be parsed using function module ‘SMUM_XML_PARSE’ to obtain appropriate structure from which we will fetch change document number generated for price change.
  • Data fetched from CDPOS table for change document number should be sufficient to generate idoc using FM ‘MASTETR_IDOC_DISTRIBUTE’.
  • Next screen shot shows the code, how xstring is parsed and change document number is obtained.

 

cd5.jpg

How to Hide VPRS Condition Record in SAP

$
0
0

Dear Friends,


Client Requirement :



I came across a requirement once in my company . I thought I should share some points which we need to consider achieving this requirement. Although some points have already been discussed in many threads for different requirements . There is an SAP note 105621. All process has been described step by step in this note.


Just I am sharing the piece of code that i have hided VPRS condition at header & Item level .


SU20.jpg

Create two authorization fields with following inputs


ZKALSM.jpg



ZSTUNR.jpg



Create Authorization Object

 

Run Tcode SU21 and Click on this icon and select Authorization Object

 

 

 

 

 

Objec.jpg





Enter object name, text, class and field names. Field ACTVT is not necessary. I have added in screenshot but you can create without this field too. It works fine without this field. Only add two fields ZKALSM and ZSTUNR.





h.jpg


 


Transactions Included VF01, VF02, and VF03.


The sameUSER EXIT we can use for VA01, VA02, and VA03 also steps are same.


Using ABAP Code we have achieve this functionality.






 

USER EXIT: LV69AFZZ.


Go to SE38 à Provide program name LV69AFZZ & Click on change.



Now you can find here



Header.jpg

FORM userexit_field_modific_kopf. “These Subroutine is for Header Level hiding VPRS or Any Condition type


“I Have included HEADER & Item Screen Fields to hide VPRS condition types  here.



DATA : dummy TYPE c.
IF sy-tcode = ‘VF01’OR sy-tcode = 'VF02' OR sy-tcode = 'VF03'.

  AUTHORITY-CHECK OBJECT 'Z_KONH_KLS'
ID 'ZKALSM' FIELD komk-kalsm
ID 'ZSTUNR' FIELD komv-stunr
ID 'ACTVT' FIELD dummy.

 

 

 

 

 

 

 

 


IF sy-subrc NE 0.
CASE screen-name.
WHEN 'KOMV-KWERT'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.
WHEN 'KOMV-KBETR'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.
WHEN 'KOMV-KWERT'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.
WHEN 'KOMV-KWERT_K'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'KOMV-KSCHL'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'T685T-VTEXT'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'XKOMV_WAERK'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'RV61A-LED_KINAK'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'KOMV-KWAEH'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.
WHEN 'RV61A-KOEIN'.

        IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.



WHEN 'KOMV-KPEIN'.

        IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'KOMV-KMEIN'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'KOMV-KUMZA'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'RV61A-MEINS'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'KOMV-KUMNE'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'RV61A-KMEI1'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

ENDCASE.

ENDIF.

ENDFORM.




Itemsss.jpg


FORM userexit_field_modification. These Subroutine is for Item Level hiding VPRS or Any Condition type

 

*I Have included HEADER & Item Screen Fields to hide VPRS condition types

 

DATA : dummy TYPE c.
IF sy-tcode = ‘VF01’OR sy-tcode = 'VF02' OR sy-tcode = 'VF03'.

  AUTHORITY-CHECK OBJECT 'Z_KONH_KLS'
ID 'ZKALSM' FIELD komk-kalsm
ID 'ZSTUNR' FIELD komv-stunr
ID 'ACTVT' FIELD dummy.

 

 

 

 

 

 

 

 


IF sy-subrc NE 0.
CASE screen-name.
WHEN 'KOMV-KWERT'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.
WHEN 'KOMV-KBETR'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.
WHEN 'KOMV-KWERT'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.
WHEN 'KOMV-KWERT_K'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'KOMV-KSCHL'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'T685T-VTEXT'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'XKOMV_WAERK'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'RV61A-LED_KINAK'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'KOMV-KWAEH'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.
WHEN 'RV61A-KOEIN'.

        IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.



WHEN 'KOMV-KPEIN'.

        IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'KOMV-KMEIN'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'KOMV-KUMZA'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'RV61A-MEINS'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'KOMV-KUMNE'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

WHEN 'RV61A-KMEI1'.
IF xkomv-kschl = 'VPRS'.
screen-active = 0.
ENDIF.

ENDCASE.

ENDIF.




Before Implementing User Exit for Header level:

I have been created Billing Document and showing the cost is included for HEADER Level


before header.jpg


After Implementing User Exit for Header level:


Output :

After header.jpg


Before Implementing User Exit for ITEM level:


I have been created Billing Document and showing the cost is included for ITEM Level.





Before Item.jpg



After Implementing User Exit for ITEM level:

Output:


AFter Item.jpg


Logic used as Authorization for entering/displaying manual condition in Sale order.

Getting Sales Conditions using ABAP

$
0
0

This is my first document on SAP SCN, so I decided to post an ABAP solution that I created some time ago to get Sales Conditions, using a key combination almost like we found running VK13 transaction (condition type, material, condition number or customer):

 

VK13.png

 

This solution uses 3 methods from a “Z” Class, which can be used separated or combined, as necessary!

 

To see all source codes, check the files attached!

 

 

Method READ_CONDITION_TABLES (Static Method – Public)

 

This method is used to read all Sales Condition tables, defined into Customizing Access Sequences.

 

Parameters:

READ_CONDITION_TABLES_Param.png

 

Method GET_CONDITION_VALUES (Static Method – Public)

 

This method is used to select dynamically all entries from Sales Condition tables read by method READ_CONDITION_TABLES.

 

Parameters:

GET_CONDITION_VALUES_Param.png

 

Method GET_SALES_CONDITIONS (Static Method – Public)

 

This method was created to return all entries from Sales Condition tables enabled, using methods READ_CONDITION_TABLES & GET_CONDITION_VALUES.

 

Parameters:

GET_SALES_CONDITIONS_Param.png

 

I hope this document be helpful for someone!

 

Best regards,

Alexandre B. Dambrowski

Runtime Errors DBIF_RSQL_SQL_ERROR;Error Text of the Database: "ORA-01653: unable to extend table in table space"

$
0
0

This document will explain you the analysis steps when you get run time error DBIF_RSQL_SQL_ERROR with error text ORA-01653: unable to extend table.


Run time error details:

 

Runtime Errors         DBIF_RSQL_SQL_ERROR

Except.                   CX_SY_OPEN_SQL_DB

 

SQL error 1653 when accessing table "DDFTX".

Error Text of the Database: "ORA-01653: unable to extend table SAPSR3.DDFTX by 1024 in table space PSAPSR3731".

Check in transaction DB02 for the table space memory. Here you can see there is no free memory in the table space PSAPSR3731 which has caused runtime error.

Contact BASIS and increase the memory of the table space to avoid the runtime error.

1.jpg

How to find the Table space for the given database table?

Go to transaction SE11 --> Display table and go to Technical settings.

2.jpg

Note the data class used, here it is SLEXC.

3.jpg

Go to table TAORA, give the data class name and find the table space.

4.jpg

How to find all tables under a given table space?

Lets find the tables under table space PSAPSR3731.

Go to table TAORA and give the table space name to get the Data class assigned to it.

5.jpg

Now go to table DD09L give the above data class to find the database tables assigned to the table space.

6.jpg

Logo/Image From MIME repository in report output

$
0
0

Introduction

 

The MIME (Multipurpose Internet Mail Exchange) Repository is used to store objects such as style sheets, graphics, and icons in the SAP System. MIMEs are created as objects in the SAP database and can be referred to on the pages of BSP (Business Server Pages) applications. These objects use the SAP development infrastructure. Changes in the MIME Repository, such as the import of new MIMEs, are written to a transport request.

 

To display an image/chart/icon along with the report output onto a screen we can utilize this option of MIME repository to display the image. We can do this based on the information provided in the following document.

 

Business Scenario

 

To display a Pie chart on the left of the report output on click of a button.

 

Procedure

  • Create a new folder called ‘ABAP’ under public as shown below

       image.jpg

  • Right click on this folder and click on import MIME object.

       image1.jpg

 

  • Select an object from the suitable location and then provide the name,
    description and click on save button. It will prompt for package and workbench
    request. Provide the details and click on proceed so that the object is
    uploaded to MIME repository. Here we have uploaded image with the name ‘Pie.jpg’
    as shown below

       image2.jpg

 

  • Now we need to create a program to display an ALV output which is based on
    the requirement. An example is shown below

      image3.jpg    

 

  • We have provided a button “Image” for input so on click on this button the
    image will be displayed in ALV output

      image4.jpg    

 

  • On click of the image button we create a docking container in the program
    which serves to display this image. We use the ABAP global class ‘cl_mime_repository_api’
    and its method ‘if_mr_api
    ~get_api’ to create an API instance.

 

  • We convert the xstring data to binary data. Then we create a temporary URL for
    this data using function module 'DP_CREATE_URL' and load the URL using load_picture_from_url_async
    method.

 

  • Now on click on this button, the image is displayed on the left hand side
    of the ALV output as shown below. This image can also be shown on the right
    hand side based on the requirements.

       image5.jpg

 

Key Benefits

  1. Any additional information which would help the end user can be display in
    the output itself
  2. This can also be served as an verification method for certain process such
    as invoice verification
  3. This image display can be made dynamic based on the requirement
  4. Since MIME repository is used we can also mass import and export from/to local
    folders.
  5. The maintenance transaction SE80 offers greater comfort than SMW0 (Web
    Repository). It is used by SAP for Web Dynpro and BSP applications.

 

Reference

 

  1. https://help.sap.com/saphelp_crm50/helpdata/en/46/bb182fab4811d4968100a0c94260a5/content.htm
  2. https://help.sap.com/saphelp_crm50/helpdata/en/46/bb183eab4811d4968100a0c94260a5/content.htm

 

Contact Details

 

Name: Shravan Uddaram

Email: shravan.k.uddaram@accenture.com


How to document the ALV output into a PDF file ( using spool )

$
0
0

This document shows you how to download the ALV output into a PDF file from program level, in an easier way.

REPORT  ztest_create2.
TYPE-POOLS:slis.
TYPES: BEGIN OF ty_t001,         bukrs TYPE t001-bukrs,         butxt TYPE t001-butxt,        ort01 TYPE t001-ort01,         land1 TYPE t001-land1,         waers TYPE t001-waers,        END  OF ty_t001.
DATA: it_t001      TYPE TABLE OF ty_t001,       it_pdf       LIKE tline OCCURS 0,       it_fieldcat  TYPE slis_t_fieldcat_alv.
DATA: g_spool      TYPE tsp01-rqident,      g_program    TYPE sy-repid VALUE sy-repid.
DATA: w_print       TYPE slis_print_alv,      w_print_ctrl  TYPE alv_s_pctl,      w_pri_params  TYPE pri_params.
** Selection screen
PARAMETERS: p_file TYPE string.
** Initialization
INITIALIZATION.  p_file = 'C:\Users\mayur.priyan\Desktop\CHECK.pdf'.
** Start of Selection
START-OF-SELECTION.  SELECT bukrs         butxt         ort01         land1         waers    FROM t001    INTO TABLE it_t001 UP TO 100 ROWS.  w_print-print = 'X'.
* Function Call to get print parameters  CALL FUNCTION 'GET_PRINT_PARAMETERS'    EXPORTING      mode                   = 'CURRENT'      no_dialog              = 'X'      user                   = sy-uname    IMPORTING      out_parameters         = w_pri_params    EXCEPTIONS      archive_info_not_found = 1      invalid_print_params   = 2      invalid_archive_params = 3      OTHERS                 = 4.
* To capture the Spool Request  NEW-PAGE PRINT ON PARAMETERS w_pri_params NO DIALOG.  PERFORM fill_catalog_alv1 USING:     'BUKRS'     'T001'    'BUKRS',     'BUTXT'     'T001'    'BUTXT',     'ORT01'     'T001'    'ORT01',     'LAND1'     'T001'    'LAND1',     'WAERS'     'T001'    'WAERS'.  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'    EXPORTING      i_callback_program = g_program      it_fieldcat        = it_fieldcat    TABLES      t_outtab           = it_t001.  IF sy-subrc EQ 0.    NEW-PAGE PRINT OFF.    g_spool = sy-spono.    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'      EXPORTING        src_spoolid = g_spool        dst_device  = 'LOCL'      TABLES        pdf         = it_pdf.    IF sy-subrc <> 0.      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.    ELSE.      CALL FUNCTION 'GUI_DOWNLOAD'        EXPORTING          filename = p_file          filetype = 'BIN'        TABLES          data_tab = it_pdf.      IF sy-subrc <> 0.        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno        WITH sy-msgv1 sy-msgv2.      ELSE.        WRITE: / 'Downloaded document successfully'.      ENDIF.    ENDIF.  ENDIF.
*&---------------------------------------------------------------------*
*&      Form  fill_catalog_alv1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FIELD_NAME   text
*      -->P_REFTAB_NAME  text
*      -->P_REF_FIELD    text
*----------------------------------------------------------------------*
FORM fill_catalog_alv1 USING p_field_name  TYPE slis_fieldname                             p_reftab_name TYPE slis_tabname                             p_ref_field   TYPE slis_fieldname.  DATA: ls_field_alv TYPE slis_fieldcat_alv.
* Filling the field catalog values.  ls_field_alv-fieldname     = p_field_name.  ls_field_alv-ref_tabname   = p_reftab_name.  ls_field_alv-ref_fieldname = p_ref_field.  APPEND ls_field_alv TO it_fieldcat.
ENDFORM.                    " FILL_CATALOG_ALV1

Setting Code Inspector Custom Variant as Default Code Inspector variant

$
0
0

In our projects we generally create a custom variant for the code inspectors, which take cares of our project related Naming convention and coding standard.

If you are new in creating Code inspector variant you can refer below link.

http://wiki.scn.sap.com/wiki/display/ABAP/Creating+code+inspector+Check+Variant+for+client+specific+naming+conventions


In general whenever we develop any object or make any changes in any object, we go to Transaction SCII and run the code inspector for Z created Variant instead of directly checking it from Object menu Class/Program/Function module etc. ->Check -> code inspector.

 

Reason for the same is our Z created variant is not set as Default.


Once it is set as Default then you can use from object menu also.


Please follow below process to set the Z variant as default variant.


Go to T-code - SCI

  1st.jpg    

In Check variant write Z variant and then click on button on left side of Check variant 2nd.png  and this will turn to 3rd.jpg              making it global as generally Variant which we create is global.(If it is created as Local keep it as it is)


Click on copy button 4th.jpg, POP up will occur, in new variant write DEFAULT and press enter it will automatically get associated with your code inspector.


5th.jpg



Now go to your program and run Code inspector



6th.jpg

You will now be able to able to see naming convention error and other project specific norm related error.

 

 

Note: When ever any alteration is been made in Z Variant we again have to assign it to our ID

ALV PROGRAM USING ABAP OOPS

$
0
0

Technical Design:

 

MVC Design Document for Volume Estimation for Cross dock deliveries:

 

 

Capture.JPG

Capture.JPG

 

 

 

Development Navigation:

 

 

Executable Program:

 

  Program Name: ZDL_VOLUME_ESTIMATION:

 

 

Code details

 

**********************************************************************
* Date          Username  Chg Req/Incident      Description
* 16.10.2014    BISWAJO  U148 Transportation  Volume estimation for
*                        Portal                cross dock deliveries
*
**********************************************************************
*&---------------------------------------------------------------------*
*& Report  ZMD_VOLUME_ESTIMATION
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zdl_volume_estimation.

***Data Declaration
INCLUDE zdl_volume_estimation_dd.
*INCLUDE zmd_volume_estimation_dd.

***Selection-Screen
INCLUDE zdl_volume_estimation_ss.
*INCLUDE zmd_volume_estimation_ss.


START-OF-SELECTION.

***Validate the selection Screen
PERFORM screen_validate.

*Get instance
go_volume_estimation
= zcl_dl_vol_estimation_model=>get_instance( ).

*Set filter
go_volume_estimation
->set_filter(
i_delivery 
= dl_ty_so[]                                  "Delivery Type
i_tr_group 
= tr_gr_so[]                                  "Transportation Group
i_cr_date   
= cr_dt_so[]                                  "Date on Which Record Was Created
i_cr_time   
= cr_tm_so[]                                  "Entry time
i_shp_pnt   
= sh_pt_so[]                                  "Shipping Point/Receiving Point
i_route     
= route_so[]                                  "Route
i_dlv_num   
= dv_nr_so[]                                  "Delivery
i_test_run 
= ts_run_p ) .                                "Checkbox for Test Run

go_volume_estimation
->retrieve_ve_details( ).
go_volume_estimation
->populate_final_table( ).
go_volume_estimation
->puopulate_field_catalog( ).
go_volume_estimation
->display_output_in_alv( ).



Include Name: ZDL_VOLUME_ESTIMATION_DD:


 


Code details

 

**********************************************************************
* Date          Username  Chg Req/Incident      Description
* 16.10.2014    BISWAJO  U148 Transportation  Volume estimation for
*                        Portal                cross dock deliveries
*                                              TOP INCLUDE
**********************************************************************
*&---------------------------------------------------------------------*
*&  Include          ZMD_VOLUME_ESTIMATION_DD
*&---------------------------------------------------------------------*
TABLES: likp.

DATA: dl_ty_so_lv TYPE lfart,                  "Delivery Type
tr_gr_so_lv
TYPE tragr,                  "Transportation Group
cr_dt_so_lv
TYPE erdat,                  "Date on Which Record Was Created
cr_tm_so_lv
TYPE erzet,                  "Entry time
sh_pt_so_lv
TYPE vstel,                  "Shipping Point/Receiving Point
route_so_lv
TYPE route,                  "Route
dv_nr_so_lv
TYPE vbeln_vl.                "Delivery

DATA: go_volume_estimation TYPE REF TO zcl_dl_vol_estimation_model.



Include Name: ZDL_VOLUME_ESTIMATION_SS:


 

Code details

 

**********************************************************************
* Date          Username  Chg Req/Incident      Description
* 17.10.2014    BISWAJO  U148 Transportation  Volume estimation for
*                        Portal                cross dock deliveries
*                                              SELECTION-SCREEN
**********************************************************************
*&---------------------------------------------------------------------*
*&  Include          ZMD_VOLUME_ESTIMATION_SS
*&---------------------------------------------------------------------*
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.
SELECT-OPTIONS: dl_ty_so    FOR likp-lfart    NO INTERVALS OBLIGATORY,              "Delivery Type
tr_gr_so   
FOR likp-tragr    NO INTERVALS OBLIGATORY,              "Transportation Group
cr_dt_so   
FOR likp-erdat    NO INTERVALS NO-EXTENSION DEFAULT SY-DATUM"Date on Which Record Was Created
cr_tm_so   
FOR likp-erzet    NO-EXTENSION ,              "Entry time
sh_pt_so   
FOR likp-vstel    NO INTERVALS,                          "Shipping Point/Receiving Point
route_so   
FOR likp-route    NO INTERVALS,                          "Route
dv_nr_so   
FOR likp-vbeln    .                          "Delivery
PARAMETERS:    ts_run_p    AS  CHECKBOX.
SELECTION-SCREEN: END OF BLOCK b1.
*&---------------------------------------------------------------------*
*&      Form  SCREEN_VALIDATE
*&---------------------------------------------------------------------*
*      text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM screen_validate .

**** Validating User Inputs for the Selection Screen

IF NOT dl_ty_so-low IS INITIAL.
SELECT SINGLE lfart
FROM likp
INTO dl_ty_so_lv
WHERE lfart EQ dl_ty_so-low.      "#EC WARNOK
*          WHERE lfart IN dl_ty_so.      "#EC WARNOK

IF sy-subrc NE 0.
MESSAGE text-001 TYPE 'I'.
STOP.
ENDIF.
ENDIF.
CLEAR dl_ty_so_lv.

IF NOT tr_gr_so-low IS INITIAL.
SELECT SINGLE tragr
FROM likp
INTO tr_gr_so_lv
*            WHERE tragr IN tr_gr_so.    "#EC WARNOK
WHERE tragr EQ tr_gr_so-low.    "#EC WARNOK

IF sy-subrc NE 0.
MESSAGE text-001 TYPE 'I'.
STOP.
ENDIF.
ENDIF.
CLEAR dl_ty_so_lv.

IF cr_dt_so-low IS INITIAL.
cr_dt_so
-low  = sy-datum.
ENDIF.

IF NOT cr_dt_so-low IS INITIAL.
SELECT SINGLE erdat
FROM likp
INTO cr_dt_so_lv
*          WHERE erdat IN cr_dt_so.      "#EC WARNOK
WHERE erdat EQ cr_dt_so-low.      "#EC WARNOK

IF sy-subrc NE 0.
MESSAGE text-002 TYPE 'I'.
STOP.
ENDIF.
ENDIF.
CLEAR cr_dt_so_lv.

IF cr_tm_so-low IS INITIAL.
cr_tm_so
-low = 000000.
ENDIF.

IF NOT cr_tm_so-low IS INITIAL.
SELECT SINGLE erzet
FROM likp
INTO cr_tm_so_lv
WHERE erzet EQ cr_tm_so-low.        "#EC WARNOK

IF sy-subrc NE 0.
MESSAGE text-003 TYPE 'I'.
STOP.
ENDIF.
ENDIF.
CLEAR cr_tm_so_lv.


IF NOT cr_tm_so-high IS INITIAL.
SELECT SINGLE erzet
FROM likp
INTO cr_tm_so_lv
WHERE erzet EQ cr_tm_so-high.        "#EC WARNOK

IF sy-subrc NE 0.
MESSAGE text-003 TYPE 'I'.
STOP.
ENDIF.
ENDIF.
CLEAR cr_tm_so_lv.

IF NOT sh_pt_so-low IS INITIAL.
SELECT SINGLE vstel
FROM likp
INTO sh_pt_so_lv
WHERE vstel EQ sh_pt_so-low.          "#EC WARNOK

IF sy-subrc NE 0.
MESSAGE text-004 TYPE 'I'.
STOP.
ENDIF.
ENDIF.
CLEAR sh_pt_so_lv.

IF NOT route_so-low IS INITIAL.
SELECT SINGLE route
FROM likp
INTO route_so_lv
WHERE route EQ route_so-low.          "#EC WARNOK

IF sy-subrc NE 0.
MESSAGE text-005 TYPE 'I'.
STOP.
ENDIF.
ENDIF.
CLEAR route_so_lv.

IF NOT dv_nr_so-low IS INITIAL.
SELECT SINGLE vbeln
FROM likp
INTO dv_nr_so_lv
WHERE vbeln EQ dv_nr_so-low.          "#EC WARNOK

IF sy-subrc NE 0.
MESSAGE text-006 TYPE 'I'.
STOP.
ENDIF.
ENDIF.
CLEAR dv_nr_so_lv.

IF NOT dv_nr_so-high IS INITIAL.
SELECT SINGLE vbeln
FROM likp
INTO dv_nr_so_lv
WHERE vbeln EQ dv_nr_so-high.          "#EC WARNOK

IF sy-subrc NE 0.
MESSAGE text-006 TYPE 'I'.
STOP.
ENDIF.
ENDIF.
CLEAR dv_nr_so_lv.

ENDFORM.                    " SCREEN_VALIDATE



Class Definition and Details:

 

  Global Model Class: ZCL_DL_VOL_ESTIMATION_MODEL:


Source CodeBased Class Builder:


 

 

class ZCL_DL_VOL_ESTIMATION_MODEL definition
public
final
create public .

public section.

types:
BEGIN OF VOLUME_ESTIMATION_FINAL_TYPES,
MANDT                 
TYPE    MANDT,
SHIPPING_POINT         
TYPE    VSTEL,
ROUTE                 
TYPE    ROUTE,
ROUTE_SCHEDULE         
TYPE    AULWE,
CUSTOMER_NUMBER       
TYPE    KUNNR,
TRAN_GROUP             
TYPE    TRAGR,
PACK_MAT_NO           
TYPE    VHILM,
COUNTER               
TYPE    Char3,
LICENSE_PLATE         
TYPE    ZLICENCE_PLATE,
DEST_ZONE             
TYPE    LZONE,
DEPA_ZONE             
TYPE    AZONE,
STATUS                 
TYPE    ZSTATUS,
DROPPING_SEQUENCE
(5)    TYPE    C,
*        DROPPING_SEQUENCE      TYPE    AUSL_REIH,
FREIGHT_GROUP         
TYPE    MFRGR,
DOOR                   
TYPE    ZDOOR,
DELIVERY_DATE         
TYPE    LFDAT,
DELIVERY_TIME         
TYPE    LFUHR,
ISSUE_DATE             
TYPE    WADAK,
ISSUE_TIME             
TYPE    WAUHR,
CUSTOMER_NAME         
TYPE    NAME1_GP,
HUB_CARRIER_ID         
TYPE    ZCARRIER,
HUB_CARRIER_NAME       
TYPE    NAME1_GP,
CARRIER_ID             
TYPE    ZCARRIER,
CARRIER_NAME           
TYPE    NAME1_GP,
AMOUNT                 
TYPE    ZAMOUNT,
WEIGHT                 
TYPE    BRGEW,
WEIGHT_UOM             
TYPE    GEWEI,
END OF VOLUME_ESTIMATION_FINAL_TYPES .
types:
range_delivery 
TYPE RANGE OF lfart .
types:
range_tr_group 
TYPE RANGE OF tragr .
types:
range_cr_date   
TYPE RANGE OF erdat .
types:
range_cr_time   
TYPE RANGE OF erzet .
types:
range_shp_pnt   
TYPE RANGE OF vstel .
types:
range_route     
TYPE RANGE OF route .
types:
range_dlv_num   
TYPE RANGE OF vbeln_vl .
types:
VOLUME_ESTIMATE_FINAL_TABLE
TYPE STANDARD TABLE OF VOLUME_ESTIMATION_FINAL_TYPES .

data VOLUME_ESTIMATE_FINAL_T type VOLUME_ESTIMATE_FINAL_TABLE .
type-pools SLIS .
data FIELDCATALOG_T type SLIS_T_FIELDCAT_ALV .
data LO_VE_CONTROL type ref to ZCL_DL_VOL_ESTIMATION_CONTROL .

methods SET_FILTER
importing
!I_DELIVERY
type RANGE_DELIVERY
!I_TR_GROUP
type RANGE_TR_GROUP
!I_CR_DATE
type RANGE_CR_DATE
!I_CR_TIME
type RANGE_CR_TIME
!I_SHP_PNT
type RANGE_SHP_PNT
!I_ROUTE
type RANGE_ROUTE
!I_DLV_NUM
type RANGE_DLV_NUM
!I_TEST_RUN
type CHAR1 .
class-methods GET_INSTANCE
returning
value(R_VE_MODEL) type ref to ZCL_DL_VOL_ESTIMATION_MODEL .
methods PUOPULATE_FIELD_CATALOG .
methods DISPLAY_OUTPUT_IN_ALV .
methods RETRIEVE_VE_DETAILS .
methods POPULATE_FINAL_TABLE .
PROTECTED SECTION.
PRIVATE SECTION.

TYPES:
BEGIN OF filter_type_ve,
delivery       
TYPE range_delivery,
tr_group       
TYPE range_tr_group,
cr_date         
TYPE range_cr_date,
cr_time         
TYPE range_cr_time,
shp_pnt         
TYPE range_shp_pnt,
route           
TYPE range_route,
dlv_num         
TYPE range_dlv_num,
test_run_flag   
TYPE char1,
END OF filter_type_ve .

CLASS-DATA ve_model TYPE REF TO zcl_dl_vol_estimation_model .
DATA filter TYPE filter_type_ve .
DATA ve_list TYPE zdl_volum_estimate_list_type .
ENDCLASS.



CLASS ZCL_DL_VOL_ESTIMATION_MODEL IMPLEMENTATION.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DL_VOL_ESTIMATION_MODEL->DISPLAY_OUTPUT_IN_ALV
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD display_output_in_alv.

**********************************************************************
* Date          Username  Chg Req/Incident      Description
* 21.10.2014    BISWAJO  U148 Transportation  Volume estimation for
*                        Portal                cross dock deliveries
*
**********************************************************************
DATA: repid_v      TYPE      sy-repid.

****Displaying Output in ALV Format****

repid_v 
= sy-repid.



IF volume_estimate_final_t IS NOT INITIAL.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program
= repid_v
*        i_callback_top_of_page  = me->TOP_OF_PAGE
it_fieldcat       
= fieldcatalog_t[]
TABLES
t_outtab         
= volume_estimate_final_t.


ENDIF.

ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_DL_VOL_ESTIMATION_MODEL=>GET_INSTANCE
* +-------------------------------------------------------------------------------------------------+
* | [<-()] R_VE_MODEL                    TYPE REF TO ZCL_DL_VOL_ESTIMATION_MODEL
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_instance.

**********************************************************************
* Date          Username  Chg Req/Incident      Description
* 22.10.2014    BISWAJO  U148 Transportation  Volume estimation for
*                        Portal                cross dock deliveries
*
**********************************************************************

**** Creating instance of the model class****

IF ve_model IS INITIAL.
CREATE OBJECT ve_model.
ENDIF.

r_ve_model
= ve_model.

ENDMETHOD.                    "get_instance


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DL_VOL_ESTIMATION_MODEL->POPULATE_FINAL_TABLE
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD populate_final_table.

**********************************************************************
* Date          Username  Chg Req/Incident      Description
* 21.10.2014    BISWAJO  U148 Transportation  Volume estimation for
*                        Portal                cross dock deliveries
*
**********************************************************************

DATA: ve_list_row  LIKE LINE OF me->ve_list.
DATA: ve_obj      TYPE REF TO zcl_dl_vol_estimation_control,
volume_estimation_final_s
TYPE volume_estimation_final_types.

LOOP AT me->ve_list INTO ve_list_row.

ve_obj
= ve_list_row-vol_estimate.
volume_estimation_final_s
-mandt              = ve_obj->mandt.                  "Client
volume_estimation_final_s
-shipping_point      = ve_obj->shipping_point.        "Shipping Point/Receiving Point
volume_estimation_final_s
-route              = ve_obj->route.                  "Route
volume_estimation_final_s
-route_schedule      = ve_obj->route_schedule.        "Route Schedule
volume_estimation_final_s
-customer_number    = ve_obj->customer_number.        "Customer Number
volume_estimation_final_s
-tran_group          = ve_obj->tran_group.            "Transportation Group
volume_estimation_final_s
-pack_mat_no        = ve_obj->pack_mat_no.            "Packaging Materials
volume_estimation_final_s
-counter            = ve_obj->counter.                "Counter
volume_estimation_final_s
-status              = ve_obj->status.                "Status of the Record
volume_estimation_final_s
-dropping_sequence  = ve_obj->dropping_sequence.      "Dropping Sequence
volume_estimation_final_s
-freight_group      = ve_obj->freight_group.          "Article freight group
volume_estimation_final_s
-depa_zone          = ve_obj->depa_zone.              "Departure zone
volume_estimation_final_s
-dest_zone          = ve_obj->dest_zone.              "Transportation zone to or from which the goods are delivered
volume_estimation_final_s
-delivery_date      = ve_obj->delivery_date.          "Delivery date
volume_estimation_final_s
-delivery_time      = ve_obj->delivery_time.          "Time of delivery
volume_estimation_final_s
-issue_date          = ve_obj->issue_date.            "Goods Issue Date
volume_estimation_final_s
-issue_time          = ve_obj->issue_time.            "Time of Goods Issue (Local, Relating to a Site)
volume_estimation_final_s
-customer_name      = ve_obj->customer_name.          "Name 1
volume_estimation_final_s
-hub_carrier_id      = ve_obj->hub_carrier_id.        "Carrier ID
volume_estimation_final_s
-hub_carrier_name    = ve_obj->hub_carrier_name.      "Name 1
volume_estimation_final_s
-carrier_id          = ve_obj->carrier_id.            "Carrier ID
volume_estimation_final_s
-carrier_name        = ve_obj->carrier_name.          "Name 1
volume_estimation_final_s
-amount              = ve_obj->amount.                "Amount
volume_estimation_final_s
-weight              = ve_obj->weight.                "Gross Weight
volume_estimation_final_s
-weight_uom          = ve_obj->weight_uom.            "Weight Unit


APPEND volume_estimation_final_s TO volume_estimate_final_t.
CLEAR volume_estimation_final_s.

ENDLOOP.

ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DL_VOL_ESTIMATION_MODEL->PUOPULATE_FIELD_CATALOG
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD puopulate_field_catalog.

**********************************************************************
* Date          Username  Chg Req/Incident      Description
* 22.10.2014    BISWAJO  U148 Transportation  Volume estimation for
*                        Portal                cross dock deliveries
*
**********************************************************************

DATA: fieldcat_s      TYPE slis_fieldcat_alv.

CONSTANTS: co_mandt                TYPE char30  VALUE 'MANDT',                      "Client
co_shipping_point       
TYPE char30  VALUE 'SHIPPING_POINT',            "Shipping Point/Receiving Point
co_route               
TYPE char30  VALUE 'ROUTE',                      "Route
co_route_schedule       
TYPE char30  VALUE 'ROUTE_SCHEDULE',            "Route Schedule
co_customer_number     
TYPE char30  VALUE 'CUSTOMER_NUMBER',            "Customer Number
co_tran_group           
TYPE char30  VALUE 'TRAN_GROUP',                "Transportation Group
co_pack_mat_no         
TYPE char30  VALUE 'PACK_MAT_NO',                "Packaging Materials
co_counter_name         
TYPE char10  VALUE 'COUNTER',                    "Counter
co_issue_date           
TYPE char30  VALUE 'ISSUE_DATE',                "Goods Issue Date
co_license_plate       
TYPE char30  VALUE 'LICENSE_PLATE',              "Vehicle Licence Plate
co_dest_zone           
TYPE char30  VALUE 'DEST_ZONE',                  "Transportation zone to or from which the goods are delivered
co_depa_zone           
TYPE char30  VALUE 'DEPA_ZONE',                  "Departure zone
co_status               
TYPE char30  VALUE 'STATUS',                    "Status of the Record
co_dropping_sequence   
TYPE char30  VALUE 'DROPPING_SEQUENCE',          "Dropping Sequence
co_freight_group       
TYPE char30  VALUE 'FREIGHT_GROUP',              "Article freight group
co_door                 
TYPE char30  VALUE 'DOOR',                      "Door Information
co_delivery_date       
TYPE char30  VALUE 'DELIVERY_DATE',              "Delivery date
co_delivery_time       
TYPE char30  VALUE 'DELIVERY_TIME',              "Time of delivery
co_issue_time           
TYPE char30  VALUE 'ISSUE_TIME',                "Time of Goods Issue (Local, Relating to a Site)
co_customer_name       
TYPE char30  VALUE 'CUSTOMER_NAME',              "Name 1
co_hub_carrier_id       
TYPE char30  VALUE 'HUB_CARRIER_ID',            "Carrier ID
co_hub_carrier_name     
TYPE char30  VALUE 'HUB_CARRIER_NAME',          "Name 1
co_carrier_id           
TYPE char30  VALUE 'CARRIER_ID',                "Carrier ID
co_carrier_name         
TYPE char30  VALUE 'CARRIER_NAME',              "Name 1
co_amount               
TYPE char30  VALUE 'AMOUNT',                    "Amount
co_weight               
TYPE char30  VALUE 'WEIGHT',                    "Gross Weight
weight_uom             
TYPE char30  VALUE 'WEIGHT_UOM'.                "Weight Unit

**Start of Processing
**Defne Macro for fieldcat

DEFINE fieldcat.
fieldcat_s
-col_pos  = &1.
fieldcat_s
-fieldname = &2.
fieldcat_s
-seltext_l = &3.
append fieldcat_s to fieldcatalog_t.
clear fieldcat_s .
END-OF-DEFINITION.

fieldcat
'1'  co_mandt                  text-001 .                                    "Client
fieldcat
'2'  co_shipping_point        text-002 .                                    "Shipping Point/Receiving Point
fieldcat
'3'  co_route                  text-003 .                                    "Route
fieldcat
'4'  co_route_schedule        text-004 .                                    "Route Schedule
fieldcat
'5'  co_customer_number        text-005 .                                    "Customer Number
fieldcat
'6'  co_tran_group            text-006 .                                    "Transportation Group
fieldcat
'7'  co_pack_mat_no            text-007 .                                    "Packaging Materials
fieldcat
'8'  co_counter_name          text-008 .                                    "Counter
fieldcat
'9'  co_issue_date            text-009 .                                    "Goods Issue Date
fieldcat
'10' co_license_plate          text-010 .                                    "Vehicle Licence Plate
fieldcat
'11' co_dest_zone              text-011 .                                    "Transportation zone to or from which the goods are delivered
fieldcat
'12' co_depa_zone              text-012 .                                    "Departure zone
fieldcat
'13' co_status                text-013 .                                    "Status of the Record
fieldcat
'14' co_dropping_sequence      text-014 .                                    "Dropping Sequence
fieldcat
'15' co_freight_group          text-015 .                                    "Article freight group
fieldcat
'16' co_door                  text-016 .                                    "Door Information
fieldcat
'17' co_delivery_date          text-017 .                                    "Delivery date
fieldcat
'18' co_delivery_time          text-018 .                                    "Time of delivery
fieldcat
'19' co_issue_time            text-019 .                                    "Time of Goods Issue (Local, Relating to a Site)
fieldcat
'20' co_customer_name          text-020 .                                    "Name 1
fieldcat
'21' co_hub_carrier_id        text-021 .                                    "Carrier ID
fieldcat
'22' co_hub_carrier_name      text-022 .                                    "Name 1
fieldcat
'23' co_carrier_id            text-023 .                                    "Carrier ID
fieldcat
'24' co_carrier_name          text-024 .                                    "Name 1
fieldcat
'25' co_amount                text-025 .                                    "Amount
fieldcat
'26' co_weight                text-026 .                                    "Gross Weight
fieldcat
'27' weight_uom                text-027 .                                    "Weight Unit


ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DL_VOL_ESTIMATION_MODEL->RETRIEVE_VE_DETAILS
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD retrieve_ve_details.

**********************************************************************
* Date          Username  Chg Req/Incident      Description
* 21.10.2014    BISWAJO  U148 Transportation  Volume estimation for
*                        Portal                cross dock deliveries
*
**********************************************************************

CREATE OBJECT lo_ve_control.
me
->ve_list = lo_ve_control->get_volume_estimation_details( me->filter ).
ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_DL_VOL_ESTIMATION_MODEL->SET_FILTER
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_DELIVERY                    TYPE        RANGE_DELIVERY
* | [--->] I_TR_GROUP                    TYPE        RANGE_TR_GROUP
* | [--->] I_CR_DATE                      TYPE        RANGE_CR_DATE
* | [--->] I_CR_TIME                      TYPE        RANGE_CR_TIME
* | [--->] I_SHP_PNT                      TYPE        RANGE_SHP_PNT
* | [--->] I_ROUTE                        TYPE        RANGE_ROUTE
* | [--->] I_DLV_NUM                      TYPE        RANGE_DLV_NUM
* | [--->] I_TEST_RUN                    TYPE        CHAR1
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD set_filter.

**********************************************************************
* Date          Username  Chg Req/Incident      Description
* 22.10.2014    BISWAJO  U148 Transportation  Volume estimation for
*                        Portal                cross dock deliveries
*
**********************************************************************

me
->filter-delivery        = i_delivery.                    "Delivery Type
me
->filter-tr_group        = i_tr_group.                    "Transportation Group
me
->filter-cr_date        = i_cr_date.                    "Date on Which Record Was Created
me
->filter-cr_time        = i_cr_time.                    "Entry time
me
->filter-shp_pnt        = i_shp_pnt.                    "Shipping Point/Receiving Point
me
->filter-route          = i_route.                      "Route
me
->filter-dlv_num        = i_dlv_num.                    "Delivery
me
->filter-test_run_flag  = i_test_run.                    "Checkbox for Test Run

ENDMETHOD.                    "SET_FILTER
ENDCLASS.



 

 

 

This will call the Controller class to provide the fetching logic and by using Persistent class, it will update the Database table as well as Log Table.

 

Thanks & Regards,

Joyjit Biswas

Add line items automatically in VA01 - Sales Order Create

$
0
0

Add a line item automatically when a user clicks on save to sales order in VA01

 

 

Limitations:

 

There is a long list of user-exits present in SD module that facilitate customization to the standard process. However, no User exits , Customer Exits or BADI's have been provided which can add an item automatically to Sales Order.

 

 

Expectations:

 

To add an item manually in a SO the only input required from the user is the material number and quantity. Rest all the information is determined automatically by the standard code.The automatic addition of item should take care of below points.

 

      • The only required input should be material number and quantity.
      • Item number ( VBAP-POSNR ) should be auto determined.
      • Item category and other item details should be read from master data / configuration tables.
      • Schedule line data to be determined as for a normal manually added item.
      • Pricing should be determined automatically.
      • Any code written in user exits should be triggered for this item as well.

 

Approach Followed:


We will be using  USEREXIT_MOVE_FIELD_TO_VBAK to write our code. This userexit is present in include MV45AFZZ of program SAPMV45A.

 

This user exit is used to transfer some fields to the sales order header.However , we will write our code in this exit to add an item during save.

 

Code:

 

*--Check if the user has pressed SAVE button

IF sy-ucomm EQ 'SICH'.

 

*--Read table XVBAP to check if the material is not already added

 

           READ TABLE xvbap INTO ls_xvbap WITH KEY matnr = 000000000000240000

                                                     updkz = 'I'.

           IF sy-subrc NE 0.

 

             CLEAR: vbap.

 

*--Initialize workareas for VBAP and VBEP


             PERFORM vbap_unterlegen(sapfv45p).

 

             PERFORM vbep_unterlegen(sapfv45e).

 

*--Populate material number and quantity

 

             vbap-matnr     = ‘000000000000240000’.

             rv45a-kwmeng   = 1000.

 

*--Call standard performs to populate material details.

*--Perform for material validations and details

             PERFORM vbap-matnr_pruefen(sapfv45p) USING charx sy-subrc.

 

*--Perform for item category determination. This will take care of substitution items if any for this material.

             PERFORM vbap-pstyv_pruefen(sapfv45p).

 

*--Perform for filling VBAP with default values from configuration and master tables

             PERFORM vbap_fuellen(sapfv45p).

 

             PERFORM vbap-matnr_null_pruefen(sapfv45p).

             PERFORM vbep-wmeng_setzen(sapfv45e).

 

*--Perform to check sales unit

             PERFORM vbap-vrkme_pruefen(sapfv45p) USING charx

                   CHANGING sy-subrc sy-msgid sy-msgty sy-msgno

                            sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

 

*--Perform to update VBAP values

             PERFORM vbap_bearbeiten(sapfv45p).

 

*--Perform for filling VBEP with default values. This will take care of schedule lines of the item

             PERFORM vbep_fuellen(sapfv45e).

 

*--Perform to check quantity

             PERFORM vbep-wmeng_pruefen(sapfv45e) USING charx

                   CHANGING sy-subrc sy-msgid sy-msgty sy-msgno

                            sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

 

*--Perform to update VBEP values

             PERFORM vbep_bearbeiten(sapfv45e).

 

*--Perform to fill conditions and pricing data

             PERFORM vbap_bearbeiten_ende(sapfv45p).

 

           ENDIF.

         ENDIF.

 

 

 

Execution Snapshots:

 

 

Go to VA01 to create a sales order. Enter sold to party and other details. Add 1 item manually.

 

1.png

 

Click on save, item 240000 should be item as next item ( POSNR 20 ).


2.png

Check the SO in VA03. Here the item 20 is added successfully.


3.png



Check line item schedule line data:


4.png

 

Check Pricing data:

 

5.png

 

Thus , we see in this way a line item can be added automatically in the sales order.

 

Advantages:

 

  • The item addition can be done on the basis of certain conditions and multiple items can be added by placing this code in a loop.
  • Since all standard performs are called to fill the data , even the different user-exits for item will be triggered if implemented for the item.
  • By adding a check for call_bapi equal to 'X' and TRTYP eq 'H' , this code can be executed from Create Sales Order BAPI also.
  • Item number is determined automatically.
  • Item category , item substitution, scheduling , availability check and pricing is done by standard performs.
  • If the requirement is to add items just as the user enters the header details, that can be done with minimum code changes.

 

Use Cases:

 

This can be used in certain business scenarios like:

 

  • Suppose based on the customer some free items need to be added to sales order. In such case the item ( material ) and customer combination can be stored in a custom table. It can be then read from and populated automatically.

 

  • It can also be used if some default material has to be added to all sales orders being created.

 

EDIT:


  • The above code can also be written in user exit  USEREXIT_SAVE_DOCUMENT_PREPARE.


  • Sometime the requirement can be to delete a line item internally using code.Below is the code for this

        Suppose we want  to delete the item number 20.


        ivbap-selkz = 'X'.

        MODIFY ivbap TRANSPORTING selkz WHERE posnr = '0020'.

        IF sy-subrc EQ 0.

          PERFORM xvbap_loeschen_loop(sapfv45p).

        ENDIF.



Help Taken from below SCN posts:


Re: New line  in SD order

Re: Adding default line items on VA01/VA21 based on Incoterms




Note:


Sensitive data has been blurred in the snapshots.

 

Feel free to provide feedback and valuable comments.

 

  • ~ Tanmay

Deriving the Translation Date from Document Date – Step by Step

$
0
0

The SAP folks working in SAP FI must be familiar with this concept. Just to give a brief introduction, Translation date is a date which is used to convert the foreign currency to local currency. Since the exchange rate is picked based on the translation date, it is a very critical date component. In standard SAP, translation date is automatically derived from posting date.

 

This document will walk you through the step by step procedure of deriving the translation date automatically from document date.

 

Before going any further, let us make a few terminologies clear:

BUDAT: Posting Date (date when document is posted)

BLDAT: Document Date/Invoice Date (date when document is entered/parked)

WWERT: Translation Date (date used to pick the exchange rates)

 

This change of date can be realized by implementation of a BADI FI_TRANS_DRIVE_WWERT. This BADI is called by function module FI_DERIVE_WWERT. Following is the step by step procedure for the same.

 

  1. Go to T-Code SE19, in the “create implementation” part and give the BADI’s name:-

Pic1.jpg

 

     2. Then, the following dialog box appears, enter the implementation name:-

pic2.jpg

     3. In the next screen, give the short description.

pic3.jpg

         4. Go to the interface tab and enter the name of the implementing class. (ZCL_IM_DERIVE_WWERT_BUDAT in this case). This will be a Z class that                will implement that interface IF_EX_FI_TRANS_DATE_DERIVE which has one method: DERIVE_WWERT.

pic4.jpg

Here, double click on the DERIVE_WWERT method and the following editor will open where you can write your piece of code.

pic5.jpg

As per this case, the code can be like the following:-

METHOD if_ex_fi_trans_date_derive~derive_wwert.
e_wwert
= i_bldat.
ENDMETHOD.

 

     5. Save the code and activate it. Save and activate the BADI implementation as well.

     6. Now is the time to test this. For this go to FV60/65 and enter an invoice. After enter the header details, go to the “Local Currency” tab and check the                  translation date. It should be same as the document date.

             pic6.jpgpic7.jpg

Hope it was useful. Please feel free to share your questions or comments if any.

Thanks,

Arashdeep

Viewing all 935 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>