> For the complete documentation index, see [llms.txt](https://docs.editran.onesait.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.editran.onesait.com/documentacion-editran/documentacion-editran-editran-sepa-v3-open-en/modo-de-uso/integracion.md).

# Integration

To incorporate the use of Editran/SEPA into that of Editran, the user processes before issuance and after issuance or after reception of Editran/G will be used. Specifically, the profile administrator must indicate in those Editran/G parameters some scripts that perform that call. In the scripts subfolder under SEPA, and within each operating system, you can consult the various examples included with the installation, which include both the call to the converter itself and the main tasks to be carried out before and after it.

The scripts `startSeparador`, `stopSeparador` should only be used if the XML Separator functionality is required (see section [9 SEPARATOR flat files and XML](#9-separador-ficheros-planos-y-xml)). The scripts for your Operating System must be copied to the SEPA root folder.

Specifically, these scripts will make a Java call, such as those seen in section [4.2 Client process](#42-proceso-cliente), for each file found either in the issuance directory (in the case of before issuance) or in the reception directory (if used in the after reception process).

If the transformation of one of the files ends with an error, the batch to be used would delete the converted files (preserving the originals) and would remain interrupted for the entire submission.

## 4.4.1 Windows

The Before Issuance script that causes Editran/SEPA to run in an issuance submission is called `PRVEMISEPA.bat`.

To be able to use that batch, you must define `.\SEPA\PRVEMISEPA.bat` in the "Before issuance" section of the "Application" option of the Editran/G submission that will send SEPA files.

> **IMPORTANT:** It is necessary to define in the issuance directory with the metacharacter `*` at the end of the path, and also relative paths cannot be used (`..\`, `.\`, etc.)

For example, if the files are in the directory `c:\Ficheros\SEPA\`in the Files section of Editran/G you must define: `c:\Ficheros\SEPA\*`

A common name can also be defined for the files to be issued and then the asterisk can be defined at the end (`c:\Ficheros\SEPA\file*`)

The script has the following steps:

* It records in the Editran/G output file (`editrang.out`) the general information about the transmission result:

```bat
echo ################################################################################
echo PRE-ISSUANCE USER SCRIPT: %0.
timestamp

if not exist "%FENTORNO%" (
    echo Error, the path %FENTORNO% does not exist
    exit -1
)
call %FENTORNO% getParametros "PRV" %*

echo SUBMISSION : %SENTIDO%-%SESION% (%LOCAL%-%REMOTO%-%APLICACION%)
echo RESULT : %RESULTADO%
echo ################################################################################
```

Where SESION is the submission name, SENTIDO is the direction of transmission (E (Issuance) or R (Reception)), RESULTADO is the result of the transmission, LOCAL is the local code, REMOTO the remote code and APLICACIÓN the application of the submission.

* The necessary variables are defined, it is checked that the issuance directory defined in Editran/G has the metacharacter `*` mandatory and Editran/SEPA is executed for each file found in the issuance directory defined in the Editran/G Files section.

If the original file has the extension `.xml` Editran/SEPA will convert it to a flat file; if it does not have an extension `.xml` it will convert it to an XML-formatted file, since by default it uses the command's one-parameter usage mode, as explained in [4.2 Client process](#42-proceso-cliente).

```bat
if not exist "%DIR_SEPA%" (
    echo Error, the path %DIR_SEPA% does not exist
    exit -1
)
set CLASSPATH=
set DIR_ORIG=orig
set ARCHIVOS_ORIG=%LOCAL%-%REMOTO%-%APLICACION%-%SENTIDO%.orig
set FLISTA=%LOCAL%-%REMOTO%-%APLICACION%-%SENTIDO%.list

goto Inicio

:Inicio
IF NOT "%RESULTADO%"=="0000" goto Fin

FOR %%f in ("%DIR_SEPA:"=%\\lib\\*.jar") do CALL :Entorno "%%f"
FOR %%f in ("%DIR_SEPA:"=%\\lib\\Win\\*.jar") do CALL :Entorno "%%f"
GOTO Start

:Entorno
set CLASSPATH=%~1;%CLASSPATH%
GOTO:EOF
:Start
rem The path of the files to be issued, previously defined with the * mask, is extracted in the
rem EDItran/G submission
cfgupt -r -i%SESION% | find "NOMBRE FICHERO" > %FLISTA%

FOR /F "tokens=2 delims='='" %%p IN (%FLISTA%) DO call :Check "%%p"
goto Correcto

:Check
set DIR_FILES=%~1
IF "%DIR_FILES:~-1%" == " " (
 set DIR_FILES="%DIR_FILES:~0,-1%"
)
set DIR_FILES=%DIR_FILES:"=%
IF "%DIR_FILES:~0, 1%" == " " (
 set DIR_FILES="%DIR_FILES:~1%"
)
set DIR_FILES=%DIR_FILES:"=%
set AST=%DIR_FILES:~-1%

IF %AST% == * (
 GOTO Pathctl
) ELSE (
 The path of the Editran/G issuance files must end with the * mask.
 GOTO badpath
)

:Pathctl
FOR %%f IN ("%DIR_FILES%") DO call :Sepa "%%f"
goto:EOF

:Sepa
rem The name of the files to be converted is saved in an auxiliary file called orig.
echo %~1>>"%ARCHIVOS_ORIG%"
set DIRAUX= %cd%
cd %DIR_SEPA%

rem Uncomment the lower lines if the flat-format input files are not of
rem fixed length
rem set FILE=%~1
rem IF NOT %FILE:~-4% == .xml IF NOT %FILE:~-4% == .XML (
rem call "%DIR_SEPA%/scripts/Win/utils/RellenaLineas.bat" %1 600
rem IF EXIST "%FILE%.old" (
rem   del "%FILE%.old"
rem )
rem )
rem set FILE=

rem EDITRAN/SEPA is executed for each file to be converted and sent.
%JAVASEPA% -cp "%CLASSPATH%" %EDITRAN_XMLMAIN% "%~1" > NUL
IF NOT %ERRORLEVEL% == 0 (
 IF NOT %ERRORLEVEL% == 36 (
  echo Error converting file %1
  echo Error=%ERRORLEVEL%
  goto Error
 ) ELSE (
  echo SEPA conversion of file %~1 completed with warnings.
 )
)
cd %DIRAUX%
goto:EOF
```

* If none of the conversions performed on the files to be issued ends with an error result, the original files are moved to a historical subdirectory called `orig`.

```bat
:Correcto
IF NOT EXIST %ARCHIVOS_ORIG% (
 echo There are no files to convert
 GOTO Fin
)

findstr /I /M ".xml" "%ARCHIVOS_ORIG%" > NUL

IF %errorlevel%==0 (
echo SEPA XML to flat conversion successful.
) ELSE (
echo SEPA flat to XML conversion successful.
)
for /F "delims=';'" %%p IN ("%ARCHIVOS_ORIG%") do call :Move "%%p"
goto Fin
```

* If, on the contrary, one or more of the conversions performed from the files to be issued ends with an error, the files that were successfully converted are deleted (if any), and the submission is stopped, leaving the original output files as they were for later review.

```bat
:Error
rem If there has been an error, it is reported in editrang.out, all converted files are deleted
rem and the batch is stopped.
cd %DIRAUX%
echo SEPA conversion incorrect.
for /F "delims=';'" %%p IN (%ARCHIVOS_ORIG%) do call :Delete "%%p"
IF EXIST %ARCHIVOS_ORIG% del %ARCHIVOS_ORIG%
IF EXIST %SESION%.emision del %SESION%.emision
exit -1
```

The After Issuance script that moves the converted and successfully sent files is called `PSTEMISEPA.bat`.

To be able to use that batch, you must define `.\SEPA\PSTEMISEPA.bat` in the "After issuance" section of the "Application" option of the Editran/G submission that will send SEPA files.

The script has the following steps:

* It records in the Editran/G output file (`editrang.out`) the general information about the transmission result:

```bat
echo ################################################################################
echo AFTER-ISSUANCE USER SCRIPT: %0.
timestamp

if not exist "%FENTORNO%" (
echo Error, the path %FENTORNO% does not exist
exit -1
)
call %FENTORNO% getParametros "PST" %*

echo SUBMISSION : %SENTIDO%-%SESION% (%LOCAL%-%REMOTO%-%APLICACION%)
echo FILES     : %LFICHEROS%
echo RESULT : %RESULTADO%
echo ################################################################################
goto Inicio
```

Where SESION is the submission name, SENTIDO is the direction of transmission (E (Issuance) or R (Reception)), RESULTADO is the result of the transmission, LOCAL is the local code, REMOTO the remote code and APLICACIÓN the application of the submission.

* The list of files successfully sent is obtained from the file `.ficheros` from the Editran buffer directory and moved to a directory called "conv".

```bat
:Inicio
IF NOT "%RESULTADO%"=="0000" goto Fin

set ARCHIVOS_CONV=conv
set LFICHEROS=%LFICHEROS:/=\\%
set LFICHEROS=%LFICHEROS:\\=\%
set FICH_TRATANDO=""
set FICH_ANTERIOR=""

setlocal enabledelayedexpansion
for /F "tokens=1 usebackq delims=," %%p in (%LFICHEROS%) do (
if "%%p" NEQ !FICH_ANTERIOR! (
set FICH_ANTERIOR="%%p"
call :Move "%%p"
)
)
endlocal

goto Fin

:Move
for %%i in (%1) do set DIRECTORY=%%~dpi
set DIRECTORY=%DIRECTORY%%ARCHIVOS_CONV%
IF NOT EXIST "%DIRECTORY%" mkdir "%DIRECTORY%"
MOVE /Y "%~1" "%DIRECTORY%" > NUL
goto:EOF

:Fin
set ARCHIVOS_CONV=
set DIRECTORY=
set DIR_SEPA=
set VARIOS_LOGICOS=
set CONLOG4J=
set EDITRAN_XMLMAIN=
set SESION=
set SENTIDO=
set LOCAL=
set REMOTO=
set APLICACION=
set RESULTADO=
set LFICHEROS=
exit 0
```

The After Reception script that causes Editran/SEPA to run in a reception submission is called `PSTRECSEPA.bat`.

To be able to use that batch, you must define `.\SEPA\PSTRECSEPA.bat` in the "After reception" section of the "Application" option of the Editran/G submission that will send SEPA files.

> **IMPORTANT:** It is recommended to define the reception directory with the option `%o` to receive the files with the name under which the remote sends them.
>
> If, when receiving files, the desired conversion is from XML to Flat, it is necessary to define in the reception directory that the file to be downloaded contains extension `.xml`, since the PSTRECSEPA batch by default uses the command's one-parameter usage mode, as explained in [4.2 Client process](#42-proceso-cliente). With the option `%o` the files are received with the name under which the remote sends them, if it sends them with the extension `.xml` no configuration will be necessary; on the contrary, if the remote does not include the extension, the parameter would have to be defined `%o` with the extension `.xml` at the end.

Other variables can also be used, see the Editran/G manual.

For example, to receive the files in the directory `c:\Ficheros\recepcion\`in the Files section of Editran/G you must define: `c:\Ficheros\recepcion\%o`. If the conversion is from XML to Flat and the remote does not include the extension when issuing, the path `c:\Ficheros\recepcion\%o.xml`

The batch has the following steps:

* It records in the Editran/G output file (`editrang.out`) the general information about the transmission result:

```bat
echo ################################################################################
echo AFTER-RECEPTION USER SCRIPT: %0.
timestamp

if not exist "%FENTORNO%" (
echo Error, the path %FENTORNO% does not exist
exit -1
)

call %FENTORNO% getParametros "PST" %*

echo SUBMISSION : %SENTIDO%-%SESION% (%LOCAL%-%REMOTO%-%APLICACION%)
echo FILES     : %LFICHEROS%
echo RESULT : %RESULTADO%
echo ################################################################################
```

Where SESION is the submission name, SENTIDO is the direction of transmission (E (Issuance) or R (Reception)), RESULTADO is the result of the transmission, LOCAL is the local code, REMOTO the remote code and APLICACIÓN the application of the submission.

The necessary variables are defined and Editran/SEPA is executed for each file received. If the original file has the extension `.xml` Editran/SEPA will convert it to a flat file; if it does not have an extension `.xml` it will convert it to an XML-formatted file.

```bat
if not exist "%DIR_SEPA%" (
echo Error, the path %DIR_SEPA% does not exist
exit -1
)
set CLASSPATH=
set DIR_ORIG=orig
set ARCHIVOS_ORIG=%LOCAL%-%REMOTO%-%APLICACION%-%SENTIDO%.orig

goto Inicio

:Inicio
IF NOT "%RESULTADO%"=="0000" goto Fin

set LFICHEROS=%LFICHEROS:/=\\%
set LFICHEROS=%LFICHEROS:\\=\%
set FICH_TRATANDO=""
set FICH_ANTERIOR=""
set INI_MSG=""

FOR %%f in ("%DIR_SEPA:"=%\\lib\\*.jar") do CALL :Entorno "%%f"
FOR %%f in ("%DIR_SEPA:"=%\\lib\\Win\\*.jar") do CALL :Entorno "%%f"
GOTO Start

:Entorno
set CLASSPATH=%~1;%CLASSPATH%
GOTO:EOF

:Start
setlocal enabledelayedexpansion
for /F "tokens=1 usebackq delims=," %%p in (%LFICHEROS%) do (
if "%%p" NEQ !FICH_ANTERIOR! (
set FICH_TRATANDO="%%p"
rem Depending on the extension, the beginning of the output message is one or the other
findstr /I /M ".xml" !FICH_TRATANDO! > NUL
if !errorlevel!==0 (
set INI_MSG=SEPA XML to flat conversion of file !FICH_TRATANDO!
) else (
set INI_MSG=SEPA flat to XML conversion of file !FICH_TRATANDO!
)

call :Sepa !FICH_TRATANDO!
set FICH_ANTERIOR=!FICH_TRATANDO!
)
)
endlocal

goto Correcto

:Sepa
echo %~1>>%ARCHIVOS_ORIG%
set DIRAUX= "%cd%"
cd "%DIR_SEPA%"
%JAVASEPA% -cp "%CLASSPATH%" %EDITRAN_XMLMAIN% "%~1" > NUL
IF NOT %ERRORLEVEL% == 0 (
IF %ERRORLEVEL% == 36 (
echo %INI_MSG% completed with warnings.
) ELSE (
echo %INI_MSG% completed with error.
echo Error=%ERRORLEVEL%
goto Error
)
) ELSE (
echo !INI_MSG! successful.
)
cd %DIRAUX%

rem Uncomment the lower lines if you want, for flat output-format files,
rem to write a line break at the end of each record
rem set NL=%~1
rem IF %NL:~-4% == .xml nl -600 -in -od "%NL:.xml=%"
rem IF EXIST "%NL:.xml=%.old" del "%NL:.xml=%.old"
rem IF %NL:~-4% == .XML nl -600 -in -od "%NL:.XML=%"
rem IF EXIST "%NL:.XML=%.old" del "%NL:.XML=%.old"

goto:EOF
```

* If none of the conversions performed on the files to be received ends with an error result, the original files will be moved to a historical subdirectory called `orig`.

```bat
:Correcto
findstr /I /M ".xml" %ARCHIVOS_ORIG% > NUL

IF %errorlevel%==0 (
echo SEPA XML to flat conversion successful.
) ELSE (
echo SEPA flat to XML conversion successful.
)
for /F "delims=';'" %%p IN (%ARCHIVOS_ORIG%) do call :Move "%%p"
goto Fin
```

* If any of the conversions performed from the files to be received ends with an error, the script will indicate it in its result. In this situation, by default the successfully converted files will be deleted, if any, leaving the original reception files as they were for later review.

```bat
:Error
echo SEPA conversion incorrect.
cd %DIRAUX%
for /F "delims=';'" %%p IN ('type "%ARCHIVOS_ORIG:"=%"') do call :Delete "%%p"
IF EXIST "%ARCHIVOS_ORIG:"=%" del "%ARCHIVOS_ORIG:"=%"
exit -1

:Delete
set BORRAR=%~1
IF %BORRAR:~-4% == .xml IF EXIST "%BORRAR:.xml=%" del "%BORRAR:.xml=%"
IF %BORRAR:~-4% == .XML IF EXIST "%BORRAR:.XML=%" del "%BORRAR:.XML=%"
IF NOT %BORRAR:~-4% == .xml IF NOT %BORRAR:~-4% == .XML IF EXIST "%BORRAR%.xml" del
"%BORRAR%.xml"
goto:EOF
```

## 4.4.2 UNIX

The Before Issuance script that causes Editran/SEPA to run in an issuance submission is called `PRVEMISEPA.sh`.

To be able to use that script, you must define `./SEPA/PRVEMISEPA.sh` in the "Before issuance" section of the "Application" option of the Editran/G submission that will send SEPA files.

> **IMPORTANT:** It is necessary to define in the issuance directory with the metacharacter `*` at the end of the path, and also relative paths cannot be used (`../`, `./`, etc.)

For example, if the files are in the directory `/opt/ficheros/SEPA/`in the Files section of Editran/G you must define: `/opt/ficheros/SEPA/*`.

A common name can also be defined for the files to be issued and then the asterisk can be defined at the end (`/opt/ficheros/SEPA/file*`)

The script has the following steps:

* It records in the Editran/G output file (`editrang.out`) the general information about the transmission result:

```sh
# -----------------------------------------------------------
#                         Functions
# -----------------------------------------------------------
function escribeCabecera()
{   echo "################################################################################"
    echo PRE-ISSUANCE USER SCRIPT: $0.
    echo "`date`"
}

function escribeParametros()
{   echo "SUBMISSION : $SENTIDO-$SESION ($LOCAL-$REMOTO-$APLICACION)"
    echo "RETURN      : $RETORNO"
    echo "################################################################################"
}

function borrarFichTrabajo()
{
    [ -f "$ARCHIVOS_ORIG" ] && rm "$ARCHIVOS_ORIG"
    [ -f "$FLISTA" ] && rm "$FLISTA"
}

function borrarFichConvertidos()
{ [ ! -f "${ARCHIVOS_ORIG}" ] && return

    while read fichConv
    do
        #Delete converted files
        case "${fichConv}" in
            *.xml|*.XML)
                fsinExtension=${fichConv%????}
                if [ -f "${fsinExtension}" ]; then
                     rm "${fsinExtension}"
                fi;;
            *)
                if [ -f "${fichConv}".xml ]; then
                     rm "${fichConv}".xml
                fi;;
        esac
    done < "${ARCHIVOS_ORIG}"
}

function moverFichOriginales()
{ [ ! -f "${ARCHIVOS_ORIG}" ] && return

    while read fichOrig
    do
        directory=`dirname "${fichOrig}"`/"${DIR_ORIG}"
        if [ ! -d "${directory}" ]; then
            mkdir -p "${directory}"
        fi
        if [ -f "${fichOrig}" ]; then
            mv "${fichOrig}" "${directory}"
        fi
    done < "${ARCHIVOS_ORIG}"
}

function mensajeResultado()
{
    if [ ! -f "${ARCHIVOS_ORIG}" ]; then
        echo "There are no files to convert"
        exit 0
    fi

     case `head -1 "${ARCHIVOS_ORIG}"` in
         *.xml|*.XML)
             echo "SEPA XML to flat conversion successful."
             ;;
         *)
             echo "SEPA flat to XML conversion successful."
             ;;
     esac
}

# -----------------------------------------------------------
#                         MAIN
# -----------------------------------------------------------
SALIDA=0
CLASSPATH=
DIR_ORIG=orig

# Writes the script header ############################
escribeCabecera

# Validate the environment variables
validaEntorno && echo "Error validaEntorno" && exit 1

# Transform the input parameters into Editran parameters
getParametrosEditran "PRV" "$@"
[ $? -ne 0 ] && echo "Error getParametrosEditran" "PRV" "$@" && exit 1

# Write the Editran parameters ############################
escribeParametros
```

Where SESION is the submission name, SENTIDO is the direction of transmission (E (Issuance) or R (Reception)), RETORNO is the result of the transmission, LOCAL is the local code, REMOTO the remote code and APLICACIÓN the application of the submission.

The necessary variables are defined, it is checked that the issuance directory defined in Editran/G has the metacharacter `*` mandatory and Editran/SEPA is executed for each file found in the issuance directory defined in the Editran/G Files section.

If the original file has the extension `.xml` Editran/SEPA will convert it to a flat file; if it does not have an extension `.xml` it will convert it to an XML-formatted file, since by default it uses the command's one-parameter usage mode, as explained in 4.2 Client process.

If none of the conversions performed on the files to be issued ends with an error result, the original files will be moved to a historical subdirectory called `orig`.

If, on the contrary, any of those conversions ends with an error, the successfully converted files are deleted, if any, and the submission sending is stopped, leaving the original output files as they were for later review.

If the issuance directory defined in Editran/G does not have the metacharacter `*` mandatory the process stops. If there were any converted file, it would be deleted:

```sh
# If RETURN is not 0, exit ##################################
if [ "${RETORNO}" != "0000" ]; then
  exit 0
fi

# Working files #######################################
ARCHIVOS_ORIG=$LOCAL-$REMOTO-$APLICACION-$SENTIDO.orig
FLISTA=$LOCAL-$REMOTO-$APLICACION-$SENTIDO.list
borrarFichTrabajo

# SEPA libraries ############################################
for f in ${DIR_LIB_SEPA}/*.jar; do
  CLASSPATH=${f}:${CLASSPATH}
done

for f in ${DIR_LIB_SEPA_SO}/*.jar; do
  CLASSPATH=${f}:${CLASSPATH}
done

# We obtain the files to convert ########################
# The path of the files to be sent is extracted, previously defined in the presentation of EDItran/G
cfgupt -r -i$SESION | grep "NOMBRE FICHERO" | cut -d"=" -f2 | sed 's/^ *//' > $FLISTA

while read fich
do
    case "${fich}" in
        */"*")
            fbuscar="${fich%??}"
            for fichconvert in "${fbuscar}"/*
            do
                if [ -f "${fichconvert}" ] ; then
                    echo "${fichconvert}" >> $ARCHIVOS_ORIG

                    diraux=${PWD}
                    cd "${DIR_SEPA}"
                    java -Dlog4j.configurationFile="conf/log4j2.properties" -cp ${CLASSPATH} \
$EDITRAN_XMLMAIN "${fichconvert}" 2>&1 > ${LOGOUT}
                    error=$?
                    cd "${diraux}"

                             if [ ${error} -ne 0 ]; then
                                 if [ ${error} -ne 36 ]; then
                                     echo "Error converting the file ${fichconvert}"
                                     echo "Error=${error}"
                                     echo "Incorrect SEPA conversion"

                                      SALIDA=1
                                      break
                                  else
                                    echo "SEPA conversion of file ${fichconvert} with warnings"
                                  fi
                             fi
                    fi
                done;;
           *)
                echo "You must define a * wildcard in the path of the EDITRAN/G sending files."

                SALIDA=1
                break
    esac
done < "$FLISTA"

# Conversion with errors ####################################
if [ $SALIDA -ne 0 ]; then
    echo "Error output"
    borrarFichConvertidos
    borrarFichTrabajo
    exit $SALIDA
fi

# Successful conversion #######################################
mensajeResultado
moverFichOriginales
borrarFichTrabajo

# Finish ##################################################
exit $SALIDA
```

The After Issuance script that moves the converted and successfully sent files is called `PSTEMISEPA.sh`.

To be able to use that script, you must define `./SEPA/PSTEMISEPA.sh` in the "After issuance" section of the "Application" option of the Editran/G submission that will send SEPA files.

The script has the following steps:

* It records in the Editran/G output file (`editrang.out`) the general information about the transmission result:

```sh
# -----------------------------------------------------------
#                         Functions
# -----------------------------------------------------------
function escribeCabecera()
{   echo "################################################################################"
    echo USER SCRIPT AFTER SENDING: $0.
    echo "`date`"
}

function escribeParametros()
{   echo "SUBMISSION : $SENTIDO-$SESION ($LOCAL-$REMOTO-$APLICACION)"
    echo "FILES     : $FLIST"
    echo "RETURN      : $RETORNO"
    echo "################################################################################"
}

# -----------------------------------------------------------
#                         MAIN
# -----------------------------------------------------------
# Writes the script header ############################
escribeCabecera

# Validate environment variables ###########################
validaEntorno && echo "Error validaEntorno" && exit 1

# Transform the input parameters into Editran parameters
getParametrosEditran "PST" "$@"
[ $? -ne 0 ] && echo "Error getParametrosEditran" "PST" "$@" && exit 1

# Write the Editran parameters ############################
escribeParametros
```

Where SESION is the submission name, SENTIDO is the direction of transmission (E (Issuance) or R (Reception)), RETORNO is the result of the transmission, LOCAL is the local code, REMOTO the remote code and APLICACIÓN the application of the submission.

* The list of files successfully sent is obtained from the file `.ficheros` from the Editran buffer directory and moved to a directory called "conv".

```sh
# If RETURN is not 0, exit ##################################
if [ "${RETORNO}" != "0000" ]; then
  exit 0
fi

# Working variables ######################################
DIR_CONV=conv
FICH_ANTERIOR=""

# Move converted files ############################
awk -F',' '{if ($1 != "") print $1}' "${FLIST}" | while read fileconv
do
    if [ -f "${fileconv}" ] && [ "${fileconv}" != "${FICH_ANTERIOR}" ]; then
        FICH_ANTERIOR="${fileconv}"

           directory=`dirname "${fileconv}"`/"${DIR_CONV}"

           if [ ! -d "${directory}" ]; then
               mkdir -p "${directory}"
           fi

           mv "${fileconv}" "${directory}"
    fi
done
```

The After Reception script that causes Editran/SEPA to run in a reception submission is called `PSTRECSEPA.sh`.

To be able to use that script, you must define `./SEPA/PSTRECSEPA.sh` in the "After reception" section of the "Application" option of the Editran/G submission that will send SEPA files.

> **IMPORTANT:** It is recommended to define the reception directory with the option `%o` to receive the files with the name under which the remote sends them.
>
> If, when receiving files, the desired conversion is from XML to Flat, it is necessary to define in the reception directory that the file to be downloaded contains extension `.xml`, since the PSTRECSEPA batch by default uses the command's one-parameter usage mode, as explained in [4.2 Client process](#42-proceso-cliente). With the option `%o` the files are received with the name under which the remote sends them, if it sends them with the extension `.xml` no configuration will be necessary; on the contrary, if the remote does not include the extension, the parameter would have to be defined `%o` with the extension `.xml` at the end.

Other variables can also be used, see the Editran/G manual.

For example, to receive the files in the directory `/opt/ficheros/recepción/`in the Files section of Editran/G you must define: `/opt/ficheros/recepción/%o`. If the conversion is from XML to Flat and the remote does not include the extension when issuing, the path `/opt/ficheros/recepción/%o.xml`.

The script has the following steps:

* It records in the Editran/G output file (`editrang.out`) the general information about the transmission result:

```sh
# -----------------------------------------------------------
#                         Functions
# -----------------------------------------------------------
function escribeCabecera()
{   echo "################################################################################"
    echo USER SCRIPT AFTER RECEIVING: $0.
    echo "`date`"
}

function escribeParametros()
{   echo "SUBMISSION : $SENTIDO-$SESION ($LOCAL-$REMOTO-$APLICACION)"
    echo "FILES     : $FLIST"
    echo "RETURN      : $RETORNO"
    echo "################################################################################"
}

function borrarFichTrabajo()
{
    [ -f "$ARCHIVOS_ORIG" ] && rm "$ARCHIVOS_ORIG"
}

function borrarFichConvertidos()
{ [ ! -f "${ARCHIVOS_ORIG}" ] && return

    while read fichConv
    do
        #Delete converted files
        case "${fichConv}" in
            *.xml|*.XML)
                fsinExtension=${fichConv%????}
                if [ -f "${fsinExtension}" ]; then
                     rm "${fsinExtension}"
                fi;;
                *)
                        if [ -f "${fichConv}".xml ]; then
                             rm "${fichConv}".xml
                        fi;;
        esac
    done < "${ARCHIVOS_ORIG}"
}

function moverFichOriginales()
{ [ ! -f "${ARCHIVOS_ORIG}" ] && return

    while read fichOrig
    do
        directory=`dirname "${fichOrig}"`/"${DIR_ORIG}"
        if [ ! -d "${directory}" ]; then
            mkdir -p "${directory}"
        fi
        if [ -f "${fichOrig}" ]; then
            mv "${fichOrig}" "${directory}"
        fi
    done < "${ARCHIVOS_ORIG}"
}

function mensajeResultado()
{
    if [ ! -f "${ARCHIVOS_ORIG}" ]; then
        echo "There are no files to convert"
        exit 0
    fi

      case `head -1 "${ARCHIVOS_ORIG}"` in
          *.xml|*.XML)
              echo "SEPA XML to flat conversion successful."
              ;;
          *)
              echo "SEPA flat to XML conversion successful."
              ;;
      esac
}

# -----------------------------------------------------------
#                         MAIN
# -----------------------------------------------------------
SALIDA=0
CLASSPATH=
DIR_ORIG=orig

# Writes the script header ############################
escribeCabecera

# Validate environment variables ###########################
validaEntorno && echo "Error validaEntorno" && exit 1

# Transform the input parameters into Editran parameters
getParametrosEditran "PST" "$@"
[ $? -ne 0 ] && echo "Error getParametrosEditran" "PST" "$@" && exit 1

# Write the Editran parameters ############################
escribeParametros
```

Where SESION is the submission name, SENTIDO is the direction of transmission (E (Issuance) or R (Reception)), RETORNO is the result of the transmission, LOCAL is the local code, REMOTO the remote code and APLICACIÓN the application of the submission.

The necessary variables are defined and Editran/SEPA is executed for each file received. If the original file has the extension `.xml` Editran/SEPA will convert it to a flat file; if it does not have an extension `.xml` it will convert it to an XML-formatted file.

If none of the conversions performed on the files to be received ends with an error, the original files will be moved to a historical subdirectory called `orig`.

If, on the contrary, any of those conversions ends with an error, the correctly converted files, if any, will be deleted, and the script will return the corresponding result, leaving the original reception files as they were for later review.

```sh
# If RETURN is not 0, exit ##################################
if [ "${RETORNO}" != "0000" ]; then
  exit 0
fi

# Working files #######################################
ARCHIVOS_ORIG=$LOCAL-$REMOTO-$APLICACION-$SENTIDO.orig
FICH_ANTERIOR=""
borrarFichTrabajo

# SEPA libraries ############################################
for f in ${DIR_LIB_SEPA}/*.jar; do
    CLASSPATH=${f}:${CLASSPATH}
done

for f in ${DIR_LIB_SEPA_SO}/*.jar; do
    CLASSPATH=${f}:${CLASSPATH}
done

# We obtain the files to convert ########################
awk -F',' '{if ($1 != "") print $1}' "${FLIST}" | while read fich
do
    if [ -f "${fich}" ] && [ "${fich}" != "${FICH_ANTERIOR}" ]; then
        FICH_ANTERIOR="${fich}"
        echo "${fich}" >> $ARCHIVOS_ORIG

        diraux=${PWD}
        cd "${DIR_SEPA}"
        java -Dlog4j.configurationFile="conf/log4j2.properties" -cp ${CLASSPATH} $EDITRAN_XMLMAIN \
"${fich}" 2>&1 > ${LOGOUT}
        error=$?
        cd "${diraux}"

           if [ ${error} -ne 0 ]; then
               if [ ${error} -ne 36 ]; then
                   echo "Failed to convert file ${fich}"
                   echo "Error=${error}"
                   echo "Incorrect SEPA conversion"

                    # Exits the read loop, not the script
                    exit 1
                else
                    echo "SEPA conversion of file ${fich} with warnings"
                fi
        fi
    fi
done
SALIDA=$?

# Conversion with errors ####################################
if [ $SALIDA -ne 0 ]; then
    echo "Error output"
    borrarFichConvertidos
    borrarFichTrabajo
    exit $SALIDA
fi

# Successful conversion #######################################
mensajeResultado
moverFichOriginales
borrarFichTrabajo

# Finish ##################################################
exit $SALIDA
```

## 4.4.3 Handling files with Warnings

By default, the scripts included with the installation are programmed so that flat files obtained from a conversion that remain incomplete (the result of the conversion will be a Warning) will be considered by Editran/SEPA as correct and therefore will be sent. This situation occurs when the file to be converted is XML and does not contain optional data according to that format which, however, are mandatory for the flat-file standard to which it is converted.

To modify this behavior and mark those files as invalid, the following change will be made in `PRVEMISEPA` and in `PSTRECSEPA`:

**Windows:**

We modify:

```bat
IF NOT %ERRORLEVEL% == 0 (
 IF NOT %ERRORLEVEL% == 36 (
  echo Error converting file %1
  echo Error=%ERRORLEVEL%
  goto Error
 )
)
```

For:

```bat
IF NOT %ERRORLEVEL% == 0 (
   echo Error converting file %1
   echo Error=%ERRORLEVEL%
   goto Error
)
```

**UNIX:**

We modify:

```sh
if [ ${error} -ne 0 -ne 36 ]; then
 echo "Error converting the file ${fichconvert}"
```

For:

```sh
if [ ${error} -ne 0 ]; then
 echo "Error converting the file ${fichconvert}"
```

## 4.4.4 Use of Onesait Ecosystems · Editran/SEPA in Onesait Ecosystems · Editran sending transmissions

When the SEPA converter is used together with Editran, in addition to implementing the processes before sending and after receiving as described in the previous sections, the Editran/G profile of the sending files must also be configured appropriately. The configuration differs depending on the type of file obtained with the conversion. The procedure to follow in each case is detailed below.

* **XML → flat**: if the initial file is XML, when passing through the SEPA converter a flat-format file is obtained, which is the one that will be sent. Therefore, "Fixed" will be defined in the "File format" field, 600 as record length and no delimiter. The alphabet will be ASCII. ASCII/EBCDIC translation will be necessary if the remote side wants to receive the flat file in EBCDIC format.

![Photo](https://620397458-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYRsCBWELAyzw5mj5JFUW%2Fuploads%2Fgit-blob-e37ea27385ff1e7b42434d9a921ab7b21ad3f96d%2Fimage.avif?alt=media)

Unix configuration example:

![Photo](https://620397458-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYRsCBWELAyzw5mj5JFUW%2Fuploads%2Fgit-blob-60e0fea8a04b8b2b3744071bac82aa2584965362%2Fimage.avif2.avif?alt=media)

* **Flat → XML**: if the initial file is flat, when passing through the SEPA converter an XML file is obtained that must necessarily be encoded in UTF-8. So this type of file will be sent in binary format, with alphabet and delimiter "NONE".

Windows configuration example:

![Photo](https://620397458-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYRsCBWELAyzw5mj5JFUW%2Fuploads%2Fgit-blob-98b6b1ea003eb2bafaee1d70ec97252d00c237d6%2Fimage.avif3.avif?alt=media)

Unix configuration example:

![Photo](https://620397458-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYRsCBWELAyzw5mj5JFUW%2Fuploads%2Fgit-blob-f613f5bcf694f31155d22bbb83e7d6d007090186%2Fimage.avif4.avif?alt=media)

It is possible to send files of both types, flat and XML, through the same Editran presentation. To do this, it will be enough to define, from Files in the G Menu, the two types of sending files as described.

In the following Editran Windows example, different folders are used to store the two types of files that will be converted and subsequently sent. All documents found in the "flat" directory will be transformed to XML and sent in binary. For their part, all those in the "XML" directory will be transformed to flat and then sent in fixed format with length 600, without delimiter and in ASCII language.

Windows configuration example:

![Photo](https://620397458-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYRsCBWELAyzw5mj5JFUW%2Fuploads%2Fgit-blob-8b62b58d103595def3c2a57dc8a1fc93148d4917%2Fimage.avif5.avif?alt=media)

Unix configuration example: ![Foto](https://620397458-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYRsCBWELAyzw5mj5JFUW%2Fuploads%2Fgit-blob-d6b28777175e9c03cdddee1b27f5454950763eec%2Fimage.avif6.avif?alt=media)

## 4.4.5 Use of Onesait Ecosystems · Editran/SEPA in Onesait Ecosystems · Editran receiving transmissions

By default, the post-receipt process is configured to receive the flat files in the machine language (ASCII on Windows and Unix) and the XML files in UTF-8. Therefore, if the flat files are not to be received in ASCII, the user must modify this process. To do this, the alphabet with which they are received must be specified in the corresponding arguments of the JAVA call to Editran/SEPA (see section [5 Onesait Ecosystems Configuration · Editran/SEPA](#5-configuración-de-onesait-ecosystems--editransepa)).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.editran.onesait.com/documentacion-editran/documentacion-editran-editran-sepa-v3-open-en/modo-de-uso/integracion.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
