Thursday, 17 April 2014

BAPI for posting Down payment Request F-47

Note :For the F-47 posting, it only post to 1 line item whereby BAPI "BAPI_ACC_DOCUMENT_POST" have to post in 2 lines for balance the account. 


*&---------------------------------------------------------------------*
*& REPORT  ZFI_DOWNPAYMENT
*&
*&---------------------------------------------------------------------*
*&Source : http://abaptechnicalhelp.blogspot.com
*&Author : Kartikeyan K
*&Email : Karthikeyana2z@gmail.com
*&---------------------------------------------------------------------*

REPORT  ZFI_DOWNPAYMENT.

DATA :  T_ACCHD TYPE TABLE OF ACCHD WITH HEADER LINE,
        T_ACCIT TYPE TABLE OF ACCIT  WITH HEADER LINE,
        T_ACCCR TYPE TABLE OF ACCCR  WITH HEADER LINE,
        T_RETURN TYPE TABLE OF MESSAGE_STRUCT  WITH HEADER LINE.
T_ACCHD-MANDT = SY-MANDT.
T_ACCHD-AWTYP = 'BKPFF'.
T_ACCHD-GLVOR = 'RFBU'.
T_ACCHD-TCODE = 'F-47'.
T_ACCHD-BKTXT = 'TEST1'.
T_ACCHD-USNAM = SY-UNAME.
APPEND T_ACCHD.
CLEAR T_ACCHD.

T_ACCIT-MANDT = SY-MANDT.
T_ACCIT-POSNR = '000001'.
T_ACCIT-GSBER = '1015'.
T_ACCIT-BUKRS = '5010'.
T_ACCIT-BLDAT = SY-DATUM.
T_ACCIT-BUDAT = SY-DATUM.
T_ACCIT-BLART = 'KA'.
T_ACCIT-XBLNR = 'XBLNR-TEST'.
T_ACCIT-VORGN = 'AZAF'.
*T_ACCIT-BUPLA = .
T_ACCIT-UMSKZ = 'F'.
T_ACCIT-ZUMSK = 'A'.
T_ACCIT-BSTAT = 'S'.
T_ACCIT-BSCHL = '39'.
T_ACCIT-SHKZG = 'H'.
T_ACCIT-KOART = 'K'.
T_ACCIT-ZFBDT = '20140430'.
T_ACCIT-ZLSPR = 'P'.
T_ACCIT-EBELN = '4500000664'.
T_ACCIT-EBELP = '000001'.
T_ACCIT-LIFNR = '0000020070'.
APPEND T_ACCIT.
CLEAR T_ACCIT.
T_ACCCR-MANDT = SY-MANDT.
T_ACCCR-AWTYP = 'BKPFF'.
T_ACCCR-POSNR = '000001'.
T_ACCCR-WAERS = 'INR'.
T_ACCCR-WRBTR = '-1000'.
T_ACCCR-CURTP = '00'.
*T_ACCCR-CURTP = '10'.
APPEND T_ACCCR.
CLEAR T_ACCCR.
T_ACCCR-MANDT = SY-MANDT.
T_ACCCR-AWTYP = 'BKPFF'.
T_ACCCR-POSNR = '000001'.
T_ACCCR-WAERS = 'INR'.
T_ACCCR-WRBTR = '-1000'.
T_ACCCR-CURTP = '10'.
APPEND T_ACCCR.
CLEAR T_ACCCR.
DATA : E_BUKRS TYPE  BUKRS,
       E_BELNR TYPE  BELNR_D,
       E_GJAHR TYPE  GJAHR.
CALL FUNCTION 'RFIDPT_ACC_DOCUMENT_POST_ADJ'
* EXPORTING
*   I_COMP             = ' '
*   I_COMP_CHECK       = ' '
*   I_FREE_TABLE       = 'X'
*   I_TEST             = 'X'
 IMPORTING
   E_BUKRS            = E_BUKRS
   E_BELNR            = E_BELNR
   E_GJAHR            = E_GJAHR
  TABLES
    T_ACCHD            = T_ACCHD
    T_ACCIT            = T_ACCIT
    T_ACCCR            = T_ACCCR
*   T_ACCTX            =
    T_RETURN           = T_RETURN
          .
FREE T_RETURN.

Monday, 31 March 2014

Adding extra tabs in standard transactions for sales and contracts without access key

NTRODUCTION:

This post will explain in detail about adding an additional Tab to standard transactions for sales order (VA01, VA02, and VA03), contract documents (VA41, VA42, and VA43) and other related transactions of the program SAPMV45A.

HISTORY:

-->When I had this requirement of adding an additional tab, I started with my research on this across SCN and other SAP related sites. Irrespective of my long research I could not find any solution for this requirement without the need of ACCESS KEY.

-->However there are solution for this requirement which requires ACCESS KEY.  There are two additional tabsADDITIONAL TAB A and ADDITIONAL TAB B which SAP has provided to add customer specific fields. The related screens for modifying these tabs are 8459, 8309.

FEW IMPORTANT POINTS ABOUT THESE TABS:

è The Additional TAB A and B are designed by SAP before the advent of BADI based plug in screens.

è The screens 8309, 8549 are never touched during upgrades, however taking access key could mean that the objects we are changing should be registered for SCCR and special care should be taken during upgrades to protect the change as they fall in SAP naming spaces.

è SAPMV45A / 8459 or 8309 even if they are in SAP naming space they are for customer modifications and SAP won’t overwrite them during upgrades.

è There are few ABAPers who are in a wrong assumption that SAP didn’t provide any BADI for this screen modification since many customers have already satisfied their need with the TABS A and B which is wrong.

è SAP has provided a BADI to add additional TABS up to 5(as far as my knowledge) to accommodate any user specific fields which depends on the later requirements of the customer.

STEP BY STEP IMPLEMENTATION OF THE BADI:

In this blog post I will explain in detail steps on how to implement the BADI.

STEP 1:

Go to transaction SE18 and give the badi name as BADI_SLS_ITEM_SCR_CUS. Click Display.

1.PNG
TEP 2:

You will be lead into this page where you can see several BADI definitions, you can see the purpose of each BADIs by reading its description.

2.PNG

STEP 3:

Now our intention here is to add additional tabs only at item level so we select the BADI accordingly, however there are different BADI for different purpose.
Now right click on the badi BADI_SLS_ITEM_SCR_CUS as below and select create implementation.
3.PNG 

STEP 4:

Click on the paper icon as marked below in red to create a new implementation.
4.PNG


STEP 5:

Give a meaningful name for the implementation as shown below.
5.PNG


STEP 6:

Give a meaningful name for the enhancement implementation and description as shown below and click the TICK icon as shown below marked in red.
6.PNG

STEP 7:

Now you will be popped up with another window as below.
7.PNG

STEP 8:

Give a meaningful name for the implementation as shown below in the boxes below.
8.PNG


STEP 9:

Give a meaningful name for the implementation as shown below in the boxes below. Please note that all the details that you have filled earlier is for enhancement and now it is for BADI.
9.PNG

STEP 10:

Give a meaningful name for the implementation as shown below in the boxes below. Class name should be same as given below, this is the class method where you will write the code.
10.PNG

STEP 11:

Activate now, after activation you will be displayed with a screen as shown below which indicates that the enhancement and BADI implementation is complete.
11.PNG

STEP 12:

Now Go out and come again into the transaction SE18 and you can see the below screen.
12.PNG


STEP 13:

Click on the enhancement implementation tab and you will see the implementation that you have created, double click on that.

13.PNG

STEP 14:

Now you will be able to see the window as below.
14.PNG

STEP 15:

Now you will be able to see the window as below. Double click on the class method.

15.PNG


STEP 16:

Now you will be able to see the window as below. Double click on the first method as shown below to code for adding the tab.

16.PNG

Now you will be able to see the screen as below, in the field caption give the ‘name of the tab’,
In the field program give the ‘module program name’, in the field dynpro give the ‘screen number’, give all the details in single quants.
Important points:
1)      Module Program: This program should contain the screen which will have the required fields and the respective logic for the fields.
2)      Screen Number: This should be screen which you want to get displayed under the Tab that you have defined.
3)      Please note that the screen that you create here must be a sub screen and not main screen failing which it will lead to a runtime error.
4)      Please note that in the if condition I have given as
                                                --> If sy-tcode cp ‘VA4*’.
Which means this tab will be there for all the item details in the contract transactions like va41, va42, va43. So you can code as per your requirement.

l1.PNG


Now after activating if you go to the required transaction you will be able to see the tab you have added as below. These fields are placed as per your requirement.

l2.PNG

Thursday, 14 November 2013

Converting Char string to Text Element Automatically

Converting Char string to Text Element Automatically


*&---------------------------------------------------------------------*
*& Report  ZSLIN
*&
*&---------------------------------------------------------------------*
*& Report Title            : <Description>
*& SAP Release             : 6.0
*& Author's Name           :
*& Creation Date           : 99/99/9999 (DD/MM/YYYY)
*
*& Description            : <Description explaining Functionality>
*&<Description explaining Functionality>
*&<Description explaining Functionality>
*&<Description explaining Functionality>
*&---------------------------------------------------------------------*
REPORT  ZSLIN.
TYPE-POOLS :SLIS, SLIN.
TYPES: BEGIN OF TY_CODE,
         CODE(5000) TYPE C,
       END OF TY_CODE.

DATA:  IT_OLD TYPE STANDARD TABLE OF TY_CODE,
       IT_NEW TYPE STANDARD TABLE OF TY_CODE,
       IT_TEXT_OLD TYPE TABLE OF TEXTPOOL,
       IT_TEXT_NEW TYPE TABLE OF TEXTPOOL,
       WA_TEXT_N TYPE TEXTPOOL,
       GV_KEY TYPE n LENGTH 3,
       W_SAVE(1) TYPE C.
******************************************************************
*     S E L E C T I O N   S C R E E N
******************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME .
PARAMETERS:
       P_REPORT LIKE SY-REPID OBLIGATORY.   " Program Name
*       P_TABLES    AS CHECKBOX,
*       P_TYPES     AS CHECKBOX,
*       P_DATA      AS CHECKBOX,
*       P_CNSTNT AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK B1.
***********************************************************************
*     AT SELECTION SCREEN
***********************************************************************
*AT SELECTION-SCREEN.
*  IF P_TABLES = '' AND P_TYPES = '' AND P_DATA = '' AND P_CNSTNT = ''.
*    MESSAGE TEXT-001 TYPE 'E'.
*  ENDIF.
***********************************************************************
*     START OF SELECTION
***********************************************************************
START-OF-SELECTION.
***********
  PERFORM CHECK CHANGING W_SAVE.
  CHECK W_SAVE EQ 'X'.
  PERFORM GETDATA.
  PERFORM SAVE.
***********

*&---------------------------------------------------------------------*
*&      Form  CHECK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CHECK CHANGING W_SAVE.
  TYPES:  BEGIN OF TY_PROGDIR,
           NAME TYPE PROGDIR-NAME , " ABAP Program Name
           STATE TYPE PROGDIR-STATE , " ABAP: Program Status (Active, Saved, Transported...)
         END OF TY_PROGDIR.

  DATA:
          LT_PROGDIR TYPE STANDARD TABLE OF TY_PROGDIR.
  DATA:
         W_FLAG_TYPES TYPE C,
         W_FLAG_TABLES TYPE C,
         W_FLAG_DATA TYPE C,
         W_FLAG_CONSTANT TYPE C,
         W_DEVCLASS TYPE TADIR-DEVCLASS, " Package
         W_UNAME TYPE TRDIR-UNAM, " Last changed by
         W_LOCK TYPE E071-LOCKFLAG, " Lock status or import status of an object entry
*       W_SAVE(1) TYPE C,
         W_SHIFT1(1) TYPE C VALUE 7,
         W_SHIFT2(2) TYPE C VALUE 9.
*         W_SAVE(1) TYPE C,
*         W_DEVCLASS TYPE TADIR-DEVCLASS. " Package
* Check to see if the program is active or not.
  SELECT NAME STATE FROM PROGDIR INTO TABLE LT_PROGDIR
  WHERE NAME = P_REPORT.
  IF SY-DBCNT > 1.
    MESSAGE TEXT-005 TYPE 'I'.
    W_SAVE = ''.
    LEAVE TO LIST-PROCESSING.
  ELSEIF SY-DBCNT = 0.
    MESSAGE TEXT-006 TYPE 'I'.
    W_SAVE = ''.
    LEAVE TO LIST-PROCESSING.
  ELSE.
* Check to see if the program is a local private object ($TMP)
    SELECT SINGLE DEVCLASS
    FROM  TADIR
    INTO W_DEVCLASS
    WHERE PGMID    = 'R3TR' AND
          OBJECT   = 'PROG' AND
          OBJ_NAME = P_REPORT.
    IF SY-SUBRC = 0 AND W_DEVCLASS = '$TMP'.
* Check the development class of the program.
      W_SAVE = 'X'.
    ELSE.
      SELECT SINGLE UNAM
      FROM  TRDIR
      INTO W_UNAME
      WHERE  NAME = P_REPORT.
* Check the user who  last changed the program.
      IF SY-SUBRC = 0 AND W_UNAME <> SY-UNAME.
        W_SAVE = ''.
        MESSAGE
        TEXT-007 TYPE 'I'.
        W_SAVE = ''.
        LEAVE TO LIST-PROCESSING.
      ELSE.
        SELECT SINGLE LOCKFLAG
        FROM  E071
        INTO W_LOCK
        WHERE ( ( PGMID = 'R3TR' AND OBJECT = 'PROG' )   OR
                 ( PGMID = 'LIMU' AND OBJECT = 'REPS' ) ) AND
                 OBJ_NAME = P_REPORT.
* Check if the program is assisgned to a transport or not.
        IF SY-SUBRC = 0 AND W_LOCK = 'X'.
          W_SAVE = 'X'.
        ELSE.
          MESSAGE  TEXT-008 TYPE 'I'.
          W_SAVE = ''.
          LEAVE TO LIST-PROCESSING.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.                    " CHECK
*&---------------------------------------------------------------------*
*&      Form  GETDATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GETDATA .
  READ REPORT P_REPORT INTO IT_OLD.
  IT_NEW[] = IT_OLD[].
  READ TEXTPOOL P_REPORT INTO IT_TEXT_OLD.
  IT_TEXT_NEW[] = IT_TEXT_OLD[].
  DELETE IT_TEXT_NEW WHERE ID NE 'I' OR KEY CA 'wertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'.
  SORT IT_TEXT_NEW DESCENDING BY KEY.
  READ TABLE IT_TEXT_NEW INTO WA_TEXT_N INDEX 1.
  GV_KEY = WA_TEXT_N-KEY.
  FREE IT_TEXT_NEW[].
  CLEAR WA_TEXT_N.
  DATA: IT_RESULT     TYPE SLIN_RESULT,                     " OCCURS 0,
        WA_RESULT TYPE SLIN_RESULT WITH HEADER LINE,
        RESULTSTAT TYPE SLIN_RESULT_STAT,
        STATUS TYPE RSLIN.
  TYPES :BEGIN OF ST,
          KEY TYPE STRING,
          VALUE TYPE STRING,
         END OF ST.
  TYPES :BEGIN OF ST1,
          TXT_NO TYPE N LENGTH 3,
          SRC_LINE TYPE N LENGTH 4,
          VALUE TYPE STRING,
         END OF ST1.
  DATA: LINE TYPE SLIN_LINE,
        ARGS LIKE TABLE OF LINE-ARGS,
        WA_TEXT TYPE STRING,
        WA_AGRS TYPE ST,
        WA_AGRS1 TYPE ST1,
        GT_ARGS TYPE TABLE OF ST1.

  STATUS-X_ALL = '' .
  STATUS-FLAGS-X_TXT = 'X'.
  CALL FUNCTION 'EXTENDED_PROGRAM_CHECK'
    EXPORTING
      PROGRAM      = P_REPORT
      COMMENT_FLAG = STATUS-X_ALL
      TEST_FLAGS   = STATUS-FLAGS
      CACHE_USE    = 'A'
    IMPORTING
      RESULT       = IT_RESULT
      RESULT_STAT  = RESULTSTAT
    EXCEPTIONS
      FATAL_ERROR  = 0.

  FREE LINE-ARGS[].
  FREE WA_RESULT-LINES[].
  CLEAR :WA_RESULT, LINE, WA_AGRS.
  LOOP AT IT_RESULT INTO WA_RESULT.
    LOOP AT WA_RESULT-LINES INTO LINE WHERE KEY = '&1'.
      LOOP AT LINE-ARGS INTO WA_AGRS.
        WA_TEXT_N-ID = 'I'.
        CONDENSE gv_key.
        gv_key = gv_key + 1.
        WA_TEXT_N-KEY = gv_key.
        WA_TEXT_N-LENGTH = strlen( WA_AGRS-VALUE ).
        WA_TEXT_N-LENGTH = WA_TEXT_N-LENGTH - 2.
        WA_TEXT_N-ENTRY = WA_AGRS-VALUE."+1(WA_TEXT_N-LENGTH).
*        WA_AGRS1-VALUE = WA_AGRS-VALUE.
        APPEND WA_TEXT_N TO IT_TEXT_NEW.
        CLEAR :WA_TEXT_N, WA_AGRS.
      ENDLOOP.
      FREE LINE-ARGS[].
    ENDLOOP.
    FREE WA_RESULT-LINES[].
  ENDLOOP.
  DATA : GV_TEXT TYPE STRING.
  LOOP AT IT_TEXT_NEW INTO WA_TEXT_N.
    CLEAR GV_TEXT.
    CONCATENATE 'TEXT' WA_TEXT_N-KEY INTO GV_TEXT SEPARATED BY '-'.
    CONDENSE GV_TEXT.
    REPLACE ALL OCCURRENCES OF REGEX WA_TEXT_N-ENTRY
    IN TABLE IT_NEW WITH GV_TEXT
    RESPECTING CASE.
    WA_TEXT_N-ENTRY = WA_TEXT_N-ENTRY+1(WA_TEXT_N-LENGTH).
    MODIFY IT_TEXT_NEW FROM WA_TEXT_N TRANSPORTING ENTRY.
  ENDLOOP.

*  ENDIF.

  LOOP AT IT_TEXT_OLD INTO WA_TEXT_N.
    APPEND WA_TEXT_N TO IT_TEXT_NEW.
    CLEAR WA_TEXT_N.
  ENDLOOP.
  SORT IT_TEXT_NEW.
ENDFORM.                    " GETDATA
*&---------------------------------------------------------------------*
*&      Form  SAVE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SAVE .


  DATA:
         L_MESSAGE TYPE MESSAGE.
  CALL FUNCTION 'PRETTY_PRINTER'
    EXPORTING
      INCTOO                        = SPACE
* IMPORTING
*   INDENTATION_MAYBE_WRONG       = INDENTATION_MAYBE_WRONG
    TABLES
      NTEXT                         = IT_NEW
      OTEXT                         = IT_NEW
   EXCEPTIONS
     ENQUEUE_TABLE_FULL            = 1
     INCLUDE_ENQUEUED              = 2
     INCLUDE_READERROR             = 3
     INCLUDE_WRITEERROR            = 4
            .

  CALL FUNCTION 'ENQUEUE_E_TRDIR'
   EXPORTING
     MODE_TRDIR           = 'X'
     NAME                 = P_REPORT
*   X_NAME               = ' '
*   _SCOPE               = '2'
*   _WAIT                = ' '
*   _COLLECT             = ' '
   EXCEPTIONS
     FOREIGN_LOCK         = 1
     SYSTEM_FAILURE       = 2
            .
  IF SY-SUBRC = 0.
    INSERT REPORT P_REPORT FROM IT_NEW.
    IF SY-SUBRC = 0.
      INSERT TEXTPOOL P_REPORT FROM IT_TEXT_NEW LANGUAGE SY-langU.
      IF SY-SUBRC = 0.
        WRITE: / TEXT-002.
      ELSE.
        WRITE: / TEXT-003.
      ENDIF.
    ELSE.
      ROLLBACK WORK.
      WRITE: / TEXT-003.
    ENDIF.
  ELSEIF SY-SUBRC = 1 OR SY-SUBRC = 2 OR SY-SUBRC = 3.
    CALL FUNCTION 'FORMAT_MESSAGE'
      EXPORTING
        ID        = SY-MSGID
        LANG      = '-D'
        NO        = SY-MSGNO
        V1        = SY-MSGV1
        V2        = SY-MSGV2
        V3        = SY-MSGV3
        V4        = SY-MSGV4
      IMPORTING
        MSG       = L_MESSAGE
      EXCEPTIONS
        NOT_FOUND = 1
        OTHERS    = 2.
    IF SY-SUBRC = 0.
      WRITE:/ L_MESSAGE.
      EXIT.
    ENDIF.
  ENDIF.
* Unlock the program after changing.
  CALL FUNCTION 'DEQUEUE_E_TRDIR'
    EXPORTING
      MODE_TRDIR = 'X'
      NAME       = P_REPORT.

  FREE :IT_TEXT_NEW, IT_TEXT_OLD.
ENDFORM.                    " SAVE