How to set (unix) permissions when creating a file in SAP ABAP? - unix

you would think this would be obvious, but searching through documentation, SAP forums, Googling, etc., I've been spectacularly unsuccessful. I'm creating a file in ABAP on a solaris filesystem using the following code:
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
the resulting file is owned and grouped according to a pre-defined admin user, which is fine, but the sticky wicket is that the permissions are set to 660/rw-rw----, meaning I can't examine the results. is there a way (possibly using that vaguely defined TYPE addition?) I can specify the resulting permissions on the new file?
thanks!

Go to SM69, create a logical system command, you could call it ZCHMOD.
Map that command to chmod, then call with the proper parameter
(man chmod on the command line is your friend).
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
commandname = 'ZCHMOD'
additional_parameters = l_par
operatingsystem = l_os
TABLES
exec_protocol = it_log
EXCEPTIONS
no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
wrong_asynchronous_parameters = 12
cant_enq_tbtco_entry = 13
jobcount_generation_error = 14
OTHERS = 15.
Obviously, that would be a 2 step process, but it works.

this works in 4.6B:
CONCATENATE 'chmod ugo=rw ' lc_filename
INTO lc_chmod SEPARATED BY space.
CALL 'SYSTEM' ID 'COMMAND' FIELD lc_chmod.
Hope this helps.
Cheers,
Heiko

In RZ10 add parameter install/umask.
Default value is 007, you can change it: 000, 002...
So, the files created will be -rw-rw-rw-, -rw-rw-r--...

Related

How to append / add layers to geopackages in PyQGIS

For a project I am creating different layers which should all be written into one geopackage.
I am using QGIS 3.16.1 and the Python console inside QGIS which runs on Python 3.7
I tried many things but cannot figure out how to do this. This is what I used so far.
vl = QgsVectorLayer("Point", "points1", "memory")
vl2 = QgsVectorLayer("Point", "points2", "memory")
pr = vl.dataProvider()
pr.addAttributes([QgsField("DayID", QVariant.Int), QgsField("distance", QVariant.Double)])
vl.updateFields()
f = QgsFeature()
for x in range(len(tag_temp)):
f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(lon[x],lat[x])))
f.setAttributes([dayID[x], distance[x]])
pr.addFeature(f)
vl.updateExtents()
# I'll do the same for vl2 but with other data
uri ="D:/Documents/QGIS/test.gpkg"
options = QgsVectorFileWriter.SaveVectorOptions()
context = QgsProject.instance().transformContext()
QgsVectorFileWriter.writeAsVectorFormatV2(vl1,uri,context,options)
QgsVectorFileWriter.writeAsVectorFormatV2(vl2,uri,context,options)
Problem is that the in the 'test.gpkg' a layer is created called 'test' and not 'points1' or 'points2'.
And the second QgsVectorFileWriter.writeAsVectorFormatV2() also overwrites the output of the first one instead of appending the layer into the existing geopackage.
I also tried to create single .geopackages and then use 'Package Layers' processing tool (processing.run("native:package") to merge all layers into one geopackage, but then the attributes types are all converted into strings unfortunately.
Any help is much appreciated. Many thanks in advance.
You need to change the SaveVectorOptions, in particular the mode of actionOnExistingFile after creating the gpkg file :
options = QgsVectorFileWriter.SaveVectorOptions()
#options.driverName = "GPKG"
options.layerName = v1.name()
QgsVectorFileWriter.writeAsVectorFormatV2(v1,uri,context,options)
#switch mode to append layer instead of overwriting the file
options.actionOnExistingFile = QgsVectorFileWriter.CreateOrOverwriteLayer
options.layerName = v2.name()
QgsVectorFileWriter.writeAsVectorFormatV2(v2,uri,context,options)
The documentation is here : SaveVectorOptions
I also tried to create single .geopackages and then use 'Package Layers' processing tool (processing.run("native:package") to merge all layers into one geopackage, but then the attributes types are all converted into strings unfortunately.
This is definitively the recommended way, please consider reporting the bug

Having hierarchical groups in ini file for QSettings

I am using QSettings to make changes in my GUI.
Currently I have understood how to use QSetting for basic key=value pairs.
[button]
enable = 1
But I want to have hierarchical groups. Something like below
[user1]
[button1]
enable = 1
[button2]
enable = 0
[user2]
[button1]
enable = 1
[button2]
enable = 0
Is there any way to do this?
Thank You :)
Like #Tab and #vahancho pointed out, the Qt Docs say the following about this:
You can form hierarchical keys using the '/' character as a separator, similar to Unix file paths. For example:
settings.setValue("mainwindow/size", win->size());
settings.setValue("mainwindow/fullScreen", win->isFullScreen());
settings.setValue("outputpanel/visible", panel->isVisible());
While not stated explicitly in the docs, deeper hierarchies (e.g., mainwindow/titleBar/color) are supported. When persisting a QSettings with the format set to QSettings::IniFormat to a *.ini file on disk using sync, the top-level part of each hierarchical key (e.g., mainwindow) is mapped to an Ini Section. Because the ini file format doesn't support nested sections, the rest of the key remains untouched and becomes the key inside the ini section. This can be seen in QConfFileSettingsPrivate::writeIniFile:
if ((slashPos = key.indexOf(QLatin1Char('/'))) != -1) {
section = key.left(slashPos);
key.remove(0, slashPos + 1);
}
QSettingsIniSection &iniSection = iniMap[section];
iniSection.keyMap[key] = j.value();
Thus, a setting like settings.setValue("mainwindow/titleBar/color", "red"); becomes
[mainwindow]
titleBar/color = red
in the ini file.

ABAP OLE - Open excel password protected workbook

I'm trying to open a password protected excel file using SAP ABAP OLE OBJECT as follows:
DATA: lt_excel_line(4096) OCCURS 10 WITH HEADER LINE.
DATA: app TYPE ole2_object,
workbook TYPE ole2_object,
worksheet TYPE ole2_object.
CREATE OBJECT app 'EXCEL.APPLICATION'.
SET PROPERTY OF app 'VISIBLE' = 0.
CALL METHOD OF app 'WORKBOOKS' = workbook.
CALL METHOD OF workbook 'OPEN'
EXPORTING
#1 = '<filename>'
#5 = '<password>'.
The filename and password are definitely correct and the following VBA code opens the file as required no problem:
Dim wb1 As Workbook
Set wb1 = Workbooks.Open Filename:="<filename>", Password:="<password>")
But the ABAP code always returns sy-subrc = 2. Anyone know what could be going on? Or what else I can try? Grateful for any help.
I think the problem is with the parameters being positional only (just a guess), as the SAP GUI automation does not support parameter names. There are 3 parameters between Filename and Password, so you numbered them correctly, but I guess the SAP GUI automation controller does not see it that way.
I replicated your problem and got it working as follows:
CALL METHOD OF workbook 'OPEN' = document
EXPORTING
#1 = '<filename>'
#2 = 0 "UpdateLinks
#3 = 0 "ReadOnly
#4 = 1 "Format
#5 = '<password>'.
Here I am explicitly passing the parameters UpdateLinks, ReadOnly and Format.
I tested it first in VBA. It seems Format (#4) must be set to true. I don't know what that does.
Remember to set the document handle as a return from this call as I do here, otherwise you don't have a reference to it!

Visual Basic 2010: How do I reference one of many objects through an additional object? (Pointer-like behaviour?)

I am writing an application in Visual Basic 2010 Express.
I have two objects of a class from a driver DLL that is provided to me. They have some of their own subroutines that I'd like to call, and I'd like an easy way to toggle between them.
Instead of writing a whole bunch of code like this:
selected = x
...
If selected = x then
DriverInstanceX.DoSomething()
Else If Selected = y then
DriverInstanceY.DoSomething()
Endif
I would like to do this:
Bob = (some reference to X - NOT a copy of X!)
...
Bob.DoSomething()
Bob.DoSomethingElse()
I'm sure this is really easy - I am just not sure where to look.
Thanks for any help!
' set the object based on what was selected first, here...
Dim selectedDriverInstance = new DriverObject
' now you can run the method without checking for each as selected was already set.
selectedDriverInstance.DoSometng()
Cool?
Of course, DriverObject can be the instance x or instance y depending on what u set it to, do the assignment there and set it to our fixed name object selectedDriverInstance. this way you can do everything using selectedDriverInstance as it is set to either instance x or instance y already, get me?

Are there restricted characters in ADO varchars?

We have a simple file browser on our intranet, built using ASP/vbscript. The files are read by the script and added to an ADO Recordset (not connected to a database), so we can sort the contents easily:
Set oFolderContents = oFolder.Files
Set rsf = Server.CreateObject("ADODB.Recordset")
rsf.Fields.Append "name", adVarChar, 255
rsf.Fields.Append "size", adInteger
rsf.Fields.Append "date", adDate
rsf.Fields.Append "type", adVarChar, 255
rsf.Open
For Each oFile In oFolderContents
if not left(oFile.Name, 3) = "Dfs" then 'Filter DFS folders
rsf.AddNew
rsf.Fields("name").Value = oFile.Name
rsf.Fields("size").Value = oFile.Size
rsf.Fields("date").Value = oFile.DateCreated
rsf.Fields("type").Value = oFile.Type
end if
Next
In one particular folder we are getting an error:
Microsoft Cursor Engine error '80040e21'
Multiple-step operation generated errors. Check each status value.
This points to the line
rsf.Fields("name").Value = oFile.Name
in the code above.
My initial thought this was caused by a long file name, but I checked the length of all the files in the directory - although some are quite long, all are under the 255 character limit set above (largest is 198 characters long).
The folder in question has nearly 2000 PDFs in it, and I do not have permissions to alter the contents, just read (it's a technical library). The files have a naming convention of "ID# - Paper Title". Some have special characters such as ', &, and ( or ) - could some of these be causing the issue? I don't recall having such a problem before. I tried searching Google for special characters in ADO, but couldn't find anything which seemed relevant.
Thanks :-)
Have you tried using adVarWChar for the name column?

Resources