• How To Hide Columns In Table Control

    In this tutorial we will explain how to hide a column in a table control use in a Dynpro screen.

    As example, we will hide a column in the table control ‘TC_DLSAM’ (used in the MRP transaction MD06).

    Step 1:

    In the flow logic of the screen where the table control is used, we will have to call a module in the screen PBO (Process Before Output) which will contains the appropriate code logic to hide the column.

    Code to call the module ‘F_HIDE_COLUMN’:

    *----------------------
    PROCESS BEFORE OUTPUT.
    *----------------------
    
    * Some Codes…
    
     
    
    * Calling the module which will hide the column.
    
      MODULE f_hide_columns.
    

    Step 2:

    The following code will hide the column ‘MRP Date’ from the table control ‘TC_DLSAM’.

     

    Code:

    *----------------------------------------------------------------------*
    * Hiding the column \'MRP Date\' in the table control \'TC_DLSAM\' in      *
    * screen 602 of transaction MD06.                                      *
    *----------------------------------------------------------------------*
    MODULE f_hide_column OUTPUT.
    *----------------------------------------------------------------------*
    * Other Declarations may be needed:
    *  CONTROLS: tc_dlsam TYPE TABLEVIEW USING SCREEN 602.
    *  TYPE-POOL CXTAB .
    *  TYPES CXTAB_COLUMN type scxtab_column.
      
    * Types:
      DATA:
        lst_cols TYPE cxtab_column.
    
    * Constants:
      CONSTANTS:
        lc_column_mrp_date TYPE char10 VALUE \'MDKE-DSDAT\'.
    
    * We will have to loop at the standard table control \'TC_DLSAM\' 
    * deep structure \'COLS\' and we will modify the display attribute
    * of column \'MRP Date\' to hide it on the report.
      LOOP AT tc_dlsam-cols INTO lst_cols.
    
    *   If the column name equals to \'MDKE-DSDAT\'(MRP Date), proceed.
        IF lst_cols-screen-name EQ lc_column_mrp_date.
    
    *     Set the \'Invisible\' display attribute of column \'MRP Date\' 
    *     to true to hide it.
          lst_cols-invisible = 1.
    
    *     Modify the table control deep structure \'COLS\' with the new
    *     display attribute for column \'MRP Date\'.
          MODIFY tc_dlsam-cols FROM lst_cols
          INDEX sy-tabix.
    
        ENDIF.
    
    *   As a best practice, clear the structure 
    *   as its inside a loop.
        CLEAR:
          lst_cols.
    
      ENDLOOP.
    
    ENDMODULE.                 \" F_HIDE_COLUMN OUTPUT

     

  • Detecting Carriage Return & Line Feed From Incoming File

    When reading a file which contains a “Carriage Return” using the function module ‘GUI_UPLOAD’, the function module ‘GUI_UPLOAD’ will display the carriage return with the symbol ‘#’.

    For example:

    Using the following code, we will try to read the content the file ‘text_file.txt’ (link) which contains a “Carriage Return” at the end of the lines.

    Code:

    CALL FUNCTION \'GUI_UPLOAD\'
    EXPORTING
    filename = \'C:\\Users\\theuser\\Desktop\\test_file.txt\'
    TABLES
    data_tab = gt_input_file
    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 EQ 0.
    
    ENDIF.

    Please note that the carriage return will not be visible when we view using ‘Notepad’. To view the carriage return, open the file using ‘Notepad++’ and click on the button ‘Show All Characters’ and the carriage return value will become visible.

    After the file ‘test_file.txt’ (link) has been read by the function module ‘GUI_UPLOAD’, in debug we can notice that the internal table ‘GT_INPUT_FILE’ contains an additional character ‘#’ which represent the carriage return from the incoming file.

    The character ‘#’ (from the incoming file) is not the same hash ‘#’ value that we type from the keyboard. They look similar but they both have different hexadecimal value.

    If we move the hash from the incoming file to variable ‘GV_CARRIAGE_RETURN’ and move a normal hash ‘#’ (type from the keyboard) to variable ‘GV_HASH’. We can notice in debug that both look same but they have different hexadecimal values.

    In case you want to identify the incoming hash ‘#’ using ABAP code, then we must use the attribute ‘CR_LF’ from the class interface ‘CL_ABAP_CHAR_UTILITIES’.

    In debug mode, we can notice that the hexadecimal value of the attribute ‘CL_ABAP_CHAR_UTILITIES=>CR_LF+0(1)’ is same as the hexadecimal value of the carriage return from the incoming file.

    For example:

    The following code will return the carriage return hash ‘#’.

    cl_abap_char_utilities=>cr_lf+0(1)

    We can use the attribute ‘CR_LF+0 (1) to identify the carriage return hash ‘#’ from the incoming file using the following code:

    Code:

    IF cl_abap_char_utilities=>cr_lf+0(1) EQ gv_carriage_return.
    
    MESSAGE \'This is a carriage return hash.\' TYPE \'I\'.
    
    ENDIF.

    Additional Information:

    cl_abap_char_utilities=>cr_lf+0(1) : Return the carriage return

    cl_abap_char_utilities=>cr_lf : Return the carriage return with line feed

  • Enable DynPro Screen Field to Accept Negative Values

    For a DynPro screen field to accept negative values, in the field attribute ‘Text’, write ‘V’ (Sign Enable) in the last letter.

    For example: ‘__________V’ (please refer to the below screenshot)

    \"\"

  • Generate One Spool Per Dunning Form

    In the FI flow, to generate each dunning form in a separate spool, the OSS note 1987841 must be installed.

  • SAP New ABAP Editor Best Tricks and Features

    The SAP ABAP editor (SE38) is one of the most used transaction by ABAPers and many useful features remains unknown to many.

    In this tutorial, we will try to reveal some useful features of the SAP ABAP editor (SE38).

    Before proceeding, please make sure that the new front-end editor is activated (please refer to below screenshot).

    \"\"

    To activate the new editor, open the transaction SE38 and in the menu ‘Utilities > Settings’, check the option ‘Front-End Editor (New)’.

    Useful features of the SAP ABAP editor:

    1. Code Completion

    The code completion feature will suggest common keywords and recently used strings in the program. It can also suggest non-keywords (like custom variables and constants) used in the program.

    Follow the following steps to activate this feature:

    Step 1:

    Open a program in SE38 and on the code screen, click on the small icon (highlighted in the screenshot below) at the bottom right of the screen.

    \"\"

    Step 2:

    On the tab ‘Code Completion’, please change the editor options as shown on the screenshot below.

    \"\"

    Click on ‘Save’, once done.

    Once done, we will notice that when writing code in the editor, SAP will suggest different keywords and non-keywords: For example:

    \"image005\"

    \"image004\"

     

    Note: When SAP suggests a keyword or non-keyword, just press the button ‘TAB’, the editor will complete it automatically.

    For example, when the suggest word appears when writing an IF statement, pressing the button ‘TAB’ will automatically complete the syntax.

    2. Editor Splitter

    The editor splitter is a nice feature which allows us to split the ABAP editor into two sections. This is useful when we want to refer to a piece of code which is at a particular point in a program.

    For example, after splitting the editor into two sections, the first sections can be used to display declarations for reference purposes while in the second section of the editor we can proceed with coding.

    To use the editor, please follow the steps below:

    Step 1:

    On the right top corner of the editor, drag the small button (highlighted on the screenshot below) downwards.

    \"\"

    Once the button is drop, the editor will be split into two sections.

    Step 2:

    In the editor sections, we can scroll the code independently.

    \"7-6-2015

     

    3. Code Selection in Block

    A quick way to select a block of code is by pressing on the button ‘ALT’ and then select the appropriate code with the mouse. This can be useful when selecting a block of elements from a type.

    To select a block of code, just click on press on the button ‘ALT’ and select the appropriate code with the mouse.

    Example of code selection:

    \"\"

    \"\"

  • Unprotect A Variant Using RSVARENT

    When creating variant for a particular program, we can protect it by checking the checkbox ‘Protect Variant’ (please refer to the below screenshot).

    \"\"

    Variants are protected to avoid unauthorized users from modifying it.

    Unprotected a variant:

    Please follow the below steps to unprotect a variant which has been protected:

    Step 1:

    In transaction SE38, execute the program ‘RSVARENT’, on the selection screen, enter the program/report name and the name of the variant to unprotect.

    \"\"

    Step 2:

    Execute the program to unprotect the variant (or cancel the protection on the variant).

    The following message will appear on the variant has been unprotected:

  • SAP ABAP Demo Programs (with Source Code)

    Please find below a list of ABAP demo programs provided by SAP which can be used for reference purposes:

    ABAPDOCU transaction : ABAP Documentation and Examples

    LIBS transaction : Collection of Ideas for Table and List Design

    BIBS transaction : Style guide

    DWDM transaction : Demo Examples in ABAP Objects (control framework). The demo programs are also stored in SDW4 package

    Flight Data Application : Demo Example for Integration Technologies: an application which demonstrates many technologies for example BAPI, BOR, ALV, Smart Forms, etc…

    SLIS package : ALV demo programs (mainly BCALV_TEST*)

    ADBC_DEMO program : Demo of ABAP database Connectivity (to connect to another database)

    SE83 : SAP Reuse Library

    We will try to keep this list updated.

  • Event Flow In An ABAP Report Program

    Below are the events (in order) which are trigger in an ABAP report program:

    • Load-of-Program
    • Initialization
    • At Selection-Screen
    • At Selection-Screen on <field(mention the field name)>
    • At Selection-Screen on block
    • At Selection-Screen output
    • start-of-selection
    • top-of-page
    • end-of-selection.
    • end-of-page.
    • At Pf<nn>
    • At Line-Selection
    • At User-Command
    • Top-of-Page during line-selection

    Hope this helps.

  • How To Automatically Execute A Batch Session

    In this tutorial, we will explain how to automatically execute a batch session via code. It will helpful in scenario where we don\’t want to manually execute batch session from transaction SM35.

     

    Step 1: Create a new job:

    * The function module \"JOB_OPEN\" will create the job.
      CALL FUNCTION \'JOB_OPEN\'
        EXPORTING
          jobname          = lv_job_name      \"Job name
        IMPORTING
          jobcount         = lv_job_number    \"Internally generated job number
        EXCEPTIONS
          cant_create_job  = 1
          invalid_job_data = 2
          jobname_missing  = 3
          OTHERS           = 4.

     

    Step 2: Automatically execute the job created in the step above:

    The code logic will execute the program \’RSBDCSUB\’ which will automatically execute the specified batch session. Additionally, the submit statement will execute via a job which will be useful to retrieve the status of the batch session after it has been executed. The job will also us to know if the batch session has been executed successfully or not.

    SUBMIT rsbdcsub
    WITH mappe     EQ \'ZBATCHSESSION\'   \" Name of the batch session.
    WITH von       EQ sy-datum          \" Current Date (Created To).
    WITH bis       EQ sy-datum          \" Current Date (Created From).
    WITH z_verarb  EQ \'X\'               \" To Process.
    WITH fehler    EQ space             \" Execute batch session in error.
    WITH batchsys  EQ space             \" Target Host.
    WITH logall    EQ space             \" Extended log.
    TO SAP-SPOOL
    SPOOL PARAMETERS   gst_print_params \" Spool Parameters.
    WITHOUT SPOOL DYNPRO
    VIA JOB          lv_job_name        \" Job Name.
    NUMBER           lv_job_number      \" Job Number.
    AND RETURN.

    Please note:
    The spool parameters mentioned above (in structure \’GST_PRINT_PARAMS) can be filled using the function module \’GET_PRINT_PARAMETERS\’. Please refer to the following code logic:

    CALL FUNCTION \'GET_PRINT_PARAMETERS\'
        EXPORTING
          destination            = \'LOCL\'              \" Printer Destination
          layout                 = \'X_65_132\'          \" Printing Layout
          list_text              = \'Batch Input Test\'  \" Text
          mode                   = \'BATCH\'             \" Mode
          no_dialog              = \'X\'                 \" Without Dialog
          report                 = \'RFBIBL00\'          \" Report Name
          user                   = sy-uname            \" Username
        IMPORTING
          out_parameters         = gst_print_params    \" Spool Parameters
        EXCEPTIONS
          archive_info_not_found = 1
          invalid_print_params   = 2
          invalid_archive_params = 3
          OTHERS                 = 4.
    
    Declaration Information:
    The type of spool parameters structure \"GST_PRINT_PARAMS\" is \"PRI_PARAMS\".

     

    Step 3: Close the job:

    We will have to close the job created in step 1 using the function module \’JOB_CLOSE\’.

    * The function module JOB_OPEN will close a job.
      CALL FUNCTION \'JOB_CLOSE\'
        EXPORTING
          jobcount             = lv_job_number          \" Job Number (from step 1)
          jobname              = lv_job_name            \" Job Name
          strtimmed            = \'X\'                    \" Immeditate Execution
        EXCEPTIONS
          cant_start_immediate = 1
          invalid_startdate    = 2
          jobname_missing      = 3
          job_close_failed     = 4
          job_nosteps          = 5
          job_notex            = 6
          lock_failed          = 7
          OTHERS               = 8.

     

    Step 4: Check the state of the job:

    To check the state of the job executed above, we will use the function module \’BP_JOB_CHECKSTATE\’.

    * This function module will return the state/status of the job.
      CALL FUNCTION \'BP_JOB_CHECKSTATE\'
        EXPORTING
          dialog                       = \'N\'              \" Dialog
          jobcount                     = lv_job_number    \" Job Number
          jobname                      = lv_job_name      \" Job Name
        IMPORTING
          status_according_to_db       = lv_job_status_db \" Job Status According to DB
          actual_status                = lv_job_status    \" Job Status
        EXCEPTIONS
          checking_of_job_has_failed   = 1
          correcting_job_status_failed = 2
          invalid_dialog_type          = 3
          job_does_not_exist           = 4
          no_check_privilege_given     = 5
          ready_switch_too_dangerous   = 6
          OTHERS                       = 7.
    
    Declaration Information:
    lv_job_number     TYPE tbtcjob-jobcount
    lv_job_name       TYPE tbtcjob-jobname
    lv_job_status_db  TYPE tbtcjob-status             
    lv_job_status     TYPE tbtcjob-status

    The status of the job executed will be available in the variable \’LV_JOB_STATUS\’.

    *If the job status equals to \'F\' (Finished) or \'A\' (Aborted) means that the job execution has finished.
    
    IF lv_job_status EQ \'F\'  \" Job Finished
    OR lv_job_status EQ \'A\'.  \" Job Aborted
    
    *Do something.
    
    ENDIF.

     

    Step 5: Retrieve the state of the batch session:
    In case you want to retrieve the status of the batch session, you will have to make a retrieval in table \’APQI\’, field \’QSTATE\’;

    SELECT QID		\"Queue Identification
           QSTATE 	        \"Queue Status
    FROM table APQI
    INTO table GT_APQI
    WHERE DATATYPE	equals \'BDC\'
    AND GROUPID	equals \'ZBATCHSESSION\'    \"Session Name
    AND PROGID	equals \'RFBIBL01\'
    AND USERID	equals SY-UNAME
    AND CREDATE	equals SY-DATUM.
    
    If sy-subrc EQ 0.
    
        * The status of the batch session will be available in the field \'APQI-QSTATE\'
        * If \'APQI-QSTATE\' equals to: 
        * \'F\' means it has \'Finished\'
        * \'A\' means it has \'Aborted\'
        * \'E\' means it was in \'Error\'
    
    End If.

    Voila, hope it helps.

  • Finding SD User Exits Using SPRO

    Finding SD User Exits Using SPRO

    We can quickly find all user exits available in SD using transaction SPRO.

    Step 1:

    Go to transaction SPRO and double click on \’SAP Reference IMG\’.

    \"1.

     

    Step 2:

    On the next screen, navigate to \”Sales and Distribution > System Modifications > User Exits\” to view all user exits (highlighted in the screenshot below) available in SD.

    \"2.

     

    Step 3:

    To view all user exits available for \”User Exits for Partner Determination\”, please view the documentation (by clicking on the button shown in the screenshot below). The documentation will provide us all user exits available.

    \"3.

    For example, when viewing the documentation of \”User Exits for Partner Determination\”, we can noticed that the following user exits are available:

    • EXIT_SAPLV09A_001
    • EXIT_SAPLV09A_002
    • EXIT_SAPLV09A_003
    • EXIT_SAPLV09A_004