Display data fields based on checkbox selection in SAP ABAP - abap

Below is simple code where I want to display location based on checkbox selection.
Eg: id p_pune is selected at seletion screen then after WRITE command my output should be as below
EMPID NAME LOCATION
1 A PUNE
Code:
TYPES: BEGIN OF ty_emp,
empid TYPE i,
name TYPE char5,
location TYPE char6,
END OF ty_emp.
DATA: wa_emp TYPE ty_emp,
it_emp TYPE TABLE OF ty_emp.
DATA: gd_ucomm TYPE sy-ucomm.
wa_emp-empid = 1.
wa_emp-name = 'A'.
wa_emp-location = 'Pune'.
append wa_emp to it_emp.
CLEAR wa_emp.
wa_emp-empid = 2.
wa_emp-name = 'B'.
wa_emp-location = 'Mumbai'.
append wa_emp to it_emp.
CLEAR wa_emp.
wa_emp-empid = 3.
wa_emp-name = 'C'.
wa_emp-location = 'Delhi'.
append wa_emp to it_emp.
CLEAR wa_emp.
wa_emp-empid = 4.
wa_emp-name = 'D'.
wa_emp-location = 'Noida'.
append wa_emp to it_emp.
CLEAR wa_emp.
PARAMETERS: p_pune AS CHECKBOX USER-COMMAND c1,
p_mumbai AS CHECKBOX USER-COMMAND c2,
p_delhi AS CHECKBOX USER-COMMAND c3,
p_noida AS CHECKBOX USER-COMMAND c4.

You can try this:
IF p_pune = abap_true.
READ TABLE it_emp INTO wa_emp INDEX '1'.
WRITE:/ wa_emp-empid, wa_emp-name, wa_emp-location.
ENDIF.
IF p_mumbai = abap_true.
READ TABLE it_emp INTO wa_emp INDEX '2'.
WRITE:/ wa_emp-empid, wa_emp-name, wa_emp-location.
ENDIF.
IF p_delhi = abap_true.
READ TABLE it_emp INTO wa_emp INDEX '3'.
WRITE:/ wa_emp-empid, wa_emp-name, wa_emp-location.
ENDIF.
IF p_noida = abap_true.
READ TABLE it_emp INTO wa_emp INDEX '4'.
WRITE:/ wa_emp-empid, wa_emp-name, wa_emp-location.
ENDIF.
When you check multiple checkboxes, it will display multiple locations.
If you want to display only one location, I suggest you use RADIO BUTTON instead of CHECKBOX.

You could convert the boolean values of the parameters to a location, using the COND statement. Then you can loop over the internal table with LOOP AT and use it's WHERE condition to filter out the location you need.
TYPES:
BEGIN OF employee,
empid TYPE i,
name TYPE char5,
location TYPE char6,
END OF employee,
employees TYPE STANDARD TABLE OF employee WITH EMPTY KEY.
DATA(employees) = VALUE employees(
( empid = 1 name = 'A' location = 'Pune' )
( empid = 2 name = 'B' location = 'Mumbai' )
( empid = 3 name = 'C' location = 'Dehli' )
( empid = 4 name = 'D' location = 'Noida' )
).
PARAMETERS: pune AS CHECKBOX,
mumbai AS CHECKBOX,
dehli AS CHECKBOX,
noida AS CHECKBOX.
START-OF-SELECTION.
DATA(wanted_location) = COND char6(
WHEN pune = abap_true THEN 'Pune'
WHEN mumbai = abap_true THEN 'Mumbai'
WHEN dehli = abap_true THEN 'Dehli'
WHEN noida = abap_true THEN 'Noida'
).
LOOP AT employees INTO DATA(employee)
WHERE location = wanted_location.
WRITE:
employee-empid,
employee-location,
employee-name.
NEW-LINE.
ENDLOOP.

Related

Assign values to dynamic structure

Need idea on the below codes, on how to simplify. Codes below works good but is there a way I could enhance or shorten the codes making it dynamic?
TYPES: BEGIN OF lty_dates,
yesterday TYPE string,
today TYPE string,
tomorrow TYPE string,
END OF lty_dates.
DATA: it_table TYPE TABLE OF lty_dates.
DO 3 TIMES.
CASE lv_count.
WHEN 1.
it_table[ 1 ]-zyesterday = 'Result Yesterday'.
it_table[ 2 ]-zyesterday = 'Result Yesterday'.
it_table[ 3 ]-zyesterday = 'Result Yesterday'.
WHEN 2.
it_table[ 1 ]-ztoday = 'Result Today'.
it_table[ 2 ]-ztoday = 'Result today'.
it_table[ 3 ]-ztoday = 'Result Today'.
WHEN 3.
it_table[ 1 ]-ztommorrow = 'Result Tomorrow'.
it_table[ 2 ]-ztommorrow = 'Result Tomorrow'.
it_table[ 3 ]-ztommorrow = 'Result Tomorrow'.
ENDCASE.
lv_count = lv_count + 1.
ENDDO.
My idea is something like the below pseudocodes. I would not want to perform CASE multiple times specially instances if fields for it_table would reach 100 (fields).
DO 3 TIMES.
ASSIGN 'ZTODAY' TO <dynamic_fieldname>.
it_table[ 1 ]-<dynamic_fieldname> = <dynamic_result>.
it_table[ 2 ]-<dynamic_fieldname> = <dynamic_result>.
it_table[ 3 ]-<dynamic_fieldname> = <dynamic_result>.
ENDDO.
Please help or light me up on this.
You could use the command ASSIGN COMPONENT compname OF STRUCTURE structure TO <field_symbol>.
TYPES: BEGIN OF lty_dates,
yesterday TYPE string,
today TYPE string,
tomorrow TYPE string,
END OF lty_dates.
TYPES: BEGIN OF lty_result ,
fieldname TYPE fieldname,
result TYPE string,
END OF lty_result .
FIELD-SYMBOLS <data> TYPE any .
DATA: lt_table TYPE TABLE OF lty_dates,
lt_result TYPE TABLE OF lty_result.
lt_result = VALUE #( ( fieldname = 'yesterday'
result = 'Result Yesterday' )
( fieldname = 'today'
result = 'Result Today' )
( fieldname = 'tomorrow'
result = 'Result Tomorrow' ) ).
lt_table = VALUE #( ( ) ( ) ( ) ). " 3 empty lines
LOOP AT lt_table ASSIGNING FIELD-SYMBOL(<table>) .
LOOP AT lt_result ASSIGNING FIELD-SYMBOL(<result>) .
ASSIGN COMPONENT <result>-fieldname OF STRUCTURE <table> TO <data> .
<data> = <result>-result.
ENDLOOP .
ENDLOOP .
Actually, your code creates this result table:
YESTERDAY TODAY TOMORROW
Result Yesterday Result Today Result Tomorrow
Result Yesterday Result today Result Tomorrow
Result Yesterday Result Today Result Tomorrow
Why not to use macro for this? Macro can perfectly fulfill your needs:
FIELD-SYMBOLS: <fvalue> TYPE ANY.
DEFINE put_values.
ASSIGN COMPONENT &1 OF STRUCTURE &2 TO <fvalue>.
<fvalue> = &3.
END-OF-DEFINITION.
it_table = VALUE #( ( ) ( ) ( ) ).
LOOP AT it_table ASSIGNING FIELD-SYMBOL(<fs_tab>).
put_values 'yesterday' <fs_tab> 'Result Yesterday'.
put_values 'today' <fs_tab> 'Result Today'.
put_values 'tomorrow' <fs_tab> 'Result Tomorrow'.
ENDLOOP.
This will work if the number if the loop iterations are equal to lines of itab (as in your code).

How to return value to user from a Search Help Exit

I have a Search Help with many fields to be displayed to the user in order to apply values. I want to get 3 fields APOFASI, SKOPOS, KATDANL from the user.
In the CALLCONTROL-STEP = SELECT in the exit FM, I want to get these values in variables and then to make some selects and find another field APOFASISAP.
I am trying to pass back to the selection fields of the search help the field APOFASSISAP, but the APOFASI field seems to be blank.
The code is:
TYPES: BEGIN OF ty_apofasisap_tr,
apofasisap_tr TYPE zglk_sap_afopasi,
END OF ty_apofasisap_tr.
DATA: it_apofasisap_tr TYPE TABLE OF ty_apofasisap_tr,
wa_apofasisap_tr LIKE LINE OF it_apofasisap_tr.
DATA: lv_apofasi TYPE zglk_kyanr_ap,
lv_skopos TYPE zskopos,
lv_katdanl TYPE zsl_cat_dan,
lv_apofasisap_arx TYPE zglk_sap_afopasi.
lv_apofasi = wa_shlp_selopt-low.
ls_result-apofasi = ''.
IF lv_apofasi <> ''.
wa_shlp_selopt-low = ''.
MODIFY shlp-selopt FROM wa_shlp_selopt INDEX sy-tabix.
ENDIF.
READ TABLE shlp-selopt INTO wa_shlp_selopt WITH KEY shlpfield = 'SKOPOS'.
lv_skopos = wa_shlp_selopt-low.
READ TABLE shlp-selopt INTO wa_shlp_selopt WITH KEY shlpfield = 'KATDANL'.
lv_katdanl = wa_shlp_selopt-low.
SELECT SINGLE apofasisap INTO lv_apofasisap_arx
FROM zsl_glk_apof
WHERE apofasi = lv_apofasi.
SELECT * FROM zsl_glk_apof_tr
WHERE apofasisap_trp = lv_apofasisap_arx.
wa_apofasisap_tr-apofasisap_tr = zsl_glk_apof_tr-apofasisap_tr.
APPEND wa_apofasisap_tr TO it_apofasisap_tr.
ENDSELECT.
wa_shlp_selopt-shlpname = 'ZAPOF_TROP'.
wa_shlp_selopt-shlpfield = 'APOFASISAP'.
wa_shlp_selopt-sign = 'I'.
wa_shlp_selopt-option = 'EQ'.
wa_shlp_selopt-low = wa_apofasisap_tr-apofasisap_tr.
APPEND wa_shlp_selopt TO shlp-selopt.
This code does not replace/add the values to the appropriate fields.
Can someone help on this?
PS. Let me add another code that I wrote with the help of internet. It is in the STEP of DISPLAY.
IF callcontrol-step = 'DISP'.
TYPES: BEGIN OF ls_result,
apofasi LIKE zsl_glk_apof-apofasi,
apofasidate LIKE zsl_glk_apof-apofasidate,
apofasisap LIKE zsl_glk_apof-apofasisap,
apofasi_trp_x LIKE zsl_glk_apof-apofasi_trp_x,
apofasi_tr_x LIKE zsl_glk_apof-apofasi_tr_x,
fek LIKE zsl_glk_apof-fek,
katdanl LIKE zsl_glk_apof-katdanl,
reference LIKE zsl_glk_apof-reference,
skopos LIKE zsl_glk_apof-skopos,
thema LIKE zsl_glk_apof-thema,
type_desc LIKE zsl_glk_apof-type_desc,
ya_first LIKE zsl_glk_apof-ya_first,
END OF ls_result.
DATA: lt_result TYPE STANDARD TABLE OF ls_result.
CLEAR: lt_result, record_tab, record_tab[].
* Read the value that user gave
READ TABLE shlp-selopt INTO wa_shlp_selopt
WITH KEY shlpfield = 'APOFASI'.
lv_apofasi = wa_shlp_selopt-low.
IF lv_apofasi <> ''.
* Clear this value
wa_shlp_selopt-low = ''.
MODIFY shlp-selopt FROM wa_shlp_selopt INDEX sy-tabix.
ENDIF.
* Find the number starting APOFASISAP from the APOFASI text
SELECT SINGLE apofasisap INTO lv_apofasisap_arx
FROM zsl_glk_apof
WHERE apofasi = lv_apofasi.
IF sy-subrc = 0.
* Find the APOFASISAPs which changes the starting one and display the
*fields
SELECT a~apofasi a~apofasidate a~apofasisap
a~apofasi_tr_x a~apofasi_trp_x
a~thema a~fek a~reference a~ya_first
INTO CORRESPONDING FIELDS OF TABLE lt_result
FROM zsl_glk_apof AS a INNER JOIN zsl_glk_apof_tr AS b
ON a~apofasisap = b~apofasisap_tr
WHERE b~apofasisap_trp = lv_apofasisap_arx.
IF sy-subrc = 0.
*Pass them to display the result.
CALL FUNCTION 'F4UT_RESULTS_MAP'
EXPORTING
* SOURCE_STRUCTURE =
apply_restrictions = 'X'
TABLES
shlp_tab = shlp_tab
record_tab = record_tab
source_tab = lt_result
CHANGING
shlp = shlp
callcontrol = callcontrol
EXCEPTIONS
illegal_structure = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
FREE lt_result.
ENDIF.
It says NO VALUES FOR THIS SELECTION. The table lt_result contains 11 records.
Thanks again.
I agree with the forespeakers, that provided code is a mess, from which nothing can be figured out.
First of all, use DISP event in SHELP FM exit, not SELECT.
Secondly, you fill the wrong table (or do not show us right filling in the snippet above). In order to pass values back to user you should modify a RECORD_TAB table.
Your code should look something like this (joined selections from zsl_glk_apof and zsl_glk_apof_tr tables):
CHECK callcontrol-step = 'DISP'.
DATA: ls_selopt TYPE ddshselopt. "loc str for shlp-selopt
DATA: BEGIN OF ls_record.
INCLUDE STRUCTURE seahlpres.
DATA: END OF ls_record.
DATA: lv_glk_apof_tr TYPE zsl_glk_apof_tr-apofasisap_tr.
LOOP AT shlp-selopt INTO ls_selopt.
* finding SKOPOS and KATDANL values
CASE ls_selopt-shlpfield.
WHEN 'SKOPOS'.
lv_skopos = ls_selopt-low.
WHEN 'KATDANL'.
lv_katdanl = ls_selopt-low.
WHEN OTHERS.
ENDCASE.
* doing smth
* finding some stuff from Z-tables
SELECT SINGLE tr~apofasisap_tr
FROM zsl_glk_apof AS ap
JOIN zsl_glk_apof_tr AS tr
ON ap~apofasisap = tr~apofasisap_trp
INTO lv_glk_apof_tr
WHERE ap~apofasi = lv_apofasi.
ENDLOOP.
* modify record_tab with the found value lv_glk_apof_tr
LOOP AT record_tab INTO ls_record.
ls_record-string+25(5) = lv_glk_apof_tr. "field shift should be based on your values
ENDLOOP.
Hello and thanks all for your valuable help.
Finally I did it as follow:
if callcontrol-step = 'SELECT'.
get parameter id 'ZAP' field p_apofasi.
get parameter id 'ZSK' field p_skopos.
get parameter id 'ZKATDANL' field p_katdanl.
select single apofasisap into lv_apofasisap_arx
from zsl_glk_apof
where apofasi = p_apofasi and
katdanl = p_katdanl and
skopos = p_skopos.
select * into corresponding fields of table it_apofasisap_tr
from zsl_glk_apof_tr
where apofasisap_trp = lv_apofasisap_arx.
* Display the results to the user
types: begin of ls_result,
apofasi like zsl_glk_apof-apofasi,
apofasidate like zsl_glk_apof-apofasidate,
apofasisap like zsl_glk_apof-apofasisap,
apofasi_trp_x like zsl_glk_apof-apofasi_trp_x,
apofasi_tr_x like zsl_glk_apof-apofasi_tr_x,
katdanl like zsl_glk_apof-katdanl,
skopos like zsl_glk_apof-skopos,
type_desc like zsl_glk_apof-type_desc,
end of ls_result.
data: lt_result type standard table of ls_result.
clear: lt_result, record_tab, record_tab[].
* Fill all the fields of the Search-Help with the data according to the
*selections of the user.
select apofasi apofasidate apofasisap
apofasi_tr_x apofasi_trp_x
katdanl skopos type_desc
into corresponding fields of table lt_result
from zsl_glk_apof
for all entries in it_apofasisap_tr
where apofasisap = it_apofasisap_tr-apofasisap_tr and
apofasi_tr_x = 'X'. "lv_apofasi_tr_x.
call function 'F4UT_RESULTS_MAP'
tables
shlp_tab = shlp_tab
record_tab = record_tab
source_tab = lt_result
changing
shlp = shlp
callcontrol = callcontrol
exceptions
illegal_structure = 1
others = 2.
if sy-subrc = 0.
callcontrol-step = 'DISP'.
else.
callcontrol-step = 'EXIT'.
endif.
endif.
Regards
Elias

Modify an itab during looping another itab

I want to do the following
Loop at itab into wa_itab.
wa_itab2-field1 = wa_itab-field1.
wa_itab2-field2 = wa_itab-field2.
wa_itab2-field3 = wa_itab-field3.
wa_itab2-field4 = wa_itab-field4.
*how to insert in itab2 if fields 1,2 & 3 do not exist or update itab2 if fields 1,2 & 3 exist?
EndLoop.
Let me explain more.
I have itab with fields bukrs, kunnr, date, action.
The itab2 with fields bukrs, kunnr, name1 (from kna1),date01 (jan), action01, date02 (Feb), action02 ... date12 (Dec), action12.
During loop of itab I want if the itab2 has a record with bukrs and kunnr then it will update date and action according to the month of itab-date, if it do not exist (bukrs, kunnr) then insert a record to itab2.
I hope that this explains what I want.
Thanks in advance
Elias
PS. Here is the program
*&---------------------------------------------------------------------*
*& Report Z_COLLECTORS_ACTIONS
*&
*&---------------------------------------------------------------------*
*& Description
*&
*&---------------------------------------------------------------------*
*& Change log:
*& Date Author Action
*&
*&---------------------------------------------------------------------*
REPORT z_collectors_actions.
TABLES: zcollectoraction, kna1, t001.
TYPE-POOLS : slis.
TYPES: BEGIN OF ty_totalcollectoractions,
bukrs TYPE zcollectoraction-bukrs,
kunnr TYPE zcollectoraction-kunnr,
name1 TYPE kna1-name1,
date01 TYPE zcollectoraction-dat,
date02 TYPE zcollectoraction-dat,
date03 TYPE zcollectoraction-dat,
date04 TYPE zcollectoraction-dat,
date05 TYPE zcollectoraction-dat,
date06 TYPE zcollectoraction-dat,
date07 TYPE zcollectoraction-dat,
date08 TYPE zcollectoraction-dat,
date09 TYPE zcollectoraction-dat,
date10 TYPE zcollectoraction-dat,
date11 TYPE zcollectoraction-dat,
date12 TYPE zcollectoraction-dat,
action01 TYPE zcollectoraction-action,
action02 TYPE zcollectoraction-action,
action03 TYPE zcollectoraction-action,
action04 TYPE zcollectoraction-action,
action05 TYPE zcollectoraction-action,
action06 TYPE zcollectoraction-action,
action07 TYPE zcollectoraction-action,
action08 TYPE zcollectoraction-action,
action09 TYPE zcollectoraction-action,
action10 TYPE zcollectoraction-action,
action11 TYPE zcollectoraction-action,
action12 TYPE zcollectoraction-action,
END OF ty_totalcollectoractions.
DATA: wa_collectoraction LIKE zcollectoraction,
it_collectoraction LIKE TABLE OF zcollectoraction,
wa_totalcollectoractions TYPE ty_totalcollectoractions,
it_totalcollectoractions TYPE TABLE OF ty_totalcollectoractions WITH KEY kunnr.
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
field_catalog TYPE lvc_t_fcat,
gd_layout TYPE slis_layout_alv,
gd_repid LIKE sy-repid,
g_save TYPE c VALUE 'X',
g_variant TYPE disvariant,
gx_variant TYPE disvariant,
g_exit TYPE c.
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-001.
PARAMETERS: variant LIKE disvariant-variant.
PARAMETERS p_bukrs TYPE bukrs OBLIGATORY.
SELECT-OPTIONS: so_kunnr FOR kna1-kunnr OBLIGATORY,
so_date FOR sy-datum OBLIGATORY.
SELECTION-SCREEN END OF BLOCK bl1.
INITIALIZATION.
gx_variant-report = sy-repid.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save = g_save
CHANGING
cs_variant = gx_variant
EXCEPTIONS
not_found = 2.
IF sy-subrc = 0.
variant = gx_variant-variant.
ENDIF.
START-OF-SELECTION.
SELECT bukrs kunnr dat MAX( time ) AS time
FROM zcollectoraction INTO CORRESPONDING FIELDS OF TABLE it_collectoraction
WHERE bukrs = p_bukrs AND
kunnr IN so_kunnr AND
dat IN so_date
GROUP BY bukrs kunnr dat.
LOOP AT it_collectoraction INTO wa_collectoraction.
SELECT SINGLE * FROM zcollectoraction INTO CORRESPONDING FIELDS OF wa_collectoraction
WHERE bukrs = wa_collectoraction-bukrs AND
kunnr = wa_collectoraction-kunnr AND
dat = wa_collectoraction-dat AND
time = wa_collectoraction-time.
MODIFY it_collectoraction FROM wa_collectoraction.
wa_totalcollectoractions-bukrs = wa_collectoraction-bukrs.
wa_totalcollectoractions-kunnr = wa_collectoraction-kunnr.
SELECT SINGLE name1 FROM kna1 INTO wa_totalcollectoractions-name1
WHERE kunnr = wa_collectoraction-kunnr.
DATA lv_month TYPE n LENGTH 2.
lv_month = wa_collectoraction-dat+4(2).
CASE lv_month.
WHEN '01'.
wa_totalcollectoractions-date01 = wa_collectoraction-dat.
wa_totalcollectoractions-action01 = wa_collectoraction-action.
WHEN '02'.
wa_totalcollectoractions-date02 = wa_collectoraction-dat.
wa_totalcollectoractions-action02 = wa_collectoraction-action.
WHEN '03'.
wa_totalcollectoractions-date03 = wa_collectoraction-dat.
wa_totalcollectoractions-action03 = wa_collectoraction-action.
WHEN '04'.
wa_totalcollectoractions-date04 = wa_collectoraction-dat.
wa_totalcollectoractions-action04 = wa_collectoraction-action.
WHEN '05'.
wa_totalcollectoractions-date05 = wa_collectoraction-dat.
wa_totalcollectoractions-action05 = wa_collectoraction-action.
WHEN '06'.
wa_totalcollectoractions-date06 = wa_collectoraction-dat.
wa_totalcollectoractions-action06 = wa_collectoraction-action.
WHEN '07'.
wa_totalcollectoractions-date07 = wa_collectoraction-dat.
wa_totalcollectoractions-action07 = wa_collectoraction-action.
WHEN '08'.
wa_totalcollectoractions-date08 = wa_collectoraction-dat.
wa_totalcollectoractions-action08 = wa_collectoraction-action.
WHEN '09'.
wa_totalcollectoractions-date09 = wa_collectoraction-dat.
wa_totalcollectoractions-action09 = wa_collectoraction-action.
WHEN '10'.
wa_totalcollectoractions-date10 = wa_collectoraction-dat.
wa_totalcollectoractions-action10 = wa_collectoraction-action.
WHEN '11'.
wa_totalcollectoractions-date11 = wa_collectoraction-dat.
wa_totalcollectoractions-action11 = wa_collectoraction-action.
WHEN '12'.
wa_totalcollectoractions-date12 = wa_collectoraction-dat.
wa_totalcollectoractions-action12 = wa_collectoraction-action.
WHEN OTHERS.
ENDCASE.
READ TABLE it_totalcollectoractions INTO wa_totalcollectoractions
WITH TABLE KEY kunnr = wa_collectoraction-kunnr.
IF sy-subrc = 0.
MODIFY it_totalcollectoractions INDEX sy-tabix FROM wa_totalcollectoractions.
ELSE.
INSERT wa_totalcollectoractions INTO TABLE it_totalcollectoractions.
ENDIF.
ENDLOOP.
PERFORM build_fieldcatalog_agreggate.
PERFORM display_alv_report.
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_alv_report .
gd_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = fieldcatalog[]
i_save = 'X'
is_variant = g_variant
TABLES
t_outtab = it_totalcollectoractions
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " DISPLAY_ALV_REPORT
*-------------------------------------------------------------------*
* Form TOP-OF-PAGE *
*-------------------------------------------------------------------*
* ALV Report Header *
*-------------------------------------------------------------------*
FORM top-of-page.
*ALV Header declarations
DATA: t_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader,
t_line LIKE wa_header-info,
ld_lines TYPE i,
ld_linesc(10) TYPE c,
lv_butxt TYPE butxt.
SELECT SINGLE butxt INTO lv_butxt FROM t001
WHERE bukrs = p_bukrs.
* Title
wa_header-typ = 'H'.
wa_header-info = 'Collectors'' Action Report'.
APPEND wa_header TO t_header.
CLEAR wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
APPEND wa_header TO t_header.
CLEAR: wa_header.
* Bukrs
wa_header-typ = 'S'.
wa_header-key = 'Company: '.
CONCATENATE p_bukrs lv_butxt INTO wa_header-info SEPARATED BY space.
APPEND wa_header TO t_header.
CLEAR wa_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.
ENDFORM. "top-of-page
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG_AGREGGATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcatalog_agreggate .
fieldcatalog-fieldname = 'KUNNR'.
fieldcatalog-seltext_m = 'Customer ID'.
fieldcatalog-col_pos = 0.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'NAME1'.
fieldcatalog-seltext_m = 'Customer Name'.
fieldcatalog-col_pos = 1.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ACTION01'.
fieldcatalog-seltext_m = 'January'.
fieldcatalog-col_pos = 2.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ACTION02'.
fieldcatalog-seltext_m = 'February'.
fieldcatalog-col_pos = 3.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ACTION03'.
fieldcatalog-seltext_m = 'March'.
fieldcatalog-col_pos = 4.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ACTION04'.
fieldcatalog-seltext_m = 'April'.
fieldcatalog-col_pos = 5.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ACTION05'.
fieldcatalog-seltext_m = 'May'.
fieldcatalog-col_pos = 6.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ACTION06'.
fieldcatalog-seltext_m = 'June'.
fieldcatalog-col_pos = 7.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ACTION07'.
fieldcatalog-seltext_m = 'July'.
fieldcatalog-col_pos = 8.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ACTION08'.
fieldcatalog-seltext_m = 'August'.
fieldcatalog-col_pos = 9.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ACTION09'.
fieldcatalog-seltext_m = 'September'.
fieldcatalog-col_pos = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ACTION10'.
fieldcatalog-seltext_m = 'Octomber'.
fieldcatalog-col_pos = 11.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ACTION11'.
fieldcatalog-seltext_m = 'Noveber'.
fieldcatalog-col_pos = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ACTION12'.
fieldcatalog-seltext_m = 'December'.
fieldcatalog-col_pos = 11.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
ENDFORM. " BUILD_FIELDCATALOG_AGREGGATE
If itab is not too big, then you can do like below.
clear: itab2[].
Loop at itab into wa_itab.
wa_itab2-field1 = wa_itab-field1.
wa_itab2-field2 = wa_itab-field2.
wa_itab2-field3 = wa_itab-field3.
wa_itab2-field4 = wa_itab-field4.
...
read table itab2 into data(ls_itab2) with key field1 = wa_itab2-field1
field2 = wa_itab2-field2
field3 = wa_itab2-field3
...
binary search.
if sy-subrc = 0 .
" modify the line
modify itab2 from wa_itab2 index sy-tabix.
else.
" append the line
append wa_itab2 to itab2.
sort itab2 ascending by field1 field2 field3 ... . "the key fields.
endif.
EndLoop.
FIELD-SYMBOLS: <fs_itab2> TYPE wa_itab2.
SORT itab2 BY bukrs kunnr.
LOOP AT itab INTO wa_itab.
***CHECK IF DATES EXIST***
READ TABLE itab2 ASSIGNING <fs_itab2> WITH KEY bukrs = wa_itab-bukrs
kunnr = wa_itab-kunnr
BINARY SEARCH.
if sy-subrc = 0 . "if the record are founded
<fs_itab2>-field1 = wa_itab-field1.
<fs_itab2>-field2 = wa_itab-field2.
<fs_itab2>-field3 = wa_itab-field3.
...
else.
APPEND INITIAL LINE TO itab2 ASSIGNING <fs_itab2>.
IF <fs_itab2> IS ASSIGNED.
<fs_itab2>-field1 = wa_itab-field1.
<fs_itab2>-field2 = wa_itab-field2.
<fs_itab2>-field3 = wa_itab-field3.
...
ENDIF.
ENDLOOP.
Thats is all with field symbols.
You do not need looping here, MOVE-CORRESPONDING do this for internal tables like a charm:
MOVE-CORRESPONDING src_tab TO target.
Here is the sample where MWST price conditions are selected into two itabs, then the currently valid ones are made invalid, then couple of additional invalid conditions with new key are added, and finally the second itab lt_upd_konh is updated, so that all MWST conditions in it gets invalidated with adding extra ones.
SELECT * FROM konh INTO TABLE #DATA(lt_konh) WHERE kschl = 'MWST'.
DATA(lt_upd_konh) = lt_konh.
LOOP AT lt_konh ASSIGNING FIELD-SYMBOL(<fs_konh>) WHERE datbi > sy-datum.
<fs_konh>-datbi = sy-datum - 1.
ENDLOOP.
<fs_konh>-knumh = 1000.
APPEND <fs_konh> TO lt_konh.
<fs_konh>-knumh = 1001.
APPEND <fs_konh> TO lt_konh.
<fs_konh>-knumh = 1002.
APPEND <fs_konh> TO lt_konh.
MOVE-CORRESPONDING lt_konh TO lt_upd_konh.

ABAP return to the initial selection screen after a write

I am new to ABAP. I have created a report that basically handles the CRUD for a database already built with function modules. It has multiple selection-screens for every function. Is there anyway to perform a READ and print it on the screen with 'write' and after that go back to the initial Selection-screen?
DATA: lv_response1 TYPE flag,
lv_response2 TYPE flag,
lv_response3 TYPE flag.
SELECTION-SCREEN BEGIN OF SCREEN 100.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-t01.
PARAMETERS: s1 RADIOBUTTON GROUP g1,
s2 RADIOBUTTON GROUP g1,
s3 RADIOBUTTON GROUP g1,
s4 RADIOBUTTON GROUP g1,
s5 RADIOBUTTON GROUP g1.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN END OF SCREEN 100.
SELECTION-SCREEN BEGIN OF SCREEN 200.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-t02.
PARAMETERS: p_skill TYPE Z0B_SKILL_ACR,
p_skills type Z0B_SKILL_SUBDOM_ACR,
p_skilld TYPE Z0B_SKILL_NAME,
p_skilll TYPE z0b_linguistic.
SELECTION-SCREEN END OF BLOCK B2.
SELECTION-SCREEN END OF SCREEN 200.
SELECTION-SCREEN BEGIN OF SCREEN 300.
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-t03.
PARAMETERS: p_skid TYPE z0b_skillid,
p_all TYPE flag.
SELECTION-SCREEN END OF BLOCK B3.
SELECTION-SCREEN END OF SCREEN 300.
SELECTION-SCREEN BEGIN OF SCREEN 400.
SELECTION-SCREEN BEGIN OF BLOCK B4 WITH FRAME TITLE TEXT-t04.
PARAMETERS: p_skacr TYPE z0b_skill_acr,
p_skdesc TYPE z0b_skill_name.
SELECTION-SCREEN END OF BLOCK B4.
SELECTION-SCREEN END OF SCREEN 400.
SELECTION-SCREEN BEGIN OF SCREEN 500.
SELECTION-SCREEN BEGIN OF BLOCK B5 WITH FRAME TITLE TEXT-t05.
PARAMETERS p_dskid TYPE z0b_skillid.
SELECTION-SCREEN END OF BLOCK B5.
SELECTION-SCREEN END OF SCREEN 500.
CALL SELECTION-SCREEN 100.
IF s1 = 'X'.
"Create skill
CALL SELECTION-SCREEN 200.
CALL FUNCTION 'Z0B_ADD_NEW_SKILL'
EXPORTING
IV_SKILL_ACR = p_skill
IV_SKILL_SUBDOM = p_skills
IV_SKILL_DESC = P_skilld
IV_SKILL_LINGUISTIC = p_skilll
IMPORTING
EV_CHECK_SUBDOM = lv_response1
EV_CHECK_SKILL_ACR_A = lv_response2
EV_CHECK = lv_response3.
IF lv_response1 eq 0.
WRITE:/ 'Subdomain does not exist.'.
ENDIF.
IF lv_response2 eq 1.
WRITE:/ 'Skill already exists.'.
ENDIF.
IF lv_response3 eq 0.
WRITE:/ 'Database error.'.
ENDIF.
IF lv_response1 eq 1 AND lv_response2 eq 0 AND lv_response3 eq 1.
WRITE:/ 'Skill created successfully.'.
ENDIF.
EXIT.
ENDIF.
***********************************************************************************************************
IF s2 = 'X'.
"Read skill
CALL SELECTION-SCREEN 300.
data: lt_skills type Z0B_MY_SKILLS_T,
ls_skills type z0b_skills_t.
IF p_all is not INITIAL.
CALL FUNCTION 'Z0B_GET_ALL_SKILLS'
IMPORTING
ET_NONLINGUISTIC_SKILLS = lt_skills
EV_CHECK = lv_response2
* EXCEPTIONS
* NO_SKILL = 1
* OTHERS = 2
.
write 'Non-linguistic skills'.
LOOP AT lt_skills into ls_skills.
write: / ls_skills-skillid, ls_skills-skill_text, ls_skills-skill_acr.
ENDLOOP.
CALL FUNCTION 'Z0B_GET_LANG'
IMPORTING
ET_LINGUISTIC_SKILLS = lt_skills
EV_CHECK = lv_response3
* EXCEPTIONS
* NO_SKILL = 1
* OTHERS = 2
.
write:/.
write:/ 'Linguistic skills'.
LOOP AT lt_skills into ls_skills.
write: / ls_skills-skillid, ls_skills-skill_text, ls_skills-skill_acr.
ENDLOOP.
IF lv_response3 eq 0 and lv_response2 eq 0.
WRITE:/ 'No entries.'.
endif.
exit.
ENDIF.
CALL FUNCTION 'Z0B_READ_MASTERDATA_SKILL'
EXPORTING
IV_SKILLID = p_skid
IMPORTING
ET_SKILLS = lt_skills
EV_CHECK = lv_response3
* EXCEPTIONS
* NO_DATA = 1
* OTHERS = 2.
IF lv_response3 eq 0.
WRITE:/ 'Database error.'.
ENDIF.
LOOP AT lt_skills into ls_skills.
write: / ls_skills-skill_text, ls_skills-skill_acr.
ENDLOOP.
endif.
***********************************************************************************
IF s3 = 'X'.
" Update a skill
CALL SELECTION-SCREEN 400.
CALL FUNCTION 'Z0B_MODIFY_SKILL'
EXPORTING
IV_SKILLS_ACR = p_skacr
IV_SKILLS_DESC = p_skdesc
IMPORTING
EV_CHECK = lv_response1
* EXCEPTIONS
* NO_SKILL = 1
* NO_DATA = 2
* NO_UPDATE = 3
* OTHERS = 4
.
IF lv_response1 = 0.
WRITE 'Failed.'.
else.
write 'Skill modified successfully'.
ENDIF.
ENDIF.
***********************************************************************************
IF s4 = 'X'.
CALL SELECTION-SCREEN 500.
CALL FUNCTION 'Z0B_DELETE_SKILL'
EXPORTING
IV_SKILLS_ID = p_dskid
IMPORTING
EV_CHECK = lv_response1
* EXCEPTIONS
* NO_SKILL = 1
* NO_MOVE = 2
* NO_DELETE_1 = 3
* NO_DELETE_2 = 4
* SKILL_USED = 5
* OTHERS = 6
.
IF lv_response1 = 0.
WRITE 'Failed.'.
else.
write 'Skill deleted successfully'.
ENDIF.
ENDIF.
Remove the SELECTION-SCREEN BEGIN/END OF SCREEN 100. That way what was screen 100 will become the standard selection screen (1000), then there also is no need to call it anymore. So, replace the CALL SELECTION-SCREEN 100 with START-OF-SELECTION. With those changes you will get back to the selection screen when you press the back arrow on the output screen.
You might also have to remove the EXIT.

How to read the position value given the cost center

I want to read the position using this FM HRWPC_RPT_COSTCENTER_EVALPATH where the cost center is given.
There are 3 result tables. from which table I can read the position value ?
here how I call the FM:
DATA i_hrrootob TYPE TABLE OF hrrootob.
DATA w_hrrootob LIKE LINE OF i_hrrootob.
DATA i_object_tab TYPE TABLE OF objec.
DATA w_object_tab LIKE LINE OF i_object_tab.
data i_STRUC TYPE TABLE OF STRUC.
w_hrrootob-otype = 'K'.
w_hrrootob-objid = w_orgdata-costcenter_key-costcenter.
APPEND w_hrrootob TO i_hrrootob.
CALL FUNCTION 'HRWPC_RPT_COSTCENTER_EVALPATH'
EXPORTING
depth = 0
evpath = 'KOSTDIUP'
* PLVAR = 01
* BEGDA = SY-DATUM
* ENDDA = SY-DATUM
* LEVEL = 1
TABLES
root_objects = i_hrrootob
result_objec = i_object_tab
result_struc = i_STRUC
EXCEPTIONS
NO_OBJECTS_FOUND = 1
OTHERS = 2
.
I got it by myself.
The result table result_objec has the value in the field stext, where the obtype ='S'