How to check a file exist or not using cl_gui_frontend_services Class

February 28, 2024

Code :
REPORT zvp_file_exist.

DATAlv_file TYPE string.
DATAlv_result TYPE string.

lv_file 'C:\Users\CODETHETA\Desktop\demo.txt'.

CALL METHOD cl_gui_frontend_services=>file_exist
  EXPORTING
    file                 lv_file
  RECEIVING
    result               lv_result
  EXCEPTIONS
    cntl_error           1
    error_no_gui         2
    wrong_parameter      3
    not_supported_by_gui 4
    OTHERS               5.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

IF lv_result 'X'.
  WRITE'File Exist'.
ELSE.
  WRITE'File Not Exist'.
ENDIF.

IDE Used To Test This Code : ABAP Editor.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us. We will reply you as soon as possible.

How to access one program data to another without EXPORT IMPORT and GET SET in SAP ABAP

February 25, 2024

ZVP_A and ZVP_B there are two programs. ZVP_A program data will be transfer to ZVP_B program using PERFORM display subroutine.

ZVP_A Program Code - 
REPORT zvp_a.

TYPESBEGIN OF ty_mara,
         matnr TYPE mara-matnr,
         mtart TYPE mara-mtart,
         matkl TYPE mara-matkl,
       END OF ty_mara.

DATAit TYPE STANDARD TABLE OF ty_mara.

SELECT matnr
       mtart
       matkl
  FROM mara INTO TABLE it
  UP TO 10 ROWS.

PERFORM display IN PROGRAM zvp_b IF FOUND.

ZVP_B Program Code - 
REPORT zvp_b.

TYPESBEGIN OF ty_mara,
         matnr TYPE mara-matnr,
         mtart TYPE mara-mtart,
         matkl TYPE mara-matkl,
       END OF ty_mara.

DATAwa TYPE ty_mara.

PERFORM display.

FORM display.
  DATAlv_tname TYPE LENGTH 30.
  FIELD-SYMBOLS <lt> TYPE ANY TABLE.
  MOVE '(ZVP_A)IT' TO lv_tname.
  ASSIGN (lv_tnameTO <lt>.

  LOOP AT <lt> INTO wa.
    write:/ wa-matnr,
            wa-mtart,
            wa-matkl.
  ENDLOOP.

ENDFORM.

IDE Used To Test This Code : SAP ABAP Editor.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us. We will reply you as soon as possible.

How to comment in Selection Screen in SAP ABAP

February 13, 2024

Code : 

REPORT ZSELECTION_SCREEN_COMMENT.

PARAMETERS: p_name TYPE char20.

SELECTION-SCREEN ULINE /1(50).
SELECTION-SCREEN COMMENT /1(50) comm1.

INITIALIZATION.
comm1 = 'selection screen comment'.

IDE Used To Test This Code : SAP ABAP Editor.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us. We will reply you as soon as possible.

How to know that ABAP program is running in background or not?

December 26, 2023

We can achieve this by using SY-BATCH system variables.

If an ABAP program running in background then value of sy-batch will be X.

If an ABAP program running in foreground then value of sy-batch will be blank.

So this is how web can differentiate the if an ABAP program running in background or not.

How to transfer internal table data to excel file using SAP_CONVERT_TO_XLS_FORMAT in SAP ABAP

October 24, 2023

In below program I have used SAP_CONVERT_TO_XLS_FORMAT function module to convert internal table data to excel file and save file to user computer.

Code :

DATALV_MATNR TYPE MARA-MATNR.

SELECT-OPTIONSS_MATNR FOR LV_MATNR.

START-OF-SELECTION.
SELECT FROM MARA INTO TABLE @DATA(IT_MARAWHERE matnr IN @S_MATNR.
      IF sy-subrc eq 0.
        CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
          EXPORTING
           I_FIELD_SEPERATOR          '#'
           I_LINE_HEADER              'X'
            i_filename                 =
'C:\Users\CODETHETA\Desktop\xyz.xls'
           I_APPL_KEEP                ' '
          tables
            i_tab_sap_data             IT_MARA
*         CHANGING
*           I_TAB_CONVERTED_DATA       =
         EXCEPTIONS
           CONVERSION_FAILED          1
           OTHERS                     2
                  .
        IF sy-subrc <> 0.
          write:'error'.
        ENDIF.

        IF sy-subrc eq 0.
          write:'created'.
        ENDIF.


      ENDIF.

IDE Used To Test This Code : SAP ABAP Editor.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us. We will reply you as soon as possible.

How to delete a file using CL_GUI_FRONTEND_SERVICES class in SAP ABAP

October 24, 2023

Here I have used CL_GUI_FRONTEND_SERVICES class to copy TXT file content.

In below program demo.txt file must exist in your desktop with some content in it.

Code : 

DATAobj TYPE REF TO cl_gui_frontend_services.
DATAlv_rc TYPE i.

CALL METHOD cl_gui_frontend_services=>file_delete
  EXPORTING
    filename             'C:\Users\CODETHETA\Desktop\demo.txt'
  CHANGING
    rc                   lv_rc
  EXCEPTIONS
    file_delete_failed   1
    cntl_error           2
    error_no_gui         3
    file_not_found       4
    access_denied        5
    unknown_error        6
    not_supported_by_gui 7
    wrong_parameter      8
    OTHERS               9.
IF sy-subrc <> 0.
  WRITE'File Not Deleted'.
ELSE.
  WRITE'File Deleted'.
ENDIF.

IDE Used To Test This Code : SAP ABAP Editor.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us. We will reply you as soon as possible.

How to copy a file using CL_GUI_FRONTEND_SERVICES class in SAP ABAP

October 16, 2023

Here I have used CL_GUI_FRONTEND_SERVICES class to copy TXT file content.

In below program demo.txt file must exist in your desktop with some content in it.

Code :

DATAlv_source TYPE string.
DATAlv_dest TYPE string.

lv_source 'C:\Users\CODETHETA\Desktop\demo.txt'.
lv_dest 'C:\Users\CODETHETA\Desktop\dest.txt'.

CALL METHOD cl_gui_frontend_services=>file_copy
  EXPORTING
    source               lv_source
    destination          lv_dest
    overwrite            SPACE
  EXCEPTIONS
    cntl_error           1
    error_no_gui         2
    wrong_parameter      3
    disk_full            4
    access_denied        5
    file_not_found       6
    destination_exists   7
    unknown_error        8
    path_not_found       9
    disk_write_protect   10
    drive_not_ready      11
    not_supported_by_gui 12
    OTHERS               13.
IF sy-subrc <> 0.
* Implement suitable error handling here
ELSE.
  WRITE'file copied successfully'.
ENDIF.

IDE Used To Test This Code : SAP ABAP Editor.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us. We will reply you as soon as possible.

PRODUCTS

LISTS OF PRODUCTS

SERVICES

SKILLS
SOFTWARE DEVELOPMENT
WEBSITE DEVELOPMENT
WEB HOSTING
BULK SMS SERVICE
SEO SERVICE
ANDROID APPS
QR CODE / BARCODE
HARDWARE SERVICE
OUR WORK AREA