Showing posts with label How-to. Show all posts
Showing posts with label How-to. Show all posts

Jul 2, 2026

IDOC Extension Step by Step in SAP




Ref: https://www.youtube.com/watch?v=aLv6uF2JM1M&t

Jun 30, 2026

How to Move Files between Directories on the Application Server?

SAP developers natively accomplish this using one of three standard methods: standard ABAP dataset commands, OS-level commands via SXPG_COMMAND_EXECUTE, or specialized functions like ARCHIVFILE_SERVER_TO_SERVER. 

Option 1: Native ABAP Statements (Recommended & Safest)
The cleanest, platform-independent approach is to copy the file content data line-by-line using datasets and then delete the original file. This completely eliminates operating system dependencies. 
abap
DATA: lv_line TYPE string.

" 1. Open the original source file
OPEN DATASET p_src_file FOR INPUT IN BINARY MODE.
IF sy-subrc = 0.
  
  " 2. Open the destination target file
  OPEN DATASET p_tgt_file FOR OUTPUT IN BINARY MODE.
  IF sy-subrc = 0.
    
    " 3. Read line by line and transfer data
    DO.
      READ DATASET p_src_file INTO lv_line.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
      TRANSFER lv_line TO p_tgt_file.
    ENDDO.
    
    CLOSE DATASET p_tgt_file.
  ENDIF.
  
  CLOSE DATASET p_src_file.
  
  " 4. Delete the source file once successfully transferred
  IF sy-subrc = 0.
    DELETE DATASET p_src_file.
  ENDIF.
ENDIF.

Option 2: Function Module ARCHIVFILE_SERVER_TO_SERVER
You can utilize the standard function module ARCHIVFILE_SERVER_TO_SERVER to replicate a copy of the file on the server and then pair it with a DELETE DATASET statement. [1, 2]
  • Limitation: The source and target parameter variables have a maximum length of 70 characters. If your filepath or filename structure exceeds this limitation, you must utilize Option 1 instead. [1]
abap
CALL FUNCTION 'ARCHIVFILE_SERVER_TO_SERVER'
  EXPORTING
    sourcepath       = p_src_file
    targetpath       = p_tgt_file
  EXCEPTIONS
    error_file       = 1
    OTHERS           = 2.

IF sy-subrc = 0.
  DELETE DATASET p_src_file. " Removes original file to complete the move action
ENDIF.

Option 3: Function Module SXPG_COMMAND_EXECUTE
If you are moving exceptionally large files, executing an operating system level command (mv for Unix/Linux or move for Windows) is the fastest option since it changes file pointers rather than rewriting raw blocks. 
  1. Create a custom OS command (e.g., ZMV) mapped to your OS type in transaction SM69.
  2. Call the function module programmatically: 
abap
DATA: lv_parameters TYPE btcxpgpar,
      lv_status     TYPE btcxpgstat.

" Concatenate source and target paths as arguments for the terminal command
CONCATENATE p_src_file p_tgt_file INTO lv_parameters SEPARATED BY space.

CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
  EXPORTING
    commandname         = 'ZMV'
    additional_parameters = lv_parameters
  IMPORTING
    status              = lv_status
  EXCEPTIONS
    no_permission       = 1
    command_not_found   = 2
    security_risk       = 3
    OTHERS              = 4.

If you would like to proceed with setting up one of these options, let me know:
  • What is the average size of the files you are moving?
  • Will your typical filepaths exceed 70 characters?
  • Which Operating System (Unix, Linux, Windows) is your SAP application server running on?

May 8, 2026

Mar 26, 2026

Running an ATC Check with Variant for a Z Program

Option 1: From SE38 (Most Direct)

  1. Open SE38, enter your Z program name
  2. Menu: Program → Check → ATC Check
  3. A dialog appears — select your Check Variant
  4. Confirm → results go to the ATC worklist

Option 2: From ATC Cockpit (Correct Flow)

  1. Go to transaction ATC
  2. Click "Schedule Run" (not "Run Check")
  3. In the next screen:
    • Define or select an Object Set containing your Z program
    • Select the Check Variant
  4. Set execution as "Immediately"
  5. Execute → view results under "Worklist"

Option 3: From SATC

  1. Go to SATC
  2. Button: "Create" a new run
  3. Specify:
    • Object Set → add your Z program (PROG / ZMYPROGRAM)
    • Check Variant
  4. Run immediately or schedule in background

Quickest Method

For a single Z program, SE38 → Program → Check → ATC Check is the fastest — it prompts for the variant inline and runs immediately without needing to define object sets.

Would you like help interpreting the results or configuring a specific check variant?

Mar 18, 2026

How to Send Internal Tables to Spool

Codes:

*&---------------------------------------------------------------------*
*& Report ZDIR_ITAB_TO_SPOOL
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zdir_itab_to_spool.

DATABEGIN OF it_t001 OCCURS 0,
        bukrs TYPE t001-bukrs,
        butxt TYPE t001-butxt,
        ort01 TYPE t001-ort01,
        land1 TYPE t001-land1,
      END OF it_t001.

DATAit_data TYPE TABLE OF lvc_s_1022,
      wa_data LIKE LINE OF it_data.

DATA:spoolid TYPE rspoid.
DATA:file_length TYPE  int4.


START-OF-SELECTION.

  SELECT FROM t001 INTO CORRESPONDING FIELDS OF TABLE it_t001.

  LOOP AT it_t001.
    CONCATENATE it_t001-bukrs
                it_t001-butxt
                it_t001-ort01
                it_t001-land1
              INTO wa_data SEPARATED BY space.
    APPEND wa_data TO it_data.
    CLEAR  wa_data.
  ENDLOOP.

  DESCRIBE TABLE it_data.
  file_length sy-tfill * 1022.

  CALL FUNCTION 'SLVC_TABLE_PS_TO_SPOOL'
    EXPORTING
      i_file_length file_length
    IMPORTING
      e_spoolid     spoolid
    TABLES
      it_textdata   it_data.

  IF sy-subrc EQ 0.
    WRITE spoolid.
  ENDIF.


Testing Result: