Example
1 Let's assume that we have a
text file with material numbers. We want to produce a
second file containing the material number together with
the division, material group and authorization group for
each material.
//
GuiXT script:
Pushbutton
(toolbar) "Generate file" "/NMM03" process="CreateMaterialFile.txt"
The
InputScript CreateMaterialFile.txt looks like this:
// Create
material file
Parameter mat_file1 "C:\GuiXT\Input.txt"
Parameter mat_file2 "C:\GuiXT\Output.txt"
// Start
Screen SAPLMGMM.0060
OpenFile "&U[mat_file1]"
OpenFile "&U[mat_file2]" -Output
label Read_File
ReadFile "&U[mat_file1]" mat_matnr
if not Q[ok]
CloseFile "&U[mat_file1]"
CloseFile "&U[mat_file2]"
Return "Material file generated"
"&U[mat_file2]"
endif
Set F[Material] "&V[mat_matnr]"
Enter
// Select view
Screen SAPLMGMM.0070
Set C[Basic Data 1] "X"
Enter
// Basic data 1
Screen SAPLMGMM.4000
Set V[mat_division] "&F[Division]"
Set V[mat_matgroup] "&F[Material group]"
Set V[mat_autgroup] "&F[Authorization
group]"
AppendFile "&U[mat_file2]" mat_matnr
mat_division mat_matgroup mat_autgroup
Enter "/NMM03"
// MM03 Start again, goto beginning of script
Screen SAPLMGMM.0060
goto Read_File
Example 2Let's assume that we have a
text file with data representing GL documents. We want to post
these documents in SAP ERP using transaction FB01. If an error message
occurs during one of these SAP ERP transactions, we put the error message
into a log file, together with some data .
//
GuiXT script MENUS00.F0040.txt:
Pushbutton
(toolbar) "GL upload" "/NFB01"
"process=FB01_GL.txt"
The
InputScript FB01_GL.txt appears as follows:
// File
names
Parameter FB01FILE "C:\GL Test\FB01_data.txt"
Parameter FB01ERR "C:\GL Test\FB01_err.txt"
// Start file
processing
OpenFile "&U[FB01FILE]" delimiter=";"
OpenFile "&U[FB01ERR]" "-Output"
Set V[FB01_errors] 0
Set V[FB01_records] 0
Screen SAPMF05A.0100
label start
// Error in previous
record?
if Q[ok]
// Increase
error count
Set V[FB01_errors] &V[FB01_errors] + 1
// Write error
log
AppendFile "&U[FB01ERR]" s_date s_text s_pstky1 s_account1
s_amount1 s_pstky2 s_account2 s_amount2 _lasterror
// Reset error
indicator (!). Automatic reset only at start of InputScript processing
Set V[_lasterror]
endif
ReadFile "&U[FB01FILE]" -stripQuotationMarks s_date s_text s_pstky1
s_account1 s_amount1 s_pstky2 s_account2 s_amount2
// Another record
to process?
if Q[ok]
// Increase
record count
Set V[FB01_records] &V[FB01_records] + 1
Set F[Document date] "&V[s_date]"
Set F[Doc.header text] "&V[s_text]"
Set F[Company Code] "0001"
Set F[Type] "SA"
Set F[Currency/rate] "USD"
Set F[Pstky] "&V[s_bschl1]"
Set F[Account] "&V[s_account]"
Enter onError="/NFB01"
else
// Processing
complete, close files
CloseFile "&U[FB01FILE]"
CloseFile "&U[FB01ERR]"
if V[FB01_errors=0]
Return "Processing done, no errors, &V[FB01_records]
documents in total"
else
//
Display error log
View "&U[FB01ERR]"
Return "Processing done: &V[FB01_errors]
errors, &V[FB01_records] documents in total"
endif
endif
Screen SAPMF05A.0300
Set F[Amount] "&V[s_amount1]"
Set F[PstKy] "&V[s_pstky2]"
Set F[GL/account] "&V[s_account2]"
Enter onError="/NFB01"
Screen SAPMF05A.0300
Set F[Amount] "&V[s_amount2]"
Enter "/11" onError="/NFB01"
Screen SAPMF05A.0100
goto start
The input file FB01_data.txt
could appear as follows:
01122000;"GL
text1";40;113100;100;50;113101;100
02122000;"GL text2";40;113100;200;50;113777;200
15122000;"GL text3";40;113100;300;50;113101;300
32122000;"GL text4";40;113100;400;50;113101;400
14122000;"GL text5";40;113100;500;50;113101;500
01122000;"GL text6";40;113100;100;50;13101M;100
02122000;"GL text7";40;113100;200;50;113777;200
15122000;"GL text8";40;113100;300;50;113101;300
32122000;"GL text9";40;113100;400;50;113101;400
|