Search this site

Saturday, December 15, 2012

Module pool programming: Create GUI Status example

Create the Guide status for program.

Enter the status name STATUS_1000

 Add item CAL to menu bar.Enter the name of menu

 Double click to CAL item.The screen will show as below:

 Create the action for the item on the Standard tool bar.In this example ,We create the action for the button BACK on the standard toolbar:


 Use the code as below to call the status bar STATUS_1000 which created on the first  step:

 Create the item CAL for the application toolbar :

 Run the progarm:You coud use function Calculate via menu item Calculate on Menu bar or button Calculate standard tool bar.The screen will show as below:

The end!


Module pool programming: Example input,output field element


1. Go to SE80 , create program:

 2. Create the screen for user dialog program:


3. Click on the button Layout to go to screen paiter.Screen painter is a tool that helps design the screen of module program.
 
4. In this example, we will create a simple program that calculate two number and show its result:
You could see on the left side is the elements you will add to the screen.First,add two input fields A and B.


Second,Create the output field RESULT to contain the calculation result from A + B.

 Third,create the button with the name CAL , fctCode CAL.

Double click to the screen 1000 ,it will show you the flow logic of the screen 1000.
It has two PROCESSES:

 PROCESS BEFORE OUTPUT : In this proscess,you could set the initial values of the screen elements or do the initial logics.
 PROCESS AFTER INPUT: In this proscess,you could get the value from the screen elements and do the needful.


 Create the MOUDLEs in each PROCESS.
 Here' code example.Notice that the name of variants in the flow logic must be same name with the name of screen elements:
REPORT  ZUSERDIALOG_01.
DATA: A TYPE I,
      B TYPE I,
      RESULT type i.

CALL SCREEN 1000.
*&---------------------------------------------------------------------*
*&      Module  STATUS_1000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_1000 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.
 A = 1.
 B = 1.
ENDMODULE.                 " STATUS_1000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_1000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_1000 INPUT.
IF sy-ucomm = 'CAL'.
  RESULT  = A + B.

 ENDIF.
ENDMODULE.                 " USER_COMMAND_1000  INPUT


F8 to run program:

The result will show after pressing CAL button.

The end. Hope this information helpful for you.

Sunday, May 20, 2012

How to debug the code in abap report ?

  1. Using Se38 to open the report , set break point as the screen below:


2. Press F8 to run report, it will show the Variant 1 screen on the right:
In this example is the internal table GT_MARA and work area GS_MARA.
You can view the value of the internal table and work area by double click the internal table GT_MARA and work area GS_mara

3. Here's the values in the internal table gt_mara when debugging.
There is 1 rows in this internal table and it has  two fields with values 1 and ABC:

4.For convenience to debug program,by clicking the icon repair on the top right screen(3) ,we could edit values in the internal table: change,insert,delete rows from internal table...

Monday, April 2, 2012

Abap query transaction

The transaction codes associated with ABAP Query are

SQ01

- ABAP Query

SQ02

- Infoset

SQ03

- User group

Sapscript example code in Abap

REPORT ZDEMO_SAPSCRIPT_PERFORM.
*----------------------------------------------------------------------
* TABLES: VBAP. TABLES: ITCPO.  " optional for setting default print parameters PARAMETERS: FORM LIKE RSSCF-TDFORM DEFAULT 'YDEMO_PERFORM'.
  START-OF-SELECTION.  
************************************************************************
 * Open the SapScript Form with the "form"                              * ************************************************************************ 
 CLEAR ITCPO .
 * itcpo-tddest     = 'ZHTM'.  
 ITCPO-TDIMMED    = 'X'.  
 ITCPO-TDDELETE   = 'X'.   
ITCPO-TDNEWID    = 'X'.    
CALL FUNCTION 'OPEN_FORM'        
 EXPORTING             FORM               = FORM        " name of form (SE71)       
       OPTIONS            = ITCPO     
      EXCEPTIONS             CANCELED           = 1  
       DEVICE             = 2 
            FORM               = 3        
     OPTIONS            = 4         
    UNCLOSED           = 5             
MAIL_OPTIONS       = 6             
OTHERS             = 7.  ************************************************************************ *
* Execute the element "HELLO" in window MAIN *  
- Nothing happens if /E HELLO is not declared in MAIN ************************************************************************
 CALL FUNCTION 'WRITE_FORM'    
  EXPORTING           ELEMENT                  = 'HELLO'  "execute element /E HELLO *                FUNCTION                 = 'SET'          
   TYPE                     = 'BODY'   "normal output
       EXCEPTIONS           ELEMENT                  = 1         
    FUNCTION                 = 2           
  TYPE                     = 3        
      UNOPENED                 = 4         
      UNSTARTED                = 5       
     WINDOW                   = 6   
     BAD_PAGEFORMAT_FOR_PRINT = 7           
OTHERS                   = 8.  ************************************************************************ 
* Close the current SapScript Form ************************************************************************
CALL FUNCTION 'CLOSE_FORM'  
    EXCEPTIONS  
         UNOPENED                 = 1    
       BAD_PAGEFORMAT_FOR_PRINT = 2 
          OTHERS                   = 3.  
FORM CALLED_FROM_SAPSCRIPT   TABLES  IN_TAB STRUCTURE ITCSY          OUT_TAB STRUCTURE ITCSY.    
DATA: TABIX LIKE SY-TABIX.
   TABLES: KNA1. 
   BREAK-POINT.  
  READ TABLE IN_TAB WITH KEY NAME = 'KUNNR'.   
KNA1-KUNNR = IN_TAB-VALUE.   
 READ TABLE OUT_TAB WITH KEY NAME = 'NAME'.   
TABIX = SY-TABIX.    
OUT_TAB-NAME  = 'NAME'.   
SELECT SINGLE * FROM KNA1 WHERE KUNNR EQ KNA1-KUNNR.   
IF SY-SUBRC EQ 0.    
   CONCATENATE KNA1-NAME1 KNA1-ORT01 INTO OUT_TAB-VALUE                                 SEPARATED BY SPACE. 
   ELSE.   
     CONCATENATE KNA1-KUNNR 'not found' INTO OUT_TAB-VALUE                               SEPARATED BY SPACE.  
 ENDIF.
   MODIFY OUT_TAB INDEX TABIX. 
ENDFORM. 


SapScript Coding
....+....1....+....2....+....3....+....4....+....5....+....6....+....7.. /E PERFORM_ABAP                                                                    /: PERFORM CALLED_FROM_SAPSCRIPT IN PROGRAM zsapscriptexits /: USING &invar1&                                      /: USING &invar2&                                      ...                                                    /: CHANGING &outvar1&                                  /: CHANGING &outvar2&                                  ...                                                    /: ENDPERFORM       
(Refer from site idocs.de)

Sunday, April 1, 2012

How to debug Sapscript ABAP

First method.
  1. Go to SE71 transaction.
  2. Click on Utilities menu -> Activate Debugger.

Sapscript tcode

SO10 - SAPscript: Standard Texts Basis - SAPscript
SE71 - SAPscript form Basis - SAPscript
SE73 - SAPscript Font Maintenance Basis - SAPscript
SE75 - SAPscript Settings Basis - SAPscript
SE72 - SAPscript Styles Basis - SAPscript
SE76 - SAPscript: Form Translation Basis - SAPscript




SE74 - SAPscript format conversion Basis - SAPscript
SE77 - SAPscript Styles Translation Basis - SAPscript
PBAT - Choose SAPscript or WinWord Personnel Mgmt - Recruitment
J2I7 - CIN: SAPScript reporting customizing FI - Localization
PM20 - Statements with SAPscript Payroll - Reuse Services for Country Development
BRFU01 - BRF: Compare SAPscript Texts Cross Application - Business Rule Framework

Sapscript command abap

Command

Use

New-page

Prints the text following this command on a new page (when a page name is specified then that page is taken as the next page)

Protect ….. Endprotect

This acts like a conditional page break. Putting the text within this command prevents the breaking of the text across multiple pages. If there is not enough space for the entire paragraph to be printed in the space remaining on the page, then the entire paragraph is printed on the next page

Box

Position

Size

The BOX command draws a box as per the specifications. The x y co-ordinates are for the upper left corner relative to the values in the position command.

POSITION command is used to set the x y co-ordinates with respect to the start position of the window.

SIZE command is used to specify the size of the box that we need to draw.

Varying these parameters also helps to draw a line instead of a box.

IF ….. END IF

This allows the conditional printing of the text on the output document. The various conditional operators that can be used are as follows

= EQ Equal to

<>

> GT Greater than

<= LE Less than or equal to

>= GE greater than or equal to

<> NE not equal to

The logical operators that can be used are as follows

NOT, AND, OR

How to create a Sapscript in abap

Please get the file :
Create a Sapscript in abap



Sapscript tutorial abap

As below show you a list of SapScript tutorial:



Module programming(user dialog programming)

1.What is module programming(dialog programming) ?
2.Module pool programming step by step



Module pool programming in abap step by step


  1. Episode 01 : Example module pool program simple for input,output and how to use event Process before output and Process after input.
  2. Episode 02: Example create GUI status in module pool programming
  3. Episode 03: Modify screen in module pool programming
  4. Episode 04: Create title of module program

Saturday, March 31, 2012

Create index in table sap ?

-Goto SE11
-Give the table name and click on 'Indexes' and then click on Create button. Give Index ID. Specify the fields which you require to be as secondary index in the same order for that table.

Get date time in abap sap ?

SY-DATLO

User’s local date, for example 19981129, 19990628, …

SY-DATUM

Current application server date, for example 19981130, 19990627, …

SY-DAYST

X during summertime, otherwise space.

SY-FDAYW

Factory calendar day of the week: Monday = 1 … Friday = 5.

SY-TIMLO

Friday, March 30, 2012

Way to find a badi in abap sap

There are several ways to find BADIs in the program.

1. Set a beark-point in method ‘CL_EXITHANDLER=>GET_INSTANCE’. Because old BAID technology will always call this method to get the BADI instance.

2. Search string ‘CL_EXITHANDLER=>GET_INSTANCE’ in the program. This drawback of this method is that the program may call another program in the runtime. In this case, you will be able to find the BADI in another program.

3. You can also go the t-code SPRO, you can also find plenty of BADIs in the related area.

4. You can also find the BADI call using ST05. Below is the steps:

  • Go to ST05, then choose ‘table buffer trace’ and activate the trace.
  • Run the t-code from where you want to find the BADI.
  • Deactive the trace and then display trace.
  • using selection criteria object ‘V_EXT_IMP’ and ‘V_EXT_ACT’ and then you can get called BADI list.

This analyzing technique is based on the fact that all BAdIs are registrated in SAP database tables. So for each BAdI call these database tables will be accessed. The BAdI database tables are SXS_INTER, SXC_EXIT, SXC_CLASS and SXC_ATTR. These tables are always accessed by the views V_EXT_IMP and V_EXT_ACT. So these two ABAP views (T: SE11) will be the basis for the trace.

Example ALV in abap SAP

&---------------------------------------------------------------------*
*& Report Z_SCREEN_DEMO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT Z_SCREEN_DEMO.


*&---------------------------------------------------------------------*
* Declare global object and selection screen.
*&---------------------------------------------------------------------*
*-----------------------------------------------------------------------
* TYPE POOL
*-----------------------------------------------------------------------
TYPE-POOLS:
SLIS.
*----------------------------------------------------------------------*
* TABLES
*----------------------------------------------------------------------*
TABLES:MARA.
*----------------------------------------------------------------------*
* TYPES
*----------------------------------------------------------------------*
*Struct MARA
TYPES: BEGIN OF GTY_MARA,
MATNR TYPE MARA-MATNR,"MATERIAL NUMBER
MTART TYPE MARA-MTART,
END OF GTY_MARA.
*Struct MAKT
TYPES: BEGIN OF GTY_MAKT,
MATNR TYPE MAKT-MATNR,"MATERIAL NUMBER
MAKTX TYPE MAKT-MAKTX,
END OF GTY_MAKT.
*Struct OUTPUT
TYPES: BEGIN OF GTY_OUTPUT,
MATNR TYPE MARA-MATNR,"MATERIAL NUMBER
MTART TYPE MARA-MTART,"MATERIAL TYPE
MAKTX TYPE MAKT-MAKTX,"MATERIAL DES
END OF GTY_OUTPUT.
*----------------------------------------------------------------------*
* Internal table
*----------------------------------------------------------------------*
DATA: GT_OUTPUT TYPE STANDARD TABLE OF GTY_OUTPUT,
GT_MARA TYPE STANDARD TABLE OF GTY_MARA,
GT_MAKT TYPE STANDARD TABLE OF GTY_MAKT,
*----------------------------------------------------------------------*
* Work area
*----------------------------------------------------------------------*
GS_OUTPUT TYPE GTY_OUTPUT,
GS_MARA TYPE GTY_MARA,
GS_MAKT TYPE GTY_MAKT.
*----------------------------------------------------------------------*
* Selection screen
*----------------------------------------------------------------------*
SELECT-OPTIONS: S_ERDA FOR MARA-ERSDA default '20110916 ' OBLIGATORY.
PARAMETERS:
pa_lim_1 RADIOBUTTON GROUP lim ,"JOIN
pa_lim_2 RADIOBUTTON GROUP lim,"FOR ALL ENTRIES
*----------------------------------------------------------------------*
* INITIALIZATION.
*----------------------------------------------------------------------*
INITIALIZATION.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
*Select data
IF PA_LIM_1 IS NOT INITIAL.
*Join
SELECT
M~MATNR
M~MTART
M2~MAKTX
INTO TABLE GT_OUTPUT
FROM
MARA AS M
JOIN MAKT AS M2 ON M~MATNR = M2~MATNR
WHERE M~ERSDA IN S_ERDA AND
M2~SPRAS = 'E'.
ELSE.
*For all entries
SELECT
MATNR
MTART
FROM MARA
INTO TABLE GT_MARA
WHERE ERSDA IN S_ERDA.
DELETE ADJACENT DUPLICATES FROM GT_MARA COMPARING MATNR.
IF GT_MARA IS NOT INITIAL.
SELECT
MATNR
MAKTX
FROM MAKT
INTO TABLE GT_MAKT
FOR ALL ENTRIES IN GT_MARA
WHERE MATNR = GT_MARA-MATNR AND SPRAS = 'E'.
ENDIF.
SORT GT_MAKT BY MATNR.
LOOP AT GT_MARA INTO GS_MARA.
CLEAR: GS_MAKT.
READ TABLE GT_MAKT BINARY SEARCH WITH KEY MATNR = GS_MARA-MATNR
INTO GS_MAKT.
GS_OUTPUT-MATNR = GS_MARA-MATNR.
GS_OUTPUT-MTART = GS_MARA-MTART.
GS_OUTPUT-MAKTX = GS_MAKT-MAKTX.
APPEND GS_OUTPUT TO GT_OUTPUT.
ENDLOOP.
ENDIF.
*----------------------------------------------------------------------*
* End-OF-SELECTION
*----------------------------------------------------------------------*
END-OF-SELECTION.
* Output data
* ALV
data: LS_FIELDCAT type slis_fieldcat_alv.
data: GT_FIELDCAT type slis_t_fieldcat_alv.
PERFORM CREATE_FIELD_CAT.
*&---------------------------------------------------------------------*
*& Form CREATE_FIELD_CAT
*&---------------------------------------------------------------------*
* Create field catalogies
*----------------------------------------------------------------------*
FORM CREATE_FIELD_CAT .
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_internal_tabname = 'GT_OUTPUT'
i_structure_name = 'ZOUTPUT'
changing
ct_fieldcat = GT_FIELDCAT.
ENDFORM. " CREATE_FIELD_CAT
*&---------------------------------------------------------------------*
*& Form GRID_DISPLAY
*&---------------------------------------------------------------------*
* Grid Display
*----------------------------------------------------------------------*
FORM GRID_DISPLAY .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = 'ZSCREEN_DEMO1'
* I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'FRM_TOP_OF_PAGE'
IT_FIELDCAT = GT_FIELDCAT
I_SAVE = 'X'
* IS_VARIANT = G_VARIANT
TABLES
T_OUTTAB = GT_OUTPUT
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. " GRID_DISPLAY
*&---------------------------------------------------------------------*
*& Form Top of page
*&---------------------------------------------------------------------*
* Top of page
*----------------------------------------------------------------------*
FORM FRM_TOP_OF_PAGE.
*ALV Header declarations
DATA: T_HEADER TYPE SLIS_T_LISTHEADER,
WA_HEADER TYPE SLIS_LISTHEADER.
* Title
WA_HEADER-TYP = 'H'.
WA_HEADER-INFO = 'ALV Demo'.
APPEND WA_HEADER TO T_HEADER.
CLEAR WA_HEADER.
* Date
WA_HEADER-TYP = 'S'.
WA_HEADER-KEY = 'Date: '.
CONCATENATE SY-DATUM+6(2) '.'
SY-DATUM+4(2) '.'
SY-DATUM(4) INTO WA_HEADER-INFO. "todays date
APPEND WA_HEADER TO T_HEADER.
CLEAR: WA_HEADER.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = T_HEADER.
ENDFORM.

*Output Result:

BDC example in ABAP ?

Here example of source code run BDC to update the logon language of a user from a file contains user language infomation.

Input file: input.txt
user01 FR
user02 EN

*&---------------------------------------------------------------------*
*& Report ZDEMO_UPDATE_SU01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZDEMO_UPDATE_SU01.
*----------------------------------------------------------------------*
* data definition
*----------------------------------------------------------------------*
* Batchinputdata of single transaction
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
* messages of call transaction
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
TABLES: T100.
DATA: BEGIN OF ST_RECORD,
BNAME TYPE USR02-BNAME,
LANGU(2) TYPE C,
END OF ST_RECORD.
DATA: GT_UPLOAD LIKE TABLE OF ST_RECORD,
GS_UPLOAD LIKE ST_RECORD.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS P_FILE TYPE RLGRAP-FILENAME OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM F4_SELECTFILE.

INITIALIZATION.

START-OF-SELECTION.
PERFORM UPLOAD_DATA.
LOOP AT GT_UPLOAD INTO GS_UPLOAD.
PERFORM BDC_DYNPRO USING 'SAPLSUU5' '0050'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'USR02-BNAME'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=CHAN'.
PERFORM BDC_FIELD USING 'USR02-BNAME'
GS_UPLOAD-BNAME.
PERFORM BDC_DYNPRO USING 'SAPLSUU5' '0100'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=DEFA'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'SZA5_D0700-TITLE_MEDI'.
PERFORM BDC_DYNPRO USING 'SAPLSUU5' '0100'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=UPD'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'USDEFAULTS-START_MENU'.
PERFORM BDC_FIELD USING 'USDEFAULTS-LANGU'
GS_UPLOAD-LANGU.
PERFORM BDC_TRANSACTION USING 'SU01'.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form UPLOAD_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM UPLOAD_DATA .
DATA: L_FILE TYPE STRING.
L_FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = L_FILE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = GT_UPLOAD
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.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " UPLOAD_DATA
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM. "BDC_DYNPRO

*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM. "BDC_FIELD
*----------------------------------------------------------------------*
* Start new transaction according to parameters *
*----------------------------------------------------------------------*
FORM BDC_TRANSACTION USING TCODE.
DATA: L_MSTRING(480).
REFRESH MESSTAB.
CALL TRANSACTION TCODE USING BDCDATA
MODE 'N'
UPDATE 'S'
MESSAGES INTO MESSTAB.

LOOP AT MESSTAB.
SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA
AND ARBGB = MESSTAB-MSGID
AND MSGNR = MESSTAB-MSGNR.
IF SY-SUBRC = 0.
L_MSTRING = T100-TEXT.
IF L_MSTRING CS '&1'.
REPLACE '&1' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&2' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&3' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&4' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ELSE.
REPLACE '&' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ENDIF.
CONDENSE L_MSTRING.
WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).
ELSE.
WRITE: / MESSTAB.
ENDIF.
ENDLOOP.
SKIP.
REFRESH BDCDATA.
ENDFORM. "BDC_TRANSACTION
*&---------------------------------------------------------------------*
*& Form F4_SELECTFILE
*&---------------------------------------------------------------------*
FORM F4_SELECTFILE .
CALL FUNCTION 'NAVIGATION_FILENAME_HELP'
EXPORTING
DEFAULT_PATH = 'TEST.TXT'
IMPORTING
SELECTED_FILENAME = P_FILE.
MOVE P_FILE TO P_FILE.
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. " F4_SELECTFILE

What is BDC in ABAP SAP ?

The full form of BDC is Batch Data Communication. It’s a technique in SAP used for mass input of data or uploading data into SAP system (If particular BAPI is not available).BDC also known as Batch Input. There are two types of BDC are there

  • Call Transaction Using (using CALL TRANSACTION statement)
  • Batch Input Session (using BDC_OPEN_GROUP, BDC_INSERT and BDC_CLOSE_GROUP function modules)

ABAP programming is requires for any BDC methods. First we need to record a transaction and then embed this recording in our ABAP program. Then we will run this using Call Transaction using or BI session method.

CALL TRANSACTION USING:

This is the fastest method to transfer data.

Syntax:

CALL TRANSACTION

USING

MODE

UPDATE

Main Display Modes used

A: Display all

E: Display Errors only

N : No Display

Main Updates modes

S: Synchronous

A: Asynchronous

L : Local Update

While we doing CALL TRANSACTION USING method, first we will create a structure BDCDATA for the transaction. This structure is used in the USING addition of the CALL TRANSACTION statement.

Batch Input Session

In this method data is stored in a batch input session and later run this session. Here is the process flow of BI session method.

  • Use BDC_OPEN_GROUP function module to create a BI session.
  • BDCDATA structure, enter the value for all screens and fields that must be processed in the transaction
  • Use BDC INSERT function module to transfer the transaction and the BDCDATA structure to the session
  • Use BDC_CLOSE_GROUP function module to close the batch input session.

Now this session will be in a batch input queue and we need to process it. The session processing can be two types

  • Manually using the batch input menu options (SM35 transaction).
  • Use RSBDCSUB program to run the session in background.

BDC

  1. What is BDC in ABAP SAP ?
  2. BDC example in ABAP ?

Tuesday, March 27, 2012

List processing example

*&---------------------------------------------------------------------*
*& Report Z_LIST_PROCESSING
*&
*&---------------------------------------------------------------------*

REPORT Z_LIST_PROCESSING .

*&---------------------------------------------------------------------*
* Declare global object and selection screen.
*&---------------------------------------------------------------------*
*-----------------------------------------------------------------------
* TYPE POOL
*-----------------------------------------------------------------------
TYPE-POOLS:
SLIS.
*----------------------------------------------------------------------*
* TABLES
*----------------------------------------------------------------------*
TABLES:MARA.
*----------------------------------------------------------------------*
* TYPES
*----------------------------------------------------------------------*
*Struct MARA
TYPES: BEGIN OF GTY_MARA,
MATNR TYPE MARA-MATNR,"MATERIAL NUMBER
MTART TYPE MARA-MTART,
END OF GTY_MARA.
*Struct MAKT
TYPES: BEGIN OF GTY_MAKT,
MATNR TYPE MAKT-MATNR,"MATERIAL NUMBER
MAKTX TYPE MAKT-MAKTX,
END OF GTY_MAKT.
*Struct OUTPUT
TYPES: BEGIN OF GTY_OUTPUT,
MATNR TYPE MARA-MATNR,"MATERIAL NUMBER
MTART TYPE MARA-MTART,"MATERIAL TYPE
MAKTX TYPE MAKT-MAKTX,"MATERIAL DES
END OF GTY_OUTPUT.
*----------------------------------------------------------------------*
* Internal table
*----------------------------------------------------------------------*
DATA: GT_OUTPUT TYPE STANDARD TABLE OF GTY_OUTPUT,
GT_MARA TYPE STANDARD TABLE OF GTY_MARA,
GT_MAKT TYPE STANDARD TABLE OF GTY_MAKT,
*----------------------------------------------------------------------*
* Work area
*----------------------------------------------------------------------*
GS_OUTPUT TYPE GTY_OUTPUT,
GS_MARA TYPE GTY_MARA,
GS_MAKT TYPE GTY_MAKT.
*----------------------------------------------------------------------*
* Selection screen
*----------------------------------------------------------------------*
SELECT-OPTIONS: S_ERDA FOR MARA-ERSDA default '20111017 ' OBLIGATORY.
PARAMETERS:
pa_lim_1 RADIOBUTTON GROUP lim ,"JOIN
pa_lim_2 RADIOBUTTON GROUP lim,"FOR ALL ENTRIES
*----------------------------------------------------------------------*
* INITIALIZATION.
*----------------------------------------------------------------------*
INITIALIZATION.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
*Select data
IF PA_LIM_1 IS NOT INITIAL.
*Join
SELECT
M~MATNR
M~MTART
M2~MAKTX
INTO TABLE GT_OUTPUT
FROM
MARA AS M
JOIN MAKT AS M2 ON M~MATNR = M2~MATNR
WHERE M~ERSDA IN S_ERDA AND
M2~SPRAS = 'E'.
ELSE.
*For all entries
SELECT
MATNR
MTART
FROM MARA
INTO TABLE GT_MARA
WHERE ERSDA IN S_ERDA.
DELETE ADJACENT DUPLICATES FROM GT_MARA COMPARING MATNR.
IF GT_MARA IS NOT INITIAL.
SELECT
MATNR
MAKTX
FROM MAKT
INTO TABLE GT_MAKT
FOR ALL ENTRIES IN GT_MARA
WHERE MATNR = GT_MARA-MATNR AND SPRAS = 'E'.
ENDIF.
SORT GT_MAKT BY MATNR.
LOOP AT GT_MARA INTO GS_MARA.
CLEAR: GS_MAKT.
READ TABLE GT_MAKT BINARY SEARCH WITH KEY MATNR = GS_MARA-MATNR
INTO GS_MAKT.
GS_OUTPUT-MATNR = GS_MARA-MATNR.
GS_OUTPUT-MTART = GS_MARA-MTART.
GS_OUTPUT-MAKTX = GS_MAKT-MAKTX.
APPEND GS_OUTPUT TO GT_OUTPUT.
ENDLOOP.
ENDIF.
*----------------------------------------------------------------------*
* End-OF-SELECTION
*----------------------------------------------------------------------*
END-OF-SELECTION.
* Output data

LIST PROCESSING

* Struct
TYPES: BEGIN OF GTY_OUTPUT1,
MTART TYPE MARA-MTART,"MATERIAL TYPE
MATNR TYPE MARA-MATNR,"MATERIAL NUMBER
MAKTX TYPE MAKT-MAKTX,"MATERIAL DES
END OF GTY_OUTPUT1.
DATA: GT_OUTPUT1 TYPE STANDARD TABLE OF GTY_OUTPUT1,
GS_OUTPUT1 TYPE GTY_OUTPUT1.
LOOP AT GT_OUTPUT INTO GS_OUTPUT.
GS_OUTPUT1-MTART = GS_OUTPUT-MTART.
GS_OUTPUT1-MATNR = GS_OUTPUT-MATNR.
GS_OUTPUT1-MAKTX = GS_OUTPUT-MAKTX.
APPEND GS_OUTPUT1 TO GT_OUTPUT1.
ENDLOOP.

SORT GT_OUTPUT1 BY MTART MATNR.
LOOP AT GT_OUTPUT1 INTO GS_OUTPUT1.
AT FIRST.
WRITE: / 'AT FIRST'.
ENDAT.
AT NEW MTART.
WRITE: /.
WRITE: /10(15) 'MATERIAL TYPE:'.
WRITE: 26(10) GS_OUTPUT1-MTART.
WRITE: /1(15) 'Material number'.
WRITE: 17(20) 'Material description'.
ENDAT.
WRITE: /1(10) GS_OUTPUT1-MATNR.
WRITE: 17(20) GS_OUTPUT1-MAKTX.
AT END OF MTART.
WRITE: /.
ULINE 10(30).
ENDAT.
AT LAST.
WRITE: / 'AT last'.
ENDAT.
ENDLOOP.
ENDIF.

Selection screen:
Here's the output: