More ABAP Tips and Tricks!

SAP ABAP Tips and Tricks

Get the PDF of any smartform

after previewing the smartform write "pdf!", it will gives the popup to save the pdf

 

Attach any document in SAP ABAP

use this code snippet in your program

DATA: manager TYPE REF TO cl_gos_manager,
      obj TYPE borident.
CONSTANTS: objtype TYPE borident-objtype VALUE 'ZDRAW'.

IF manager IS INITIAL.
    obj-objtype = objtype.
    SELECT SINGLE name FROM trdir
           INTO obj-objkey
           WHERE name = sy-repid.
      CONCATENATE obj-objkey '100' into obj-objkey SEPARATED BY
space.

endif.
START-OF-SELECTION.

set PF-STATUS 'ONE'.

*Creating the object of class 'CL_GOS_MANAGER'
    CREATE OBJECT manager
      EXPORTING
        is_object    = obj
        ip_no_commit = 'R'
      EXCEPTIONS
        OTHERS       = 1.

end-of-SELECTION.
WRITE: 'Hi'.
case sy-ucomm.
  WHen 'ATTACH'.

   CALL METHOD manager->start_service_direct
      EXPORTING
        ip_service       = 'PCATTA_CREA'
        is_object        = obj
      EXCEPTIONS
        no_object        = 1
        object_invalid   = 2
        execution_failed = 3
        OTHERS           = 4.
* Displaying the attached document
  WHen 'VIEW'.
    CALL METHOD manager->start_service_direct
      EXPORTING
        ip_service       = 'VIEW_ATTA'
        is_object        = obj
      EXCEPTIONS
        no_object        = 1
        object_invalid   = 2
        execution_failed = 3
        OTHERS           = 4.

ENDCASE.


 

Translate value of variable in to upper case

Translate v_var into upper case

 

Simpleast way to select and get selected fields in ALV

in the layout of ALV:

w_layout-box_fieldname           = '%_BOX'.
  w_layout-box_tabname             = 'I_OUTPUT'.

in the looping find by:

 LOOP AT i_output WHERE %_box = c_x.

 

Find any node in smartform

some times it is very difficult to find any node where it is being printed

to find that simply press ctrl+f and it will open a new window there you will find the node

 

Speed up the loop in 2 or more loops:  Use Parallel cusrsor

Simple program to use parallel cursor

loop at itab1 into wtab1.

 READ TABLE itab2 INTO wtab2 WITH KEY
                      matnr = witab1-matnr
                      werks = witab1-werks
                      idnrk = witab1-idnrk
                      BINARY SEARCH.

      IF sy-subrc = 0 .
        lw_tabix = sy-tabix.
        LOOP AT itab2 INTO wtab2 FROM lw_tabix WHERE
                                        matnr = witab1-matnr
                                        werks = witab1-werks
                                        idnrk = witab1-idnrk.

*             no.of records in 2nd table
          lw_count = lw_count + 1 .

        ENDLOOP.

     else.

       exit.

      ENDIF.

endloop.

 

Create Notepad text editor in SAP

Code Snippet to create notepad text editor

CREATE OBJECT EDITOR_CONTAINER
      EXPORTING
        CONTAINER_NAME              = 'TEXTEDITOR'
      EXCEPTIONS
        CNTL_ERROR                  = 1
        CNTL_SYSTEM_ERROR           = 2
        CREATE_ERROR                = 3
        LIFETIME_ERROR              = 4
        LIFETIME_DYNPRO_DYNPRO_LINK = 5.

    CREATE OBJECT TEXT__EDITOR
      EXPORTING
        PARENT           = EDITOR_CONTAINER
        WORDWRAP_MODE    = CL_GUI_TEXTEDIT=>WORDWRAP_AT_FIXED_POSITION
        WORDWRAP_POSITION          = LINE_LENGTH
        WORDWRAP_TO_LINEBREAK_MODE = CL_GUI_TEXTEDIT=>TRUE.
*if want to display in table form
 CALL METHOD text__editor->set_text_as_r3table
      EXPORTING
        table           = i_text     " data to be passed to text editor
      EXCEPTIONS
        error_dp        = 1
        error_dp_create = 2
        OTHERS          = 3.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
*
**
*
* CALL METHOD TEXT_EDITOR->SET_TOOLBAR_MODE
*      EXPORTING
*        TOOLBAR_MODE = CL_GUI_TEXTEDIT=>FALSE.
*
*    CALL METHOD TEXT_EDITOR->SET_STATUSBAR_MODE
*      EXPORTING
*        STATUSBAR_MODE = CL_GUI_TEXTEDIT=>FALSE.
ENDIF.

 

Progress Indicator in SAP

Class : cl_progress_indicator

or

FM SAPGUI_PROGRESS_INDICATOR