Visual Selection of SAP Table Data with ABAP and PowerShell
To write an UI with SAP GUI for Windows for a visual selection of table data is not so easy as it seems. But it is possible to simplify this kind of requirement. For that we can use PowerShell as an addition to the SAP GUI for Windows. I described the basically procedure here.
The following ABAP method reads table data, in this case from the table SFLIGHT, converts it to JSON, initialized PowerShell in ABAP and views the table date in a grid. After a selection of one or multiple lines the selected lines will be delivered back and the data will be converted from JSON to the SAP table structure.
METHOD ViewTableData.
DATA:
lo_ps TYPE REF TO zactivexposhv3,
lt_sflight TYPE STANDARD TABLE OF sflight,
lv_data TYPE string,
lv_Result TYPE string
.
SELECT * FROM sflight INTO TABLE lt_sflight.
lv_data = /ui2/cl_json=>serialize( data = lt_sflight ).
CREATE OBJECT lo_ps.
CHECK lo_PS->LoadLib( ) = lo_PS->mc_True.
CHECK lo_PS->getIsPowershellInstalled( ) = lo_PS->mc_True AND
lo_PS->Init( iv_Load_Profiles = lo_PS->mc_False ) = 0.
lo_PS->setOutputMode( iv_Mode = lo_PS->mc_OutputBuffer ).
lo_PS->ClearOutput( ).
lo_PS->Execute( iv_Command =
'(''' && lv_data && ''' | ConvertFrom-Json) | ' &&
'Out-GridView -Title "SFLIGHT" -OutputMode Multiple | ' &&
'ConvertTo-Json' ).
lv_Result = lo_PS->getOutputString( ).
lo_PS->FreeLib( ).
CLEAR lt_sflight.
/ui2/cl_json=>deserialize(
EXPORTING
json = lv_result
CHANGING
data = lt_sflight
).
ENDMETHOD.
This example shows a visual SAP table data selection with the combination of ABAP and PowerShell. On this way it is very easy to combine both worlds, the power of SAP ABAP on the back-end server and the force of PowerShell on the front-end server.
The Out-GridView cmdlet offers many possbilities to hide, show, order, sort and filter table data. You can find a full documentation here. All these functionalities you get as a gift. You have nothing to define or to code, all you have to do is to use Out-GridView.
The integration of a PowerShell UI in SAP ABAP offers great possibilities, flexibility and freedom.