SAP/ABAP info: Tips & Tricks
Modifying generated source codes
By the Post in Bern we hit the problem, that after release 4.7 you cannot edit generated ABAP source codes in SAP. This is blocked I think because SAP reserves the right to regenerate these source codes at any time. However this causes a great deal of problem in HR, because all the infotypes above 9000 have generated programs and these have to be modified by the user.
 

Before continuing, please make sure, that you checked SAP OSS for a better solution. Maybe they aleady delivered a nicer answer to this problem.
My Solution:To regain this ability to modify these source codes, you can use the function TRINT_TADIR_UPDATE to get GENFLAG out of the corresponding TADIR entry. This is a very sensitive function, use it carefully.

Hide Programs
In the very first line on the utmost left position put in this special character sequence: *@#@@[SAP]
Nothing else has to be in the first line. After saving your source code it's still there. Leave the editor and try to go back in order to change the source again. Won't work any longer. Try to display the source code. Won't work. Try to debug. Works a bit, but the pity is you have a blank grey screen. So you can't see the source. You can only execute the main program or delete the hidden program.
 

I prefer to hide ABAPs in special include members. The only way to get it back as I know is to have a backup of your source. First delete the hidden ABAP then restore the backup version from e.g. your PC. Another way is to export your source with a transport request by using LIMU REPS . Then edit the exported data file with a hex editor and overwrite the special sequence with spaces. Then do a re-import. I tried it a lot of times and it works. Even then ABAP statement READ REPORT INTO will fail. It gives you a RC of 4.

 
Transferring a data line into a structure in SAP Enterprise (4.7)

With the new unicode check enabled, you cannot make the following anymore:

R_struct = l_dataline.

Instead you have to define field-symbols to make this transfer:

Field-symbols: <fs_struct> type xtype,
             <fs_dataline> type ytype.

Assign r_struct to <fs_struct>                           casting.
Assign r_dataline to <fs_dataline>                         casting.

<fs_struct> = <fs_dataline>.


I couldn’t check these lines, because I don’t have any Enterprise System I could use now.

 

 

 
 
Dynamic structure

* If you receive x bytes per line and
* you want to declare a dynamic
* structure for it, then the solution
* is in this report.


REPORT zmaschl_create_data_dynamic .
TYPE-POOLS: slis.
DATA: it_fcat TYPE slis_t_fieldcat_alv,
is_fcat LIKE LINE OF it_fcat.
DATA: it_fieldcat TYPE lvc_t_fcat,
is_fieldcat LIKE LINE OF it_fieldcat.
DATA: new_table TYPE REF TO data.
DATA: new_line TYPE REF TO data.
FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
* Build fieldcat
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SYST'
CHANGING
ct_fieldcat = it_fcat[].

LOOP AT it_fcat INTO is_fcat WHERE NOT reptext_ddic IS initial.
MOVE-CORRESPONDING is_fcat TO is_fieldcat.
is_fieldcat-fieldname = is_fcat-fieldname.
is_fieldcat-ref_field = is_fcat-fieldname.
is_fieldcat-ref_table = is_fcat-ref_tabname.
APPEND is_fieldcat TO it_fieldcat.
ENDLOOP.

 



* Create a new Table
CALL METHOD cl_alv_table_create =>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = new_table.

* Create a new Line with the same structure of the table.
ASSIGN new_table->* TO <l_table>.
CREATE DATA new_line LIKE LINE OF <l_table>.
ASSIGN new_line->* TO <l_line>.
* Test it...
DO 30 TIMES.
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
<l_field> = sy-index.
INSERT <l_line> INTO TABLE <l_table>.
ENDDO.
LOOP AT <l_table> ASSIGNING <l_line>.
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
WRITE <l_field>.
ENDLOOP.

 
 
Published on zbalai.com in 2004.