Thursday, March 19, 2020

READ_TEXT Function Module call in program In SAP ABAP.


READ_TEXT Function Module Use in SAP.


READ_TEXT Function Module.

DATA:lv_output_text TYPE char50.

PERFORM f_read_text USING 'ABCD'            " Text ID
                          'E'               " Text Language
                          '12345678'        " Text Name
                          'VBBK'            " Text Object
                 CHANGING lv_output_text.   " Return Text

*Display the standard text.
WRITE lv_output_text.

*----------------------------------------------------------------------*
FORM f_read_text USING pi_textid      TYPE thead-tdid
                       pi_language    TYPE thead-tdspras
                       pi_name        TYPE thead-tdname
                       pi_object      TYPE thead-tdobject
              CHANGING pc_output_text TYPE char50.
*----------------------------------------------------------------------*
* Data Declarations.
* Internal Tables.
  DATA:
    lt_lines TYPE STANDARD TABLE OF tline.

* Field Symbols.
  FIELD-SYMBOLS:
    <fs_lines> TYPE tline.

* Clearing field to be on the safer side.
  CLEAR pc_output_text.

  CALL FUNCTION 'READ_TEXT'
    EXPORTING
      id                             = pi_textid
      language                  = pi_language
      name                        = pi_name
      object                  = pi_object
    TABLES
      lines                         = lt_lines
    EXCEPTIONS
      id                             = 1
      language                  = 2
      name                        = 3
      not_found            = 4
      object                   = 5
      reference_check         = 6
      wrong_access_to_archive = 7
      OTHERS                  = 8.

  IF sy-subrc EQ 0.

*  Fetch the text from the FM table.
    READ TABLE lt_lines
    ASSIGNING <fs_lines>
    INDEX 1.

    IF sy-subrc EQ 0.

*    Standard text Details.
      pc_output_text = <fs_lines>-tdline.

    ENDIF.

  ENDIF.

ENDFORM.

Wednesday, March 18, 2020

Implement BADI BADI_ACC_DOCUMENT for Enabling Parameter Extension2 .

Implement BADI BADI_ACC_DOCUMENT for Enabling Parameter Extension2 in BAPI_ACC_DOCUMENT_POST.


Implement BADI BADI_ACC_DOCUMENT.




BAPI_ACC_DOCUMENT_POST is meanly used to create FI documents like as GL, AP, and AR (TCode F-02). This BAPI, there are EXTENTION2 table parameters that can be used to throw data for which fields are not provided by BAPI BAPI_ACC_DOCUMENT_POST, such as the Ref field. Key 1 Header (BKPF-XREF1_HD), or even for the need to change the key post from the journal to be made.

However, this EXTENTION2 parameter will only function if BADI_ACC_DOCUMENT has been implemented. Following are the steps for implementing BADI_ACC_DOCUMENT:

Copy class CL_EXM_IM_ACC_DOCUMENT to custome class YCL_EXM_IM_ACC_DOCUMENT via SE24. Activate.
Run TCode SE19 and create BADI_ACC_DOCUMENT in the Create Implementation >> New BAdI section.

Write the name of the BAdI Enhancement Implementation along with the Composite Enhancement Implementation (if there is no composite yet, create it first.


• Enter the name of the BAdI custome in step 3 and the name of the custom class in step 1, and select the name BAdI Definitioan = BADI_ACC_DOCUMENT.

1.Save & Activate.



1.On the Technical Tab, double click the custom class for BAdI custom coding according to the requirement.



1.Double click the ~ CHANGE method to start coding.

  • Save & Activate
  • ABAP program, the passing parameter extension2 is as follows


  DATA:  ld_header LIKE bapiache09,
         ld_objkey LIKE bapiache09-obj_key,
         lt_gl     LIKE bapiacgl09 OCCURS 0 WITH HEADER LINE,
         lt_ap     LIKE bapiacap09 OCCURS 0 WITH HEADER LINE,
         lt_amt    LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE,
         lt_ext    LIKE bapiparex OCCURS 0 WITH HEADER LINE,
         lt_ret    LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
         ld_itemno LIKE bapiacgl09-itemno_acc,

  CONSTANT: c_struct TYPE TE_STRUC VALUE 'XREF1_HD'.

    CLEAR lt_ext.
    ADD 1 TO ld_itemno.
    lt_ext-structure   = c_struct.
    lt_ext-valuepart1  = ld_itemno.
    lt_ext-valuepart2  = 'Test Ref Key Header'.
    APPEND lt_ext.

    CLEAR lt_ext.
    ADD 1 TO ld_itemno.
    lt_ext-structure   = c_struct.
    lt_ext-valuepart1  = ld_itemno.
    lt_ext-valuepart2  = 'Test Ref Key Header'.
    APPEND lt_ext.

*isi parameter ld_header, lt_gl, lt_amt sesuai requirement.
    CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
      EXPORTING
        documentheader = ld_header
      IMPORTING
        obj_key        = ld_objkey
      TABLES
        accountgl      = lt_gl
        accountpayable = lt_ap
        currencyamount = lt_amt
        return         = lt_ret
        extension2     = lt_ext
      EXCEPTIONS
        OTHERS         = 1.

    IF ld_objkey IS INITIAL OR ld_objkey EQ '$'.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ENDIF.
 The CHANGE method does the following coding:
  DATA: wa_extension   TYPE bapiparex,
        wa_accit       TYPE accit,
        ld_posnr       TYPE posnr_acc.

  LOOP AT c_extension2 INTO wa_extension.
    ld_posnr = wa_extension-valuepart1.
    READ TABLE c_accit WITH KEY posnr = ld_posnr
          INTO wa_accit.
    IF sy-subrc IS INITIAL.
      IF wa_extension-structure = 'XREF1_HD'.
        wa_accit-xref1_hd = wa_extension-valuepart2.
        MODIFY c_accit FROM wa_accit index sy-tabix TRANSPORTING xref1_hd.
      ENDIF.
    ENDIF.
  ENDLOOP.




BAPI for FI documents post (BAPI_ACC_DOCUMENT_POST).


BAPI BAPI_ACC_DOCUMENT_POST.

BAPI_ACC_DOCUMENT_POST.



This post FI documents in a program. To this need, it would be better if you use the standard BAPI from SAP, rather than using BDC. Why? Because BDC is based on screen to screen, and if functional does customizing screens for FI transactions, it is difficult for developer to change their BDC according to customizing functional.

This FI documents post BAPI is commonly used BAPI_ACC_DOCUMENT_POST.

Below we discuss the following parameters need to be filled in to run this BAPI.

 DATA:  ld_documentheader like bapiache09,
        lt_accountgl like table of bapiacgl09 with header line,
        lt_currencyamount like table of bapiaccr09 with header line,
        lt_return like table of bapiret2 with header line.

  DATA: ld_comp_code type bukrs,
        ld_gl1 type hkont,
        ld_gl2 type hkont,
        ld_gsber type gsber,
        ld_costcent type kostl,
        ld_profcent type prctr,
        ld_waers type waers,
        ld_amount type bapiwrbtr,
        ld_key like bapiache09-obj_key,
        ls_return like bapiret2,
        ls_nodoc like bseg-belnr.

*  - Documentheader
    ld_documentheader-username = sy-uname.
    ld_documentheader-header_txt = 'Header Text'.
    ld_documentheader-comp_code = ld_comp_code.
    ld_documentheader-doc_date = sy-datum.
    ld_documentheader-pstng_date = sy-datum.
    ld_documentheader-fisc_year = sy-datum(4)."optional
    ld_documentheader-fis_period = sy-datum+4(2)."optional
    ld_documentheader-doc_type = 'SA'.
    ld_documentheader-ref_doc_no = 'Ref Doc No.'.

*  - Accountgl
*  -- Item 1
    lt_accountgl-itemno_acc = 1.
    lt_accountgl-gl_account = ld_gl1.
    lt_accountgl-item_text = 'Text GL 1'.
    lt_accountgl-doc_type = 'SA'.
    lt_accountgl-comp_code = ld_documentheader-comp_code.
    lt_accountgl-bus_area = ld_gsber.
    lt_accountgl-pstng_date = sy-datum.
    lt_accountgl-value_date = sy-datum.
    lt_accountgl-costcenter = ld_costcent.
    lt_accountgl-profit_ctr = ld_profcent.
    append lt_accountgl.

*  -- Item 2
    lt_accountgl-itemno_acc = 2.
    lt_accountgl-gl_account = ld_gl2.
    lt_accountgl-item_text = 'Text GL 2'.
    clear lt_accountgl-costcenter.
    append lt_accountgl.

*  - Currencyamount
*  -- Item 1
    lt_currencyamount-itemno_acc = 1.
    lt_currencyamount-currency = ld_waers.
    lt_currencyamount-amt_doccur = ld_amount.
    if lt_currencyamount-currency eq 'IDR'.
      lt_currencyamount-amt_doccur =
        lt_currencyamount-amt_doccur * 100.
    endif.
    append lt_currencyamount.

*  -- Item 2
    lt_currencyamount-itemno_acc = 2.
    lt_currencyamount-amt_doccur = -1 * lt_currencyamount-amt_doccur.
    append lt_currencyamount.

*  - Call BAPI
    call function 'BAPI_ACC_DOCUMENT_POST'
      exporting
        documentheader = ld_documentheader
      importing 
        obj_key        = ld_key
      tables
        accountgl      = lt_accountgl
        currencyamount = lt_currencyamount
        return         = lt_return.

    read table lt_return with key type = 'S'.
    if sy-subrc eq 0.
*  - Commit BAPI
    call function 'BAPI_TRANSACTION_COMMIT'
      exporting
        wait   = 'X'
      importing
        return = ls_return.
      if not ls_return is initial.
*  - ROLLBACK
        call function 'BAPI_TRANSACTION_ROLLBACK'
          importing
            return = fs_return.
      else.
        ld_nodoc = ld_key(10).
      endif.
    else.
*  - ROLLBACK
      call function 'BAPI_TRANSACTION_ROLLBACK'
        importing
          return = fs_return.
    endif.


If this document post is successful, after that the program will commit the transaction and will import the document number into the local data ld_key. If  BAPI fails, after that program will rollback the transaction.



Upload text file to internal table in SAP ABAP.



Upload text file to internal table in SAP ABAP.


Upload text file to internal table.

It was explained how to get all the file from the local system to fetch the text file to be uploaded. Well, This post is an example of using the function module to process text files that are uploaded into the internal table. The function used for uploading is GUI_UPLOAD.

To upload the flat text passing parameter file 'ASC', while the delimited tab use 'DAT'.

*&---------------------------------------------------------------------*
*&      Data Declaration
*&---------------------------------------------------------------------*
TABLES: rlgrap.

TYPES: BEGIN OF ty_item,
        ebeln LIKE ekpo-ebeln,
        ebelp LIKE ekpo-ebelp,
      END OF ty_item.

DATA: t_item TYPE STANDARD TABLE OF ty_item WITH HEADER LINE.

SELECT-OPTIONS: s_file FOR rlgrap-filename NO INTERVALS NO-EXTENSION.

*&---------------------------------------------------------------------*
*&      Events
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_file-low.
  PERFORM f_help_for_file CHANGING s_file-low.

START-OF-SELECTION.
  PERFORM f_upload_data TABLES t_item.

  LOOP AT t_item.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = t_item-ebeln
      IMPORTING
        output = t_item-ebeln.
    MODIFY t_item.
  ENDLOOP.
*&---------------------------------------------------------------------*
*&      Form  f_help_for_file
*&---------------------------------------------------------------------*
FORM f_help_for_file  CHANGING s_file-low.

  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      static    = 'X'
    CHANGING
      file_name = s_file-low.

ENDFORM.                    " F_HELP_FOR_FILE

*&---------------------------------------------------------------------*
*&      Form  f_upload_data
*&---------------------------------------------------------------------*
FORM f_upload_data TABLES ft_table.
  DATA: ld_string TYPE string.

  ld_string = s_file-low.
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = ld_string
      filetype                = 'ASC'
      has_field_separator     = ' '
    TABLES
      data_tab                = ft_table
    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 NE 0.
    WRITE: 'error', sy-subrc.
    STOP.
  ENDIF.

ENDFORM.                    " F_UPLOAD_DATA

Customer Exit and BAdI for PO in SAP

Customer Exit and BAdI for PO.

BAdI for PO.




The following is a list of customer Exits and BADI that I have used to date, along with their functions:

BADI ME_PURCHDOC_POSTED
Method: POSTED
TCode: ME22N, ME23N, ME29N

BADI ME_PROCESS_PO_CUST
Method: CLOSED
TCode: ME22N, ME23N, ME29N

Customer Exit MM06E005 (Customer fields in purchasing documents)
EXIT_SAPMM06E_016 (Export Data to Customer Subscreen for Purchasing Document Items (PBO))
desc: can be used to validate the header line or line item before
data storage process. so later validation checks will be made at the time
the user presses enter after inputting data on the subscreen.

Actually there are many more exits that can be used. I wrote only a few possible references.

Tuesday, March 17, 2020

SCC1 in SAP.


SCC1  Client Copy.
SCC1
T-Code: SCC1 this t-code use for supplement to the client copy. It can be used to meanly transfer individual transport request to directly out for the source client into the current client. This activities are listed in a clearly structured copy log. Example, you can start the report in test mode, which generates a log as in the production run but does not perform any database update. If the number or size of the tables is very large, you are recommended to start this report in the background process.

T-Code: SCC1 this is different from T-code: STMS because transaction code.SCC1 T-code is used to transport request from different client in the same system.