
CLASS z_cl_posh_handle_incl DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
interfaces IF_HTTP_EXTENSION .
"! Detects Includes
"! @parameter iv_inclpattern | Detection pattern
"!
"! @parameter rt_incl | List of includes
"!
"! @exception not_authorized | No authorization
METHODS get_incl
IMPORTING
VALUE(iv_inclpattern) TYPE sobj_name
RETURNING
VALUE(rt_incl) TYPE rslpo_th_objnm
EXCEPTIONS
not_authorized
.
"! Reads an Include
"! @parameter iv_inclname | Name of the include
"!
"! @parameter rv_strincl | Include as string
"!
"! @exception not_authorized | No authorization
METHODS read_incl
IMPORTING
VALUE(iv_inclname) TYPE sobj_name
RETURNING
VALUE(rv_incl) TYPE string
EXCEPTIONS
not_authorized
.
"! Writes an Include
"! @parameter iv_inclname | Name of the include
"! @parameter iv_strincl | Include as string
"!
"! @parameter rv_result | Return value, 1 for success, otherwise 0
"!
"! @exception not_authorized | No authorization
METHODS write_incl
IMPORTING
VALUE(iv_inclname) TYPE sobj_name
VALUE(iv_incl) TYPE string
RETURNING
VALUE(rv_result) TYPE integer
EXCEPTIONS
not_authorized
.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS z_cl_posh_handle_incl IMPLEMENTATION.
METHOD if_http_extension~handle_request."-----------------------------
DATA:
lv_verb TYPE string,
lv_operation TYPE string,
lv_inclpattern TYPE sobj_name,
lt_incl TYPE rslop_th_objnm,
lv_inclname TYPE sobj_name,
lv_incl TYPE string
.
lv_verb = server->request->get_header_field( name = '~request_method' ).
CASE lv_verb.
WHEN 'GET'.
lv_operation = server->request->get_header_field( name = 'operation' ).
CASE lv_operation.
WHEN 'get'."-get_incl-----------------------------------------
lv_inclpattern = server->request->get_header_field( name = 'inclpattern' ).
CHECK lv_inclpattern IS NOT INITIAL.
TRY.
lt_incl = me->get_incl( iv_inclpattern = lv_inclpattern ).
CATCH cx_root.
CALL METHOD server->response->set_status(
code = 403
reason = 'Error - Not authorized' ).
RETURN.
ENDTRY.
IF lt_incl IS INITIAL.
CALL METHOD server->response->set_status(
code = 204
reason = 'No Response' ).
ELSE.
CALL METHOD server->response->set_cdata(
data = /ui2/cl_json=>serialize( data = lt_incl )
).
CALL METHOD server->response->set_status( code = 200 reason = 'Ok' ).
ENDIF.
WHEN 'read'."-read_incl---------------------------------------
lv_inclname = server->request->get_header_field( name = 'inclname' ).
CHECK lv_inclname IS NOT INITIAL.
TRY.
lv_incl = me->read_incl( iv_inclname = lv_inclname ).
CATCH cx_root.
CALL METHOD server->response->set_status(
code = 403
reason = 'Error - Not authorized' ).
RETURN.
ENDTRY.
IF lv_incl IS INITIAL.
CALL METHOD server->response->set_status(
code = 204
reason = 'No Response' ).
ELSE.
CALL METHOD server->response->set_cdata( data = lv_incl ).
CALL METHOD server->response->set_status( code = 200 reason = 'Ok' ).
ENDIF.
ENDCASE.
WHEN 'POST'."-write_incl------------------------------------------
lv_inclname = server->request->get_header_field( name = 'inclname' ).
CHECK lv_inclname IS NOT INITIAL.
lv_incl = server->request->get_cdata( ).
CHECK lv_incl IS NOT INITIAL.
TRY.
CASE me->write_incl( iv_inclname = lv_inclname iv_incl = lv_incl ).
WHEN 0.
CALL METHOD server->response->set_status( code = 500 reason = 'Error - Can not write' ).
WHEN 1.
CALL METHOD server->response->set_status( code = 200 reason = 'Ok' ).
ENDCASE.
CATCH cx_root.
CALL METHOD server->response->set_status(
code = 403
reason = 'Error - Not authorized' ).
RETURN.
ENDTRY.
WHEN OTHERS.
CALL METHOD server->response->set_status(
code = 400
reason = 'Error - Verb not supported' ).
ENDCASE.
ENDMETHOD.
METHOD get_incl."-----------------------------------------------------
AUTHORITY-CHECK OBJECT 'S_DEVELOP'
ID 'ACTVT' FIELD '03'.
IF sy-subrc <> 0.
RAISE not_authorized.
ENDIF.
CHECK iv_inclpattern IS NOT INITIAL.
SELECT name FROM trdir INTO TABLE rt_incl WHERE name LIKE iv_inclpattern AND
subc = 'I' AND appl = SPACE.
ENDMETHOD.
METHOD read_incl."----------------------------------------------------
DATA:
lt_trdir TYPE trdir,
lt_incl TYPE TABLE OF string,
lv_inclline TYPE string,
lv_retincl TYPE string
.
AUTHORITY-CHECK OBJECT 'S_DEVELOP'
ID 'ACTVT' FIELD '03'.
IF sy-subrc <> 0.
RAISE not_authorized.
ENDIF.
SELECT SINGLE * FROM trdir INTO lt_trdir WHERE name = iv_inclname AND
subc = 'I' AND appl = SPACE.
CHECK sy-subrc = 0.
READ REPORT iv_inclname INTO lt_incl.
CHECK sy-subrc = 0.
LOOP AT lt_incl INTO lv_inclline.
lv_retincl = lv_retincl && lv_inclline && cl_abap_char_utilities=>cr_lf.
CLEAR lv_inclline.
ENDLOOP.
rv_incl = lv_retincl.
ENDMETHOD.
METHOD write_incl."---------------------------------------------------
DATA:
lt_trdir TYPE trdir,
lt_incl TYPE TABLE OF string
.
AUTHORITY-CHECK OBJECT 'S_DEVELOP'
ID 'ACTVT' FIELD '02'.
IF sy-subrc <> 0.
RAISE not_authorized.
ENDIF.
rv_result = 0.
CHECK iv_inclname+0(1) = 'Y' OR iv_inclname+0(1) = 'Z'.
SELECT SINGLE * FROM trdir INTO lt_trdir WHERE name = iv_inclname AND
subc = 'I' AND appl = space.
CHECK sy-subrc = 0.
SPLIT iv_incl AT cl_abap_char_utilities=>cr_lf INTO TABLE lt_incl.
INSERT REPORT iv_inclname FROM lt_incl PROGRAM TYPE 'I'.
CHECK sy-subrc = 0.
rv_result = 1.
ENDMETHOD.
ENDCLASS.
FUNCTION z_rfc_readincl
IMPORTING
VALUE(IV_INCLNAME) TYPE SOBJ_NAME
EXPORTING
VALUE(EV_STRINCL) TYPE STRING
EXCEPTIONS
NOT_AUTHORIZED.
DATA:
lo_incl TYPE REF TO /gkv/qm90_cl_posh_handle_incl
.
CREATE OBJECT lo_incl.
TRY.
ev_strincl = lo_incl->read_incl( iv_inclname = iv_inclname ).
CATCH cx_root.
RAISE not_authorized.
ENDTRY.
ENDFUNCTION.
FUNCTION z_rfc_writeincl
IMPORTING
VALUE(iv_inclname) TYPE sobj_name
VALUE(iv_strincl) TYPE string
EXPORTING
VALUE(ev_result) TYPE integer
EXCEPTIONS
not_authorized.
DATA:
lo_incl TYPE REF TO /gkv/qm90_cl_posh_handle_incl
.
CREATE OBJECT lo_incl.
TRY.
ev_result = lo_incl->write_incl( iv_inclname = iv_inclname iv_incl = iv_strincl ).
CATCH cx_root.
RAISE not_authorized.
ENDTRY.
ENDFUNCTION.
Function Read-SAPInclude {
#-Begin-----------------------------------------------------------------
#-Function Get-Destination--------------------------------------------
Function Get-Destination {
#-Verbindungsparamter-----------------------------------------------
$cfgParams = `
New-Object SAP.Middleware.Connector.RfcConfigParameters
$cfgParams.Add($cfgParams::Name, "TEST")
$cfgParams.Add($cfgParams::AppServerHost, "ABAP")
$cfgParams.Add($cfgParams::SystemNumber, "00")
$cfgParams.Add($cfgParams::Client, "001")
$cfgParams.Add($cfgParams::User, "BCUSER")
$SecPasswd = Read-Host -Prompt "Passwort" -AsSecureString
$ptrPasswd = `
[Runtime.InteropServices.Marshal]::SecureStringToBStr($SecPasswd)
$Passwd = `
[Runtime.InteropServices.Marshal]::PtrToStringBStr($ptrPasswd)
$cfgParams.Add($cfgParams::Password, $Passwd)
Return [SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($cfgParams)
}
#-Sub ReadInclude-----------------------------------------------------
Function ReadInclude([string]$InclName) {
$destination = Get-Destination
$rfcFunction = $destination.Repository.CreateFunction("Z_RFC_READINCL")
$rfcFunction.SetValue("IV_INCLNAME", $InclName)
$rfcFunction.Invoke($destination)
$NewTab = $psISE.CurrentPowerShellTab.Files.Add()
$NewTab.Editor.Text = $rfcFunction.GetValue("EV_STRINCL")
$NewTab.Editor.SetCaretPosition(1,1)
}
#-Sub Main------------------------------------------------------------
Function Main () {
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$InclName = [Microsoft.VisualBasic.Interaction]::InputBox("Include Name", `
"Request")
If (-not ([string]::IsNullOrEmpty($InclName))) {
ReadInclude $InclName.ToUpper()
}
}
#-Main----------------------------------------------------------------
Main
#-Error routine-------------------------------------------------------
Trap {
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") > $Null
[Void] [System.Windows.Forms.MessageBox]::Show( `
$_.Exception.GetType().FullName + `
[System.Environment]::NewLine + `
"Error at line " + $_.InvocationInfo.ScriptLineNumber + `
" in " + $_.InvocationInfo.ScriptName + `
[System.Environment]::NewLine + [System.Environment]::NewLine + `
$_.Exception.Message, "An Error Occurred", 0)
Exit
}
#-End-------------------------------------------------------------------
}
Function Write-SAPInclude {
#-Begin-----------------------------------------------------------------
#-Function Get-Destination--------------------------------------------
Function Get-Destination {
#-Verbindungsparamter-----------------------------------------------
$cfgParams = `
New-Object SAP.Middleware.Connector.RfcConfigParameters
$cfgParams.Add($cfgParams::Name, "TEST")
$cfgParams.Add($cfgParams::AppServerHost, "ABAP")
$cfgParams.Add($cfgParams::SystemNumber, "00")
$cfgParams.Add($cfgParams::Client, "001")
$cfgParams.Add($cfgParams::User, "BCUSER")
$SecPasswd = Read-Host -Prompt "Passwort" -AsSecureString
$ptrPasswd = `
[Runtime.InteropServices.Marshal]::SecureStringToBStr($SecPasswd)
$Passwd = `
[Runtime.InteropServices.Marshal]::PtrToStringBStr($ptrPasswd)
$cfgParams.Add($cfgParams::Password, $Passwd)
Return [SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($cfgParams)
}
#-Sub WriteInclude----------------------------------------------------
Function WriteInclude([string]$InclName) {
$destination = Get-Destination
$rfcFunction = $destination.Repository.CreateFunction("Z_RFC_WRITEINCL")
$rfcFunction.SetValue("IV_INCLNAME", $InclName)
$rfcFunction.SetValue("IV_STRINCL", $psISE.CurrentFile.Editor.Text)
$rfcFunction.Invoke($destination)
$Result = $rfcFunction.GetValue("EV_RESULT")
If ($Result = 0) {
Write-Host "An Error Occurred"
}
}
#-Sub Main------------------------------------------------------------
Function Main () {
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$InclName = [Microsoft.VisualBasic.Interaction]::InputBox("Include Name", `
"Request")
If (-not ([string]::IsNullOrEmpty($InclName))) {
WriteInclude $InclName.ToUpper()
}
}
#-Main----------------------------------------------------------------
Main
#-Error routine-------------------------------------------------------
Trap {
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") > $Null
[Void] [System.Windows.Forms.MessageBox]::Show( `
$_.Exception.GetType().FullName + `
[System.Environment]::NewLine + `
"Error at line " + $_.InvocationInfo.ScriptLineNumber + `
" in " + $_.InvocationInfo.ScriptName + `
[System.Environment]::NewLine + [System.Environment]::NewLine + `
$_.Exception.Message, "An Error Occurred", 0)
Exit
}
#-End-------------------------------------------------------------------
}
#-Sub Load-NCo----------------------------------------------------------
Function Load-NCo {
[String]$ScriptDir = "C:\Dummy"
If ([Environment]::Is64BitProcess) {
[String]$Path = $ScriptDir + "\x64\"
} Else {
[String]$Path = $ScriptDir + "\x86\"
}
[String]$File = $Path + "sapnco.dll"; Add-Type -Path $File
$File = $Path + "sapnco_utils.dll"; Add-Type -Path $File
}
#-Main------------------------------------------------------------------
Load-NCo
$null = $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Read SAP Include", { Read-SAPInclude }, $null)
$null = $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Write SAP Include", { Write-SAPInclude }, $null)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |