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

Finding a user exit - code to do so

$
0
0

This is some code that I have archived on another site:

 

It specifies in it's initial comments the primary contributers to the best of my knowledge.

 

Good luck!

 

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

*& Report  Z_FIND_USEREXIT_RNW

*&

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

*&

*&

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

 

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

*& Report  Z_FIND_EXIT

*&

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

*&

 

*I'm thinking that this is based on a post by

*

*SimonaD86 in http://sap.

*ittoolbox.com/groups/technical-functional/sap-abap/determinate-the-transaction-that-called-a-certain-userexitfrom-the-user-exit-2760810

*

*or  santoshkj in http://sap.

*ittoolbox.com/groups/technical-functional/sap-dev/developing-screen-exits-in-sap-520079

*

*or Deertay in http://sap.

*ittoolbox.com/groups/technical-functional/sap-dev/user-exit-for-a-transaction-code-mb1bmigo-1155130

 

 

*&

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

 

REPORT  z_find_exit.

 

TABLES : tstc,

         tadir,

         modsapt,

         modact,

         trdir,

         tfdir,

         enlfdir,

         sxs_attrt ,

         tstct.

 

DATA : jtab LIKE tadir OCCURS 0 WITH HEADER LINE.

DATA : field1(30).

DATA : v_devclass LIKE tadir-devclass.

 

PARAMETERS : p_tcode LIKE tstc-tcode,

             p_pgmna LIKE tstc-pgmna .

 

DATA wa_tadir TYPE tadir.

 

START-OF-SELECTION.

 

  IF NOT p_tcode IS INITIAL.

    SELECT SINGLE * FROM tstc WHERE tcode EQ p_tcode.

 

  ELSEIF NOT p_pgmna IS INITIAL.

    tstc-pgmna = p_pgmna.

  ENDIF.

 

  IF sy-subrc EQ 0.

    SELECT SINGLE * FROM tadir

           WHERE pgmid = 'R3TR'

             AND object = 'PROG'

             AND obj_name = tstc-pgmna.

 

    MOVE : tadir-devclass TO v_devclass.

 

    IF sy-subrc NE 0.

      SELECT SINGLE * FROM trdir

             WHERE name = tstc-pgmna.

      IF trdir-subc EQ 'F'.

        SELECT SINGLE * FROM tfdir

               WHERE pname = tstc-pgmna.

 

        SELECT SINGLE * FROM enlfdir

               WHERE funcname = tfdir-funcname.

 

        SELECT SINGLE * FROM tadir

               WHERE pgmid = 'R3TR'

                 AND object = 'FUGR'

                 AND obj_name EQ enlfdir-area.

 

        MOVE : tadir-devclass TO v_devclass.

      ENDIF.

    ENDIF.

 

    SELECT * FROM tadir INTO TABLE jtab

           WHERE pgmid = 'R3TR'

             AND object IN ('SMOD', 'SXSD')

             AND devclass = v_devclass.

 

    SELECT SINGLE * FROM tstct

           WHERE sprsl EQ sy-langu

             AND tcode EQ p_tcode.

 

    FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.

    WRITE:/001(19) 'Transaction Code - ',

           020(20) p_tcode,

           045(50) tstct-ttext.

    SKIP.

    IF NOT jtab[] IS INITIAL.

      WRITE:/(105) sy-uline.

      FORMAT COLOR COL_HEADING INTENSIFIED ON.

 

*Sorting the internal Table

      SORT jtab BY object.

      DATA : wf_txt(60) TYPE c,

             wf_smod TYPE i ,

             wf_badi TYPE i ,

             wf_object2(30) TYPE c.

      CLEAR : wf_smod, wf_badi , wf_object2.

 

*Get the total SMOD.

 

      LOOP AT jtab INTO wa_tadir.

 

        AT FIRST.

          FORMAT COLOR COL_HEADING INTENSIFIED ON.

 

          WRITE:/1 sy-vline,

          2 'Enhancement/ Business Add-in',

          41 sy-vline ,

          42 'Description',

          105 sy-vline.

          WRITE:/(105) sy-uline.

        ENDAT.

        CLEAR wf_txt.

 

        AT NEW object.

          IF wa_tadir-object = 'SMOD'.

            wf_object2 = 'Enhancement' .

          ELSEIF wa_tadir-object = 'SXSD'.

            wf_object2 = ' Business Add-in'.

 

          ENDIF.

          FORMAT COLOR COL_GROUP INTENSIFIED ON.

 

          WRITE:/1 sy-vline,

 

          2 wf_object2,

          105 sy-vline.

        ENDAT.

 

        CASE wa_tadir-object.

          WHEN 'SMOD'.

            wf_smod = wf_smod + 1.

            SELECT SINGLE modtext INTO wf_txt

            FROM modsapt

            WHERE sprsl = sy-langu

            AND name = wa_tadir-obj_name.

            FORMAT COLOR COL_NORMAL INTENSIFIED OFF.

 

          WHEN 'SXSD'.

 

*For BADis

            wf_badi = wf_badi + 1 .

            SELECT SINGLE text INTO wf_txt

            FROM sxs_attrt

            WHERE sprsl = sy-langu

            AND exit_name = wa_tadir-obj_name.

            FORMAT COLOR COL_NORMAL INTENSIFIED ON.

 

        ENDCASE.

 

        WRITE:/001 sy-vline,

               002 wa_tadir-obj_name HOTSPOT ON,

               041 sy-vline ,

               042 wf_txt,

               105 sy-vline.

        AT END OF object.

          WRITE : /(105) sy-uline.

        ENDAT.

 

      ENDLOOP.

 

      WRITE:/(105) sy-uline.

 

      SKIP.

      FORMAT COLOR COL_TOTAL INTENSIFIED ON.

      WRITE:/ 'No. of Exits:' , wf_smod.

      WRITE:/ 'No. of BADis:' , wf_badi.

 

    ELSE.

      FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.

      WRITE:/(105) 'No userexits or BADis exist'.

    ENDIF.

  ELSE.

    FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.

    WRITE:/(105) 'Transaction does not exist'.

  ENDIF.

 

AT LINE-SELECTION.

 

  DATA : wf_object TYPE tadir-object.

  CLEAR wf_object.

 

  GET CURSOR FIELD field1.

  CHECK field1(8) EQ 'WA_TADIR'.

  READ TABLE jtab WITH KEY obj_name = sy-lisel+1(20).

  MOVE jtab-object TO wf_object.

 

  CASE wf_object.

    WHEN 'SMOD'.

      SET PARAMETER ID 'MON' FIELD sy-lisel+1(10).

 

      CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.

    WHEN 'SXSD'.

      SET PARAMETER ID 'EXN' FIELD sy-lisel+1(20).

      CALL TRANSACTION 'SE18' AND SKIP FIRST SCREEN.

  ENDCASE.


Integer Arithmetic Operations on Large Numbers

$
0
0

Maximum positive value that can be stored by integer type variable in ABAP is 2147483647.

For values beyond maximum limit of integer variable, workarounds can be used.

One such example is discussion MOD operation fail for large numbers started by Starlet Abraham

I was able to calculate correct result of 512^17 MOD 2773 using the methods detailed below.

 

I have written this program to do following operations on large integers.

  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Mod
  • Power

 

Full code snippet is posted at the end of this document.

Program has its flaws, but it works.

I would briefly go through how the logic works.

 

How are big numbers stored?

Local class lcl_bignum has instance attributes that store big numbers.

LV_STRING - Number stored as string type.

LT_INT - an internal table of integers. The string is broken into substrings of size 4 (base 10000), and those substrings ( as int4 ) are stored in internal table.

LV_SIGN - integer type to store the sign of number. +1 for positive, -1 for negative.

For example, number 1234567890 will be stored in internal table as

 

LT_INT
7890
3456
12

 

 

 

Why is number broken into base 10000?

Base 10000 is safe considering the capacity of integer variable type in ABAP.

Computing 9999 * 9999 results in 99980001, which is within the limits of integer type.

On the other hand, 99999 * 99999 results in 999980001, which would lead to overflow exception.

 

How to create instance and store big number?

Below code snippets can be used to create instance of big number.

The constructor parameters are options.

CREATE OBJECT lr3.

 

--

Above code will create instance with zero value in it.

 

CREATE OBJECT lr2
  EXPORTING
    i_value = '533335555511111'.

--

Above code will create instance and populate lv_string and lt_int by breaking down input string.

Sign of number is positive by default.

Input string should have only numbers in it.

 

CREATE OBJECT lr1
  EXPORTING
    i_value = '6584389034291301828999'
    i_negative = 'X'.

--

Using above code, 'X' can be passed i_negative flag if we have a negative number.

 

How to add numbers?

Instance method Add( ) can be used for adding numbers.

It accepts 2 object reference that need to be added, and result is stored in object whose method gets called.

We are adding the numbers starting lowest weightage (LT_INT[1]), and carrying forward extra in case of overflow.

For example, we add 12345678 and 22223333. Program would add (5678,3333) first, and then (1234,2222).

For A = B + C, below code can be used.

 

lr3->add( i_obj1 = lr1
          i_obj2 = lr2 ).

--

For A = A + B, below code can be used.

 

lr3->add( i_obj1 = lr3
          i_obj2 = lr2 ).

--

 

How to subtract numbers?

Instance method Subtract( ) can be used for subtracting numbers.

The usage is same as Add( ) method.

 

Looking at code, you would see that Add( ) and Subtract( ) are calling each other.

It is done the tackle how absolute values are treated depending on their sign.

For example, A = B + C, the values of B and C will be added, and common sign will be retained if B and C have same sign. Both positive, or both negative.

If the signs of B and C are different, we essentially have to keep sign of B, and calculate |B| - |C| (absolute values).

 

How to multiply numbers?

Instance method Multiply( ) can be used.

It accepts 2 object references, and stores result in calling object.

I would explain the logic using example. It is similar to the method used in elementary school.

For elementary example of multiplying 123 and 456, below logic is used.

123

456

===

3*6 + (3*5+2*6) + (3*4+2*5+1*6) + (2*4+1*5) + 1*4

Same thing is done in program at base 10000 level.

At every stage we are carrying forward the overflow value.

 

How to divide numbers?

For division, I am guessing the answer by multiplying.

Something like binary search, I start with 1 as answer, keep on multiplying it by 10000 still answer crosses dividend.

Once the guess surpasses dividend, I take a step back, and start multiplying by square root of 10000.

A point comes when multiplier is reduced to 1, and multiplication can no longer be used to get closer to answer.

I then use addition to get closer to answer. Instead of square root, divide by 2 to get next "jump value".

A dry run using elementary example would be something like this.

451

4

---

 

How to do calculate remainder (MOD operation)

Instance method Mod( ) can be used, which internally uses Divide( ), Multiply( ) and Subtract( ).

To calculate A = B MOD C, program does something like:

A = B - C * ( B DIV C )

Here we are reusing the code written in previous methods.

 

How to calculate Power?

Instance method Power( ) can be used, which internally uses Multiply( ) and Subtract( ).

For calculating A = B POWER C, program starts with 1 as answer, uses loop to multiply B to answer, C number of times.

 

Full code snippet

  1. *----------------------------------------------------------------------*
  2. *       CLASS lcl_bignum DEFINITION
  3. *----------------------------------------------------------------------*
  4. *
  5. *----------------------------------------------------------------------*
  6. CLASS lcl_bignum DEFINITION.
  7.   PUBLICSECTION.
  8.     METHODS constructor IMPORTING i_value TYPE string OPTIONAL
  9.                     i_negative  TYPEcOPTIONAL.
  10.     METHODS get_sign RETURNING value(r_sign) TYPEi.
  11.     METHODS get_string RETURNING value(r_string) TYPE string.
  12.     METHODS get_int RETURNING value(r_int) TYPE int4_table.
  13.     METHODS set_data IMPORTING i_value TYPE string
  14.                    i_negative TYPEcOPTIONAL.
  15.     METHODSaddIMPORTING i_obj1 TYPEREFTO lcl_bignum
  16.                 i_obj2 TYPEREFTO lcl_bignum.
  17.     METHODSsubtractIMPORTING  i_obj1 TYPEREFTO lcl_bignum
  18.                   i_obj2 TYPEREFTO lcl_bignum.
  19.     METHODSmultiplyIMPORTING  i_obj1 TYPEREFTO lcl_bignum
  20.                   i_obj2 TYPEREFTO lcl_bignum.
  21.     METHODSdivideIMPORTING i_obj1 TYPEREFTO lcl_bignum
  22.                  i_obj2 TYPEREFTO lcl_bignum.
  23.     METHODSmodIMPORTING i_obj1 TYPEREFTO lcl_bignum
  24.                 i_obj2 TYPEREFTO lcl_bignum.
  25.     METHODS power IMPORTING i_obj1 TYPEREFTO lcl_bignum
  26.                 i_obj2 TYPEREFTO lcl_bignum.
  27.     METHODS invert_sign.
  28.     METHODS copy_values IMPORTING i_obj TYPEREFTO lcl_bignum.
  29.     METHODS abs_compare IMPORTING i_obj TYPEREFTO lcl_bignum
  30.               RETURNING value(r_result) TYPEi.
  31.   PROTECTEDSECTION.
  32.     METHODS int_to_string.
  33.     METHODS split_into_int.
  34.     METHODS delete_leading_zeros.
  35.     METHODS divide_by_2.
  36.   PRIVATESECTION.
  37.     DATA lv_string TYPE string.
  38.     DATA lv_sign TYPEiVALUE1.
  39.     DATA lt_int TYPE int4_table.
  40.     "sqrt of max int4 is 46340
  41.     CONSTANTS: gc_unit_size TYPEiVALUE10000,
  42.            gc_unit_digits TYPEiVALUE4,
  43.            gc_gt TYPEiVALUE1"greater than
  44.            gc_lt TYPEiVALUE2"less than
  45.            gc_eq TYPEiVALUE0"equals
  46. ENDCLASS.                    "lcl_bignum DEFINITION
  47. *----------------------------------------------------------------------*
  48. *       CLASS lcl_bignum IMPLEMENTATION
  49. *----------------------------------------------------------------------*
  50. *
  51. *----------------------------------------------------------------------*
  52. CLASS lcl_bignum IMPLEMENTATION.
  53.   METHOD constructor.
  54.     IF i_value ISSUPPLIED.
  55.       IF i_value CO' 1234567890'.
  56.         lv_string = i_value.
  57.         CONDENSE lv_string.
  58.       ENDIF.
  59.       split_into_int( ).
  60.     ENDIF.
  61.     IF i_negative ISSUPPLIED.
  62.       IF i_negative EQ'X'.
  63.         lv_sign = -1.
  64.       ENDIF.
  65.     ENDIF.
  66.   ENDMETHOD.                    "constructor
  67.   METHOD set_data.
  68.     CLEAR: lv_string, lt_int.
  69.     lv_sign = 1.
  70.     IF i_value CO' 1234567890'.
  71.       lv_string = i_value.
  72.       CONDENSE lv_string.
  73.     ENDIF.
  74.     split_into_int( ).
  75.     IF i_negative ISSUPPLIED.
  76.       IF i_negative EQ'X'.
  77.         lv_sign = -1.
  78.       ENDIF.
  79.     ENDIF.
  80.   ENDMETHOD.                    "set_data
  81.   METHOD split_into_int.
  82.     DATA lv_string TYPE string.
  83.     DATA lv_int TYPEi.
  84.     lv_string = me->lv_string.
  85.     WHILE lv_string ISNOTINITIAL.
  86.       IFSTRLEN( lv_string ) GT gc_unit_digits.
  87.         SHIFT lv_string RIGHT BY gc_unit_digits PLACES CIRCULAR.
  88.         lv_int = lv_string+0(gc_unit_digits).
  89.         SHIFT lv_string LEFTBY gc_unit_digits PLACES.
  90.       ELSE.
  91.         lv_int = lv_string.
  92.         CLEAR lv_string.
  93.       ENDIF.
  94. *      INSERT lv_int INTO lt_int INDEX 1.
  95.       APPEND lv_int TO lt_int.
  96.     ENDWHILE.
  97.   ENDMETHOD.                    "split_into_int
  98.   METHOD delete_leading_zeros.
  99.     DATA: lt_temp TYPE int4_table,
  100.         lv_temp TYPEi,
  101.         lv_count TYPEi.
  102.     CHECK lt_int ISNOTINITIAL.
  103.     lt_temp = lt_int.
  104.     CLEAR lt_int.
  105.     lv_count = LINES( lt_temp ).
  106.     DO lv_count TIMES.
  107.       READTABLE lt_temp INTO lv_temp INDEX lv_count.
  108.       IF lv_temp ISNOTINITIAL.
  109.         EXIT.
  110.       ENDIF.
  111.       lv_count = lv_count - 1.
  112.     ENDDO.
  113.     IF lv_count ISNOTINITIALAND
  114.        lv_count LELINES( lt_temp ).
  115.       APPENDLINESOF lt_temp FROM1TO lv_count TO lt_int.
  116.     ENDIF.
  117.   ENDMETHOD.                    "delete_leading_zeros
  118.   METHOD int_to_string.
  119.     DATA lv_int TYPEi.
  120.     DATA lv_char TYPE n LENGTH gc_unit_digits.
  121.     LOOPAT lt_int INTO lv_int.
  122.       lv_char = lv_int.
  123.       CONCATENATE lv_char lv_string INTO lv_string.
  124.     ENDLOOP.
  125.     SHIFT lv_string LEFT DELETING LEADING'0'.
  126.   ENDMETHOD.                    "int_to_string
  127.   METHOD get_int.
  128.     r_int = lt_int.
  129.   ENDMETHOD.                    "get_int
  130.   METHOD get_sign.
  131.     r_sign = lv_sign.
  132.   ENDMETHOD.                    "get_sign
  133.   METHOD get_string.
  134.     r_string = lv_string.
  135.   ENDMETHOD.                    "get_string
  136.   METHOD copy_values.
  137.     lv_string = i_obj->get_string( ).
  138.     lv_sign = i_obj->get_sign( ).
  139.     lt_int = i_obj->get_int( ).
  140.   ENDMETHOD.                    "copy_values
  141.   METHOD abs_compare.
  142.     DATA: lt_int2 TYPE int4_table,
  143.         lv_int TYPEi,
  144.         lv_int2 TYPEi,
  145.         lv_max TYPEi.
  146.     lt_int2 = i_obj->get_int( ).
  147.     lv_max = LINES( lt_int ).
  148.     IFLINES( lt_int2 ) GT lv_max.
  149.       lv_max = LINES( lt_int2 ).
  150.     ENDIF.
  151.     WHILE lv_max GT0.
  152.       CLEAR: lv_int,
  153.          lv_int2.
  154.       READTABLE lt_int INTO lv_int INDEX lv_max.
  155.       READTABLE lt_int2 INTO lv_int2 INDEX lv_max.
  156.       IF lv_int EQ lv_int2.
  157.         lv_max = lv_max - 1.
  158.       ELSE.
  159.         IF lv_int GT lv_int2.
  160.           r_result = gc_gt.
  161.         ELSEIF lv_int LT lv_int2.
  162.           r_result = gc_lt.
  163.         ENDIF.
  164.         EXIT.
  165.       ENDIF.
  166.     ENDWHILE.
  167.   ENDMETHOD.                    "abs_compare
  168.   METHOD divide_by_2.
  169.     DATA: lv_int TYPEi,
  170.         lt_temp TYPE int4_table,
  171.         lv_mod TYPEi,
  172.         lv_count TYPEi.
  173.     lv_count = LINES( lt_int ).
  174.     DO lv_count TIMES.
  175.       READTABLE lt_int INTO lv_int INDEX lv_count.
  176.       IF sy-subrc EQ0.
  177.         lv_int = lv_int + lv_mod * gc_unit_size.
  178.         lv_mod = lv_int MOD2.
  179.         lv_int = lv_int DIV2.
  180.         INSERT lv_int INTO lt_temp INDEX1.
  181.       ENDIF.
  182.       lv_count = lv_count - 1.
  183.     ENDDO.
  184.     lt_int = lt_temp.
  185.     delete_leading_zeros( ).
  186.     int_to_string( ).
  187.   ENDMETHOD.                    "divide_by_2
  188.   METHOD invert_sign.
  189.     lv_sign = lv_sign * -1.
  190.   ENDMETHOD.                    "invert_sign
  191.   METHODadd.
  192.     DATA: lt_int1 TYPE int4_table,
  193.         lt_int2 TYPE int4_table,
  194.         lv_int TYPEi,
  195.         lv_int1 TYPEi,
  196.         lv_int2 TYPEi,
  197.         lv_index TYPEi,
  198.         lv_count TYPEi,
  199.         lv_extra TYPEi.
  200.     lt_int1 = i_obj1->get_int( ).
  201.     lt_int2 = i_obj2->get_int( ).
  202.     IF i_obj1->get_sign( ) NE i_obj2->get_sign( ).
  203.       subtract( i_obj1 = i_obj1
  204.           i_obj2 = i_obj2 ).
  205.       EXIT.
  206.     ENDIF.
  207.     lv_count = LINES( lt_int1 ).
  208.     IF lv_count LTLINES( lt_int2 ).
  209.       lv_count = LINES( lt_int2 ).
  210.     ENDIF.
  211.     CLEAR: lt_int, lv_string.
  212.     lv_sign = i_obj1->get_sign( ).
  213.     DO lv_count TIMES.
  214.       CLEAR: lv_int1,
  215.          lv_int2.
  216.       lv_index = sy-index.
  217.       READTABLE lt_int1 INTO lv_int1 INDEX lv_index.
  218.       READTABLE lt_int2 INTO lv_int2 INDEX lv_index.
  219.       lv_int = lv_extra + lv_int1 + lv_int2.
  220.       lv_extra = lv_int DIV gc_unit_size.
  221.       lv_int = lv_int MOD gc_unit_size.
  222.       APPEND lv_int TO lt_int.
  223.     ENDDO.
  224.     int_to_string( ).
  225.   ENDMETHOD.                    "add
  226.   METHODsubtract.
  227.     DATA: lt_int1 TYPE int4_table,
  228.         lt_int2 TYPE int4_table,
  229.         lv_int TYPEi,
  230.         lv_int1 TYPEi,
  231.         lv_int2 TYPEi,
  232.         lv_index TYPEi,
  233.         lv_count TYPEi,
  234.         lv_extra TYPEi.
  235.     FIELD-SYMBOLS: <fs_int> TYPEi.
  236.     lt_int1 = i_obj1->get_int( ).
  237.     lt_int2 = i_obj2->get_int( ).
  238.     IF i_obj1->get_sign( ) NE i_obj2->get_sign( ).
  239.       i_obj2->invert_sign( ).
  240.       add( i_obj1 = i_obj1
  241.          i_obj2 = i_obj2 ).
  242.       EXIT.
  243.     ENDIF.
  244.     lv_count = LINES( lt_int1 ).
  245.     IF lv_count LTLINES( lt_int2 ).
  246.       lv_count = LINES( lt_int2 ).
  247.     ENDIF.
  248.     CLEAR: lt_int, lv_string.
  249.     lv_sign = i_obj1->get_sign( ).
  250.     DO lv_count TIMES.
  251.       CLEAR: lv_int1,
  252.          lv_int2.
  253.       lv_index = sy-index.
  254.       READTABLE lt_int1 INTO lv_int1 INDEX lv_index.
  255.       READTABLE lt_int2 INTO lv_int2 INDEX lv_index.
  256.       lv_int = lv_extra + lv_int1 - lv_int2.
  257.       CLEAR lv_extra.
  258.       IF lv_int LT0.
  259.         lv_int = lv_int + gc_unit_size.
  260.         lv_extra = -1.
  261.       ENDIF.
  262.       lv_int = lv_int MOD gc_unit_size.
  263.       APPEND lv_int TO lt_int.
  264.     ENDDO.
  265.     IF lv_extra ISNOTINITIAL.
  266.       lv_sign = lv_sign * lv_extra.
  267.       LOOPAT lt_int ASSIGNING<fs_int>.
  268.         IF sy-tabix EQ1.
  269.           <fs_int> = gc_unit_size - <fs_int>.
  270.         ELSE.
  271.           <fs_int> = gc_unit_size - <fs_int> + 1.
  272.         ENDIF.
  273.       ENDLOOP.
  274.     ENDIF.
  275.     delete_leading_zeros( ).
  276.     int_to_string( ).
  277.   ENDMETHOD.                    "subtract
  278.   METHODmultiply.
  279.     DATA: lt_int1 TYPE int4_table,
  280.         lt_int2 TYPE int4_table,
  281.         lv_int TYPEi,
  282.         lv_int1 TYPEi,
  283.         lv_int2 TYPEi,
  284.         lv_int_tmp TYPEi,
  285.         lv_index TYPEi,
  286.         lv_index_start TYPEi,
  287.         lv_index_end   TYPEi,
  288.         lv_index_start_tmp TYPEi,
  289.         lv_index_end_tmp TYPEi,
  290.         lv_count TYPEi,
  291.         lv_carry TYPEi,
  292.         lv_extra TYPEi.
  293.     lt_int1 = i_obj1->get_int( ).
  294.     lt_int2 = i_obj2->get_int( ).
  295.     lv_count = LINES( lt_int1 ).
  296.     IF lv_count LTLINES( lt_int2 ).
  297.       lv_count = LINES( lt_int2 ).
  298.     ENDIF.
  299.     CLEAR: lt_int, lv_string.
  300.     lv_sign = i_obj1->get_sign( ) * i_obj2->get_sign( ).
  301.     CHECK lv_count ISNOTINITIAL.
  302.     lv_index_start = 1.
  303.     lv_index_end   = 1.
  304.     DO.
  305.       CLEAR lv_int.
  306.       lv_index_start_tmp = lv_index_start.
  307.       lv_index_end_tmp   = lv_index_end.
  308.       lv_int = lv_extra.
  309.       CLEAR lv_extra.
  310.       WHILE lv_index_start_tmp LE lv_index_end.
  311.         CLEAR: lv_int1,
  312.              lv_int2.
  313.         READTABLE lt_int1 INTO lv_int1 INDEX lv_index_start_tmp.
  314.         READTABLE lt_int2 INTO lv_int2 INDEX lv_index_end_tmp.
  315.         lv_int_tmp = ( lv_int1 * lv_int2 ) MOD gc_unit_size.
  316.         lv_extra = lv_extra + ( lv_int1 * lv_int2 ) DIV gc_unit_size.
  317.         lv_int = lv_int + lv_int_tmp.
  318.         lv_extra = lv_extra + lv_int DIV gc_unit_size.
  319.         lv_int = lv_int MOD gc_unit_size.
  320.         lv_index_start_tmp = lv_index_start_tmp + 1.
  321.         lv_index_end_tmp = lv_index_end_tmp - 1.
  322.       ENDWHILE.
  323.       APPEND lv_int TO lt_int.
  324.       IF lv_index_end LT lv_count.
  325.         lv_index_end = lv_index_end + 1.
  326.       ELSEIF lv_index_start LT lv_count.
  327.         lv_index_start = lv_index_start + 1.
  328.       ELSEIF lv_index_start EQ lv_count AND
  329.        lv_index_end   EQ lv_count.
  330.         EXIT.
  331.       ENDIF.
  332.     ENDDO.
  333.     IF lv_extra ISNOTINITIAL.
  334.       APPEND lv_extra TO lt_int.
  335.     ENDIF.
  336.     delete_leading_zeros( ).
  337.     int_to_string( ).
  338.   ENDMETHOD.                    "multiply
  339.   METHODdivide.
  340.     DATA: lt_int1 TYPE int4_table,
  341.         lt_int2 TYPE int4_table,
  342.         lv_int TYPEi,
  343.         lv_int1 TYPEi,
  344.         lv_int2 TYPEi,
  345.         lv_string1 TYPE string,
  346.         lv_string2 TYPE string,
  347.         lv_index TYPEi,
  348.         lv_count TYPEi,
  349.         lv_extra TYPEi,
  350.         lv_sign1 TYPEi,
  351.         lr1 TYPEREFTO lcl_bignum,
  352.         lr2 TYPEREFTO lcl_bignum,
  353.         lr_guess TYPEREFTO lcl_bignum,
  354.         lr_step TYPEREFTO lcl_bignum,
  355.         lv_step_str TYPE string,
  356.         lv_step TYPEi,
  357.         lr_temp  TYPEREFTO lcl_bignum.
  358.     CREATE OBJECT lr1.
  359.     CREATE OBJECT lr2.
  360.     lr1->copy_values( i_obj1 ).
  361.     lr2->copy_values( i_obj2 ).
  362. *   quotient is zero when divisor is bigger than dividend
  363.     CHECK lr1->abs_compare( lr2 ) EQ gc_gt.
  364.     IF lr1->get_sign( ) LT0.
  365.       lr1->invert_sign( ).
  366.     ENDIF.
  367.     IF lr2->get_sign( ) LT0.
  368.       lr2->invert_sign( ).
  369.     ENDIF.
  370. * start with 1, keep multiplying by gc_unit_size
  371.     CREATE OBJECT lr_guess
  372.       EXPORTING
  373.         i_value = '1'.
  374.     CREATE OBJECT lr_temp.
  375.     CREATE OBJECT lr_step.
  376.     lv_step = gc_unit_size.
  377.     DO.
  378.       DO.
  379.         lr_temp->multiply( i_obj1 = lr_guess
  380.                    i_obj2 = lr2 ).
  381.         CASE lr_temp->abs_compare( lr1 ).
  382.           WHEN gc_eq.
  383.             copy_values( lr_guess ).
  384.             RETURN.
  385.           WHEN gc_gt.
  386.             EXIT.
  387.           WHEN gc_lt.
  388. * increment
  389. *            lv_step = gc_unit_size.
  390.             copy_values( lr_guess ).
  391.             lv_step_str = lv_step.
  392.             lr_step->set_data( lv_step_str ).
  393.             lr_guess->multiply( i_obj1 = lr_guess
  394.                       i_obj2 = lr_step ).
  395. *        when others.
  396.         ENDCASE.
  397.       ENDDO.
  398.       lr_guess->copy_values( me ).
  399.       lv_step = SQRT( lv_step ).
  400.       IF lv_step EQ1.
  401.         EXIT.
  402.       ENDIF.
  403.     ENDDO.
  404. * answer is between guess and guess * 2
  405. * now add steps to move closer to answer
  406. *    lv_step = gc_unit_size.
  407.     lr_step->copy_values( lr_guess ).
  408.     DO.
  409.       DO.
  410.         lr_temp->multiply( i_obj1 = lr_guess
  411.                    i_obj2 = lr2 ).
  412.         CASE lr_temp->abs_compare( lr1 ).
  413.           WHEN gc_eq.
  414.             copy_values( lr_guess ).
  415.             RETURN.
  416.           WHEN gc_gt.
  417.             EXIT.
  418.           WHEN gc_lt.
  419. * increment
  420.             copy_values( lr_guess ).
  421.             lr_guess->add( i_obj1 = lr_guess
  422.                      i_obj2 = lr_step ).
  423. *        when others.
  424.         ENDCASE.
  425.       ENDDO.
  426.       lr_guess->copy_values( me ).
  427. * quick way to divide by 2
  428.       lr_step->divide_by_2( ).
  429.       IF lr_step->get_int( ) ISINITIAL.
  430.         EXIT.
  431.       ENDIF.
  432.     ENDDO.
  433. *    int_to_string( ).
  434.   ENDMETHOD.                    "divide
  435.   METHODmod.
  436.     DATA lr_div TYPEREFTO lcl_bignum.
  437.     CREATE OBJECT lr_div.
  438.     lr_div->divide( i_obj1 = i_obj1
  439.             i_obj2 = i_obj2 ).
  440.     lr_div->multiply( i_obj1 = lr_div
  441.               i_obj2 = i_obj2 ).
  442.     subtract( i_obj1 = i_obj1
  443.           i_obj2 = lr_div ).
  444.   ENDMETHOD.                    "mod
  445.   METHOD power.
  446.     DATA: lr_power TYPEREFTO lcl_bignum,
  447.         lr_one   TYPEREFTO lcl_bignum.
  448.     CREATE OBJECT lr_one
  449.       EXPORTING
  450.         i_value = '1'.
  451.     CREATE OBJECT lr_power.
  452.     lr_power->copy_values( i_obj2 ).
  453.     lr_power->delete_leading_zeros( ).
  454. * only positive power
  455.     IF get_sign( ) NE lr_power->get_sign( ).
  456.       lr_power->invert_sign( ).
  457.     ENDIF.
  458. * result 1 when power is 0
  459.     set_data( '1' ).
  460.     DO.
  461.       IF lr_power->get_int( ) ISINITIAL.
  462.         EXIT.
  463.       ELSE.
  464.         lr_power->subtract( i_obj1 = lr_power
  465.                   i_obj2 = lr_one ).
  466.         multiply( i_obj1 = me
  467.               i_obj2 = i_obj1 ).
  468.       ENDIF.
  469.     ENDDO.
  470.   ENDMETHOD.                    "power
  471. ENDCLASS.                    "lcl_bignum IMPLEMENTATION
  472. START-OF-SELECTION.
  473.   DATA lr1 TYPEREFTO lcl_bignum.
  474.   DATA lr2 TYPEREFTO lcl_bignum.
  475.   DATA lr3 TYPEREFTO lcl_bignum.
  476.   TRY .
  477.       CREATE OBJECT lr1
  478.         EXPORTING
  479.           i_value = '6584389034291301828999'.
  480. *          i_negative = 'X'.
  481.       CREATE OBJECT lr2
  482.         EXPORTING
  483.           i_value = '533335555511111'.
  484.       CREATE OBJECT lr3.
  485.       lr3->add( i_obj1 = lr1
  486.           i_obj2 = lr2 ).
  487. *     lr3->subtract( i_obj1 = lr1
  488. *                    i_obj2 = lr2 ).
  489. *     lr3->multiply( i_obj1 = lr1
  490. *                    i_obj2 = lr2 ).
  491. *     lr3->divide( i_obj1 = lr1
  492. *                  i_obj2 = lr2 ).
  493. *     lr3->mod( i_obj1 = lr1
  494. *               i_obj2 = lr2 ).
  495.       lr1->set_data( '512' ).
  496.       lr2->set_data( '17' ).
  497.       lr3->power( i_obj1 = lr1
  498.             i_obj2 = lr2 ).
  499.       lr2->set_data( '2773' ).
  500.       lr3->mod( i_obj1 = lr3
  501.           i_obj2 = lr2 ).
  502.     CATCH cx_root.
  503.   ENDTRY.

/.

Upload Files to SharePoint folders From SAP

$
0
0

Hi Friends,

 

Now-a-days we hear a lot about integrating SAP with Share Point.

I have recently work on such a requirement, where in I need to Upload files to SharePoint folders from SAP. So wanted to share my experience.

 

There are two different scenarios:

 

1) SharePoint and SAP are hosted on same server.

 

2) SharePoint and SAP are hosted on different server.

 

 

1) SharePoint and SAP are hosted on same server.

 

In this scenario,

 

Files can be directly uploaded Via GUI_UPLOAD or any equivalent FM or Classes.

 

STEPS:

  • Create new document library in your share point site.
  • GOTO--> Library and click on "Open with explorer" icon as shown below

folder.JPG

  • Then the server location opens as below

path.JPG

  • Pass the path to GUI_UPLOAD to upload to the folder.

 

 

2) SharePoint and SAP are hosted on different server.

 

In this case, we make use of a facility provided by Share Point known as "Communication Through Incoming email setings" to upload files onto it's folders.

 

STEPS:

 

                                                     

  • Create new document library in your share point site.

 

  • Once library created. Go to "Document library settings". -> Communication -> Incoming email settings

 

email.JPG

 

  • Enable the settings

 

              "Incoming email"=Yes

 

              Email address = "Define unique email ID"

 

              E-Mail Attachments=Save all attachments in root folder

 

address.JPG

 

  • Use email ID, in your ABAP program to send document in email.

 

 

 

Once you send mail to specific email ID as maintained in share point site, you will see document getting placed automatically in share point whatever you send it through email (as attachment ).

Uploading and Downloading Files from SAP to PC and Vice Versa

$
0
0


Hi,

 

Please find the code for Downloading/Uploading/Deleting the files from Application Server to presentation Server and vice versa.

 

   *&---------------------------------------------------------------------*
*& Report  Z_UPLOAD_APPSERV
*&
*&---------------------------------------------------------------------*
*& Cust prog to upload files from folder in Presentation server to
*  Applic server
*&---------------------------------------------------------------------*

REPORT  z_upload_appserv.


DATA: it_pcfile TYPE filetable,
      wa_pcfile TYPE file_table.

DATA: it_appfile TYPE TABLE OF ddshretval,
      wa_appfile TYPE ddshretval.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_upl  RADIOBUTTON GROUP g1 USER-COMMAND flag DEFAULT 'X' MODIF ID mf1,
            p_down RADIOBUTTON GROUP g1 MODIF ID mf1,
            p_del  RADIOBUTTON GROUP g1 MODIF ID mf1.

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS p_chk1 AS CHECKBOX MODIF ID mf5.
PARAMETERS p_pres1 RADIOBUTTON GROUP g2 USER-COMMAND flag1 DEFAULT 'X' MODIF ID mf2 .
SELECTION-SCREEN COMMENT 7(25) text-002 FOR FIELD p_pres1 MODIF ID mf2.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS p_chk2 AS CHECKBOX MODIF ID mf5.
PARAMETERS p_appl1 RADIOBUTTON GROUP g2 MODIF ID mf2.
SELECTION-SCREEN COMMENT 7(25) text-003 FOR FIELD p_appl1 MODIF ID mf2.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 10(30) text-008 MODIF ID mf6.
PARAMETERS p_dir TYPE localfile MODIF ID mf6."#EC *
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 10(30) text-005 MODIF ID mf3.
PARAMETERS p_pres TYPE localfile MODIF ID mf3.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 10(30) text-006 MODIF ID mf4.
PARAMETERS p_appl TYPE txt1024 MODIF ID mf4 .
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 10(30) text-007 MODIF ID mf7.
PARAMETERS p_file TYPE txt1024 MODIF ID mf7."#EC *
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN OUTPUT.

  LOOP AT SCREEN.
    IF p_upl  = 'X'.
      IF screen-group1 = 'MF2' OR
         screen-group1 = 'MF5' OR
         screen-group1 = 'MF6' OR
         screen-group1 = 'MF7'.
        screen-active  = 0.
        MODIFY SCREEN.
      ENDIF.
    ELSEIF p_down = 'X'.
      IF screen-group1 = 'MF2' OR
         screen-group1 = 'MF3' OR
         screen-group1 = 'MF5'.
        screen-active  = 0.
        MODIFY SCREEN.
      ENDIF.
    ELSEIF p_del = 'X'.
      IF p_pres1 = 'X'.
        IF screen-group1 = 'MF4' OR
           screen-group1 = 'MF5' OR
           screen-group1 = 'MF6' OR
           screen-group1 = 'MF7'.
          screen-active  = 0.
          MODIFY SCREEN.
        ENDIF.
      ELSEIF p_appl1 = 'X'.
        IF screen-group1 = 'MF3' OR
           screen-group1 = 'MF5' OR
           screen-group1 = 'MF6'.
          screen-active  = 0.
          MODIFY SCREEN.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDLOOP.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dir.
  PERFORM select_dir_from_pc.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_pres.
  PERFORM select_files_from_pc.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  PERFORM select_files_from_appl.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_appl.
  PERFORM select_direc_from_appl.

START-OF-SELECTION.

  IF p_upl = 'X'.
    PERFORM upload_files.
  ELSEIF p_down = 'X'.
    PERFORM download_files.
  ELSEIF p_del = 'X'.
    IF p_pres1 = 'X'.
      PERFORM delete_pc_files.
    ELSEIF p_appl1 = 'X'.
      PERFORM delete_app_files.
    ENDIF.
  ENDIF.

END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&      Form  select_dir_from_pc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM select_dir_from_pc.

  DATA: lv_dir TYPE string.

  CALL METHOD cl_gui_frontend_services=>directory_browse
    CHANGING
      selected_folder      = lv_dir
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.
  IF sy-subrc = 0.
    p_dir = lv_dir.
  ENDIF.

ENDFORM.                    "select_dir_from_pc

*&---------------------------------------------------------------------*
*&      Form  select_files_from_pc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM select_files_from_pc.

  DATA lv_rc TYPE i.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
*      file_filter             = '*.txt|*.TXT'
      multiselection          = 'X'
    CHANGING
      file_table              = it_pcfile
      rc                      = lv_rc
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.
  IF sy-subrc = 0.
    SORT it_pcfile BY filename.
  ENDIF.

ENDFORM.                    "select_files_from_pc

*&---------------------------------------------------------------------*
*&      Form  select_files_from_appl
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM select_files_from_appl.

  DATA: lt_dynp TYPE TABLE OF dynpread,
        lt_pcfile TYPE TABLE OF eps2fili,
        ls_dynp TYPE dynpread,
        "ls_pcfile TYPE eps2fili,
        lv_dir  TYPE eps2filnam.

  ls_dynp-fieldname = 'P_APPL'.
  APPEND ls_dynp TO lt_dynp.
** Get Value of P_APPL
  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname               = sy-repid
      dynumb               = sy-dynnr
    TABLES
      dynpfields           = lt_dynp
    EXCEPTIONS
      invalid_abapworkarea = 1
      invalid_dynprofield  = 2
      invalid_dynproname   = 3
      invalid_dynpronummer = 4
      invalid_request      = 5
      no_fielddescription  = 6
      invalid_parameter    = 7
      undefind_error       = 8
      double_conversion    = 9
      stepl_not_found      = 10
      OTHERS               = 11.
  IF sy-subrc = 0.
    READ TABLE lt_dynp INTO ls_dynp INDEX 1.
    IF sy-subrc IS INITIAL.
      lv_dir = ls_dynp-fieldvalue.
    ENDIF.
** Get List of Files in the selected directory
    IF lv_dir IS NOT INITIAL.
      CALL FUNCTION 'EPS2_GET_DIRECTORY_LISTING'
        EXPORTING
          iv_dir_name            = lv_dir
        TABLES
          dir_list               = lt_pcfile
        EXCEPTIONS
          invalid_eps_subdir     = 1
          sapgparam_failed       = 2
          build_directory_failed = 3
          no_authorization       = 4
          read_directory_failed  = 5
          too_many_read_errors   = 6
          empty_directory_list   = 7
          OTHERS                 = 8.
      IF sy-subrc <> 0.
        MESSAGE text-015 TYPE 'I'.
      ELSE.
        CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
          EXPORTING
            retfield        = 'NAME'
            dynpprog        = sy-repid
            dynpnr          = sy-dynnr
            value_org       = 'S'
            multiple_choice = 'X'
          TABLES
            value_tab       = lt_pcfile
            return_tab      = it_appfile
          EXCEPTIONS
            parameter_error = 1
            no_values_found = 2
            OTHERS          = 3.
        IF sy-subrc = 0.
          SORT it_appfile.
        ENDIF.
      ENDIF.
    ENDIF.

  ENDIF.

ENDFORM.                    "select_files_from_appl

*&---------------------------------------------------------------------*
*&      Form  upload_files
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM upload_files.

  DATA: lv_file   TYPE rcgfiletr-ftappl,
        lt_match  TYPE match_result_tab,
        ls_match  TYPE match_result,
        lv_count  TYPE i,
        lv_len    TYPE i,
        lv_offset TYPE i,
        lv_chars  TYPE i,
        lv_temp   TYPE char256,
        lt_data   TYPE TABLE OF text4096,
        ls_data   TYPE text4096,
        lv_fname  TYPE string.

  LOOP AT it_pcfile INTO wa_pcfile.

    CLEAR: lv_file, lv_temp, lv_len, lv_count, lv_offset, lv_chars.

    FIND ALL OCCURRENCES OF '\' IN wa_pcfile-filename RESULTS lt_match.
    DESCRIBE TABLE lt_match LINES lv_count.
    READ TABLE lt_match INTO ls_match INDEX lv_count.
    IF sy-subrc IS INITIAL.
      lv_len = STRLEN( wa_pcfile-filename ).
      lv_offset = ls_match-offset + 1.
      lv_chars = lv_len - lv_offset.
      lv_temp = wa_pcfile-filename+lv_offset(lv_chars).
    ENDIF.

    CONCATENATE p_appl '/' lv_temp INTO lv_file.

    CLEAR lv_fname.
    REFRESH lt_data.
    lv_fname = wa_pcfile-filename.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                = lv_fname
        filetype                = 'ASC'
      TABLES
        data_tab                = lt_data
      EXCEPTIONS
        file_open_error         = 1
        file_read_error         = 2
        no_batch                = 3
        gui_refuse_filetransfer = 4
        invalid_type            = 5
        no_authority            = 6
        unknown_error           = 7
        bad_data_format         = 8
        header_not_allowed      = 9
        separator_not_allowed   = 10
        header_too_long         = 11
        unknown_dp_error        = 12
        access_denied           = 13
        dp_out_of_memory        = 14
        disk_full               = 15
        dp_timeout              = 16
        OTHERS                  = 17.
    IF sy-subrc = 0.
      OPEN DATASET lv_file IN TEXT MODE FOR OUTPUT ENCODING DEFAULT.
      IF sy-subrc IS INITIAL.
        LOOP AT lt_data INTO ls_data.
          TRANSFER ls_data TO lv_file.
        ENDLOOP.
        CLOSE DATASET lv_file.
        WRITE: / text-009, wa_pcfile-filename.
      ELSE.
        WRITE: / text-010, wa_pcfile-filename.
      ENDIF.
    ELSE.
      WRITE: / text-010, wa_pcfile-filename.
    ENDIF.
  ENDLOOP.

ENDFORM.                    "upload_files

*&---------------------------------------------------------------------*
*&      Form  download_files
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM download_files.

  DATA: lv_pcfile TYPE string,
        lv_apfile TYPE rcgfiletr-ftappl,
        lv_rvstri TYPE rcgfiletr-ftappl,
        lt_data   TYPE TABLE OF text4096,
        ls_data   TYPE text4096.

  LOOP AT it_appfile INTO wa_appfile.

    CLEAR: lv_pcfile, lv_apfile.

    CONCATENATE: p_dir '\'  wa_appfile-fieldval INTO lv_pcfile,
                 p_appl '/' wa_appfile-fieldval INTO lv_apfile.

    REFRESH lt_data.
    CALL FUNCTION 'STRING_REVERSE'
      EXPORTING
        string    = lv_apfile
        lang      = sy-langu
      IMPORTING
        rstring   = lv_rvstri
      EXCEPTIONS
        too_small = 1
        OTHERS    = 2.
    IF    ( sy-subrc = 0
      AND ( lv_rvstri+0(3) = 'FDP'
      OR    lv_rvstri+0(3) = 'fdp') ) .

      sy-cprog = 'SAPLC13G'."#EC WRITE_OK
      CALL FUNCTION 'C13Z_FILE_DOWNLOAD_BINARY'
        EXPORTING
          i_file_front_end   = lv_pcfile
          i_file_appl        = lv_apfile
          i_file_overwrite   = 'X'
        EXCEPTIONS
          fe_file_open_error = 1
          fe_file_exists     = 2
          ap_no_authority    = 4.
    ELSEif ( sy-subrc = 0 ).
      OPEN
       DATASET lv_apfile
            IN TEXT MODE
           FOR INPUT
      ENCODING DEFAULT.
      IF sy-subrc = 0.
        DO.
          READ DATASET lv_apfile INTO ls_data.
          IF sy-subrc IS INITIAL.
            APPEND ls_data TO lt_data.
          ELSE.
            EXIT.
          ENDIF.
        ENDDO.
        CLOSE DATASET lv_apfile.
      ENDIF.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename                = lv_pcfile
          append                  = 'X'
        TABLES
          data_tab                = lt_data
        EXCEPTIONS
          file_write_error        = 1
          no_batch                = 2
          gui_refuse_filetransfer = 3
          invalid_type            = 4
          no_authority            = 5
          unknown_error           = 6
          header_not_allowed      = 7
          separator_not_allowed   = 8
          filesize_not_allowed    = 9
          header_too_long         = 10
          dp_error_create         = 11
          dp_error_send           = 12
          dp_error_write          = 13
          unknown_dp_error        = 14
          access_denied           = 15
          dp_out_of_memory        = 16
          disk_full               = 17
          dp_timeout              = 18
          file_not_found          = 19
          dataprovider_exception  = 20
          control_flush_error     = 21
          OTHERS                  = 22.
    ENDIF.

    IF sy-subrc = 0.
      WRITE: / text-011, lv_pcfile.
    ELSE.
      WRITE: / text-012, lv_apfile.
    ENDIF.

  ENDLOOP.

ENDFORM.                    "download_files

*&---------------------------------------------------------------------*
*&      Form  delete_pc_files
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM delete_pc_files.

  DATA: lv_pcfile TYPE string,
        lv_rc     TYPE i.

  LOOP AT it_pcfile INTO wa_pcfile.

    CLEAR lv_pcfile.
    lv_pcfile = wa_pcfile-filename.

    CALL METHOD cl_gui_frontend_services=>file_delete
      EXPORTING
        filename             = lv_pcfile
      CHANGING
        rc                   = lv_rc
      EXCEPTIONS
        file_delete_failed   = 1
        cntl_error           = 2
        error_no_gui         = 3
        file_not_found       = 4
        access_denied        = 5
        unknown_error        = 6
        not_supported_by_gui = 7
        wrong_parameter      = 8
        OTHERS               = 9.
    IF sy-subrc = 0.
      WRITE: / text-013, lv_pcfile.
    ELSE.
      WRITE: / text-014, lv_pcfile.
    ENDIF.

  ENDLOOP.

ENDFORM.                    "delete_pc_files

*&---------------------------------------------------------------------*
*&      Form  delete_app_files
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM delete_app_files.

  DATA lv_apfile TYPE rcgfiletr-ftappl.

  LOOP AT it_appfile INTO wa_appfile.
    CLEAR: lv_apfile.
    CONCATENATE p_appl '/' wa_appfile-fieldval INTO lv_apfile.
    DELETE DATASET lv_apfile.
    IF sy-subrc IS INITIAL.
      WRITE: / text-013, lv_apfile.
    ELSE.
      WRITE: / text-014, lv_apfile.
    ENDIF.
  ENDLOOP.

ENDFORM.                    "delete_app_files
*&---------------------------------------------------------------------*
*&      Form  SELECT_DIREC_FROM_APPL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM select_direc_from_appl .

  TYPES : BEGIN OF ty_direc,
          dirnme TYPE dirname,
          END OF ty_direc .

  DATA : lv_path TYPE TABLE OF ddshretval,
         lt_dir TYPE TABLE OF ty_direc .

  DATA : wa_path TYPE ddshretval.

  "selecting the list of custom directory in application server
  SELECT dirname
    FROM user_dir
    INTO
   TABLE lt_dir .

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'  "Fm to display the IT as Serach help
    EXPORTING
*   DDIC_STRUCTURE         = ' '
      retfield             = 'DIRNME'
      dynpprog             = sy-repid
      dynpnr               = sy-dynnr
      value_org            = 'S'
    TABLES
      value_tab            = lt_dir
   return_tab              = lv_path
   EXCEPTIONS
     parameter_error        = 1
     no_values_found        = 2
     OTHERS                 = 3.

  IF sy-subrc = 0 AND lv_path IS NOT INITIAL .

    READ
    TABLE lv_path
    INTO  wa_path
    INDEX 1.

    p_appl = wa_path-fieldval.

  ENDIF.

ENDFORM.                    " SELECT_DIREC_FROM_APPL

 

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

** Maintain Text Symbols for the program

001 Selection Options

002 From Presentation Server

003 From Application Server

005 File(s) in Pres Serv

006 Application Server Directory

007 Application Server File(s)

008 Directory in Presentation Server

009 File has been uploaded successfully

010 Error while copying the file

011 File has been downloaded succssfully

012 Error while downloading file

013 File has been deleted succssfully

014 Error while deleting file

015 No Files Available

 

**Selection Types:

P_APPL Path in ApplicationServer

P_APPL1 From Application Server

P_CHK1 No

P_CHK2 No

P_DEL Delete File(s)

P_DIR ?...

P_DOWN Download File(s)

P_FILE ?...

P_PRES Path in Pres Serv

P_PRES1 From Presentation Serv

P_UPL Upload File(s) from Pres Serv

 

With Regards,

Giriesh M

How to run SAP query in background and create a file in application server

$
0
0

It is possible to run SAP queries in background and to create a query output as a file in application server.

 

Follow below steps to implement the same.

 

1) As per OSS note 537735 - SAP Query: save to file in the background activate the enhancement SQUE0001 using the t.code SMOD.

 

2) Once the above enhancement is activated, it will add a new radio button option with text "Private file" under the output format block of the Query selection screen.

 

2-4-2014 3-00-13 PM.jpg

3) Create a Z table and maintain the sever filepath in which the files to be stored in application server.

2-4-2014 3-27-48 PM.jpg

4) Go to the function exit "EXIT_RSAQEXCE_001" and do your customized coding in the INCLUDE ZXQUEU01.

 

*Data Declaration.

DATA : c_lv_buf TYPE string,

      c_lv_line TYPE string,

      c_lv_filepath TYPE localfile,

      c_lv_query TYPE aqs_quname.

 

*Field symbols

FIELD-SYMBOLS : <fs_record>TYPEANY,

                <fs_comp>TYPEANY.

 

*Get a Query name from the program

CALLFUNCTION'RSAQ_DECODE_REPORT_NAME'

  EXPORTING

    reportname    = program

  IMPORTING

    query          = c_lv_query

  EXCEPTIONS

    no_query_report = 1

    OTHERS        = 2.

IF sy-subrc <>0.

  MESSAGEID sy-msgid TYPE sy-msgty NUMBER sy-msgno

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

ENDIF.

 

*Select the filepath from ZBSD_T0246 table based

*on the query name and variant.

SELECTSINGLE filepath

  FROM zbsd_t0246

  INTO c_lv_filepath

  WHERE query = c_lv_query

  AND qvariant = syst-slset.

 

IF sy-subrc = 0.

*Open application server file.

  OPENDATASET c_lv_filepath FOROUTPUTINTEXTMODE ENCODING DEFAULT.

  IF sy-subrc = 0.

    CLEAR c_lv_line.

 

*Create header of the file

    LOOPAT listdesc.

      CONCATENATE c_lv_line listdesc-fcol ';'INTO c_lv_line.

    ENDLOOP.

    TRANSFER c_lv_line TO c_lv_filepath.

    CLEAR c_lv_line.

 

*Transfer the data to the file

    LOOPAT datatab ASSIGNING<fs_record>.

      DO.

        ASSIGN COMPONENT sy-index OFSTRUCTURE<fs_record>TO<fs_comp>.

        IF sy-subrc <>0.

          EXIT.

        ENDIF.

        c_lv_buf = <fs_comp>.

        IF sy-index = 1.

          c_lv_line = c_lv_buf.

        ELSE.

          CONCATENATE c_lv_line c_lv_buf INTO c_lv_line SEPARATEDBY';'.

        ENDIF.

        CLEAR c_lv_buf.

      ENDDO.

      TRANSFER c_lv_line TO c_lv_filepath.

      CLEAR c_lv_line.

    ENDLOOP.

 

*Close the file once the datas are transfered.

    CLOSEDATASET c_lv_filepath.

    IF sy-subrc = 0.

 

*File created in path &1

      MESSAGE s483(zbsd_0001)WITH c_lv_filepath.

    ENDIF.

  ENDIF.

ELSE.

 

*File path not maintained in table ZBSD_T0246

  MESSAGE e484(zbsd_0001).

ENDIF.

 

5) Run the query in the background and the files will be created in the application server path maintained in Z-table.

Real estate table relationships

Breakpoint at a select statement of a given DB table

$
0
0

This document is on setting a breakpoint on SELECT statement of a given database table. This is done through debugger script that is available from EHP 6.

Following is an example where a breakpoint will be set on VBAP table queries in VA02 transaction.

 

  1. Go to VA02 and input a sales order number
  2. Enable the debugger through /h in command field
  3. Go to “Script” tab in the debugger and click on the “Load Script” button,  take F4 help and select the report as highlighted in below imageLoad Script.png
  4. Click on “Start Script” button and input the Database table names on whose SELECT statement debugger has to stop and click execution button on the pop up window
  5. Debugger script stops at the given DB tables select statements

Debugger.png

6.    To continue further debugging(stop at given DB table queries) click on “Continue Script” button, highlighted in the above image

Transfer Data between SAP Systems/developers without STMS (using SAPLink)

$
0
0

Hi SCN,

 

Using STMS is the standard and easiest way of transporting data between your linked SAP Systems.
However, if the SAP Systems are not linked and you wish to share any sort of data between the two SAP Systems or developers, keep on reading.

 

I was looking for a way to transport a program which I created on SAP System X to SAP System Y.

The easiest and fastest way for me, to transport ABAP developments between two independent systems, was to use SAPLink.

"     SAPLink is an open source project that aims to make it easier to share ABAP developments betwen programmers.
      It provides the ability to easily distribute and package custom objects.     "

(Source: saplink)

 

In this tutorial I'll explain how to install and configure SAPLink into your SAP System and how to transfer data using SAPLink.

 

Installation and configuration of SAPLink into your SAP System

 

  1. Download and extract the SAPLink installation files to your file system (Downloads -  saplink)
    (Note: it is advised to install a stable release and not a beta, or even alpha, version)
  2. If you don’t have a package yet to save the objects you will create in the following steps, create one now in transaction SE80.
  3. Create a new executable program in transaction SE38 (when asked for a package, save as local object since this program only handles the installation and will only be run once) and copy the code from the “ZSAPLINK_INSTALLER.TXT” into the program (which you extracted in step 1).
    Make sure to change the report statement at the top of the page to the name of your program. Save, activate and execute your program afterwards.
  4. The following screen will appear:
    a.png
    Select the “NUGG_SAPLINK-0.1.4” file (0.1.4 may be different version when you downloaded another release) from your file system which you extracted in step 1.

    If you want to overwrite a previous installation, you can flag the “Overwrite Originals” checkbox.

    Execute the report and when asked, enter the package (step 2) you will be using for SAPLink.
  5. When the installation (objects are created) was successful the following screen will appear:
    a.png
  6. Now the objects need to be activated:
    1. For classes go to transaction SE24, enter the name of the class and press activate.
      Repeat this for every class mentioned in the screen above.
    2. For programs go to transaction SE38, enter the name of the program and press activate. For programs you also have to activate a STATUS.              To do this go to transaction SE41, enter the program name and press F4 in the STATUS field. The value “SELOBJ” will appear; now press activate.
    3. If you want to activate multiple inactive files at the same time, do following steps:
      Transaction SE80 > Select “Inactive Objects” > Enter your username > Display > Right-click (on the objects that needs to activated) > Activate
      a.png
  7. You can now execute the “ZSAPLINK” program in transaction SE38.
    The following screen will appear:
    a.png
    The “Nugget” tab is for handling “.nugg” files and the “Slinkee” tab for handling “.slnk” files.
    These files can be used for importing plugins (extensions of original functionality, see underneath
    step 8) or be created for the export of SAP objects (data that needs to be transferred, see underneath step 9).
  8. Plugins can be download from the following website: SAPlink plugin list.
    (these plugins extend the posibilities of what you can export)

    Click on the desired plugin, download it to your file system and choose to import the plugin file (either nugget or slinkee depending in file extension) in the program ZSAPLINK.

    On success the following screen will appear:
    a.png
    Note: don’t forget to activate the installed components (see step 6)
  9. You'll have to install the ZSAPLINK program and plugins on both the source and target SAP System.

 

Export custom objects from source SAP System

 

  1. Execute “ZSAPLINK” program (transaction SE38)
  2. Select “Create New Nugget”, enter the desired nugget name and press execute:
    Navigate to the location where you want to save the file and press “Save”.
    (The system will ask you if you want to allow the SAP system from accessing the file system, press “Allow”)

    a.png
  3. Now specify which object you want to add to the nugget, in this case the whole package:
    You specify which object/package you want to add to the Nugget, where the Nugget is located (see previous step) and press “Execute”.

    a.png
  4. In the next screen, select what you want to add from the package and press the green wink:
    NOTE: To be able to select all the objects, I had to install some plugins.
    The amount of plugins you have to install, depends on what you want to transfer (e.g.: if you want to transfer Adobe Forms objects, you’ll need to install the PDF Forms and PDF Interface plugins - see step 8 from SAPLink installation).

    You can select every object (after installing plugins) except the package itself.
    a.png
    If all objects are succesfully copied to the Nugget a green light will appear in the "Exception" column.
    The objects are now stored in the ".nugg" file which you specified before.


Import custom objects in target SAP System

 

  1. Create a new package, for the Nugget that you will be importing, in transaction SE80
  2. Go to transaction SE38 and run the ZSAPLINK program.
  3. Choose to “Import Nugget” and look up the “Nugget File Name” from the file system on the location where you exported it to.
    Note: It is possible that not all objects can be imported at the first import because of the order of imports. Just run the “Import Nugget” a second time, this time with the “Overwrite Originals” checkbox flagged.
  4. When you import the Nugget, all objects are added to the “$TMP” package.
    You need to add all the objects to the package you created in step 1.
    Go to SE80 > Inactive Objects > Enter Username OR SE80 > Package > Enter "$TMP"
    Select all the objects that needs to be transferred to your package, right-click on your selection and choose “Change Package Assignment”.
  5. Select the objects one by one after the “Change Package Assignment” and activate them.

 

All your objects are now present and usable in the target SAP System.

If you have any questions, feel free to contact me.


Regards,

 

Niels


Getting Started with AS ABAP 7.4 SP5 incl. BW on SAP HANA SP7 [Developer Edition]

$
0
0

This guide describes how to set up and run the developer edition of Application Server ABAP 7.4 SP5 on SAP HANA SP7, which is provided as virtual appliance by the SAP Cloud Appliance Library.

View this Document

Adobe form Password protected with Java script

$
0
0


Summary:  Password protection for Adobe Form with Java Script

 

Approach:

1.Go to Transaction SFP

SFP.jpg

2. Create a form

Create a Form.jpg

 

3. Go to Layout and create a text on Master page as shown below

Decalre Text.jpg

 

4. Create Password check for adobe form

 

->Go to the Initialize event of DATA as shown below

Write Java code.jpg

 

->Write down below code


//Decalre variables
var a=1;
var b=2;
var password;


//Prompt for password from user to open the adobe form
password = xfa.host.response("Enter the Password","The title","123");

 

 

//Check for Correct password
{
if (password == "123")    // In this case Password id hard coded to 123
{
  xfa.host.messageBox("Right password","You Know right",3,0);
  a = 1;
  b = 1;
}
else
{
  xfa.host.messageBox("Wrong password","You know ur Wrong",1,1);
  a = 1;
  b = 2;
  password = xfa.host.response("Enter the Password","The title","123");
}
}
while( a != b );

 

 

5. Now execute the form

  -> Do not forget the mark Fillable of Form I/P as 'X'

Test form.jpg

 

Mark Fillable.jpg

 

and execute.

 

Now, Adobe form will ask for password as shown below

Fill pop for password.jpg

 

Till correct password is enetered this pop up will appear. We can download this form and try to open still password protection will be vaild.

 

 

Drawbacks:

->Password is harcoded, I do not how to check with an value from table or rule dynamically

->I ain't any good in Java scipt, hence could not hide password ( genrally it works with form calc)

Transaction Types

$
0
0


Introduction


Transactions are used to execute each SAP program.  The transaction code can be entered directly by the users into the command box in the toolbar , or they can be attached to the SAP Menu.

 

Purpose


This article allows gives you a basic overview of the different types of transactions that can be created .To create a transaction we use the Tcode SE93. When we goto Tcode SE93 and try to create a Tcode, you will find that 5 types of transactions are available from which you can select th eone appropraite for your particular program. The 5 types of transactions are :

  • Dialog Transactions
  • Report Transactions
  • Object Oriented Transation
  • Parameter Transation
  • Variant Transaction

 

 

Dialog Transaction


Introduction

Dialog Transactions are used to execute programs with type ‘Dialog Module’ or ‘Module Pool’. Programs created with this type cannot be executed without creating a Tcode for it.

 

Steps

To create a Dialog Transation:-

  1. Take SE93 and click Create.
  2. Give the Tcode name to be created and a description adn click Enter.
  3. In the dialog box that pops up, select Dialog transaction.
  4. Now in the screen that appears, enter  the Program name and fill the main screen no . ( The screen whose PBO is to be executed first ).
  5. Now select the check box to Inherit GUI Attributes. Save and Check.
  6. Execute the Tcode .

 

 

Report Transation


Introduction

Report Transactions are used to create TCodes for  programs of type 1 or Executable programs.

 

Eg. Purpose

Let us say, we have created a Type 1 program for displaying the details of selected materials. Suppose our program name is ZMMRDSP001. We will now see the steps required to create a T code for the program. We will set the T Code as ZMMR001. The following are the steps needed to create it.

 

Steps

To create a report transaction:-

  1. Take SE93 and click Create.
  2. Give the T code name as ZMMR001 and a description as Material Display, and click Enter.
  3. In the dialog box that pops up, select Report transaction.
  4. Now in the screen that appears, enter  the Program name ZMMRDSP001.
  5. If you want any specific variant to be executed by default, give the variant name.
  6. Now select the check box to Inherit GUI Attributes. Save and Check.
  7. Execute the T code .

 

 

Object Oriented Transaction


Introduction

Object Oriented Transactions can be used when you want to execute a class method directly.

 

Steps

To create a Object Oriented Transaction:-

  1. Take SE93 and click Create.
  2. Give the T code name to be created and a description adn click Enter.
  3. In the dialog box that pops up, select  Object oriented transaction.
  4. Now in the screen that appears, enter  the Class Name and give the name of the method that is to be executed first.
  5. Now select the check box to Inherit GUI Attributes. Save and Check.
  6. Execute the T code .

 

 

Parameter Transaction


Introduction

Parameter Transactions are useful when you need to personalize Standard Transactions with some pre-defined values. It involves executing transactions with pre-defined values. It also provides the option of skipping the first screen ( or executing the first screen with your pre-defined values).

 

Eg. Purpose

We are going to create a transaction code ZMN which allows the user to maintain entries in the table ZMINE which has a table maintenance view. So when the user enters the transaction ZMN, he can directly see the table entries screen.

 

Steps

  1. Goto T code SE93.
  2. Enter  the Transaction Code  ZMN and give a valid description.                                                                    
  3. Choose Parameter Transaction Radio Button and Continue.
  4. Enter details in the subsequent screen as shown to the right and click Enter.
  5. Now in the bottom part you can see a section ‘Default Values’. In here, using F4 help , you can see teh fields(screen field names) available on that particular screen( SM30 in this case). Select screen field ‘VIEWNAME’ and ‘UPDATE’ now.
  6. In the right side ( Value ) add ‘ZMINE’ ( your view name which has a table maintenance view) against VIEWNAME and ‘X’ against UPDATE. [FYI:   Update is a button present in the SM30 screen which is clicked to maintain data. Setting that value to ‘X’ will give the effect of clicking the Maintain button on SM30 with viewname as ZMINE.                                                                                            
  7. Now Save and Check.And Execute. If there are no errors, you should be able to see your maintenance screen directly.

 

Output

When the user now clicks the transaction ZMN the screen he sees will be

 

 

 

Variant Transaction

   

Introduction

Transaction Variants can be very useful in making design level changes in Standard Transactions. They can also be sued to set default values on screens and to set screen field properties.They can then be assigned to Standard T code itself, So that these changes get reflected for all users accessing the T code , or we can set separate T code for the same.

 

Eg. Purpose

In this document , we will create a Transaction Variant for the T Code VA01, in which we will make a variant transaction(ZVA01) of VA01 in which the initial screen ( with order type etc) need not be filled as they will be defaulted and PO number made mandatory .

 

Steps

  1. Goto T Code SHD0.
  2. Enter  the Transaction Code for which you want to create a variant. In this case, enter  Tcode VA01 and give a name for your transaction variant. Say ZVA01.                                                                                              
  3. Now click the Create button. You will be taken to the Tcode VA01.
  4. Enter values in the initial screen as you would during normal processing and click enter. 
  5. Now a new screen will pop up showing all the fieldnames and properties that can be changed.                                                                         
  6. Give the values in the pop up as given above and click ENTER to go to the next screen.
  7. Similarly, you can set any properties you need in the screen and on clicking enter , the properties tab will pop up. You can makethe desired changes there. I will set PO number to required and the Document Currency to INR. I will also hide the tabstrip for Shipping details. So the values in the pop ups will be  
  8. Note that several pop ups will show.This is because a popup for each sub screen will be displayed.
  9. Now click Exit and Save button.
  10. All the values entered and shown will get displayed in a single screen. You can make any changes necessary and then save with a description.
  11. Save all and assign each to package.
  12. Now click back and you will be taken to the initial screen in SHD0. Save.
  13. Now take T Code se93 and give a new Tcode for executing the variant and click Create.
  14. In the radio button options that appear, select variant Transaction.
  15. Now go inside, and  give T Code as VA01 and variant s ZVA01 and select cross Client Check Box.
  16. Now select the check box to Inherit GUI Attributes. Save and Check.
  17. Now execute your transaction.

 

Output

You are now directed directly to the 2nd screen after skipping the initial screen with the values you have set by default through your variant. Further , if you try saving without the PO number, it will give a message asking you to fill the PO number.


Conclusion

 

So this is how the different types of transactions are created . Make sure you assign the correct type to the transaction or your program may not work correctly. Happy Coding :D.

 


Related Content

Transaction Variants

Varient Transaction

 

 

Create QRCode via ABAP code

$
0
0

In the previous blog we discuss how to generate QRCode to enable it be scanned via mobile phone.

 

In that solution, the QRCode is generated and stored in a PDF file via ABAP webdynpro framework, we only proivde the form template. In fact it is quite easy to adapt the solution to generate the PDF by ourself, so that the QRCode could be used more flexibly in many other scenario for example as an attachment of email.

 

Note: it is still necessary to create a form interface and form template as described in the blog.

 

The report source code is below:

 

PARAMETERS: content TYPE string.
DATA:  ls_outputparams TYPE sfpoutputparams,  ls_docparams    TYPE sfpdocparams,  ls_pdf_file        TYPE fpformoutput,  ls_post            TYPE crmd_soc_post,  lv_fm_name      TYPE rs38l_fnam.
ls_outputparams-noprint   = 'X'.
ls_outputparams-nopributt = 'X'.
ls_outputparams-noarchive = 'X'.
ls_outputparams-nodialog  = 'X'.
ls_outputparams-preview   = 'X'.
ls_outputparams-getpdf    = 'X'.
CALL FUNCTION 'FP_JOB_OPEN'  CHANGING    ie_outputparams = ls_outputparams  EXCEPTIONS    cancel                = 1    usage_error        = 2    system_error       = 3    internal_error      = 4    OTHERS              = 5.
CHECK sy-subrc = 0.
TRY.    CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'      EXPORTING        i_name        = 'ZPF_QRCODE' " put your own form template name here      IMPORTING        e_funcname = lv_fm_name.  CATCH cx_fp_api_repository        cx_fp_api_usage        cx_fp_api_internal.    RETURN.
ENDTRY.
ls_docparams-langu     = 'E'.
ls_docparams-country   = 'US'.
CALL FUNCTION lv_fm_name  EXPORTING    /1bcdwb/docparams  = ls_docparams    qrcode_input            = content  IMPORTING    /1bcdwb/formoutput = ls_pdf_file  EXCEPTIONS    usage_error         = 1    system_error       = 2    internal_error      = 3    OTHERS             = 4.
CHECK sy-subrc = 0.
CALL FUNCTION 'FP_JOB_CLOSE'
EXCEPTIONS    usage_error    = 1    system_error   = 2    internal_error  = 3
OTHERS         = 4.


execute the report, the PDF binary is stored in ls_pdf_file-pdf.

clipboard1.png

clipboard2.png

It could be scanned by the QRCode scanner installed in my mobile phone:

clipboard3.png

Read GOS (Generic Object Service) Picture Attachments and Display it into Adobe Form

$
0
0

Abhijit MandalPurpose & Overview:There are lot of threads, wiki’s and blogs available about GOS. Reading and downloading GOS attachment and also we will find lots of article on how to attach a document into GOS.

 

But there are not many documents which describes the complete cycle of reading GOS object and display it into adobe form dynamically. The idea of this document is to build a complete cycle of reading a GOS attachment and then embed it into SAP Adobe form.

 

Limitations & Restrictions: This document is to read GOS picture attachments and embedding it into SAP adobe form. As, I have tried for reading a .PDF GOS attachment and embedding it into SAP Adobe form but as per my knowledge SAP doesn’t provide such solutions till now. So, this is restricted to picture format (.JPG, .GIF, .BMP, .PNG and .TIFF etc.).

 

Business Requirement & Descriptions: In this document I will read GOS attachments which are quality certificates and display the quality certificates into SAP Adobe form. This is applicable for other transactions which have got generic object service.

 

Create a structure & table type which will be sent to SAP adobe form as an import parameter.

Image1.jpg

Create table type:

Image2.jpg

Building the program:

 

REPORT  zabhi_gos_attachment_read.

DATAlv_lgsystm    TYPE logsys,
       lv_line      
TYPE i,
       lv_input_len 
TYPE i,
       ls_connection
TYPE bdn_con,
       lv_docid     
TYPE so_entryid,
       lv_objkey    
TYPE swo_typeid,
       ls_doc_data  
TYPE sofolenti1,
       ls_certattach
TYPE ztst_itab,
       lv_string    
TYPE xstring.


DATAlt_connection TYPE STANDARD TABLE OF bdn_con,
       lt_content   
TYPE STANDARD TABLE OF solisti1,
       lt_cont_hex  
TYPE STANDARD TABLE OF solix,
       lt_attachment
TYPE ztst_tt_itab.

FIELD-SYMBOLS<lfs_connection> TYPE bdn_con.

 
CLEAR: lv_lgsystm,
       lv_input_len
,
       lv_line
.


* Build selection screen


SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS: p_bo   TYPE bds_clsnam OBLIGATORY DEFAULT 'BUS2117',
            p_cert
TYPE qcpr-certno OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.
* To Get own logical system


CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
     IMPORTING
      own_logical_system            
= lv_lgsystm
     EXCEPTIONS
      own_logical_system_not_defined
= 1
            OTHERS                                                = 2.
     IF sy-subrc <> 0.
     
CLEAR lv_lgsystm .
     ENDIF.

* Retrieves list of attachment (quality certificate images) details through BDS_GOS_CONNECTIONS_GET function module .


CLEAR lv_objkey.
MOVE p_cert TO lv_objkey.

CALL FUNCTION 'BDS_GOS_CONNECTIONS_GET'
     EXPORTING
      logical_system    
= lv_lgsystm
      classname         
= p_bo
      objkey            
= lv_objkey

     TABLES
      gos_connections   
= lt_connection[]
     EXCEPTIONS
      no_objects_found  
= 1
      internal_error    
= 2
      internal_gos_error
= 3
     
OTHERS                         = 4.
     IF sy-subrc = 0.
     
SORT lt_connection .
     ENDIF.

LOOP AT lt_connection ASSIGNING <lfs_connection>.


     
TRANSLATE <lfs_connection>-docuclass TO UPPER CASE.
     
MOVE <lfs_connection>-loio_id TO lv_docid.

* Reading the content of the image file. Internal table lt_cont_hex is the converted binary format of the image is    generating.


CALL FUNCTION 'SO_DOCUMENT_READ_API1'
     
EXPORTING
           document_id                
= lv_docid
     
IMPORTING
           document_data              
= ls_doc_data
     
TABLES
            object_content            
= lt_content[]
            contents_hex              
= lt_cont_hex[]
     
EXCEPTIONS
            document_id_not_exist     
= 1
            operation_no_authorization
= 2
            x_error                   
= 3
           
OTHERS                                         = 4.
     
IF sy-subrc <> 0.
          
CLEAR ls_doc_data.
     
ENDIF.

CLEAR: lv_line, lv_input_len.

* The most important part is to get correct length. If you do not pass the correct length you image will not be displayed.
     DESCRIBE TABLE lt_cont_hex LINES lv_line.
   lv_input_len 
= lv_line * sy-tleng .

* Converting binary data to Xstring format

CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
     
EXPORTING
           input_length 
= lv_input_len
           first_line   
= 0
           last_line    
= 0
     
IMPORTING
          
buffer                   = lv_string
     
TABLES
           binary_tab  
= lt_cont_hex
     
EXCEPTIONS
           failed      
= 1
          
OTHERS             = 2.
         IF sy-subrc <> 0.
     
CLEAR lv_string.
   
ENDIF.

* Now we need to convert the Xstring data to string data otherwise the image will not be shown.
ls_certattach
-certno = p_cert.

     CALL FUNCTION 'SSFC_BASE64_ENCODE'
     
EXPORTING
           bindata
= lv_string

     
IMPORTING
           b64data
= ls_certattach-f_string.
     
IF sy-subrc <> 0.
          
CLEAR ls_certattach-f_string.
     
ENDIF.

     
APPEND ls_certattach TO lt_attachment.
     
CLEAR ls_certattach.

ENDLOOP.

 

 


* To print the image into adobe form call below subroutine.


PERFORM f_sub_print_form USING lt_attachment.
*&---------------------------------------------------------------------*
*&      Form  F_SUB_PRINT_FORM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_sub_print_form  USING  p_gt_tab TYPE ztst_tt_itab.
     
DATA : ls_sfpoutputparams  TYPE sfpoutputparams,
            ls_docparams       
TYPE sfpdocparams,
            ls_pdf_file        
TYPE fpformoutput,
            lv_formname        
TYPE fpname VALUE 'ZTEST_DYNAMIC_PICTURE',
            lv_fmname          
TYPE funcname,
            lv_mseg            
TYPE  string,
            lv_w_cx_root       
TYPE  REF TO cx_root" Exception class


      ls_sfpoutputparams
-dest     = 'XX01'.
      ls_sfpoutputparams
-nodialog = 'X'.
      ls_sfpoutputparams
-preview  = 'X'.


     CALL FUNCTION 'FP_JOB_OPEN'
     
CHANGING
           ie_outputparams
= ls_sfpoutputparams
     
EXCEPTIONS
           cancel         
= 1
           usage_error    
= 2
           system_error   
= 3
           internal_error 
= 4
          
OTHERS          = 5.

     
IF sy-subrc <> 0.
          
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
     
ENDIF.

     TRY .
     
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
          
EXPORTING
                i_name    
= lv_formname
          
IMPORTING
                e_funcname
= lv_fmname.

     
CATCH cx_root INTO lv_w_cx_root.
           lv_mseg
= lv_w_cx_root->get_text( ).
          
MESSAGE lv_mseg TYPE 'E'.

     ENDTRY.

     MOVE: sy-langu TO ls_docparams-langu.

     CALL FUNCTION lv_fmname
     
EXPORTING
           /1bcdwb/docparams 
= ls_docparams
           im_itab           
= p_gt_tab
     
IMPORTING
           /1bcdwb/formoutput
= ls_pdf_file
     
EXCEPTIONS
           usage_error       
= 1
           system_error      
= 2
           internal_error    
= 3
     
OTHERS             = 4.

     
IF sy-subrc <> 0.
          
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
     
ENDIF.

     CALL FUNCTION 'FP_JOB_CLOSE'
     
*   IMPORTING
     
*     E_RESULT             =
     
EXCEPTIONS
           usage_error         
= 1
           system_error        
= 2
           internal_error      
= 3
          
OTHERS               = 4.

     
IF sy-subrc <> 0.
          
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
     
ENDIF.


ENDFORM.                    " F_SUB_PRINT_FORM


Now build the simple form to test:


Go To SFP: Build an interface ZTEST_I_DYNAMIC_PICTURE and pass the import parameter in INPUT and OUTPUT parameter.

Image3.jpg

Now Build FORM Context.

image 4.jpg

Go to Layout:

Create one Image field into Design view and bind it with F_Sring which is the converted image in string format.


layout.jpg


Activate it.


Now execute your program. Enter the parameters. Business object and Object key. Here object key is the certificate Number and Business object 'BUS2117'.


If you choose different Business object then you have to give correct object key. To get correct object key you can check the business object in SWO1 transaction.


After executing the output is coming like below.

output.jpg

Reference: I don't want to mention particular documents but I take help on few threads on GOS and Adobe form in SCN to build this document.


Suggestion: Please feel free to suggest.

Download PDF copy for any report

$
0
0

Guys,

Sometime, client may ask some tool to be able to download report output (be it classical, ALV grid or list) to PDF. One of customer asked us to enable them to download PDF thereby restricting it’s staff activities.  I have made efforts not to restrict its applicability and maintain generality.

This functionality is encapsulated in a Function module and encompasses following action.

  • Prepare job name.
  • Schedule job in background and read latest spool.
  • Introduce wait period of 120seconds to let the job complete.
  • Download PDF locally with spool number as input upon completion of job.

Steps to be carried out in target report:

  • Prepare selection table.
  • Call function module on click of button ‘PDF Download’ added to toolbar.

There are few things you should keep in mind:

  • Selection criteria should be filled in the selection table as it appears in selection screen.
  • In case of ALV generation using FM ‘REUSE_ALV_GRID_DISPLAY’ do remember to pass parameter ‘SLIS_PRINT_ALV’ to suppress list info like no of records appearing in PDF (ls_print-no_print_listinfos = 'X').
  • An endless loop in a report can result in unexpected result (Including long running job).

 

At bottom I have included an example how to implement in your report.

 

Please provide your suggestion/inputs and like it if it is helpful.

 

Cheers,

N. Gautam

Featured Content for ABAP Development

$
0
0

Free Developer Edition: AS ABAP incl. BW on SAP HANA

Do you want to explore the latest features of SAP Business Warehouse, try out ABAP development on SAP HANA or the SAP HANA interactive education? Now we offer a new developer edition of AS ABAP incl. BW 7.4 SP5 on SAP HANA SP7 for our developer community.February 18, 2014

 

ABAP Language News for Release 7.40 SP05

SP05 for AS ABAP 7.40 comes with a new kernel release 741 and a new kernel release means new ABAP language features. Read this blog by Horst Keller covering the most important ABAP language news.February 6, 2014

 

What is ANST and why aren't you using it?

Do you already know ANST, the Automated Notes Search Tool? This powerful application searches SAP notes for a specific problem based on the issue in your system. For more information, read this blog by Kristen Scheffler.January 9, 2014

 

ABAP Developement Tools for Eclipse 2.19

The ABAP Development Tools for Eclipse 2.19 are available as of today! Read this interesting blog by Thomas Fiedler to find out what's new and where to get the latest version.December 20, 2013

 


Recently Featured Content in ABAP Development

$
0
0

SQL Monitor Unleashed

Have you heard about the SQL Monitor already? It can be used to detect custom code which can be optimized (in the context of the migration to SAP HANA, but also independent of that). If you like to learn more, read Johannes Marbach's blog series. You find the first blog here.November 18, 2013

 

Considerations for Custom ABAP Code During a Migration to SAP HANA

Considering a migration of your custom code to an AS ABAP 7.4 on SAP HANA system? Then you should read this best practice guide by Eric Westenberger containing important considerations and recommendations.September 27, 2013

 

ABAP language news for SAP NetWeaver 7.4

Don't miss this comprehensive blog series by Horst Keller describing the latest enhancements of the ABAP programming language for the SAP NetWeaver Application Server ABAP 7.4 release.July 23, 2013

 

Now Available! SAP NetWeaver AS ABAP 7.4

SAP NetWeaver AS ABAP 7.4 provides non-disruptive innovations and enhancements for the proven and reliable ABAP technology and is optimized for SAP HANA, Cloud, and Mobile. Learn about the most significant values and capabilities of the SAP NetWeaver AS ABAP 7.4.

 

Learn more about NetWeaver 7.4 in blogs by Bjoern Goerke and Karl Kessler:

SAP NetWeaver 7.4 Made Generally Available (GA)

New landing page published for SAP NetWeaver 7.4

 

Explore the ABAP Development on SAP HANA step by step using ABAP for SAP HANA Reference Scenario Open Items Analytics which is an integral part of the SAP NetWeaver AS ABAP 7.4. May 13, 2013

 

ABAP Development Tools 2.7 are generally available!

http://scn.sap.com/profile-image-display.jspa?imageID=6190&size=72Testdrive the latest version of SAP's ABAP IDE on Eclipse and get familiar with its new features and enhancements. This article by Christopher Kaestner describes the highlights of the ABAP development tools 2.7 and where to download them.May 12, 2013

 

Performance Guidelines for ABAP Development on the SAP HANA Database

If you’re an experienced ABAP developer, you’re probably familiar with the classic performance guidelines for using Open SQL. This begs the question of what changes are there to the guidelines in the context of SAP HANA. Eric Westenberger tackles that question.  April 10, 2013

 

Experience the Magic: How to Setup Your Own ABAP on HANA in the Cloud

http://scn.sap.com/profile-image-display.jspa?imageID=12354&size=72Are you an ABAP developer who can’t wait to explore the intricacies of ABAP on HANA coding? Do you want to set up a sandbox environment where you can try out things such as consuming HANA Calculation Views or Stored Procedures from ABAP programs, and learn how to accelerate your ABAP applications with HANA or build entirely new ones? Then SAP Mentor Thorsten Franz wrote this for you. April 10, 2013

 

ABAP in Eclipse: Why Eclipse wins?

http://scn.sap.com/profile-image-display.jspa?imageID=17269&size=72 What makes working with ABAP in Eclipse more efficient as in SE80? In this blog, Adam Krawczyk shares his practical experience with ABAP Development Tools giving handy tips and advices for optimal usage.April 11, 2013

 

ABAP Code Modularization: Lesson Learned

http://scn.sap.com/profile-image-display.jspa?imageID=3669&size=72It can’t be all Objects all the time! In this blog, Otto Gold shares tips and best practices on how to structure program code depending on the situation. Mine through the comments section and you’ll find more nuggets of wisdom. Mr. Gold provides more nuggets in “My "light" tricks for building more "robust" ABAP code.”March 22, 2013

 

How to Create a Watch Point for a Field Symbol in the ABAP Debugger

You can’t create a watch point for a field symbol. You'll get an error. Try telling that to Brian O'Neill, who said, “Even though I received an error, I do not like being told what I can't do in SAP, so I decided to find a way!” March 18, 2013

 

ABAP for SAP HANA Fitness Contest at DSAG Technology Days

http://scn.sap.com/profile-image-display.jspa?imageID=3662&size=72SAP Mentor Tobias Trapp writes about the ABAP for SAP HANA Fitness Contest at DSAG Technology Days. There 20 customers and partners had the chance to get early insights into what ABAP development on SAP HANA as primary persistence means. March 4, 2013

 

 


SAP TechEd Live Interviews for ABAP Developers

 

Get more interviews and lecture sessions from SAP TechEd Online. January 8, 2012

 

Optimizing ABAP for SAP HANA: SAP's 3-Step Approach

In this SAPinsider article, you'll learn SAP's three-step approach to optimize SAP NetWeaver Application Server (SAP NetWeaver AS) ABAP for the SAP HANA database. December 26, 2012


ABAP Development Tools: Now you can debug ABAP applications in Eclipse

http://scn.sap.com/profile-image-display.jspa?imageID=6190&size=72Want to debug your ABAP applications with native Eclipse debugger directly within the ABAP Development Tools (ADT) for Eclipse? Now it's possible since the availability of the new SAP Kernel 7.21 in combination with SAP Basis 7.31 SP4 (prerequisite for using ADT). Learn the capabilities of the new ABAP debugger in Eclipse also by watching the embedded video. December 3, 2012

 


SAP Insider: Turbocharge Your ABAP Development with Innovation from Eclipse

https://scn.sap.com/profile-image-display.jspa?imageID=2207&size=72With SAP NetWeaver 7.31, support package stack 4, SAP introduces ABAP development tools for SAP NetWeaver, also known as "ABAP in Eclipse," which brings Eclipse capabilities to ABAP Workbench (SE80) functionality. In this SAP Insider article, you'll learn more about ABAP in Eclipse and how it moves ABAP, which is ripe for productivity and usability improvements, into a complementary alignment with SAP's other Eclipse-based development environments. November 26, 2012

 

Crossing the Great Divide - Procedural vs. OO ABAP Programming

http://scn.sap.com/profile-image-display.jspa?imageID=4295&size=72Indulge in this blog by Paul Hardy from Hanson Australia Pty Ltd, as he takes us through his journey from the “old school” (he started procedural programming at age 14) to modern programming techniques. November 6, 2012

 

 

A Call to Arms for ABAP Developers

http://scn.sap.com/profile-image-display.jspa?imageID=2427&size=72 SAP Mentor Graham Robinson shares his concerns for those who have not kept in touch with contemporary development trends including ABAP skills. Read his “call to arms.” October 26, 2012

 

 

 

ABAP Development Tools Tutorials - Learn how to use ABAP in Eclipse

Want to learn fast all new features and capabilities of the ABAP in Eclipse IDE? Just step through the short ABAP Development Tools video tutorials online.October 16, 2012


ABAP Technology @ SAP TechEd 2012

Are you interested in the latest ABAP technology news and visiting one of the upcoming SAP TechEd 2012 events? This blog post gives a brief overview of sessions that might be of interest for you. September 25, 2012


ABAP Test Cockpit – SAP’s new quality assurance tool

Bugs in your custom ABAP code can be quite expensive when they impact critical business processes. Thus, SAP invested in the ABAP Test Cockpit (ATC), SAP’s new quality assurance tool for ABAP. Read this document to learn more about ATC. September 21, 2012


Free Trial on SCN for ABAP in Eclipse

Want to check out ABAP in Eclipse? Simply download the SCN trial version following the ABAP Development Tools for SAP NetWeaver - Trial Version document orvisit the new space focusing on the Eclipse-based ABAP Development Tools for SAP NetWeaver. July 5, 2012


SAP NetWeaver AS ABAP for HANA

How does ABAP help to leverage the benefits of in-memory database technology? This documentdescribes SAP's vision, strategy, development, and commitment to enable ABAP for SAP HANA. Also available in German language.June 25, 2012

 

ABAP in Eclipse is Here!

ABAP in Eclipse was shipped on 25 June with SAP NetWeaver AS ABAP 7.03/7.31 SP4. Visit the new space focusing on the Eclipse-based ABAP Development Tools for SAP NetWeaver, or “ABAP in Eclipse.” Check out Get Started with ABAP Development Tools for SAP NetWeaver, Working with ABAP Development Tools, and Download and Installation Instructions (SMP login required). June 26, 2012

 

"Light" Tricks for Building More "Robust" ABAP Code

http://scn.sap.com/profile-image-display.jspa?imageID=3669&size=72 SAP Mentor Otto Gold shares some thoughts on ABAP coding and general development, and sparks another robust discussion following his blog. Otto offers up more useful tricks in another recent blog, All you need to know about HR-PD Qualifications from the development perspective. June 12, 2012

 

 

Modernizing ABAP Development

Questions about code modernization and skills development tend to leave a big footprint on SCN. In this blog, Brian O'Neill of IGT asks how and whether to modernize. June 12, 2012

 

Customer Feedback on the Pilot Version of the ABAP Development Tools for SAP NetWeaver

http://scn.sap.com/profile-image-display.jspa?imageID=4972&size=72Also known as "ABAP in Eclipse," ABAP Development Tools for SAP NetWeaver were part of a customer engagement initiative to evaluate the pilot version. Olga Dolinskaja summarizes the results. May 3, 2012

 

 

 

Developer's Journal: ABAP/HANA Connectivity via Secondary Database Connection

http://scn.sap.com/profile-image-display.jspa?imageID=2203&size=72

Interested in how to access HANA from your ABAP systems? In his edition of the HANA Developer's Journal Thomas Jung expains how much can be done today when HANA runs as a secondary database for your current ABAP based systems and what development options within the ABAP environment support this  scenario. April 23, 2012


 

 

The quality of an answer depends significantly on the quality of the question (or: how to ask good questions)

In his post Hermann Gahmgives some useful hints how to ask 'good' questions and especially correct questions regarding ABAP code in order to get an answer of a good quality. April 23, 2012

 

ABAP Objects: Performance Analysis (SAT) with ABAP Unit

Posted by Bjorn-Henrik Zink. February 2, 2012

 

How to Do ABAP Nugget Based Code Migration

SAPlink is a project that aims to make it easier to share ABAP developments between programmers. It provides the ability to easily distribute and package custom objects. This article covers ABAP basis versions compatible with SAPlink and how to install the latest version of SAPlink. January 26, 2012

 

ABAP Keyword Documentation 7.03/7.31

The ABAP Keyword Documentation for Release 7.31 aka 7.03 is online. January 14, 2012

 

Coding and Performance Tips for New ABAP Programmers

In this blog, SAP Technology Analyst, Nabheet Madan, offers tips for new ABAP programmers who have just developed a few objects. Nabheet looks at fundamentals including documentation and reusable code, naming conventions, maintainability and performance optimization. January 3, 2012

 

2011

 

ABAP Trilemma

The ABAP development triangle is a model that describes the trilemma of ABAP development. In this blog, Elvez describes how the ABAP development triangle - performance, security and design - can be used as an agreement between developers on how to prioritize development efforts. December 13, 2011

Report for batch job detail extraction with step variant and variant values

$
0
0

This program does the following....

1. Extract data for any job with all details up to variant level including values of variables in the variant.

2. Find a particular job with variant value specified

 

It Provides the lowest level detail for a job and is very useful.

Dynamic selection screen

$
0
0

The purpose of this sample code is to generate select-options dynamically.

The selection-screen takes the table name as input and generates the select-options for the fields selected dynamically.

 

1.Selection screen:

Image1.JPG

 

 

2.Creating dynamic selection screen

Interface to read a table from the ABAP Dictionary

 

for example: iv_kotab = A549
CALL FUNCTION 'DDIF_TABL_GET'
EXPORTING
NAME
= IV_KOTAB
TABLES
DD03P_TAB
= GT_DD03P.

 

Build dynamic selection:

  •   Build Selections
    S_SELOPT
    -SIGN = 'I'.
    S_SELOPT
    -OPTION = 'EQ'.

 

LOOP AT GT_DD03P.
CASE GT_DD03P-FIELDNAME.
WHEN 'MANDT'
OR 'KAPPL'
OR 'KSCHL'
OR 'KNUMH'.
* Do nothing
WHEN OTHERS.
* Insert other selection
CONCATENATE
GT_DD03P
-TABNAME '-' GT_DD03P-FIELDNAME
INTO S_SELOPT-LOW.
APPEND S_SELOPT.
ENDCASE.
ENDCASE.
ENDLOOP.

 

Looping the seleopt table to generate the selection code

 

CONCATENATE 'SELECT-OPTIONS:' W_PARAMNAME INTO W_SRC
SEPARATED BY SPACE.
CONCATENATE W_SRC 'FOR' W_TABNAME INTO W_SRC
SEPARATED BY SPACE.
CONCATENATE W_SRC '-' W_FIELDNAME '.' INTO W_SRC.

* add field description at offset 42 - if possible
W_STRLEN
= STRLEN( W_SRC ).
IF W_STRLEN < 42.
WRITE: '"' TO W_SRC+42.
WRITE: W_FIELDTEXT TO W_SRC+43.
ELSE.
CONCATENATE W_SRC '"' W_FIELDTEXT INTO W_SRC.
ENDIF.

APPEND_LINE I_SELSCR_SRC W_SRC
.

* generate a text element for this select-option
CLEAR I_TEXTS.
I_TEXTS-
ID = 'S'.
I_TEXTS-
KEY = W_PARAMNAME.
I_TEXTS-ENTRY
= 'D'. "=take DDIC text if available
WRITE: W_FIELDTEXT TO I_TEXTS-ENTRY+8.
APPEND I_TEXTS.

* *****************************************
* Build some Types that reflects the Selection fields.
APPEND_EMPTY I_TYPES_SRC
.
CONCATENATE
'TYPES: BEGIN OF TP_' W_PARAMNAME+2(6) '.' INTO W_SRC.
APPEND_LINE I_TYPES_SRC W_SRC
.

CONCATENATE
'INCLUDE STRUCTURE' W_PARAMNAME '.' INTO W_SRC
SEPARATED BY SPACE.
APPEND_LINE I_TYPES_SRC W_SRC
.

CONCATENATE
'TYPES: END OF TP_' W_PARAMNAME+2(6) '.' INTO W_SRC.
APPEND_LINE I_TYPES_SRC W_SRC
.

 

  •   Combine all statements for selection include

    * Table declaration
    CONCATENATE
    'TABLES:' GV_KOTAB '.'
    INTO W_SRC SEPARATED BY SPACE.
    APPEND W_SRC TO L_SOURCE.

    * Frame start
    W_SRC =
    'SELECTION-SCREEN BEGIN OF BLOCK B0 WITH FRAME.'.
    APPEND W_SRC TO L_SOURCE.

    * Selection options
    APPEND LINES OF I_SELSCR_SRC TO L_SOURCE.

    * Frame end
    W_SRC =
    'SELECTION-SCREEN END OF BLOCK B0.'.
    APPEND W_SRC TO L_SOURCE.

    * Types
    APPEND LINES OF I_TYPES_SRC TO L_SOURCE.
    REFRESH I_TYPES_SRC.

    * ********************************
    * Add report title and change selection texts as text elements
    CLEAR I_TEXTS.
    I_TEXTS
    -ID = 'R'.
    I_TEXTS
    -ENTRY = 'Selection for Conversion of Condition Records'.
    APPEND I_TEXTS.
    SORT I_TEXTS BY ID KEY.

    * Create text elements
    DELETE TEXTPOOL C_DYN_REPID LANGUAGE SY-LANGU.
    INSERT TEXTPOOL C_DYN_REPID FROM I_TEXTS LANGUAGE SY-LANGU.

    * ********************************
    * Rebuild the selection include
    * program code inserted into ABAP repository
    INSERT REPORT C_DYN_REPID_SELECTION FROM L_SOURCE
    KEEPING DIRECTORY ENTRY.

 

Output:

 

Image2.JPG

Overcome Update Termination while using OIJ_NOM_MAINTAIN_MULTIPLE FM

$
0
0

When we try to update the Nomination using the Function Module OIJ_NOM_MAINTAIN_MULTIPLE, we get an Error Message ‘Update was terminated for xyz user’.

Pic1.png

 

 

The following screenshots are from SM13 Transaction Code:

 

 

pic2.png

pic3.JPG

After debugging the standard Function Module, we found out it is due to insertion of repeated records.

pic4.png

 

In the above piece of code (SAP standard Function Module), the Internal Table is not sorted and in READ statement, BINARY SEARCH is used. This is causing the problem.

Hence, we sorted the Internal Table by NOMTK , NOMIT and then passed to the Function Module OIJ_NOM_MAINTAIN_MULTIPLE which resolved the issue.

SORT l_t_nomi BY nomtk nomit.

CALLFUNCTION'OIJ_NOM_MAINTAIN_MULTIPLE'
    EXPORTING
      it_nom_header       = p_l_t_headerdata
      it_nom_item         = p_l_t_nomi
      iv_update_worklist  = c_on
      iv_update_stockproj = c_on
      iv_add_to_log       = c_on
      iv_internal         = c_on
      iv_lock             = c_off
      iv_application      =
'NOMINATION'
    IMPORTING
      et_return           = l_t_return
   
EXCEPTIONS
      nomination_locked   = 1
      error_phase_01      = 2
      error_phase_02      = 3
      OTHERS              = 4.

Getting Started with AS ABAP 7.4 SP5 incl. BW on SAP HANA SP7 [Developer Edition]

$
0
0

This guide describes how to set up and run the developer edition of Application Server ABAP 7.4 SP5 on SAP HANA SP7, which is provided as virtual appliance by the SAP Cloud Appliance Library.

View this Document

Viewing all 935 articles
Browse latest View live