Category Archives: ABAP

Create and change SAP tables without coding or debugging

To create/change the content of a table (usually for test purposes), we typically use SE16 to write a report program or debug. But, with this tip, you can do it easily through a SAP standard technique without coding or debugging.Code:
1. Call transaction SE16N and enter the required table name to be edited(ex. KNA1).
2. type ‘&sap_edit’ in the command window and press enter key. The message ‘SAP editing function is activated’ will display.
3. Click on the execute online button (F8). Now the table will be in edit mode!

Advertisement

Sales Order Changed History Display

You can execute the report by :

1.  Change Date

2.  User Name

3.  Sales Order Number

REPORT ZSDCHANGE LINE-SIZE 132 NO STANDARD PAGE HEADING

                 LINE-COUNT 065(001)

                 MESSAGE-ID VR.

TABLES: DD04T,

        CDHDR,

        CDPOS,

        DD03L,

        DD41V,

        T685T,

        VBPA,

        TPART,

        KONVC,

        VBUK.

DATA: BEGIN OF ICDHDR OCCURS 50.

        INCLUDE STRUCTURE CDHDR.

DATA: END OF ICDHDR.

SELECT-OPTIONS: XUDATE FOR ICDHDR-UDATE,

                XNAME  FOR ICDHDR-USERNAME,

                XVBELN FOR VBUK-VBELN.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.

PARAMETERS: SUDATE RADIOBUTTON GROUP R1,

            SNAME  RADIOBUTTON GROUP R1,

            SOBID  RADIOBUTTON GROUP R1.

SELECTION-SCREEN END OF BLOCK BLK1.

DATA: WFLAG,

      WCHANGENR LIKE CDHDR-CHANGENR,

      WUDATE LIKE CDHDR-UDATE,

      WNAME  LIKE CDHDR-USERNAME,

      WVBELN LIKE VBUK-VBELN,

      WDEC1 TYPE P DECIMALS 3,

      WDEC2 TYPE P DECIMALS 3,

      WDEC3 TYPE P DECIMALS 3,

      WDEC4 TYPE P DECIMALS 3.

DATA: UTEXT(16) VALUE 'has been changed',

      ITEXT(16) VALUE 'has been created',

      DTEXT(16) VALUE 'has been deleted'.

DATA: BEGIN OF ICDSHW OCCURS 50.

        INCLUDE STRUCTURE CDSHW.

DATA: END OF ICDSHW.

DATA: BEGIN OF ITAB OCCURS 10.

        INCLUDE STRUCTURE CDSHW.

DATA:   UDATE LIKE CDHDR-UDATE,

        USERNAME LIKE CDHDR-USERNAME,

        CHANGENR LIKE CDHDR-CHANGENR,

        VBELN(10),

        POSNR(6),

        ETENR(4),

        INDTEXT(200),

  END OF ITAB.

SELECT * FROM VBUK WHERE VBELN IN XVBELN.

  CLEAR CDHDR.

  CLEAR CDPOS.

  CDHDR-OBJECTCLAS = 'VERKBELEG'.

  CDHDR-OBJECTID   = VBUK-VBELN.

  PERFORM READHEADER.

  PERFORM READPOS.

  LOOP AT ITAB.

    CASE ITAB-TABNAME.

      WHEN 'VBPA'.

        IF ITAB-FNAME = 'KUNNR' OR

           ITAB-FNAME = 'LIFNR' OR

           ITAB-FNAME = 'PARNR' OR

           ITAB-FNAME = 'PERNR' OR

           ITAB-FNAME IS INITIAL.

         MOVE ITAB-TABKEY TO VBPA.

         SELECT SINGLE * FROM TPART WHERE SPRAS = SY-LANGU

                                   AND   PARVW = VBPA-PARVW.

         IF SY-SUBRC = 0.

           REPLACE '&' WITH TPART-VTEXT INTO ITAB-INDTEXT.

         ENDIF.

       ENDIF.

     WHEN 'VBAP'.

       IF ITAB-FNAME IS INITIAL.

         REPLACE '&' WITH 'Item' INTO ITAB-INDTEXT.

       ENDIF.

     WHEN 'KONVC'.

       MOVE ITAB-TABKEY TO KONVC.

       SELECT SINGLE * FROM T685T WHERE SPRAS = SY-LANGU

                                 AND   KVEWE = 'A'

                                 AND   KAPPL = 'V'

                                 AND   KSCHL = KONVC-KSCHL.

       IF SY-SUBRC = 0.

         REPLACE '&' WITH T685T-VTEXT INTO ITAB-INDTEXT.

       ENDIF.

     ENDCASE.

     IF ITAB-INDTEXT(1) EQ '&'.

       REPLACE '&' WITH ITAB-FTEXT(40) INTO ITAB-INDTEXT.

     ENDIF.

     IF ITAB-CHNGIND = 'I'.

       REPLACE '%' WITH ITEXT INTO ITAB-INDTEXT.

     ELSEIF ITAB-CHNGIND = 'U'.

       REPLACE '%' WITH UTEXT INTO ITAB-INDTEXT.

     ELSE.

       REPLACE '%' WITH DTEXT INTO ITAB-INDTEXT.

     ENDIF.

     CONDENSE ITAB-INDTEXT.

     MODIFY ITAB.

   ENDLOOP.

ENDSELECT.

IF SUDATE = 'X'.

  SORT ITAB BY UDATE VBELN POSNR ETENR.

ELSEIF SOBID = 'X'.

  SORT ITAB BY VBELN POSNR ETENR UDATE.

ELSE.

  SORT ITAB BY USERNAME VBELN POSNR ETENR UDATE.

ENDIF.

LOOP AT ITAB.

  CLEAR WFLAG.

  IF SUDATE = 'X'.

    IF WUDATE NE ITAB-UDATE.

      SKIP.

      WRITE:/001 ITAB-UDATE,

             023 ITAB-USERNAME,

             037(10) ITAB-VBELN.

      WFLAG = 'X'.

      WUDATE = ITAB-UDATE.

      WCHANGENR = ITAB-CHANGENR.

    ENDIF.

  ELSEIF SOBID NE 'X'.

    IF WVBELN NE ITAB-VBELN.

      SKIP.

      WRITE:/001 ITAB-VBELN.

      WVBELN = ITAB-VBELN.

    ENDIF.

  ELSE.

    IF WNAME NE ITAB-USERNAME.

      SKIP.

      WRITE:/001 ITAB-USERNAME.

      WNAME = ITAB-USERNAME.

    ENDIF.

  ENDIF.

  IF WCHANGENR NE ITAB-CHANGENR.

    WRITE:/023 ITAB-USERNAME,

           037(10) ITAB-VBELN.

       WFLAG = 'X'.

       WCHANGENR = ITAB-CHANGENR.

    ENDIF.

    IF WFLAG = 'X'.

      WRITE: 013 ITAB-CHNGIND,

             049 ITAB-POSNR,

             057 ITAB-ETENR,

             065 ITAB-INDTEXT(60).

    ELSE.

      WRITE: /013 ITAB-CHNGIND,

              049 ITAB-POSNR,

              057 ITAB-ETENR,

              065 ITAB-INDTEXT(60).

    ENDIF.

  WRITE:/065 ITAB-F_OLD.

  WRITE:/065 ITAB-F_NEW.

ENDLOOP.

FORM READHEADER.

  CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'

       EXPORTING

            DATE_OF_CHANGE    = CDHDR-UDATE

            OBJECTCLASS       = CDHDR-OBJECTCLAS

            OBJECTID          = CDHDR-OBJECTID

            TIME_OF_CHANGE    = CDHDR-UTIME

            USERNAME          = CDHDR-USERNAME

       TABLES

            I_CDHDR           = ICDHDR

       EXCEPTIONS

            NO_POSITION_FOUND = 1

            OTHERS            = 2.

  CASE SY-SUBRC.

    WHEN '0000'.

    WHEN '0001'.

      MESSAGE S311.

      LEAVE.

    WHEN '0002'.

      MESSAGE S311.

      LEAVE.

  ENDCASE.

ENDFORM.

FORM READPOS.

  LOOP AT ICDHDR.

    CHECK ICDHDR-UDATE

                        IN XUDATE.

    CHECK ICDHDR-USERNAME

                          IN XNAME.

    CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'

         EXPORTING

              CHANGENUMBER      = ICDHDR-CHANGENR

              TABLEKEY          = CDPOS-TABKEY

              TABLENAME         = CDPOS-TABNAME

         IMPORTING

              HEADER            = CDHDR

         TABLES

              EDITPOS           = ICDSHW

         EXCEPTIONS

              NO_POSITION_FOUND = 1

              OTHERS            = 2.

    CASE SY-SUBRC.

      WHEN '0000'.

        LOOP AT ICDSHW.

          CHECK ICDSHW-CHNGIND NE 'E'.

          CLEAR ITAB.

          MOVE-CORRESPONDING ICDHDR TO ITAB.

          MOVE-CORRESPONDING ICDSHW TO ITAB.

          CASE ITAB-TABNAME.

            WHEN 'KONVC'.

              MOVE ICDHDR-OBJECTID TO ITAB-VBELN.

              MOVE ICDSHW-TABKEY(6) TO ITAB-POSNR.

            WHEN OTHERS.

              MOVE ICDSHW-TABKEY+3(10)  TO ITAB-VBELN.

              MOVE ICDSHW-TABKEY+13(6)  TO ITAB-POSNR.

              MOVE ICDSHW-TABKEY+19(4)  TO ITAB-ETENR.

          ENDCASE.

          MOVE '& %' TO ITAB-INDTEXT.

          APPEND ITAB.

          CLEAR ITAB.

        ENDLOOP.

      WHEN OTHERS.

        MESSAGE S311.

        LEAVE.

    ENDCASE.

  ENDLOOP.

ENDFORM.

TOP-OF-PAGE.

WRITE:/ SY-DATUM,SY-UZEIT,

       50 'SALES ORDER CHANGE HISTORY',

      120 'Page', SY-PAGNO.

WRITE: / SY-REPID,

         60 'SALES ORDERS STATISTICS'.

SKIP.

ULINE.

IF SUDATE = 'X'.

  WRITE:/001 'Change Date',

         013 'Time',

         023 'User Name',

         037 'Sale Order',

         049 'Line',

         057 'Sch No',

         065 'Changes'.

ELSEIF SOBID = 'X'.

  WRITE:/001 'Sale Order',

         013 'Line',

         021 'Sch No',

         029 'Change Date',

         041 'Time',

         051 'User Name',

         065 'Comment'.

ELSE.

  WRITE:/001 'User Name',

         015 'Time',

         025 'Change Date',

         037 'Sale Order',

         049 'Line',

         057 'Sch No',

         065 'Changes'.

ENDIF.

ULINE.

 

Deletion / Archiving of IDOCs

There is no special deletion program for IDocs.
Use the archiving programs. IDoc is a separate archiving class. The following programs are available:

1. Archive RSEXARCA and RSEXARCB (as of Release 3.0C)
2. Delete RSEXARCD
3. Read archiveRSEXARCR
4. Restore RSEXARCL

RSEXARCB is similar to RSEXARCA except for the selection screen. The selection options for RSEXARCB are designed for periodic scheduling.

The Idoc archiving is checked against the status. The statuses which can be archived and those that cannot be archived are stored in the “Status maintenance” table. You can change the standard settings. Menu path: Area menu “WEDI”, control, status maintenance.

Program To Generate IDoc

Report  ZZ_Program_To_Create_Idoc

report  zz_program_to_create_idoc                     .
tables: ekko,ekpo.

selection-screen skip 3.
selection-screen begin of block b1 with frame title titl.
selection-screen skip.
select-options s_ebeln for ekko-ebeln.
selection-screen skip.
selection-screen end of block b1.

data: header_segment_name like edidd-segnam value 'Z1EKKO',
      item_segment_name like edidd-segnam value 'Z1EKPO',
      idoc_name like edidc-idoctp value 'Z19838IDOC1'.

data: header_segment_data like z1ekko,
      item_segment_data like z1ekpo.

data: control_record like edidc.

data: messagetyp like edmsg-msgtyp value 'ZZ9838MESG1'.

data: i_communication like edidc occurs 0 with header line,
      i_data like edidd occurs 0 with header line.

data: begin of i_ekko occurs 0,
      ebeln like ekko-ebeln,
      aedat like ekko-aedat,
      bukrs like ekko-bukrs,
      bsart like ekko-bsart,
      lifnr like ekko-lifnr,
      end of i_ekko.

data: begin of i_ekpo occurs 0,
      ebelp like ekpo-ebelp,
      matnr like ekpo-matnr,
      menge like ekpo-menge,
      meins like ekpo-meins,
      netpr like ekpo-netpr,
      end of i_ekpo.

start-of-selection.

select  ebeln aedat bukrs bsart lifnr from ekko
          into table i_ekko where ebeln in s_ebeln.

select ebelp
       matnr
       menge
       meins
       netpr
       from ekpo
       into table i_ekpo
       where ebeln in s_ebeln.

control_record-mestyp = messagetyp.
control_record-rcvprt = 'LS'.
control_record-idoctp = idoc_name.
control_record-rcvprn = '0MART800'.

loop at i_ekko.
header_segment_data-ebeln = i_ekko-ebeln.
header_segment_data-aedat = i_ekko-aedat.
header_segment_data-bukrs = i_ekko-bukrs.
header_segment_data-bsart = i_ekko-bsart.
header_segment_data-lifnr = i_ekko-lifnr.
i_data-segnam = header_segment_name.
i_data-sdata = header_segment_data.
append i_data.

select ebelp
       matnr
       menge
       meins
       netpr
       from ekpo
       into table i_ekpo
       where ebeln = i_ekko-ebeln.

loop at i_ekpo.
item_segment_data-ebelp = i_ekpo-ebelp.
item_segment_data-matnr = i_ekpo-matnr.
item_segment_data-menge = i_ekpo-menge.
item_segment_data-meins = i_ekpo-meins.
item_segment_data-netpr = i_ekpo-netpr.
i_data-segnam = item_segment_name.
i_data-sdata = item_segment_data.
append i_data.
endloop.
clear i_ekpo.
refresh i_ekpo.
endloop.

call function 'MASTER_IDOC_DISTRIBUTE'
  exporting
    master_idoc_control                  = control_record
*   OBJ_TYPE                             = ''
*   CHNUM                                = ''
  tables
    communication_idoc_control           = i_communication
    master_idoc_data                     = i_data
 exceptions
   error_in_idoc_control                = 1
   error_writing_idoc_status            = 2
   error_in_idoc_data                   = 3
   sending_logical_system_unknown       = 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.
else.

  loop at i_communication.
    write: 'IDOC GENERATED', i_communication-docnum.
  endloop.
  commit work.

endif.

initialization.
titl = 'ENTER THE PURCHASE ORDER NUMBER'

IDOC / BAPIs

There are many differences between IDOCs and BAPIs.

BAPIs in 3.1 are synchronous; in 4.+ they can be asynchronous (and I
believe they then drive certain ALE/IDOCs).

BAPIs are called from the outside-in.  That is, an external program
invokes a BAPI that gets data from SAP to display or updates data in
SAP.  The BAPI concept does not include an event concept — you cannot
tell SAP that when certain events happen to a “business object”, to fire
a message or a file to an external system.

BAPIs are invokable from Java or C/C++ or Visual Basic (and I think some
people are using Delphi).

In 3.1x there are very few BAPIs to use.  In 4.+ SAP has added a large
number.

BAPIs are not totally immune to upgrades but if they are to be retired
you supposedly will have them supported for two releases.  Whether those
are point or letter releases, I don’t know.   I believe that IDOCs may
be more changable from release to release.

BAPIs are reasonably well documented and there is a common place to look
to see what is available.   IDOCs — I have heard — are poorly
documented in terms of finding them, and IDOCs were done differently by
different groups in SAP.

BTW, you can also use Java, C/C++, Visual Basic, … to invoke RFCs in
SAP and get or update data.  That’s how the BAPIs work since they
utimately are sets of RFC calls (written to a design spec for BAPIs).

What is the different between ALE, IDOC and BAPI?

ALE (click here for documentation)

ALE is SAP proprietary technology that enables data communications between two or more SAP R/3 systems and/or R/3 and external systems. When a new enterprise resource planning (ERP) solution such as R/3 is implemented, companies have to interface the ERP system with legacy systems or other ERP systems.

ALE provides intelligent mechanisms where by clients can achieve integration as well as distribution of applications and data.

ALE technology facilitates rapid application prototyping and application interface development, thus reducing implementation time.

The ALE components are inherently integrated with SAP applications and are robust, leading to a highly reliable system.

ALE comes with application distribution/integration scenarios as well as a set of tools, programs, data definitions, and methodologies that you can easily configure to get an interface up and running.

BAPI

BAPIs provide a stable, standardized method for third-party applications and components to integrate into the Business Framework. These interfaces are being specified as part of SAP’s initiative with customers, partners and leading standards organizations. Also, SAP has implemented the emerging Object Application Group (OAG) specifications with BAPIs.

BAPI AND CALL TRANSACTION

BAPI
One of the big plusses for BAPIs is that the interface and function are not supposed to change. This is a big plus when you do upgrades or hot packs because the transaction can change (format, required inputs etc) which means you then need to update the call transaction.

Some of the BAPIs are better documented and easier to use than others.

You usually need to perform the BAPI that actually does the COMMIT after you call your BAPI.

The Program coding for calling a BAPI is usually cleaner than setting up the screen flow etc for the Call Transaction.

You don’t need to worry about special data circumstances interrupting the normal data flow of the screens and causing errors because of that.

BAPIs probably have better performance since they don’t do the screen flow processing.

In general if the BAPI exists for the transaction you want to perform and you can figure out how to use it the BAPI is probably the best way to go.

This is just from my experience working with both BAPI and Call Transaction. I have had some very good successes with BAPIs, but very occasionally found that I could not get the BAPI to perform the update I needed.

The interface concept of the classic R/3 is based on two different strategies: Remote Function Calls (RFC) and data exchange through IDoc message documents. RFC makes direct and synchronous calls of a program in the remote system. If the caller is an external program it will call an RFC-enabled function in R/3 and if the calling program is the R/3 system it will call an
RFC-function in another R/3-system or it will call a non-R/3 program through a gateway-proxy (usually rfcexec.exe). BAPIs are a subset of the RFC-enabled function modules, especially designed as Application Programming Interface (API) to the SAP business object, or in other words: are function modules officially released by SAP to be called from external programs.

IDocs are text encoded documents with a rigid structure that are used to exchange data between R/3 and a foreign system. Instead of calling a program in the destination system directly, the data is first packed into an IDoc and then sent to the receiving system, where it is analyzed and properly processed. Therefore an IDoc data exchange is always an
asynchronous process. The significant difference between simple RFC-calls and IDoc data exchange is the fact, that every action performed on IDocs are protocolled by R/3 and IDocs can be reprocessed if an error occurred in one of the message steps.

While IDocs have to be understood as a data exchange protocol, EDI and ALE are typical use cases for IDocs. R/3 uses IDocs for both EDI and ALE to deliver data to the receiving system. ALE is basically the scheduling mechanism that defines when and between which partners and what kind of data will be exchanged on a regular or event triggered basis. Such a set-up is called an ALE-scenario.

The philosophical difference between EDI and ALE can be pinned as follows: If we send data to an external partner, we generally speak of EDI, while ALE is a mechanism to reliable replicate data between trusting systems to store a redundant copy of the IDoc data. The difference is made clear, when we think of a purchase order that is sent as an IDoc. If we send the purchase order to a supplier then the supplier will store the purchase order as a sales order. However, if we send the purchase order via ALE to another R/3 system, then the receiving system will store the purchase order also as a purchase order.