Trying to fill empty fields by using IS INITAL - abap

I am trying to update a certain part of the code, where the code is shown below.
READ TABLE lt_cc_data ASSIGNING <ls_cc_data>
WITH KEY qmnum = ls_refferal-qmnum.
IF <ls_cc_data>-pruef is INITAL. *>>>>>Statement that I added
IF sy-subrc IS INITIAL.
<ls_cc_data>-pruef = <ls_ccicons>-icon_id.
ENDIF.
ENDIF.
Before entering the statement that I have shown in the code, the program would enter in each qnum = ls_refferal-qmnum and fill the pruef field, however it did not take into account the cases when the qnum had the same values throughout the table. What I try to did is filling the pruef field only in those cases when the field is empty.
Being that I cannot test it due to lack of data in the development system, is the logic behind my solution correct and if not can someone give me an similar solution?
Thank you all in advance!
EDIT
The code would look like this now:
READ TABLE lt_cc_data ASSIGNING <ls_cc_data>
WITH KEY qmnum = ls_refferal-qmnum.
IF <ls_cc_data>-pruef is INITAL. *>>>>>Statement that I added
<ls_cc_data>-pruef = <ls_ccicons>-icon_id.
ENDIF.

Related

Syntax error "Field "L_TABDEF–TLTYPE" is unknown" in Smart Form

I have defined local variables in a program line in SMARTFORMS but it seems that even it is locally declared within the program line node, it does not see the variables.
Error shown below.
Field "L_TABDEF–TLTYPE" is unknown. It is neither in one of the
specified tables nor defined by a "DATA" statement. "DATA" state
FIELD-SYMBOLS: <f_tab> TYPE tsftabdef.
DATA: l_tabdef TYPE ssftabdef , " Work Area for the Table
t_ltypes TYPE tsfltype , " Table – Line types
l_ltypes TYPE ssfltype , " Work Area for the table
t_colinfo TYPE tsfcolinfo , " Table – Columns
l_colinfo TYPE ssfcolinfo , " Work area for the table
t_border TYPE tsfctaba , " Tables – Borders
l_border TYPE ssfctaba . " Work Area for the border
ASSIGN ('(SAPLSTXBC)TABDEFS') TO <f_tab>.
* Table definition table
LOOP AT <f_tab> INTO l_tabdef.
LOOP AT l_tabdef–tltype INTO l_ltypes WHERE linetype = 'LINE'.
LOOP AT l_ltypes–tcolinfo INTO l_colinfo.
LOOP AT l_colinfo-borders INTO l_border.
CLEAR l_border-intensity.
l_border-fillcolor-red = '255'.
l_border-fillcolor-green = '000'.
l_border-fillcolor-blue = '000'.
l_border-fillcolor-used = 'X'.
l_border-cfillcolor-color = 'X'.
l_border-cfillcolor-xred = 'FF'.
l_border-cfillcolor-xgreen = '00'.
l_border-cfillcolor-xblue = '00'.
MODIFY l_colinfo-borders FROM l_border.
ENDLOOP.
MODIFY l_ltypes-tcolinfo FROM l_colinfo.
ENDLOOP.
MODIFY l_tabdef-tltype FROM l_ltypes.
ENDLOOP.
MODIFY <f_tab> FROM l_tabdef.
ENDLOOP.
What am I missing here?
In l_tabdef–tltype, you are confused by the dash character which is in fact the invalid Unicode character EN DASH U+2013, so it's not recognized as the "structure component selector" (i.e. the dash character U+002D) and the compiler considers the whole name as referring to a classic data object, not a structure component.
Probably the error originates from a copy/paste from your favorite Text Processing software.
Solution: please retype "-" in l_tabdef–tltype.
PS: thank you for having provided this Minimal, Complete, and Verifiable example otherwise it would have been impossible to troubleshoot the issue!

ALV report fill gap between documents

I was trying to challenge myself to make an ALV report that displays all the data by company code. but some document number has a gap.
I want to fill the gap between missing number
For example:
last index value: 20012
then next value is: 20014
How do I able to insert 20013 in the grid if the report is using all the data that exist in internal tables?
Thanks.
This is just blind text typing, but I hope you are able to understand it ... should be quite simple. Dont expect complete code, unless your are not even providing ANY code.
DATA: lv_current type i,
lv_next type i.
SORT lt_internalTable by BUKRS ascending.
LOOP AT lt_internalTable into ls_internalTable.
MOVE sy-tabix to lv_current.
READ TABLE lt_internalTable into ls_tempinternalTable INDEX sy-tabix + 1.
MOVE sy-tabix to lv_next.
IF (lv_next - lv_current) > 1.
... do your stuff
ENDIF.
CLEAR: ls_internalTable, lv_current, lv_next.
ENDLOOP.

Update itab from another itab?

My program simply put the locks on users if the 'LOCK' checkbox is selected.
Everything works and the users records are updated in the USR02. When this change occurs I want that it also be reflected in IT_USR02, i.e. DB table USR02 and itab it_usr02 should be identical.
SELECT-OPTIONS: USER_ID FOR USR02-BNAME.
START-OF-SELECTION.
SELECT BNAME
USTYP
UFLAG
FROM USR02
INTO TABLE IT_USR02
WHERE BNAME IN USER_ID.
LOOP AT IT_USR02 INTO ST_USR02.
IF LOCK = 'X'.
CALL FUNCTION 'BAPI_USER_LOCK'
EXPORTING
USERNAME = ST_USR02-BNAME
TABLES
RETURN = I_BAPI_RETURN.
MOVE-CORRESPONDING IT_USR02[] TO IT_ZATO_LOCK_UNLOCK[].
MODIFY ZATO_LOCK_UNLOCK FROM TABLE IT_ZATO_LOCK_UNLOCK.
ENDIF.
ENDLOOP.
Essentially after BAPI_USER_LOCK function is called I want that change to be made in the IT_USR02 table as well. From there I copy the contents of IT_USR02 to my custom table ZATO_LOCK_UNLOCK.
Everything here seems to work fine I just can't figure out how to update my internal table. Any help would be appreciated.
If I understand your problem correctly then something like this is what you need:
LOOP AT IT_USR02 ASSIGNING FIELD-SYMBOL(<USR02>).
" Using field symbol for performance and so the entry can be changed
IF LOCK = 'X'.
CALL FUNCTION 'BAPI_USER_LOCK'
EXPORTING
USERNAME = ST_USR02-BNAME
TABLES
RETURN = I_BAPI_RETURN.
IF "All is OK in I_BAPI_RETURN
" Change the table entry
<USR02>-UFLAG = 32. " Not sure if this is the right value
ENDIF.
ENDIF.
ENDLOOP.
" This needs to be outside the loop since you are handling the complete table
MOVE-CORRESPONDING IT_USR02[] TO IT_ZATO_LOCK_UNLOCK[].
MODIFY ZATO_LOCK_UNLOCK FROM TABLE IT_ZATO_LOCK_UNLOCK.
" A commit work might be needed here
Note that you still need to code the condition to check if all was OK with the BAPI call. I am not familiar with the BAPI so do not know if no entries is good news or if you need to check if there are any errors in the returned table.

How to retrieve a specific field from a list output?

I don't have any developer rights in my SAP-System but I found a way to write some ABAP-Code in a tiny "User-Exit" box (I don't know if that's what you call it) inside a report.
I'm trying to submit a HR-Report and plug it's outcoming PERNR into that same report again.
There's a syntax-error that is telling me that t_list doesn't have a component with the Name PERNR.
What do I have to do in order to get this to work?
DATA: t_list TYPE TABLE OF abaplist WITH HEADER LINE,
seltab TYPE TABLE OF rsparams,
selline LIKE LINE OF seltab.
*I found out that the name of the selection field in the Report-GUI is "PNPPERNR" and tested it
selline-selname = 'PNPPERNR'.
selline-sign = 'I'.
selline-option = 'EQ'.
SUBMIT Y5000112
USING SELECTION-SET 'V1_TEST'
EXPORTING LIST TO MEMORY
AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = t_list
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
WRITE 'Unable to get list from memory'.
ELSE.
LOOP AT t_list.
*The Problem is here: how do I get the pnppernr out of t_list, it's the first column of the report output
selline-low = t_list-pernr.
append selline to seltab.
ENDLOOP.
SUBMIT Y5000112
WITH SELECTION-TABLE seltab
USING SELECTION-SET 'V2_TEST'
AND RETURN.
ENDIF.
Use the function module LIST_TO_ASCI to decode the contents of t_list into something readable. This answer contains some sample code including the data types required. At this point, the data you're looking for will probably occur at the same column range in the output. Use the standard substring access methods - e. g. line+42(21) to obtain the part of the line you need.
The vwegert's answer is more than useful! In my previous answer I forgot to mention LIST_TO_ASCI FM :)
The only thing I can add is that parsing of result lines has no universal solution and greatly depends on its structure. Usually it is done like:
LOOP AT t_list.
SPLIT t_list AT '|' INTO <required_structure>.
selline-low = <required_structure>-pernr.
APPEND selline TO seltab.
ENDLOOP.
where <`required_structure> is your Y5000112 output structure. But this may be not so simple and may require additional manipulations.

How to find a standard text within a SapScript or SmartForm?

I need to track down where within a large number of custom sapscripts and smartforms a specific standard text (SO10) is being used.
Apart from the equivalent of "check the code for each print script", I've not found a workable solution online. Any suggestions?
After posting, I found a partial solution. The code below will search for a standard text within sapscripts, but not smartforms.
PARAMETERS: p_sttxt LIKE stxh-tdname.
DATA: BEGIN OF t_stxh OCCURS 0,
tdname LIKE stxh-tdname,
tdspras LIKE stxh-tdspras,
END OF t_stxh.
DATA t_lines LIKE tline OCCURS 0 WITH HEADER LINE.
SELECT tdname tdspras FROM stxh INTO TABLE t_stxh
WHERE tdobject = 'FORM'
AND tdid = 'TXT'
AND tdspras = 'E'.
LOOP AT t_stxh.
REFRESH t_lines.
CALL FUNCTION 'READ_TEXT'
EXPORTING
* CLIENT = SY-MANDT
id = 'TXT'
language = t_stxh-tdspras
name = t_stxh-tdname
object = 'FORM'
TABLES
lines = t_lines
EXCEPTIONS
id = 0
language = 0
name = 0
not_found = 0
object = 0
reference_check = 0
wrong_access_to_archive = 0
OTHERS = 0 .
SEARCH t_lines FOR p_sttxt.
IF sy-subrc EQ 0.
WRITE:/ t_stxh-tdname, t_stxh-tdspras.
ENDIF.
ENDLOOP.
This is a (fixed) version of the code found here: http://scn.sap.com/thread/179142
What concerns SmartForms, you cannot. You cannot just find it like you want it.
Unfortunately, in such ̶g̶o̶o̶d̶ ̶o̶l̶'̶ legacy technology as SmartForms everything is working legacy way, and standard texts are simply hard-coded. Yes, it looks awkward but they are really hard-coded, and these names are written out to SmartForm FM code every time it is re-generated.
So the only workaround here is to analyze the code.
Find all FMs for existing Smart Forms in system
There is a D010INC table containing all forms with their includes. The main point here is that all SmartForm FMs start with /1BCDWB/ prefix.
The main logic is in the includes, so we need to find correspondent INCLUDE for the target form.
Fetch SF include source code
It can be done in a several ways: via CL_RECA_RS_SERVICES class, via table REPOSRC, but the simplest way is ABAP statement READ REPORT.
Search SO10 text element name in the source code
Get Smart Form names for the FMs from hit list. It can be done via STXFADMI table, like in below snippet, but the more correct way is SSF_FUNCTION_MODULE_NAME FM
Bingo!
Sample solution could look like this:
DATA: lt_source TYPE TABLE OF string,
lt_smartforms TYPE TABLE OF d010inc,
so_text TYPE char50,
fs_form TYPE string,
used_in TYPE TABLE OF string,
len TYPE i.
* populating the list of SmartForm FMs
SELECT * FROM d010inc AS d
INTO TABLE lt_smartforms
WHERE master LIKE '/1BCDWB/%'
AND include LIKE '/1BCDWB/%'.
so_text = '85XX_FOOTER'. " <- our SO10 text element name
LOOP AT lt_smartforms ASSIGNING FIELD-SYMBOL(<fs_fm_name>).
* reading FM source code
READ REPORT <fs_fm_name>-include INTO lt_source.
* checking if SO11 exists in source code
FIND FIRST OCCURRENCE OF so_text IN TABLE lt_source.
IF sy-subrc = 0.
len = strlen( <fs_fm_name>-include ) - 7.
* searching for SmartForm related to the target FM
SELECT SINGLE formname
FROM stxfadmi
INTO fs_form
WHERE fmnumb = <fs_fm_name>-include+len(4).
IF sy-subrc = 0.
APPEND fs_form TO used_in.
ENDIF.
ENDIF.
ENDLOOP.
Yes, it is junky, not elegant and awkward, but who said it should be so?