Passing the data from the structure into the table - abap

I am trying to pass data from a work area to a table. The idea is that I have declared the elements from the Screen Painter as data from a structure, e.g. The field with the name Banks would be as gs_zfr_bn-bankl, where the structure would be declared in the report as gs_zfr_bn TYPE zfr_bn, where zfr_bn is an global table.
Now I am trying to create a form which would serve to pass the data from the structure to the table, where the form would be activated from the event of pressing a button in the selection screen. I have been trying to create a code for that, however I am having an error. The code to pass the data is shown as follows:
DATA: gt_zfr_bn TYPE TABLE OF zfr_bn.
LOOP AT gt_zfr_bn INTO gs_zfr_bn.
APPEND LINES OF gs_zfr_bn TO gt_zfr_bn.
ENDLOOP.
The error is that gs_zfr_bn is not an internal table and the append would not work.
Is there any way to pass the data from the structure into the table gt_zfr_bn, be that hard coded or via an method?
Thank you all in advance!

You mention that you already using gs_zfr_bn structure in screen paint. So you don't need to re-declare it. Just append structure to itab.
APPEND gs_zfr_bn TO gt_zfr_bn.

Just use APPEND without the LINES OF:
APPEND gs_zfr_bn TO gt_zfr_bn.
(APPEND LINES OF ... this would append the lines of one internal table to another.)

Related

Modifying text on input field without using of TABLES keyword

I want to show text on input field in the screen, which is value from work area, respectivetly name, age and city, as you can see. When I declare znew_fdkey01 and znew_fdkey02 (which are transparent tables) with using TABLES keyword like this:
TABLES: znew_fdkey01, znew_fdkey02.
it works perfectly. But when I want to obtain the same effect without using this keyword, and when I declare variables like this:
DATA: znew_fdkey01 TYPE znew_fdkey01,
znew_fdkey02 TYPE znew_fdkey02.
it does not show me text in the input field.
Why?
NB: here is the code to initialize the screen fields (the same in both cases):
LOOP AT SCREEN INTO screen_wa.
IF screen_wa-name = 'ZNEW_FDKEY01-NAME'.
znew_fdkey01-name = lr_znewfdkey3-name.
ENDIF.
IF screen_wa-name = 'ZNEW_FDKEY01-AGE'.
znew_fdkey01-age = lr_znewfdkey3-age.
ENDIF.
IF screen_wa-name = 'ZNEW_FDKEY02-CITY'.
znew_fdkey02-city = lr_znewfdkey3-city.
ENDIF.
MODIFY SCREEN FROM screen_wa.
ENDLOOP.
This is correct, TABLES defines work areas and at the same time it is necessary to ensure the automatic communication between the screen (dynpro) and the ABAP program, as documented in the ABAP Help:
Table work areas declared using TABLES are interface work areas...
The statement TABLES is required for exchanging data between dynpro fields and the ABAP program, if the fields were defined in a dynpro in the program by being taken from ABAP Dictionary, . In the dynpro event PBO, the content of the table work area is passed to identically named dynpro fields. In PAI, the system takes the data from identically named dynpro fields.
(Otherwise don't use TABLES to declare work areas, that is obsolete)
You must use TABLES only if you define your screen input/output field as a "DDIC" field (Data/ABAP Dictionary). This is a checkbox defined in the Screen Painter for each screen field.
There are two possibilities:
Either you name your screen I/O field like according to an existing DDIC structure field (as you did, ZNEW_FDKEY01-NAME) and you define it as a "DDIC" field (it's a field attribute in the Screen Painter) and you must use TABLES to transfer values.
Or you don't define your screen input field as a "DDIC" field, and you define the field name as a global variable in your program, using TABLES is completely optional. But in that case, you lose some features in the screen that are unique to the DDIC, like the reuse of DDIC labels (any change impacts all screens), the Value Help/F4 like the search help implying multiple fields (but you can still code it in ABAP from scratch), etc.
Example:
Create this program:
TABLES spfli. " Mandatory as screen field SPFLI-CARRID is connected to the "DDIC"
DATA scarr TYPE scarr. " or TABLES scarr if you wish
spfli-carrid = 'LH'.
scarr-carrname = 'Name of company'.
CALL SCREEN 100.
MODULE screen_0100_pai INPUT.
LEAVE TO SCREEN 0.
ENDMODULE.
Create the dynpro 0100 with these fields (pay attention to "Dict.field")
Name Type Line Col. Def Vis Format Inp Out Dict.field
SPFLI-CARRID I/O 1 18 3 3 CHAR X X X
SCARR-CARRNAME I/O 2 18 20 20 CHAR X X
and this flow logic:
PROCESS BEFORE OUTPUT.
PROCESS AFTER INPUT.
MODULE SCREEN_0100_PAI.
Activate and run the program.
Result as expected:

ABAP : Fill an I/O field of a Screen from Database

I have just started writing a program using ABAP, I have a screen (named 9007) that contains an Input/Output field and I want to fill it with a variable from my database.
The beginning looks like this :
PROGRAM ZMCQ.
MODULE USER_COMMAND_9007 INPUT.
SELECT SINGLE FIELD1
FROM ZTABLE_NAME INTO ??? *it doesn't work to put the field name there *
WHERE FIELD2 EQ 3.
ENDMODULE.
I am stuck here and I don't know how should I do that .. help please x)
You have to declare a global variable in your Report. Than got to your to Dynpro Settings to the Tab "Elementlist" an put the variable name in line of your I/O field.
After this you have the connection between your Dynpro-Field and a variable.

ABAP Report Logic

I am new to ABAP.
I have a requirement in abap.In my presentation server ,there is header text file, which I want to upload data from that text file to Header table. But the custom table is having different structure from text file.
It includes extra 4 fields- PO_CREATED_DATE, PO_CREATED_BY, PO_CHANGED_DATE, PO_CHANGED_BY.
These fields have to populate from our report program using sy-datum and sy-uname.
In this scenario,we have to check,If the data is existing then populate
PO_CHANGED_DATE, PO_CHANGED_BY and if the data is not there,then populate PO_CREATED_DATE, PO_CREATED_BY.
Please let me know the logic...
first load the file into an internal table with only 1 very long field (long enough to contain at least the longest possible line in the file). Then loop over that itab and split the individual lines using the separator that is used in the file. You split the contents into a work area that contains all your fields, including the 4 extra fields that may or may not be included in the file. Make sure to clear the work area before splitting the line into the WA. Append the work area to an itab with the same structure as the wa, then continue with the next line.
After that, loop over that second itab and check for lines where your 4 extra fields are initial. Those are the lines where you need to add the data by code. After that, do whatever you need to do with the data in the itab.
I uploaded text file header data to it_input1 using gui_upload.But the it_input1 is not having extra 4 fields.I declared another itable it_header which is having the same structure as Header custom table.Now i wnt to check whether the data in the it_input 1 is alredy existing or not.If existing ,populate it_header-po_changed_date and it_header-po_changed_by or else, it_header-po_created_date and it_header-po_created_by.
Take a look to the "Pattern" Button on top. Select ABAP Objects an press enter.
Now you can supply the class and methdo you want to call.
CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
GUI_UPLOAD is a static method. If you are new that is the easiest way to see which parameters must be supplied. With the forward navigation (double-click) you can check the signature for typing the parameter variables.
Then you just need to convert your data (e.g. SPLIT). I can only recommend to use the F1-Help.
Kind regards!

Get Text Symbol Programmatically With ID

Is there any way of programmatically getting the value of a Text Symbol at runtime?
The scenario is that I have a simple report that calls a function module. I receive an exported parameter in variable LV_MSG of type CHAR1. This indicates a certain status message created in the program, for instance F (Fail), X (Match) or E (Error). I currently use a CASE statement to switch on LV_MSG and fill another variable with a short description of the message. These descriptions are maintained as text symbols that I retrieve at compile time with text-MS# where # is the same as the possible returns of LV_MSG, for instance text-MSX has the value "Exact Match Found".
Now it seems to me that the entire CASE statement is unnecessary as I could just assign to my description variable the value of the text symbol with ID 'MS' + LV_MSG (pseudocode, would use CONCATENATE). Now my issue is how I can find a text symbol based on the String representation of its ID at runtime. Is this even possible?
If it is, my code would look cleaner and I wouldn't have to update my actual code when new messages are added in the function module, as I would simply have to add a new text symbol. But would this approach be any faster or would it in fact degrade the report's performance?
Personally, I would probably define a domain and use the fixed values of the domain to represent the values. This way, you would even get around the string concatenation. You can use the function module DD_DOMVALUE_TEXT_GET to easily access the language-dependent text of a domain value.
To access the text elements of a program, use a function module like READ_TEXT_ELEMENTS.
Be aware that generic programming like this will definitely slow down your program. Whether it would make your code look cleaner is in the eye of the beholder - if the values change rarely, I don't see why a simple CASE statement should be inferior to some generic text access.
Hope I understand you correctly but here goes. This is possible with a little trickery, all the text symbols in a report are defined as variables in the program (with the name text-abc where abc is the text ID). So you can use the following:
data: lt_all_text type standard table of textpool with default key,
lsr_text type ref to textpool.
"Load texts - you will only want to do this once
read textpool sy-repid into lt_all_text language sy-langu.
sort lt_all_Text by entry.
"Find a text, the field KEY is the text ID without TEXT-
read table lt_all_text with key entry = i_wanted_text
reference into lsr_text binary search.
If you want the address you can add:
field-symbols: <l_text> type any.
data l_name type string.
data lr_address type ref to data.
concatenate 'TEXT-' lsr_text->key into l_name.
assign (l_name) to <l_text>.
if sy-subrc = 0.
get reference of <l_text> into lr_address.
endif.
As vwegert pointed out this is probably not the best solution, for error handling rather use message classes or exception objects. This is useful in other cases though so now you know how.

Filling parameter with value from Zeconfig_var table

I have the following selection parameter:
PARAMETERS: p_ver(2) AS LISTBOX VISIBLE LENGTH 5.
I would like to populate it with the results from a ZECONFIG_VAR table.
At what point would I do this. Selection Screen Output, Start of Selection, or other. I am trying to allow users the ability to decide what version of the web service they would like to call. The config table will have different url's for the different versions.
I have looked at this Answer and the tutorial provided does not make sense to me.
I would do it at the event INITIALIZATION
However, it may be even easier to just create a search-help, and assign it to p_ver using the following:
parameters: p_ver(2) visible lenghth 5 MATCHCODE OBJECT zshelpname.
Esti is right that you probably want to fill an internal table from the DB table during INITIALIZATION.
But to the populate the listbox parameter, you need to put the call to VRM_SET_VALUES in AT SELECTION-SCREEN OUTPUT.