Thursday, May 30, 2013

Control Break Statements in SAP ABAP


Control break statements are like events inside the loop. There are 5 control break statements in ABAP. These are used within loop.(Except ON CHANGE OF which can be used outside the loop as well)

  • AT FIRST - ENDAT
  • AT NEW - ENDAT
  • AT END OF - ENDAT
  • AT LAST - ENDAT
  • ON CHANGE OF

Explanation:


AT FIRST : Will trigger at the first run of the loop.

AT LAST: Will trigger at the last run of the loop.

The below 3 events are normally used when the table is sorted.


AT END OF : When we use At end for a field, it will trigger whenever there is any change in any of the fields from the left to that of the particular field. The trigger point will be the at the last occurrence  of the same value for the field.

AT NEW: When we use At new for a field, it will trigger whenever there is any change in any of the fields from the left to that of the particular field.The trigger point will be the at the first occurrence of the new value for the field.


ON CHANGE OF: On change of it triggers only when there is any change in the particular field.
On change of can be used outside the loop too

Example Program:


Here is an example program which gives you the practical understanding of all control break statements.
Example Program for Control Break Statements
Example Program for Control Break Statements
NOTE: It is important to note that we need a temporary work-area apart from the work-area used in loop for the last 3 control break statements. If we directly use the work-area of the loop, then we will get **** value and not the output we are expecting.


*&---------------------------------------------------------------------*
*& Report  ZAU_CONTROLBREAK
*&
*&---------------------------------------------------------------------*
*& NEW TO SAP CONTROL BREAK EXAMPLE
*& http://www.newtosap.info
*&
*&---------------------------------------------------------------------*

REPORT  zau_controlbreak.
TYPESBEGIN OF ty_marc,
        matnr TYPE marc-matnr,
        werks TYPE marc-werks,
       END OF ty_marc.

DATA: it_marc TYPE STANDARD TABLE OF ty_marc,
      wa_marc TYPE ty_marc,
      wa_temp TYPE ty_marc.

SELECT matnr werks FROM marc INTO TABLE it_marc UP TO 10 ROWS WHERE matnr ge 40.
SORT it_marc BY matnr.


WRITE:/ 'FULL TABLE'.
LOOP AT it_marc INTO wa_marc.
  wa_temp = wa_marc.
  WRITE: / sy-tabix , wa_temp-matnr,  wa_temp-werks.
ENDLOOP.

WRITE:/ 'AT FIRST AND LAST'.
LOOP AT it_marc INTO wa_marc.
  wa_temp = wa_marc.
  AT FIRST.
    WRITE:/ 'First Entry'.
    WRITE:/  wa_temp-matnr,  wa_temp-werks.
  ENDAT.
  AT LAST.
    WRITE:/ 'Last Entry'.
    WRITE:/  wa_temp-matnr,  wa_temp-werks.
  ENDAT.
ENDLOOP.


WRITE:/ 'AT END OF'.
LOOP AT it_marc INTO wa_marc.
  wa_temp = wa_marc.
  AT END OF matnr.
    WRITE: / sy-tabix , wa_temp-matnr,  wa_temp-werks.
  ENDAT.
ENDLOOP.

WRITE:/ 'AT NEW'.

LOOP AT it_marc INTO wa_marc.
  wa_temp = wa_marc.
  AT NEW matnr.
    WRITE: / sy-tabix , wa_temp-matnr,  wa_temp-werks.
  ENDAT.
ENDLOOP.

WRITE:/ 'ON CHANGE OF'.
LOOP AT it_marc INTO wa_marc.
  wa_temp = wa_marc.
  ASSIGN wa_marc-matnr TO <matnr>.
  ON CHANGE OF wa_marc-matnr.
    WRITE: / sy-tabix ,wa_temp-matnr,  wa_temp-werks.
  ENDON.
ENDLOOP.

Simple steps of IDOC

What is a IDOC?

An IDoc is simply a data container that is used to exchange information between any two processes that can understand the syntax and semantics of the data. IDoc is not a process.
-         IDocs are stored in the database.
-         In the SAP system, IDocs are stored in database tables.
-         IDocs are independent of the sending and receiving systems.
-         IDocs are independent of the direction of data exchange.
 

Creation of IDOCs

Transaction code: WE 30

Steps of Defining Segment

Creating Segment : Tcode - WE31
Creating Message Type : Tcode - we81
Assigning Message type to Idoc type: Tcode - we82

Process

The two processes for IDoc are Outbound Process and Inbound Process.
 

Outbound Process

When the data is sent out from the system, the process is called Outbound Process and the IDoc is known as Outbound IDoc.
 

Inbound Process

When the data is coming in, the process is called Inbound Process and the IDoc is known as Inbound IDoc.
 

Outbound Process (Sending System) Steps :

1) Goto Tcode SALE:
 Creating the logical system
Click on Sending and Receiving Systems à Select Logical Systems--Here Define the Logical Systems à Click on Execute Button
Go for New Entries
1)  System Name : LOG1:Description: Sending System
2)  System Name : LOG2:Description: Receiving System
Press Enter & Save it will ask for Request if you want new request create new request or press continue for transferring the objects.
Assigning Client to the Logical System:
Select Assign Client to Logical Systems -
Client                   : Sending System
Logical System    : LOG1
and also
Client   : Receiving System
Logical System    : LOG2
Save this Data.
 
Step 2) For RFC Creation:
 Goto Tcode SM59 and  Select R/3 Connects
Click on create Button
RFC Destination Name should be same as partner's logical system name and case sensitive to create the ports automatically while generating the partner profiles
Give the information for required fields:
RFC Destination    : LOG2
Connection type    : 3
Target Host            : sappdc.wipro.com
System No              : 00
Client                      : 210
User                        : Login user name
Password                :
Save this & Test it and Remote Login
Step 3) Goto Tcode BD64: 
 Click on the change button>Click on the create model view
Short Text: model view
Technical Name: LMOD
Save this & press ok
Select just created model view
Name: "LMOD"
Goto add message type
Model Name  : LMOD
Sender           : LOG1
Receiver         : LOG2
Message type: ZAZHARMESS
Save and press Enter.
 
4) Goto Tcode BD82:
Give Model View   : LMOD
Partner system     : LOG2
Execute this by pressing F8
It will gives you sending system port No:  A00000000089 (Like)
 
5) Goto Tcode BD64:
Select the model view
Goto >Edit >model view > Distribute
Press ok & Press Enter.
 
Run your Zprogram
REPORT  ZIDOC1                             .
DATA: Begin of imara occurs 0,
matnr like mara-matnr,
mtart like mara-mtart,
end of imara.
DATA: wamas_con LIKE edidc,
imas_data LIKE edidd OCCURS 0 WITH HEADER LINE,
icom_con LIKE edidc OCCURS 0 WITH HEADER LINE.
PARAMETERS: e_matnr LIKE mara-matnr,
e_msgtyp LIKE edidc-mestyp,
e_rcvprn LIKE edidc-rcvprn.
* retrive app. data from DB
SELECT matnr mtart FROM mara INTO TABLE imara WHERE
matnr = e_matnr.
*Master idoc control record
wamas_con-rcvprt = 'LS'.
wamas_con-rcvprn = e_rcvprn.
wamas_con-idoctp = 'ZAZHARIDOC'.
wamas_con-mestyp = e_msgtyp.
* master idoc data records
LOOP AT imara.
imas_data-segnam = 'ZAZHARSEG'.
move imara to imas_data-sdata .
APPEND imas_data.
ENDLOOP.
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
master_idoc_control = wamas_con
TABLES
communication_idoc_control = icom_con
master_idoc_data = imas_data
COMMIT WORK.
 
6) Verifying Transfer of IDOCs Tcode - we05
ALE/IDOC Status Codes (outbound):
01> IDoc Added
30 > IDoc ready for dispatch
29 >Error in ALE service Layer
12 >Dispatch ok
 03 > Data passed to port ok.
 

Inbound Process (Receiving System) Steps:

Do the same step as you did in sending system
>  Creating IDoc
>   Defining the Segment
>   Creating Message Type
>   Assigning the Message Type
>   Defining the Logical System
>   Assigning the Logical System
>   Creating the Distribution Model
1) Goto Tcode - we57:
Assign function module to IDoc type
Module: Function module
Basic type:
Message type:
Direction: 2 (inbound)
2) Creating Inbound process code - we42
3) Verifying Idoc List Tcode - we05
4) ALE/IDOC Status Codes (Inbound):
50 > IDoc Added
51 >Application Document not posted
64 >IDoc ready to be transferred to application
62 >IDoc passed to application
53 >Application Document posted

Sunday, May 26, 2013

How to AUTO REFRESH ALV REPORT

REPORT  ZAUTOREFRESH.

CLASS lcl_timer DEFINITION DEFERRED .

DATA : i_spfli TYPE TABLE OF spfli .

DATA : ob_grid    TYPE REF TO cl_gui_alv_grid ,
       ob_recev   TYPE REF TO lcl_timer       ,
       ob_timer   TYPE REF TO cl_gui_timer    .

*----------------------------------------------------------------------*
*       CLASS lcl_receiver DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_timer DEFINITION.
  PUBLIC SECTION.
    METHODS:
      handle_finished FOR EVENT finished OF cl_gui_timer.
ENDCLASS.                    "lcl_receiver DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_timer IMPLEMENTATION.
  METHOD handle_finished.
    PERFORM refresh_data .
    MESSAGE s003(z001) WITH 'Report refreshed at' sy-uzeit.
    CALL METHOD ob_timer->run.
  ENDMETHOD.                    "handle_finished
ENDCLASS.                    "lcl_receiver IMPLEMENTATION

*--------------------------------------------------------------------*
*     Start of Selection
*--------------------------------------------------------------------*
START-OF-SELECTION .
  PERFORM select_data .

*--------------------------------------------------------------------*
*     End of Selection
*--------------------------------------------------------------------*
END-OF-SELECTION .

* Step 1 : Initialise Time control
  CREATE OBJECT ob_timer.

* Step 2 : Initialise object to receive event
  CREATE OBJECT ob_recev.

* Step 3 : Couple event to method
  SET HANDLER ob_recev->handle_finished FOR ob_timer. "

* Step 4 : Set Interval in seconds
  ob_timer->interval = 20 .

* Step 5 : Start Timer
  CALL METHOD ob_timer->run.

  PERFORM display_data .

*--------------------------------------------------------------------*
*&      Form  Select_Date
*--------------------------------------------------------------------*
FORM select_data .
  SELECT *
    APPENDING TABLE i_spfli
    FROM spfli .
ENDFORM.                    "SELECT_DATA

*&---------------------------------------------------------------------*
*&      Form  refresh_data
*&---------------------------------------------------------------------*
FORM refresh_data .

* Get grid reference
  IF ob_grid IS INITIAL .
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      IMPORTING
        e_grid = ob_grid.
  ENDIF.

  IF ob_grid IS NOT INITIAL"Sanity Test
    PERFORM select_data .
    CALL METHOD ob_grid->refresh_table_display.
  ENDIF.

ENDFORM.                    "refresh_data

*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
FORM display_data .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_structure_name = 'SPFLI'
    TABLES
      t_outtab         = i_spfli
    EXCEPTIONS
      program_error    = 1
      OTHERS           = 2.

  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 .                    "display_data


Output





Useful SAP / ABAP development transaction code.


AL11 
SAP directorie structure 

BAPI 
BAPI Explorer, view all sap BAPI's 

BRF 
Business rule framework transaction 

BRFAPL01 
Define new application class. Once defined use tcode BRF to create application class. 

BRFIMC01 
Create implementing class. Use program BRF_COPY_IMPL_CLASSES to copy standard implementing classes to your new application class 

BUSP 
Project management of SAP enhancements 

FILE 
Maintain Logical file path definitions 

GRANT_CUSTOMIZE 
Customize Grant management screens via SAP's BDT(business data toolset) - Must have permission from SAP to use this method of modification 

I18N 
Internationalization in SAP 

OAOR 
Business document navigator (edit ENJOYSAP_LOGO etc for 
ALV Tree) 

OLE 
Examples for OLE Processing 

PFTC 
Workflow task maintain 

PPOM_OLD 
View SAP personnel hr org structure 

SA38 
Execute SAP ABAP program 

SALE 
IDoc and ALE development 

SCC1 
Client Copy, copy transport 

SCDO 
Change Document / Change History 

SCOT 
SAPconnect Administration 

SCU3 - Table change history 
Analysis of changed table entries and other customizing objects. Simple way to implement change history to a sap datbase table 

SE01 
Transport Organizer (extended view) 

SE03 
Transport Organizer Tools (change package/dev class etc..) 

SE09 
Workbench organiser 

SE11 
ABAP Dictionary 

SE14 
Database utility: Adjust after change to definition, delete…. 

SE16 
Data browser, view/add table data 

SE18 
Business Add-ins(BADI’s): Definition transaction 

SE19 
Business Add-ins(BADI’s): Implementation transaction 

SE24 
Class builder 

SE38 
Program Editor 

SE39 
Split screen editor 

SE41 
Menu Painter 

SE51 
Screen Painter 

SE61 
Document maintenance 

SE71 
Form painter (SAPscript) 

SE75 
SAPScript settings including Text objetcs and IDs 

SE80 
Object Navigator ( SAP Development workbench, most development functionality is available from this transaction ) 

SE81 
Application Hierarchy (leads to SE84 for desired area) 

SE84 
Repository info system 

SE91 
Message Maintenance 

SE93 
Maintain Transaction code 

SHD0 
Create Transaction Variant. Enter name of transaction plus name of new/existing variant. 

SHDB 
Batch input recorder
SLIN 
ABAP program extended syntax check (full check of programs syntax)
 

SM04 
User Overview List, Display list of online (logged in) users
 

SM12 
Lock entries
 

SM13 
Update Requests
 

SM21 
Online system log analysis
 

SM30 
Maintain table views
 

SM31 
Table maintenance
 

SM35 
Batch input i.e. Recording
 

SM36
 
Create background job
 

SM37
 
Background job monitor, Select background jobs
 

SM49 
External Commands
 

SM50 
Process overview (within current server)
 

SM51 
Server overview
 

SM59 
Display and Maintain RFC destination 

SM64 
Display/maintain Events
 

SM66 
Process(session) overview across all servers
 

SM69 
External commands(Maintain)
 

SMW0 
SAP WEB Repository(binary data) - add/ mod images(used to put in screen containers)
 

SMX 
View background jobs
 

SNOTE 
SAP note assistant (if installed). Installs OSS notes for you, usually removes the need for manual code changes 

SNRO
 
Maintain number ranges (use FM '
NUMBER_GET_NEXT' to retrieve next number in range.) 

SO10 
Standard text editor 

SP01 
Spool list
 

SP02 
Display your Own spool list
 

SPAD 
SAP Spool Administrator
 

SPAM 
Support package manager
 

SPAU 
Modification adjustment
 

SPRO 
SAP System Customizing, IMG
 

SQ01 
Sap Query development
 

ST02 
Database Tune Summary
 

ST04 
DB Performance Monitor
 

STMS 
Transport Management system
 

ST22 
ABAP runtime analysis ( ABAP Dump Analysis )
 

SU01 
User Maintenance
 

SU53 
Retrieve authorisation data for object, execute after error message is displayed(/nsu53) 

SUIM 
User info system (New user, Roles, Authorisations, User tcodes etc..) 

SWO1 
Business objects builder (change) 

SWO2 
Business objects browser (display) 

SXDA 
SAP Data transfer workbench 

VOK2 
Output determination by functional area / output type (Output programs) 

WEDI 
IDoc and EDI Basis

Drop Down lists in the selection parameters

PROGRAM ztest.   TYPE-POOLS : vrm.   DATA : name TYPE vrm_id,        list TYPE vrm_values,        value LIKE LINE OF list. ...