Sap Technology‎ > ‎

ABAP DEVELOPMENT

  • Add text from payment doc to FCHN This improve version of standard report FCHN add text from payment document line item. For quick modification , I used not used yet field "Name of the payee 4 " ( alv_header-ZNME4 )  to store SGTXT from BSAS     . Insert Code:     Select SGTXT from BSAS into alv_header-ZNME4     where BUKRS = alv_header-ZBUKR        and  BELNR = alv_header-VBLNR        and GJAHR =    alv_header-GJAHR.     ENDSELECT.
    Posted Sep 17, 2015, 9:30 PM by Sen Long
  • Example for Reporting Events This example shows a typical report where the logical database F1S is assigned to its properties. REPORT demo_get. NODES: spfli, sflight, sbook. DATA: weight TYPE p LENGTH 8 DECIMALS 4, total_weight TYPE p LENGTH 8 DECIMALS 4. INITIALIZATION. carrid-sign = 'I'. carrid-option = 'EQ'. carrid-low = 'AA'. carrid-high = 'LH'. APPEND carrid TO carrid. START-OF-SELECTION. WRITE 'Luggage weight of flights'. GET spfli FIELDS carrid connid cityfrom cityto. SKIP. ULINE. WRITE: / 'Carrid:', spfli-carrid, 'Connid:', spfli-connid, / 'From: ', spfli-cityfrom, 'To: ', spfli-cityto. ULINE. GET sflight FIELDS fldate. SKIP. WRITE: / 'Date:', sflight-fldate. GET sbook FIELDS luggweight. weight = weight + sbook-luggweight. GET sflight LATE FIELDS carrid . WRITE: / 'Luggage weight =', weight. total_weight = total_weight + weight. weight = 0 ...
    Posted Oct 5, 2014, 6:20 AM by Sen Long
  • # Helpful ABAP reports  ABAP Program to delete mass documents  ABAP System Fields ABAP Objects  ABAP statements - overview  Introducing the next generation of ABAP debugging Example : Simple ABAP ALV LIST VIEWER Here are some ABAP reports rarely used bit helpful for ABAPer:RSCLTCOPCopy tables across clients RSAVGL00Table adjustment across clients RSINCL00Extended program list RSBDCSUBRelease batch-input sessions automaticly RSTXSCRPTransport SAPscript files across systems RSORARELGet the Oracle Release RGUGBR00Substitution/Validation utility RSPARAMDisplay all instance parameters RSUSR003Check the passwords of users SAP* and DDIC in all clients RSUSR006List users last login
    Posted Oct 5, 2014, 6:09 AM by Sen Long
  • Smartform : Good Issue Note Form This sample smartform print good issue delivery note base on Material Document.Code to call form: *----------------------------------------------------------------------- * Program Name : ZMRGISL * Description  : This program is used to: *              :   - print document related to goods issue transaction *----------------------------------------------------------------------- * Change History Log *----------------------------------------------------------------------- * Date        | Changed by        | <<CR#-DEVK# *             | Change Requestor  | => Description *----------------------------------------------------------------------- * Date Aug 18 2011 * Change by htkhoa * Add form for HCM *----------------------------------------------------------------------- REPORT  ZMRGISL MESSAGE-ID zmsg. INCLUDE ZMRGISLFORM. PERFORM show_form. form show_form.   data: OUTPUT_OPTIONS type SSFCOMPOP,         control type SSFCTRLOP. TABLES :          USR01. SELECT SINGLE FROM USR01 WHERE BNAME = SY-UNAME. "control-device = 'PRINTER'. "control-device = 'LP01'. "OUTPUT_OPTIONS-TDNOPRINT = 'X'. "OUTPUT_OPTIONS-TDIMMED  = 'X'. OUTPUT_OPTIONS-TDDEST = USR01-SPLD. OUTPUT_OPTIONS-TDNEWID = 'X'. "control-no_dialog = 'X'. Data : version type ...
    Posted Nov 7, 2013, 12:10 AM by Sen Long
  • ABAP Program to delete mass documents Generally, parked documents can be deleted separately. However, there is no option for deleting several documents at the same time. This ZDELEPARKED program solve this issue.Step 1. Call transaction SE38 and create the ZDELEPARKED report.              Title: Mass deletion of parked documents              Type: Executable program              Copy the report from the correction instructions then save and activate it.              Step 2. Create following text symbols (SE38 - text elements):              001 General selections              002 Processing status              003 Delete parked documents              004 Do you really want to delete the documents selected?              005 No documents found              006 Number of documents:              007 Documents were already deleted.              Save and activate the change.              Step 3. Create the following selection texts with reference to the dictionary:              BELNR Document number              BKTXT ...
    Posted Jun 26, 2013, 3:46 AM by Khoa Huynh
Showing posts 1 - 5 of 11. View more »


Add text from payment doc to FCHN

posted Sep 17, 2015, 9:28 PM by Sen Long   [ updated Sep 17, 2015, 9:30 PM ]


This improve version of standard report FCHN add text from payment document line item. For quick modification , I used not used yet field "Name of the payee 4 " ( alv_header-ZNME4 )  to store SGTXT from BSAS     . 

Insert Code:
    Select SGTXT from BSAS into alv_header-ZNME4
    where BUKRS = alv_header-ZBUKR
       and  BELNR = alv_header-VBLNR
       and GJAHR =    alv_header-GJAHR.
    ENDSELECT.



Example for Reporting Events

posted Oct 5, 2014, 6:20 AM by Sen Long   [ updated Oct 5, 2014, 6:20 AM ]

This example shows a typical report where the logical database F1S is assigned to its properties.

REPORT demo_get.

NODES: spfli, sflight, sbook.

DATA: weight TYPE p LENGTH 8 DECIMALS 4,
total_weight TYPE p LENGTH 8 DECIMALS 4.

INITIALIZATION.
carrid-sign = 'I'.
carrid-option = 'EQ'.
carrid-low = 'AA'.
carrid-high = 'LH'.
APPEND carrid TO carrid.

START-OF-SELECTION.
WRITE 'Luggage weight of flights'.

GET spfli FIELDS carrid connid cityfrom cityto.
SKIP.
ULINE.
WRITE: / 'Carrid:', spfli-carrid,
'Connid:', spfli-connid,
/ 'From: ', spfli-cityfrom,
'To: ', spfli-cityto.
ULINE.

GET sflight FIELDS fldate.
SKIP.
WRITE: / 'Date:', sflight-fldate.

GET sbook FIELDS luggweight.
weight = weight + sbook-luggweight.
GET sflight LATE FIELDS carrid .
WRITE: / 'Luggage weight =', weight.
total_weight = total_weight + weight.
weight = 0.

END-OF-SELECTION.
ULINE.
WRITE: / 'Sum of luggage weights =', total_weight.

# Helpful ABAP reports

posted Oct 5, 2014, 6:08 AM by Sen Long   [ updated Oct 5, 2014, 6:09 AM ]


Here are some ABAP reports rarely used bit helpful for ABAPer:

RSCLTCOP
Copy tables across clients
RSAVGL00
Table adjustment across clients
RSINCL00
Extended program list
RSBDCSUB
Release batch-input sessions automaticly
RSTXSCRP
Transport SAPscript files across systems
RSORAREL
Get the Oracle Release
RGUGBR00
Substitution/Validation utility
RSPARAM
Display all instance parameters
RSUSR003
Check the passwords of users SAP* and DDIC in all clients
RSUSR006
List users last login

Smartform : Good Issue Note Form

posted Nov 7, 2013, 12:09 AM by Sen Long   [ updated Nov 7, 2013, 12:10 AM ]

This sample smartform print good issue delivery note base on Material Document.
Good Issue Note

Code to call form:

*-----------------------------------------------------------------------
* Program Name : ZMRGISL
* Description  : This program is used to:
*              :   - print document related to goods issue transaction
*-----------------------------------------------------------------------
* Change History Log
*-----------------------------------------------------------------------
* Date        | Changed by        | <<CR#-DEVK#
*             | Change Requestor  | => Description
*-----------------------------------------------------------------------
* Date Aug 18 2011
* Change by htkhoa
* Add form for HCM
*-----------------------------------------------------------------------

REPORT  ZMRGISL MESSAGE-ID zmsg.
INCLUDE ZMRGISLFORM.
PERFORM show_form.
form show_form.
  data: OUTPUT_OPTIONS type SSFCOMPOP,
        control type SSFCTRLOP.
TABLES :
         USR01.
SELECT SINGLE FROM USR01 WHERE BNAME = SY-UNAME.
"control-device = 'PRINTER'.
"control-device = 'LP01'.
"OUTPUT_OPTIONS-TDNOPRINT = 'X'.
"OUTPUT_OPTIONS-TDIMMED  = 'X'.
OUTPUT_OPTIONS-TDDEST = USR01-SPLD.
OUTPUT_OPTIONS-TDNEWID = 'X'.
"control-no_dialog = 'X'.

Data : version type tdsfname.
If HN = 'X' .
  version = 'ZSD_DLVNOTE' .
ELSEIF NA 'X'.
  version = 'ZSD_DLVNOTE_NA' .
Else.
  version = 'ZSD_DLVNOTE_HCM' .
ENDIF.

 data:    form_name TYPE rs38l_fnam.
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
  formname = version
IMPORTING
  fm_name = form_name
EXCEPTIONS
  no_form = 1
  no_function_module = 2
  OTHERS 3.


CALL FUNCTION form_name
EXPORTING
    output_options = output_options
    control_parameters = control
    user_settings = ' '
    p_mblnr = p_mblnr
    p_mjahr = p_mjahr
TABLES
  it_mkpf = it_mkpf
.
IF sy-subrc <> 0.
ENDIF.

ENDFORM.


ABAP Program to delete mass documents

posted Jun 26, 2013, 3:37 AM by Khoa Huynh   [ updated Jun 26, 2013, 3:46 AM ]

Generally, parked documents can be deleted separately. However, there is no option for deleting several documents at the same time. This ZDELEPARKED program solve this issue.


Step 1. Call transaction SE38 and create the ZDELEPARKED report.
              Title: Mass deletion of parked documents
              Type: Executable program
              Copy the report from the correction instructions then save and activate it.
              
Step 2. Create following text symbols (SE38 - text elements):
              001 General selections
              002 Processing status
              003 Delete parked documents
              004 Do you really want to delete the documents selected?
              005 No documents found
              006 Number of documents:
              007 Documents were already deleted.
              Save and activate the change.
              
Step 3. Create the following selection texts with reference to the dictionary:
              BELNR Document number
              BKTXT Document header text
              BLART Document type
              BLDAT Document date
              BUDAT Posting date
              BUKRS Company code
              GJAHR Fiscal year
              USNAM User
              XBLNR Reference
              XFRGE Released
              XPRFG Document complete
              XWFFR Release required.
              Save and activate the change.
              
Step 4. Call transaction SE41 (Menu Painter) with the following parameters:
              Program: ZDELEPARKED
              Status: DELE
              Choose CREATE.
              Short text: Delete parked documents
              Status type: Dialog status
a) Fill the SAVE function key (diskette) with the 'DELE' function code with the following parameters:

                       Functional type: Empty
                       Function text: Delete
                       Icon name: ICON_DELETE
                       Icon text: Delete
                       Fastpath: space
b) Fill the BACK function key (green arrow) with the 'BACK' function code.
c) Fill the EXIT function key (yellow arrow) with the '%EX' function code.
d) Fill the CANCEL function key (red arrow) with the 'RW' function code.
e) Fill the PRINT function key with the '%PRI' function code.
              
f) Create the LIST entry for the menu bar and assign to it these menu options:
                       %PRI Print
                       %PC Download
                       %EX Exit
g) Create the EDIT entry for the menu bar and assign to it these menu options:
                       DELE Delete
                       %SC  Find string
                       RW   Cancel
h) Create the GOTO entry for the menu bar and assign to it this menu option:
                       BACK Back
              
i) Save and activate the status.
              

Step 5. Activate the ZDELEPARKED report.


Code:
*&---------------------------------------------------------------------*
*& Report  ZDELEPARKED
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZDELEPARKED.

TABLES: vbkpf, t020.
DATA:   mode TYPE c VALUE 'N'.
DATA:   BEGIN OF tbkpf OCCURS 5.
        INCLUDE STRUCTURE vbkpf.
DATA:   END   OF tbkpf.
DATA:   BEGIN OF it020 OCCURS 0.
        INCLUDE STRUCTURE t020.
DATA:   END   OF it020.
DATA:   BEGIN OF bdcdata OCCURS 0.
        INCLUDE STRUCTURE bdcdata.
DATA:   END OF bdcdata.
DATA:   BEGIN OF messtab OCCURS 0.
        INCLUDE STRUCTURE bdcmsgcoll.
DATA:   END OF messtab.
DATA:    char(20)       TYPE c,
         count          TYPE i,
         xdele.

SELECT-OPTIONS:
         bukrs     FOR  vbkpf-bukrs MEMORY ID buk,
         belnr     FOR  vbkpf-belnr,
         gjahr     FOR  vbkpf-gjahr MEMORY ID gjr.


SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK 2 WITH FRAME TITLE text-001.
SELECT-OPTIONS:
         budat     FOR  vbkpf-budat,
         bldat     FOR  vbkpf-bldat,
         blart     FOR  vbkpf-blart,
         xblnr     FOR  vbkpf-xblnr,
         bktxt     FOR  vbkpf-bktxt,
         usnam     FOR  vbkpf-usnam DEFAULT sy-uname.
SELECTION-SCREEN END OF BLOCK 2.

SELECTION-SCREEN BEGIN OF BLOCK 3 WITH FRAME TITLE text-002.
SELECT-OPTIONS:
         xwffr     FOR  vbkpf-xwffr,
         xprfg     FOR  vbkpf-xprfg,
         xfrge     FOR  vbkpf-xfrge.
SELECTION-SCREEN END OF BLOCK 3.


AT SELECTION-SCREEN.

START-OF-SELECTION.

  SET PF-STATUS 'DELE'.

  CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
    EXPORTING
      tcode  = 'FBV0'
    EXCEPTIONS
      ok     = 1
      OTHERS = 4.
  IF sy-subrc = 4.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    EXIT.
  ENDIF.


  SELECT * FROM vbkpf INTO tbkpf
                      WHERE   ausbk IN bukrs
                        AND   belnr IN belnr
                        AND   gjahr IN gjahr
                        AND   budat IN budat
                        AND   bldat IN bldat
                        AND   blart IN blart
                        AND   bktxt IN bktxt
                        AND   xblnr IN xblnr
                        AND   usnam IN usnam
                        AND   bstat EQ 'V'
                        AND   xwffr IN xwffr
                        AND   xfrge IN xfrge
                        AND   xprfg IN xprfg.

    APPEND tbkpf.
    count = count + 1.
  ENDSELECT.

  SORT tbkpf BY ausbk belnr gjahr.

  IF count = 0.
    WRITE: /, text-005.
  ELSE.
    WRITE: /, text-006, count, /.
    ULINE.
    LOOP AT tbkpf.
      WRITE: /, tbkpf-ausbk, tbkpf-bukrs, tbkpf-belnr, tbkpf-gjahr.
    ENDLOOP.
  ENDIF.

END-OF-SELECTION.

AT USER-COMMAND.
  CLEAR: char.
  IF count > 0.
    CASE sy-ucomm.
      WHEN 'DELE'.
        IF xdele = space.
          CALL FUNCTION 'POPUP_TO_CONFIRM_LOSS_OF_DATA'
            EXPORTING
              titel     = text-003
              textline1 = text-004
              textline2 = space
            IMPORTING
              answer    = char(1).
          IF char(1) = 'J'.
            PERFORM fbv0_dele.
            xdele = 'X'.
          ELSE.
            EXIT.
          ENDIF.
        ELSE.
          MESSAGE i899(f5) WITH text-007.
        ENDIF.
      WHEN 'BACK'.
      WHEN OTHERS.
        EXIT.
    ENDCASE.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  FBV0_DELE
*&---------------------------------------------------------------------*                                                                    *
*&      Find out, how document was parked (classically or by ENJOY)
*&---------------------------------------------------------------------*                                                                    *

FORM fbv0_dele.
  REFRESH messtab.
  LOOP AT tbkpf.
    CLEAR t020.
    SELECT SINGLE * FROM t020 WHERE tcode = tbkpf-tcode.
    IF t020-gener = space.              "parked by classical transaction
      PERFORM fbv0_dele1 USING tbkpf-gjahr
                                  tbkpf-belnr
                                  tbkpf-bukrs.
    ELSE.                               "parked by ENJOY
      PERFORM fbv0_dele2 USING tbkpf-gjahr
                            tbkpf-belnr
                            tbkpf-bukrs.
    ENDIF.
  ENDLOOP.
  CHECK sy-subrc EQ 0.
  LOOP AT messtab.
    WRITE: / messtab.
  ENDLOOP.
ENDFORM.                                                    "FBV0_DELE

*&---------------------------------------------------------------------*
*&      Form  FBV0_DELE1
*&---------------------------------------------------------------------*
*&      Classically parked documents
*&---------------------------------------------------------------------*

FORM fbv0_dele1 USING i_gjahr LIKE bkpf-gjahr
                     i_belnr LIKE bkpf-belnr
                     i_bukrs LIKE bkpf-bukrs.

  DATA: xdate(10) TYPE c.
  REFRESH bdcdata.
  PERFORM bdc_dynpro      USING 'SAPMF05V'
                                '0100'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'RF05V-GJAHR'.
  PERFORM bdc_field       USING 'RF05V-BUKRS'
                                i_bukrs.
  PERFORM bdc_field       USING 'RF05V-BELNR'
                                i_belnr.
  PERFORM bdc_field       USING 'RF05V-GJAHR'
                                i_gjahr.
  PERFORM bdc_dynpro      USING 'SAPLF040'
                                '0700'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'BKPF-XBLNR'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                'BL'.
  PERFORM bdc_dynpro      USING 'SAPLSPO1'
                                '0200'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'SPOP-OPTION1'.              "Button YES
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                'ENTER'.

  CALL TRANSACTION 'FBV0' USING  bdcdata
                          MODE   mode
                          UPDATE 'S'.

  CALL FUNCTION 'MESSAGE_TEXT_BUILD'
    EXPORTING
      msgid               = sy-msgid
      msgnr               = sy-msgno
      msgv1               = sy-msgv1
      msgv2               = sy-msgv2
      msgv3               = sy-msgv3
      msgv4               = sy-msgv4
    IMPORTING
      message_text_output = messtab
    EXCEPTIONS
      OTHERS              = 4.
  APPEND messtab.
ENDFORM.                                                    "FBV0_DELE2

*&---------------------------------------------------------------------*
*&      Form  fbv0_dele2
*&---------------------------------------------------------------------*
*&     Documents parked by ENJOY
*&---------------------------------------------------------------------*

FORM fbv0_dele2  USING    i_gjahr
                          i_belnr
                          i_bukrs.
  DATA: xdate(10) TYPE c.
  REFRESH bdcdata.
  PERFORM bdc_dynpro      USING 'SAPMF05V'
                                '0100'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'RF05V-GJAHR'.
  PERFORM bdc_field       USING 'RF05V-BUKRS'
                                i_bukrs.
  PERFORM bdc_field       USING 'RF05V-BELNR'
                                i_belnr.
  PERFORM bdc_field       USING 'RF05V-GJAHR'
                                i_gjahr.

  IF t020-koart = 'D'.
    PERFORM bdc_dynpro      USING 'SAPMF05A'
                                   '1200'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'INVFO-ACCNT'.
  ELSEIF t020-koart = 'K'.
    PERFORM bdc_dynpro      USING 'SAPMF05A'
                                   '1100'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                   'INVFO-ACCNT'.
  ELSEIF t020-koart = 'S'.
    PERFORM bdc_dynpro      USING 'SAPMF05A'
                                   '1001'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'ACGL_HEAD-BLDAT'.
  ENDIF.

  PERFORM bdc_field       USING 'BDC_OKCODE'
                                 '=9-PD'.

  PERFORM bdc_dynpro      USING 'SAPLSPO1'
                                 '0200'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'SPOP-OPTION1'.              "Button YES
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                'ENTER'.

  CALL TRANSACTION 'FBV0' USING  bdcdata
                          MODE   mode
                          UPDATE 'S'.

  CALL FUNCTION 'MESSAGE_TEXT_BUILD'
    EXPORTING
      msgid               = sy-msgid
      msgnr               = sy-msgno
      msgv1               = sy-msgv1
      msgv2               = sy-msgv2
      msgv3               = sy-msgv3
      msgv4               = sy-msgv4
    IMPORTING
      message_text_output = messtab
    EXCEPTIONS
      OTHERS              = 4.

  APPEND messtab.

ENDFORM.                    " fbv0_dele2

*&---------------------------------------------------------------------*
*&      Form  BDC_DYNPRO
*&---------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
  CLEAR bdcdata.
  bdcdata-program  = program.
  bdcdata-dynpro   = dynpro.
  bdcdata-dynbegin = 'X'.
  APPEND bdcdata.
ENDFORM.                    "BDC_DYNPRO

*&---------------------------------------------------------------------*
*&      Form  BDC_FIELD
*&---------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
  CLEAR bdcdata.
  bdcdata-fnam = fnam.
  bdcdata-fval = fval.
  APPEND bdcdata.
ENDFORM.                    "BDC_FIELD

[Code] BAdi/Enahcement to add custom fields to standard screens

posted Jun 20, 2013, 12:51 AM by Sen Long

This sample program to find BADI and enhancement for a given transaction code. Create a custom program in your system by cut and paste example below codes.

 

 

REPORT ZTEST.

 

TABLES: TSTC,

TADIR,

MODSAPT,

MODACT,

TRDIR,

TFDIR,

ENLFDIR,

SXS_ATTRT ,

TSTCT.

 

DATA: JTAB LIKE TADIR OCCURS 0 WITH HEADER LINE.

DATA: FIELD1(30).

DATA: V_DEVCLASS LIKE TADIR-DEVCLASS.

 

PARAMETERS: P_TCODE LIKE TSTC-TCODE,

P_PGMNA LIKE TSTC-PGMNA .

 

DATA: WA_TADIR TYPE TADIR.

 

 

START-OF-SELECTION.

 

IF NOT P_TCODE IS INITIAL.

SELECT SINGLE * FROM TSTC WHERE TCODE EQ P_TCODE.

ELSEIF NOT P_PGMNA IS INITIAL.

TSTC-PGMNA = P_PGMNA.

ENDIF.

 

IF SY-SUBRC EQ 0.

SELECT SINGLE * FROM TADIR

WHERE PGMID = 'R3TR'

AND OBJECT = 'PROG'

AND OBJ_NAME = TSTC-PGMNA.

 

MOVE : TADIR-DEVCLASS TO V_DEVCLASS.

 

IF SY-SUBRC NE 0.

SELECT SINGLE * FROM TRDIR

WHERE NAME = TSTC-PGMNA.

 

IF TRDIR-SUBC EQ 'F'.

SELECT SINGLE * FROM TFDIR

WHERE PNAME = TSTC-PGMNA.

 

SELECT SINGLE * FROM ENLFDIR

WHERE FUNCNAME = TFDIR-FUNCNAME.

 

SELECT SINGLE * FROM TADIR

WHERE PGMID = 'R3TR'

AND OBJECT = 'FUGR'

AND OBJ_NAME EQ ENLFDIR-AREA.

 

MOVE : TADIR-DEVCLASS TO V_DEVCLASS.

ENDIF.

ENDIF.

 

SELECT * FROM TADIR INTO TABLE JTAB

WHERE PGMID = 'R3TR'

AND OBJECT in ('SMOD', 'SXSD')

AND DEVCLASS = V_DEVCLASS.

 

SELECT SINGLE * FROM TSTCT

WHERE SPRSL EQ SY-LANGU

AND TCODE EQ P_TCODE.

 

FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.

WRITE:/(19) 'Transaction Code - ',

20(20) P_TCODE,

45(50) TSTCT-TTEXT.

SKIP.

IF NOT JTAB[] IS INITIAL.

WRITE:/(105) SY-ULINE.

FORMAT COLOR COL_HEADING INTENSIFIED ON.

 

  • Sorting the internal Table

sort jtab by OBJECT.

data : wf_txt(60) type c,

wf_smod type i ,

wf_badi type i ,

wf_object2(30) type C.

clear : wf_smod, wf_badi , wf_object2.

  • Get the total SMOD.

 

LOOP AT JTAB into wa_tadir.

at first.

FORMAT COLOR COL_HEADING INTENSIFIED ON.

 

WRITE:/1 SY-VLINE,

2 'Enhancement/ Business Add-in',

41 SY-VLINE ,

42 'Description',

105 SY-VLINE.

WRITE:/(105) SY-ULINE.

endat.

clear wf_txt.

at new object.

if wa_tadir-object = 'SMOD'.

wf_object2 = 'Enhancement' .

elseif wa_tadir-object = 'SXSD'.

wf_object2 = ' Business Add-in'.

 

endif.

FORMAT COLOR COL_GROUP INTENSIFIED ON.

 

WRITE:/1 SY-VLINE,

 

2 wf_object2,

105 SY-VLINE.

endat.

 

case wa_tadir-object.

when 'SMOD'.

wf_smod = wf_smod + 1.

SELECT SINGLE MODTEXT into wf_txt

FROM MODSAPT

WHERE SPRSL = SY-LANGU

AND NAME = wa_tadir-OBJ_NAME.

FORMAT COLOR COL_NORMAL INTENSIFIED OFF.

 

when 'SXSD'.

  • For BADis

wf_badi = wf_badi + 1 .

select single TEXT into wf_txt

from SXS_ATTRT

where sprsl = sy-langu

and EXIT_NAME = wa_tadir-OBJ_NAME.

FORMAT COLOR COL_NORMAL INTENSIFIED ON.

 

endcase.

 

WRITE:/1 SY-VLINE,

2 wa_tadir-OBJ_NAME hotspot on,

41 SY-VLINE ,

42 wf_txt,

105 SY-VLINE.

AT END OF object.

write : /(105) sy-ULINE.

ENDAT.

 

ENDLOOP.

 

WRITE:/(105) SY-ULINE.

 

SKIP.

FORMAT COLOR COL_TOTAL INTENSIFIED ON.

WRITE:/ 'No.of Exits:' , wf_smod.

WRITE:/ 'No.of BADis:' , wf_badi.

 

ELSE.

FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.

WRITE:/(105) 'No userexits or BADis exist'.

ENDIF.

ELSE.

FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.

WRITE:/(105) 'Transaction does not exist'.

ENDIF.

 

AT LINE-SELECTION.

 

data : wf_object type tadir-object.

clear wf_object.

 

GET CURSOR FIELD FIELD1.

CHECK FIELD1(8) EQ 'WA_TADIR'.

read table jtab with key obj_name = sy-lisel+1(20).

move jtab-object to wf_object.

 

case wf_object.

when 'SMOD'.

SET PARAMETER ID 'MON' FIELD SY-LISEL+1(10).

 

CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.

when 'SXSD'.

SET PARAMETER ID 'EXN' FIELD SY-LISEL+1(20).

CALL TRANSACTION 'SE18' AND SKIP FIRST SCREEN.

ENDCASE.

Ways to find a userexit

posted Dec 9, 2011, 1:14 AM by Sen Long   [ updated Dec 9, 2011, 1:15 AM ]



Application- Specific User Exits (Userexit)
SAP Reference IMG -> Sales and Distribution -> System Modifications -> Userexits

Customer Exits(SMOD/CMOD)
ABAP Workbench -> Utilities -> Enhancements -> Definition (SMOD).
Repository Info System (SE84): Enhancements -> Customer Exits -> Enhancements

VOFM Routines
SAP Reference IMG -> Sales and Distribution -> System Modifications -> Routines
Transaction code: VOFM

Business Transaction Events
SAP Reference IMG -> Financial Accounting -> Financial Accounting Global Settings -> Business Transaction Events (FIBF)
Business Event Repository (BERE)

Classic BAdIs
Repository Info System (SE84):Enhancements -> Business Add-ins -> Definitions
Accelerators: Find BAdI: Find the BADI related to your transaction in minutes

Enhancement Framework
Enhancement Information System in the Object Navigator (transaction SE80).
Repository Info System (SE84): Enhancements -> Enhancements Spots
Repository Info System (SE84): Enhancements -> Composite Enhancements Spots
Accelerators: Find Enhancement Points/Sections: ABAP Ninja

Validations and Substitutions exits
Transaction code GGB0: Validation Overview
Transaction code GBB1: Substitutions Overview


Application- Specific User Exits (Userexit)
Modification Browser (SE95)


Field Exit
Report RSMODPRF


Customer Exits(SMOD/CMOD)
ABAP Workbench -> Utilities -> Enhancements -> Project Management (CMOD).
Repository Info System (SE84): Enhancements -> Customer Exits -> Projects


VOFM Routines
Transaction code: VOFM
Modification Browser (SE95)


Business Transaction Events
SAP Reference IMG -> Financial Accounting -> Financial Accounting Global Settings -> Business Transaction Events (FIBF)
Business Event Repository (BERE)


Classic BAdIs
Repository Info System (SE84): Enhancements -> Business Add-ins -> Implementations


Enhancement Framework
Enhancement Information System in the Object Navigator (transaction SE80)
Repository Info System (SE84): Enhancements -> Enhancements Implementations
Repository Info System (SE84): Enhancements -> Composite Enh. Implementations

Blogs and Articles
How Many Exit Routines are active in your SAP ERP system?
SAP User Exits and the People Who Love Them

Finding BADI Using SQL Trace (TCODE-ST05)
Accelerators
ABAP X-it Ray Eye (Scans all the exit routines active in SAP ERP)
To find out User Exit's and BADI's for Any Transaction code
Find User-exits, BADIs, BTEs, Etc by TCode or Program

Best Practices
Best Practice for a SAP ECC Consolidation project: filter dependent BAdI to organize the user-exits and enhancements
Dangerous Liaisons in User-Exits and How to Avoid Them
Dangerous Liaisons in User-Exits - Revisited

Relevant SAP Notes
381348 - Using Userexit, Customer Exit, VOFM in SD
842318 - FAQs about validations + substitutions
356737 - Customer name range for VOFM routines
327220 - VOFM function and its objects
29377 - FAQs: Field exits (CMOD)

SAP ALV grids & lists.

posted Apr 26, 2011, 11:47 PM by Sen Long   [ updated Apr 26, 2011, 11:49 PM ]

SAP provides two different ways to incorporate SAP ALV into your reports or programs which need to deal with tabular data. They are mentioned below:

Using REUSE_ALV_* function modules

SAP offers some easy to use function modules using which different kinds of ALV grid can be displayed from your program. These function modules provide a very simplified programming approach to use SAP ALV to display and work with tabular data. All such function modules can be found under the Function group SALV & SLVC_FULLSCREEN in the package (development class) SLIS. These function modules provide an easy & simple to program way of using SAP ALV, but on the other hand compromise with some advanced functionalities and gives lesser flexibility to the programmer. Still, this is the easiest way to program SAP ALV for simple reports and applications where the main purpose of report/ program is to display a tabular result.

There are four different forms of SAP ALV exposed through reuse function modules in order to cater different kinds of data display requirements.

(A) Simple ALV list

This form of ALV is used to display single table display. All the function modules in the above mentioned function group SALV with prefix REUSE_ALV_LIST_ belong to this form of ALV e.g. REUSE_ALV_LIST_DISPLAY, REUSE_ALV_LIST_LAYOUT_INFO_SET, REUSE_ALV_LIST_SELECTIONS_SET etc. This form of ALV outputs a single list on one complete screen. There’s a very limited possibility to control the layout of this output screen.

SAP ALV Tutorial, Simple SAP ALV List

Simple SAP ALV List

(B) Hierarchical sequential ALV list

This form of ALV lists is used to display 2 tables of data which form a 2-step hierarchy. The main function module to display this kind of ALV is REUSE_ALV_HIERSEQ_LIST_DISPLAY in function group SALV. There are some more function modules in function group SALV with prefix REUSE_ALV_HS_ belonging to this form of ALV. Typical to REUSE_ALV_* method of using ALV, it has a very limited possibility to control the layout of this output screen.

SAP ALV Tutorial, Hierarchical Sequential ALV List

Hierarchical Sequential ALV List


(C) Block ALV List

This form of ALV lists is used to display multiple independent tables. All the function modules in above mentioned function group SALV having prefix REUSE_ALV_BLOCK_ belong to this form of ALV. Block ALV list is used to display multiple ALV lists on the same output screen one after another.

SAP ALV Tutorial, Block ALV List

Block ALV List

(D) ALV Grid

This is the new generation of ALV replacing classical list formats mentioned above with grids. It’s used for the purpose similar to simple lists, but overtakes simple lists in terms of better usability, more in-built functionalities and look & feel. All the function modules related to this form of ALV can be found under function group SLVC_FULLSCREEN of package SLIS.

SAP ALV Tutorial, ALV Grid

ALV Grid

Using ABAP Class CL_GUI_ALV_GRID

This method of programming ALV grid runs on Control framework & is based on ABAP Objects. It gives 100% control of programming ALV to the developers. You can use this method to work with ALV similar to other screen elements and also freely add other screen elements on the same screen along with ALV. The main ABAP Class involved in this method is CL_GUI_ALV_GRID.

SAP ALV Tutorial, Multiple=

Multiple ALV Grids & Tree on same screen using CL_GUI_ALV_GRID method

I would be explaining important aspects of each of these methods to work with the SAP ALV in detail in my following posts.

ABAP Sample : Changing Lines

posted Apr 17, 2011, 7:43 PM by Sap Team

Use the MODIFYstatement.

We can use the table key to find and change a single line using its key, or find and change a set of lines that meet a certain condition. If the table has a non-unique key and there are duplicate entries, the first entry is changed.

Changing a Line Using the Table Key

To change a single line, use the following statement:

MODIFY TABLE itab FROM wa [TRANSPORTING f1 f2 ...].

The work area wa, which must be compatible with the line type of the internal table, plays a double role in this statement. Not only it is used to find the line that you want to change, but it also contains the new contents. The system searches the internal table for the line whose table key corresponds to the key fields in wa.

The system searches for the relevant table types as follows:

·        Standard tables

Linear search, where the runtime is in linear relation to the number of table entries. The first entry found is changed.

·        Sorted tables

Binary search, where the runtime is in logarithmic relation to the number of table entries. The first entry found is changed.

·        Hashed tables

The entry is found using the hash algorithm of the internal table. The runtime is independent of the number of table entries.

If a line is found, the contents of the non-key fields of the work area are copied into the corresponding fields of the line, and sy-subrc is set to 0. Otherwise, sy-subrc is set to 4. If the table has a non-unique key and the system finds duplicate entries, it changes the first entry.

You can specify the non-key fields that you want to assign to the table line in the TRANSPORTING addition. You can also specify the fields f1 f2 … dynamically using (n1) (n2) … as the contents of a field n1 n2 …. If <ni> is empty when the statement is executed, it is ignored. You can also restrict all fields f1 f2 … to subfields by specifying offset and length.

For tables with a complex line structure, the use of the TRANSPORTINGaddition results in better performance, provided the system does not have to transport unnecessary table-like components.

Changing Several Lines Using a Condition

To change one or more lines using a condition, use the following statement:

MODIFY itab FROM wa TRANSPORTING f1 f2 ... WHERE cond.

This processes all of the lines that meet the logical condition cond. The logical expression cond can consist of more than one comparison. In each comparison, the first operand must be a component of the line structure. If the table lines are not structured, the first operand can also be the expression TABLE_LINE. The comparison then applies to the entire line. If the line type of the internal table contains object reference variables as component comp or if the entire line type is a reference variable, the attributes of the attr object to which the respective line reference points can be specified as comparison values using comp->attr or table_line->attr.

The work area wa, which must be compatible with the line type of the internal table, contains the new contents, which in turn will be assigned to the relevant table line using the TRANSPORTING addition. Unlike the above MODIFYstatement, the TRANSPORTING addition is not optional here. Furthermore, you can only modify the key fields of the internal table if it is a standard table. If at least one line is changed, the system sets sy-subrc to 0, otherwise to 4.


REPORT demo_int_tables_modify .

DATA: BEGIN OF line,
        col1 TYPE i,
        col2 TYPE i,
      END OF line.

DATA itab LIKE HASHED TABLE OF line WITH UNIQUE KEY col1.

DO 4 TIMES.
  line-col1 = sy-index.
  line-col2 = sy-index ** 2.
  INSERT line INTO TABLE itab.

ENDDO.

line-col1 = 2.
line-col2 = 100.

MODIFY TABLE itab FROM line.

LOOP AT itab INTO line.
  WRITE: / line-col1, line-col2.
ENDLOOP.

The list output is:

         1        1
         2      100
         3        9
         4       16

The program fills a hashed table with a list of square numbers. The MODIFY statement changes the line of the table in which the key field col1 has the value 2.


REPORT demo_int_tables_modify_transp.

DATA: BEGIN OF line,
        col1 TYPE i,
        col2 TYPE i,
      END OF line.

DATA itab LIKE HASHED TABLE OF line WITH UNIQUE KEY col1.

DO 4 TIMES.
  line-col1 = sy-index.
  line-col2 = sy-index ** 2.
  INSERT line INTO TABLE itab.

ENDDO.

line-col2 = 100.

MODIFY itab FROM line TRANSPORTING col2
            WHERE ( col2 > 1 ) AND ( col1 < 4 ).

LOOP AT itab INTO line.
  WRITE: / line-col1, line-col2.
ENDLOOP.

The list output is:

         1        1
         2      100
         3      100
         4       16

The program fills a hashed table with a list of square numbers. The MODIFY statement changes the lines of the table where the content of field col2 is greater than 1 and the content of field col1 is less than 4.

Changing Table Lines Using the Index

You can use the MODIFY statement to change lines in tables using their index. There is also an obsolete variant of the WRITE TOstatement that you can use to modify lines in standard tables.

Changing Single Lines using MODIFY

To change a line using its index, use the following statement:

MODIFY itab FROM wa [INDEX idx] [TRANSPORTING f1 f2... ].

The work area wa specified in the FROM addition replaces the addressed line in the itab table. The work area must be convertible into the line type of the internal table.

If you use the INDEX option, the contents of the work area overwrite the contents of the line with the index idx. If the operation is successful, sy-subrc is set to 0. If the internal table contains fewer lines than idx, no line is changed and sy-subrc is set to 4.

Without the INDEX addition, you can only use the above statement within a LOOP. In this case, you delete the current line. idx is implicitly set to sy-tabix .

When you change lines in sorted tables, remember that you must not change the contents of key fields, and that a runtime error will occur if you try to replace the contents of a key field with another value. However, you can assign the same value.

The TRANSPORTING addition allows you to specify the fields that you want to change explicitly in a list.  If you change a sorted table, you may only specify non-key fields.


REPORT demo_int_tables_modify_ind.

DATA: BEGIN OF line,
        col1 TYPE i,
        col2 TYPE i,
      END OF line.

DATA itab LIKE TABLE OF line.

DO 3 TIMES.
  line-col1 = sy-index.
  line-col2 = sy-index ** 2.
  APPEND line TO itab.

ENDDO.

LOOP AT itab INTO line.
  IF sy-tabix = 2.
    line-col1 = sy-tabix * 10.
    line-col2 = ( sy-tabix * 10 ) ** 2.
    MODIFY itab FROM line.

  ENDIF.
ENDLOOP.

LOOP AT itab INTO line.
  WRITE: / sy-tabix, line-col1, line-col2.
ENDLOOP.

This produces the following output:

         1         1          1
         2        20        400
         3         3          9

Here, a sorted table itab is created and filled with three lines. The second line is replaced by the contents of the work area line.


REPORT demo_int_tables_modify_ind_ind.

DATA name(4) TYPE c VALUE 'col2'.

DATA: BEGIN OF line,
         col1 TYPE i,
         col2 TYPE i,
      END OF line.

DATA itab LIKE SORTED TABLE OF line WITH UNIQUE KEY col1.

DO 4 TIMES.
  line-col1 = sy-index.
  line-col2 = sy-index ** 2.
  APPEND line TO itab.

ENDDO.

line-col2 = 222.
MODIFY itab FROM line INDEX 2 TRANSPORTING (name).

line-col1 = 3.
line-col2 = 333.
MODIFY itab FROM line INDEX 3.

LOOP AT itab INTO line.
  WRITE: / sy-tabix, line-col1, line-col2.
ENDLOOP.

The list output is:

         1         1          1
         2         2        222
         3         3        333
         4         4         16

The example fills a sorted table with four lines. In the second and third lines, the component col2 is modified. If the third line were to be changed so that the value of line-col1 was no longer 3, a runtime error would occur, since the key fields of sorted tables may not be changed.

ABAP Sample Code : Overview of Stock Issue and Receive vs Billed Quatity by Storage Location

posted Apr 17, 2011, 7:19 PM by Sap Team   [ updated Apr 17, 2011, 7:21 PM ]

REPORT Z_SUM_01 LINE-SIZE 160 LINE-COUNT 44 NO STANDARD PAGE HEADING .
INCLUDE Z_SUM_TOP.
SET MARGIN 5.
DATA  BEGIN OF wa_zm01,
           WERKS TYPE ZM01-WERKS,
           LGORT TYPE ZM01-LGORT,
           MATNR TYPE ZM01-MATNR,
           MBLNR TYPE ZM01-MBLNR,
           ZEILE TYPE ZM01-ZEILE,
           BUDAT TYPE ZM01-BUDAT,
           LGNUM TYPE ZM01-LGNUM,
           CHARG TYPE ZM01-CHARG,
           SHKZG TYPE ZM01-SHKZG,
           MENGE TYPE ZM01-MENGE,
        END OF wa_zm01.
DATA  itab_zm01 LIKE SORTED TABLE OF wa_zm01 WITH UNIQUE KEY TABLE LINE."  WITH UNIQUE KEY LGORT MBLNR ZEILE.

DATA  begin of itab1 occurs ,
          WERKS LIKE MSEG-WERKS,  "Plant
          LGORT LIKE MSEG-LGORT,  "Storage
          MATNR LIKE MSEG-MATNR , "Material
          v_input LIKE MSEG-MENGE , " Return 602
          v_output LIKE MSEG-MENGE , " Issue 601
          v_total LIKE MSEG-MENGE  , "Net Lot
        end of itab1  .

*DATA  : tab1 LIKE STANDARD TABLE OF itab1 INITIAL SIZE 33.

SELECTION-SCREEN BEGIN OF BLOCK block1.
PARAMETERS:  pPlant LIKE MSEG-WERKS obligatory VALUE CHECK,
             FROMDATE LIKE BSIS-BUDAT obligatory,
             TODATE LIKE BSIS-BUDAT.

SELECTION-SCREEN END OF BLOCK block1.
PERFORM WriteHeader.
PERFORM Initialize .
*Select LGORT MATNR MBLNR ZEILE MENGE From ZM01 INTO CORRESPONDING FIELDS OF TABLE itab_zm01
Select From ZM01 INTO CORRESPONDING FIELDS OF TABLE itab_zm01
  Where WERKS = pPlant AND ( BUDAT GE FROMDATE ) and ( BUDAT LE TODATE ).
DATA :  t_input LIKE MSEG-MENGE , " Return 602
        t_output LIKE MSEG-MENGE . " Issue 601

 Loop at itab_zm01 into wa_zm01.
    AT NEW LGORT.
      WRITE: / 'Plan:', wa_zm01-LGORT.
      ULINE.
    ENDAT.
        AT NEW MATNR.
          WRITE: / 'Material:', wa_zm01-MATNR.
        ENDAT.
        AT END OF MATNR.
          itab1-LGORT = wa_zm01-LGORT.
          itab1-MATNR = wa_zm01-MATNR.
          t_input  = t_input + itab1-v_input.
          t_output = t_output + itab1-v_output.
          append itab1.
          clear itab1.
        ENDAT.
    AT END OF LGORT.
          itab1-LGORT = wa_zm01-LGORT.
          itab1-MATNR = '********'.
          itab1-v_output = t_output.
          itab1-v_input = t_input.
          append itab1.
          clear itab1.
          clear t_input.
          clear t_output.
    ENDAT.

    IF ( wa_zm01-SHKZG = 'H' ).
        itab1-v_output = itab1-v_output + wa_zm01-MENGE .
    ELSE.
        itab1-v_input = itab1-v_input + wa_zm01-MENGE .
    ENDIF.

    "WRITE : / wa_zm01-LGORT , wa_zm01-MATNR ,wa_zm01-MBLNR ,wa_zm01-ZEILE,wa_zm01-MENGE.

 Endloop.

 Loop at itab1.
    Write : / itab1-LGORT , itab1-MATNR , itab1-v_input ,itab1-v_output.
 Endloop.

*SELECT * FROM MSEG INTO wa_mseg
*   WHERE WERKS EQ pPlant ." and ( BUDAT GE FROMDATE ) and ( BUDAT LE TODATE ).
*
*ENDSELECT.

*PERFORM UpdateReport .

*PERFORM WriteReport.
PERFORM TEST.


FORM INITIALIZE .
  Clear itab_zm01.
  Clear itab1.
ENDFORM.                    " INITIALIZE
*&---------------------------------------------------------------------*
*&      Form  TEST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM TEST .
 Loop at itab_zm01 into wa_zm01.

 Endloop.
ENDFORM.                    " TEST
*&---------------------------------------------------------------------*
*&      Form  UPDATEREPORT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM UPDATEREPORT .
"Lưu chuyển tiền thuần từ hoạt động kinh doanh

ENDFORM.                    " UPDATEREPORT
*&---------------------------------------------------------------------*
*&      Form  WRITEHEADER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM WRITEHEADER .
  "FORMAT INTENSIFIED COLOR = 2.
  WRITE : /5(100) 'SUMMARY OF STOCK AND MONEY' COLOR COL_HEADING INTENSIFIED OFF INVERSE.
  ULINE.


ENDFORM.                    " WRITEHEADER

FORM WRITEREPORT.

*  FORMAT INTENSIFIED COLOR = 1.
  WRITE : /5(85) '' ,90(10) '(70)' , 100(30) ''  LEFT-JUSTIFIED , 130(30) LEFT-JUSTIFIED.

ENDFORM.                    " WRITEREPORT

1-10 of 11