Pass table parameter to FM via selection screen - dynamic

I need to call a function that has a table type as import parameter in a program. I thought about doing this with a selection screen but I can't use deep structures as parameters. When I 'TEST' that function module it shows me a thing where I can add multiple entries and submit everything in the end. Can I get something similar during the execution of a program?
edit: I have to offer a program that calls the function module create_skill_profile.
1
2
3

You can call the function module RS_COMPLEX_OBJECT_EDIT in your report for editing a complex structure. This is the same function module that is used for editing test data in the function module single test.
So, in your report, you could ask for the name of the desired type (if that has to be a dynamic one), and then, in start-of-selection, you can create a data object of this type and pass it to RS_COMPLEX_OBJECT_EDIT to let the user fill it.
A serious limitation of RS_COMPLEX_OBJECT_EDIT is that it can't handle sorted or hashed tables as input. So all the components of your complex structure, if they are of table kind, they have to be standard tables.

What I understand: You want to call a function module that requires a table as import parameter. The table's rows are filled from user input. The number of rows is dynamic.
Approaches:
1) use selection screen with predefined input fields and show/hide them dynamically via PAI (AT SELECTION-SCREEN (on xxx). LOOP AT SCREEN.) then build your table and call your function module on START-OF-SELECTION.
2) show editable ALV grid with table structure. Implement an application toolbar button or use SAVE button to let the user call your function module when he finished inserting his input.
I would defenitely prefer 2), although custom input validation is a bit tricky. But if the required user input is the same as ddic defined table structure the input validation happens automatically.

Related

Show all variables and their values in VBA during runtime

In my current project in Access VBA, I created a window which works like a console and now I am trying to add a possibility to display any public variable. It should work like:
Show_var [variable_name]
So it should be like in the direct window where i can type:
? pVar.variable_A
I found out that using
Application.VBE.ActiveVBProject.VBComponents(11).CodeModule.CountOfLines
I can display the number of lines within a module or form so I thought perhaps I could somehow find the variables there, cycle through them and when the correct one is found, its value can be shown. OFC I could make a Select Case Statement where all variables are included but that is not the way I want to do it because it is complicated and must be changed every time update my public variable list.
There are so many problems that I think you are out of luck. Let me just list some of them:
There is no way to get a list of all variables - that would mean you would need access to the internal symbol table.
As a consequence, you would have to read the code (CodeModule lets you read the code of a module), and write an own parser to fetch all declarations (hopefully you use Option Explicit)
AFAIK, the is no method that can access the content of a variable via it's name.
Even if there would be any such method: What would you do with different data types, arrays and especially with objects.
If a user runs into problems, often it is a runtime error. If you don't handle that errors with some kind of error handler, the only option if a user cannot enter the debugger is to press "End" - which would destroy the content of all variables.
You have to deal with scope of variables, you can have several variables with the same name and you will likely have lots of variables that are out of scope in the moment you want to dump them.

Making dynamic selections field required

I need to define one dynamic selection field as required.
I created a transaction code with a starting variant.
For this variant in the attributes screen assignment, there is no "required field" option on dynamic selections, only "protect field".
Any idea how to implement this?
On variant attributes screen assignment there is not required field
option on dynamic selections
There is Required attribute in screen variant and it is perfectly usable for making regular field mandatory, and in dynamic selections too.
If you lack it, check your release or maybe your installation is corrupted. I don't believe it is tcode-dependent.
If you are talking about the Dynamic Selections, then you can only protect the fields. Example with demo program DEMO_LIST_OUTPUT (which is based on the F1S Logical Database):
You can only protect those fields against input, and all other attributes are deactivated (they are not implemented as you can see in subroutine MODIFY_SCREEN of program SAPLSSEL).
The only possible workaround to simulate a mandatory field is to implement ABAP code after the user has entered selections (or not). For instance, in the program DEMO_LIST_OUTPUT, you may add this ABAP code which checks that the screen field "Connection Number" contains a value when the user executes the program:
TABLES sscrfields.
AT SELECTION-SCREEN.
DATA dynsel TYPE rsds_trange.
CALL FUNCTION 'RS_REFRESH_FROM_DYNAMICAL_SEL'
EXPORTING
curr_report = sy-repid
mode_write_or_move = 'W'
IMPORTING
p_trange = dynsel
EXCEPTIONS
not_found = 1
wrong_type = 2.
DATA(connid) = VALUE spfli-connid(
dynsel[ tablename = 'SPFLI'
]-frange_t[ fieldname = 'CONNID'
]-selopt_t[ 1 ]-low OPTIONAL ).
IF sscrfields-ucomm = 'ONLI' AND connid IS INITIAL.
MESSAGE 'Flight Connection number is required' TYPE 'E'.
ENDIF.
NB: Tested with ABAP 7.52. Dynamic Selections can be implemented implicitly via Logical Databases (which are obsolete since ABAP 7.02 or 7.31) or explicitly by calling the function modules FREE_SELECTIONS_INIT and FREE_SELECTIONS_DIALOG.

How do i get all ui elements of a view? (Web Dynpro ABAP)

I want to make the labels of an input field invisible when the input field is invisible.
I cant bind it to the same context because they are build dynamically.
Is there a way to get all view elements so i can loop over them and make the label invisible dynamically?
Here's some example action handler code which finds the label MYLABEL inside a container and hides it. It doesn't completely cover your use case, but I think it will get you started.
data view type ref to cl_wdr_view.
view ?= wd_this->wd_get_api( ).
data container type ref to cl_wd_uielement_container.
container ?= view->root_element.
data children type cl_wd_uielement=>tt_uielement.
children = container->get_children( ).
data element type ref to cl_wd_uielement.
loop at children into element.
data id type string.
id = element->get_id( ).
if id = `MYLABEL`.
element->set_visible( `01` ).
endif.
endloop.
Each view controller contains the method WDDOMODIFYVIEW with an initially empty implementation. Inside this method you have access to the whole UI element hierarcy and should be able to retrieve references to both the label and the input field and hide the lable in case the input field is hidden.
First, write a second program that will be responsible for calling your program using the SUBMIT ABAP instruction with the EXPORTING LIST TO MEMORY addition.
When you run this caller program it will call your program using the SUBIT, but instead of generating output on screen, system will send the output to system memory.
Later, in webdynpro or in any other program, you can call ABAP function LIST_FROM_MEMORY to retrieve your program's earlier output to an internal table.
Cheers!

RFC for remote call transaction

How do I call the SAP report (for example RSPARAM) with help JCo?
What RFC may be used to remotely call SA38 transaction with RSPARAM (e.t.c.) as parameter and then return results for later work ?
RFC is for calling function modules, not programs. It's possible to use some generic function module to start a report, but since you'll usually want to process the results of the program and the program does not know that it was meant to deliver its results in a machine-readable way, you probably won't get too far this was. What exactly are you trying to do?
With the nearly infinite possible results of calling a transaction, i don't think there is a RFC to execute such an operation and return a result. What would be the result in case of an ALV display, or if the program then wait for some interactions ?
You can display a transaction in SAP portal using transactions Iviews. You're then using the portal page as a HTMLGui for your transaction.
also, some FM can sometime be used to perform operations instead of a full program (ie HR_INFOTYPE_OPERATION instead of pa30).
regards
Guillaume
Edition : since you want the result of RRSPARAM, you could encapsulate the "important" part (form SHOW_ACTUAL_PAR_VALUES_ALV) in a module function accessible by RFC, and returning a table of CST_RSPFPAR_ALV (ie the same structure that is displayed in the report)
regards
If You don't find a function to call, just create one by yourself. Tag it as callable from outside via RFC and in the coding, perform such things as "submit report xyz with param1 = value1 ... and return ... exporting list to memory". Then you can even return list output from this. Define the interface of the freshly created function module as you need (that means, report name as input, list output as a table of strings, e.g.). Attention, there is of course a big security risk, having an remote function accepting variable reportnames. But I am sure You know :-)

Execute a program via SUBMIT, with GUI suppression

I want to expose the functionality of an SAP program (transaction) as a BAPI.
I need to call a report and supply range filters such that the GUI is bypassed.
Does anyone have a working example of the SUBMIT ... WITH ... ABAP construct, or other suggestions on how to accomplish what I need to do?
Here is a working example:
SUBMIT SAPF140
TO SAP-SPOOL "optional"
SPOOL PARAMETERS print_parameters "optional"
WITHOUT SPOOL DYNPRO "optional (hides the spool pop-up)"
VIA JOB jobname NUMBER l_number "optional"
AND RETURN "optional - returns to the calling prog"
WITH EVENT = REVENT
WITH BUKRS IN RBUKRS
WITH BELNR IN lRBELNR
WITH GJAHR IN RGJAHR
WITH USNAM = SY-UNAME
WITH DATUM = SAVE_DATUM
WITH UZEIT = SAVE_UZEIT
WITH DELDAYS = RDELDAYS
WITH KAUTO = 'X'
WITH RPDEST = SAVE_PDEST
WITH TITLE = TITLE.
All the "WITH" statements relates to selection fields on the called program where I use = it is a PARAMETER statement (single field), where I use IN it is a SELECT_OPTIONS statement (range)
Here is a simple example of how to fill a range:
REFRESH lrbelnr.
lrbelnr-sign = 'I'.
lrbelnr-option = 'EQ'.
lrbelnr-low = HBKORM-belnr.
CLEAR lrbelnr-high.
append lrbelnr.
If you want to suppress this functionality as a BAPI you have to wrap the functionality in a Remote Function Call (RFC) module. Just implement a RFC function module. Depending how the report is implemented, it may use ABAP objects, which can also be called from your RFC implementation. Given that case you have a quite good solution. Whenever the report is adjusted, also your BAPI will reflect the changes. In case it's a standard programm from SAP which cannot be wrapped, think about copying it into your namespace and adjusting it. Nevertheless this might give some hassle, when SAP performs an update via Support Package Stack and you won't realize it. The output of the two methods is different. Apart from that, if you want to call it from outside, there is nothing else possible than implementing a RFC module.
A submit report can not return the values outside. Reports are always only for GUI functionalities and not for exchanging data. In case your report uses select options, you somehow have to implement this feature "by hand" in your RFC, as this statements can not be used inside RFC modules. I would generally try to rework the report, modularize it and put the selection information in a central class or maybe another function module wich can be called from the report and your BAPI function module. The filters you are talking about can not be implemented in RFCs automatically. You have to implement those ranges manually. The warning which comes up cannot be suppressed, if you do a RFC call from a remote system and the popup with the warning comes up you'll end with a shortdump. Therefore, you have to rework the report and to re-implement it for your needs.
If you are just looking for bypassing it via job scheduling, create a variant and schedule the report with that variant but I suppose that's not the solution you're looking for.
You can use inbuilt BAPI also just write "Range" and press F4.
You can wrap your report in an BATCH INPUT session and execute it inside a function. The only drawback is that you need to rewrite the BATCH INPUT every time you change the report.