This is the third part in this series, which talks about, usage of two of the important macros used in ITS development. This will be useful when large amounts of data have to be sent back from the web to the SAP GUI or vice versa. The transfer of the data is done using the macros. This article talks about two such macros (FIELD-GET and FIELD-SET macros), which are used extensively in ITS development.
Before going into the development part let us first have a look at what exactly these two macros are used for.
FIELD-GET macro
FIELD-GET macro is used to get the values of variables from the ITS during PAI. This is useful for retrieving large or unknown amounts of data such as an HTML text area:
- If the text area contains a small amount of data, you can use a step loop in R/3
- If the text area contains a large amount of data, a step loop may not be large enough to hold all the data coming from the Web browser, so the text could be truncated.
In this case, the field-get macro is used in the PAI module of the transaction.
FIELD-SET macro
FIELD-SET macro is used to assign values to ITS variables in the active context. This allows setting the values of a single variable (especially if that variable contains a large amount of data) or building up an array of values from one column of a table.
Typically, these values are set in the PBO module of a transaction when preparing data for display. Also, multiple field-set calls can be made in separate PBO modules.
To understand how these macros works, two text areas have been created, one is for entering the text and another for displaying the text.
In order to create the above text area, the <textarea> tag has been used in the HTML template .The HTML code that needs to written in the template is given below:
<textarea style="font-family:courier;font-size:11px;"
id="GT_SCR_SPEC_NOTE:132[]" name="GT_SCR_SPEC_NOTE:132[]"
cols="40" rows="4" wrap="physical" title="`#AREA_INFO`">`
repeat with r in GT_SCR_SPEC_NOTE;write (r, "rn");end
</textarea>
The important thing to notice here is that the name of the textarea, GT_SCR_SPEC_NOTE will be used in the PAI module of the program ZYMOVIE1.
Similarly for the text area named as “see the text below” , HTML code is as follows:
<textarea style="font-family:courier;font-size:11px;"
id="GT_SCR_SPEC_NOTE1:132[]" name="GT_SCR_SPEC_NOTE1:132[]"
cols="40" rows="4" wrap="physical" title="`#AREA_INFO`">`
repeat with r in GT_SCR_SPEC_NOTE1;write (r, "rn");end`
</textarea>
The difference in HTML code for the above two text areas is just the name of the text area. The “repeat” and “write” statements perform the task of putting the text present in the GT_SCR_SPEC_NOTE1 into the textarea. Without these statements, the text will not appear in the textarea.
To store the text entered in the textarea, a table has been created with the name ZTEXT.
Now Coming to the ABAP part on how to transfer the text entered in the textarea GT_SCR_SPEC_NOTE to the table ZTEXT.
For this purpose we use FIELD-GET macro in the module “get_record” (in PAI section) as shown below:
lv_next = 1.
DO.
CLEAR lt_text.
REFRESH lt_text.
field-get 'GT_SCR_SPEC_NOTE' lv_next lt_text lv_datalan.
IF sy-subrc = 0.
READ TABLE lt_text INDEX 1.
gt_scr_spec_note2-text = lt_text.
APPEND gt_scr_spec_note2.
lv_next = lv_next + 1.
IF lt_text IS NOT INITIAL.
lv_last_not_blank = sy-tabix.
ENDIF.
ELSE.
lv_last_index = sy-tabix.
EXIT.
ENDIF.
ENDDO.
The important thing to note here is that the name “GT_SCR_SPEC_NOTE” is same as the name of the textarea, defined in the HTML template.
FIELD-GET macro transfers the text entered in the textarea into the internal table “lt_text”. This text is in turn taken into another internal table “gt_scr_spec_note2”. Once all the text is transferred to the internal table “gt_scr_spec_note2”, the below mentioned code does the updating of the table ZTEXT.
LOOP AT gt_scr_spec_note2.
wa_ztext-mandt = '100'.
wa_ztext-notes = gt_scr_spec_note2-text.
wa_ztext-counter = sy-tabix.
update ztext from wa_ztext.
ENDLOOP.
To transfer the data from the table ZTEXT to the textarea ” see the text here” , we use FIELD-SET macro. The ABAP code is given below:
select * from ztext into corresponding fields of table itab_ztext.
loop at itab_ztext.
gt_scr_spec_note1-text = itab_ztext-notes.
append gt_scr_spec_note1.
endloop.
lv_next1 = 0.
LOOP AT gt_scr_spec_note1.
ADD 1 TO lv_next1.
field-set 'GT_SCR_SPEC_NOTE1' lv_next1 gt_scr_spec_note1-text.
field-transport.
ENDLOOP.
As mentioned in the FIELD-GET section , the variable name used in the macro should be same as the name of the textarea given in the HTML template ( i.e., GT_SCR_SPEC_NOTE1 )
Useful links:
- For learning HTML and Javascript, the best starting point would be w3schools.com
- For learning HTMLB, I haven’t found anything better than this link
Sankar Rao Bhatta is an SAP NetWeaver Consultant with Intel, India. After completing M.Tech from IIT Bombay, he worked with IBM as SAP Consultant before joining Intel. Other areas of his expertise include SAP SRM and ABAP.